From dce6b6d26636cc44eec7bd0cb7237a331c24ac72 Mon Sep 17 00:00:00 2001 From: thomcsmits Date: Fri, 19 Jan 2024 11:03:51 -0500 Subject: [PATCH] Updates --- ...ex.es-3acd4243.js => index.es-9c0fafeb.js} | 2 +- ...n-5cd5e647.js => jspdf.es.min-c088be8f.js} | 4 +- assets/{main-316b396b.js => main-49fcee98.js} | 472 +++++++++--------- index.html | 2 +- 4 files changed, 240 insertions(+), 240 deletions(-) rename assets/{index.es-3acd4243.js => index.es-9c0fafeb.js} (99%) rename assets/{jspdf.es.min-5cd5e647.js => jspdf.es.min-c088be8f.js} (99%) rename assets/{main-316b396b.js => main-49fcee98.js} (70%) diff --git a/assets/index.es-3acd4243.js b/assets/index.es-9c0fafeb.js similarity index 99% rename from assets/index.es-3acd4243.js rename to assets/index.es-9c0fafeb.js index 0408095..5ea8d8c 100644 --- a/assets/index.es-3acd4243.js +++ b/assets/index.es-9c0fafeb.js @@ -1,4 +1,4 @@ -import{c as Je,g as Do}from"./main-316b396b.js";import{_ as Ha}from"./jspdf.es.min-5cd5e647.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-49fcee98.js";import{_ as Ha}from"./jspdf.es.min-c088be8f.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-5cd5e647.js b/assets/jspdf.es.min-c088be8f.js similarity index 99% rename from assets/jspdf.es.min-5cd5e647.js rename to assets/jspdf.es.min-c088be8f.js index d3d5b48..440d60a 100644 --- a/assets/jspdf.es.min-5cd5e647.js +++ b/assets/jspdf.es.min-c088be8f.js @@ -1,4 +1,4 @@ -import{_ as ls}from"./main-316b396b.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-49fcee98.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-3acd4243.js"),["assets/index.es-3acd4243.js","assets/main-316b396b.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-9c0fafeb.js"),["assets/index.es-9c0fafeb.js","assets/main-49fcee98.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;bg in e?Yke(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I;var Gu=(e,g,I)=>(Kke(e,typeof g!="symbol"?g+"":g,I),I);function xke(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 yI=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function jc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function P_(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 Mue={exports:{}},LH={},zue={exports:{}},pg={};/** +var zke=Object.defineProperty;var Pke=(e,g,i)=>g in e?zke(e,g,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[g]=i;var Zu=(e,g,i)=>(Pke(e,typeof g!="symbol"?g+"":g,i),i);function Jke(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 r of n)if(r.type==="childList")for(const C of r.addedNodes)C.tagName==="LINK"&&C.rel==="modulepreload"&&I(C)}).observe(document,{childList:!0,subtree:!0});function i(n){const r={};return n.integrity&&(r.integrity=n.integrity),n.referrerPolicy&&(r.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?r.credentials="include":n.crossOrigin==="anonymous"?r.credentials="omit":r.credentials="same-origin",r}function I(n){if(n.ep)return;n.ep=!0;const r=i(n);fetch(n.href,r)}})();var yi=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Qc(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Q_(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 Que={exports:{}},jH={},jue={exports:{}},pg={};/** * @license React * react.production.min.js * @@ -6,7 +6,7 @@ var Yke=Object.defineProperty;var Kke=(e,g,I)=>g in e?Yke(e,g,{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 pS=Symbol.for("react.element"),Dke=Symbol.for("react.portal"),Fke=Symbol.for("react.fragment"),Eke=Symbol.for("react.strict_mode"),Mke=Symbol.for("react.profiler"),zke=Symbol.for("react.provider"),Pke=Symbol.for("react.context"),Jke=Symbol.for("react.forward_ref"),Oke=Symbol.for("react.suspense"),_ke=Symbol.for("react.memo"),Lke=Symbol.for("react.lazy"),n6=Symbol.iterator;function Uke(e){return e===null||typeof e!="object"?null:(e=n6&&e[n6]||e["@@iterator"],typeof e=="function"?e:null)}var Pue={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},Jue=Object.assign,Oue={};function y0(e,g,I){this.props=e,this.context=g,this.refs=Oue,this.updater=I||Pue}y0.prototype.isReactComponent={};y0.prototype.setState=function(e,g){if(typeof e!="object"&&typeof e!="function"&&e!=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,e,g,"setState")};y0.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function _ue(){}_ue.prototype=y0.prototype;function J_(e,g,I){this.props=e,this.context=g,this.refs=Oue,this.updater=I||Pue}var O_=J_.prototype=new _ue;O_.constructor=J_;Jue(O_,y0.prototype);O_.isPureReactComponent=!0;var C6=Array.isArray,Lue=Object.prototype.hasOwnProperty,__={current:null},Uue={key:!0,ref:!0,__self:!0,__source:!0};function Que(e,g,I){var i,n={},C=null,r=null;if(g!=null)for(i in g.ref!==void 0&&(r=g.ref),g.key!==void 0&&(C=""+g.key),g)Lue.call(g,i)&&!Uue.hasOwnProperty(i)&&(n[i]=g[i]);var o=arguments.length-2;if(o===1)n.children=I;else if(1g in e?Yke(e,g,{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 eYe=U,tYe=Symbol.for("react.element"),gYe=Symbol.for("react.fragment"),IYe=Object.prototype.hasOwnProperty,iYe=eYe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,nYe={key:!0,ref:!0,__self:!0,__source:!0};function jue(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)IYe.call(g,i)&&!nYe.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:tYe,type:e,key:C,ref:r,props:n,_owner:iYe.current}}LH.Fragment=gYe;LH.jsx=jue;LH.jsxs=jue;Mue.exports=LH;var Oe=Mue.exports,IE={},$ue={exports:{}},br={},que={exports:{}},ede={};/** + */var CYe=U,oYe=Symbol.for("react.element"),aYe=Symbol.for("react.fragment"),AYe=Object.prototype.hasOwnProperty,sYe=CYe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,lYe={key:!0,ref:!0,__self:!0,__source:!0};function nde(e,g,i){var I,n={},r=null,C=null;i!==void 0&&(r=""+i),g.key!==void 0&&(r=""+g.key),g.ref!==void 0&&(C=g.ref);for(I in g)AYe.call(g,I)&&!lYe.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:oYe,type:e,key:r,ref:C,props:n,_owner:sYe.current}}jH.Fragment=aYe;jH.jsx=nde;jH.jsxs=nde;Que.exports=jH;var Oe=Que.exports,oE={},rde={exports:{}},pC={},Cde={exports:{}},ode={};/** * @license React * scheduler.production.min.js * @@ -22,7 +22,7 @@ var Yke=Object.defineProperty;var Kke=(e,g,I)=>g in e?Yke(e,g,{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(e){function g(F,J){var P=F.length;F.push(J);e:for(;0>>1,q=F[ge];if(0>>1;ge<$;){var j=2*(ge+1)-1,te=F[j],Q=j+1,ie=F[Q];if(0>n(te,P))Qn(ie,te)?(F[ge]=ie,F[Q]=P,ge=Q):(F[ge]=te,F[j]=P,ge=j);else if(Qn(ie,P))F[ge]=ie,F[Q]=P,ge=Q;else break e}}return J}function n(F,J){var P=F.sortIndex-J.sortIndex;return P!==0?P:F.id-J.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(F){for(var J=I(s);J!==null;){if(J.callback===null)i(s);else if(J.startTime<=F)i(s),J.sortIndex=J.expirationTime,g(a,J);else break;J=I(s)}}function y(F){if(h=!1,p(F),!d)if(I(a)!==null)d=!0,Y(Z);else{var J=I(s);J!==null&&K(y,J.startTime-F)}}function Z(F,J){d=!1,h&&(h=!1,f(v),v=-1),u=!0;var P=c;try{for(p(J),l=I(a);l!==null&&(!(l.expirationTime>J)||F&&!S());){var ge=l.callback;if(typeof ge=="function"){l.callback=null,c=l.priorityLevel;var q=ge(l.expirationTime<=J);J=e.unstable_now(),typeof q=="function"?l.callback=q:l===I(a)&&i(a),p(J)}else i(a);l=I(a)}if(l!==null)var $=!0;else{var j=I(s);j!==null&&K(y,j.startTime-J),$=!1}return $}finally{l=null,c=P,u=!1}}var B=!1,G=null,v=-1,w=5,V=-1;function S(){return!(e.unstable_now()-VF||125ge?(F.sortIndex=P,g(s,F),I(a)===null&&F===I(s)&&(h?(f(v),v=-1):h=!0,K(y,P-ge))):(F.sortIndex=q,g(a,F),d||u||(d=!0,Y(Z))),F},e.unstable_shouldYield=S,e.unstable_wrapCallback=function(F){var J=c;return function(){var P=c;c=J;try{return F.apply(this,arguments)}finally{c=P}}}})(ede);que.exports=ede;var CYe=que.exports;/** + */(function(e){function g(x,J){var P=x.length;x.push(J);e:for(;0>>1,q=x[ge];if(0>>1;ge<$;){var j=2*(ge+1)-1,te=x[j],Q=j+1,Ie=x[Q];if(0>n(te,P))Qn(Ie,te)?(x[ge]=Ie,x[Q]=P,ge=Q):(x[ge]=te,x[j]=P,ge=j);else if(Qn(Ie,P))x[ge]=Ie,x[Q]=P,ge=Q;else break e}}return J}function n(x,J){var P=x.sortIndex-J.sortIndex;return P!==0?P:x.id-J.id}if(typeof performance=="object"&&typeof performance.now=="function"){var r=performance;e.unstable_now=function(){return r.now()}}else{var C=Date,o=C.now();e.unstable_now=function(){return C.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(x){for(var J=i(s);J!==null;){if(J.callback===null)I(s);else if(J.startTime<=x)I(s),J.sortIndex=J.expirationTime,g(a,J);else break;J=i(s)}}function y(x){if(h=!1,p(x),!d)if(i(a)!==null)d=!0,Y(Z);else{var J=i(s);J!==null&&K(y,J.startTime-x)}}function Z(x,J){d=!1,h&&(h=!1,f(v),v=-1),u=!0;var P=c;try{for(p(J),l=i(a);l!==null&&(!(l.expirationTime>J)||x&&!S());){var ge=l.callback;if(typeof ge=="function"){l.callback=null,c=l.priorityLevel;var q=ge(l.expirationTime<=J);J=e.unstable_now(),typeof q=="function"?l.callback=q:l===i(a)&&I(a),p(J)}else I(a);l=i(a)}if(l!==null)var $=!0;else{var j=i(s);j!==null&&K(y,j.startTime-J),$=!1}return $}finally{l=null,c=P,u=!1}}var B=!1,G=null,v=-1,w=5,R=-1;function S(){return!(e.unstable_now()-Rx||125ge?(x.sortIndex=P,g(s,x),i(a)===null&&x===i(s)&&(h?(f(v),v=-1):h=!0,K(y,P-ge))):(x.sortIndex=q,g(a,x),d||u||(d=!0,Y(Z))),x},e.unstable_shouldYield=S,e.unstable_wrapCallback=function(x){var J=c;return function(){var P=c;c=J;try{return x.apply(this,arguments)}finally{c=P}}}})(ode);Cde.exports=ode;var cYe=Cde.exports;/** * @license React * react-dom.production.min.js * @@ -30,66 +30,66 @@ var Yke=Object.defineProperty;var Kke=(e,g,I)=>g in e?Yke(e,g,{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 tde=U,fr=CYe;function st(e){for(var g="https://reactjs.org/docs/error-decoder.html?invariant="+e,I=1;I"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),iE=Object.prototype.hasOwnProperty,rYe=/^[: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]*$/,o6={},a6={};function oYe(e){return iE.call(a6,e)?!0:iE.call(o6,e)?!1:rYe.test(e)?a6[e]=!0:(o6[e]=!0,!1)}function aYe(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 AYe(e,g,I,i){if(g===null||typeof g>"u"||aYe(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 hC(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 hn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){hn[e]=new hC(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var g=e[0];hn[g]=new hC(g,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){hn[e]=new hC(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){hn[e]=new hC(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){hn[e]=new hC(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){hn[e]=new hC(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){hn[e]=new hC(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){hn[e]=new hC(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){hn[e]=new hC(e,5,!1,e.toLowerCase(),null,!1,!1)});var U_=/[\-:]([a-z])/g;function Q_(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(U_,Q_);hn[g]=new hC(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(U_,Q_);hn[g]=new hC(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(U_,Q_);hn[g]=new hC(g,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){hn[e]=new hC(e,1,!1,e.toLowerCase(),null,!1,!1)});hn.xlinkHref=new hC("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){hn[e]=new hC(e,1,!1,e.toLowerCase(),null,!0,!0)});function j_(e,g,I,i){var n=hn.hasOwnProperty(g)?hn[g]:null;(n!==null?n.type!==0:i||!(2o||n[r]!==C[o]){var a=` -`+n[r].replace(" at new "," at ");return e.displayName&&a.includes("")&&(a=a.replace("",e.displayName)),a}while(1<=r&&0<=o);break}}}finally{UY=!1,Error.prepareStackTrace=I}return(e=e?e.displayName||e.name:"")?XZ(e):""}function sYe(e){switch(e.tag){case 5:return XZ(e.type);case 16:return XZ("Lazy");case 13:return XZ("Suspense");case 19:return XZ("SuspenseList");case 0:case 2:case 15:return e=QY(e.type,!1),e;case 11:return e=QY(e.type.render,!1),e;case 1:return e=QY(e.type,!0),e;default:return""}}function oE(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 Jf:return"Fragment";case Pf:return"Portal";case nE:return"Profiler";case $_:return"StrictMode";case CE:return"Suspense";case rE:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case ide:return(e.displayName||"Context")+".Consumer";case Ide:return(e._context.displayName||"Context")+".Provider";case q_:var g=e.render;return e=e.displayName,e||(e=g.displayName||g.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case eL:return g=e.displayName||null,g!==null?g:oE(e.type)||"Memo";case El:g=e._payload,e=e._init;try{return oE(e(g))}catch{}}return null}function lYe(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 oE(g);case 8:return g===$_?"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 Mc(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function Cde(e){var g=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(g==="checkbox"||g==="radio")}function cYe(e){var g=Cde(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 $w(e){e._valueTracker||(e._valueTracker=cYe(e))}function rde(e){if(!e)return!1;var g=e._valueTracker;if(!g)return!0;var I=g.getValue(),i="";return e&&(i=Cde(e)?e.checked?"true":"false":e.value),e=i,e!==I?(g.setValue(e),!0):!1}function PW(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 aE(e,g){var I=g.checked;return zI({},g,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:I??e._wrapperState.initialChecked})}function s6(e,g){var I=g.defaultValue==null?"":g.defaultValue,i=g.checked!=null?g.checked:g.defaultChecked;I=Mc(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 ode(e,g){g=g.checked,g!=null&&j_(e,"checked",g,!1)}function AE(e,g){ode(e,g);var I=Mc(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")?sE(e,g.type,I):g.hasOwnProperty("defaultValue")&&sE(e,g.type,Mc(g.defaultValue)),g.checked==null&&g.defaultChecked!=null&&(e.defaultChecked=!!g.defaultChecked)}function l6(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 sE(e,g,I){(g!=="number"||PW(e.ownerDocument)!==e)&&(I==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+I&&(e.defaultValue=""+I))}var HZ=Array.isArray;function hp(e,g,I,i){if(e=e.options,g){g={};for(var n=0;n"+g.valueOf().toString()+"",g=qw.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;g.firstChild;)e.appendChild(g.firstChild)}});function Fv(e,g){if(g){var I=e.firstChild;if(I&&I===e.lastChild&&I.nodeType===3){I.nodeValue=g;return}}e.textContent=g}var BG={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},uYe=["Webkit","ms","Moz","O"];Object.keys(BG).forEach(function(e){uYe.forEach(function(g){g=g+e.charAt(0).toUpperCase()+e.substring(1),BG[g]=BG[e]})});function lde(e,g,I){return g==null||typeof g=="boolean"||g===""?"":I||typeof g!="number"||g===0||BG.hasOwnProperty(e)&&BG[e]?(""+g).trim():g+"px"}function cde(e,g){e=e.style;for(var I in g)if(g.hasOwnProperty(I)){var i=I.indexOf("--")===0,n=lde(I,g[I],i);I==="float"&&(I="cssFloat"),i?e.setProperty(I,n):e[I]=n}}var dYe=zI({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 uE(e,g){if(g){if(dYe[e]&&(g.children!=null||g.dangerouslySetInnerHTML!=null))throw Error(st(137,e));if(g.dangerouslySetInnerHTML!=null){if(g.children!=null)throw Error(st(60));if(typeof g.dangerouslySetInnerHTML!="object"||!("__html"in g.dangerouslySetInnerHTML))throw Error(st(61))}if(g.style!=null&&typeof g.style!="object")throw Error(st(62))}}function dE(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 hE=null;function tL(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var mE=null,mp=null,fp=null;function d6(e){if(e=ZS(e)){if(typeof mE!="function")throw Error(st(280));var g=e.stateNode;g&&(g=qH(g),mE(e.stateNode,e.type,g))}}function ude(e){mp?fp?fp.push(e):fp=[e]:mp=e}function dde(){if(mp){var e=mp,g=fp;if(fp=mp=null,d6(e),g)for(e=0;e>>=0,e===0?32:31-(SYe(e)/wYe|0)|0}var eV=64,tV=4194304;function TZ(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 LW(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=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(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 bS(e,g,I){e.pendingLanes|=g,g!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,g=31-ea(g),e[g]=I}function XYe(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=wG),v6=String.fromCharCode(32),B6=!1;function kde(e,g){switch(e){case"keyup":return nKe.indexOf(g.keyCode)!==-1;case"keydown":return g.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Yde(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Of=!1;function rKe(e,g){switch(e){case"compositionend":return Yde(g);case"keypress":return g.which!==32?null:(B6=!0,v6);case"textInput":return e=g.data,e===v6&&B6?null:e;default:return null}}function oKe(e,g){if(Of)return e==="compositionend"||!aL&&kde(e,g)?(e=Tde(),h1=CL=oc=null,Of=!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=R6(I)}}function Fde(e,g){return e&&g?e===g?!0:e&&e.nodeType===3?!1:g&&g.nodeType===3?Fde(e,g.parentNode):"contains"in e?e.contains(g):e.compareDocumentPosition?!!(e.compareDocumentPosition(g)&16):!1:!1}function Ede(){for(var e=window,g=PW();g instanceof e.HTMLIFrameElement;){try{var I=typeof g.contentWindow.location.href=="string"}catch{I=!1}if(I)e=g.contentWindow;else break;g=PW(e.document)}return g}function AL(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 mKe(e){var g=Ede(),I=e.focusedElem,i=e.selectionRange;if(g!==I&&I&&I.ownerDocument&&Fde(I.ownerDocument.documentElement,I)){if(i!==null&&AL(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=W6(I,C);var r=W6(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,_f=null,GE=null,RG=null,vE=!1;function X6(e,g,I){var i=I.window===I?I.document:I.nodeType===9?I:I.ownerDocument;vE||_f==null||_f!==PW(i)||(i=_f,"selectionStart"in i&&AL(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}),RG&&Ov(RG,i)||(RG=i,i=jW(GE,"onSelect"),0Qf||(e.current=WE[Qf],WE[Qf]=null,Qf--)}function oI(e,g){Qf++,WE[Qf]=e.current,e.current=g}var zc={},Kn=qc(zc),xC=qc(!1),zd=zc;function gb(e,g){var I=e.type.contextTypes;if(!I)return zc;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 DC(e){return e=e.childContextTypes,e!=null}function qW(){ZI(xC),ZI(Kn)}function x6(e,g,I){if(Kn.current!==zc)throw Error(st(168));oI(Kn,g),oI(xC,I)}function Qde(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(st(108,lYe(e)||"Unknown",n));return zI({},I,i)}function eX(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||zc,zd=Kn.current,oI(Kn,e),oI(xC,xC.current),!0}function D6(e,g,I){var i=e.stateNode;if(!i)throw Error(st(169));I?(e=Qde(e,g,zd),i.__reactInternalMemoizedMergedChildContext=e,ZI(xC),ZI(Kn),oI(Kn,e)):ZI(xC),oI(xC,I)}var ts=null,eT=!1,AK=!1;function jde(e){ts===null?ts=[e]:ts.push(e)}function RKe(e){eT=!0,jde(e)}function eu(){if(!AK&&ts!==null){AK=!0;var e=0,g=Jg;try{var I=ts;for(Jg=1;e>=r,n-=r,ls=1<<32-ea(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),WI&&Mu(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),WI&&Mu(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 WI&&Mu(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)}),WI&&Mu(f,v),Z}function m(f,b,p,y){if(typeof p=="object"&&p!==null&&p.type===Jf&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case jw:e:{for(var Z=p.key,B=b;B!==null;){if(B.key===Z){if(Z=p.type,Z===Jf){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===El&&O6(Z)===B.type){I(f,B.sibling),b=n(B,p.props),b.ref=Sy(f,B,p),b.return=f,f=b;break e}I(f,B);break}else g(f,B);B=B.sibling}p.type===Jf?(b=Sd(p.props.children,f.mode,y,p.key),b.return=f,f=b):(y=v1(p.type,p.key,p.props,null,f.mode,y),y.ref=Sy(f,b,p),y.return=f,f=y)}return r(f);case Pf: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=fK(p,f.mode,y),b.return=f,f=b}return r(f);case El:return B=p._init,m(f,b,B(p._payload),y)}if(HZ(p))return d(f,b,p,y);if(yy(p))return h(f,b,p,y);oV(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=mK(p,f.mode,y),b.return=f,f=b),r(f)):I(f,b)}return m}var ib=nhe(!0),Che=nhe(!1),GS={},aA=qc(GS),Qv=qc(GS),jv=qc(GS);function od(e){if(e===GS)throw Error(st(174));return e}function pL(e,g){switch(oI(jv,g),oI(Qv,e),oI(aA,GS),e=g.nodeType,e){case 9:case 11:g=(g=g.documentElement)?g.namespaceURI:cE(null,"");break;default:e=e===8?g.parentNode:g,g=e.namespaceURI||null,e=e.tagName,g=cE(g,e)}ZI(aA),oI(aA,g)}function nb(){ZI(aA),ZI(Qv),ZI(jv)}function rhe(e){od(jv.current);var g=od(aA.current),I=cE(g,e.type);g!==I&&(oI(Qv,e),oI(aA,I))}function bL(e){Qv.current===e&&(ZI(aA),ZI(Qv))}var KI=qc(0);function CX(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 sK=[];function yL(){for(var e=0;eI?I:4,e(!0);var i=lK.transition;lK.transition={};try{e(!1),g()}finally{Jg=I,lK.transition=i}}function Ghe(){return Io().memoizedState}function TKe(e,g,I){var i=Vc(e);if(I={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null},vhe(e))Bhe(g,I);else if(I=the(e,g,I,i),I!==null){var n=oC();ta(I,e,i,n),She(I,g,i)}}function NKe(e,g,I){var i=Vc(e),n={lane:i,action:I,hasEagerState:!1,eagerState:null,next:null};if(vhe(e))Bhe(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,aa(o,r)){var a=g.interleaved;a===null?(n.next=n,mL(g)):(n.next=a.next,a.next=n),g.interleaved=n;return}}catch{}finally{}I=the(e,g,n,i),I!==null&&(n=oC(),ta(I,e,i,n),She(I,g,i))}}function vhe(e){var g=e.alternate;return e===EI||g!==null&&g===EI}function Bhe(e,g){WG=rX=!0;var I=e.pending;I===null?g.next=g:(g.next=I.next,I.next=g),e.pending=g}function She(e,g,I){if(I&4194240){var i=g.lanes;i&=e.pendingLanes,I|=i,g.lanes=I,IL(e,I)}}var oX={readContext:go,useCallback:Zn,useContext:Zn,useEffect:Zn,useImperativeHandle:Zn,useInsertionEffect:Zn,useLayoutEffect:Zn,useMemo:Zn,useReducer:Zn,useRef:Zn,useState:Zn,useDebugValue:Zn,useDeferredValue:Zn,useTransition:Zn,useMutableSource:Zn,useSyncExternalStore:Zn,useId:Zn,unstable_isNewReconciler:!1},kKe={readContext:go,useCallback:function(e,g){return ka().memoizedState=[e,g===void 0?null:g],e},useContext:go,useEffect:L6,useImperativeHandle:function(e,g,I){return I=I!=null?I.concat([e]):null,b1(4194308,4,fhe.bind(null,g,e),I)},useLayoutEffect:function(e,g){return b1(4194308,4,e,g)},useInsertionEffect:function(e,g){return b1(4,2,e,g)},useMemo:function(e,g){var I=ka();return g=g===void 0?null:g,e=e(),I.memoizedState=[e,g],e},useReducer:function(e,g,I){var i=ka();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=TKe.bind(null,EI,e),[i.memoizedState,e]},useRef:function(e){var g=ka();return e={current:e},g.memoizedState=e},useState:_6,useDebugValue:SL,useDeferredValue:function(e){return ka().memoizedState=e},useTransition:function(){var e=_6(!1),g=e[0];return e=HKe.bind(null,e[1]),ka().memoizedState=e,[g,e]},useMutableSource:function(){},useSyncExternalStore:function(e,g,I){var i=EI,n=ka();if(WI){if(I===void 0)throw Error(st(407));I=I()}else{if(I=g(),Qi===null)throw Error(st(349));Jd&30||Ahe(i,g,I)}n.memoizedState=I;var C={value:I,getSnapshot:g};return n.queue=C,L6(lhe.bind(null,i,C,e),[e]),i.flags|=2048,eB(9,she.bind(null,i,C,I,g),void 0,null),I},useId:function(){var e=ka(),g=Qi.identifierPrefix;if(WI){var I=cs,i=ls;I=(i&~(1<<32-ea(i)-1)).toString(32)+I,g=":"+g+"R"+I,I=$v++,0<\/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[Ea]=g,e[Uv]=i,khe(e,g,!1,!1),g.stateNode=e;e:{switch(r=dE(I,i),I){case"dialog":uI("cancel",e),uI("close",e),n=i;break;case"iframe":case"object":case"embed":uI("load",e),n=i;break;case"video":case"audio":for(n=0;nrb&&(g.flags|=128,i=!0,wy(C,!1),g.lanes=4194304)}else{if(!i)if(e=CX(r),e!==null){if(g.flags|=128,i=!0,I=e.updateQueue,I!==null&&(g.updateQueue=I,g.flags|=4),wy(C,!0),C.tail===null&&C.tailMode==="hidden"&&!r.alternate&&!WI)return Gn(g),null}else 2*Ai()-C.renderingStartTime>rb&&I!==1073741824&&(g.flags|=128,i=!0,wy(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=Ai(),g.sibling=null,I=KI.current,oI(KI,i?I&1|2:I&1),g):(Gn(g),null);case 22:case 23:return HL(),i=g.memoizedState!==null,e!==null&&e.memoizedState!==null!==i&&(g.flags|=8192),i&&g.mode&1?qC&1073741824&&(Gn(g),g.subtreeFlags&6&&(g.flags|=8192)):Gn(g),null;case 24:return null;case 25:return null}throw Error(st(156,g.tag))}function zKe(e,g){switch(lL(g),g.tag){case 1:return DC(g.type)&&qW(),e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 3:return nb(),ZI(xC),ZI(Kn),yL(),e=g.flags,e&65536&&!(e&128)?(g.flags=e&-65537|128,g):null;case 5:return bL(g),null;case 13:if(ZI(KI),e=g.memoizedState,e!==null&&e.dehydrated!==null){if(g.alternate===null)throw Error(st(340));Ib()}return e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 19:return ZI(KI),null;case 4:return nb(),null;case 10:return hL(g.type._context),null;case 22:case 23:return HL(),null;case 24:return null;default:return null}}var AV=!1,kn=!1,PKe=typeof WeakSet=="function"?WeakSet:Set,wt=null;function ep(e,g){var I=e.ref;if(I!==null)if(typeof I=="function")try{I(null)}catch(i){UI(e,g,i)}else I.current=null}function ME(e,g,I){try{I()}catch(i){UI(e,g,i)}}var Iq=!1;function JKe(e,g){if(BE=UW,e=Ede(),AL(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(SE={focusedElem:e,selectionRange:I},UW=!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:Do(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(st(163))}}catch(y){UI(g,g.return,y)}if(e=g.sibling,e!==null){e.return=g.return,wt=e;break}wt=g.return}return d=Iq,Iq=!1,d}function XG(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&&ME(g,I,C)}n=n.next}while(n!==i)}}function IT(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 zE(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 xhe(e){var g=e.alternate;g!==null&&(e.alternate=null,xhe(g)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(g=e.stateNode,g!==null&&(delete g[Ea],delete g[Uv],delete g[RE],delete g[wKe],delete g[VKe])),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 Dhe(e){return e.tag===5||e.tag===3||e.tag===4}function iq(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||Dhe(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 PE(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=$W));else if(i!==4&&(e=e.child,e!==null))for(PE(e,g,I),e=e.sibling;e!==null;)PE(e,g,I),e=e.sibling}function JE(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(JE(e,g,I),e=e.sibling;e!==null;)JE(e,g,I),e=e.sibling}var on=null,Eo=!1;function dl(e,g,I){for(I=I.child;I!==null;)Fhe(e,g,I),I=I.sibling}function Fhe(e,g,I){if(oA&&typeof oA.onCommitFiberUnmount=="function")try{oA.onCommitFiberUnmount(UH,I)}catch{}switch(I.tag){case 5:kn||ep(I,g);case 6:var i=on,n=Eo;on=null,dl(e,g,I),on=i,Eo=n,on!==null&&(Eo?(e=on,I=I.stateNode,e.nodeType===8?e.parentNode.removeChild(I):e.removeChild(I)):on.removeChild(I.stateNode));break;case 18:on!==null&&(Eo?(e=on,I=I.stateNode,e.nodeType===8?aK(e.parentNode,I):e.nodeType===1&&aK(e,I),Pv(e)):aK(on,I.stateNode));break;case 4:i=on,n=Eo,on=I.stateNode.containerInfo,Eo=!0,dl(e,g,I),on=i,Eo=n;break;case 0:case 11:case 14:case 15:if(!kn&&(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)&&ME(I,g,r),n=n.next}while(n!==i)}dl(e,g,I);break;case 1:if(!kn&&(ep(I,g),i=I.stateNode,typeof i.componentWillUnmount=="function"))try{i.props=I.memoizedProps,i.state=I.memoizedState,i.componentWillUnmount()}catch(o){UI(I,g,o)}dl(e,g,I);break;case 21:dl(e,g,I);break;case 22:I.mode&1?(kn=(i=kn)||I.memoizedState!==null,dl(e,g,I),kn=i):dl(e,g,I);break;default:dl(e,g,I)}}function nq(e){var g=e.updateQueue;if(g!==null){e.updateQueue=null;var I=e.stateNode;I===null&&(I=e.stateNode=new PKe),g.forEach(function(i){var n=e5e.bind(null,e,i);I.has(i)||(I.add(i),i.then(n,n))})}}function ho(e,g){var I=g.deletions;if(I!==null)for(var i=0;in&&(n=r),i&=~C}if(i=n,i=Ai()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*_Ke(i/1960))-i,10e?16:e,ac===null)var i=!1;else{if(e=ac,ac=null,sX=0,Tg&6)throw Error(st(331));var n=Tg;for(Tg|=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;aAi()-WL?Bd(e,0):RL|=I),FC(e,g)}function Lhe(e,g){g===0&&(e.mode&1?(g=tV,tV<<=1,!(tV&130023424)&&(tV=4194304)):g=1);var I=oC();e=Ns(e,g),e!==null&&(bS(e,g,I),FC(e,I))}function qKe(e){var g=e.memoizedState,I=0;g!==null&&(I=g.retryLane),Lhe(e,I)}function e5e(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(st(314))}i!==null&&i.delete(g),Lhe(e,I)}var Uhe;Uhe=function(e,g,I){if(e!==null)if(e.memoizedProps!==g.pendingProps||xC.current)kC=!0;else{if(!(e.lanes&I)&&!(g.flags&128))return kC=!1,EKe(e,g,I);kC=!!(e.flags&131072)}else kC=!1,WI&&g.flags&1048576&&$de(g,gX,g.index);switch(g.lanes=0,g.tag){case 2:var i=g.type;y1(e,g),e=g.pendingProps;var n=gb(g,Kn.current);bp(g,I),n=GL(null,g,i,e,n,I);var C=vL();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,DC(i)?(C=!0,eX(g)):C=!1,g.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,fL(g),n.updater=tT,g.stateNode=n,n._reactInternals=g,kE(g,i,e,I),g=xE(null,g,i,!0,C,I)):(g.tag=0,WI&&C&&sL(g),Un(null,g,n,I),g=g.child),g;case 16:i=g.elementType;e:{switch(y1(e,g),e=g.pendingProps,n=i._init,i=n(i._payload),g.type=i,n=g.tag=g5e(i),e=Do(i,e),n){case 0:g=KE(null,g,i,e,I);break e;case 1:g=eq(null,g,i,e,I);break e;case 11:g=$6(null,g,i,e,I);break e;case 14:g=q6(null,g,i,Do(i.type,e),I);break e}throw Error(st(306,i,""))}return g;case 0:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:Do(i,n),KE(e,g,i,n,I);case 1:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:Do(i,n),eq(e,g,i,n,I);case 3:e:{if(Hhe(g),e===null)throw Error(st(387));i=g.pendingProps,C=g.memoizedState,n=C.element,ghe(e,g),nX(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=Cb(Error(st(423)),g),g=tq(e,g,i,I,n);break e}else if(i!==n){n=Cb(Error(st(424)),g),g=tq(e,g,i,I,n);break e}else for(sr=Bc(g.stateNode.containerInfo.firstChild),ur=g,WI=!0,zo=null,I=Che(g,null,i,I),g.child=I;I;)I.flags=I.flags&-3|4096,I=I.sibling;else{if(Ib(),i===n){g=ks(e,g,I);break e}Un(e,g,i,I)}g=g.child}return g;case 5:return rhe(g),e===null&&HE(g),i=g.type,n=g.pendingProps,C=e!==null?e.memoizedProps:null,r=n.children,wE(i,n)?r=null:C!==null&&wE(i,C)&&(g.flags|=32),Xhe(e,g),Un(e,g,r,I),g.child;case 6:return e===null&&HE(g),null;case 13:return The(e,g,I);case 4:return pL(g,g.stateNode.containerInfo),i=g.pendingProps,e===null?g.child=ib(g,null,i,I):Un(e,g,i,I),g.child;case 11:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:Do(i,n),$6(e,g,i,n,I);case 7:return Un(e,g,g.pendingProps,I),g.child;case 8:return Un(e,g,g.pendingProps.children,I),g.child;case 12:return Un(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,oI(IX,i._currentValue),i._currentValue=r,C!==null)if(aa(C.value,r)){if(C.children===n.children&&!xC.current){g=ks(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=Ss(-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),TE(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(st(341));r.lanes|=I,o=r.alternate,o!==null&&(o.lanes|=I),TE(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}Un(e,g,n.children,I),g=g.child}return g;case 9:return n=g.type,i=g.pendingProps.children,bp(g,I),n=go(n),i=i(n),g.flags|=1,Un(e,g,i,I),g.child;case 14:return i=g.type,n=Do(i,g.pendingProps),n=Do(i.type,n),q6(e,g,i,n,I);case 15:return Rhe(e,g,g.type,g.pendingProps,I);case 17:return i=g.type,n=g.pendingProps,n=g.elementType===i?n:Do(i,n),y1(e,g),g.tag=1,DC(i)?(e=!0,eX(g)):e=!1,bp(g,I),ihe(g,i,n),kE(g,i,n,I),xE(null,g,i,!0,e,I);case 19:return Nhe(e,g,I);case 22:return Whe(e,g,I)}throw Error(st(156,g.tag))};function Qhe(e,g){return Zde(e,g)}function t5e(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 Jr(e,g,I,i){return new t5e(e,g,I,i)}function NL(e){return e=e.prototype,!(!e||!e.isReactComponent)}function g5e(e){if(typeof e=="function")return NL(e)?1:0;if(e!=null){if(e=e.$$typeof,e===q_)return 11;if(e===eL)return 14}return 2}function Rc(e,g){var I=e.alternate;return I===null?(I=Jr(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 v1(e,g,I,i,n,C){var r=2;if(i=e,typeof e=="function")NL(e)&&(r=1);else if(typeof e=="string")r=5;else e:switch(e){case Jf:return Sd(I.children,n,C,g);case $_:r=8,n|=8;break;case nE:return e=Jr(12,I,g,n|2),e.elementType=nE,e.lanes=C,e;case CE:return e=Jr(13,I,g,n),e.elementType=CE,e.lanes=C,e;case rE:return e=Jr(19,I,g,n),e.elementType=rE,e.lanes=C,e;case nde:return nT(I,n,C,g);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Ide:r=10;break e;case ide:r=9;break e;case q_:r=11;break e;case eL:r=14;break e;case El:r=16,i=null;break e}throw Error(st(130,e==null?e:typeof e,""))}return g=Jr(r,I,g,n),g.elementType=e,g.type=i,g.lanes=C,g}function Sd(e,g,I,i){return e=Jr(7,e,i,g),e.lanes=I,e}function nT(e,g,I,i){return e=Jr(22,e,i,g),e.elementType=nde,e.lanes=I,e.stateNode={isHidden:!1},e}function mK(e,g,I){return e=Jr(6,e,null,g),e.lanes=I,e}function fK(e,g,I){return g=Jr(4,e.children!==null?e.children:[],e.key,g),g.lanes=I,g.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},g}function I5e(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=$Y(0),this.expirationTimes=$Y(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=$Y(0),this.identifierPrefix=i,this.onRecoverableError=n,this.mutableSourceEagerHydrationData=null}function kL(e,g,I,i,n,C,r,o,a){return e=new I5e(e,g,I,o,a),g===1?(g=1,C===!0&&(g|=8)):g=0,C=Jr(3,null,null,g),e.current=C,C.stateNode=e,C.memoizedState={element:i,isDehydrated:I,cache:null,transitions:null,pendingSuspenseBoundaries:null},fL(C),e}function i5e(e,g,I){var i=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(eme)}catch(e){console.error(e)}}eme(),$ue.exports=br;var Aa=$ue.exports;const jI=jc(Aa);var cq=Aa;IE.createRoot=cq.createRoot,IE.hydrateRoot=cq.hydrateRoot;const a5e="modulepreload",A5e=function(e){return"/alt-gosling/"+e},uq={},s5e=function(g,I,i){if(!I||I.length===0)return g();const n=document.getElementsByTagName("link");return Promise.all(I.map(C=>{if(C=A5e(C),C in uq)return;uq[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":a5e,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 l5e(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 c5e(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 window.document>"u"||typeof window.document.createElement>"u"),aE=Object.prototype.hasOwnProperty,uYe=/^[: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]*$/,u6={},d6={};function dYe(e){return aE.call(d6,e)?!0:aE.call(u6,e)?!1:uYe.test(e)?d6[e]=!0:(u6[e]=!0,!1)}function hYe(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 mYe(e,g,i,I){if(g===null||typeof g>"u"||hYe(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 dr(e,g,i,I,n,r,C){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=r,this.removeEmptyString=C}var hn={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){hn[e]=new dr(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var g=e[0];hn[g]=new dr(g,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){hn[e]=new dr(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){hn[e]=new dr(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){hn[e]=new dr(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){hn[e]=new dr(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){hn[e]=new dr(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){hn[e]=new dr(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){hn[e]=new dr(e,5,!1,e.toLowerCase(),null,!1,!1)});var tL=/[\-:]([a-z])/g;function gL(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(tL,gL);hn[g]=new dr(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(tL,gL);hn[g]=new dr(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(tL,gL);hn[g]=new dr(g,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){hn[e]=new dr(e,1,!1,e.toLowerCase(),null,!1,!1)});hn.xlinkHref=new dr("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){hn[e]=new dr(e,1,!1,e.toLowerCase(),null,!0,!0)});function iL(e,g,i,I){var n=hn.hasOwnProperty(g)?hn[g]:null;(n!==null?n.type!==0:I||!(2o||n[C]!==r[o]){var a=` +`+n[C].replace(" at new "," at ");return e.displayName&&a.includes("")&&(a=a.replace("",e.displayName)),a}while(1<=C&&0<=o);break}}}finally{$Y=!1,Error.prepareStackTrace=i}return(e=e?e.displayName||e.name:"")?HZ(e):""}function fYe(e){switch(e.tag){case 5:return HZ(e.type);case 16:return HZ("Lazy");case 13:return HZ("Suspense");case 19:return HZ("SuspenseList");case 0:case 2:case 15:return e=qY(e.type,!1),e;case 11:return e=qY(e.type.render,!1),e;case 1:return e=qY(e.type,!0),e;default:return""}}function cE(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 Pf:return"Fragment";case zf:return"Portal";case AE:return"Profiler";case IL:return"StrictMode";case sE:return"Suspense";case lE:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case lde:return(e.displayName||"Context")+".Consumer";case sde:return(e._context.displayName||"Context")+".Provider";case nL:var g=e.render;return e=e.displayName,e||(e=g.displayName||g.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case rL:return g=e.displayName||null,g!==null?g:cE(e.type)||"Memo";case El:g=e._payload,e=e._init;try{return cE(e(g))}catch{}}return null}function pYe(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 cE(g);case 8:return g===IL?"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 Ec(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function ude(e){var g=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(g==="checkbox"||g==="radio")}function bYe(e){var g=ude(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,r=i.set;return Object.defineProperty(e,g,{configurable:!0,get:function(){return n.call(this)},set:function(C){I=""+C,r.call(this,C)}}),Object.defineProperty(e,g,{enumerable:i.enumerable}),{getValue:function(){return I},setValue:function(C){I=""+C},stopTracking:function(){e._valueTracker=null,delete e[g]}}}}function tR(e){e._valueTracker||(e._valueTracker=bYe(e))}function dde(e){if(!e)return!1;var g=e._valueTracker;if(!g)return!0;var i=g.getValue(),I="";return e&&(I=ude(e)?e.checked?"true":"false":e.value),e=I,e!==i?(g.setValue(e),!0):!1}function _W(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 uE(e,g){var i=g.checked;return zi({},g,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:i??e._wrapperState.initialChecked})}function m6(e,g){var i=g.defaultValue==null?"":g.defaultValue,I=g.checked!=null?g.checked:g.defaultChecked;i=Ec(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 hde(e,g){g=g.checked,g!=null&&iL(e,"checked",g,!1)}function dE(e,g){hde(e,g);var i=Ec(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")?hE(e,g.type,i):g.hasOwnProperty("defaultValue")&&hE(e,g.type,Ec(g.defaultValue)),g.checked==null&&g.defaultChecked!=null&&(e.defaultChecked=!!g.defaultChecked)}function f6(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 hE(e,g,i){(g!=="number"||_W(e.ownerDocument)!==e)&&(i==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+i&&(e.defaultValue=""+i))}var TZ=Array.isArray;function mp(e,g,i,I){if(e=e.options,g){g={};for(var n=0;n"+g.valueOf().toString()+"",g=gR.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;g.firstChild;)e.appendChild(g.firstChild)}});function zv(e,g){if(g){var i=e.firstChild;if(i&&i===e.lastChild&&i.nodeType===3){i.nodeValue=g;return}}e.textContent=g}var BG={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},yYe=["Webkit","ms","Moz","O"];Object.keys(BG).forEach(function(e){yYe.forEach(function(g){g=g+e.charAt(0).toUpperCase()+e.substring(1),BG[g]=BG[e]})});function bde(e,g,i){return g==null||typeof g=="boolean"||g===""?"":i||typeof g!="number"||g===0||BG.hasOwnProperty(e)&&BG[e]?(""+g).trim():g+"px"}function yde(e,g){e=e.style;for(var i in g)if(g.hasOwnProperty(i)){var I=i.indexOf("--")===0,n=bde(i,g[i],I);i==="float"&&(i="cssFloat"),I?e.setProperty(i,n):e[i]=n}}var ZYe=zi({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 pE(e,g){if(g){if(ZYe[e]&&(g.children!=null||g.dangerouslySetInnerHTML!=null))throw Error(st(137,e));if(g.dangerouslySetInnerHTML!=null){if(g.children!=null)throw Error(st(60));if(typeof g.dangerouslySetInnerHTML!="object"||!("__html"in g.dangerouslySetInnerHTML))throw Error(st(61))}if(g.style!=null&&typeof g.style!="object")throw Error(st(62))}}function bE(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 yE=null;function CL(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var ZE=null,fp=null,pp=null;function y6(e){if(e=BS(e)){if(typeof ZE!="function")throw Error(st(280));var g=e.stateNode;g&&(g=gT(g),ZE(e.stateNode,e.type,g))}}function Zde(e){fp?pp?pp.push(e):pp=[e]:fp=e}function Gde(){if(fp){var e=fp,g=pp;if(pp=fp=null,y6(e),g)for(e=0;e>>=0,e===0?32:31-(TYe(e)/NYe|0)|0}var iR=64,IR=4194304;function NZ(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 jW(e,g){var i=e.pendingLanes;if(i===0)return 0;var I=0,n=e.suspendedLanes,r=e.pingedLanes,C=i&268435455;if(C!==0){var o=C&~n;o!==0?I=NZ(o):(r&=C,r!==0&&(I=NZ(r)))}else C=i&~n,C!==0?I=NZ(C):r!==0&&(I=NZ(r));if(I===0)return 0;if(g!==0&&g!==I&&!(g&n)&&(n=I&-I,r=g&-g,n>=r||n===16&&(r&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-ea(g),e[g]=i}function FYe(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=wG),W6=String.fromCharCode(32),X6=!1;function zde(e,g){switch(e){case"keyup":return lKe.indexOf(g.keyCode)!==-1;case"keydown":return g.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function Pde(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Jf=!1;function uKe(e,g){switch(e){case"compositionend":return Pde(g);case"keypress":return g.which!==32?null:(X6=!0,W6);case"textInput":return e=g.data,e===W6&&X6?null:e;default:return null}}function dKe(e,g){if(Jf)return e==="compositionend"||!dL&&zde(e,g)?(e=Ede(),p1=lL=oc=null,Jf=!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=k6(i)}}function Lde(e,g){return e&&g?e===g?!0:e&&e.nodeType===3?!1:g&&g.nodeType===3?Lde(e,g.parentNode):"contains"in e?e.contains(g):e.compareDocumentPosition?!!(e.compareDocumentPosition(g)&16):!1:!1}function Ude(){for(var e=window,g=_W();g instanceof e.HTMLIFrameElement;){try{var i=typeof g.contentWindow.location.href=="string"}catch{i=!1}if(i)e=g.contentWindow;else break;g=_W(e.document)}return g}function hL(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 vKe(e){var g=Ude(),i=e.focusedElem,I=e.selectionRange;if(g!==i&&i&&i.ownerDocument&&Lde(i.ownerDocument.documentElement,i)){if(I!==null&&hL(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,r=Math.min(I.start,n);I=I.end===void 0?r:Math.min(I.end,n),!e.extend&&r>I&&(n=I,I=r,r=n),n=Y6(i,r);var C=Y6(i,I);n&&C&&(e.rangeCount!==1||e.anchorNode!==n.node||e.anchorOffset!==n.offset||e.focusNode!==C.node||e.focusOffset!==C.offset)&&(g=g.createRange(),g.setStart(n.node,n.offset),e.removeAllRanges(),r>I?(e.addRange(g),e.extend(C.node,C.offset)):(g.setEnd(C.node,C.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,Of=null,RE=null,VG=null,VE=!1;function K6(e,g,i){var I=i.window===i?i.document:i.nodeType===9?i:i.ownerDocument;VE||Of==null||Of!==_W(I)||(I=Of,"selectionStart"in I&&hL(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}),VG&&Uv(VG,I)||(VG=I,I=e9(RE,"onSelect"),0Uf||(e.current=kE[Uf],kE[Uf]=null,Uf--)}function oi(e,g){Uf++,kE[Uf]=e.current,e.current=g}var Mc={},Kn=$c(Mc),Kr=$c(!1),Md=Mc;function ib(e,g){var i=e.type.contextTypes;if(!i)return Mc;var I=e.stateNode;if(I&&I.__reactInternalMemoizedUnmaskedChildContext===g)return I.__reactInternalMemoizedMaskedChildContext;var n={},r;for(r in i)n[r]=g[r];return I&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=g,e.__reactInternalMemoizedMaskedChildContext=n),n}function Fr(e){return e=e.childContextTypes,e!=null}function g9(){Zi(Kr),Zi(Kn)}function P6(e,g,i){if(Kn.current!==Mc)throw Error(st(168));oi(Kn,g),oi(Kr,i)}function Ihe(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(st(108,pYe(e)||"Unknown",n));return zi({},i,I)}function i9(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Mc,Md=Kn.current,oi(Kn,e),oi(Kr,Kr.current),!0}function J6(e,g,i){var I=e.stateNode;if(!I)throw Error(st(169));i?(e=Ihe(e,g,Md),I.__reactInternalMemoizedMergedChildContext=e,Zi(Kr),Zi(Kn),oi(Kn,e)):Zi(Kr),oi(Kr,i)}var ts=null,iT=!1,cK=!1;function nhe(e){ts===null?ts=[e]:ts.push(e)}function YKe(e){iT=!0,nhe(e)}function qc(){if(!cK&&ts!==null){cK=!0;var e=0,g=Jg;try{var i=ts;for(Jg=1;e>=C,n-=C,ls=1<<32-ea(g)+n|i<v?(w=G,G=null):w=G.sibling;var R=c(f,G,p[v],y);if(R===null){G===null&&(G=w);break}e&&G&&R.alternate===null&&g(f,G),b=r(R,b,v),B===null?Z=R:B.sibling=R,B=R,G=w}if(v===p.length)return i(f,G),Wi&&Eu(f,v),Z;if(G===null){for(;vv?(w=G,G=null):w=G.sibling;var S=c(f,G,R.value,y);if(S===null){G===null&&(G=w);break}e&&G&&S.alternate===null&&g(f,G),b=r(S,b,v),B===null?Z=S:B.sibling=S,B=S,G=w}if(R.done)return i(f,G),Wi&&Eu(f,v),Z;if(G===null){for(;!R.done;v++,R=p.next())R=l(f,R.value,y),R!==null&&(b=r(R,b,v),B===null?Z=R:B.sibling=R,B=R);return Wi&&Eu(f,v),Z}for(G=I(f,G);!R.done;v++,R=p.next())R=u(G,f,v,R.value,y),R!==null&&(e&&R.alternate!==null&&G.delete(R.key===null?v:R.key),b=r(R,b,v),B===null?Z=R:B.sibling=R,B=R);return e&&G.forEach(function(X){return g(f,X)}),Wi&&Eu(f,v),Z}function m(f,b,p,y){if(typeof p=="object"&&p!==null&&p.type===Pf&&p.key===null&&(p=p.props.children),typeof p=="object"&&p!==null){switch(p.$$typeof){case eR:e:{for(var Z=p.key,B=b;B!==null;){if(B.key===Z){if(Z=p.type,Z===Pf){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===El&&$6(Z)===B.type){i(f,B.sibling),b=n(B,p.props),b.ref=wy(f,B,p),b.return=f,f=b;break e}i(f,B);break}else g(f,B);B=B.sibling}p.type===Pf?(b=Bd(p.props.children,f.mode,y,p.key),b.return=f,f=b):(y=w1(p.type,p.key,p.props,null,f.mode,y),y.ref=wy(f,b,p),y.return=f,f=y)}return C(f);case zf: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=yK(p,f.mode,y),b.return=f,f=b}return C(f);case El:return B=p._init,m(f,b,B(p._payload),y)}if(TZ(p))return d(f,b,p,y);if(Zy(p))return h(f,b,p,y);sR(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=bK(p,f.mode,y),b.return=f,f=b),C(f)):i(f,b)}return m}var nb=che(!0),uhe=che(!1),SS={},aA=$c(SS),qv=$c(SS),eB=$c(SS);function Cd(e){if(e===SS)throw Error(st(174));return e}function BL(e,g){switch(oi(eB,g),oi(qv,e),oi(aA,SS),e=g.nodeType,e){case 9:case 11:g=(g=g.documentElement)?g.namespaceURI:fE(null,"");break;default:e=e===8?g.parentNode:g,g=e.namespaceURI||null,e=e.tagName,g=fE(g,e)}Zi(aA),oi(aA,g)}function rb(){Zi(aA),Zi(qv),Zi(eB)}function dhe(e){Cd(eB.current);var g=Cd(aA.current),i=fE(g,e.type);g!==i&&(oi(qv,e),oi(aA,i))}function SL(e){qv.current===e&&(Zi(aA),Zi(qv))}var Ki=$c(0);function a9(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 uK=[];function wL(){for(var e=0;ei?i:4,e(!0);var I=dK.transition;dK.transition={};try{e(!1),g()}finally{Jg=i,dK.transition=I}}function Xhe(){return io().memoizedState}function xKe(e,g,i){var I=Rc(e);if(i={lane:I,action:i,hasEagerState:!1,eagerState:null,next:null},Hhe(e))The(g,i);else if(i=ahe(e,g,i,I),i!==null){var n=Cr();ta(i,e,I,n),Nhe(i,g,I)}}function EKe(e,g,i){var I=Rc(e),n={lane:I,action:i,hasEagerState:!1,eagerState:null,next:null};if(Hhe(e))The(g,n);else{var r=e.alternate;if(e.lanes===0&&(r===null||r.lanes===0)&&(r=g.lastRenderedReducer,r!==null))try{var C=g.lastRenderedState,o=r(C,i);if(n.hasEagerState=!0,n.eagerState=o,aa(o,C)){var a=g.interleaved;a===null?(n.next=n,GL(g)):(n.next=a.next,a.next=n),g.interleaved=n;return}}catch{}finally{}i=ahe(e,g,n,I),i!==null&&(n=Cr(),ta(i,e,I,n),Nhe(i,g,I))}}function Hhe(e){var g=e.alternate;return e===Ei||g!==null&&g===Ei}function The(e,g){WG=A9=!0;var i=e.pending;i===null?g.next=g:(g.next=i.next,i.next=g),e.pending=g}function Nhe(e,g,i){if(i&4194240){var I=g.lanes;I&=e.pendingLanes,i|=I,g.lanes=i,aL(e,i)}}var s9={readContext:go,useCallback:Zn,useContext:Zn,useEffect:Zn,useImperativeHandle:Zn,useInsertionEffect:Zn,useLayoutEffect:Zn,useMemo:Zn,useReducer:Zn,useRef:Zn,useState:Zn,useDebugValue:Zn,useDeferredValue:Zn,useTransition:Zn,useMutableSource:Zn,useSyncExternalStore:Zn,useId:Zn,unstable_isNewReconciler:!1},MKe={readContext:go,useCallback:function(e,g){return ka().memoizedState=[e,g===void 0?null:g],e},useContext:go,useEffect:eq,useImperativeHandle:function(e,g,i){return i=i!=null?i.concat([e]):null,G1(4194308,4,She.bind(null,g,e),i)},useLayoutEffect:function(e,g){return G1(4194308,4,e,g)},useInsertionEffect:function(e,g){return G1(4,2,e,g)},useMemo:function(e,g){var i=ka();return g=g===void 0?null:g,e=e(),i.memoizedState=[e,g],e},useReducer:function(e,g,i){var I=ka();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=xKe.bind(null,Ei,e),[I.memoizedState,e]},useRef:function(e){var g=ka();return e={current:e},g.memoizedState=e},useState:q6,useDebugValue:HL,useDeferredValue:function(e){return ka().memoizedState=e},useTransition:function(){var e=q6(!1),g=e[0];return e=DKe.bind(null,e[1]),ka().memoizedState=e,[g,e]},useMutableSource:function(){},useSyncExternalStore:function(e,g,i){var I=Ei,n=ka();if(Wi){if(i===void 0)throw Error(st(407));i=i()}else{if(i=g(),QI===null)throw Error(st(349));Pd&30||fhe(I,g,i)}n.memoizedState=i;var r={value:i,getSnapshot:g};return n.queue=r,eq(bhe.bind(null,I,r,e),[e]),I.flags|=2048,iB(9,phe.bind(null,I,r,i,g),void 0,null),i},useId:function(){var e=ka(),g=QI.identifierPrefix;if(Wi){var i=cs,I=ls;i=(I&~(1<<32-ea(I)-1)).toString(32)+i,g=":"+g+"R"+i,i=tB++,0<\/script>",e=e.removeChild(e.firstChild)):typeof I.is=="string"?e=C.createElement(i,{is:I.is}):(e=C.createElement(i),i==="select"&&(C=e,I.multiple?C.multiple=!0:I.size&&(C.size=I.size))):e=C.createElementNS(e,i),e[Ea]=g,e[$v]=I,zhe(e,g,!1,!1),g.stateNode=e;e:{switch(C=bE(i,I),i){case"dialog":ui("cancel",e),ui("close",e),n=I;break;case"iframe":case"object":case"embed":ui("load",e),n=I;break;case"video":case"audio":for(n=0;nob&&(g.flags|=128,I=!0,Ry(r,!1),g.lanes=4194304)}else{if(!I)if(e=a9(C),e!==null){if(g.flags|=128,I=!0,i=e.updateQueue,i!==null&&(g.updateQueue=i,g.flags|=4),Ry(r,!0),r.tail===null&&r.tailMode==="hidden"&&!C.alternate&&!Wi)return Gn(g),null}else 2*AI()-r.renderingStartTime>ob&&i!==1073741824&&(g.flags|=128,I=!0,Ry(r,!1),g.lanes=4194304);r.isBackwards?(C.sibling=g.child,g.child=C):(i=r.last,i!==null?i.sibling=C:g.child=C,r.last=C)}return r.tail!==null?(g=r.tail,r.rendering=g,r.tail=g.sibling,r.renderingStartTime=AI(),g.sibling=null,i=Ki.current,oi(Ki,I?i&1|2:i&1),g):(Gn(g),null);case 22:case 23:return FL(),I=g.memoizedState!==null,e!==null&&e.memoizedState!==null!==I&&(g.flags|=8192),I&&g.mode&1?$r&1073741824&&(Gn(g),g.subtreeFlags&6&&(g.flags|=8192)):Gn(g),null;case 24:return null;case 25:return null}throw Error(st(156,g.tag))}function QKe(e,g){switch(fL(g),g.tag){case 1:return Fr(g.type)&&g9(),e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 3:return rb(),Zi(Kr),Zi(Kn),wL(),e=g.flags,e&65536&&!(e&128)?(g.flags=e&-65537|128,g):null;case 5:return SL(g),null;case 13:if(Zi(Ki),e=g.memoizedState,e!==null&&e.dehydrated!==null){if(g.alternate===null)throw Error(st(340));Ib()}return e=g.flags,e&65536?(g.flags=e&-65537|128,g):null;case 19:return Zi(Ki),null;case 4:return rb(),null;case 10:return ZL(g.type._context),null;case 22:case 23:return FL(),null;case 24:return null;default:return null}}var cR=!1,kn=!1,jKe=typeof WeakSet=="function"?WeakSet:Set,wt=null;function qf(e,g){var i=e.ref;if(i!==null)if(typeof i=="function")try{i(null)}catch(I){Ui(e,g,I)}else i.current=null}function _E(e,g,i){try{i()}catch(I){Ui(e,g,I)}}var aq=!1;function $Ke(e,g){if(WE=$W,e=Ude(),hL(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,r=I.focusNode;I=I.focusOffset;try{i.nodeType,r.nodeType}catch{i=null;break e}var C=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=C+n),l!==r||I!==0&&l.nodeType!==3||(a=C+I),l.nodeType===3&&(C+=l.nodeValue.length),(u=l.firstChild)!==null;)c=l,l=u;for(;;){if(l===e)break t;if(c===i&&++s===n&&(o=C),c===r&&++A===I&&(a=C),(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(XE={focusedElem:e,selectionRange:i},$W=!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:Do(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(st(163))}}catch(y){Ui(g,g.return,y)}if(e=g.sibling,e!==null){e.return=g.return,wt=e;break}wt=g.return}return d=aq,aq=!1,d}function XG(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 r=n.destroy;n.destroy=void 0,r!==void 0&&_E(g,i,r)}n=n.next}while(n!==I)}}function rT(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 LE(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 Ohe(e){var g=e.alternate;g!==null&&(e.alternate=null,Ohe(g)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(g=e.stateNode,g!==null&&(delete g[Ea],delete g[$v],delete g[NE],delete g[NKe],delete g[kKe])),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 _he(e){return e.tag===5||e.tag===3||e.tag===4}function Aq(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||_he(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 UE(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=t9));else if(I!==4&&(e=e.child,e!==null))for(UE(e,g,i),e=e.sibling;e!==null;)UE(e,g,i),e=e.sibling}function QE(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(QE(e,g,i),e=e.sibling;e!==null;)QE(e,g,i),e=e.sibling}var on=null,Eo=!1;function dl(e,g,i){for(i=i.child;i!==null;)Lhe(e,g,i),i=i.sibling}function Lhe(e,g,i){if(oA&&typeof oA.onCommitFiberUnmount=="function")try{oA.onCommitFiberUnmount($H,i)}catch{}switch(i.tag){case 5:kn||qf(i,g);case 6:var I=on,n=Eo;on=null,dl(e,g,i),on=I,Eo=n,on!==null&&(Eo?(e=on,i=i.stateNode,e.nodeType===8?e.parentNode.removeChild(i):e.removeChild(i)):on.removeChild(i.stateNode));break;case 18:on!==null&&(Eo?(e=on,i=i.stateNode,e.nodeType===8?lK(e.parentNode,i):e.nodeType===1&&lK(e,i),_v(e)):lK(on,i.stateNode));break;case 4:I=on,n=Eo,on=i.stateNode.containerInfo,Eo=!0,dl(e,g,i),on=I,Eo=n;break;case 0:case 11:case 14:case 15:if(!kn&&(I=i.updateQueue,I!==null&&(I=I.lastEffect,I!==null))){n=I=I.next;do{var r=n,C=r.destroy;r=r.tag,C!==void 0&&(r&2||r&4)&&_E(i,g,C),n=n.next}while(n!==I)}dl(e,g,i);break;case 1:if(!kn&&(qf(i,g),I=i.stateNode,typeof I.componentWillUnmount=="function"))try{I.props=i.memoizedProps,I.state=i.memoizedState,I.componentWillUnmount()}catch(o){Ui(i,g,o)}dl(e,g,i);break;case 21:dl(e,g,i);break;case 22:i.mode&1?(kn=(I=kn)||i.memoizedState!==null,dl(e,g,i),kn=I):dl(e,g,i);break;default:dl(e,g,i)}}function sq(e){var g=e.updateQueue;if(g!==null){e.updateQueue=null;var i=e.stateNode;i===null&&(i=e.stateNode=new jKe),g.forEach(function(I){var n=C5e.bind(null,e,I);i.has(I)||(i.add(I),I.then(n,n))})}}function ho(e,g){var i=g.deletions;if(i!==null)for(var I=0;In&&(n=C),I&=~r}if(I=n,I=AI()-I,I=(120>I?120:480>I?480:1080>I?1080:1920>I?1920:3e3>I?3e3:4320>I?4320:1960*e5e(I/1960))-I,10e?16:e,ac===null)var I=!1;else{if(e=ac,ac=null,u9=0,Tg&6)throw Error(st(331));var n=Tg;for(Tg|=4,wt=e.current;wt!==null;){var r=wt,C=r.child;if(wt.flags&16){var o=r.deletions;if(o!==null){for(var a=0;aAI()-YL?vd(e,0):kL|=i),Dr(e,g)}function gme(e,g){g===0&&(e.mode&1?(g=IR,IR<<=1,!(IR&130023424)&&(IR=4194304)):g=1);var i=Cr();e=Ns(e,g),e!==null&&(GS(e,g,i),Dr(e,i))}function r5e(e){var g=e.memoizedState,i=0;g!==null&&(i=g.retryLane),gme(e,i)}function C5e(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(st(314))}I!==null&&I.delete(g),gme(e,i)}var ime;ime=function(e,g,i){if(e!==null)if(e.memoizedProps!==g.pendingProps||Kr.current)Nr=!0;else{if(!(e.lanes&i)&&!(g.flags&128))return Nr=!1,LKe(e,g,i);Nr=!!(e.flags&131072)}else Nr=!1,Wi&&g.flags&1048576&&rhe(g,n9,g.index);switch(g.lanes=0,g.tag){case 2:var I=g.type;v1(e,g),e=g.pendingProps;var n=ib(g,Kn.current);yp(g,i),n=VL(null,g,I,e,n,i);var r=WL();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,Fr(I)?(r=!0,i9(g)):r=!1,g.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,vL(g),n.updater=IT,g.stateNode=n,n._reactInternals=g,xE(g,I,e,i),g=zE(null,g,I,!0,r,i)):(g.tag=0,Wi&&r&&mL(g),Ln(null,g,n,i),g=g.child),g;case 16:I=g.elementType;e:{switch(v1(e,g),e=g.pendingProps,n=I._init,I=n(I._payload),g.type=I,n=g.tag=a5e(I),e=Do(I,e),n){case 0:g=ME(null,g,I,e,i);break e;case 1:g=rq(null,g,I,e,i);break e;case 11:g=Iq(null,g,I,e,i);break e;case 14:g=nq(null,g,I,Do(I.type,e),i);break e}throw Error(st(306,I,""))}return g;case 0:return I=g.type,n=g.pendingProps,n=g.elementType===I?n:Do(I,n),ME(e,g,I,n,i);case 1:return I=g.type,n=g.pendingProps,n=g.elementType===I?n:Do(I,n),rq(e,g,I,n,i);case 3:e:{if(xhe(g),e===null)throw Error(st(387));I=g.pendingProps,r=g.memoizedState,n=r.element,Ahe(e,g),o9(g,I,null,i);var C=g.memoizedState;if(I=C.element,r.isDehydrated)if(r={element:I,isDehydrated:!1,cache:C.cache,pendingSuspenseBoundaries:C.pendingSuspenseBoundaries,transitions:C.transitions},g.updateQueue.baseState=r,g.memoizedState=r,g.flags&256){n=Cb(Error(st(423)),g),g=Cq(e,g,I,i,n);break e}else if(I!==n){n=Cb(Error(st(424)),g),g=Cq(e,g,I,i,n);break e}else for(AC=Bc(g.stateNode.containerInfo.firstChild),cC=g,Wi=!0,zo=null,i=uhe(g,null,I,i),g.child=i;i;)i.flags=i.flags&-3|4096,i=i.sibling;else{if(Ib(),I===n){g=ks(e,g,i);break e}Ln(e,g,I,i)}g=g.child}return g;case 5:return dhe(g),e===null&&KE(g),I=g.type,n=g.pendingProps,r=e!==null?e.memoizedProps:null,C=n.children,HE(I,n)?C=null:r!==null&&HE(I,r)&&(g.flags|=32),Dhe(e,g),Ln(e,g,C,i),g.child;case 6:return e===null&&KE(g),null;case 13:return Ehe(e,g,i);case 4:return BL(g,g.stateNode.containerInfo),I=g.pendingProps,e===null?g.child=nb(g,null,I,i):Ln(e,g,I,i),g.child;case 11:return I=g.type,n=g.pendingProps,n=g.elementType===I?n:Do(I,n),Iq(e,g,I,n,i);case 7:return Ln(e,g,g.pendingProps,i),g.child;case 8:return Ln(e,g,g.pendingProps.children,i),g.child;case 12:return Ln(e,g,g.pendingProps.children,i),g.child;case 10:e:{if(I=g.type._context,n=g.pendingProps,r=g.memoizedProps,C=n.value,oi(r9,I._currentValue),I._currentValue=C,r!==null)if(aa(r.value,C)){if(r.children===n.children&&!Kr.current){g=ks(e,g,i);break e}}else for(r=g.child,r!==null&&(r.return=g);r!==null;){var o=r.dependencies;if(o!==null){C=r.child;for(var a=o.firstContext;a!==null;){if(a.context===I){if(r.tag===1){a=Ss(-1,i&-i),a.tag=2;var s=r.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}}r.lanes|=i,a=r.alternate,a!==null&&(a.lanes|=i),FE(r.return,i,g),o.lanes|=i;break}a=a.next}}else if(r.tag===10)C=r.type===g.type?null:r.child;else if(r.tag===18){if(C=r.return,C===null)throw Error(st(341));C.lanes|=i,o=C.alternate,o!==null&&(o.lanes|=i),FE(C,i,g),C=r.sibling}else C=r.child;if(C!==null)C.return=r;else for(C=r;C!==null;){if(C===g){C=null;break}if(r=C.sibling,r!==null){r.return=C.return,C=r;break}C=C.return}r=C}Ln(e,g,n.children,i),g=g.child}return g;case 9:return n=g.type,I=g.pendingProps.children,yp(g,i),n=go(n),I=I(n),g.flags|=1,Ln(e,g,I,i),g.child;case 14:return I=g.type,n=Do(I,g.pendingProps),n=Do(I.type,n),nq(e,g,I,n,i);case 15:return Khe(e,g,g.type,g.pendingProps,i);case 17:return I=g.type,n=g.pendingProps,n=g.elementType===I?n:Do(I,n),v1(e,g),g.tag=1,Fr(I)?(e=!0,i9(g)):e=!1,yp(g,i),lhe(g,I,n),xE(g,I,n,i),zE(null,g,I,!0,e,i);case 19:return Mhe(e,g,i);case 22:return Fhe(e,g,i)}throw Error(st(156,g.tag))};function Ime(e,g){return Wde(e,g)}function o5e(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 PC(e,g,i,I){return new o5e(e,g,i,I)}function xL(e){return e=e.prototype,!(!e||!e.isReactComponent)}function a5e(e){if(typeof e=="function")return xL(e)?1:0;if(e!=null){if(e=e.$$typeof,e===nL)return 11;if(e===rL)return 14}return 2}function Vc(e,g){var i=e.alternate;return i===null?(i=PC(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 w1(e,g,i,I,n,r){var C=2;if(I=e,typeof e=="function")xL(e)&&(C=1);else if(typeof e=="string")C=5;else e:switch(e){case Pf:return Bd(i.children,n,r,g);case IL:C=8,n|=8;break;case AE:return e=PC(12,i,g,n|2),e.elementType=AE,e.lanes=r,e;case sE:return e=PC(13,i,g,n),e.elementType=sE,e.lanes=r,e;case lE:return e=PC(19,i,g,n),e.elementType=lE,e.lanes=r,e;case cde:return oT(i,n,r,g);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case sde:C=10;break e;case lde:C=9;break e;case nL:C=11;break e;case rL:C=14;break e;case El:C=16,I=null;break e}throw Error(st(130,e==null?e:typeof e,""))}return g=PC(C,i,g,n),g.elementType=e,g.type=I,g.lanes=r,g}function Bd(e,g,i,I){return e=PC(7,e,I,g),e.lanes=i,e}function oT(e,g,i,I){return e=PC(22,e,I,g),e.elementType=cde,e.lanes=i,e.stateNode={isHidden:!1},e}function bK(e,g,i){return e=PC(6,e,null,g),e.lanes=i,e}function yK(e,g,i){return g=PC(4,e.children!==null?e.children:[],e.key,g),g.lanes=i,g.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},g}function A5e(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=tK(0),this.expirationTimes=tK(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=tK(0),this.identifierPrefix=I,this.onRecoverableError=n,this.mutableSourceEagerHydrationData=null}function EL(e,g,i,I,n,r,C,o,a){return e=new A5e(e,g,i,o,a),g===1?(g=1,r===!0&&(g|=8)):g=0,r=PC(3,null,null,g),e.current=r,r.stateNode=e,r.memoizedState={element:I,isDehydrated:i,cache:null,transitions:null,pendingSuspenseBoundaries:null},vL(r),e}function s5e(e,g,i){var I=3"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(ome)}catch(e){console.error(e)}}ome(),rde.exports=pC;var Aa=rde.exports;const ji=Qc(Aa);var pq=Aa;oE.createRoot=pq.createRoot,oE.hydrateRoot=pq.hydrateRoot;const h5e="modulepreload",m5e=function(e){return"/alt-gosling/"+e},bq={},f5e=function(g,i,I){if(!i||i.length===0)return g();const n=document.getElementsByTagName("link");return Promise.all(i.map(r=>{if(r=m5e(r),r in bq)return;bq[r]=!0;const C=r.endsWith(".css"),o=C?'[rel="stylesheet"]':"";if(!!I)for(let A=n.length-1;A>=0;A--){const l=n[A];if(l.href===r&&(!C||l.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${r}"]${o}`))return;const s=document.createElement("link");if(s.rel=C?"stylesheet":h5e,C||(s.as="script",s.crossOrigin=""),s.href=r,document.head.appendChild(s),C)return new Promise((A,l)=>{s.addEventListener("load",A),s.addEventListener("error",()=>l(new Error(`Unable to preload CSS for ${r}`)))})})).then(()=>g()).catch(r=>{const C=new Event("vite:preloadError",{cancelable:!0});if(C.payload=r,window.dispatchEvent(C),!C.defaultPrevented)throw r})};function p5e(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 b5e(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 r=n.length;function C(a,s){if(s&&(typeof s=="object"||typeof s=="function")){var A=s.then;if(typeof A=="function"){A.call(s,function(l){C(a,l)},function(l){n[a]={status:"rejected",reason:l},--r===0&&i(n)});return}}n[a]={status:"fulfilled",value:s},--r===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=MI);Object.assign||(Object.assign=v5e);var B5e=16;Date.now&&Date.prototype.getTime||(Date.now=function(){return new Date().getTime()});if(!(globalThis.performance&&globalThis.performance.now)){var S5e=Date.now();globalThis.performance||(globalThis.performance={}),globalThis.performance.now=function(){return Date.now()-S5e}}var pK=Date.now(),hq=["ms","moz","webkit","o"];for(var bK=0;bK0?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);/*! + */typeof globalThis>"u"&&(typeof self<"u"?self.globalThis=self:typeof global<"u"&&(global.globalThis=global));globalThis.Promise||(globalThis.Promise=Mi);Object.assign||(Object.assign=X5e);var H5e=16;Date.now&&Date.prototype.getTime||(Date.now=function(){return new Date().getTime()});if(!(globalThis.performance&&globalThis.performance.now)){var T5e=Date.now();globalThis.performance||(globalThis.performance={}),globalThis.performance.now=function(){return Date.now()-T5e}}var ZK=Date.now(),Zq=["ms","moz","webkit","o"];for(var GK=0;GK0?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 mA;(function(e){e[e.WEBGL_LEGACY=0]="WEBGL_LEGACY",e[e.WEBGL=1]="WEBGL",e[e.WEBGL2=2]="WEBGL2"})(mA||(mA={}));var ob;(function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.WEBGL=1]="WEBGL",e[e.CANVAS=2]="CANVAS"})(ob||(ob={}));var IB;(function(e){e[e.COLOR=16384]="COLOR",e[e.DEPTH=256]="DEPTH",e[e.STENCIL=1024]="STENCIL"})(IB||(IB={}));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 Or;(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"})(Or||(Or={}));var ft;(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"})(ft||(ft={}));var Wc;(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"})(Wc||(Wc={}));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 iB;(function(e){e[e.FLOAT=0]="FLOAT",e[e.INT=1]="INT",e[e.UINT=2]="UINT"})(iB||(iB={}));var Qo;(function(e){e[e.NEAREST=0]="NEAREST",e[e.LINEAR=1]="LINEAR"})(Qo||(Qo={}));var ga;(function(e){e[e.CLAMP=33071]="CLAMP",e[e.REPEAT=10497]="REPEAT",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT"})(ga||(ga={}));var io;(function(e){e[e.OFF=0]="OFF",e[e.POW2=1]="POW2",e[e.ON=2]="ON",e[e.ON_MANUAL=3]="ON_MANUAL"})(io||(io={}));var no;(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"})(no||(no={}));var Dr;(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"})(Dr||(Dr={}));var nB;(function(e){e[e.AUTO=0]="AUTO",e[e.MANUAL=1]="MANUAL"})(nB||(nB={}));var YC;(function(e){e.LOW="lowp",e.MEDIUM="mediump",e.HIGH="highp"})(YC||(YC={}));var Ci;(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"})(Ci||(Ci={}));var $E;(function(e){e[e.RED=1]="RED",e[e.GREEN=2]="GREEN",e[e.BLUE=4]="BLUE",e[e.ALPHA=8]="ALPHA"})($E||($E={}));var fI;(function(e){e[e.NONE=0]="NONE",e[e.LOW=2]="LOW",e[e.MEDIUM=4]="MEDIUM",e[e.HIGH=8]="HIGH"})(fI||(fI={}));var Ia;(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"})(Ia||(Ia={}));/*! + */var mA;(function(e){e[e.WEBGL_LEGACY=0]="WEBGL_LEGACY",e[e.WEBGL=1]="WEBGL",e[e.WEBGL2=2]="WEBGL2"})(mA||(mA={}));var ab;(function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.WEBGL=1]="WEBGL",e[e.CANVAS=2]="CANVAS"})(ab||(ab={}));var rB;(function(e){e[e.COLOR=16384]="COLOR",e[e.DEPTH=256]="DEPTH",e[e.STENCIL=1024]="STENCIL"})(rB||(rB={}));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 JC;(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"})(JC||(JC={}));var ft;(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"})(ft||(ft={}));var Wc;(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"})(Wc||(Wc={}));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 CB;(function(e){e[e.FLOAT=0]="FLOAT",e[e.INT=1]="INT",e[e.UINT=2]="UINT"})(CB||(CB={}));var Qo;(function(e){e[e.NEAREST=0]="NEAREST",e[e.LINEAR=1]="LINEAR"})(Qo||(Qo={}));var ga;(function(e){e[e.CLAMP=33071]="CLAMP",e[e.REPEAT=10497]="REPEAT",e[e.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT"})(ga||(ga={}));var Io;(function(e){e[e.OFF=0]="OFF",e[e.POW2=1]="POW2",e[e.ON=2]="ON",e[e.ON_MANUAL=3]="ON_MANUAL"})(Io||(Io={}));var no;(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"})(no||(no={}));var FC;(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"})(FC||(FC={}));var oB;(function(e){e[e.AUTO=0]="AUTO",e[e.MANUAL=1]="MANUAL"})(oB||(oB={}));var kr;(function(e){e.LOW="lowp",e.MEDIUM="mediump",e.HIGH="highp"})(kr||(kr={}));var rI;(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"})(rI||(rI={}));var iM;(function(e){e[e.RED=1]="RED",e[e.GREEN=2]="GREEN",e[e.BLUE=4]="BLUE",e[e.ALPHA=8]="ALPHA"})(iM||(iM={}));var fi;(function(e){e[e.NONE=0]="NONE",e[e.LOW=2]="LOW",e[e.MEDIUM=4]="MEDIUM",e[e.HIGH=8]="HIGH"})(fi||(fi={}));var ia;(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"})(ia||(ia={}));/*! * @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 nme={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)}},ZK=/iPhone/i,mq=/iPod/i,fq=/iPad/i,pq=/\biOS-universal(?:.+)Mac\b/i,GK=/\bAndroid(?:.+)Mobile\b/i,bq=/Android/i,Rm=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,cV=/Silk/i,xA=/Windows Phone/i,yq=/\bWindows(?:.+)ARM\b/i,Zq=/BlackBerry/i,Gq=/BB10/i,vq=/Opera Mini/i,Bq=/\b(CriOS|Chrome)(?:.+)Mobile/i,Sq=/Mobile(?:.+)Firefox\b/i,wq=function(e){return typeof e<"u"&&e.platform==="MacIntel"&&typeof e.maxTouchPoints=="number"&&e.maxTouchPoints>1&&typeof MSStream>"u"};function w5e(e){return function(g){return g.test(e)}}function V5e(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=w5e(I),C={apple:{phone:n(ZK)&&!n(xA),ipod:n(mq),tablet:!n(ZK)&&(n(fq)||wq(g))&&!n(xA),universal:n(pq),device:(n(ZK)||n(mq)||n(fq)||n(pq)||wq(g))&&!n(xA)},amazon:{phone:n(Rm),tablet:!n(Rm)&&n(cV),device:n(Rm)||n(cV)},android:{phone:!n(xA)&&n(Rm)||!n(xA)&&n(GK),tablet:!n(xA)&&!n(Rm)&&!n(GK)&&(n(cV)||n(bq)),device:!n(xA)&&(n(Rm)||n(cV)||n(GK)||n(bq))||n(/\bokhttp\b/i)},windows:{phone:n(xA),tablet:n(yq),device:n(xA)||n(yq)},other:{blackberry:n(Zq),blackberry10:n(Gq),opera:n(vq),firefox:n(Sq),chrome:n(Bq),device:n(Zq)||n(Gq)||n(vq)||n(Sq)||n(Bq)},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 _r=V5e(globalThis.navigator);function R5e(){return!_r.apple.device}function W5e(e){var g=!0;if(_r.tablet||_r.phone){if(_r.apple.device){var I=navigator.userAgent.match(/OS (\d+)_(\d+)?/);if(I){var i=parseInt(I[1],10);i<11&&(g=!1)}}if(_r.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 Gt={ADAPTER:nme,MIPMAP_TEXTURES:io.POW2,ANISOTROPIC_LEVEL:0,RESOLUTION:1,FILTER_RESOLUTION:1,FILTER_MULTISAMPLE:fI.NONE,SPRITE_MAX_TEXTURES:W5e(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:nB.AUTO,GC_MAX_IDLE:60*60,GC_MAX_CHECK_COUNT:60*10,WRAP_MODE:ga.CLAMP,SCALE_MODE:Qo.LINEAR,PRECISION_VERTEX:YC.HIGH,PRECISION_FRAGMENT:_r.apple.device?YC.HIGH:YC.MEDIUM,CAN_UPLOAD_SAME_BUFFER:R5e(),CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1},Cme={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 CB(C,r,I,o,a,u,0),r}function rme(e,g,I,i,n){var C,r;if(n===tM(e,g,I,i)>0)for(C=g;C=g;C-=i)r=Vq(C,e[C],e[C+1],r);return r&&sT(r,r.next)&&(oB(r),r=r.next),r}function Ld(e,g){if(!e)return e;g||(g=e);var I=e,i;do if(i=!1,!I.steiner&&(sT(I,I.next)||xI(I.prev,I,I.next)===0)){if(oB(I),I=g=I.prev,I===I.next)break;i=!0}else I=I.next;while(i||I!==g);return g}function CB(e,g,I,i,n,C,r){if(e){!r&&C&&E5e(e,i,n,C);for(var o=e,a,s;e.prev!==e.next;){if(a=e.prev,s=e.next,C?T5e(e,i,n,C):H5e(e)){g.push(a.i/I|0),g.push(e.i/I|0),g.push(s.i/I|0),oB(e),e=s.next,o=s.next;continue}if(e=s,e===o){r?r===1?(e=N5e(Ld(e),g,I),CB(e,g,I,i,n,C,2)):r===2&&k5e(e,g,I,i,n,C):CB(Ld(e),g,I,i,n,C,1);break}}}}function H5e(e){var g=e.prev,I=e,i=e.next;if(xI(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&&gp(n,o,C,a,r,s,d.x,d.y)&&xI(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function T5e(e,g,I,i){var n=e.prev,C=e,r=e.next;if(xI(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,g,I,i),b=qE(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&&gp(o,A,a,l,s,c,p.x,p.y)&&xI(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&&gp(o,A,a,l,s,c,y.x,y.y)&&xI(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&&gp(o,A,a,l,s,c,p.x,p.y)&&xI(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&&gp(o,A,a,l,s,c,y.x,y.y)&&xI(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function N5e(e,g,I){var i=e;do{var n=i.prev,C=i.next.next;!sT(n,C)&&ome(n,i,i.next,C)&&rB(n,C)&&rB(C,n)&&(g.push(n.i/I|0),g.push(i.i/I|0),g.push(C.i/I|0),oB(i),oB(i.next),i=e=C),i=i.next}while(i!==e);return Ld(i)}function k5e(e,g,I,i,n,C){var r=e;do{for(var o=r.next.next;o!==r.prev;){if(r.i!==o.i&&P5e(r,o)){var a=ame(r,o);r=Ld(r,r.next),a=Ld(a,a.next),CB(r,g,I,i,n,C,0),CB(a,g,I,i,n,C,0);return}o=o.next}r=r.next}while(r!==e)}function Y5e(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&&gp(nr.x||I.x===r.x&&F5e(r,I)))&&(r=I,l=c)),I=I.next;while(I!==a);return r}function F5e(e,g){return xI(e.prev,e,g.prev)<0&&xI(g.next,e,e.next)<0}function E5e(e,g,I,i){var n=e;do n.z===0&&(n.z=qE(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,M5e(n)}function M5e(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 qE(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 z5e(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 P5e(e,g){return e.next.i!==g.i&&e.prev.i!==g.i&&!J5e(e,g)&&(rB(e,g)&&rB(g,e)&&O5e(e,g)&&(xI(e.prev,e,g.prev)||xI(e,g.prev,g))||sT(e,g)&&xI(e.prev,e,e.next)>0&&xI(g.prev,g,g.next)>0)}function xI(e,g,I){return(g.y-e.y)*(I.x-g.x)-(g.x-e.x)*(I.y-g.y)}function sT(e,g){return e.x===g.x&&e.y===g.y}function ome(e,g,I,i){var n=dV(xI(e,g,I)),C=dV(xI(e,g,i)),r=dV(xI(I,i,e)),o=dV(xI(I,i,g));return!!(n!==C&&r!==o||n===0&&uV(e,I,g)||C===0&&uV(e,i,g)||r===0&&uV(I,e,i)||o===0&&uV(I,g,i))}function uV(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 dV(e){return e>0?1:e<0?-1:0}function J5e(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&&ome(I,I.next,e,g))return!0;I=I.next}while(I!==e);return!1}function rB(e,g){return xI(e.prev,e,e.next)<0?xI(e,g,e.next)>=0&&xI(e,e.prev,g)>=0:xI(e,g,e.prev)<0||xI(e,e.next,g)<0}function O5e(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 ame(e,g){var I=new eM(e.i,e.x,e.y),i=new eM(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 Vq(e,g,I,i){var n=new eM(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 oB(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 eM(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}AT.deviation=function(e,g,I,i){var n=g&&g.length,C=n?g[0]*I:e.length,r=Math.abs(tM(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 _5e=DL.exports;const FL=jc(_5e);var uX={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */uX.exports;(function(e,g){(function(I){var i=g&&!g.nodeType&&g,n=e&&!e.nodeType&&e,C=typeof yI=="object"&&yI;(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(P){throw new RangeError(p[P])}function w(P,ge){for(var q=P.length,$=[];q--;)$[q]=ge(P[q]);return $}function V(P,ge){var q=P.split("@"),$="";q.length>1&&($=q[0]+"@",P=q[1]),P=P.replace(b,".");var j=P.split("."),te=w(j,ge).join(".");return $+te}function S(P){for(var ge=[],q=0,$=P.length,j,te;q<$;)j=P.charCodeAt(q++),j>=55296&&j<=56319&&q<$?(te=P.charCodeAt(q++),(te&64512)==56320?ge.push(((j&1023)<<10)+(te&1023)+65536):(ge.push(j),q--)):ge.push(j);return ge}function X(P){return w(P,function(ge){var q="";return ge>65535&&(ge-=65536,q+=B(ge>>>10&1023|55296),ge=56320|ge&1023),q+=B(ge),q}).join("")}function W(P){return P-48<10?P-22:P-65<26?P-65:P-97<26?P-97:a}function R(P,ge){return P+22+75*(P<26)-((ge!=0)<<5)}function H(P,ge,q){var $=0;for(P=q?Z(P/c):P>>1,P+=Z(P/ge);P>y*A>>1;$+=a)P=Z(P/y);return Z($+(y+1)*P/(P+l))}function Y(P){var ge=[],q=P.length,$,j=0,te=d,Q=u,ie,he,ne,be,pe,ve,We,Be,Je;for(ie=P.lastIndexOf(h),ie<0&&(ie=0),he=0;he=128&&v("not-basic"),ge.push(P.charCodeAt(he));for(ne=ie>0?ie+1:0;ne=q&&v("invalid-input"),We=W(P.charCodeAt(ne++)),(We>=a||We>Z((o-j)/pe))&&v("overflow"),j+=We*pe,Be=ve<=Q?s:ve>=Q+A?A:ve-Q,!(WeZ(o/Je)&&v("overflow"),pe*=Je;$=ge.length+1,Q=H(j-be,$,be==0),Z(j/$)>o-te&&v("overflow"),te+=Z(j/$),j%=$,ge.splice(j++,0,te)}return X(ge)}function K(P){var ge,q,$,j,te,Q,ie,he,ne,be,pe,ve=[],We,Be,Je,Pe;for(P=S(P),We=P.length,ge=d,q=0,te=u,Q=0;Q=ge&&peZ((o-q)/Be)&&v("overflow"),q+=(ie-ge)*Be,ge=ie,Q=0;Qo&&v("overflow"),pe==ge){for(he=q,ne=a;be=ne<=te?s:ne>=te+A?A:ne-te,!(he"u"||!zi?mg:zi(Uint8Array),Vd={"%AggregateError%":typeof AggregateError>"u"?mg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?mg:ArrayBuffer,"%ArrayIteratorPrototype%":Wm&&zi?zi([][Symbol.iterator]()):mg,"%AsyncFromSyncIteratorPrototype%":mg,"%AsyncFunction%":mf,"%AsyncGenerator%":mf,"%AsyncGeneratorFunction%":mf,"%AsyncIteratorPrototype%":mf,"%Atomics%":typeof Atomics>"u"?mg:Atomics,"%BigInt%":typeof BigInt>"u"?mg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?mg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?mg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?mg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?mg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?mg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?mg:FinalizationRegistry,"%Function%":Ame,"%GeneratorFunction%":mf,"%Int8Array%":typeof Int8Array>"u"?mg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?mg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?mg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Wm&&zi?zi(zi([][Symbol.iterator]())):mg,"%JSON%":typeof JSON=="object"?JSON:mg,"%Map%":typeof Map>"u"?mg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Wm||!zi?mg:zi(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?mg:Promise,"%Proxy%":typeof Proxy>"u"?mg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?mg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?mg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Wm||!zi?mg:zi(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?mg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Wm&&zi?zi(""[Symbol.iterator]()):mg,"%Symbol%":Wm?Symbol:mg,"%SyntaxError%":ab,"%ThrowTypeError%":lxe,"%TypedArray%":uxe,"%TypeError%":Zp,"%Uint8Array%":typeof Uint8Array>"u"?mg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?mg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?mg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?mg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?mg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?mg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?mg:WeakSet};if(zi)try{null.error}catch(e){var dxe=zi(zi(e));Vd["%Error.prototype%"]=dxe}var hxe=function e(g){var I;if(g==="%AsyncFunction%")I=vK("async function () {}");else if(g==="%GeneratorFunction%")I=vK("function* () {}");else if(g==="%AsyncGeneratorFunction%")I=vK("async function* () {}");else if(g==="%AsyncGenerator%"){var i=e("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&zi&&(I=zi(n.prototype))}return Vd[g]=I,I},Hq={"%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"]},vS=EL,dX=sxe,mxe=vS.call(Function.call,Array.prototype.concat),fxe=vS.call(Function.apply,Array.prototype.splice),Tq=vS.call(Function.call,String.prototype.replace),hX=vS.call(Function.call,String.prototype.slice),pxe=vS.call(Function.call,RegExp.prototype.exec),bxe=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,yxe=/\\(\\)?/g,Zxe=function(g){var I=hX(g,0,1),i=hX(g,-1);if(I==="%"&&i!=="%")throw new ab("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new ab("invalid intrinsic syntax, expected opening `%`");var n=[];return Tq(g,bxe,function(C,r,o,a){n[n.length]=o?Tq(a,yxe,"$1"):r||C}),n},Gxe=function(g,I){var i=g,n;if(dX(Hq,i)&&(n=Hq[i],i="%"+n[0]+"%"),dX(Vd,i)){var C=Vd[i];if(C===mf&&(C=hxe(i)),typeof C>"u"&&!I)throw new Zp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new ab("intrinsic "+g+" does not exist!")},_h=function(g,I){if(typeof g!="string"||g.length===0)throw new Zp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new Zp('"allowMissing" argument must be a boolean');if(pxe(/^%?[^%]*%?$/,g)===null)throw new ab("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=Zxe(g),n=i.length>0?i[0]:"",C=Gxe("%"+n+"%",I),r=C.name,o=C.value,a=!1,s=C.alias;s&&(n=s[0],fxe(i,mxe([0,1],s)));for(var A=1,l=!0;A=i.length){var h=wd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=dX(o,c),o=o[c];l&&!a&&(Vd[r]=o)}}return o},sme={exports:{}},vxe=_h,gM=vxe("%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 lme=IM,Bxe=_h,B1=Bxe("%Object.getOwnPropertyDescriptor%",!0);if(B1)try{B1([],"length")}catch{B1=null}var cme=B1,Sxe=lme(),ML=_h,NG=Sxe&&ML("%Object.defineProperty%",!0);if(NG)try{NG({},"a",{value:1})}catch{NG=!1}var wxe=ML("%SyntaxError%"),Xm=ML("%TypeError%"),Nq=cme,Vxe=function(g,I,i){if(!g||typeof g!="object"&&typeof g!="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=!!Nq&&Nq(g,I);if(NG)NG(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 wxe("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},ume=_h,kq=Vxe,Rxe=lme(),Yq=cme,Kq=ume("%TypeError%"),Wxe=ume("%Math.floor%"),Xxe=function(g,I){if(typeof g!="function")throw new Kq("`fn` is not a function");if(typeof I!="number"||I<0||I>4294967295||Wxe(I)!==I)throw new Kq("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in g&&Yq){var r=Yq(g,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(Rxe?kq(g,"length",I,!0,!0):kq(g,"length",I)),g};(function(e){var g=EL,I=_h,i=Xxe,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})(sme);var Hxe=sme.exports,dme=_h,hme=Hxe,Txe=hme(dme("String.prototype.indexOf")),Nxe=function(g,I){var i=dme(g,!!I);return typeof i=="function"&&Txe(g,".prototype.")>-1?hme(i):i};const mme={},kxe=Object.freeze(Object.defineProperty({__proto__:null,default:mme},Symbol.toStringTag,{value:"Module"})),Yxe=P_(kxe);var zL=typeof Map=="function"&&Map.prototype,SK=Object.getOwnPropertyDescriptor&&zL?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,mX=zL&&SK&&typeof SK.get=="function"?SK.get:null,xq=zL&&Map.prototype.forEach,PL=typeof Set=="function"&&Set.prototype,wK=Object.getOwnPropertyDescriptor&&PL?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,fX=PL&&wK&&typeof wK.get=="function"?wK.get:null,Dq=PL&&Set.prototype.forEach,Kxe=typeof WeakMap=="function"&&WeakMap.prototype,kG=Kxe?WeakMap.prototype.has:null,xxe=typeof WeakSet=="function"&&WeakSet.prototype,YG=xxe?WeakSet.prototype.has:null,Dxe=typeof WeakRef=="function"&&WeakRef.prototype,Fq=Dxe?WeakRef.prototype.deref:null,Fxe=Boolean.prototype.valueOf,Exe=Object.prototype.toString,Mxe=Function.prototype.toString,zxe=String.prototype.match,JL=String.prototype.slice,Ac=String.prototype.replace,Pxe=String.prototype.toUpperCase,Eq=String.prototype.toLowerCase,fme=RegExp.prototype.test,Mq=Array.prototype.concat,Ka=Array.prototype.join,Jxe=Array.prototype.slice,zq=Math.floor,iM=typeof BigInt=="function"?BigInt.prototype.valueOf:null,VK=Object.getOwnPropertySymbols,nM=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Ab=typeof Symbol=="function"&&typeof Symbol.iterator=="object",xn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Ab||"symbol")?Symbol.toStringTag:null,pme=Object.prototype.propertyIsEnumerable,Pq=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function Jq(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||fme.call(/e/,g))return g;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var i=e<0?-zq(-e):zq(e);if(i!==e){var n=String(i),C=JL.call(g,n.length+1);return Ac.call(n,I,"$&_")+"."+Ac.call(Ac.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Ac.call(g,I,"$&_")}var CM=Yxe,Oq=CM.custom,_q=yme(Oq)?Oq:null,Oxe=function e(g,I,i,n){var C=I||{};if(zl(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(zl(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=zl(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(zl(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(zl(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 Gme(g,C);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var a=String(g);return o?Jq(g,a):a}if(typeof g=="bigint"){var s=String(g)+"n";return o?Jq(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 rM(g)?"[Array]":"[Object]";var l=ADe(C,i);if(typeof n>"u")n=[];else if(Zme(n,g)>=0)return"[Circular]";function c(W,R,H){if(R&&(n=Jxe.call(n),n.push(R)),H){var Y={depth:C.depth};return zl(C,"quoteStyle")&&(Y.quoteStyle=C.quoteStyle),e(W,Y,i+1,n)}return e(W,C,i+1,n)}if(typeof g=="function"&&!Lq(g)){var u=tDe(g),d=hV(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+Ka.call(d,", ")+" }":"")}if(yme(g)){var h=Ab?Ac.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):nM.call(g);return typeof g=="object"&&!Ab?Ry(h):h}if(rDe(g)){for(var m="<"+Eq.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(rM(g)){if(g.length===0)return"[]";var p=hV(g,c);return l&&!aDe(p)?"["+oM(p,l)+"]":"[ "+Ka.call(p,", ")+" ]"}if(Uxe(g)){var y=hV(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!pme.call(g,"cause")?"{ ["+String(g)+"] "+Ka.call(Mq.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+Ka.call(y,", ")+" }"}if(typeof g=="object"&&r){if(_q&&typeof g[_q]=="function"&&CM)return CM(g,{depth:A-i});if(r!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(gDe(g)){var Z=[];return xq&&xq.call(g,function(W,R){Z.push(c(R,g,!0)+" => "+c(W,g))}),Uq("Map",mX.call(g),Z,l)}if(nDe(g)){var B=[];return Dq&&Dq.call(g,function(W){B.push(c(W,g))}),Uq("Set",fX.call(g),B,l)}if(IDe(g))return RK("WeakMap");if(CDe(g))return RK("WeakSet");if(iDe(g))return RK("WeakRef");if(jxe(g))return Ry(c(Number(g)));if(qxe(g))return Ry(c(iM.call(g)));if($xe(g))return Ry(Fxe.call(g));if(Qxe(g))return Ry(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===yI)return"{ [object globalThis] }";if(!Lxe(g)&&!Lq(g)){var G=hV(g,c),v=Pq?Pq(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",V=!v&&xn&&Object(g)===g&&xn in g?JL.call(tu(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(V||w?"["+Ka.call(Mq.call([],V||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+oM(G,l)+"}":X+"{ "+Ka.call(G,", ")+" }"}return String(g)};function bme(e,g,I){var i=(I.quoteStyle||g)==="double"?'"':"'";return i+e+i}function _xe(e){return Ac.call(String(e),/"/g,""")}function rM(e){return tu(e)==="[object Array]"&&(!xn||!(typeof e=="object"&&xn in e))}function Lxe(e){return tu(e)==="[object Date]"&&(!xn||!(typeof e=="object"&&xn in e))}function Lq(e){return tu(e)==="[object RegExp]"&&(!xn||!(typeof e=="object"&&xn in e))}function Uxe(e){return tu(e)==="[object Error]"&&(!xn||!(typeof e=="object"&&xn in e))}function Qxe(e){return tu(e)==="[object String]"&&(!xn||!(typeof e=="object"&&xn in e))}function jxe(e){return tu(e)==="[object Number]"&&(!xn||!(typeof e=="object"&&xn in e))}function $xe(e){return tu(e)==="[object Boolean]"&&(!xn||!(typeof e=="object"&&xn in e))}function yme(e){if(Ab)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!nM)return!1;try{return nM.call(e),!0}catch{}return!1}function qxe(e){if(!e||typeof e!="object"||!iM)return!1;try{return iM.call(e),!0}catch{}return!1}var eDe=Object.prototype.hasOwnProperty||function(e){return e in this};function zl(e,g){return eDe.call(e,g)}function tu(e){return Exe.call(e)}function tDe(e){if(e.name)return e.name;var g=zxe.call(Mxe.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function Zme(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 Gme(JL.call(e,0,g.maxStringLength),g)+i}var n=Ac.call(Ac.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,oDe);return bme(n,"single",g)}function oDe(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":"")+Pxe.call(g.toString(16))}function Ry(e){return"Object("+e+")"}function RK(e){return e+" { ? }"}function Uq(e,g,I,i){var n=i?oM(I,i):Ka.call(I,", ");return e+" ("+g+") {"+n+"}"}function aDe(e){for(var g=0;g=0)return!1;return!0}function ADe(e,g){var I;if(e.indent===" ")I=" ";else if(typeof e.indent=="number"&&e.indent>0)I=Ka.call(Array(e.indent+1)," ");else return null;return{base:I,prev:Ka.call(Array(g+1),I)}}function oM(e,g){if(e.length===0)return"";var I=` -`+g.prev+g.base;return I+Ka.call(e,","+I)+` -`+g.prev}function hV(e,g){var I=rM(e),i=[];if(I){i.length=e.length;for(var n=0;n1;){var I=g.pop(),i=I.obj[I.prop];if(Id(i)){for(var n=[],C=0;C=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||C===BDe.RFC1738&&(s===40||s===41)){o+=r.charAt(a);continue}if(s<128){o=o+Sa[s];continue}if(s<2048){o=o+(Sa[192|s>>6]+Sa[128|s&63]);continue}if(s<55296||s>=57344){o=o+(Sa[224|s>>12]+Sa[128|s>>6&63]+Sa[128|s&63]);continue}a+=1,s=65536+((s&1023)<<10|r.charCodeAt(a)&1023),o+=Sa[240|s>>18]+Sa[128|s>>12&63]+Sa[128|s>>6&63]+Sa[128|s&63]}return o},XDe=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"&&gs(f)&&(f=S1.maybeMap(f,function(Y){return Y instanceof Date?l(Y):Y})),f===null){if(C)return o&&!d?o(I,Nn.encoder,h,"key",c):I;f=""}if(DDe(f)||S1.isBuffer(f)){if(o){var B=d?I:o(I,Nn.encoder,h,"key",c);return[u(B)+"="+u(o(f,Nn.encoder,h,"value",c))]}return[u(I)+"="+u(String(f))]}var G=[];if(typeof f>"u")return G;var v;if(i==="comma"&&gs(f))d&&o&&(f=S1.maybeMap(f,o)),v=[{value:f.length>0?f.join(",")||null:void 0}];else if(gs(a))v=a;else{var w=Object.keys(f);v=s?w.sort(s):w}for(var V=n&&gs(f)&&f.length===1?I+"[]":I,S=0;S"u"?Nn.allowDots:!!g.allowDots,charset:I,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:Nn.charsetSentinel,delimiter:typeof g.delimiter>"u"?Nn.delimiter:g.delimiter,encode:typeof g.encode=="boolean"?g.encode:Nn.encode,encoder:typeof g.encoder=="function"?g.encoder:Nn.encoder,encodeValuesOnly:typeof g.encodeValuesOnly=="boolean"?g.encodeValuesOnly:Nn.encodeValuesOnly,filter:C,format:i,formatter:n,serializeDate:typeof g.serializeDate=="function"?g.serializeDate:Nn.serializeDate,skipNulls:typeof g.skipNulls=="boolean"?g.skipNulls:Nn.skipNulls,sort:typeof g.sort=="function"?g.sort:null,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:Nn.strictNullHandling}},MDe=function(e,g){var I=e,i=EDe(g),n,C;typeof i.filter=="function"?(C=i.filter,I=C("",I)):gs(i.filter)&&(C=i.filter,n=C);var r=[];if(typeof I!="object"||I===null)return"";var o;g&&g.arrayFormat in Qq?o=g.arrayFormat:g&&"indices"in g?o=g.indices?"indices":"repeat":o="indices";var a=Qq[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=Sme(),l=0;l0?d+u:""},sb=Bme,aM=Object.prototype.hasOwnProperty,zDe=Array.isArray,Mi={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:sb.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},PDe=function(e){return e.replace(/&#(\d+);/g,function(g,I){return String.fromCharCode(parseInt(I,10))})},Vme=function(e,g){return e&&typeof e=="string"&&g.comma&&e.indexOf(",")>-1?e.split(","):e},JDe="utf8=%26%2310003%3B",ODe="utf8=%E2%9C%93",_De=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=zDe(d)?[d]:d),aM.call(i,u)?i[u]=sb.combine(i[u],d):i[u]=d}return i},LDe=function(e,g,I,i){for(var n=i?g:Vme(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},UDe=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&&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"?Mi.charset:g.charset;return{allowDots:typeof g.allowDots>"u"?Mi.allowDots:!!g.allowDots,allowPrototypes:typeof g.allowPrototypes=="boolean"?g.allowPrototypes:Mi.allowPrototypes,allowSparse:typeof g.allowSparse=="boolean"?g.allowSparse:Mi.allowSparse,arrayLimit:typeof g.arrayLimit=="number"?g.arrayLimit:Mi.arrayLimit,charset:I,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:Mi.charsetSentinel,comma:typeof g.comma=="boolean"?g.comma:Mi.comma,decoder:typeof g.decoder=="function"?g.decoder:Mi.decoder,delimiter:typeof g.delimiter=="string"||sb.isRegExp(g.delimiter)?g.delimiter:Mi.delimiter,depth:typeof g.depth=="number"||g.depth===!1?+g.depth:Mi.depth,ignoreQueryPrefix:g.ignoreQueryPrefix===!0,interpretNumericEntities:typeof g.interpretNumericEntities=="boolean"?g.interpretNumericEntities:Mi.interpretNumericEntities,parameterLimit:typeof g.parameterLimit=="number"?g.parameterLimit:Mi.parameterLimit,parseArrays:g.parseArrays!==!1,plainObjects:typeof g.plainObjects=="boolean"?g.plainObjects:Mi.plainObjects,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:Mi.strictNullHandling}},jDe=function(e,g){var I=QDe(g);if(e===""||e===null||typeof e>"u")return I.plainObjects?Object.create(null):{};for(var i=typeof e=="string"?_De(e,I):e,n=I.plainObjects?Object.create(null):{},C=Object.keys(i),r=0;r",'"',"`"," ","\r",` -`," "],rFe=["{","}","|","\\","^","`"].concat(CFe),AM=["'"].concat(rFe),$q=["%","/","?",";","#"].concat(AM),qq=["/","?","#"],oFe=255,eee=/^[+a-z0-9A-Z_-]{0,63}$/,aFe=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,AFe={javascript:!0,"javascript:":!0},sM={javascript:!0,"javascript:":!0},Gp={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},lM=tFe;function lT(e,g,I){if(e&&typeof e=="object"&&e instanceof ia)return e;var i=new ia;return i.parse(e,g,I),i}ia.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(eee)){var v=b.slice(0,u),w=b.slice(u+1),V=y.match(aFe);V&&(v.push(V[1]),w.unshift(V[2])),w.length&&(o="/"+w.join(".")+o),this.hostname=v.join(".");break}}}this.hostname.length>oFe?this.hostname="":this.hostname=this.hostname.toLowerCase(),f||(this.hostname=gFe.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(!AFe[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=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};ia.prototype.parseHost=function(){var e=this.host,g=iFe.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 cFe=lT,uFe=lFe,dFe=sFe;/*! + */var cme={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)}},BK=/iPhone/i,Gq=/iPod/i,vq=/iPad/i,Bq=/\biOS-universal(?:.+)Mac\b/i,SK=/\bAndroid(?:.+)Mobile\b/i,Sq=/Android/i,Rm=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,hR=/Silk/i,FA=/Windows Phone/i,wq=/\bWindows(?:.+)ARM\b/i,Rq=/BlackBerry/i,Vq=/BB10/i,Wq=/Opera Mini/i,Xq=/\b(CriOS|Chrome)(?:.+)Mobile/i,Hq=/Mobile(?:.+)Firefox\b/i,Tq=function(e){return typeof e<"u"&&e.platform==="MacIntel"&&typeof e.maxTouchPoints=="number"&&e.maxTouchPoints>1&&typeof MSStream>"u"};function N5e(e){return function(g){return g.test(e)}}function k5e(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=N5e(i),r={apple:{phone:n(BK)&&!n(FA),ipod:n(Gq),tablet:!n(BK)&&(n(vq)||Tq(g))&&!n(FA),universal:n(Bq),device:(n(BK)||n(Gq)||n(vq)||n(Bq)||Tq(g))&&!n(FA)},amazon:{phone:n(Rm),tablet:!n(Rm)&&n(hR),device:n(Rm)||n(hR)},android:{phone:!n(FA)&&n(Rm)||!n(FA)&&n(SK),tablet:!n(FA)&&!n(Rm)&&!n(SK)&&(n(hR)||n(Sq)),device:!n(FA)&&(n(Rm)||n(hR)||n(SK)||n(Sq))||n(/\bokhttp\b/i)},windows:{phone:n(FA),tablet:n(wq),device:n(FA)||n(wq)},other:{blackberry:n(Rq),blackberry10:n(Vq),opera:n(Wq),firefox:n(Hq),chrome:n(Xq),device:n(Rq)||n(Vq)||n(Wq)||n(Hq)||n(Xq)},any:!1,phone:!1,tablet:!1};return r.any=r.apple.device||r.android.device||r.windows.device||r.other.device,r.phone=r.apple.phone||r.android.phone||r.windows.phone,r.tablet=r.apple.tablet||r.android.tablet||r.windows.tablet,r}var OC=k5e(globalThis.navigator);function Y5e(){return!OC.apple.device}function K5e(e){var g=!0;if(OC.tablet||OC.phone){if(OC.apple.device){var i=navigator.userAgent.match(/OS (\d+)_(\d+)?/);if(i){var I=parseInt(i[1],10);I<11&&(g=!1)}}if(OC.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 Gt={ADAPTER:cme,MIPMAP_TEXTURES:Io.POW2,ANISOTROPIC_LEVEL:0,RESOLUTION:1,FILTER_RESOLUTION:1,FILTER_MULTISAMPLE:fi.NONE,SPRITE_MAX_TEXTURES:K5e(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:oB.AUTO,GC_MAX_IDLE:60*60,GC_MAX_CHECK_COUNT:60*10,WRAP_MODE:ga.CLAMP,SCALE_MODE:Qo.LINEAR,PRECISION_VERTEX:kr.HIGH,PRECISION_FRAGMENT:OC.apple.device?kr.HIGH:kr.MEDIUM,CAN_UPLOAD_SAME_BUFFER:Y5e(),CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1},ume={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 r(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 C(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 aB(r,C,i,o,a,u,0),C}function dme(e,g,i,I,n){var r,C;if(n===rM(e,g,i,I)>0)for(r=g;r=g;r-=I)C=Nq(r,e[r],e[r+1],C);return C&&uT(C,C.next)&&(sB(C),C=C.next),C}function _d(e,g){if(!e)return e;g||(g=e);var i=e,I;do if(I=!1,!i.steiner&&(uT(i,i.next)||Fi(i.prev,i,i.next)===0)){if(sB(i),i=g=i.prev,i===i.next)break;I=!0}else i=i.next;while(I||i!==g);return g}function aB(e,g,i,I,n,r,C){if(e){!C&&r&&L5e(e,I,n,r);for(var o=e,a,s;e.prev!==e.next;){if(a=e.prev,s=e.next,r?x5e(e,I,n,r):D5e(e)){g.push(a.i/i|0),g.push(e.i/i|0),g.push(s.i/i|0),sB(e),e=s.next,o=s.next;continue}if(e=s,e===o){C?C===1?(e=E5e(_d(e),g,i),aB(e,g,i,I,n,r,2)):C===2&&M5e(e,g,i,I,n,r):aB(_d(e),g,i,I,n,r,1);break}}}}function D5e(e){var g=e.prev,i=e,I=e.next;if(Fi(g,i,I)>=0)return!1;for(var n=g.x,r=i.x,C=I.x,o=g.y,a=i.y,s=I.y,A=nr?n>C?n:C:r>C?r:C,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&&tp(n,o,r,a,C,s,d.x,d.y)&&Fi(d.prev,d,d.next)>=0)return!1;d=d.next}return!0}function x5e(e,g,i,I){var n=e.prev,r=e,C=e.next;if(Fi(n,r,C)>=0)return!1;for(var o=n.x,a=r.x,s=C.x,A=n.y,l=r.y,c=C.y,u=oa?o>s?o:s:a>s?a:s,m=A>l?A>c?A:c:l>c?l:c,f=IM(u,d,g,i,I),b=IM(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!==C&&tp(o,A,a,l,s,c,p.x,p.y)&&Fi(p.prev,p,p.next)>=0||(p=p.prevZ,y.x>=u&&y.x<=h&&y.y>=d&&y.y<=m&&y!==n&&y!==C&&tp(o,A,a,l,s,c,y.x,y.y)&&Fi(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!==C&&tp(o,A,a,l,s,c,p.x,p.y)&&Fi(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!==C&&tp(o,A,a,l,s,c,y.x,y.y)&&Fi(y.prev,y,y.next)>=0)return!1;y=y.nextZ}return!0}function E5e(e,g,i){var I=e;do{var n=I.prev,r=I.next.next;!uT(n,r)&&hme(n,I,I.next,r)&&AB(n,r)&&AB(r,n)&&(g.push(n.i/i|0),g.push(I.i/i|0),g.push(r.i/i|0),sB(I),sB(I.next),I=e=r),I=I.next}while(I!==e);return _d(I)}function M5e(e,g,i,I,n,r){var C=e;do{for(var o=C.next.next;o!==C.prev;){if(C.i!==o.i&&j5e(C,o)){var a=mme(C,o);C=_d(C,C.next),a=_d(a,a.next),aB(C,g,i,I,n,r,0),aB(a,g,i,I,n,r,0);return}o=o.next}C=C.next}while(C!==e)}function z5e(e,g,i,I){var n=[],r,C,o,a,s;for(r=0,C=g.length;r=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>r&&(r=o,C=i.x=i.x&&i.x>=s&&I!==i.x&&tp(nC.x||i.x===C.x&&_5e(C,i)))&&(C=i,l=c)),i=i.next;while(i!==a);return C}function _5e(e,g){return Fi(e.prev,e,g.prev)<0&&Fi(g.next,e,e.next)<0}function L5e(e,g,i,I){var n=e;do n.z===0&&(n.z=IM(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,U5e(n)}function U5e(e){var g,i,I,n,r,C,o,a,s=1;do{for(i=e,e=null,r=null,C=0;i;){for(C++,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--),r?r.nextZ=n:e=n,n.prevZ=r,r=n;i=I}r.nextZ=null,s*=2}while(C>1);return e}function IM(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 Q5e(e){var g=e,i=e;do(g.x=(e-C)*(r-o)&&(e-C)*(I-o)>=(i-C)*(g-o)&&(i-C)*(r-o)>=(n-C)*(I-o)}function j5e(e,g){return e.next.i!==g.i&&e.prev.i!==g.i&&!$5e(e,g)&&(AB(e,g)&&AB(g,e)&&q5e(e,g)&&(Fi(e.prev,e,g.prev)||Fi(e,g.prev,g))||uT(e,g)&&Fi(e.prev,e,e.next)>0&&Fi(g.prev,g,g.next)>0)}function Fi(e,g,i){return(g.y-e.y)*(i.x-g.x)-(g.x-e.x)*(i.y-g.y)}function uT(e,g){return e.x===g.x&&e.y===g.y}function hme(e,g,i,I){var n=fR(Fi(e,g,i)),r=fR(Fi(e,g,I)),C=fR(Fi(i,I,e)),o=fR(Fi(i,I,g));return!!(n!==r&&C!==o||n===0&&mR(e,i,g)||r===0&&mR(e,I,g)||C===0&&mR(i,e,I)||o===0&&mR(i,g,I))}function mR(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 fR(e){return e>0?1:e<0?-1:0}function $5e(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&&hme(i,i.next,e,g))return!0;i=i.next}while(i!==e);return!1}function AB(e,g){return Fi(e.prev,e,e.next)<0?Fi(e,g,e.next)>=0&&Fi(e,e.prev,g)>=0:Fi(e,g,e.prev)<0||Fi(e,e.next,g)<0}function q5e(e,g){var i=e,I=!1,n=(e.x+g.x)/2,r=(e.y+g.y)/2;do i.y>r!=i.next.y>r&&i.next.y!==i.y&&n<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(I=!I),i=i.next;while(i!==e);return I}function mme(e,g){var i=new nM(e.i,e.x,e.y),I=new nM(g.i,g.x,g.y),n=e.next,r=g.prev;return e.next=g,g.prev=e,i.next=n,n.prev=i,I.next=i,i.prev=I,r.next=I,I.prev=r,I}function Nq(e,g,i,I){var n=new nM(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 sB(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 nM(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}cT.deviation=function(e,g,i,I){var n=g&&g.length,r=n?g[0]*i:e.length,C=Math.abs(rM(e,0,r,i));if(n)for(var o=0,a=g.length;o0&&(I+=e[n-1].length,i.holes.push(I))}return i};var eFe=JL.exports;const OL=Qc(eFe);var m9={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */m9.exports;(function(e,g){(function(i){var I=g&&!g.nodeType&&g,n=e&&!e.nodeType&&e,r=typeof yi=="object"&&yi;(r.global===r||r.window===r||r.self===r)&&(i=r);var C,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(P){throw new RangeError(p[P])}function w(P,ge){for(var q=P.length,$=[];q--;)$[q]=ge(P[q]);return $}function R(P,ge){var q=P.split("@"),$="";q.length>1&&($=q[0]+"@",P=q[1]),P=P.replace(b,".");var j=P.split("."),te=w(j,ge).join(".");return $+te}function S(P){for(var ge=[],q=0,$=P.length,j,te;q<$;)j=P.charCodeAt(q++),j>=55296&&j<=56319&&q<$?(te=P.charCodeAt(q++),(te&64512)==56320?ge.push(((j&1023)<<10)+(te&1023)+65536):(ge.push(j),q--)):ge.push(j);return ge}function X(P){return w(P,function(ge){var q="";return ge>65535&&(ge-=65536,q+=B(ge>>>10&1023|55296),ge=56320|ge&1023),q+=B(ge),q}).join("")}function W(P){return P-48<10?P-22:P-65<26?P-65:P-97<26?P-97:a}function V(P,ge){return P+22+75*(P<26)-((ge!=0)<<5)}function H(P,ge,q){var $=0;for(P=q?Z(P/c):P>>1,P+=Z(P/ge);P>y*A>>1;$+=a)P=Z(P/y);return Z($+(y+1)*P/(P+l))}function Y(P){var ge=[],q=P.length,$,j=0,te=d,Q=u,Ie,he,ne,be,pe,ve,We,Be,Je;for(Ie=P.lastIndexOf(h),Ie<0&&(Ie=0),he=0;he=128&&v("not-basic"),ge.push(P.charCodeAt(he));for(ne=Ie>0?Ie+1:0;ne=q&&v("invalid-input"),We=W(P.charCodeAt(ne++)),(We>=a||We>Z((o-j)/pe))&&v("overflow"),j+=We*pe,Be=ve<=Q?s:ve>=Q+A?A:ve-Q,!(WeZ(o/Je)&&v("overflow"),pe*=Je;$=ge.length+1,Q=H(j-be,$,be==0),Z(j/$)>o-te&&v("overflow"),te+=Z(j/$),j%=$,ge.splice(j++,0,te)}return X(ge)}function K(P){var ge,q,$,j,te,Q,Ie,he,ne,be,pe,ve=[],We,Be,Je,Pe;for(P=S(P),We=P.length,ge=d,q=0,te=u,Q=0;Q=ge&&peZ((o-q)/Be)&&v("overflow"),q+=(Ie-ge)*Be,ge=Ie,Q=0;Qo&&v("overflow"),pe==ge){for(he=q,ne=a;be=ne<=te?s:ne>=te+A?A:ne-te,!(he"u"||!zI?mg:zI(Uint8Array),wd={"%AggregateError%":typeof AggregateError>"u"?mg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?mg:ArrayBuffer,"%ArrayIteratorPrototype%":Vm&&zI?zI([][Symbol.iterator]()):mg,"%AsyncFromSyncIteratorPrototype%":mg,"%AsyncFunction%":hf,"%AsyncGenerator%":hf,"%AsyncGeneratorFunction%":hf,"%AsyncIteratorPrototype%":hf,"%Atomics%":typeof Atomics>"u"?mg:Atomics,"%BigInt%":typeof BigInt>"u"?mg:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?mg:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?mg:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?mg:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Error,"%eval%":eval,"%EvalError%":EvalError,"%Float32Array%":typeof Float32Array>"u"?mg:Float32Array,"%Float64Array%":typeof Float64Array>"u"?mg:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?mg:FinalizationRegistry,"%Function%":fme,"%GeneratorFunction%":hf,"%Int8Array%":typeof Int8Array>"u"?mg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?mg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?mg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Vm&&zI?zI(zI([][Symbol.iterator]())):mg,"%JSON%":typeof JSON=="object"?JSON:mg,"%Map%":typeof Map>"u"?mg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Vm||!zI?mg:zI(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?mg:Promise,"%Proxy%":typeof Proxy>"u"?mg:Proxy,"%RangeError%":RangeError,"%ReferenceError%":ReferenceError,"%Reflect%":typeof Reflect>"u"?mg:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?mg:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Vm||!zI?mg:zI(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?mg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Vm&&zI?zI(""[Symbol.iterator]()):mg,"%Symbol%":Vm?Symbol:mg,"%SyntaxError%":Ab,"%ThrowTypeError%":pFe,"%TypedArray%":yFe,"%TypeError%":Gp,"%Uint8Array%":typeof Uint8Array>"u"?mg:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?mg:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?mg:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?mg:Uint32Array,"%URIError%":URIError,"%WeakMap%":typeof WeakMap>"u"?mg:WeakMap,"%WeakRef%":typeof WeakRef>"u"?mg:WeakRef,"%WeakSet%":typeof WeakSet>"u"?mg:WeakSet};if(zI)try{null.error}catch(e){var ZFe=zI(zI(e));wd["%Error.prototype%"]=ZFe}var GFe=function e(g){var i;if(g==="%AsyncFunction%")i=wK("async function () {}");else if(g==="%GeneratorFunction%")i=wK("function* () {}");else if(g==="%AsyncGeneratorFunction%")i=wK("async function* () {}");else if(g==="%AsyncGenerator%"){var I=e("%AsyncGeneratorFunction%");I&&(i=I.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&zI&&(i=zI(n.prototype))}return wd[g]=i,i},Fq={"%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=_L,f9=fFe,vFe=wS.call(Function.call,Array.prototype.concat),BFe=wS.call(Function.apply,Array.prototype.splice),Dq=wS.call(Function.call,String.prototype.replace),p9=wS.call(Function.call,String.prototype.slice),SFe=wS.call(Function.call,RegExp.prototype.exec),wFe=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,RFe=/\\(\\)?/g,VFe=function(g){var i=p9(g,0,1),I=p9(g,-1);if(i==="%"&&I!=="%")throw new Ab("invalid intrinsic syntax, expected closing `%`");if(I==="%"&&i!=="%")throw new Ab("invalid intrinsic syntax, expected opening `%`");var n=[];return Dq(g,wFe,function(r,C,o,a){n[n.length]=o?Dq(a,RFe,"$1"):C||r}),n},WFe=function(g,i){var I=g,n;if(f9(Fq,I)&&(n=Fq[I],I="%"+n[0]+"%"),f9(wd,I)){var r=wd[I];if(r===hf&&(r=GFe(I)),typeof r>"u"&&!i)throw new Gp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:I,value:r}}throw new Ab("intrinsic "+g+" does not exist!")},Oh=function(g,i){if(typeof g!="string"||g.length===0)throw new Gp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof i!="boolean")throw new Gp('"allowMissing" argument must be a boolean');if(SFe(/^%?[^%]*%?$/,g)===null)throw new Ab("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var I=VFe(g),n=I.length>0?I[0]:"",r=WFe("%"+n+"%",i),C=r.name,o=r.value,a=!1,s=r.alias;s&&(n=s[0],BFe(I,vFe([0,1],s)));for(var A=1,l=!0;A=I.length){var h=Sd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=f9(o,c),o=o[c];l&&!a&&(wd[C]=o)}}return o},pme={exports:{}},XFe=Oh,CM=XFe("%Object.defineProperty%",!0),oM=function(){if(CM)try{return CM({},"a",{value:1}),!0}catch{return!1}return!1};oM.hasArrayLengthDefineBug=function(){if(!oM())return null;try{return CM([],"length",{value:1}).length!==1}catch{return!0}};var bme=oM,HFe=Oh,R1=HFe("%Object.getOwnPropertyDescriptor%",!0);if(R1)try{R1([],"length")}catch{R1=null}var yme=R1,TFe=bme(),LL=Oh,NG=TFe&&LL("%Object.defineProperty%",!0);if(NG)try{NG({},"a",{value:1})}catch{NG=!1}var NFe=LL("%SyntaxError%"),Wm=LL("%TypeError%"),xq=yme,kFe=function(g,i,I){if(!g||typeof g!="object"&&typeof g!="function")throw new Wm("`obj` must be an object or a function`");if(typeof i!="string"&&typeof i!="symbol")throw new Wm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new Wm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new Wm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new Wm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new Wm("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,r=arguments.length>4?arguments[4]:null,C=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,a=!!xq&&xq(g,i);if(NG)NG(g,i,{configurable:C===null&&a?a.configurable:!C,enumerable:n===null&&a?a.enumerable:!n,value:I,writable:r===null&&a?a.writable:!r});else if(o||!n&&!r&&!C)g[i]=I;else throw new NFe("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Zme=Oh,Eq=kFe,YFe=bme(),Mq=yme,zq=Zme("%TypeError%"),KFe=Zme("%Math.floor%"),FFe=function(g,i){if(typeof g!="function")throw new zq("`fn` is not a function");if(typeof i!="number"||i<0||i>4294967295||KFe(i)!==i)throw new zq("`length` must be a positive 32-bit integer");var I=arguments.length>2&&!!arguments[2],n=!0,r=!0;if("length"in g&&Mq){var C=Mq(g,"length");C&&!C.configurable&&(n=!1),C&&!C.writable&&(r=!1)}return(n||r||!I)&&(YFe?Eq(g,"length",i,!0,!0):Eq(g,"length",i)),g};(function(e){var g=_L,i=Oh,I=FFe,n=i("%TypeError%"),r=i("%Function.prototype.apply%"),C=i("%Function.prototype.call%"),o=i("%Reflect.apply%",!0)||g.call(C,r),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,C,arguments);return I(u,1+s(0,c.length-(arguments.length-1)),!0)};var A=function(){return o(g,r,arguments)};a?a(e.exports,"apply",{value:A}):e.exports.apply=A})(pme);var DFe=pme.exports,Gme=Oh,vme=DFe,xFe=vme(Gme("String.prototype.indexOf")),EFe=function(g,i){var I=Gme(g,!!i);return typeof I=="function"&&xFe(g,".prototype.")>-1?vme(I):I};const Bme={},MFe=Object.freeze(Object.defineProperty({__proto__:null,default:Bme},Symbol.toStringTag,{value:"Module"})),zFe=Q_(MFe);var UL=typeof Map=="function"&&Map.prototype,VK=Object.getOwnPropertyDescriptor&&UL?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,b9=UL&&VK&&typeof VK.get=="function"?VK.get:null,Pq=UL&&Map.prototype.forEach,QL=typeof Set=="function"&&Set.prototype,WK=Object.getOwnPropertyDescriptor&&QL?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,y9=QL&&WK&&typeof WK.get=="function"?WK.get:null,Jq=QL&&Set.prototype.forEach,PFe=typeof WeakMap=="function"&&WeakMap.prototype,kG=PFe?WeakMap.prototype.has:null,JFe=typeof WeakSet=="function"&&WeakSet.prototype,YG=JFe?WeakSet.prototype.has:null,OFe=typeof WeakRef=="function"&&WeakRef.prototype,Oq=OFe?WeakRef.prototype.deref:null,_Fe=Boolean.prototype.valueOf,LFe=Object.prototype.toString,UFe=Function.prototype.toString,QFe=String.prototype.match,jL=String.prototype.slice,Ac=String.prototype.replace,jFe=String.prototype.toUpperCase,_q=String.prototype.toLowerCase,Sme=RegExp.prototype.test,Lq=Array.prototype.concat,Ka=Array.prototype.join,$Fe=Array.prototype.slice,Uq=Math.floor,aM=typeof BigInt=="function"?BigInt.prototype.valueOf:null,XK=Object.getOwnPropertySymbols,AM=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,sb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Fn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===sb||"symbol")?Symbol.toStringTag:null,wme=Object.prototype.propertyIsEnumerable,Qq=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function jq(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||Sme.call(/e/,g))return g;var i=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var I=e<0?-Uq(-e):Uq(e);if(I!==e){var n=String(I),r=jL.call(g,n.length+1);return Ac.call(n,i,"$&_")+"."+Ac.call(Ac.call(r,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Ac.call(g,i,"$&_")}var sM=zFe,$q=sM.custom,qq=Vme($q)?$q:null,qFe=function e(g,i,I,n){var r=i||{};if(zl(r,"quoteStyle")&&r.quoteStyle!=="single"&&r.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(zl(r,"maxStringLength")&&(typeof r.maxStringLength=="number"?r.maxStringLength<0&&r.maxStringLength!==1/0:r.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var C=zl(r,"customInspect")?r.customInspect:!0;if(typeof C!="boolean"&&C!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(zl(r,"indent")&&r.indent!==null&&r.indent!==" "&&!(parseInt(r.indent,10)===r.indent&&r.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(zl(r,"numericSeparator")&&typeof r.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=r.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 Xme(g,r);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var a=String(g);return o?jq(g,a):a}if(typeof g=="bigint"){var s=String(g)+"n";return o?jq(g,s):s}var A=typeof r.depth>"u"?5:r.depth;if(typeof I>"u"&&(I=0),I>=A&&A>0&&typeof g=="object")return lM(g)?"[Array]":"[Object]";var l=mDe(r,I);if(typeof n>"u")n=[];else if(Wme(n,g)>=0)return"[Circular]";function c(W,V,H){if(V&&(n=$Fe.call(n),n.push(V)),H){var Y={depth:r.depth};return zl(r,"quoteStyle")&&(Y.quoteStyle=r.quoteStyle),e(W,Y,I+1,n)}return e(W,r,I+1,n)}if(typeof g=="function"&&!eee(g)){var u=oDe(g),d=pR(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+Ka.call(d,", ")+" }":"")}if(Vme(g)){var h=sb?Ac.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):AM.call(g);return typeof g=="object"&&!sb?Wy(h):h}if(uDe(g)){for(var m="<"+_q.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(lM(g)){if(g.length===0)return"[]";var p=pR(g,c);return l&&!hDe(p)?"["+cM(p,l)+"]":"[ "+Ka.call(p,", ")+" ]"}if(gDe(g)){var y=pR(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!wme.call(g,"cause")?"{ ["+String(g)+"] "+Ka.call(Lq.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+Ka.call(y,", ")+" }"}if(typeof g=="object"&&C){if(qq&&typeof g[qq]=="function"&&sM)return sM(g,{depth:A-I});if(C!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(aDe(g)){var Z=[];return Pq&&Pq.call(g,function(W,V){Z.push(c(V,g,!0)+" => "+c(W,g))}),tee("Map",b9.call(g),Z,l)}if(lDe(g)){var B=[];return Jq&&Jq.call(g,function(W){B.push(c(W,g))}),tee("Set",y9.call(g),B,l)}if(ADe(g))return HK("WeakMap");if(cDe(g))return HK("WeakSet");if(sDe(g))return HK("WeakRef");if(IDe(g))return Wy(c(Number(g)));if(rDe(g))return Wy(c(aM.call(g)));if(nDe(g))return Wy(_Fe.call(g));if(iDe(g))return Wy(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===yi)return"{ [object globalThis] }";if(!tDe(g)&&!eee(g)){var G=pR(g,c),v=Qq?Qq(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",R=!v&&Fn&&Object(g)===g&&Fn in g?jL.call(eu(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(R||w?"["+Ka.call(Lq.call([],R||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+cM(G,l)+"}":X+"{ "+Ka.call(G,", ")+" }"}return String(g)};function Rme(e,g,i){var I=(i.quoteStyle||g)==="double"?'"':"'";return I+e+I}function eDe(e){return Ac.call(String(e),/"/g,""")}function lM(e){return eu(e)==="[object Array]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function tDe(e){return eu(e)==="[object Date]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function eee(e){return eu(e)==="[object RegExp]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function gDe(e){return eu(e)==="[object Error]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function iDe(e){return eu(e)==="[object String]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function IDe(e){return eu(e)==="[object Number]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function nDe(e){return eu(e)==="[object Boolean]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Vme(e){if(sb)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!AM)return!1;try{return AM.call(e),!0}catch{}return!1}function rDe(e){if(!e||typeof e!="object"||!aM)return!1;try{return aM.call(e),!0}catch{}return!1}var CDe=Object.prototype.hasOwnProperty||function(e){return e in this};function zl(e,g){return CDe.call(e,g)}function eu(e){return LFe.call(e)}function oDe(e){if(e.name)return e.name;var g=QFe.call(UFe.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function Wme(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 Xme(jL.call(e,0,g.maxStringLength),g)+I}var n=Ac.call(Ac.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,dDe);return Rme(n,"single",g)}function dDe(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":"")+jFe.call(g.toString(16))}function Wy(e){return"Object("+e+")"}function HK(e){return e+" { ? }"}function tee(e,g,i,I){var n=I?cM(i,I):Ka.call(i,", ");return e+" ("+g+") {"+n+"}"}function hDe(e){for(var g=0;g=0)return!1;return!0}function mDe(e,g){var i;if(e.indent===" ")i=" ";else if(typeof e.indent=="number"&&e.indent>0)i=Ka.call(Array(e.indent+1)," ");else return null;return{base:i,prev:Ka.call(Array(g+1),i)}}function cM(e,g){if(e.length===0)return"";var i=` +`+g.prev+g.base;return i+Ka.call(e,","+i)+` +`+g.prev}function pR(e,g){var i=lM(e),I=[];if(i){I.length=e.length;for(var n=0;n1;){var i=g.pop(),I=i.obj[i.prop];if(gd(I)){for(var n=[],r=0;r=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122||r===HDe.RFC1738&&(s===40||s===41)){o+=C.charAt(a);continue}if(s<128){o=o+Sa[s];continue}if(s<2048){o=o+(Sa[192|s>>6]+Sa[128|s&63]);continue}if(s<55296||s>=57344){o=o+(Sa[224|s>>12]+Sa[128|s>>6&63]+Sa[128|s&63]);continue}a+=1,s=65536+((s&1023)<<10|C.charCodeAt(a)&1023),o+=Sa[240|s>>18]+Sa[128|s>>12&63]+Sa[128|s>>6&63]+Sa[128|s&63]}return o},FDe=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"&&gs(f)&&(f=V1.maybeMap(f,function(Y){return Y instanceof Date?l(Y):Y})),f===null){if(r)return o&&!d?o(i,Nn.encoder,h,"key",c):i;f=""}if(ODe(f)||V1.isBuffer(f)){if(o){var B=d?i:o(i,Nn.encoder,h,"key",c);return[u(B)+"="+u(o(f,Nn.encoder,h,"value",c))]}return[u(i)+"="+u(String(f))]}var G=[];if(typeof f>"u")return G;var v;if(I==="comma"&&gs(f))d&&o&&(f=V1.maybeMap(f,o)),v=[{value:f.length>0?f.join(",")||null:void 0}];else if(gs(a))v=a;else{var w=Object.keys(f);v=s?w.sort(s):w}for(var R=n&&gs(f)&&f.length===1?i+"[]":i,S=0;S"u"?Nn.allowDots:!!g.allowDots,charset:i,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:Nn.charsetSentinel,delimiter:typeof g.delimiter>"u"?Nn.delimiter:g.delimiter,encode:typeof g.encode=="boolean"?g.encode:Nn.encode,encoder:typeof g.encoder=="function"?g.encoder:Nn.encoder,encodeValuesOnly:typeof g.encodeValuesOnly=="boolean"?g.encodeValuesOnly:Nn.encodeValuesOnly,filter:r,format:I,formatter:n,serializeDate:typeof g.serializeDate=="function"?g.serializeDate:Nn.serializeDate,skipNulls:typeof g.skipNulls=="boolean"?g.skipNulls:Nn.skipNulls,sort:typeof g.sort=="function"?g.sort:null,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:Nn.strictNullHandling}},UDe=function(e,g){var i=e,I=LDe(g),n,r;typeof I.filter=="function"?(r=I.filter,i=r("",i)):gs(I.filter)&&(r=I.filter,n=r);var C=[];if(typeof i!="object"||i===null)return"";var o;g&&g.arrayFormat in gee?o=g.arrayFormat:g&&"indices"in g?o=g.indices?"indices":"repeat":o="indices";var a=gee[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=Nme(),l=0;l0?d+u:""},lb=Tme,uM=Object.prototype.hasOwnProperty,QDe=Array.isArray,MI={allowDots:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:lb.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},jDe=function(e){return e.replace(/&#(\d+);/g,function(g,i){return String.fromCharCode(parseInt(i,10))})},Yme=function(e,g){return e&&typeof e=="string"&&g.comma&&e.indexOf(",")>-1?e.split(","):e},$De="utf8=%26%2310003%3B",qDe="utf8=%E2%9C%93",exe=function(g,i){var I={__proto__:null},n=i.ignoreQueryPrefix?g.replace(/^\?/,""):g,r=i.parameterLimit===1/0?void 0:i.parameterLimit,C=n.split(i.delimiter,r),o=-1,a,s=i.charset;if(i.charsetSentinel)for(a=0;a-1&&(d=QDe(d)?[d]:d),uM.call(I,u)?I[u]=lb.combine(I[u],d):I[u]=d}return I},txe=function(e,g,i,I){for(var n=I?g:Yme(g,i),r=e.length-1;r>=0;--r){var C,o=e[r];if(o==="[]"&&i.parseArrays)C=[].concat(n);else{C=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===""?C={0:n}:!isNaN(s)&&o!==a&&String(s)===a&&s>=0&&i.parseArrays&&s<=i.arrayLimit?(C=[],C[s]=n):a!=="__proto__"&&(C[a]=n)}n=C}return n},gxe=function(g,i,I,n){if(g){var r=I.allowDots?g.replace(/\.([^.[]+)/g,"[$1]"):g,C=/(\[[^[\]]*])/,o=/(\[[^[\]]*])/g,a=I.depth>0&&C.exec(r),s=a?r.slice(0,a.index):r,A=[];if(s){if(!I.plainObjects&&uM.call(Object.prototype,s)&&!I.allowPrototypes)return;A.push(s)}for(var l=0;I.depth>0&&(a=o.exec(r))!==null&&l"u"?MI.charset:g.charset;return{allowDots:typeof g.allowDots>"u"?MI.allowDots:!!g.allowDots,allowPrototypes:typeof g.allowPrototypes=="boolean"?g.allowPrototypes:MI.allowPrototypes,allowSparse:typeof g.allowSparse=="boolean"?g.allowSparse:MI.allowSparse,arrayLimit:typeof g.arrayLimit=="number"?g.arrayLimit:MI.arrayLimit,charset:i,charsetSentinel:typeof g.charsetSentinel=="boolean"?g.charsetSentinel:MI.charsetSentinel,comma:typeof g.comma=="boolean"?g.comma:MI.comma,decoder:typeof g.decoder=="function"?g.decoder:MI.decoder,delimiter:typeof g.delimiter=="string"||lb.isRegExp(g.delimiter)?g.delimiter:MI.delimiter,depth:typeof g.depth=="number"||g.depth===!1?+g.depth:MI.depth,ignoreQueryPrefix:g.ignoreQueryPrefix===!0,interpretNumericEntities:typeof g.interpretNumericEntities=="boolean"?g.interpretNumericEntities:MI.interpretNumericEntities,parameterLimit:typeof g.parameterLimit=="number"?g.parameterLimit:MI.parameterLimit,parseArrays:g.parseArrays!==!1,plainObjects:typeof g.plainObjects=="boolean"?g.plainObjects:MI.plainObjects,strictNullHandling:typeof g.strictNullHandling=="boolean"?g.strictNullHandling:MI.strictNullHandling}},Ixe=function(e,g){var i=ixe(g);if(e===""||e===null||typeof e>"u")return i.plainObjects?Object.create(null):{};for(var I=typeof e=="string"?exe(e,i):e,n=i.plainObjects?Object.create(null):{},r=Object.keys(I),C=0;C",'"',"`"," ","\r",` +`," "],uxe=["{","}","|","\\","^","`"].concat(cxe),dM=["'"].concat(uxe),Iee=["%","/","?",";","#"].concat(dM),nee=["/","?","#"],dxe=255,ree=/^[+a-z0-9A-Z_-]{0,63}$/,hxe=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,mxe={javascript:!0,"javascript:":!0},hM={javascript:!0,"javascript:":!0},vp={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},mM=oxe;function dT(e,g,i){if(e&&typeof e=="object"&&e instanceof Ia)return e;var I=new Ia;return I.parse(e,g,i),I}Ia.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(ree)){var v=b.slice(0,u),w=b.slice(u+1),R=y.match(hxe);R&&(v.push(R[1]),w.unshift(R[2])),w.length&&(o="/"+w.join(".")+o),this.hostname=v.join(".");break}}}this.hostname.length>dxe?this.hostname="":this.hostname=this.hostname.toLowerCase(),f||(this.hostname=axe.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(!mxe[A])for(var u=0,p=dM.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 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=e.auth||i.auth,i.slashes=i.slashes||e.slashes,i.href=i.format(),i};Ia.prototype.parseHost=function(){var e=this.host,g=sxe.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 bxe=dT,yxe=pxe,Zxe=fxe;/*! * @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 ad={parse:cFe,format:dFe,resolve:uFe};function mo(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function tee(e){var g=e.split("?")[0];return g.split("#")[0]}function hFe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function mFe(e,g,I){return e.replace(new RegExp(hFe(g),"g"),I)}function fFe(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 Rme={toPosix:function(e){return mFe(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){mo(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=tee(this.toPosix(g??Gt.ADAPTER.getBaseUrl())),n=tee(this.toPosix(I??this.rootname(i)));if(mo(e),e=this.toPosix(e),e.startsWith("/"))return Rme.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),mo(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=fFe(e,!1),e.length>0&&i&&(e+="/"),I?"/"+e:g+e},isAbsolute:function(e){return mo(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(mo(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){mo(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){mo(e),g&&mo(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){mo(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){mo(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:":"};Gt.RETINA_PREFIX=/@([0-9\.]+)x/;Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var cM=!1,gee="6.5.10";function pFe(){cM=!0}function Wme(e){var g;if(!cM){if(Gt.ADAPTER.getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){var I=[` - %c %c %c PixiJS `+gee+" - ✰ "+e+` ✰ %c %c http://www.pixijs.com/ %c %c ♥%c♥%c♥ + */var od={parse:bxe,format:Zxe,resolve:yxe};function mo(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function Cee(e){var g=e.split("?")[0];return g.split("#")[0]}function Gxe(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function vxe(e,g,i){return e.replace(new RegExp(Gxe(g),"g"),i)}function Bxe(e,g){for(var i="",I=0,n=-1,r=0,C,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,r=0;continue}}else if(i.length===2||i.length===1){i="",I=0,n=o,r=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,r=0}else C===46&&r!==-1?++r:r=-1}return i}var Kme={toPosix:function(e){return vxe(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){mo(e),e=this.toPosix(e);var g="",i=/^file:\/\/\//.exec(e),I=/^[^/:]+:\/\//.exec(e),n=/^[^/:]+:\//.exec(e);if(i||I||n){var r=(i==null?void 0:i[0])||(I==null?void 0:I[0])||(n==null?void 0:n[0]);g=r,e=e.slice(r.length)}return g},toAbsolute:function(e,g,i){if(this.isDataUrl(e))return e;var I=Cee(this.toPosix(g??Gt.ADAPTER.getBaseUrl())),n=Cee(this.toPosix(i??this.rootname(I)));if(mo(e),e=this.toPosix(e),e.startsWith("/"))return Kme.join(n,e.slice(1));var r=this.isAbsolute(e)?e:this.join(I,e);return r},normalize:function(e){if(e=this.toPosix(e),mo(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=Bxe(e,!1),e.length>0&&I&&(e+="/"),i?"/"+e:g+e},isAbsolute:function(e){return mo(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=C;else{var o=(g=i[r-1])!==null&&g!==void 0?g:"";this.extname(o)?n+="/../"+C:n+="/"+C}}return n===void 0?".":this.normalize(n)},dirname:function(e){if(mo(e),e.length===0)return".";e=this.toPosix(e);var g=e.charCodeAt(0),i=g===47,I=-1,n=!0,r=this.getProtocol(e),C=e;e=e.slice(r.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(C)?r+e:r:i&&I===1?"//":r+e.slice(0,I)},rootname:function(e){mo(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){mo(e),g&&mo(g),e=this.toPosix(e);var i=0,I=-1,n=!0,r;if(g!==void 0&&g.length>0&&g.length<=e.length){if(g.length===e.length&&g===e)return"";var C=g.length-1,o=-1;for(r=e.length-1;r>=0;--r){var a=e.charCodeAt(r);if(a===47){if(!n){i=r+1;break}}else o===-1&&(n=!1,o=r+1),C>=0&&(a===g.charCodeAt(C)?--C===-1&&(I=r):(C=-1,I=o))}return i===I?I=o:I===-1&&(I=e.length),e.slice(i,I)}for(r=e.length-1;r>=0;--r)if(e.charCodeAt(r)===47){if(!n){i=r+1;break}}else I===-1&&(n=!1,I=r+1);return I===-1?"":e.slice(i,I)},extname:function(e){mo(e),e=this.toPosix(e);for(var g=-1,i=0,I=-1,n=!0,r=0,C=e.length-1;C>=0;--C){var o=e.charCodeAt(C);if(o===47){if(!n){i=C+1;break}continue}I===-1&&(n=!1,I=C+1),o===46?g===-1?g=C:r!==1&&(r=1):g!==-1&&(r=-1)}return g===-1||I===-1||r===0||r===1&&g===I-1&&g===i+1?"":e.slice(g,I)},parse:function(e){mo(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 r=-1,C=0,o=-1,a=!0,s=e.length-1,A=0;s>=n;--s){if(i=e.charCodeAt(s),i===47){if(!a){C=s+1;break}continue}o===-1&&(a=!1,o=s+1),i===46?r===-1?r=s:A!==1&&(A=1):r!==-1&&(A=-1)}return r===-1||o===-1||A===0||A===1&&r===o-1&&r===C+1?o!==-1&&(C===0&&I?g.base=g.name=e.slice(1,o):g.base=g.name=e.slice(C,o)):(C===0&&I?(g.name=e.slice(1,r),g.base=e.slice(1,o)):(g.name=e.slice(C,r),g.base=e.slice(C,o)),g.ext=e.slice(r,o)),g.dir=this.dirname(e),g},sep:"/",delimiter:":"};Gt.RETINA_PREFIX=/@([0-9\.]+)x/;Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var fM=!1,oee="6.5.10";function Sxe(){fM=!0}function Fme(e){var g;if(!fM){if(Gt.ADAPTER.getNavigator().userAgent.toLowerCase().indexOf("chrome")>-1){var i=[` + %c %c %c PixiJS `+oee+" - ✰ "+e+` ✰ %c %c http://www.pixijs.com/ %c %c ♥%c♥%c♥ -`,"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 "+gee+" - "+e+" - http://www.pixijs.com/");cM=!0}}var TK;function Xme(){return typeof TK>"u"&&(TK=function(){var g={stencil:!0,failIfMajorPerformanceCaveat:Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!Gt.ADAPTER.getWebGLRenderingContext())return!1;var I=Gt.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}}()),TK}var bFe="#f0f8ff",yFe="#faebd7",ZFe="#00ffff",GFe="#7fffd4",vFe="#f0ffff",BFe="#f5f5dc",SFe="#ffe4c4",wFe="#000000",VFe="#ffebcd",RFe="#0000ff",WFe="#8a2be2",XFe="#a52a2a",HFe="#deb887",TFe="#5f9ea0",NFe="#7fff00",kFe="#d2691e",YFe="#ff7f50",KFe="#6495ed",xFe="#fff8dc",DFe="#dc143c",FFe="#00ffff",EFe="#00008b",MFe="#008b8b",zFe="#b8860b",PFe="#a9a9a9",JFe="#006400",OFe="#a9a9a9",_Fe="#bdb76b",LFe="#8b008b",UFe="#556b2f",QFe="#ff8c00",jFe="#9932cc",$Fe="#8b0000",qFe="#e9967a",eEe="#8fbc8f",tEe="#483d8b",gEe="#2f4f4f",IEe="#2f4f4f",iEe="#00ced1",nEe="#9400d3",CEe="#ff1493",rEe="#00bfff",oEe="#696969",aEe="#696969",AEe="#1e90ff",sEe="#b22222",lEe="#fffaf0",cEe="#228b22",uEe="#ff00ff",dEe="#dcdcdc",hEe="#f8f8ff",mEe="#daa520",fEe="#ffd700",pEe="#808080",bEe="#008000",yEe="#adff2f",ZEe="#808080",GEe="#f0fff0",vEe="#ff69b4",BEe="#cd5c5c",SEe="#4b0082",wEe="#fffff0",VEe="#f0e68c",REe="#fff0f5",WEe="#e6e6fa",XEe="#7cfc00",HEe="#fffacd",TEe="#add8e6",NEe="#f08080",kEe="#e0ffff",YEe="#fafad2",KEe="#d3d3d3",xEe="#90ee90",DEe="#d3d3d3",FEe="#ffb6c1",EEe="#ffa07a",MEe="#20b2aa",zEe="#87cefa",PEe="#778899",JEe="#778899",OEe="#b0c4de",_Ee="#ffffe0",LEe="#00ff00",UEe="#32cd32",QEe="#faf0e6",jEe="#ff00ff",$Ee="#800000",qEe="#66cdaa",eMe="#0000cd",tMe="#ba55d3",gMe="#9370db",IMe="#3cb371",iMe="#7b68ee",nMe="#00fa9a",CMe="#48d1cc",rMe="#c71585",oMe="#191970",aMe="#f5fffa",AMe="#ffe4e1",sMe="#ffe4b5",lMe="#ffdead",cMe="#000080",uMe="#fdf5e6",dMe="#808000",hMe="#6b8e23",mMe="#ffa500",fMe="#ff4500",pMe="#da70d6",bMe="#eee8aa",yMe="#98fb98",ZMe="#afeeee",GMe="#db7093",vMe="#ffefd5",BMe="#ffdab9",SMe="#cd853f",wMe="#ffc0cb",VMe="#dda0dd",RMe="#b0e0e6",WMe="#800080",XMe="#663399",HMe="#ff0000",TMe="#bc8f8f",NMe="#4169e1",kMe="#8b4513",YMe="#fa8072",KMe="#f4a460",xMe="#2e8b57",DMe="#fff5ee",FMe="#a0522d",EMe="#c0c0c0",MMe="#87ceeb",zMe="#6a5acd",PMe="#708090",JMe="#708090",OMe="#fffafa",_Me="#00ff7f",LMe="#4682b4",UMe="#d2b48c",QMe="#008080",jMe="#d8bfd8",$Me="#ff6347",qMe="#40e0d0",e3e="#ee82ee",t3e="#f5deb3",g3e="#ffffff",I3e="#f5f5f5",i3e="#ffff00",n3e="#9acd32",C3e={aliceblue:bFe,antiquewhite:yFe,aqua:ZFe,aquamarine:GFe,azure:vFe,beige:BFe,bisque:SFe,black:wFe,blanchedalmond:VFe,blue:RFe,blueviolet:WFe,brown:XFe,burlywood:HFe,cadetblue:TFe,chartreuse:NFe,chocolate:kFe,coral:YFe,cornflowerblue:KFe,cornsilk:xFe,crimson:DFe,cyan:FFe,darkblue:EFe,darkcyan:MFe,darkgoldenrod:zFe,darkgray:PFe,darkgreen:JFe,darkgrey:OFe,darkkhaki:_Fe,darkmagenta:LFe,darkolivegreen:UFe,darkorange:QFe,darkorchid:jFe,darkred:$Fe,darksalmon:qFe,darkseagreen:eEe,darkslateblue:tEe,darkslategray:gEe,darkslategrey:IEe,darkturquoise:iEe,darkviolet:nEe,deeppink:CEe,deepskyblue:rEe,dimgray:oEe,dimgrey:aEe,dodgerblue:AEe,firebrick:sEe,floralwhite:lEe,forestgreen:cEe,fuchsia:uEe,gainsboro:dEe,ghostwhite:hEe,goldenrod:mEe,gold:fEe,gray:pEe,green:bEe,greenyellow:yEe,grey:ZEe,honeydew:GEe,hotpink:vEe,indianred:BEe,indigo:SEe,ivory:wEe,khaki:VEe,lavenderblush:REe,lavender:WEe,lawngreen:XEe,lemonchiffon:HEe,lightblue:TEe,lightcoral:NEe,lightcyan:kEe,lightgoldenrodyellow:YEe,lightgray:KEe,lightgreen:xEe,lightgrey:DEe,lightpink:FEe,lightsalmon:EEe,lightseagreen:MEe,lightskyblue:zEe,lightslategray:PEe,lightslategrey:JEe,lightsteelblue:OEe,lightyellow:_Ee,lime:LEe,limegreen:UEe,linen:QEe,magenta:jEe,maroon:$Ee,mediumaquamarine:qEe,mediumblue:eMe,mediumorchid:tMe,mediumpurple:gMe,mediumseagreen:IMe,mediumslateblue:iMe,mediumspringgreen:nMe,mediumturquoise:CMe,mediumvioletred:rMe,midnightblue:oMe,mintcream:aMe,mistyrose:AMe,moccasin:sMe,navajowhite:lMe,navy:cMe,oldlace:uMe,olive:dMe,olivedrab:hMe,orange:mMe,orangered:fMe,orchid:pMe,palegoldenrod:bMe,palegreen:yMe,paleturquoise:ZMe,palevioletred:GMe,papayawhip:vMe,peachpuff:BMe,peru:SMe,pink:wMe,plum:VMe,powderblue:RMe,purple:WMe,rebeccapurple:XMe,red:HMe,rosybrown:TMe,royalblue:NMe,saddlebrown:kMe,salmon:YMe,sandybrown:KMe,seagreen:xMe,seashell:DMe,sienna:FMe,silver:EMe,skyblue:MMe,slateblue:zMe,slategray:PMe,slategrey:JMe,snow:OMe,springgreen:_Me,steelblue:LMe,tan:UMe,teal:QMe,thistle:jMe,tomato:$Me,turquoise:qMe,violet:e3e,wheat:t3e,white:g3e,whitesmoke:I3e,yellow:i3e,yellowgreen:n3e};function Ud(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 UL(e){var g=e.toString(16);return g="000000".substring(0,6-g.length)+g,"#"+g}function QL(e){return typeof e=="string"&&(e=C3e[e.toLowerCase()]||e,e[0]==="#"&&(e=e.slice(1))),parseInt(e,16)}function Hme(e){return(e[0]*255<<16)+(e[1]*255<<8)+(e[2]*255|0)}function r3e(){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 jL=r3e();function $L(e,g){return jL[g?1:0][e]}function Tme(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 cT(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 qL(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 Nme(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 uM(e){return!(e&e-1)&&!!e}function dM(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 Rd(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(` +`,"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 "+oee+" - "+e+" - http://www.pixijs.com/");fM=!0}}var YK;function Dme(){return typeof YK>"u"&&(YK=function(){var g={stencil:!0,failIfMajorPerformanceCaveat:Gt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT};try{if(!Gt.ADAPTER.getWebGLRenderingContext())return!1;var i=Gt.ADAPTER.createCanvas(),I=i.getContext("webgl",g)||i.getContext("experimental-webgl",g),n=!!(I&&I.getContextAttributes().stencil);if(I){var r=I.getExtension("WEBGL_lose_context");r&&r.loseContext()}return I=null,n}catch{return!1}}()),YK}var wxe="#f0f8ff",Rxe="#faebd7",Vxe="#00ffff",Wxe="#7fffd4",Xxe="#f0ffff",Hxe="#f5f5dc",Txe="#ffe4c4",Nxe="#000000",kxe="#ffebcd",Yxe="#0000ff",Kxe="#8a2be2",Fxe="#a52a2a",Dxe="#deb887",xxe="#5f9ea0",Exe="#7fff00",Mxe="#d2691e",zxe="#ff7f50",Pxe="#6495ed",Jxe="#fff8dc",Oxe="#dc143c",_xe="#00ffff",Lxe="#00008b",Uxe="#008b8b",Qxe="#b8860b",jxe="#a9a9a9",$xe="#006400",qxe="#a9a9a9",eEe="#bdb76b",tEe="#8b008b",gEe="#556b2f",iEe="#ff8c00",IEe="#9932cc",nEe="#8b0000",rEe="#e9967a",CEe="#8fbc8f",oEe="#483d8b",aEe="#2f4f4f",AEe="#2f4f4f",sEe="#00ced1",lEe="#9400d3",cEe="#ff1493",uEe="#00bfff",dEe="#696969",hEe="#696969",mEe="#1e90ff",fEe="#b22222",pEe="#fffaf0",bEe="#228b22",yEe="#ff00ff",ZEe="#dcdcdc",GEe="#f8f8ff",vEe="#daa520",BEe="#ffd700",SEe="#808080",wEe="#008000",REe="#adff2f",VEe="#808080",WEe="#f0fff0",XEe="#ff69b4",HEe="#cd5c5c",TEe="#4b0082",NEe="#fffff0",kEe="#f0e68c",YEe="#fff0f5",KEe="#e6e6fa",FEe="#7cfc00",DEe="#fffacd",xEe="#add8e6",EEe="#f08080",MEe="#e0ffff",zEe="#fafad2",PEe="#d3d3d3",JEe="#90ee90",OEe="#d3d3d3",_Ee="#ffb6c1",LEe="#ffa07a",UEe="#20b2aa",QEe="#87cefa",jEe="#778899",$Ee="#778899",qEe="#b0c4de",eMe="#ffffe0",tMe="#00ff00",gMe="#32cd32",iMe="#faf0e6",IMe="#ff00ff",nMe="#800000",rMe="#66cdaa",CMe="#0000cd",oMe="#ba55d3",aMe="#9370db",AMe="#3cb371",sMe="#7b68ee",lMe="#00fa9a",cMe="#48d1cc",uMe="#c71585",dMe="#191970",hMe="#f5fffa",mMe="#ffe4e1",fMe="#ffe4b5",pMe="#ffdead",bMe="#000080",yMe="#fdf5e6",ZMe="#808000",GMe="#6b8e23",vMe="#ffa500",BMe="#ff4500",SMe="#da70d6",wMe="#eee8aa",RMe="#98fb98",VMe="#afeeee",WMe="#db7093",XMe="#ffefd5",HMe="#ffdab9",TMe="#cd853f",NMe="#ffc0cb",kMe="#dda0dd",YMe="#b0e0e6",KMe="#800080",FMe="#663399",DMe="#ff0000",xMe="#bc8f8f",EMe="#4169e1",MMe="#8b4513",zMe="#fa8072",PMe="#f4a460",JMe="#2e8b57",OMe="#fff5ee",_Me="#a0522d",LMe="#c0c0c0",UMe="#87ceeb",QMe="#6a5acd",jMe="#708090",$Me="#708090",qMe="#fffafa",e3e="#00ff7f",t3e="#4682b4",g3e="#d2b48c",i3e="#008080",I3e="#d8bfd8",n3e="#ff6347",r3e="#40e0d0",C3e="#ee82ee",o3e="#f5deb3",a3e="#ffffff",A3e="#f5f5f5",s3e="#ffff00",l3e="#9acd32",c3e={aliceblue:wxe,antiquewhite:Rxe,aqua:Vxe,aquamarine:Wxe,azure:Xxe,beige:Hxe,bisque:Txe,black:Nxe,blanchedalmond:kxe,blue:Yxe,blueviolet:Kxe,brown:Fxe,burlywood:Dxe,cadetblue:xxe,chartreuse:Exe,chocolate:Mxe,coral:zxe,cornflowerblue:Pxe,cornsilk:Jxe,crimson:Oxe,cyan:_xe,darkblue:Lxe,darkcyan:Uxe,darkgoldenrod:Qxe,darkgray:jxe,darkgreen:$xe,darkgrey:qxe,darkkhaki:eEe,darkmagenta:tEe,darkolivegreen:gEe,darkorange:iEe,darkorchid:IEe,darkred:nEe,darksalmon:rEe,darkseagreen:CEe,darkslateblue:oEe,darkslategray:aEe,darkslategrey:AEe,darkturquoise:sEe,darkviolet:lEe,deeppink:cEe,deepskyblue:uEe,dimgray:dEe,dimgrey:hEe,dodgerblue:mEe,firebrick:fEe,floralwhite:pEe,forestgreen:bEe,fuchsia:yEe,gainsboro:ZEe,ghostwhite:GEe,goldenrod:vEe,gold:BEe,gray:SEe,green:wEe,greenyellow:REe,grey:VEe,honeydew:WEe,hotpink:XEe,indianred:HEe,indigo:TEe,ivory:NEe,khaki:kEe,lavenderblush:YEe,lavender:KEe,lawngreen:FEe,lemonchiffon:DEe,lightblue:xEe,lightcoral:EEe,lightcyan:MEe,lightgoldenrodyellow:zEe,lightgray:PEe,lightgreen:JEe,lightgrey:OEe,lightpink:_Ee,lightsalmon:LEe,lightseagreen:UEe,lightskyblue:QEe,lightslategray:jEe,lightslategrey:$Ee,lightsteelblue:qEe,lightyellow:eMe,lime:tMe,limegreen:gMe,linen:iMe,magenta:IMe,maroon:nMe,mediumaquamarine:rMe,mediumblue:CMe,mediumorchid:oMe,mediumpurple:aMe,mediumseagreen:AMe,mediumslateblue:sMe,mediumspringgreen:lMe,mediumturquoise:cMe,mediumvioletred:uMe,midnightblue:dMe,mintcream:hMe,mistyrose:mMe,moccasin:fMe,navajowhite:pMe,navy:bMe,oldlace:yMe,olive:ZMe,olivedrab:GMe,orange:vMe,orangered:BMe,orchid:SMe,palegoldenrod:wMe,palegreen:RMe,paleturquoise:VMe,palevioletred:WMe,papayawhip:XMe,peachpuff:HMe,peru:TMe,pink:NMe,plum:kMe,powderblue:YMe,purple:KMe,rebeccapurple:FMe,red:DMe,rosybrown:xMe,royalblue:EMe,saddlebrown:MMe,salmon:zMe,sandybrown:PMe,seagreen:JMe,seashell:OMe,sienna:_Me,silver:LMe,skyblue:UMe,slateblue:QMe,slategray:jMe,slategrey:$Me,snow:qMe,springgreen:e3e,steelblue:t3e,tan:g3e,teal:i3e,thistle:I3e,tomato:n3e,turquoise:r3e,violet:C3e,wheat:o3e,white:a3e,whitesmoke:A3e,yellow:s3e,yellowgreen:l3e};function Ld(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 tU(e){var g=e.toString(16);return g="000000".substring(0,6-g.length)+g,"#"+g}function gU(e){return typeof e=="string"&&(e=c3e[e.toLowerCase()]||e,e[0]==="#"&&(e=e.slice(1))),parseInt(e,16)}function xme(e){return(e[0]*255<<16)+(e[1]*255<<8)+(e[2]*255|0)}function u3e(){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 iU=u3e();function IU(e,g){return iU[g?1:0][e]}function Eme(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 hT(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 nU(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 Mme(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 pM(e){return!(e&e-1)&&!!e}function bM(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 Rd(e,g,i){var I=e.length,n;if(!(g>=I||i===0)){i=g+i>I?I-g:i;var r=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))),Iee[g]=!0}}var hM={},VC=Object.create(null),Nr=Object.create(null);function s3e(){var e;for(e in VC)VC[e].destroy();for(e in Nr)Nr[e].destroy()}function l3e(){var e;for(e in VC)delete VC[e];for(e in Nr)delete Nr[e]}var mM=function(){function e(g,I,i){this.canvas=Gt.ADAPTER.createCanvas(),this.context=this.canvas.getContext("2d"),this.resolution=i||Gt.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 kme(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=bV[0].set(g.left,g.top),c=bV[1].set(g.left,g.bottom),u=bV[2].set(g.right,g.top),d=bV[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}(),Fme=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=Xi.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 wg(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}(),Eme=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=Xi.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 wg(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}(),xG=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}(),Mme=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=Xi.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}(),sd=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}(),Zi=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 aI;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 aI;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(sB-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}(),Pu=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Ju=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Ou=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],_u=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],fM=[],zme=[],yV=Math.sign;function d3e(){for(var e=0;e<16;e++){var g=[];fM.push(g);for(var I=0;I<16;I++)for(var i=yV(Pu[e]*Pu[I]+Ou[e]*Ju[I]),n=yV(Ju[e]*Pu[I]+_u[e]*Ju[I]),C=yV(Pu[e]*Ou[I]+Ou[e]*_u[I]),r=yV(Ju[e]*Ou[I]+_u[e]*_u[I]),o=0;o<16;o++)if(Pu[o]===i&&Ju[o]===n&&Ou[o]===C&&_u[o]===r){g.push(o);break}}for(var e=0;e<16;e++){var a=new Zi;a.set(Pu[e],Ju[e],Ou[e],_u[e],0,0),zme.push(a)}}d3e();var wI={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 Pu[e]},uY:function(e){return Ju[e]},vX:function(e){return Ou[e]},vY:function(e){return _u[e]},inv:function(e){return e&8?e&15:-e&7},add:function(e,g){return fM[e][g]},sub:function(e,g){return fM[e][wI.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?wI.S:wI.N:Math.abs(g)*2<=Math.abs(e)?e>0?wI.E:wI.W:g>0?e>0?wI.SE:wI.SW:e>0?wI.NE:wI.NW},matrixAppendRotationInv:function(e,g,I,i){I===void 0&&(I=0),i===void 0&&(i=0);var n=zme[wI.inv(g)];n.tx=I,n.ty=i,e.append(n)}},eU=function(){function e(){this.worldTransform=new Zi,this.localTransform=new Zi,this.position=new sd(this.onChange,this,0,0),this.scale=new sd(this.onChange,this,1,1),this.pivot=new sd(this.onChange,this,0,0),this.skew=new sd(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}();/*! + */var uB=Math.PI*2,Ome=180/Math.PI,_me=Math.PI/180,XI;(function(e){e[e.POLY=0]="POLY",e[e.RECT=1]="RECT",e[e.CIRC=2]="CIRC",e[e.ELIP=3]="ELIP",e[e.RREC=4]="RREC"})(XI||(XI={}));var ai=function(){function e(g,i){g===void 0&&(g=0),i===void 0&&(i=0),this.x=0,this.y=0,this.x=g,this.y=i}return e.prototype.clone=function(){return new e(this.x,this.y)},e.prototype.copyFrom=function(g){return this.set(g.x,g.y),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.set=function(g,i){return g===void 0&&(g=0),i===void 0&&(i=g),this.x=g,this.y=i,this},e.prototype.toString=function(){return"[@pixi/math:Point x="+this.x+" y="+this.y+"]"},e}(),GR=[new ai,new ai,new ai,new ai],wg=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=Number(g),this.y=Number(i),this.width=Number(I),this.height=Number(n),this.type=XI.RECT}return Object.defineProperty(e.prototype,"left",{get:function(){return this.x},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"right",{get:function(){return this.x+this.width},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"top",{get:function(){return this.y},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bottom",{get:function(){return this.y+this.height},enumerable:!1,configurable:!0}),Object.defineProperty(e,"EMPTY",{get:function(){return new e(0,0,0,0)},enumerable:!1,configurable:!0}),e.prototype.clone=function(){return new e(this.x,this.y,this.width,this.height)},e.prototype.copyFrom=function(g){return this.x=g.x,this.y=g.y,this.width=g.width,this.height=g.height,this},e.prototype.copyTo=function(g){return g.x=this.x,g.y=this.y,g.width=this.width,g.height=this.height,g},e.prototype.contains=function(g,i){return this.width<=0||this.height<=0?!1:g>=this.x&&g=this.y&&ig.right?g.right:this.right;if(n<=I)return!1;var r=this.yg.bottom?g.bottom:this.bottom;return C>r}var o=this.left,a=this.right,s=this.top,A=this.bottom;if(a<=o||A<=s)return!1;var l=GR[0].set(g.left,g.top),c=GR[1].set(g.left,g.bottom),u=GR[2].set(g.right,g.top),d=GR[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,R=B*o+G*A,S=B*a+G*A;return!(Math.max(v,w,R,S)<=B*l.x+G*l.y||Math.min(v,w,R,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),r=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(r-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),r=Math.max(this.y+this.height,g.y+g.height);return this.x=i,this.width=I-i,this.y=n,this.height=r-n,this},e.prototype.toString=function(){return"[@pixi/math:Rectangle x="+this.x+" y="+this.y+" width="+this.width+" height="+this.height+"]"},e}(),Lme=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=XI.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,r=this.y-i;return n*=n,r*=r,n+r<=I},e.prototype.getBounds=function(){return new wg(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}(),Ume=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=XI.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 wg(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}(),FG=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}(),Qme=function(){function e(g,i,I,n,r){g===void 0&&(g=0),i===void 0&&(i=0),I===void 0&&(I=0),n===void 0&&(n=0),r===void 0&&(r=20),this.x=g,this.y=i,this.width=I,this.height=n,this.radius=r,this.type=XI.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),r=i-(this.y+I),C=I*I;if(n*n+r*r<=C||(n=g-(this.x+this.width-I),n*n+r*r<=C)||(r=i-(this.y+this.height-I),n*n+r*r<=C)||(n=g-(this.x+I),n*n+r*r<=C))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}(),Ad=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}(),ZI=function(){function e(g,i,I,n,r,C){g===void 0&&(g=1),i===void 0&&(i=0),I===void 0&&(I=0),n===void 0&&(n=1),r===void 0&&(r=0),C===void 0&&(C=0),this.array=null,this.a=g,this.b=i,this.c=I,this.d=n,this.tx=r,this.ty=C}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,r,C){return this.a=g,this.b=i,this.c=I,this.d=n,this.tx=r,this.ty=C,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 ai;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 ai;var I=1/(this.a*this.d+this.c*-this.b),n=g.x,r=g.y;return i.x=this.d*I*n+-this.c*I*r+(this.ty*this.c-this.tx*this.d)*I,i.y=this.a*I*r+-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,r=this.c,C=this.tx;return this.a=n*i-this.b*I,this.b=n*I+this.b*i,this.c=r*i-this.d*I,this.d=r*I+this.d*i,this.tx=C*i-this.ty*I,this.ty=C*I+this.ty*i,this},e.prototype.append=function(g){var i=this.a,I=this.b,n=this.c,r=this.d;return this.a=g.a*i+g.b*n,this.b=g.a*I+g.b*r,this.c=g.c*i+g.d*n,this.d=g.c*I+g.d*r,this.tx=g.tx*i+g.ty*n+this.tx,this.ty=g.tx*I+g.ty*r+this.ty,this},e.prototype.setTransform=function(g,i,I,n,r,C,o,a,s){return this.a=Math.cos(o+s)*r,this.b=Math.sin(o+s)*r,this.c=-Math.sin(o-a)*C,this.d=Math.cos(o-a)*C,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,r=this.d,C=g.pivot,o=-Math.atan2(-n,r),a=Math.atan2(I,i),s=Math.abs(o+a);return s<1e-5||Math.abs(uB-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+r*r),g.position.x=this.tx+(C.x*i+C.y*n),g.position.y=this.ty+(C.x*I+C.y*r),g},e.prototype.invert=function(){var g=this.a,i=this.b,I=this.c,n=this.d,r=this.tx,C=g*n-i*I;return this.a=n/C,this.b=-i/C,this.c=-I/C,this.d=g/C,this.tx=(I*this.ty-n*r)/C,this.ty=-(g*this.ty-i*r)/C,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}(),zu=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Pu=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Ju=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Ou=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],GM=[],jme=[],vR=Math.sign;function Z3e(){for(var e=0;e<16;e++){var g=[];GM.push(g);for(var i=0;i<16;i++)for(var I=vR(zu[e]*zu[i]+Ju[e]*Pu[i]),n=vR(Pu[e]*zu[i]+Ou[e]*Pu[i]),r=vR(zu[e]*Ju[i]+Ju[e]*Ou[i]),C=vR(Pu[e]*Ju[i]+Ou[e]*Ou[i]),o=0;o<16;o++)if(zu[o]===I&&Pu[o]===n&&Ju[o]===r&&Ou[o]===C){g.push(o);break}}for(var e=0;e<16;e++){var a=new ZI;a.set(zu[e],Pu[e],Ju[e],Ou[e],0,0),jme.push(a)}}Z3e();var wi={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 zu[e]},uY:function(e){return Pu[e]},vX:function(e){return Ju[e]},vY:function(e){return Ou[e]},inv:function(e){return e&8?e&15:-e&7},add:function(e,g){return GM[e][g]},sub:function(e,g){return GM[e][wi.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?wi.S:wi.N:Math.abs(g)*2<=Math.abs(e)?e>0?wi.E:wi.W:g>0?e>0?wi.SE:wi.SW:e>0?wi.NE:wi.NW},matrixAppendRotationInv:function(e,g,i,I){i===void 0&&(i=0),I===void 0&&(I=0);var n=jme[wi.inv(g)];n.tx=i,n.ty=I,e.append(n)}},rU=function(){function e(){this.worldTransform=new ZI,this.localTransform=new ZI,this.position=new Ad(this.onChange,this,0,0),this.scale=new Ad(this.onChange,this,1,1),this.pivot=new Ad(this.onChange,this,0,0),this.skew=new Ad(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 - */Gt.SORTABLE_CHILDREN=!1;var lB=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?wg.EMPTY:(g=g||new wg(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}();/*! ***************************************************************************** + */Gt.SORTABLE_CHILDREN=!1;var dB=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?wg.EMPTY:(g=g||new wg(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,r=g.c,C=g.d,o=g.tx,a=g.ty,s=I*i.x+r*i.y+o,A=n*i.x+C*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,r=this.maxY,C=g[0],o=g[1];i=Cn?C:n,r=o>r?o:r,C=g[2],o=g[3],i=Cn?C:n,r=o>r?o:r,C=g[4],o=g[5],i=Cn?C:n,r=o>r?o:r,C=g[6],o=g[7],i=Cn?C:n,r=o>r?o:r,this.minX=i,this.minY=I,this.maxX=n,this.maxY=r},e.prototype.addFrame=function(g,i,I,n,r){this.addFrameMatrix(g.worldTransform,i,I,n,r)},e.prototype.addFrameMatrix=function(g,i,I,n,r){var C=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=C*i+a*I+A,f=o*i+s*I+l;c=md?m:d,h=f>h?f:h,m=C*n+a*I+A,f=o*n+s*I+l,c=md?m:d,h=f>h?f:h,m=C*i+a*r+A,f=o*i+s*r+l,c=md?m:d,h=f>h?f:h,m=C*n+a*r+A,f=o*n+s*r+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,r=this.minY,C=this.maxX,o=this.maxY,a=i;aC?s:C,o=A>o?A:o}this.minX=n,this.minY=r,this.maxX=C,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,r,C){r===void 0&&(r=0),C===void 0&&(C=r);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>r?g.maxY:r},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,r=g.maxXs?r:s,this.maxY=C>A?C: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,r=g.maxXs?r:s,this.maxY=C>A?C: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,r,C){g-=r,i-=C,I+=r,n+=C,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 @@ -102,7 +102,7 @@ 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 pM=function(e,g){return pM=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])},pM(e,g)};function tU(e,g){pM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var $I=function(e){tU(g,e);function g(){var I=e.call(this)||this;return I.tempDisplayObjectParent=null,I.transform=new eU,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 lB,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);Rd(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(h3e),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;r1)for(var r=0;rthis.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),r=this.getChildIndex(I);this.children[n]=I,this.children[r]=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);Rd(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 r=0;r0&&C<=r){o=this.children.splice(n,C);for(var a=0;a1&&this.children.sort(G3e),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,r;if(this.cullArea?(n=this.cullArea,r=this.worldTransform):this._render!==g.prototype._render&&(n=this.getBounds(!0)),n&&I.intersects(n,r))this._render(i);else if(this.cullArea)return;for(var C=0,o=this.children.length;C8)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(Li.prototype,{dispatch:{value:Li.prototype.emit},run:{value:Li.prototype.emit}});/*! + */var LI=function(){function e(g){this.items=[],this._name=g,this._aliasCount=0}return e.prototype.emit=function(g,i,I,n,r,C,o,a){if(arguments.length>8)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(LI.prototype,{dispatch:{value:LI.prototype.emit},run:{value:LI.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 - */Gt.TARGET_FPMS=.06;var fA;(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"})(fA||(fA={}));var NK=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}(),Ui=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 NK(null,null,1/0),this.deltaMS=1/Gt.TARGET_FPMS,this.elapsedMS=1/Gt.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=fA.NORMAL),this._addListener(new NK(g,I,i))},e.prototype.addOnce=function(g,I,i){return i===void 0&&(i=fA.NORMAL),this._addListener(new NK(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(ii.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=cB[n];if(C.test&&C.test(e,I))return new C(e,g)}throw new Error("Unrecognized source type to auto-detect Resource")}/*! ***************************************************************************** + */Gt.PREFER_ENV=OC.any?mA.WEBGL:mA.WEBGL2;Gt.STRICT_TEXTURE_CACHE=!1;var hB=[];function fT(e,g){if(!e)return null;var i="";if(typeof e=="string"){var I=/\.(\w{3,4})(?:$|\?|#)/i.exec(e);I&&(i=I[1].toLowerCase())}for(var n=hB.length-1;n>=0;--n){var r=hB[n];if(r.test&&r.test(e,i))return new r(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 @@ -152,11 +152,11 @@ 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 bM=function(e,g){return bM=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])},bM(e,g)};function AI(e,g){bM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var yM=function(){return yM=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=uM(this.realWidth)&&uM(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 Nr[this.cacheId],delete VC[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=Gt.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+"_"+Pc()}r=I._pixiId}var a=Nr[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 Lh(I,{width:i,height:n}),o=I instanceof Float32Array?Et.FLOAT:Et.UNSIGNED_BYTE;return new g(r,Object.assign({},f3e,C||{width:i,height:n,type:o}))},g.addToCache=function(I,i){i&&(I.textureCacheIds.indexOf(i)===-1&&I.textureCacheIds.push(i),Nr[i]&&console.warn("BaseTexture added to the cache with an id ["+i+"] that already had an entry"),Nr[i]=I)},g.removeFromCache=function(I){if(typeof I=="string"){var i=Nr[I];if(i){var n=i.textureCacheIds.indexOf(I);return n>-1&&i.textureCacheIds.splice(n,1),delete Nr[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=Wc.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}(pA),rU=function(e){AI(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];pA.crossOrigin(C,r,i.crossorigin);for(var o=0;o2},g.prototype._onPlayStart=function(){this.valid||this._onCanPlay(),this.autoUpdate&&!this._isConnectedToTicker&&(Ui.shared.add(this.update,this),this._isConnectedToTicker=!0)},g.prototype._onPlayStop=function(){this._isConnectedToTicker&&(Ui.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&&(Ui.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?(Ui.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._isSourcePlaying()&&(Ui.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}(pA),oU=function(e){AI(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}(pA);cB.push(mT,oU,iU,rU,CU,Lh,nU,IU);var Jme={__proto__:null,Resource:Qd,BaseImageResource:pA,INSTALLED:cB,autoDetectResource:dT,AbstractMultiResource:hT,ArrayResource:IU,BufferResource:Lh,CanvasResource:iU,CubeResource:nU,ImageResource:mT,SVGResource:CU,VideoResource:rU,ImageBitmapResource:oU},p3e=function(e){AI(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===no.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}(Lh),pX=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 Li("disposeFramebuffer"),this.multisample=fI.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 Gg(null,{scaleMode:Qo.NEAREST,resolution:1,mipmap:io.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this},e.prototype.addDepthTexture=function(g){return this.depthTexture=g||new Gg(new p3e(null,{width:this.width,height:this.height}),{scaleMode:Qo.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:io.OFF,format:ft.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 VC[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 Gg),ZV(g._EMPTY),ZV(g._EMPTY.baseTexture)),g._EMPTY},enumerable:!1,configurable:!0}),Object.defineProperty(g,"WHITE",{get:function(){if(!g._WHITE){var I=Gt.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(Gg.from(I)),ZV(g._WHITE),ZV(g._WHITE.baseTexture)}return g._WHITE},enumerable:!1,configurable:!0}),g}(v0),Ys=function(e){AI(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||fI.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,Dr.CLEAR,I);var u=A;A=l,l=u}i[c].apply(this,A,s.renderTexture,Dr.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=Dr.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===Dr.CLEAR||I===Dr.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(Or.TRIANGLES)):(C.geometry.bind(this.quad),C.geometry.draw(Or.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(Zi.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=fI.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||fI.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?kK.copyFrom(C):kK.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}(),BS=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}(),cU=function(){function e(g){this.renderer=g,this.emptyRenderer=new BS(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=mA.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}(),Ume=function(){function e(g){this.framebuffer=g,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=fI.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}return e}(),S3e=new wg,dU=function(){function e(g){this.renderer=g,this.managedFramebuffers=[],this.unknownFramebuffer=new pX(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 wg,this.hasMRT=!0,this.writeDepthTexture=!0,this.renderer.context.webGLVersion===1){var I=this.renderer.context.extensions.drawBuffers,i=this.renderer.context.extensions.depthTexture;Gt.PREFER_ENV===mA.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=IB.COLOR|IB.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 Ume(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=fI.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=mA.WEBGL2&&(g=e.getContext("webgl2",{})),g||(g=e.getContext("webgl",{})||e.getContext("experimental-webgl",{}),g?g.getExtension("WEBGL_draw_buffers"):g=null),Wy=g}return Wy}var vV;function V3e(){if(!vV){vV=YC.MEDIUM;var e=qme();if(e&&e.getShaderPrecisionFormat){var g=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT);vV=g.precision?YC.HIGH:YC.MEDIUM}}return vV}function Aee(e,g,I){if(e.substring(0,9)!=="precision"){var i=g;return g===YC.HIGH&&I!==YC.HIGH&&(i=YC.MEDIUM),"precision "+i+` float; -`+e}else if(I!==YC.HIGH&&e.substring(0,15)==="precision highp")return e.replace("precision highp","precision mediump");return e}var R3e={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 efe(e){return R3e[e]}var BV=null,see={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 tfe(e,g){if(!BV){var I=Object.keys(see);BV={};for(var i=0;i0&&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=pM(this.realWidth)&&pM(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 TC[this.cacheId],delete wr[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=Gt.STRICT_TEXTURE_CACHE);var r=typeof i=="string",C=null;if(r)C=i;else{if(!i._pixiId){var o=I&&I.pixiIdPrefix||"pixiid";i._pixiId=o+"_"+zc()}C=i._pixiId}var a=TC[C];if(r&&n&&!a)throw new Error('The cacheId "'+C+'" does not exist in BaseTextureCache.');return a||(a=new g(i,I),a.cacheId=C,g.addToCache(a,C)),a},g.fromBuffer=function(i,I,n,r){i=i||new Float32Array(I*n*4);var C=new _h(i,{width:I,height:n}),o=i instanceof Float32Array?Et.FLOAT:Et.UNSIGNED_BYTE;return new g(C,Object.assign({},B3e,r||{width:I,height:n,type:o}))},g.addToCache=function(i,I){I&&(i.textureCacheIds.indexOf(I)===-1&&i.textureCacheIds.push(I),TC[I]&&console.warn("BaseTexture added to the cache with an id ["+I+"] that already had an entry"),TC[I]=i)},g.removeFromCache=function(i){if(typeof i=="string"){var I=TC[i];if(I){var n=I.textureCacheIds.indexOf(i);return n>-1&&I.textureCacheIds.splice(n,1),delete TC[i],I}}else if(i&&i.textureCacheIds){for(var r=0;r0)if(i.resource)this.addResourceAt(i.resource,I);else throw new Error("CubeResource does not support copying of renderTexture.");else i.target=Wc.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 r=this.itemDirtyIds,C=0;C)?\s*()]*-->)?\s*\]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i,g}(pA),cU=function(e){Ai(g,e);function g(i,I){var n=this;if(I=I||{},!(i instanceof HTMLVideoElement)){var r=document.createElement("video");r.setAttribute("preload","auto"),r.setAttribute("webkit-playsinline",""),r.setAttribute("playsinline",""),typeof i=="string"&&(i=[i]);var C=i[0].src||i[0];pA.crossOrigin(r,C,I.crossorigin);for(var o=0;o2},g.prototype._onPlayStart=function(){this.valid||this._onCanPlay(),this.autoUpdate&&!this._isConnectedToTicker&&(UI.shared.add(this.update,this),this._isConnectedToTicker=!0)},g.prototype._onPlayStop=function(){this._isConnectedToTicker&&(UI.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&&(UI.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?(UI.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._isSourcePlaying()&&(UI.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}(pA),uU=function(e){Ai(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}(pA);hB.push(bT,uU,AU,cU,lU,_h,sU,aU);var qme={__proto__:null,Resource:Ud,BaseImageResource:pA,INSTALLED:hB,autoDetectResource:fT,AbstractMultiResource:pT,ArrayResource:aU,BufferResource:_h,CanvasResource:AU,CubeResource:sU,ImageResource:bT,SVGResource:lU,VideoResource:cU,ImageBitmapResource:uU},S3e=function(e){Ai(g,e);function g(){return e!==null&&e.apply(this,arguments)||this}return g.prototype.upload=function(i,I,n){var r=i.gl;r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,I.alphaMode===no.UNPACK);var C=I.realWidth,o=I.realHeight;return n.width===C&&n.height===o?r.texSubImage2D(I.target,0,0,0,C,o,I.format,n.type,this.data):(n.width=C,n.height=o,r.texImage2D(I.target,0,n.internalFormat,C,o,0,I.format,n.type,this.data)),!0},g}(_h),Z9=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 LI("disposeFramebuffer"),this.multisample=fi.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 Gg(null,{scaleMode:Qo.NEAREST,resolution:1,mipmap:Io.OFF,width:this.width,height:this.height}),this.dirtyId++,this.dirtyFormat++,this},e.prototype.addDepthTexture=function(g){return this.depthTexture=g||new Gg(new S3e(null,{width:this.width,height:this.height}),{scaleMode:Qo.NEAREST,resolution:1,width:this.width,height:this.height,mipmap:Io.OFF,format:ft.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 wr[i],I}}else if(i&&i.textureCacheIds){for(var r=0;rthis.baseTexture.width,a=n+C>this.baseTexture.height;if(o||a){var s=o&&a?"and":"or",A="X: "+I+" + "+r+" = "+(I+r)+" > "+this.baseTexture.width,l="Y: "+n+" + "+C+" = "+(n+C)+" > "+this.baseTexture.height;throw new Error("Texture Error: frame does not fit inside the base Texture dimensions: "+(A+" "+s+" "+l))}this.valid=r&&C&&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 Gg),BR(g._EMPTY),BR(g._EMPTY.baseTexture)),g._EMPTY},enumerable:!1,configurable:!0}),Object.defineProperty(g,"WHITE",{get:function(){if(!g._WHITE){var i=Gt.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(Gg.from(i)),BR(g._WHITE),BR(g._WHITE.baseTexture)}return g._WHITE},enumerable:!1,configurable:!0}),g}(B0),Ys=function(e){Ai(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 r=this.baseTexture.resolution,C=Math.round(i*r)/r,o=Math.round(I*r)/r;this.valid=C>0&&o>0,this._frame.width=this.orig.width=C,this._frame.height=this.orig.height=o,n&&this.baseTexture.resize(C,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=[],r=1;r>>0,n>1&&(r+=n*4294967296)):r=n>1?-n:-1,this.texturePool[r]||(this.texturePool[r]=[]);var C=this.texturePool[r].pop();return C||(C=this.createTexture(g,i,n)),C.filterPoolKey=r,C.setResolution(I),C},e.prototype.getFilterTexture=function(g,i,I){var n=this.getOptimalTexture(g.width,g.height,i||g.resolution,I||fi.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,FC.CLEAR,i);var u=A;A=l,l=u}I[c].apply(this,A,s.renderTexture,FC.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=FC.CLEAR);var I=this.renderer,n=I.renderTexture,r=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 C=this.tempRect;C.x=0,C.y=0,C.width=g.filterFrame.width,C.height=g.filterFrame.height,n.bind(g,g.filterFrame,C)}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=r.stateId&1||this.forceClear;(i===FC.CLEAR||i===FC.BLIT&&o)&&this.renderer.framebuffer.clear(0,0,0,0)},e.prototype.applyFilter=function(g,i,I,n){var r=this.renderer;r.state.set(g.state),this.bindAndClear(I,n),g.uniforms.uSampler=i,g.uniforms.filterGlobals=this.globalUniforms,r.shader.bind(g),g.legacy=!!g.program.attributeData.aTextureCoord,g.legacy?(this.quadUv.map(i._frame,i.filterFrame),r.geometry.bind(this.quadUv),r.geometry.draw(JC.TRIANGLES)):(r.geometry.bind(this.quad),r.geometry.draw(JC.TRIANGLE_STRIP))},e.prototype.calculateSpriteMatrix=function(g,i){var I=this.activeState,n=I.sourceFrame,r=I.destinationFrame,C=i._texture.orig,o=g.set(r.width,0,0,r.height,n.x,n.y),a=i.worldTransform.copyTo(ZI.TEMP_MATRIX);return a.invert(),o.prepend(a),o.scale(1/C.width,1/C.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=fi.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 r=this.texturePool.getOptimalTexture(g.width,g.height,i||g.resolution,I||fi.NONE);return r.filterFrame=g.filterFrame,r},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=SR[0],n=SR[1],r=SR[2],C=SR[3];I.set(i.left,i.top),n.set(i.left,i.bottom),r.set(i.right,i.top),C.set(i.right,i.bottom),g.apply(I,I),g.apply(n,n),g.apply(r,r),g.apply(C,C);var o=Math.min(I.x,n.x,r.x,C.x),a=Math.min(I.y,n.y,r.y,C.y),s=Math.max(I.x,n.x,r.x,C.x),A=Math.max(I.y,n.y,r.y,C.y);i.x=o,i.y=a,i.width=s-o,i.height=A-a},e.prototype.roundFrame=function(g,i,I,n,r){if(!(g.width<=0||g.height<=0||I.width<=0||I.height<=0)){if(r){var C=r.a,o=r.b,a=r.c,s=r.d;if((Math.abs(o)>1e-4||Math.abs(a)>1e-4)&&(Math.abs(C)>1e-4||Math.abs(s)>1e-4))return}r=r?FK.copyFrom(r):FK.identity(),r.translate(-I.x,-I.y).scale(n.width/I.width,n.height/I.height).translate(n.x,n.y),this.transformAABB(r,g),g.ceil(i),this.transformAABB(r.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}(),pU=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 r=g.elements,C=g.ids,o=g.count,a=0,s=0;s=0&&l=mA.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}(),ife=function(){function e(g){this.framebuffer=g,this.stencil=null,this.dirtyId=-1,this.dirtyFormat=-1,this.dirtySize=-1,this.multisample=fi.NONE,this.msaaBuffer=null,this.blitFramebuffer=null,this.mipLevel=0}return e}(),T3e=new wg,yU=function(){function e(g){this.renderer=g,this.managedFramebuffers=[],this.unknownFramebuffer=new Z9(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 wg,this.hasMRT=!0,this.writeDepthTexture=!0,this.renderer.context.webGLVersion===1){var i=this.renderer.context.extensions.drawBuffers,I=this.renderer.context.extensions.depthTexture;Gt.PREFER_ENV===mA.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 r=g.glFramebuffers[this.CONTEXT_UID]||this.initFramebuffer(g);this.current!==g&&(this.current=g,n.bindFramebuffer(n.FRAMEBUFFER,r.framebuffer)),r.mipLevel!==I&&(g.dirtyId++,g.dirtyFormat++,r.mipLevel=I),r.dirtyId!==g.dirtyId&&(r.dirtyId=g.dirtyId,r.dirtyFormat!==g.dirtyFormat?(r.dirtyFormat=g.dirtyFormat,r.dirtySize=g.dirtySize,this.updateFramebuffer(g,I)):r.dirtySize!==g.dirtySize&&(r.dirtySize=g.dirtySize,this.resizeFramebuffer(g)));for(var C=0;C>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 r=this.viewport;g=Math.round(g),i=Math.round(i),I=Math.round(I),n=Math.round(n),(r.width!==I||r.height!==n||r.x!==g||r.y!==i)&&(r.x=g,r.y=i,r.width=I,r.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,r){r===void 0&&(r=rB.COLOR|rB.DEPTH);var C=this.gl;C.clearColor(g,i,I,n),C.clear(r)},e.prototype.initFramebuffer=function(g){var i=this.gl,I=new ife(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,r=n.length;i.drawBuffers||(r=Math.min(r,1));for(var C=0;C1&&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=fi.NONE;if(g<=1||i===null)return I;for(var n=0;n=0&&this.managedFramebuffers.splice(r,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=mA.WEBGL2&&(g=e.getContext("webgl2",{})),g||(g=e.getContext("webgl",{})||e.getContext("experimental-webgl",{}),g?g.getExtension("WEBGL_draw_buffers"):g=null),Xy=g}return Xy}var wR;function k3e(){if(!wR){wR=kr.MEDIUM;var e=Cfe();if(e&&e.getShaderPrecisionFormat){var g=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT);wR=g.precision?kr.HIGH:kr.MEDIUM}}return wR}function hee(e,g,i){if(e.substring(0,9)!=="precision"){var I=g;return g===kr.HIGH&&i!==kr.HIGH&&(I=kr.MEDIUM),"precision "+I+` float; +`+e}else if(i!==kr.HIGH&&e.substring(0,15)==="precision highp")return e.replace("precision highp","precision mediump");return e}var Y3e={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 ofe(e){return Y3e[e]}var RR=null,mee={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 afe(e,g){if(!RR){var i=Object.keys(mee);RR={};for(var I=0;I0&&(g+=` -else `),I0&&(g+=` +else `),i"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}(),ife=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}(),cee=new Zi,uee=[],fU=function(e){AI(g,e);function g(I){var i=e.call(this,I)||this;return i.glConst=Gt.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=uee.pop())!==null&&i!==void 0?i:new wg);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?cee.copyFrom(r):cee.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&&uee.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}(ife),pU=function(e){AI(g,e);function g(I){var i=e.call(this,I)||this;return i.glConst=Gt.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}(ife),bU=function(){function e(g){this.renderer=g,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new Zi,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}(),vu=new wg,Hy=new wg,yU=function(){function e(g){this.renderer=g,this.clearColor=g._backgroundColorRgba,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new wg,this.destinationFrame=new wg,this.viewportFrame=new wg}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||(vu.width=g.frame.width,vu.height=g.frame.height,I=vu),i||(Hy.x=g.frame.x,Hy.y=g.frame.y,Hy.width=I.width,Hy.height=I.height,i=Hy),r=C.framebuffer):(o=n.resolution,I||(vu.width=n.screen.width,vu.height=n.screen.height,I=vu),i||(i=vu,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 z3e(e,g,I,i,n){I.buffer.update(n)}var P3e={float:` +`,fee=new ZI,yT=function(){function e(g,i){this._texture=g,this.mapCoord=new ZI,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._textureID=-1,this._updateID=0,this.clampOffset=0,this.clampMargin=typeof i>"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}(),lfe=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}(),pee=new ZI,bee=[],vU=function(e){Ai(g,e);function g(i){var I=e.call(this,i)||this;return I.glConst=Gt.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,r=i.maskObject,C=this.renderer,o=C.renderTexture,a=r.getBounds(!0,(I=bee.pop())!==null&&I!==void 0?I:new wg);this.roundFrameToPixels(a,o.current?o.current.resolution:C.resolution,o.sourceFrame,o.destinationFrame,C.projection.transform),n&&a.fit(n),i._scissorRectLocal=a}},g.isMatrixRotated=function(i){if(!i)return!1;var I=i.a,n=i.b,r=i.c,C=i.d;return(Math.abs(n)>1e-4||Math.abs(r)>1e-4)&&(Math.abs(I)>1e-4||Math.abs(C)>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,r,C){g.isMatrixRotated(C)||(C=C?pee.copyFrom(C):pee.identity(),C.translate(-n.x,-n.y).scale(r.width/n.width,r.height/n.height).translate(r.x,r.y),this.renderer.filter.transformAABB(C,i),i.fit(r),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&&bee.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}(lfe),BU=function(e){Ai(g,e);function g(i){var I=e.call(this,i)||this;return I.glConst=Gt.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,r=i._stencilCounter;r===0&&(this.renderer.framebuffer.forceStencil(),n.clearStencil(0),n.clear(n.STENCIL_BUFFER_BIT),n.enable(n.STENCIL_TEST)),i._stencilCounter++;var C=i._colorMask;C!==0&&(i._colorMask=0,n.colorMask(!1,!1,!1,!1)),n.stencilFunc(n.EQUAL,r,4294967295),n.stencilOp(n.KEEP,n.KEEP,n.INCR),I.renderable=!0,I.render(this.renderer),this.renderer.batch.flush(),I.renderable=!1,C!==0&&(i._colorMask=C,n.colorMask((C&1)!==0,(C&2)!==0,(C&4)!==0,(C&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,r=n?n._colorMask:15;r!==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,r!==0&&(n._colorMask=r,I.colorMask((r&1)!==0,(r&2)!==0,(r&4)!==0,(r&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}(lfe),SU=function(){function e(g){this.renderer=g,this.destinationFrame=null,this.sourceFrame=null,this.defaultFrame=null,this.projectionMatrix=new ZI,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 r=this.renderer;r.globalUniforms.uniforms.projectionMatrix=this.projectionMatrix,r.globalUniforms.update(),r.shader.shader&&r.shader.syncUniformGroup(r.shader.shader.uniforms.globals)},e.prototype.calculateProjection=function(g,i,I,n){var r=this.projectionMatrix,C=n?-1:1;r.identity(),r.a=1/i.width*2,r.d=C*(1/i.height*2),r.tx=-1-i.x*r.a,r.ty=-C-i.y*r.d},e.prototype.setTransform=function(g){},e.prototype.destroy=function(){this.renderer=null},e}(),Gu=new wg,Ty=new wg,wU=function(){function e(g){this.renderer=g,this.clearColor=g._backgroundColorRgba,this.defaultMaskStack=[],this.current=null,this.sourceFrame=new wg,this.destinationFrame=new wg,this.viewportFrame=new wg}return e.prototype.bind=function(g,i,I){g===void 0&&(g=null);var n=this.renderer;this.current=g;var r,C,o;g?(r=g.baseTexture,o=r.resolution,i||(Gu.width=g.frame.width,Gu.height=g.frame.height,i=Gu),I||(Ty.x=g.frame.x,Ty.y=g.frame.y,Ty.width=i.width,Ty.height=i.height,I=Ty),C=r.framebuffer):(o=n.resolution,i||(Gu.width=n.screen.width,Gu.height=n.screen.height,i=Gu),I||(I=Gu,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(C,a),this.renderer.projection.update(I,i,o,!C),g?this.renderer.mask.setMaskStack(r.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,r=I.width!==n.width||I.height!==n.height;if(r){var C=this.viewportFrame,o=C.x,a=C.y,s=C.width,A=C.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),r&&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 Q3e(e,g,i,I,n){i.buffer.update(n)}var j3e={float:` data[offset] = v; `,vec2:` data[offset] = v[0]; @@ -525,7 +525,7 @@ void main(void) { data[offset + i] = v[i]; } - `},nfe={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 Cfe(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 rfe(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 ofe(e,g){if(!e.autoManage)return{size:0,syncFunc:z3e};for(var I=rfe(e.uniforms,g),i=Cfe(I),n=i.uboElements,C=i.size,r=[` + `},cfe={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 ufe(e){for(var g=e.map(function(a){return{data:a,offset:0,dataLen:0,dirty:0}}),i=0,I=0,n=0,r=0;r1&&(i=Math.max(i,16)*C.data.size),C.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,C.offset=n,n+=i,I=i):(C.offset=n,I+=i,n+=i)}return n=Math.ceil(n/16)*16,{uboElements:g,size:n}}function dfe(e,g){var i=[];for(var I in e)g[I]&&i.push(g[I]);return i.sort(function(n,r){return n.index-r.index}),i}function hfe(e,g){if(!e.autoManage)return{size:0,syncFunc:Q3e};for(var i=dfe(e.uniforms,g),I=ufe(i),n=I.uboElements,r=I.size,C=[` var v = null; var v2 = null; var cv = null; @@ -533,7 +533,7 @@ void main(void) var gl = renderer.gl var index = 0; var data = buffer.data; - `],o=0;o1){var d=efe(a.data.type),h=Math.max(nfe[a.data.type]/16,1),m=d/h,f=(4-m%4)%4;r.push(` + `],o=0;o1){var d=ofe(a.data.type),h=Math.max(cfe[a.data.type]/16,1),m=d/h,f=(4-m%4)%4;C.push(` cv = ud.`+A+`.value; v = uv.`+A+`; offset = `+a.offset/4+`; @@ -549,15 +549,15 @@ void main(void) offset += `+f+`; } - `)}else{var b=P3e[a.data.type];r.push(` + `)}else{var b=j3e[a.data.type];C.push(` cv = ud.`+A+`.value; v = uv.`+A+`; offset = `+a.offset/4+`; `+b+`; - `)}}return r.push(` + `)}}return C.push(` renderer.buffer.update(buffer); - `),{size:C,syncFunc:new Function("ud","uv","renderer","syncData","buffer",r.join(` -`))}}var J3e=function(){function e(){}return e}(),afe=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 O3e(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 gze(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[ft.RGBA]=e.RGBA8,I[ft.RGB]=e.RGB8,I[ft.RG]=e.RG8,I[ft.RED]=e.R8,I[ft.RGBA_INTEGER]=e.RGBA8UI,I[ft.RGB_INTEGER]=e.RGB8UI,I[ft.RG_INTEGER]=e.RG8UI,I[ft.RED_INTEGER]=e.R8UI,I[ft.ALPHA]=e.ALPHA,I[ft.LUMINANCE]=e.LUMINANCE,I[ft.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,I),g[Et.BYTE]=(i={},i[ft.RGBA]=e.RGBA8_SNORM,i[ft.RGB]=e.RGB8_SNORM,i[ft.RG]=e.RG8_SNORM,i[ft.RED]=e.R8_SNORM,i[ft.RGBA_INTEGER]=e.RGBA8I,i[ft.RGB_INTEGER]=e.RGB8I,i[ft.RG_INTEGER]=e.RG8I,i[ft.RED_INTEGER]=e.R8I,i),g[Et.UNSIGNED_SHORT]=(n={},n[ft.RGBA_INTEGER]=e.RGBA16UI,n[ft.RGB_INTEGER]=e.RGB16UI,n[ft.RG_INTEGER]=e.RG16UI,n[ft.RED_INTEGER]=e.R16UI,n[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT16,n),g[Et.SHORT]=(C={},C[ft.RGBA_INTEGER]=e.RGBA16I,C[ft.RGB_INTEGER]=e.RGB16I,C[ft.RG_INTEGER]=e.RG16I,C[ft.RED_INTEGER]=e.R16I,C),g[Et.UNSIGNED_INT]=(r={},r[ft.RGBA_INTEGER]=e.RGBA32UI,r[ft.RGB_INTEGER]=e.RGB32UI,r[ft.RG_INTEGER]=e.RG32UI,r[ft.RED_INTEGER]=e.R32UI,r[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT24,r),g[Et.INT]=(o={},o[ft.RGBA_INTEGER]=e.RGBA32I,o[ft.RGB_INTEGER]=e.RGB32I,o[ft.RG_INTEGER]=e.RG32I,o[ft.RED_INTEGER]=e.R32I,o),g[Et.FLOAT]=(a={},a[ft.RGBA]=e.RGBA32F,a[ft.RGB]=e.RGB32F,a[ft.RG]=e.RG32F,a[ft.RED]=e.R32F,a[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT32F,a),g[Et.HALF_FLOAT]=(s={},s[ft.RGBA]=e.RGBA16F,s[ft.RGB]=e.RGB16F,s[ft.RG]=e.RG16F,s[ft.RED]=e.R16F,s),g[Et.UNSIGNED_SHORT_5_6_5]=(A={},A[ft.RGB]=e.RGB565,A),g[Et.UNSIGNED_SHORT_4_4_4_4]=(l={},l[ft.RGBA]=e.RGBA4,l),g[Et.UNSIGNED_SHORT_5_5_5_1]=(c={},c[ft.RGBA]=e.RGB5_A1,c),g[Et.UNSIGNED_INT_2_10_10_10_REV]=(u={},u[ft.RGBA]=e.RGB10_A2,u[ft.RGBA_INTEGER]=e.RGB10_A2UI,u),g[Et.UNSIGNED_INT_10F_11F_11F_REV]=(d={},d[ft.RGB]=e.R11F_G11F_B10F,d),g[Et.UNSIGNED_INT_5_9_9_9_REV]=(h={},h[ft.RGB]=e.RGB9_E5,h),g[Et.UNSIGNED_INT_24_8]=(m={},m[ft.DEPTH_STENCIL]=e.DEPTH24_STENCIL8,m),g[Et.FLOAT_32_UNSIGNED_INT_24_8_REV]=(f={},f[ft.DEPTH_STENCIL]=e.DEPTH32F_STENCIL8,f),g):G=(b={},b[Et.UNSIGNED_BYTE]=(p={},p[ft.RGBA]=e.RGBA,p[ft.RGB]=e.RGB,p[ft.ALPHA]=e.ALPHA,p[ft.LUMINANCE]=e.LUMINANCE,p[ft.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,p),b[Et.UNSIGNED_SHORT_5_6_5]=(y={},y[ft.RGB]=e.RGB,y),b[Et.UNSIGNED_SHORT_4_4_4_4]=(Z={},Z[ft.RGBA]=e.RGBA,Z),b[Et.UNSIGNED_SHORT_5_5_5_1]=(B={},B[ft.RGBA]=e.RGBA,B),b),G}var w1=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=ft.RGBA,this.samplerType=0}return e}(),BU=function(){function e(g){this.renderer=g,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new Gg,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=gze(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!==iB.FLOAT&&this.renderer.texture.unbind(o)}}},e.prototype.initTexture=function(g){var I=new w1(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!==iB.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&&Rd(this.managedTextures,n,1)}},e.prototype.updateTextureStyle=function(g){var I=g._glTextures[this.CONTEXT_UID];I&&((g.mipmap===io.POW2||this.webGLVersion!==2)&&!g.isPowerOfTwo?I.mipmap=!1:I.mipmap=g.mipmap>=1,this.webGLVersion!==2&&!g.isPowerOfTwo?I.wrapMode=ga.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!==io.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===Qo.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);var n=this.renderer.context.extensions.anisotropicFiltering;if(n&&g.anisotropicLevel>0&&g.scaleMode===Qo.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===Qo.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(g.target,i.TEXTURE_MAG_FILTER,g.scaleMode===Qo.LINEAR?i.LINEAR:i.NEAREST)},e.prototype.destroy=function(){this.renderer=null},e}(),sfe={__proto__:null,FilterSystem:lU,BatchSystem:cU,ContextSystem:uU,FramebufferSystem:dU,GeometrySystem:hU,MaskSystem:mU,ScissorSystem:fU,StencilSystem:pU,ProjectionSystem:bU,RenderTextureSystem:yU,ShaderSystem:ZU,StateSystem:GU,TextureGCSystem:vU,TextureSystem:BU},PK=new Zi,lfe=function(e){AI(g,e);function g(I,i){I===void 0&&(I=ob.UNKNOWN);var n=e.call(this)||this;return i=Object.assign({},Gt.RENDER_OPTIONS,i),n.options=i,n.type=I,n.screen=new wg(0,0,i.width,i.height),n.view=i.view||Gt.ADAPTER.createCanvas(),n.resolution=i.resolution||Gt.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&&(aC("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"&&(aC("6.1.0","generateTexture options (scaleMode, resolution, region) are now object options."),i={scaleMode:i,resolution:n,region:C});var r=i.region,o=m3e(i,["region"]);C=r||I.getLocalBounds(null,!0),C.width===0&&(C.width=1),C.height===0&&(C.height=1);var a=Ys.create(yM({width:C.width,height:C.height},o));return PK.tx=-C.x,PK.ty=-C.y,this.render(I,{renderTexture:a,clear:!1,transform:PK,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=ob.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=UL(I),Ud(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}(v0),Ize=function(){function e(g){this.buffer=g||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}return e}(),ize=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=fI.HIGH?this.multisample=fI.HIGH:i>=fI.MEDIUM?this.multisample=fI.MEDIUM:i>=fI.LOW?this.multisample=fI.LOW:this.multisample=fI.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 Ys?(aC("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 aC("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){aC("6.5.0","Renderer.registerPlugin() has been deprecated, please use extensions.add() instead."),wA.add({name:I,type:Og.RendererPlugin,ref:i})},g.__plugins={},g}(lfe);wA.handleByMap(Og.RendererPlugin,SU.__plugins);function cfe(e){return SU.create(e)}var nze=`attribute vec2 aVertexPosition; + `),{size:r,syncFunc:new Function("ud","uv","renderer","syncData","buffer",C.join(` +`))}}var $3e=function(){function e(){}return e}(),mfe=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 q3e(e,g){for(var i={},I=g.getProgramParameter(e,g.ACTIVE_ATTRIBUTES),n=0;nl?1:-1});for(var C=0;C>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(r,!0),i[n]=null,I=!0)}if(I){for(var C=0,n=0;n=0;n--)this.unload(g.children[n])},e.prototype.destroy=function(){this.renderer=null},e}();function aze(e){var g,i,I,n,r,C,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[ft.RGBA]=e.RGBA8,i[ft.RGB]=e.RGB8,i[ft.RG]=e.RG8,i[ft.RED]=e.R8,i[ft.RGBA_INTEGER]=e.RGBA8UI,i[ft.RGB_INTEGER]=e.RGB8UI,i[ft.RG_INTEGER]=e.RG8UI,i[ft.RED_INTEGER]=e.R8UI,i[ft.ALPHA]=e.ALPHA,i[ft.LUMINANCE]=e.LUMINANCE,i[ft.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,i),g[Et.BYTE]=(I={},I[ft.RGBA]=e.RGBA8_SNORM,I[ft.RGB]=e.RGB8_SNORM,I[ft.RG]=e.RG8_SNORM,I[ft.RED]=e.R8_SNORM,I[ft.RGBA_INTEGER]=e.RGBA8I,I[ft.RGB_INTEGER]=e.RGB8I,I[ft.RG_INTEGER]=e.RG8I,I[ft.RED_INTEGER]=e.R8I,I),g[Et.UNSIGNED_SHORT]=(n={},n[ft.RGBA_INTEGER]=e.RGBA16UI,n[ft.RGB_INTEGER]=e.RGB16UI,n[ft.RG_INTEGER]=e.RG16UI,n[ft.RED_INTEGER]=e.R16UI,n[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT16,n),g[Et.SHORT]=(r={},r[ft.RGBA_INTEGER]=e.RGBA16I,r[ft.RGB_INTEGER]=e.RGB16I,r[ft.RG_INTEGER]=e.RG16I,r[ft.RED_INTEGER]=e.R16I,r),g[Et.UNSIGNED_INT]=(C={},C[ft.RGBA_INTEGER]=e.RGBA32UI,C[ft.RGB_INTEGER]=e.RGB32UI,C[ft.RG_INTEGER]=e.RG32UI,C[ft.RED_INTEGER]=e.R32UI,C[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT24,C),g[Et.INT]=(o={},o[ft.RGBA_INTEGER]=e.RGBA32I,o[ft.RGB_INTEGER]=e.RGB32I,o[ft.RG_INTEGER]=e.RG32I,o[ft.RED_INTEGER]=e.R32I,o),g[Et.FLOAT]=(a={},a[ft.RGBA]=e.RGBA32F,a[ft.RGB]=e.RGB32F,a[ft.RG]=e.RG32F,a[ft.RED]=e.R32F,a[ft.DEPTH_COMPONENT]=e.DEPTH_COMPONENT32F,a),g[Et.HALF_FLOAT]=(s={},s[ft.RGBA]=e.RGBA16F,s[ft.RGB]=e.RGB16F,s[ft.RG]=e.RG16F,s[ft.RED]=e.R16F,s),g[Et.UNSIGNED_SHORT_5_6_5]=(A={},A[ft.RGB]=e.RGB565,A),g[Et.UNSIGNED_SHORT_4_4_4_4]=(l={},l[ft.RGBA]=e.RGBA4,l),g[Et.UNSIGNED_SHORT_5_5_5_1]=(c={},c[ft.RGBA]=e.RGB5_A1,c),g[Et.UNSIGNED_INT_2_10_10_10_REV]=(u={},u[ft.RGBA]=e.RGB10_A2,u[ft.RGBA_INTEGER]=e.RGB10_A2UI,u),g[Et.UNSIGNED_INT_10F_11F_11F_REV]=(d={},d[ft.RGB]=e.R11F_G11F_B10F,d),g[Et.UNSIGNED_INT_5_9_9_9_REV]=(h={},h[ft.RGB]=e.RGB9_E5,h),g[Et.UNSIGNED_INT_24_8]=(m={},m[ft.DEPTH_STENCIL]=e.DEPTH24_STENCIL8,m),g[Et.FLOAT_32_UNSIGNED_INT_24_8_REV]=(f={},f[ft.DEPTH_STENCIL]=e.DEPTH32F_STENCIL8,f),g):G=(b={},b[Et.UNSIGNED_BYTE]=(p={},p[ft.RGBA]=e.RGBA,p[ft.RGB]=e.RGB,p[ft.ALPHA]=e.ALPHA,p[ft.LUMINANCE]=e.LUMINANCE,p[ft.LUMINANCE_ALPHA]=e.LUMINANCE_ALPHA,p),b[Et.UNSIGNED_SHORT_5_6_5]=(y={},y[ft.RGB]=e.RGB,y),b[Et.UNSIGNED_SHORT_4_4_4_4]=(Z={},Z[ft.RGBA]=e.RGBA,Z),b[Et.UNSIGNED_SHORT_5_5_5_1]=(B={},B[ft.RGBA]=e.RGBA,B),b),G}var W1=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=ft.RGBA,this.samplerType=0}return e}(),XU=function(){function e(g){this.renderer=g,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new Gg,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=aze(g);var i=g.getParameter(g.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=i;for(var I=0;I=0;--C){var o=I[C];if(o){var a=o._glTextures[r];a.samplerType!==CB.FLOAT&&this.renderer.texture.unbind(o)}}},e.prototype.initTexture=function(g){var i=new W1(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!==CB.FLOAT&&(this.hasIntegerTextures=!0);else{var n=g.realWidth,r=g.realHeight,C=I.gl;(i.width!==n||i.height!==r||i.dirtyId<0)&&(i.width=n,i.height=r,C.texImage2D(g.target,0,i.internalFormat,n,r,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&&Rd(this.managedTextures,n,1)}},e.prototype.updateTextureStyle=function(g){var i=g._glTextures[this.CONTEXT_UID];i&&((g.mipmap===Io.POW2||this.webGLVersion!==2)&&!g.isPowerOfTwo?i.mipmap=!1:i.mipmap=g.mipmap>=1,this.webGLVersion!==2&&!g.isPowerOfTwo?i.wrapMode=ga.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!==Io.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===Qo.LINEAR?I.LINEAR_MIPMAP_LINEAR:I.NEAREST_MIPMAP_NEAREST);var n=this.renderer.context.extensions.anisotropicFiltering;if(n&&g.anisotropicLevel>0&&g.scaleMode===Qo.LINEAR){var r=Math.min(g.anisotropicLevel,I.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));I.texParameterf(g.target,n.TEXTURE_MAX_ANISOTROPY_EXT,r)}}else I.texParameteri(g.target,I.TEXTURE_MIN_FILTER,g.scaleMode===Qo.LINEAR?I.LINEAR:I.NEAREST);I.texParameteri(g.target,I.TEXTURE_MAG_FILTER,g.scaleMode===Qo.LINEAR?I.LINEAR:I.NEAREST)},e.prototype.destroy=function(){this.renderer=null},e}(),pfe={__proto__:null,FilterSystem:fU,BatchSystem:pU,ContextSystem:bU,FramebufferSystem:yU,GeometrySystem:ZU,MaskSystem:GU,ScissorSystem:vU,StencilSystem:BU,ProjectionSystem:SU,RenderTextureSystem:wU,ShaderSystem:RU,StateSystem:VU,TextureGCSystem:WU,TextureSystem:XU},_K=new ZI,bfe=function(e){Ai(g,e);function g(i,I){i===void 0&&(i=ab.UNKNOWN);var n=e.call(this)||this;return I=Object.assign({},Gt.RENDER_OPTIONS,I),n.options=I,n.type=i,n.screen=new wg(0,0,I.width,I.height),n.view=I.view||Gt.ADAPTER.createCanvas(),n.resolution=I.resolution||Gt.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&&(or("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,r=this.view.height/this.resolution;this.screen.width=n,this.screen.height=r,this.autoDensity&&(this.view.style.width=n+"px",this.view.style.height=r+"px"),this.emit("resize",n,r)},g.prototype.generateTexture=function(i,I,n,r){I===void 0&&(I={}),typeof I=="number"&&(or("6.1.0","generateTexture options (scaleMode, resolution, region) are now object options."),I={scaleMode:I,resolution:n,region:r});var C=I.region,o=v3e(I,["region"]);r=C||i.getLocalBounds(null,!0),r.width===0&&(r.width=1),r.height===0&&(r.height=1);var a=Ys.create(SM({width:r.width,height:r.height},o));return _K.tx=-r.x,_K.ty=-r.y,this.render(i,{renderTexture:a,clear:!1,transform:_K,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=ab.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=tU(i),Ld(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}(B0),Aze=function(){function e(g){this.buffer=g||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}return e}(),sze=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,r=g._glBuffers[n]||this.createGLBuffer(g);I.bindBuffer(g.type,r.buffer)},e.prototype.bindBufferBase=function(g,i){var I=this,n=I.gl,r=I.CONTEXT_UID;if(this.boundBufferBases[i]!==g){var C=g._glBuffers[r]||this.createGLBuffer(g);this.boundBufferBases[i]=g,n.bindBufferBase(n.UNIFORM_BUFFER,i,C.buffer)}},e.prototype.bindBufferRange=function(g,i,I){var n=this,r=n.gl,C=n.CONTEXT_UID;I=I||0;var o=g._glBuffers[C]||this.createGLBuffer(g);r.bindBufferRange(r.UNIFORM_BUFFER,i||0,o.buffer,I*256,256)},e.prototype.update=function(g){var i=this,I=i.gl,n=i.CONTEXT_UID,r=g._glBuffers[n];if(g._updateID!==r.updateID)if(r.updateID=g._updateID,I.bindBuffer(g.type,r.buffer),r.byteLength>=g.data.byteLength)I.bufferSubData(g.type,0,g.data);else{var C=g.static?I.STATIC_DRAW:I.DYNAMIC_DRAW;r.byteLength=g.data.byteLength,I.bufferData(g.type,g.data,C)}},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=fi.HIGH?this.multisample=fi.HIGH:I>=fi.MEDIUM?this.multisample=fi.MEDIUM:I>=fi.LOW?this.multisample=fi.LOW:this.multisample=fi.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 r in this.runners)this.runners[r].add(n);return this},g.prototype.render=function(i,I){var n,r,C,o;if(I&&(I instanceof Ys?(or("6.0.0","Renderer#render arguments changed, use options instead."),n=I,r=arguments[2],C=arguments[3],o=arguments[4]):(n=I.renderTexture,r=I.clear,C=I.transform,o=I.skipUpdateTransform)),this.renderingToScreen=!n,this.runners.prerender.emit(),this.emit("prerender"),this.projection.transform=C,!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(),(r!==void 0?r: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,r){I===void 0&&(I={});var C=e.prototype.generateTexture.call(this,i,I,n,r);return this.framebuffer.blit(),C},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 or("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){or("6.5.0","Renderer.registerPlugin() has been deprecated, please use extensions.add() instead."),wA.add({name:i,type:Og.RendererPlugin,ref:I})},g.__plugins={},g}(bfe);wA.handleByMap(Og.RendererPlugin,HU.__plugins);function yfe(e){return HU.create(e)}var lze=`attribute vec2 aVertexPosition; attribute vec2 aTextureCoord; uniform mat3 projectionMatrix; @@ -568,7 +568,7 @@ void main(void) { gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0); vTextureCoord = aTextureCoord; -}`,Cze=`attribute vec2 aVertexPosition; +}`,cze=`attribute vec2 aVertexPosition; uniform mat3 projectionMatrix; @@ -594,15 +594,15 @@ void main(void) gl_Position = filterVertexPosition(); vTextureCoord = filterTextureCoord(); } -`,ufe=nze,wU=Cze,rze=function(){function e(g){aC("6.1.0","System class is deprecated, implemement ISystem interface instead."),this.renderer=g}return e.prototype.destroy=function(){this.renderer=null},e}(),bX=function(){function e(){this.texArray=null,this.blend=0,this.type=Or.TRIANGLES,this.start=0,this.size=0,this.data=null}return e}(),yX=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=++Gg._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 `),ithis.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,r=g._textureArrayPool,C=this.renderer.batch,o=this._tempBoundTextures,a=this.renderer.textureGC.count,s=++Gg._globalBatch,A=0,l=r[0],c=0;C.copyBoundTextures(o,n);for(var u=0;u=n&&(C.boundArray(l,o,s,n),this.buildDrawCalls(l,c,u),c=u,l=r[++A],++s),d._batchEnabled=s,d.touched=a,l.elements[l.count++]=d)}l.count>0&&(C.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=VV+"px",I.style.height=VV+"px",I.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",I.style.position="absolute",I.style.zIndex=mee.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===Aze&&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:[Og.RendererPlugin,Og.CanvasRendererPlugin]},e}();/*! + */var Vfe={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,_accessibleActive:!1,_accessibleDiv:null,accessibleType:"button",accessiblePointerEvents:"auto",accessibleChildren:!0,renderId:-1};$i.mixin(Vfe);var mze=9,XR=100,fze=0,pze=0,Gee=2,vee=1,bze=-1e3,yze=-1e3,Zze=2,Wfe=function(){function e(g){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,(OC.tablet||OC.phone)&&this.createTouchHook();var i=document.createElement("div");i.style.width=XR+"px",i.style.height=XR+"px",i.style.position="absolute",i.style.top=fze+"px",i.style.left=pze+"px",i.style.zIndex=Gee.toString(),this.div=i,this.renderer=g,this._onKeyDown=this._onKeyDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)}return Object.defineProperty(e.prototype,"isActive",{get:function(){return this._isActive},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isMobileAccessibility",{get:function(){return this._isMobileAccessibility},enumerable:!1,configurable:!0}),e.prototype.createTouchHook=function(){var g=this,i=document.createElement("button");i.style.width=vee+"px",i.style.height=vee+"px",i.style.position="absolute",i.style.top=bze+"px",i.style.left=yze+"px",i.style.zIndex=Zze.toString(),i.style.backgroundColor="#FF0000",i.title="select to enable accessibility for this content",i.addEventListener("focus",function(){g._isMobileAccessibility=!0,g.activate(),g.destroyTouchHook()}),document.body.appendChild(i),this._hookDiv=i},e.prototype.destroyTouchHook=function(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)},e.prototype.activate=function(){var g;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),(g=this.renderer.view.parentNode)===null||g===void 0||g.appendChild(this.div))},e.prototype.deactivate=function(){var g;!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),(g=this.div.parentNode)===null||g===void 0||g.removeChild(this.div))},e.prototype.updateAccessibleObjects=function(g){if(!(!g.visible||!g.accessibleChildren)){g.accessible&&g.interactive&&(g._accessibleActive||this.addChild(g),g.renderId=this.renderId);var i=g.children;if(i)for(var I=0;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=XR+"px",i.style.height=XR+"px",i.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",i.style.position="absolute",i.style.zIndex=Gee.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===mze&&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:[Og.RendererPlugin,Og.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 GM=function(){function e(){this.pressure=0,this.rotationAngle=0,this.twist=0,this.tangentialPressure=0,this.global=new aI,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}();/*! ***************************************************************************** + */var RM=function(){function e(){this.pressure=0,this.rotationAngle=0,this.twist=0,this.tangentialPressure=0,this.global=new ai,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 @@ -658,25 +658,25 @@ 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 vM=function(e,g){return vM=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])},vM(e,g)};function hze(e,g){vM(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(){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}(),V1=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}(),mze=function(){function e(){this._tempPoint=new aI}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}(),vfe={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};$I.mixin(vfe);var RV=1,WV={target:null,data:{global:null}},Bfe=function(e){hze(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 GM,n.mouse.identifier=RV,n.mouse.global.set(-999999),n.activeInteractionData={},n.activeInteractionData[RV]=n.mouse,n.interactionDataPool=[],n.eventData=new Gfe,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 mze,n._tempDisplayObject=new gU,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 WV.target=null,WV.data.global=I,i||(i=this.lastObjectRendered),this.processInteractive(WV,i,null,!0),WV.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||(Ui.system.add(this.tickerUpdate,this,fA.INTERACTION),this.tickerAdded=!0)},g.prototype.removeTickerListener=function(){this.tickerAdded&&(Ui.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=RV),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:[Og.RendererPlugin,Og.CanvasRendererPlugin]},g}(v0);/*! +***************************************************************************** */var VM=function(e,g){return VM=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])},VM(e,g)};function Gze(e,g){VM(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var Xfe=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}(),X1=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}(),vze=function(){function e(){this._tempPoint=new ai}return e.prototype.recursiveFindHit=function(g,i,I,n,r){var C;if(!i||!i.visible)return!1;var o=g.data.global;r=i.interactive||r;var a=!1,s=r,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&&!(!((C=l.containsPoint)===null||C===void 0)&&C.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 r&&(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}(),Hfe={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};$i.mixin(Hfe);var HR=1,TR={target:null,data:{global:null}},Tfe=function(e){Gze(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 RM,n.mouse.identifier=HR,n.mouse.global.set(-999999),n.activeInteractionData={},n.activeInteractionData[HR]=n.mouse,n.interactionDataPool=[],n.eventData=new Xfe,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 vze,n._tempDisplayObject=new oU,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 TR.target=null,TR.data.global=i,I||(I=this.lastObjectRendered),this.processInteractive(TR,I,null,!0),TR.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||(UI.system.add(this.tickerUpdate,this,fA.INTERACTION),this.tickerAdded=!0)},g.prototype.removeTickerListener=function(){this.tickerAdded&&(UI.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"&&(C.button=i.touches.length?1:0),typeof C.buttons>"u"&&(C.buttons=i.touches.length?1:0),typeof C.isPrimary>"u"&&(C.isPrimary=i.touches.length===1&&i.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,I.push(C)}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=HR),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:[Og.RendererPlugin,Og.CanvasRendererPlugin]},g}(B0);/*! * @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 fze=new wg,pze=4,Sfe=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 mM(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 mM(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 Ys)r=g;else{var a=i.context.webGLVersion>=2?i.multisample:fI.NONE;if(r=this.renderer.generateTexture(g,{multisample:a}),a!==fI.NONE){var s=Ys.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=fze,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(pze*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=2?I.multisample:fi.NONE;if(C=this.renderer.generateTexture(g,{multisample:a}),a!==fi.NONE){var s=Ys.create({width:C.width,height:C.height});I.framebuffer.bind(C.framebuffer),I.framebuffer.blit(s.framebuffer),I.framebuffer.bind(null),C.destroy(!0),C=s}o=!0}C?(n=C.baseTexture.resolution,i=i??C.frame,r=!1,I.renderTexture.bind(C)):(n=I.resolution,i||(i=Bze,i.width=I.width,i.height=I.height),r=!0,I.renderTexture.bind(null));var A=Math.round(i.width*n),l=Math.round(i.height*n),c=new Uint8Array(Sze*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&&C.destroy(!0),{pixels:c,width:A,height:l,flipY:r}},e.prototype.destroy=function(){this.renderer=null},e.arrayPostDivide=function(g,i){for(var I=0;I"u"&&(JK=!!(globalThis.XDomainRequest&&!("withCredentials"in new XMLHttpRequest))),JK&&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"?bee:g.status;(g.responseType===""||g.responseType==="text"||typeof g.responseType>"u")&&(I=g.responseText),i===bze&&(I.length>0||g.responseType===e.XHR_RESPONSE_TYPE.BUFFER)?i=bee:i===Zze&&(i=yze);var n=i/100|0;if(n===Gze)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,HV||(HV=document.createElement("a")),HV.href=g;var i=wfe(HV.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=="})(DI||(DI={}));function Bu(){}function vze(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;C"u"&&(LK=!!(globalThis.XDomainRequest&&!("withCredentials"in new XMLHttpRequest))),LK&&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"?See:g.status;(g.responseType===""||g.responseType==="text"||typeof g.responseType>"u")&&(i=g.responseText),I===wze&&(i.length>0||g.responseType===e.XHR_RESPONSE_TYPE.BUFFER)?I=See:I===Vze&&(I=Rze);var n=I/100|0;if(n===Wze)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 r=new DOMParser;this.data=r.parseFromString(i,"text/xml")}else{var C=document.createElement("div");C.innerHTML=i,this.data=C}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,kR||(kR=document.createElement("a")),kR.href=g;var I=kfe(kR.href,{strictMode:!0}),n=!I.port&&i.port===""||I.port===i.port,r=I.protocol?I.protocol+":":"";return I.host!==i.hostname||!n||r!==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("?"),r=g.indexOf("#"),C=Math.min(n>-1?n:g.length,r>-1?r:g.length);g=g.substring(0,C),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=="})(Di||(Di={}));function vu(){}function Xze(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 C=i-(e.length-1);switch(C){case 2:n[3]=64,n[2]=64;break;case 1:n[3]=64;break}for(var r=0;r0&&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*dB[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*dB[i];return s},g}(Xfe),Hfe=function(){function e(){}return e.use=function(g,I){var i=g.data,n=this;if(g.type===DI.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(J){var P=J[0].levelBuffer,ge=!1;return C===Et.FLOAT?P=new Float32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4):C===Et.UNSIGNED_INT?(ge=!0,P=new Uint32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4)):C===Et.INT&&(ge=!0,P=new Int32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4)),{resource:new Lh(P,{width:J[0].levelWidth,height:J[0].levelHeight}),type:C,format:ge?jze(r):r}}),kvData:B}:{compressed:p.map(function(J){return new GX(null,{format:o,width:a,height:s,levels:u,levelBuffers:J})}),kvData:B}}function Qze(e,g){for(var I=0;Ig-n){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}for(var a=0;a0&&r[r.length-1])&&(s[0]===6||s[0]===2)){i=0;continue}if(s[0]===3&&(!r||s[1]>r[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,r,C,o,a){for(var s=new Array(n),A=i.byteOffset,l=o,c=a,u=l+r-1&~(r-1),d=c+C-1&~(C-1),h=u*d*fB[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+r-1&~(r-1),d=c+C-1&~(C-1),h=u*d*fB[I];return s},g}(Dfe),xfe=function(){function e(){}return e.use=function(g,i){var I=g.data,n=this;if(g.type===Di.TYPE.JSON&&I&&I.cacheID&&I.textures){for(var r=I.textures,C=void 0,o=void 0,a=0,s=r.length;a>>1,R=R>>>1}for(var H=B,S=0;S1||r!==0?w:S,levelHeight:u>1||r!==0?R: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,R=R>>1||1,S=w+h-1&~(h-1),X=R+m-1&~(m-1),v=S*X*Z}return r!==0?{uncompressed:p.map(function(J){var P=J[0].levelBuffer,ge=!1;return r===Et.FLOAT?P=new Float32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4):r===Et.UNSIGNED_INT?(ge=!0,P=new Uint32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4)):r===Et.INT&&(ge=!0,P=new Int32Array(J[0].levelBuffer.buffer,J[0].levelBuffer.byteOffset,J[0].levelBuffer.byteLength/4)),{resource:new _h(P,{width:J[0].levelWidth,height:J[0].levelHeight}),type:r,format:ge?IPe(C):C}}),kvData:B}:{compressed:p.map(function(J){return new S9(null,{format:o,width:a,height:s,levels:u,levelBuffers:J})}),kvData:B}}function iPe(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,Ud(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.lengtho&&(n=o),C._properties=[!1,!0,!1,!1,!1],C._maxSize=i,C._batchSize=n,C._buffers=null,C._bufferUpdateIDs=[],C._updateID=0,C.interactiveChildren=!1,C.blendMode=Jt.NORMAL,C.autoResize=r,C.roundPixels=!0,C.baseTexture=null,C.setProperties(I),C._tint=0,C.tintRgb=new Float32Array(4),C.tint=16777215,C}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,Ld(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.lengthn&&!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=$L(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=Tme(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?cT(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:Og.RendererPlugin},g}(BS);/*! +`,Ufe=function(e){Lfe(g,e);function g(i){var I=e.call(this,i)||this;return I.shader=null,I.properties=null,I.tempMatrix=new ZI,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=ws.from(oPe,CPe,{}),I.state=tu.for2d(),I}return g.prototype.render=function(i){var I=i.children,n=i._maxSize,r=i._batchSize,C=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=IU(i.blendMode,A),C.state.set(this.state);var l=C.gl,c=i.worldTransform.copyTo(this.tempMatrix);c.prepend(C.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=c.toArray(!0),this.shader.uniforms.uColor=Eme(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;dr&&(m=r),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?hT(s._tintRGB,l):s._tintRGB+(l*255<<24);r[o]=c,r[o+C]=c,r[o+C*2]=c,r[o+C*3]=c,o+=C*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:Og.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 Ma;(function(e){e.MITER="miter",e.BEVEL="bevel",e.ROUND="round"})(Ma||(Ma={}));var us;(function(e){e.BUTT="butt",e.ROUND="round",e.SQUARE="square"})(us||(us={}));var lb={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}},XU=function(){function e(){this.color=16777215,this.alpha=1,this.texture=gg.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=gg.WHITE,this.matrix=null,this.visible=!1},e.prototype.destroy=function(){this.texture=null,this.matrix=null},e}();/*! ***************************************************************************** + */var Ma;(function(e){e.MITER="miter",e.BEVEL="bevel",e.ROUND="round"})(Ma||(Ma={}));var us;(function(e){e.BUTT="butt",e.ROUND="round",e.SQUARE="square"})(us||(us={}));var cb={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}},KU=function(){function e(){this.color=16777215,this.alpha=1,this.texture=gg.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=gg.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 @@ -760,7 +760,7 @@ 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 WM=function(e,g){return WM=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])},WM(e,g)};function HU(e,g){WM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function See(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){See(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===Ma.ROUND?d+=Su(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),Q=(-S+G)*(-X+B)-(-S+Z)*(-X+v),ie=(F*Q-P*te)/$,he=(ge*te-J*Q)/$,ne=(ie-Z)*(ie-Z)+(he-B)*(he-B),be=Z+(ie-Z)*H,pe=B+(he-B)*H,ve=Z-(ie-Z)*Y,We=B-(he-B)*Y,Be=Math.min(F*F+J*J,P*P+ge*ge),Je=j?H:Y,Pe=Be+Je*Je*f,De=ne<=Pe;De?C.join===Ma.BEVEL||ne/f>b?(j?(c.push(be,pe),c.push(Z+w*Y,B+V*Y),c.push(be,pe),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-V*H),c.push(ve,We),c.push(Z-S*H,B-X*H),c.push(ve,We)),d+=2):C.join===Ma.ROUND?j?(c.push(be,pe),c.push(Z+w*Y,B+V*Y),d+=Su(Z,B,Z+w*Y,B+V*Y,Z+S*Y,B+X*Y,c,!0)+4,c.push(be,pe),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-V*H),c.push(ve,We),d+=Su(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(ve,We)):(c.push(be,pe),c.push(ve,We)):(c.push(Z-w*H,B-V*H),c.push(Z+w*Y,B+V*Y),C.join===Ma.ROUND?j?d+=Su(Z,B,Z+w*Y,B+V*Y,Z+S*Y,B+X*Y,c,!0)+2:d+=Su(Z,B,Z-w*H,B-V*H,Z-S*H,B-X*H,c,!1)+2:C.join===Ma.MITER&&ne/f<=b&&(j?(c.push(ve,We),c.push(ve,We)):(c.push(be,pe),c.push(be,pe)),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===us.ROUND?d+=Su(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===us.SQUARE&&(d+=wee(Z,B,w,V,H,Y,!1,c)));for(var Qe=g.indices,_e=lb.epsilon*lb.epsilon,K=h;Kc*s}},e.arc=function(g,I,i,n,C,r,o,a,s){for(var A=o-r,l=lb._segmentsCount(Math.abs(A)*C,Math.ceil(Math.abs(A)/sB)*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}(),Pfe=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=lb._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}(),Jfe=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=lb._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}(),Ofe=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}(),wu,R1=(wu={},wu[Xi.POLY]=TU,wu[Xi.CIRC]=hB,wu[Xi.ELIP]=hB,wu[Xi.RECT]=Mfe,wu[Xi.RREC]=zfe,wu),TM=[],kZ=[],NM=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}(),Tm=new aI,_fe=function(e){HU(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 lB,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 NM(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 NM(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=kZ.pop(),r||(r=new bX,r.texArray=new yX),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=ga.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)}Gg._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=cT(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 xG,this.currentPath.closeStroke=!1,this.currentPath.points.push(I[i-2],I[i-1]))}else this.currentPath=new xG,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),Jfe.curveTo(I,i,n,C,r),this},g.prototype.bezierCurveTo=function(I,i,n,C,r,o){return this._initCurve(),Pfe.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=HM.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+=sB:o&&C<=r&&(C+=sB);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 wg(I,i,n,C))},g.prototype.drawRoundedRect=function(I,i,n,C,r){return this.drawShape(new Mme(I,i,n,C,r))},g.prototype.drawCircle=function(I,i,n){return this.drawShape(new Fme(I,i,n))},g.prototype.drawEllipse=function(I,i,n,C){return this.drawShape(new Eme(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;u0||g&&r<=0)for(var l=n/2,C=l+l%2;C=6){Hee(i,!1);for(var C=[],o=0;o=0&&o>=0&&n>=0&&r>=0)){g.length=0;return}var u=Math.ceil(2.3*Math.sqrt(C+o)),d=u*8+(n?4:0)+(r?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+r,g[2]=g[4]=i-n,g[5]=g[7]=I-r;return}var h=0,m=u*4+(n?2:0)+2,f=m,b=d;{var p=n+C,y=r,Z=i+p,B=i-p,G=I+y;if(g[h++]=Z,g[h++]=G,g[--m]=G,g[--m]=B,r){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){C.push(e,g),C.push(i,I);for(var b=1,p=c;b=0&&(r.join===Ma.ROUND?d+=Bu(Z,B,Z-w*H,B-R*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)*(-R+B)-(-w+Z)*(-R+y),Q=(-S+G)*(-X+B)-(-S+Z)*(-X+v),Ie=(x*Q-P*te)/$,he=(ge*te-J*Q)/$,ne=(Ie-Z)*(Ie-Z)+(he-B)*(he-B),be=Z+(Ie-Z)*H,pe=B+(he-B)*H,ve=Z-(Ie-Z)*Y,We=B-(he-B)*Y,Be=Math.min(x*x+J*J,P*P+ge*ge),Je=j?H:Y,Pe=Be+Je*Je*f,De=ne<=Pe;De?r.join===Ma.BEVEL||ne/f>b?(j?(c.push(be,pe),c.push(Z+w*Y,B+R*Y),c.push(be,pe),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-R*H),c.push(ve,We),c.push(Z-S*H,B-X*H),c.push(ve,We)),d+=2):r.join===Ma.ROUND?j?(c.push(be,pe),c.push(Z+w*Y,B+R*Y),d+=Bu(Z,B,Z+w*Y,B+R*Y,Z+S*Y,B+X*Y,c,!0)+4,c.push(be,pe),c.push(Z+S*Y,B+X*Y)):(c.push(Z-w*H,B-R*H),c.push(ve,We),d+=Bu(Z,B,Z-w*H,B-R*H,Z-S*H,B-X*H,c,!1)+4,c.push(Z-S*H,B-X*H),c.push(ve,We)):(c.push(be,pe),c.push(ve,We)):(c.push(Z-w*H,B-R*H),c.push(Z+w*Y,B+R*Y),r.join===Ma.ROUND?j?d+=Bu(Z,B,Z+w*Y,B+R*Y,Z+S*Y,B+X*Y,c,!0)+2:d+=Bu(Z,B,Z-w*H,B-R*H,Z-S*H,B-X*H,c,!1)+2:r.join===Ma.MITER&&ne/f<=b&&(j?(c.push(ve,We),c.push(ve,We)):(c.push(be,pe),c.push(be,pe)),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),R=p-Z,W=Math.sqrt(w*w+R*R),w/=W,R/=W,w*=m,R*=m,c.push(Z-w*H,B-R*H),c.push(Z+w*Y,B+R*Y),a||(r.cap===us.ROUND?d+=Bu(Z-w*(H-Y)*.5,B-R*(H-Y)*.5,Z-w*H,B-R*H,Z+w*Y,B+R*Y,c,!1)+2:r.cap===us.SQUARE&&(d+=Tee(Z,B,w,R,H,Y,!1,c)));for(var Qe=g.indices,_e=cb.epsilon*cb.epsilon,K=h;Kc*s}},e.arc=function(g,i,I,n,r,C,o,a,s){for(var A=o-C,l=cb._segmentsCount(Math.abs(A)*r,Math.ceil(Math.abs(A)/uB)*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+C+u*p,Z=Math.cos(y),B=-Math.sin(y);s.push((d*Z+h*B)*r+I,(d*-B+h*Z)*r+n)}},e}(),$fe=function(){function e(){}return e.curveLength=function(g,i,I,n,r,C,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*r+u*o,b=m*i+3*h*l*n+3*d*c*C+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,r,C,o){var a=o[o.length-2],s=o[o.length-1];o.length-=2;var A=cb._segmentsCount(e.curveLength(a,s,g,i,I,n,r,C)),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*r,u*s+3*c*f*i+3*l*d*n+h*C)},e}(),qfe=function(){function e(){}return e.curveLength=function(g,i,I,n,r,C){var o=g-2*I+r,a=i-2*n+C,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,r){for(var C=r[r.length-2],o=r[r.length-1],a=cb._segmentsCount(e.curveLength(C,o,g,i,I,n)),s=0,A=0,l=1;l<=a;++l){var c=l/a;s=C+(g-C)*c,A=o+(i-o)*c,r.push(s+(g+(I-g)*c-s)*c,A+(i+(n-i)*c-A)*c)}},e}(),epe=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}(),Su,H1=(Su={},Su[XI.POLY]=DU,Su[XI.CIRC]=pB,Su[XI.ELIP]=pB,Su[XI.RECT]=Qfe,Su[XI.RREC]=jfe,Su),FM=[],YZ=[],DM=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}(),Hm=new ai,tpe=function(e){FU(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 dB,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,r){I===void 0&&(I=null),n===void 0&&(n=null),r===void 0&&(r=null);var C=new DM(i,I,n,r);return this.graphicsData.push(C),this.dirty++,this},g.prototype.drawHole=function(i,I){if(I===void 0&&(I=null),!this.graphicsData.length)return null;var n=new DM(i,null,null,I),r=this.graphicsData[this.graphicsData.length-1];return n.lineStyle=r.lineStyle,r.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],r=n.style);for(var C=this.shapeIndex;C65535;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&&(C=YZ.pop(),C||(C=new G9,C.texArray=new v9),this.drawCalls.push(C)),C.start=c,C.size=0,C.texArray.count=0,C.type=l),m.touched=1,m._batchEnabled=i,m._batchLocation=o,m.wrapMode=ga.REPEAT,C.texArray.elements[C.texArray.count++]=m,o++)),C.size+=u.size,c+=u.size,s=m._batchLocation,this.addColors(n,h.color,h.alpha,u.attribSize,u.attribStart),this.addTextureIds(r,s,u.attribSize,u.attribStart)}Gg._globalBatch=i,this.packAttributes()},g.prototype.packAttributes=function(){for(var i=this.points,I=this.uvs,n=this.colors,r=this.textureIds,C=new ArrayBuffer(i.length*3*4),o=new Float32Array(C),a=new Uint32Array(C),s=0,A=0;A>16)+(I&65280)+((I&255)<<16),a=hT(o,n);i.length=Math.max(i.length,C+r);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 FG,this.currentPath.closeStroke=!1,this.currentPath.points.push(i[I-2],i[I-1]))}else this.currentPath=new FG,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,r=n[n.length-2],C=n[n.length-1];return(r!==i||C!==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,r){this._initCurve();var C=this.currentPath.points;return C.length===0&&this.moveTo(0,0),qfe.curveTo(i,I,n,r,C),this},g.prototype.bezierCurveTo=function(i,I,n,r,C,o){return this._initCurve(),$fe.curveTo(i,I,n,r,C,o,this.currentPath.points),this},g.prototype.arcTo=function(i,I,n,r,C){this._initCurve(i,I);var o=this.currentPath.points,a=KM.curveTo(i,I,n,r,C,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,r,C,o){if(o===void 0&&(o=!1),r===C)return this;!o&&C<=r?C+=uB:o&&r<=C&&(r+=uB);var a=C-r;if(a===0)return this;var s=i+Math.cos(r)*n,A=I+Math.sin(r)*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,r){return this.drawShape(new wg(i,I,n,r))},g.prototype.drawRoundedRect=function(i,I,n,r,C){return this.drawShape(new Qme(i,I,n,r,C))},g.prototype.drawCircle=function(i,I,n){return this.drawShape(new Lme(i,I,n))},g.prototype.drawEllipse=function(i,I,n,r){return this.drawShape(new Ume(i,I,n,r))},g.prototype.drawPolygon=function(){for(var i=arguments,I=[],n=0;n>16&255)/255*C,o.tint[1]=(r>>8&255)/255*C,o.tint[2]=(r&255)/255*C,o.tint[3]=C,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,r=I.b,C=I.c,o=I.d,a=I.tx,s=I.ty,A=this._geometry.points,l=this.vertexData,c=0,u=0;u=C&&ky.x=r&&ky.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||gg.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}(sa);/*! +***************************************************************************** */var xM=function(e,g){return xM=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])},xM(e,g)};function cPe(e,g){xM(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var Yy=new ai,uPe=new Uint16Array([0,1,2,0,2,3]),V0=function(e){cPe(g,e);function g(i){var I=e.call(this)||this;return I._anchor=new Ad(I._onAnchorUpdate,I,i?i.defaultAnchor.x:0,i?i.defaultAnchor.y:0),I._texture=null,I._width=0,I._height=0,I._tint=null,I._tintRGB=null,I.tint=16777215,I.blendMode=Jt.NORMAL,I._cachedTint=16777215,I.uvs=null,I.texture=i||gg.EMPTY,I.vertexData=new Float32Array(8),I.vertexTrimmedData=null,I._transformID=-1,I._textureID=-1,I._transformTrimmedID=-1,I._textureTrimmedID=-1,I.indices=uPe,I.pluginName="batch",I.isSprite=!0,I._roundPixels=Gt.ROUND_PIXELS,I}return g.prototype._onTextureUpdate=function(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=ad(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=ad(this.scale.y)*this._height/this._texture.orig.height)},g.prototype._onAnchorUpdate=function(){this._transformID=-1,this._transformTrimmedID=-1},g.prototype.calculateVertices=function(){var i=this._texture;if(!(this._transformID===this.transform._worldID&&this._textureID===i._updateID)){this._textureID!==i._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=i._updateID;var I=this.transform.worldTransform,n=I.a,r=I.b,C=I.c,o=I.d,a=I.tx,s=I.ty,A=this.vertexData,l=i.trim,c=i.orig,u=this._anchor,d=0,h=0,m=0,f=0;if(l?(h=l.x-u._x*c.width,d=h+l.width,f=l.y-u._y*c.height,m=f+l.height):(h=-u._x*c.width,d=h+c.width,f=-u._y*c.height,m=f+c.height),A[0]=n*h+C*f+a,A[1]=o*f+r*h+s,A[2]=n*d+C*f+a,A[3]=o*f+r*d+s,A[4]=n*d+C*m+a,A[5]=o*m+r*d+s,A[6]=n*h+C*m+a,A[7]=o*m+r*h+s,this._roundPixels)for(var b=Gt.RESOLUTION,p=0;p=r&&Yy.x=C&&Yy.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||gg.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}(sa);/*! * @pixi/text - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -798,8 +798,8 @@ 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 YM=function(e,g){return YM=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])},YM(e,g)};function oPe(e,g){YM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var cb;(function(e){e[e.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",e[e.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL"})(cb||(cb={}));var jK={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:cb.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},aPe=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],jd=function(){function e(g){this.styleID=0,this.reset(),qK(this,g,g)}return e.prototype.clone=function(){var g={};return qK(g,this,jK),new e(g)},e.prototype.reset=function(){qK(this,jK,jK)},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=$K(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=$K(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){APe(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=$K(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)&&aPe.indexOf(n)<0&&(n='"'+n+'"'),I[i]=n}return this.fontStyle+" "+this.fontVariant+" "+this.fontWeight+" "+g+" "+I.join(",")},e}();function Vee(e){return typeof e=="number"?UL(e):(typeof e=="string"&&e.indexOf("0x")===0&&(e=e.replace("0x","#")),e)}function $K(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+1=0;I--){var n=i[I].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&hPe.indexOf(n)<0&&(n='"'+n+'"'),i[I]=n}return this.fontStyle+" "+this.fontVariant+" "+this.fontWeight+" "+g+" "+i.join(",")},e}();function Nee(e){return typeof e=="number"?tU(e):(typeof e=="string"&&e.indexOf("0x")===0&&(e=e.replace("0x","#")),e)}function t5(e){if(Array.isArray(e)){for(var g=0;gd)if(C!==""&&(o+=e.addLine(C),C="",r=0),e.canBreakWords(f,i.breakWords))for(var Z=e.wordWrapSplit(f),B=0;Bd&&(o+=e.addLine(C),u=!1,C="",r=0),C+=G,r+=S}else{C.length>0&&(o+=e.addLine(C),C="",r=0);var X=m===h.length-1;o+=e.addLine(f,!X),u=!1,C="",r=0}else y+r>d&&(u=!1,o+=e.addLine(C),C="",r=0),(C.length>0||!e.isBreakingSpace(f)||u)&&(C+=f,r+=y)}return o+=e.addLine(C,!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 r=I[g];if(typeof r!="number"){var C=g.length*i;r=n.measureText(g).width+C,I[g]=r}return r},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 cPe(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&&Ui.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 jfe(e,g){return g instanceof Gg?(g._glTextures[e.CONTEXT_UID]||e.texture.bind(g),!0):!1}function bPe(e,g){if(!(g instanceof mB))return!1;var I=g.geometry;g.finishPoly(),I.updateBatches();for(var i=I.batches,n=0;n0},e}();function bPe(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&&UI.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 npe(e,g){return g instanceof Gg?(g._glTextures[e.CONTEXT_UID]||e.texture.bind(g),!0):!1}function wPe(e,g){if(!(g instanceof bB))return!1;var i=g.geometry;g.finishPoly(),i.updateBatches();for(var I=i.batches,n=0;n=C&&Yy.x=r&&Yy.y=r&&Ky.x=C&&Ky.y1?ws.from(SPe,wPe,i):ws.from(Ree,BPe,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!==ga.CLAMP:s.wrapMode===ga.CLAMP&&(s.wrapMode=ga.REPEAT));var d=u?this.simpleShader:this.shader,h=a.width,m=a.height,f=I._width,b=I._height;xV.set(l.a*h/f,l.b*h/b,l.c*m/f,l.d*m/b,l.tx/f,l.ty/b),xV.invert(),u?xV.prepend(c.mapCoord):(d.uniforms.uMapCoord=c.mapCoord.toArray(!0),d.uniforms.uClampFrame=c.uClampFrame,d.uniforms.uClampOffset=c.uClampOffset),d.uniforms.uTransform=xV.toArray(!0),d.uniforms.uColor=qL(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=$L(I.blendMode,A),i.state.set(this.state),i.geometry.draw(this.renderer.gl.TRIANGLES,6,0)},g.extension={name:"tilingSprite",type:Og.RendererPlugin},g}(BS);/*! +`,ER=new ZI,Ape=function(e){ape(g,e);function g(i){var I=e.call(this,i)||this;return i.runners.contextChange.add(I),I.quad=new mU,I.state=tu.for2d(),I}return g.prototype.contextChange=function(){var i=this.renderer,I={globals:i.globalUniforms};this.simpleShader=ws.from(kee,XPe,I),this.shader=i.context.webGLVersion>1?ws.from(TPe,NPe,I):ws.from(kee,HPe,I)},g.prototype.render=function(i){var I=this.renderer,n=this.quad,r=n.vertices;r[0]=r[6]=i._width*-i.anchor.x,r[1]=r[3]=i._height*-i.anchor.y,r[2]=r[4]=i._width*(1-i.anchor.x),r[5]=r[7]=i._height*(1-i.anchor.y);var C=i.uvRespectAnchor?i.anchor.x:0,o=i.uvRespectAnchor?i.anchor.y:0;r=n.uvs,r[0]=r[6]=-C,r[1]=r[3]=-o,r[2]=r[4]=1-C,r[5]=r[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!==ga.CLAMP:s.wrapMode===ga.CLAMP&&(s.wrapMode=ga.REPEAT));var d=u?this.simpleShader:this.shader,h=a.width,m=a.height,f=i._width,b=i._height;ER.set(l.a*h/f,l.b*h/b,l.c*m/f,l.d*m/b,l.tx/f,l.ty/b),ER.invert(),u?ER.prepend(c.mapCoord):(d.uniforms.uMapCoord=c.mapCoord.toArray(!0),d.uniforms.uClampFrame=c.uClampFrame,d.uniforms.uClampOffset=c.uClampOffset),d.uniforms.uTransform=ER.toArray(!0),d.uniforms.uColor=nU(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=IU(i.blendMode,A),I.state.set(this.state),I.geometry.draw(this.renderer.gl.TRIANGLES,6,0)},g.extension={name:"tilingSprite",type:Og.RendererPlugin},g}(RS);/*! * @pixi/mesh - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -976,7 +976,7 @@ 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 DM=function(e,g){return DM=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])},DM(e,g)};function kU(e,g){DM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var Ipe=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}(),e5=new aI,Wee=new xG,ub=function(e){kU(g,e);function g(I,i,n,C){C===void 0&&(C=Or.TRIANGLES);var r=e.call(this)||this;return r.geometry=I,r.shader=i,r.state=n||gu.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=Gt.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===Or.TRIANGLES&&i.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;qL(this._tint,this._alpha,this.uniforms.uColor,I.alphaMode)}this.uvMatrix.update()&&(this.uniforms.uTextureMatrix=this.uvMatrix.mapCoord)},g}(ws),SS=function(e){kU(g,e);function g(I,i,n){var C=e.call(this)||this,r=new mi(I),o=new mi(i,!0),a=new mi(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}(S0);/*! +`,hb=function(e){EU(g,e);function g(i,I){var n=this,r={uSampler:i,alpha:1,uTextureMatrix:ZI.IDENTITY,uColor:new Float32Array([1,1,1,1])};return I=Object.assign({tint:16777215,alpha:1,pluginName:"batch"},I),I.uniforms&&Object.assign(r,I.uniforms),n=e.call(this,I.program||R0.from(YPe,kPe),r)||this,n._colorDirty=!1,n.uvMatrix=new yT(i),n.batchable=I.program===void 0,n.pluginName=I.pluginName,n.tint=I.tint,n.alpha=I.alpha,n}return Object.defineProperty(g.prototype,"texture",{get:function(){return this.uniforms.uSampler},set:function(i){this.uniforms.uSampler!==i&&(!this.uniforms.uSampler.baseTexture.alphaMode!=!i.baseTexture.alphaMode&&(this._colorDirty=!0),this.uniforms.uSampler=i,this.uvMatrix.texture=i)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"alpha",{get:function(){return this._alpha},set:function(i){i!==this._alpha&&(this._alpha=i,this._colorDirty=!0)},enumerable:!1,configurable:!0}),Object.defineProperty(g.prototype,"tint",{get:function(){return this._tint},set:function(i){i!==this._tint&&(this._tint=i,this._tintRGB=(i>>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;nU(this._tint,this._alpha,this.uniforms.uColor,i.alphaMode)}this.uvMatrix.update()&&(this.uniforms.uTextureMatrix=this.uvMatrix.mapCoord)},g}(ws),VS=function(e){EU(g,e);function g(i,I,n){var r=e.call(this)||this,C=new mI(i),o=new mI(I,!0),a=new mI(n,!0,!0);return r.addAttribute("aVertexPosition",C,2,!1,Et.FLOAT).addAttribute("aTextureCoord",o,2,!1,Et.FLOAT).addIndex(a),r._updateId=-1,r}return Object.defineProperty(g.prototype,"vertexDirtyId",{get:function(){return this.buffers[0]._updateID},enumerable:!1,configurable:!0}),g}(w0);/*! * @pixi/text-bitmap - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -1019,7 +1019,7 @@ 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 FM=function(e,g){return FM=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])},FM(e,g)};function WPe(e,g){FM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var fB=function(){function e(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}return e}(),ipe=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 fB;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}(),vX=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 fB,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 vX.test(I)}return!1},e.parse=function(g){var I=new globalThis.DOMParser().parseFromString(g,"text/xml");return vX.parse(I)},e}(),t5=[ipe,vX,npe];function YU(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}HPe(m,f,G,d,h,o,l);var S=W1(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")>-1){var i=new globalThis.DOMParser().parseFromString(g,"text/xml");return w9.test(i)}return!1},e.parse=function(g){var i=new globalThis.DOMParser().parseFromString(g,"text/xml");return w9.parse(i)},e}(),I5=[lpe,w9,cpe];function MU(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),R*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}DPe(m,f,G,d,h,o,l);var S=T1(G.text);u.char.push({id:S,page:y.length-1,x:d/o,y:h/o,width:R,height:w,xoffset:0,yoffset:0,xadvance:Math.ceil(v-(l.dropShadow?l.dropShadowDistance:0)-(l.stroke?l.strokeThickness:0))}),d+=(R+2*C)*o,d=Math.ceil(d)}if(!(I!=null&&I.skipKerning))for(var Z=0,X=A.length;Z0&&r.x>c&&(++y,Rd(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={},K=[],F=this._activePagesMeshData;u.push.apply(u,F);for(var G=0;G6*ie)||ge.vertices.length0&&C.x>c&&(++y,Rd(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++,C.x=0,C.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 V=0;this._align==="right"?V=m-a[G]:this._align==="center"?V=(m-a[G])/2:this._align==="justify"&&(V=s[G]<0?0:(m-a[G])/s[G]),W.push(V)}var H=o.length,Y={},K=[],x=this._activePagesMeshData;u.push.apply(u,x);for(var G=0;G6*Ie)||ge.vertices.length=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 zM=function(e){ope(g,e);function g(I,i,n,C,r){i===void 0&&(i=8),n===void 0&&(n=4),C===void 0&&(C=Gt.FILTER_RESOLUTION),r===void 0&&(r=5);var o=this,a=EPe(r,I),s=PPe(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,Dr.CLEAR);for(var A=1;A=i&&(C=e-o-1),a=a.replace("%value%",g[C].toString()),n+=a,n+=` +`}return I=I.replace("%blur%",n),I=I.replace("%size%",e.toString()),I}var LM=function(e){hpe(g,e);function g(i,I,n,r,C){I===void 0&&(I=8),n===void 0&&(n=4),r===void 0&&(r=Gt.FILTER_RESOLUTION),C===void 0&&(C=5);var o=this,a=LPe(C,i),s=jPe(C);return o=e.call(this,a,s)||this,o.horizontal=i,o.resolution=r,o._quality=0,o.quality=n,o.blur=I,o}return g.prototype.apply=function(i,I,n,r){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,r);else{var C=i.getFilterTexture(),o=i.renderer,a=I,s=C;this.state.blend=!1,i.applyFilter(this,a,s,FC.CLEAR);for(var A=1;A>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}(Qs);JM.prototype.grayscale=JM.prototype.greyscale;/*! +`,QM=function(e){qPe(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,TU,eJe,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,r=i>>8&255,C=i&255,o=[n/255,0,0,0,0,0,r/255,0,0,0,0,0,C/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),r=Math.sin(i),C=Math.sqrt,o=1/3,a=C(o),s=n+(1-n)*o,A=o*(1-n)-a*r,l=o*(1-n)+a*r,c=o*(1-n)+a*r,u=n+o*(1-n),d=o*(1-n)-a*r,h=o*(1-n)-a*r,m=o*(1-n)+a*r,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,r=-.5*(n-1),C=[n,0,0,0,r,0,n,0,0,r,0,0,n,0,r,0,0,0,1,0];this._loadMatrix(C,I)},g.prototype.saturate=function(i,I){i===void 0&&(i=0);var n=i*2/3+1,r=(n-1)*-.5,C=[n,r,r,0,0,r,n,r,0,0,r,r,n,0,0,0,0,0,1,0];this._loadMatrix(C,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,r,C){i=i||.2,I=I||.15,n=n||16770432,r=r||3375104;var o=(n>>16&255)/255,a=(n>>8&255)/255,s=(n&255)/255,A=(r>>16&255)/255,l=(r>>8&255)/255,c=(r&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,C)},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}(Qs);QM.prototype.grayscale=QM.prototype.greyscale;/*! * @pixi/filter-displacement - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -1242,7 +1242,7 @@ 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 OM=function(e,g){return OM=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])},OM(e,g)};function LPe(e,g){OM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var UPe=`varying vec2 vFilterCoord; +***************************************************************************** */var jM=function(e,g){return jM=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])},jM(e,g)};function tJe(e,g){jM(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var gJe=`varying vec2 vFilterCoord; varying vec2 vTextureCoord; uniform vec2 scale; @@ -1262,7 +1262,7 @@ void main(void) gl_FragColor = texture2D(uSampler, clamp(vec2(vTextureCoord.x + map.x, vTextureCoord.y + map.y), inputClamp.xy, inputClamp.zw)); } -`,QPe=`attribute vec2 aVertexPosition; +`,iJe=`attribute vec2 aVertexPosition; uniform mat3 projectionMatrix; uniform mat3 filterMatrix; @@ -1291,7 +1291,7 @@ void main(void) vTextureCoord = filterTextureCoord(); vFilterCoord = ( filterMatrix * vec3( vTextureCoord, 1.0) ).xy; } -`,jPe=function(e){LPe(g,e);function g(I,i){var n=this,C=new Zi;return I.renderable=!1,n=e.call(this,QPe,UPe,{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 aI(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}(Qs);/*! +`,IJe=function(e){tJe(g,e);function g(i,I){var n=this,r=new ZI;return i.renderable=!1,n=e.call(this,iJe,gJe,{mapSampler:i._texture,filterMatrix:r,scale:{x:1,y:1},rotation:new Float32Array([1,0,0,1])})||this,n.maskSprite=i,n.maskMatrix=r,I==null&&(I=20),n.scale=new ai(I,I),n}return g.prototype.apply=function(i,I,n,r){this.uniforms.filterMatrix=i.calculateSpriteMatrix(this.maskMatrix,this.maskSprite),this.uniforms.scale.x=this.scale.x,this.uniforms.scale.y=this.scale.y;var C=this.maskSprite.worldTransform,o=Math.sqrt(C.a*C.a+C.b*C.b),a=Math.sqrt(C.c*C.c+C.d*C.d);o!==0&&a!==0&&(this.uniforms.rotation[0]=C.a/o,this.uniforms.rotation[1]=C.b/o,this.uniforms.rotation[2]=C.c/a,this.uniforms.rotation[3]=C.d/a),i.applyFilter(this,I,n,r)},Object.defineProperty(g.prototype,"map",{get:function(){return this.uniforms.mapSampler},set:function(i){this.uniforms.mapSampler=i},enumerable:!1,configurable:!0}),g}(Qs);/*! * @pixi/filter-fxaa - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -1310,7 +1310,7 @@ 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 _M=function(e,g){return _M=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])},_M(e,g)};function $Pe(e,g){_M(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var qPe=` +***************************************************************************** */var $M=function(e,g){return $M=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])},$M(e,g)};function nJe(e,g){$M(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var rJe=` attribute vec2 aVertexPosition; uniform mat3 projectionMatrix; @@ -1352,7 +1352,7 @@ void main(void) { texcoords(vFragCoord, inputSize.zw, v_rgbNW, v_rgbNE, v_rgbSW, v_rgbSE, v_rgbM); } -`,eJe=`varying vec2 v_rgbNW; +`,CJe=`varying vec2 v_rgbNW; varying vec2 v_rgbNE; varying vec2 v_rgbSW; varying vec2 v_rgbSE; @@ -1473,7 +1473,7 @@ void main() { gl_FragColor = color; } -`,tJe=function(e){$Pe(g,e);function g(){return e.call(this,qPe,eJe)||this}return g}(Qs);/*! +`,oJe=function(e){nJe(g,e);function g(){return e.call(this,rJe,CJe)||this}return g}(Qs);/*! * @pixi/filter-noise - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -1492,7 +1492,7 @@ 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 LM=function(e,g){return LM=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])},LM(e,g)};function gJe(e,g){LM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var IJe=`precision highp float; +***************************************************************************** */var qM=function(e,g){return qM=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])},qM(e,g)};function aJe(e,g){qM(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var AJe=`precision highp float; varying vec2 vTextureCoord; varying vec4 vColor; @@ -1526,31 +1526,31 @@ void main() gl_FragColor = color; } -`,iJe=function(e){gJe(g,e);function g(I,i){I===void 0&&(I=.5),i===void 0&&(i=Math.random());var n=e.call(this,wU,IJe,{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}(Qs);/*! +`,sJe=function(e){aJe(g,e);function g(i,I){i===void 0&&(i=.5),I===void 0&&(I=Math.random());var n=e.call(this,TU,AJe,{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}(Qs);/*! * @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 ape=new Zi;$I.prototype._cacheAsBitmap=!1;$I.prototype._cacheData=null;$I.prototype._cacheAsBitmapResolution=null;$I.prototype._cacheAsBitmapMultisample=fI.NONE;var nJe=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($I.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 nJe),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)}}}});$I.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))};$I.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(Gt.RESOLUTION);var r=g.renderTexture.current,o=g.renderTexture.sourceFrame.clone(),a=g.renderTexture.destinationFrame.clone(),s=g.projection.transform,A=Ys.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_"+Pc();this._cacheData.textureCacheId=l,Gg.addToCache(A.baseTexture,l),gg.addToCache(A,l);var c=this.transform.localTransform.copyTo(ape).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 V0(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)}};$I.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))};$I.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(Gt.RESOLUTION);var r=Ys.create({width:I.width,height:I.height}),o="cacheAsBitmap_"+Pc();this._cacheData.textureCacheId=o,Gg.addToCache(r.baseTexture,o),gg.addToCache(r,o);var a=ape;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 V0(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)}};$I.prototype._calculateCachedBounds=function(){this._bounds.clear(),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite._calculateBounds(),this._bounds.updateID=this._boundsID};$I.prototype._getCachedLocalBounds=function(){return this._cacheData.sprite.getLocalBounds(null)};$I.prototype._destroyCachedDisplayObject=function(){this._cacheData.sprite._texture.destroy(!0),this._cacheData.sprite=null,Gg.removeFromCache(this._cacheData.textureCacheId),gg.removeFromCache(this._cacheData.textureCacheId),this._cacheData.textureCacheId=null};$I.prototype._cacheAsBitmapDestroy=function(g){this.cacheAsBitmap=!1,this.destroy(g)};/*! + */var mpe=new ZI;$i.prototype._cacheAsBitmap=!1;$i.prototype._cacheData=null;$i.prototype._cacheAsBitmapResolution=null;$i.prototype._cacheAsBitmapMultisample=fi.NONE;var lJe=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($i.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 lJe),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)}}}});$i.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))};$i.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 r=this.filters[0].padding;n.pad(r)}n.ceil(Gt.RESOLUTION);var C=g.renderTexture.current,o=g.renderTexture.sourceFrame.clone(),a=g.renderTexture.destinationFrame.clone(),s=g.projection.transform,A=Ys.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_"+zc();this._cacheData.textureCacheId=l,Gg.addToCache(A.baseTexture,l),gg.addToCache(A,l);var c=this.transform.localTransform.copyTo(mpe).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(C,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 V0(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)}};$i.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))};$i.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,r=g._projTransform;i.ceil(Gt.RESOLUTION);var C=Ys.create({width:i.width,height:i.height}),o="cacheAsBitmap_"+zc();this._cacheData.textureCacheId=o,Gg.addToCache(C.baseTexture,o),gg.addToCache(C,o);var a=mpe;this.transform.localTransform.copyTo(a),a.invert(),a.tx-=i.x,a.ty-=i.y,this.renderCanvas=this._cacheData.originalRenderCanvas,g.render(this,{renderTexture:C,clear:!0,transform:a,skipUpdateTransform:!1}),g.context=n,g._projTransform=r,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 V0(C);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)}};$i.prototype._calculateCachedBounds=function(){this._bounds.clear(),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite._calculateBounds(),this._bounds.updateID=this._boundsID};$i.prototype._getCachedLocalBounds=function(){return this._cacheData.sprite.getLocalBounds(null)};$i.prototype._destroyCachedDisplayObject=function(){this._cacheData.sprite._texture.destroy(!0),this._cacheData.sprite=null,Gg.removeFromCache(this._cacheData.textureCacheId),gg.removeFromCache(this._cacheData.textureCacheId),this._cacheData.textureCacheId=null};$i.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 - */$I.prototype.name=null;sa.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}(SS),CJe=function(e){R0(g,e);function g(I,i,n){n===void 0&&(n=0);var C=this,r=new cpe(I.height,i,n),o=new db(I);return n>0&&(I.baseTexture.wrapMode=ga.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}(ub),upe=function(e){R0(g,e);function g(I,i,n){var C=this,r=new lpe(I.width,I.height,i,n),o=new db(gg.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}(ub),rJe=function(e){R0(g,e);function g(I,i,n,C,r){I===void 0&&(I=gg.EMPTY);var o=this,a=new SS(i,n,C);a.getBuffer("aVertexPosition").static=!1;var s=new db(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}(ub),DV=10,oJe=function(e){R0(g,e);function g(I,i,n,C,r){i===void 0&&(i=DV),n===void 0&&(n=DV),C===void 0&&(C=DV),r===void 0&&(r=DV);var o=e.call(this,gg.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}(upe);/*! +***************************************************************************** */var e3=function(e,g){return e3=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])},e3(e,g)};function W0(e,g){e3(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}var bpe=function(e){W0(g,e);function g(i,I,n,r){i===void 0&&(i=100),I===void 0&&(I=100),n===void 0&&(n=10),r===void 0&&(r=10);var C=e.call(this)||this;return C.segWidth=n,C.segHeight=r,C.width=i,C.height=I,C.build(),C}return g.prototype.build=function(){for(var i=this.segWidth*this.segHeight,I=[],n=[],r=[],C=this.segWidth-1,o=this.segHeight-1,a=this.width/C,s=this.height/o,A=0;A0){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);C[u]=a,C[u+1]=0,C[u+2]=a,C[u+3]=1}for(var f=0,c=0;c0?this.textureScale*this._width/2:this._width/2;r/=c,C/=c,r*=u,C*=u,o[l]=A.x+r,o[l+1]=A.y+C,o[l+2]=A.x-r,o[l+3]=A.y-C,I=A}this.buffers[0].update()}},g.prototype.update=function(){this.textureScale>0?this.build():this.updateVertices()},g}(VS),cJe=function(e){W0(g,e);function g(i,I,n){n===void 0&&(n=0);var r=this,C=new ype(i.height,I,n),o=new hb(i);return n>0&&(i.baseTexture.wrapMode=ga.REPEAT),r=e.call(this,C,o)||this,r.autoUpdate=!0,r}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}(db),Zpe=function(e){W0(g,e);function g(i,I,n){var r=this,C=new bpe(i.width,i.height,I,n),o=new hb(gg.WHITE);return r=e.call(this,C,o)||this,r.texture=i,r.autoResize=!0,r}return g.prototype.textureUpdated=function(){this._textureID=this.shader.texture._updateID;var i=this.geometry,I=this.shader.texture,n=I.width,r=I.height;this.autoResize&&(i.width!==n||i.height!==r)&&(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}(db),uJe=function(e){W0(g,e);function g(i,I,n,r,C){i===void 0&&(i=gg.EMPTY);var o=this,a=new VS(I,n,r);a.getBuffer("aVertexPosition").static=!1;var s=new hb(i);return o=e.call(this,a,s,null,C)||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}(db),MR=10,dJe=function(e){W0(g,e);function g(i,I,n,r,C){I===void 0&&(I=MR),n===void 0&&(n=MR),r===void 0&&(r=MR),C===void 0&&(C=MR);var o=e.call(this,gg.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=r,o._topHeight=n,o._bottomHeight=C,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,r=this._height>n?1:this._height/n,C=Math.min(I,r);return C},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,r=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]=r*this._topHeight,I[17]=I[19]=I[21]=I[23]=1-r*this._bottomHeight,this.updateHorizontalVertices(),this.updateVerticalVertices(),this.geometry.buffers[0].update(),this.geometry.buffers[1].update()},g}(Zpe);/*! * @pixi/sprite-animated - v6.5.10 * Compiled Thu, 06 Jul 2023 15:25:11 UTC * @@ -1588,53 +1588,53 @@ 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 QM=function(e,g){return QM=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])},QM(e,g)};function aJe(e,g){QM(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}var AJe=function(e){aJe(g,e);function g(I,i){i===void 0&&(i=!0);var n=e.call(this,I[0]instanceof gg?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&&(Ui.shared.remove(this.update,this),this._isConnectedToTicker=!1))},g.prototype.play=function(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(Ui.shared.add(this.update,this,fA.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=this._durations[this.currentFrame];)r-=this._durations[this.currentFrame]*C,this._currentTime+=C;this._currentTime+=r/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?FV(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):I===4?FV(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=cJe.exec(e))?new iC(g[1],g[2],g[3],1):(g=uJe.exec(e))?new iC(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=dJe.exec(e))?FV(g[1],g[2],g[3],g[4]):(g=hJe.exec(e))?FV(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=mJe.exec(e))?Fee(g[1],g[2]/100,g[3]/100,1):(g=fJe.exec(e))?Fee(g[1],g[2]/100,g[3]/100,g[4]):Nee.hasOwnProperty(e)?Kee(Nee[e]):e==="transparent"?new iC(NaN,NaN,NaN,0):null}function Kee(e){return new iC(e>>16&255,e>>8&255,e&255,1)}function FV(e,g,I,i){return i<=0&&(e=g=I=NaN),new iC(e,g,I,i)}function hpe(e){return e instanceof W0||(e=qd(e)),e?(e=e.rgb(),new iC(e.r,e.g,e.b,e.opacity)):new iC}function BX(e,g,I,i){return arguments.length===1?hpe(e):new iC(e,g,I,i??1)}function iC(e,g,I,i){this.r=+e,this.g=+g,this.b=+I,this.opacity=+i}pT(iC,BX,KU(W0,{brighter:function(e){return e=e==null?hb:Math.pow(hb,e),new iC(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?$d:Math.pow($d,e),new iC(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:xee,formatHex:xee,formatRgb:Dee,toString:Dee}));function xee(){return"#"+g5(this.r)+g5(this.g)+g5(this.b)}function Dee(){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 g5(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function Fee(e,g,I,i){return i<=0?e=g=I=NaN:I<=0||I>=1?e=g=NaN:g<=0&&(e=NaN),new za(e,g,I,i)}function mpe(e){if(e instanceof za)return new za(e.h,e.s,e.l,e.opacity);if(e instanceof W0||(e=qd(e)),!e)return new za;if(e instanceof za)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 za(r,o,a,e.opacity)}function bJe(e,g,I,i){return arguments.length===1?mpe(e):new za(e,g,I,i??1)}function za(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}pT(za,bJe,KU(W0,{brighter:function(e){return e=e==null?hb:Math.pow(hb,e),new za(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?$d:Math.pow($d,e),new za(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 iC(I5(e>=240?e-240:e+120,n,i),I5(e,n,i),I5(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 I5(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 yJe=Math.PI/180,ZJe=180/Math.PI;var fpe=-.14861,xU=1.78277,DU=-.29227,bT=-.90649,bB=1.97294,Eee=bB*bT,Mee=bB*xU,zee=xU*DU-bT*fpe;function GJe(e){if(e instanceof Xd)return new Xd(e.h,e.s,e.l,e.opacity);e instanceof iC||(e=hpe(e));var g=e.r/255,I=e.g/255,i=e.b/255,n=(zee*i+Eee*g-Mee*I)/(zee+Eee-Mee),C=i-n,r=(bB*(I-n)-DU*C)/bT,o=Math.sqrt(r*r+C*C)/(bB*n*(1-n)),a=o?Math.atan2(r,C)*ZJe-120:NaN;return new Xd(a<0?a+360:a,o,n,e.opacity)}function Jc(e,g,I,i){return arguments.length===1?GJe(e):new Xd(e,g,I,i??1)}function Xd(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}pT(Xd,Jc,KU(W0,{brighter:function(e){return e=e==null?hb:Math.pow(hb,e),new Xd(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?$d:Math.pow($d,e),new Xd(this.h,this.s,this.l*e,this.opacity)},rgb:function(){var e=isNaN(this.h)?0:(this.h+120)*yJe,g=+this.l,I=isNaN(this.s)?0:this.s*g*(1-g),i=Math.cos(e),n=Math.sin(e);return new iC(255*(g+I*(fpe*i+xU*n)),255*(g+I*(DU*i+bT*n)),255*(g+I*(bB*i)),this.opacity)}}));function ppe(e,g){return eg?1:e>=g?0:NaN}function FU(e){let g=e,I=e;e.length===1&&(g=(r,o)=>e(r)-o,I=vJe(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 vJe(e){return(g,I)=>ppe(e(g),I)}function BJe(e){return e===null?NaN:+e}const SJe=FU(ppe),wJe=SJe.right;FU(BJe).center;const VJe=wJe;let RJe=class extends Map{constructor(g,I=HJe){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(Pee(this,g))}has(g){return super.has(Pee(this,g))}set(g,I){return super.set(WJe(this,g),I)}delete(g){return super.delete(XJe(this,g))}};function Pee({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):I}function WJe({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):(e.set(i,I),I)}function XJe({_intern:e,_key:g},I){const i=g(I);return e.has(i)&&(I=e.get(I),e.delete(i)),I}function HJe(e){return e!==null&&typeof e=="object"?e.valueOf():e}function Jee(e){return e}function yT(e,...g){return TJe(e,Jee,Jee,g)}function TJe(e,g,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new RJe,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 jM=Math.sqrt(50),$M=Math.sqrt(10),qM=Math.sqrt(2);function NJe(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>=jM?10:C>=$M?5:C>=qM?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=jM?10:C>=$M?5:C>=qM?2:1)}function kJe(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>=jM?n*=10:C>=$M?n*=5:C>=qM&&(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 X1(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 YJe(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=wr(e,g)+wr(1-e,g),i=I-1;return Ky(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=wr(1-e,g),i=wr(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 mt.lli8(n,C,r,o,a,s,A,l)},lli:function(e,g){return mt.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 Ii(I,i,I+r,i+o,I+2*r,i+2*o,n,C)},findbbox:function(e){let g=i5,I=i5,i=n5,n=n5;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=mt.makeline(g.points[i-1],e.points[0]),r=mt.makeline(e.points[n-1],g.points[0]),o={startcap:C,forward:e,back:g,endcap:r,bbox:mt.findbbox([C,e,g,r])};return o.intersections=function(a){return mt.shapeintersections(o,o.bbox,a,a.bbox,I)},o},getminmax:function(e,g,I){if(!I)return{min:0,max:0};let i=i5,n=n5,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=-xy(g.p2.y-i,g.p2.x-I),C=function(r){return{x:(r.x-I)*FA(n)-(r.y-i)*Nm(n),y:(r.x-I)*Nm(n)+(r.y-i)*FA(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=mt.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=-ml(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(mt.approximately(s,0)){if(mt.approximately(A,0))return mt.approximately(l,0)?[]:[-c/l].filter(n);const G=ml(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=ml(v),V=-h/(2*w),S=V<-1?-1:V>1?1:V,X=KJe(S),W=Dy(w),R=2*W;return y=R*FA(X/3)-A/3,Z=R*FA((X+EV)/3)-A/3,B=R*FA((X+2*EV)/3)-A/3,[y,Z,B].filter(n)}else{if(f===0)return b=m<0?Dy(-m):-Dy(m),y=2*b-A/3,Z=-b-A/3,[y,Z].filter(n);{const G=ml(f);return b=Dy(-m+G),p=Dy(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=-ml(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=mt.compute(e,g),c=mt.compute(e,I),u=l.x*l.x+l.y*l.y;if(i?(C=ml(wr(l.y*c.z-c.y*l.z,2)+wr(l.z*c.x-c.z*l.x,2)+wr(l.x*c.y-c.x*l.y,2)),r=wr(u+l.z*l.z,3/2)):(C=l.x*c.y-l.y*c.x,r=wr(u,3/2)),C===0||r===0)return{k:0,r:0};if(s=C/r,A=r/C,!n){const d=mt.curvature(e-.001,g,I,i,!0).k,h=mt.curvature(e+.001,g,I,i,!0).k;a=(h-s+(s-d))/2,o=(Ky(h-s)+Ky(s-d))/2}return{k:s,r:A,dk:a,adk:o}},inflections:function(e){if(e.length<4)return[];const g=mt.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(mt.approximately(r,0)){if(!mt.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 mt.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+=EV),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;cFy(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 Ii(I,I,i);if(n===1)return new Ii(g,I,I);const C=Ii.getABC(2,g,I,i,n);return new Ii(g,C.A,i)}static cubicFromPoints(g,I,i,n,C){typeof n>"u"&&(n=.5);const r=Ii.getABC(3,g,I,i,n);typeof C>"u"&&(C=mt.dist(I,r.C));const o=C*(1-n)/n,a=mt.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 Ii(g,y,Z,i)}static getUtils(){return mt}getUtils(){return Ii.getUtils()}static get PolyBezier(){return SX}valueOf(){return this.toString()}toString(){return mt.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 mt.length(this.derivative.bind(this))}static getABC(g=2,I,i,n,C=.5){const r=mt.projectionratio(C,g),o=1-r,a={x:r*I.x+o*n.x,y:r*I.y+o*n.y},s=mt.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 Ii.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?mt.computeWithRatios(g,this.points,this.ratios,this._3d):mt.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(mt.numberSort))}).bind(this)),g.values=I.sort(mt.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]=mt.getminmax(this,i,g[i])}).bind(this)),I}overlaps(g){const I=this.bbox(),i=g.bbox();return mt.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 Ii(n)]}return this.reduce().map(function(i){return i._linear?i.offset(g)[0]:i.scale(g)})}simple(){if(this.order===3){const n=mt.angle(this.points[0],this.points[3],this.points[1]),C=mt.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),Fy(MJe(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]=mt.lli4(c,d,A,a[l+1])}),new Ii(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 mt.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=mt.makeline(m,d),p=mt.makeline(h,f),y=[b].concat(o).concat([p]).concat(a);return y.length,new SX(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 mt.between(o.x,I,n)&&mt.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=mt.dist(g,I),s=mt.dist(g,r),A=mt.dist(g,o);return Fy(s-a)+Fy(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=mt.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*FJe(s.e),y:s.y+s.r*EJe(s.e)};s.e+=mt.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 EU(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function PJe(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 Uee=Symbol("implicit");function wX(){var e=new Map,g=[],I=[],i=Uee;function n(C){var r=C+"",o=e.get(r);if(!o){if(i!==Uee)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 wX(g,I).unknown(i)},EU.apply(n,arguments),n}function Zpe(){var e=wX().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 Gpe(e,g){return function(I){return e+I*g}}function _Je(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 LJe(e,g){var I=g-e;return I?Gpe(e,I>180||I<-180?I-360*Math.round(I/360):I):ZT(isNaN(e)?g:e)}function UJe(e){return(e=+e)==1?Bp:function(g,I){return I-g?_Je(g,I,e):ZT(isNaN(g)?I:g)}}function Bp(e,g){var I=g-e;return I?Gpe(e,I):ZT(isNaN(e)?g:e)}const Qee=function e(g){var I=UJe(g);function i(n,C){var r=I((n=BX(n)).r,(C=BX(C)).r),o=I(n.g,C.g),a=I(n.b,C.b),s=Bp(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 QJe(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:VX(i,n)})),I=C5.lastIndex;return Ig&&(I=e,e=g,g=I),function(i){return Math.max(e,Math.min(g,i))}}function aOe(e,g,I){var i=e[0],n=e[1],C=g[0],r=g[1];return n2?AOe:aOe,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),VX)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,rOe),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=vpe,A()},l.clamp=function(c){return arguments.length?(r=c?!0:sc,A()):r!==sc},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 cOe(){return lOe()(sc,sc)}function uOe(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function RX(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=RX(Math.abs(e)),e?e[1]:NaN}function dOe(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 hOe(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var mOe=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function WX(e){if(!(g=mOe.exec(e)))throw new Error("invalid format: "+e);var g;return new MU({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]})}WX.prototype=MU.prototype;function MU(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+""}MU.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 fOe(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 wpe;function pOe(e,g){var I=RX(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(wpe=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")+RX(e,Math.max(0,g+C-1))[0]}function $ee(e,g){var I=RX(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 qee={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:uOe,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)=>$ee(e*100,g),r:$ee,s:pOe,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function ete(e){return e}var tte=Array.prototype.map,gte=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function bOe(e){var g=e.grouping===void 0||e.thousands===void 0?ete:dOe(tte.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?ete:hOe(tte.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=WX(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"):qee[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=qee[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 K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=fOe(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?gte[8+wpe/3]:"")+W+(K&&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 F=X.length+S.length+W.length,J=F>1)+X+S+W+J.slice(F);break;default:S=J+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function A(l,c){var u=s((l=WX(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(mb(c)/3)))*3,h=Math.pow(10,-d),m=gte[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var MV,Vpe,Rpe;yOe({thousands:",",grouping:[3],currency:["$",""]});function yOe(e){return MV=bOe(e),Vpe=MV.format,Rpe=MV.formatPrefix,MV}function ZOe(e){return Math.max(0,-mb(Math.abs(e)))}function GOe(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(mb(g)/3)))*3-mb(Math.abs(e)))}function vOe(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,mb(g)-mb(e))+1}function BOe(e,g,I,i){var n=kJe(e,g,I),C;switch(i=WX(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(e),Math.abs(g));return i.precision==null&&!isNaN(C=GOe(n,r))&&(i.precision=C),Rpe(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=vOe(n,Math.max(Math.abs(e),Math.abs(g))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=ZOe(n))&&(i.precision=C-(i.type==="%")*2);break}}return Vpe(i)}function Wpe(e){var g=e.domain;return e.ticks=function(I){var i=g();return NJe(i[0],i[i.length-1],I??10)},e.tickFormat=function(I,i){var n=g();return BOe(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=bpe(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 eh(){var e=cOe();return e.copy=function(){return sOe(e,eh())},EU.apply(e,arguments),Wpe(e)}function SOe(){var e=0,g=1,I,i,n,C,r=sc,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(GT),s.rangeRound=A(vpe),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 wOe(e,g){return g.domain(e.domain()).interpolator(e.interpolator()).clamp(e.clamp()).unknown(e.unknown())}function Xpe(){var e=Wpe(SOe()(sc));return e.copy=function(){return wOe(e,Xpe())},PJe.apply(e,arguments)}var VOe=typeof global=="object"&&global&&global.Object===Object&&global;const Hpe=VOe;var ROe=typeof self=="object"&&self&&self.Object===Object&&self,WOe=Hpe||ROe||Function("return this")();const VA=WOe;var XOe=VA.Symbol;const bA=XOe;var Tpe=Object.prototype,HOe=Tpe.hasOwnProperty,TOe=Tpe.toString,My=bA?bA.toStringTag:void 0;function NOe(e){var g=HOe.call(e,My),I=e[My];try{e[My]=void 0;var i=!0}catch{}var n=TOe.call(e);return i&&(g?e[My]=I:delete e[My]),n}var kOe=Object.prototype,YOe=kOe.toString;function KOe(e){return YOe.call(e)}var xOe="[object Null]",DOe="[object Undefined]",Ite=bA?bA.toStringTag:void 0;function X0(e){return e==null?e===void 0?DOe:xOe:Ite&&Ite in Object(e)?NOe(e):KOe(e)}function Oc(e){return e!=null&&typeof e=="object"}var FOe="[object Symbol]";function vT(e){return typeof e=="symbol"||Oc(e)&&X0(e)==FOe}function Npe(e,g){for(var I=-1,i=e==null?0:e.length,n=Array(i);++I-1}var W_e=9007199254740991,X_e=/^(?:0|[1-9]\d*)$/;function zU(e,g){var I=typeof e;return g=g??W_e,!!g&&(I=="number"||I!="symbol"&&X_e.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=N_e}function JU(e){return e!=null&&PU(e.length)&&!Ype(e)}function k_e(e,g,I){if(!Ks(I))return!1;var i=typeof g;return(i=="number"?JU(I)&&zU(g,I.length):i=="string"&&g in I)?BT(I[g],e):!1}var Y_e=Object.prototype;function OU(e){var g=e&&e.constructor,I=typeof g=="function"&&g.prototype||Y_e;return e===I}function K_e(e,g){for(var I=-1,i=Array(e);++I-1}function jLe(e,g){var I=this.__data__,i=wT(I,e);return i<0?(++this.size,I.push([e,g])):I[i][1]=g,this}function js(e){var g=-1,I=e==null?0:e.length;for(this.clear();++g=g?e:g)),e}function hUe(){this.__data__=new js,this.size=0}function mUe(e){var g=this.__data__,I=g.delete(e);return this.size=g.size,I}function fUe(e){return this.__data__.get(e)}function pUe(e){return this.__data__.has(e)}var bUe=200;function yUe(e,g){var I=this.__data__;if(I instanceof js){var i=I.__data__;if(!ZB||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&oQe?new vB:void 0;for(C.set(e,g),C.set(g,e);++l=Ije){var s=g?null:gje(e);if(s)return qU(s);r=!1,n=nbe,a=new vB}else a=g?[]:o;e:for(;++ijJe(e[e.length-1]);var Cje=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(RA);const rje=H0(Cje);var oje=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(RA);const aje=H0(oje);var Aje=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(RA);const sje=H0(Aje);var lje=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(RA);const cje=H0(lje);var uje=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(RA);const dje=H0(uje);var hje=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(RA);const mje=H0(hje);function fje(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 pje=Spe(Jc(-100,.75,.35),Jc(80,1.5,.8));Spe(Jc(260,.75,.35),Jc(80,1.5,.8));Jc();function XT(e){var g=e.length;return function(I){return e[Math.max(0,Math.min(g-1,Math.floor(I*g)))]}}const sbe=XT(RA("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));XT(RA("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));XT(RA("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));XT(RA("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));var gh={},HT={};HT.byteLength=Zje;HT.toByteArray=vje;HT.fromByteArray=wje;var Pa=[],Wr=[],bje=typeof Uint8Array<"u"?Uint8Array:Array,A5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var km=0,yje=A5.length;km0)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 Zje(e){var g=lbe(e),I=g[0],i=g[1];return(I+i)*3/4-i}function Gje(e,g,I){return(g+I)*3/4-I}function vje(e){var g,I=lbe(e),i=I[0],n=I[1],C=new bje(Gje(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 Bje(e){return Pa[e>>18&63]+Pa[e>>12&63]+Pa[e>>6&63]+Pa[e&63]}function Sje(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 t7={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */t7.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)};t7.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};/*! + */wA.add(Wfe,Nfe,Tfe,Ufe,rpe,kU,Ape,dpe,xfe,Ofe,_fe,ope,$me,Yfe);var fJe={AlphaFilter:OPe,BlurFilter:$Pe,BlurFilterPass:LM,ColorMatrixFilter:QM,DisplacementFilter:IJe,FXAAFilter:oJe,NoiseFilter:sJe};const Gpe=Object.freeze(Object.defineProperty({__proto__:null,get ALPHA_MODES(){return no},AbstractBatchRenderer:Gfe,AbstractMultiResource:pT,AbstractRenderer:bfe,AccessibilityManager:Wfe,AnimatedSprite:mJe,AppLoaderPlugin:Yfe,Application:ppe,ArrayResource:aU,Attribute:wM,get BLEND_MODES(){return Jt},get BUFFER_BITS(){return rB},get BUFFER_TYPE(){return ia},BaseImageResource:pA,BasePrepare:Ipe,BaseRenderTexture:dU,BaseTexture:Gg,BatchDrawCall:G9,BatchGeometry:NU,BatchPluginFactory:Bfe,BatchRenderer:kU,BatchShaderGenerator:vfe,BatchSystem:pU,BatchTextureArray:v9,BitmapFont:qA,BitmapFontData:yB,BitmapFontLoader:dpe,BitmapText:zPe,BlobResource:Dfe,Bounds:dB,BrowserAdapter:cme,Buffer:mI,BufferResource:_h,get CLEAR_MODES(){return FC},get COLOR_MASK_BITS(){return iM},CanvasResource:AU,Circle:Lme,CompressedTextureLoader:xfe,CompressedTextureResource:S9,Container:sa,ContextSystem:bU,CountLimiter:ipe,CubeResource:sU,DDSLoader:Ofe,DEG_TO_RAD:_me,get DRAW_MODES(){return JC},DisplayObject:$i,get ENV(){return mA},Ellipse:Ume,get ExtensionType(){return Og},Extract:Nfe,get FORMATS(){return ft},FORMATS_TO_COMPONENTS:zfe,FillStyle:KU,Filter:Qs,FilterState:gfe,FilterSystem:fU,Framebuffer:Z9,FramebufferSystem:yU,get GC_MODES(){return oB},GLFramebuffer:ife,GLProgram:mfe,GLTexture:W1,GRAPHICS_CURVES:cb,Geometry:w0,GeometrySystem:ZU,Graphics:bB,GraphicsData:DM,GraphicsGeometry:tpe,IGLUniformData:$3e,INSTALLED:hB,get INTERNAL_FORMATS(){return Ig},INTERNAL_FORMAT_TO_BYTES_PER_PIXEL:fB,ImageBitmapResource:uU,ImageResource:bT,InteractionData:RM,InteractionEvent:Xfe,InteractionManager:Tfe,InteractionTrackingData:X1,KTXLoader:_fe,get LINE_CAP(){return us},get LINE_JOIN(){return Ma},LineStyle:gpe,Loader:mB,get LoaderResource(){return Di},get MASK_TYPES(){return rI},get MIPMAP_MODES(){return Io},get MSAA_QUALITY(){return fi},MaskData:Ife,MaskSystem:GU,Matrix:ZI,Mesh:db,MeshBatchUvs:spe,MeshGeometry:VS,MeshMaterial:hb,NineSlicePlane:dJe,ObjectRenderer:RS,ObservablePoint:Ad,PI_2:uB,get PRECISION(){return kr},ParticleContainer:rPe,ParticleRenderer:Ufe,PlaneGeometry:bpe,Point:ai,Polygon:FG,Prepare:rpe,Program:R0,ProjectionSystem:SU,Quad:tfe,QuadUv:mU,RAD_TO_DEG:Ome,get RENDERER_TYPE(){return ab},Rectangle:wg,RenderTexture:Ys,RenderTexturePool:efe,RenderTextureSystem:wU,Renderer:HU,ResizePlugin:fpe,Resource:Ud,RopeGeometry:ype,RoundedRectangle:Qme,Runner:LI,get SAMPLER_TYPES(){return CB},get SCALE_MODES(){return Qo},get SHAPES(){return XI},SVGResource:lU,ScissorSystem:vU,Shader:ws,ShaderSystem:RU,SimpleMesh:uJe,SimplePlane:Zpe,SimpleRope:cJe,Sprite:V0,SpriteMaskFilter:sfe,Spritesheet:Cpe,SpritesheetLoader:ope,State:tu,StateSystem:VU,StencilSystem:BU,System:uze,get TARGETS(){return Wc},get TEXT_GRADIENT(){return ub},get TYPES(){return Et},TYPES_TO_BYTES_PER_COMPONENT:TM,TYPES_TO_BYTES_PER_PIXEL:Pfe,TemporaryDisplayObject:oU,Text:xU,TextFormat:lpe,TextMetrics:da,TextStyle:Qd,Texture:gg,TextureGCSystem:WU,TextureLoader:Kfe,TextureMatrix:yT,TextureSystem:XU,TextureUvs:hU,Ticker:UI,TickerPlugin:$me,TilingSprite:WPe,TilingSpriteRenderer:Ape,TimeLimiter:VPe,Transform:rU,get UPDATE_PRIORITY(){return fA},UniformGroup:Xc,VERSION:Rfe,VideoResource:cU,ViewableBuffer:B9,get WRAP_MODES(){return ga},XMLFormat:w9,XMLStringFormat:cpe,accessibleTarget:Vfe,autoDetectFormat:MU,autoDetectRenderer:yfe,autoDetectResource:fT,checkMaxIfStatementsInShader:Afe,createUBOElements:ufe,defaultFilterVertex:TU,defaultVertex:Zfe,extensions:wA,filters:fJe,generateProgram:ffe,generateUniformBufferSync:hfe,getTestContext:Cfe,getUBOData:dfe,graphicsUtils:lPe,groupD8:wi,interactiveTarget:Hfe,isMobile:OC,parseDDS:Mfe,parseKTX:Jfe,resources:Sfe,settings:Gt,systems:wfe,uniformParsers:Vd,utils:y3e},Symbol.toStringTag,{value:"Module"}));function ZT(e,g,i){e.prototype=g.prototype=i,i.constructor=e}function zU(e,g){var i=Object.create(e.prototype);for(var I in g)i[I]=g[I];return i}function X0(){}var jd=.7,mb=1/jd,Bp="\\s*([+-]?\\d+)\\s*",ZB="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)\\s*",AA="\\s*([+-]?\\d*\\.?\\d+(?:[eE][+-]?\\d+)?)%\\s*",pJe=/^#([0-9a-f]{3,8})$/,bJe=new RegExp("^rgb\\("+[Bp,Bp,Bp]+"\\)$"),yJe=new RegExp("^rgb\\("+[AA,AA,AA]+"\\)$"),ZJe=new RegExp("^rgba\\("+[Bp,Bp,Bp,ZB]+"\\)$"),GJe=new RegExp("^rgba\\("+[AA,AA,AA,ZB]+"\\)$"),vJe=new RegExp("^hsl\\("+[ZB,AA,AA]+"\\)$"),BJe=new RegExp("^hsla\\("+[ZB,AA,AA,ZB]+"\\)$"),xee={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(X0,$d,{copy:function(e){return Object.assign(new this.constructor,this,e)},displayable:function(){return this.rgb().displayable()},hex:Eee,formatHex:Eee,formatHsl:SJe,formatRgb:Mee,toString:Mee});function Eee(){return this.rgb().formatHex()}function SJe(){return Bpe(this).formatHsl()}function Mee(){return this.rgb().formatRgb()}function $d(e){var g,i;return e=(e+"").trim().toLowerCase(),(g=pJe.exec(e))?(i=g[1].length,g=parseInt(g[1],16),i===6?zee(g):i===3?new ir(g>>8&15|g>>4&240,g>>4&15|g&240,(g&15)<<4|g&15,1):i===8?zR(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):i===4?zR(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=bJe.exec(e))?new ir(g[1],g[2],g[3],1):(g=yJe.exec(e))?new ir(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=ZJe.exec(e))?zR(g[1],g[2],g[3],g[4]):(g=GJe.exec(e))?zR(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=vJe.exec(e))?Oee(g[1],g[2]/100,g[3]/100,1):(g=BJe.exec(e))?Oee(g[1],g[2]/100,g[3]/100,g[4]):xee.hasOwnProperty(e)?zee(xee[e]):e==="transparent"?new ir(NaN,NaN,NaN,0):null}function zee(e){return new ir(e>>16&255,e>>8&255,e&255,1)}function zR(e,g,i,I){return I<=0&&(e=g=i=NaN),new ir(e,g,i,I)}function vpe(e){return e instanceof X0||(e=$d(e)),e?(e=e.rgb(),new ir(e.r,e.g,e.b,e.opacity)):new ir}function R9(e,g,i,I){return arguments.length===1?vpe(e):new ir(e,g,i,I??1)}function ir(e,g,i,I){this.r=+e,this.g=+g,this.b=+i,this.opacity=+I}ZT(ir,R9,zU(X0,{brighter:function(e){return e=e==null?mb:Math.pow(mb,e),new ir(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?jd:Math.pow(jd,e),new ir(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:Pee,formatHex:Pee,formatRgb:Jee,toString:Jee}));function Pee(){return"#"+n5(this.r)+n5(this.g)+n5(this.b)}function Jee(){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 n5(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function Oee(e,g,i,I){return I<=0?e=g=i=NaN:i<=0||i>=1?e=g=NaN:g<=0&&(e=NaN),new za(e,g,i,I)}function Bpe(e){if(e instanceof za)return new za(e.h,e.s,e.l,e.opacity);if(e instanceof X0||(e=$d(e)),!e)return new za;if(e instanceof za)return e;e=e.rgb();var g=e.r/255,i=e.g/255,I=e.b/255,n=Math.min(g,i,I),r=Math.max(g,i,I),C=NaN,o=r-n,a=(r+n)/2;return o?(g===r?C=(i-I)/o+(i0&&a<1?0:C,new za(C,o,a,e.opacity)}function wJe(e,g,i,I){return arguments.length===1?Bpe(e):new za(e,g,i,I??1)}function za(e,g,i,I){this.h=+e,this.s=+g,this.l=+i,this.opacity=+I}ZT(za,wJe,zU(X0,{brighter:function(e){return e=e==null?mb:Math.pow(mb,e),new za(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?jd:Math.pow(jd,e),new za(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 ir(r5(e>=240?e-240:e+120,n,I),r5(e,n,I),r5(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 r5(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 RJe=Math.PI/180,VJe=180/Math.PI;var Spe=-.14861,PU=1.78277,JU=-.29227,GT=-.90649,GB=1.97294,_ee=GB*GT,Lee=GB*PU,Uee=PU*JU-GT*Spe;function WJe(e){if(e instanceof Wd)return new Wd(e.h,e.s,e.l,e.opacity);e instanceof ir||(e=vpe(e));var g=e.r/255,i=e.g/255,I=e.b/255,n=(Uee*I+_ee*g-Lee*i)/(Uee+_ee-Lee),r=I-n,C=(GB*(i-n)-JU*r)/GT,o=Math.sqrt(C*C+r*r)/(GB*n*(1-n)),a=o?Math.atan2(C,r)*VJe-120:NaN;return new Wd(a<0?a+360:a,o,n,e.opacity)}function Pc(e,g,i,I){return arguments.length===1?WJe(e):new Wd(e,g,i,I??1)}function Wd(e,g,i,I){this.h=+e,this.s=+g,this.l=+i,this.opacity=+I}ZT(Wd,Pc,zU(X0,{brighter:function(e){return e=e==null?mb:Math.pow(mb,e),new Wd(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?jd:Math.pow(jd,e),new Wd(this.h,this.s,this.l*e,this.opacity)},rgb:function(){var e=isNaN(this.h)?0:(this.h+120)*RJe,g=+this.l,i=isNaN(this.s)?0:this.s*g*(1-g),I=Math.cos(e),n=Math.sin(e);return new ir(255*(g+i*(Spe*I+PU*n)),255*(g+i*(JU*I+GT*n)),255*(g+i*(GB*I)),this.opacity)}}));function wpe(e,g){return eg?1:e>=g?0:NaN}function OU(e){let g=e,i=e;e.length===1&&(g=(C,o)=>e(C)-o,i=XJe(e));function I(C,o,a,s){for(a==null&&(a=0),s==null&&(s=C.length);a>>1;i(C[A],o)<0?a=A+1:s=A}return a}function n(C,o,a,s){for(a==null&&(a=0),s==null&&(s=C.length);a>>1;i(C[A],o)>0?s=A:a=A+1}return a}function r(C,o,a,s){a==null&&(a=0),s==null&&(s=C.length);const A=I(C,o,a,s-1);return A>a&&g(C[A-1],o)>-g(C[A],o)?A-1:A}return{left:I,center:r,right:n}}function XJe(e){return(g,i)=>wpe(e(g),i)}function HJe(e){return e===null?NaN:+e}const TJe=OU(wpe),NJe=TJe.right;OU(HJe).center;const kJe=NJe;let YJe=class extends Map{constructor(g,i=DJe){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(Qee(this,g))}has(g){return super.has(Qee(this,g))}set(g,i){return super.set(KJe(this,g),i)}delete(g){return super.delete(FJe(this,g))}};function Qee({_intern:e,_key:g},i){const I=g(i);return e.has(I)?e.get(I):i}function KJe({_intern:e,_key:g},i){const I=g(i);return e.has(I)?e.get(I):(e.set(I,i),i)}function FJe({_intern:e,_key:g},i){const I=g(i);return e.has(I)&&(i=e.get(i),e.delete(I)),i}function DJe(e){return e!==null&&typeof e=="object"?e.valueOf():e}function jee(e){return e}function vT(e,...g){return xJe(e,jee,jee,g)}function xJe(e,g,i,I){return function n(r,C){if(C>=I.length)return i(r);const o=new YJe,a=I[C++];let s=-1;for(const A of r){const l=a(A,++s,r),c=o.get(l);c?c.push(A):o.set(l,[A])}for(const[A,l]of o)o.set(A,n(l,C));return g(o)}(e,0)}var g3=Math.sqrt(50),i3=Math.sqrt(10),I3=Math.sqrt(2);function EJe(e,g,i){var I,n=-1,r,C,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,C=new Array(r=s-a+1);++ng&&--s,C=new Array(r=s-a+1);++n=0?(r>=g3?10:r>=i3?5:r>=I3?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(r>=g3?10:r>=i3?5:r>=I3?2:1)}function MJe(e,g,i){var I=Math.abs(g-e)/Math.max(0,i),n=Math.pow(10,Math.floor(Math.log(I)/Math.LN10)),r=I/n;return r>=g3?n*=10:r>=i3?n*=5:r>=I3&&(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 N1(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 zJe(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,r=new Array(n);++I1;){for(let o=0;o1;n--,r--){const C=[];for(let o=0,a;o"u")e=.5;else if(e===0||e===1)return e;const i=SC(e,g)+SC(1-e,g),I=i-1;return Fy(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=SC(1-e,g),I=SC(e,g)+i;return i/I},lli8:function(e,g,i,I,n,r,C,o){const a=(e*I-g*i)*(n-C)-(e-i)*(n*o-r*C),s=(e*I-g*i)*(r-o)-(g-I)*(n*o-r*C),A=(e-i)*(r-o)-(g-I)*(n-C);return A==0?!1:{x:a/A,y:s/A}},lli4:function(e,g,i,I){const n=e.x,r=e.y,C=g.x,o=g.y,a=i.x,s=i.y,A=I.x,l=I.y;return mt.lli8(n,r,C,o,a,s,A,l)},lli:function(e,g){return mt.lli4(e,e.c,g,g.c)},makeline:function(e,g){const i=e.x,I=e.y,n=g.x,r=g.y,C=(n-i)/3,o=(r-I)/3;return new iI(i,I,i+C,I+o,i+2*C,I+2*o,n,r)},findbbox:function(e){let g=C5,i=C5,I=o5,n=o5;return e.forEach(function(r){const C=r.bbox();g>C.x.min&&(g=C.x.min),i>C.y.min&&(i=C.y.min),I0&&(A.c1=a,A.c2=s,A.s1=e,A.s2=i,r.push(A))})}),r},makeshape:function(e,g,i){const I=g.points.length,n=e.points.length,r=mt.makeline(g.points[I-1],e.points[0]),C=mt.makeline(e.points[n-1],g.points[0]),o={startcap:r,forward:e,back:g,endcap:C,bbox:mt.findbbox([r,e,g,C])};return o.intersections=function(a){return mt.shapeintersections(o,o.bbox,a,a.bbox,i)},o},getminmax:function(e,g,i){if(!i)return{min:0,max:0};let I=C5,n=o5,r,C;i.indexOf(0)===-1&&(i=[0].concat(i)),i.indexOf(1)===-1&&i.push(1);for(let o=0,a=i.length;on&&(n=C[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=-Dy(g.p2.y-I,g.p2.x-i),r=function(C){return{x:(C.x-i)*xA(n)-(C.y-I)*Tm(n),y:(C.x-i)*Tm(n)+(C.y-I)*xA(n)}};return e.map(r)},roots:function(e,g){g=g||{p1:{x:0,y:0},p2:{x:1,y:0}};const i=e.length-1,I=mt.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,R=G-2*v+w;if(R!==0){const S=-ml(v*v-G*w),X=-G+v,W=-(S+X)/R,V=-(-S+X)/R;return[W,V].filter(n)}else if(v!==w&&R===0)return[(2*v-w)/(2*v-2*w)].filter(n);return[]}const r=I[0].y,C=I[1].y,o=I[2].y,a=I[3].y;let s=-r+3*C-3*o+a,A=3*r-6*C+3*o,l=-3*r+3*C,c=r;if(mt.approximately(s,0)){if(mt.approximately(A,0))return mt.approximately(l,0)?[]:[-c/l].filter(n);const G=ml(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=ml(v),R=-h/(2*w),S=R<-1?-1:R>1?1:R,X=PJe(S),W=xy(w),V=2*W;return y=V*xA(X/3)-A/3,Z=V*xA((X+PR)/3)-A/3,B=V*xA((X+2*PR)/3)-A/3,[y,Z,B].filter(n)}else{if(f===0)return b=m<0?xy(-m):-xy(m),y=2*b-A/3,Z=-b-A/3,[y,Z].filter(n);{const G=ml(f);return b=xy(-m+G),p=xy(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 r=-ml(i*i-g*I),C=-g+i,o=-(r+C)/n,a=-(-r+C)/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 r,C,o,a,s=0,A=0;const l=mt.compute(e,g),c=mt.compute(e,i),u=l.x*l.x+l.y*l.y;if(I?(r=ml(SC(l.y*c.z-c.y*l.z,2)+SC(l.z*c.x-c.z*l.x,2)+SC(l.x*c.y-c.x*l.y,2)),C=SC(u+l.z*l.z,3/2)):(r=l.x*c.y-l.y*c.x,C=SC(u,3/2)),r===0||C===0)return{k:0,r:0};if(s=r/C,A=C/r,!n){const d=mt.curvature(e-.001,g,i,I,!0).k,h=mt.curvature(e+.001,g,i,I,!0).k;a=(h-s+(s-d))/2,o=(Fy(h-s)+Fy(s-d))/2}return{k:s,r:A,dk:a,adk:o}},inflections:function(e){if(e.length<4)return[];const g=mt.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,r=g[3].x*g[2].y,C=18*(-3*i+2*I+3*n-r),o=18*(3*i-I-3*n),a=18*(n-i);if(mt.approximately(C,0)){if(!mt.approximately(o,0)){let c=-a/o;if(0<=c&&c<=1)return[c]}return[]}const s=o*o-4*C*a,A=Math.sqrt(s),l=2*C;return mt.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,r,C,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(),r=1e5,C=i||.5;if(I.x.size+I.y.sizeB||B>G)&&(Z+=PR),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(r!==6&&r!==8&&r!==9&&r!==12&&arguments.length!==1)throw new Error("Only new Bezier(point[]) is accepted for 4th and higher order curves");const C=this._3d=!n&&(r===9||r===12)||g&&g[0]&&typeof g[0].z<"u",o=this.points=[];for(let c=0,u=C?3:2;cEy(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 iI(i,i,I);if(n===1)return new iI(g,i,i);const r=iI.getABC(2,g,i,I,n);return new iI(g,r.A,I)}static cubicFromPoints(g,i,I,n,r){typeof n>"u"&&(n=.5);const C=iI.getABC(3,g,i,I,n);typeof r>"u"&&(r=mt.dist(i,C.C));const o=r*(1-n)/n,a=mt.dist(g,I),s=(I.x-g.x)/a,A=(I.y-g.y)/a,l=r*s,c=r*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=C.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 iI(g,y,Z,I)}static getUtils(){return mt}getUtils(){return iI.getUtils()}static get PolyBezier(){return V9}valueOf(){return this.toString()}toString(){return mt.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 r=1,C=g.length;r0}length(){return mt.length(this.derivative.bind(this))}static getABC(g=2,i,I,n,r=.5){const C=mt.projectionratio(r,g),o=1-C,a={x:C*i.x+o*n.x,y:C*i.y+o*n.y},s=mt.abcratio(r,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 iI.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?mt.computeWithRatios(g,this.points,this.ratios,this._3d):mt.compute(g,this.points,this._3d,this.ratios)}raise(){const g=this.points,i=[g[0]],I=g.length;for(let n=1,r,C;n1;){I=[];for(let C=0,o,a=i.length-1;C=0&&C<=1}),i=i.concat(g[I].sort(mt.numberSort))}).bind(this)),g.values=i.sort(mt.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]=mt.getminmax(this,I,g[I])}).bind(this)),i}overlaps(g){const i=this.bbox(),I=g.bbox();return mt.bboxoverlap(i,I)}offset(g,i){if(typeof i<"u"){const I=this.get(g),n=this.normal(g),r={c:I,n,x:I.x+n.x*i,y:I.y+n.y*i};return this._3d&&(r.z=I.z+n.z*i),r}if(this._linear){const I=this.normal(0),n=this.points.map(function(r){const C={x:r.x+g*I.x,y:r.y+g*I.y};return r.z&&I.z&&(C.z=r.z+g*I.z),C});return[new iI(n)]}return this.reduce().map(function(I){return I._linear?I.offset(g)[0]:I.scale(g)})}simple(){if(this.order===3){const n=mt.angle(this.points[0],this.points[3],this.points[1]),r=mt.angle(this.points[0],this.points[3],this.points[2]);if(n>0&&r<0||n<0&&r>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),Ey(UJe(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]=mt.lli4(c,d,A,a[l+1])}),new iI(s))}outline(g,i,I,n){i=typeof i>"u"?g:i;const r=this.reduce(),C=r.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(R){const S=v/G,X=(v+w)/G,W=B-Z;return mt.map(R,0,1,Z+S*W,Z+X*W)}}r.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[C-1].points[o[C-1].points.length-1],m=a[C-1].points[a[C-1].points.length-1],f=a[0].points[0],b=mt.makeline(m,d),p=mt.makeline(h,f),y=[b].concat(o).concat([p]).concat(a);return y.length,new V9(y)}outlineshapes(g,i,I){i=i||g;const n=this.outline(g,i).curves,r=[];for(let C=1,o=n.length;C1,a.endcap.virtual=C{var o=this.get(C);return mt.between(o.x,i,n)&&mt.between(o.y,I,r)})}selfintersects(g){const i=this.reduce(),I=i.length-2,n=[];for(let r=0,C,o,a;r0&&(r=r.concat(o))}),r}arcs(g){return g=g||.5,this._iterate(g,[])}_error(g,i,I,n){const r=(n-I)/4,C=this.get(I+r),o=this.get(n-r),a=mt.dist(g,i),s=mt.dist(g,C),A=mt.dist(g,o);return Ey(s-a)+Ey(A-a)}_iterate(g,i){let I=0,n=1,r;do{r=0,n=1;let C=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=mt.getccenter(C,o,a),s.interval={start:I,end:n},l=this._error(s,C,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*_Je(s.e),y:s.y+s.r*LJe(s.e)};s.e+=mt.angle({x:s.x,y:s.y},f,this.get(1))}break}n=n+(n-I)/2}else n=d;while(!u&&r++<100);if(r>=100)break;A=A||s,i.push(A),I=h}while(n<1);return i}}function _U(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function jJe(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 tte=Symbol("implicit");function W9(){var e=new Map,g=[],i=[],I=tte;function n(r){var C=r+"",o=e.get(C);if(!o){if(I!==tte)return I;e.set(C,o=g.push(r))}return i[(o-1)%i.length]}return n.domain=function(r){if(!arguments.length)return g.slice();g=[],e=new Map;for(const C of r){const o=C+"";e.has(o)||e.set(o,g.push(C))}return n},n.range=function(r){return arguments.length?(i=Array.from(r),n):i.slice()},n.unknown=function(r){return arguments.length?(I=r,n):I},n.copy=function(){return W9(g,i).unknown(I)},_U.apply(n,arguments),n}function Wpe(){var e=W9().unknown(void 0),g=e.domain,i=e.range,I=0,n=1,r,C,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],r=e[I+1],C=I>0?e[I-1]:2*n-r,o=I()=>e;function Xpe(e,g){return function(i){return e+i*g}}function eOe(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 tOe(e,g){var i=g-e;return i?Xpe(e,i>180||i<-180?i-360*Math.round(i/360):i):BT(isNaN(e)?g:e)}function gOe(e){return(e=+e)==1?Sp:function(g,i){return i-g?eOe(g,i,e):BT(isNaN(g)?i:g)}}function Sp(e,g){var i=g-e;return i?Xpe(e,i):BT(isNaN(e)?g:e)}const gte=function e(g){var i=gOe(g);function I(n,r){var C=i((n=R9(n)).r,(r=R9(r)).r),o=i(n.g,r.g),a=i(n.b,r.b),s=Sp(n.opacity,r.opacity);return function(A){return n.r=C(A),n.g=o(A),n.b=a(A),n.opacity=s(A),n+""}}return I.gamma=e,I}(1);function iOe(e){return function(g){var i=g.length,I=new Array(i),n=new Array(i),r=new Array(i),C,o;for(C=0;Ci&&(r=g.slice(i,r),o[C]?o[C]+=r:o[++C]=r),(I=I[0])===(n=n[0])?o[C]?o[C]+=n:o[++C]=n:(o[++C]=null,a.push({i:C,x:X9(I,n)})),i=a5.lastIndex;return ig&&(i=e,e=g,g=i),function(I){return Math.max(e,Math.min(g,I))}}function hOe(e,g,i){var I=e[0],n=e[1],r=g[0],C=g[1];return n2?mOe:hOe,a=s=null,l}function l(c){return c==null||isNaN(c=+c)?r:(a||(a=o(e.map(I),g,i)))(I(C(c)))}return l.invert=function(c){return C(n((s||(s=o(g,e.map(I),X9)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,uOe),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=Hpe,A()},l.clamp=function(c){return arguments.length?(C=c?!0:sc,A()):C!==sc},l.interpolate=function(c){return arguments.length?(i=c,A()):i},l.unknown=function(c){return arguments.length?(r=c,l):r},function(c,u){return I=c,n=u,A()}}function bOe(){return pOe()(sc,sc)}function yOe(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function H9(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 fb(e){return e=H9(Math.abs(e)),e?e[1]:NaN}function ZOe(e,g){return function(i,I){for(var n=i.length,r=[],C=0,o=e[0],a=0;n>0&&o>0&&(a+o+1>I&&(o=Math.max(1,I-a)),r.push(i.substring(n-=o,n+o)),!((a+=o+1)>I));)o=e[C=(C+1)%e.length];return r.reverse().join(g)}}function GOe(e){return function(g){return g.replace(/[0-9]/g,function(i){return e[+i]})}}var vOe=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function T9(e){if(!(g=vOe.exec(e)))throw new Error("invalid format: "+e);var g;return new LU({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]})}T9.prototype=LU.prototype;function LU(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+""}LU.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 BOe(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 kpe;function SOe(e,g){var i=H9(e,g);if(!i)return e+"";var I=i[0],n=i[1],r=n-(kpe=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,C=I.length;return r===C?I:r>C?I+new Array(r-C+1).join("0"):r>0?I.slice(0,r)+"."+I.slice(r):"0."+new Array(1-r).join("0")+H9(e,Math.max(0,g+r-1))[0]}function Ite(e,g){var i=H9(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 nte={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:yOe,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)=>Ite(e*100,g),r:Ite,s:SOe,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function rte(e){return e}var Cte=Array.prototype.map,ote=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function wOe(e){var g=e.grouping===void 0||e.thousands===void 0?rte:ZOe(Cte.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+"",r=e.numerals===void 0?rte:GOe(Cte.call(e.numerals,String)),C=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=T9(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"):nte[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)?C:"",v=nte[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=B,W=G,V,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=BOe(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?ote[8+kpe/3]:"")+W+(K&&d==="("?")":""),w){for(V=-1,H=S.length;++VY||Y>57){W=(Y===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=g(S,1/0));var x=X.length+S.length+W.length,J=x>1)+X+S+W+J.slice(x);break;default:S=J+X+S+W;break}return r(S)}return R.toString=function(){return l+""},R}function A(l,c){var u=s((l=T9(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(fb(c)/3)))*3,h=Math.pow(10,-d),m=ote[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var JR,Ype,Kpe;ROe({thousands:",",grouping:[3],currency:["$",""]});function ROe(e){return JR=wOe(e),Ype=JR.format,Kpe=JR.formatPrefix,JR}function VOe(e){return Math.max(0,-fb(Math.abs(e)))}function WOe(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(fb(g)/3)))*3-fb(Math.abs(e)))}function XOe(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,fb(g)-fb(e))+1}function HOe(e,g,i,I){var n=MJe(e,g,i),r;switch(I=T9(I??",f"),I.type){case"s":{var C=Math.max(Math.abs(e),Math.abs(g));return I.precision==null&&!isNaN(r=WOe(n,C))&&(I.precision=r),Kpe(I,C)}case"":case"e":case"g":case"p":case"r":{I.precision==null&&!isNaN(r=XOe(n,Math.max(Math.abs(e),Math.abs(g))))&&(I.precision=r-(I.type==="e"));break}case"f":case"%":{I.precision==null&&!isNaN(r=VOe(n))&&(I.precision=r-(I.type==="%")*2);break}}return Ype(I)}function Fpe(e){var g=e.domain;return e.ticks=function(i){var I=g();return EJe(I[0],I[I.length-1],i??10)},e.tickFormat=function(i,I){var n=g();return HOe(n[0],n[n.length-1],i??10,I)},e.nice=function(i){i==null&&(i=10);var I=g(),n=0,r=I.length-1,C=I[n],o=I[r],a,s,A=10;for(o0;){if(s=Rpe(C,o,i),s===a)return I[n]=C,I[r]=o,g(I);if(s>0)C=Math.floor(C/s)*s,o=Math.ceil(o/s)*s;else if(s<0)C=Math.ceil(C*s)/s,o=Math.floor(o*s)/s;else break;a=s}return e},e}function qd(){var e=bOe();return e.copy=function(){return fOe(e,qd())},_U.apply(e,arguments),Fpe(e)}function TOe(){var e=0,g=1,i,I,n,r,C=sc,o=!1,a;function s(l){return l==null||isNaN(l=+l)?a:C(n===0?.5:(l=(r(l)-i)*n,o?Math.max(0,Math.min(1,l)):l))}s.domain=function(l){return arguments.length?([e,g]=l,i=r(e=+e),I=r(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?(C=l,s):C};function A(l){return function(c){var u,d;return arguments.length?([u,d]=c,C=l(u,d),s):[C(0),C(1)]}}return s.range=A(ST),s.rangeRound=A(Hpe),s.unknown=function(l){return arguments.length?(a=l,s):a},function(l){return r=l,i=l(e),I=l(g),n=i===I?0:1/(I-i),s}}function NOe(e,g){return g.domain(e.domain()).interpolator(e.interpolator()).clamp(e.clamp()).unknown(e.unknown())}function Dpe(){var e=Fpe(TOe()(sc));return e.copy=function(){return NOe(e,Dpe())},jJe.apply(e,arguments)}var kOe=typeof global=="object"&&global&&global.Object===Object&&global;const xpe=kOe;var YOe=typeof self=="object"&&self&&self.Object===Object&&self,KOe=xpe||YOe||Function("return this")();const RA=KOe;var FOe=RA.Symbol;const bA=FOe;var Epe=Object.prototype,DOe=Epe.hasOwnProperty,xOe=Epe.toString,zy=bA?bA.toStringTag:void 0;function EOe(e){var g=DOe.call(e,zy),i=e[zy];try{e[zy]=void 0;var I=!0}catch{}var n=xOe.call(e);return I&&(g?e[zy]=i:delete e[zy]),n}var MOe=Object.prototype,zOe=MOe.toString;function POe(e){return zOe.call(e)}var JOe="[object Null]",OOe="[object Undefined]",ate=bA?bA.toStringTag:void 0;function H0(e){return e==null?e===void 0?OOe:JOe:ate&&ate in Object(e)?EOe(e):POe(e)}function Jc(e){return e!=null&&typeof e=="object"}var _Oe="[object Symbol]";function wT(e){return typeof e=="symbol"||Jc(e)&&H0(e)==_Oe}function Mpe(e,g){for(var i=-1,I=e==null?0:e.length,n=Array(I);++i-1}var K_e=9007199254740991,F_e=/^(?:0|[1-9]\d*)$/;function UU(e,g){var i=typeof e;return g=g??K_e,!!g&&(i=="number"||i!="symbol"&&F_e.test(e))&&e>-1&&e%1==0&&e-1&&e%1==0&&e<=E_e}function jU(e){return e!=null&&QU(e.length)&&!Ppe(e)}function M_e(e,g,i){if(!Ks(i))return!1;var I=typeof g;return(I=="number"?jU(i)&&UU(g,i.length):I=="string"&&g in i)?RT(i[g],e):!1}var z_e=Object.prototype;function $U(e){var g=e&&e.constructor,i=typeof g=="function"&&g.prototype||z_e;return e===i}function P_e(e,g){for(var i=-1,I=Array(e);++i-1}function IUe(e,g){var i=this.__data__,I=WT(i,e);return I<0?(++this.size,i.push([e,g])):i[I][1]=g,this}function js(e){var g=-1,i=e==null?0:e.length;for(this.clear();++g=g?e:g)),e}function GUe(){this.__data__=new js,this.size=0}function vUe(e){var g=this.__data__,i=g.delete(e);return this.size=g.size,i}function BUe(e){return this.__data__.get(e)}function SUe(e){return this.__data__.has(e)}var wUe=200;function RUe(e,g){var i=this.__data__;if(i instanceof js){var I=i.__data__;if(!BB||I.lengtho))return!1;var s=r.get(e),A=r.get(g);if(s&&A)return s==g&&A==e;var l=-1,c=!0,u=i&dQe?new wB:void 0;for(r.set(e,g),r.set(g,e);++l=A4e){var s=g?null:a4e(e);if(s)return n7(s);C=!1,n=cbe,a=new wB}else a=g?[]:o;e:for(;++IIOe(e[e.length-1]);var c4e=new Array(3).concat("ef8a62f7f7f767a9cf","ca0020f4a58292c5de0571b0","ca0020f4a582f7f7f792c5de0571b0","b2182bef8a62fddbc7d1e5f067a9cf2166ac","b2182bef8a62fddbc7f7f7f7d1e5f067a9cf2166ac","b2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac","b2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac","67001fb2182bd6604df4a582fddbc7d1e5f092c5de4393c32166ac053061","67001fb2182bd6604df4a582fddbc7f7f7f7d1e5f092c5de4393c32166ac053061").map(VA);const u4e=T0(c4e);var d4e=new Array(3).concat("fc8d59ffffbf99d594","d7191cfdae61abdda42b83ba","d7191cfdae61ffffbfabdda42b83ba","d53e4ffc8d59fee08be6f59899d5943288bd","d53e4ffc8d59fee08bffffbfe6f59899d5943288bd","d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd","d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd","9e0142d53e4ff46d43fdae61fee08be6f598abdda466c2a53288bd5e4fa2","9e0142d53e4ff46d43fdae61fee08bffffbfe6f598abdda466c2a53288bd5e4fa2").map(VA);const h4e=T0(d4e);var m4e=new Array(3).concat("e0ecf49ebcda8856a7","edf8fbb3cde38c96c688419d","edf8fbb3cde38c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68856a7810f7c","edf8fbbfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d6e016b","f7fcfde0ecf4bfd3e69ebcda8c96c68c6bb188419d810f7c4d004b").map(VA);const f4e=T0(m4e);var p4e=new Array(3).concat("fde0ddfa9fb5c51b8a","feebe2fbb4b9f768a1ae017e","feebe2fbb4b9f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1c51b8a7a0177","feebe2fcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a0177","fff7f3fde0ddfcc5c0fa9fb5f768a1dd3497ae017e7a017749006a").map(VA);const b4e=T0(p4e);var y4e=new Array(3).concat("fff7bcfec44fd95f0e","ffffd4fed98efe9929cc4c02","ffffd4fed98efe9929d95f0e993404","ffffd4fee391fec44ffe9929d95f0e993404","ffffd4fee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c028c2d04","ffffe5fff7bcfee391fec44ffe9929ec7014cc4c02993404662506").map(VA);const Z4e=T0(y4e);var G4e=new Array(3).concat("f0f0f0bdbdbd636363","f7f7f7cccccc969696525252","f7f7f7cccccc969696636363252525","f7f7f7d9d9d9bdbdbd969696636363252525","f7f7f7d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525","fffffff0f0f0d9d9d9bdbdbd969696737373525252252525000000").map(VA);const v4e=T0(G4e);function B4e(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 S4e=Npe(Pc(-100,.75,.35),Pc(80,1.5,.8));Npe(Pc(260,.75,.35),Pc(80,1.5,.8));Pc();function NT(e){var g=e.length;return function(i){return e[Math.max(0,Math.min(g-1,Math.floor(i*g)))]}}const pbe=NT(VA("44015444025645045745055946075a46085c460a5d460b5e470d60470e6147106347116447136548146748166848176948186a481a6c481b6d481c6e481d6f481f70482071482173482374482475482576482677482878482979472a7a472c7a472d7b472e7c472f7d46307e46327e46337f463480453581453781453882443983443a83443b84433d84433e85423f854240864241864142874144874045884046883f47883f48893e49893e4a893e4c8a3d4d8a3d4e8a3c4f8a3c508b3b518b3b528b3a538b3a548c39558c39568c38588c38598c375a8c375b8d365c8d365d8d355e8d355f8d34608d34618d33628d33638d32648e32658e31668e31678e31688e30698e306a8e2f6b8e2f6c8e2e6d8e2e6e8e2e6f8e2d708e2d718e2c718e2c728e2c738e2b748e2b758e2a768e2a778e2a788e29798e297a8e297b8e287c8e287d8e277e8e277f8e27808e26818e26828e26828e25838e25848e25858e24868e24878e23888e23898e238a8d228b8d228c8d228d8d218e8d218f8d21908d21918c20928c20928c20938c1f948c1f958b1f968b1f978b1f988b1f998a1f9a8a1e9b8a1e9c891e9d891f9e891f9f881fa0881fa1881fa1871fa28720a38620a48621a58521a68522a78522a88423a98324aa8325ab8225ac8226ad8127ad8128ae8029af7f2ab07f2cb17e2db27d2eb37c2fb47c31b57b32b67a34b67935b77937b87838b9773aba763bbb753dbc743fbc7340bd7242be7144bf7046c06f48c16e4ac16d4cc26c4ec36b50c46a52c56954c56856c66758c7655ac8645cc8635ec96260ca6063cb5f65cb5e67cc5c69cd5b6ccd5a6ece5870cf5773d05675d05477d1537ad1517cd2507fd34e81d34d84d44b86d54989d5488bd6468ed64590d74393d74195d84098d83e9bd93c9dd93ba0da39a2da37a5db36a8db34aadc32addc30b0dd2fb2dd2db5de2bb8de29bade28bddf26c0df25c2df23c5e021c8e020cae11fcde11dd0e11cd2e21bd5e21ad8e219dae319dde318dfe318e2e418e5e419e7e419eae51aece51befe51cf1e51df4e61ef6e620f8e621fbe723fde725"));NT(VA("00000401000501010601010802010902020b02020d03030f03031204041405041606051806051a07061c08071e0907200a08220b09240c09260d0a290e0b2b100b2d110c2f120d31130d34140e36150e38160f3b180f3d19103f1a10421c10441d11471e114920114b21114e22115024125325125527125829115a2a115c2c115f2d11612f116331116533106734106936106b38106c390f6e3b0f703d0f713f0f72400f74420f75440f764510774710784910784a10794c117a4e117b4f127b51127c52137c54137d56147d57157e59157e5a167e5c167f5d177f5f187f601880621980641a80651a80671b80681c816a1c816b1d816d1d816e1e81701f81721f817320817521817621817822817922827b23827c23827e24828025828125818326818426818627818827818928818b29818c29818e2a81902a81912b81932b80942c80962c80982d80992d809b2e7f9c2e7f9e2f7fa02f7fa1307ea3307ea5317ea6317da8327daa337dab337cad347cae347bb0357bb2357bb3367ab5367ab73779b83779ba3878bc3978bd3977bf3a77c03a76c23b75c43c75c53c74c73d73c83e73ca3e72cc3f71cd4071cf4070d0416fd2426fd3436ed5446dd6456cd8456cd9466bdb476adc4869de4968df4a68e04c67e24d66e34e65e44f64e55064e75263e85362e95462ea5661eb5760ec5860ed5a5fee5b5eef5d5ef05f5ef1605df2625df2645cf3655cf4675cf4695cf56b5cf66c5cf66e5cf7705cf7725cf8745cf8765cf9785df9795df97b5dfa7d5efa7f5efa815ffb835ffb8560fb8761fc8961fc8a62fc8c63fc8e64fc9065fd9266fd9467fd9668fd9869fd9a6afd9b6bfe9d6cfe9f6dfea16efea36ffea571fea772fea973feaa74feac76feae77feb078feb27afeb47bfeb67cfeb77efeb97ffebb81febd82febf84fec185fec287fec488fec68afec88cfeca8dfecc8ffecd90fecf92fed194fed395fed597fed799fed89afdda9cfddc9efddea0fde0a1fde2a3fde3a5fde5a7fde7a9fde9aafdebacfcecaefceeb0fcf0b2fcf2b4fcf4b6fcf6b8fcf7b9fcf9bbfcfbbdfcfdbf"));NT(VA("00000401000501010601010802010a02020c02020e03021004031204031405041706041907051b08051d09061f0a07220b07240c08260d08290e092b10092d110a30120a32140b34150b37160b39180c3c190c3e1b0c411c0c431e0c451f0c48210c4a230c4c240c4f260c51280b53290b552b0b572d0b592f0a5b310a5c320a5e340a5f3609613809623909633b09643d09653e0966400a67420a68440a68450a69470b6a490b6a4a0c6b4c0c6b4d0d6c4f0d6c510e6c520e6d540f6d550f6d57106e59106e5a116e5c126e5d126e5f136e61136e62146e64156e65156e67166e69166e6a176e6c186e6d186e6f196e71196e721a6e741a6e751b6e771c6d781c6d7a1d6d7c1d6d7d1e6d7f1e6c801f6c82206c84206b85216b87216b88226a8a226a8c23698d23698f24699025689225689326679526679727669827669a28659b29649d29649f2a63a02a63a22b62a32c61a52c60a62d60a82e5fa92e5eab2f5ead305dae305cb0315bb1325ab3325ab43359b63458b73557b93556ba3655bc3754bd3853bf3952c03a51c13a50c33b4fc43c4ec63d4dc73e4cc83f4bca404acb4149cc4248ce4347cf4446d04545d24644d34743d44842d54a41d74b3fd84c3ed94d3dda4e3cdb503bdd513ade5238df5337e05536e15635e25734e35933e45a31e55c30e65d2fe75e2ee8602de9612bea632aeb6429eb6628ec6726ed6925ee6a24ef6c23ef6e21f06f20f1711ff1731df2741cf3761bf37819f47918f57b17f57d15f67e14f68013f78212f78410f8850ff8870ef8890cf98b0bf98c0af98e09fa9008fa9207fa9407fb9606fb9706fb9906fb9b06fb9d07fc9f07fca108fca309fca50afca60cfca80dfcaa0ffcac11fcae12fcb014fcb216fcb418fbb61afbb81dfbba1ffbbc21fbbe23fac026fac228fac42afac62df9c72ff9c932f9cb35f8cd37f8cf3af7d13df7d340f6d543f6d746f5d949f5db4cf4dd4ff4df53f4e156f3e35af3e55df2e661f2e865f2ea69f1ec6df1ed71f1ef75f1f179f2f27df2f482f3f586f3f68af4f88ef5f992f6fa96f8fb9af9fc9dfafda1fcffa4"));NT(VA("0d088710078813078916078a19068c1b068d1d068e20068f2206902406912605912805922a05932c05942e05952f059631059733059735049837049938049a3a049a3c049b3e049c3f049c41049d43039e44039e46039f48039f4903a04b03a14c02a14e02a25002a25102a35302a35502a45601a45801a45901a55b01a55c01a65e01a66001a66100a76300a76400a76600a76700a86900a86a00a86c00a86e00a86f00a87100a87201a87401a87501a87701a87801a87a02a87b02a87d03a87e03a88004a88104a78305a78405a78606a68707a68808a68a09a58b0aa58d0ba58e0ca48f0da4910ea3920fa39410a29511a19613a19814a099159f9a169f9c179e9d189d9e199da01a9ca11b9ba21d9aa31e9aa51f99a62098a72197a82296aa2395ab2494ac2694ad2793ae2892b02991b12a90b22b8fb32c8eb42e8db52f8cb6308bb7318ab83289ba3388bb3488bc3587bd3786be3885bf3984c03a83c13b82c23c81c33d80c43e7fc5407ec6417dc7427cc8437bc9447aca457acb4679cc4778cc4977cd4a76ce4b75cf4c74d04d73d14e72d24f71d35171d45270d5536fd5546ed6556dd7566cd8576bd9586ada5a6ada5b69db5c68dc5d67dd5e66de5f65de6164df6263e06363e16462e26561e26660e3685fe4695ee56a5de56b5de66c5ce76e5be76f5ae87059e97158e97257ea7457eb7556eb7655ec7754ed7953ed7a52ee7b51ef7c51ef7e50f07f4ff0804ef1814df1834cf2844bf3854bf3874af48849f48948f58b47f58c46f68d45f68f44f79044f79143f79342f89441f89540f9973ff9983ef99a3efa9b3dfa9c3cfa9e3bfb9f3afba139fba238fca338fca537fca636fca835fca934fdab33fdac33fdae32fdaf31fdb130fdb22ffdb42ffdb52efeb72dfeb82cfeba2cfebb2bfebd2afebe2afec029fdc229fdc328fdc527fdc627fdc827fdca26fdcb26fccd25fcce25fcd025fcd225fbd324fbd524fbd724fad824fada24f9dc24f9dd25f8df25f8e125f7e225f7e425f6e626f6e826f5e926f5eb27f4ed27f3ee27f3f027f2f227f1f426f1f525f0f724f0f921"));var th={},kT={};kT.byteLength=V4e;kT.toByteArray=X4e;kT.fromByteArray=N4e;var Pa=[],VC=[],w4e=typeof Uint8Array<"u"?Uint8Array:Array,c5="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var Nm=0,R4e=c5.length;Nm0)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 V4e(e){var g=bbe(e),i=g[0],I=g[1];return(i+I)*3/4-I}function W4e(e,g,i){return(g+i)*3/4-i}function X4e(e){var g,i=bbe(e),I=i[0],n=i[1],r=new w4e(W4e(e,I,n)),C=0,o=n>0?I-4:I,a;for(a=0;a>16&255,r[C++]=g>>8&255,r[C++]=g&255;return n===2&&(g=VC[e.charCodeAt(a)]<<2|VC[e.charCodeAt(a+1)]>>4,r[C++]=g&255),n===1&&(g=VC[e.charCodeAt(a)]<<10|VC[e.charCodeAt(a+1)]<<4|VC[e.charCodeAt(a+2)]>>2,r[C++]=g>>8&255,r[C++]=g&255),r}function H4e(e){return Pa[e>>18&63]+Pa[e>>12&63]+Pa[e>>6&63]+Pa[e&63]}function T4e(e,g,i){for(var I,n=[],r=g;ro?o:C+r));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 C7={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */C7.read=function(e,g,i,I,n){var r,C,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,r=u&(1<<-A)-1,u>>=-A,A+=o;A>0;r=r*256+e[g+l],l+=c,A-=8);for(C=r&(1<<-A)-1,r>>=-A,A+=I;A>0;C=C*256+e[g+l],l+=c,A-=8);if(r===0)r=1-s;else{if(r===a)return C?NaN:(u?-1:1)*(1/0);C=C+Math.pow(2,I),r=r-s}return(u?-1:1)*C*Math.pow(2,r-I)};C7.write=function(e,g,i,I,n,r){var C,o,a,s=r*8-n-1,A=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=I?0:r-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,C=A):(C=Math.floor(Math.log(g)/Math.LN2),g*(a=Math.pow(2,-C))<1&&(C--,a*=2),C+l>=1?g+=c/a:g+=c*Math.pow(2,1-l),g*a>=2&&(C++,a/=2),C+l>=A?(o=0,C=A):C+l>=1?(o=(g*a-1)*Math.pow(2,n),C=C+l):(o=g*Math.pow(2,l-1)*Math.pow(2,n),C=0));n>=8;e[i+u]=o&255,u+=d,o/=256,n-=8);for(C=C<0;e[i+u]=C&255,u+=d,C/=256,s-=8);e[i+u-d]|=h*128};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT - */(function(e){const g=HT,I=t7,i=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=o,e.SlowBuffer=b,e.INSPECT_MAX_BYTES=50;const n=2147483647;e.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 x=new Uint8Array(1),T={foo:function(){return 42}};return Object.setPrototypeOf(T,Uint8Array.prototype),Object.setPrototypeOf(x,T),x.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(x){if(x>n)throw new RangeError('The value "'+x+'" is invalid for option "size"');const T=new Uint8Array(x);return Object.setPrototypeOf(T,o.prototype),T}function o(x,T,k){if(typeof x=="number"){if(typeof T=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(x)}return a(x,T,k)}o.poolSize=8192;function a(x,T,k){if(typeof x=="string")return c(x,T);if(ArrayBuffer.isView(x))return d(x);if(x==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof x);if(tt(x,ArrayBuffer)||x&&tt(x.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(tt(x,SharedArrayBuffer)||x&&tt(x.buffer,SharedArrayBuffer)))return h(x,T,k);if(typeof x=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const Ie=x.valueOf&&x.valueOf();if(Ie!=null&&Ie!==x)return o.from(Ie,T,k);const me=m(x);if(me)return me;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof x[Symbol.toPrimitive]=="function")return o.from(x[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 x)}o.from=function(x,T,k){return a(x,T,k)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function s(x){if(typeof x!="number")throw new TypeError('"size" argument must be of type number');if(x<0)throw new RangeError('The value "'+x+'" is invalid for option "size"')}function A(x,T,k){return s(x),x<=0?r(x):T!==void 0?typeof k=="string"?r(x).fill(T,k):r(x).fill(T):r(x)}o.alloc=function(x,T,k){return A(x,T,k)};function l(x){return s(x),r(x<0?0:f(x)|0)}o.allocUnsafe=function(x){return l(x)},o.allocUnsafeSlow=function(x){return l(x)};function c(x,T){if((typeof T!="string"||T==="")&&(T="utf8"),!o.isEncoding(T))throw new TypeError("Unknown encoding: "+T);const k=p(x,T)|0;let Ie=r(k);const me=Ie.write(x,T);return me!==k&&(Ie=Ie.slice(0,me)),Ie}function u(x){const T=x.length<0?0:f(x.length)|0,k=r(T);for(let Ie=0;Ie=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return x|0}function b(x){return+x!=x&&(x=0),o.alloc(+x)}o.isBuffer=function(T){return T!=null&&T._isBuffer===!0&&T!==o.prototype},o.compare=function(T,k){if(tt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),tt(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 Ie=T.length,me=k.length;for(let Re=0,we=Math.min(Ie,me);Reme.length?(o.isBuffer(we)||(we=o.from(we)),we.copy(me,Re)):Uint8Array.prototype.set.call(me,we,Re);else if(o.isBuffer(we))we.copy(me,Re);else throw new TypeError('"list" argument must be an Array of Buffers');Re+=we.length}return me};function p(x,T){if(o.isBuffer(x))return x.length;if(ArrayBuffer.isView(x)||tt(x,ArrayBuffer))return x.byteLength;if(typeof x!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof x);const k=x.length,Ie=arguments.length>2&&arguments[2]===!0;if(!Ie&&k===0)return 0;let me=!1;for(;;)switch(T){case"ascii":case"latin1":case"binary":return k;case"utf8":case"utf-8":return De(x).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k*2;case"hex":return k>>>1;case"base64":return gt(x).length;default:if(me)return Ie?-1:De(x).length;T=(""+T).toLowerCase(),me=!0}}o.byteLength=p;function y(x,T,k){let Ie=!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(x||(x="utf8");;)switch(x){case"hex":return J(this,T,k);case"utf8":case"utf-8":return R(this,T,k);case"ascii":return K(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 P(this,T,k);default:if(Ie)throw new TypeError("Unknown encoding: "+x);x=(x+"").toLowerCase(),Ie=!0}}o.prototype._isBuffer=!0;function Z(x,T,k){const Ie=x[T];x[T]=x[k],x[k]=Ie}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,Ie,me,Re){if(tt(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),Ie===void 0&&(Ie=T?T.length:0),me===void 0&&(me=0),Re===void 0&&(Re=this.length),k<0||Ie>T.length||me<0||Re>this.length)throw new RangeError("out of range index");if(me>=Re&&k>=Ie)return 0;if(me>=Re)return-1;if(k>=Ie)return 1;if(k>>>=0,Ie>>>=0,me>>>=0,Re>>>=0,this===T)return 0;let we=Re-me,je=Ie-k;const at=Math.min(we,je),bt=this.slice(me,Re),ct=T.slice(k,Ie);for(let Ht=0;Ht2147483647?k=2147483647:k<-2147483648&&(k=-2147483648),k=+k,Xe(k)&&(k=me?0:x.length-1),k<0&&(k=x.length+k),k>=x.length){if(me)return-1;k=x.length-1}else if(k<0)if(me)k=0;else return-1;if(typeof T=="string"&&(T=o.from(T,Ie)),o.isBuffer(T))return T.length===0?-1:G(x,T,k,Ie,me);if(typeof T=="number")return T=T&255,typeof Uint8Array.prototype.indexOf=="function"?me?Uint8Array.prototype.indexOf.call(x,T,k):Uint8Array.prototype.lastIndexOf.call(x,T,k):G(x,[T],k,Ie,me);throw new TypeError("val must be string, number or Buffer")}function G(x,T,k,Ie,me){let Re=1,we=x.length,je=T.length;if(Ie!==void 0&&(Ie=String(Ie).toLowerCase(),Ie==="ucs2"||Ie==="ucs-2"||Ie==="utf16le"||Ie==="utf-16le")){if(x.length<2||T.length<2)return-1;Re=2,we/=2,je/=2,k/=2}function at(ct,Ht){return Re===1?ct[Ht]:ct.readUInt16BE(Ht*Re)}let bt;if(me){let ct=-1;for(bt=k;btwe&&(k=we-je),bt=k;bt>=0;bt--){let ct=!0;for(let Ht=0;Htme&&(Ie=me)):Ie=me;const Re=T.length;Ie>Re/2&&(Ie=Re/2);let we;for(we=0;we>>0,isFinite(Ie)?(Ie=Ie>>>0,me===void 0&&(me="utf8")):(me=Ie,Ie=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const Re=this.length-k;if((Ie===void 0||Ie>Re)&&(Ie=Re),T.length>0&&(Ie<0||k<0)||k>this.length)throw new RangeError("Attempt to write outside buffer bounds");me||(me="utf8");let we=!1;for(;;)switch(me){case"hex":return v(this,T,k,Ie);case"utf8":case"utf-8":return w(this,T,k,Ie);case"ascii":case"latin1":case"binary":return V(this,T,k,Ie);case"base64":return S(this,T,k,Ie);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,T,k,Ie);default:if(we)throw new TypeError("Unknown encoding: "+me);me=(""+me).toLowerCase(),we=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function W(x,T,k){return T===0&&k===x.length?g.fromByteArray(x):g.fromByteArray(x.slice(T,k))}function R(x,T,k){k=Math.min(x.length,k);const Ie=[];let me=T;for(;me239?4:Re>223?3:Re>191?2:1;if(me+je<=k){let at,bt,ct,Ht;switch(je){case 1:Re<128&&(we=Re);break;case 2:at=x[me+1],(at&192)===128&&(Ht=(Re&31)<<6|at&63,Ht>127&&(we=Ht));break;case 3:at=x[me+1],bt=x[me+2],(at&192)===128&&(bt&192)===128&&(Ht=(Re&15)<<12|(at&63)<<6|bt&63,Ht>2047&&(Ht<55296||Ht>57343)&&(we=Ht));break;case 4:at=x[me+1],bt=x[me+2],ct=x[me+3],(at&192)===128&&(bt&192)===128&&(ct&192)===128&&(Ht=(Re&15)<<18|(at&63)<<12|(bt&63)<<6|ct&63,Ht>65535&&Ht<1114112&&(we=Ht))}}we===null?(we=65533,je=1):we>65535&&(we-=65536,Ie.push(we>>>10&1023|55296),we=56320|we&1023),Ie.push(we),me+=je}return Y(Ie)}const H=4096;function Y(x){const T=x.length;if(T<=H)return String.fromCharCode.apply(String,x);let k="",Ie=0;for(;IeIe)&&(k=Ie);let me="";for(let Re=T;ReIe&&(T=Ie),k<0?(k+=Ie,k<0&&(k=0)):k>Ie&&(k=Ie),kk)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(T,k,Ie){T=T>>>0,k=k>>>0,Ie||ge(T,k,this.length);let me=this[T],Re=1,we=0;for(;++we>>0,k=k>>>0,Ie||ge(T,k,this.length);let me=this[T+--k],Re=1;for(;k>0&&(Re*=256);)me+=this[T+--k]*Re;return me},o.prototype.readUint8=o.prototype.readUInt8=function(T,k){return T=T>>>0,k||ge(T,1,this.length),this[T]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(T,k){return T=T>>>0,k||ge(T,2,this.length),this[T]|this[T+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(T,k){return T=T>>>0,k||ge(T,2,this.length),this[T]<<8|this[T+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(T,k){return T=T>>>0,k||ge(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||ge(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,We(T,"offset");const k=this[T],Ie=this[T+7];(k===void 0||Ie===void 0)&&Be(T,this.length-8);const me=k+this[++T]*2**8+this[++T]*2**16+this[++T]*2**24,Re=this[++T]+this[++T]*2**8+this[++T]*2**16+Ie*2**24;return BigInt(me)+(BigInt(Re)<>>0,We(T,"offset");const k=this[T],Ie=this[T+7];(k===void 0||Ie===void 0)&&Be(T,this.length-8);const me=k*2**24+this[++T]*2**16+this[++T]*2**8+this[++T],Re=this[++T]*2**24+this[++T]*2**16+this[++T]*2**8+Ie;return(BigInt(me)<>>0,k=k>>>0,Ie||ge(T,k,this.length);let me=this[T],Re=1,we=0;for(;++we=Re&&(me-=Math.pow(2,8*k)),me},o.prototype.readIntBE=function(T,k,Ie){T=T>>>0,k=k>>>0,Ie||ge(T,k,this.length);let me=k,Re=1,we=this[T+--me];for(;me>0&&(Re*=256);)we+=this[T+--me]*Re;return Re*=128,we>=Re&&(we-=Math.pow(2,8*k)),we},o.prototype.readInt8=function(T,k){return T=T>>>0,k||ge(T,1,this.length),this[T]&128?(255-this[T]+1)*-1:this[T]},o.prototype.readInt16LE=function(T,k){T=T>>>0,k||ge(T,2,this.length);const Ie=this[T]|this[T+1]<<8;return Ie&32768?Ie|4294901760:Ie},o.prototype.readInt16BE=function(T,k){T=T>>>0,k||ge(T,2,this.length);const Ie=this[T+1]|this[T]<<8;return Ie&32768?Ie|4294901760:Ie},o.prototype.readInt32LE=function(T,k){return T=T>>>0,k||ge(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||ge(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,We(T,"offset");const k=this[T],Ie=this[T+7];(k===void 0||Ie===void 0)&&Be(T,this.length-8);const me=this[T+4]+this[T+5]*2**8+this[T+6]*2**16+(Ie<<24);return(BigInt(me)<>>0,We(T,"offset");const k=this[T],Ie=this[T+7];(k===void 0||Ie===void 0)&&Be(T,this.length-8);const me=(k<<24)+this[++T]*2**16+this[++T]*2**8+this[++T];return(BigInt(me)<>>0,k||ge(T,4,this.length),I.read(this,T,!0,23,4)},o.prototype.readFloatBE=function(T,k){return T=T>>>0,k||ge(T,4,this.length),I.read(this,T,!1,23,4)},o.prototype.readDoubleLE=function(T,k){return T=T>>>0,k||ge(T,8,this.length),I.read(this,T,!0,52,8)},o.prototype.readDoubleBE=function(T,k){return T=T>>>0,k||ge(T,8,this.length),I.read(this,T,!1,52,8)};function q(x,T,k,Ie,me,Re){if(!o.isBuffer(x))throw new TypeError('"buffer" argument must be a Buffer instance');if(T>me||Tx.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(T,k,Ie,me){if(T=+T,k=k>>>0,Ie=Ie>>>0,!me){const je=Math.pow(2,8*Ie)-1;q(this,T,k,Ie,je,0)}let Re=1,we=0;for(this[k]=T&255;++we>>0,Ie=Ie>>>0,!me){const je=Math.pow(2,8*Ie)-1;q(this,T,k,Ie,je,0)}let Re=Ie-1,we=1;for(this[k+Re]=T&255;--Re>=0&&(we*=256);)this[k+Re]=T/we&255;return k+Ie},o.prototype.writeUint8=o.prototype.writeUInt8=function(T,k,Ie){return T=+T,k=k>>>0,Ie||q(this,T,k,1,255,0),this[k]=T&255,k+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(T,k,Ie){return T=+T,k=k>>>0,Ie||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,Ie){return T=+T,k=k>>>0,Ie||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,Ie){return T=+T,k=k>>>0,Ie||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,Ie){return T=+T,k=k>>>0,Ie||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 $(x,T,k,Ie,me){ve(T,Ie,me,x,k,7);let Re=Number(T&BigInt(4294967295));x[k++]=Re,Re=Re>>8,x[k++]=Re,Re=Re>>8,x[k++]=Re,Re=Re>>8,x[k++]=Re;let we=Number(T>>BigInt(32)&BigInt(4294967295));return x[k++]=we,we=we>>8,x[k++]=we,we=we>>8,x[k++]=we,we=we>>8,x[k++]=we,k}function j(x,T,k,Ie,me){ve(T,Ie,me,x,k,7);let Re=Number(T&BigInt(4294967295));x[k+7]=Re,Re=Re>>8,x[k+6]=Re,Re=Re>>8,x[k+5]=Re,Re=Re>>8,x[k+4]=Re;let we=Number(T>>BigInt(32)&BigInt(4294967295));return x[k+3]=we,we=we>>8,x[k+2]=we,we=we>>8,x[k+1]=we,we=we>>8,x[k]=we,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,Ie,me){if(T=+T,k=k>>>0,!me){const at=Math.pow(2,8*Ie-1);q(this,T,k,Ie,at-1,-at)}let Re=0,we=1,je=0;for(this[k]=T&255;++Re>0)-je&255;return k+Ie},o.prototype.writeIntBE=function(T,k,Ie,me){if(T=+T,k=k>>>0,!me){const at=Math.pow(2,8*Ie-1);q(this,T,k,Ie,at-1,-at)}let Re=Ie-1,we=1,je=0;for(this[k+Re]=T&255;--Re>=0&&(we*=256);)T<0&&je===0&&this[k+Re+1]!==0&&(je=1),this[k+Re]=(T/we>>0)-je&255;return k+Ie},o.prototype.writeInt8=function(T,k,Ie){return T=+T,k=k>>>0,Ie||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,Ie){return T=+T,k=k>>>0,Ie||q(this,T,k,2,32767,-32768),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeInt16BE=function(T,k,Ie){return T=+T,k=k>>>0,Ie||q(this,T,k,2,32767,-32768),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeInt32LE=function(T,k,Ie){return T=+T,k=k>>>0,Ie||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,Ie){return T=+T,k=k>>>0,Ie||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(x,T,k,Ie,me,Re){if(k+Ie>x.length)throw new RangeError("Index out of range");if(k<0)throw new RangeError("Index out of range")}function Q(x,T,k,Ie,me){return T=+T,k=k>>>0,me||te(x,T,k,4),I.write(x,T,k,Ie,23,4),k+4}o.prototype.writeFloatLE=function(T,k,Ie){return Q(this,T,k,!0,Ie)},o.prototype.writeFloatBE=function(T,k,Ie){return Q(this,T,k,!1,Ie)};function ie(x,T,k,Ie,me){return T=+T,k=k>>>0,me||te(x,T,k,8),I.write(x,T,k,Ie,52,8),k+8}o.prototype.writeDoubleLE=function(T,k,Ie){return ie(this,T,k,!0,Ie)},o.prototype.writeDoubleBE=function(T,k,Ie){return ie(this,T,k,!1,Ie)},o.prototype.copy=function(T,k,Ie,me){if(!o.isBuffer(T))throw new TypeError("argument should be a Buffer");if(Ie||(Ie=0),!me&&me!==0&&(me=this.length),k>=T.length&&(k=T.length),k||(k=0),me>0&&me=this.length)throw new RangeError("Index out of range");if(me<0)throw new RangeError("sourceEnd out of bounds");me>this.length&&(me=this.length),T.length-k>>0,Ie=Ie===void 0?this.length:Ie>>>0,T||(T=0);let Re;if(typeof T=="number")for(Re=k;Re2**32?me=be(String(k)):typeof k=="bigint"&&(me=String(k),(k>BigInt(2)**BigInt(32)||k<-(BigInt(2)**BigInt(32)))&&(me=be(me)),me+="n"),Ie+=` It must be ${T}. Received ${me}`,Ie},RangeError);function be(x){let T="",k=x.length;const Ie=x[0]==="-"?1:0;for(;k>=Ie+4;k-=3)T=`_${x.slice(k-3,k)}${T}`;return`${x.slice(0,k)}${T}`}function pe(x,T,k){We(T,"offset"),(x[T]===void 0||x[T+k]===void 0)&&Be(T,x.length-(k+1))}function ve(x,T,k,Ie,me,Re){if(x>k||x3?T===0||T===BigInt(0)?je=`>= 0${we} and < 2${we} ** ${(Re+1)*8}${we}`:je=`>= -(2${we} ** ${(Re+1)*8-1}${we}) and < 2 ** ${(Re+1)*8-1}${we}`:je=`>= ${T}${we} and <= ${k}${we}`,new he.ERR_OUT_OF_RANGE("value",je,x)}pe(Ie,me,Re)}function We(x,T){if(typeof x!="number")throw new he.ERR_INVALID_ARG_TYPE(T,"number",x)}function Be(x,T,k){throw Math.floor(x)!==x?(We(x,k),new he.ERR_OUT_OF_RANGE(k||"offset","an integer",x)):T<0?new he.ERR_BUFFER_OUT_OF_BOUNDS:new he.ERR_OUT_OF_RANGE(k||"offset",`>= ${k?1:0} and <= ${T}`,x)}const Je=/[^+/0-9A-Za-z-_]/g;function Pe(x){if(x=x.split("=")[0],x=x.trim().replace(Je,""),x.length<2)return"";for(;x.length%4!==0;)x=x+"=";return x}function De(x,T){T=T||1/0;let k;const Ie=x.length;let me=null;const Re=[];for(let we=0;we55295&&k<57344){if(!me){if(k>56319){(T-=3)>-1&&Re.push(239,191,189);continue}else if(we+1===Ie){(T-=3)>-1&&Re.push(239,191,189);continue}me=k;continue}if(k<56320){(T-=3)>-1&&Re.push(239,191,189),me=k;continue}k=(me-55296<<10|k-56320)+65536}else me&&(T-=3)>-1&&Re.push(239,191,189);if(me=null,k<128){if((T-=1)<0)break;Re.push(k)}else if(k<2048){if((T-=2)<0)break;Re.push(k>>6|192,k&63|128)}else if(k<65536){if((T-=3)<0)break;Re.push(k>>12|224,k>>6&63|128,k&63|128)}else if(k<1114112){if((T-=4)<0)break;Re.push(k>>18|240,k>>12&63|128,k>>6&63|128,k&63|128)}else throw new Error("Invalid code point")}return Re}function Qe(x){const T=[];for(let k=0;k>8,me=k%256,Re.push(me),Re.push(Ie);return Re}function gt(x){return g.toByteArray(Pe(x))}function lt(x,T,k,Ie){let me;for(me=0;me=T.length||me>=x.length);++me)T[me+k]=x[me];return me}function tt(x,T){return x instanceof T||x!=null&&x.constructor!=null&&x.constructor.name!=null&&x.constructor.name===T.name}function Xe(x){return x!==x}const ae=function(){const x="0123456789abcdef",T=new Array(256);for(let k=0;k<16;++k){const Ie=k*16;for(let me=0;me<16;++me)T[Ie+me]=x[k]+x[me]}return T}();function ye(x){return typeof BigInt>"u"?He:x}function He(){throw new Error("BigInt not supported")}})(gh);let cbe=class{async getBufferFromResponse(g){if(typeof g.buffer=="function")return g.buffer();if(typeof g.arrayBuffer=="function"){const I=await g.arrayBuffer();return gh.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=gh.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 Vje=Object.defineProperty,Rje=(e,g,I)=>g in e?Vje(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I,Wje=(e,g,I)=>(Rje(e,typeof g!="symbol"?g+"":g,I),I);const TX=6,Xje=130,Hje=600,Tte=600,T1=10,ube=.3,Tje=0,Nje="gray",pt=e=>{let g=qd(e);return g||(g=qd(Nje)),Hme([g.rgb().r/255,g.rgb().g/255,g.rgb().b/255])},gn=0;function jg(e,g,I,i,n){const C=Math.max(Math.min(g,e),0),r=n??gn,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(jg(e,g,C,r)),y:n+I*Math.sin(jg(e,g,C,r))}}function lc(e,g,I,i){return I<=e?Math.atan((g-i)/(e-I)):Math.atan((g-i)/(e-I))-Math.PI}function kje(e,g,I,i){return(Math.atan2(-(g-i),e-I)/Math.PI*180+270)%360}function Yje(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=>!pI(w,a.row)||pI(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),K=I.markVisibility(w,{width:W,zoomLevel:c}),F=Math.min(K,Y);if(!(W<=.1||F===0||V+W<0||V-W>A))if(g.lineStyle(R,pt(H),F,1),u){const J=h-(v+B-S)/l*b,P=Mt(V,A,J,p,y,m,f);g.beginFill(pt(X),F),g.drawCircle(P.x,P.y,W),I.getMouseEventModel().addPointBasedEvent(w,[P.x,P.y,W])}else g.beginFill(pt(X),F),g.drawCircle(V,v+B-S,W),I.getMouseEventModel().addPointBasedEvent(w,[V,v+B-S,W])})})}function Kje(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 xje(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=>(!pI(V,A.row)||pI(V,A.row)===G)&&(!pI(V,A.color)||pI(V,A.color)===w)).sort((V,S)=>pI(V,A.x)-pI(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,pt(H),Y,.5),c){const K=d-(v+Z-W)/i*f,F=Mt(X,I,K,b,p,h,m);S===0?e.moveTo(F.x,F.y):e.lineTo(F.x,F.y),g.getMouseEventModel().addPointBasedEvent(V,[F.x,F.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 Dje(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:K}=e.getTilePosAndDimensions(g.tileData.zoomLevel,g.tileData.tilePos,d);w=v(Y+K/d)-v(Y)}const V=(o=I.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],S=u/V.length,X=!ut(A.row)||ut(A.row)&&typeof A.row.clip>"u"||A.row.clip,W=ut(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(TT(A)){const Y=I.getGenomicChannel();if(!Y||!Y.field){console.warn("Genomic field is not provided in the specification");return}const K=yT(l,J=>J[Y.field]);[...K.keys()].forEach(J=>{var P;let ge=0;(P=K.get(J))==null||P.forEach(q=>{const $=I.encodedPIXIProperty("color",q),j=I.encodedPIXIProperty("stroke",q),te=I.encodedPIXIProperty("strokeWidth",q),Q=I.encodedPIXIProperty("opacity",q),ie=I.encodedPIXIProperty("y",q),he=I.encodedPIXIProperty("width",q,{tileUnitWidth:w}),ne=I.encodedPIXIProperty("x-start",q,{markWidth:he}),be=ne+he,pe=I.markVisibility(q,{width:he,zoomLevel:h}),ve=Math.min(pe,Q);if(ve===0||he<=0||ie<=0)return;H.lineStyle(te,pt(j),ve,0);let We=[];if(m){const Be=b-(S-ge)/u*Z,Je=b-(S-ie-ge)/u*Z,Pe=Mt(ne,c,Je,B,G,p,y),De=jg(ne,c,p,y),Qe=jg(ne+he,c,p,y);H.beginFill(pt($),$==="none"?0:ve),H.moveTo(Pe.x,Pe.y),H.arc(B,G,Je,De,Qe,!0),H.arc(B,G,Be,Qe,De,!1),We=Array.from(H.currentPath.points),H.closePath()}else{H.beginFill(pt($),$==="none"?0:ve),H.drawRect(ne,S-ie-ge,he,ie);const Be=S-ie-ge,Je=Be+ie;We=[ne,Be,ne,Je,be,Je,be,Be]}I.getMouseEventModel().addPolygonBasedEvent(q,We),ge+=ie})})}else V.forEach(Y=>{const K=I.encodedValue("row",Y);l.filter(F=>{const J=pI(F,A.row);return!J||J===Y}).forEach(F=>{const J=I.encodedPIXIProperty("color",F),P=I.encodedPIXIProperty("stroke",F),ge=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 te=I.encodedPIXIProperty("width",F,{tileUnitWidth:w}),Q=I.encodedPIXIProperty("x-start",F,{markWidth:te}),ie=Q+te;let he;typeof j>"u"?(he=K+S-R-$,j=K+S-R,(ut(A.y)&&A.y.flip||A.flipY)&&(j=he,he=K)):(he=K+S-j,j=K+S-$),X&&(he=Math.max(K,he),he=Math.min(he,K+S),j=Math.max(K,j),j=Math.min(j,K+S));const ne=I.markVisibility(F,{width:te,zoomLevel:h}),be=Math.min(ne,q);if(be===0||te===0||j-he===0)return;H.lineStyle(ge,pt(P),be,0);let pe=[];if(m){const ve=b-he/u*Z,We=b-j/u*Z,Be=Mt(Q,c,We,B,G,p,y),Je=jg(Q,c,p,y),Pe=jg(Q+te,c,p,y);H.beginFill(pt(J),J==="none"?0:be),H.moveTo(Be.x,Be.y),H.arc(B,G,We,Je,Pe,!0),H.arc(B,G,ve,Pe,Je,!1),pe=Array.from(H.currentPath.points),H.closePath()}else H.beginFill(pt(J),J==="none"?0:be),H.drawRect(Q,he,te,j-he),pe=[Q,he,Q,j,ie,j,ie,he];I.getMouseEventModel().addPolygonBasedEvent(F,pe)})})}function Fje(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 Eje(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(TT(A)){const R=i.getGenomicChannel();if(!R||!R.field){console.warn("Genomic field is not provided in the specification");return}const H=yT(l,F=>F[R.field]),Y=[...H.keys()];W.lineStyle(S,pt(X),V,1);const K={};w.forEach(F=>{const J=[],P=[];Y.forEach((q,$,j)=>{var te,Q;(Q=(te=H.get(q))==null?void 0:te.filter(ie=>pI(ie,A.color)===F))==null||Q.forEach(ie=>{const he=+q,ne=B(he),be=FG([i.encodedPIXIProperty("y",ie),0]);typeof K[q]>"u"&&(K[q]=0);const pe=v-be-K[q],ve=v-K[q];if(d){if($===0){const De=m-v/u*p,Qe=Mt(ne,c,De,y,Z,f,b);J.push([Qe.x,Qe.y]),P.push([Qe.x,Qe.y])}const We=m-pe/u*p,Be=Mt(ne,c,We,y,Z,f,b);J.push([Be.x,Be.y]);const Je=m-ve/u*p,Pe=Mt(ne,c,Je,y,Z,f,b);if(P.push([Pe.x,Pe.y]),$===j.length-1){const De=m-v/u*p,Qe=Mt(ne,c,De,y,Z,f,b);J.push([Qe.x,Qe.y]),P.push([Qe.x,Qe.y])}i.getMouseEventModel().addPointBasedEvent(ie,[Pe.x,Pe.y,1])}else $===0&&(J.push([ne,v]),P.push([ne,v])),J.push([ne,pe]),P.push([ne,ve]),$===j.length-1&&(J.push([ne,v]),P.push([ne,v])),i.getMouseEventModel().addPointBasedEvent(ie,[ne,pe,1]);K[q]+=be})});const ge=i.encodedValue("color",F);W.beginFill(pt(ge),V),W.drawPolygon([...J.reduce((q,$)=>q.concat($)),...P.reverse().reduce((q,$)=>q.concat($))]),W.endFill()})}else G.forEach(R=>{const H=i.encodedValue("row",R);W.lineStyle(S,pt(X),V,0),w.forEach(Y=>{const K=[],F=[],J=m-(H+v)/u*p;let P=0;l.filter(q=>(typeof pI(q,A.row)>"u"||pI(q,A.row)===R)&&(typeof pI(q,A.color)>"u"||pI(q,A.color)===Y)).sort((q,$)=>i.encodedPIXIProperty("x",q)-i.encodedPIXIProperty("x",$)).forEach((q,$,j)=>{const te=X1([FG([i.encodedPIXIProperty("y",q),0]),v]),Q=i.encodedPIXIProperty("x",q);if(d){const ie=Mt(Q,c,J,y,Z,f,b);K.push([ie.x,ie.y]),$===0&&F.push(ie.x,ie.y);const he=m-(H+v-te)/u*p,ne=Mt(Q,c,he,y,Z,f,b);if(F.push(ne.x,ne.y),$===j.length-1){const be=m-(H+v)/u*p,pe=Mt(Q,c,be,y,Z,f,b);F.push(pe.x,pe.y)}i.getMouseEventModel().addPointBasedEvent(q,[ne.x,ne.y,1])}else $===0&&(F.push(Q,H+v),P=Q),F.push(Q,H+v-te),$===j.length-1&&(F.push(Q,H+v),F.push(P,H+v)),i.getMouseEventModel().addPointBasedEvent(q,[Q,H+v-te,1])}),d&&K.length!==0&&F.push(...K.reverse().reduce((q,$)=>q.concat($)));const ge=i.encodedValue("color",Y);W.beginFill(pt(ge),V),W.drawPolygon(F),W.endFill()})})}function Mje(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=ut(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,K=i.encodedPIXIProperty("x",R),F=i.encodedPIXIProperty("color",R),J=i.encodedPIXIProperty("stroke",R),P=i.encodedPIXIProperty("strokeWidth",R),ge=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)}),Q=Math.min(te,ge);if(Q===0||$===0||q<=1e-4)return;const[ie,he,ne,be]=[K,K+q,Y+w-j-$/2,Y+w-j+$/2],pe=(H=i.visualPropertyByChannel("size",R))!=null?H:void 0;W.lineStyle(P,pt(J),Q,.5);let ve=[];if(d){if(he<0||c{const S=g.encodedValue("row",V);c.filter(X=>!pI(X,l.row)||pI(X,l.row)===V).forEach(X=>{var W,R,H;const Y=g.encodedPIXIProperty("x",X),K=g.encodedPIXIProperty("xe",X),F=(W=g.encodedPIXIProperty("size",X))!=null?W:K===void 0?w:K-Y,J=g.encodedPIXIProperty("y",X),P=g.encodedPIXIProperty("strokeWidth",X),ge=g.encodedPIXIProperty("stroke",X),q=g.encodedPIXIProperty("color",X),$=g.encodedPIXIProperty("opacity",X);let j=[];if(d){let te=Y||K-F,Q=K||Y+F,ie=(te+Q)/2;const he=m-(S+G-J)/i*p,ne=he-w/2,be=he+w/2;if(((R=l.style)==null?void 0:R.align)==="right"&&!K&&(te-=F,Q-=F,ie-=F),l.mark==="triangleLeft"){const We=Mt(Q,I,ne,y,Z,f,b),Be=Mt(te,I,he,y,Z,f,b),Je=Mt(Q,I,be,y,Z,f,b),Pe=Mt(Q,I,ne,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}else if(l.mark==="triangleRight"){const We=Mt(te,I,ne,y,Z,f,b),Be=Mt(Q,I,he,y,Z,f,b),Je=Mt(te,I,be,y,Z,f,b),Pe=Mt(te,I,ne,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}else if(l.mark==="triangleBottom"){te=ie-F/2,Q=ie+F/2;const We=Mt(te,I,be,y,Z,f,b),Be=Mt(Q,I,be,y,Z,f,b),Je=Mt(ie,I,ne,y,Z,f,b),Pe=Mt(te,I,be,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}const pe=g.markVisibility(X,{width:Q-te,zoomLevel:u}),ve=Math.min(pe,$);e.lineStyle(P,pt(ge),Q-te>2?ve:0,0),e.beginFill(pt(q),ve),e.drawPolygon(j),e.endFill()}else{let te=Y||K-F,Q=K||Y+F,ie=te+(Q-te)/2;const he=S+G-J,ne=S+G-J-w/2,be=S+G-J+w/2;((H=l.style)==null?void 0:H.align)==="right"&&!K&&(te-=F,Q-=F,ie-=F),j={triangleLeft:[Q,ne,te,he,Q,be,Q,ne],triangleRight:[te,ne,Q,he,te,be,te,ne],triangleBottom:[te,ne,Q,ne,ie,be,te,ne]}[l.mark];const pe=g.markVisibility(X,{width:Q-te,zoomLevel:u}),ve=Math.min(pe,$);e.lineStyle(P,pt(ge),Q-te>2?ve:0,.5),e.beginFill(pt(q),ve),e.drawPolygon(j),e.endFill()}g.getMouseEventModel().addPolygonBasedEvent(X,j)})})}const wa={fontSize:"12px",fontFamily:"sans-serif",fontWeight:"normal",fill:"black",background:"white",lineJoin:"round",stroke:"#ffffff",strokeThickness:0};function Jje(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(TT(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 K=yT(h,J=>J[Y.field]);[...K.keys()].forEach(J=>{var P;let ge=0;(P=K.get(J))==null||P.forEach(q=>{var $,j,te,Q,ie,he,ne,be;const pe=i.encodedPIXIProperty("text",q),ve=i.encodedPIXIProperty("color",q),We=i.encodedPIXIProperty("x",q)+X,Be=i.encodedPIXIProperty("xe",q)+X,Je=i.encodedPIXIProperty("x-center",q)+X,Pe=i.encodedPIXIProperty("y",q)+W,De=i.encodedPIXIProperty("size",q),Qe=i.encodedPIXIProperty("stroke",q),_e=i.encodedPIXIProperty("strokeWidth",q),gt=i.encodedPIXIProperty("opacity",q);if(Je<0||Je>m||g.textsBeingUsed>1e3)return;const lt={...wa,fontSize:De??(($=d.style)!=null&&$.textFontSize?`${(j=d.style)==null?void 0:j.textFontSize}px`:wa.fontSize),stroke:(Q=Qe??((te=d.style)==null?void 0:te.textStroke))!=null?Q:wa.stroke,strokeThickness:(he=_e??((ie=d.style)==null?void 0:ie.textStrokeWidth))!=null?he:wa.strokeThickness,fontWeight:(be=(ne=d.style)==null?void 0:ne.textFontWeight)!=null?be:wa.fontWeight},tt=new e.libraries.PIXI.TextStyle(lt);let Xe;g.textGraphics.length>g.textsBeingUsed?(Xe=g.textGraphics[g.textsBeingUsed],Xe.style.fill=ve,Xe.visible=!0,Xe.text=pe,Xe.alpha=1):(Xe=new e.libraries.PIXI.Text(pe,{...lt,fill:ve}),g.textGraphics.push(Xe));const ae=e.libraries.PIXI.TextMetrics.measureText(pe,tt);g.textsBeingUsed++;const ye=i.markVisibility(q,{...ae,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),He=Math.min(ye,gt);if(!pe||He===0){g.textsBeingUsed--,Xe.visible=!1;return}Xe.alpha=He,Xe.resolution=8,Xe.updateText(),Xe.texture.baseTexture.scaleMode=e.libraries.PIXI.SCALE_MODES.LINEAR;const x=new e.libraries.PIXI.Sprite(Xe.texture);x.x=We,x.y=S-Pe-ge,x.width=Be-We,x.height=Pe,H.addChild(x),ge+=Pe})})}else V.forEach(H=>{const Y=I.graphics,K=i.encodedValue("row",H);h.filter(F=>!pI(F,d.row)||pI(F,d.row)===H).forEach(F=>{var J,P,ge,q,$,j,te,Q;const ie=i.encodedPIXIProperty("text",F),he=i.encodedPIXIProperty("color",F),ne=i.encodedPIXIProperty("x-center",F)+X,be=i.encodedPIXIProperty("y",F)+W,pe=i.encodedPIXIProperty("size",F),ve=i.encodedPIXIProperty("stroke",F),We=i.encodedPIXIProperty("strokeWidth",F),Be=i.encodedPIXIProperty("opacity",F);if(ne<0||ne>m||g.textsBeingUsed>1e3)return;const Je={...wa,fontSize:pe??((J=d.style)!=null&&J.textFontSize?`${(P=d.style)==null?void 0:P.textFontSize}px`:wa.fontSize),stroke:(q=ve??((ge=d.style)==null?void 0:ge.textStroke))!=null?q:wa.stroke,strokeThickness:(j=We??(($=d.style)==null?void 0:$.textStrokeWidth))!=null?j:wa.strokeThickness,fontWeight:(Q=(te=d.style)==null?void 0:te.textFontWeight)!=null?Q:wa.fontWeight},Pe=new e.libraries.PIXI.TextStyle(Je);let De;g.textGraphics.length>g.textsBeingUsed?(De=g.textGraphics[g.textsBeingUsed],De.style.fill=he,De.visible=!0,De.text=ie,De.alpha=1):(De=new e.libraries.PIXI.Text(ie,{...Je,fill:he}),g.textGraphics.push(De));const Qe=e.libraries.PIXI.TextMetrics.measureText(ie,Pe);g.textsBeingUsed++;const _e=i.markVisibility(F,{...Qe,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),gt=Math.min(_e,Be);if(!ie||gt===0){g.textsBeingUsed--,De.visible=!1;return}De.alpha=gt,De.anchor.y=.5,De.anchor.x=R==="middle"?.5:R==="start"?0:1;let lt=[];if(b){const tt=y-(K+S-be)/f*G,Xe=Mt(ne,m,tt,v,w,Z,B);De.x=Xe.x,De.y=Xe.y,De.resolution=4;const ae=Qe.width/(2*tt*Math.PI)*m;let[ye,He]=[ne-ae/2,ne+ae/2];if(ye<0){const me=-ye;ye=0,He+=me}else if(He>m){const me=He-m;He=m,ye-=me}const x=[],T=[],k=[];for(let me=He;me>=ye;me-=ae/10){const Re=Mt(me,m,tt,v,w,Z,B);x.push(new e.libraries.PIXI.Point(Re.x,Re.y));const we=Mt(me,m,tt+Qe.height/2,v,w,Z,B),je=Mt(me,m,tt-Qe.height/2,v,w,Z,B);T.push(we.x,we.y),me===He&&k.push(we.y,we.x),k.push(je.y,je.x)}De.updateText();const Ie=new e.libraries.PIXI.SimpleRope(De.texture,x);Ie.alpha=gt,Y.addChild(Ie),k.reverse(),lt=T.concat(k)}else{De.position.x=ne,De.position.y=K+S-be,Y.addChild(De);const{height:tt,width:Xe}=Qe,ae=De.position.y-tt/2,ye=ae+tt;let He=0,x=0;R==="start"?(He=ne,x=ne+Xe):R==="middle"?(He=ne-Xe/2,x=ne+Xe/2):(He=ne-Xe,x=ne),lt=[He,ae,He,ye,x,ye,x,ae]}i.getMouseEventModel().addPolygonBasedEvent(F,lt)})})}function Oje(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=>!pI(Y,c.row)||pI(Y,c.row)===R).forEach(Y=>{const K=i.encodedPIXIProperty("x",Y),F=i.encodedPIXIProperty("xe",Y),J=i.encodedPIXIProperty("y",Y),P=i.encodedPIXIProperty("color",Y),ge=i.encodedPIXIProperty("strokeWidth",Y),q=i.encodedPIXIProperty("opacity",Y),$=i.markVisibility(Y,{width:F-K,zoomLevel:g._xScale.invert(d)-g._xScale.invert(0)}),j=Math.min($,q);if(W.lineStyle(ge,pt(P),j,.5),!F&&(!c.y||!("field"in c.y))){if(m)return;if(V){const[te,Q]=V;let ie=0;do W.moveTo(K,ie),W.lineTo(K,ie+te),ie+=te+Q;while(ie{const H=I.encodedValue("row",R);d.filter(Y=>!pI(Y,u.row)||pI(Y,u.row)===R).forEach(Y=>{var K,F,J,P,ge;let q=I.encodedPIXIProperty("x",Y),$=I.encodedPIXIProperty("xe",Y),j=I.encodedPIXIProperty("x1",Y),te=I.encodedPIXIProperty("x1e",Y);const Q=I.encodedPIXIProperty("y",Y),ie=I.encodedPIXIProperty("ye",Y),he=I.encodedPIXIProperty("stroke",Y),ne=I.encodedPIXIProperty("strokeWidth",Y),be=I.encodedPIXIProperty("color",Y),pe=I.encodedPIXIProperty("opacity",Y);typeof $<"u"&&([q,$]=[q,$].sort((Pe,De)=>Pe-De)),typeof j<"u"&&typeof te<"u"&&([j,te]=[j,te].sort((Pe,De)=>Pe-De));const ve=typeof $<"u"&&typeof j<"u"&&typeof te<"u"&&Math.abs(q-$)>.1&&Math.abs(j-te)>.1;if(!ve&&$===void 0&&!nC(u)){if(j===void 0&&te===void 0)return;$=j!==void 0?j:te}!ve&&Math.abs(q-$)<=.1&&Math.abs(j-te)<=.1&&(q=(q+$)/2,$=(j+te)/2),e.lineStyle(ne,pt(he),pe,.5);const We=ut(u.y)&&u.y.flip||u.flipY,Be=(K=u.baselineY)!=null?K:H+(We?0:V);let Je=[];if(ve){e.beginFill(pt(be==="none"?"white":be),be==="none"?0:pe);let[Pe,De,Qe,_e]=[q,$,j,te];if([Pe,De,Qe,_e]=[Pe,De,Qe,_e].sort((gt,lt)=>gt-lt),Pe>h||_e<0||Math.abs(_e-Pe)<.5)return;if(f){if(Pe<0||_e>h)return;const gt=p-H/m*B,lt=Mt(Pe,h,gt,G,v,y,Z),tt=Mt(De,h,gt,G,v,y,Z),Xe=Mt(Qe,h,gt,G,v,y,Z),ae=Mt(_e,h,gt,G,v,y,Z);e.moveTo(lt.x,lt.y),e.bezierCurveTo(G,v,G,v,ae.x,ae.y),e.arc(G,v,p,lc(ae.x,ae.y,G,v),lc(Xe.x,Xe.y,G,v),!1),e.bezierCurveTo(G,v,G,v,tt.x,tt.y),e.arc(G,v,p,lc(tt.x,tt.y,G,v),lc(lt.x,lt.y,G,v),!1),Je=Array.from(e.currentPath.points),e.endFill()}else e.moveTo(Pe,Be),!((F=u.style)!=null&&F.linkStyle)||((J=u.style)==null?void 0:J.linkStyle)==="circular"?(e.arc((Pe+_e)/2,Be,(_e-Pe)/2,-Math.PI,Math.PI,!1),e.arc((De+Qe)/2,Be,(Qe-De)/2,Math.PI,-Math.PI,!0),Je=Array.from(e.currentPath.points),e.closePath()):(e.lineTo(Qe,H+V),e.bezierCurveTo(Qe+(De-Qe)/3,H+V-(De-Qe)/2,Qe+(De-Qe)/3*2,H+V-(De-Qe)/2,De,H+V),e.lineTo(_e,H+V),e.bezierCurveTo(Pe+(_e-Pe)/3*2,H+V-(_e-Pe)/2,Pe+(_e-Pe)/3,H+V-(_e-Pe)/2,Pe,H+V),Je=Array.from(e.currentPath.points),e.endFill());I.getMouseEventModel().addPolygonBasedEvent(Y,Je)}else{const Pe=(q+$)/2;if(e.beginFill(pt("white"),0),f){if(q<0||$>h)return;if(((P=u.style)==null?void 0:P.linkStyle)==="straight"){const De=p-H/m*B,Qe=Mt(q,h,De,G,v,y,Z),_e=Mt($,h,De,G,v,y,Z),gt=Qe.x,lt=Qe.y,tt=_e.x,Xe=_e.y;e.moveTo(gt,lt),e.lineTo(tt,Xe);const ae=100;Je=Array.from({length:ae},(He,x)=>({x:(tt-gt)/(ae-1)*x+gt,y:(Xe-lt)/(ae-1)*x+lt})).flatMap(He=>[He.x,He.y])}else{const De=p-H/m*B,Qe=Mt(q,h,De,G,v,y,Z),_e=Mt($,h,De,G,v,y,Z),gt=Qe.x,lt=Qe.y,tt=Qe.x,Xe=Qe.y,ae=h/2,ye=m/2,He=_e.x,x=_e.y;e.moveTo(gt,lt);const T=new Ii(gt,lt,tt,Xe,ae,ye,He,x);T.getLUT(14).forEach(me=>e.lineTo(me.x,me.y)),Je=T.getLUT(1e3).flatMap(me=>[me.x,me.y])}}else if(((ge=u.style)==null?void 0:ge.linkStyle)==="elliptical"){if(!(0<=q&&q<=h)&&!(0<=$&&$<=h))return;const De=[],Qe=ut(u.y);for(let _e=0;_e<=X;_e++){const gt=Math.PI*(_e/X),lt=($-q)/2*Math.cos(gt)+(q+$)/2;let tt=Be-Q*Math.sin(gt)*(Qe?1:Math.min($-q+h*S,h)/h)*(We?-1:1);if(typeof Q<"u"&&typeof ie<"u"){const Xe=Math.abs(ie-Q),ae=ie>Q;tt=Q-Xe*Math.sin(gt)*(ae?-1:1)}if(_e===0)if(W){const Xe=We?Be-m:Be;e.moveTo(lt,Xe),De.push({x:lt,y:Xe}),e.lineTo(lt,tt)}else e.moveTo(lt,tt);else e.lineTo(lt,tt);if(De.push({x:lt,y:tt}),_e===X&&W){const Xe=We?Be-m:Be;e.lineTo(lt,Xe),De.push({x:lt,y:Xe})}}Je=De.flatMap(_e=>[_e.x,_e.y])}else{if($<0||q>h)return;e.arc(Pe,Be,($-q)/2,-Math.PI,Math.PI),Je=Array.from(e.currentPath.points),e.closePath()}I.getMouseEventModel().addLineBasedEvent(Y,Je)}})})}function Lje(e,g,I){return[...e.slice(0,g),I,...e.slice(g)]}function Uje(e){const g=[];for(let I=0;Itypeof g=="number")}function hbe(e){return dbe(e,g=>typeof g=="string")}function Qje(e,g,I){$je(e,g,I),jje(e,g,I)}function jje(e,g,I){var i,n,C,r;const o=g.spec();if(!ut(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=jg(0,A,h,m),Y=jg(A,A,h,m);B.lineStyle(G,pt("black"),0,.5),B.beginFill(pt(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,pt(I.axis.gridColor),1,.5);const V=s+w+Z/2;B.moveTo(a,V),B.lineTo(a+A,V)}})}function $je(e,g,I){var i,n,C,r,o;const a=g.spec();if(!ut(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(!hbe(G))return;const w=g.getChannelScale("y"),V=g.getChannelDomainArray("y");if(!w||!V||!g7(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 K=w.ticks(Y).filter(F=>V[0]<=F&&F<=V[1]);K.length===1&&(K=w.ticks(Y+1).filter(F=>V[0]<=F&&F<=V[1])),h?K.forEach(F=>{const J=w(F),P=f-(R+v-J)/c*y,ge=P+X/2,q=P-X/2,$=Mt(0,l,q,Z,B,b,p),j=jg(0,l,b,p),te=jg(l,l,b,p);S.lineStyle(X,pt("black"),0,.5),S.beginFill(pt(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,ge,te,j,!1),S.closePath()}):(S.lineStyle(X,pt(I.axis.gridColor),1,.5),K.forEach(F=>{var J;const P=A+R+v-w(F);if(I.axis.gridStrokeType==="solid")S.moveTo(u,P),S.lineTo(d,P);else if(I.axis.gridStrokeType==="dashed"){const[ge,q]=(J=I.axis.gridStrokeDash)!=null?J:[1,1];for(let $=u;$=V;Y-=w/10){const K=Mt(Y,A,b-v.height/2,h,m,u,d);X.push(new e.libraries.PIXI.Point(K.x,K.y))}const W=jg(V,A,u,d),R=jg(S+p,A,u,d);f.lineStyle(1,pt("red"),0,.5),f.beginFill(pt(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 e4e(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,pt((r=(C=g.spec().style)==null?void 0:C.outline)!=null?r:I.track.outline),1,.5),o.beginFill(pt("white"),0),o.drawRect(a,s,A,l);const c=g.spec().x;o.lineStyle(1,pt(I.axis.baselineColor),1,.5),ut(c)&&c.axis==="top"?(o.moveTo(a,s),o.lineTo(a+A,s)):ut(c)&&c.axis==="bottom"&&(o.moveTo(a,s+l),o.lineTo(a+A,s+l))}function t4e(e,g,I,i,n){if(!g.gLegend)return;g.gLegend.selectAll(".brush").remove();const C=i.spec(),r={offsetRight:0};if(ut(C.color)&&C.color.legend)switch(C.color.type){case"nominal":g4e(e,g,I,i,n);break;case"quantitative":Nte(e,g,I,i,n,"color",r);break}if(ut(C.stroke)&&C.stroke.legend)switch(C.stroke.type){case"quantitative":Nte(e,g,I,i,n,"stroke",r);break}}function Nte(e,g,I,i,n,C,r){const o=i.spec(),a=o[C];if(!ut(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(pt(n.legend.background),n.legend.backgroundOpacity),y.lineStyle(1,pt(n.legend.backgroundStroke),n.legend.backgroundOpacity,0),y.drawRect(m,f,u,d),a.title){const H=a.title,Y=xs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),K=new e.libraries.PIXI.Text(H,{...Y,fontWeight:"bold"});K.anchor.x=0,K.anchor.y=0,K.position.x=m+10,K.position.y=f+10;const F=new e.libraries.PIXI.TextStyle({...Y,fontWeight:"bold"}),J=e.libraries.PIXI.TextMetrics.measureText(H,F);y.addChild(K),h.top+=J.height+4,h.height-=J.height+4}const[Z,B]=p,G=B-Z,v=ut(a)&&a.scaleOffset?a.scaleOffset:[0,1];[...Array(h.height).keys()].forEach(H=>{let Y;const K=Array.from(v).sort();if(H/h.height>=K[1])Y=B;else if(H/h.height<=K[0])Y=Z;else{const F=eh().domain([h.height*K[0],h.height*K[1]]).range([0,h.height]);Y=eh().domain([0,h.height]).range([Z,B])(F(H))}y.beginFill(pt(b(Y)),1),y.lineStyle(1,pt(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 K=H.sourceEvent,F=g.startEvent.clientY-K.clientY,J=[a.scaleOffset[0],a.scaleOffset[1]];Y.id===0?J[0]+=F/h.height:J[1]+=F/h.height,J[0]=Math.min(1,Math.max(0,J[0])),J[1]=Math.min(1,Math.max(0,J[1])),g.updateScaleOffsetFromOriginalSpec(o._renderingId,J,C),g.shareScaleOffsetAcrossTracksAndTiles(J,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,pt(n.legend.tickColor),1,.5);const W=xs({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 K=new e.libraries.PIXI.Text(H,W);K.anchor.x=1,K.anchor.y=.5,K.position.x=R-6,K.position.y=Y,y.addChild(K)}),r.offsetRight=l-m}function g4e(e,g,I,i,n){var C,r,o,a,s;const A=i.spec();if(!ut(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=xs({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,pt("black"),0,0),m.beginFill(pt(G.color),1),m.drawCircle(G.x,G.y,4)})}function I4e(e,g,I,i,n){var C;const r=i.spec();if(!ut(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=xs({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(pt(n.legend.background),n.legend.backgroundOpacity),a.lineStyle(1,pt(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 r3=8,YZ=6;function i4e(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||!g7(a))return;const[A,l]=g.dimensions,[c,u]=g.position,d=(C=i.getChannelDomainArray("row"))!=null?C:["___SINGLE_ROW___"];if(!hbe(d))return;const h=l/d.length;if(h<=20)return;const m=i.spec().y,f=!(ut(m)&&"axis"in m&&m.axis==="right"),b=eh().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,pt(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,pt(n.axis.tickColor),1,.5);let V=f?B+YZ:B-YZ;w.forEach(X=>{const W=b(X);p.moveTo(B,G+h-W),p.lineTo(V,G+h-W)}),V=f?B+r3:B-r3,p.moveTo(B,G),p.lineTo(V,G),p.moveTo(B,G+h),p.lineTo(V,G+h);const S=xs({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+YZ*2:B-YZ*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 n4e(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||!g7(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=!(ut(w)&&"axis"in w&&w.axis==="right"),S=eh().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,K=Mt(V?0:d,d,H,Z,B,p,y),F=Mt(V?0:d,d,Y,Z,B,p,y);X.lineStyle(1,pt(n.axis.baselineColor),1,.5),X.moveTo(K.x,K.y),X.lineTo(F.x,F.y);const J=j=>YZ*d/2/Math.PI/j,P=j=>r3*d/2/Math.PI/j,ge=v/h*b,q=Math.max(Math.ceil(ge/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,pt(n.axis.tickColor),1,.5),$.forEach(j=>{const te=S(j),Q=f-(R+v-te)/h*b,ie=V?0:d-J(Q),he=V?J(Q):d,ne=Mt(ie,d,Q,Z,B,p,y),be=jg(ie,d,p,y),pe=jg(he,d,p,y);X.moveTo(ne.x,ne.y),X.arc(Z,B,Q,be,pe,!0),X.arc(Z,B,Q,pe,be,!1),X.closePath()});{const j=V?0:d-P(m),te=V?P(m):d,Q=jg(j,d,p,y),ie=jg(te,d,p,y);X.moveTo(K.x,K.y),X.arc(Z,B,m,Q,ie,!0),X.arc(Z,B,m,ie,Q,!1),X.closePath()}{const j=V?0:d-P(f),te=V?P(f):d,Q=jg(j,d,p,y),ie=jg(te,d,p,y);X.moveTo(F.x,F.y),X.arc(Z,B,f,Q,ie,!0),X.arc(Z,B,f,ie,Q,!1),X.closePath()}$.forEach(j=>{const te=S(j),Q=f-(R+v-te)/h*b,ie=Mt(J(Q)*2,d,Q,Z,B,p,y),he=xs({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight}),ne=new e.libraries.PIXI.Text(j,he);ne.anchor.x=V?1:0,ne.anchor.y=.5,ne.position.x=ie.x,ne.position.y=ie.y,ne.resolution=4;const be=new e.libraries.PIXI.TextStyle(he),ve=e.libraries.PIXI.TextMetrics.measureText(ne.text,be).width/(2*Q*Math.PI)*d*360/(y-p),We=V?J(Q)*2:d-J(Q)*2-ve,Be=V?J(Q)*2+ve:d-J(Q)*2,Je=[];for(let De=Be;De>=We;De-=ve/10){const Qe=Mt(De,d,Q,Z,B,p,y);Je.push(new e.libraries.PIXI.Point(Qe.x,Qe.y))}ne.updateText();const Pe=new e.libraries.PIXI.SimpleRope(ne.texture,Je);X.addChild(Pe)})})}function C4e(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=jg(0,b,B,G),X=jg(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,pt((A=(s=h.style)==null?void 0:s.outline)!=null?A:"#DBDBDB"),1,1),W.beginFill(pt((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()),ut(h.x)&&h.x.axis==="top"&&(W.lineStyle(.5,pt("black"),0,.5),W.beginFill(pt("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,pt("black"),0,.5),W.beginFill(pt("white"),0),W.moveTo(v,w),W.arc(v,w,Z+3,S,X,!1),W.closePath(),W.lineStyle(1,pt("#DBDBDB"),0,0),W.beginFill(pt("white"),0),W.drawCircle(v,w,y-1)}function r4e(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=Hte((r=g.spec().style)==null?void 0:r.backgroundOpacity)?1:(o=g.spec().style)==null?void 0:o.backgroundOpacity;u.lineStyle(1,pt("white"),0,0),u.beginFill(pt(d),h),u.drawRect(s,A,l,c)}if(I.track.alternatingBackground&&I.track.alternatingBackground!=="transparent"){const d=g.spec();if(!ut(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=Hte((y=g.spec().style)==null?void 0:y.backgroundOpacity)?1:(Z=g.spec().style)==null?void 0:Z.backgroundOpacity;u.lineStyle(1,pt("white"),0,0),u.beginFill(pt(G),v),u.drawRect(e.position[0],e.position[1]+B,l,c/h.length)})}}function o4e(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=>!pI(v,a.row)||pI(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),K=I.encodedPIXIProperty("strokeWidth",v),F=I.encodedPIXIProperty("color",v),J=I.encodedPIXIProperty("opacity",v);typeof X<"u"&&([S,X]=[S,X].sort((ge,q)=>ge-q)),typeof W<"u"&&typeof R<"u"&&([W,R]=[W,R].sort((ge,q)=>ge-q));const P=typeof X<"u"&&typeof W<"u"&&typeof R<"u"&&Math.abs(S-X)>.1&&Math.abs(W-R)>.1;if(!P&&X===void 0&&!nC(a)){if(W===void 0&&R===void 0)return;X=W!==void 0?W:R}if(!P&&Math.abs(S-X)<=.1&&Math.abs(W-R)<=.1&&(S=(S+X)/2,X=(W+R)/2),e.lineStyle(K,pt(Y),J,.5),P){e.beginFill(pt(F==="none"?"white":F),F==="none"?0:J);let[ge,q,$,j]=[S,X,W,R];if([ge,q]=[ge,q].sort((te,Q)=>te-Q),[$,j]=[$,j].sort((te,Q)=>te-Q),ge>A||j<0||Math.abs(j-ge)<.5)return;if(c){if(ge<0||j>A)return;const te=d-G/l*f,Q=Mt(ge,A,te,b,p,h,m),ie=Mt(q,A,te,b,p,h,m),he=Mt($,A,te,b,p,h,m),ne=Mt(j,A,te,b,p,h,m);e.moveTo(Q.x,Q.y),e.bezierCurveTo(b,p,b,p,ne.x,ne.y),e.arc(b,p,d,lc(ne.x,ne.y,b,p),lc(he.x,he.y,b,p),!1),e.bezierCurveTo(b,p,b,p,ie.x,ie.y),e.arc(b,p,d,lc(ie.x,ie.y,b,p),lc(Q.x,Q.y,b,p),!1),e.endFill()}else e.moveTo(ge,G),e.lineTo(q,G),e.lineTo(j,G+Z),e.lineTo($,G+Z),e.lineTo(ge,G),e.closePath()}else{if(nC(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 ge,q;for(let $=0;$<=1;$+=.02){const j=ne=>Math.log(ne/(1-ne)),te=ne=>d-1/(1+Math.exp(j(ne)))*f+3,Q=(ne,be,pe)=>((pe-be)*ne+be)/A,ie=b+te($)*Math.cos(-Q($,S,X)*2*Math.PI-Math.PI/2),he=p+te($)*Math.sin(-Q($,S,X)*2*Math.PI-Math.PI/2);ge&&q&&(e.lineStyle(K,pt(Y),J,.5),e.moveTo(ge,q),e.lineTo(ie,he)),ge=ie,q=he}return}e.moveTo(X,G+Z),e.lineTo(S,G)}})})}const Hd=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function a4e(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)}),nC(i.spec())||y4e(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":Yje(g,I.graphics,i);break;case"bar":Dje(g,I,i);break;case"line":xje(I.graphics,i,n,C);break;case"area":Eje(e,g,I,i);break;case"rect":Mje(e,g,I,i);break;case"triangleLeft":case"triangleRight":case"triangleBottom":Pje(I.graphics,i,n,C);break;case"text":Jje(e,g,I,i);break;case"rule":Oje(e,g,I,i);break;case"betweenLink":o4e(I.graphics,g,i);break;case"withinLink":_je(I.graphics,g,i);break;default:console.warn("Unsupported mark type");break}}function A4e(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"?C4e(g,i,n):(r4e(g,i,n),e4e(g,i,n)),Qje(g,i,n)}function s4e(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"?(n4e(e,g,I,i,n),qje(e,g,I,i,n)):(i4e(e,g,I,i,n),I4e(e,g,I,i,n)),t4e(e,g,I,i,n)}function T0(e){if(pbe(e)||VS(e))return[];if(!ui(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=>{ut(C.x)&&C.x.axis&&!i&&(i=C.x.axis)}),I.map(C=>({...C,x:{...C.x,axis:i}}))}function mbe(e){return[].concat(...e.map(g=>{if(pbe(g)||!ui(g)||g._overlay.length<=1)return[g];if(g._overlay.filter(r=>r.data).length===0)return[g];if(kte([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||kte([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=Fr(r)&&ut(r.y)&&!r.y.axis&&s?{...r.y,axis:o===1?"right":"none"}:Fr(r)?r.y:void 0;return r.title&&o!==a.length-1&&a.length!==1&&delete r.title,{...r,overlayOnPreviousTrack:s,y:A}})}))}function kte(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 NX={viridis:sbe,grey:mje,warm:pje,spectral:aje,cividis:fje,bupu:sje,rdbu:rje,hot:dje,pink:cje};function I7(e){return typeof e=="object"&&e!==null}function PV(e){return I7(e)&&"getTabularData"in e}function l4e(e,g){var I;return((I=e.dataTransform)!=null?I:[]).some(i=>i.type===g)}function c4e(e="viridis",g=100){var I;const i=(I=NX[e])!=null?I:NX.viridis;return[...Array(g)].map((n,C)=>i(1/g*C))}function fbe(e){return!("alignment"in e)&&!e.tracks.find(g=>g.alignment==="overlay"||"tracks"in g)}function u4e(e){return"alignment"in e&&e.alignment==="overlay"}function d4e(e){return!fbe(e)&&!u4e(e)}function pbe(e){return!ui(e)&&"data"in e&&!("mark"in e)}function VS(e){return"type"in e&&e.type=="dummy-track"}function h4e(e){return!!("data"in e&&"overrideTemplate"in e&&e.overrideTemplate)}function Yte(e){return typeof e=="object"}function m4e(e){return"chromosome"in e&&!("interval"in e)}function f4e(e){return!("chromosome"in e)&&"interval"in e}function p4e(e){return"chromosome"in e&&"interval"in e}function Fr(e){return!("_overlay"in e)}function ui(e){return"_overlay"in e}function b4e(e){return"template"in e}function y4e(e){return Fr(e)&&!ut(e.x)&&ut(e.y)&&e.y.type==="genomic"}function nC(e){const g=Fr(e)?e:T0(e)[0];return ut(g.x)&&g.x.type==="genomic"&&ut(g.y)&&g.y.type==="genomic"}function Z4e(e){return nC(e)&&e.data.type==="matrix"&&(e.mark==="bar"||e.mark==="rect")&&e.xe&&e.ye}function N1(e){return e!==null&&typeof e=="object"&&"value"in e}function i7(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 ut(e){return I7(e)&&!("value"in e)}function G4e(e){return"oneOf"in e}function v4e(e){return"inRange"in e}function B4e(e){return"include"in e}function Kte(e){return Array.isArray(e)}function S4e(e){return Array.isArray(e)}function TT(e){return(e.mark==="bar"||e.mark==="area"||e.mark==="text")&&ut(e.color)&&e.color.type==="nominal"&&(!e.row||N1(e.row))&&ut(e.y)&&e.y.type==="quantitative"&&!ut(e.ye)}function w4e(e,g){const I=e[g];return TT(e)&&(g==="x"||g==="y")&&ut(I)&&I.type==="quantitative"}function pI(e,g){if(ut(g)&&g.field)return e[g==null?void 0:g.field]}function V4e(e){const g=[];return Hd.forEach(I=>{const i=e[I];ut(i)&&"aggregate"in i&&g.push(I)}),g}function s5(e,g){const I=[];return Hd.forEach(i=>{const n=e[i];ut(n)&&n.type===g&&I.push(i)}),I}function kX(e){if((Fr(e)||ui(e))&&ut(e.x)&&e.x.axis&&e.x.axis!=="none")return!0;if(ui(e)){let g=!1;return e._overlay.forEach(I=>{g||ut(I.x)&&I.x.axis&&I.x.axis!=="none"&&(g=!0)}),g}return!1}function R4e(e){if((Fr(e)||ui(e))&&ut(e.y)&&e.y.axis&&e.y.axis!=="none")return!0;if(ui(e)){let g=!1;return e._overlay.forEach(I=>{g||ut(I.y)&&I.y.axis&&I.y.axis!=="none"&&(g=!0)}),g}return!1}function Ym(e){return typeof e=="object"}var Ih=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function W4e(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var o3={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)})(Ih,function(I){function i(){for(var O=arguments.length,D=Array(O),ee=0;ee1){D[0]=D[0].slice(0,-1);for(var ce=D.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(O){throw new RangeError(V[O])}function H(O,D){for(var ee=[],ce=O.length;ce--;)ee[ce]=D(O[ce]);return ee}function Y(O,D){var ee=O.split("@"),ce="";ee.length>1&&(ce=ee[0]+"@",O=ee[1]),O=O.replace(w,".");var de=O.split("."),Le=H(de,D).join(".");return ce+Le}function K(O){for(var D=[],ee=0,ce=O.length;ee=55296&&de<=56319&&ee>1,D+=X(D/ee);D>S*f>>1;de+=h)D=X(D/S);return X(de+(S+1)*D/(D+b))},q=function(D){var ee=[],ce=D.length,de=0,Le=Z,Ue=y,dt=D.lastIndexOf(B);dt<0&&(dt=0);for(var yt=0;yt=128&&R("not-basic"),ee.push(D.charCodeAt(yt));for(var kt=dt>0?dt+1:0;kt=ce&&R("invalid-input");var At=J(D.charCodeAt(kt++));(At>=h||At>X((d-de)/Vt))&&R("overflow"),de+=At*Vt;var Xt=Ft<=Ue?m:Ft>=Ue+f?f:Ft-Ue;if(AtX(d/Pt)&&R("overflow"),Vt*=Pt}var xt=ee.length+1;Ue=ge(de-ht,xt,ht==0),X(de/xt)>d-Le&&R("overflow"),Le+=X(de/xt),de%=xt,ee.splice(de++,0,Le)}return String.fromCodePoint.apply(String,ee)},$=function(D){var ee=[];D=K(D);var ce=D.length,de=Z,Le=0,Ue=y,dt=!0,yt=!1,kt=void 0;try{for(var ht=D[Symbol.iterator](),Vt;!(dt=(Vt=ht.next()).done);dt=!0){var Ft=Vt.value;Ft<128&&ee.push(W(Ft))}}catch(pC){yt=!0,kt=pC}finally{try{!dt&&ht.return&&ht.return()}finally{if(yt)throw kt}}var At=ee.length,Xt=At;for(At&&ee.push(B);Xt=de&&LtX((d-Le)/Yt)&&R("overflow"),Le+=(Pt-de)*Yt,de=Pt;var Wt=!0,eg=!1,_t=void 0;try{for(var $t=D[Symbol.iterator](),ag;!(Wt=(ag=$t.next()).done);Wt=!0){var Wg=ag.value;if(Wgd&&R("overflow"),Wg==de){for(var hg=Le,PI=h;;PI+=h){var en=PI<=Ue?m:PI>=Ue+f?f:PI-Ue;if(hg>6|192).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase():ee="%"+(D>>12|224).toString(16).toUpperCase()+"%"+(D>>6&63|128).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase(),ee}function ne(O){for(var D="",ee=0,ce=O.length;ee=194&&de<224){if(ce-ee>=6){var Le=parseInt(O.substr(ee+4,2),16);D+=String.fromCharCode((de&31)<<6|Le&63)}else D+=O.substr(ee,6);ee+=6}else if(de>=224){if(ce-ee>=9){var Ue=parseInt(O.substr(ee+4,2),16),dt=parseInt(O.substr(ee+7,2),16);D+=String.fromCharCode((de&15)<<12|(Ue&63)<<6|dt&63)}else D+=O.substr(ee,9);ee+=9}else D+=O.substr(ee,3),ee+=3}return D}function be(O,D){function ee(ce){var de=ne(ce);return de.match(D.UNRESERVED)?de:ce}return O.scheme&&(O.scheme=String(O.scheme).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_SCHEME,"")),O.userinfo!==void 0&&(O.userinfo=String(O.userinfo).replace(D.PCT_ENCODED,ee).replace(D.NOT_USERINFO,he).replace(D.PCT_ENCODED,r)),O.host!==void 0&&(O.host=String(O.host).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_HOST,he).replace(D.PCT_ENCODED,r)),O.path!==void 0&&(O.path=String(O.path).replace(D.PCT_ENCODED,ee).replace(O.scheme?D.NOT_PATH:D.NOT_PATH_NOSCHEME,he).replace(D.PCT_ENCODED,r)),O.query!==void 0&&(O.query=String(O.query).replace(D.PCT_ENCODED,ee).replace(D.NOT_QUERY,he).replace(D.PCT_ENCODED,r)),O.fragment!==void 0&&(O.fragment=String(O.fragment).replace(D.PCT_ENCODED,ee).replace(D.NOT_FRAGMENT,he).replace(D.PCT_ENCODED,r)),O}function pe(O){return O.replace(/^0*(.*)/,"$1")||"0"}function ve(O,D){var ee=O.match(D.IPV4ADDRESS)||[],ce=c(ee,2),de=ce[1];return de?de.split(".").map(pe).join("."):O}function We(O,D){var ee=O.match(D.IPV6ADDRESS)||[],ce=c(ee,3),de=ce[1],Le=ce[2];if(de){for(var Ue=de.toLowerCase().split("::").reverse(),dt=c(Ue,2),yt=dt[0],kt=dt[1],ht=kt?kt.split(":").map(pe):[],Vt=yt.split(":").map(pe),Ft=D.IPV4ADDRESS.test(Vt[Vt.length-1]),At=Ft?7:8,Xt=Vt.length-At,Pt=Array(At),xt=0;xt1){var Zt=Pt.slice(0,qg.index),Lt=Pt.slice(qg.index+qg.length);It=Zt.join(":")+"::"+Lt.join(":")}else It=Pt.join(":");return Le&&(It+="%"+Le),It}else return O}var Be=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function Pe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee={},ce=D.iri!==!1?l:A;D.reference==="suffix"&&(O=(D.scheme?D.scheme+":":"")+"//"+O);var de=O.match(Be);if(de){Je?(ee.scheme=de[1],ee.userinfo=de[3],ee.host=de[4],ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=de[7],ee.fragment=de[8],isNaN(ee.port)&&(ee.port=de[5])):(ee.scheme=de[1]||void 0,ee.userinfo=O.indexOf("@")!==-1?de[3]:void 0,ee.host=O.indexOf("//")!==-1?de[4]:void 0,ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=O.indexOf("?")!==-1?de[7]:void 0,ee.fragment=O.indexOf("#")!==-1?de[8]:void 0,isNaN(ee.port)&&(ee.port=O.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),ee.host&&(ee.host=We(ve(ee.host,ce),ce)),ee.scheme===void 0&&ee.userinfo===void 0&&ee.host===void 0&&ee.port===void 0&&!ee.path&&ee.query===void 0?ee.reference="same-document":ee.scheme===void 0?ee.reference="relative":ee.fragment===void 0?ee.reference="absolute":ee.reference="uri",D.reference&&D.reference!=="suffix"&&D.reference!==ee.reference&&(ee.error=ee.error||"URI is not a "+D.reference+" reference.");var Le=ie[(D.scheme||ee.scheme||"").toLowerCase()];if(!D.unicodeSupport&&(!Le||!Le.unicodeSupport)){if(ee.host&&(D.domainHost||Le&&Le.domainHost))try{ee.host=Q.toASCII(ee.host.replace(ce.PCT_ENCODED,ne).toLowerCase())}catch(Ue){ee.error=ee.error||"Host's domain name can not be converted to ASCII via punycode: "+Ue}be(ee,A)}else be(ee,ce);Le&&Le.parse&&Le.parse(ee,D)}else ee.error=ee.error||"URI can not be parsed.";return ee}function De(O,D){var ee=D.iri!==!1?l:A,ce=[];return O.userinfo!==void 0&&(ce.push(O.userinfo),ce.push("@")),O.host!==void 0&&ce.push(We(ve(String(O.host),ee),ee).replace(ee.IPV6ADDRESS,function(de,Le,Ue){return"["+Le+(Ue?"%25"+Ue:"")+"]"})),(typeof O.port=="number"||typeof O.port=="string")&&(ce.push(":"),ce.push(String(O.port))),ce.length?ce.join(""):void 0}var Qe=/^\.\.?\//,_e=/^\/\.(\/|$)/,gt=/^\/\.\.(\/|$)/,lt=/^\/?(?:.|\n)*?(?=\/|$)/;function tt(O){for(var D=[];O.length;)if(O.match(Qe))O=O.replace(Qe,"");else if(O.match(_e))O=O.replace(_e,"/");else if(O.match(gt))O=O.replace(gt,"/"),D.pop();else if(O==="."||O==="..")O="";else{var ee=O.match(lt);if(ee){var ce=ee[0];O=O.slice(ce.length),D.push(ce)}else throw new Error("Unexpected dot segment condition")}return D.join("")}function Xe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee=D.iri?l:A,ce=[],de=ie[(D.scheme||O.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(O,D),O.host&&!ee.IPV6ADDRESS.test(O.host)){if(D.domainHost||de&&de.domainHost)try{O.host=D.iri?Q.toUnicode(O.host):Q.toASCII(O.host.replace(ee.PCT_ENCODED,ne).toLowerCase())}catch(dt){O.error=O.error||"Host's domain name can not be converted to "+(D.iri?"Unicode":"ASCII")+" via punycode: "+dt}}be(O,ee),D.reference!=="suffix"&&O.scheme&&(ce.push(O.scheme),ce.push(":"));var Le=De(O,D);if(Le!==void 0&&(D.reference!=="suffix"&&ce.push("//"),ce.push(Le),O.path&&O.path.charAt(0)!=="/"&&ce.push("/")),O.path!==void 0){var Ue=O.path;!D.absolutePath&&(!de||!de.absolutePath)&&(Ue=tt(Ue)),Le===void 0&&(Ue=Ue.replace(/^\/\//,"/%2F")),ce.push(Ue)}return O.query!==void 0&&(ce.push("?"),ce.push(O.query)),O.fragment!==void 0&&(ce.push("#"),ce.push(O.fragment)),ce.join("")}function ae(O,D){var ee=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(O=Pe(Xe(O,ee),ee),D=Pe(Xe(D,ee),ee)),ee=ee||{},!ee.tolerant&&D.scheme?(de.scheme=D.scheme,de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.userinfo!==void 0||D.host!==void 0||D.port!==void 0?(de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.path?(D.path.charAt(0)==="/"?de.path=tt(D.path):((O.userinfo!==void 0||O.host!==void 0||O.port!==void 0)&&!O.path?de.path="/"+D.path:O.path?de.path=O.path.slice(0,O.path.lastIndexOf("/")+1)+D.path:de.path=D.path,de.path=tt(de.path)),de.query=D.query):(de.path=O.path,D.query!==void 0?de.query=D.query:de.query=O.query),de.userinfo=O.userinfo,de.host=O.host,de.port=O.port),de.scheme=O.scheme),de.fragment=D.fragment,de}function ye(O,D,ee){var ce=a({scheme:"null"},ee);return Xe(ae(Pe(O,ce),Pe(D,ce),ce,!0),ce)}function He(O,D){return typeof O=="string"?O=Xe(Pe(O,D),D):C(O)==="object"&&(O=Pe(Xe(O,D),D)),O}function x(O,D,ee){return typeof O=="string"?O=Xe(Pe(O,ee),ee):C(O)==="object"&&(O=Xe(O,ee)),typeof D=="string"?D=Xe(Pe(D,ee),ee):C(D)==="object"&&(D=Xe(D,ee)),O===D}function T(O,D){return O&&O.toString().replace(!D||!D.iri?A.ESCAPE:l.ESCAPE,he)}function k(O,D){return O&&O.toString().replace(!D||!D.iri?A.PCT_ENCODED:l.PCT_ENCODED,ne)}var Ie={scheme:"http",domainHost:!0,parse:function(D,ee){return D.host||(D.error=D.error||"HTTP URIs must have a host."),D},serialize:function(D,ee){var ce=String(D.scheme).toLowerCase()==="https";return(D.port===(ce?443:80)||D.port==="")&&(D.port=void 0),D.path||(D.path="/"),D}},me={scheme:"https",domainHost:Ie.domainHost,parse:Ie.parse,serialize:Ie.serialize};function Re(O){return typeof O.secure=="boolean"?O.secure:String(O.scheme).toLowerCase()==="wss"}var we={scheme:"ws",domainHost:!0,parse:function(D,ee){var ce=D;return ce.secure=Re(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(D,ee){if((D.port===(Re(D)?443:80)||D.port==="")&&(D.port=void 0),typeof D.secure=="boolean"&&(D.scheme=D.secure?"wss":"ws",D.secure=void 0),D.resourceName){var ce=D.resourceName.split("?"),de=c(ce,2),Le=de[0],Ue=de[1];D.path=Le&&Le!=="/"?Le:void 0,D.query=Ue,D.resourceName=void 0}return D.fragment=void 0,D}},je={scheme:"wss",domainHost:we.domainHost,parse:we.parse,serialize:we.serialize},at={},bt="[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)),Ce="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=i(E,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ye=new RegExp(bt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(i("[^]",Ce,"[\\.]",'[\\"]',_),"g"),re=new RegExp(i("[^]",bt,fe),"g"),oe=re;function Ve(O){var D=ne(O);return D.match(Ye)?D:O}var Fe={scheme:"mailto",parse:function(D,ee){var ce=D,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Le=!1,Ue={},dt=ce.query.split("&"),yt=0,kt=dt.length;yt=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 c$e(e,g,I){var i=Vbe.call(this,e,g,I);i>=0&&this._compilations.splice(i,1)}function Vbe(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,Hbe=/^(?:(?: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,Tbe=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Nbe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,kbe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Ybe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,B$e=KT;function KT(e){return e=e=="full"?"full":"fast",p$e.copy(KT[e])}KT.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":Xbe,url:Hbe,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:Wbe,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:Dbe,uuid:Tbe,"json-pointer":Nbe,"json-pointer-uri-fragment":kbe,"relative-json-pointer":Ybe};KT.full={date:Kbe,time:xbe,"date-time":V$e,uri:W$e,"uri-reference":v$e,"uri-template":Xbe,url:Hbe,email:/^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)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:(?: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:Dbe,uuid:Tbe,"json-pointer":Nbe,"json-pointer-uri-fragment":kbe,"relative-json-pointer":Ybe};function S$e(e){return e%4===0&&(e%100!==0||e%400===0)}function Kbe(e){var g=e.match(b$e);if(!g)return!1;var I=+g[1],i=+g[2],n=+g[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&S$e(I)?29:y$e[i])}function xbe(e,g){var I=e.match(Z$e);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 w$e=/t|\s/i;function V$e(e){var g=e.split(w$e);return g.length==2&&Kbe(g[0])&&xbe(g[1],!0)}var R$e=/\/|:/;function W$e(e){return R$e.test(e)&&G$e.test(e)}var X$e=/[^\\]\\Z/;function Dbe(e){if(X$e.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var H$e=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},T$e=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},N$e=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},x$e=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=P,n+=" } ",A&&(n+=" if ("+h+") { ",d+="}"))}return A&&(n+=" "+d+" if ("+c+" == errors) {"),n},D$e=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},F$e=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},E$e=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},M$e=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},Mte=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},zte=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},Pte=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},Jte=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},z$e=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},P$e=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},J$e=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},O$e=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},_$e=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(F),B=g.schema.patternProperties||{},G=Object.keys(B).filter(F),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 J=Z;if(J)for(var P,ge=-1,q=J.length-1;ge0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var gt=g.util.getProperty(P),We=l+gt,lt=Je&&_e.default!==void 0;u.schema=_e,u.schemaPath=a+gt,u.errSchemaPath=s+"/"+g.util.escapeFragment(P),u.errorPath=g.util.getPath(g.errorPath,P,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(P);var Be=g.validate(u);if(u.baseId=H,g.util.varOccurences(Be,p)<2){Be=g.util.varReplace(Be,p,We);var tt=We}else{var tt=p;n+=" var "+p+" = "+We+"; "}if(lt)n+=" "+Be+" ";else{if(K&&K[P]){n+=" if ( "+tt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = false; ";var ie=g.errorPath,ne=s,Xe=g.util.escapeQuotes(P);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(ie,P,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var be=be||[];be.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Xe+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Xe+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+a+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var pe=n;n=be.pop(),!g.compositeRule&&A?g.async?n+=" throw new ValidationError(["+pe+"]); ":n+=" validate.errors = ["+pe+"]; return false; ":n+=" var err = "+pe+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=ne,g.errorPath=ie,n+=" } else { "}else A?(n+=" if ( "+tt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+tt+" !== undefined ",R&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=" ) { ");n+=" "+Be+" } "}}A&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var ae=G;if(ae)for(var j,ye=-1,He=ae.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 We=l+"["+m+"]";u.dataPathArr[b]=m;var Be=g.validate(u);u.baseId=H,g.util.varOccurences(Be,p)<2?n+=" "+g.util.varReplace(Be,p,We)+" ":n+=" var "+p+" = "+We+"; "+Be+" ",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$e=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},j$e={$ref:H$e,allOf:T$e,anyOf:N$e,$comment:k$e,const:Y$e,contains:K$e,dependencies:x$e,enum:D$e,format:F$e,if:E$e,items:M$e,maximum:Mte,minimum:Mte,maxItems:zte,minItems:zte,maxLength:Pte,minLength:Pte,maxProperties:Jte,minProperties:Jte,multipleOf:z$e,not:P$e,oneOf:J$e,pattern:O$e,properties:_$e,propertyNames:L$e,required:U$e,uniqueItems:Q$e,validate:Sbe},Ote=j$e,c5=N0.toHash,$$e=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=c5(I),g.types=c5(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:Ote[r],implements:o};return s}),g.all.$comment={keyword:"$comment",code:Ote.$comment},C.type&&(g.types[C.type]=C)}),g.keywords=c5(I.concat(i)),g.custom={},g},_te=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],q$e=function(e,g){for(var I=0;I{g(I,i,n),EX(I,g)}):"views"in e&&e.views.forEach(I=>EX(I,g))}function pb(e,g){"tracks"in e?e.tracks.forEach(I=>{g(I),pb(I,g)}):"views"in e&&e.views.forEach(I=>{g(I),pb(I,g)})}function Ube(e,g){"tracks"in e||(g(e),e.views.forEach(I=>{Ube(I,g)}))}function Qbe(e){if(fbe(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 d4e(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 h3(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=d5(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=ube),e.spacing===void 0&&(e.spacing=T1),"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=ln()),"tracks"in e){let I=Qbe(e);I=mbe(I);const i=ln();I.forEach((n,C,r)=>{var o,a,s;if(n.id||(n.id=ln()),n.width||(n.width=nC(n)?Tte:Hje),n.height||(n.height=nC(n)?Tte:Xje),"displacement"in n)if(((o=n.displacement)==null?void 0:o.type)==="pile"&&n.row===void 0&&ut(n.x)&&n.x.field&&ut(n.xe)&&n.xe.field){const A=ln(),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"&&VS(n)){n._invalidTrack=!0;return}if(n.style=d5(e.style,n.style),ui(n)&&(n._overlay=n._overlay.filter(A=>!("type"in A&&A.type=="dummy-track")),n._overlay.forEach(A=>{A.style=d5(n.style,A.style)})),(n.layout==="circular"||nC(n))&&n.orientation==="vertical"&&(n.orientation="horizontal"),nC(n)&&(n.layout="linear",(Fr(n)||ui(n))&&ut(n.y)&&!n.y.domain?n.y.domain=e.yDomain:ui(n)&&n._overlay.forEach(A=>{ut(A.y)&&!A.y.domain&&(A.y.domain=e.yDomain)})),(Fr(n)||ui(n))&&ut(n.x)&&!n.x.domain?n.x.domain=e.xDomain:ui(n)&&n._overlay.forEach(A=>{ut(A.x)&&!A.x.domain&&(A.x.domain=e.xDomain)}),(Fr(n)||ui(n))&&ut(n.x)&&!n.x.linkingId)n.x.linkingId=(s=e.linkingId)!=null?s:i;else if(ui(n)){let A=!1;n._overlay.forEach(l=>{var c;A||ut(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)&&((Fr(n)||ui(n))&&ut(n.x)&&!n.x.axis?n.orientation==="vertical"?n.x.axis="left":n.x.axis="top":ui(n)&&n._overlay.forEach(A=>{ut(A.x)&&!A.x.axis&&(n.orientation==="vertical"?A.x.axis="left":A.x.axis="top")})),(Fr(n)||ui(n))&&ut(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"):ui(n)&&n._overlay.forEach(A=>{ut(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=>{h3(I,e)})}function g6e(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 I6e(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 i6e(e){EX(e,(g,I,i)=>{var n,C,r,o,a;if(!(!("data"in g)||!g.data||!i7(g.data))&&!("alignment"in g)&&h4e(g))switch(g.data.type){case"vector":case"bigwig":i[I]=Object.assign(g6e((n=g.data.column)!=null?n:"position",(C=g.data.value)!=null?C:"value"),g);break;case"multivec":i[I]=Object.assign(I6e((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 h5={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},m5={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},f5={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},p5={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},b5={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},y5={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},Z5={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 Uu(e,g,I=!1){const i=Object.entries(bI(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 bI(e){if(e&&typeof e=="string"&&e in G5)return G5[e];if(Array.isArray(e)&&e.length!==0){const g=Object.fromEntries(e);return{size:g,interval:Wl(g),total:Xl(g),path:n6e(e)}}else return G5.hg38}const pl=e=>`https://s3.amazonaws.com/gosling-lang.org/data/${e}.chrom.sizes`,G5=Object.freeze({hg38:{size:h5,interval:Wl(h5),total:Xl(h5),path:pl("hg38")},hg19:{size:m5,interval:Wl(m5),total:Xl(m5),path:pl("hg19")},hg18:{size:f5,interval:Wl(f5),total:Xl(f5),path:pl("hg18")},hg17:{size:p5,interval:Wl(p5),total:Xl(p5),path:pl("hg17")},hg16:{size:b5,interval:Wl(b5),total:Xl(b5),path:pl("hg16")},mm10:{size:y5,interval:Wl(y5),total:Xl(y5),path:pl("mm10")},mm9:{size:Z5,interval:Wl(Z5),total:Xl(Z5),path:pl("mm9")},unknown:{size:{chr:Number.MAX_VALUE},interval:{chr:[0,Number.MAX_VALUE]},total:Number.MAX_VALUE,path:pl("hg38")}});function C6e(e){switch(e){case"hg19":return"OHJakQICQD6gTD7skx4EWA";case"mm10":return"QDutvmyiSrec5nX4pA5WGQ";case"mm9":return"GUm5aBiLRCyz2PsBea7Yzg";case"hg38":default:return"P0PLbQMwTYGy-5uPIQid7A"}}function Wl(e){const g={};return Object.keys(e).reduce((I,i)=>(g[i]=[I,I+e[i]],I+e[i]),0),g}function Xl(e){return Object.values(e).reduce((g,I)=>g+I,0)}function r6e(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 u7{constructor(g,I,i){this.chromosome=g,this.start=I,this.end=i}static fromString(g){const I=r6e(g);return new u7(I.chromosome,I.start,I.end)}toAbsoluteCoordinates(g,I=0){const i=bI(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 jbe(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}})}FU(e=>e.pos).left;function m3(e,g,I){return Array.isArray(g)||(I?e=e.replace(I,"chr"):e.includes("chr")||(e=`chr${e}`)),e}class $be extends cbe{constructor(){super(...arguments),Wje(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 Qte=()=>Math.random().toString(36).substring(2,8),o6e=(e,{force:g=!1}={})=>{let I=Qte();for(;window.higlassTracks[I];)I=Qte();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},a6e=(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},Vu=(e,g={})=>{const{pluginType:I="track"}=g;I==="track"?o6e(e,g):I==="dataFetcher"&&a6e(e,g)};var WS={},f3={exports:{}},jte=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof window.msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto);if(jte){var $te=new Uint8Array(16);f3.exports=function(){return jte($te),$te}}else{var qte=new Array(16);f3.exports=function(){for(var g=0,I;g<16;g++)g&3||(I=Math.random()*4294967296),qte[g]=I>>>((g&3)<<3)&255;return qte}}var A6e=f3.exports,qbe=[];for(var LV=0;LV<256;++LV)qbe[LV]=(LV+256).toString(16).substr(1);function s6e(e,g){var I=g||0,i=qbe;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 l6e=s6e,c6e=A6e,u6e=l6e;function d6e(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||c6e)();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||u6e(n)}var h6e=d6e,p3=[],e0e={};for(var Km=0;Km<256;Km++)p3[Km]=(Km+256).toString(16).substr(1),e0e[p3[Km]]=Km;function m6e(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++]=e0e[C])});n<16;)g[i+n++]=0;return g}function f6e(e,g){var I=g||0,i=p3;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 p6e={parse:m6e,unparse:f6e},t0e=h6e,g0e=p6e;WS.encode=function(e){var g=g0e.parse(e),I=new Buffer(g).toString("base64"),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};WS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return g0e.unparse(new Buffer(g,"base64"))};WS.v4=function(){var e=t0e(null,new Buffer(16)),g=e.toString("base64"),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};WS.nice=function(){var e=t0e(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 b6e=WS;const y6e=jc(b6e);var Z6e=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));I0e(e,g,A,l,n)}var c=e[g],u=I,d=i;for(zy(e,I,g),n(e[i],c)>0&&zy(e,I,i);u0;)d--}n(e[I],c)===0?zy(e,I,d):(d++,zy(e,d,i)),d<=g&&(I=d+1),g<=d&&(i=d-1)}}function zy(e,g,I){var i=e[g];e[g]=e[I],e[I]=i}function H6e(e,g){return eg?1:0}class T6e{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(!QV(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=ff(i.children.splice(r,i.children.length-r));o.height=i.height,o.leaf=i.leaf,xm(i,this.toBBox),xm(o,this.toBBox),I?g[I-1].children.push(o):this._splitRoot(i,o)}_splitRoot(g,I){this.data=ff([g,I]),this.data.height=g.height+1,this.data.leaf=!1,xm(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=KZ(g,0,o,this.toBBox),s=KZ(g,o,i,this.toBBox),A=x6e(a,s),l=v5(a)+v5(s);A=I;s--){const A=g.children[s];xZ(o,g.leaf?C(A):A),a+=UV(o)}return a}_adjustParentBBoxes(g,I,i){for(let n=i;n>=0;n--)xZ(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():xm(g[I],this.toBBox)}}function N6e(e,g,I){if(!I)return g.indexOf(e);for(let i=0;i=e.minX&&g.maxY>=e.minY}function ff(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function ege(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;X6e(e,r,g,I,n),C.push(g,r,r,I)}}function D6e(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function MX(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 y3(e){return e=MX(Math.abs(e)),e?e[1]:NaN}function F6e(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 E6e(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var M6e=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Z3(e){if(!(g=M6e.exec(e)))throw new Error("invalid format: "+e);var g;return new d7({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]})}Z3.prototype=d7.prototype;function d7(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+""}d7.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 z6e(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 i0e;function P6e(e,g){var I=MX(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(i0e=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")+MX(e,Math.max(0,g+C-1))[0]}function tge(e,g){var I=MX(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 gge={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:D6e,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)=>tge(e*100,g),r:tge,s:P6e,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Ige(e){return e}var ige=Array.prototype.map,nge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function J6e(e){var g=e.grouping===void 0||e.thousands===void 0?Ige:F6e(ige.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?Ige:E6e(ige.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=Z3(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"):gge[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=gge[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 K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=z6e(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?nge[8+i0e/3]:"")+W+(K&&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 F=X.length+S.length+W.length,J=F>1)+X+S+W+J.slice(F);break;default:S=J+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function A(l,c){var u=s((l=Z3(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(y3(c)/3)))*3,h=Math.pow(10,-d),m=nge[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var jV,n0e,C0e;O6e({thousands:",",grouping:[3],currency:["$",""]});function O6e(e){return jV=J6e(e),n0e=jV.format,C0e=jV.formatPrefix,jV}function _6e(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(y3(g)/3)))*3-y3(Math.abs(e)))}const G3=Math.PI,v3=2*G3,Qu=1e-6,L6e=v3-Qu;function B3(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function r0e(){return new B3}B3.prototype=r0e.prototype={constructor:B3,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>Qu)if(!(Math.abs(A*o-a*s)>Qu)||!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((G3-Math.acos((d+l-h)/(2*m*f)))/2),p=b/f,y=b/m;Math.abs(p-1)>Qu&&(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)>Qu||Math.abs(this._y1-s)>Qu)&&(this._+="L"+a+","+s),I&&(l<0&&(l=l%v3+v3),l>L6e?this._+="A"+I+","+I+",0,1,"+A+","+(e-r)+","+(g-o)+"A"+I+","+I+",0,1,"+A+","+(this._x1=a)+","+(this._y1=s):l>Qu&&(this._+="A"+I+","+I+",0,"+ +(l>=G3)+","+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 bl(e){return function(){return e}}var Cge=Math.abs,vn=Math.atan2,Ru=Math.cos,U6e=Math.max,S5=Math.min,Va=Math.sin,Ip=Math.sqrt,vC=1e-12,BB=Math.PI,zX=BB/2,Q6e=2*BB;function j6e(e){return e>1?0:e<-1?BB:Math.acos(e)}function rge(e){return e>=1?zX:e<=-1?-zX:Math.asin(e)}function $6e(e){return e.innerRadius}function q6e(e){return e.outerRadius}function eqe(e){return e.startAngle}function tqe(e){return e.endAngle}function gqe(e){return e&&e.padAngle}function Iqe(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 iqe(){var e=$6e,g=q6e,I=bl(0),i=null,n=eqe,C=tqe,r=gqe,o=null;function a(){var s,A,l=+e.apply(this,arguments),c=+g.apply(this,arguments),u=n.apply(this,arguments)-zX,d=C.apply(this,arguments)-zX,h=Cge(d-u),m=d>u;if(o||(o=s=r0e()),cvC))o.moveTo(0,0);else if(h>Q6e-vC)o.moveTo(c*Ru(u),c*Va(u)),o.arc(0,0,c,u,d,!m),l>vC&&(o.moveTo(l*Ru(d),l*Va(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>vC&&(i?+i.apply(this,arguments):Ip(l*l+c*c)),w=S5(Cge(c-l)/2,+I.apply(this,arguments)),V=w,S=w,X,W;if(v>vC){var R=rge(v/l*Va(G)),H=rge(v/c*Va(G));(Z-=R*2)>vC?(R*=m?1:-1,p+=R,y-=R):(Z=0,p=y=(u+d)/2),(B-=H*2)>vC?(H*=m?1:-1,f+=H,b-=H):(B=0,f=b=(u+d)/2)}var Y=c*Ru(f),K=c*Va(f),F=l*Ru(y),J=l*Va(y);if(w>vC){var P=c*Ru(b),ge=c*Va(b),q=l*Ru(p),$=l*Va(p),j;if(hvC?S>vC?(X=$V(q,$,Y,K,c,S,m),W=$V(P,ge,F,J,c,S,m),o.moveTo(X.cx+X.x01,X.cy+X.y01),SvC)||!(Z>vC)?o.lineTo(F,J):V>vC?(X=$V(F,J,P,ge,l,-V,m),W=$V(Y,K,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 o0e={},qr={},ih={};Object.defineProperty(ih,"__esModule",{value:!0});ih.DefaultSerializer=ih.extendSerializer=void 0;function Cqe(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)}}}ih.extendSerializer=Cqe;const oge={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}}},rqe=e=>e&&typeof e=="object"&&"__error_marker"in e&&e.__error_marker==="$$error";ih.DefaultSerializer={deserialize(e){return rqe(e)?oge.deserialize(e):e},serialize(e){return e instanceof Error?oge.serialize(e):e}};Object.defineProperty(qr,"__esModule",{value:!0});qr.serialize=qr.deserialize=qr.registerSerializer=void 0;const a0e=ih;let PX=a0e.DefaultSerializer;function oqe(e){PX=a0e.extendSerializer(PX,e)}qr.registerSerializer=oqe;function aqe(e){return PX.deserialize(e)}qr.deserialize=aqe;function Aqe(e){return PX.serialize(e)}qr.serialize=Aqe;var A0e={},Vs={},bb={};Object.defineProperty(bb,"__esModule",{value:!0});bb.getBundleURL=bb.getBaseURL=void 0;let w5;function sqe(){return w5||(w5=lqe()),w5}bb.getBundleURL=sqe;function lqe(){try{throw new Error}catch(e){const g=(""+e.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(g)return s0e(g[0])}return"/"}function s0e(e){return(""+e).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}bb.getBaseURL=s0e;Object.defineProperty(Vs,"__esModule",{value:!0});Vs.isWorkerRuntime=Vs.getWorkerImplementation=Vs.defaultPoolSize=void 0;const age=bb;Vs.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const Age=e=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(e);function sge(e){const g=new Blob([e],{type:"application/javascript"});return URL.createObjectURL(g)}function cqe(){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"&&!Age(i)&&age.getBundleURL().match(/^file:\/\//i)&&(i=new URL(i,age.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((C=n==null?void 0:n.CORSWorkaround)!==null&&C!==void 0)||C)&&(i=sge(`importScripts(${JSON.stringify(i)});`))),typeof i=="string"&&Age(i)&&(!((r=n==null?void 0:n.CORSWorkaround)!==null&&r!==void 0)||r)&&(i=sge(`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 V5;function uqe(){return V5||(V5=cqe()),V5}Vs.getWorkerImplementation=uqe;function dqe(){const e=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!e)}Vs.isWorkerRuntime=dqe;var l0e={},S3={exports:{}},R5,lge;function hqe(){if(lge)return R5;lge=1;var e=1e3,g=e*60,I=g*60,i=I*24,n=i*7,C=i*365.25;R5=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 R5}function mqe(e){I.debug=I,I.default=I,I.coerce=a,I.disable=C,I.enable=n,I.enabled=r,I.humanize=hqe(),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=fqe(g);const{formatters:o}=e.exports;o.j=function(a){try{return JSON.stringify(a)}catch(s){return"[UnexpectedJSONParseError]: "+s.message}}})(S3,S3.exports);var h7=S3.exports,pqe=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 DT{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(()=>pqe(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 c0e=()=>typeof Symbol=="function",XS=e=>c0e()&&!!Symbol[e],m7=e=>XS(e)?Symbol[e]:"@@"+e;XS("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const bqe=m7("iterator"),w3=m7("observable"),u0e=m7("species");function JX(e,g){const I=e[g];if(I!=null){if(typeof I!="function")throw new TypeError(I+" is not a function");return I}}function Py(e){let g=e.constructor;return g!==void 0&&(g=g[u0e],g===null&&(g=void 0)),g!==void 0?g:nh}function yqe(e){return e instanceof nh}function yb(e){yb.log?yb.log(e):setTimeout(()=>{throw e},0)}function Y1(e){Promise.resolve().then(()=>{try{e()}catch(g){yb(g)}})}function d0e(e){const g=e._cleanup;if(g!==void 0&&(e._cleanup=void 0,!!g))try{if(typeof g=="function")g();else{const I=JX(g,"unsubscribe");I&&I.call(g)}}catch(I){yb(I)}}function V3(e){e._observer=void 0,e._queue=void 0,e._state="closed"}function Zqe(e){const g=e._queue;if(g){e._queue=void 0,e._state="ready";for(const I of g)if(h0e(e,I.type,I.value),e._state==="closed")break}}function h0e(e,g,I){e._state="running";const i=e._observer;try{const n=i?JX(i,g):void 0;switch(g){case"next":n&&n.call(i,I);break;case"error":if(V3(e),n)n.call(i,I);else throw I;break;case"complete":V3(e),n&&n.call(i);break}}catch(n){yb(n)}e._state==="closed"?d0e(e):e._state==="running"&&(e._state="ready")}function W5(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}],Y1(()=>Zqe(e));return}h0e(e,g,I)}}let Gqe=class{constructor(g,I){this._cleanup=void 0,this._observer=g,this._queue=void 0,this._state="initializing";const i=new vqe(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"&&(V3(this),d0e(this))}};class vqe{constructor(g){this._subscription=g}get closed(){return this._subscription._state==="closed"}next(g){W5(this._subscription,"next",g)}error(g){W5(this._subscription,"error",g)}complete(){W5(this._subscription,"complete")}}let nh=class DZ{constructor(g){if(!(this instanceof DZ))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 Gqe(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 DZ(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=Py(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=Py(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=Py(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=Py(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=Py(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()}})}[w3](){return this}static from(g){const I=typeof this=="function"?this:DZ;if(g==null)throw new TypeError(g+" is not an object");const i=JX(g,w3);if(i){const n=i.call(g);if(Object(n)!==n)throw new TypeError(n+" is not an object");return yqe(n)&&n.constructor===I?n:new I(C=>n.subscribe(C))}if(XS("iterator")){const n=JX(g,bqe);if(n)return new I(C=>{Y1(()=>{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=>{Y1(()=>{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:DZ;return new I(i=>{Y1(()=>{if(!i.closed){for(const n of g)if(i.next(n),i.closed)return;i.complete()}})})}static get[u0e](){return this}};c0e()&&Object.defineProperty(nh,Symbol("extensions"),{value:{symbol:w3,hostReportError:yb},configurable:!0});const jh=nh;function $h(e){typeof e=="function"?e():e&&typeof e.unsubscribe=="function"&&e.unsubscribe()}var Bqe=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 Sqe(e){return g=>new jh(I=>{const i=new DT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>Bqe(this,void 0,void 0,function*(){(yield e(C))&&r(C)}))}});return()=>$h(n)})}function wqe(e){return e&&XS("asyncIterator")&&e[Symbol.asyncIterator]}function Vqe(e){return e&&XS("iterator")&&e[Symbol.iterator]}var Rqe=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())})},Wqe=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 Xqe(e){return g=>new jh(I=>{const i=new DT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>Rqe(this,void 0,void 0,function*(){var o,a;const s=yield e(C);if(Vqe(s)||wqe(s))try{for(var A=Wqe(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()=>$h(n)})}function Hqe(e){return new nh(g=>{let I=0;const i=setInterval(()=>{g.next(I++)},e);return()=>clearInterval(i)})}var Tqe=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 Nqe(e){return g=>new jh(I=>{const i=new DT(I),n=g.subscribe({complete(){i.complete()},error(C){i.error(C)},next(C){i.schedule(r=>Tqe(this,void 0,void 0,function*(){const o=yield e(C);r(o)}))}});return()=>$h(n)})}function kqe(...e){return e.length===0?nh.from([]):new nh(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=>$h(C))};return n})}class Yqe extends jh{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 m0e=Yqe;function Kqe(e){const g=new m0e;let I,i=0;return new jh(n=>{I||(I=e.subscribe(g));const C=g.subscribe(n);return i++,()=>{i--,C.unsubscribe(),i===0&&($h(I),I=void 0)}})}var xqe=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 Dqe(e,g){return I=>new jh(i=>{let n,C=0;const r=new DT(i),o=I.subscribe({complete(){r.complete()},error(a){r.error(a)},next(a){r.schedule(s=>xqe(this,void 0,void 0,function*(){n=yield e(C===0?typeof g>"u"?a:g:n,a,C++),s(n)}))}});return()=>$h(o)})}const Fqe=Object.freeze(Object.defineProperty({__proto__:null,Observable:jh,Subject:m0e,filter:Sqe,flatMap:Xqe,interval:Hqe,map:Nqe,merge:kqe,multicast:Kqe,scan:Dqe,unsubscribe:$h},Symbol.toStringTag,{value:"Module"})),FT=P_(Fqe);var ET={};Object.defineProperty(ET,"__esModule",{value:!0});ET.allSettled=void 0;function Eqe(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)}}))}ET.allSettled=Eqe;var f0e={};(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={}))})(f0e);var HS={},NC={};Object.defineProperty(NC,"__esModule",{value:!0});NC.$worker=NC.$transferable=NC.$terminate=NC.$events=NC.$errors=void 0;NC.$errors=Symbol("thread.errors");NC.$events=Symbol("thread.events");NC.$terminate=Symbol("thread.terminate");NC.$transferable=Symbol("thread.transferable");NC.$worker=Symbol("thread.worker");Object.defineProperty(HS,"__esModule",{value:!0});HS.Thread=void 0;const X5=NC;function cge(e){throw Error(e)}HS.Thread={errors(e){return e[X5.$errors]||cge("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(e){return e[X5.$events]||cge("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(e){return e[X5.$terminate]()}};(function(e){var g=yI&&yI.__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=yI&&yI.__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(h7),n=FT,C=ET,r=Vs,o=f0e;Object.defineProperty(e,"PoolEventType",{enumerable:!0,get:function(){return o.PoolEventType}});const a=HS;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})(l0e);var MT={},zT={};Object.defineProperty(zT,"__esModule",{value:!0});zT.createPromiseWithResolver=void 0;const Mqe=()=>{};function zqe(){let e=!1,g,I=Mqe;return[new Promise(C=>{e?C(g):I=C}),C=>{e=!0,g=C,I(g)}]}zT.createPromiseWithResolver=zqe;var p0e={};(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={}))})(p0e);var Zb={},PT={};Object.defineProperty(PT,"__esModule",{value:!0});PT.ObservablePromise=void 0;const Pqe=FT,Jqe=()=>{},Oqe=e=>e,uge=e=>Promise.resolve().then(e);function _qe(e){throw e}function Lqe(e){return e&&typeof e.then=="function"}class f7 extends Pqe.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)uge(()=>I(g))}onCompletion(){this.state="fulfilled";for(const g of this.fulfillmentCallbacks)uge(()=>g(this.firstValue))}then(g,I){const i=g||Oqe,n=I||_qe;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||Jqe;return this.then(i=>(I(),i),()=>I())}static from(g){return Lqe(g)?new f7(I=>{const i=C=>{I.next(C),I.complete()},n=C=>{I.error(C)};g.then(i,n)}):super.from(g)}}PT.ObservablePromise=f7;var Ds={};Object.defineProperty(Ds,"__esModule",{value:!0});Ds.Transfer=Ds.isTransferDescriptor=void 0;const b0e=NC;function Uqe(e){return!(!e||typeof e!="object")}function Qqe(e){return e&&typeof e=="object"&&e[b0e.$transferable]}Ds.isTransferDescriptor=Qqe;function jqe(e,g){if(!g){if(!Uqe(e))throw Error();g=[e]}return{[b0e.$transferable]:!0,send:e,transferables:g}}Ds.Transfer=jqe;var p7={};(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={}))})(p7);var $qe=yI&&yI.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Zb,"__esModule",{value:!0});Zb.createProxyModule=Zb.createProxyFunction=void 0;const qqe=$qe(h7),y0e=FT,MG=qr,dge=PT,eet=Ds,TS=p7,Z0e=qqe.default("threads:master:messages");let tet=1;const get=e=>Array.from(new Set(e)),Iet=e=>e&&e.type===TS.WorkerMessageType.error,iet=e=>e&&e.type===TS.WorkerMessageType.result,net=e=>e&&e.type===TS.WorkerMessageType.running;function Cet(e,g){return new y0e.Observable(I=>{let i;const n=C=>{if(Z0e("Message from worker:",C.data),!(!C.data||C.data.uid!==g)){if(net(C.data))i=C.data.resultType;else if(iet(C.data))i==="promise"?(typeof C.data.payload<"u"&&I.next(MG.deserialize(C.data.payload)),I.complete(),e.removeEventListener("message",n)):(C.data.payload&&I.next(MG.deserialize(C.data.payload)),C.data.complete&&(I.complete(),e.removeEventListener("message",n)));else if(Iet(C.data)){const r=MG.deserialize(C.data.error);I.error(r),e.removeEventListener("message",n)}}};return e.addEventListener("message",n),()=>{if(i==="observable"||!i){const C={type:TS.MasterMessageType.cancel,uid:g};e.postMessage(C)}e.removeEventListener("message",n)}})}function ret(e){if(e.length===0)return{args:[],transferables:[]};const g=[],I=[];for(const i of e)eet.isTransferDescriptor(i)?(g.push(MG.serialize(i.send)),I.push(...i.transferables)):g.push(MG.serialize(i));return{args:g,transferables:I.length===0?I:get(I)}}function G0e(e,g){return(...I)=>{const i=tet++,{args:n,transferables:C}=ret(I),r={type:TS.MasterMessageType.run,uid:i,method:g,args:n};Z0e("Sending command to run function to worker:",r);try{e.postMessage(r,C)}catch(o){return dge.ObservablePromise.from(Promise.reject(o))}return dge.ObservablePromise.from(y0e.multicast(Cet(e,i)))}}Zb.createProxyFunction=G0e;function oet(e,g){const I={};for(const i of g)I[i]=G0e(e,i);return I}Zb.createProxyModule=oet;var b7=yI&&yI.__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())})},aet=yI&&yI.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(MT,"__esModule",{value:!0});MT.spawn=void 0;const y7=aet(h7),Aet=FT,set=qr,cet=zT,qV=NC,K1=p0e,hge=Zb,uet=y7.default("threads:master:messages"),det=y7.default("threads:master:spawn"),v0e=y7.default("threads:master:thread-utils"),het=e=>e&&e.type==="init",met=e=>e&&e.type==="uncaughtError",fet=typeof process<"u"&&{}.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt({}.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function pet(e,g,I){return b7(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 bet(e){return new Promise((g,I)=>{const i=n=>{uet("Message from worker before finishing initialization:",n.data),het(n.data)?(e.removeEventListener("message",i),g(n.data)):met(n.data)&&(e.removeEventListener("message",i),I(set.deserialize(n.data.error)))};e.addEventListener("message",i)})}function yet(e,g){return new Aet.Observable(I=>{const i=C=>{const r={type:K1.WorkerEventType.message,data:C.data};I.next(r)},n=C=>{v0e("Unhandled promise rejection event in thread:",C);const r={type:K1.WorkerEventType.internalError,error:Error(C.reason)};I.next(r)};e.addEventListener("message",i),e.addEventListener("unhandledrejection",n),g.then(()=>{const C={type:K1.WorkerEventType.termination};e.removeEventListener("message",i),e.removeEventListener("unhandledrejection",n),I.next(C),I.complete()})})}function Zet(e){const[g,I]=cet.createPromiseWithResolver();return{terminate:()=>b7(this,void 0,void 0,function*(){v0e("Terminating worker"),yield e.terminate(),I()}),termination:g}}function mge(e,g,I,i){const n=I.filter(C=>C.type===K1.WorkerEventType.internalError).map(C=>C.error);return Object.assign(e,{[qV.$errors]:n,[qV.$events]:I,[qV.$terminate]:i,[qV.$worker]:g})}function Get(e,g){return b7(this,void 0,void 0,function*(){det("Initializing new thread");const I=g&&g.timeout?g.timeout:fet,n=(yield pet(bet(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}=Zet(e),o=yet(e,C);if(n.type==="function"){const a=hge.createProxyFunction(e);return mge(a,e,o,r)}else if(n.type==="module"){const a=hge.createProxyModule(e,n.methods);return mge(a,e,o,r)}else{const a=n.type;throw Error(`Worker init message states unexpected type of expose(): ${a}`)}})}MT.spawn=Get;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Worker=e.BlobWorker=e.isWorkerRuntime=e.Thread=e.spawn=e.Pool=void 0;const g=Vs;Object.defineProperty(e,"isWorkerRuntime",{enumerable:!0,get:function(){return g.isWorkerRuntime}});var I=l0e;Object.defineProperty(e,"Pool",{enumerable:!0,get:function(){return I.Pool}});var i=MT;Object.defineProperty(e,"spawn",{enumerable:!0,get:function(){return i.spawn}});var n=HS;Object.defineProperty(e,"Thread",{enumerable:!0,get:function(){return n.Thread}}),e.BlobWorker=g.getWorkerImplementation().blob,e.Worker=g.getWorkerImplementation().default})(A0e);var B0e={},vet=e=>e?typeof Symbol.observable=="symbol"&&typeof e[Symbol.observable]=="function"?e===e[Symbol.observable]():typeof e["@@observable"]=="function"?e===e["@@observable"]():!1:!1,Z7={};Object.defineProperty(Z7,"__esModule",{value:!0});const Bet=function(){const g=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!g)},wet=function(g,I){self.postMessage(g,I)},Vet=function(g){const I=n=>{g(n.data)},i=()=>{self.removeEventListener("message",I)};return self.addEventListener("message",I),i};Z7.default={isWorkerRuntime:Bet,postMessageToMaster:wet,subscribeToMasterMessages:Vet};(function(e){var g=yI&&yI.__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(J){try{F(X.next(J))}catch(P){H(P)}}function K(J){try{F(X.throw(J))}catch(P){H(P)}}function F(J){J.done?R(J.value):W(J.value).then(Y,K)}F((X=X.apply(w,V||[])).next())})},I=yI&&yI.__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(vet),n=qr,C=Ds,r=p7,o=I(Z7);var a=qr;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return a.registerSerializer}});var s=Ds;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)}))})(B0e);(function(e){var g=yI&&yI.__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=yI&&yI.__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=qr;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return i.registerSerializer}}),I(A0e,e);var n=B0e;Object.defineProperty(e,"expose",{enumerable:!0,get:function(){return n.expose}});var C=ih;Object.defineProperty(e,"DefaultSerializer",{enumerable:!0,get:function(){return C.DefaultSerializer}});var r=Ds;Object.defineProperty(e,"Transfer",{enumerable:!0,get:function(){return r.Transfer}})})(o0e);const iu=jc(o0e);iu.registerSerializer;const JT=iu.spawn;iu.BlobWorker;iu.DefaultSerializer;iu.Pool;iu.Thread;iu.Transfer;iu.Worker;class Ret 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 fge={},H5={},T5=34,Jy=10,N5=13;function S0e(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function Wet(e,g){var I=S0e(e);return function(i,n){return g(I(i),n,e)}}function pge(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 Het(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":Xet(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 Tet(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?Wet(m,c):S0e(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)===Jy&&--d,l.charCodeAt(d-1)===N5&&--d;function y(){if(b)return H5;if(p)return p=!1,fge;var B,G=h,v;if(l.charCodeAt(G)===T5){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===Jy?p=!0:v===N5&&(p=!0,l.charCodeAt(h)===Jy&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;hn)throw new RangeError('The value "'+F+'" is invalid for option "size"');const T=new Uint8Array(F);return Object.setPrototypeOf(T,o.prototype),T}function o(F,T,k){if(typeof F=="number"){if(typeof T=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return l(F)}return a(F,T,k)}o.poolSize=8192;function a(F,T,k){if(typeof F=="string")return c(F,T);if(ArrayBuffer.isView(F))return d(F);if(F==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof F);if(tt(F,ArrayBuffer)||F&&tt(F.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(tt(F,SharedArrayBuffer)||F&&tt(F.buffer,SharedArrayBuffer)))return h(F,T,k);if(typeof F=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const ie=F.valueOf&&F.valueOf();if(ie!=null&&ie!==F)return o.from(ie,T,k);const me=m(F);if(me)return me;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof F[Symbol.toPrimitive]=="function")return o.from(F[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 F)}o.from=function(F,T,k){return a(F,T,k)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array);function s(F){if(typeof F!="number")throw new TypeError('"size" argument must be of type number');if(F<0)throw new RangeError('The value "'+F+'" is invalid for option "size"')}function A(F,T,k){return s(F),F<=0?C(F):T!==void 0?typeof k=="string"?C(F).fill(T,k):C(F).fill(T):C(F)}o.alloc=function(F,T,k){return A(F,T,k)};function l(F){return s(F),C(F<0?0:f(F)|0)}o.allocUnsafe=function(F){return l(F)},o.allocUnsafeSlow=function(F){return l(F)};function c(F,T){if((typeof T!="string"||T==="")&&(T="utf8"),!o.isEncoding(T))throw new TypeError("Unknown encoding: "+T);const k=p(F,T)|0;let ie=C(k);const me=ie.write(F,T);return me!==k&&(ie=ie.slice(0,me)),ie}function u(F){const T=F.length<0?0:f(F.length)|0,k=C(T);for(let ie=0;ie=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return F|0}function b(F){return+F!=F&&(F=0),o.alloc(+F)}o.isBuffer=function(T){return T!=null&&T._isBuffer===!0&&T!==o.prototype},o.compare=function(T,k){if(tt(T,Uint8Array)&&(T=o.from(T,T.offset,T.byteLength)),tt(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 ie=T.length,me=k.length;for(let Ve=0,we=Math.min(ie,me);Veme.length?(o.isBuffer(we)||(we=o.from(we)),we.copy(me,Ve)):Uint8Array.prototype.set.call(me,we,Ve);else if(o.isBuffer(we))we.copy(me,Ve);else throw new TypeError('"list" argument must be an Array of Buffers');Ve+=we.length}return me};function p(F,T){if(o.isBuffer(F))return F.length;if(ArrayBuffer.isView(F)||tt(F,ArrayBuffer))return F.byteLength;if(typeof F!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof F);const k=F.length,ie=arguments.length>2&&arguments[2]===!0;if(!ie&&k===0)return 0;let me=!1;for(;;)switch(T){case"ascii":case"latin1":case"binary":return k;case"utf8":case"utf-8":return De(F).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k*2;case"hex":return k>>>1;case"base64":return gt(F).length;default:if(me)return ie?-1:De(F).length;T=(""+T).toLowerCase(),me=!0}}o.byteLength=p;function y(F,T,k){let ie=!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(F||(F="utf8");;)switch(F){case"hex":return J(this,T,k);case"utf8":case"utf-8":return V(this,T,k);case"ascii":return K(this,T,k);case"latin1":case"binary":return x(this,T,k);case"base64":return W(this,T,k);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return P(this,T,k);default:if(ie)throw new TypeError("Unknown encoding: "+F);F=(F+"").toLowerCase(),ie=!0}}o.prototype._isBuffer=!0;function Z(F,T,k){const ie=F[T];F[T]=F[k],F[k]=ie}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,ie,me,Ve){if(tt(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),ie===void 0&&(ie=T?T.length:0),me===void 0&&(me=0),Ve===void 0&&(Ve=this.length),k<0||ie>T.length||me<0||Ve>this.length)throw new RangeError("out of range index");if(me>=Ve&&k>=ie)return 0;if(me>=Ve)return-1;if(k>=ie)return 1;if(k>>>=0,ie>>>=0,me>>>=0,Ve>>>=0,this===T)return 0;let we=Ve-me,je=ie-k;const at=Math.min(we,je),bt=this.slice(me,Ve),ct=T.slice(k,ie);for(let Ht=0;Ht2147483647?k=2147483647:k<-2147483648&&(k=-2147483648),k=+k,Xe(k)&&(k=me?0:F.length-1),k<0&&(k=F.length+k),k>=F.length){if(me)return-1;k=F.length-1}else if(k<0)if(me)k=0;else return-1;if(typeof T=="string"&&(T=o.from(T,ie)),o.isBuffer(T))return T.length===0?-1:G(F,T,k,ie,me);if(typeof T=="number")return T=T&255,typeof Uint8Array.prototype.indexOf=="function"?me?Uint8Array.prototype.indexOf.call(F,T,k):Uint8Array.prototype.lastIndexOf.call(F,T,k):G(F,[T],k,ie,me);throw new TypeError("val must be string, number or Buffer")}function G(F,T,k,ie,me){let Ve=1,we=F.length,je=T.length;if(ie!==void 0&&(ie=String(ie).toLowerCase(),ie==="ucs2"||ie==="ucs-2"||ie==="utf16le"||ie==="utf-16le")){if(F.length<2||T.length<2)return-1;Ve=2,we/=2,je/=2,k/=2}function at(ct,Ht){return Ve===1?ct[Ht]:ct.readUInt16BE(Ht*Ve)}let bt;if(me){let ct=-1;for(bt=k;btwe&&(k=we-je),bt=k;bt>=0;bt--){let ct=!0;for(let Ht=0;Htme&&(ie=me)):ie=me;const Ve=T.length;ie>Ve/2&&(ie=Ve/2);let we;for(we=0;we>>0,isFinite(ie)?(ie=ie>>>0,me===void 0&&(me="utf8")):(me=ie,ie=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");const Ve=this.length-k;if((ie===void 0||ie>Ve)&&(ie=Ve),T.length>0&&(ie<0||k<0)||k>this.length)throw new RangeError("Attempt to write outside buffer bounds");me||(me="utf8");let we=!1;for(;;)switch(me){case"hex":return v(this,T,k,ie);case"utf8":case"utf-8":return w(this,T,k,ie);case"ascii":case"latin1":case"binary":return R(this,T,k,ie);case"base64":return S(this,T,k,ie);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return X(this,T,k,ie);default:if(we)throw new TypeError("Unknown encoding: "+me);me=(""+me).toLowerCase(),we=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function W(F,T,k){return T===0&&k===F.length?g.fromByteArray(F):g.fromByteArray(F.slice(T,k))}function V(F,T,k){k=Math.min(F.length,k);const ie=[];let me=T;for(;me239?4:Ve>223?3:Ve>191?2:1;if(me+je<=k){let at,bt,ct,Ht;switch(je){case 1:Ve<128&&(we=Ve);break;case 2:at=F[me+1],(at&192)===128&&(Ht=(Ve&31)<<6|at&63,Ht>127&&(we=Ht));break;case 3:at=F[me+1],bt=F[me+2],(at&192)===128&&(bt&192)===128&&(Ht=(Ve&15)<<12|(at&63)<<6|bt&63,Ht>2047&&(Ht<55296||Ht>57343)&&(we=Ht));break;case 4:at=F[me+1],bt=F[me+2],ct=F[me+3],(at&192)===128&&(bt&192)===128&&(ct&192)===128&&(Ht=(Ve&15)<<18|(at&63)<<12|(bt&63)<<6|ct&63,Ht>65535&&Ht<1114112&&(we=Ht))}}we===null?(we=65533,je=1):we>65535&&(we-=65536,ie.push(we>>>10&1023|55296),we=56320|we&1023),ie.push(we),me+=je}return Y(ie)}const H=4096;function Y(F){const T=F.length;if(T<=H)return String.fromCharCode.apply(String,F);let k="",ie=0;for(;ieie)&&(k=ie);let me="";for(let Ve=T;Veie&&(T=ie),k<0?(k+=ie,k<0&&(k=0)):k>ie&&(k=ie),kk)throw new RangeError("Trying to access beyond buffer length")}o.prototype.readUintLE=o.prototype.readUIntLE=function(T,k,ie){T=T>>>0,k=k>>>0,ie||ge(T,k,this.length);let me=this[T],Ve=1,we=0;for(;++we>>0,k=k>>>0,ie||ge(T,k,this.length);let me=this[T+--k],Ve=1;for(;k>0&&(Ve*=256);)me+=this[T+--k]*Ve;return me},o.prototype.readUint8=o.prototype.readUInt8=function(T,k){return T=T>>>0,k||ge(T,1,this.length),this[T]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(T,k){return T=T>>>0,k||ge(T,2,this.length),this[T]|this[T+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(T,k){return T=T>>>0,k||ge(T,2,this.length),this[T]<<8|this[T+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(T,k){return T=T>>>0,k||ge(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||ge(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,We(T,"offset");const k=this[T],ie=this[T+7];(k===void 0||ie===void 0)&&Be(T,this.length-8);const me=k+this[++T]*2**8+this[++T]*2**16+this[++T]*2**24,Ve=this[++T]+this[++T]*2**8+this[++T]*2**16+ie*2**24;return BigInt(me)+(BigInt(Ve)<>>0,We(T,"offset");const k=this[T],ie=this[T+7];(k===void 0||ie===void 0)&&Be(T,this.length-8);const me=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+ie;return(BigInt(me)<>>0,k=k>>>0,ie||ge(T,k,this.length);let me=this[T],Ve=1,we=0;for(;++we=Ve&&(me-=Math.pow(2,8*k)),me},o.prototype.readIntBE=function(T,k,ie){T=T>>>0,k=k>>>0,ie||ge(T,k,this.length);let me=k,Ve=1,we=this[T+--me];for(;me>0&&(Ve*=256);)we+=this[T+--me]*Ve;return Ve*=128,we>=Ve&&(we-=Math.pow(2,8*k)),we},o.prototype.readInt8=function(T,k){return T=T>>>0,k||ge(T,1,this.length),this[T]&128?(255-this[T]+1)*-1:this[T]},o.prototype.readInt16LE=function(T,k){T=T>>>0,k||ge(T,2,this.length);const ie=this[T]|this[T+1]<<8;return ie&32768?ie|4294901760:ie},o.prototype.readInt16BE=function(T,k){T=T>>>0,k||ge(T,2,this.length);const ie=this[T+1]|this[T]<<8;return ie&32768?ie|4294901760:ie},o.prototype.readInt32LE=function(T,k){return T=T>>>0,k||ge(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||ge(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,We(T,"offset");const k=this[T],ie=this[T+7];(k===void 0||ie===void 0)&&Be(T,this.length-8);const me=this[T+4]+this[T+5]*2**8+this[T+6]*2**16+(ie<<24);return(BigInt(me)<>>0,We(T,"offset");const k=this[T],ie=this[T+7];(k===void 0||ie===void 0)&&Be(T,this.length-8);const me=(k<<24)+this[++T]*2**16+this[++T]*2**8+this[++T];return(BigInt(me)<>>0,k||ge(T,4,this.length),i.read(this,T,!0,23,4)},o.prototype.readFloatBE=function(T,k){return T=T>>>0,k||ge(T,4,this.length),i.read(this,T,!1,23,4)},o.prototype.readDoubleLE=function(T,k){return T=T>>>0,k||ge(T,8,this.length),i.read(this,T,!0,52,8)},o.prototype.readDoubleBE=function(T,k){return T=T>>>0,k||ge(T,8,this.length),i.read(this,T,!1,52,8)};function q(F,T,k,ie,me,Ve){if(!o.isBuffer(F))throw new TypeError('"buffer" argument must be a Buffer instance');if(T>me||TF.length)throw new RangeError("Index out of range")}o.prototype.writeUintLE=o.prototype.writeUIntLE=function(T,k,ie,me){if(T=+T,k=k>>>0,ie=ie>>>0,!me){const je=Math.pow(2,8*ie)-1;q(this,T,k,ie,je,0)}let Ve=1,we=0;for(this[k]=T&255;++we>>0,ie=ie>>>0,!me){const je=Math.pow(2,8*ie)-1;q(this,T,k,ie,je,0)}let Ve=ie-1,we=1;for(this[k+Ve]=T&255;--Ve>=0&&(we*=256);)this[k+Ve]=T/we&255;return k+ie},o.prototype.writeUint8=o.prototype.writeUInt8=function(T,k,ie){return T=+T,k=k>>>0,ie||q(this,T,k,1,255,0),this[k]=T&255,k+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(T,k,ie){return T=+T,k=k>>>0,ie||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,ie){return T=+T,k=k>>>0,ie||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,ie){return T=+T,k=k>>>0,ie||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,ie){return T=+T,k=k>>>0,ie||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 $(F,T,k,ie,me){ve(T,ie,me,F,k,7);let Ve=Number(T&BigInt(4294967295));F[k++]=Ve,Ve=Ve>>8,F[k++]=Ve,Ve=Ve>>8,F[k++]=Ve,Ve=Ve>>8,F[k++]=Ve;let we=Number(T>>BigInt(32)&BigInt(4294967295));return F[k++]=we,we=we>>8,F[k++]=we,we=we>>8,F[k++]=we,we=we>>8,F[k++]=we,k}function j(F,T,k,ie,me){ve(T,ie,me,F,k,7);let Ve=Number(T&BigInt(4294967295));F[k+7]=Ve,Ve=Ve>>8,F[k+6]=Ve,Ve=Ve>>8,F[k+5]=Ve,Ve=Ve>>8,F[k+4]=Ve;let we=Number(T>>BigInt(32)&BigInt(4294967295));return F[k+3]=we,we=we>>8,F[k+2]=we,we=we>>8,F[k+1]=we,we=we>>8,F[k]=we,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,ie,me){if(T=+T,k=k>>>0,!me){const at=Math.pow(2,8*ie-1);q(this,T,k,ie,at-1,-at)}let Ve=0,we=1,je=0;for(this[k]=T&255;++Ve>0)-je&255;return k+ie},o.prototype.writeIntBE=function(T,k,ie,me){if(T=+T,k=k>>>0,!me){const at=Math.pow(2,8*ie-1);q(this,T,k,ie,at-1,-at)}let Ve=ie-1,we=1,je=0;for(this[k+Ve]=T&255;--Ve>=0&&(we*=256);)T<0&&je===0&&this[k+Ve+1]!==0&&(je=1),this[k+Ve]=(T/we>>0)-je&255;return k+ie},o.prototype.writeInt8=function(T,k,ie){return T=+T,k=k>>>0,ie||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,ie){return T=+T,k=k>>>0,ie||q(this,T,k,2,32767,-32768),this[k]=T&255,this[k+1]=T>>>8,k+2},o.prototype.writeInt16BE=function(T,k,ie){return T=+T,k=k>>>0,ie||q(this,T,k,2,32767,-32768),this[k]=T>>>8,this[k+1]=T&255,k+2},o.prototype.writeInt32LE=function(T,k,ie){return T=+T,k=k>>>0,ie||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,ie){return T=+T,k=k>>>0,ie||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(F,T,k,ie,me,Ve){if(k+ie>F.length)throw new RangeError("Index out of range");if(k<0)throw new RangeError("Index out of range")}function Q(F,T,k,ie,me){return T=+T,k=k>>>0,me||te(F,T,k,4),i.write(F,T,k,ie,23,4),k+4}o.prototype.writeFloatLE=function(T,k,ie){return Q(this,T,k,!0,ie)},o.prototype.writeFloatBE=function(T,k,ie){return Q(this,T,k,!1,ie)};function Ie(F,T,k,ie,me){return T=+T,k=k>>>0,me||te(F,T,k,8),i.write(F,T,k,ie,52,8),k+8}o.prototype.writeDoubleLE=function(T,k,ie){return Ie(this,T,k,!0,ie)},o.prototype.writeDoubleBE=function(T,k,ie){return Ie(this,T,k,!1,ie)},o.prototype.copy=function(T,k,ie,me){if(!o.isBuffer(T))throw new TypeError("argument should be a Buffer");if(ie||(ie=0),!me&&me!==0&&(me=this.length),k>=T.length&&(k=T.length),k||(k=0),me>0&&me=this.length)throw new RangeError("Index out of range");if(me<0)throw new RangeError("sourceEnd out of bounds");me>this.length&&(me=this.length),T.length-k>>0,ie=ie===void 0?this.length:ie>>>0,T||(T=0);let Ve;if(typeof T=="number")for(Ve=k;Ve2**32?me=be(String(k)):typeof k=="bigint"&&(me=String(k),(k>BigInt(2)**BigInt(32)||k<-(BigInt(2)**BigInt(32)))&&(me=be(me)),me+="n"),ie+=` It must be ${T}. Received ${me}`,ie},RangeError);function be(F){let T="",k=F.length;const ie=F[0]==="-"?1:0;for(;k>=ie+4;k-=3)T=`_${F.slice(k-3,k)}${T}`;return`${F.slice(0,k)}${T}`}function pe(F,T,k){We(T,"offset"),(F[T]===void 0||F[T+k]===void 0)&&Be(T,F.length-(k+1))}function ve(F,T,k,ie,me,Ve){if(F>k||F3?T===0||T===BigInt(0)?je=`>= 0${we} and < 2${we} ** ${(Ve+1)*8}${we}`:je=`>= -(2${we} ** ${(Ve+1)*8-1}${we}) and < 2 ** ${(Ve+1)*8-1}${we}`:je=`>= ${T}${we} and <= ${k}${we}`,new he.ERR_OUT_OF_RANGE("value",je,F)}pe(ie,me,Ve)}function We(F,T){if(typeof F!="number")throw new he.ERR_INVALID_ARG_TYPE(T,"number",F)}function Be(F,T,k){throw Math.floor(F)!==F?(We(F,k),new he.ERR_OUT_OF_RANGE(k||"offset","an integer",F)):T<0?new he.ERR_BUFFER_OUT_OF_BOUNDS:new he.ERR_OUT_OF_RANGE(k||"offset",`>= ${k?1:0} and <= ${T}`,F)}const Je=/[^+/0-9A-Za-z-_]/g;function Pe(F){if(F=F.split("=")[0],F=F.trim().replace(Je,""),F.length<2)return"";for(;F.length%4!==0;)F=F+"=";return F}function De(F,T){T=T||1/0;let k;const ie=F.length;let me=null;const Ve=[];for(let we=0;we55295&&k<57344){if(!me){if(k>56319){(T-=3)>-1&&Ve.push(239,191,189);continue}else if(we+1===ie){(T-=3)>-1&&Ve.push(239,191,189);continue}me=k;continue}if(k<56320){(T-=3)>-1&&Ve.push(239,191,189),me=k;continue}k=(me-55296<<10|k-56320)+65536}else me&&(T-=3)>-1&&Ve.push(239,191,189);if(me=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 Qe(F){const T=[];for(let k=0;k>8,me=k%256,Ve.push(me),Ve.push(ie);return Ve}function gt(F){return g.toByteArray(Pe(F))}function lt(F,T,k,ie){let me;for(me=0;me=T.length||me>=F.length);++me)T[me+k]=F[me];return me}function tt(F,T){return F instanceof T||F!=null&&F.constructor!=null&&F.constructor.name!=null&&F.constructor.name===T.name}function Xe(F){return F!==F}const ae=function(){const F="0123456789abcdef",T=new Array(256);for(let k=0;k<16;++k){const ie=k*16;for(let me=0;me<16;++me)T[ie+me]=F[k]+F[me]}return T}();function ye(F){return typeof BigInt>"u"?He:F}function He(){throw new Error("BigInt not supported")}})(th);let ybe=class{async getBufferFromResponse(g){if(typeof g.buffer=="function")return g.buffer();if(typeof g.arrayBuffer=="function"){const i=await g.arrayBuffer();return th.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,r={}){const{headers:C={},signal:o,overrides:a={}}=r;I<1/0?C.range=`bytes=${n}-${n+I}`:I===1/0&&n!==0&&(C.range=`bytes=${n}-`);const s={...this.baseOverrides,...a,headers:{...C,...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:r,overrides:C={}}=I,o={headers:n,method:"GET",redirect:"follow",mode:"cors",signal:r,...this.baseOverrides,...C},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=th.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 k4e=Object.defineProperty,Y4e=(e,g,i)=>g in e?k4e(e,g,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[g]=i,K4e=(e,g,i)=>(Y4e(e,typeof g!="symbol"?g+"":g,i),i);const Y9=6,F4e=130,D4e=600,Dte=600,Y1=10,Zbe=.3,x4e=0,E4e="gray",pt=e=>{let g=$d(e);return g||(g=$d(E4e)),xme([g.rgb().r/255,g.rgb().g/255,g.rgb().b/255])},gn=0;function jg(e,g,i,I,n){const r=Math.max(Math.min(g,e),0),C=n??gn,o=(I-i)/360*Math.PI*2-C*2;return-(i/360*Math.PI*2+r/g*o)-Math.PI/2-C}function Mt(e,g,i,I,n,r,C){return{x:I+i*Math.cos(jg(e,g,r,C)),y:n+i*Math.sin(jg(e,g,r,C))}}function lc(e,g,i,I){return i<=e?Math.atan((g-I)/(e-i)):Math.atan((g-I)/(e-i))-Math.PI}function M4e(e,g,i,I){return(Math.atan2(-(g-I),e-i)/Math.PI*180+270)%360}function z4e(e,g,i){var I,n,r,C,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=(r=a.startAngle)!=null?r:0,f=(C=a.endAngle)!=null?C: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=>!pi(w,a.row)||pi(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),Y=i.encodedPIXIProperty("opacity",w),K=i.markVisibility(w,{width:W,zoomLevel:c}),x=Math.min(K,Y);if(!(W<=.1||x===0||R+W<0||R-W>A))if(g.lineStyle(V,pt(H),x,1),u){const J=h-(v+B-S)/l*b,P=Mt(R,A,J,p,y,m,f);g.beginFill(pt(X),x),g.drawCircle(P.x,P.y,W),i.getMouseEventModel().addPointBasedEvent(w,[P.x,P.y,W])}else g.beginFill(pt(X),x),g.drawCircle(R,v+B-S,W),i.getMouseEventModel().addPointBasedEvent(w,[R,v+B-S,W])})})}function P4e(e,g,i){const I=e.visualPropertyByChannel("xe",i),n=e.visualPropertyByChannel("x",i),r=e.visualPropertyByChannel("size",i);switch(g){case"x-center":return I?(I+n)/2:n;case"y-center":{const C=e.visualPropertyByChannel("ye",i),o=e.visualPropertyByChannel("y",i);return C?(C+o)/2:o}case"p-size":return I&&e.spec().stretch?(I-n)/2:r;default:return}}function J4e(e,g,i,I){var n,r,C,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=(r=A.outerRadius)!=null?r:300,h=(C=A.startAngle)!=null?C: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(R=>(!pi(R,A.row)||pi(R,A.row)===G)&&(!pi(R,A.color)||pi(R,A.color)===w)).sort((R,S)=>pi(R,A.x)-pi(S,A.x)).forEach((R,S)=>{const X=g.encodedPIXIProperty("x",R),W=g.encodedPIXIProperty("y",R),V=g.encodedPIXIProperty("size",R),H=g.encodedPIXIProperty("color",R),Y=g.encodedPIXIProperty("opacity",R);if(e.lineStyle(V,pt(H),Y,.5),c){const K=d-(v+Z-W)/I*f,x=Mt(X,i,K,b,p,h,m);S===0?e.moveTo(x.x,x.y):e.lineTo(x.x,x.y),g.getMouseEventModel().addPointBasedEvent(R,[x.x,x.y,1])}else S===0?e.moveTo(X,v+Z-W):e.lineTo(X,v+Z-W),g.getMouseEventModel().addPointBasedEvent(R,[X,v+Z-W,1])})})})}function O4e(e,g,i){var I,n,r,C,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=(r=A.startAngle)!=null?r:0,y=(C=A.endAngle)!=null?C:360,Z=b-f,B=c/2,G=u/2,v=i.getChannelScale("x");let w;if(g.tileData.tilePos){const{tileX:Y,tileWidth:K}=e.getTilePosAndDimensions(g.tileData.zoomLevel,g.tileData.tilePos,d);w=v(Y+K/d)-v(Y)}const R=(o=i.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],S=u/R.length,X=!ut(A.row)||ut(A.row)&&typeof A.row.clip>"u"||A.row.clip,W=ut(A.y)?(a=A.y)==null?void 0:a.baseline:void 0,V=(s=i.encodedValue("y",W))!=null?s:0,H=g.graphics;if(YT(A)){const Y=i.getGenomicChannel();if(!Y||!Y.field){console.warn("Genomic field is not provided in the specification");return}const K=vT(l,J=>J[Y.field]);[...K.keys()].forEach(J=>{var P;let ge=0;(P=K.get(J))==null||P.forEach(q=>{const $=i.encodedPIXIProperty("color",q),j=i.encodedPIXIProperty("stroke",q),te=i.encodedPIXIProperty("strokeWidth",q),Q=i.encodedPIXIProperty("opacity",q),Ie=i.encodedPIXIProperty("y",q),he=i.encodedPIXIProperty("width",q,{tileUnitWidth:w}),ne=i.encodedPIXIProperty("x-start",q,{markWidth:he}),be=ne+he,pe=i.markVisibility(q,{width:he,zoomLevel:h}),ve=Math.min(pe,Q);if(ve===0||he<=0||Ie<=0)return;H.lineStyle(te,pt(j),ve,0);let We=[];if(m){const Be=b-(S-ge)/u*Z,Je=b-(S-Ie-ge)/u*Z,Pe=Mt(ne,c,Je,B,G,p,y),De=jg(ne,c,p,y),Qe=jg(ne+he,c,p,y);H.beginFill(pt($),$==="none"?0:ve),H.moveTo(Pe.x,Pe.y),H.arc(B,G,Je,De,Qe,!0),H.arc(B,G,Be,Qe,De,!1),We=Array.from(H.currentPath.points),H.closePath()}else{H.beginFill(pt($),$==="none"?0:ve),H.drawRect(ne,S-Ie-ge,he,Ie);const Be=S-Ie-ge,Je=Be+Ie;We=[ne,Be,ne,Je,be,Je,be,Be]}i.getMouseEventModel().addPolygonBasedEvent(q,We),ge+=Ie})})}else R.forEach(Y=>{const K=i.encodedValue("row",Y);l.filter(x=>{const J=pi(x,A.row);return!J||J===Y}).forEach(x=>{const J=i.encodedPIXIProperty("color",x),P=i.encodedPIXIProperty("stroke",x),ge=i.encodedPIXIProperty("strokeWidth",x),q=i.encodedPIXIProperty("opacity");let $=i.encodedPIXIProperty("y",x),j=i.encodedPIXIProperty("ye",x);typeof j<"u"&&$>j&&([$,j]=[j,$]);const te=i.encodedPIXIProperty("width",x,{tileUnitWidth:w}),Q=i.encodedPIXIProperty("x-start",x,{markWidth:te}),Ie=Q+te;let he;typeof j>"u"?(he=K+S-V-$,j=K+S-V,(ut(A.y)&&A.y.flip||A.flipY)&&(j=he,he=K)):(he=K+S-j,j=K+S-$),X&&(he=Math.max(K,he),he=Math.min(he,K+S),j=Math.max(K,j),j=Math.min(j,K+S));const ne=i.markVisibility(x,{width:te,zoomLevel:h}),be=Math.min(ne,q);if(be===0||te===0||j-he===0)return;H.lineStyle(ge,pt(P),be,0);let pe=[];if(m){const ve=b-he/u*Z,We=b-j/u*Z,Be=Mt(Q,c,We,B,G,p,y),Je=jg(Q,c,p,y),Pe=jg(Q+te,c,p,y);H.beginFill(pt(J),J==="none"?0:be),H.moveTo(Be.x,Be.y),H.arc(B,G,We,Je,Pe,!0),H.arc(B,G,ve,Pe,Je,!1),pe=Array.from(H.currentPath.points),H.closePath()}else H.beginFill(pt(J),J==="none"?0:be),H.drawRect(Q,he,te,j-he),pe=[Q,he,Q,j,Ie,j,Ie,he];i.getMouseEventModel().addPolygonBasedEvent(x,pe)})})}function _4e(e,g,i,I){const n=e.visualPropertyByChannel("x",i),r=e.visualPropertyByChannel("xe",i),C=e.visualPropertyByChannel("size",i);switch(g){case"width":return C??(r?r-n:I==null?void 0:I.tileUnitWidth);case"x-start":return I!=null&&I.markWidth?r?(n+r-(I==null?void 0:I.markWidth))/2:n-(I==null?void 0:I.markWidth)/2:void 0;default:return}}function L4e(e,g,i,I){var n,r,C,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=(r=A.outerRadius)!=null?r:300,f=(C=A.startAngle)!=null?C: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___"],R=I.encodedPIXIProperty("opacity"),S=I.encodedPIXIProperty("strokeWidth"),X=I.encodedPIXIProperty("stroke"),W=i.graphics;if(YT(A)){const V=I.getGenomicChannel();if(!V||!V.field){console.warn("Genomic field is not provided in the specification");return}const H=vT(l,x=>x[V.field]),Y=[...H.keys()];W.lineStyle(S,pt(X),R,1);const K={};w.forEach(x=>{const J=[],P=[];Y.forEach((q,$,j)=>{var te,Q;(Q=(te=H.get(q))==null?void 0:te.filter(Ie=>pi(Ie,A.color)===x))==null||Q.forEach(Ie=>{const he=+q,ne=B(he),be=xG([I.encodedPIXIProperty("y",Ie),0]);typeof K[q]>"u"&&(K[q]=0);const pe=v-be-K[q],ve=v-K[q];if(d){if($===0){const De=m-v/u*p,Qe=Mt(ne,c,De,y,Z,f,b);J.push([Qe.x,Qe.y]),P.push([Qe.x,Qe.y])}const We=m-pe/u*p,Be=Mt(ne,c,We,y,Z,f,b);J.push([Be.x,Be.y]);const Je=m-ve/u*p,Pe=Mt(ne,c,Je,y,Z,f,b);if(P.push([Pe.x,Pe.y]),$===j.length-1){const De=m-v/u*p,Qe=Mt(ne,c,De,y,Z,f,b);J.push([Qe.x,Qe.y]),P.push([Qe.x,Qe.y])}I.getMouseEventModel().addPointBasedEvent(Ie,[Pe.x,Pe.y,1])}else $===0&&(J.push([ne,v]),P.push([ne,v])),J.push([ne,pe]),P.push([ne,ve]),$===j.length-1&&(J.push([ne,v]),P.push([ne,v])),I.getMouseEventModel().addPointBasedEvent(Ie,[ne,pe,1]);K[q]+=be})});const ge=I.encodedValue("color",x);W.beginFill(pt(ge),R),W.drawPolygon([...J.reduce((q,$)=>q.concat($)),...P.reverse().reduce((q,$)=>q.concat($))]),W.endFill()})}else G.forEach(V=>{const H=I.encodedValue("row",V);W.lineStyle(S,pt(X),R,0),w.forEach(Y=>{const K=[],x=[],J=m-(H+v)/u*p;let P=0;l.filter(q=>(typeof pi(q,A.row)>"u"||pi(q,A.row)===V)&&(typeof pi(q,A.color)>"u"||pi(q,A.color)===Y)).sort((q,$)=>I.encodedPIXIProperty("x",q)-I.encodedPIXIProperty("x",$)).forEach((q,$,j)=>{const te=N1([xG([I.encodedPIXIProperty("y",q),0]),v]),Q=I.encodedPIXIProperty("x",q);if(d){const Ie=Mt(Q,c,J,y,Z,f,b);K.push([Ie.x,Ie.y]),$===0&&x.push(Ie.x,Ie.y);const he=m-(H+v-te)/u*p,ne=Mt(Q,c,he,y,Z,f,b);if(x.push(ne.x,ne.y),$===j.length-1){const be=m-(H+v)/u*p,pe=Mt(Q,c,be,y,Z,f,b);x.push(pe.x,pe.y)}I.getMouseEventModel().addPointBasedEvent(q,[ne.x,ne.y,1])}else $===0&&(x.push(Q,H+v),P=Q),x.push(Q,H+v-te),$===j.length-1&&(x.push(Q,H+v),x.push(P,H+v)),I.getMouseEventModel().addPointBasedEvent(q,[Q,H+v-te,1])}),d&&K.length!==0&&x.push(...K.reverse().reduce((q,$)=>q.concat($)));const ge=I.encodedValue("color",Y);W.beginFill(pt(ge),R),W.drawPolygon(x),W.endFill()})})}function U4e(e,g,i,I){var n,r,C,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=(r=A.outerRadius)!=null?r:300,f=(C=A.startAngle)!=null?C: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 V=g.tilesetInfo.tile_size,{tileX:H,tileWidth:Y}=g.getTilePosAndDimensions(i.tileData.zoomLevel,i.tileData.tilePos,V);G=B(H+Y/V)-B(H)}const v=(a=I.getChannelDomainArray("row"))!=null?a:["___SINGLE_ROW___"],w=u/v.length,R=ut(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 Y=I.encodedPIXIProperty("row",V)+R,K=I.encodedPIXIProperty("x",V),x=I.encodedPIXIProperty("color",V),J=I.encodedPIXIProperty("stroke",V),P=I.encodedPIXIProperty("strokeWidth",V),ge=I.encodedPIXIProperty("opacity",V),q=I.encodedPIXIProperty("width",V,{markWidth:G}),$=I.encodedPIXIProperty("height",V,{markHeight:X}),j=I.encodedPIXIProperty("y",V),te=I.markVisibility(V,{width:q,zoomLevel:g._xScale.invert(c)-g._xScale.invert(0)}),Q=Math.min(te,ge);if(Q===0||$===0||q<=1e-4)return;const[Ie,he,ne,be]=[K,K+q,Y+w-j-$/2,Y+w-j+$/2],pe=(H=I.visualPropertyByChannel("size",V))!=null?H:void 0;W.lineStyle(P,pt(J),Q,.5);let ve=[];if(d){if(he<0||c{const S=g.encodedValue("row",R);c.filter(X=>!pi(X,l.row)||pi(X,l.row)===R).forEach(X=>{var W,V,H;const Y=g.encodedPIXIProperty("x",X),K=g.encodedPIXIProperty("xe",X),x=(W=g.encodedPIXIProperty("size",X))!=null?W:K===void 0?w:K-Y,J=g.encodedPIXIProperty("y",X),P=g.encodedPIXIProperty("strokeWidth",X),ge=g.encodedPIXIProperty("stroke",X),q=g.encodedPIXIProperty("color",X),$=g.encodedPIXIProperty("opacity",X);let j=[];if(d){let te=Y||K-x,Q=K||Y+x,Ie=(te+Q)/2;const he=m-(S+G-J)/I*p,ne=he-w/2,be=he+w/2;if(((V=l.style)==null?void 0:V.align)==="right"&&!K&&(te-=x,Q-=x,Ie-=x),l.mark==="triangleLeft"){const We=Mt(Q,i,ne,y,Z,f,b),Be=Mt(te,i,he,y,Z,f,b),Je=Mt(Q,i,be,y,Z,f,b),Pe=Mt(Q,i,ne,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}else if(l.mark==="triangleRight"){const We=Mt(te,i,ne,y,Z,f,b),Be=Mt(Q,i,he,y,Z,f,b),Je=Mt(te,i,be,y,Z,f,b),Pe=Mt(te,i,ne,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}else if(l.mark==="triangleBottom"){te=Ie-x/2,Q=Ie+x/2;const We=Mt(te,i,be,y,Z,f,b),Be=Mt(Q,i,be,y,Z,f,b),Je=Mt(Ie,i,ne,y,Z,f,b),Pe=Mt(te,i,be,y,Z,f,b);j=[We.x,We.y,Be.x,Be.y,Je.x,Je.y,Pe.x,Pe.y]}const pe=g.markVisibility(X,{width:Q-te,zoomLevel:u}),ve=Math.min(pe,$);e.lineStyle(P,pt(ge),Q-te>2?ve:0,0),e.beginFill(pt(q),ve),e.drawPolygon(j),e.endFill()}else{let te=Y||K-x,Q=K||Y+x,Ie=te+(Q-te)/2;const he=S+G-J,ne=S+G-J-w/2,be=S+G-J+w/2;((H=l.style)==null?void 0:H.align)==="right"&&!K&&(te-=x,Q-=x,Ie-=x),j={triangleLeft:[Q,ne,te,he,Q,be,Q,ne],triangleRight:[te,ne,Q,he,te,be,te,ne],triangleBottom:[te,ne,Q,ne,Ie,be,te,ne]}[l.mark];const pe=g.markVisibility(X,{width:Q-te,zoomLevel:u}),ve=Math.min(pe,$);e.lineStyle(P,pt(ge),Q-te>2?ve:0,.5),e.beginFill(pt(q),ve),e.drawPolygon(j),e.endFill()}g.getMouseEventModel().addPolygonBasedEvent(X,j)})})}const wa={fontSize:"12px",fontFamily:"sans-serif",fontWeight:"normal",fill:"black",background:"white",lineJoin:"round",stroke:"#ffffff",strokeThickness:0};function $4e(e,g,i,I){var n,r,C,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=(r=d.outerRadius)!=null?r:300,Z=(C=d.startAngle)!=null?C:0,B=(o=d.endAngle)!=null?o:360,G=y-p,v=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(YT(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 K=vT(h,J=>J[Y.field]);[...K.keys()].forEach(J=>{var P;let ge=0;(P=K.get(J))==null||P.forEach(q=>{var $,j,te,Q,Ie,he,ne,be;const pe=I.encodedPIXIProperty("text",q),ve=I.encodedPIXIProperty("color",q),We=I.encodedPIXIProperty("x",q)+X,Be=I.encodedPIXIProperty("xe",q)+X,Je=I.encodedPIXIProperty("x-center",q)+X,Pe=I.encodedPIXIProperty("y",q)+W,De=I.encodedPIXIProperty("size",q),Qe=I.encodedPIXIProperty("stroke",q),_e=I.encodedPIXIProperty("strokeWidth",q),gt=I.encodedPIXIProperty("opacity",q);if(Je<0||Je>m||g.textsBeingUsed>1e3)return;const lt={...wa,fontSize:De??(($=d.style)!=null&&$.textFontSize?`${(j=d.style)==null?void 0:j.textFontSize}px`:wa.fontSize),stroke:(Q=Qe??((te=d.style)==null?void 0:te.textStroke))!=null?Q:wa.stroke,strokeThickness:(he=_e??((Ie=d.style)==null?void 0:Ie.textStrokeWidth))!=null?he:wa.strokeThickness,fontWeight:(be=(ne=d.style)==null?void 0:ne.textFontWeight)!=null?be:wa.fontWeight},tt=new e.libraries.PIXI.TextStyle(lt);let Xe;g.textGraphics.length>g.textsBeingUsed?(Xe=g.textGraphics[g.textsBeingUsed],Xe.style.fill=ve,Xe.visible=!0,Xe.text=pe,Xe.alpha=1):(Xe=new e.libraries.PIXI.Text(pe,{...lt,fill:ve}),g.textGraphics.push(Xe));const ae=e.libraries.PIXI.TextMetrics.measureText(pe,tt);g.textsBeingUsed++;const ye=I.markVisibility(q,{...ae,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),He=Math.min(ye,gt);if(!pe||He===0){g.textsBeingUsed--,Xe.visible=!1;return}Xe.alpha=He,Xe.resolution=8,Xe.updateText(),Xe.texture.baseTexture.scaleMode=e.libraries.PIXI.SCALE_MODES.LINEAR;const F=new e.libraries.PIXI.Sprite(Xe.texture);F.x=We,F.y=S-Pe-ge,F.width=Be-We,F.height=Pe,H.addChild(F),ge+=Pe})})}else R.forEach(H=>{const Y=i.graphics,K=I.encodedValue("row",H);h.filter(x=>!pi(x,d.row)||pi(x,d.row)===H).forEach(x=>{var J,P,ge,q,$,j,te,Q;const Ie=I.encodedPIXIProperty("text",x),he=I.encodedPIXIProperty("color",x),ne=I.encodedPIXIProperty("x-center",x)+X,be=I.encodedPIXIProperty("y",x)+W,pe=I.encodedPIXIProperty("size",x),ve=I.encodedPIXIProperty("stroke",x),We=I.encodedPIXIProperty("strokeWidth",x),Be=I.encodedPIXIProperty("opacity",x);if(ne<0||ne>m||g.textsBeingUsed>1e3)return;const Je={...wa,fontSize:pe??((J=d.style)!=null&&J.textFontSize?`${(P=d.style)==null?void 0:P.textFontSize}px`:wa.fontSize),stroke:(q=ve??((ge=d.style)==null?void 0:ge.textStroke))!=null?q:wa.stroke,strokeThickness:(j=We??(($=d.style)==null?void 0:$.textStrokeWidth))!=null?j:wa.strokeThickness,fontWeight:(Q=(te=d.style)==null?void 0:te.textFontWeight)!=null?Q:wa.fontWeight},Pe=new e.libraries.PIXI.TextStyle(Je);let De;g.textGraphics.length>g.textsBeingUsed?(De=g.textGraphics[g.textsBeingUsed],De.style.fill=he,De.visible=!0,De.text=Ie,De.alpha=1):(De=new e.libraries.PIXI.Text(Ie,{...Je,fill:he}),g.textGraphics.push(De));const Qe=e.libraries.PIXI.TextMetrics.measureText(Ie,Pe);g.textsBeingUsed++;const _e=I.markVisibility(x,{...Qe,zoomLevel:g._xScale.invert(m)-g._xScale.invert(0)}),gt=Math.min(_e,Be);if(!Ie||gt===0){g.textsBeingUsed--,De.visible=!1;return}De.alpha=gt,De.anchor.y=.5,De.anchor.x=V==="middle"?.5:V==="start"?0:1;let lt=[];if(b){const tt=y-(K+S-be)/f*G,Xe=Mt(ne,m,tt,v,w,Z,B);De.x=Xe.x,De.y=Xe.y,De.resolution=4;const ae=Qe.width/(2*tt*Math.PI)*m;let[ye,He]=[ne-ae/2,ne+ae/2];if(ye<0){const me=-ye;ye=0,He+=me}else if(He>m){const me=He-m;He=m,ye-=me}const F=[],T=[],k=[];for(let me=He;me>=ye;me-=ae/10){const Ve=Mt(me,m,tt,v,w,Z,B);F.push(new e.libraries.PIXI.Point(Ve.x,Ve.y));const we=Mt(me,m,tt+Qe.height/2,v,w,Z,B),je=Mt(me,m,tt-Qe.height/2,v,w,Z,B);T.push(we.x,we.y),me===He&&k.push(we.y,we.x),k.push(je.y,je.x)}De.updateText();const ie=new e.libraries.PIXI.SimpleRope(De.texture,F);ie.alpha=gt,Y.addChild(ie),k.reverse(),lt=T.concat(k)}else{De.position.x=ne,De.position.y=K+S-be,Y.addChild(De);const{height:tt,width:Xe}=Qe,ae=De.position.y-tt/2,ye=ae+tt;let He=0,F=0;V==="start"?(He=ne,F=ne+Xe):V==="middle"?(He=ne-Xe/2,F=ne+Xe/2):(He=ne-Xe,F=ne),lt=[He,ae,He,ye,F,ye,F,ae]}I.getMouseEventModel().addPolygonBasedEvent(x,lt)})})}function q4e(e,g,i,I){var n,r,C,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=(r=c.outerRadius)!=null?r:300,p=(C=c.startAngle)!=null?C: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,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;v.forEach(V=>{const H=I.encodedValue("row",V);u.filter(Y=>!pi(Y,c.row)||pi(Y,c.row)===V).forEach(Y=>{const K=I.encodedPIXIProperty("x",Y),x=I.encodedPIXIProperty("xe",Y),J=I.encodedPIXIProperty("y",Y),P=I.encodedPIXIProperty("color",Y),ge=I.encodedPIXIProperty("strokeWidth",Y),q=I.encodedPIXIProperty("opacity",Y),$=I.markVisibility(Y,{width:x-K,zoomLevel:g._xScale.invert(d)-g._xScale.invert(0)}),j=Math.min($,q);if(W.lineStyle(ge,pt(P),j,.5),!x&&(!c.y||!("field"in c.y))){if(m)return;if(R){const[te,Q]=R;let Ie=0;do W.moveTo(K,Ie),W.lineTo(K,Ie+te),Ie+=te+Q;while(Ie{const H=i.encodedValue("row",V);d.filter(Y=>!pi(Y,u.row)||pi(Y,u.row)===V).forEach(Y=>{var K,x,J,P,ge;let q=i.encodedPIXIProperty("x",Y),$=i.encodedPIXIProperty("xe",Y),j=i.encodedPIXIProperty("x1",Y),te=i.encodedPIXIProperty("x1e",Y);const Q=i.encodedPIXIProperty("y",Y),Ie=i.encodedPIXIProperty("ye",Y),he=i.encodedPIXIProperty("stroke",Y),ne=i.encodedPIXIProperty("strokeWidth",Y),be=i.encodedPIXIProperty("color",Y),pe=i.encodedPIXIProperty("opacity",Y);typeof $<"u"&&([q,$]=[q,$].sort((Pe,De)=>Pe-De)),typeof j<"u"&&typeof te<"u"&&([j,te]=[j,te].sort((Pe,De)=>Pe-De));const ve=typeof $<"u"&&typeof j<"u"&&typeof te<"u"&&Math.abs(q-$)>.1&&Math.abs(j-te)>.1;if(!ve&&$===void 0&&!Ir(u)){if(j===void 0&&te===void 0)return;$=j!==void 0?j:te}!ve&&Math.abs(q-$)<=.1&&Math.abs(j-te)<=.1&&(q=(q+$)/2,$=(j+te)/2),e.lineStyle(ne,pt(he),pe,.5);const We=ut(u.y)&&u.y.flip||u.flipY,Be=(K=u.baselineY)!=null?K:H+(We?0:R);let Je=[];if(ve){e.beginFill(pt(be==="none"?"white":be),be==="none"?0:pe);let[Pe,De,Qe,_e]=[q,$,j,te];if([Pe,De,Qe,_e]=[Pe,De,Qe,_e].sort((gt,lt)=>gt-lt),Pe>h||_e<0||Math.abs(_e-Pe)<.5)return;if(f){if(Pe<0||_e>h)return;const gt=p-H/m*B,lt=Mt(Pe,h,gt,G,v,y,Z),tt=Mt(De,h,gt,G,v,y,Z),Xe=Mt(Qe,h,gt,G,v,y,Z),ae=Mt(_e,h,gt,G,v,y,Z);e.moveTo(lt.x,lt.y),e.bezierCurveTo(G,v,G,v,ae.x,ae.y),e.arc(G,v,p,lc(ae.x,ae.y,G,v),lc(Xe.x,Xe.y,G,v),!1),e.bezierCurveTo(G,v,G,v,tt.x,tt.y),e.arc(G,v,p,lc(tt.x,tt.y,G,v),lc(lt.x,lt.y,G,v),!1),Je=Array.from(e.currentPath.points),e.endFill()}else e.moveTo(Pe,Be),!((x=u.style)!=null&&x.linkStyle)||((J=u.style)==null?void 0:J.linkStyle)==="circular"?(e.arc((Pe+_e)/2,Be,(_e-Pe)/2,-Math.PI,Math.PI,!1),e.arc((De+Qe)/2,Be,(Qe-De)/2,Math.PI,-Math.PI,!0),Je=Array.from(e.currentPath.points),e.closePath()):(e.lineTo(Qe,H+R),e.bezierCurveTo(Qe+(De-Qe)/3,H+R-(De-Qe)/2,Qe+(De-Qe)/3*2,H+R-(De-Qe)/2,De,H+R),e.lineTo(_e,H+R),e.bezierCurveTo(Pe+(_e-Pe)/3*2,H+R-(_e-Pe)/2,Pe+(_e-Pe)/3,H+R-(_e-Pe)/2,Pe,H+R),Je=Array.from(e.currentPath.points),e.endFill());i.getMouseEventModel().addPolygonBasedEvent(Y,Je)}else{const Pe=(q+$)/2;if(e.beginFill(pt("white"),0),f){if(q<0||$>h)return;if(((P=u.style)==null?void 0:P.linkStyle)==="straight"){const De=p-H/m*B,Qe=Mt(q,h,De,G,v,y,Z),_e=Mt($,h,De,G,v,y,Z),gt=Qe.x,lt=Qe.y,tt=_e.x,Xe=_e.y;e.moveTo(gt,lt),e.lineTo(tt,Xe);const ae=100;Je=Array.from({length:ae},(He,F)=>({x:(tt-gt)/(ae-1)*F+gt,y:(Xe-lt)/(ae-1)*F+lt})).flatMap(He=>[He.x,He.y])}else{const De=p-H/m*B,Qe=Mt(q,h,De,G,v,y,Z),_e=Mt($,h,De,G,v,y,Z),gt=Qe.x,lt=Qe.y,tt=Qe.x,Xe=Qe.y,ae=h/2,ye=m/2,He=_e.x,F=_e.y;e.moveTo(gt,lt);const T=new iI(gt,lt,tt,Xe,ae,ye,He,F);T.getLUT(14).forEach(me=>e.lineTo(me.x,me.y)),Je=T.getLUT(1e3).flatMap(me=>[me.x,me.y])}}else if(((ge=u.style)==null?void 0:ge.linkStyle)==="elliptical"){if(!(0<=q&&q<=h)&&!(0<=$&&$<=h))return;const De=[],Qe=ut(u.y);for(let _e=0;_e<=X;_e++){const gt=Math.PI*(_e/X),lt=($-q)/2*Math.cos(gt)+(q+$)/2;let tt=Be-Q*Math.sin(gt)*(Qe?1:Math.min($-q+h*S,h)/h)*(We?-1:1);if(typeof Q<"u"&&typeof Ie<"u"){const Xe=Math.abs(Ie-Q),ae=Ie>Q;tt=Q-Xe*Math.sin(gt)*(ae?-1:1)}if(_e===0)if(W){const Xe=We?Be-m:Be;e.moveTo(lt,Xe),De.push({x:lt,y:Xe}),e.lineTo(lt,tt)}else e.moveTo(lt,tt);else e.lineTo(lt,tt);if(De.push({x:lt,y:tt}),_e===X&&W){const Xe=We?Be-m:Be;e.lineTo(lt,Xe),De.push({x:lt,y:Xe})}}Je=De.flatMap(_e=>[_e.x,_e.y])}else{if($<0||q>h)return;e.arc(Pe,Be,($-q)/2,-Math.PI,Math.PI),Je=Array.from(e.currentPath.points),e.closePath()}i.getMouseEventModel().addLineBasedEvent(Y,Je)}})})}function tje(e,g,i){return[...e.slice(0,g),i,...e.slice(g)]}function gje(e){const g=[];for(let i=0;itypeof g=="number")}function vbe(e){return Gbe(e,g=>typeof g=="string")}function ije(e,g,i){nje(e,g,i),Ije(e,g,i)}function Ije(e,g,i){var I,n,r,C;const o=g.spec();if(!ut(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=(r=o.startAngle)!=null?r:0,m=(C=o.endAngle)!=null?C: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 R=w+Z/2,S=d-R/l*f,X=S+G/2,W=S-G/2,V=Mt(0,A,W,b,p,h,m),H=jg(0,A,h,m),Y=jg(A,A,h,m);B.lineStyle(G,pt("black"),0,.5),B.beginFill(pt(i.axis.gridColor),1),B.moveTo(a+V.x,s+V.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,pt(i.axis.gridColor),1,.5);const R=s+w+Z/2;B.moveTo(a,R),B.lineTo(a+A,R)}})}function nje(e,g,i){var I,n,r,C,o;const a=g.spec();if(!ut(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=(r=a.startAngle)!=null?r:0,p=(C=a.endAngle)!=null?C:360,y=f-m,Z=l/2,B=c/2,G=(o=g.getChannelDomainArray("row"))!=null?o:["___SINGLE_ROW___"],v=c/G.length;if(!vbe(G))return;const w=g.getChannelScale("y"),R=g.getChannelDomainArray("y");if(!w||!R||!o7(R)||h&&v/c*y<=20||!h&&v<=20)return;const S=e.pBackground,X=i.axis.gridStrokeWidth;G.forEach(W=>{const V=g.encodedValue("row",W),H=h?v/c*y:v,Y=Math.max(Math.ceil(H/40),1);let K=w.ticks(Y).filter(x=>R[0]<=x&&x<=R[1]);K.length===1&&(K=w.ticks(Y+1).filter(x=>R[0]<=x&&x<=R[1])),h?K.forEach(x=>{const J=w(x),P=f-(V+v-J)/c*y,ge=P+X/2,q=P-X/2,$=Mt(0,l,q,Z,B,b,p),j=jg(0,l,b,p),te=jg(l,l,b,p);S.lineStyle(X,pt("black"),0,.5),S.beginFill(pt(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,ge,te,j,!1),S.closePath()}):(S.lineStyle(X,pt(i.axis.gridColor),1,.5),K.forEach(x=>{var J;const P=A+V+v-w(x);if(i.axis.gridStrokeType==="solid")S.moveTo(u,P),S.lineTo(d,P);else if(i.axis.gridStrokeType==="dashed"){const[ge,q]=(J=i.axis.gridStrokeDash)!=null?J:[1,1];for(let $=u;$=R;Y-=w/10){const K=Mt(Y,A,b-v.height/2,h,m,u,d);X.push(new e.libraries.PIXI.Point(K.x,K.y))}const W=jg(R,A,u,d),V=jg(S+p,A,u,d);f.lineStyle(1,pt("red"),0,.5),f.beginFill(pt(n.track.titleBackground),.5),f.moveTo(y.x,y.y),f.arc(h,m,b-v.height,W,V,!0),f.arc(h,m,b,V,W,!1),f.closePath(),B.updateText();const H=new e.libraries.PIXI.SimpleRope(B.texture,X);f.addChild(H)}function Cje(e,g,i){var I,n,r,C;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,pt((C=(r=g.spec().style)==null?void 0:r.outline)!=null?C:i.track.outline),1,.5),o.beginFill(pt("white"),0),o.drawRect(a,s,A,l);const c=g.spec().x;o.lineStyle(1,pt(i.axis.baselineColor),1,.5),ut(c)&&c.axis==="top"?(o.moveTo(a,s),o.lineTo(a+A,s)):ut(c)&&c.axis==="bottom"&&(o.moveTo(a,s+l),o.lineTo(a+A,s+l))}function oje(e,g,i,I,n){if(!g.gLegend)return;g.gLegend.selectAll(".brush").remove();const r=I.spec(),C={offsetRight:0};if(ut(r.color)&&r.color.legend)switch(r.color.type){case"nominal":aje(e,g,i,I,n);break;case"quantitative":xte(e,g,i,I,n,"color",C);break}if(ut(r.stroke)&&r.stroke.legend)switch(r.stroke.type){case"quantitative":xte(e,g,i,I,n,"stroke",C);break}}function xte(e,g,i,I,n,r,C){const o=I.spec(),a=o[r];if(!ut(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-C.offsetRight,f=A+1,b=I.getChannelScale(r),p=I.getChannelDomainArray(r);if(!b||!p)return;const y=g.pBorder;if(y.beginFill(pt(n.legend.background),n.legend.backgroundOpacity),y.lineStyle(1,pt(n.legend.backgroundStroke),n.legend.backgroundOpacity,0),y.drawRect(m,f,u,d),a.title){const H=a.title,Y=Fs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),K=new e.libraries.PIXI.Text(H,{...Y,fontWeight:"bold"});K.anchor.x=0,K.anchor.y=0,K.position.x=m+10,K.position.y=f+10;const x=new e.libraries.PIXI.TextStyle({...Y,fontWeight:"bold"}),J=e.libraries.PIXI.TextMetrics.measureText(H,x);y.addChild(K),h.top+=J.height+4,h.height-=J.height+4}const[Z,B]=p,G=B-Z,v=ut(a)&&a.scaleOffset?a.scaleOffset:[0,1];[...Array(h.height).keys()].forEach(H=>{let Y;const K=Array.from(v).sort();if(H/h.height>=K[1])Y=B;else if(H/h.height<=K[0])Y=Z;else{const x=qd().domain([h.height*K[0],h.height*K[1]]).range([0,h.height]);Y=qd().domain([0,h.height]).range([Z,B])(x(H))}y.beginFill(pt(b(Y)),1),y.lineStyle(1,pt(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",r).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 K=H.sourceEvent,x=g.startEvent.clientY-K.clientY,J=[a.scaleOffset[0],a.scaleOffset[1]];Y.id===0?J[0]+=x/h.height:J[1]+=x/h.height,J[0]=Math.min(1,Math.max(0,J[0])),J[1]=Math.min(1,Math.max(0,J[1])),g.updateScaleOffsetFromOriginalSpec(o._renderingId,J,r),g.shareScaleOffsetAcrossTracksAndTiles(J,r),g.draw(),g.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,pt(n.legend.tickColor),1,.5);const W=Fs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily}),V=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(V-3,Y),y.lineTo(V,Y);const K=new e.libraries.PIXI.Text(H,W);K.anchor.x=1,K.anchor.y=.5,K.position.x=V-6,K.position.y=Y,y.addChild(K)}),C.offsetRight=l-m}function aje(e,g,i,I,n){var r,C,o,a,s;const A=I.spec();if(!ut(A.color)||A.color.type!=="nominal"||!A.color.legend)return;const l=(r=I.getChannelDomainArray("color"))!=null?r:["___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=Fs({color:n.legend.labelColor,size:n.legend.labelFontSize,fontWeight:n.legend.labelFontWeight,fontFamily:n.legend.labelFontFamily});if((C=A.style)!=null&&C.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 R=new e.libraries.PIXI.TextStyle(B),S=e.libraries.PIXI.TextMetrics.measureText(G,R);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 R=new e.libraries.PIXI.TextStyle(B),S=e.libraries.PIXI.TextMetrics.measureText(G,R);y{m.lineStyle(1,pt("black"),0,0),m.beginFill(pt(G.color),1),m.drawCircle(G.x,G.y,4)})}function Aje(e,g,i,I,n){var r;const C=I.spec();if(!ut(C.row)||C.row.type!=="nominal"||!C.row.legend)return;const o=(r=I.getChannelDomainArray("row"))!=null?r:["___SINGLE_ROW___"];if(o.length===0)return;const a=g.pBorder,s=4,A=2,l=Fs({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(pt(n.legend.background),n.legend.backgroundOpacity),a.lineStyle(1,pt(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 l3=8,KZ=6;function sje(e,g,i,I,n){var r;const C=I.spec(),o=C.layout==="circular",a=I.getChannelDomainArray("y"),s=I.getChannelRangeArray("y");if(o||!I.isShowYAxis()||!a||!s||!o7(a))return;const[A,l]=g.dimensions,[c,u]=g.position,d=(r=I.getChannelDomainArray("row"))!=null?r:["___SINGLE_ROW___"];if(!vbe(d))return;const h=l/d.length;if(h<=20)return;const m=I.spec().y,f=!(ut(m)&&"axis"in m&&m.axis==="right"),b=qd().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,pt(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,pt(n.axis.tickColor),1,.5);let R=f?B+KZ:B-KZ;w.forEach(X=>{const W=b(X);p.moveTo(B,G+h-W),p.lineTo(R,G+h-W)}),R=f?B+l3:B-l3,p.moveTo(B,G),p.lineTo(R,G),p.moveTo(B,G+h),p.lineTo(R,G+h);const S=Fs({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?B+KZ*2:B-KZ*2;const V=new e.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,C.orientation==="vertical"&&(V.anchor.x=f?1:0,V.scale.x*=-1),p.addChild(V)})})}function lje(e,g,i,I,n){var r,C,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||!o7(c))return;const[d,h]=g.dimensions,m=(r=A.innerRadius)!=null?r:220,f=(C=A.outerRadius)!=null?C: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,R=!(ut(w)&&"axis"in w&&w.axis==="right"),S=qd().domain(c).range(u),X=i.graphics;G.forEach(W=>{const V=I.encodedValue("row",W),H=f-(V+v)/h*b,Y=f-V/h*b,K=Mt(R?0:d,d,H,Z,B,p,y),x=Mt(R?0:d,d,Y,Z,B,p,y);X.lineStyle(1,pt(n.axis.baselineColor),1,.5),X.moveTo(K.x,K.y),X.lineTo(x.x,x.y);const J=j=>KZ*d/2/Math.PI/j,P=j=>l3*d/2/Math.PI/j,ge=v/h*b,q=Math.max(Math.ceil(ge/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,pt(n.axis.tickColor),1,.5),$.forEach(j=>{const te=S(j),Q=f-(V+v-te)/h*b,Ie=R?0:d-J(Q),he=R?J(Q):d,ne=Mt(Ie,d,Q,Z,B,p,y),be=jg(Ie,d,p,y),pe=jg(he,d,p,y);X.moveTo(ne.x,ne.y),X.arc(Z,B,Q,be,pe,!0),X.arc(Z,B,Q,pe,be,!1),X.closePath()});{const j=R?0:d-P(m),te=R?P(m):d,Q=jg(j,d,p,y),Ie=jg(te,d,p,y);X.moveTo(K.x,K.y),X.arc(Z,B,m,Q,Ie,!0),X.arc(Z,B,m,Ie,Q,!1),X.closePath()}{const j=R?0:d-P(f),te=R?P(f):d,Q=jg(j,d,p,y),Ie=jg(te,d,p,y);X.moveTo(x.x,x.y),X.arc(Z,B,f,Q,Ie,!0),X.arc(Z,B,f,Ie,Q,!1),X.closePath()}$.forEach(j=>{const te=S(j),Q=f-(V+v-te)/h*b,Ie=Mt(J(Q)*2,d,Q,Z,B,p,y),he=Fs({color:n.axis.labelColor,size:n.axis.labelFontSize,fontFamily:n.axis.labelFontFamily,fontWeight:n.axis.labelFontWeight}),ne=new e.libraries.PIXI.Text(j,he);ne.anchor.x=R?1:0,ne.anchor.y=.5,ne.position.x=Ie.x,ne.position.y=Ie.y,ne.resolution=4;const be=new e.libraries.PIXI.TextStyle(he),ve=e.libraries.PIXI.TextMetrics.measureText(ne.text,be).width/(2*Q*Math.PI)*d*360/(y-p),We=R?J(Q)*2:d-J(Q)*2-ve,Be=R?J(Q)*2+ve:d-J(Q)*2,Je=[];for(let De=Be;De>=We;De-=ve/10){const Qe=Mt(De,d,Q,Z,B,p,y);Je.push(new e.libraries.PIXI.Point(Qe.x,Qe.y))}ne.updateText();const Pe=new e.libraries.PIXI.SimpleRope(ne.texture,Je);X.addChild(Pe)})})}function cje(e,g,i){var I,n,r,C,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=(r=h.startAngle)!=null?r:0,G=(C=h.endAngle)!=null?C:360,v=m+b/2,w=f+p/2,R=Mt(0,b,y,v,w,B,G),S=jg(0,b,B,G),X=jg(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,pt((A=(s=h.style)==null?void 0:s.outline)!=null?A:"#DBDBDB"),1,1),W.beginFill(pt((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(R.x,R.y),W.arc(v,w,y,S,X,!0),W.arc(v,w,Z,X,S,!1),W.closePath()),ut(h.x)&&h.x.axis==="top"&&(W.lineStyle(.5,pt("black"),0,.5),W.beginFill(pt("white"),0),W.moveTo(R.x,R.y),W.arc(v,w,Z-.5,S,X,!0),W.arc(v,w,Z,X,S,!1),W.closePath()),W.lineStyle(.5,pt("black"),0,.5),W.beginFill(pt("white"),0),W.moveTo(v,w),W.arc(v,w,Z+3,S,X,!1),W.closePath(),W.lineStyle(1,pt("#DBDBDB"),0,0),W.beginFill(pt("white"),0),W.drawCircle(v,w,y-1)}function uje(e,g,i){var I,n,r,C,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=(r=(n=g.spec().style)==null?void 0:n.background)!=null?r:i.track.background,h=Fte((C=g.spec().style)==null?void 0:C.backgroundOpacity)?1:(o=g.spec().style)==null?void 0:o.backgroundOpacity;u.lineStyle(1,pt("white"),0,0),u.beginFill(pt(d),h),u.drawRect(s,A,l,c)}if(i.track.alternatingBackground&&i.track.alternatingBackground!=="transparent"){const d=g.spec();if(!ut(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=Fte((y=g.spec().style)==null?void 0:y.backgroundOpacity)?1:(Z=g.spec().style)==null?void 0:Z.backgroundOpacity;u.lineStyle(1,pt("white"),0,0),u.beginFill(pt(G),v),u.drawRect(e.position[0],e.position[1]+B,l,c/h.length)})}}function dje(e,g,i){var I,n,r,C,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=(r=a.startAngle)!=null?r:0,m=(C=a.endAngle)!=null?C: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=>!pi(v,a.row)||pi(v,a.row)===B).forEach(v=>{var w,R;let S=i.encodedPIXIProperty("x",v),X=i.encodedPIXIProperty("xe",v),W=i.encodedPIXIProperty("x1",v),V=i.encodedPIXIProperty("x1e",v);const H=i.encodedPIXIProperty("y",v),Y=i.encodedPIXIProperty("stroke",v),K=i.encodedPIXIProperty("strokeWidth",v),x=i.encodedPIXIProperty("color",v),J=i.encodedPIXIProperty("opacity",v);typeof X<"u"&&([S,X]=[S,X].sort((ge,q)=>ge-q)),typeof W<"u"&&typeof V<"u"&&([W,V]=[W,V].sort((ge,q)=>ge-q));const P=typeof X<"u"&&typeof W<"u"&&typeof V<"u"&&Math.abs(S-X)>.1&&Math.abs(W-V)>.1;if(!P&&X===void 0&&!Ir(a)){if(W===void 0&&V===void 0)return;X=W!==void 0?W:V}if(!P&&Math.abs(S-X)<=.1&&Math.abs(W-V)<=.1&&(S=(S+X)/2,X=(W+V)/2),e.lineStyle(K,pt(Y),J,.5),P){e.beginFill(pt(x==="none"?"white":x),x==="none"?0:J);let[ge,q,$,j]=[S,X,W,V];if([ge,q]=[ge,q].sort((te,Q)=>te-Q),[$,j]=[$,j].sort((te,Q)=>te-Q),ge>A||j<0||Math.abs(j-ge)<.5)return;if(c){if(ge<0||j>A)return;const te=d-G/l*f,Q=Mt(ge,A,te,b,p,h,m),Ie=Mt(q,A,te,b,p,h,m),he=Mt($,A,te,b,p,h,m),ne=Mt(j,A,te,b,p,h,m);e.moveTo(Q.x,Q.y),e.bezierCurveTo(b,p,b,p,ne.x,ne.y),e.arc(b,p,d,lc(ne.x,ne.y,b,p),lc(he.x,he.y,b,p),!1),e.bezierCurveTo(b,p,b,p,Ie.x,Ie.y),e.arc(b,p,d,lc(Ie.x,Ie.y,b,p),lc(Q.x,Q.y,b,p),!1),e.endFill()}else e.moveTo(ge,G),e.lineTo(q,G),e.lineTo(j,G+Z),e.lineTo($,G+Z),e.lineTo(ge,G),e.closePath()}else{if(Ir(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)):((R=a.style)==null?void 0:R.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 ge,q;for(let $=0;$<=1;$+=.02){const j=ne=>Math.log(ne/(1-ne)),te=ne=>d-1/(1+Math.exp(j(ne)))*f+3,Q=(ne,be,pe)=>((pe-be)*ne+be)/A,Ie=b+te($)*Math.cos(-Q($,S,X)*2*Math.PI-Math.PI/2),he=p+te($)*Math.sin(-Q($,S,X)*2*Math.PI-Math.PI/2);ge&&q&&(e.lineStyle(K,pt(Y),J,.5),e.moveTo(ge,q),e.lineTo(Ie,he)),ge=Ie,q=he}return}e.moveTo(X,G+Z),e.lineTo(S,G)}})})}const Xd=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function hje(e,g,i,I){if(!e||!g||!i||I.spec().mark==="brush")return;if(["x","x1","x1e","xe"].forEach(C=>{I.setChannelScale(C,g._xScale)}),Ir(I.spec())||Rje(I.spec())){const C=g._yScale.copy();C.range([C.range()[1],C.range()[0]]),["y","y1","y1e","ye"].forEach(o=>{I.setChannelScale(o,C)})}const[n,r]=g.dimensions;switch(I.spec().mark){case"point":z4e(g,i.graphics,I);break;case"bar":O4e(g,i,I);break;case"line":J4e(i.graphics,I,n,r);break;case"area":L4e(e,g,i,I);break;case"rect":U4e(e,g,i,I);break;case"triangleLeft":case"triangleRight":case"triangleBottom":j4e(i.graphics,I,n,r);break;case"text":$4e(e,g,i,I);break;case"rule":q4e(e,g,i,I);break;case"betweenLink":dje(i.graphics,g,I);break;case"withinLink":eje(i.graphics,g,I);break;default:console.warn("Unsupported mark type");break}}function mje(e,g,i,I,n){if(!e||!g||!i||I.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(C=>{I.setChannelScale(C,g._xScale)}),I.spec().layout==="circular"?cje(g,I,n):(uje(g,I,n),Cje(g,I,n)),ije(g,I,n)}function fje(e,g,i,I,n){if(!e||!g||!i||I.spec().mark==="brush")return;["x","x1","x1e","xe"].forEach(C=>{I.setChannelScale(C,g._xScale)}),I.spec().layout==="circular"?(lje(e,g,i,I,n),rje(e,g,i,I,n)):(sje(e,g,i,I,n),Aje(e,g,i,I,n)),oje(e,g,i,I,n)}function N0(e){if(wbe(e)||XS(e))return[];if(!uI(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((r,C)=>{const o=Object.assign(JSON.parse(JSON.stringify(g)),r);o.title&&C!==0&&delete o.title,i.push(o)});let I;return i.forEach(r=>{ut(r.x)&&r.x.axis&&!I&&(I=r.x.axis)}),i.map(r=>({...r,x:{...r.x,axis:I}}))}function Bbe(e){return[].concat(...e.map(g=>{if(wbe(g)||!uI(g)||g._overlay.length<=1)return[g];if(g._overlay.filter(C=>C.data).length===0)return[g];if(Ete([g.data,...g._overlay.map(C=>C.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(C=>{if(n.data||(n.data=C.data),n.id||(n.id=C.id),!C.data||Ete([n.data,C.data])){n._overlay.push(C);return}const o=Object.assign(JSON.parse(JSON.stringify(i)),C);I.push(o)}),(n._overlay.length>0?[n,...I]:I).map((C,o,a)=>{const s=o!==0,A=DC(C)&&ut(C.y)&&!C.y.axis&&s?{...C.y,axis:o===1?"right":"none"}:DC(C)?C.y:void 0;return C.title&&o!==a.length-1&&a.length!==1&&delete C.title,{...C,overlayOnPreviousTrack:s,y:A}})}))}function Ete(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(C=>JSON.stringify(C[n])))).length!==1){I=!1;return}}),I}const K9={viridis:pbe,grey:v4e,warm:S4e,spectral:h4e,cividis:B4e,bupu:f4e,rdbu:u4e,hot:Z4e,pink:b4e};function a7(e){return typeof e=="object"&&e!==null}function _R(e){return a7(e)&&"getTabularData"in e}function pje(e,g){var i;return((i=e.dataTransform)!=null?i:[]).some(I=>I.type===g)}function bje(e="viridis",g=100){var i;const I=(i=K9[e])!=null?i:K9.viridis;return[...Array(g)].map((n,r)=>I(1/g*r))}function Sbe(e){return!("alignment"in e)&&!e.tracks.find(g=>g.alignment==="overlay"||"tracks"in g)}function yje(e){return"alignment"in e&&e.alignment==="overlay"}function Zje(e){return!Sbe(e)&&!yje(e)}function wbe(e){return!uI(e)&&"data"in e&&!("mark"in e)}function XS(e){return"type"in e&&e.type=="dummy-track"}function Gje(e){return!!("data"in e&&"overrideTemplate"in e&&e.overrideTemplate)}function Mte(e){return typeof e=="object"}function vje(e){return"chromosome"in e&&!("interval"in e)}function Bje(e){return!("chromosome"in e)&&"interval"in e}function Sje(e){return"chromosome"in e&&"interval"in e}function DC(e){return!("_overlay"in e)}function uI(e){return"_overlay"in e}function wje(e){return"template"in e}function Rje(e){return DC(e)&&!ut(e.x)&&ut(e.y)&&e.y.type==="genomic"}function Ir(e){const g=DC(e)?e:N0(e)[0];return ut(g.x)&&g.x.type==="genomic"&&ut(g.y)&&g.y.type==="genomic"}function Vje(e){return Ir(e)&&e.data.type==="matrix"&&(e.mark==="bar"||e.mark==="rect")&&e.xe&&e.ye}function K1(e){return e!==null&&typeof e=="object"&&"value"in e}function A7(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 ut(e){return a7(e)&&!("value"in e)}function Wje(e){return"oneOf"in e}function Xje(e){return"inRange"in e}function Hje(e){return"include"in e}function zte(e){return Array.isArray(e)}function Tje(e){return Array.isArray(e)}function YT(e){return(e.mark==="bar"||e.mark==="area"||e.mark==="text")&&ut(e.color)&&e.color.type==="nominal"&&(!e.row||K1(e.row))&&ut(e.y)&&e.y.type==="quantitative"&&!ut(e.ye)}function Nje(e,g){const i=e[g];return YT(e)&&(g==="x"||g==="y")&&ut(i)&&i.type==="quantitative"}function pi(e,g){if(ut(g)&&g.field)return e[g==null?void 0:g.field]}function kje(e){const g=[];return Xd.forEach(i=>{const I=e[i];ut(I)&&"aggregate"in I&&g.push(i)}),g}function u5(e,g){const i=[];return Xd.forEach(I=>{const n=e[I];ut(n)&&n.type===g&&i.push(I)}),i}function F9(e){if((DC(e)||uI(e))&&ut(e.x)&&e.x.axis&&e.x.axis!=="none")return!0;if(uI(e)){let g=!1;return e._overlay.forEach(i=>{g||ut(i.x)&&i.x.axis&&i.x.axis!=="none"&&(g=!0)}),g}return!1}function Yje(e){if((DC(e)||uI(e))&&ut(e.y)&&e.y.axis&&e.y.axis!=="none")return!0;if(uI(e)){let g=!1;return e._overlay.forEach(i=>{g||ut(i.y)&&i.y.axis&&i.y.axis!=="none"&&(g=!0)}),g}return!1}function km(e){return typeof e=="object"}var gh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Kje(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var c3={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)})(gh,function(i){function I(){for(var O=arguments.length,D=Array(O),ee=0;ee1){D[0]=D[0].slice(0,-1);for(var ce=D.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(O){throw new RangeError(R[O])}function H(O,D){for(var ee=[],ce=O.length;ce--;)ee[ce]=D(O[ce]);return ee}function Y(O,D){var ee=O.split("@"),ce="";ee.length>1&&(ce=ee[0]+"@",O=ee[1]),O=O.replace(w,".");var de=O.split("."),Le=H(de,D).join(".");return ce+Le}function K(O){for(var D=[],ee=0,ce=O.length;ee=55296&&de<=56319&&ee>1,D+=X(D/ee);D>S*f>>1;de+=h)D=X(D/S);return X(de+(S+1)*D/(D+b))},q=function(D){var ee=[],ce=D.length,de=0,Le=Z,Ue=y,dt=D.lastIndexOf(B);dt<0&&(dt=0);for(var yt=0;yt=128&&V("not-basic"),ee.push(D.charCodeAt(yt));for(var kt=dt>0?dt+1:0;kt=ce&&V("invalid-input");var At=J(D.charCodeAt(kt++));(At>=h||At>X((d-de)/Rt))&&V("overflow"),de+=At*Rt;var Xt=xt<=Ue?m:xt>=Ue+f?f:xt-Ue;if(AtX(d/Pt)&&V("overflow"),Rt*=Pt}var Ft=ee.length+1;Ue=ge(de-ht,Ft,ht==0),X(de/Ft)>d-Le&&V("overflow"),Le+=X(de/Ft),de%=Ft,ee.splice(de++,0,Le)}return String.fromCodePoint.apply(String,ee)},$=function(D){var ee=[];D=K(D);var ce=D.length,de=Z,Le=0,Ue=y,dt=!0,yt=!1,kt=void 0;try{for(var ht=D[Symbol.iterator](),Rt;!(dt=(Rt=ht.next()).done);dt=!0){var xt=Rt.value;xt<128&&ee.push(W(xt))}}catch(fr){yt=!0,kt=fr}finally{try{!dt&&ht.return&&ht.return()}finally{if(yt)throw kt}}var At=ee.length,Xt=At;for(At&&ee.push(B);Xt=de&&LtX((d-Le)/Yt)&&V("overflow"),Le+=(Pt-de)*Yt,de=Pt;var Wt=!0,eg=!1,_t=void 0;try{for(var $t=D[Symbol.iterator](),ag;!(Wt=(ag=$t.next()).done);Wt=!0){var Wg=ag.value;if(Wgd&&V("overflow"),Wg==de){for(var hg=Le,Pi=h;;Pi+=h){var en=Pi<=Ue?m:Pi>=Ue+f?f:Pi-Ue;if(hg>6|192).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase():ee="%"+(D>>12|224).toString(16).toUpperCase()+"%"+(D>>6&63|128).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase(),ee}function ne(O){for(var D="",ee=0,ce=O.length;ee=194&&de<224){if(ce-ee>=6){var Le=parseInt(O.substr(ee+4,2),16);D+=String.fromCharCode((de&31)<<6|Le&63)}else D+=O.substr(ee,6);ee+=6}else if(de>=224){if(ce-ee>=9){var Ue=parseInt(O.substr(ee+4,2),16),dt=parseInt(O.substr(ee+7,2),16);D+=String.fromCharCode((de&15)<<12|(Ue&63)<<6|dt&63)}else D+=O.substr(ee,9);ee+=9}else D+=O.substr(ee,3),ee+=3}return D}function be(O,D){function ee(ce){var de=ne(ce);return de.match(D.UNRESERVED)?de:ce}return O.scheme&&(O.scheme=String(O.scheme).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_SCHEME,"")),O.userinfo!==void 0&&(O.userinfo=String(O.userinfo).replace(D.PCT_ENCODED,ee).replace(D.NOT_USERINFO,he).replace(D.PCT_ENCODED,C)),O.host!==void 0&&(O.host=String(O.host).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_HOST,he).replace(D.PCT_ENCODED,C)),O.path!==void 0&&(O.path=String(O.path).replace(D.PCT_ENCODED,ee).replace(O.scheme?D.NOT_PATH:D.NOT_PATH_NOSCHEME,he).replace(D.PCT_ENCODED,C)),O.query!==void 0&&(O.query=String(O.query).replace(D.PCT_ENCODED,ee).replace(D.NOT_QUERY,he).replace(D.PCT_ENCODED,C)),O.fragment!==void 0&&(O.fragment=String(O.fragment).replace(D.PCT_ENCODED,ee).replace(D.NOT_FRAGMENT,he).replace(D.PCT_ENCODED,C)),O}function pe(O){return O.replace(/^0*(.*)/,"$1")||"0"}function ve(O,D){var ee=O.match(D.IPV4ADDRESS)||[],ce=c(ee,2),de=ce[1];return de?de.split(".").map(pe).join("."):O}function We(O,D){var ee=O.match(D.IPV6ADDRESS)||[],ce=c(ee,3),de=ce[1],Le=ce[2];if(de){for(var Ue=de.toLowerCase().split("::").reverse(),dt=c(Ue,2),yt=dt[0],kt=dt[1],ht=kt?kt.split(":").map(pe):[],Rt=yt.split(":").map(pe),xt=D.IPV4ADDRESS.test(Rt[Rt.length-1]),At=xt?7:8,Xt=Rt.length-At,Pt=Array(At),Ft=0;Ft1){var Zt=Pt.slice(0,qg.index),Lt=Pt.slice(qg.index+qg.length);it=Zt.join(":")+"::"+Lt.join(":")}else it=Pt.join(":");return Le&&(it+="%"+Le),it}else return O}var Be=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function Pe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee={},ce=D.iri!==!1?l:A;D.reference==="suffix"&&(O=(D.scheme?D.scheme+":":"")+"//"+O);var de=O.match(Be);if(de){Je?(ee.scheme=de[1],ee.userinfo=de[3],ee.host=de[4],ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=de[7],ee.fragment=de[8],isNaN(ee.port)&&(ee.port=de[5])):(ee.scheme=de[1]||void 0,ee.userinfo=O.indexOf("@")!==-1?de[3]:void 0,ee.host=O.indexOf("//")!==-1?de[4]:void 0,ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=O.indexOf("?")!==-1?de[7]:void 0,ee.fragment=O.indexOf("#")!==-1?de[8]:void 0,isNaN(ee.port)&&(ee.port=O.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),ee.host&&(ee.host=We(ve(ee.host,ce),ce)),ee.scheme===void 0&&ee.userinfo===void 0&&ee.host===void 0&&ee.port===void 0&&!ee.path&&ee.query===void 0?ee.reference="same-document":ee.scheme===void 0?ee.reference="relative":ee.fragment===void 0?ee.reference="absolute":ee.reference="uri",D.reference&&D.reference!=="suffix"&&D.reference!==ee.reference&&(ee.error=ee.error||"URI is not a "+D.reference+" reference.");var Le=Ie[(D.scheme||ee.scheme||"").toLowerCase()];if(!D.unicodeSupport&&(!Le||!Le.unicodeSupport)){if(ee.host&&(D.domainHost||Le&&Le.domainHost))try{ee.host=Q.toASCII(ee.host.replace(ce.PCT_ENCODED,ne).toLowerCase())}catch(Ue){ee.error=ee.error||"Host's domain name can not be converted to ASCII via punycode: "+Ue}be(ee,A)}else be(ee,ce);Le&&Le.parse&&Le.parse(ee,D)}else ee.error=ee.error||"URI can not be parsed.";return ee}function De(O,D){var ee=D.iri!==!1?l:A,ce=[];return O.userinfo!==void 0&&(ce.push(O.userinfo),ce.push("@")),O.host!==void 0&&ce.push(We(ve(String(O.host),ee),ee).replace(ee.IPV6ADDRESS,function(de,Le,Ue){return"["+Le+(Ue?"%25"+Ue:"")+"]"})),(typeof O.port=="number"||typeof O.port=="string")&&(ce.push(":"),ce.push(String(O.port))),ce.length?ce.join(""):void 0}var Qe=/^\.\.?\//,_e=/^\/\.(\/|$)/,gt=/^\/\.\.(\/|$)/,lt=/^\/?(?:.|\n)*?(?=\/|$)/;function tt(O){for(var D=[];O.length;)if(O.match(Qe))O=O.replace(Qe,"");else if(O.match(_e))O=O.replace(_e,"/");else if(O.match(gt))O=O.replace(gt,"/"),D.pop();else if(O==="."||O==="..")O="";else{var ee=O.match(lt);if(ee){var ce=ee[0];O=O.slice(ce.length),D.push(ce)}else throw new Error("Unexpected dot segment condition")}return D.join("")}function Xe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee=D.iri?l:A,ce=[],de=Ie[(D.scheme||O.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(O,D),O.host&&!ee.IPV6ADDRESS.test(O.host)){if(D.domainHost||de&&de.domainHost)try{O.host=D.iri?Q.toUnicode(O.host):Q.toASCII(O.host.replace(ee.PCT_ENCODED,ne).toLowerCase())}catch(dt){O.error=O.error||"Host's domain name can not be converted to "+(D.iri?"Unicode":"ASCII")+" via punycode: "+dt}}be(O,ee),D.reference!=="suffix"&&O.scheme&&(ce.push(O.scheme),ce.push(":"));var Le=De(O,D);if(Le!==void 0&&(D.reference!=="suffix"&&ce.push("//"),ce.push(Le),O.path&&O.path.charAt(0)!=="/"&&ce.push("/")),O.path!==void 0){var Ue=O.path;!D.absolutePath&&(!de||!de.absolutePath)&&(Ue=tt(Ue)),Le===void 0&&(Ue=Ue.replace(/^\/\//,"/%2F")),ce.push(Ue)}return O.query!==void 0&&(ce.push("?"),ce.push(O.query)),O.fragment!==void 0&&(ce.push("#"),ce.push(O.fragment)),ce.join("")}function ae(O,D){var ee=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(O=Pe(Xe(O,ee),ee),D=Pe(Xe(D,ee),ee)),ee=ee||{},!ee.tolerant&&D.scheme?(de.scheme=D.scheme,de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.userinfo!==void 0||D.host!==void 0||D.port!==void 0?(de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.path?(D.path.charAt(0)==="/"?de.path=tt(D.path):((O.userinfo!==void 0||O.host!==void 0||O.port!==void 0)&&!O.path?de.path="/"+D.path:O.path?de.path=O.path.slice(0,O.path.lastIndexOf("/")+1)+D.path:de.path=D.path,de.path=tt(de.path)),de.query=D.query):(de.path=O.path,D.query!==void 0?de.query=D.query:de.query=O.query),de.userinfo=O.userinfo,de.host=O.host,de.port=O.port),de.scheme=O.scheme),de.fragment=D.fragment,de}function ye(O,D,ee){var ce=a({scheme:"null"},ee);return Xe(ae(Pe(O,ce),Pe(D,ce),ce,!0),ce)}function He(O,D){return typeof O=="string"?O=Xe(Pe(O,D),D):r(O)==="object"&&(O=Pe(Xe(O,D),D)),O}function F(O,D,ee){return typeof O=="string"?O=Xe(Pe(O,ee),ee):r(O)==="object"&&(O=Xe(O,ee)),typeof D=="string"?D=Xe(Pe(D,ee),ee):r(D)==="object"&&(D=Xe(D,ee)),O===D}function T(O,D){return O&&O.toString().replace(!D||!D.iri?A.ESCAPE:l.ESCAPE,he)}function k(O,D){return O&&O.toString().replace(!D||!D.iri?A.PCT_ENCODED:l.PCT_ENCODED,ne)}var ie={scheme:"http",domainHost:!0,parse:function(D,ee){return D.host||(D.error=D.error||"HTTP URIs must have a host."),D},serialize:function(D,ee){var ce=String(D.scheme).toLowerCase()==="https";return(D.port===(ce?443:80)||D.port==="")&&(D.port=void 0),D.path||(D.path="/"),D}},me={scheme:"https",domainHost:ie.domainHost,parse:ie.parse,serialize:ie.serialize};function Ve(O){return typeof O.secure=="boolean"?O.secure:String(O.scheme).toLowerCase()==="wss"}var we={scheme:"ws",domainHost:!0,parse:function(D,ee){var ce=D;return ce.secure=Ve(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(D,ee){if((D.port===(Ve(D)?443:80)||D.port==="")&&(D.port=void 0),typeof D.secure=="boolean"&&(D.scheme=D.secure?"wss":"ws",D.secure=void 0),D.resourceName){var ce=D.resourceName.split("?"),de=c(ce,2),Le=de[0],Ue=de[1];D.path=Le&&Le!=="/"?Le:void 0,D.query=Ue,D.resourceName=void 0}return D.fragment=void 0,D}},je={scheme:"wss",domainHost:we.domainHost,parse:we.parse,serialize:we.serialize},at={},bt="[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)),re="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=I(E,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ye=new RegExp(bt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(I("[^]",re,"[\\.]",'[\\"]',_),"g"),Ce=new RegExp(I("[^]",bt,fe),"g"),oe=Ce;function Re(O){var D=ne(O);return D.match(Ye)?D:O}var xe={scheme:"mailto",parse:function(D,ee){var ce=D,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Le=!1,Ue={},dt=ce.query.split("&"),yt=0,kt=dt.length;yt=55296&&r<=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(r="data"+(g-I||""),!n)return r}for(var o=r,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 b$e(e,g,i){var I=Ybe.call(this,e,g,i);I>=0&&this._compilations.splice(I,1)}function Ybe(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,xbe=/^(?:(?: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,Ebe=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,Mbe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,zbe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,Pbe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,H$e=xT;function xT(e){return e=e=="full"?"full":"fast",S$e.copy(xT[e])}xT.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":Dbe,url:xbe,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:Fbe,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:Ebe,"json-pointer":Mbe,"json-pointer-uri-fragment":zbe,"relative-json-pointer":Pbe};xT.full={date:Jbe,time:Obe,"date-time":k$e,uri:K$e,"uri-reference":X$e,"uri-template":Dbe,url:xbe,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:Fbe,ip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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:_be,uuid:Ebe,"json-pointer":Mbe,"json-pointer-uri-fragment":zbe,"relative-json-pointer":Pbe};function T$e(e){return e%4===0&&(e%100!==0||e%400===0)}function Jbe(e){var g=e.match(w$e);if(!g)return!1;var i=+g[1],I=+g[2],n=+g[3];return I>=1&&I<=12&&n>=1&&n<=(I==2&&T$e(i)?29:R$e[I])}function Obe(e,g){var i=e.match(V$e);if(!i)return!1;var I=i[1],n=i[2],r=i[3],C=i[5];return(I<=23&&n<=59&&r<=59||I==23&&n==59&&r==60)&&(!g||C)}var N$e=/t|\s/i;function k$e(e){var g=e.split(N$e);return g.length==2&&Jbe(g[0])&&Obe(g[1],!0)}var Y$e=/\/|:/;function K$e(e){return Y$e.test(e)&&W$e.test(e)}var F$e=/[^\\]\\Z/;function _be(e){if(F$e.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var D$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.errSchemaPath+"/"+i,s=!g.opts.allErrors,A="data"+(C||""),l="valid"+r,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=C?"data"+(C-1||""):"parentData",B=C?g.dataPathArr[C]:"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},x$e=function(g,i,I){var n=" ",r=g.schema[i],C=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=r;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=C+"["+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},E$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,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 R=n;return n=w.pop(),!g.compositeRule&&A?g.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; } "),g.opts.allErrors&&(n+=" } "),n},J$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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"+r+";";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,R=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=P,n+=" } ",A&&(n+=" if ("+h+") { ",d+="}"))}return A&&(n+=" "+d+" if ("+c+" == errors) {"),n},O$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u=g.opts.$data&&o&&o.$data;u&&(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ");var d="i"+r,h="schema"+r;u||(n+=" var "+h+" = validate.schema"+a+";"),n+="var "+c+";",u&&(n+=" if (schema"+r+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+r+")) "+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"+r+" } ",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},_$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||"");if(g.opts.format===!1)return A&&(n+=" if (true) { "),n;var c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):u=o;var d=g.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+r,f="isObject"+r,b="formatType"+r;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"+r+" = "+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"+r+" ? 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},L$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,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"+r,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"+r,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},U$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f="i"+r,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 R,S=-1,X=w.length-1;S0||R===!1:g.util.schemaHasRules(R,g.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=g.util.getPathExpr(g.errorPath,S,g.opts.jsonPointers,!0),d.dataPathArr[b]=S;var V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",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 V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",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 V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",A&&(n+=" if (!"+m+") break; "),n+=" }"}return A&&(n+=" "+h+" if ("+u+" == errors) {"),n},Lte=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,y,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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,C,g.dataPathArr),B="exclusive"+r,G="exclType"+r,v="exclIsNumber"+r,w="op"+r,R="' + "+w+" + '";n+=" var schemaExcl"+r+" = "+Z+"; ",Z="schemaExcl"+r,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"+r+" = "+B+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=g.errSchemaPath+"/"+h,u=Z,c=f)}else{var v=typeof m=="number",R=b;if(v&&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{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,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="",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 "+R+" ",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},Ute=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},Qte=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},jte=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},Q$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):u=o,!(c||typeof o=="number"))throw new Error(i+" must be number");n+="var division"+r+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+r+" = "+l+" / "+u+", ",g.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+r+") - division"+r+") > 1e-"+g.opts.multipleOfPrecision+" ":n+=" division"+r+" !== parseInt(division"+r+") ",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},j$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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},$$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+r,p="passingSchemas"+r;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},q$e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},e8e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m="key"+r,f="idx"+r,b=u.dataLevel=g.dataLevel+1,p="data"+b,y="dataProperties"+r,Z=Object.keys(o||{}).filter(x),B=g.schema.patternProperties||{},G=Object.keys(B).filter(x),v=g.schema.additionalProperties,w=Z.length||G.length,R=v===!1,S=typeof v=="object"&&Object.keys(v).length,X=g.opts.removeAdditional,W=R||S||X,V=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 J=Z;if(J)for(var P,ge=-1,q=J.length-1;ge0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var gt=g.util.getProperty(P),We=l+gt,lt=Je&&_e.default!==void 0;u.schema=_e,u.schemaPath=a+gt,u.errSchemaPath=s+"/"+g.util.escapeFragment(P),u.errorPath=g.util.getPath(g.errorPath,P,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(P);var Be=g.validate(u);if(u.baseId=H,g.util.varOccurences(Be,p)<2){Be=g.util.varReplace(Be,p,We);var tt=We}else{var tt=p;n+=" var "+p+" = "+We+"; "}if(lt)n+=" "+Be+" ";else{if(K&&K[P]){n+=" if ( "+tt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = false; ";var Ie=g.errorPath,ne=s,Xe=g.util.escapeQuotes(P);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(Ie,P,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var be=be||[];be.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Xe+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Xe+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+a+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var pe=n;n=be.pop(),!g.compositeRule&&A?g.async?n+=" throw new ValidationError(["+pe+"]); ":n+=" validate.errors = ["+pe+"]; return false; ":n+=" var err = "+pe+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=ne,g.errorPath=Ie,n+=" } else { "}else A?(n+=" if ( "+tt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+tt+" !== undefined ",V&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=" ) { ");n+=" "+Be+" } "}}A&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var ae=G;if(ae)for(var j,ye=-1,He=ae.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),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 ("+g.usePattern(j)+".test("+m+")) { ",u.errorPath=g.util.getPathExpr(g.errorPath,m,g.opts.jsonPointers);var We=l+"["+m+"]";u.dataPathArr[b]=m;var Be=g.validate(u);u.baseId=H,g.util.varOccurences(Be,p)<2?n+=" "+g.util.varReplace(Be,p,We)+" ":n+=" var "+p+" = "+We+"; "+Be+" ",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},t8e=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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"+r,f="idx"+r,b="i"+r,p="' + "+m+" + '",y=u.dataLevel=g.dataLevel+1,Z="data"+y,B="dataProperties"+r,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"+r+" = errors; ";var w=m,R=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=R,n+=" if (!"+h+") { for (var "+b+"=startErrs"+r+"; "+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"+r+"; ",B){u||(n+=" var "+d+" = validate.schema"+a+"; ");var v="i"+r,w="schema"+r+"["+v+"]",R="' + "+w+" + '";g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPathExpr(Z,w,g.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+r+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+r+")) "+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: '"+R+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+R+"\\'",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 V,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},I8e={$ref:D$e,allOf:x$e,anyOf:E$e,$comment:M$e,const:z$e,contains:P$e,dependencies:J$e,enum:O$e,format:_$e,if:L$e,items:U$e,maximum:Lte,minimum:Lte,maxItems:Ute,minItems:Ute,maxLength:Qte,minLength:Qte,maxProperties:jte,minProperties:jte,multipleOf:Q$e,not:j$e,oneOf:$$e,pattern:q$e,properties:e8e,propertyNames:t8e,required:g8e,uniqueItems:i8e,validate:Nbe},$te=I8e,h5=k0.toHash,n8e=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=h5(i),g.types=h5(n),g.forEach(function(r){r.rules=r.rules.map(function(C){var o;if(typeof C=="object"){var a=Object.keys(C)[0];o=C[a],C=a,o.forEach(function(A){i.push(A),g.all[A]=!0})}i.push(C);var s=g.all[C]={keyword:C,code:$te[C],implements:o};return s}),g.all.$comment={keyword:"$comment",code:$te.$comment},r.type&&(g.types[r.type]=r)}),g.keywords=h5(i.concat(I)),g.custom={},g},qte=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],r8e=function(e,g){for(var i=0;i{g(i,I,n),P9(i,g)}):"views"in e&&e.views.forEach(i=>P9(i,g))}function bb(e,g){"tracks"in e?e.tracks.forEach(i=>{g(i),bb(i,g)}):"views"in e&&e.views.forEach(i=>{g(i),bb(i,g)})}function i0e(e,g){"tracks"in e||(g(e),e.views.forEach(i=>{i0e(i,g)}))}function I0e(e){if(Sbe(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 Zje(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 y3(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=f5(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=Zbe),e.spacing===void 0&&(e.spacing=Y1),"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=ln()),"tracks"in e){let i=I0e(e);i=Bbe(i);const I=ln();i.forEach((n,r,C)=>{var o,a,s;if(n.id||(n.id=ln()),n.width||(n.width=Ir(n)?Dte:D4e),n.height||(n.height=Ir(n)?Dte:F4e),"displacement"in n)if(((o=n.displacement)==null?void 0:o.type)==="pile"&&n.row===void 0&&ut(n.x)&&n.x.field&&ut(n.xe)&&n.xe.field){const A=ln(),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"&&XS(n)){n._invalidTrack=!0;return}if(n.style=f5(e.style,n.style),uI(n)&&(n._overlay=n._overlay.filter(A=>!("type"in A&&A.type=="dummy-track")),n._overlay.forEach(A=>{A.style=f5(n.style,A.style)})),(n.layout==="circular"||Ir(n))&&n.orientation==="vertical"&&(n.orientation="horizontal"),Ir(n)&&(n.layout="linear",(DC(n)||uI(n))&&ut(n.y)&&!n.y.domain?n.y.domain=e.yDomain:uI(n)&&n._overlay.forEach(A=>{ut(A.y)&&!A.y.domain&&(A.y.domain=e.yDomain)})),(DC(n)||uI(n))&&ut(n.x)&&!n.x.domain?n.x.domain=e.xDomain:uI(n)&&n._overlay.forEach(A=>{ut(A.x)&&!A.x.domain&&(A.x.domain=e.xDomain)}),(DC(n)||uI(n))&&ut(n.x)&&!n.x.linkingId)n.x.linkingId=(s=e.linkingId)!=null?s:I;else if(uI(n)){let A=!1;n._overlay.forEach(l=>{var c;A||ut(l.x)&&!l.x.linkingId&&(l.x.linkingId=(c=e.linkingId)!=null?c:I,A=!0)})}r===0&&(n.overlayOnPreviousTrack=!1),(r===0||r!==0&&i.slice(0,r).filter(A=>!A.overlayOnPreviousTrack).length===1&&n.overlayOnPreviousTrack===!0)&&((DC(n)||uI(n))&&ut(n.x)&&!n.x.axis?n.orientation==="vertical"?n.x.axis="left":n.x.axis="top":uI(n)&&n._overlay.forEach(A=>{ut(A.x)&&!A.x.axis&&(n.orientation==="vertical"?A.x.axis="left":A.x.axis="top")})),(DC(n)||uI(n))&&ut(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"):uI(n)&&n._overlay.forEach(A=>{ut(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"))}),r!==0&&(r===C.length-1&&C.slice(0,r+1).filter(A=>A.overlayOnPreviousTrack).lengthA.overlayOnPreviousTrack).length===C.length-r-1&&C.slice(0,r+1).filter(A=>A.overlayOnPreviousTrack).length{A.mark==="withinLink"&&A.flipY===void 0&&(A.flipY=!0)}))),n.overlayOnPreviousTrack&&C[r-1]&&(n.width=C[r-1].width,n.height=C[r-1].height,n.layout=C[r-1].layout,n.assembly=C[r-1].assembly)}),i=i.filter(n=>!n._invalidTrack),e.tracks=i}else e.views.forEach(i=>{y3(i,e)})}function a6e(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 A6e(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 s6e(e){P9(e,(g,i,I)=>{var n,r,C,o,a;if(!(!("data"in g)||!g.data||!A7(g.data))&&!("alignment"in g)&&Gje(g))switch(g.data.type){case"vector":case"bigwig":I[i]=Object.assign(a6e((n=g.data.column)!=null?n:"position",(r=g.data.value)!=null?r:"value"),g);break;case"multivec":I[i]=Object.assign(A6e((C=g.data.row)!=null?C:"category",(o=g.data.column)!=null?o:"position",(a=g.data.value)!=null?a:"value",g.data.categories),g);break}})}const p5={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},y5={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},Z5={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},G5={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},B5={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 Lu(e,g,i=!1){const I=Object.entries(bi(g).interval),n={chromosome:"unknown",position:1/0},r={chromosome:"unknown",position:0};for(const C of I){const[o,a]=C,[s,A]=a;if(s<=e&&er.position&&(r.chromosome=o,r.position=A)}return i?eI.join(" ")).join(` +`),i=new Blob([g],{type:"text/tsv"});return URL.createObjectURL(i)}function bi(e){if(e&&typeof e=="string"&&e in S5)return S5[e];if(Array.isArray(e)&&e.length!==0){const g=Object.fromEntries(e);return{size:g,interval:Wl(g),total:Xl(g),path:l6e(e)}}else return S5.hg38}const pl=e=>`https://s3.amazonaws.com/gosling-lang.org/data/${e}.chrom.sizes`,S5=Object.freeze({hg38:{size:p5,interval:Wl(p5),total:Xl(p5),path:pl("hg38")},hg19:{size:b5,interval:Wl(b5),total:Xl(b5),path:pl("hg19")},hg18:{size:y5,interval:Wl(y5),total:Xl(y5),path:pl("hg18")},hg17:{size:Z5,interval:Wl(Z5),total:Xl(Z5),path:pl("hg17")},hg16:{size:G5,interval:Wl(G5),total:Xl(G5),path:pl("hg16")},mm10:{size:v5,interval:Wl(v5),total:Xl(v5),path:pl("mm10")},mm9:{size:B5,interval:Wl(B5),total:Xl(B5),path:pl("mm9")},unknown:{size:{chr:Number.MAX_VALUE},interval:{chr:[0,Number.MAX_VALUE]},total:Number.MAX_VALUE,path:pl("hg38")}});function c6e(e){switch(e){case"hg19":return"OHJakQICQD6gTD7skx4EWA";case"mm10":return"QDutvmyiSrec5nX4pA5WGQ";case"mm9":return"GUm5aBiLRCyz2PsBea7Yzg";case"hg38":default:return"P0PLbQMwTYGy-5uPIQid7A"}}function Wl(e){const g={};return Object.keys(e).reduce((i,I)=>(g[I]=[i,i+e[I]],i+e[I]),0),g}function Xl(e){return Object.values(e).reduce((g,i)=>g+i,0)}function u6e(e){const[g,i]=e.split(":");if(i){const[I,n]=i.split("-").map(r=>+r.replace(/,/g,""));if(!Number.isNaN(I)&&!Number.isNaN(n))return{chromosome:g,start:I,end:n}}return{chromosome:g}}class b7{constructor(g,i,I){this.chromosome=g,this.start=i,this.end=I}static fromString(g){const i=u6e(g);return new b7(i.chromosome,i.start,i.end)}toAbsoluteCoordinates(g,i=0){const I=bi(g),n=I.size[this.chromosome],r=I.interval[this.chromosome];if(n===void 0||r===void 0)throw new Error(`Chromosome name ${this.chromosome} is not valid`);let{start:C,end:o}=this;(C===void 0||o===void 0)&&([C,o]=[1,n]);const a=r[0];return[C+a-i,o+a+i]}}function n0e(e,[g,i],I){const{x:n,xe:r,x1:C,x1e:o}=I,a=[n,r,C,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}})}OU(e=>e.pos).left;function Z3(e,g,i){return Array.isArray(g)||(i?e=e.replace(i,"chr"):e.includes("chr")||(e=`chr${e}`)),e}class r0e extends ybe{constructor(){super(...arguments),K4e(this,"read",async(g,i=0,I,n=0,r={})=>{const{headers:C={},signal:o,overrides:a={}}=r;I<1/0?C.range=`bytes=${n}-${n+I}`:I===1/0&&n!==0&&(C.range=`bytes=${n}-`);const s={...this.baseOverrides,...a,headers:{...C,...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 gge=()=>Math.random().toString(36).substring(2,8),d6e=(e,{force:g=!1}={})=>{let i=gge();for(;window.higlassTracks[i];)i=gge();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},h6e=(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},wu=(e,g={})=>{const{pluginType:i="track"}=g;i==="track"?d6e(e,g):i==="dataFetcher"&&h6e(e,g)};var TS={},G3={exports:{}},ige=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof window.msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto);if(ige){var Ige=new Uint8Array(16);G3.exports=function(){return ige(Ige),Ige}}else{var nge=new Array(16);G3.exports=function(){for(var g=0,i;g<16;g++)g&3||(i=Math.random()*4294967296),nge[g]=i>>>((g&3)<<3)&255;return nge}}var m6e=G3.exports,C0e=[];for(var jR=0;jR<256;++jR)C0e[jR]=(jR+256).toString(16).substr(1);function f6e(e,g){var i=g||0,I=C0e;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 p6e=f6e,b6e=m6e,y6e=p6e;function Z6e(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||b6e)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,g)for(var r=0;r<16;++r)g[I+r]=n[r];return g||y6e(n)}var G6e=Z6e,v3=[],o0e={};for(var Ym=0;Ym<256;Ym++)v3[Ym]=(Ym+256).toString(16).substr(1),o0e[v3[Ym]]=Ym;function v6e(e,g,i){var I=g&&i||0,n=0;for(g=g||[],e.toLowerCase().replace(/[0-9a-f]{2}/g,function(r){n<16&&(g[I+n++]=o0e[r])});n<16;)g[I+n++]=0;return g}function B6e(e,g){var i=g||0,I=v3;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 S6e={parse:v6e,unparse:B6e},a0e=G6e,A0e=S6e;TS.encode=function(e){var g=A0e.parse(e),i=new Buffer(g).toString("base64"),I=i.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};TS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return A0e.unparse(new Buffer(g,"base64"))};TS.v4=function(){var e=a0e(null,new Buffer(16)),g=e.toString("base64"),i=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};TS.nice=function(){var e=a0e(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 w6e=TS;const R6e=Qc(w6e);var V6e=function(){function e(g,i){for(var I=0;I1?i-1:0),n=1;ni;){if(I-i>600){var r=I-i+1,C=g-i+1,o=Math.log(r),a=.5*Math.exp(2*o/3),s=.5*Math.sqrt(o*a*(r-a)/r)*(C-r/2<0?-1:1),A=Math.max(i,Math.floor(g-C*a/r+s)),l=Math.min(I,Math.floor(g+(r-C)*a/r+s));s0e(e,g,A,l,n)}var c=e[g],u=i,d=I;for(Py(e,i,g),n(e[I],c)>0&&Py(e,i,I);u0;)d--}n(e[i],c)===0?Py(e,i,d):(d++,Py(e,d,I)),d<=g&&(i=d+1),g<=d&&(I=d-1)}}function Py(e,g,i){var I=e[g];e[g]=e[i],e[i]=I}function D6e(e,g){return eg?1:0}class x6e{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(!qR(g,i))return I;const n=this.toBBox,r=[];for(;i;){for(let C=0;C=0&&r[i].children.length>this._maxEntries;)this._split(r,i),i--;this._adjustParentBBoxes(n,r,i)}_split(g,i){const I=g[i],n=I.children.length,r=this._minEntries;this._chooseSplitAxis(I,r,n);const C=this._chooseSplitIndex(I,r,n),o=mf(I.children.splice(C,I.children.length-C));o.height=I.height,o.leaf=I.leaf,Km(I,this.toBBox),Km(o,this.toBBox),i?g[i-1].children.push(o):this._splitRoot(I,o)}_splitRoot(g,i){this.data=mf([g,i]),this.data.height=g.height+1,this.data.leaf=!1,Km(this.data,this.toBBox)}_chooseSplitIndex(g,i,I){let n,r=1/0,C=1/0;for(let o=i;o<=I-i;o++){const a=FZ(g,0,o,this.toBBox),s=FZ(g,o,I,this.toBBox),A=J6e(a,s),l=w5(a)+w5(s);A=i;s--){const A=g.children[s];DZ(o,g.leaf?r(A):A),a+=$R(o)}return a}_adjustParentBBoxes(g,i,I){for(let n=I;n>=0;n--)DZ(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():Km(g[i],this.toBBox)}}function E6e(e,g,i){if(!i)return g.indexOf(e);for(let I=0;I=e.minX&&g.maxY>=e.minY}function mf(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function rge(e,g,i,I,n){const r=[g,i];for(;r.length;){if(i=r.pop(),g=r.pop(),i-g<=I)continue;const C=g+Math.ceil((i-g)/I/2)*I;F6e(e,C,g,i,n),r.push(g,C,C,i)}}function O6e(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function J9(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 S3(e){return e=J9(Math.abs(e)),e?e[1]:NaN}function _6e(e,g){return function(i,I){for(var n=i.length,r=[],C=0,o=e[0],a=0;n>0&&o>0&&(a+o+1>I&&(o=Math.max(1,I-a)),r.push(i.substring(n-=o,n+o)),!((a+=o+1)>I));)o=e[C=(C+1)%e.length];return r.reverse().join(g)}}function L6e(e){return function(g){return g.replace(/[0-9]/g,function(i){return e[+i]})}}var U6e=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function w3(e){if(!(g=U6e.exec(e)))throw new Error("invalid format: "+e);var g;return new y7({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]})}w3.prototype=y7.prototype;function y7(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+""}y7.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 Q6e(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 l0e;function j6e(e,g){var i=J9(e,g);if(!i)return e+"";var I=i[0],n=i[1],r=n-(l0e=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,C=I.length;return r===C?I:r>C?I+new Array(r-C+1).join("0"):r>0?I.slice(0,r)+"."+I.slice(r):"0."+new Array(1-r).join("0")+J9(e,Math.max(0,g+r-1))[0]}function Cge(e,g){var i=J9(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 oge={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:O6e,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)=>Cge(e*100,g),r:Cge,s:j6e,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function age(e){return e}var Age=Array.prototype.map,sge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function $6e(e){var g=e.grouping===void 0||e.thousands===void 0?age:_6e(Age.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+"",r=e.numerals===void 0?age:L6e(Age.call(e.numerals,String)),C=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=w3(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"):oge[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)?C:"",v=oge[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=B,W=G,V,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=Q6e(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?sge[8+l0e/3]:"")+W+(K&&d==="("?")":""),w){for(V=-1,H=S.length;++VY||Y>57){W=(Y===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=g(S,1/0));var x=X.length+S.length+W.length,J=x>1)+X+S+W+J.slice(x);break;default:S=J+X+S+W;break}return r(S)}return R.toString=function(){return l+""},R}function A(l,c){var u=s((l=w3(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(S3(c)/3)))*3,h=Math.pow(10,-d),m=sge[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var eV,c0e,u0e;q6e({thousands:",",grouping:[3],currency:["$",""]});function q6e(e){return eV=$6e(e),c0e=eV.format,u0e=eV.formatPrefix,eV}function eqe(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(S3(g)/3)))*3-S3(Math.abs(e)))}const R3=Math.PI,V3=2*R3,Uu=1e-6,tqe=V3-Uu;function W3(){this._x0=this._y0=this._x1=this._y1=null,this._=""}function d0e(){return new W3}W3.prototype=d0e.prototype={constructor:W3,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,r){this._+="C"+ +e+","+ +g+","+ +i+","+ +I+","+(this._x1=+n)+","+(this._y1=+r)},arcTo:function(e,g,i,I,n){e=+e,g=+g,i=+i,I=+I,n=+n;var r=this._x1,C=this._y1,o=i-e,a=I-g,s=r-e,A=C-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>Uu)if(!(Math.abs(A*o-a*s)>Uu)||!n)this._+="L"+(this._x1=e)+","+(this._y1=g);else{var c=i-r,u=I-C,d=o*o+a*a,h=c*c+u*u,m=Math.sqrt(d),f=Math.sqrt(l),b=n*Math.tan((R3-Math.acos((d+l-h)/(2*m*f)))/2),p=b/f,y=b/m;Math.abs(p-1)>Uu&&(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,r){e=+e,g=+g,i=+i,r=!!r;var C=i*Math.cos(I),o=i*Math.sin(I),a=e+C,s=g+o,A=1^r,l=r?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)>Uu||Math.abs(this._y1-s)>Uu)&&(this._+="L"+a+","+s),i&&(l<0&&(l=l%V3+V3),l>tqe?this._+="A"+i+","+i+",0,1,"+A+","+(e-C)+","+(g-o)+"A"+i+","+i+",0,1,"+A+","+(this._x1=a)+","+(this._y1=s):l>Uu&&(this._+="A"+i+","+i+",0,"+ +(l>=R3)+","+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 bl(e){return function(){return e}}var lge=Math.abs,vn=Math.atan2,Ru=Math.cos,gqe=Math.max,V5=Math.min,Ra=Math.sin,gp=Math.sqrt,Gr=1e-12,RB=Math.PI,O9=RB/2,iqe=2*RB;function Iqe(e){return e>1?0:e<-1?RB:Math.acos(e)}function cge(e){return e>=1?O9:e<=-1?-O9:Math.asin(e)}function nqe(e){return e.innerRadius}function rqe(e){return e.outerRadius}function Cqe(e){return e.startAngle}function oqe(e){return e.endAngle}function aqe(e){return e&&e.padAngle}function Aqe(e,g,i,I,n,r,C,o){var a=i-e,s=I-g,A=C-n,l=o-r,c=l*a-A*s;if(!(c*cV*V+H*H&&(v=R,w=S),{cx:v,cy:w,x01:-A,y01:-l,x11:v*(n/Z-1),y11:w*(n/Z-1)}}function sqe(){var e=nqe,g=rqe,i=bl(0),I=null,n=Cqe,r=oqe,C=aqe,o=null;function a(){var s,A,l=+e.apply(this,arguments),c=+g.apply(this,arguments),u=n.apply(this,arguments)-O9,d=r.apply(this,arguments)-O9,h=lge(d-u),m=d>u;if(o||(o=s=d0e()),cGr))o.moveTo(0,0);else if(h>iqe-Gr)o.moveTo(c*Ru(u),c*Ra(u)),o.arc(0,0,c,u,d,!m),l>Gr&&(o.moveTo(l*Ru(d),l*Ra(d)),o.arc(0,0,l,d,u,m));else{var f=u,b=d,p=u,y=d,Z=h,B=h,G=C.apply(this,arguments)/2,v=G>Gr&&(I?+I.apply(this,arguments):gp(l*l+c*c)),w=V5(lge(c-l)/2,+i.apply(this,arguments)),R=w,S=w,X,W;if(v>Gr){var V=cge(v/l*Ra(G)),H=cge(v/c*Ra(G));(Z-=V*2)>Gr?(V*=m?1:-1,p+=V,y-=V):(Z=0,p=y=(u+d)/2),(B-=H*2)>Gr?(H*=m?1:-1,f+=H,b-=H):(B=0,f=b=(u+d)/2)}var Y=c*Ru(f),K=c*Ra(f),x=l*Ru(y),J=l*Ra(y);if(w>Gr){var P=c*Ru(b),ge=c*Ra(b),q=l*Ru(p),$=l*Ra(p),j;if(hGr?S>Gr?(X=tV(q,$,Y,K,c,S,m),W=tV(P,ge,x,J,c,S,m),o.moveTo(X.cx+X.x01,X.cy+X.y01),SGr)||!(Z>Gr)?o.lineTo(x,J):R>Gr?(X=tV(x,J,P,ge,l,-R,m),W=tV(Y,K,q,$,l,-R,m),o.lineTo(X.cx+X.x01,X.cy+X.y01),R({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 h0e={},$C={},ih={};Object.defineProperty(ih,"__esModule",{value:!0});ih.DefaultSerializer=ih.extendSerializer=void 0;function cqe(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)}}}ih.extendSerializer=cqe;const uge={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}}},uqe=e=>e&&typeof e=="object"&&"__error_marker"in e&&e.__error_marker==="$$error";ih.DefaultSerializer={deserialize(e){return uqe(e)?uge.deserialize(e):e},serialize(e){return e instanceof Error?uge.serialize(e):e}};Object.defineProperty($C,"__esModule",{value:!0});$C.serialize=$C.deserialize=$C.registerSerializer=void 0;const m0e=ih;let _9=m0e.DefaultSerializer;function dqe(e){_9=m0e.extendSerializer(_9,e)}$C.registerSerializer=dqe;function hqe(e){return _9.deserialize(e)}$C.deserialize=hqe;function mqe(e){return _9.serialize(e)}$C.serialize=mqe;var f0e={},Rs={},yb={};Object.defineProperty(yb,"__esModule",{value:!0});yb.getBundleURL=yb.getBaseURL=void 0;let W5;function fqe(){return W5||(W5=pqe()),W5}yb.getBundleURL=fqe;function pqe(){try{throw new Error}catch(e){const g=(""+e.stack).match(/(https?|file|ftp|chrome-extension|moz-extension):\/\/[^)\n]+/g);if(g)return p0e(g[0])}return"/"}function p0e(e){return(""+e).replace(/^((?:https?|file|ftp|chrome-extension|moz-extension):\/\/.+)?\/[^/]+(?:\?.*)?$/,"$1")+"/"}yb.getBaseURL=p0e;Object.defineProperty(Rs,"__esModule",{value:!0});Rs.isWorkerRuntime=Rs.getWorkerImplementation=Rs.defaultPoolSize=void 0;const dge=yb;Rs.defaultPoolSize=typeof navigator<"u"&&navigator.hardwareConcurrency?navigator.hardwareConcurrency:4;const hge=e=>/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(e);function mge(e){const g=new Blob([e],{type:"application/javascript"});return URL.createObjectURL(g)}function bqe(){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 r,C;typeof I=="string"&&n&&n._baseURL?I=new URL(I,n._baseURL):typeof I=="string"&&!hge(I)&&dge.getBundleURL().match(/^file:\/\//i)&&(I=new URL(I,dge.getBundleURL().replace(/\/[^\/]+$/,"/")),(!((r=n==null?void 0:n.CORSWorkaround)!==null&&r!==void 0)||r)&&(I=mge(`importScripts(${JSON.stringify(I)});`))),typeof I=="string"&&hge(I)&&(!((C=n==null?void 0:n.CORSWorkaround)!==null&&C!==void 0)||C)&&(I=mge(`importScripts(${JSON.stringify(I)});`)),super(I,n)}}class g extends e{constructor(I,n){const r=window.URL.createObjectURL(I);super(r,n)}static fromText(I,n){const r=new window.Blob([I],{type:"text/javascript"});return new g(r,n)}}return{blob:g,default:e}}let X5;function yqe(){return X5||(X5=bqe()),X5}Rs.getWorkerImplementation=yqe;function Zqe(){const e=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!e)}Rs.isWorkerRuntime=Zqe;var b0e={},X3={exports:{}},H5,fge;function Gqe(){if(fge)return H5;fge=1;var e=1e3,g=e*60,i=g*60,I=i*24,n=I*7,r=I*365.25;H5=function(A,l){l=l||{};var c=typeof A;if(c==="string"&&A.length>0)return C(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 C(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*r;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 H5}function vqe(e){i.debug=i,i.default=i,i.coerce=a,i.disable=r,i.enable=n,i.enabled=C,i.humanize=Gqe(),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 C(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 r(){let a;try{a=g.storage.getItem("debug")}catch{}return!a&&typeof process<"u"&&"env"in process&&(a={}.DEBUG),a}function C(){try{return localStorage}catch{}}e.exports=Bqe(g);const{formatters:o}=e.exports;o.j=function(a){try{return JSON.stringify(a)}catch(s){return"[UnexpectedJSONParseError]: "+s.message}}})(X3,X3.exports);var Z7=X3.exports,Sqe=globalThis&&globalThis.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(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=C=>I.push(C),r=Promise.resolve().then(()=>Sqe(this,void 0,void 0,function*(){yield i,yield g(n),this._pendingPromises.delete(r);for(const C of I)this._baseObserver.next(C)})).catch(C=>{this._pendingPromises.delete(r),this._baseObserver.error(C)});this._pendingPromises.add(r)}}const y0e=()=>typeof Symbol=="function",NS=e=>y0e()&&!!Symbol[e],G7=e=>NS(e)?Symbol[e]:"@@"+e;NS("asyncIterator")||(Symbol.asyncIterator=Symbol.asyncIterator||Symbol.for("Symbol.asyncIterator"));const wqe=G7("iterator"),H3=G7("observable"),Z0e=G7("species");function L9(e,g){const i=e[g];if(i!=null){if(typeof i!="function")throw new TypeError(i+" is not a function");return i}}function Jy(e){let g=e.constructor;return g!==void 0&&(g=g[Z0e],g===null&&(g=void 0)),g!==void 0?g:Ih}function Rqe(e){return e instanceof Ih}function Zb(e){Zb.log?Zb.log(e):setTimeout(()=>{throw e},0)}function D1(e){Promise.resolve().then(()=>{try{e()}catch(g){Zb(g)}})}function G0e(e){const g=e._cleanup;if(g!==void 0&&(e._cleanup=void 0,!!g))try{if(typeof g=="function")g();else{const i=L9(g,"unsubscribe");i&&i.call(g)}}catch(i){Zb(i)}}function T3(e){e._observer=void 0,e._queue=void 0,e._state="closed"}function Vqe(e){const g=e._queue;if(g){e._queue=void 0,e._state="ready";for(const i of g)if(v0e(e,i.type,i.value),e._state==="closed")break}}function v0e(e,g,i){e._state="running";const I=e._observer;try{const n=I?L9(I,g):void 0;switch(g){case"next":n&&n.call(I,i);break;case"error":if(T3(e),n)n.call(I,i);else throw i;break;case"complete":T3(e),n&&n.call(I);break}}catch(n){Zb(n)}e._state==="closed"?G0e(e):e._state==="running"&&(e._state="ready")}function T5(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}],D1(()=>Vqe(e));return}v0e(e,g,i)}}let Wqe=class{constructor(g,i){this._cleanup=void 0,this._observer=g,this._queue=void 0,this._state="initializing";const I=new Xqe(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"&&(T3(this),G0e(this))}};class Xqe{constructor(g){this._subscription=g}get closed(){return this._subscription._state==="closed"}next(g){T5(this._subscription,"next",g)}error(g){T5(this._subscription,"error",g)}complete(){T5(this._subscription,"complete")}}let Ih=class xZ{constructor(g){if(!(this instanceof xZ))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 Wqe(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 xZ(r=>this.subscribe({next(C){n.next&&n.next(C),r.next(C)},error(C){n.error&&n.error(C),r.error(C)},complete(){n.complete&&n.complete(),r.complete()},start(C){n.start&&n.start(C)}}))}forEach(g){return new Promise((i,I)=>{if(typeof g!="function"){I(new TypeError(g+" is not a function"));return}function n(){r.unsubscribe(),i(void 0)}const r=this.subscribe({next(C){try{g(C,n)}catch(o){I(o),r.unsubscribe()}},error(C){I(C)},complete(){i(void 0)}})})}map(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const i=Jy(this);return new i(I=>this.subscribe({next(n){let r=n;try{r=g(n)}catch(C){return I.error(C)}I.next(r)},error(n){I.error(n)},complete(){I.complete()}}))}filter(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const i=Jy(this);return new i(I=>this.subscribe({next(n){try{if(!g(n))return}catch(r){return I.error(r)}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=Jy(this),n=arguments.length>1;let r=!1,C=i;return new I(o=>this.subscribe({next(a){const s=!r;if(r=!0,!s||n)try{C=g(C,a)}catch(A){return o.error(A)}else C=a},error(a){o.error(a)},complete(){if(!r&&!n)return o.error(new TypeError("Cannot reduce an empty sequence"));o.next(C),o.complete()}}))}concat(...g){const i=Jy(this);return new i(I=>{let n,r=0;function C(o){n=o.subscribe({next(a){I.next(a)},error(a){I.error(a)},complete(){r===g.length?(n=void 0,I.complete()):C(i.from(g[r++]))}})}return C(this),()=>{n&&(n.unsubscribe(),n=void 0)}})}flatMap(g){if(typeof g!="function")throw new TypeError(g+" is not a function");const i=Jy(this);return new i(I=>{const n=[],r=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),C()}});n.push(s)},error(o){I.error(o)},complete(){C()}});function C(){r.closed&&n.length===0&&I.complete()}return()=>{n.forEach(o=>o.unsubscribe()),r.unsubscribe()}})}[H3](){return this}static from(g){const i=typeof this=="function"?this:xZ;if(g==null)throw new TypeError(g+" is not an object");const I=L9(g,H3);if(I){const n=I.call(g);if(Object(n)!==n)throw new TypeError(n+" is not an object");return Rqe(n)&&n.constructor===i?n:new i(r=>n.subscribe(r))}if(NS("iterator")){const n=L9(g,wqe);if(n)return new i(r=>{D1(()=>{if(!r.closed){for(const C of n.call(g))if(r.next(C),r.closed)return;r.complete()}})})}if(Array.isArray(g))return new i(n=>{D1(()=>{if(!n.closed){for(const r of g)if(n.next(r),n.closed)return;n.complete()}})});throw new TypeError(g+" is not observable")}static of(...g){const i=typeof this=="function"?this:xZ;return new i(I=>{D1(()=>{if(!I.closed){for(const n of g)if(I.next(n),I.closed)return;I.complete()}})})}static get[Z0e](){return this}};y0e()&&Object.defineProperty(Ih,Symbol("extensions"),{value:{symbol:H3,hostReportError:Zb},configurable:!0});const Qh=Ih;function jh(e){typeof e=="function"?e():e&&typeof e.unsubscribe=="function"&&e.unsubscribe()}var Hqe=globalThis&&globalThis.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(A.value):n(A.value).then(o,a)}s((I=I.apply(e,g||[])).next())})};function Tqe(e){return g=>new Qh(i=>{const I=new MT(i),n=g.subscribe({complete(){I.complete()},error(r){I.error(r)},next(r){I.schedule(C=>Hqe(this,void 0,void 0,function*(){(yield e(r))&&C(r)}))}});return()=>jh(n)})}function Nqe(e){return e&&NS("asyncIterator")&&e[Symbol.asyncIterator]}function kqe(e){return e&&NS("iterator")&&e[Symbol.iterator]}var Yqe=globalThis&&globalThis.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(A.value):n(A.value).then(o,a)}s((I=I.apply(e,g||[])).next())})},Kqe=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(r){i[r]=e[r]&&function(C){return new Promise(function(o,a){C=e[r](C),n(o,a,C.done,C.value)})}}function n(r,C,o,a){Promise.resolve(a).then(function(s){r({value:s,done:o})},C)}};function Fqe(e){return g=>new Qh(i=>{const I=new MT(i),n=g.subscribe({complete(){I.complete()},error(r){I.error(r)},next(r){I.schedule(C=>Yqe(this,void 0,void 0,function*(){var o,a;const s=yield e(r);if(kqe(s)||Nqe(s))try{for(var A=Kqe(s),l;l=yield A.next(),!l.done;){const c=l.value;C(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=>C(c))}))}});return()=>jh(n)})}function Dqe(e){return new Ih(g=>{let i=0;const I=setInterval(()=>{g.next(i++)},e);return()=>clearInterval(I)})}var xqe=globalThis&&globalThis.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(A.value):n(A.value).then(o,a)}s((I=I.apply(e,g||[])).next())})};function Eqe(e){return g=>new Qh(i=>{const I=new MT(i),n=g.subscribe({complete(){I.complete()},error(r){I.error(r)},next(r){I.schedule(C=>xqe(this,void 0,void 0,function*(){const o=yield e(r);C(o)}))}});return()=>jh(n)})}function Mqe(...e){return e.length===0?Ih.from([]):new Ih(g=>{let i=0;const I=e.map(r=>r.subscribe({error(C){g.error(C),n()},next(C){g.next(C)},complete(){++i===e.length&&(g.complete(),n())}})),n=()=>{I.forEach(r=>jh(r))};return n})}class zqe extends Qh{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 B0e=zqe;function Pqe(e){const g=new B0e;let i,I=0;return new Qh(n=>{i||(i=e.subscribe(g));const r=g.subscribe(n);return I++,()=>{I--,r.unsubscribe(),I===0&&(jh(i),i=void 0)}})}var Jqe=globalThis&&globalThis.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(A.value):n(A.value).then(o,a)}s((I=I.apply(e,g||[])).next())})};function Oqe(e,g){return i=>new Qh(I=>{let n,r=0;const C=new MT(I),o=i.subscribe({complete(){C.complete()},error(a){C.error(a)},next(a){C.schedule(s=>Jqe(this,void 0,void 0,function*(){n=yield e(r===0?typeof g>"u"?a:g:n,a,r++),s(n)}))}});return()=>jh(o)})}const _qe=Object.freeze(Object.defineProperty({__proto__:null,Observable:Qh,Subject:B0e,filter:Tqe,flatMap:Fqe,interval:Dqe,map:Eqe,merge:Mqe,multicast:Pqe,scan:Oqe,unsubscribe:jh},Symbol.toStringTag,{value:"Module"})),zT=Q_(_qe);var PT={};Object.defineProperty(PT,"__esModule",{value:!0});PT.allSettled=void 0;function Lqe(e){return Promise.all(e.map(g=>{const i=r=>({status:"fulfilled",value:r}),I=r=>({status:"rejected",reason:r}),n=Promise.resolve(g);try{return n.then(i,I)}catch(r){return Promise.reject(r)}}))}PT.allSettled=Lqe;var S0e={};(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={}))})(S0e);var kS={},Tr={};Object.defineProperty(Tr,"__esModule",{value:!0});Tr.$worker=Tr.$transferable=Tr.$terminate=Tr.$events=Tr.$errors=void 0;Tr.$errors=Symbol("thread.errors");Tr.$events=Symbol("thread.events");Tr.$terminate=Symbol("thread.terminate");Tr.$transferable=Symbol("thread.transferable");Tr.$worker=Symbol("thread.worker");Object.defineProperty(kS,"__esModule",{value:!0});kS.Thread=void 0;const N5=Tr;function pge(e){throw Error(e)}kS.Thread={errors(e){return e[N5.$errors]||pge("Error observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},events(e){return e[N5.$events]||pge("Events observable not found. Make sure to pass a thread instance as returned by the spawn() promise.")},terminate(e){return e[N5.$terminate]()}};(function(e){var g=yi&&yi.__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{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?B(S.value):Z(S.value).then(v,w)}R((y=y.apply(f,b||[])).next())})},i=yi&&yi.__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(Z7),n=zT,r=PT,C=Rs,o=S0e;Object.defineProperty(e,"PoolEventType",{enumerable:!0,get:function(){return o.PoolEventType}});const a=kS;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=C.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 r.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 r.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})(b0e);var JT={},OT={};Object.defineProperty(OT,"__esModule",{value:!0});OT.createPromiseWithResolver=void 0;const Uqe=()=>{};function Qqe(){let e=!1,g,i=Uqe;return[new Promise(r=>{e?r(g):i=r}),r=>{e=!0,g=r,i(g)}]}OT.createPromiseWithResolver=Qqe;var w0e={};(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={}))})(w0e);var Gb={},_T={};Object.defineProperty(_T,"__esModule",{value:!0});_T.ObservablePromise=void 0;const jqe=zT,$qe=()=>{},qqe=e=>e,bge=e=>Promise.resolve().then(e);function eet(e){throw e}function tet(e){return e&&typeof e.then=="function"}class v7 extends jqe.Observable{constructor(g){super(i=>{const I=this,n=Object.assign(Object.assign({},i),{complete(){i.complete(),I.onCompletion()},error(r){i.error(r),I.onError(r)},next(r){i.next(r),I.onNext(r)}});try{return this.initHasRun=!0,g(n)}catch(r){n.error(r)}}),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)bge(()=>i(g))}onCompletion(){this.state="fulfilled";for(const g of this.fulfillmentCallbacks)bge(()=>g(this.firstValue))}then(g,i){const I=g||qqe,n=i||eet;let r=!1;return new Promise((C,o)=>{const a=A=>{if(!r){r=!0;try{C(n(A))}catch(l){o(l)}}},s=A=>{try{C(I(A))}catch(l){a(l)}};if(this.initHasRun||this.subscribe({error:a}),this.state==="fulfilled")return C(I(this.firstValue));if(this.state==="rejected")return r=!0,C(n(this.rejection));this.fulfillmentCallbacks.push(s),this.rejectionCallbacks.push(a)})}catch(g){return this.then(void 0,g)}finally(g){const i=g||$qe;return this.then(I=>(i(),I),()=>i())}static from(g){return tet(g)?new v7(i=>{const I=r=>{i.next(r),i.complete()},n=r=>{i.error(r)};g.then(I,n)}):super.from(g)}}_T.ObservablePromise=v7;var Ds={};Object.defineProperty(Ds,"__esModule",{value:!0});Ds.Transfer=Ds.isTransferDescriptor=void 0;const R0e=Tr;function get(e){return!(!e||typeof e!="object")}function iet(e){return e&&typeof e=="object"&&e[R0e.$transferable]}Ds.isTransferDescriptor=iet;function Iet(e,g){if(!g){if(!get(e))throw Error();g=[e]}return{[R0e.$transferable]:!0,send:e,transferables:g}}Ds.Transfer=Iet;var B7={};(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={}))})(B7);var net=yi&&yi.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Gb,"__esModule",{value:!0});Gb.createProxyModule=Gb.createProxyFunction=void 0;const ret=net(Z7),V0e=zT,MG=$C,yge=_T,Cet=Ds,YS=B7,W0e=ret.default("threads:master:messages");let oet=1;const aet=e=>Array.from(new Set(e)),Aet=e=>e&&e.type===YS.WorkerMessageType.error,set=e=>e&&e.type===YS.WorkerMessageType.result,cet=e=>e&&e.type===YS.WorkerMessageType.running;function uet(e,g){return new V0e.Observable(i=>{let I;const n=r=>{if(W0e("Message from worker:",r.data),!(!r.data||r.data.uid!==g)){if(cet(r.data))I=r.data.resultType;else if(set(r.data))I==="promise"?(typeof r.data.payload<"u"&&i.next(MG.deserialize(r.data.payload)),i.complete(),e.removeEventListener("message",n)):(r.data.payload&&i.next(MG.deserialize(r.data.payload)),r.data.complete&&(i.complete(),e.removeEventListener("message",n)));else if(Aet(r.data)){const C=MG.deserialize(r.data.error);i.error(C),e.removeEventListener("message",n)}}};return e.addEventListener("message",n),()=>{if(I==="observable"||!I){const r={type:YS.MasterMessageType.cancel,uid:g};e.postMessage(r)}e.removeEventListener("message",n)}})}function det(e){if(e.length===0)return{args:[],transferables:[]};const g=[],i=[];for(const I of e)Cet.isTransferDescriptor(I)?(g.push(MG.serialize(I.send)),i.push(...I.transferables)):g.push(MG.serialize(I));return{args:g,transferables:i.length===0?i:aet(i)}}function X0e(e,g){return(...i)=>{const I=oet++,{args:n,transferables:r}=det(i),C={type:YS.MasterMessageType.run,uid:I,method:g,args:n};W0e("Sending command to run function to worker:",C);try{e.postMessage(C,r)}catch(o){return yge.ObservablePromise.from(Promise.reject(o))}return yge.ObservablePromise.from(V0e.multicast(uet(e,I)))}}Gb.createProxyFunction=X0e;function het(e,g){const i={};for(const I of g)i[I]=X0e(e,I);return i}Gb.createProxyModule=het;var S7=yi&&yi.__awaiter||function(e,g,i,I){function n(r){return r instanceof i?r:new i(function(C){C(r)})}return new(i||(i=Promise))(function(r,C){function o(A){try{s(I.next(A))}catch(l){C(l)}}function a(A){try{s(I.throw(A))}catch(l){C(l)}}function s(A){A.done?r(A.value):n(A.value).then(o,a)}s((I=I.apply(e,g||[])).next())})},met=yi&&yi.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(JT,"__esModule",{value:!0});JT.spawn=void 0;const w7=met(Z7),fet=zT,pet=$C,bet=OT,gV=Tr,x1=w0e,Zge=Gb,yet=w7.default("threads:master:messages"),Zet=w7.default("threads:master:spawn"),H0e=w7.default("threads:master:thread-utils"),Get=e=>e&&e.type==="init",vet=e=>e&&e.type==="uncaughtError",Bet=typeof process<"u"&&{}.THREADS_WORKER_INIT_TIMEOUT?Number.parseInt({}.THREADS_WORKER_INIT_TIMEOUT,10):1e4;function wet(e,g,i){return S7(this,void 0,void 0,function*(){let I;const n=new Promise((C,o)=>{I=setTimeout(()=>o(Error(i)),g)}),r=yield Promise.race([e,n]);return clearTimeout(I),r})}function Ret(e){return new Promise((g,i)=>{const I=n=>{yet("Message from worker before finishing initialization:",n.data),Get(n.data)?(e.removeEventListener("message",I),g(n.data)):vet(n.data)&&(e.removeEventListener("message",I),i(pet.deserialize(n.data.error)))};e.addEventListener("message",I)})}function Vet(e,g){return new fet.Observable(i=>{const I=r=>{const C={type:x1.WorkerEventType.message,data:r.data};i.next(C)},n=r=>{H0e("Unhandled promise rejection event in thread:",r);const C={type:x1.WorkerEventType.internalError,error:Error(r.reason)};i.next(C)};e.addEventListener("message",I),e.addEventListener("unhandledrejection",n),g.then(()=>{const r={type:x1.WorkerEventType.termination};e.removeEventListener("message",I),e.removeEventListener("unhandledrejection",n),i.next(r),i.complete()})})}function Wet(e){const[g,i]=bet.createPromiseWithResolver();return{terminate:()=>S7(this,void 0,void 0,function*(){H0e("Terminating worker"),yield e.terminate(),i()}),termination:g}}function Gge(e,g,i,I){const n=i.filter(r=>r.type===x1.WorkerEventType.internalError).map(r=>r.error);return Object.assign(e,{[gV.$errors]:n,[gV.$events]:i,[gV.$terminate]:I,[gV.$worker]:g})}function Xet(e,g){return S7(this,void 0,void 0,function*(){Zet("Initializing new thread");const i=g&&g.timeout?g.timeout:Bet,n=(yield wet(Ret(e),i,`Timeout: Did not receive an init message from worker after ${i}ms. Make sure the worker calls expose().`)).exposed,{termination:r,terminate:C}=Wet(e),o=Vet(e,r);if(n.type==="function"){const a=Zge.createProxyFunction(e);return Gge(a,e,o,C)}else if(n.type==="module"){const a=Zge.createProxyModule(e,n.methods);return Gge(a,e,o,C)}else{const a=n.type;throw Error(`Worker init message states unexpected type of expose(): ${a}`)}})}JT.spawn=Xet;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Worker=e.BlobWorker=e.isWorkerRuntime=e.Thread=e.spawn=e.Pool=void 0;const g=Rs;Object.defineProperty(e,"isWorkerRuntime",{enumerable:!0,get:function(){return g.isWorkerRuntime}});var i=b0e;Object.defineProperty(e,"Pool",{enumerable:!0,get:function(){return i.Pool}});var I=JT;Object.defineProperty(e,"spawn",{enumerable:!0,get:function(){return I.spawn}});var n=kS;Object.defineProperty(e,"Thread",{enumerable:!0,get:function(){return n.Thread}}),e.BlobWorker=g.getWorkerImplementation().blob,e.Worker=g.getWorkerImplementation().default})(f0e);var T0e={},Het=e=>e?typeof Symbol.observable=="symbol"&&typeof e[Symbol.observable]=="function"?e===e[Symbol.observable]():typeof e["@@observable"]=="function"?e===e["@@observable"]():!1:!1,R7={};Object.defineProperty(R7,"__esModule",{value:!0});const Tet=function(){const g=typeof self<"u"&&typeof Window<"u"&&self instanceof Window;return!!(typeof self<"u"&&self.postMessage&&!g)},Net=function(g,i){self.postMessage(g,i)},ket=function(g){const i=n=>{g(n.data)},I=()=>{self.removeEventListener("message",i)};return self.addEventListener("message",i),I};R7.default={isWorkerRuntime:Tet,postMessageToMaster:Net,subscribeToMasterMessages:ket};(function(e){var g=yi&&yi.__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 Y(J){try{x(X.next(J))}catch(P){H(P)}}function K(J){try{x(X.throw(J))}catch(P){H(P)}}function x(J){J.done?V(J.value):W(J.value).then(Y,K)}x((X=X.apply(w,R||[])).next())})},i=yi&&yi.__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(Het),n=$C,r=Ds,C=B7,o=i(R7);var a=$C;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return a.registerSerializer}});var s=Ds;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===C.MasterMessageType.cancel,u=w=>w&&w.type===C.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 r.isTransferDescriptor(w)?{payload:w.send,transferables:w.transferables}:{payload:w,transferables:void 0}}function f(){const w={type:C.WorkerMessageType.init,exposed:{type:"function"}};o.default.postMessageToMaster(w)}function b(w){const R={type:C.WorkerMessageType.init,exposed:{type:"module",methods:w}};o.default.postMessageToMaster(R)}function p(w,R){const{payload:S,transferables:X}=m(R),W={type:C.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:C.WorkerMessageType.result,uid:w,complete:R?!0:void 0,payload:X};o.default.postMessageToMaster(V,W)}function Z(w,R){const S={type:C.WorkerMessageType.running,uid:w,resultType:R};o.default.postMessageToMaster(S)}function B(w){try{const R={type:C.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 g(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 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(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))}})}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 R=w.reason;R&&typeof R.message=="string"&&setTimeout(()=>B(R),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)}))})(T0e);(function(e){var g=yi&&yi.__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=yi&&yi.__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=$C;Object.defineProperty(e,"registerSerializer",{enumerable:!0,get:function(){return I.registerSerializer}}),i(f0e,e);var n=T0e;Object.defineProperty(e,"expose",{enumerable:!0,get:function(){return n.expose}});var r=ih;Object.defineProperty(e,"DefaultSerializer",{enumerable:!0,get:function(){return r.DefaultSerializer}});var C=Ds;Object.defineProperty(e,"Transfer",{enumerable:!0,get:function(){return C.Transfer}})})(h0e);const iu=Qc(h0e);iu.registerSerializer;const LT=iu.spawn;iu.BlobWorker;iu.DefaultSerializer;iu.Pool;iu.Thread;iu.Transfer;iu.Worker;class Yet 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,r]=I;this._deleteIfExpired(n,r)===!1&&(yield[n,r.value])}g=[...this.oldCache];for(let i=g.length-1;i>=0;--i){const I=g[i],[n,r]=I;this.cache.has(n)||this._deleteIfExpired(n,r)===!1&&(yield[n,r.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 vge={},k5={},Y5=34,Oy=10,K5=13;function N0e(e){return new Function("d","return {"+e.map(function(g,i){return JSON.stringify(g)+": d["+i+'] || ""'}).join(",")+"}")}function Ket(e,g){var i=N0e(e);return function(I,n){return g(i(I),n,e)}}function Bge(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 vr(e,g){var i=e+"",I=i.length;return I9999?"+"+vr(e,6):vr(e,4)}function Det(e){var g=e.getUTCHours(),i=e.getUTCMinutes(),I=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":Fet(e.getUTCFullYear())+"-"+vr(e.getUTCMonth()+1,2)+"-"+vr(e.getUTCDate(),2)+(n?"T"+vr(g,2)+":"+vr(i,2)+":"+vr(I,2)+"."+vr(n,3)+"Z":I?"T"+vr(g,2)+":"+vr(i,2)+":"+vr(I,2)+"Z":i||g?"T"+vr(g,2)+":"+vr(i,2)+"Z":"")}function xet(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?Ket(m,c):N0e(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)===Oy&&--d,l.charCodeAt(d-1)===K5&&--d;function y(){if(b)return k5;if(p)return p=!1,vge;var B,G=h,v;if(l.charCodeAt(G)===Y5){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===Oy?p=!0:v===K5&&(p=!0,l.charCodeAt(h)===Oy&&++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(e)}}catch(g){console.error("vite-plugin-css-injected-by-js",g)}})();var $e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};function JC(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function qs(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 w0e={exports:{}},ket="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",Yet=ket,Ket=Yet;function V0e(){}function R0e(){}R0e.resetWarningCache=V0e;var xet=function(){function e(i,n,C,r,o,a){if(a!==Ket){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:R0e,resetWarningCache:V0e};return I.PropTypes=I,I};w0e.exports=xet();var el=w0e.exports;const L=JC(el);var R3="http://www.w3.org/1999/xhtml";const W3={svg:"http://www.w3.org/2000/svg",xhtml:R3,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function qh(e){var g=e+="",I=g.indexOf(":");return I>=0&&(g=e.slice(0,I))!=="xmlns"&&(e=e.slice(I+1)),W3.hasOwnProperty(g)?{space:W3[g],local:e}:e}function Det(e){return function(){var g=this.ownerDocument,I=this.namespaceURI;return I===R3&&g.documentElement.namespaceURI===R3?g.createElement(e):g.createElementNS(I,e)}}function Fet(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function OT(e){var g=qh(e);return(g.local?Fet:Det)(g)}function Eet(){}function NS(e){return e==null?Eet:function(){return this.querySelector(e)}}function Met(e){typeof e!="function"&&(e=NS(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 stt(e){e||(e=ltt);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 ctt(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function utt(){return Array.from(this)}function dtt(){for(var e=this._groups,g=0,I=e.length;g1?this.each((g==null?Stt:typeof g=="function"?Vtt:wtt)(e,g,I??"")):Co(this.node(),e)}function Co(e,g){return e.style.getPropertyValue(g)||B7(e).getComputedStyle(e,null).getPropertyValue(g)}function Wtt(e){return function(){delete this[e]}}function Xtt(e,g){return function(){this[e]=g}}function Htt(e,g){return function(){var I=g.apply(this,arguments);I==null?delete this[e]:this[e]=I}}function Ttt(e,g){return arguments.length>1?this.each((g==null?Wtt:typeof g=="function"?Htt:Xtt)(e,g)):this.node()[e]}function H0e(e){return e.trim().split(/^|\s+/)}function S7(e){return e.classList||new T0e(e)}function T0e(e){this._node=e,this._names=H0e(e.getAttribute("class")||"")}T0e.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 N0e(e,g){for(var I=S7(e),i=-1,n=g.length;++i=0&&(I=g.slice(i+1),g=g.slice(0,i)),{type:g,name:I}})}function rgt(e){return function(){var g=this.__on;if(g){for(var I=0,i=-1,n=g.length,C;Izg(I,g))}function fgt(e){return typeof e=="string"?new Dn([document.querySelectorAll(e)],[document.documentElement]):new Dn([e==null?[]:v7(e)],w7)}const pgt=Object.freeze(Object.defineProperty({__proto__:null,create:dgt,creator:OT,local:K0e,matcher:LT,namespace:qh,namespaces:W3,pointer:zg,pointers:mgt,select:dg,selectAll:fgt,selection:ha,selector:NS,selectorAll:_T,style:Co,window:B7},Symbol.toStringTag,{value:"Module"}));function yi(e,g){return eg?1:e>=g?0:NaN}function k0(e){let g=e,I=e;e.length===1&&(g=(r,o)=>e(r)-o,I=bgt(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 bgt(e){return(g,I)=>yi(e(g),I)}function D0e(e){return e===null?NaN:+e}function*ygt(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 F0e=k0(yi),E0e=F0e.right,Zgt=F0e.left,Ggt=k0(D0e).center,em=E0e;function UT(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 vgt(e){return e.length|0}function Bgt(e){return!(e>0)}function Sgt(e){return typeof e!="object"||"length"in e?e:Array.from(e)}function wgt(e){return g=>e(...g)}function Vgt(...e){const g=typeof e[e.length-1]=="function"&&wgt(e.pop());e=e.map(Sgt);const I=e.map(vgt),i=e.length-1,n=new Array(i+1).fill(0),C=[];if(i<0||I.some(Bgt))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 Rgt(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 Wgt(e,g){return ge?1:g>=e?0:NaN}function V7(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 R7(e,g){const I=V7(e,g);return I&&Math.sqrt(I)}function x1(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 kgt(e,g){const I=new Yi;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 Ygt(e,g){const I=new Yi;let i=-1;return Float64Array.from(e,g===void 0?n=>I.add(+n||0):n=>I.add(+g(n,++i,e)||0))}function M0e(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function yge(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 Egt(e){try{return Function.toString.call(e).indexOf("[native code]")!==-1}catch{return typeof e=="function"}}function SB(e,g){return SB=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(i,n){return i.__proto__=n,i},SB(e,g)}function lr(e){return lr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},lr(e)}let UX=function(e){P0e(I,e);var g=J0e(I);function I(i,n=U0e){var C;if(M0e(this,I),C=g.call(this),Object.defineProperties(W7(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const[r,o]of i)C.set(r,o);return C}return z0e(I,[{key:"get",value:function(n){return IA(lr(I.prototype),"get",this).call(this,H3(this,n))}},{key:"has",value:function(n){return IA(lr(I.prototype),"has",this).call(this,H3(this,n))}},{key:"set",value:function(n,C){return IA(lr(I.prototype),"set",this).call(this,_0e(this,n),C)}},{key:"delete",value:function(n){return IA(lr(I.prototype),"delete",this).call(this,L0e(this,n))}}]),I}(LX(Map)),Mgt=function(e){P0e(I,e);var g=J0e(I);function I(i,n=U0e){var C;if(M0e(this,I),C=g.call(this),Object.defineProperties(W7(C),{_intern:{value:new Map},_key:{value:n}}),i!=null)for(const r of i)C.add(r);return C}return z0e(I,[{key:"has",value:function(n){return IA(lr(I.prototype),"has",this).call(this,H3(this,n))}},{key:"add",value:function(n){return IA(lr(I.prototype),"add",this).call(this,_0e(this,n))}},{key:"delete",value:function(n){return IA(lr(I.prototype),"delete",this).call(this,L0e(this,n))}}]),I}(LX(Set));function H3({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):I}function _0e({_intern:e,_key:g},I){const i=g(I);return e.has(i)?e.get(i):(e.set(i,I),I)}function L0e({_intern:e,_key:g},I){const i=g(I);return e.has(i)&&(I=e.get(I),e.delete(i)),I}function U0e(e){return e!==null&&typeof e=="object"?e.valueOf():e}function Gb(e){return e}function Q0e(e,...g){return Y0(e,Gb,Gb,g)}function zgt(e,...g){return Y0(e,Array.from,Gb,g)}function j0e(e,g,...I){return Y0(e,Gb,g,I)}function Pgt(e,g,...I){return Y0(e,Array.from,g,I)}function Jgt(e,...g){return Y0(e,Gb,$0e,g)}function Ogt(e,...g){return Y0(e,Array.from,$0e,g)}function $0e(e){if(e.length!==1)throw new Error("duplicate key");return e[0]}function Y0(e,g,I,i){return function n(C,r){if(r>=i.length)return I(C);const o=new UX,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 q0e(e,g){return Array.from(g,I=>e[I])}function T3(e,...g){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");e=Array.from(e);let[I=yi]=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=yi(r[n],r[C]);if(o)return o}})):(I=e.map(I),i.sort((n,C)=>yi(I[n],I[C]))),q0e(e,i)}return e.sort(I)}function _gt(e,g,I){return(g.length===1?T3(j0e(e,g,I),([i,n],[C,r])=>yi(n,r)||yi(i,C)):T3(Q0e(e,I),([i,n],[C,r])=>g(n,r)||yi(i,C))).map(([i])=>i)}var Lgt=Array.prototype,Ugt=Lgt.slice;function eR(e){return function(){return e}}var N3=Math.sqrt(50),k3=Math.sqrt(10),Y3=Math.sqrt(2);function Ch(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>=N3?10:C>=k3?5:C>=Y3?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(C>=N3?10:C>=k3?5:C>=Y3?2:1)}function QX(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>=N3?n*=10:C>=k3?n*=5:C>=Y3&&(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 tye(e){return Math.ceil(Math.log(UT(e))/Math.LN2)+1}function Zge(){var e=Gb,g=x1,I=tye;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===x1){const b=kS(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 jX(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 X7(e,g,I=0,i=e.length-1,n=yi){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));X7(e,g,u,d,n)}const C=e[g];let r=I,o=i;for(Oy(e,I,g),n(e[i],C)>0&&Oy(e,I,i);r0;)--o}n(e[I],C)===0?Oy(e,I,o):(++o,Oy(e,o,i)),o<=g&&(I=o+1),g<=o&&(i=o-1)}return e}function Oy(e,g,I){const i=e[g];e[g]=e[I],e[I]=i}function wB(e,g,I){if(e=Float64Array.from(ygt(e,I)),!!(i=e.length)){if((g=+g)<=0||i<2)return jX(e);if(g>=1)return K3(e);var i,n=(i-1)*g,C=Math.floor(n),r=K3(X7(e,C).subarray(0,C+1)),o=jX(e.subarray(C+1));return r+(o-r)*(n-C)}}function gye(e,g,I=D0e){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 Qgt(e,g,I){return Math.ceil((I-g)/(2*(wB(e,.75)-wB(e,.25))*Math.pow(UT(e),-1/3)))}function jgt(e,g,I){return Math.ceil((I-g)/(3.5*R7(e)*Math.pow(UT(e),-1/3)))}function Iye(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 x3(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 H7(e,g){return wB(e,.5,g)}function*$gt(e){for(const g of e)yield*g}function T7(e){return Array.from($gt(e))}function iye(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 qgt(e,g=eIt){const I=[];let i,n=!1;for(const C of e)n&&I.push(g(i,C)),i=C,n=!0;return I}function eIt(e,g){return[e,g]}function CC(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:yi(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 IIt(e,g=yi){if(g.length===1)return Iye(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 iIt(e,g){const I=nye(e,g);return I<0?void 0:I}const nIt=Cye(Math.random);function Cye(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 rye(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 oye(e){if(!(C=e.length))return[];for(var g=-1,I=jX(e,CIt),i=new Array(I);++gg(I,i,e))}function lIt(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 cIt(e){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");return Array.from(e).reverse()}function uIt(e,...g){e=new Set(e);for(const I of g)for(const i of I)e.delete(i);return e}function dIt(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 hIt(e){return e instanceof Set?e:new Set(e)}function mIt(e,...g){e=new Set(e),g=g.map(hIt);e:for(const I of e)for(const i of g)if(!i.has(I)){e.delete(I);continue e}return e}function aye(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 fIt(e,g){return aye(g,e)}function pIt(...e){const g=new Set;for(const I of e)for(const i of I)g.add(i);return g}const bIt=Object.freeze(Object.defineProperty({__proto__:null,Adder:Yi,InternMap:UX,InternSet:Mgt,ascending:yi,bin:Zge,bisect:em,bisectCenter:Ggt,bisectLeft:Zgt,bisectRight:E0e,bisector:k0,count:UT,cross:Vgt,cumsum:Rgt,descending:Wgt,deviation:R7,difference:uIt,disjoint:dIt,every:oIt,extent:x1,fcumsum:Ygt,filter:AIt,fsum:kgt,greatest:gIt,greatestIndex:IIt,group:Q0e,groupSort:_gt,groups:zgt,histogram:Zge,index:Jgt,indexes:Ogt,intersection:mIt,least:tIt,leastIndex:nye,map:sIt,max:K3,maxIndex:Iye,mean:x3,median:H7,merge:T7,min:jX,minIndex:iye,nice:eye,pairs:qgt,permute:q0e,quantile:wB,quantileSorted:gye,quickselect:X7,range:CC,reduce:lIt,reverse:cIt,rollup:j0e,rollups:Pgt,scan:iIt,shuffle:nIt,shuffler:Cye,some:aIt,sort:T3,subset:fIt,sum:rye,superset:aye,thresholdFreedmanDiaconis:Qgt,thresholdScott:jgt,thresholdSturges:tye,tickIncrement:kS,tickStep:QX,ticks:Ch,transpose:oye,union:pIt,variance:V7,zip:rIt},Symbol.toStringTag,{value:"Module"}));function Ao(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function tl(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 D3=Symbol("implicit");function N7(){var e=new UX,g=[],I=[],i=D3;function n(C){let r=e.get(C);if(r===void 0){if(i!==D3)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 UX;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 N7(g,I).unknown(i)},Ao.apply(n,arguments),n}function YS(){var e=N7().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?tR(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):I===4?tR(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=GIt.exec(e))?new cn(g[1],g[2],g[3],1):(g=vIt.exec(e))?new cn(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=BIt.exec(e))?tR(g[1],g[2],g[3],g[4]):(g=SIt.exec(e))?tR(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=wIt.exec(e))?Rge(g[1],g[2]/100,g[3]/100,1):(g=VIt.exec(e))?Rge(g[1],g[2]/100,g[3]/100,g[4]):Gge.hasOwnProperty(e)?Sge(Gge[e]):e==="transparent"?new cn(NaN,NaN,NaN,0):null}function Sge(e){return new cn(e>>16&255,e>>8&255,e&255,1)}function tR(e,g,I,i){return i<=0&&(e=g=I=NaN),new cn(e,g,I,i)}function k7(e){return e instanceof nu||(e=Hi(e)),e?(e=e.rgb(),new cn(e.r,e.g,e.b,e.opacity)):new cn}function Bb(e,g,I,i){return arguments.length===1?k7(e):new cn(e,g,I,i??1)}function cn(e,g,I,i){this.r=+e,this.g=+g,this.b=+I,this.opacity=+i}K0(cn,Bb,KS(nu,{brighter:function(e){return e=e==null?vb:Math.pow(vb,e),new cn(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?rh:Math.pow(rh,e),new cn(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:wge,formatHex:wge,formatRgb:Vge,toString:Vge}));function wge(){return"#"+k5(this.r)+k5(this.g)+k5(this.b)}function Vge(){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 k5(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function Rge(e,g,I,i){return i<=0?e=g=I=NaN:I<=0||I>=1?e=g=NaN:g<=0&&(e=NaN),new Ja(e,g,I,i)}function sye(e){if(e instanceof Ja)return new Ja(e.h,e.s,e.l,e.opacity);if(e instanceof nu||(e=Hi(e)),!e)return new Ja;if(e instanceof Ja)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 Ja(r,o,a,e.opacity)}function lye(e,g,I,i){return arguments.length===1?sye(e):new Ja(e,g,I,i??1)}function Ja(e,g,I,i){this.h=+e,this.s=+g,this.l=+I,this.opacity=+i}K0(Ja,lye,KS(nu,{brighter:function(e){return e=e==null?vb:Math.pow(vb,e),new Ja(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?rh:Math.pow(rh,e),new Ja(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 cn(Y5(e>=240?e-240:e+120,n,i),Y5(e,n,i),Y5(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 Y5(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 cye=Math.PI/180,uye=180/Math.PI,$X=18,dye=.96422,hye=1,mye=.82521,fye=4/29,Vp=6/29,pye=3*Vp*Vp,WIt=Vp*Vp*Vp;function bye(e){if(e instanceof na)return new na(e.l,e.a,e.b,e.opacity);if(e instanceof iA)return vye(e);e instanceof cn||(e=k7(e));var g=F5(e.r),I=F5(e.g),i=F5(e.b),n=K5((.2225045*g+.7168786*I+.0606169*i)/hye),C,r;return g===I&&I===i?C=r=n:(C=K5((.4360747*g+.3850649*I+.1430804*i)/dye),r=K5((.0139322*g+.0971045*I+.7141733*i)/mye)),new na(116*n-16,500*(C-n),200*(n-r),e.opacity)}function XIt(e,g){return new na(e,0,0,g??1)}function yye(e,g,I,i){return arguments.length===1?bye(e):new na(e,g,I,i??1)}function na(e,g,I,i){this.l=+e,this.a=+g,this.b=+I,this.opacity=+i}K0(na,yye,KS(nu,{brighter:function(e){return new na(this.l+$X*(e??1),this.a,this.b,this.opacity)},darker:function(e){return new na(this.l-$X*(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=dye*x5(g),e=hye*x5(e),I=mye*x5(I),new cn(D5(3.1338561*g-1.6168667*e-.4906146*I),D5(-.9787684*g+1.9161415*e+.033454*I),D5(.0719453*g-.2289914*e+1.4052427*I),this.opacity)}}));function K5(e){return e>WIt?Math.pow(e,1/3):e/pye+fye}function x5(e){return e>Vp?e*e*e:pye*(e-fye)}function D5(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function F5(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function Zye(e){if(e instanceof iA)return new iA(e.h,e.c,e.l,e.opacity);if(e instanceof na||(e=bye(e)),e.a===0&&e.b===0)return new iA(NaN,0()=>e;function kIt(e,g){return function(I){return e+I*g}}function YIt(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 KIt(e){return(e=+e)==1?wye:function(g,I){return I-g?YIt(g,I,e):x7(isNaN(g)?I:g)}}function wye(e,g){var I=g-e;return I?kIt(e,I):x7(isNaN(e)?g:e)}const Sb=function e(g){var I=KIt(g);function i(n,C){var r=I((n=Bb(n)).r,(C=Bb(C)).r),o=I(n.g,C.g),a=I(n.b,C.b),s=wye(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 xIt(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:Er(i,n)})),I=E5.lastIndex;return I180?A+=360:A-s>180&&(s+=360),c.push({i:l.push(n(l)+"rotate(",null,i)-2,x:Er(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:Er(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:Er(s,l)},{i:h-2,x:Er(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 eit(e,g,I){var i=e[0],n=e[1],C=g[0],r=g[1];return n2?tit:eit,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),Er)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,qX),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=F7,A()},l.clamp=function(c){return arguments.length?(r=c?!0:rC,A()):r!==rC},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 E7(){return jT()(rC,rC)}function git(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function e9(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 wb(e){return e=e9(Math.abs(e)),e?e[1]:NaN}function Iit(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 iit(e){return function(g){return g.replace(/[0-9]/g,function(I){return e[+I]})}}var nit=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Vb(e){if(!(g=nit.exec(e)))throw new Error("invalid format: "+e);var g;return new $T({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]})}Vb.prototype=$T.prototype;function $T(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+""}$T.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 Cit(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 Hye;function rit(e,g){var I=e9(e,g);if(!I)return e+"";var i=I[0],n=I[1],C=n-(Hye=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")+e9(e,Math.max(0,g+C-1))[0]}function Yge(e,g){var I=e9(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 Kge={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:git,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)=>Yge(e*100,g),r:Yge,s:rit,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function xge(e){return e}var Dge=Array.prototype.map,Fge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Tye(e){var g=e.grouping===void 0||e.thousands===void 0?xge:Iit(Dge.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?xge:iit(Dge.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=Vb(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"):Kge[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=Kge[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 K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=Cit(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?Fge[8+Hye/3]:"")+W+(K&&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 F=X.length+S.length+W.length,J=F>1)+X+S+W+J.slice(F);break;default:S=J+X+S+W;break}return C(S)}return V.toString=function(){return l+""},V}function A(l,c){var u=s((l=Vb(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(wb(c)/3)))*3,h=Math.pow(10,-d),m=Fge[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var IR,dr,gm;Nye({thousands:",",grouping:[3],currency:["$",""]});function Nye(e){return IR=Tye(e),dr=IR.format,gm=IR.formatPrefix,IR}function kye(e){return Math.max(0,-wb(Math.abs(e)))}function x0(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(wb(g)/3)))*3-wb(Math.abs(e)))}function Yye(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,wb(g)-wb(e))+1}const oit=Object.freeze(Object.defineProperty({__proto__:null,FormatSpecifier:$T,get format(){return dr},formatDefaultLocale:Nye,formatLocale:Tye,get formatPrefix(){return gm},formatSpecifier:Vb,precisionFixed:kye,precisionPrefix:x0,precisionRound:Yye},Symbol.toStringTag,{value:"Module"}));function Kye(e,g,I,i){var n=QX(e,g,I),C;switch(i=Vb(i??",f"),i.type){case"s":{var r=Math.max(Math.abs(e),Math.abs(g));return i.precision==null&&!isNaN(C=x0(n,r))&&(i.precision=C),gm(i,r)}case"":case"e":case"g":case"p":case"r":{i.precision==null&&!isNaN(C=Yye(n,Math.max(Math.abs(e),Math.abs(g))))&&(i.precision=C-(i.type==="e"));break}case"f":case"%":{i.precision==null&&!isNaN(C=kye(n))&&(i.precision=C-(i.type==="%")*2);break}}return dr(i)}function Cu(e){var g=e.domain;return e.ticks=function(I){var i=g();return Ch(i[0],i[i.length-1],I??10)},e.tickFormat=function(I,i){var n=g();return Kye(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=kS(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 tg(){var e=E7();return e.copy=function(){return xS(e,tg())},Ao.apply(e,arguments),Cu(e)}function xye(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,qX),I):e.slice()},I.unknown=function(i){return arguments.length?(g=i,I):g},I.copy=function(){return xye(e).unknown(g)},e=arguments.length?Array.from(e,qX):[0,1],Cu(I)}function Dye(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 cit(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 zge(e){return(g,I)=>-e(-g,I)}function M7(e){const g=e(Ege,Mge),I=g.domain;let i=10,n,C;function r(){return n=cit(i),C=lit(i),I()[0]<0?(n=zge(n),C=zge(C),e(ait,Ait)):e(Ege,Mge),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=Vb(a)).precision==null&&(a.trim=!0),a=dr(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(Dye(I(),{floor:o=>C(Math.floor(n(o))),ceil:o=>C(Math.ceil(n(o)))})),g}function ru(){const e=M7(jT()).domain([1,10]);return e.copy=()=>xS(e,ru()).base(e.base()),Ao.apply(e,arguments),e}function Pge(e){return function(g){return Math.sign(g)*Math.log1p(Math.abs(g/e))}}function Jge(e){return function(g){return Math.sign(g)*Math.expm1(Math.abs(g))*e}}function z7(e){var g=1,I=e(Pge(g),Jge(g));return I.constant=function(i){return arguments.length?e(Pge(g=+i),Jge(g)):g},Cu(I)}function Fye(){var e=z7(jT());return e.copy=function(){return xS(e,Fye()).constant(e.constant())},Ao.apply(e,arguments)}function Oge(e){return function(g){return g<0?-Math.pow(-g,e):Math.pow(g,e)}}function uit(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function dit(e){return e<0?-e*e:e*e}function P7(e){var g=e(rC,rC),I=1;function i(){return I===1?e(rC,rC):I===.5?e(uit,dit):e(Oge(I),Oge(1/I))}return g.exponent=function(n){return arguments.length?(I=+n,i()):I},Cu(g)}function J7(){var e=P7(jT());return e.copy=function(){return xS(e,J7()).exponent(e.exponent())},Ao.apply(e,arguments),e}function hit(){return J7.apply(null,arguments).exponent(.5)}function _ge(e){return Math.sign(e)*e*e}function mit(e){return Math.sign(e)*Math.sqrt(Math.abs(e))}function Eye(){var e=E7(),g=[0,1],I=!1,i;function n(C){var r=mit(e(C));return isNaN(r)?i:I?Math.round(r):r}return n.invert=function(C){return e.invert(_ge(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,qX)).map(_ge)),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 Eye(e.domain(),g).round(I).clamp(e.clamp()).unknown(i)},Ao.apply(n,arguments),Cu(n)}function t9(){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 Mye().domain([e,g]).range(n).unknown(C)},Ao.apply(Cu(r),arguments)}function zye(){var e=[.5],g=[0,1],I,i=1;function n(C){return C!=null&&C<=C?g[em(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 zye().domain(e).range(g).unknown(I)},Ao.apply(n,arguments)}const M5=new Date,z5=new Date;function xi(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(sxi(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)=>(M5.setTime(+C),z5.setTime(+r),e(M5),e(z5),Math.floor(I(M5,z5))),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 g9=xi(()=>{},(e,g)=>{e.setTime(+e+g)},(e,g)=>g-e);g9.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?xi(g=>{g.setTime(Math.floor(g/e)*e)},(g,I)=>{g.setTime(+g+I*e)},(g,I)=>(I-g)/e):g9);g9.range;const ds=1e3,Lr=ds*60,hs=Lr*60,Fs=hs*24,O7=Fs*7,Lge=Fs*30,P5=Fs*365,ld=xi(e=>{e.setTime(e-e.getMilliseconds())},(e,g)=>{e.setTime(+e+g*ds)},(e,g)=>(g-e)/ds,e=>e.getUTCSeconds());ld.range;const _7=xi(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*ds)},(e,g)=>{e.setTime(+e+g*Lr)},(e,g)=>(g-e)/Lr,e=>e.getMinutes());_7.range;const L7=xi(e=>{e.setUTCSeconds(0,0)},(e,g)=>{e.setTime(+e+g*Lr)},(e,g)=>(g-e)/Lr,e=>e.getUTCMinutes());L7.range;const U7=xi(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*ds-e.getMinutes()*Lr)},(e,g)=>{e.setTime(+e+g*hs)},(e,g)=>(g-e)/hs,e=>e.getHours());U7.range;const Q7=xi(e=>{e.setUTCMinutes(0,0,0)},(e,g)=>{e.setTime(+e+g*hs)},(e,g)=>(g-e)/hs,e=>e.getUTCHours());Q7.range;const DS=xi(e=>e.setHours(0,0,0,0),(e,g)=>e.setDate(e.getDate()+g),(e,g)=>(g-e-(g.getTimezoneOffset()-e.getTimezoneOffset())*Lr)/Fs,e=>e.getDate()-1);DS.range;const qT=xi(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/Fs,e=>e.getUTCDate()-1);qT.range;const Pye=xi(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/Fs,e=>Math.floor(e/Fs));Pye.range;function Im(e){return xi(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())*Lr)/O7)}const eN=Im(0),I9=Im(1),fit=Im(2),pit=Im(3),Rb=Im(4),bit=Im(5),yit=Im(6);eN.range;I9.range;fit.range;pit.range;Rb.range;bit.range;yit.range;function im(e){return xi(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)/O7)}const tN=im(0),i9=im(1),Zit=im(2),Git=im(3),Wb=im(4),vit=im(5),Bit=im(6);tN.range;i9.range;Zit.range;Git.range;Wb.range;vit.range;Bit.range;const j7=xi(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());j7.range;const $7=xi(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());$7.range;const Es=xi(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());Es.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:xi(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)});Es.range;const Ms=xi(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());Ms.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:xi(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)});Ms.range;function Jye(e,g,I,i,n,C){const r=[[ld,1,ds],[ld,5,5*ds],[ld,15,15*ds],[ld,30,30*ds],[C,1,Lr],[C,5,5*Lr],[C,15,15*Lr],[C,30,30*Lr],[n,1,hs],[n,3,3*hs],[n,6,6*hs],[n,12,12*hs],[i,1,Fs],[i,2,2*Fs],[I,1,O7],[g,1,Lge],[g,3,3*Lge],[e,1,P5]];function o(s,A,l){const c=Am).right(r,c);if(u===r.length)return e.every(QX(s/P5,A/P5,l));if(u===0)return g9.every(Math.max(QX(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?(Be=O5(_y(ve.y,0,1)),Je=Be.getUTCDay(),Be=Je>4||Je===0?i9.ceil(Be):i9(Be),Be=qT.offset(Be,(ve.V-1)*7),ve.y=Be.getUTCFullYear(),ve.m=Be.getUTCMonth(),ve.d=Be.getUTCDate()+(ve.w+6)%7):(Be=J5(_y(ve.y,0,1)),Je=Be.getDay(),Be=Je>4||Je===0?I9.ceil(Be):I9(Be),Be=DS.offset(Be,(ve.V-1)*7),ve.y=Be.getFullYear(),ve.m=Be.getMonth(),ve.d=Be.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),Je="Z"in ve?O5(_y(ve.y,0,1)).getUTCDay():J5(_y(ve.y,0,1)).getDay(),ve.m=0,ve.d="W"in ve?(ve.w+6)%7+ve.W*7-(Je+5)%7:ve.w+ve.U*7-(Je+6)%7);return"Z"in ve?(ve.H+=ve.Z/100|0,ve.M+=ve.Z%100,O5(ve)):J5(ve)}}function v(ne,be,pe,ve){for(var We=0,Be=be.length,Je=pe.length,Pe,De;We=Je)return-1;if(Pe=be.charCodeAt(We++),Pe===37){if(Pe=be.charAt(We++),De=Z[Pe in Uge?be.charAt(We++):Pe],!De||(ve=De(ne,pe,ve))<0)return-1}else if(Pe!=pe.charCodeAt(ve++))return-1}return ve}function w(ne,be,pe){var ve=s.exec(be.slice(pe));return ve?(ne.p=A.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function V(ne,be,pe){var ve=u.exec(be.slice(pe));return ve?(ne.w=d.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function S(ne,be,pe){var ve=l.exec(be.slice(pe));return ve?(ne.w=c.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function X(ne,be,pe){var ve=f.exec(be.slice(pe));return ve?(ne.m=b.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function W(ne,be,pe){var ve=h.exec(be.slice(pe));return ve?(ne.m=m.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function R(ne,be,pe){return v(ne,g,be,pe)}function H(ne,be,pe){return v(ne,I,be,pe)}function Y(ne,be,pe){return v(ne,i,be,pe)}function K(ne){return r[ne.getDay()]}function F(ne){return C[ne.getDay()]}function J(ne){return a[ne.getMonth()]}function P(ne){return o[ne.getMonth()]}function ge(ne){return n[+(ne.getHours()>=12)]}function q(ne){return 1+~~(ne.getMonth()/3)}function $(ne){return r[ne.getUTCDay()]}function j(ne){return C[ne.getUTCDay()]}function te(ne){return a[ne.getUTCMonth()]}function Q(ne){return o[ne.getUTCMonth()]}function ie(ne){return n[+(ne.getUTCHours()>=12)]}function he(ne){return 1+~~(ne.getUTCMonth()/3)}return{format:function(ne){var be=B(ne+="",p);return be.toString=function(){return ne},be},parse:function(ne){var be=G(ne+="",!1);return be.toString=function(){return ne},be},utcFormat:function(ne){var be=B(ne+="",y);return be.toString=function(){return ne},be},utcParse:function(ne){var be=G(ne+="",!0);return be.toString=function(){return ne},be}}}var Uge={"-":"",_:" ",0:"0"},$i=/^\s*\d+/,Xit=/^%/,Hit=/[\\^$*+?|[\]().{}]/g;function Yg(e,g,I){var i=e<0?"-":"",n=(i?-e:e)+"",C=n.length;return i+(C[g.toLowerCase(),I]))}function Nit(e,g,I){var i=$i.exec(g.slice(I,I+1));return i?(e.w=+i[0],I+i[0].length):-1}function kit(e,g,I){var i=$i.exec(g.slice(I,I+1));return i?(e.u=+i[0],I+i[0].length):-1}function Yit(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.U=+i[0],I+i[0].length):-1}function Kit(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.V=+i[0],I+i[0].length):-1}function xit(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.W=+i[0],I+i[0].length):-1}function Qge(e,g,I){var i=$i.exec(g.slice(I,I+4));return i?(e.y=+i[0],I+i[0].length):-1}function jge(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 Dit(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 Fit(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 Eit(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 $ge(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.d=+i[0],I+i[0].length):-1}function Mit(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 qge(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.H=+i[0],I+i[0].length):-1}function zit(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.M=+i[0],I+i[0].length):-1}function Pit(e,g,I){var i=$i.exec(g.slice(I,I+2));return i?(e.S=+i[0],I+i[0].length):-1}function Jit(e,g,I){var i=$i.exec(g.slice(I,I+3));return i?(e.L=+i[0],I+i[0].length):-1}function Oit(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 _it(e,g,I){var i=Xit.exec(g.slice(I,I+1));return i?I+i[0].length:-1}function Lit(e,g,I){var i=$i.exec(g.slice(I));return i?(e.Q=+i[0],I+i[0].length):-1}function Uit(e,g,I){var i=$i.exec(g.slice(I));return i?(e.s=+i[0],I+i[0].length):-1}function eIe(e,g){return Yg(e.getDate(),g,2)}function Qit(e,g){return Yg(e.getHours(),g,2)}function jit(e,g){return Yg(e.getHours()%12||12,g,2)}function $it(e,g){return Yg(1+DS.count(Es(e),e),g,3)}function Oye(e,g){return Yg(e.getMilliseconds(),g,3)}function qit(e,g){return Oye(e,g)+"000"}function ent(e,g){return Yg(e.getMonth()+1,g,2)}function tnt(e,g){return Yg(e.getMinutes(),g,2)}function gnt(e,g){return Yg(e.getSeconds(),g,2)}function Int(e){var g=e.getDay();return g===0?7:g}function int(e,g){return Yg(eN.count(Es(e)-1,e),g,2)}function _ye(e){var g=e.getDay();return g>=4||g===0?Rb(e):Rb.ceil(e)}function nnt(e,g){return e=_ye(e),Yg(Rb.count(Es(e),e)+(Es(e).getDay()===4),g,2)}function Cnt(e){return e.getDay()}function rnt(e,g){return Yg(I9.count(Es(e)-1,e),g,2)}function ont(e,g){return Yg(e.getFullYear()%100,g,2)}function ant(e,g){return e=_ye(e),Yg(e.getFullYear()%100,g,2)}function Ant(e,g){return Yg(e.getFullYear()%1e4,g,4)}function snt(e,g){var I=e.getDay();return e=I>=4||I===0?Rb(e):Rb.ceil(e),Yg(e.getFullYear()%1e4,g,4)}function lnt(e){var g=e.getTimezoneOffset();return(g>0?"-":(g*=-1,"+"))+Yg(g/60|0,"0",2)+Yg(g%60,"0",2)}function tIe(e,g){return Yg(e.getUTCDate(),g,2)}function cnt(e,g){return Yg(e.getUTCHours(),g,2)}function unt(e,g){return Yg(e.getUTCHours()%12||12,g,2)}function dnt(e,g){return Yg(1+qT.count(Ms(e),e),g,3)}function Lye(e,g){return Yg(e.getUTCMilliseconds(),g,3)}function hnt(e,g){return Lye(e,g)+"000"}function mnt(e,g){return Yg(e.getUTCMonth()+1,g,2)}function fnt(e,g){return Yg(e.getUTCMinutes(),g,2)}function pnt(e,g){return Yg(e.getUTCSeconds(),g,2)}function bnt(e){var g=e.getUTCDay();return g===0?7:g}function ynt(e,g){return Yg(tN.count(Ms(e)-1,e),g,2)}function Uye(e){var g=e.getUTCDay();return g>=4||g===0?Wb(e):Wb.ceil(e)}function Znt(e,g){return e=Uye(e),Yg(Wb.count(Ms(e),e)+(Ms(e).getUTCDay()===4),g,2)}function Gnt(e){return e.getUTCDay()}function vnt(e,g){return Yg(i9.count(Ms(e)-1,e),g,2)}function Bnt(e,g){return Yg(e.getUTCFullYear()%100,g,2)}function Snt(e,g){return e=Uye(e),Yg(e.getUTCFullYear()%100,g,2)}function wnt(e,g){return Yg(e.getUTCFullYear()%1e4,g,4)}function Vnt(e,g){var I=e.getUTCDay();return e=I>=4||I===0?Wb(e):Wb.ceil(e),Yg(e.getUTCFullYear()%1e4,g,4)}function Rnt(){return"+0000"}function gIe(){return"%"}function IIe(e){return+e}function iIe(e){return Math.floor(+e/1e3)}var Dm,Qye,jye;Wnt({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 Wnt(e){return Dm=Wit(e),Qye=Dm.format,Dm.parse,jye=Dm.utcFormat,Dm.utcParse,Dm}function Xnt(e){return new Date(e)}function Hnt(e){return e instanceof Date?+e:+new Date(+e)}function q7(e,g,I,i,n,C,r,o,a,s){var A=E7(),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)=>wB(e,C/i))},I.copy=function(){return tZe(g).domain(e)},tl.apply(I,arguments)}function IN(){var e=0,g=.5,I=1,i=1,n,C,r,o,a,s=rC,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=(In[e[g+0]]+In[e[g+1]]+In[e[g+2]]+In[e[g+3]]+"-"+In[e[g+4]]+In[e[g+5]]+"-"+In[e[g+6]]+In[e[g+7]]+"-"+In[e[g+8]]+In[e[g+9]]+"-"+In[e[g+10]]+In[e[g+11]]+In[e[g+12]]+In[e[g+13]]+In[e[g+14]]+In[e[g+15]]).toLowerCase();if(!iN(I))throw TypeError("Stringified UUID is invalid");return I}var nIe,L5,U5=0,Q5=0;function Fnt(e,g,I){var i=g&&I||0,n=g||new Array(16);e=e||{};var C=e.node||nIe,r=e.clockseq!==void 0?e.clockseq:L5;if(C==null||r==null){var o=e.random||(e.rng||nZe)();C==null&&(C=nIe=[o[0]|1,o[1],o[2],o[3],o[4],o[5]]),r==null&&(r=L5=(o[6]<<8|o[7])&16383)}var a=e.msecs!==void 0?e.msecs:Date.now(),s=e.nsecs!==void 0?e.nsecs:Q5+1,A=a-U5+(s-Q5)/1e4;if(A<0&&e.clockseq===void 0&&(r=r+1&16383),(A<0||a>U5)&&e.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");U5=a,Q5=s,L5=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||nN(n)}function CZe(e){if(!iN(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 Ent(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 oZe(e){return(e+64>>>9<<4)+14+1}function Ont(e,g){e[g>>5]|=128<>5]|=(e[i/8]&255)<>16)+(g>>16)+(I>>16);return i<<16|I&65535}function Lnt(e,g){return e<>>32-g}function CN(e,g,I,i,n,C){return uc(Lnt(uc(uc(g,e),uc(i,C)),n),I)}function Bn(e,g,I,i,n,C,r){return CN(g&I|~g&i,e,g,n,C,r)}function Sn(e,g,I,i,n,C,r){return CN(g&i|I&~i,e,g,n,C,r)}function wn(e,g,I,i,n,C,r){return CN(g^I^i,e,g,n,C,r)}function Vn(e,g,I,i,n,C,r){return CN(I^(g|~i),e,g,n,C,r)}var Unt=rZe("v3",48,Pnt);const Qnt=Unt;function jnt(e,g,I){e=e||{};var i=e.random||(e.rng||nZe)();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 nN(i)}function $nt(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 j5(e,g){return e<>>32-g}function qnt(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=j5(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 eCt=rZe("v5",80,qnt);const tCt=eCt,gCt="00000000-0000-0000-0000-000000000000";function ICt(e){if(!iN(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}const iCt=Object.freeze(Object.defineProperty({__proto__:null,NIL:gCt,parse:CZe,stringify:nN,v1:Fnt,v3:Qnt,v4:jnt,v5:tCt,validate:iN,version:ICt},Symbol.toStringTag,{value:"Module"})),nCt=qs(iCt);var rN=nCt,gQ=(()=>typeof Buffer<"u"?e=>Buffer.from(e).toString("base64"):e=>btoa(String.fromCharCode(...e)))(),CCt=(()=>typeof Buffer<"u"?e=>Buffer.from(e,"base64"):e=>Uint8Array.from(atob(e),g=>g.charCodeAt(0)))();FS.encode=function(e){var g=rN.parse(e),I=gQ(g),i=I.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};FS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return rN.stringify(CCt(g))};FS.v4=function(){var e=rN.v4(null,new Uint8Array(16)),g=gQ(e),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};FS.nice=function(){var e=rN.v4(null,new Uint8Array(16));e[0]=e[0]&127;var g=gQ(e),I=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};var rCt=FS;const sg=JC(rCt);var aZe={exports:{}},oN={},n9={exports:{}};n9.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]",K="[object Int32Array]",F="[object Uint8Array]",J="[object Uint8ClampedArray]",P="[object Uint16Array]",ge="[object Uint32Array]",q=/[\\^$.*+?()[\]{}|]/g,$=/^\[object .+?Constructor\]$/,j=/^(?:0|[1-9]\d*)$/,te={};te[W]=te[R]=te[H]=te[Y]=te[K]=te[F]=te[J]=te[P]=te[ge]=!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 Q=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,ie=typeof self=="object"&&self&&self.Object===Object&&self,he=Q||ie||Function("return this")(),ne=g&&!g.nodeType&&g,be=ne&&!0&&e&&!e.nodeType&&e,pe=be&&be.exports===ne,ve=pe&&Q.process,We=function(){try{return ve&&ve.binding&&ve.binding("util")}catch{}}(),Be=We&&We.isTypedArray;function Je(Se,ze){for(var Ct=-1,St=Se==null?0:Se.length,sI=0,Cg=[];++Ct-1}function At(Se,ze){var Ct=this.__data__,St=PI(Ct,Se);return St<0?(++this.size,Ct.push([Se,ze])):Ct[St][1]=ze,this}yt.prototype.clear=kt,yt.prototype.delete=ht,yt.prototype.get=Vt,yt.prototype.has=Ft,yt.prototype.set=At;function Xt(Se){var ze=-1,Ct=Se==null?0:Se.length;for(this.clear();++zeFi))return!1;var TI=Cg.get(Se);if(TI&&Cg.get(ze))return TI==ze;var UC=-1,uo=!0,yn=Ct&C?new Zt:void 0;for(Cg.set(Se,ze),Cg.set(ze,Se);++UC-1&&Se%1==0&&Se-1&&Se%1==0&&Se<=r}function g6(Se){var ze=typeof Se;return Se!=null&&(ze=="object"||ze=="function")}function by(Se){return Se!=null&&typeof Se=="object"}var I6=Be?_e(Be):pke;function Tke(Se){return Xke(Se)?hg(Se):bke(Se)}function Nke(){return[]}function kke(){return!1}e.exports=Hke})(n9,n9.exports);var aN=n9.exports,AZe={exports:{}};/*! +`)}function s(l){return l.map(A).join(e)}function A(l){return l==null?"":l instanceof Date?Det(l):g.test(l+="")?'"'+l.replace(/"/g,'""')+'"':l}return{parse:I,parseRows:n,format:C,formatBody:o,formatRows:a,formatRow:s,formatValue:A}}var U9={exports:{}};U9.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||yi,function(i){var I={},n=-1,r="*";function C(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,r,m,f)}}function c(h){var m=String(h),f=!!(Object.prototype.hasOwnProperty.call(I,m)&&C(I[m]));return f}function u(h){for(var m=String(h),f=c(m)||c(r),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(r,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}})})(U9,U9.exports);var Eet=U9.exports;const V7=Qc(Eet);(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 $e=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};function Pr(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function qs(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 k0e={exports:{}},Met="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED",zet=Met,Pet=zet;function Y0e(){}function K0e(){}K0e.resetWarningCache=Y0e;var Jet=function(){function e(I,n,r,C,o,a){if(a!==Pet){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:K0e,resetWarningCache:Y0e};return i.PropTypes=i,i};k0e.exports=Jet();var el=k0e.exports;const L=Pr(el);var N3="http://www.w3.org/1999/xhtml";const k3={svg:"http://www.w3.org/2000/svg",xhtml:N3,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function $h(e){var g=e+="",i=g.indexOf(":");return i>=0&&(g=e.slice(0,i))!=="xmlns"&&(e=e.slice(i+1)),k3.hasOwnProperty(g)?{space:k3[g],local:e}:e}function Oet(e){return function(){var g=this.ownerDocument,i=this.namespaceURI;return i===N3&&g.documentElement.namespaceURI===N3?g.createElement(e):g.createElementNS(i,e)}}function _et(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function UT(e){var g=$h(e);return(g.local?_et:Oet)(g)}function Let(){}function KS(e){return e==null?Let:function(){return this.querySelector(e)}}function Uet(e){typeof e!="function"&&(e=KS(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;)(C=I[n])&&(r&&C.compareDocumentPosition(r)^4&&r.parentNode.insertBefore(C,r),r=C);return this}function ftt(e){e||(e=ptt);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),r=0;rg?1:e>=g?0:NaN}function btt(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function ytt(){return Array.from(this)}function Ztt(){for(var e=this._groups,g=0,i=e.length;g1?this.each((g==null?Ttt:typeof g=="function"?ktt:Ntt)(e,g,i??"")):ro(this.node(),e)}function ro(e,g){return e.style.getPropertyValue(g)||X7(e).getComputedStyle(e,null).getPropertyValue(g)}function Ktt(e){return function(){delete this[e]}}function Ftt(e,g){return function(){this[e]=g}}function Dtt(e,g){return function(){var i=g.apply(this,arguments);i==null?delete this[e]:this[e]=i}}function xtt(e,g){return arguments.length>1?this.each((g==null?Ktt:typeof g=="function"?Dtt:Ftt)(e,g)):this.node()[e]}function x0e(e){return e.trim().split(/^|\s+/)}function H7(e){return e.classList||new E0e(e)}function E0e(e){this._node=e,this._names=x0e(e.getAttribute("class")||"")}E0e.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 M0e(e,g){for(var i=H7(e),I=-1,n=g.length;++I=0&&(i=g.slice(I+1),g=g.slice(0,I)),{type:g,name:i}})}function ugt(e){return function(){var g=this.__on;if(g){for(var i=0,I=-1,n=g.length,r;izg(i,g))}function Bgt(e){return typeof e=="string"?new Dn([document.querySelectorAll(e)],[document.documentElement]):new Dn([e==null?[]:W7(e)],T7)}const Sgt=Object.freeze(Object.defineProperty({__proto__:null,create:Zgt,creator:UT,local:J0e,matcher:jT,namespace:$h,namespaces:k3,pointer:zg,pointers:vgt,select:dg,selectAll:Bgt,selection:ha,selector:KS,selectorAll:QT,style:ro,window:X7},Symbol.toStringTag,{value:"Module"}));function yI(e,g){return eg?1:e>=g?0:NaN}function Y0(e){let g=e,i=e;e.length===1&&(g=(C,o)=>e(C)-o,i=wgt(e));function I(C,o,a,s){for(a==null&&(a=0),s==null&&(s=C.length);a>>1;i(C[A],o)<0?a=A+1:s=A}return a}function n(C,o,a,s){for(a==null&&(a=0),s==null&&(s=C.length);a>>1;i(C[A],o)>0?s=A:a=A+1}return a}function r(C,o,a,s){a==null&&(a=0),s==null&&(s=C.length);const A=I(C,o,a,s-1);return A>a&&g(C[A-1],o)>-g(C[A],o)?A-1:A}return{left:I,center:r,right:n}}function wgt(e){return(g,i)=>yI(e(g),i)}function _0e(e){return e===null?NaN:+e}function*Rgt(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 L0e=Y0(yI),U0e=L0e.right,Vgt=L0e.left,Wgt=Y0(_0e).center,qh=U0e;function $T(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 Xgt(e){return e.length|0}function Hgt(e){return!(e>0)}function Tgt(e){return typeof e!="object"||"length"in e?e:Array.from(e)}function Ngt(e){return g=>e(...g)}function kgt(...e){const g=typeof e[e.length-1]=="function"&&Ngt(e.pop());e=e.map(Tgt);const i=e.map(Xgt),I=e.length-1,n=new Array(I+1).fill(0),r=[];if(I<0||i.some(Hgt))return r;for(;;){r.push(n.map((o,a)=>e[a][o]));let C=I;for(;++n[C]===i[C];){if(C===0)return g?r.map(g):r;n[C--]=0}}}function Ygt(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 Kgt(e,g){return ge?1:g>=e?0:NaN}function N7(e,g){let i=0,I,n=0,r=0;if(g===void 0)for(let C of e)C!=null&&(C=+C)>=C&&(I=C-n,n+=I/++i,r+=I*(C-n));else{let C=-1;for(let o of e)(o=g(o,++C,e))!=null&&(o=+o)>=o&&(I=o-n,n+=I/++i,r+=I*(o-n))}if(i>1)return r/(i-1)}function k7(e,g){const i=N7(e,g);return i&&Math.sqrt(i)}function E1(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=r&&(i=I=r):(i>r&&(i=r),I0){for(o=i[--I];I>0&&(n=o,r=i[--I],o=n+r,C=r-(o-n),!C););I>0&&(C<0&&i[I-1]<0||C>0&&i[I-1]>0)&&(r=C*2,n=o+r,r==n-o&&(o=n))}return o}}]),e}();function Mgt(e,g){const i=new YI;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 zgt(e,g){const i=new YI;let I=-1;return Float64Array.from(e,g===void 0?n=>i.add(+n||0):n=>i.add(+g(n,++I,e)||0))}function Q0e(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function wge(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 Lgt(e){try{return Function.toString.call(e).indexOf("[native code]")!==-1}catch{return typeof e=="function"}}function VB(e,g){return VB=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(I,n){return I.__proto__=n,I},VB(e,g)}function sC(e){return sC=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},sC(e)}let $9=function(e){$0e(i,e);var g=q0e(i);function i(I,n=iye){var r;if(Q0e(this,i),r=g.call(this),Object.defineProperties(Y7(r),{_intern:{value:new Map},_key:{value:n}}),I!=null)for(const[C,o]of I)r.set(C,o);return r}return j0e(i,[{key:"get",value:function(n){return iA(sC(i.prototype),"get",this).call(this,K3(this,n))}},{key:"has",value:function(n){return iA(sC(i.prototype),"has",this).call(this,K3(this,n))}},{key:"set",value:function(n,r){return iA(sC(i.prototype),"set",this).call(this,tye(this,n),r)}},{key:"delete",value:function(n){return iA(sC(i.prototype),"delete",this).call(this,gye(this,n))}}]),i}(j9(Map)),Ugt=function(e){$0e(i,e);var g=q0e(i);function i(I,n=iye){var r;if(Q0e(this,i),r=g.call(this),Object.defineProperties(Y7(r),{_intern:{value:new Map},_key:{value:n}}),I!=null)for(const C of I)r.add(C);return r}return j0e(i,[{key:"has",value:function(n){return iA(sC(i.prototype),"has",this).call(this,K3(this,n))}},{key:"add",value:function(n){return iA(sC(i.prototype),"add",this).call(this,tye(this,n))}},{key:"delete",value:function(n){return iA(sC(i.prototype),"delete",this).call(this,gye(this,n))}}]),i}(j9(Set));function K3({_intern:e,_key:g},i){const I=g(i);return e.has(I)?e.get(I):i}function tye({_intern:e,_key:g},i){const I=g(i);return e.has(I)?e.get(I):(e.set(I,i),i)}function gye({_intern:e,_key:g},i){const I=g(i);return e.has(I)&&(i=e.get(i),e.delete(I)),i}function iye(e){return e!==null&&typeof e=="object"?e.valueOf():e}function vb(e){return e}function Iye(e,...g){return K0(e,vb,vb,g)}function Qgt(e,...g){return K0(e,Array.from,vb,g)}function nye(e,g,...i){return K0(e,vb,g,i)}function jgt(e,g,...i){return K0(e,Array.from,g,i)}function $gt(e,...g){return K0(e,vb,rye,g)}function qgt(e,...g){return K0(e,Array.from,rye,g)}function rye(e){if(e.length!==1)throw new Error("duplicate key");return e[0]}function K0(e,g,i,I){return function n(r,C){if(C>=I.length)return i(r);const o=new $9,a=I[C++];let s=-1;for(const A of r){const l=a(A,++s,r),c=o.get(l);c?c.push(A):o.set(l,[A])}for(const[A,l]of o)o.set(A,n(l,C));return g(o)}(e,0)}function Cye(e,g){return Array.from(g,i=>e[i])}function F3(e,...g){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");e=Array.from(e);let[i=yI]=g;if(i.length===1||g.length>1){const I=Uint32Array.from(e,(n,r)=>r);return g.length>1?(g=g.map(n=>e.map(n)),I.sort((n,r)=>{for(const C of g){const o=yI(C[n],C[r]);if(o)return o}})):(i=e.map(i),I.sort((n,r)=>yI(i[n],i[r]))),Cye(e,I)}return e.sort(i)}function eit(e,g,i){return(g.length===1?F3(nye(e,g,i),([I,n],[r,C])=>yI(n,C)||yI(I,r)):F3(Iye(e,i),([I,n],[r,C])=>g(n,C)||yI(I,r))).map(([I])=>I)}var tit=Array.prototype,git=tit.slice;function iV(e){return function(){return e}}var D3=Math.sqrt(50),x3=Math.sqrt(10),E3=Math.sqrt(2);function nh(e,g,i){var I,n=-1,r,C,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,C=new Array(r=s-a+1);++ng&&--s,C=new Array(r=s-a+1);++n=0?(r>=D3?10:r>=x3?5:r>=E3?2:1)*Math.pow(10,n):-Math.pow(10,-n)/(r>=D3?10:r>=x3?5:r>=E3?2:1)}function q9(e,g,i){var I=Math.abs(g-e)/Math.max(0,i),n=Math.pow(10,Math.floor(Math.log(I)/Math.LN10)),r=I/n;return r>=D3?n*=10:r>=x3?n*=5:r>=E3&&(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 aye(e){return Math.ceil(Math.log($T(e))/Math.LN2)+1}function Rge(){var e=vb,g=E1,i=aye;function I(n){Array.isArray(n)||(n=Array.from(n));var r,C=n.length,o,a=new Array(C);for(r=0;r=l)if(m>=l&&g===E1){const b=FS(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(r=0;r<=u;++r)h=d[r]=[],h.x0=r>0?c[r-1]:A,h.x1=r=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 eX(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 K7(e,g,i=0,I=e.length-1,n=yI){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));K7(e,g,u,d,n)}const r=e[g];let C=i,o=I;for(_y(e,i,g),n(e[I],r)>0&&_y(e,i,I);C0;)--o}n(e[i],r)===0?_y(e,i,o):(++o,_y(e,o,I)),o<=g&&(i=o+1),g<=o&&(I=o-1)}return e}function _y(e,g,i){const I=e[g];e[g]=e[i],e[i]=I}function WB(e,g,i){if(e=Float64Array.from(Rgt(e,i)),!!(I=e.length)){if((g=+g)<=0||I<2)return eX(e);if(g>=1)return M3(e);var I,n=(I-1)*g,r=Math.floor(n),C=M3(K7(e,r).subarray(0,r+1)),o=eX(e.subarray(r+1));return C+(o-C)*(n-r)}}function Aye(e,g,i=_0e){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,r=Math.floor(n),C=+i(e[r],r,e),o=+i(e[r+1],r+1,e);return C+(o-C)*(n-r)}}function iit(e,g,i){return Math.ceil((i-g)/(2*(WB(e,.75)-WB(e,.25))*Math.pow($T(e),-1/3)))}function Iit(e,g,i){return Math.ceil((i-g)/(3.5*k7(e)*Math.pow($T(e),-1/3)))}function sye(e,g){let i,I=-1,n=-1;if(g===void 0)for(const r of e)++n,r!=null&&(i=r)&&(i=r,I=n);else for(let r of e)(r=g(r,++n,e))!=null&&(i=r)&&(i=r,I=n);return I}function z3(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 r of e)(r=g(r,++n,e))!=null&&(r=+r)>=r&&(++i,I+=r)}if(i)return I/i}function F7(e,g){return WB(e,.5,g)}function*nit(e){for(const g of e)yield*g}function D7(e){return Array.from(nit(e))}function lye(e,g){let i,I=-1,n=-1;if(g===void 0)for(const r of e)++n,r!=null&&(i>r||i===void 0&&r>=r)&&(i=r,I=n);else for(let r of e)(r=g(r,++n,e))!=null&&(i>r||i===void 0&&r>=r)&&(i=r,I=n);return I}function rit(e,g=Cit){const i=[];let I,n=!1;for(const r of e)n&&i.push(g(I,r)),I=r,n=!0;return i}function Cit(e,g){return[e,g]}function nr(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,r=new Array(n);++I0:yI(C,C)===0)&&(i=r,n=C,I=!0)}}else for(const n of e)(I?g(n,i)>0:g(n,n)===0)&&(i=n,I=!0);return i}function Ait(e,g=yI){if(g.length===1)return sye(e,g);let i,I=-1,n=-1;for(const r of e)++n,(I<0?g(r,r)===0:g(r,i)>0)&&(i=r,I=n);return I}function sit(e,g){const i=cye(e,g);return i<0?void 0:i}const lit=uye(Math.random);function uye(e){return function(i,I=0,n=i.length){let r=n-(I=+I);for(;r;){const C=e()*r--|0,o=i[r+I];i[r+I]=i[C+I],i[C+I]=o}return i}}function dye(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 hye(e){if(!(r=e.length))return[];for(var g=-1,i=eX(e,cit),I=new Array(i);++gg(i,I,e))}function pit(e,g,i){if(typeof g!="function")throw new TypeError("reducer is not a function");const I=e[Symbol.iterator]();let n,r,C=-1;if(arguments.length<3){if({done:n,value:i}=I.next(),n)return;++C}for(;{done:n,value:r}=I.next(),!n;)i=g(i,r,++C,e);return i}function bit(e){if(typeof e[Symbol.iterator]!="function")throw new TypeError("values is not iterable");return Array.from(e).reverse()}function yit(e,...g){e=new Set(e);for(const i of g)for(const I of i)e.delete(I);return e}function Zit(e,g){const i=g[Symbol.iterator](),I=new Set;for(const n of e){if(I.has(n))return!1;let r,C;for(;({value:r,done:C}=i.next())&&!C;){if(Object.is(n,r))return!1;I.add(r)}}return!0}function Git(e){return e instanceof Set?e:new Set(e)}function vit(e,...g){e=new Set(e),g=g.map(Git);e:for(const i of e)for(const I of g)if(!I.has(i)){e.delete(i);continue e}return e}function mye(e,g){const i=e[Symbol.iterator](),I=new Set;for(const n of g){if(I.has(n))continue;let r,C;for(;{value:r,done:C}=i.next();){if(C)return!1;if(I.add(r),Object.is(n,r))break}}return!0}function Bit(e,g){return mye(g,e)}function Sit(...e){const g=new Set;for(const i of e)for(const I of i)g.add(I);return g}const wit=Object.freeze(Object.defineProperty({__proto__:null,Adder:YI,InternMap:$9,InternSet:Ugt,ascending:yI,bin:Rge,bisect:qh,bisectCenter:Wgt,bisectLeft:Vgt,bisectRight:U0e,bisector:Y0,count:$T,cross:kgt,cumsum:Ygt,descending:Kgt,deviation:k7,difference:yit,disjoint:Zit,every:dit,extent:E1,fcumsum:zgt,filter:mit,fsum:Mgt,greatest:ait,greatestIndex:Ait,group:Iye,groupSort:eit,groups:Qgt,histogram:Rge,index:$gt,indexes:qgt,intersection:vit,least:oit,leastIndex:cye,map:fit,max:M3,maxIndex:sye,mean:z3,median:F7,merge:D7,min:eX,minIndex:lye,nice:oye,pairs:rit,permute:Cye,quantile:WB,quantileSorted:Aye,quickselect:K7,range:nr,reduce:pit,reverse:bit,rollup:nye,rollups:jgt,scan:sit,shuffle:lit,shuffler:uye,some:hit,sort:F3,subset:Bit,sum:dye,superset:mye,thresholdFreedmanDiaconis:iit,thresholdScott:Iit,thresholdSturges:aye,tickIncrement:FS,tickStep:q9,ticks:nh,transpose:hye,union:Sit,variance:N7,zip:uit},Symbol.toStringTag,{value:"Module"}));function Ao(e,g){switch(arguments.length){case 0:break;case 1:this.range(e);break;default:this.range(g).domain(e);break}return this}function tl(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 P3=Symbol("implicit");function x7(){var e=new $9,g=[],i=[],I=P3;function n(r){let C=e.get(r);if(C===void 0){if(I!==P3)return I;e.set(r,C=g.push(r)-1)}return i[C%i.length]}return n.domain=function(r){if(!arguments.length)return g.slice();g=[],e=new $9;for(const C of r)e.has(C)||e.set(C,g.push(C)-1);return n},n.range=function(r){return arguments.length?(i=Array.from(r),n):i.slice()},n.unknown=function(r){return arguments.length?(I=r,n):I},n.copy=function(){return x7(g,i).unknown(I)},Ao.apply(n,arguments),n}function DS(){var e=x7().unknown(void 0),g=e.domain,i=e.range,I=0,n=1,r,C,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?IV(g>>24&255,g>>16&255,g>>8&255,(g&255)/255):i===4?IV(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=Wit.exec(e))?new cn(g[1],g[2],g[3],1):(g=Xit.exec(e))?new cn(g[1]*255/100,g[2]*255/100,g[3]*255/100,1):(g=Hit.exec(e))?IV(g[1],g[2],g[3],g[4]):(g=Tit.exec(e))?IV(g[1]*255/100,g[2]*255/100,g[3]*255/100,g[4]):(g=Nit.exec(e))?kge(g[1],g[2]/100,g[3]/100,1):(g=kit.exec(e))?kge(g[1],g[2]/100,g[3]/100,g[4]):Vge.hasOwnProperty(e)?Hge(Vge[e]):e==="transparent"?new cn(NaN,NaN,NaN,0):null}function Hge(e){return new cn(e>>16&255,e>>8&255,e&255,1)}function IV(e,g,i,I){return I<=0&&(e=g=i=NaN),new cn(e,g,i,I)}function E7(e){return e instanceof Iu||(e=HI(e)),e?(e=e.rgb(),new cn(e.r,e.g,e.b,e.opacity)):new cn}function Sb(e,g,i,I){return arguments.length===1?E7(e):new cn(e,g,i,I??1)}function cn(e,g,i,I){this.r=+e,this.g=+g,this.b=+i,this.opacity=+I}F0(cn,Sb,xS(Iu,{brighter:function(e){return e=e==null?Bb:Math.pow(Bb,e),new cn(this.r*e,this.g*e,this.b*e,this.opacity)},darker:function(e){return e=e==null?rh:Math.pow(rh,e),new cn(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:Tge,formatHex:Tge,formatRgb:Nge,toString:Nge}));function Tge(){return"#"+F5(this.r)+F5(this.g)+F5(this.b)}function Nge(){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 F5(e){return e=Math.max(0,Math.min(255,Math.round(e)||0)),(e<16?"0":"")+e.toString(16)}function kge(e,g,i,I){return I<=0?e=g=i=NaN:i<=0||i>=1?e=g=NaN:g<=0&&(e=NaN),new Ja(e,g,i,I)}function pye(e){if(e instanceof Ja)return new Ja(e.h,e.s,e.l,e.opacity);if(e instanceof Iu||(e=HI(e)),!e)return new Ja;if(e instanceof Ja)return e;e=e.rgb();var g=e.r/255,i=e.g/255,I=e.b/255,n=Math.min(g,i,I),r=Math.max(g,i,I),C=NaN,o=r-n,a=(r+n)/2;return o?(g===r?C=(i-I)/o+(i0&&a<1?0:C,new Ja(C,o,a,e.opacity)}function bye(e,g,i,I){return arguments.length===1?pye(e):new Ja(e,g,i,I??1)}function Ja(e,g,i,I){this.h=+e,this.s=+g,this.l=+i,this.opacity=+I}F0(Ja,bye,xS(Iu,{brighter:function(e){return e=e==null?Bb:Math.pow(Bb,e),new Ja(this.h,this.s,this.l*e,this.opacity)},darker:function(e){return e=e==null?rh:Math.pow(rh,e),new Ja(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 cn(D5(e>=240?e-240:e+120,n,I),D5(e,n,I),D5(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 D5(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 yye=Math.PI/180,Zye=180/Math.PI,tX=18,Gye=.96422,vye=1,Bye=.82521,Sye=4/29,Vp=6/29,wye=3*Vp*Vp,Kit=Vp*Vp*Vp;function Rye(e){if(e instanceof na)return new na(e.l,e.a,e.b,e.opacity);if(e instanceof IA)return Hye(e);e instanceof cn||(e=E7(e));var g=z5(e.r),i=z5(e.g),I=z5(e.b),n=x5((.2225045*g+.7168786*i+.0606169*I)/vye),r,C;return g===i&&i===I?r=C=n:(r=x5((.4360747*g+.3850649*i+.1430804*I)/Gye),C=x5((.0139322*g+.0971045*i+.7141733*I)/Bye)),new na(116*n-16,500*(r-n),200*(n-C),e.opacity)}function Fit(e,g){return new na(e,0,0,g??1)}function Vye(e,g,i,I){return arguments.length===1?Rye(e):new na(e,g,i,I??1)}function na(e,g,i,I){this.l=+e,this.a=+g,this.b=+i,this.opacity=+I}F0(na,Vye,xS(Iu,{brighter:function(e){return new na(this.l+tX*(e??1),this.a,this.b,this.opacity)},darker:function(e){return new na(this.l-tX*(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=Gye*E5(g),e=vye*E5(e),i=Bye*E5(i),new cn(M5(3.1338561*g-1.6168667*e-.4906146*i),M5(-.9787684*g+1.9161415*e+.033454*i),M5(.0719453*g-.2289914*e+1.4052427*i),this.opacity)}}));function x5(e){return e>Kit?Math.pow(e,1/3):e/wye+Sye}function E5(e){return e>Vp?e*e*e:wye*(e-Sye)}function M5(e){return 255*(e<=.0031308?12.92*e:1.055*Math.pow(e,1/2.4)-.055)}function z5(e){return(e/=255)<=.04045?e/12.92:Math.pow((e+.055)/1.055,2.4)}function Wye(e){if(e instanceof IA)return new IA(e.h,e.c,e.l,e.opacity);if(e instanceof na||(e=Rye(e)),e.a===0&&e.b===0)return new IA(NaN,0()=>e;function Mit(e,g){return function(i){return e+i*g}}function zit(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 Pit(e){return(e=+e)==1?kye:function(g,i){return i-g?zit(g,i,e):P7(isNaN(g)?i:g)}}function kye(e,g){var i=g-e;return i?Mit(e,i):P7(isNaN(e)?g:e)}const wb=function e(g){var i=Pit(g);function I(n,r){var C=i((n=Sb(n)).r,(r=Sb(r)).r),o=i(n.g,r.g),a=i(n.b,r.b),s=kye(n.opacity,r.opacity);return function(A){return n.r=C(A),n.g=o(A),n.b=a(A),n.opacity=s(A),n+""}}return I.gamma=e,I}(1);function Jit(e,g){g||(g=[]);var i=e?Math.min(g.length,e.length):0,I=g.slice(),n;return function(r){for(n=0;ni&&(r=g.slice(i,r),o[C]?o[C]+=r:o[++C]=r),(I=I[0])===(n=n[0])?o[C]?o[C]+=n:o[++C]=n:(o[++C]=null,a.push({i:C,x:xC(I,n)})),i=P5.lastIndex;return i180?A+=360:A-s>180&&(s+=360),c.push({i:l.push(n(l)+"rotate(",null,I)-2,x:xC(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:xC(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:xC(s,l)},{i:h-2,x:xC(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),r(s.translateX,s.translateY,A.translateX,A.translateY,l,c),C(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 CIt(e,g,i){var I=e[0],n=e[1],r=g[0],C=g[1];return n2?oIt:CIt,a=s=null,l}function l(c){return c==null||isNaN(c=+c)?r:(a||(a=o(e.map(I),g,i)))(I(C(c)))}return l.invert=function(c){return C(n((s||(s=o(g,e.map(I),xC)))(c)))},l.domain=function(c){return arguments.length?(e=Array.from(c,gX),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=O7,A()},l.clamp=function(c){return arguments.length?(C=c?!0:rr,A()):C!==rr},l.interpolate=function(c){return arguments.length?(i=c,A()):i},l.unknown=function(c){return arguments.length?(r=c,l):r},function(c,u){return I=c,n=u,A()}}function _7(){return eN()(rr,rr)}function aIt(e){return Math.abs(e=Math.round(e))>=1e21?e.toLocaleString("en").replace(/,/g,""):e.toString(10)}function iX(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=iX(Math.abs(e)),e?e[1]:NaN}function AIt(e,g){return function(i,I){for(var n=i.length,r=[],C=0,o=e[0],a=0;n>0&&o>0&&(a+o+1>I&&(o=Math.max(1,I-a)),r.push(i.substring(n-=o,n+o)),!((a+=o+1)>I));)o=e[C=(C+1)%e.length];return r.reverse().join(g)}}function sIt(e){return function(g){return g.replace(/[0-9]/g,function(i){return e[+i]})}}var lIt=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function Vb(e){if(!(g=lIt.exec(e)))throw new Error("invalid format: "+e);var g;return new tN({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]})}Vb.prototype=tN.prototype;function tN(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+""}tN.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 cIt(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 xye;function uIt(e,g){var i=iX(e,g);if(!i)return e+"";var I=i[0],n=i[1],r=n-(xye=Math.max(-8,Math.min(8,Math.floor(n/3)))*3)+1,C=I.length;return r===C?I:r>C?I+new Array(r-C+1).join("0"):r>0?I.slice(0,r)+"."+I.slice(r):"0."+new Array(1-r).join("0")+iX(e,Math.max(0,g+r-1))[0]}function Mge(e,g){var i=iX(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 zge={"%":(e,g)=>(e*100).toFixed(g),b:e=>Math.round(e).toString(2),c:e=>e+"",d:aIt,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)=>Mge(e*100,g),r:Mge,s:uIt,X:e=>Math.round(e).toString(16).toUpperCase(),x:e=>Math.round(e).toString(16)};function Pge(e){return e}var Jge=Array.prototype.map,Oge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Eye(e){var g=e.grouping===void 0||e.thousands===void 0?Pge:AIt(Jge.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+"",r=e.numerals===void 0?Pge:sIt(Jge.call(e.numerals,String)),C=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=Vb(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"):zge[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)?C:"",v=zge[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=B,W=G,V,H,Y;if(Z==="c")W=v(S)+W,S="";else{S=+S;var K=S<0||1/S<0;if(S=isNaN(S)?a:v(Math.abs(S),p),y&&(S=cIt(S)),K&&+S==0&&d!=="+"&&(K=!1),X=(K?d==="("?d:o:d==="-"||d==="("?"":d)+X,W=(Z==="s"?Oge[8+xye/3]:"")+W+(K&&d==="("?")":""),w){for(V=-1,H=S.length;++VY||Y>57){W=(Y===46?n+S.slice(V+1):S.slice(V))+W,S=S.slice(0,V);break}}}b&&!m&&(S=g(S,1/0));var x=X.length+S.length+W.length,J=x>1)+X+S+W+J.slice(x);break;default:S=J+X+S+W;break}return r(S)}return R.toString=function(){return l+""},R}function A(l,c){var u=s((l=Vb(l),l.type="f",l)),d=Math.max(-8,Math.min(8,Math.floor(Rb(c)/3)))*3,h=Math.pow(10,-d),m=Oge[8+d/3];return function(f){return u(h*f)+m}}return{format:s,formatPrefix:A}}var rV,uC,tm;Mye({thousands:",",grouping:[3],currency:["$",""]});function Mye(e){return rV=Eye(e),uC=rV.format,tm=rV.formatPrefix,rV}function zye(e){return Math.max(0,-Rb(Math.abs(e)))}function D0(e,g){return Math.max(0,Math.max(-8,Math.min(8,Math.floor(Rb(g)/3)))*3-Rb(Math.abs(e)))}function Pye(e,g){return e=Math.abs(e),g=Math.abs(g)-e,Math.max(0,Rb(g)-Rb(e))+1}const dIt=Object.freeze(Object.defineProperty({__proto__:null,FormatSpecifier:tN,get format(){return uC},formatDefaultLocale:Mye,formatLocale:Eye,get formatPrefix(){return tm},formatSpecifier:Vb,precisionFixed:zye,precisionPrefix:D0,precisionRound:Pye},Symbol.toStringTag,{value:"Module"}));function Jye(e,g,i,I){var n=q9(e,g,i),r;switch(I=Vb(I??",f"),I.type){case"s":{var C=Math.max(Math.abs(e),Math.abs(g));return I.precision==null&&!isNaN(r=D0(n,C))&&(I.precision=r),tm(I,C)}case"":case"e":case"g":case"p":case"r":{I.precision==null&&!isNaN(r=Pye(n,Math.max(Math.abs(e),Math.abs(g))))&&(I.precision=r-(I.type==="e"));break}case"f":case"%":{I.precision==null&&!isNaN(r=zye(n))&&(I.precision=r-(I.type==="%")*2);break}}return uC(I)}function nu(e){var g=e.domain;return e.ticks=function(i){var I=g();return nh(I[0],I[I.length-1],i??10)},e.tickFormat=function(i,I){var n=g();return Jye(n[0],n[n.length-1],i??10,I)},e.nice=function(i){i==null&&(i=10);var I=g(),n=0,r=I.length-1,C=I[n],o=I[r],a,s,A=10;for(o0;){if(s=FS(C,o,i),s===a)return I[n]=C,I[r]=o,g(I);if(s>0)C=Math.floor(C/s)*s,o=Math.ceil(o/s)*s;else if(s<0)C=Math.ceil(C*s)/s,o=Math.floor(o*s)/s;else break;a=s}return e},e}function tg(){var e=_7();return e.copy=function(){return ES(e,tg())},Ao.apply(e,arguments),nu(e)}function Oye(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,gX),i):e.slice()},i.unknown=function(I){return arguments.length?(g=I,i):g},i.copy=function(){return Oye(e).unknown(g)},e=arguments.length?Array.from(e,gX):[0,1],nu(i)}function _ye(e,g){e=e.slice();var i=0,I=e.length-1,n=e[i],r=e[I],C;return rMath.pow(e,g)}function bIt(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 Uge(e){return(g,i)=>-e(-g,i)}function L7(e){const g=e(_ge,Lge),i=g.domain;let I=10,n,r;function C(){return n=bIt(I),r=pIt(I),i()[0]<0?(n=Uge(n),r=Uge(r),e(hIt,mIt)):e(_ge,Lge),g}return g.base=function(o){return arguments.length?(I=+o,C()):I},g.domain=function(o){return arguments.length?(i(o),C()):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/r(-c):d*r(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=Vb(a)).precision==null&&(a.trim=!0),a=uC(a)),o===1/0)return a;const s=Math.max(1,I*o/g.ticks().length);return A=>{let l=A/r(Math.round(n(A)));return l*Ii(_ye(i(),{floor:o=>r(Math.floor(n(o))),ceil:o=>r(Math.ceil(n(o)))})),g}function ru(){const e=L7(eN()).domain([1,10]);return e.copy=()=>ES(e,ru()).base(e.base()),Ao.apply(e,arguments),e}function Qge(e){return function(g){return Math.sign(g)*Math.log1p(Math.abs(g/e))}}function jge(e){return function(g){return Math.sign(g)*Math.expm1(Math.abs(g))*e}}function U7(e){var g=1,i=e(Qge(g),jge(g));return i.constant=function(I){return arguments.length?e(Qge(g=+I),jge(g)):g},nu(i)}function Lye(){var e=U7(eN());return e.copy=function(){return ES(e,Lye()).constant(e.constant())},Ao.apply(e,arguments)}function $ge(e){return function(g){return g<0?-Math.pow(-g,e):Math.pow(g,e)}}function yIt(e){return e<0?-Math.sqrt(-e):Math.sqrt(e)}function ZIt(e){return e<0?-e*e:e*e}function Q7(e){var g=e(rr,rr),i=1;function I(){return i===1?e(rr,rr):i===.5?e(yIt,ZIt):e($ge(i),$ge(1/i))}return g.exponent=function(n){return arguments.length?(i=+n,I()):i},nu(g)}function j7(){var e=Q7(eN());return e.copy=function(){return ES(e,j7()).exponent(e.exponent())},Ao.apply(e,arguments),e}function GIt(){return j7.apply(null,arguments).exponent(.5)}function qge(e){return Math.sign(e)*e*e}function vIt(e){return Math.sign(e)*Math.sqrt(Math.abs(e))}function Uye(){var e=_7(),g=[0,1],i=!1,I;function n(r){var C=vIt(e(r));return isNaN(C)?I:i?Math.round(C):C}return n.invert=function(r){return e.invert(qge(r))},n.domain=function(r){return arguments.length?(e.domain(r),n):e.domain()},n.range=function(r){return arguments.length?(e.range((g=Array.from(r,gX)).map(qge)),n):g.slice()},n.rangeRound=function(r){return n.range(r).round(!0)},n.round=function(r){return arguments.length?(i=!!r,n):i},n.clamp=function(r){return arguments.length?(e.clamp(r),n):e.clamp()},n.unknown=function(r){return arguments.length?(I=r,n):I},n.copy=function(){return Uye(e.domain(),g).round(i).clamp(e.clamp()).unknown(I)},Ao.apply(n,arguments),nu(n)}function IX(){var e=[],g=[],i=[],I;function n(){var C=0,o=Math.max(1,g.length);for(i=new Array(o-1);++C0?i[o-1]:e[0],o=i?[I[i-1],g]:[I[s-1],I[s]]},C.unknown=function(a){return arguments.length&&(r=a),C},C.thresholds=function(){return I.slice()},C.copy=function(){return Qye().domain([e,g]).range(n).unknown(r)},Ao.apply(nu(C),arguments)}function jye(){var e=[.5],g=[0,1],i,I=1;function n(r){return r!=null&&r<=r?g[qh(e,r,0,I)]:i}return n.domain=function(r){return arguments.length?(e=Array.from(r),I=Math.min(e.length,g.length-1),n):e.slice()},n.range=function(r){return arguments.length?(g=Array.from(r),I=Math.min(e.length,g.length-1),n):g.slice()},n.invertExtent=function(r){var C=g.indexOf(r);return[e[C-1],e[C]]},n.unknown=function(r){return arguments.length?(i=r,n):i},n.copy=function(){return jye().domain(e).range(g).unknown(i)},Ao.apply(n,arguments)}const J5=new Date,O5=new Date;function FI(e,g,i,I){function n(r){return e(r=arguments.length===0?new Date:new Date(+r)),r}return n.floor=r=>(e(r=new Date(+r)),r),n.ceil=r=>(e(r=new Date(r-1)),g(r,1),e(r),r),n.round=r=>{const C=n(r),o=n.ceil(r);return r-C(g(r=new Date(+r),C==null?1:Math.floor(C)),r),n.range=(r,C,o)=>{const a=[];if(r=n.ceil(r),o=o==null?1:Math.floor(o),!(r0))return a;let s;do a.push(s=new Date(+r)),g(r,o),e(r);while(sFI(C=>{if(C>=C)for(;e(C),!r(C);)C.setTime(C-1)},(C,o)=>{if(C>=C)if(o<0)for(;++o<=0;)for(;g(C,-1),!r(C););else for(;--o>=0;)for(;g(C,1),!r(C););}),i&&(n.count=(r,C)=>(J5.setTime(+r),O5.setTime(+C),e(J5),e(O5),Math.floor(i(J5,O5))),n.every=r=>(r=Math.floor(r),!isFinite(r)||!(r>0)?null:r>1?n.filter(I?C=>I(C)%r===0:C=>n.count(0,C)%r===0):n)),n}const nX=FI(()=>{},(e,g)=>{e.setTime(+e+g)},(e,g)=>g-e);nX.every=e=>(e=Math.floor(e),!isFinite(e)||!(e>0)?null:e>1?FI(g=>{g.setTime(Math.floor(g/e)*e)},(g,i)=>{g.setTime(+g+i*e)},(g,i)=>(i-g)/e):nX);nX.range;const ds=1e3,_C=ds*60,hs=_C*60,xs=hs*24,$7=xs*7,eie=xs*30,_5=xs*365,sd=FI(e=>{e.setTime(e-e.getMilliseconds())},(e,g)=>{e.setTime(+e+g*ds)},(e,g)=>(g-e)/ds,e=>e.getUTCSeconds());sd.range;const q7=FI(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*ds)},(e,g)=>{e.setTime(+e+g*_C)},(e,g)=>(g-e)/_C,e=>e.getMinutes());q7.range;const eQ=FI(e=>{e.setUTCSeconds(0,0)},(e,g)=>{e.setTime(+e+g*_C)},(e,g)=>(g-e)/_C,e=>e.getUTCMinutes());eQ.range;const tQ=FI(e=>{e.setTime(e-e.getMilliseconds()-e.getSeconds()*ds-e.getMinutes()*_C)},(e,g)=>{e.setTime(+e+g*hs)},(e,g)=>(g-e)/hs,e=>e.getHours());tQ.range;const gQ=FI(e=>{e.setUTCMinutes(0,0,0)},(e,g)=>{e.setTime(+e+g*hs)},(e,g)=>(g-e)/hs,e=>e.getUTCHours());gQ.range;const MS=FI(e=>e.setHours(0,0,0,0),(e,g)=>e.setDate(e.getDate()+g),(e,g)=>(g-e-(g.getTimezoneOffset()-e.getTimezoneOffset())*_C)/xs,e=>e.getDate()-1);MS.range;const gN=FI(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/xs,e=>e.getUTCDate()-1);gN.range;const $ye=FI(e=>{e.setUTCHours(0,0,0,0)},(e,g)=>{e.setUTCDate(e.getUTCDate()+g)},(e,g)=>(g-e)/xs,e=>Math.floor(e/xs));$ye.range;function gm(e){return FI(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())*_C)/$7)}const iN=gm(0),rX=gm(1),BIt=gm(2),SIt=gm(3),Wb=gm(4),wIt=gm(5),RIt=gm(6);iN.range;rX.range;BIt.range;SIt.range;Wb.range;wIt.range;RIt.range;function im(e){return FI(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)/$7)}const IN=im(0),CX=im(1),VIt=im(2),WIt=im(3),Xb=im(4),XIt=im(5),HIt=im(6);IN.range;CX.range;VIt.range;WIt.range;Xb.range;XIt.range;HIt.range;const iQ=FI(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());iQ.range;const IQ=FI(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());IQ.range;const Es=FI(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());Es.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:FI(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)});Es.range;const Ms=FI(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());Ms.every=e=>!isFinite(e=Math.floor(e))||!(e>0)?null:FI(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)});Ms.range;function qye(e,g,i,I,n,r){const C=[[sd,1,ds],[sd,5,5*ds],[sd,15,15*ds],[sd,30,30*ds],[r,1,_C],[r,5,5*_C],[r,15,15*_C],[r,30,30*_C],[n,1,hs],[n,3,3*hs],[n,6,6*hs],[n,12,12*hs],[I,1,xs],[I,2,2*xs],[i,1,$7],[g,1,eie],[g,3,3*eie],[e,1,_5]];function o(s,A,l){const c=Am).right(C,c);if(u===C.length)return e.every(q9(s/_5,A/_5,l));if(u===0)return nX.every(Math.max(q9(s,A,l),1));const[d,h]=C[c/C[u-1][2]53)return null;"w"in ve||(ve.w=1),"Z"in ve?(Be=U5(Ly(ve.y,0,1)),Je=Be.getUTCDay(),Be=Je>4||Je===0?CX.ceil(Be):CX(Be),Be=gN.offset(Be,(ve.V-1)*7),ve.y=Be.getUTCFullYear(),ve.m=Be.getUTCMonth(),ve.d=Be.getUTCDate()+(ve.w+6)%7):(Be=L5(Ly(ve.y,0,1)),Je=Be.getDay(),Be=Je>4||Je===0?rX.ceil(Be):rX(Be),Be=MS.offset(Be,(ve.V-1)*7),ve.y=Be.getFullYear(),ve.m=Be.getMonth(),ve.d=Be.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),Je="Z"in ve?U5(Ly(ve.y,0,1)).getUTCDay():L5(Ly(ve.y,0,1)).getDay(),ve.m=0,ve.d="W"in ve?(ve.w+6)%7+ve.W*7-(Je+5)%7:ve.w+ve.U*7-(Je+6)%7);return"Z"in ve?(ve.H+=ve.Z/100|0,ve.M+=ve.Z%100,U5(ve)):L5(ve)}}function v(ne,be,pe,ve){for(var We=0,Be=be.length,Je=pe.length,Pe,De;We=Je)return-1;if(Pe=be.charCodeAt(We++),Pe===37){if(Pe=be.charAt(We++),De=Z[Pe in tie?be.charAt(We++):Pe],!De||(ve=De(ne,pe,ve))<0)return-1}else if(Pe!=pe.charCodeAt(ve++))return-1}return ve}function w(ne,be,pe){var ve=s.exec(be.slice(pe));return ve?(ne.p=A.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function R(ne,be,pe){var ve=u.exec(be.slice(pe));return ve?(ne.w=d.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function S(ne,be,pe){var ve=l.exec(be.slice(pe));return ve?(ne.w=c.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function X(ne,be,pe){var ve=f.exec(be.slice(pe));return ve?(ne.m=b.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function W(ne,be,pe){var ve=h.exec(be.slice(pe));return ve?(ne.m=m.get(ve[0].toLowerCase()),pe+ve[0].length):-1}function V(ne,be,pe){return v(ne,g,be,pe)}function H(ne,be,pe){return v(ne,i,be,pe)}function Y(ne,be,pe){return v(ne,I,be,pe)}function K(ne){return C[ne.getDay()]}function x(ne){return r[ne.getDay()]}function J(ne){return a[ne.getMonth()]}function P(ne){return o[ne.getMonth()]}function ge(ne){return n[+(ne.getHours()>=12)]}function q(ne){return 1+~~(ne.getMonth()/3)}function $(ne){return C[ne.getUTCDay()]}function j(ne){return r[ne.getUTCDay()]}function te(ne){return a[ne.getUTCMonth()]}function Q(ne){return o[ne.getUTCMonth()]}function Ie(ne){return n[+(ne.getUTCHours()>=12)]}function he(ne){return 1+~~(ne.getUTCMonth()/3)}return{format:function(ne){var be=B(ne+="",p);return be.toString=function(){return ne},be},parse:function(ne){var be=G(ne+="",!1);return be.toString=function(){return ne},be},utcFormat:function(ne){var be=B(ne+="",y);return be.toString=function(){return ne},be},utcParse:function(ne){var be=G(ne+="",!0);return be.toString=function(){return ne},be}}}var tie={"-":"",_:" ",0:"0"},$I=/^\s*\d+/,FIt=/^%/,DIt=/[\\^$*+?|[\]().{}]/g;function Yg(e,g,i){var I=e<0?"-":"",n=(I?-e:e)+"",r=n.length;return I+(r[g.toLowerCase(),i]))}function EIt(e,g,i){var I=$I.exec(g.slice(i,i+1));return I?(e.w=+I[0],i+I[0].length):-1}function MIt(e,g,i){var I=$I.exec(g.slice(i,i+1));return I?(e.u=+I[0],i+I[0].length):-1}function zIt(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.U=+I[0],i+I[0].length):-1}function PIt(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.V=+I[0],i+I[0].length):-1}function JIt(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.W=+I[0],i+I[0].length):-1}function gie(e,g,i){var I=$I.exec(g.slice(i,i+4));return I?(e.y=+I[0],i+I[0].length):-1}function iie(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 OIt(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 _It(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 LIt(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 Iie(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.d=+I[0],i+I[0].length):-1}function UIt(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 nie(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.H=+I[0],i+I[0].length):-1}function QIt(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.M=+I[0],i+I[0].length):-1}function jIt(e,g,i){var I=$I.exec(g.slice(i,i+2));return I?(e.S=+I[0],i+I[0].length):-1}function $It(e,g,i){var I=$I.exec(g.slice(i,i+3));return I?(e.L=+I[0],i+I[0].length):-1}function qIt(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 ent(e,g,i){var I=FIt.exec(g.slice(i,i+1));return I?i+I[0].length:-1}function tnt(e,g,i){var I=$I.exec(g.slice(i));return I?(e.Q=+I[0],i+I[0].length):-1}function gnt(e,g,i){var I=$I.exec(g.slice(i));return I?(e.s=+I[0],i+I[0].length):-1}function rie(e,g){return Yg(e.getDate(),g,2)}function int(e,g){return Yg(e.getHours(),g,2)}function Int(e,g){return Yg(e.getHours()%12||12,g,2)}function nnt(e,g){return Yg(1+MS.count(Es(e),e),g,3)}function eZe(e,g){return Yg(e.getMilliseconds(),g,3)}function rnt(e,g){return eZe(e,g)+"000"}function Cnt(e,g){return Yg(e.getMonth()+1,g,2)}function ont(e,g){return Yg(e.getMinutes(),g,2)}function ant(e,g){return Yg(e.getSeconds(),g,2)}function Ant(e){var g=e.getDay();return g===0?7:g}function snt(e,g){return Yg(iN.count(Es(e)-1,e),g,2)}function tZe(e){var g=e.getDay();return g>=4||g===0?Wb(e):Wb.ceil(e)}function lnt(e,g){return e=tZe(e),Yg(Wb.count(Es(e),e)+(Es(e).getDay()===4),g,2)}function cnt(e){return e.getDay()}function unt(e,g){return Yg(rX.count(Es(e)-1,e),g,2)}function dnt(e,g){return Yg(e.getFullYear()%100,g,2)}function hnt(e,g){return e=tZe(e),Yg(e.getFullYear()%100,g,2)}function mnt(e,g){return Yg(e.getFullYear()%1e4,g,4)}function fnt(e,g){var i=e.getDay();return e=i>=4||i===0?Wb(e):Wb.ceil(e),Yg(e.getFullYear()%1e4,g,4)}function pnt(e){var g=e.getTimezoneOffset();return(g>0?"-":(g*=-1,"+"))+Yg(g/60|0,"0",2)+Yg(g%60,"0",2)}function Cie(e,g){return Yg(e.getUTCDate(),g,2)}function bnt(e,g){return Yg(e.getUTCHours(),g,2)}function ynt(e,g){return Yg(e.getUTCHours()%12||12,g,2)}function Znt(e,g){return Yg(1+gN.count(Ms(e),e),g,3)}function gZe(e,g){return Yg(e.getUTCMilliseconds(),g,3)}function Gnt(e,g){return gZe(e,g)+"000"}function vnt(e,g){return Yg(e.getUTCMonth()+1,g,2)}function Bnt(e,g){return Yg(e.getUTCMinutes(),g,2)}function Snt(e,g){return Yg(e.getUTCSeconds(),g,2)}function wnt(e){var g=e.getUTCDay();return g===0?7:g}function Rnt(e,g){return Yg(IN.count(Ms(e)-1,e),g,2)}function iZe(e){var g=e.getUTCDay();return g>=4||g===0?Xb(e):Xb.ceil(e)}function Vnt(e,g){return e=iZe(e),Yg(Xb.count(Ms(e),e)+(Ms(e).getUTCDay()===4),g,2)}function Wnt(e){return e.getUTCDay()}function Xnt(e,g){return Yg(CX.count(Ms(e)-1,e),g,2)}function Hnt(e,g){return Yg(e.getUTCFullYear()%100,g,2)}function Tnt(e,g){return e=iZe(e),Yg(e.getUTCFullYear()%100,g,2)}function Nnt(e,g){return Yg(e.getUTCFullYear()%1e4,g,4)}function knt(e,g){var i=e.getUTCDay();return e=i>=4||i===0?Xb(e):Xb.ceil(e),Yg(e.getUTCFullYear()%1e4,g,4)}function Ynt(){return"+0000"}function oie(){return"%"}function aie(e){return+e}function Aie(e){return Math.floor(+e/1e3)}var Fm,IZe,nZe;Knt({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 Knt(e){return Fm=KIt(e),IZe=Fm.format,Fm.parse,nZe=Fm.utcFormat,Fm.utcParse,Fm}function Fnt(e){return new Date(e)}function Dnt(e){return e instanceof Date?+e:+new Date(+e)}function nQ(e,g,i,I,n,r,C,o,a,s){var A=_7(),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,r)=>WB(e,r/I))},i.copy=function(){return aZe(g).domain(e)},tl.apply(i,arguments)}function rN(){var e=0,g=.5,i=1,I=1,n,r,C,o,a,s=rr,A,l=!1,c;function u(h){return isNaN(h=+h)?c:(h=.5+((h=+A(h))-r)*(I*h1&&arguments[1]!==void 0?arguments[1]:0,i=(In[e[g+0]]+In[e[g+1]]+In[e[g+2]]+In[e[g+3]]+"-"+In[e[g+4]]+In[e[g+5]]+"-"+In[e[g+6]]+In[e[g+7]]+"-"+In[e[g+8]]+In[e[g+9]]+"-"+In[e[g+10]]+In[e[g+11]]+In[e[g+12]]+In[e[g+13]]+In[e[g+14]]+In[e[g+15]]).toLowerCase();if(!CN(i))throw TypeError("Stringified UUID is invalid");return i}var sie,j5,$5=0,q5=0;function _nt(e,g,i){var I=g&&i||0,n=g||new Array(16);e=e||{};var r=e.node||sie,C=e.clockseq!==void 0?e.clockseq:j5;if(r==null||C==null){var o=e.random||(e.rng||cZe)();r==null&&(r=sie=[o[0]|1,o[1],o[2],o[3],o[4],o[5]]),C==null&&(C=j5=(o[6]<<8|o[7])&16383)}var a=e.msecs!==void 0?e.msecs:Date.now(),s=e.nsecs!==void 0?e.nsecs:q5+1,A=a-$5+(s-q5)/1e4;if(A<0&&e.clockseq===void 0&&(C=C+1&16383),(A<0||a>$5)&&e.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");$5=a,q5=s,j5=C,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++]=C>>>8|128,n[I++]=C&255;for(var u=0;u<6;++u)n[I+u]=r[u];return g||oN(n)}function uZe(e){if(!CN(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 Lnt(e){e=unescape(encodeURIComponent(e));for(var g=[],i=0;i>5]>>>n%32&255,C=parseInt(I.charAt(r>>>4&15)+I.charAt(r&15),16);g.push(C)}return g}function hZe(e){return(e+64>>>9<<4)+14+1}function qnt(e,g){e[g>>5]|=128<>5]|=(e[I/8]&255)<>16)+(g>>16)+(i>>16);return I<<16|i&65535}function trt(e,g){return e<>>32-g}function aN(e,g,i,I,n,r){return uc(trt(uc(uc(g,e),uc(I,r)),n),i)}function Bn(e,g,i,I,n,r,C){return aN(g&i|~g&I,e,g,n,r,C)}function Sn(e,g,i,I,n,r,C){return aN(g&I|i&~I,e,g,n,r,C)}function wn(e,g,i,I,n,r,C){return aN(g^i^I,e,g,n,r,C)}function Rn(e,g,i,I,n,r,C){return aN(i^(g|~I),e,g,n,r,C)}var grt=dZe("v3",48,jnt);const irt=grt;function Irt(e,g,i){e=e||{};var I=e.random||(e.rng||cZe)();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 oN(I)}function nrt(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 eF(e,g){return e<>>32-g}function rrt(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=eF(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 Crt=dZe("v5",80,rrt);const ort=Crt,art="00000000-0000-0000-0000-000000000000";function Art(e){if(!CN(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)}const srt=Object.freeze(Object.defineProperty({__proto__:null,NIL:art,parse:uZe,stringify:oN,v1:_nt,v3:irt,v4:Irt,v5:ort,validate:CN,version:Art},Symbol.toStringTag,{value:"Module"})),lrt=qs(srt);var AN=lrt,oQ=(()=>typeof Buffer<"u"?e=>Buffer.from(e).toString("base64"):e=>btoa(String.fromCharCode(...e)))(),crt=(()=>typeof Buffer<"u"?e=>Buffer.from(e,"base64"):e=>Uint8Array.from(atob(e),g=>g.charCodeAt(0)))();zS.encode=function(e){var g=AN.parse(e),i=oQ(g),I=i.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return I};zS.decode=function(e){var g=e.replace(/-/g,"+").replace(/_/g,"/")+"==";return AN.stringify(crt(g))};zS.v4=function(){var e=AN.v4(null,new Uint8Array(16)),g=oQ(e),i=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};zS.nice=function(){var e=AN.v4(null,new Uint8Array(16));e[0]=e[0]&127;var g=oQ(e),i=g.replace(/\+/g,"-").replace(/\//g,"_").substring(0,22);return i};var urt=zS;const sg=Pr(urt);var mZe={exports:{}},sN={},oX={exports:{}};oX.exports;(function(e,g){var i=200,I="__lodash_hash_undefined__",n=1,r=2,C=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]",R="[object WeakMap]",S="[object ArrayBuffer]",X="[object DataView]",W="[object Float32Array]",V="[object Float64Array]",H="[object Int8Array]",Y="[object Int16Array]",K="[object Int32Array]",x="[object Uint8Array]",J="[object Uint8ClampedArray]",P="[object Uint16Array]",ge="[object Uint32Array]",q=/[\\^$.*+?()[\]{}|]/g,$=/^\[object .+?Constructor\]$/,j=/^(?:0|[1-9]\d*)$/,te={};te[W]=te[V]=te[H]=te[Y]=te[K]=te[x]=te[J]=te[P]=te[ge]=!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[R]=!1;var Q=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,Ie=typeof self=="object"&&self&&self.Object===Object&&self,he=Q||Ie||Function("return this")(),ne=g&&!g.nodeType&&g,be=ne&&!0&&e&&!e.nodeType&&e,pe=be&&be.exports===ne,ve=pe&&Q.process,We=function(){try{return ve&&ve.binding&&ve.binding("util")}catch{}}(),Be=We&&We.isTypedArray;function Je(Se,ze){for(var rt=-1,St=Se==null?0:Se.length,si=0,rg=[];++rt-1}function At(Se,ze){var rt=this.__data__,St=Pi(rt,Se);return St<0?(++this.size,rt.push([Se,ze])):rt[St][1]=ze,this}yt.prototype.clear=kt,yt.prototype.delete=ht,yt.prototype.get=Rt,yt.prototype.has=xt,yt.prototype.set=At;function Xt(Se){var ze=-1,rt=Se==null?0:Se.length;for(this.clear();++zexI))return!1;var Ti=rg.get(Se);if(Ti&&rg.get(ze))return Ti==ze;var Lr=-1,uo=!0,yn=rt&r?new Zt:void 0;for(rg.set(Se,ze),rg.set(ze,Se);++Lr-1&&Se%1==0&&Se-1&&Se%1==0&&Se<=C}function o6(Se){var ze=typeof Se;return Se!=null&&(ze=="object"||ze=="function")}function yy(Se){return Se!=null&&typeof Se=="object"}var a6=Be?_e(Be):Ske;function xke(Se){return Fke(Se)?hg(Se):wke(Se)}function Eke(){return[]}function Mke(){return!1}e.exports=Dke})(oX,oX.exports);var lN=oX.exports,fZe={exports:{}};/*! Copyright (c) 2018 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(e){(function(){var g={}.hasOwnProperty;function I(){for(var i=[],n=0;ng&&(g=I);return g}function lCt(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 cZe(e,g,I){for(var i=IQ(e),n=iQ(e,g),C=Array(e.length),r=0,o=n.length;rg.y+g.h)break;AN(g,o)&&P3(e,o,I+g[n],i)}}g[i]=I}function uZe(e,g,I,i,n){var C=I==="vertical",r=I==="horizontal";if(C)for(g.y=Math.min(C9(e),g.y);g.y>0&&!Wp(e,g);)g.y--;else if(r)for(g.y=Math.min(C9(e),g.y);g.x>0&&!Wp(e,g);)g.x--;for(var o=void 0;o=Wp(e,g);)r?P3(n,g,o.x+o.w,"x"):P3(n,g,o.y+o.h,"y"),r&&g.x+g.w>i&&(g.x=i-g.w,g.y++);return g}function dZe(e,g){for(var I=IQ(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(;Wp(I,C);)C.y++}return e}function hZe(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=mZe(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 pZe(e){return[].concat(e).sort(function(g,I){return g.x>I.x||g.x===I.x&&g.y>I.y?1:-1})}function fCt(e,g,I,i){e=e||[];var n=[];return z3.default.Children.forEach(g,function(C,r){var o=hZe(e,String(C.key));if(o)n[r]=Rp(o);else{var a=C.props["data-grid"]||C.props._grid;a?n[r]=Rp(oCt({},a,{i:C.key})):n[r]=Rp({w:1,h:1,x:0,y:C9(n),i:String(C.key)})}}),n=dZe(n,{cols:I}),n=cZe(n,i,I),n}function pCt(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?Ve-1:0),xe=1;xe2?Fe-2:0),Me=2;Meg&&(g=i);return g}function prt(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 yZe(e,g,i){for(var I=aQ(e),n=AQ(e,g),r=Array(e.length),C=0,o=n.length;Cg.y+g.h)break;cN(g,o)&&U3(e,o,i+g[n],I)}}g[I]=i}function ZZe(e,g,i,I,n){var r=i==="vertical",C=i==="horizontal";if(r)for(g.y=Math.min(aX(e),g.y);g.y>0&&!Xp(e,g);)g.y--;else if(C)for(g.y=Math.min(aX(e),g.y);g.x>0&&!Xp(e,g);)g.x--;for(var o=void 0;o=Xp(e,g);)C?U3(n,g,o.x+o.w,"x"):U3(n,g,o.y+o.h,"y"),C&&g.x+g.w>I&&(g.x=I-g.w,g.y++);return g}function GZe(e,g){for(var i=aQ(e),I=0,n=e.length;Ig.cols&&(r.x=g.cols-r.w),r.x<0&&(r.x=0,r.w=g.cols),!r.static)i.push(r);else for(;Xp(i,r);)r.y++}return e}function vZe(e,g){for(var i=0,I=e.length;i=I:C==="horizontal"&&typeof i=="number"?a>=i:!1;l&&(A=A.reverse());var c=BZe(A,g);if(r&&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 wZe(e){return[].concat(e).sort(function(g,i){return g.x>i.x||g.x===i.x&&g.y>i.y?1:-1})}function Brt(e,g,i,I){e=e||[];var n=[];return L3.default.Children.forEach(g,function(r,C){var o=vZe(e,String(r.key));if(o)n[C]=Wp(o);else{var a=r.props["data-grid"]||r.props._grid;a?n[C]=Wp(drt({},a,{i:r.key})):n[C]=Wp({w:1,h:1,x:0,y:aX(n),i:String(r.key)})}}),n=GZe(n,{cols:i}),n=yZe(n,I,i),n}function Srt(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?Re-1:0),Fe=1;Fe2?xe-2:0),Me=2;Me"u"||It===null)return""+It;var Zt=Pt(It);if(Zt==="object"){if(It instanceof Date)return"date";if(It instanceof RegExp)return"regexp"}return Zt}function Rg(It){var Zt=xt(It);switch(Zt){case"array":case"object":return"an "+Zt;case"boolean":case"date":case"regexp":return"a "+Zt;default:return Zt}}function qg(It){return!It.constructor||!It.constructor.name?Me:It.constructor.name}return ke.checkPropTypes=S,ke.PropTypes=ke,ke},W=n(function(re){{var oe=typeof Symbol=="function"&&Symbol.for&&Symbol.for("react.element")||60103,Ve=function(xe){return typeof xe=="object"&&xe!==null&&xe.$$typeof===oe},Fe=!0;re.exports=X(Ve,Fe)}}),R=n(function(re){/*! +*/var d=Object.getOwnPropertySymbols,h=Object.prototype.hasOwnProperty,m=Object.prototype.propertyIsEnumerable;function f(Ce){if(Ce==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(Ce)}function b(){try{if(!Object.assign)return!1;var Ce=new String("abc");if(Ce[5]="de",Object.getOwnPropertyNames(Ce)[0]==="5")return!1;for(var oe={},Re=0;Re<10;Re++)oe["_"+String.fromCharCode(Re)]=Re;var xe=Object.getOwnPropertyNames(oe).map(function(Me){return oe[Me]});if(xe.join("")!=="0123456789")return!1;var Fe={};return"abcdefghijklmnopqrst".split("").forEach(function(Me){Fe[Me]=Me}),Object.keys(Object.assign({},Fe)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var p=b()?Object.assign:function(Ce,oe){for(var Re,xe=f(Ce),Fe,Me=1;Me"u"||it===null)return""+it;var Zt=Pt(it);if(Zt==="object"){if(it instanceof Date)return"date";if(it instanceof RegExp)return"regexp"}return Zt}function Vg(it){var Zt=Ft(it);switch(Zt){case"array":case"object":return"an "+Zt;case"boolean":case"date":case"regexp":return"a "+Zt;default:return Zt}}function qg(it){return!it.constructor||!it.constructor.name?Me:it.constructor.name}return ke.checkPropTypes=S,ke.PropTypes=ke,ke},W=n(function(Ce){{var oe=typeof Symbol=="function"&&Symbol.for&&Symbol.for("react.element")||60103,Re=function(Fe){return typeof Fe=="object"&&Fe!==null&&Fe.$$typeof===oe},xe=!0;Ce.exports=X(Re,xe)}}),V=n(function(Ce){/*! Copyright (c) 2016 Jed Watson. Licensed under the MIT License (MIT), see http://jedwatson.github.io/classnames -*/(function(){var oe={}.hasOwnProperty;function Ve(){for(var Fe=[],xe=0;xe0&&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 Ve=0;Ve0&&arguments[0]!==void 0?arguments[0]:"transform";if(typeof window>"u"||typeof window.document>"u")return"";var oe=window.document.documentElement.style;if(Ce in oe)return"";for(var Re=0;Re0&&arguments[0]!==void 0?arguments[0]:{};return he({touchAction:"none"},re)}function Ie(re,oe){re.classList?re.classList.add(oe):re.className.match(new RegExp("(?:^|\\s)"+oe+"(?!\\S)"))||(re.className+=" "+oe)}function me(re,oe){re.classList?re.classList.remove(oe):re.className=re.className.replace(new RegExp("(?:^|\\s)"+oe+"(?!\\S)","g"),"")}function Re(re,oe,Ve){if(!re.props.bounds)return[oe,Ve];var Fe=re.props.bounds;Fe=typeof Fe=="string"?Fe:Ce(Fe);var xe=E(re);if(typeof Fe=="string"){var Me=xe.ownerDocument,ke=Me.defaultView,Ee=void 0;if(Fe==="parent"?Ee=xe.parentNode:Ee=Me.querySelector(Fe),!(Ee instanceof ke.HTMLElement))throw new Error('Bounds selector "'+Fe+'" could not find an element.');var O=ke.getComputedStyle(xe),D=ke.getComputedStyle(Ee);Fe={left:-xe.offsetLeft+F(D.paddingLeft)+F(O.marginLeft),top:-xe.offsetTop+F(D.paddingTop)+F(O.marginTop),right:gt(Ee)-Qe(xe)-xe.offsetLeft+F(D.paddingRight)-F(O.marginRight),bottom:_e(Ee)-De(xe)-xe.offsetTop+F(D.paddingBottom)-F(O.marginBottom)}}return K(Fe.right)&&(oe=Math.min(oe,Fe.right)),K(Fe.bottom)&&(Ve=Math.min(Ve,Fe.bottom)),K(Fe.left)&&(oe=Math.max(oe,Fe.left)),K(Fe.top)&&(Ve=Math.max(Ve,Fe.top)),[oe,Ve]}function we(re,oe,Ve){var Fe=Math.round(oe/re[0])*re[0],xe=Math.round(Ve/re[1])*re[1];return[Fe,xe]}function je(re){return re.props.axis==="both"||re.props.axis==="x"}function at(re){return re.props.axis==="both"||re.props.axis==="y"}function bt(re,oe,Ve){var Fe=typeof oe=="number"?ye(re,oe):null;if(typeof oe=="number"&&!Fe)return null;var xe=E(Ve),Me=Ve.props.offsetParent||xe.offsetParent||xe.ownerDocument.body;return lt(Fe||re,Me)}function ct(re,oe,Ve){var Fe=re.state,xe=!K(Fe.lastX),Me=E(re);return xe?{node:Me,deltaX:0,deltaY:0,lastX:oe,lastY:Ve,x:oe,y:Ve}:{node:Me,deltaX:oe-Fe.lastX,deltaY:Ve-Fe.lastY,lastX:Fe.lastX,lastY:Fe.lastY,x:oe,y:Ve}}function Ht(re,oe){var Ve=re.props.scale;return{node:oe.node,x:re.state.x+oe.deltaX/Ve,y:re.state.y+oe.deltaY/Ve,deltaX:oe.deltaX/Ve,deltaY:oe.deltaY/Ve,lastX:re.state.x,lastY:re.state.y}}function Ce(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 _(){}var fe={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}},Ye=fe.mouse,ue=function(re){ne(oe,re);function oe(){var Ve,Fe,xe,Me;te(this,oe);for(var ke=arguments.length,Ee=Array(ke),O=0;O not mounted on DragStart!");var ce=ee.ownerDocument;if(!(xe.props.disabled||!(D.target instanceof ce.defaultView.Node)||xe.props.handle&&!Be(D.target,xe.props.handle,ee)||xe.props.cancel&&Be(D.target,xe.props.cancel,ee))){var de=He(D);xe.setState({touchIdentifier:de});var Le=bt(D,de,xe);if(Le!=null){var Ue=Le.x,dt=Le.y,yt=ct(xe,Ue,dt);xe.props.onStart;var kt=xe.props.onStart(D,yt);kt!==!1&&(xe.props.enableUserSelectHack&&x(ce),xe.setState({dragging:!0,lastX:Ue,lastY:dt}),Je(ce,Ye.move,xe.handleDrag),Je(ce,Ye.stop,xe.handleDragStop))}}},xe.handleDrag=function(D){D.type==="touchmove"&&D.preventDefault();var ee=bt(D,xe.state.touchIdentifier,xe);if(ee!=null){var ce=ee.x,de=ee.y;if(Array.isArray(xe.props.grid)){var Le=ce-xe.state.lastX,Ue=de-xe.state.lastY,dt=we(xe.props.grid,Le,Ue),yt=pe(dt,2);if(Le=yt[0],Ue=yt[1],!Le&&!Ue)return;ce=xe.state.lastX+Le,de=xe.state.lastY+Ue}var kt=ct(xe,ce,de),ht=xe.props.onDrag(D,kt);if(ht===!1){try{xe.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),xe.handleDragStop(Vt)}return}xe.setState({lastX:ce,lastY:de})}},xe.handleDragStop=function(D){if(xe.state.dragging){var ee=bt(D,xe.state.touchIdentifier,xe);if(ee!=null){var ce=ee.x,de=ee.y,Le=ct(xe,ce,de),Ue=I.findDOMNode(xe);Ue&&xe.props.enableUserSelectHack&&T(Ue.ownerDocument),xe.setState({dragging:!1,lastX:NaN,lastY:NaN}),xe.props.onStop(D,Le),Ue&&(Pe(Ue.ownerDocument,Ye.move,xe.handleDrag),Pe(Ue.ownerDocument,Ye.stop,xe.handleDragStop))}}},xe.onMouseDown=function(D){return Ye=fe.mouse,xe.handleDragStart(D)},xe.onMouseUp=function(D){return Ye=fe.mouse,xe.handleDragStop(D)},xe.onTouchStart=function(D){return Ye=fe.touch,xe.handleDragStart(D)},xe.onTouchEnd=function(D){return Ye=fe.touch,xe.handleDragStop(D)},Fe),be(xe,Me)}return Q(oe,[{key:"componentWillUnmount",value:function(){var Fe=I.findDOMNode(this);if(Fe){var xe=Fe.ownerDocument;Pe(xe,fe.mouse.move,this.handleDrag),Pe(xe,fe.touch.move,this.handleDrag),Pe(xe,fe.mouse.stop,this.handleDragStop),Pe(xe,fe.touch.stop,this.handleDragStop),this.props.enableUserSelectHack&&T(xe)}}},{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,Ve){if(oe[Ve]&&oe[Ve].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:J,style:J,transform:J},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){ne(oe,re);function oe(Ve){te(this,oe);var Fe=be(this,(oe.__proto__||Object.getPrototypeOf(oe)).call(this,Ve));return Fe.onDragStart=function(xe,Me){var ke=Fe.props.onStart(xe,Ht(Fe,Me));if(ke===!1)return!1;Fe.setState({dragging:!0,dragged:!0})},Fe.onDrag=function(xe,Me){if(!Fe.state.dragging)return!1;var ke=Ht(Fe,Me),Ee={x:ke.x,y:ke.y};if(Fe.props.bounds){var O=Ee.x,D=Ee.y;Ee.x+=Fe.state.slackX,Ee.y+=Fe.state.slackY;var ee=Re(Fe,Ee.x,Ee.y),ce=pe(ee,2),de=ce[0],Le=ce[1];Ee.x=de,Ee.y=Le,Ee.slackX=Fe.state.slackX+(O-Ee.x),Ee.slackY=Fe.state.slackY+(D-Ee.y),ke.x=Ee.x,ke.y=Ee.y,ke.deltaX=Ee.x-Fe.state.x,ke.deltaY=Ee.y-Fe.state.y}var Ue=Fe.props.onDrag(xe,ke);if(Ue===!1)return!1;Fe.setState(Ee)},Fe.onDragStop=function(xe,Me){if(!Fe.state.dragging)return!1;var ke=Fe.props.onStop(xe,Ht(Fe,Me));if(ke===!1)return!1;var Ee={dragging:!1,slackX:0,slackY:0},O=!!Fe.props.position;if(O){var D=Fe.props.position,ee=D.x,ce=D.y;Ee.x=ee,Ee.y=ce}Fe.setState(Ee)},Fe.state={dragging:!1,dragged:!1,x:Ve.position?Ve.position.x:Ve.defaultPosition.x,y:Ve.position?Ve.position.y:Ve.defaultPosition.y,slackX:0,slackY:0,isElementSVG:!1},Ve.position&&!(Ve.onDrag||Ve.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."),Fe}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(Fe){Fe.position&&(!this.props.position||Fe.position.x!==this.props.position.x||Fe.position.y!==this.props.position.y)&&this.setState({x:Fe.position.x,y:Fe.position.y})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"render",value:function(){var Fe,xe={},Me=null,ke=!!this.props.position,Ee=!ke||this.state.dragging,O=this.props.position||this.props.defaultPosition,D={x:je(this)&&Ee?this.state.x:O.x,y:at(this)&&Ee?this.state.y:O.y};this.state.isElementSVG?Me=Xe(D,this.props.positionOffset):xe=tt(D,this.props.positionOffset);var ee=this.props,ce=ee.defaultClassName,de=ee.defaultClassNameDragging,Le=ee.defaultClassNameDragged,Ue=i.Children.only(this.props.children),dt=R(Ue.props.className||"",ce,(Fe={},ie(Fe,de,this.state.dragging),ie(Fe,Le,this.state.dragged),Fe));return i.createElement(ue,he({},this.props,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),i.cloneElement(Ue,{className:dt,style:he({},Ue.props.style,xe),transform:Me}))}}]),oe}(i.Component);return le.displayName="Draggable",le.propTypes=he({},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:J,style:J,transform:J}),le.defaultProps=he({},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})})(bZe);var yCt=bZe.exports,sN={exports:{}},ES={},lN={exports:{}},yZe={};function ZZe(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;i<$5.length;i++)if(vZe(g,$5[i])in I)return $5[i];return""}function vZe(e,g){return g?"".concat(g).concat(WCt(e)):e}function RCt(e,g){return g?"-".concat(g.toLowerCase(),"-").concat(e):e}function WCt(e){let g="",I=!0;for(let i=0;ig===I.identifier)||e.changedTouches&&(0,hr.findInArray)(e.changedTouches,I=>g===I.identifier)}function zCt(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function PCt(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;} +`,Ce.getElementsByTagName("head")[0].appendChild(oe)),Ce.body&&ie(Ce.body,"react-draggable-transparent-selection")}}function T(Ce){try{Ce&&Ce.body&&me(Ce.body,"react-draggable-transparent-selection"),Ce.selection?Ce.selection.empty():window.getSelection().removeAllRanges()}catch{}}function k(){var Ce=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return he({touchAction:"none"},Ce)}function ie(Ce,oe){Ce.classList?Ce.classList.add(oe):Ce.className.match(new RegExp("(?:^|\\s)"+oe+"(?!\\S)"))||(Ce.className+=" "+oe)}function me(Ce,oe){Ce.classList?Ce.classList.remove(oe):Ce.className=Ce.className.replace(new RegExp("(?:^|\\s)"+oe+"(?!\\S)","g"),"")}function Ve(Ce,oe,Re){if(!Ce.props.bounds)return[oe,Re];var xe=Ce.props.bounds;xe=typeof xe=="string"?xe:re(xe);var Fe=E(Ce);if(typeof xe=="string"){var Me=Fe.ownerDocument,ke=Me.defaultView,Ee=void 0;if(xe==="parent"?Ee=Fe.parentNode:Ee=Me.querySelector(xe),!(Ee instanceof ke.HTMLElement))throw new Error('Bounds selector "'+xe+'" could not find an element.');var O=ke.getComputedStyle(Fe),D=ke.getComputedStyle(Ee);xe={left:-Fe.offsetLeft+x(D.paddingLeft)+x(O.marginLeft),top:-Fe.offsetTop+x(D.paddingTop)+x(O.marginTop),right:gt(Ee)-Qe(Fe)-Fe.offsetLeft+x(D.paddingRight)-x(O.marginRight),bottom:_e(Ee)-De(Fe)-Fe.offsetTop+x(D.paddingBottom)-x(O.marginBottom)}}return K(xe.right)&&(oe=Math.min(oe,xe.right)),K(xe.bottom)&&(Re=Math.min(Re,xe.bottom)),K(xe.left)&&(oe=Math.max(oe,xe.left)),K(xe.top)&&(Re=Math.max(Re,xe.top)),[oe,Re]}function we(Ce,oe,Re){var xe=Math.round(oe/Ce[0])*Ce[0],Fe=Math.round(Re/Ce[1])*Ce[1];return[xe,Fe]}function je(Ce){return Ce.props.axis==="both"||Ce.props.axis==="x"}function at(Ce){return Ce.props.axis==="both"||Ce.props.axis==="y"}function bt(Ce,oe,Re){var xe=typeof oe=="number"?ye(Ce,oe):null;if(typeof oe=="number"&&!xe)return null;var Fe=E(Re),Me=Re.props.offsetParent||Fe.offsetParent||Fe.ownerDocument.body;return lt(xe||Ce,Me)}function ct(Ce,oe,Re){var xe=Ce.state,Fe=!K(xe.lastX),Me=E(Ce);return Fe?{node:Me,deltaX:0,deltaY:0,lastX:oe,lastY:Re,x:oe,y:Re}:{node:Me,deltaX:oe-xe.lastX,deltaY:Re-xe.lastY,lastX:xe.lastX,lastY:xe.lastY,x:oe,y:Re}}function Ht(Ce,oe){var Re=Ce.props.scale;return{node:oe.node,x:Ce.state.x+oe.deltaX/Re,y:Ce.state.y+oe.deltaY/Re,deltaX:oe.deltaX/Re,deltaY:oe.deltaY/Re,lastX:Ce.state.x,lastY:Ce.state.y}}function re(Ce){return{left:Ce.left,top:Ce.top,right:Ce.right,bottom:Ce.bottom}}function E(Ce){var oe=i.findDOMNode(Ce);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"}},Ye=fe.mouse,ue=function(Ce){ne(oe,Ce);function oe(){var Re,xe,Fe,Me;te(this,oe);for(var ke=arguments.length,Ee=Array(ke),O=0;O not mounted on DragStart!");var ce=ee.ownerDocument;if(!(Fe.props.disabled||!(D.target instanceof ce.defaultView.Node)||Fe.props.handle&&!Be(D.target,Fe.props.handle,ee)||Fe.props.cancel&&Be(D.target,Fe.props.cancel,ee))){var de=He(D);Fe.setState({touchIdentifier:de});var Le=bt(D,de,Fe);if(Le!=null){var Ue=Le.x,dt=Le.y,yt=ct(Fe,Ue,dt);Fe.props.onStart;var kt=Fe.props.onStart(D,yt);kt!==!1&&(Fe.props.enableUserSelectHack&&F(ce),Fe.setState({dragging:!0,lastX:Ue,lastY:dt}),Je(ce,Ye.move,Fe.handleDrag),Je(ce,Ye.stop,Fe.handleDragStop))}}},Fe.handleDrag=function(D){D.type==="touchmove"&&D.preventDefault();var ee=bt(D,Fe.state.touchIdentifier,Fe);if(ee!=null){var ce=ee.x,de=ee.y;if(Array.isArray(Fe.props.grid)){var Le=ce-Fe.state.lastX,Ue=de-Fe.state.lastY,dt=we(Fe.props.grid,Le,Ue),yt=pe(dt,2);if(Le=yt[0],Ue=yt[1],!Le&&!Ue)return;ce=Fe.state.lastX+Le,de=Fe.state.lastY+Ue}var kt=ct(Fe,ce,de),ht=Fe.props.onDrag(D,kt);if(ht===!1){try{Fe.handleDragStop(new MouseEvent("mouseup"))}catch{var Rt=document.createEvent("MouseEvents");Rt.initMouseEvent("mouseup",!0,!0,window,0,0,0,0,0,!1,!1,!1,!1,0,null),Fe.handleDragStop(Rt)}return}Fe.setState({lastX:ce,lastY:de})}},Fe.handleDragStop=function(D){if(Fe.state.dragging){var ee=bt(D,Fe.state.touchIdentifier,Fe);if(ee!=null){var ce=ee.x,de=ee.y,Le=ct(Fe,ce,de),Ue=i.findDOMNode(Fe);Ue&&Fe.props.enableUserSelectHack&&T(Ue.ownerDocument),Fe.setState({dragging:!1,lastX:NaN,lastY:NaN}),Fe.props.onStop(D,Le),Ue&&(Pe(Ue.ownerDocument,Ye.move,Fe.handleDrag),Pe(Ue.ownerDocument,Ye.stop,Fe.handleDragStop))}}},Fe.onMouseDown=function(D){return Ye=fe.mouse,Fe.handleDragStart(D)},Fe.onMouseUp=function(D){return Ye=fe.mouse,Fe.handleDragStop(D)},Fe.onTouchStart=function(D){return Ye=fe.touch,Fe.handleDragStart(D)},Fe.onTouchEnd=function(D){return Ye=fe.touch,Fe.handleDragStop(D)},xe),be(Fe,Me)}return Q(oe,[{key:"componentWillUnmount",value:function(){var xe=i.findDOMNode(this);if(xe){var Fe=xe.ownerDocument;Pe(Fe,fe.mouse.move,this.handleDrag),Pe(Fe,fe.touch.move,this.handleDrag),Pe(Fe,fe.mouse.stop,this.handleDragStop),Pe(Fe,fe.touch.stop,this.handleDragStop),this.props.enableUserSelectHack&&T(Fe)}}},{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,Re){if(oe[Re]&&oe[Re].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:J,style:J,transform:J},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(Ce){ne(oe,Ce);function oe(Re){te(this,oe);var xe=be(this,(oe.__proto__||Object.getPrototypeOf(oe)).call(this,Re));return xe.onDragStart=function(Fe,Me){var ke=xe.props.onStart(Fe,Ht(xe,Me));if(ke===!1)return!1;xe.setState({dragging:!0,dragged:!0})},xe.onDrag=function(Fe,Me){if(!xe.state.dragging)return!1;var ke=Ht(xe,Me),Ee={x:ke.x,y:ke.y};if(xe.props.bounds){var O=Ee.x,D=Ee.y;Ee.x+=xe.state.slackX,Ee.y+=xe.state.slackY;var ee=Ve(xe,Ee.x,Ee.y),ce=pe(ee,2),de=ce[0],Le=ce[1];Ee.x=de,Ee.y=Le,Ee.slackX=xe.state.slackX+(O-Ee.x),Ee.slackY=xe.state.slackY+(D-Ee.y),ke.x=Ee.x,ke.y=Ee.y,ke.deltaX=Ee.x-xe.state.x,ke.deltaY=Ee.y-xe.state.y}var Ue=xe.props.onDrag(Fe,ke);if(Ue===!1)return!1;xe.setState(Ee)},xe.onDragStop=function(Fe,Me){if(!xe.state.dragging)return!1;var ke=xe.props.onStop(Fe,Ht(xe,Me));if(ke===!1)return!1;var Ee={dragging:!1,slackX:0,slackY:0},O=!!xe.props.position;if(O){var D=xe.props.position,ee=D.x,ce=D.y;Ee.x=ee,Ee.y=ce}xe.setState(Ee)},xe.state={dragging:!1,dragged:!1,x:Re.position?Re.position.x:Re.defaultPosition.x,y:Re.position?Re.position.y:Re.defaultPosition.y,slackX:0,slackY:0,isElementSVG:!1},Re.position&&!(Re.onDrag||Re.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."),xe}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(xe){xe.position&&(!this.props.position||xe.position.x!==this.props.position.x||xe.position.y!==this.props.position.y)&&this.setState({x:xe.position.x,y:xe.position.y})}},{key:"componentWillUnmount",value:function(){this.setState({dragging:!1})}},{key:"render",value:function(){var xe,Fe={},Me=null,ke=!!this.props.position,Ee=!ke||this.state.dragging,O=this.props.position||this.props.defaultPosition,D={x:je(this)&&Ee?this.state.x:O.x,y:at(this)&&Ee?this.state.y:O.y};this.state.isElementSVG?Me=Xe(D,this.props.positionOffset):Fe=tt(D,this.props.positionOffset);var ee=this.props,ce=ee.defaultClassName,de=ee.defaultClassNameDragging,Le=ee.defaultClassNameDragged,Ue=I.Children.only(this.props.children),dt=V(Ue.props.className||"",ce,(xe={},Ie(xe,de,this.state.dragging),Ie(xe,Le,this.state.dragged),xe));return I.createElement(ue,he({},this.props,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),I.cloneElement(Ue,{className:dt,style:he({},Ue.props.style,Fe),transform:Me}))}}]),oe}(I.Component);return le.displayName="Draggable",le.propTypes=he({},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:J,style:J,transform:J}),le.defaultProps=he({},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})})(RZe);var Rrt=RZe.exports,uN={exports:{}},PS={},dN={exports:{}},VZe={};function WZe(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,dC.findInArray)(e.changedTouches,i=>g===i.identifier)}function Qrt(e){if(e.targetTouches&&e.targetTouches[0])return e.targetTouches[0].identifier;if(e.changedTouches&&e.changedTouches[0])return e.changedTouches[0].identifier}function jrt(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&&wZe(e.body,"react-draggable-transparent-selection")}function JCt(e){if(e)try{if(e.body&&VZe(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 wZe(e,g){e.classList?e.classList.add(g):e.className.match(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)")))||(e.className+=" ".concat(g))}function VZe(e,g){e.classList?e.classList.remove(g):e.className=e.className.replace(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)"),"g"),"")}var XA={};Object.defineProperty(XA,"__esModule",{value:!0});XA.canDragX=LCt;XA.canDragY=UCt;XA.createCoreData=jCt;XA.createDraggableData=$Ct;XA.getBoundPosition=OCt;XA.getControlPosition=QCt;XA.snapToGrid=_Ct;var jC=WA,ip=ti;function OCt(e,g,I){if(!e.props.bounds)return[g,I];let{bounds:i}=e.props;i=typeof i=="string"?i:qCt(i);const n=rQ(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,ip.innerWidth)(a)-(0,ip.outerWidth)(n)-n.offsetLeft+(0,jC.int)(A.paddingRight)-(0,jC.int)(s.marginRight),bottom:(0,ip.innerHeight)(a)-(0,ip.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 _Ct(e,g,I){const i=Math.round(g/e[0])*e[0],n=Math.round(I/e[1])*e[1];return[i,n]}function LCt(e){return e.props.axis==="both"||e.props.axis==="x"}function UCt(e){return e.props.axis==="both"||e.props.axis==="y"}function QCt(e,g,I){const i=typeof g=="number"?(0,ip.getTouch)(e,g):null;if(typeof g=="number"&&!i)return null;const n=rQ(I),C=I.props.offsetParent||n.offsetParent||n.ownerDocument.body;return(0,ip.offsetXYFromParent)(i||e,C,I.props.scale)}function jCt(e,g,I){const i=!(0,jC.isNum)(e.lastX),n=rQ(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 $Ct(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 qCt(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}}function rQ(e){const g=e.findDOMNode();if(!g)throw new Error(": Unmounted during event!");return g}var cN={},uN={};Object.defineProperty(uN,"__esModule",{value:!0});uN.default=ert;function ert(){}function trt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function rIe(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 r9(e){return r9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},r9(e)}Object.defineProperty(cN,"__esModule",{value:!0});cN.default=void 0;var q5=Art(N),bC=oQ(el),art=oQ(jI),Rn=ti,yl=XA,ex=WA,Qy=oQ(uN);function oQ(e){return e&&e.__esModule?e:{default:e}}function RZe(e){if(typeof WeakMap!="function")return null;var g=new WeakMap,I=new WeakMap;return(RZe=function(i){return i?I:g})(e)}function Art(e,g){if(!g&&e&&e.__esModule)return e;if(e===null||typeof e!="object"&&typeof e!="function")return{default:e};var I=RZe(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 Ln(e,g,I){return g=srt(g),g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}function srt(e){var g=lrt(e,"string");return typeof g=="symbol"?g:String(g)}function lrt(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 ko={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let Zl=ko.mouse,dN=function(e){nrt(I,e);var g=Crt(I);function I(){var i;return trt(this,I),i=g.apply(this,arguments),Ln(Bi(i),"dragging",!1),Ln(Bi(i),"lastX",NaN),Ln(Bi(i),"lastY",NaN),Ln(Bi(i),"touchIdentifier",null),Ln(Bi(i),"mounted",!1),Ln(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,Rn.matchesSelectorAndParentsTo)(n.target,i.props.handle,C)||i.props.cancel&&(0,Rn.matchesSelectorAndParentsTo)(n.target,i.props.cancel,C))return;n.type==="touchstart"&&n.preventDefault();const o=(0,Rn.getTouchIdentifier)(n);i.touchIdentifier=o;const a=(0,yl.getControlPosition)(n,o,Bi(i));if(a==null)return;const{x:s,y:A}=a,l=(0,yl.createCoreData)(Bi(i),s,A);(0,Qy.default)("DraggableCore: handleDragStart: %j",l),(0,Qy.default)("calling",i.props.onStart),!(i.props.onStart(n,l)===!1||i.mounted===!1)&&(i.props.enableUserSelectHack&&(0,Rn.addUserSelectStyles)(r),i.dragging=!0,i.lastX=s,i.lastY=A,(0,Rn.addEvent)(r,Zl.move,i.handleDrag),(0,Rn.addEvent)(r,Zl.stop,i.handleDragStop))}),Ln(Bi(i),"handleDrag",n=>{const C=(0,yl.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,yl.snapToGrid)(i.props.grid,A,l),!A&&!l)return;r=i.lastX+A,o=i.lastY+l}const a=(0,yl.createCoreData)(Bi(i),r,o);if((0,Qy.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}),Ln(Bi(i),"handleDragStop",n=>{if(!i.dragging)return;const C=(0,yl.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,yl.snapToGrid)(i.props.grid,l,c),r=i.lastX+l,o=i.lastY+c}const a=(0,yl.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,Rn.removeUserSelectStyles)(A.ownerDocument),(0,Qy.default)("DraggableCore: handleDragStop: %j",a),i.dragging=!1,i.lastX=NaN,i.lastY=NaN,A&&((0,Qy.default)("DraggableCore: Removing handlers"),(0,Rn.removeEvent)(A.ownerDocument,Zl.move,i.handleDrag),(0,Rn.removeEvent)(A.ownerDocument,Zl.stop,i.handleDragStop))}),Ln(Bi(i),"onMouseDown",n=>(Zl=ko.mouse,i.handleDragStart(n))),Ln(Bi(i),"onMouseUp",n=>(Zl=ko.mouse,i.handleDragStop(n))),Ln(Bi(i),"onTouchStart",n=>(Zl=ko.touch,i.handleDragStart(n))),Ln(Bi(i),"onTouchEnd",n=>(Zl=ko.touch,i.handleDragStop(n))),i}return grt(I,[{key:"componentDidMount",value:function(){this.mounted=!0;const n=this.findDOMNode();n&&(0,Rn.addEvent)(n,ko.touch.start,this.onTouchStart,{passive:!1})}},{key:"componentWillUnmount",value:function(){this.mounted=!1;const n=this.findDOMNode();if(n){const{ownerDocument:C}=n;(0,Rn.removeEvent)(C,ko.mouse.move,this.handleDrag),(0,Rn.removeEvent)(C,ko.touch.move,this.handleDrag),(0,Rn.removeEvent)(C,ko.mouse.stop,this.handleDragStop),(0,Rn.removeEvent)(C,ko.touch.stop,this.handleDragStop),(0,Rn.removeEvent)(n,ko.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,Rn.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:art.default.findDOMNode(this)}},{key:"render",value:function(){return q5.cloneElement(q5.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),I}(q5.Component);cN.default=dN;Ln(dN,"displayName","DraggableCore");Ln(dN,"propTypes",{allowAnyClick:bC.default.bool,children:bC.default.node.isRequired,disabled:bC.default.bool,enableUserSelectHack:bC.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:bC.default.arrayOf(bC.default.number),handle:bC.default.string,cancel:bC.default.string,nodeRef:bC.default.object,onStart:bC.default.func,onDrag:bC.default.func,onStop:bC.default.func,onMouseDown:bC.default.func,scale:bC.default.number,className:ex.dontSetMe,style:ex.dontSetMe,transform:ex.dontSetMe});Ln(dN,"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(el),h=B(jI),m=B(GCt),f=ti,b=XA,p=WA,y=B(cN),Z=B(uN);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(K){return K?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 K={},F=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var J in R)if(J!=="default"&&Object.prototype.hasOwnProperty.call(R,J)){var P=F?Object.getOwnPropertyDescriptor(R,J):null;P&&(P.get||P.set)?Object.defineProperty(K,J,P):K[J]=R[J]}return K.default=R,Y&&Y.set(R,K),K}function w(){return w=Object.assign?Object.assign.bind():function(R){for(var H=1;H{if((0,Z.default)("Draggable: onDragStart: %j",P),F.props.onStart(J,(0,b.createDraggableData)(A(F),P))===!1)return!1;F.setState({dragging:!0,dragged:!0})}),V(A(F),"onDrag",(J,P)=>{if(!F.state.dragging)return!1;(0,Z.default)("Draggable: onDrag: %j",P);const ge=(0,b.createDraggableData)(A(F),P),q={x:ge.x,y:ge.y,slackX:0,slackY:0};if(F.props.bounds){const{x:j,y:te}=q;q.x+=F.state.slackX,q.y+=F.state.slackY;const[Q,ie]=(0,b.getBoundPosition)(A(F),q.x,q.y);q.x=Q,q.y=ie,q.slackX=F.state.slackX+(j-q.x),q.slackY=F.state.slackY+(te-q.y),ge.x=q.x,ge.y=q.y,ge.deltaX=q.x-F.state.x,ge.deltaY=q.y-F.state.y}if(F.props.onDrag(J,ge)===!1)return!1;F.setState(q)}),V(A(F),"onDragStop",(J,P)=>{if(!F.state.dragging||F.props.onStop(J,(0,b.createDraggableData)(A(F),P))===!1)return!1;(0,Z.default)("Draggable: onDragStop: %j",P);const q={dragging:!1,slackX:0,slackY:0};if(!!F.props.position){const{x:j,y:te}=F.props.position;q.x=j,q.y=te}F.setState(q)}),F.state={dragging:!1,dragged:!1,x:K.position?K.position.x:K.defaultPosition.x,y:K.position?K.position.y:K.defaultPosition.y,prevPropsPosition:{...K.position},slackX:0,slackY:0,isElementSVG:!1},K.position&&!(K.onDrag||K.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(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 F,J;return(F=(J=this.props)===null||J===void 0||(J=J.nodeRef)===null||J===void 0?void 0:J.current)!==null&&F!==void 0?F:h.default.findDOMNode(this)}},{key:"render",value:function(){const{axis:F,bounds:J,children:P,defaultPosition:ge,defaultClassName:q,defaultClassNameDragging:$,defaultClassNameDragged:j,position:te,positionOffset:Q,scale:ie,...he}=this.props;let ne={},be=null;const ve=!!!te||this.state.dragging,We=te||ge,Be={x:(0,b.canDragX)(this)&&ve?this.state.x:We.x,y:(0,b.canDragY)(this)&&ve?this.state.y:We.y};this.state.isElementSVG?be=(0,f.createSVGTransform)(Be,Q):ne=(0,f.createCSSTransform)(Be,Q);const Je=(0,m.default)(P.props.className||"",q,{[$]:this.state.dragging,[j]:this.state.dragged});return u.createElement(y.default,w({},he,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),u.cloneElement(u.Children.only(P),{className:Je,style:{...P.props.style,...ne},transform:be}))}}],[{key:"getDerivedStateFromProps",value:function(F,J){let{position:P}=F,{prevPropsPosition:ge}=J;return P&&(!ge||P.x!==ge.x||P.y!==ge.y)?((0,Z.default)("Draggable: getDerivedStateFromProps %j",{position:P,prevPropsPosition:ge}),{x:P.x,y:P.y,prevPropsPosition:{...P}}):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})})(yZe);const{default:WZe,DraggableCore:crt}=yZe;lN.exports=WZe;lN.exports.default=WZe;lN.exports.DraggableCore=crt;var urt=lN.exports,aQ={};aQ.__esModule=!0;aQ.cloneElement=frt;var drt=hrt(N);function hrt(e){return e&&e.__esModule?e:{default:e}}function oIe(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 aIe(e){for(var g=1;g=0)&&(I[n]=e[n]);return I}function gx(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Srt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function Xp(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}var AQ=function(e){Srt(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 cIe(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Hrt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function a9(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}var TZe=function(e){Hrt(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,Mg.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,Mg.getLayoutItem)(A,i);this.props.onResizeStop(A,l,u,null,o,a);var d=(0,Mg.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 ju.default.createElement(mIe.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},ju.default.createElement("div",null))},g.prototype.processGridItem=function(i){if(!(!i||!i.key)){var n=(0,Mg.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 ju.default.createElement(mIe.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,_rt.default)("react-grid-layout",C),a=dIe({height:this.containerHeight()},r);return ju.default.createElement("div",{className:o,style:a},ju.default.Children.map(this.props.children,function(s){return i.processGridItem(s)}),this.placeholder())},g}(ju.default.Component);mN.displayName="ReactGridLayout";mN.propTypes={className:cI.default.string,style:cI.default.object,width:cI.default.number,autoSize:cI.default.bool,cols:cI.default.number,draggableCancel:cI.default.string,draggableHandle:cI.default.string,verticalCompact:function(g){g.verticalCompact},compactType:cI.default.oneOf(["vertical","horizontal"]),layout:function(g){var I=g.layout;I!==void 0&&(0,Mg.validateLayout)(I,"layout")},margin:cI.default.arrayOf(cI.default.number),containerPadding:cI.default.arrayOf(cI.default.number),rowHeight:cI.default.number,maxRows:cI.default.number,isDraggable:cI.default.bool,isResizable:cI.default.bool,preventCollision:cI.default.bool,useCSSTransforms:cI.default.bool,onLayoutChange:cI.default.func,onDragStart:cI.default.func,onDrag:cI.default.func,onDragStop:cI.default.func,onResizeStart:cI.default.func,onResize:cI.default.func,onResizeStop:cI.default.func,children:function(g,I){var i=g[I],n={};ju.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})}};mN.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:Mg.noop,onDragStart:Mg.noop,onDrag:Mg.noop,onDragStop:Mg.noop,onResizeStart:Mg.noop,onResize:Mg.noop,onResizeStop:Mg.noop};var $rt=function(){this.state={activeDrag:null,layout:(0,Mg.synchronizeLayoutWithChildren)(this.props.layout,this.props.children,this.props.cols,this.compactType()),mounted:!1,oldDragItem:null,oldLayout:null,oldResizeItem:null}};oN.default=mN;var cQ={},Cm={};Cm.__esModule=!0;Cm.getBreakpointFromWidth=qrt;Cm.getColsFromBreakpoint=eot;Cm.findOrGenerateResponsiveLayout=tot;Cm.sortBreakpoints=uQ;var rR=Dg;function qrt(e,g){for(var I=uQ(e),i=I[0],n=1,C=I.length;ne[r]&&(i=r)}return i}function eot(e,g){if(!g[e])throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint "+e+" is missing!");return g[e]}function tot(e,g,I,i,n,C){if(e[I])return(0,rR.cloneLayout)(e[I]);for(var r=e[i],o=uQ(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 oot(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function bIe(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 aot(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 yIe=function(g){return Object.prototype.toString.call(g)},dQ=function(e){aot(g,e);function g(){var I,i,n;oot(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 mot(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ZIe(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 fot(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 pot(e){var g,I;return I=g=function(i){fot(n,i);function n(){var C,r,o;mot(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 F in K)K.hasOwnProperty(F)&&(R[K[F]]?this.element.setAttribute(K[F],R[K[F]].substr(1)):this.element.removeAttribute(K[F]))}}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: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[P].minWidth&&(J=P);if(J||(J=S),X!==J)if(W[J])v[X].style.display="none",v[J].style.display="block",X=J;else{var ge=new Image;ge.onload=function(){v[J].src=V[J],v[X].style.display="none",v[J].style.display="block",W[J]=!0,X=J},ge.src=V[J]}else v[J].src=V[J]}G.resizeSensorInstance=new I(G,F),F()}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};gl.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};gl.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?pN(g):this.shift;for(r=0;r/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return I.replace(/>\s{0,}<")};gl.prototype.jsonmin=function(e){return typeof JSON>"u"?e:JSON.stringify(JSON.parse(e),null,0)};gl.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,"*/")};gl.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")};var Bot=new gl;const Sot=JC(Bot);var wot=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},fQ={},Vot=Object.prototype.hasOwnProperty,Rot;function GIe(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function vIe(e){try{return encodeURIComponent(e)}catch{return null}}function Wot(e){for(var g=/([^=?#&]+)=?([^&]*)/g,I={},i;i=g.exec(e);){var n=GIe(i[1]),C=GIe(i[2]);n===null||C===null||n in I||(I[n]=C)}return I}function Xot(e,g){g=g||"";var I=[],i,n;typeof g!="string"&&(g="?");for(n in e)if(Vot.call(e,n)){if(i=e[n],!i&&(i===null||i===Rot||isNaN(i))&&(i=""),n=vIe(n),i=vIe(i),n===null||i===null)continue;I.push(n+"="+i)}return I.length?g+I.join("&"):""}fQ.stringify=Xot;fQ.parse=Wot;var KZe=wot,bN=fQ,Hot=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,xZe=/[\n\r\t]/g,Tot=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,DZe=/:\d+$/,Not=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,kot=/^[a-zA-Z]:/;function pQ(e){return(e||"").toString().replace(Hot,"")}var Q3=[["#","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]],BIe={hash:1,query:1};function FZe(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 yA(unescape(e.pathname),{});else if(n==="string"){i=new yA(e,{});for(C in BIe)delete i[C]}else if(n==="object"){for(C in e)C in BIe||(i[C]=e[C]);i.slashes===void 0&&(i.slashes=Tot.test(e.href))}return i}function cA(e){return e==="file:"||e==="ftp:"||e==="http:"||e==="https:"||e==="ws:"||e==="wss:"}function EZe(e,g){e=pQ(e),e=e.replace(xZe,""),g=g||{};var I=Not.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 Yot(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 yA(e,g,I){if(e=pQ(e),e=e.replace(xZe,""),!(this instanceof yA))return new yA(e,g,I);var i,n,C,r,o,a,s=Q3.slice(),A=typeof g,l=this,c=0;for(A!=="object"&&A!=="string"&&(I=g,g=null),I&&typeof I!="function"&&(I=bN.parse),g=FZe(g),n=EZe(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||kot.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:()=>{}}}})(),bQ=(e,g)=>g?e.toLowerCase():e,zZe=(e,{caseInsensitive:g}={})=>(I,i,n=1/0)=>{const C=bQ(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}},yQ=(e,{caseInsensitive:g}={})=>(I,i)=>{typeof I=="object"&&(i=I.handler,I=I.event);const n=bQ(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))},SIe=(e,g)=>()=>{e.forEach(I=>I(g))},PZe=(e,{isGlobal:g,caseInsensitive:I,async:i}={})=>{const n=yQ(e);return(C,r,o={})=>{const a=bQ(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(SIe(s,r),0):SIe(s,r)(),g&&!o.isNoGlobalBroadcast)try{MZe.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}}},JZe=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]})},OZe=()=>({__times__:{}}),yN=(e={})=>{const g=e.async||!1,I=e.caseInsensitive||!1,i=e.stack||OZe();return i.__times__||(i.__times__={}),{publish:PZe(i,{async:g,caseInsensitive:I}),subscribe:zZe(i,{caseInsensitive:I}),unsubscribe:yQ(i,{caseInsensitive:I}),clear:JZe(i),stack:i}},$y=OZe(),zG={publish:PZe($y,{isGlobal:!0}),subscribe:zZe($y),unsubscribe:yQ($y),clear:JZe($y),stack:$y};MZe.onmessage=({data:{event:e,news:g}})=>zG.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 Ig(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))}Ig.defaultProps={onMouseEnter:()=>{},onMouseLeave:()=>{}};Ig.propTypes={children:L.node.isRequired,onClick:L.func.isRequired,onMouseEnter:L.func,onMouseLeave:L.func};var Eot={value:()=>{}};function D0(){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=D0.prototype={constructor:F1,on:function(e,g){var I=this._,i=Mot(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 j3(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}})}j3.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function Pot(e){return!e.ctrlKey&&!e.button}function Jot(){return this.parentNode}function Oot(e,g){return g??{x:e.x,y:e.y}}function _ot(){return navigator.maxTouchPoints||"ontouchstart"in this}function QA(){var e=Pot,g=Jot,I=Oot,i=_ot,n={},C=D0("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&&(dg(y.view).on("mousemove.drag",d,!0).on("mouseup.drag",h,!0),ZN(y.view),Cx(y),s=!1,o=y.clientX,a=y.clientY,B("start",y))}}function d(y){if(Tp(y),!s){var Z=y.clientX-o,B=y.clientY-a;s=Z*Z+B*B>l}n.mouse("drag",y)}function h(y){dg(y.view).on("mousemove.drag mouseup.drag",null),GN(y.view,s),Tp(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;--Xb}function VIe(){oh=(l9=WB.now())+vN,Xb=FZ=0;try{Qot()}finally{Xb=0,$ot(),oh=0}}function jot(){var e=WB.now(),g=e-l9;g>_Ze&&(vN-=g,l9=e)}function $ot(){for(var e,g=s9,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:s9=I);EZ=e,$3(i)}function $3(e){if(!Xb){FZ&&(FZ=clearTimeout(FZ));var g=e-oh;g>24?(e<1/0&&(FZ=setTimeout(VIe,e-WB.now()-vN)),qy&&(qy=clearInterval(qy))):(qy||(l9=WB.now(),qy=setInterval(jot,_Ze)),Xb=1,LZe(VIe))}}function RIe(e,g,I){var i=new c9;return g=g==null?0:+g,i.restart(n=>{i.stop(),e(n+g)},g,I),i}var qot=D0("start","end","cancel","interrupt"),eat=[],QZe=0,WIe=1,q3=2,E1=3,XIe=4,ez=5,M1=6;function BN(e,g,I,i,n,C){var r=e.__transition;if(!r)e.__transition={};else if(I in r)return;tat(e,I,{name:g,index:i,group:n,on:qot,tween:eat,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:QZe})}function GQ(e,g){var I=ma(e,g);if(I.state>QZe)throw new Error("too late; already scheduled");return I}function HA(e,g){var I=ma(e,g);if(I.state>E1)throw new Error("too late; already running");return I}function ma(e,g){var I=e.__transition;if(!I||!(I=I[g]))throw new Error("transition not found");return I}function tat(e,g,I){var i=e.__transition,n;i[g]=I,I.timer=UZe(C,0,I.time);function C(s){I.state=WIe,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!==WIe)return a();for(A in i)if(u=i[A],u.name===I.name){if(u.state===E1)return RIe(r);u.state===XIe?(u.state=M1,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete i[A]):+Aq3&&i.state=0&&(g=g.slice(0,I)),!g||g==="start"})}function Xat(e,g,I){var i,n,C=Wat(g)?GQ:HA;return function(){var r=C(this,e),o=r.on;o!==i&&(n=(i=o).copy()).on(g,I),r.on=n}}function Hat(e,g){var I=this._id;return arguments.length<2?ma(this.node(),I).on.on(e):this.each(Xat(I,e,g))}function Tat(e){return function(){var g=this.parentNode;for(var I in this.__transition)if(+I!==e)return;g&&g.removeChild(this)}}function Nat(){return this.on("end.remove",Tat(this._id))}function kat(e){var g=this._name,I=this._id;typeof e!="function"&&(e=NS(e));for(var i=this._groups,n=i.length,C=new Array(n),r=0;r()=>e;function CAt(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 rAt(e){e.stopImmediatePropagation()}function ox(e){e.preventDefault(),e.stopImmediatePropagation()}var HIe={name:"drag"},ax={name:"space"},Fm={name:"handle"},Em={name:"center"};const{abs:TIe,max:Wn,min:Xn}=Math;function NIe(e){return[+e[0],+e[1]]}function gz(e){return[NIe(e[0]),NIe(e[1])]}var z1={name:"x",handles:["w","e"].map(XB),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]]}},P1={name:"y",handles:["n","s"].map(XB),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]]}},oAt={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(XB),input:function(e){return e==null?null:gz(e)},output:function(e){return e}},EA={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"},kIe={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},YIe={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},aAt={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},AAt={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function XB(e){return{type:e}}function sAt(e){return!e.ctrlKey&&!e.button}function lAt(){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 cAt(){return navigator.maxTouchPoints||"ontouchstart"in this}function Ax(e){for(;!e.__brush;)if(!(e=e.parentNode))return;return e.__brush}function uAt(e){return e[0][0]===e[1][0]||e[0][1]===e[1][1]}function dAt(e){var g=e.__brush;return g?g.dim.output(g.selection):null}function SN(){return SQ(z1)}function PS(){return SQ(P1)}function BQ(){return SQ(oAt)}function SQ(e){var g=lAt,I=sAt,i=cAt,n=!0,C=D0("start","brush","end"),r=6,o;function a(m){var f=m.property("__brush",h).selectAll(".overlay").data([XB("overlay")]);f.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",EA.overlay).merge(f).each(function(){var p=Ax(this).extent;dg(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([XB("selection")]).enter().append("rect").attr("class","selection").attr("cursor",EA.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 EA[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=tm(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();tz(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=dg(this),f=Ax(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=dg(this.that).datum();C.call(m,this.that,new CAt(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"?HIe:n&&m.altKey?Em:Fm,y=e===P1?null:aAt[b],Z=e===z1?null:AAt[b],B=Ax(f),G=B.extent,v=B.selection,w=G[0][0],V,S,X=G[0][1],W,R,H=G[1][0],Y,K,F=G[1][1],J,P,ge=0,q=0,$,j=y&&Z&&n&&m.shiftKey,te,Q,ie=Array.from(m.touches||[m],De=>{const Qe=De.identifier;return De=zg(De,f),De.point0=De.slice(),De.identifier=Qe,De});if(b==="overlay"){v&&($=!0);const De=[ie[0],ie[1]||ie[0]];B.selection=v=[[V=e===P1?w:Xn(De[0][0],De[1][0]),W=e===z1?X:Xn(De[0][1],De[1][1])],[Y=e===P1?H:Wn(De[0][0],De[1][0]),J=e===z1?F:Wn(De[0][1],De[1][1])]],ie.length>1&&We()}else V=v[0][0],W=v[0][1],Y=v[1][0],J=v[1][1];S=V,R=W,K=Y,P=J;var he=dg(f).attr("pointer-events","none"),ne=he.selectAll(".overlay").attr("cursor",EA[b]);tz(f);var be=A(f,arguments,!0).beforestart();if(m.touches)be.moved=ve,be.ended=Be;else{var pe=dg(m.view).on("mousemove.brush",ve,!0).on("mouseup.brush",Be,!0);n&&pe.on("keydown.brush",Je,!0).on("keyup.brush",Pe,!0),ZN(m.view)}s.call(f),be.start(m,p.name);function ve(De){for(const Qe of De.changedTouches||[De])for(const _e of ie)_e.identifier===Qe.identifier&&(_e.cur=zg(Qe,f));if(j&&!te&&!Q&&ie.length===1){const Qe=ie[0];TIe(Qe.cur[0]-Qe[0])>TIe(Qe.cur[1]-Qe[1])?Q=!0:te=!0}for(const Qe of ie)Qe.cur&&(Qe[0]=Qe.cur[0],Qe[1]=Qe.cur[1]);$=!0,ox(De),We(De)}function We(De){const Qe=ie[0],_e=Qe.point0;var gt;switch(ge=Qe[0]-_e[0],q=Qe[1]-_e[1],p){case ax:case HIe:{y&&(ge=Wn(w-V,Xn(H-Y,ge)),S=V+ge,K=Y+ge),Z&&(q=Wn(X-W,Xn(F-J,q)),R=W+q,P=J+q);break}case Fm:{ie[1]?(y&&(S=Wn(w,Xn(H,ie[0][0])),K=Wn(w,Xn(H,ie[1][0])),y=1),Z&&(R=Wn(X,Xn(F,ie[0][1])),P=Wn(X,Xn(F,ie[1][1])),Z=1)):(y<0?(ge=Wn(w-V,Xn(H-V,ge)),S=V+ge,K=Y):y>0&&(ge=Wn(w-Y,Xn(H-Y,ge)),S=V,K=Y+ge),Z<0?(q=Wn(X-W,Xn(F-W,q)),R=W+q,P=J):Z>0&&(q=Wn(X-J,Xn(F-J,q)),R=W,P=J+q));break}case Em:{y&&(S=Wn(w,Xn(H,V-ge*y)),K=Wn(w,Xn(H,Y+ge*y))),Z&&(R=Wn(X,Xn(F,W-q*Z)),P=Wn(X,Xn(F,J+q*Z)));break}}K0&&(V=S-ge),Z<0?J=P-q:Z>0&&(W=R-q),p=ax,ne.attr("cursor",EA.selection),We());break}default:return}ox(De)}function Pe(De){switch(De.keyCode){case 16:{j&&(te=Q=j=!1,We());break}case 18:{p===Em&&(y<0?Y=K:y>0&&(V=S),Z<0?J=P:Z>0&&(W=R),p=Fm,We());break}case 32:{p===ax&&(De.altKey?(y&&(Y=K-ge*y,V=S+ge*y),Z&&(J=P-q*Z,W=R+q*Z),p=Em):(y<0?Y=K:y>0&&(V=S),Z<0?J=P:Z>0&&(W=R),p=Fm),ne.attr("cursor",EA[b]),We());break}default:return}ox(De)}}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=gz(g.apply(this,arguments)),m.dim=e,m}return a.extent=function(m){return arguments.length?(g=typeof m=="function"?m:rx(gz(m)),a):g},a.filter=function(m){return arguments.length?(I=typeof m=="function"?m:rx(!!m),a):I},a.touchable=function(m){return arguments.length?(i=typeof m=="function"?m:rx(!!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 hAt=Object.freeze(Object.defineProperty({__proto__:null,brush:BQ,brushSelection:dAt,brushX:SN,brushY:PS},Symbol.toStringTag,{value:"Module"}));function HB(){return HB=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(VAt)}}]),e}();function VAt(e,g){var I=e.node.sortableInfo.index,i=g.node.sortableInfo.index;return I-i}function RAt(e,g,I){return e=e.slice(),e.splice(I<0?e.length+I:I,0,e.splice(g,1)[0]),e}function IGe(e,g){return Object.keys(e).reduce(function(I,i){return g.indexOf(i)===-1&&(I[i]=e[i]),I},{})}var Mm={end:["touchend","touchcancel","mouseup"],move:["touchmove","mousemove"],start:["touchstart","mousedown"]},iGe=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 aR(e,g){Object.keys(g).forEach(function(I){e.style[I]=g[I]})}function AR(e,g){e.style["".concat(iGe,"Transform")]=g==null?"":"translate3d(".concat(g.x,"px,").concat(g.y,"px,0)")}function lx(e,g){e.style["".concat(iGe,"TransitionDuration")]=g==null?"":"".concat(g,"ms")}function MZ(e,g){for(;e;){if(g(e))return e;e=e.parentNode}return null}function xIe(e,g,I){return Math.max(e,Math.min(I,g))}function np(e){return e.substr(-2)==="px"?parseFloat(e):0}function WAt(e){var g=window.getComputedStyle(e);return{bottom:np(g.marginBottom),left:np(g.marginLeft),right:np(g.marginRight),top:np(g.marginTop)}}function RQ(e,g){var I=g.displayName||g.name;return I?"".concat(e,"(").concat(I,")"):e}function cx(e,g){var I=e.getBoundingClientRect();return{top:I.top+g.top,left:I.left+g.left}}function eZ(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 XAt(e){return e.touches&&e.touches.length||e.changedTouches&&e.changedTouches.length}function J1(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:J1(e.parentNode,g,i)}}function HAt(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 nz(e){var g,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=g=function(n){VQ(C,n);function C(){return JS(this,C),wQ(this,TB(C).apply(this,arguments))}return OS(C,[{key:"componentDidMount",value:function(){var o=Aa.findDOMNode(this);o.sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return ah(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 U.createElement(e,HB({ref:o},this.props))}}]),C}(U.Component),Ug(g,"displayName",RQ("sortableHandle",e)),I}function FIe(e){return e.sortableHandle!=null}var KAt=function(){function e(g,I){JS(this,e),this.container=g,this.onScrollCallback=I}return OS(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 xAt(e){var g=e.node;return{height:g.offsetHeight,width:g.offsetWidth}}function DAt(e){var g=[id.Input,id.Textarea,id.Select,id.Option,id.Button];return!!(g.indexOf(e.target.tagName)!==-1||MZ(e.target,function(I){return I.contentEditable==="true"}))}var CGe={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},rGe={lift:[Tu.SPACE],drop:[Tu.SPACE],cancel:[Tu.ESC],up:[Tu.UP,Tu.LEFT],down:[Tu.DOWN,Tu.RIGHT]},FAt={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:xAt,hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,keyCodes:rGe,shouldCancelStart:DAt,transitionDuration:300,useWindowAsScrollContainer:!1},EAt=Object.keys(CGe);function MAt(e){ah(!(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 zAt(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 PAt(e){var g,I,i=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return I=g=function(n){VQ(C,n);function C(r){var o;return JS(this,C),o=wQ(this,TB(C).call(this,r)),Ug(bg(bg(o)),"state",{}),Ug(bg(bg(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=eZ(a);var c=MZ(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&&!MZ(a.target,FIe))return;o.manager.active={collection:m,index:h},!XAt(a)&&a.target.tagName===id.Anchor&&a.preventDefault(),A||(o.props.pressDelay===0?o.handlePress(a):o.pressTimer=setTimeout(function(){return o.handlePress(a)},o.props.pressDelay))}}}),Ug(bg(bg(o)),"nodeIsChild",function(a){return a.sortableInfo.manager===o.manager}),Ug(bg(bg(o)),"handleMove",function(a){var s=o.props,A=s.distance,l=s.pressThreshold;if(!o.state.sorting&&o.touched&&!o._awaitingUpdateBeforeSortStart){var c=eZ(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)}}),Ug(bg(bg(o)),"handleEnd",function(){o.touched=!1,o.cancel()}),Ug(bg(bg(o)),"cancel",function(){var a=o.props.distance,s=o.state.sorting;s||(a||clearTimeout(o.pressTimer),o.manager.active=null)}),Ug(bg(bg(o)),"handlePress",function(a){try{var s=o.manager.getActive(),A=function(){if(s){var l=function(){var w=y.sortableInfo.index,V=WAt(y),S=kAt(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=J1(y,o.container),B?o.initialOffset=eZ(sx({},a,{pageX:o.boundingClientRect.left,pageY:o.boundingClientRect.top})):o.initialOffset=eZ(a),o.initialScroll={left:o.scrollContainer.scrollLeft,top:o.scrollContainer.scrollTop},o.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},o.helper=o.helperContainer.appendChild(YAt(y)),aR(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,aR(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,K=R.width,F=R.height,J=H+F,P=Y+K;o.axis.x&&(o.minTranslate.x=Y-o.boundingClientRect.left,o.maxTranslate.x=P-(o.boundingClientRect.left+o.width)),o.axis.y&&(o.minTranslate.y=H-o.boundingClientRect.top,o.maxTranslate.y=J-(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(ge){return o.helper.classList.add(ge)}),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)):(Mm.move.forEach(function(ge){return o.listenerNode.addEventListener(ge,o.handleSortMove,!1)}),Mm.end.forEach(function(ge){return o.listenerNode.addEventListener(ge,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=zAt(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)}}),Ug(bg(bg(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)}),Ug(bg(bg(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)):(Mm.move.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortMove)}),Mm.end.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortEnd)}))),o.helper.parentNode.removeChild(o.helper),A&&o.sortableGhost&&aR(o.sortableGhost,{opacity:"",visibility:""});for(var m=0,f=h.length;mA)){o.prevIndex=c,o.newIndex=l;var u=HAt(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||cx(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=J1(p,this.container),u[f].edgeOffset=S,h&&(u[f].boundingClientRect=cx(p,l)));var X=f0&&u[f-1];if(X&&!X.edgeOffset&&(X.edgeOffset=J1(X.node,this.container),h&&(X.boundingClientRect=cx(X.node,l))),y===this.index){s&&(this.sortableGhost=p,aR(p,{opacity:0,visibility:"hidden"}));continue}a&&lx(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){VQ(C,n);function C(){return JS(this,C),wQ(this,TB(C).apply(this,arguments))}return OS(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=Aa.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 ah(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 U.createElement(e,HB({ref:o},IGe(this.props,JAt)))}}]),C}(U.Component),Ug(g,"displayName",RQ("sortableElement",e)),Ug(g,"contextTypes",{manager:L.object.isRequired}),Ug(g,"propTypes",oGe),Ug(g,"defaultProps",{collection:0}),I}const AGe=k0(e=>e.pos).left,Ti=(e,g)=>{if(!g||!g.cumPositions||!g.cumPositions.length)return null;let I=AGe(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]},sGe=(e,g)=>I=>I%e*g+Math.floor(I/e),OAt=e=>e,lGe=(e,g,I=OAt)=>e.map((i,n)=>i+g[I(n)]),_At="http://www.w3.org/2000/svg",u9=(e,g)=>{if(e.namespaceURI===_At){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|$)`))},LAt="http://www.w3.org/2000/svg",UAt=(e,g)=>{if(e.namespaceURI===LAt){if(!u9(e,g)){const I=e.getAttribute("class")||"";e.setAttribute("class",`${I} ${g}`)}}else e.classList?e.classList.add(g):u9(e,g)||(e.className+=` ${g}`)},QAt=(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}`})},d9=(e,g,I)=>I.chrPositions[e].pos+g,cGe=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},_c=(e,g=!1)=>{const I=e.map((r,o)=>o*(255/(e.length-1))),i=tg().domain(I).range(e),C=CC(g?255:254,-1,-1).map(i).map(r=>{const o=Bb(r);return[o.r,o.g,o.b,o.opacity*255]});return C.length<256&&C.push([255,255,255,0]),C},zZ=0,PZ=5,uGe=10,dGe=10,hGe=300,h9="move",Mr="select",Cz=100,m9=10,mGe=110,JZ=3e3,OZ="locationListenerPrefix",fGe=1e3,rz="http://higlass.io/api/v1",pGe=400,bGe=300,oz=["top","left","right","bottom","center","whole","gallery"],yGe=20,ZGe=20,f9=Symbol("Light theme"),gI=Symbol("Dark theme"),jAt=f9,ot={PIXI:dpe},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"},$At={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"},qAt={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"},est={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"},tst={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"},gst={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"},Ist={id:"play",paths:["M96 64l320 192-320 192z"],viewBox:"0 0 512 512"},ist={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"},nst={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"},Cst={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"]},rst={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"]},ost={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"]},ast={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"]},Ast={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"]},sst={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"]},lst={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"]},cst={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"]},ust=[$At,qAt,est,tst,gst,Ist,ist,nst,Cst,rst,ost,ast,lst,cst,Ast,sst],fa=new DOMParser,dst='',WQ=fa.parseFromString(dst,"text/xml").documentElement,hst=` +`,e.getElementsByTagName("head")[0].appendChild(g)),e.body&&kZe(e.body,"react-draggable-transparent-selection")}function $rt(e){if(e)try{if(e.body&&YZe(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 kZe(e,g){e.classList?e.classList.add(g):e.className.match(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)")))||(e.className+=" ".concat(g))}function YZe(e,g){e.classList?e.classList.remove(g):e.className=e.className.replace(new RegExp("(?:^|\\s)".concat(g,"(?!\\S)"),"g"),"")}var XA={};Object.defineProperty(XA,"__esModule",{value:!0});XA.canDragX=tCt;XA.canDragY=gCt;XA.createCoreData=ICt;XA.createDraggableData=nCt;XA.getBoundPosition=qrt;XA.getControlPosition=iCt;XA.snapToGrid=eCt;var Qr=WA,ip=tI;function qrt(e,g,i){if(!e.props.bounds)return[g,i];let{bounds:I}=e.props;I=typeof I=="string"?I:rCt(I);const n=cQ(e);if(typeof I=="string"){const{ownerDocument:r}=n,C=r.defaultView;let o;if(I==="parent"?o=n.parentNode:o=r.querySelector(I),!(o instanceof C.HTMLElement))throw new Error('Bounds selector "'+I+'" could not find an element.');const a=o,s=C.getComputedStyle(n),A=C.getComputedStyle(a);I={left:-n.offsetLeft+(0,Qr.int)(A.paddingLeft)+(0,Qr.int)(s.marginLeft),top:-n.offsetTop+(0,Qr.int)(A.paddingTop)+(0,Qr.int)(s.marginTop),right:(0,ip.innerWidth)(a)-(0,ip.outerWidth)(n)-n.offsetLeft+(0,Qr.int)(A.paddingRight)-(0,Qr.int)(s.marginRight),bottom:(0,ip.innerHeight)(a)-(0,ip.outerHeight)(n)-n.offsetTop+(0,Qr.int)(A.paddingBottom)-(0,Qr.int)(s.marginBottom)}}return(0,Qr.isNum)(I.right)&&(g=Math.min(g,I.right)),(0,Qr.isNum)(I.bottom)&&(i=Math.min(i,I.bottom)),(0,Qr.isNum)(I.left)&&(g=Math.max(g,I.left)),(0,Qr.isNum)(I.top)&&(i=Math.max(i,I.top)),[g,i]}function eCt(e,g,i){const I=Math.round(g/e[0])*e[0],n=Math.round(i/e[1])*e[1];return[I,n]}function tCt(e){return e.props.axis==="both"||e.props.axis==="x"}function gCt(e){return e.props.axis==="both"||e.props.axis==="y"}function iCt(e,g,i){const I=typeof g=="number"?(0,ip.getTouch)(e,g):null;if(typeof g=="number"&&!I)return null;const n=cQ(i),r=i.props.offsetParent||n.offsetParent||n.ownerDocument.body;return(0,ip.offsetXYFromParent)(I||e,r,i.props.scale)}function ICt(e,g,i){const I=!(0,Qr.isNum)(e.lastX),n=cQ(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 nCt(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 rCt(e){return{left:e.left,top:e.top,right:e.right,bottom:e.bottom}}function cQ(e){const g=e.findDOMNode();if(!g)throw new Error(": Unmounted during event!");return g}var hN={},mN={};Object.defineProperty(mN,"__esModule",{value:!0});mN.default=CCt;function CCt(){}function oCt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cie(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 AX(e){return AX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},AX(e)}Object.defineProperty(hN,"__esModule",{value:!0});hN.default=void 0;var gF=mCt(N),pr=uQ(el),hCt=uQ(ji),Vn=tI,yl=XA,iF=WA,jy=uQ(mN);function uQ(e){return e&&e.__esModule?e:{default:e}}function KZe(e){if(typeof WeakMap!="function")return null;var g=new WeakMap,i=new WeakMap;return(KZe=function(I){return I?i:g})(e)}function mCt(e,g){if(!g&&e&&e.__esModule)return e;if(e===null||typeof e!="object"&&typeof e!="function")return{default:e};var i=KZe(g);if(i&&i.has(e))return i.get(e);var I={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var r in e)if(r!=="default"&&Object.prototype.hasOwnProperty.call(e,r)){var C=n?Object.getOwnPropertyDescriptor(e,r):null;C&&(C.get||C.set)?Object.defineProperty(I,r,C):I[r]=e[r]}return I.default=e,i&&i.set(e,I),I}function _n(e,g,i){return g=fCt(g),g in e?Object.defineProperty(e,g,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[g]=i,e}function fCt(e){var g=pCt(e,"string");return typeof g=="symbol"?g:String(g)}function pCt(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 ko={touch:{start:"touchstart",move:"touchmove",stop:"touchend"},mouse:{start:"mousedown",move:"mousemove",stop:"mouseup"}};let Zl=ko.mouse,fN=function(e){lCt(i,e);var g=cCt(i);function i(){var I;return oCt(this,i),I=g.apply(this,arguments),_n(BI(I),"dragging",!1),_n(BI(I),"lastX",NaN),_n(BI(I),"lastY",NaN),_n(BI(I),"touchIdentifier",null),_n(BI(I),"mounted",!1),_n(BI(I),"handleDragStart",n=>{if(I.props.onMouseDown(n),!I.props.allowAnyClick&&typeof n.button=="number"&&n.button!==0)return!1;const r=I.findDOMNode();if(!r||!r.ownerDocument||!r.ownerDocument.body)throw new Error(" not mounted on DragStart!");const{ownerDocument:C}=r;if(I.props.disabled||!(n.target instanceof C.defaultView.Node)||I.props.handle&&!(0,Vn.matchesSelectorAndParentsTo)(n.target,I.props.handle,r)||I.props.cancel&&(0,Vn.matchesSelectorAndParentsTo)(n.target,I.props.cancel,r))return;n.type==="touchstart"&&n.preventDefault();const o=(0,Vn.getTouchIdentifier)(n);I.touchIdentifier=o;const a=(0,yl.getControlPosition)(n,o,BI(I));if(a==null)return;const{x:s,y:A}=a,l=(0,yl.createCoreData)(BI(I),s,A);(0,jy.default)("DraggableCore: handleDragStart: %j",l),(0,jy.default)("calling",I.props.onStart),!(I.props.onStart(n,l)===!1||I.mounted===!1)&&(I.props.enableUserSelectHack&&(0,Vn.addUserSelectStyles)(C),I.dragging=!0,I.lastX=s,I.lastY=A,(0,Vn.addEvent)(C,Zl.move,I.handleDrag),(0,Vn.addEvent)(C,Zl.stop,I.handleDragStop))}),_n(BI(I),"handleDrag",n=>{const r=(0,yl.getControlPosition)(n,I.touchIdentifier,BI(I));if(r==null)return;let{x:C,y:o}=r;if(Array.isArray(I.props.grid)){let A=C-I.lastX,l=o-I.lastY;if([A,l]=(0,yl.snapToGrid)(I.props.grid,A,l),!A&&!l)return;C=I.lastX+A,o=I.lastY+l}const a=(0,yl.createCoreData)(BI(I),C,o);if((0,jy.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=C,I.lastY=o}),_n(BI(I),"handleDragStop",n=>{if(!I.dragging)return;const r=(0,yl.getControlPosition)(n,I.touchIdentifier,BI(I));if(r==null)return;let{x:C,y:o}=r;if(Array.isArray(I.props.grid)){let l=C-I.lastX||0,c=o-I.lastY||0;[l,c]=(0,yl.snapToGrid)(I.props.grid,l,c),C=I.lastX+l,o=I.lastY+c}const a=(0,yl.createCoreData)(BI(I),C,o);if(I.props.onStop(n,a)===!1||I.mounted===!1)return!1;const A=I.findDOMNode();A&&I.props.enableUserSelectHack&&(0,Vn.removeUserSelectStyles)(A.ownerDocument),(0,jy.default)("DraggableCore: handleDragStop: %j",a),I.dragging=!1,I.lastX=NaN,I.lastY=NaN,A&&((0,jy.default)("DraggableCore: Removing handlers"),(0,Vn.removeEvent)(A.ownerDocument,Zl.move,I.handleDrag),(0,Vn.removeEvent)(A.ownerDocument,Zl.stop,I.handleDragStop))}),_n(BI(I),"onMouseDown",n=>(Zl=ko.mouse,I.handleDragStart(n))),_n(BI(I),"onMouseUp",n=>(Zl=ko.mouse,I.handleDragStop(n))),_n(BI(I),"onTouchStart",n=>(Zl=ko.touch,I.handleDragStart(n))),_n(BI(I),"onTouchEnd",n=>(Zl=ko.touch,I.handleDragStop(n))),I}return aCt(i,[{key:"componentDidMount",value:function(){this.mounted=!0;const n=this.findDOMNode();n&&(0,Vn.addEvent)(n,ko.touch.start,this.onTouchStart,{passive:!1})}},{key:"componentWillUnmount",value:function(){this.mounted=!1;const n=this.findDOMNode();if(n){const{ownerDocument:r}=n;(0,Vn.removeEvent)(r,ko.mouse.move,this.handleDrag),(0,Vn.removeEvent)(r,ko.touch.move,this.handleDrag),(0,Vn.removeEvent)(r,ko.mouse.stop,this.handleDragStop),(0,Vn.removeEvent)(r,ko.touch.stop,this.handleDragStop),(0,Vn.removeEvent)(n,ko.touch.start,this.onTouchStart,{passive:!1}),this.props.enableUserSelectHack&&(0,Vn.removeUserSelectStyles)(r)}}},{key:"findDOMNode",value:function(){var n,r;return(n=this.props)!==null&&n!==void 0&&n.nodeRef?(r=this.props)===null||r===void 0||(r=r.nodeRef)===null||r===void 0?void 0:r.current:hCt.default.findDOMNode(this)}},{key:"render",value:function(){return gF.cloneElement(gF.Children.only(this.props.children),{onMouseDown:this.onMouseDown,onMouseUp:this.onMouseUp,onTouchEnd:this.onTouchEnd})}}]),i}(gF.Component);hN.default=fN;_n(fN,"displayName","DraggableCore");_n(fN,"propTypes",{allowAnyClick:pr.default.bool,children:pr.default.node.isRequired,disabled:pr.default.bool,enableUserSelectHack:pr.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:pr.default.arrayOf(pr.default.number),handle:pr.default.string,cancel:pr.default.string,nodeRef:pr.default.object,onStart:pr.default.func,onDrag:pr.default.func,onStop:pr.default.func,onMouseDown:pr.default.func,scale:pr.default.number,className:iF.dontSetMe,style:iF.dontSetMe,transform:iF.dontSetMe});_n(fN,"defaultProps",{allowAnyClick:!1,disabled:!1,enableUserSelectHack:!0,onStart:function(){},onDrag:function(){},onStop:function(){},onMouseDown:function(){},scale:1});(function(e){function g(V,H){if(!(V instanceof H))throw new TypeError("Cannot call a class as a function")}function i(V,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(V){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(Y){return Y.__proto__||Object.getPrototypeOf(Y)},c(V)}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(el),h=B(ji),m=B(Wrt),f=tI,b=XA,p=WA,y=B(hN),Z=B(mN);function B(V){return V&&V.__esModule?V:{default:V}}function G(V){if(typeof WeakMap!="function")return null;var H=new WeakMap,Y=new WeakMap;return(G=function(K){return K?Y:H})(V)}function v(V,H){if(!H&&V&&V.__esModule)return V;if(V===null||typeof V!="object"&&typeof V!="function")return{default:V};var Y=G(H);if(Y&&Y.has(V))return Y.get(V);var K={},x=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var J in V)if(J!=="default"&&Object.prototype.hasOwnProperty.call(V,J)){var P=x?Object.getOwnPropertyDescriptor(V,J):null;P&&(P.get||P.set)?Object.defineProperty(K,J,P):K[J]=V[J]}return K.default=V,Y&&Y.set(V,K),K}function w(){return w=Object.assign?Object.assign.bind():function(V){for(var H=1;H{if((0,Z.default)("Draggable: onDragStart: %j",P),x.props.onStart(J,(0,b.createDraggableData)(A(x),P))===!1)return!1;x.setState({dragging:!0,dragged:!0})}),R(A(x),"onDrag",(J,P)=>{if(!x.state.dragging)return!1;(0,Z.default)("Draggable: onDrag: %j",P);const ge=(0,b.createDraggableData)(A(x),P),q={x:ge.x,y:ge.y,slackX:0,slackY:0};if(x.props.bounds){const{x:j,y:te}=q;q.x+=x.state.slackX,q.y+=x.state.slackY;const[Q,Ie]=(0,b.getBoundPosition)(A(x),q.x,q.y);q.x=Q,q.y=Ie,q.slackX=x.state.slackX+(j-q.x),q.slackY=x.state.slackY+(te-q.y),ge.x=q.x,ge.y=q.y,ge.deltaX=q.x-x.state.x,ge.deltaY=q.y-x.state.y}if(x.props.onDrag(J,ge)===!1)return!1;x.setState(q)}),R(A(x),"onDragStop",(J,P)=>{if(!x.state.dragging||x.props.onStop(J,(0,b.createDraggableData)(A(x),P))===!1)return!1;(0,Z.default)("Draggable: onDragStop: %j",P);const q={dragging:!1,slackX:0,slackY:0};if(!!x.props.position){const{x:j,y:te}=x.props.position;q.x=j,q.y=te}x.setState(q)}),x.state={dragging:!1,dragged:!1,x:K.position?K.position.x:K.defaultPosition.x,y:K.position?K.position.y:K.defaultPosition.y,prevPropsPosition:{...K.position},slackX:0,slackY:0,isElementSVG:!1},K.position&&!(K.onDrag||K.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."),x}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 x,J;return(x=(J=this.props)===null||J===void 0||(J=J.nodeRef)===null||J===void 0?void 0:J.current)!==null&&x!==void 0?x:h.default.findDOMNode(this)}},{key:"render",value:function(){const{axis:x,bounds:J,children:P,defaultPosition:ge,defaultClassName:q,defaultClassNameDragging:$,defaultClassNameDragged:j,position:te,positionOffset:Q,scale:Ie,...he}=this.props;let ne={},be=null;const ve=!!!te||this.state.dragging,We=te||ge,Be={x:(0,b.canDragX)(this)&&ve?this.state.x:We.x,y:(0,b.canDragY)(this)&&ve?this.state.y:We.y};this.state.isElementSVG?be=(0,f.createSVGTransform)(Be,Q):ne=(0,f.createCSSTransform)(Be,Q);const Je=(0,m.default)(P.props.className||"",q,{[$]:this.state.dragging,[j]:this.state.dragged});return u.createElement(y.default,w({},he,{onStart:this.onDragStart,onDrag:this.onDrag,onStop:this.onDragStop}),u.cloneElement(u.Children.only(P),{className:Je,style:{...P.props.style,...ne},transform:be}))}}],[{key:"getDerivedStateFromProps",value:function(x,J){let{position:P}=x,{prevPropsPosition:ge}=J;return P&&(!ge||P.x!==ge.x||P.y!==ge.y)?((0,Z.default)("Draggable: getDerivedStateFromProps %j",{position:P,prevPropsPosition:ge}),{x:P.x,y:P.y,prevPropsPosition:{...P}}):null}}]),Y}(u.Component);e.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})})(VZe);const{default:FZe,DraggableCore:bCt}=VZe;dN.exports=FZe;dN.exports.default=FZe;dN.exports.DraggableCore=bCt;var yCt=dN.exports,dQ={};dQ.__esModule=!0;dQ.cloneElement=BCt;var ZCt=GCt(N);function GCt(e){return e&&e.__esModule?e:{default:e}}function uie(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 die(e){for(var g=1;g=0)&&(i[n]=e[n]);return i}function nF(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function TCt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function Hp(e,g,i){return g in e?Object.defineProperty(e,g,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[g]=i,e}var hQ=function(e){TCt(g,e);function g(){for(var I,n=arguments.length,r=new Array(n),C=0;C=0)&&(i[n]=e[n]);return i}function pie(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function DCt(e,g){e.prototype=Object.create(g.prototype),e.prototype.constructor=e,e.__proto__=g}function lX(e,g,i){return g in e?Object.defineProperty(e,g,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[g]=i,e}var EZe=function(e){DCt(g,e);function g(){for(var I,n=arguments.length,r=new Array(n),C=0;Cg.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=r);var y={w:h.w,h:h.h,x:h.x,y:h.y,static:!0,i:I};this.props.onResize(A,l,h,y,o,a),this.setState({layout:(0,Mg.compact)(A,this.compactType(),u),activeDrag:y})}},g.prototype.onResizeStop=function(I,n,r,C){var o=C.e,a=C.node,s=this.state,A=s.layout,l=s.oldResizeItem,c=this.props.cols,u=(0,Mg.getLayoutItem)(A,I);this.props.onResizeStop(A,l,u,null,o,a);var d=(0,Mg.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,r=n.width,C=n.cols,o=n.margin,a=n.containerPadding,s=n.rowHeight,A=n.maxRows,l=n.useCSSTransforms;return Qu.default.createElement(Gie.default,{w:I.w,h:I.h,x:I.x,y:I.y,i:I.i,className:"react-grid-placeholder",containerWidth:r,cols:C,margin:o,containerPadding:a||o,maxRows:A,rowHeight:s,isDraggable:!1,isResizable:!1,useCSSTransforms:l},Qu.default.createElement("div",null))},g.prototype.processGridItem=function(I){if(!(!I||!I.key)){var n=(0,Mg.getLayoutItem)(this.state.layout,String(I.key));if(!n)return null;var r=this.props,C=r.width,o=r.cols,a=r.margin,s=r.containerPadding,A=r.rowHeight,l=r.maxRows,c=r.isDraggable,u=r.isResizable,d=r.useCSSTransforms,h=r.draggableCancel,m=r.draggableHandle,f=this.state.mounted,b=!!(!n.static&&c&&(n.isDraggable||n.isDraggable==null)),p=!!(!n.static&&u&&(n.isResizable||n.isResizable==null));return Qu.default.createElement(Gie.default,{containerWidth:C,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,r=n.className,C=n.style,o=(0,eot.default)("react-grid-layout",r),a=yie({height:this.containerHeight()},C);return Qu.default.createElement("div",{className:o,style:a},Qu.default.Children.map(this.props.children,function(s){return I.processGridItem(s)}),this.placeholder())},g}(Qu.default.Component);bN.displayName="ReactGridLayout";bN.propTypes={className:ci.default.string,style:ci.default.object,width:ci.default.number,autoSize:ci.default.bool,cols:ci.default.number,draggableCancel:ci.default.string,draggableHandle:ci.default.string,verticalCompact:function(g){g.verticalCompact},compactType:ci.default.oneOf(["vertical","horizontal"]),layout:function(g){var i=g.layout;i!==void 0&&(0,Mg.validateLayout)(i,"layout")},margin:ci.default.arrayOf(ci.default.number),containerPadding:ci.default.arrayOf(ci.default.number),rowHeight:ci.default.number,maxRows:ci.default.number,isDraggable:ci.default.bool,isResizable:ci.default.bool,preventCollision:ci.default.bool,useCSSTransforms:ci.default.bool,onLayoutChange:ci.default.func,onDragStart:ci.default.func,onDrag:ci.default.func,onDragStop:ci.default.func,onResizeStart:ci.default.func,onResize:ci.default.func,onResizeStop:ci.default.func,children:function(g,i){var I=g[i],n={};Qu.default.Children.forEach(I,function(r){if(n[r.key])throw new Error('Duplicate child key "'+r.key+'" found! This will cause problems in ReactGridLayout.');n[r.key]=!0})}};bN.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:Mg.noop,onDragStart:Mg.noop,onDrag:Mg.noop,onDragStop:Mg.noop,onResizeStart:Mg.noop,onResize:Mg.noop,onResizeStop:Mg.noop};var not=function(){this.state={activeDrag:null,layout:(0,Mg.synchronizeLayoutWithChildren)(this.props.layout,this.props.children,this.props.cols,this.compactType()),mounted:!1,oldDragItem:null,oldLayout:null,oldResizeItem:null}};sN.default=bN;var pQ={},nm={};nm.__esModule=!0;nm.getBreakpointFromWidth=rot;nm.getColsFromBreakpoint=Cot;nm.findOrGenerateResponsiveLayout=oot;nm.sortBreakpoints=bQ;var AV=Dg;function rot(e,g){for(var i=bQ(e),I=i[0],n=1,r=i.length;ne[C]&&(I=C)}return I}function Cot(e,g){if(!g[e])throw new Error("ResponsiveReactGridLayout: `cols` entry for breakpoint "+e+" is missing!");return g[e]}function oot(e,g,i,I,n,r){if(e[i])return(0,AV.cloneLayout)(e[i]);for(var C=e[I],o=bQ(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 dot(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Sie(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 hot(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 wie=function(g){return Object.prototype.toString.call(g)},yQ=function(e){hot(g,e);function g(){var i,I,n;dot(this,g);for(var r=arguments.length,C=Array(r),o=0;o=0||Object.prototype.hasOwnProperty.call(e,I)&&(i[I]=e[I]);return i}function vot(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Rie(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 Bot(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 Sot(e){var g,i;return i=g=function(I){Bot(n,I);function n(){var r,C,o;vot(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 r(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[Y]||(V[Y]=""),H&&(" "+V[Y]+" ").indexOf(" "+H+" ")===-1&&(V[Y]+=" "+H));for(var x in K)K.hasOwnProperty(x)&&(V[K[x]]?this.element.setAttribute(K[x],V[K[x]].substr(1)):this.element.removeAttribute(K[x]))}}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,R){if(typeof C[G]>"u"){C[G]=[];var S=o.length;r.innerHTML+=` +`+G+" {animation: 0.1s element-queries;}",r.innerHTML+=` +`+G+" > .resize-sensor {min-width: "+S+"px;}",o.push(G)}C[G].push({mode:v,property:w,value:R})}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 C)if(C.hasOwnProperty(w))for(var R=v(w,G),S=0,X=R.length;Sw[P].minWidth&&(J=P);if(J||(J=S),X!==J)if(W[J])v[X].style.display="none",v[J].style.display="block",X=J;else{var ge=new Image;ge.onload=function(){v[J].src=R[J],v[X].style.display="none",v[J].style.display="block",W[J]=!0,X=J},ge.src=R[J]}else v[J].src=R[J]}G.resizeSensorInstance=new i(G,x),x()}function f(){for(var G=d(),v=G("[data-responsive-image],[responsive-image]"),w=0,R=v.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",r.innerHTML+=` +@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(r),B=!0);for(var v=0,w=document.styleSheets.length;v\s{0,}<").replace(/-1?(C+=a[r]+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?(C+=i[o],n=!1):/^<\w/.exec(i[o-1])&&/^<\/\w/.exec(i[o])&&/^<[\w:\-\.\,]+/.exec(i[o-1])==/^<\/[\w:\-\.\,]+/.exec(i[o])[0].replace("/","")?(C+=i[o],n||r--):i[o].search(/<\w/)>-1&&i[o].search(/<\//)==-1&&i[o].search(/\/>/)==-1?C=n?C+=i[o]:C+=a[r++]+i[o]:i[o].search(/<\w/)>-1&&i[o].search(/<\//)>-1?C=n?C+=i[o]:C+=a[r]+i[o]:i[o].search(/<\//)>-1?C=n?C+=i[o]:C+=a[--r]+i[o]:i[o].search(/\/>/)>-1?C=n?C+=i[o]:C+=a[r]+i[o]:i[o].search(/<\?/)>-1||i[o].search(/xmlns\:/)>-1||i[o].search(/xmlns\=/)>-1?C+=a[r]+i[o]:C+=i[o];return C[0]==` +`?C.slice(1):C};gl.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};gl.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,r="",C=0,o=g?ZN(g):this.shift;for(C=0;C/g,"").replace(/[ \r\n\t]{1,}xmlns/g," xmlns");return i.replace(/>\s{0,}<")};gl.prototype.jsonmin=function(e){return typeof JSON>"u"?e:JSON.stringify(JSON.parse(e),null,0)};gl.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,"*/")};gl.prototype.sqlmin=function(e){return e.replace(/\s{1,}/g," ").replace(/\s{1,}\(/,"(").replace(/\s{1,}\)/,")")};var Hot=new gl;const Tot=Pr(Hot);var Not=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},vQ={},kot=Object.prototype.hasOwnProperty,Yot;function Vie(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function Wie(e){try{return encodeURIComponent(e)}catch{return null}}function Kot(e){for(var g=/([^=?#&]+)=?([^&]*)/g,i={},I;I=g.exec(e);){var n=Vie(I[1]),r=Vie(I[2]);n===null||r===null||n in i||(i[n]=r)}return i}function Fot(e,g){g=g||"";var i=[],I,n;typeof g!="string"&&(g="?");for(n in e)if(kot.call(e,n)){if(I=e[n],!I&&(I===null||I===Yot||isNaN(I))&&(I=""),n=Wie(n),I=Wie(I),n===null||I===null)continue;i.push(n+"="+I)}return i.length?g+i.join("&"):""}vQ.stringify=Fot;vQ.parse=Kot;var JZe=Not,GN=vQ,Dot=/^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/,OZe=/[\n\r\t]/g,xot=/^[A-Za-z][A-Za-z0-9+-.]*:\/\//,_Ze=/:\d+$/,Eot=/^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i,Mot=/^[a-zA-Z]:/;function BQ(e){return(e||"").toString().replace(Dot,"")}var tz=[["#","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]],Xie={hash:1,query:1};function LZe(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,r;if(e.protocol==="blob:")I=new yA(unescape(e.pathname),{});else if(n==="string"){I=new yA(e,{});for(r in Xie)delete I[r]}else if(n==="object"){for(r in e)r in Xie||(I[r]=e[r]);I.slashes===void 0&&(I.slashes=xot.test(e.href))}return I}function cA(e){return e==="file:"||e==="ftp:"||e==="http:"||e==="https:"||e==="ws:"||e==="wss:"}function UZe(e,g){e=BQ(e),e=e.replace(OZe,""),g=g||{};var i=Eot.exec(e),I=i[1]?i[1].toLowerCase():"",n=!!i[2],r=!!i[3],C=0,o;return n?r?(o=i[2]+i[3]+i[4],C=i[2].length+i[3].length):(o=i[2]+i[4],C=i[2].length):r?(o=i[3]+i[4],C=i[3].length):o=i[4],I==="file:"?C>=2&&(o=o.slice(2)):cA(I)?o=i[4]:I?n&&(o=o.slice(2)):C>=2&&cA(g.protocol)&&(o=i[4]),{protocol:I,slashes:n||cA(I),slashesCount:C,rest:o}}function zot(e,g){if(e==="")return g;for(var i=(g||"/").split("/").slice(0,-1).concat(e.split("/")),I=i.length,n=i[I-1],r=!1,C=0;I--;)i[I]==="."?i.splice(I,1):i[I]===".."?(i.splice(I,1),C++):C&&(I===0&&(r=!0),i.splice(I,1),C--);return r&&i.unshift(""),(n==="."||n==="..")&&i.push(""),i.join("/")}function yA(e,g,i){if(e=BQ(e),e=e.replace(OZe,""),!(this instanceof yA))return new yA(e,g,i);var I,n,r,C,o,a,s=tz.slice(),A=typeof g,l=this,c=0;for(A!=="object"&&A!=="string"&&(i=g,g=null),i&&typeof i!="function"&&(i=GN.parse),g=LZe(g),n=UZe(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||Mot.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:()=>{}}}})(),SQ=(e,g)=>g?e.toLowerCase():e,jZe=(e,{caseInsensitive:g}={})=>(i,I,n=1/0)=>{const r=SQ(i,g);return e[r]||(e[r]=[],e.__times__[r]=[]),e[r].push(I),e.__times__[r].push(+n||1/0),{event:r,handler:I}},wQ=(e,{caseInsensitive:g}={})=>(i,I)=>{typeof i=="object"&&(I=i.handler,i=i.event);const n=SQ(i,g);if(!e[n])return;const r=e[n].indexOf(I);r===-1||r>=e[n].length||(e[n].splice(r,1),e.__times__[n].splice(r,1))},Hie=(e,g)=>()=>{e.forEach(i=>i(g))},$Ze=(e,{isGlobal:g,caseInsensitive:i,async:I}={})=>{const n=wQ(e);return(r,C,o={})=>{const a=SQ(r,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(Hie(s,C),0):Hie(s,C)(),g&&!o.isNoGlobalBroadcast)try{QZe.postMessage({event:a,news:C})}catch(A){if(A instanceof DOMException)console.warn(`Could not broadcast '${a}' globally. Payload is not clonable.`);else throw A}}},qZe=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]})},eGe=()=>({__times__:{}}),vN=(e={})=>{const g=e.async||!1,i=e.caseInsensitive||!1,I=e.stack||eGe();return I.__times__||(I.__times__={}),{publish:$Ze(I,{async:g,caseInsensitive:i}),subscribe:jZe(I,{caseInsensitive:i}),unsubscribe:wQ(I,{caseInsensitive:i}),clear:qZe(I),stack:I}},qy=eGe(),zG={publish:$Ze(qy,{isGlobal:!0}),subscribe:jZe(qy),unsubscribe:wQ(qy),clear:qZe(qy),stack:qy};QZe.onmessage=({data:{event:e,news:g}})=>zG.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 ig(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))}ig.defaultProps={onMouseEnter:()=>{},onMouseLeave:()=>{}};ig.propTypes={children:L.node.isRequired,onClick:L.func.isRequired,onMouseEnter:L.func,onMouseLeave:L.func};var Lot={value:()=>{}};function x0(){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}})}z1.prototype=x0.prototype={constructor:z1,on:function(e,g){var i=this._,I=Uot(e+"",i),n,r=-1,C=I.length;if(arguments.length<2){for(;++r0)for(var i=new Array(n),I=0,n,r;I()=>e;function gz(e,{sourceEvent:g,subject:i,target:I,identifier:n,active:r,x:C,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:r,enumerable:!0,configurable:!0},x:{value:C,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}})}gz.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function jot(e){return!e.ctrlKey&&!e.button}function $ot(){return this.parentNode}function qot(e,g){return g??{x:e.x,y:e.y}}function eat(){return navigator.maxTouchPoints||"ontouchstart"in this}function QA(){var e=jot,g=$ot,i=qot,I=eat,n={},r=x0("start","drag","end"),C=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&&(dg(y.view).on("mousemove.drag",d,!0).on("mouseup.drag",h,!0),BN(y.view),aF(y),s=!1,o=y.clientX,a=y.clientY,B("start",y))}}function d(y){if(Np(y),!s){var Z=y.clientX-o,B=y.clientY-a;s=Z*Z+B*B>l}n.mouse("drag",y)}function h(y){dg(y.view).on("mousemove.drag mouseup.drag",null),SN(y.view,s),Np(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,R;for(w=0;w=0&&e._call.call(null,g),e=e._next;--Hb}function Nie(){Ch=(dX=TB.now())+wN,Hb=EZ=0;try{iat()}finally{Hb=0,nat(),Ch=0}}function Iat(){var e=TB.now(),g=e-dX;g>tGe&&(wN-=g,dX=e)}function nat(){for(var e,g=uX,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:uX=i);MZ=e,iz(I)}function iz(e){if(!Hb){EZ&&(EZ=clearTimeout(EZ));var g=e-Ch;g>24?(e<1/0&&(EZ=setTimeout(Nie,e-TB.now()-wN)),eZ&&(eZ=clearInterval(eZ))):(eZ||(dX=TB.now(),eZ=setInterval(Iat,tGe)),Hb=1,gGe(Nie))}}function kie(e,g,i){var I=new hX;return g=g==null?0:+g,I.restart(n=>{I.stop(),e(n+g)},g,i),I}var rat=x0("start","end","cancel","interrupt"),Cat=[],IGe=0,Yie=1,Iz=2,P1=3,Kie=4,nz=5,J1=6;function RN(e,g,i,I,n,r){var C=e.__transition;if(!C)e.__transition={};else if(i in C)return;oat(e,i,{name:g,index:I,group:n,on:rat,tween:Cat,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:IGe})}function VQ(e,g){var i=ma(e,g);if(i.state>IGe)throw new Error("too late; already scheduled");return i}function HA(e,g){var i=ma(e,g);if(i.state>P1)throw new Error("too late; already running");return i}function ma(e,g){var i=e.__transition;if(!i||!(i=i[g]))throw new Error("transition not found");return i}function oat(e,g,i){var I=e.__transition,n;I[g]=i,i.timer=iGe(r,0,i.time);function r(s){i.state=Yie,i.timer.restart(C,i.delay,i.time),i.delay<=s&&C(s-i.delay)}function C(s){var A,l,c,u;if(i.state!==Yie)return a();for(A in I)if(u=I[A],u.name===i.name){if(u.state===P1)return kie(C);u.state===Kie?(u.state=J1,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete I[A]):+AIz&&I.state=0&&(g=g.slice(0,i)),!g||g==="start"})}function Fat(e,g,i){var I,n,r=Kat(g)?VQ:HA;return function(){var C=r(this,e),o=C.on;o!==I&&(n=(I=o).copy()).on(g,i),C.on=n}}function Dat(e,g){var i=this._id;return arguments.length<2?ma(this.node(),i).on.on(e):this.each(Fat(i,e,g))}function xat(e){return function(){var g=this.parentNode;for(var i in this.__transition)if(+i!==e)return;g&&g.removeChild(this)}}function Eat(){return this.on("end.remove",xat(this._id))}function Mat(e){var g=this._name,i=this._id;typeof e!="function"&&(e=KS(e));for(var I=this._groups,n=I.length,r=new Array(n),C=0;C()=>e;function cAt(e,{sourceEvent:g,target:i,selection:I,mode:n,dispatch:r}){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:r}})}function uAt(e){e.stopImmediatePropagation()}function sF(e){e.preventDefault(),e.stopImmediatePropagation()}var Fie={name:"drag"},lF={name:"space"},Dm={name:"handle"},xm={name:"center"};const{abs:Die,max:Wn,min:Xn}=Math;function xie(e){return[+e[0],+e[1]]}function Cz(e){return[xie(e[0]),xie(e[1])]}var O1={name:"x",handles:["w","e"].map(NB),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]]}},_1={name:"y",handles:["n","s"].map(NB),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]]}},dAt={name:"xy",handles:["n","w","e","s","nw","ne","sw","se"].map(NB),input:function(e){return e==null?null:Cz(e)},output:function(e){return e}},EA={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"},Eie={e:"w",w:"e",nw:"ne",ne:"nw",se:"sw",sw:"se"},Mie={n:"s",s:"n",nw:"sw",ne:"se",se:"ne",sw:"nw"},hAt={overlay:1,selection:1,n:null,e:1,s:null,w:-1,nw:-1,ne:1,se:1,sw:-1},mAt={overlay:1,selection:1,n:-1,e:null,s:1,w:null,nw:-1,ne:-1,se:1,sw:1};function NB(e){return{type:e}}function fAt(e){return!e.ctrlKey&&!e.button}function pAt(){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 bAt(){return navigator.maxTouchPoints||"ontouchstart"in this}function cF(e){for(;!e.__brush;)if(!(e=e.parentNode))return;return e.__brush}function yAt(e){return e[0][0]===e[1][0]||e[0][1]===e[1][1]}function ZAt(e){var g=e.__brush;return g?g.dim.output(g.selection):null}function VN(){return HQ(O1)}function _S(){return HQ(_1)}function XQ(){return HQ(dAt)}function HQ(e){var g=pAt,i=fAt,I=bAt,n=!0,r=x0("start","brush","end"),C=6,o;function a(m){var f=m.property("__brush",h).selectAll(".overlay").data([NB("overlay")]);f.enter().append("rect").attr("class","overlay").attr("pointer-events","all").attr("cursor",EA.overlay).merge(f).each(function(){var p=cF(this).extent;dg(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([NB("selection")]).enter().append("rect").attr("class","selection").attr("cursor",EA.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 EA[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=em(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();rz(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=dg(this),f=cF(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]-C/2:f[0][0]-C/2}).attr("y",function(b){return b.type[0]==="s"?f[1][1]-C/2:f[0][1]-C/2}).attr("width",function(b){return b.type==="n"||b.type==="s"?f[1][0]-f[0][0]+C:C}).attr("height",function(b){return b.type==="e"||b.type==="w"?f[1][1]-f[0][1]+C:C})):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=dg(this.that).datum();r.call(m,this.that,new cAt(m,{sourceEvent:f,target:a,selection:e.output(this.state.selection),mode:b,dispatch:r}),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"?Fie:n&&m.altKey?xm:Dm,y=e===_1?null:hAt[b],Z=e===O1?null:mAt[b],B=cF(f),G=B.extent,v=B.selection,w=G[0][0],R,S,X=G[0][1],W,V,H=G[1][0],Y,K,x=G[1][1],J,P,ge=0,q=0,$,j=y&&Z&&n&&m.shiftKey,te,Q,Ie=Array.from(m.touches||[m],De=>{const Qe=De.identifier;return De=zg(De,f),De.point0=De.slice(),De.identifier=Qe,De});if(b==="overlay"){v&&($=!0);const De=[Ie[0],Ie[1]||Ie[0]];B.selection=v=[[R=e===_1?w:Xn(De[0][0],De[1][0]),W=e===O1?X:Xn(De[0][1],De[1][1])],[Y=e===_1?H:Wn(De[0][0],De[1][0]),J=e===O1?x:Wn(De[0][1],De[1][1])]],Ie.length>1&&We()}else R=v[0][0],W=v[0][1],Y=v[1][0],J=v[1][1];S=R,V=W,K=Y,P=J;var he=dg(f).attr("pointer-events","none"),ne=he.selectAll(".overlay").attr("cursor",EA[b]);rz(f);var be=A(f,arguments,!0).beforestart();if(m.touches)be.moved=ve,be.ended=Be;else{var pe=dg(m.view).on("mousemove.brush",ve,!0).on("mouseup.brush",Be,!0);n&&pe.on("keydown.brush",Je,!0).on("keyup.brush",Pe,!0),BN(m.view)}s.call(f),be.start(m,p.name);function ve(De){for(const Qe of De.changedTouches||[De])for(const _e of Ie)_e.identifier===Qe.identifier&&(_e.cur=zg(Qe,f));if(j&&!te&&!Q&&Ie.length===1){const Qe=Ie[0];Die(Qe.cur[0]-Qe[0])>Die(Qe.cur[1]-Qe[1])?Q=!0:te=!0}for(const Qe of Ie)Qe.cur&&(Qe[0]=Qe.cur[0],Qe[1]=Qe.cur[1]);$=!0,sF(De),We(De)}function We(De){const Qe=Ie[0],_e=Qe.point0;var gt;switch(ge=Qe[0]-_e[0],q=Qe[1]-_e[1],p){case lF:case Fie:{y&&(ge=Wn(w-R,Xn(H-Y,ge)),S=R+ge,K=Y+ge),Z&&(q=Wn(X-W,Xn(x-J,q)),V=W+q,P=J+q);break}case Dm:{Ie[1]?(y&&(S=Wn(w,Xn(H,Ie[0][0])),K=Wn(w,Xn(H,Ie[1][0])),y=1),Z&&(V=Wn(X,Xn(x,Ie[0][1])),P=Wn(X,Xn(x,Ie[1][1])),Z=1)):(y<0?(ge=Wn(w-R,Xn(H-R,ge)),S=R+ge,K=Y):y>0&&(ge=Wn(w-Y,Xn(H-Y,ge)),S=R,K=Y+ge),Z<0?(q=Wn(X-W,Xn(x-W,q)),V=W+q,P=J):Z>0&&(q=Wn(X-J,Xn(x-J,q)),V=W,P=J+q));break}case xm:{y&&(S=Wn(w,Xn(H,R-ge*y)),K=Wn(w,Xn(H,Y+ge*y))),Z&&(V=Wn(X,Xn(x,W-q*Z)),P=Wn(X,Xn(x,J+q*Z)));break}}K0&&(R=S-ge),Z<0?J=P-q:Z>0&&(W=V-q),p=lF,ne.attr("cursor",EA.selection),We());break}default:return}sF(De)}function Pe(De){switch(De.keyCode){case 16:{j&&(te=Q=j=!1,We());break}case 18:{p===xm&&(y<0?Y=K:y>0&&(R=S),Z<0?J=P:Z>0&&(W=V),p=Dm,We());break}case 32:{p===lF&&(De.altKey?(y&&(Y=K-ge*y,R=S+ge*y),Z&&(J=P-q*Z,W=V+q*Z),p=xm):(y<0?Y=K:y>0&&(R=S),Z<0?J=P:Z>0&&(W=V),p=Dm),ne.attr("cursor",EA[b]),We());break}default:return}sF(De)}}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=Cz(g.apply(this,arguments)),m.dim=e,m}return a.extent=function(m){return arguments.length?(g=typeof m=="function"?m:AF(Cz(m)),a):g},a.filter=function(m){return arguments.length?(i=typeof m=="function"?m:AF(!!m),a):i},a.touchable=function(m){return arguments.length?(I=typeof m=="function"?m:AF(!!m),a):I},a.handleSize=function(m){return arguments.length?(C=+m,a):C},a.keyModifiers=function(m){return arguments.length?(n=!!m,a):n},a.on=function(){var m=r.on.apply(r,arguments);return m===r?a:m},a}const GAt=Object.freeze(Object.defineProperty({__proto__:null,brush:XQ,brushSelection:ZAt,brushX:VN,brushY:_S},Symbol.toStringTag,{value:"Module"}));function kB(){return kB=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(kAt)}}]),e}();function kAt(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 sGe(e,g){return Object.keys(e).reduce(function(i,I){return g.indexOf(I)===-1&&(i[I]=e[I]),i},{})}var Em={end:["touchend","touchcancel","mouseup"],move:["touchmove","mousemove"],start:["touchstart","mousedown"]},lGe=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 lV(e,g){Object.keys(g).forEach(function(i){e.style[i]=g[i]})}function cV(e,g){e.style["".concat(lGe,"Transform")]=g==null?"":"translate3d(".concat(g.x,"px,").concat(g.y,"px,0)")}function dF(e,g){e.style["".concat(lGe,"TransitionDuration")]=g==null?"":"".concat(g,"ms")}function zZ(e,g){for(;e;){if(g(e))return e;e=e.parentNode}return null}function Pie(e,g,i){return Math.max(e,Math.min(i,g))}function Ip(e){return e.substr(-2)==="px"?parseFloat(e):0}function KAt(e){var g=window.getComputedStyle(e);return{bottom:Ip(g.marginBottom),left:Ip(g.marginLeft),right:Ip(g.marginRight),top:Ip(g.marginTop)}}function kQ(e,g){var i=g.displayName||g.name;return i?"".concat(e,"(").concat(i,")"):e}function hF(e,g){var i=e.getBoundingClientRect();return{top:i.top+g.top,left:i.left+g.left}}function tZ(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 FAt(e){return e.touches&&e.touches.length||e.changedTouches&&e.changedTouches.length}function L1(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:L1(e.parentNode,g,I)}}function DAt(e,g,i){return eg?e-1:e>i&&e0&&i[C].height>0){var o=r.getContext("2d");o.drawImage(i[C],0,0)}}),I}function Az(e){var g,i,I=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return i=g=function(n){NQ(r,n);function r(){return LS(this,r),TQ(this,YB(r).apply(this,arguments))}return US(r,[{key:"componentDidMount",value:function(){var o=Aa.findDOMNode(this);o.sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return oh(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 U.createElement(e,kB({ref:o},this.props))}}]),r}(U.Component),Ug(g,"displayName",kQ("sortableHandle",e)),i}function Oie(e){return e.sortableHandle!=null}var PAt=function(){function e(g,i){LS(this,e),this.container=g,this.onScrollCallback=i}return US(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,r=i.minTranslate,C=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>=C.y-a/2&&!y?(s.y=1,A.y=l.y*Math.abs((C.y-a/2-n.y)/a)):n.x>=C.x-o/2&&!B?(s.x=1,A.x=l.x*Math.abs((C.x-o/2-n.x)/o)):n.y<=r.y+a/2&&!p?(s.y=-1,A.y=l.y*Math.abs((n.y-a/2-r.y)/a)):n.x<=r.x+o/2&&!Z&&(s.x=-1,A.x=l.x*Math.abs((n.x-o/2-r.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 JAt(e){var g=e.node;return{height:g.offsetHeight,width:g.offsetWidth}}function OAt(e){var g=[id.Input,id.Textarea,id.Select,id.Option,id.Button];return!!(g.indexOf(e.target.tagName)!==-1||zZ(e.target,function(i){return i.contentEditable==="true"}))}var uGe={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},dGe={lift:[Hu.SPACE],drop:[Hu.SPACE],cancel:[Hu.ESC],up:[Hu.UP,Hu.LEFT],down:[Hu.DOWN,Hu.RIGHT]},_At={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:JAt,hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,keyCodes:dGe,shouldCancelStart:OAt,transitionDuration:300,useWindowAsScrollContainer:!1},LAt=Object.keys(uGe);function UAt(e){oh(!(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 QAt(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 jAt(e){var g,i,I=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{withRef:!1};return i=g=function(n){NQ(r,n);function r(C){var o;return LS(this,r),o=TQ(this,YB(r).call(this,C)),Ug(bg(bg(o)),"state",{}),Ug(bg(bg(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=tZ(a);var c=zZ(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&&!zZ(a.target,Oie))return;o.manager.active={collection:m,index:h},!FAt(a)&&a.target.tagName===id.Anchor&&a.preventDefault(),A||(o.props.pressDelay===0?o.handlePress(a):o.pressTimer=setTimeout(function(){return o.handlePress(a)},o.props.pressDelay))}}}),Ug(bg(bg(o)),"nodeIsChild",function(a){return a.sortableInfo.manager===o.manager}),Ug(bg(bg(o)),"handleMove",function(a){var s=o.props,A=s.distance,l=s.pressThreshold;if(!o.state.sorting&&o.touched&&!o._awaitingUpdateBeforeSortStart){var c=tZ(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)}}),Ug(bg(bg(o)),"handleEnd",function(){o.touched=!1,o.cancel()}),Ug(bg(bg(o)),"cancel",function(){var a=o.props.distance,s=o.state.sorting;s||(a||clearTimeout(o.pressTimer),o.manager.active=null)}),Ug(bg(bg(o)),"handlePress",function(a){try{var s=o.manager.getActive(),A=function(){if(s){var l=function(){var w=y.sortableInfo.index,R=KAt(y),S=MAt(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=L1(y,o.container),B?o.initialOffset=tZ(uF({},a,{pageX:o.boundingClientRect.left,pageY:o.boundingClientRect.top})):o.initialOffset=tZ(a),o.initialScroll={left:o.scrollContainer.scrollLeft,top:o.scrollContainer.scrollTop},o.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},o.helper=o.helperContainer.appendChild(zAt(y)),lV(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")}),B&&o.helper.focus(),m&&(o.sortableGhost=y,lV(y,{opacity:0,visibility:"hidden"})),o.minTranslate={},o.maxTranslate={},B){var V=p?{top:0,left:0,width:o.contentWindow.innerWidth,height:o.contentWindow.innerHeight}:o.containerBoundingRect,H=V.top,Y=V.left,K=V.width,x=V.height,J=H+x,P=Y+K;o.axis.x&&(o.minTranslate.x=Y-o.boundingClientRect.left,o.maxTranslate.x=P-(o.boundingClientRect.left+o.width)),o.axis.y&&(o.minTranslate.y=H-o.boundingClientRect.top,o.maxTranslate.y=J-(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(ge){return o.helper.classList.add(ge)}),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)):(Em.move.forEach(function(ge){return o.listenerNode.addEventListener(ge,o.handleSortMove,!1)}),Em.end.forEach(function(ge){return o.listenerNode.addEventListener(ge,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=QAt(function(){var w=y.sortableInfo.index;return Promise.resolve(f({collection:Z,index:w,node:y,isKeySorting:B},a)).then(function(){})},function(w,R){if(o._awaitingUpdateBeforeSortStart=!1,w)throw R;return R});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)}}),Ug(bg(bg(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)}),Ug(bg(bg(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)):(Em.move.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortMove)}),Em.end.forEach(function(y){return o.listenerNode.removeEventListener(y,o.handleSortEnd)}))),o.helper.parentNode.removeChild(o.helper),A&&o.sortableGhost&&lV(o.sortableGhost,{opacity:"",visibility:""});for(var m=0,f=h.length;mA)){o.prevIndex=c,o.newIndex=l;var u=DAt(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||hF(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,R={x:0,y:0},S=u[f].edgeOffset;S||(S=L1(p,this.container),u[f].edgeOffset=S,h&&(u[f].boundingClientRect=hF(p,l)));var X=f0&&u[f-1];if(X&&!X.edgeOffset&&(X.edgeOffset=L1(X.node,this.container),h&&(X.boundingClientRect=hF(X.node,l))),y===this.index){s&&(this.sortableGhost=p,lV(p,{opacity:0,visibility:"hidden"}));continue}a&&dF(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)):(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))&&(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=g=function(n){NQ(r,n);function r(){return LS(this,r),TQ(this,YB(r).apply(this,arguments))}return US(r,[{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=Aa.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 oh(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 U.createElement(e,kB({ref:o},sGe(this.props,$At)))}}]),r}(U.Component),Ug(g,"displayName",kQ("sortableElement",e)),Ug(g,"contextTypes",{manager:L.object.isRequired}),Ug(g,"propTypes",hGe),Ug(g,"defaultProps",{collection:0}),i}const fGe=Y0(e=>e.pos).left,TI=(e,g)=>{if(!g||!g.cumPositions||!g.cumPositions.length)return null;let i=fGe(g.cumPositions,e);const I=g.cumPositions[g.cumPositions.length-1].chr,n=g.chromLengths[I];i>0&&(i-=1);let r=Math.floor(e-g.cumPositions[i].pos),C=0;return r<0&&(C=r-1,r=1),i===g.cumPositions.length-1&&r>n&&(C=r-n,r=n),[g.cumPositions[i].chr,r,C,i]},pGe=(e,g)=>i=>i%e*g+Math.floor(i/e),qAt=e=>e,bGe=(e,g,i=qAt)=>e.map((I,n)=>I+g[i(n)]),est="http://www.w3.org/2000/svg",mX=(e,g)=>{if(e.namespaceURI===est){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|$)`))},tst="http://www.w3.org/2000/svg",gst=(e,g)=>{if(e.namespaceURI===tst){if(!mX(e,g)){const i=e.getAttribute("class")||"";e.setAttribute("class",`${i} ${g}`)}}else e.classList?e.classList.add(g):mX(e,g)||(e.className+=` ${g}`)},ist=(e,g,i)=>{const I=document.createElement("canvas");return new Promise((n,r)=>{const C=new window.Image;C.onload=()=>{I.width=g||C.width,I.height=i||C.height;const o=I.getContext("2d");if(!o){r(new Error("Could not get canvas context"));return}o.drawImage(C,0,0),n(I)},C.onerror=()=>{r(new Error("Could not convert base64 to canvas"))},C.src=`data:image/png;base64,${e}`})},fX=(e,g,i)=>i.chrPositions[e].pos+g,yGe=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},Oc=(e,g=!1)=>{const i=e.map((C,o)=>o*(255/(e.length-1))),I=tg().domain(i).range(e),r=nr(g?255:254,-1,-1).map(I).map(C=>{const o=Sb(C);return[o.r,o.g,o.b,o.opacity*255]});return r.length<256&&r.push([255,255,255,0]),r},PZ=0,JZ=5,ZGe=10,GGe=10,vGe=300,pX="move",EC="select",sz=100,bX=10,BGe=110,OZ=3e3,_Z="locationListenerPrefix",SGe=1e3,lz="http://higlass.io/api/v1",wGe=400,RGe=300,cz=["top","left","right","bottom","center","whole","gallery"],VGe=20,WGe=20,yX=Symbol("Light theme"),gi=Symbol("Dark theme"),Ist=yX,ot={PIXI:Gpe},wC={"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"},nst={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"},rst={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"},Cst={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"},ost={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"},ast={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"},Ast={id:"play",paths:["M96 64l320 192-320 192z"],viewBox:"0 0 512 512"},sst={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"},lst={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"},cst={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"]},ust={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"]},dst={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"]},hst={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"]},mst={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"]},fst={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"]},pst={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"]},bst={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"]},yst=[nst,rst,Cst,ost,ast,Ast,sst,lst,cst,ust,dst,hst,pst,bst,mst,fst],fa=new DOMParser,Zst='',YQ=fa.parseFromString(Zst,"text/xml").documentElement,Gst=` @@ -1643,7 +1643,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,mst=fa.parseFromString(hst,"text/xml").documentElement,fst=` +`,vst=fa.parseFromString(Gst,"text/xml").documentElement,Bst=` line @@ -1651,7 +1651,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,pst=fa.parseFromString(fst,"text/xml").documentElement,bst=` +`,Sst=fa.parseFromString(Bst,"text/xml").documentElement,wst=` 2d-tiles-icon @@ -1681,7 +1681,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,EIe=fa.parseFromString(bst,"text/xml").documentElement,yst=` +`,_ie=fa.parseFromString(wst,"text/xml").documentElement,Rst=` 2d-heatmap @@ -1709,7 +1709,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,MIe=fa.parseFromString(yst,"text/xml").documentElement,GGe=` +`,Lie=fa.parseFromString(Rst,"text/xml").documentElement,XGe=` axis-1d @@ -1719,7 +1719,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Zst=fa.parseFromString(GGe,"text/xml").documentElement,Gst=dg(fa.parseFromString(GGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),vst=` +`,Vst=fa.parseFromString(XGe,"text/xml").documentElement,Wst=dg(fa.parseFromString(XGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),Xst=` gene-annotations @@ -1746,7 +1746,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Bst=fa.parseFromString(vst,"text/xml").documentElement,vGe=` +`,Hst=fa.parseFromString(Xst,"text/xml").documentElement,HGe=` 1d-tiles-icon @@ -1766,7 +1766,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,Sst=fa.parseFromString(vGe,"text/xml").documentElement,wst=dg(fa.parseFromString(vGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),Vst=` +`,Tst=fa.parseFromString(HGe,"text/xml").documentElement,Nst=dg(fa.parseFromString(HGe,"text/xml").documentElement).style("transform","rotate(90deg)").node(),kst=` arrowhead-domains @@ -1786,27 +1786,27 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho -`,tZ=fa.parseFromString(Vst,"text/xml").documentElement;function BGe({theStyle:e,onClick:g}){return N.createElement("svg",{className:Vr[e],viewBox:"0 0 12 13",onClick:g,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"})))}BGe.propTypes={theStyle:L.string,onClick:L.func};const zIe={type:"osm-tiles",datatype:["map-tiles"],local:!0,orientation:"2d",hidden:!0,name:"OSM Tiles",thumbnail:WQ,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}},PIe={type:"mapbox-tiles",datatype:["map-tiles"],local:!0,orientation:"2d",hidden:!0,name:"Mapbox Tiles",thumbnail:WQ,availableOptions:["style","labelPosition","labelLeftMargin","labelRightMargin","labelTopMargin","labelBottomMargin","name"],defaultOptions:{style:"mapbox.streets",labelPosition:"bottomRight",labelLeftMargin:0,labelRightMargin:0,labelTopMargin:0,labelBottomMargin:0}},Ah=[zIe,{...zIe,type:"osm"},PIe,{...PIe,type:"mapbox"},{type:"left-axis",datatype:["axis"],local:!0,orientation:"1d-vertical",name:"Left Axis",thumbnail:Gst,availableOptions:["minWidth"],defaultOptions:{minWidth:100}},{type:"top-axis",datatype:["axis"],local:!0,orientation:"1d-horizontal",name:"Top Axis",thumbnail:Zst,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:MIe,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:{[gI]:{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:MIe,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:pst,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:{[gI]:{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:mst,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:{[gI]:{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:EIe},{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:Bst,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:{[gI]:{labelColor:"#ffffff",labelBackgroundColor:"#000000",trackBorderColor:"#ffffff",mousePositionColor:"#ffffff",plusStrandColor:"#40a0ff"}}},{type:"arrowhead-domains",datatype:["arrowhead-domains"],local:!1,orientation:"2d",name:"Arrowhead Domains",thumbnail:tZ,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:tZ,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:tZ,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:tZ,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:tZ,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:{[gI]:{color:"#808080",stroke:"#000000",mousePositionColor:"#ffffff"}}},{type:"vertical-1d-tiles",datatype:["1d-tiles"],local:!1,orientation:"1d-vertical",name:"Vertical 1D Tile Outlines",thumbnail:wst},{type:"horizontal-1d-tiles",datatype:["vector","stacked-interval","gene-annotation"],local:!1,orientation:"1d-horizontal",name:"Horizontal 1D Tile Outlines",thumbnail:Sst},{type:"osm-2d-tile-ids",datatype:["map-tiles"],local:!1,orientation:"2d",name:"OSM Tile Outlines",thumbnail:EIe,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:WQ,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:{}}],XQ=e=>{const g={},I=i=>!!(i.orientation===e||e==="1d-vertical"&&i.orientation==="1d-horizontal"&&i.rotatable);return Ah.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},Tb=[[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]],Qg=Ah.reduce((e,g)=>{if(e[g.type]=g,g.aliases)for(const I of g.aliases)e[I]=g;return e},{}),Rst=Ah.reduce((e,g)=>{for(let I=0;I{const I=XQ(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]},SGe=8,HQ=8,Wst=Object.freeze(Object.defineProperty({__proto__:null,AVAILABLE_TRACK_TYPES:p9,DATATYPE_TO_TRACK_TYPE:XQ,DEFAULT_CONTAINER_PADDING_X:uGe,DEFAULT_CONTAINER_PADDING_Y:dGe,DEFAULT_SERVER:rz,DEFAULT_TRACKS_FOR_DATATYPE:NB,DEFAULT_VIEW_MARGIN:zZ,DEFAULT_VIEW_PADDING:PZ,GLOBALS:ot,HEATED_OBJECT_MAP:Tb,LOCATION_LISTENER_PREFIX:OZ,LONG_DRAG_TIMEOUT:JZ,MAX_CLICK_DELAY:hGe,MIN_HORIZONTAL_HEIGHT:yGe,MIN_VERTICAL_WIDTH:ZGe,MOUSE_TOOL_MOVE:h9,MOUSE_TOOL_SELECT:Mr,NUM_PRECOMP_SUBSETS_PER_1D_TTILE:SGe,NUM_PRECOMP_SUBSETS_PER_2D_TTILE:HQ,POSITIONS_BY_DATATYPE:Rst,SHORT_DRAG_TIMEOUT:mGe,THEME_DARK:gI,THEME_DEFAULT:jAt,THEME_LIGHT:f9,TILE_FETCH_DEBOUNCE:Cz,TRACKS_INFO:Ah,TRACKS_INFO_BY_TYPE:Qg,TRACK_LOCATIONS:oz,VIEW_HEADER_MED_WIDTH_SEARCH_BAR:pGe,VIEW_HEADER_MIN_WIDTH_SEARCH_BAR:bGe,ZOOM_DEBOUNCE:m9,ZOOM_TRANSITION_DURATION:fGe},Symbol.toStringTag,{value:"Module"})),Kt=e=>{const g=Hi(e);return ot.PIXI.utils.rgb2hex([g.r/255,g.g/255,g.b/255])},wGe=e=>{if(e==="transparent")return[255,255,255,0];const g=Hi(e);return[g.r,g.g,g.b,255]},b9=(e,g,I)=>{const i=Ti(e,I),n=Ti(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])]},TQ=(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},az=e=>(e+16**6).toString(16).substr(-6),VGe=e=>{const g={};return e.forEach(I=>{g[I[0]]=I[1]}),g},Tr=e=>{const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push([I,e[I]]);return g};function Rr(e){const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push(I);return g}function Eg(e){const g=[];for(const I in e)e.hasOwnProperty(I)&&g.push(e[I]);return g}function PG(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 RGe=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=Qg[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||yGe)})),I.map(i=>e[i]).forEach(i=>i.forEach(n=>{const C=Qg[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||ZGe)})),e},WGe=e=>g=>Array.prototype.reduce.call(g,e),Xst=WGe((e,g)=>e.concat(g)),Hst=e=>g=>Array.prototype.forEach.call(g,e),y9=(e,g)=>{g.dispatchEvent(cGe(e))},Tst=(e,g)=>[d9(e[0],e[1],g),d9(e[2],e[3],g)];function Nst(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=NB[e]!==void 0?NB[e][g]:void 0;return n!==void 0&&(i=I.find(C=>C.type===n)||i),i};var JIe={},ux={},dx=34,gZ=10,hx=13;function XGe(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function kst(e,g){var I=XGe(e);return function(i,n){return g(I(i),n,e)}}function OIe(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 SC(e,g){var I=e+"",i=I.length;return i9999?"+"+SC(e,6):SC(e,4)}function Kst(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":Yst(e.getUTCFullYear())+"-"+SC(e.getUTCMonth()+1,2)+"-"+SC(e.getUTCDate(),2)+(n?"T"+SC(g,2)+":"+SC(I,2)+":"+SC(i,2)+"."+SC(n,3)+"Z":i?"T"+SC(g,2)+":"+SC(I,2)+":"+SC(i,2)+"Z":I||g?"T"+SC(g,2)+":"+SC(I,2)+"Z":"")}function kQ(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?kst(m,c):XGe(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)===hx&&--d;function y(){if(b)return ux;if(p)return p=!1,JIe;var B,G=h,v;if(l.charCodeAt(G)===dx){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===gZ?p=!0:v===hx&&(p=!0,l.charCodeAt(h)===gZ&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;h{const g={},i=I=>!!(I.orientation===e||e==="1d-vertical"&&I.orientation==="1d-horizontal"&&I.rotatable);return ah.filter(i).forEach(I=>{let n=I.datatype;Array.isArray(I.datatype)||(n=[n]),n.forEach(r=>{r in g||(g[r]=[]),g[r].push(I)})}),g.none=[],g},Nb=[[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]],Qg=ah.reduce((e,g)=>{if(e[g.type]=g,g.aliases)for(const i of g.aliases)e[i]=g;return e},{}),Yst=ah.reduce((e,g)=>{for(let i=0;i{const i=KQ(g);let I=new Set(Object.values(i).flatMap(n=>n));for(const n of e){const r=new Set(n);I=new Set([...I].filter(C=>C.datatype.filter(o=>r.has(o)).length>0))}return[...I]},NGe=8,FQ=8,Kst=Object.freeze(Object.defineProperty({__proto__:null,AVAILABLE_TRACK_TYPES:ZX,DATATYPE_TO_TRACK_TYPE:KQ,DEFAULT_CONTAINER_PADDING_X:ZGe,DEFAULT_CONTAINER_PADDING_Y:GGe,DEFAULT_SERVER:lz,DEFAULT_TRACKS_FOR_DATATYPE:KB,DEFAULT_VIEW_MARGIN:PZ,DEFAULT_VIEW_PADDING:JZ,GLOBALS:ot,HEATED_OBJECT_MAP:Nb,LOCATION_LISTENER_PREFIX:_Z,LONG_DRAG_TIMEOUT:OZ,MAX_CLICK_DELAY:vGe,MIN_HORIZONTAL_HEIGHT:VGe,MIN_VERTICAL_WIDTH:WGe,MOUSE_TOOL_MOVE:pX,MOUSE_TOOL_SELECT:EC,NUM_PRECOMP_SUBSETS_PER_1D_TTILE:NGe,NUM_PRECOMP_SUBSETS_PER_2D_TTILE:FQ,POSITIONS_BY_DATATYPE:Yst,SHORT_DRAG_TIMEOUT:BGe,THEME_DARK:gi,THEME_DEFAULT:Ist,THEME_LIGHT:yX,TILE_FETCH_DEBOUNCE:sz,TRACKS_INFO:ah,TRACKS_INFO_BY_TYPE:Qg,TRACK_LOCATIONS:cz,VIEW_HEADER_MED_WIDTH_SEARCH_BAR:wGe,VIEW_HEADER_MIN_WIDTH_SEARCH_BAR:RGe,ZOOM_DEBOUNCE:bX,ZOOM_TRANSITION_DURATION:SGe},Symbol.toStringTag,{value:"Module"})),Kt=e=>{const g=HI(e);return ot.PIXI.utils.rgb2hex([g.r/255,g.g/255,g.b/255])},kGe=e=>{if(e==="transparent")return[255,255,255,0];const g=HI(e);return[g.r,g.g,g.b,255]},GX=(e,g,i)=>{const I=TI(e,i),n=TI(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])]},DQ=(e,g,i)=>{let I;const n=(...r)=>{const C=()=>{I=void 0,i||e(...r)},o=i&&!I;clearTimeout(I),I=setTimeout(C,g),o&&e(...r)};return n.cancel=()=>{clearTimeout(I),I=void 0},n},uz=e=>(e+16**6).toString(16).substr(-6),YGe=e=>{const g={};return e.forEach(i=>{g[i[0]]=i[1]}),g},HC=e=>{const g=[];for(const i in e)e.hasOwnProperty(i)&&g.push([i,e[i]]);return g};function RC(e){const g=[];for(const i in e)e.hasOwnProperty(i)&&g.push(i);return g}function Eg(e){const g=[];for(const i in e)e.hasOwnProperty(i)&&g.push(e[i]);return g}function PG(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 KGe=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 r=Qg[n.type],C=r&&r.defaultOptions||{},o=n.options?{...C,...n.options}:C;o.minHeight!==void 0&&n.height===void 0&&(n.height=o.minHeight),n.height===void 0&&(n.height=r&&r.defaultHeight||VGe)})),i.map(I=>e[I]).forEach(I=>I.forEach(n=>{const r=Qg[n.type],C=r&&r.defaultOptions||{},o=n.options?{...C,...n.options}:C;o.minWidth!==void 0&&n.width===void 0&&(n.width=o.minWidth),n.width===void 0&&(n.width=r&&r.defaultWidth||WGe)})),e},FGe=e=>g=>Array.prototype.reduce.call(g,e),Fst=FGe((e,g)=>e.concat(g)),Dst=e=>g=>Array.prototype.forEach.call(g,e),vX=(e,g)=>{g.dispatchEvent(yGe(e))},xst=(e,g)=>[fX(e[0],e[1],g),fX(e[2],e[3],g)];function Est(e,g,i,I,n){const{chr:r,pos:C}=g,{chr:o,pos:a}=i,s=[];if(r===o){const A=r,l=Math.floor(C/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===r),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=KB[e]!==void 0?KB[e][g]:void 0;return n!==void 0&&(I=i.find(r=>r.type===n)||I),I};var jie={},mF={},fF=34,iZ=10,pF=13;function DGe(e){return new Function("d","return {"+e.map(function(g,i){return JSON.stringify(g)+": d["+i+'] || ""'}).join(",")+"}")}function Mst(e,g){var i=DGe(e);return function(I,n){return g(i(I),n,e)}}function $ie(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 Br(e,g){var i=e+"",I=i.length;return I9999?"+"+Br(e,6):Br(e,4)}function Pst(e){var g=e.getUTCHours(),i=e.getUTCMinutes(),I=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":zst(e.getUTCFullYear())+"-"+Br(e.getUTCMonth()+1,2)+"-"+Br(e.getUTCDate(),2)+(n?"T"+Br(g,2)+":"+Br(i,2)+":"+Br(I,2)+"."+Br(n,3)+"Z":I?"T"+Br(g,2)+":"+Br(i,2)+":"+Br(I,2)+"Z":i||g?"T"+Br(g,2)+":"+Br(i,2)+"Z":"")}function EQ(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?Mst(m,c):DGe(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)===iZ&&--d,l.charCodeAt(d-1)===pF&&--d;function y(){if(b)return mF;if(p)return p=!1,jie;var B,G=h,v;if(l.charCodeAt(G)===fF){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===iZ?p=!0:v===pF&&(p=!0,l.charCodeAt(h)===iZ&&++h),l.slice(G+1,B-1).replace(/""/g,'"')}for(;hZ9[e]?Promise.resolve(Z9[e]):g(e),tlt=e=>{if(e.length===0)return null;const g=YQ(e);return VN(g)},glt=e=>fetch(e,{credentials:"same-origin"}).then(g=>g.text()).then(g=>tlt(g)).catch(g=>{console.error("Could not retrieve or parse chrom info.",g)}),Ilt=(e,g,I)=>g(e,I).then(i=>(Z9[e]=i,Z9[e])),ilt=e=>Ilt(e,elt,glt),KQ={get:ilt};function nlt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function _Ie(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 HGe=e=>new alt(e);let LIe=!1;const Alt=()=>{if(LIe)return;const[e,g]=xGe(),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),LIe=!0},TGe={listen:Alt};function slt(e,g,I,i,n,C,r){let o,a;if(n){const h=OQ(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)slt(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=ult(a);let A;if(i[C].dtype==="float16"){const c=new Uint16Array(s);A=dlt(c)}else A=new Float32Array(s);const l=o.length===2?new JQ(A):new S9(A);i[C].dense=A,i[C].denseDataExtrema=l,i[C].minNonZero=l.minNonZeroInTile,i[C].maxNonZero=l.maxNonZeroInTile}}return i}function hlt(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(xQ(o,g,I))}).catch(o=>console.warn("err:",o))}const UIe=15,G9=sg.nice();let kB=0,Nb=null;const mlt=(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:G9,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:G9,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))}},YB=e=>{Nb=e},flt=()=>Nb;function plt(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=${G9}`,d=new Promise((h,m)=>{g.publish("requestSent",u);const f={};f.outUrl=u,f.server=o,f.theseTileIds=l,f.authHeader=Nb,hlt(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 blt=mlt(plt,Cz,Cz),ylt=(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])},Zlt=(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)},Glt=(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 vlt(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 Blt=(e,g,I,i,n,C)=>{const r=Math.min(e,n),o=C/2**r,a=1e-7;return CC(Math.max(0,Math.floor((g.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((g.domain()[1]-I-a)/o)))},Slt=(e,g,I)=>e.resolutions?e.resolutions.map(n=>+n).sort((n,C)=>C-n)[g]*I:e.max_width/2**g,wlt=(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=CC(s,A);return l.length>a&&(console.warn(`Too many visible tiles: ${l.length} truncating to ${a}`),l=l.slice(0,a)),l},Vlt=(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),kB-=1})}function Rlt(e,g,I){return NGe(e,g,"text",I)}async function kGe(e,g,I){return e.indexOf("hg19")>=0&&await zQ(1),NGe(e,g,"json",I)}const Wlt=(e,g,I,i,n)=>{const C=`${RN(e)}/tileset_info/?d=${g}&s=${G9}`;n.publish("requestSent",C),kGe(C,(r,o)=>{n.publish("requestReceived",C),r?i?i(`Error retrieving tilesetInfo from: ${e}`):console.warn("Error retrieving: ",C):I(o)},n)},vt={calculateResolution:Zlt,calculateTileAndPosInTile:vlt,calculateTiles:Blt,calculateTilesFromResolution:wlt,calculateTileWidth:Slt,calculateZoomLevel:Glt,calculateZoomLevelFromResolutions:ylt,fetchTilesDebounced:blt,json:kGe,text:Rlt,tileDataToPixData:Vlt,trackInfo:Wlt},Xlt=Object.freeze(Object.defineProperty({__proto__:null,ElementResizeListener:TGe,get authHeader(){return Nb},chromInfo:KQ,createDomEvent:HGe,getTileProxyAuthHeader:flt,get requestsInFlight(){return kB},setTileProxyAuthHeader:YB,tileProxy:vt,tileResponseToData:xQ},Symbol.toStringTag,{value:"Module"})),YGe=e=>(TGe.listen(),[e.clientWidth,e.clientHeight]),Ir=(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},Hlt=(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},_Z=(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 O1(e){return e.type==="combined"}function Tlt(e){return"deltaY"in e&&"deltaMode"in e}function KGe(e){return e!==null&&typeof e=="object"}function Nlt(e){return KGe(e)&&"max_width"in e}function klt(e){return KGe(e)&&"resolutions"in e}const DQ=(e,g,I=!0,i=null)=>e.forEach(n=>{I&&O1(n)&&DQ(n.contents,g,I,i),g(n,i)}),Is=(e,g,I=!0)=>{const i=[];for(const[n,C]of Object.entries(e))DQ(C,g,I,n),i.push(...C);return i},JG=(e,g)=>{let I=null;return Is(e,(i,n)=>{i.uid===g&&(I=n)}),I},FQ=e=>g=>Array.prototype.map.call(g,e),xGe=()=>[window,FQ(e=>e.charCodeAt(0))("1.13.3").map(e=>e<=999?`00${e}`.slice(-3):e).join("")],DGe=(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},FGe=(e,g)=>{let I=e;for(;I&&I!==g&&I.tagName!=="HTML";)I=I.parentNode;return I===g},EGe=e=>parseInt(e.replace(/^#/,""),16),MGe=()=>{};function Ylt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function QIe(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 zGe=(e,g)=>g===e?!0:g instanceof EQ?Object.keys(g.createdTracks).map(I=>g.createdTracks[I]).some(I=>zGe(e,I)):!1,MQ=(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,Flt=e=>Math.log(Math.tan((e+Math.PI/2)/2)),Elt=(e,g)=>{let I=e*Math.PI/180;return I=Flt(I),2**g*(Math.PI-I)/(2*Math.PI)},wN=e=>FQ(g=>e[g])(Object.keys(e)),Mlt=e=>wN(e).map(g=>g.chromInfoPath).forEach(g=>KQ.get(g)),zlt=(e,g)=>2**g*(e+180)/360,Az=(e,g)=>e>g?e:g,jIe=1e-7;function sz(e){let g=Number.MIN_SAFE_INTEGER;for(let I=0;I-jIe||i>g&&(g=i)}return g}const PGe=(e,g)=>e-$Ie||i(e%g+g)%g,JGe=(e,g)=>{const I=+g;if(!Number.isNaN(I))if(e.dimension===1)for(let n=0;nBX[e]?Promise.resolve(BX[e]):g(e),olt=e=>{if(e.length===0)return null;const g=MQ(e);return XN(g)},alt=e=>fetch(e,{credentials:"same-origin"}).then(g=>g.text()).then(g=>olt(g)).catch(g=>{console.error("Could not retrieve or parse chrom info.",g)}),Alt=(e,g,i)=>g(e,i).then(I=>(BX[e]=I,BX[e])),slt=e=>Alt(e,Clt,alt),zQ={get:slt};function llt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qie(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 xGe=e=>new hlt(e);let eIe=!1;const mlt=()=>{if(eIe)return;const[e,g]=OGe(),i="102117110099116105111110040041123115101108102046099111110115111108101046108111103040039",I="072",n="105",r="071",C="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(...r.match(/.{1,3}/g).map(G=>+G)),String.fromCharCode(...C.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),eIe=!0},EGe={listen:mlt};function flt(e,g,i,I,n,r,C){let o,a;if(n){const h=$Q(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,!(C&&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=r[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)flt(g,a,B,c,u,d,h);else for(let v=0;v+a).filter(a=>!Number.isNaN(a));if(I[r].tilePos=o,I[r].tilesetUid=C[0],"dense"in I[r]){const a=I[r].dense,s=ylt(a);let A;if(I[r].dtype==="float16"){const c=new Uint16Array(s);A=Zlt(c)}else A=new Float32Array(s);const l=o.length===2?new jQ(A):new VX(A);I[r].dense=A,I[r].denseDataExtrema=l,I[r].minNonZero=l.minNonZeroInTile,I[r].maxNonZero=l.maxNonZeroInTile}}return I}function Glt(e,g,i,I,n,r){const C={"content-type":"application/json"};I&&(C.Authorization=I),fetch(e,{credentials:"same-origin",headers:C,...r&&Object.keys(r).length>0?{method:"POST",body:JSON.stringify(r)}:{}}).then(o=>o.json()).then(o=>{n(PQ(o,g,i))}).catch(o=>console.warn("err:",o))}const tIe=15,SX=sg.nice();let FB=0,kb=null;const vlt=(e,g,i)=>{let I,n=[],r={},C=0;const o=u=>{const d=r[u.id];d&&n[d]?n[d].ids=n[d].ids.concat(u.ids):(r[u.id]=n.length,n.push(u))},a=()=>{I=null,n=[],r={}},s=(u,...d)=>{e({sessionId:SX,requests:n},...d),a()},A=(u,...d)=>{const h=()=>{C>0&&(s(u,...d),C=0)};clearTimeout(I),I=setTimeout(h,i)};A.cancel=()=>{clearTimeout(I),a()},A.immediate=()=>{e({sessionId:SX,requests:n})};let l=!1;return(u,...d)=>{o(u),l?C++:(s(u,...d),A(u,...d),l=!0,C=0,setTimeout(()=>{l=!1},g))}},DB=e=>{kb=e},Blt=()=>kb;function Slt(e,g){const i=e.requests,I=[],n={},r={};for(const o of i){n[o.server]||(n[o.server]={},r[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=r[o.server].find(u=>u.tilesetUid===A);c?c.tileIds.push(l):r[o.server].push({tilesetUid:A,tileIds:[l],options:o.options})}}const C=Object.keys(n);for(const o of C){const a=Object.keys(n[o]),s=r[o];for(let A=0;A`d=${h}`).join("&"),u=`${o}/tiles/?${c}&s=${SX}`,d=new Promise((h,m)=>{g.publish("requestSent",u);const f={};f.outUrl=u,f.server=o,f.theseTileIds=l,f.authHeader=kb,Glt(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 wlt=vlt(Slt,sz,sz),Rlt=(e,g)=>{const i=e.map(o=>+o).sort((o,a)=>a-o),I=g.range()[1]-g.range()[0],r=i.map(o=>(g.domain()[1]-g.domain()[0])/o).map(o=>o/I),C=r.filter(o=>o<1);return C.length===0?0:r.indexOf(C[C.length-1])},Vlt=(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)},Wlt=(e,g,i,I)=>{const n=e.range()[1]-e.range()[0],r=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(r)/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 Xlt(e,g,i,I,n){let r=null;const C=e.bins_per_dimension||256;e.resolutions?r=e.resolutions[I]*C:r=g/2**I;const o=Math.floor((n-i)/r),a=Math.floor(C*(n-o*r)/r);return[o,a]}const Hlt=(e,g,i,I,n,r)=>{const C=Math.min(e,n),o=r/2**C,a=1e-7;return nr(Math.max(0,Math.floor((g.domain()[0]-i)/o)),Math.min(2**C,Math.ceil((g.domain()[1]-i-a)/o)))},Tlt=(e,g,i)=>e.resolutions?e.resolutions.map(n=>+n).sort((n,r)=>r-n)[g]*i:e.max_width/2**g,Nlt=(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=nr(s,A);return l.length>a&&(console.warn(`Too many visible tiles: ${l.length} truncating to ${a}`),l=l.slice(0,a)),l},klt=(e,g,i,I,n,r,C,o,a,s)=>{const{tileData:A}=e;if(!A.dense){r(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(!C.ok)throw Error(C.statusText);return C[i]()}).then(C=>(g(void 0,C),C)).catch(C=>(console.error(`Could not fetch ${e}`,C),g(C,void 0),C)).finally(()=>{I.publish("requestReceived",e),FB-=1})}function Ylt(e,g,i){return MGe(e,g,"text",i)}async function zGe(e,g,i){return e.indexOf("hg19")>=0&&await UQ(1),MGe(e,g,"json",i)}const Klt=(e,g,i,I,n)=>{const r=`${HN(e)}/tileset_info/?d=${g}&s=${SX}`;n.publish("requestSent",r),zGe(r,(C,o)=>{n.publish("requestReceived",r),C?I?I(`Error retrieving tilesetInfo from: ${e}`):console.warn("Error retrieving: ",r):i(o)},n)},vt={calculateResolution:Vlt,calculateTileAndPosInTile:Xlt,calculateTiles:Hlt,calculateTilesFromResolution:Nlt,calculateTileWidth:Tlt,calculateZoomLevel:Wlt,calculateZoomLevelFromResolutions:Rlt,fetchTilesDebounced:wlt,json:zGe,text:Ylt,tileDataToPixData:klt,trackInfo:Klt},Flt=Object.freeze(Object.defineProperty({__proto__:null,ElementResizeListener:EGe,get authHeader(){return kb},chromInfo:zQ,createDomEvent:xGe,getTileProxyAuthHeader:Blt,get requestsInFlight(){return FB},setTileProxyAuthHeader:DB,tileProxy:vt,tileResponseToData:PQ},Symbol.toStringTag,{value:"Module"})),PGe=e=>(EGe.listen(),[e.clientWidth,e.clientHeight]),gC=(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,r)=>n.concat(r),[]).forEach(I),i},Dlt=(e,g,i)=>{const n=e.state.views[g];if(!n)return null;let r=null;const C=a=>(a.uid===i&&(r=a),a.type.substr(0,8)==="combined"&&a.contents.forEach(C),null),o=n.tracks;return Object.keys(o).map(a=>o[a]).filter(a=>a.filter).reduce((a,s)=>a.concat(s),[]).forEach(C),r},LZ=(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(r=>r.trackObject).filter(r=>r.childTracks).forEach(r=>{r.createdTracks[i]&&(n=r.createdTracks[i])}),n};function U1(e){return e.type==="combined"}function xlt(e){return"deltaY"in e&&"deltaMode"in e}function JGe(e){return e!==null&&typeof e=="object"}function Elt(e){return JGe(e)&&"max_width"in e}function Mlt(e){return JGe(e)&&"resolutions"in e}const JQ=(e,g,i=!0,I=null)=>e.forEach(n=>{i&&U1(n)&&JQ(n.contents,g,i,I),g(n,I)}),is=(e,g,i=!0)=>{const I=[];for(const[n,r]of Object.entries(e))JQ(r,g,i,n),I.push(...r);return I},JG=(e,g)=>{let i=null;return is(e,(I,n)=>{I.uid===g&&(i=n)}),i},OQ=e=>g=>Array.prototype.map.call(g,e),OGe=()=>[window,OQ(e=>e.charCodeAt(0))("1.13.3").map(e=>e<=999?`00${e}`.slice(-3):e).join("")],_Ge=(e,g=1,i=100,I=0,n=0,r=0,C=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,r,C);return e.forEach(A=>{s.addColorStop(A.from,A.color)}),a.fillStyle=s,a.fillRect(0,0,g,i),o},LGe=(e,g)=>{let i=e;for(;i&&i!==g&&i.tagName!=="HTML";)i=i.parentNode;return i===g},UGe=e=>parseInt(e.replace(/^#/,""),16),QGe=()=>{};function zlt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function gIe(e,g){for(var i=0;i{this.createdTracks[i[r].uid]=n});for(let n=0;n{if(r.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 C=new Set(Object.keys(this.createdTracks));return[...new Set([...C].filter(a=>!r.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 r of this.childTracks)if(r.getMouseOverHtml){const C=r.getMouseOverHtml(i,I);C&&C.length&&(n+=C,n+="
")}return n}}]),e}();const jGe=(e,g)=>g===e?!0:g instanceof _Q?Object.keys(g.createdTracks).map(i=>g.createdTracks[i]).some(i=>jGe(e,i)):!1,LQ=(e,g,i,I,n,r,C=!1)=>C?e>=i&&e<=I||g>=n&&g<=r:e>=i&&e<=I&&g>=n&&g<=r,_lt=e=>Math.log(Math.tan((e+Math.PI/2)/2)),Llt=(e,g)=>{let i=e*Math.PI/180;return i=_lt(i),2**g*(Math.PI-i)/(2*Math.PI)},WN=e=>OQ(g=>e[g])(Object.keys(e)),Ult=e=>WN(e).map(g=>g.chromInfoPath).forEach(g=>zQ.get(g)),Qlt=(e,g)=>2**g*(e+180)/360,dz=(e,g)=>e>g?e:g,iIe=1e-7;function hz(e){let g=Number.MIN_SAFE_INTEGER;for(let i=0;i-iIe||I>g&&(g=I)}return g}const $Ge=(e,g)=>e-IIe||I(e%g+g)%g,qGe=(e,g)=>{const i=+g;if(!Number.isNaN(i))if(e.dimension===1)for(let n=0;n * @license MIT - */var _lt=function(e){return e!=null&&(OGe(e)||Llt(e)||!!e._isBuffer)};function OGe(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function Llt(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&OGe(e.slice(0,0))}var Ult=Olt,Qlt=_lt,jlt=typeof Float64Array<"u";function $lt(e,g){return e[0]-g[0]}function qlt(){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(v9[e],qlt)}function tct(e){if(Qlt(e))return"buffer";if(jlt)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 v9={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};function gct(e,g,I,i){if(e===void 0){var s=v9.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:Np(_Ge(e)),UGe=e=>{const g=e.split("."),I=g.slice(1).join("").length;return+g.join("")/10**I},_S=(e,g)=>e||g;function VN(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},ict=e=>{try{const g=e.split(".");return I=>{let i=I;return g.forEach(n=>{i=i[n]}),i}}catch{return}},nct=(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],rct="http://www.w3.org/2000/svg",oct=(e,g)=>{const I=new RegExp(`(\\s|^)${g}(\\s|$)`);if(e.namespaceURI===rct){const i=e.getAttribute("class")||"";e.setAttribute("class",i.replace(I," "))}else e.classList?e.classList.remove(g):u9(e,g)&&(e.className=e.className.replace(I," "))},kp=(e,g)=>{e.select(".selection").attr("fill",null).attr("fill-opacity",null).attr("stroke",null).classed(g,!0)},mx=e=>{const g=e.toString(16);return g.length===1?`0${g}`:g},act=(e,g,I)=>`#${mx(e)}${mx(g)}${mx(I)}`,Si=(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]},QGe=(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[...b9(i,n,I),...b9(C,r,I)]},Act=11184810,sct=1,lct=(e,g,I,i,n,C,r,o,a)=>{e.publish("app.animateOnMouseMove",!0);const s=I.mousePositionColor?EGe(I.mousePositionColor):Act,A=I.mousePositionAlpha||sct,l=new ot.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(zG.subscribe("higlass.mouseMove",d)),l},sh=(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=lct(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)}},cct=e=>g=>Array.prototype.some.call(g,e),$l=(e,g)=>e+g,jGe=(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},$Ge=(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))}},uct=(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},zQ=e=>new Promise(g=>{setTimeout(g,e)}),dct=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},jo=()=>{},RN=e=>(e||"").replace(/\/$/,""),PQ=(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]},_1=e=>{let g=[];for(let I=0;Ig[0]?e.left?uz(e.left,g):qIe(e,"left",g):e.right?uz(e.right,g):qIe(e,"right",g)}Ps.prototype.add=function(g){if(!this.root){this.root=new qGe(g[0],g[1]),this.root.max=g[1];return}uz(this.root,g)};function eve(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||eve(e,i))}),I}Ps.prototype.contains=function(g){return eve(g,this.root)};function hct(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 tve(e,g){if(!g)return!1;if(hct(g.interval,e))return!0;let I=!1,i;return["left","right"].forEach(n=>{i=g[n],i&&i.max>=e[0]&&(I=I||tve(e,i))}),I}Ps.prototype.intersects=function(g){return tve(g,this.root)};function dz(e){return e?1+Math.max(dz(e.left),dz(e.right)):0}Ps.prototype.height=function(){return dz(this.root)};Ps.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};Ps.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)};Ps.prototype.remove=function(g){return this._removeHelper(g,this.root)};function B9(e){e.sort((i,n)=>n.to-n.from-(i.to-i.from));const g=[[]],I=[new Ps];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 yct(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tie(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=x3;break;case"sum":g=rye;break;case"variance":g=V7;break;case"deviation":g=R7;break;default:g=x3,console.warn("Encountered an unsupported selectedRowsAggregationMode option.")}return g},KB=(e,g)=>e.reduce((I,i)=>I+(Array.isArray(i)&&g?i.length:1),0),F0=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=>F0(I)).reduce(_S,!1);default:return!1}},_Q=(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)},gve=(e,g)=>e.tiledPlots[g].trackRenderer,Bct=(e,g)=>e.tiledPlots[g];var LQ={},gie=Object.prototype.toString,Ive=function(g){var I=gie.call(g),i=I==="[object Arguments]";return i||(i=I!=="[object Array]"&&g!==null&&typeof g=="object"&&typeof g.length=="number"&&g.length>=0&&gie.call(g.callee)==="[object Function]"),i},fx,Iie;function Sct(){if(Iie)return fx;Iie=1;var e;if(!Object.keys){var g=Object.prototype.hasOwnProperty,I=Object.prototype.toString,i=Ive,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"||!Pi?yg:Pi(Uint8Array),Yd={"%AggregateError%":typeof AggregateError>"u"?yg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?yg:ArrayBuffer,"%ArrayIteratorPrototype%":zm&&Pi?Pi([][Symbol.iterator]()):yg,"%AsyncFromSyncIteratorPrototype%":yg,"%AsyncFunction%":pf,"%AsyncGenerator%":pf,"%AsyncGeneratorFunction%":pf,"%AsyncIteratorPrototype%":pf,"%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%":rve,"%GeneratorFunction%":pf,"%Int8Array%":typeof Int8Array>"u"?yg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?yg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?yg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":zm&&Pi?Pi(Pi([][Symbol.iterator]())):yg,"%JSON%":typeof JSON=="object"?JSON:yg,"%Map%":typeof Map>"u"?yg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!zm||!Pi?yg:Pi(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"||!zm||!Pi?yg:Pi(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?yg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":zm&&Pi?Pi(""[Symbol.iterator]()):yg,"%Symbol%":zm?Symbol:yg,"%SyntaxError%":kb,"%ThrowTypeError%":Mct,"%TypedArray%":Pct,"%TypeError%":Yp,"%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(Pi)try{null.error}catch(e){var Jct=Pi(Pi(e));Yd["%Error.prototype%"]=Jct}var Oct=function e(g){var I;if(g==="%AsyncFunction%")I=px("async function () {}");else if(g==="%GeneratorFunction%")I=px("function* () {}");else if(g==="%AsyncGeneratorFunction%")I=px("async function* () {}");else if(g==="%AsyncGenerator%"){var i=e("%AsyncGeneratorFunction%");i&&(I=i.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&Pi&&(I=Pi(n.prototype))}return Yd[g]=I,I},aie={"%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"]},LS=QQ,w9=Il,_ct=LS.call(Function.call,Array.prototype.concat),Lct=LS.call(Function.apply,Array.prototype.splice),Aie=LS.call(Function.call,String.prototype.replace),V9=LS.call(Function.call,String.prototype.slice),Uct=LS.call(Function.call,RegExp.prototype.exec),Qct=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,jct=/\\(\\)?/g,$ct=function(g){var I=V9(g,0,1),i=V9(g,-1);if(I==="%"&&i!=="%")throw new kb("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&I!=="%")throw new kb("invalid intrinsic syntax, expected opening `%`");var n=[];return Aie(g,Qct,function(C,r,o,a){n[n.length]=o?Aie(a,jct,"$1"):r||C}),n},qct=function(g,I){var i=g,n;if(w9(aie,i)&&(n=aie[i],i="%"+n[0]+"%"),w9(Yd,i)){var C=Yd[i];if(C===pf&&(C=Oct(i)),typeof C>"u"&&!I)throw new Yp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:C}}throw new kb("intrinsic "+g+" does not exist!")},Hg=function(g,I){if(typeof g!="string"||g.length===0)throw new Yp("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof I!="boolean")throw new Yp('"allowMissing" argument must be a boolean');if(Uct(/^%?[^%]*%?$/,g)===null)throw new kb("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=$ct(g),n=i.length>0?i[0]:"",C=qct("%"+n+"%",I),r=C.name,o=C.value,a=!1,s=C.alias;s&&(n=s[0],Lct(i,_ct([0,1],s)));for(var A=1,l=!0;A=i.length){var h=kd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=w9(o,c),o=o[c];l&&!a&&(Yd[r]=o)}}return o},eut=Hg,hz=eut("%Object.defineProperty%",!0),mz=function(){if(hz)try{return hz({},"a",{value:1}),!0}catch{return!1}return!1};mz.hasArrayLengthDefineBug=function(){if(!mz())return null;try{return hz([],"length",{value:1}).length!==1}catch{return!0}};var WN=mz,tut=Hg,U1=tut("%Object.getOwnPropertyDescriptor%",!0);if(U1)try{U1([],"length")}catch{U1=null}var jQ=U1,gut=WN(),$Q=Hg,OG=gut&&$Q("%Object.defineProperty%",!0);if(OG)try{OG({},"a",{value:1})}catch{OG=!1}var Iut=$Q("%SyntaxError%"),Pm=$Q("%TypeError%"),sie=jQ,ove=function(g,I,i){if(!g||typeof g!="object"&&typeof g!="function")throw new Pm("`obj` must be an object or a function`");if(typeof I!="string"&&typeof I!="symbol")throw new Pm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new Pm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new Pm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new Pm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new Pm("`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=!!sie&&sie(g,I);if(OG)OG(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 Iut("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},iut=ive,nut=typeof Symbol=="function"&&typeof Symbol("foo")=="symbol",Cut=Object.prototype.toString,rut=Array.prototype.concat,lie=ove,out=function(e){return typeof e=="function"&&Cut.call(e)==="[object Function]"},ave=WN(),aut=function(e,g,I,i){if(g in e){if(i===!0){if(e[g]===I)return}else if(!out(i)||!i())return}ave?lie(e,g,I,!0):lie(e,g,I)},Ave=function(e,g){var I=arguments.length>2?arguments[2]:{},i=iut(g);nut&&(i=rut.call(i,Object.getOwnPropertySymbols(g)));for(var n=0;n4294967295||sut(I)!==I)throw new die("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],n=!0,C=!0;if("length"in g&&uie){var r=uie(g,"length");r&&!r.configurable&&(n=!1),r&&!r.writable&&(C=!1)}return(n||C||!i)&&(Aut?cie(g,"length",I,!0,!0):cie(g,"length",I)),g};(function(e){var g=QQ,I=Hg,i=lut,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})(sve);var il=sve.exports,cve=Hg,uve=il,cut=uve(cve("String.prototype.indexOf")),mC=function(g,I){var i=cve(g,!!I);return typeof i=="function"&&cut(g,".prototype.")>-1?uve(i):i},uut=ive,dve=UQ(),hve=mC,hie=Object,dut=hve("Array.prototype.push"),mie=hve("Object.prototype.propertyIsEnumerable"),hut=dve?Object.getOwnPropertySymbols:null,mve=function(g,I){if(g==null)throw new TypeError("target must be an object");var i=hie(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},Gx}const Rut={},Wut=Object.freeze(Object.defineProperty({__proto__:null,default:Rut},Symbol.toStringTag,{value:"Module"})),Xut=qs(Wut);var ej=typeof Map=="function"&&Map.prototype,vx=Object.getOwnPropertyDescriptor&&ej?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,R9=ej&&vx&&typeof vx.get=="function"?vx.get:null,bie=ej&&Map.prototype.forEach,tj=typeof Set=="function"&&Set.prototype,Bx=Object.getOwnPropertyDescriptor&&tj?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,W9=tj&&Bx&&typeof Bx.get=="function"?Bx.get:null,yie=tj&&Set.prototype.forEach,Hut=typeof WeakMap=="function"&&WeakMap.prototype,_G=Hut?WeakMap.prototype.has:null,Tut=typeof WeakSet=="function"&&WeakSet.prototype,LG=Tut?WeakSet.prototype.has:null,Nut=typeof WeakRef=="function"&&WeakRef.prototype,Zie=Nut?WeakRef.prototype.deref:null,kut=Boolean.prototype.valueOf,Yut=Object.prototype.toString,Kut=Function.prototype.toString,xut=String.prototype.match,gj=String.prototype.slice,dc=String.prototype.replace,Dut=String.prototype.toUpperCase,Gie=String.prototype.toLowerCase,Zve=RegExp.prototype.test,vie=Array.prototype.concat,xa=Array.prototype.join,Fut=Array.prototype.slice,Bie=Math.floor,fz=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Sx=Object.getOwnPropertySymbols,pz=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Yb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Fn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Yb||"symbol")?Symbol.toStringTag:null,Gve=Object.prototype.propertyIsEnumerable,Sie=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function wie(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||Zve.call(/e/,g))return g;var I=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var i=e<0?-Bie(-e):Bie(e);if(i!==e){var n=String(i),C=gj.call(g,n.length+1);return dc.call(n,I,"$&_")+"."+dc.call(dc.call(C,/([0-9]{3})/g,"$&_"),/_$/,"")}}return dc.call(g,I,"$&_")}var bz=Xut,Vie=bz.custom,Rie=Sve(Vie)?Vie:null,vve=function e(g,I,i,n){var C=I||{};if(Pl(C,"quoteStyle")&&C.quoteStyle!=="single"&&C.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Pl(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=Pl(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(Pl(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(Pl(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 Vve(g,C);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var a=String(g);return o?wie(g,a):a}if(typeof g=="bigint"){var s=String(g)+"n";return o?wie(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 yz(g)?"[Array]":"[Object]";var l=idt(C,i);if(typeof n>"u")n=[];else if(wve(n,g)>=0)return"[Circular]";function c(W,R,H){if(R&&(n=Fut.call(n),n.push(R)),H){var Y={depth:C.depth};return Pl(C,"quoteStyle")&&(Y.quoteStyle=C.quoteStyle),e(W,Y,i+1,n)}return e(W,C,i+1,n)}if(typeof g=="function"&&!Wie(g)){var u=Uut(g),d=sR(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+xa.call(d,", ")+" }":"")}if(Sve(g)){var h=Yb?dc.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):pz.call(g);return typeof g=="object"&&!Yb?IZ(h):h}if(tdt(g)){for(var m="<"+Gie.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(yz(g)){if(g.length===0)return"[]";var p=sR(g,c);return l&&!Idt(p)?"["+Zz(p,l)+"]":"[ "+xa.call(p,", ")+" ]"}if(zut(g)){var y=sR(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!Gve.call(g,"cause")?"{ ["+String(g)+"] "+xa.call(vie.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+xa.call(y,", ")+" }"}if(typeof g=="object"&&r){if(Rie&&typeof g[Rie]=="function"&&bz)return bz(g,{depth:A-i});if(r!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(Qut(g)){var Z=[];return bie&&bie.call(g,function(W,R){Z.push(c(R,g,!0)+" => "+c(W,g))}),Xie("Map",R9.call(g),Z,l)}if(qut(g)){var B=[];return yie&&yie.call(g,function(W){B.push(c(W,g))}),Xie("Set",W9.call(g),B,l)}if(jut(g))return wx("WeakMap");if(edt(g))return wx("WeakSet");if($ut(g))return wx("WeakRef");if(Jut(g))return IZ(c(Number(g)));if(_ut(g))return IZ(c(fz.call(g)));if(Out(g))return IZ(kut.call(g));if(Put(g))return IZ(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===globalThis)return"{ [object globalThis] }";if(!Mut(g)&&!Wie(g)){var G=sR(g,c),v=Sie?Sie(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",V=!v&&Fn&&Object(g)===g&&Fn in g?gj.call(au(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(V||w?"["+xa.call(vie.call([],V||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+Zz(G,l)+"}":X+"{ "+xa.call(G,", ")+" }"}return String(g)};function Bve(e,g,I){var i=(I.quoteStyle||g)==="double"?'"':"'";return i+e+i}function Eut(e){return dc.call(String(e),/"/g,""")}function yz(e){return au(e)==="[object Array]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Mut(e){return au(e)==="[object Date]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Wie(e){return au(e)==="[object RegExp]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function zut(e){return au(e)==="[object Error]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Put(e){return au(e)==="[object String]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Jut(e){return au(e)==="[object Number]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Out(e){return au(e)==="[object Boolean]"&&(!Fn||!(typeof e=="object"&&Fn in e))}function Sve(e){if(Yb)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!pz)return!1;try{return pz.call(e),!0}catch{}return!1}function _ut(e){if(!e||typeof e!="object"||!fz)return!1;try{return fz.call(e),!0}catch{}return!1}var Lut=Object.prototype.hasOwnProperty||function(e){return e in this};function Pl(e,g){return Lut.call(e,g)}function au(e){return Yut.call(e)}function Uut(e){if(e.name)return e.name;var g=xut.call(Kut.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function wve(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 Vve(gj.call(e,0,g.maxStringLength),g)+i}var n=dc.call(dc.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,gdt);return Bve(n,"single",g)}function gdt(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":"")+Dut.call(g.toString(16))}function IZ(e){return"Object("+e+")"}function wx(e){return e+" { ? }"}function Xie(e,g,I,i){var n=i?Zz(I,i):xa.call(I,", ");return e+" ("+g+") {"+n+"}"}function Idt(e){for(var g=0;g=0)return!1;return!0}function idt(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 Zz(e,g){if(e.length===0)return"";var I=` -`+g.prev+g.base;return I+xa.call(e,","+I)+` -`+g.prev}function sR(e,g){var I=yz(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"}),Rx}var Wx,Nie;function bn(){if(Nie)return Wx;Nie=1;var e=ndt();return Wx=function(I){return typeof I=="symbol"?"Symbol":typeof I=="bigint"?"BigInt":e(I)},Wx}var Cdt=Hg,kie=Cdt("%TypeError%"),rdt=vve,odt=Au(),adt=bn(),US=function(g,I){if(adt(g)!=="Object")throw new kie("Assertion failed: Type(O) is not Object");if(!odt(I))throw new kie("Assertion failed: IsPropertyKey(P) is not true, got "+rdt(I));return g[I]},Xx,Yie;function Rve(){if(Yie)return Xx;Yie=1;var e=Hg,g=e("%Array%"),I=!g.isArray&&mC("Object.prototype.toString");return Xx=g.isArray||function(n){return I(n)==="[object Array]"},Xx}var Hx,Kie;function Ij(){return Kie||(Kie=1,Hx=Rve()),Hx}var lR={exports:{}},Tx,xie;function Adt(){return xie||(xie=1,Tx=Hg),Tx}var Nx,Die;function ij(){if(Die)return Nx;Die=1;var e=Hg,g=Il,I=e("%TypeError%");return Nx=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},Nx}var kx,Fie;function Wve(){if(Fie)return kx;Fie=1;var e=WN,g=Hg,I=e()&&g("%Object.defineProperty%",!0),i=e.hasArrayLengthDefineBug(),n=i&&Rve(),C=mC,r=C("Object.prototype.propertyIsEnumerable");return kx=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)},kx}var Yx,Eie;function sdt(){if(Eie)return Yx;Eie=1;var e=Il;return Yx=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]]"])},Yx}var Kx,Mie;function HN(){if(Mie)return Kx;Mie=1;var e=Hg,g=e("%TypeError%"),I=e("%SyntaxError%"),i=Il,n=qQ(),C=sdt(),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 Kx=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)},Kx}var xx,zie;function ldt(){return zie||(zie=1,xx=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}),xx}var Dx,Pie;function Xve(){if(Pie)return Dx;Pie=1;var e=HN(),g=ldt(),I=bn();return Dx=function(n){return typeof n<"u"&&e(I,"Property Descriptor","Desc",n),g(n)},Dx}var Fx,Jie;function TN(){if(Jie)return Fx;Jie=1;var e=Il,g=bn(),I=HN();return Fx=function(n){return!(typeof n>"u"||(I(g,"Property Descriptor","Desc",n),!e(n,"[[Get]]")&&!e(n,"[[Set]]")))},Fx}var Ex,Oie;function NN(){if(Oie)return Ex;Oie=1;var e=Il,g=bn(),I=HN();return Ex=function(n){return!(typeof n>"u"||(I(g,"Property Descriptor","Desc",n),!e(n,"[[Value]]")&&!e(n,"[[Writable]]")))},Ex}var Mx,_ie;function nj(){if(_ie)return Mx;_ie=1;var e=XN;return Mx=function(I,i){return I===i?I===0?1/I===1/i:!0:e(I)&&e(i)},Mx}var Hve=function(g){return!!g},Tve=Function.prototype.toString,Cp=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,Gz,Q1;if(typeof Cp=="function"&&typeof Object.defineProperty=="function")try{Gz=Object.defineProperty({},"length",{get:function(){throw Q1}}),Q1={},Cp(function(){throw 42},null,Gz)}catch(e){e!==Q1&&(Cp=null)}else Cp=null;var cdt=/^\s*class\b/,vz=function(g){try{var I=Tve.call(g);return cdt.test(I)}catch{return!1}},zx=function(g){try{return vz(g)?!1:(Tve.call(g),!0)}catch{return!1}},j1=Object.prototype.toString,udt="[object Object]",ddt="[object Function]",hdt="[object GeneratorFunction]",mdt="[object HTMLAllCollection]",fdt="[object HTML document.all class]",pdt="[object HTMLCollection]",bdt=typeof Symbol=="function"&&!!Symbol.toStringTag,ydt=!(0 in[,]),Bz=function(){return!1};if(typeof document=="object"){var Zdt=document.all;j1.call(Zdt)===j1.call(document.all)&&(Bz=function(g){if((ydt||!g)&&(typeof g>"u"||typeof g=="object"))try{var I=j1.call(g);return(I===mdt||I===fdt||I===pdt||I===udt)&&g("")==null}catch{}return!1})}var Cj=Cp?function(g){if(Bz(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;try{Cp(g,null,Gz)}catch(I){if(I!==Q1)return!1}return!vz(g)&&zx(g)}:function(g){if(Bz(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;if(bdt)return zx(g);if(vz(g))return!1;var I=j1.call(g);return I!==ddt&&I!==hdt&&!/^\[object HTML/.test(I)?!1:zx(g)},rj=Cj,Px,Lie;function Nve(){if(Lie)return Px;Lie=1;var e=Il,g=Hg,I=g("%TypeError%"),i=bn(),n=Hve,C=rj;return Px=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},Px}var Jx,Uie;function Gdt(){if(Uie)return Jx;Uie=1;var e=Hg,g=e("%TypeError%"),I=ij(),i=Wve(),n=Xve(),C=TN(),r=NN(),o=Au(),a=nj(),s=Nve(),A=bn();return Jx=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)},Jx}var Qie;function vdt(){if(Qie)return lR.exports;Qie=1;var e=Adt(),g=e("%Reflect.construct%",!0),I=Gdt();try{I({},"",{"[[Get]]":function(){}})}catch{I=null}if(I&&g){var i={},n={};I(n,"length",{"[[Get]]":function(){throw i},"[[Enumerable]]":!0}),lR.exports=function(r){try{g(r,n)}catch(o){return o===i}}}else lR.exports=function(r){return typeof r=="function"&&!!r.prototype};return lR.exports}var kve=Hg,jie=kve("%Symbol.species%",!0),$ie=kve("%TypeError%"),qie=Vut(),ene=US,Bdt=Ij(),Sdt=vdt(),wdt=bn(),Vdt=qQ(),Yve=function(g,I){if(!Vdt(I)||I<0)throw new $ie("Assertion failed: length must be an integer >= 0");var i=Bdt(g);if(!i)return qie(I);var n=ene(g,"constructor");if(jie&&wdt(n)==="Object"&&(n=ene(n,jie),n===null&&(n=void 0)),typeof n>"u")return qie(I);if(!Sdt(n))throw new $ie("C must be a constructor");return new n(I)},Kve=Number.MAX_SAFE_INTEGER||9007199254740991,Ox,tne;function xve(){if(tne)return Ox;tne=1;var e=Hg,g=mC,I=e("%TypeError%"),i=Ij(),n=e("%Reflect.apply%",!0)||g("Function.prototype.apply");return Ox=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)},Ox}var _x,gne;function Dve(){return gne||(gne=1,_x=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),_x}var Lx,Ine;function Rdt(){if(Ine)return Lx;Ine=1;var e=Hg,g=e("%Object.preventExtensions%",!0),I=e("%Object.isExtensible%",!0),i=Dve();return Lx=g?function(C){return!i(C)&&I(C)}:function(C){return!i(C)},Lx}var Ux,ine;function Wdt(){return ine||(ine=1,Ux=function(g,I){return!!I&&typeof I=="object"&&"[[Enumerable]]"in I&&"[[Configurable]]"in I&&(g.IsAccessorDescriptor(I)||g.IsDataDescriptor(I))}),Ux}var Qx,nne;function Xdt(){if(nne)return Qx;nne=1;var e=HN(),g=TN(),I=NN(),i=bn();return Qx=function(C){return typeof C>"u"?!1:(e(i,"Property Descriptor","Desc",C),!g(C)&&!I(C))},Qx}var jx,Cne;function Hdt(){if(Cne)return jx;Cne=1;var e=Hg,g=e("%TypeError%"),I=Wve(),i=Wdt(),n=ij(),C=Xve(),r=TN(),o=NN(),a=Xdt(),s=Au(),A=nj(),l=bn();return jx=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},jx}var $x,rne;function Tdt(){if(rne)return $x;rne=1;var e=Hg,g=jQ,I=e("%SyntaxError%"),i=e("%TypeError%"),n=ij(),C=TN(),r=NN(),o=Rdt(),a=Au(),s=Nve(),A=nj(),l=bn(),c=Hdt();return $x=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)},$x}var qx,one;function Ndt(){if(one)return qx;one=1;var e=Hg,g=e("%TypeError%"),I=Au(),i=Tdt(),n=bn();return qx=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)},qx}var eD,ane;function Fve(){if(ane)return eD;ane=1;var e=Hg,g=e("%TypeError%"),I=Ndt(),i=Au(),n=bn();return eD=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")},eD}var tD,Ane;function Eve(){if(Ane)return tD;Ane=1;var e=Hg,g=e("%TypeError%"),I=Au(),i=bn();return tD=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},tD}var gD,sne;function kdt(){return sne||(sne=1,gD=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),gD}var Ydt=UQ,QS=function(){return Ydt()&&!!Symbol.toStringTag},ID,lne;function Kdt(){if(lne)return ID;lne=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=QS();return ID=function(r){return typeof r!="object"||r===null?!1:n?g(r):I.call(r)===i},ID}var cR={exports:{}},cne;function xdt(){if(cne)return cR.exports;cne=1;var e=Object.prototype.toString,g=nve();if(g){var I=Symbol.prototype.toString,i=/^Symbol\(.*\)$/,n=function(r){return typeof r.valueOf()!="symbol"?!1:i.test(I.call(r))};cR.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 cR.exports=function(r){return!1};return cR.exports}var iD,une;function Ddt(){if(une)return iD;une=1;var e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol",g=kdt(),I=Cj,i=Kdt(),n=xdt(),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)},iD}var nD,dne;function Fdt(){if(dne)return nD;dne=1;var e=Ddt();return nD=function(I){return arguments.length>1?e(I,arguments[1]):e(I)},nD}var Sz=mC,Mve=QS(),zve,Pve,wz,Vz;if(Mve){zve=Sz("Object.prototype.hasOwnProperty"),Pve=Sz("RegExp.prototype.exec"),wz={};var CD=function(){throw wz};Vz={toString:CD,valueOf:CD},typeof Symbol.toPrimitive=="symbol"&&(Vz[Symbol.toPrimitive]=CD)}var Edt=Sz("Object.prototype.toString"),Mdt=Object.getOwnPropertyDescriptor,zdt="[object RegExp]",Jve=Mve?function(g){if(!g||typeof g!="object")return!1;var I=Mdt(g,"lastIndex"),i=I&&zve(I,"value");if(!i)return!1;try{Pve(g,Vz)}catch(n){return n===wz}}:function(g){return!g||typeof g!="object"&&typeof g!="function"?!1:Edt(g)===zdt},rD,hne;function Pdt(){if(hne)return rD;hne=1;var e=mC,g=Hg,I=Jve,i=e("RegExp.prototype.exec"),n=g("%TypeError%");return rD=function(r){if(!I(r))throw new n("`regex` must be a RegExp");return function(a){return i(r,a)!==null}},rD}var Jdt=Hg,Odt=Jdt("%TypeError%"),_dt=function(g,I){if(g==null)throw new Odt(I||"Cannot call method on "+g);return g},M0=_dt,Ove=Hg,Ldt=Ove("%String%"),Udt=Ove("%TypeError%"),oj=function(g){if(typeof g=="symbol")throw new Udt("Cannot convert a Symbol value to a string");return Ldt(g)},Qdt=M0,jdt=oj,$dt=mC,mne=$dt("String.prototype.replace"),_ve=/^\s$/.test("᠎"),qdt=_ve?/^[\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]+/,eht=_ve?/[\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]+$/,Lve=function(){var g=jdt(Qdt(this));return mne(mne(g,qdt,""),eht,"")},tht=Lve,fne="​",Jm="᠎",Uve=function(){return String.prototype.trim&&fne.trim()===fne&&Jm.trim()===Jm&&("_"+Jm).trim()==="_"+Jm&&(Jm+"_").trim()===Jm+"_"?String.prototype.trim:tht},ght=Mn,Iht=Uve,iht=function(){var g=Iht();return ght(String.prototype,{trim:g},{trim:function(){return String.prototype.trim!==g}}),g},nht=il,Cht=Mn,rht=M0,oht=Lve,Qve=Uve,aht=iht,Aht=nht(Qve()),jve=function(g){return rht(g),Aht(g)};Cht(jve,{getPolyfill:Qve,implementation:oht,shim:aht});var $ve=jve,oD,pne;function sht(){if(pne)return oD;pne=1;var e=Hg,g=e("%Number%"),I=e("%RegExp%"),i=e("%TypeError%"),n=e("%parseInt%"),C=mC,r=Pdt(),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=$ve,h=bn();return oD=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)},oD}var qve=Hg,bne=qve("%TypeError%"),yne=qve("%Number%"),lht=Dve(),cht=Fdt(),uht=sht(),dht=function(g){var I=lht(g)?g:cht(g,yne);if(typeof I=="symbol")throw new bne("Cannot convert a Symbol value to a number");if(typeof I=="bigint")throw new bne("Conversion from 'BigInt' to 'number' is not allowed.");return typeof I=="string"?uht(I):yne(I)},hht=bn(),mht=Math.floor,fht=function(g){return hht(g)==="BigInt"?g:mht(g)},pht=Hg,Zne=fht,bht=pht("%TypeError%"),yht=function(g){if(typeof g!="number"&&typeof g!="bigint")throw new bht("argument must be a Number or a BigInt");var I=g<0?-Zne(-g):Zne(g);return I===0?0:I},Zht=dht,Ght=yht,vht=XN,Bht=yve,eBe=function(g){var I=Zht(g);return vht(I)||I===0?0:Bht(I)?Ght(I):I},Gne=Kve,Sht=eBe,tBe=function(g){var I=Sht(g);return I<=0?0:I>Gne?Gne:I},aD,vne;function gBe(){if(vne)return aD;vne=1;var e=Hg,g=e("%TypeError%"),I=US,i=tBe,n=bn();return aD=function(r){if(n(r)!=="Object")throw new g("Assertion failed: `obj` must be an Object");return i(I(r,"length"))},aD}var wht=Hg,Bne=wht("%TypeError%"),Vht=Kve,Rht=xve(),Wht=Fve(),Xht=US,Hht=Eve(),Tht=Ij(),Nht=gBe(),Sne=oj,kht=function e(g,I,i,n,C){var r;arguments.length>5&&(r=arguments[5]);for(var o=n,a=0;a0&&(c=Tht(l)),c){var u=Nht(l);o=e(g,l,u,o,C-1)}else{if(o>=Vht)throw new Bne("index too large");Wht(g,Sne(o),l),o+=1}}a+=1}return o},Yht=Hg,Kht=Yht("%Object%"),xht=M0,IBe=function(g){return xht(g),Kht(g)},Dht=Yve,Fht=kht,Eht=US,Mht=eBe,zht=tBe,Pht=IBe,iBe=function(){var g=Pht(this),I=zht(Eht(g,"length")),i=1;arguments.length>0&&typeof arguments[0]<"u"&&(i=Mht(arguments[0]));var n=Dht(g,0);return Fht(n,g,I,0,i),n},Jht=iBe,nBe=function(){return Array.prototype.flat||Jht},AD,wne;function Oht(){if(wne)return AD;wne=1;var e=Il,g=typeof Symbol=="function"&&typeof Symbol.unscopables=="symbol",I=g&&Array.prototype[Symbol.unscopables],i=TypeError;return AD=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)},AD}var sD,Vne;function _ht(){if(Vne)return sD;Vne=1;var e=Mn,g=Oht(),I=nBe;return sD=function(){var n=I();return e(Array.prototype,{flat:n},{flat:function(){return Array.prototype.flat!==n}}),g("flat"),n},sD}var Lht=Mn,Uht=il,Qht=iBe,CBe=nBe,jht=CBe(),$ht=_ht(),rBe=Uht(jht);Lht(rBe,{getPolyfill:CBe,implementation:Qht,shim:$ht});var jS=rBe,Rne={}.hasOwnProperty,lD=Function.prototype.call,z0=lD.bind?lD.bind(Rne):function(e,g){return lD.call(Rne,e,g)},$S={},Rz={exports:{}},Wne=function(e){return e!==e},oBe=function(g,I){return g===0&&I===0?1/g===1/I:!!(g===I||Wne(g)&&Wne(I))},qht=oBe,aBe=function(){return typeof Object.is=="function"?Object.is:qht},emt=aBe,tmt=Mn,gmt=function(){var g=emt();return tmt(Object,{is:g},{is:function(){return Object.is!==g}}),g},Imt=Mn,imt=il,nmt=oBe,ABe=aBe,Cmt=gmt,sBe=imt(ABe(),Object);Imt(sBe,{getPolyfill:ABe,implementation:nmt,shim:Cmt});var aj=sBe;(function(e,g){Object.defineProperty(g,"__esModule",{value:!0}),g.default=r;var I=n(aj),i=n(z0);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=cD(g);return(I===Xmt||I===Wmt)&&g("")==null}catch{}return!1})}var vBe=function(){if(GBe(this)||!wmt(this)&&!bBe(this))throw new TypeError("Function.prototype.name sham getter called on non-function");if(Bmt&&vmt(this,"name"))return this.name;if(this===Hmt)return"";var g=yBe(this),I=ZBe(g,Vmt),i=I&&I[1];return i},Nmt=vBe,BBe=function(){return Nmt},kmt=Mn.supportsDescriptors,Ymt=pBe(),Kmt=BBe,Hne=Object.defineProperty,xmt=TypeError,Dmt=function(){var g=Kmt();if(Ymt)return g;if(!kmt)throw new xmt("Shimming Function.prototype.name support requires ES5 property descriptor support.");var I=Function.prototype;return Hne(I,"name",{configurable:!0,enumerable:!1,get:function(){var i=g.call(this);return this!==I&&Hne(this,"name",{configurable:!0,enumerable:!1,value:i,writable:!1}),i}}),g},Fmt=Mn,Emt=il,SBe=vBe,Mmt=BBe,zmt=Dmt,wBe=Emt(SBe);Fmt(wBe,{getPolyfill:Mmt,implementation:SBe,shim:zmt});var sj=wBe,VBe={},RBe={};Object.defineProperty(RBe,"__esModule",{value:!0});var kN={},P0={},X9=$e&&$e.__assign||function(){return X9=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}(lj);cg.NodeWithChildren=KN;var TBe=function(e){su(g,e);function g(){var I=e!==null&&e.apply(this,arguments)||this;return I.type=EC.ElementType.CDATA,I}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 4},enumerable:!1,configurable:!0}),g}(KN);cg.CDATA=TBe;var NBe=function(e){su(g,e);function g(){var I=e!==null&&e.apply(this,arguments)||this;return I.type=EC.ElementType.Root,I}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 9},enumerable:!1,configurable:!0}),g}(KN);cg.Document=NBe;var kBe=function(e){su(g,e);function g(I,i,n,C){n===void 0&&(n=[]),C===void 0&&(C=I==="script"?EC.ElementType.Script:I==="style"?EC.ElementType.Style:EC.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}(KN);cg.Element=kBe;function YBe(e){return(0,EC.isTag)(e)}cg.isTag=YBe;function KBe(e){return e.type===EC.ElementType.CDATA}cg.isCDATA=KBe;function xBe(e){return e.type===EC.ElementType.Text}cg.isText=xBe;function DBe(e){return e.type===EC.ElementType.Comment}cg.isComment=DBe;function FBe(e){return e.type===EC.ElementType.Directive}cg.isDirective=FBe;function EBe(e){return e.type===EC.ElementType.Root}cg.isDocument=EBe;function Omt(e){return Object.prototype.hasOwnProperty.call(e,"children")}cg.hasChildren=Omt;function cj(e,g){g===void 0&&(g=!1);var I;if(xBe(e))I=new WBe(e.data);else if(DBe(e))I=new XBe(e.data);else if(YBe(e)){var i=g?uD(e.children):[],n=new kBe(e.name,QG({},e.attribs),i);i.forEach(function(a){return a.parent=n}),e.namespace!=null&&(n.namespace=e.namespace),e["x-attribsNamespace"]&&(n["x-attribsNamespace"]=QG({},e["x-attribsNamespace"])),e["x-attribsPrefix"]&&(n["x-attribsPrefix"]=QG({},e["x-attribsPrefix"])),I=n}else if(KBe(e)){var i=g?uD(e.children):[],C=new TBe(i);i.forEach(function(s){return s.parent=C}),I=C}else if(EBe(e)){var i=g?uD(e.children):[],r=new NBe(i);i.forEach(function(s){return s.parent=r}),e["x-mode"]&&(r["x-mode"]=e["x-mode"]),I=r}else if(FBe(e)){var o=new HBe(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}cg.cloneNode=cj;function uD(e){for(var g=e.map(function(i){return cj(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 dj={};Object.defineProperty(dj,"__esModule",{value:!0});dj.default=new Uint16Array("Ȁaglq \x1Bɭ\0\0p;䀦os;䀧t;䀾t;䀼uot;䀢".split("").map(function(e){return e.charCodeAt(0)}));var Wz={};(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})(Wz);(function(e){var g=$e&&$e.__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=$e&&$e.__setModuleDefault||(Object.create?function(S,X){Object.defineProperty(S,"default",{enumerable:!0,value:X})}:function(S,X){S.default=X}),i=$e&&$e.__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=$e&&$e.__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(uj);e.htmlDecodeTree=C.default;var r=n(dj);e.xmlDecodeTree=r.default;var o=i(Wz);e.decodeCodePoint=o.default;var a=Wz;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(K===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 K=0,F=0;(F=H.indexOf("&",F))>=0;){X+=H.slice(K,F),W.startEntity(Y);var J=W.write(H,F+1);if(J<0){K=F+W.end();break}K=F+J,F=J===0?K+1:K}var P=X+H.slice(K);return X="",P}}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 K=R-Y;return K<0||K>=H?-1:S[W+K]-1}for(var F=W,J=F+H-1;F<=J;){var P=F+J>>>1,ge=S[P];if(geR)J=P-1;else return S[P+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})(lh);var ch={},hj={};Object.defineProperty(hj,"__esModule",{value:!0});function uR(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," "]]))})(Kb);var _mt=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(ch,"__esModule",{value:!0});ch.encodeNonAsciiHTML=ch.encodeHTML=void 0;var Lmt=_mt(hj),zBe=Kb,Umt=/[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;function Qmt(e){return PBe(Umt,e)}ch.encodeHTML=Qmt;function jmt(e){return PBe(zBe.xmlReplacer,e)}ch.encodeNonAsciiHTML=jmt;function PBe(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=Lmt.default.get(r);if(typeof o=="object"){if(C+10&&(i+=xN(e.children,g)),(g.xmlMode||!Nne.has(e.name))&&(i+=""))),i}function oft(e){return"<".concat(e.data,">")}function aft(e,g){var I,i=e.data||"";return((I=g.encodeEntities)!==null&&I!==void 0?I:g.decodeEntities)!==!1&&!(!g.xmlMode&&e.parent&&tft.has(e.parent.name))&&(i=g.xmlMode||g.encodeEntities!=="utf8"?(0,H9.encodeXML)(i):(0,H9.escapeText)(i)),i}function Aft(e){return"")}function sft(e){return"")}var lft=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(Cr,"__esModule",{value:!0});Cr.innerText=Cr.textContent=Cr.getText=Cr.getInnerHTML=Cr.getOuterHTML=void 0;var uA=En,cft=lft(O0),uft=J0;function OBe(e,g){return(0,cft.default)(e,g)}Cr.getOuterHTML=OBe;function dft(e,g){return(0,uA.hasChildren)(e)?e.children.map(function(I){return OBe(I,g)}).join(""):""}Cr.getInnerHTML=dft;function $1(e){return Array.isArray(e)?e.map($1).join(""):(0,uA.isTag)(e)?e.name==="br"?` -`:$1(e.children):(0,uA.isCDATA)(e)?$1(e.children):(0,uA.isText)(e)?e.data:""}Cr.getText=$1;function Xz(e){return Array.isArray(e)?e.map(Xz).join(""):(0,uA.hasChildren)(e)&&!(0,uA.isComment)(e)?Xz(e.children):(0,uA.isText)(e)?e.data:""}Cr.textContent=Xz;function Hz(e){return Array.isArray(e)?e.map(Hz).join(""):(0,uA.hasChildren)(e)&&(e.type===uft.ElementType.Tag||(0,uA.isCDATA)(e))?Hz(e.children):(0,uA.isText)(e)?e.data:""}Cr.innerText=Hz;var _i={};Object.defineProperty(_i,"__esModule",{value:!0});_i.prevElementSibling=_i.nextElementSibling=_i.getName=_i.hasAttrib=_i.getAttributeValue=_i.getSiblings=_i.getParent=_i.getChildren=void 0;var mj=En;function _Be(e){return(0,mj.hasChildren)(e)?e.children:[]}_i.getChildren=_Be;function LBe(e){return e.parent||null}_i.getParent=LBe;function hft(e){var g,I,i=LBe(e);if(i!=null)return _Be(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}_i.getSiblings=hft;function mft(e,g){var I;return(I=e.attribs)===null||I===void 0?void 0:I[g]}_i.getAttributeValue=mft;function fft(e,g){return e.attribs!=null&&Object.prototype.hasOwnProperty.call(e.attribs,g)&&e.attribs[g]!=null}_i.hasAttrib=fft;function pft(e){return e.name}_i.getName=pft;function bft(e){for(var g,I=e.next;I!==null&&!(0,mj.isTag)(I);)g=I,I=g.next;return I}_i.nextElementSibling=bft;function yft(e){for(var g,I=e.prev;I!==null&&!(0,mj.isTag)(I);)g=I,I=g.prev;return I}_i.prevElementSibling=yft;var HC={};Object.defineProperty(HC,"__esModule",{value:!0});HC.prepend=HC.prependChild=HC.append=HC.appendChild=HC.replaceElement=HC.removeElement=void 0;function qS(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}HC.removeElement=qS;function Zft(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}}HC.replaceElement=Zft;function Gft(e,g){if(qS(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}HC.appendChild=Gft;function vft(e,g){qS(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)}HC.append=vft;function Bft(e,g){if(qS(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}HC.prependChild=Bft;function Sft(e,g){qS(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}HC.prepend=Sft;var Qn={};Object.defineProperty(Qn,"__esModule",{value:!0});Qn.findAll=Qn.existsOne=Qn.findOne=Qn.findOneChild=Qn.find=Qn.filter=void 0;var DN=En;function wft(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),UBe(e,Array.isArray(g)?g:[g],I,i)}Qn.filter=wft;function UBe(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,DN.hasChildren)(o)&&o.children.length>0&&(r.unshift(0),C.unshift(o.children))}}Qn.find=UBe;function Vft(e,g){return g.find(e)}Qn.findOneChild=Vft;function QBe(e,g,I){I===void 0&&(I=!0);for(var i=null,n=0;n0&&(i=QBe(e,C.children,!0));else continue}return i}Qn.findOne=QBe;function jBe(e,g){return g.some(function(I){return(0,DN.isTag)(I)&&(e(I)||jBe(e,I.children))})}Qn.existsOne=jBe;function Rft(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,DN.isTag)(C)&&(e(C)&&I.push(C),C.children.length>0&&(n.unshift(0),i.unshift(C.children)))}}Qn.findAll=Rft;var rr={};Object.defineProperty(rr,"__esModule",{value:!0});rr.getElementsByTagType=rr.getElementsByTagName=rr.getElementById=rr.getElements=rr.testElement=void 0;var nd=En,FN=Qn,T9={tag_name:function(e){return typeof e=="function"?function(g){return(0,nd.isTag)(g)&&e(g.name)}:e==="*"?nd.isTag:function(g){return(0,nd.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,nd.isText)(g)&&e(g.data)}:function(g){return(0,nd.isText)(g)&&g.data===e}}};function $Be(e,g){return typeof g=="function"?function(I){return(0,nd.isTag)(I)&&g(I.attribs[e])}:function(I){return(0,nd.isTag)(I)&&I.attribs[e]===g}}function Wft(e,g){return function(I){return e(I)||g(I)}}function qBe(e){var g=Object.keys(e).map(function(I){var i=e[I];return Object.prototype.hasOwnProperty.call(T9,I)?T9[I](i):$Be(I,i)});return g.length===0?null:g.reduce(Wft)}function Xft(e,g){var I=qBe(e);return I?I(g):!0}rr.testElement=Xft;function Hft(e,g,I,i){i===void 0&&(i=1/0);var n=qBe(e);return n?(0,FN.filter)(n,g,I,i):[]}rr.getElements=Hft;function Tft(e,g,I){return I===void 0&&(I=!0),Array.isArray(g)||(g=[g]),(0,FN.findOne)($Be("id",e),g,I)}rr.getElementById=Tft;function Nft(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,FN.filter)(T9.tag_name(e),g,I,i)}rr.getElementsByTagName=Nft;function kft(e,g,I,i){return I===void 0&&(I=!0),i===void 0&&(i=1/0),(0,FN.filter)(T9.tag_type(e),g,I,i)}rr.getElementsByTagType=kft;var eSe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueSort=e.compareDocumentPosition=e.DocumentPosition=e.removeSubsets=void 0;var g=En;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})(eSe);var EN={};Object.defineProperty(EN,"__esModule",{value:!0});EN.getFeed=void 0;var Yft=Cr,ew=rr;function Kft(e){var g=N9(Mft,e);return g?g.name==="feed"?xft(g):Dft(g):null}EN.getFeed=Kft;function xft(e){var g,I=e.children,i={type:"atom",items:(0,ew.getElementsByTagName)("entry",I).map(function(r){var o,a=r.children,s={media:tSe(a)};RC(s,"id","id",a),RC(s,"title","title",a);var A=(o=N9("link",a))===null||o===void 0?void 0:o.attribs.href;A&&(s.link=A);var l=hc("summary",a)||hc("content",a);l&&(s.description=l);var c=hc("updated",a);return c&&(s.pubDate=new Date(c)),s})};RC(i,"id","id",I),RC(i,"title","title",I);var n=(g=N9("link",I))===null||g===void 0?void 0:g.attribs.href;n&&(i.link=n),RC(i,"description","subtitle",I);var C=hc("updated",I);return C&&(i.updated=new Date(C)),RC(i,"author","email",I,!0),i}function Dft(e){var g,I,i=(I=(g=N9("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,ew.getElementsByTagName)("item",e.children).map(function(r){var o=r.children,a={media:tSe(o)};RC(a,"id","guid",o),RC(a,"title","title",o),RC(a,"link","link",o),RC(a,"description","description",o);var s=hc("pubDate",o)||hc("dc:date",o);return s&&(a.pubDate=new Date(s)),a})};RC(n,"title","title",i),RC(n,"link","link",i),RC(n,"description","description",i);var C=hc("lastBuildDate",i);return C&&(n.updated=new Date(C)),RC(n,"author","managingEditor",i,!0),n}var Fft=["url","type","lang"],Eft=["fileSize","bitrate","framerate","samplingrate","channels","duration","height","width"];function tSe(e){return(0,ew.getElementsByTagName)("media:content",e).map(function(g){for(var I=g.attribs,i={medium:I.medium,isDefault:!!I.isDefault},n=0,C=Fft;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})(lu);Object.defineProperty(hi,"__esModule",{value:!0});hi.toggleClass=hi.removeClass=hi.addClass=hi.hasClass=hi.removeAttr=hi.val=hi.data=hi.prop=hi.attr=void 0;var ISe=ai,Pg=lu,Yne=Ca,Kp=Object.prototype.hasOwnProperty,DB=/\s+/,dD="data-",Kne={null:null,true:!0,false:!1},fj=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,tpt=/^{[^]*}$|^\[[^]*]$/;function k9(e,g,I){var i;if(!(!e||!(0,Pg.isTag)(e))){if((i=e.attribs)!==null&&i!==void 0||(e.attribs={}),!g)return e.attribs;if(Kp.call(e.attribs,g))return!I&&fj.test(g)?g:e.attribs[g];if(e.name==="option"&&g==="value")return(0,ISe.text)(e.children);if(e.name==="input"&&(e.attribs.type==="radio"||e.attribs.type==="checkbox")&&g==="value")return"on"}}function xp(e,g,I){I===null?iSe(e,g):e.attribs[g]="".concat(I)}function gpt(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,Pg.domEach)(this,function(I,i){(0,Pg.isTag)(I)&&xp(I,e,g.call(I,i,I.attribs[e]))})}return(0,Pg.domEach)(this,function(I){(0,Pg.isTag)(I)&&(typeof e=="object"?Object.keys(e).forEach(function(i){var n=e[i];xp(I,i,n)}):xp(I,e,g))})}return arguments.length>1?this:k9(this[0],e,this.options.xmlMode)}hi.attr=gpt;function xne(e,g,I){return g in e?e[g]:!I&&fj.test(g)?k9(e,g,!1)!==void 0:k9(e,g,I)}function hD(e,g,I,i){g in e?e[g]=I:xp(e,g,!i&&fj.test(g)?I?"":null:"".concat(I))}function Ipt(e,g){var I=this,i;if(typeof e=="string"&&g===void 0){var n=this[0];if(!n||!(0,Pg.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,Yne.innerText)(n);case"textContent":return(0,Yne.textContent)(n);case"outerHTML":return this.clone().wrap("").parent().html();case"innerHTML":return this.html();default:return xne(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,Pg.domEach)(this,function(a,s){(0,Pg.isTag)(a)&&hD(a,e,g.call(a,s,xne(a,e,I.options.xmlMode)),I.options.xmlMode)})}return(0,Pg.domEach)(this,function(a){(0,Pg.isTag)(a)&&(typeof e=="object"?Object.keys(e).forEach(function(s){var A=e[s];hD(a,s,A,I.options.xmlMode)}):hD(a,e,g,I.options.xmlMode))})}}hi.prop=Ipt;function Dne(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 Fne(e,g){var I,i,n;g==null?(I=Object.keys(e.attribs).filter(function(a){return a.startsWith(dD)}),i=I.map(function(a){return(0,Pg.camelCase)(a.slice(dD.length))})):(I=[dD+(0,Pg.cssCase)(g)],i=[g]);for(var C=0;C-1;){var n=i+e.length;if((i===0||DB.test(I[i-1]))&&(n===I.length||DB.test(I[n])))return!0}return!1})}hi.hasClass=rpt;function nSe(e){if(typeof e=="function")return(0,Pg.domEach)(this,function(s,A){if((0,Pg.isTag)(s)){var l=s.attribs.class||"";nSe.call([s],e.call(s,A,l))}});if(!e||typeof e!="string")return this;for(var g=e.split(DB),I=this.length,i=0;i=0&&(C.splice(a,1),r=!0,o--)}r&&(n.attribs.class=C.join(" "))}})}hi.removeClass=CSe;function rSe(e,g){if(typeof e=="function")return(0,Pg.domEach)(this,function(l,c){(0,Pg.isTag)(l)&&rSe.call([l],e.call(l,c,l.attribs.class||"",g),g)});if(!e||typeof e!="string")return this;for(var I=e.split(DB),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}hi.toggleClass=rSe;var Rt={},oSe={},Zg;(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"})(Zg||(Zg={}));const opt={Unknown:null,QuirksMode:"quirks",IgnoreCase:!0,CaseSensitive:!1};var RI;(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"})(RI||(RI={}));const Ene=/^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/,apt=/\\([\da-f]{1,6}\s?|(\s)|.)/gi,Apt=new Map([[126,RI.Element],[94,RI.Start],[36,RI.End],[42,RI.Any],[33,RI.Not],[124,RI.Hyphen]]),spt=new Set(["has","not","matches","is","where","host","host-context"]);function aSe(e){switch(e.type){case Zg.Adjacent:case Zg.Child:case Zg.Descendant:case Zg.Parent:case Zg.Sibling:case Zg.ColumnCombinator:return!0;default:return!1}}const lpt=new Set(["contains","icontains"]);function cpt(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 iZ(e){return e.replace(apt,cpt)}function mD(e){return e===39||e===34}function Mne(e){return e===32||e===9||e===10||e===12||e===13}function upt(e){const g=[],I=ASe(g,`${e}`,0);if(I0&&I0&&aSe(i[i.length-1]))throw new Error("Did not expect successive traversals.")}function s(c){if(i.length>0&&i[i.length-1].type===Zg.Descendant){i[i.length-1].type=c;return}a(),i.push({type:c})}function A(c,u){i.push({type:Zg.Attribute,name:c,action:u,value:n(1),namespace:null,ignoreCase:"quirks"})}function l(){if(i.length&&i[i.length-1].type===Zg.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))),zne=new Set(lSe.map(e=>e.charCodeAt(0))),op=new Set([...lSe,"~","^","$","*","+","!","|",":","[","]"," ","."].map(e=>e.charCodeAt(0)));function cSe(e){return e.map(g=>g.map(hpt).join("")).join(", ")}function hpt(e,g,I){switch(e.type){case Zg.Child:return g===0?"> ":" > ";case Zg.Parent:return g===0?"< ":" < ";case Zg.Sibling:return g===0?"~ ":" ~ ";case Zg.Adjacent:return g===0?"+ ":" + ";case Zg.Descendant:return" ";case Zg.ColumnCombinator:return g===0?"|| ":" || ";case Zg.Universal:return e.namespace==="*"&&g+10?i+e.slice(I):e}const fpt=Object.freeze(Object.defineProperty({__proto__:null,get AttributeAction(){return RI},IgnoreCaseMode:opt,get SelectorType(){return Zg},isTraversal:aSe,parse:upt,stringify:cSe},Symbol.toStringTag,{value:"Module"})),tw=qs(fpt);var Nz={},am={trueFunc:function(){return!0},falseFunc:function(){return!1}},Tc={},_0={};Object.defineProperty(_0,"__esModule",{value:!0});_0.isTraversal=void 0;var ir=tw,dSe=new Map([[ir.SelectorType.Universal,50],[ir.SelectorType.Tag,30],[ir.SelectorType.Attribute,1],[ir.SelectorType.Pseudo,0]]);function ppt(e){return!dSe.has(e.type)}_0.isTraversal=ppt;var bpt=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 ypt(e){for(var g=e.map(hSe),I=1;I=0&&i>=1)):e.type===ir.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(hSe))})),i<0&&(i=0)):i=2:i=3),i}var zN={},PN={},Zpt=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(PN,"__esModule",{value:!0});PN.attributeRules=void 0;var dR=Zpt(am),Gpt=/[-[\]{}()*+?.,\\^$|#\s]/g;function Jne(e){return e.replace(Gpt,"\\$&")}var vpt=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 Nu(e,g){return typeof e.ignoreCase=="boolean"?e.ignoreCase:e.ignoreCase==="quirks"?!!g.quirksMode:!g.xmlMode&&vpt.has(e.name)}PN.attributeRules={equals:function(e,g,I){var i=I.adapter,n=g.name,C=g.value;return Nu(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 Nu(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 dR.default.falseFunc;var r=new RegExp("(?:^|\\s)".concat(Jne(C),"(?:$|\\s)"),Nu(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?dR.default.falseFunc:Nu(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?dR.default.falseFunc:Nu(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 dR.default.falseFunc;if(Nu(g,I)){var r=new RegExp(Jne(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)}:Nu(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 pj={},mSe={},fSe={},JN={};Object.defineProperty(JN,"__esModule",{value:!0});JN.parse=void 0;var Bpt=new Set([9,10,12,13,32]),One="0".charCodeAt(0),Spt="9".charCodeAt(0);function wpt(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=One&&e.charCodeAt(g)<=Spt;)s=s*10+(e.charCodeAt(g)-One),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}}Db.compile=Rpt;function Wpt(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})}Db.generate=Wpt;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.sequence=e.generate=e.compile=e.parse=void 0;var g=JN;Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return g.parse}});var I=Db;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})(fSe);(function(e){var g=$e&&$e.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(e,"__esModule",{value:!0}),e.filters=void 0;var I=g(fSe),i=g(am);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)}}}})(mSe);var Fb={};Object.defineProperty(Fb,"__esModule",{value:!0});Fb.verifyPseudoArgs=Fb.pseudos=void 0;Fb.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 Xpt(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"))}Fb.verifyPseudoArgs=Xpt;var ON={};Object.defineProperty(ON,"__esModule",{value:!0});ON.aliases=void 0;ON.aliases={"any-link":":is(a, area, link)[href]",link:":any-link:not(:visited)",disabled:`:is( + */var ect=function(e){return e!=null&&(eve(e)||tct(e)||!!e._isBuffer)};function eve(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function tct(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&eve(e.slice(0,0))}var gct=qlt,ict=ect,Ict=typeof Float64Array<"u";function nct(e,g){return e[0]-g[0]}function rct(){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("+C.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("+C.join(",")+"){"),I?n.push("return this.data.get("+o+")}"):n.push("return this.data["+o+"]}"),n.push("proto.index=function "+i+"_index(",C.join(),"){return "+o+"}"),n.push("proto.hi=function "+i+"_hi("+C.join(",")+"){return new "+i+"(this.data,"+r.map(function(m){return["(typeof i",m,"!=='number'||i",m,"<0)?this.shape[",m,"]:i",m,"|0"].join("")}).join(",")+","+r.map(function(m){return"this.stride["+m+"]"}).join(",")+",this.offset)}");var A=r.map(function(m){return"a"+m+"=this.shape["+m+"]"}),l=r.map(function(m){return"c"+m+"=this.stride["+m+"]"});n.push("proto.lo=function "+i+"_lo("+C.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,"+r.map(function(m){return"a"+m}).join(",")+","+r.map(function(m){return"c"+m}).join(",")+",b)}"),n.push("proto.step=function "+i+"_step("+C.join(",")+"){var "+r.map(function(m){return"a"+m+"=this.shape["+m+"]"}).join(",")+","+r.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,"+r.map(function(m){return"shape["+m+"]"}).join(",")+","+r.map(function(m){return"stride["+m+"]"}).join(",")+",offset)}");var h=new Function("CTOR_LIST","ORDER",n.join(` +`));return h(wX[e],rct)}function oct(e){if(ict(e))return"buffer";if(Ict)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 wX={float32:[],float64:[],int8:[],int16:[],int32:[],uint8:[],uint16:[],uint32:[],array:[],uint8_clamped:[],bigint64:[],biguint64:[],buffer:[],generic:[]};function act(e,g,i,I){if(e===void 0){var s=wX.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 r=n-1,C=1;r>=0;--r)i[r]=C,C*=g[r]}if(I===void 0){I=0;for(var r=0;r{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:kp(tve(e)),ive=e=>{const g=e.split("."),i=g.slice(1).join("").length;return+g.join("")/10**i},QS=(e,g)=>e||g;function XN(e){const g=[],i={},I={};let n=0;for(let r=0;r{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},sct=e=>{try{const g=e.split(".");return i=>{let I=i;return g.forEach(n=>{I=I[n]}),I}}catch{return}},lct=(e,g,i,I,n,r,C=0,o=0,a)=>{const s=r?n:I,A=r?I:n,l=r?o:C,c=r?C: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],uct="http://www.w3.org/2000/svg",dct=(e,g)=>{const i=new RegExp(`(\\s|^)${g}(\\s|$)`);if(e.namespaceURI===uct){const I=e.getAttribute("class")||"";e.setAttribute("class",I.replace(i," "))}else e.classList?e.classList.remove(g):mX(e,g)&&(e.className=e.className.replace(i," "))},Yp=(e,g)=>{e.select(".selection").attr("fill",null).attr("fill-opacity",null).attr("stroke",null).classed(g,!0)},bF=e=>{const g=e.toString(16);return g.length===1?`0${g}`:g},hct=(e,g,i)=>`#${bF(e)}${bF(g)}${bF(i)}`,SI=(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]},Ive=(e,g,i)=>{if(i===null||!e||!g)return;const I=e.domain()[0],n=e.domain()[1],r=g.domain()[0],C=g.domain()[1];return[...GX(I,n,i),...GX(r,C,i)]},mct=11184810,fct=1,pct=(e,g,i,I,n,r,C,o,a)=>{e.publish("app.animateOnMouseMove",!0);const s=i.mousePositionColor?UGe(i.mousePositionColor):mct,A=i.mousePositionAlpha||fct,l=new ot.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(r()[0]+b,h)}else{const b=o?n()[1]:0;l.moveTo(h,0),l.lineTo(h,r()[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=C()?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(zG.subscribe("higlass.mouseMove",d)),l},Ah=(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()],r=pct(e.pubSub,e.pubSubs,e.options,n,e.getPosition.bind(e),e.getDimensions.bind(e),e.getProp("flipText"),g,i);return I.addChild(r),()=>{I.removeChild(r)}},bct=e=>g=>Array.prototype.some.call(g,e),$l=(e,g)=>e+g,nve=(e,g,i,I,n,r)=>{const C=document.createElement("line");return C.setAttribute("x1",e),C.setAttribute("x2",i),C.setAttribute("y1",g),C.setAttribute("y2",I),n&&C.setAttribute("stroke-width",n),r&&C.setAttribute("stroke",r),C},rve=(e,g,i)=>{let I,n=0;const r=()=>{I=void 0},C=(...s)=>{const A=()=>{n>0&&(e(...s),n=0)};clearTimeout(I),I=setTimeout(A,i)};C.cancel=()=>{clearTimeout(I),r()},C.immediate=(...s)=>{e(...s)};let o=!1;return(s,...A)=>{o?n++:(e(...A),C(...A),o=!0,n=0,setTimeout(()=>{o=!1},g))}},yct=(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 r=new ImageData(e,I.width,I.height);return n.putImageData(r,0,0),I},UQ=e=>new Promise(g=>{setTimeout(g,e)}),Zct=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},jo=()=>{},HN=e=>(e||"").replace(/\/$/,""),QQ=(e,g,i=0,I=1e-6)=>n=>{let r=255;return n>I&&(r=Math.max(0,Math.min(255,Math.floor(e(n+i))))),g[r]},Q1=e=>{let g=[];for(let i=0;ig[0]?e.left?pz(e.left,g):nIe(e,"left",g):e.right?pz(e.right,g):nIe(e,"right",g)}Ps.prototype.add=function(g){if(!this.root){this.root=new Cve(g[0],g[1]),this.root.max=g[1];return}pz(this.root,g)};function ove(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||ove(e,I))}),i}Ps.prototype.contains=function(g){return ove(g,this.root)};function Gct(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 ave(e,g){if(!g)return!1;if(Gct(g.interval,e))return!0;let i=!1,I;return["left","right"].forEach(n=>{I=g[n],I&&I.max>=e[0]&&(i=i||ave(e,I))}),i}Ps.prototype.intersects=function(g){return ave(g,this.root)};function bz(e){return e?1+Math.max(bz(e.left),bz(e.right)):0}Ps.prototype.height=function(){return bz(this.root)};Ps.prototype.findMax=function(g){const i=[g];let I,n=-1/0,r;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],r=I);return r};Ps.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 r=n.interval;n.interval=i.interval,i.interval=r,this._removeHelper(n.interval,i)}else{let n="left";i.right&&(n="right");const r=i.parentNode;r?(r.left===i?r.left=i[n]:r.right=i[n],i[n]&&(i[n].parentNode=r)):(this.root=i[n],this.root&&(this.root.parentNode=null))}const I=i.parentNode;if(I){let n=this.findMax(I);const r=n.interval[1];for(;n;)n.max===i.interval[1]?(n.max=r,n=n.parentNode):n=!1}}else this._removeHelper(g,i.left),this._removeHelper(g,i.right)};Ps.prototype.remove=function(g){return this._removeHelper(g,this.root)};function RX(e){e.sort((I,n)=>n.to-n.from-(I.to-I.from));const g=[[]],i=[new Ps];for(let I=0;I=o?this.minNonZero(this.data,I,n):(Io*this.subsetSize&&(r=Math.min(r,this.minNonZero(this.data,o*this.subsetSize,n))),r)}},{key:"getMaxNonZeroInSubset",value:function(i){const I=i[0],n=i[1];let r=Number.MIN_SAFE_INTEGER;if(I===0&&n===this.tileSize)return this.maxNonZeroInTile;const C=Math.ceil(I/this.subsetSize),o=Math.floor((n-1)/this.subsetSize);return C>=o?this.maxNonZero(this.data,I,n):(Io*this.subsetSize&&(r=Math.max(r,this.maxNonZero(this.data,o*this.subsetSize,n))),r)}},{key:"computeSubsetNonZeroMinimums",value:function(){const i=[];for(let I=0;I-this.epsilon||C-this.epsilon||C>n&&(n=C))}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 r=Number.MAX_SAFE_INTEGER;for(let C=I;C-this.epsilon||o-this.epsilon||o>r&&(r=o)}return r}}]),e}();function Rct(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function CIe(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=z3;break;case"sum":g=dye;break;case"variance":g=N7;break;case"deviation":g=k7;break;default:g=z3,console.warn("Encountered an unsupported selectedRowsAggregationMode option.")}return g},xB=(e,g)=>e.reduce((i,I)=>i+(Array.isArray(I)&&g?I.length:1),0),E0=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=>E0(i)).reduce(QS,!1);default:return!1}},qQ=(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)},Ave=(e,g)=>e.tiledPlots[g].trackRenderer,Hct=(e,g)=>e.tiledPlots[g];var e4={},oIe=Object.prototype.toString,sve=function(g){var i=oIe.call(g),I=i==="[object Arguments]";return I||(I=i!=="[object Array]"&&g!==null&&typeof g=="object"&&typeof g.length=="number"&&g.length>=0&&oIe.call(g.callee)==="[object Function]"),I},yF,aIe;function Tct(){if(aIe)return yF;aIe=1;var e;if(!Object.keys){var g=Object.prototype.hasOwnProperty,i=Object.prototype.toString,I=sve,n=Object.prototype.propertyIsEnumerable,r=!n.call({toString:null},"toString"),C=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=C&&h;if(f&&u.length>0&&!g.call(u,0))for(var y=0;y0)for(var Z=0;Z"u"||!PI?yg:PI(Uint8Array),kd={"%AggregateError%":typeof AggregateError>"u"?yg:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?yg:ArrayBuffer,"%ArrayIteratorPrototype%":Mm&&PI?PI([][Symbol.iterator]()):yg,"%AsyncFromSyncIteratorPrototype%":yg,"%AsyncFunction%":ff,"%AsyncGenerator%":ff,"%AsyncGeneratorFunction%":ff,"%AsyncIteratorPrototype%":ff,"%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%":dve,"%GeneratorFunction%":ff,"%Int8Array%":typeof Int8Array>"u"?yg:Int8Array,"%Int16Array%":typeof Int16Array>"u"?yg:Int16Array,"%Int32Array%":typeof Int32Array>"u"?yg:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Mm&&PI?PI(PI([][Symbol.iterator]())):yg,"%JSON%":typeof JSON=="object"?JSON:yg,"%Map%":typeof Map>"u"?yg:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Mm||!PI?yg:PI(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"||!Mm||!PI?yg:PI(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?yg:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Mm&&PI?PI(""[Symbol.iterator]()):yg,"%Symbol%":Mm?Symbol:yg,"%SyntaxError%":Yb,"%ThrowTypeError%":Uct,"%TypedArray%":jct,"%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(PI)try{null.error}catch(e){var $ct=PI(PI(e));kd["%Error.prototype%"]=$ct}var qct=function e(g){var i;if(g==="%AsyncFunction%")i=ZF("async function () {}");else if(g==="%GeneratorFunction%")i=ZF("function* () {}");else if(g==="%AsyncGeneratorFunction%")i=ZF("async function* () {}");else if(g==="%AsyncGenerator%"){var I=e("%AsyncGeneratorFunction%");I&&(i=I.prototype)}else if(g==="%AsyncIteratorPrototype%"){var n=e("%AsyncGenerator%");n&&PI&&(i=PI(n.prototype))}return kd[g]=i,i},dIe={"%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"]},jS=g4,WX=il,eut=jS.call(Function.call,Array.prototype.concat),tut=jS.call(Function.apply,Array.prototype.splice),hIe=jS.call(Function.call,String.prototype.replace),XX=jS.call(Function.call,String.prototype.slice),gut=jS.call(Function.call,RegExp.prototype.exec),iut=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Iut=/\\(\\)?/g,nut=function(g){var i=XX(g,0,1),I=XX(g,-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 hIe(g,iut,function(r,C,o,a){n[n.length]=o?hIe(a,Iut,"$1"):C||r}),n},rut=function(g,i){var I=g,n;if(WX(dIe,I)&&(n=dIe[I],I="%"+n[0]+"%"),WX(kd,I)){var r=kd[I];if(r===ff&&(r=qct(I)),typeof r>"u"&&!i)throw new Kp("intrinsic "+g+" exists, but is not available. Please file an issue!");return{alias:n,name:I,value:r}}throw new Yb("intrinsic "+g+" does not exist!")},Hg=function(g,i){if(typeof g!="string"||g.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(gut(/^%?[^%]*%?$/,g)===null)throw new Yb("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var I=nut(g),n=I.length>0?I[0]:"",r=rut("%"+n+"%",i),C=r.name,o=r.value,a=!1,s=r.alias;s&&(n=s[0],tut(I,eut([0,1],s)));for(var A=1,l=!0;A=I.length){var h=Nd(o,c);l=!!h,l&&"get"in h&&!("originalValue"in h.get)?o=h.get:o=o[c]}else l=WX(o,c),o=o[c];l&&!a&&(kd[C]=o)}}return o},Cut=Hg,yz=Cut("%Object.defineProperty%",!0),Zz=function(){if(yz)try{return yz({},"a",{value:1}),!0}catch{return!1}return!1};Zz.hasArrayLengthDefineBug=function(){if(!Zz())return null;try{return yz([],"length",{value:1}).length!==1}catch{return!0}};var TN=Zz,out=Hg,$1=out("%Object.getOwnPropertyDescriptor%",!0);if($1)try{$1([],"length")}catch{$1=null}var i4=$1,aut=TN(),I4=Hg,OG=aut&&I4("%Object.defineProperty%",!0);if(OG)try{OG({},"a",{value:1})}catch{OG=!1}var Aut=I4("%SyntaxError%"),zm=I4("%TypeError%"),mIe=i4,hve=function(g,i,I){if(!g||typeof g!="object"&&typeof g!="function")throw new zm("`obj` must be an object or a function`");if(typeof i!="string"&&typeof i!="symbol")throw new zm("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new zm("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new zm("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new zm("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new zm("`loose`, if provided, must be a boolean");var n=arguments.length>3?arguments[3]:null,r=arguments.length>4?arguments[4]:null,C=arguments.length>5?arguments[5]:null,o=arguments.length>6?arguments[6]:!1,a=!!mIe&&mIe(g,i);if(OG)OG(g,i,{configurable:C===null&&a?a.configurable:!C,enumerable:n===null&&a?a.enumerable:!n,value:I,writable:r===null&&a?a.writable:!r});else if(o||!n&&!r&&!C)g[i]=I;else throw new Aut("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},sut=lve,lut=typeof Symbol=="function"&&typeof Symbol("foo")=="symbol",cut=Object.prototype.toString,uut=Array.prototype.concat,fIe=hve,dut=function(e){return typeof e=="function"&&cut.call(e)==="[object Function]"},mve=TN(),hut=function(e,g,i,I){if(g in e){if(I===!0){if(e[g]===i)return}else if(!dut(I)||!I())return}mve?fIe(e,g,i,!0):fIe(e,g,i)},fve=function(e,g){var i=arguments.length>2?arguments[2]:{},I=sut(g);lut&&(I=uut.call(I,Object.getOwnPropertySymbols(g)));for(var n=0;n4294967295||fut(i)!==i)throw new yIe("`length` must be a positive 32-bit integer");var I=arguments.length>2&&!!arguments[2],n=!0,r=!0;if("length"in g&&bIe){var C=bIe(g,"length");C&&!C.configurable&&(n=!1),C&&!C.writable&&(r=!1)}return(n||r||!I)&&(mut?pIe(g,"length",i,!0,!0):pIe(g,"length",i)),g};(function(e){var g=g4,i=Hg,I=put,n=i("%TypeError%"),r=i("%Function.prototype.apply%"),C=i("%Function.prototype.call%"),o=i("%Reflect.apply%",!0)||g.call(C,r),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,C,arguments);return I(u,1+s(0,c.length-(arguments.length-1)),!0)};var A=function(){return o(g,r,arguments)};a?a(e.exports,"apply",{value:A}):e.exports.apply=A})(pve);var Il=pve.exports,yve=Hg,Zve=Il,but=Zve(yve("String.prototype.indexOf")),hr=function(g,i){var I=yve(g,!!i);return typeof I=="function"&&but(g,".prototype.")>-1?Zve(I):I},yut=lve,Gve=t4(),vve=hr,ZIe=Object,Zut=vve("Array.prototype.push"),GIe=vve("Object.prototype.propertyIsEnumerable"),Gut=Gve?Object.getOwnPropertySymbols:null,Bve=function(g,i){if(g==null)throw new TypeError("target must be an object");var I=ZIe(g);if(arguments.length===1)return I;for(var n=1;n= 0");if(A>C)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},SF}const Yut={},Kut=Object.freeze(Object.defineProperty({__proto__:null,default:Yut},Symbol.toStringTag,{value:"Module"})),Fut=qs(Kut);var r4=typeof Map=="function"&&Map.prototype,wF=Object.getOwnPropertyDescriptor&&r4?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,HX=r4&&wF&&typeof wF.get=="function"?wF.get:null,SIe=r4&&Map.prototype.forEach,C4=typeof Set=="function"&&Set.prototype,RF=Object.getOwnPropertyDescriptor&&C4?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,TX=C4&&RF&&typeof RF.get=="function"?RF.get:null,wIe=C4&&Set.prototype.forEach,Dut=typeof WeakMap=="function"&&WeakMap.prototype,_G=Dut?WeakMap.prototype.has:null,xut=typeof WeakSet=="function"&&WeakSet.prototype,LG=xut?WeakSet.prototype.has:null,Eut=typeof WeakRef=="function"&&WeakRef.prototype,RIe=Eut?WeakRef.prototype.deref:null,Mut=Boolean.prototype.valueOf,zut=Object.prototype.toString,Put=Function.prototype.toString,Jut=String.prototype.match,o4=String.prototype.slice,dc=String.prototype.replace,Out=String.prototype.toUpperCase,VIe=String.prototype.toLowerCase,Wve=RegExp.prototype.test,WIe=Array.prototype.concat,Fa=Array.prototype.join,_ut=Array.prototype.slice,XIe=Math.floor,Gz=typeof BigInt=="function"?BigInt.prototype.valueOf:null,VF=Object.getOwnPropertySymbols,vz=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Kb=typeof Symbol=="function"&&typeof Symbol.iterator=="object",xn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Kb||"symbol")?Symbol.toStringTag:null,Xve=Object.prototype.propertyIsEnumerable,HIe=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function TIe(e,g){if(e===1/0||e===-1/0||e!==e||e&&e>-1e3&&e<1e3||Wve.call(/e/,g))return g;var i=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof e=="number"){var I=e<0?-XIe(-e):XIe(e);if(I!==e){var n=String(I),r=o4.call(g,n.length+1);return dc.call(n,i,"$&_")+"."+dc.call(dc.call(r,/([0-9]{3})/g,"$&_"),/_$/,"")}}return dc.call(g,i,"$&_")}var Bz=Fut,NIe=Bz.custom,kIe=Nve(NIe)?NIe:null,Hve=function e(g,i,I,n){var r=i||{};if(Pl(r,"quoteStyle")&&r.quoteStyle!=="single"&&r.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Pl(r,"maxStringLength")&&(typeof r.maxStringLength=="number"?r.maxStringLength<0&&r.maxStringLength!==1/0:r.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var C=Pl(r,"customInspect")?r.customInspect:!0;if(typeof C!="boolean"&&C!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Pl(r,"indent")&&r.indent!==null&&r.indent!==" "&&!(parseInt(r.indent,10)===r.indent&&r.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Pl(r,"numericSeparator")&&typeof r.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var o=r.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 Yve(g,r);if(typeof g=="number"){if(g===0)return 1/0/g>0?"0":"-0";var a=String(g);return o?TIe(g,a):a}if(typeof g=="bigint"){var s=String(g)+"n";return o?TIe(g,s):s}var A=typeof r.depth>"u"?5:r.depth;if(typeof I>"u"&&(I=0),I>=A&&A>0&&typeof g=="object")return Sz(g)?"[Array]":"[Object]";var l=sdt(r,I);if(typeof n>"u")n=[];else if(kve(n,g)>=0)return"[Circular]";function c(W,V,H){if(V&&(n=_ut.call(n),n.push(V)),H){var Y={depth:r.depth};return Pl(r,"quoteStyle")&&(Y.quoteStyle=r.quoteStyle),e(W,Y,I+1,n)}return e(W,r,I+1,n)}if(typeof g=="function"&&!YIe(g)){var u=gdt(g),d=uV(g,c);return"[Function"+(u?": "+u:" (anonymous)")+"]"+(d.length>0?" { "+Fa.call(d,", ")+" }":"")}if(Nve(g)){var h=Kb?dc.call(String(g),/^(Symbol\(.*\))_[^)]*$/,"$1"):vz.call(g);return typeof g=="object"&&!Kb?IZ(h):h}if(odt(g)){for(var m="<"+VIe.call(String(g.nodeName)),f=g.attributes||[],b=0;b",m}if(Sz(g)){if(g.length===0)return"[]";var p=uV(g,c);return l&&!Adt(p)?"["+wz(p,l)+"]":"[ "+Fa.call(p,", ")+" ]"}if(Qut(g)){var y=uV(g,c);return!("cause"in Error.prototype)&&"cause"in g&&!Xve.call(g,"cause")?"{ ["+String(g)+"] "+Fa.call(WIe.call("[cause]: "+c(g.cause),y),", ")+" }":y.length===0?"["+String(g)+"]":"{ ["+String(g)+"] "+Fa.call(y,", ")+" }"}if(typeof g=="object"&&C){if(kIe&&typeof g[kIe]=="function"&&Bz)return Bz(g,{depth:A-I});if(C!=="symbol"&&typeof g.inspect=="function")return g.inspect()}if(idt(g)){var Z=[];return SIe&&SIe.call(g,function(W,V){Z.push(c(V,g,!0)+" => "+c(W,g))}),KIe("Map",HX.call(g),Z,l)}if(rdt(g)){var B=[];return wIe&&wIe.call(g,function(W){B.push(c(W,g))}),KIe("Set",TX.call(g),B,l)}if(Idt(g))return WF("WeakMap");if(Cdt(g))return WF("WeakSet");if(ndt(g))return WF("WeakRef");if($ut(g))return IZ(c(Number(g)));if(edt(g))return IZ(c(Gz.call(g)));if(qut(g))return IZ(Mut.call(g));if(jut(g))return IZ(c(String(g)));if(typeof window<"u"&&g===window)return"{ [object Window] }";if(g===globalThis)return"{ [object globalThis] }";if(!Uut(g)&&!YIe(g)){var G=uV(g,c),v=HIe?HIe(g)===Object.prototype:g instanceof Object||g.constructor===Object,w=g instanceof Object?"":"null prototype",R=!v&&xn&&Object(g)===g&&xn in g?o4.call(ou(g),8,-1):w?"Object":"",S=v||typeof g.constructor!="function"?"":g.constructor.name?g.constructor.name+" ":"",X=S+(R||w?"["+Fa.call(WIe.call([],R||[],w||[]),": ")+"] ":"");return G.length===0?X+"{}":l?X+"{"+wz(G,l)+"}":X+"{ "+Fa.call(G,", ")+" }"}return String(g)};function Tve(e,g,i){var I=(i.quoteStyle||g)==="double"?'"':"'";return I+e+I}function Lut(e){return dc.call(String(e),/"/g,""")}function Sz(e){return ou(e)==="[object Array]"&&(!xn||!(typeof e=="object"&&xn in e))}function Uut(e){return ou(e)==="[object Date]"&&(!xn||!(typeof e=="object"&&xn in e))}function YIe(e){return ou(e)==="[object RegExp]"&&(!xn||!(typeof e=="object"&&xn in e))}function Qut(e){return ou(e)==="[object Error]"&&(!xn||!(typeof e=="object"&&xn in e))}function jut(e){return ou(e)==="[object String]"&&(!xn||!(typeof e=="object"&&xn in e))}function $ut(e){return ou(e)==="[object Number]"&&(!xn||!(typeof e=="object"&&xn in e))}function qut(e){return ou(e)==="[object Boolean]"&&(!xn||!(typeof e=="object"&&xn in e))}function Nve(e){if(Kb)return e&&typeof e=="object"&&e instanceof Symbol;if(typeof e=="symbol")return!0;if(!e||typeof e!="object"||!vz)return!1;try{return vz.call(e),!0}catch{}return!1}function edt(e){if(!e||typeof e!="object"||!Gz)return!1;try{return Gz.call(e),!0}catch{}return!1}var tdt=Object.prototype.hasOwnProperty||function(e){return e in this};function Pl(e,g){return tdt.call(e,g)}function ou(e){return zut.call(e)}function gdt(e){if(e.name)return e.name;var g=Jut.call(Put.call(e),/^function\s*([\w$]+)/);return g?g[1]:null}function kve(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 Yve(o4.call(e,0,g.maxStringLength),g)+I}var n=dc.call(dc.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,adt);return Tve(n,"single",g)}function adt(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":"")+Out.call(g.toString(16))}function IZ(e){return"Object("+e+")"}function WF(e){return e+" { ? }"}function KIe(e,g,i,I){var n=I?wz(i,I):Fa.call(i,", ");return e+" ("+g+") {"+n+"}"}function Adt(e){for(var g=0;g=0)return!1;return!0}function sdt(e,g){var i;if(e.indent===" ")i=" ";else if(typeof e.indent=="number"&&e.indent>0)i=Fa.call(Array(e.indent+1)," ");else return null;return{base:i,prev:Fa.call(Array(g+1),i)}}function wz(e,g){if(e.length===0)return"";var i=` +`+g.prev+g.base;return i+Fa.call(e,","+i)+` +`+g.prev}function uV(e,g){var i=Sz(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"}),HF}var TF,xIe;function bn(){if(xIe)return TF;xIe=1;var e=ldt();return TF=function(i){return typeof i=="symbol"?"Symbol":typeof i=="bigint"?"BigInt":e(i)},TF}var cdt=Hg,EIe=cdt("%TypeError%"),udt=Hve,ddt=au(),hdt=bn(),$S=function(g,i){if(hdt(g)!=="Object")throw new EIe("Assertion failed: Type(O) is not Object");if(!ddt(i))throw new EIe("Assertion failed: IsPropertyKey(P) is not true, got "+udt(i));return g[i]},NF,MIe;function Kve(){if(MIe)return NF;MIe=1;var e=Hg,g=e("%Array%"),i=!g.isArray&&hr("Object.prototype.toString");return NF=g.isArray||function(n){return i(n)==="[object Array]"},NF}var kF,zIe;function a4(){return zIe||(zIe=1,kF=Kve()),kF}var dV={exports:{}},YF,PIe;function mdt(){return PIe||(PIe=1,YF=Hg),YF}var KF,JIe;function A4(){if(JIe)return KF;JIe=1;var e=Hg,g=il,i=e("%TypeError%");return KF=function(n,r){if(n.Type(r)!=="Object")return!1;var C={"[[Configurable]]":!0,"[[Enumerable]]":!0,"[[Get]]":!0,"[[Set]]":!0,"[[Value]]":!0,"[[Writable]]":!0};for(var o in r)if(g(r,o)&&!C[o])return!1;if(n.IsDataDescriptor(r)&&n.IsAccessorDescriptor(r))throw new i("Property Descriptors may not be both accessor and data descriptors");return!0},KF}var FF,OIe;function Fve(){if(OIe)return FF;OIe=1;var e=TN,g=Hg,i=e()&&g("%Object.defineProperty%",!0),I=e.hasArrayLengthDefineBug(),n=I&&Kve(),r=hr,C=r("Object.prototype.propertyIsEnumerable");return FF=function(a,s,A,l,c,u){if(!i){if(!a(u)||!u["[[Configurable]]"]||!u["[[Writable]]"]||c in l&&C(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)},FF}var DF,_Ie;function fdt(){if(_Ie)return DF;_Ie=1;var e=il;return DF=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]]"])},DF}var xF,LIe;function kN(){if(LIe)return xF;LIe=1;var e=Hg,g=e("%TypeError%"),i=e("%SyntaxError%"),I=il,n=n4(),r=fdt(),C={"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":r,"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]]")&&C["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 xF=function(a,s,A,l){var c=C[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)},xF}var EF,UIe;function pdt(){return UIe||(UIe=1,EF=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}),EF}var MF,QIe;function Dve(){if(QIe)return MF;QIe=1;var e=kN(),g=pdt(),i=bn();return MF=function(n){return typeof n<"u"&&e(i,"Property Descriptor","Desc",n),g(n)},MF}var zF,jIe;function YN(){if(jIe)return zF;jIe=1;var e=il,g=bn(),i=kN();return zF=function(n){return!(typeof n>"u"||(i(g,"Property Descriptor","Desc",n),!e(n,"[[Get]]")&&!e(n,"[[Set]]")))},zF}var PF,$Ie;function KN(){if($Ie)return PF;$Ie=1;var e=il,g=bn(),i=kN();return PF=function(n){return!(typeof n>"u"||(i(g,"Property Descriptor","Desc",n),!e(n,"[[Value]]")&&!e(n,"[[Writable]]")))},PF}var JF,qIe;function s4(){if(qIe)return JF;qIe=1;var e=NN;return JF=function(i,I){return i===I?i===0?1/i===1/I:!0:e(i)&&e(I)},JF}var xve=function(g){return!!g},Eve=Function.prototype.toString,np=typeof Reflect=="object"&&Reflect!==null&&Reflect.apply,Rz,q1;if(typeof np=="function"&&typeof Object.defineProperty=="function")try{Rz=Object.defineProperty({},"length",{get:function(){throw q1}}),q1={},np(function(){throw 42},null,Rz)}catch(e){e!==q1&&(np=null)}else np=null;var bdt=/^\s*class\b/,Vz=function(g){try{var i=Eve.call(g);return bdt.test(i)}catch{return!1}},OF=function(g){try{return Vz(g)?!1:(Eve.call(g),!0)}catch{return!1}},eW=Object.prototype.toString,ydt="[object Object]",Zdt="[object Function]",Gdt="[object GeneratorFunction]",vdt="[object HTMLAllCollection]",Bdt="[object HTML document.all class]",Sdt="[object HTMLCollection]",wdt=typeof Symbol=="function"&&!!Symbol.toStringTag,Rdt=!(0 in[,]),Wz=function(){return!1};if(typeof document=="object"){var Vdt=document.all;eW.call(Vdt)===eW.call(document.all)&&(Wz=function(g){if((Rdt||!g)&&(typeof g>"u"||typeof g=="object"))try{var i=eW.call(g);return(i===vdt||i===Bdt||i===Sdt||i===ydt)&&g("")==null}catch{}return!1})}var l4=np?function(g){if(Wz(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;try{np(g,null,Rz)}catch(i){if(i!==q1)return!1}return!Vz(g)&&OF(g)}:function(g){if(Wz(g))return!0;if(!g||typeof g!="function"&&typeof g!="object")return!1;if(wdt)return OF(g);if(Vz(g))return!1;var i=eW.call(g);return i!==Zdt&&i!==Gdt&&!/^\[object HTML/.test(i)?!1:OF(g)},c4=l4,_F,ene;function Mve(){if(ene)return _F;ene=1;var e=il,g=Hg,i=g("%TypeError%"),I=bn(),n=xve,r=c4;return _F=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"&&!r(s))throw new i("getter must be a function");a["[[Get]]"]=s}if(e(o,"set")){var A=o.set;if(typeof A<"u"&&!r(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},_F}var LF,tne;function Wdt(){if(tne)return LF;tne=1;var e=Hg,g=e("%TypeError%"),i=A4(),I=Fve(),n=Dve(),r=YN(),C=KN(),o=au(),a=s4(),s=Mve(),A=bn();return LF=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:C,IsAccessorDescriptor:r},d)?d:s(d);if(!i({Type:A,IsDataDescriptor:C,IsAccessorDescriptor:r},h))throw new g("Assertion failed: Desc is not a valid Property Descriptor");return I(C,a,n,c,u,h)},LF}var gne;function Xdt(){if(gne)return dV.exports;gne=1;var e=mdt(),g=e("%Reflect.construct%",!0),i=Wdt();try{i({},"",{"[[Get]]":function(){}})}catch{i=null}if(i&&g){var I={},n={};i(n,"length",{"[[Get]]":function(){throw I},"[[Enumerable]]":!0}),dV.exports=function(C){try{g(C,n)}catch(o){return o===I}}}else dV.exports=function(C){return typeof C=="function"&&!!C.prototype};return dV.exports}var zve=Hg,ine=zve("%Symbol.species%",!0),Ine=zve("%TypeError%"),nne=kut(),rne=$S,Hdt=a4(),Tdt=Xdt(),Ndt=bn(),kdt=n4(),Pve=function(g,i){if(!kdt(i)||i<0)throw new Ine("Assertion failed: length must be an integer >= 0");var I=Hdt(g);if(!I)return nne(i);var n=rne(g,"constructor");if(ine&&Ndt(n)==="Object"&&(n=rne(n,ine),n===null&&(n=void 0)),typeof n>"u")return nne(i);if(!Tdt(n))throw new Ine("C must be a constructor");return new n(i)},Jve=Number.MAX_SAFE_INTEGER||9007199254740991,UF,Cne;function Ove(){if(Cne)return UF;Cne=1;var e=Hg,g=hr,i=e("%TypeError%"),I=a4(),n=e("%Reflect.apply%",!0)||g("Function.prototype.apply");return UF=function(C,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(C,o,a)},UF}var QF,one;function _ve(){return one||(one=1,QF=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),QF}var jF,ane;function Ydt(){if(ane)return jF;ane=1;var e=Hg,g=e("%Object.preventExtensions%",!0),i=e("%Object.isExtensible%",!0),I=_ve();return jF=g?function(r){return!I(r)&&i(r)}:function(r){return!I(r)},jF}var $F,Ane;function Kdt(){return Ane||(Ane=1,$F=function(g,i){return!!i&&typeof i=="object"&&"[[Enumerable]]"in i&&"[[Configurable]]"in i&&(g.IsAccessorDescriptor(i)||g.IsDataDescriptor(i))}),$F}var qF,sne;function Fdt(){if(sne)return qF;sne=1;var e=kN(),g=YN(),i=KN(),I=bn();return qF=function(r){return typeof r>"u"?!1:(e(I,"Property Descriptor","Desc",r),!g(r)&&!i(r))},qF}var eD,lne;function Ddt(){if(lne)return eD;lne=1;var e=Hg,g=e("%TypeError%"),i=Fve(),I=Kdt(),n=A4(),r=Dve(),C=YN(),o=KN(),a=Fdt(),s=au(),A=s4(),l=bn();return eD=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:C},m))throw new g("Assertion failed: Desc must be a Property Descriptor");if(l(f)!=="Undefined"&&!n({Type:l,IsDataDescriptor:o,IsAccessorDescriptor:C},f))throw new g("Assertion failed: current must be a Property Descriptor, or undefined");if(l(f)==="Undefined")return h?b==="Undefined"?!0:C(m)?i(o,A,r,u,d,m):i(o,A,r,u,d,{"[[Configurable]]":!!m["[[Configurable]]"],"[[Enumerable]]":!!m["[[Enumerable]]"],"[[Value]]":m["[[Value]]"],"[[Writable]]":!!m["[[Writable]]"]}):!1;if(!I({IsAccessorDescriptor:C,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(C(m),C(f)))return!1;if(C(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)&&C(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],i(o,A,r,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Get]]":("[[Get]]"in m?m:f)["[[Get]]"],"[[Set]]":("[[Set]]"in m?m:f)["[[Set]]"]})):C(f)&&o(m)?(p=("[[Configurable]]"in m?m:f)["[[Configurable]]"],y=("[[Enumerable]]"in m?m:f)["[[Enumerable]]"],i(o,A,r,u,d,{"[[Configurable]]":!!p,"[[Enumerable]]":!!y,"[[Value]]":("[[Value]]"in m?m:f)["[[Value]]"],"[[Writable]]":!!("[[Writable]]"in m?m:f)["[[Writable]]"]})):i(o,A,r,u,d,m)}return!0},eD}var tD,cne;function xdt(){if(cne)return tD;cne=1;var e=Hg,g=i4,i=e("%SyntaxError%"),I=e("%TypeError%"),n=A4(),r=YN(),C=KN(),o=Ydt(),a=au(),s=Mve(),A=s4(),l=bn(),c=Ddt();return tD=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:C,IsAccessorDescriptor:r},m))throw new I("Assertion failed: Desc must be a Property Descriptor");if(!g){if(r(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)},tD}var gD,une;function Edt(){if(une)return gD;une=1;var e=Hg,g=e("%TypeError%"),i=au(),I=xdt(),n=bn();return gD=function(C,o,a){if(n(C)!=="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(C,o,s)},gD}var iD,dne;function Lve(){if(dne)return iD;dne=1;var e=Hg,g=e("%TypeError%"),i=Edt(),I=au(),n=bn();return iD=function(C,o,a){if(n(C)!=="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(C,o,a);if(!s)throw new g("unable to create data property")},iD}var ID,hne;function Uve(){if(hne)return ID;hne=1;var e=Hg,g=e("%TypeError%"),i=au(),I=bn();return ID=function(r,C){if(I(r)!=="Object")throw new g("Assertion failed: `O` must be an Object");if(!i(C))throw new g("Assertion failed: `P` must be a Property Key");return C in r},ID}var nD,mne;function Mdt(){return mne||(mne=1,nD=function(g){return g===null||typeof g!="function"&&typeof g!="object"}),nD}var zdt=t4,qS=function(){return zdt()&&!!Symbol.toStringTag},rD,fne;function Pdt(){if(fne)return rD;fne=1;var e=Date.prototype.getDay,g=function(C){try{return e.call(C),!0}catch{return!1}},i=Object.prototype.toString,I="[object Date]",n=qS();return rD=function(C){return typeof C!="object"||C===null?!1:n?g(C):i.call(C)===I},rD}var hV={exports:{}},pne;function Jdt(){if(pne)return hV.exports;pne=1;var e=Object.prototype.toString,g=cve();if(g){var i=Symbol.prototype.toString,I=/^Symbol\(.*\)$/,n=function(C){return typeof C.valueOf()!="symbol"?!1:I.test(i.call(C))};hV.exports=function(C){if(typeof C=="symbol")return!0;if(e.call(C)!=="[object Symbol]")return!1;try{return n(C)}catch{return!1}}}else hV.exports=function(C){return!1};return hV.exports}var CD,bne;function Odt(){if(bne)return CD;bne=1;var e=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol",g=Mdt(),i=l4,I=Pdt(),n=Jdt(),r=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=C(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"),r(a,s==="default"?"number":s)},CD}var oD,yne;function _dt(){if(yne)return oD;yne=1;var e=Odt();return oD=function(i){return arguments.length>1?e(i,arguments[1]):e(i)},oD}var Xz=hr,Qve=qS(),jve,$ve,Hz,Tz;if(Qve){jve=Xz("Object.prototype.hasOwnProperty"),$ve=Xz("RegExp.prototype.exec"),Hz={};var aD=function(){throw Hz};Tz={toString:aD,valueOf:aD},typeof Symbol.toPrimitive=="symbol"&&(Tz[Symbol.toPrimitive]=aD)}var Ldt=Xz("Object.prototype.toString"),Udt=Object.getOwnPropertyDescriptor,Qdt="[object RegExp]",qve=Qve?function(g){if(!g||typeof g!="object")return!1;var i=Udt(g,"lastIndex"),I=i&&jve(i,"value");if(!I)return!1;try{$ve(g,Tz)}catch(n){return n===Hz}}:function(g){return!g||typeof g!="object"&&typeof g!="function"?!1:Ldt(g)===Qdt},AD,Zne;function jdt(){if(Zne)return AD;Zne=1;var e=hr,g=Hg,i=qve,I=e("RegExp.prototype.exec"),n=g("%TypeError%");return AD=function(C){if(!i(C))throw new n("`regex` must be a RegExp");return function(a){return I(C,a)!==null}},AD}var $dt=Hg,qdt=$dt("%TypeError%"),eht=function(g,i){if(g==null)throw new qdt(i||"Cannot call method on "+g);return g},z0=eht,eBe=Hg,tht=eBe("%String%"),ght=eBe("%TypeError%"),u4=function(g){if(typeof g=="symbol")throw new ght("Cannot convert a Symbol value to a string");return tht(g)},iht=z0,Iht=u4,nht=hr,Gne=nht("String.prototype.replace"),tBe=/^\s$/.test("᠎"),rht=tBe?/^[\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]+/,Cht=tBe?/[\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]+$/,gBe=function(){var g=Iht(iht(this));return Gne(Gne(g,rht,""),Cht,"")},oht=gBe,vne="​",Pm="᠎",iBe=function(){return String.prototype.trim&&vne.trim()===vne&&Pm.trim()===Pm&&("_"+Pm).trim()==="_"+Pm&&(Pm+"_").trim()===Pm+"_"?String.prototype.trim:oht},aht=Mn,Aht=iBe,sht=function(){var g=Aht();return aht(String.prototype,{trim:g},{trim:function(){return String.prototype.trim!==g}}),g},lht=Il,cht=Mn,uht=z0,dht=gBe,IBe=iBe,hht=sht,mht=lht(IBe()),nBe=function(g){return uht(g),mht(g)};cht(nBe,{getPolyfill:IBe,implementation:dht,shim:hht});var rBe=nBe,sD,Bne;function fht(){if(Bne)return sD;Bne=1;var e=Hg,g=e("%Number%"),i=e("%RegExp%"),I=e("%TypeError%"),n=e("%parseInt%"),r=hr,C=jdt(),o=r("String.prototype.slice"),a=C(/^0b[01]+$/i),s=C(/^0o[0-7]+$/i),A=C(/^[-+]0x[0-9a-f]+$/i),l=["…","​","￾"].join(""),c=new i("["+l+"]","g"),u=C(c),d=rBe,h=bn();return sD=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)},sD}var CBe=Hg,Sne=CBe("%TypeError%"),wne=CBe("%Number%"),pht=_ve(),bht=_dt(),yht=fht(),Zht=function(g){var i=pht(g)?g:bht(g,wne);if(typeof i=="symbol")throw new Sne("Cannot convert a Symbol value to a number");if(typeof i=="bigint")throw new Sne("Conversion from 'BigInt' to 'number' is not allowed.");return typeof i=="string"?yht(i):wne(i)},Ght=bn(),vht=Math.floor,Bht=function(g){return Ght(g)==="BigInt"?g:vht(g)},Sht=Hg,Rne=Bht,wht=Sht("%TypeError%"),Rht=function(g){if(typeof g!="number"&&typeof g!="bigint")throw new wht("argument must be a Number or a BigInt");var i=g<0?-Rne(-g):Rne(g);return i===0?0:i},Vht=Zht,Wht=Rht,Xht=NN,Hht=Vve,oBe=function(g){var i=Vht(g);return Xht(i)||i===0?0:Hht(i)?Wht(i):i},Vne=Jve,Tht=oBe,aBe=function(g){var i=Tht(g);return i<=0?0:i>Vne?Vne:i},lD,Wne;function ABe(){if(Wne)return lD;Wne=1;var e=Hg,g=e("%TypeError%"),i=$S,I=aBe,n=bn();return lD=function(C){if(n(C)!=="Object")throw new g("Assertion failed: `obj` must be an Object");return I(i(C,"length"))},lD}var Nht=Hg,Xne=Nht("%TypeError%"),kht=Jve,Yht=Ove(),Kht=Lve(),Fht=$S,Dht=Uve(),xht=a4(),Eht=ABe(),Hne=u4,Mht=function e(g,i,I,n,r){var C;arguments.length>5&&(C=arguments[5]);for(var o=n,a=0;a0&&(c=xht(l)),c){var u=Eht(l);o=e(g,l,u,o,r-1)}else{if(o>=kht)throw new Xne("index too large");Kht(g,Hne(o),l),o+=1}}a+=1}return o},zht=Hg,Pht=zht("%Object%"),Jht=z0,sBe=function(g){return Jht(g),Pht(g)},Oht=Pve,_ht=Mht,Lht=$S,Uht=oBe,Qht=aBe,jht=sBe,lBe=function(){var g=jht(this),i=Qht(Lht(g,"length")),I=1;arguments.length>0&&typeof arguments[0]<"u"&&(I=Uht(arguments[0]));var n=Oht(g,0);return _ht(n,g,i,0,I),n},$ht=lBe,cBe=function(){return Array.prototype.flat||$ht},cD,Tne;function qht(){if(Tne)return cD;Tne=1;var e=il,g=typeof Symbol=="function"&&typeof Symbol.unscopables=="symbol",i=g&&Array.prototype[Symbol.unscopables],I=TypeError;return cD=function(r){if(typeof r!="string"||!r)throw new I("method must be a non-empty string");if(!e(Array.prototype,r))throw new I("method must be on Array.prototype");g&&(i[r]=!0)},cD}var uD,Nne;function emt(){if(Nne)return uD;Nne=1;var e=Mn,g=qht(),i=cBe;return uD=function(){var n=i();return e(Array.prototype,{flat:n},{flat:function(){return Array.prototype.flat!==n}}),g("flat"),n},uD}var tmt=Mn,gmt=Il,imt=lBe,uBe=cBe,Imt=uBe(),nmt=emt(),dBe=gmt(Imt);tmt(dBe,{getPolyfill:uBe,implementation:imt,shim:nmt});var ew=dBe,kne={}.hasOwnProperty,dD=Function.prototype.call,P0=dD.bind?dD.bind(kne):function(e,g){return dD.call(kne,e,g)},tw={},Nz={exports:{}},Yne=function(e){return e!==e},hBe=function(g,i){return g===0&&i===0?1/g===1/i:!!(g===i||Yne(g)&&Yne(i))},rmt=hBe,mBe=function(){return typeof Object.is=="function"?Object.is:rmt},Cmt=mBe,omt=Mn,amt=function(){var g=Cmt();return omt(Object,{is:g},{is:function(){return Object.is!==g}}),g},Amt=Mn,smt=Il,lmt=hBe,fBe=mBe,cmt=amt,pBe=smt(fBe(),Object);Amt(pBe,{getPolyfill:fBe,implementation:lmt,shim:cmt});var d4=pBe;(function(e,g){Object.defineProperty(g,"__esModule",{value:!0}),g.default=C;var i=n(d4),I=n(P0);function n(o){return o&&o.__esModule?o:{default:o}}function r(o){"@babel/helpers - typeof";return r=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},r(o)}function C(o,a){if((0,i.default)(o,a))return!0;if(!o||!a||r(o)!=="object"||r(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=hD(g);return(i===Fmt||i===Kmt)&&g("")==null}catch{}return!1})}var HBe=function(){if(XBe(this)||!Nmt(this)&&!RBe(this))throw new TypeError("Function.prototype.name sham getter called on non-function");if(Hmt&&Xmt(this,"name"))return this.name;if(this===Dmt)return"";var g=VBe(this),i=WBe(g,kmt),I=i&&i[1];return I},Emt=HBe,TBe=function(){return Emt},Mmt=Mn.supportsDescriptors,zmt=wBe(),Pmt=TBe,Fne=Object.defineProperty,Jmt=TypeError,Omt=function(){var g=Pmt();if(zmt)return g;if(!Mmt)throw new Jmt("Shimming Function.prototype.name support requires ES5 property descriptor support.");var i=Function.prototype;return Fne(i,"name",{configurable:!0,enumerable:!1,get:function(){var I=g.call(this);return this!==i&&Fne(this,"name",{configurable:!0,enumerable:!1,value:I,writable:!1}),I}}),g},_mt=Mn,Lmt=Il,NBe=HBe,Umt=TBe,Qmt=Omt,kBe=Lmt(NBe);_mt(kBe,{getPolyfill:Umt,implementation:NBe,shim:Qmt});var m4=kBe,YBe={},KBe={};Object.defineProperty(KBe,"__esModule",{value:!0});var FN={},J0={},NX=$e&&$e.__assign||function(){return NX=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}(f4);cg.NodeWithChildren=xN;var EBe=function(e){Au(g,e);function g(){var i=e!==null&&e.apply(this,arguments)||this;return i.type=xr.ElementType.CDATA,i}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 4},enumerable:!1,configurable:!0}),g}(xN);cg.CDATA=EBe;var MBe=function(e){Au(g,e);function g(){var i=e!==null&&e.apply(this,arguments)||this;return i.type=xr.ElementType.Root,i}return Object.defineProperty(g.prototype,"nodeType",{get:function(){return 9},enumerable:!1,configurable:!0}),g}(xN);cg.Document=MBe;var zBe=function(e){Au(g,e);function g(i,I,n,r){n===void 0&&(n=[]),r===void 0&&(r=i==="script"?xr.ElementType.Script:i==="style"?xr.ElementType.Style:xr.ElementType.Tag);var C=e.call(this,n)||this;return C.name=i,C.attribs=I,C.type=r,C}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,r;return{name:I,value:i.attribs[I],namespace:(n=i["x-attribsNamespace"])===null||n===void 0?void 0:n[I],prefix:(r=i["x-attribsPrefix"])===null||r===void 0?void 0:r[I]}})},enumerable:!1,configurable:!0}),g}(xN);cg.Element=zBe;function PBe(e){return(0,xr.isTag)(e)}cg.isTag=PBe;function JBe(e){return e.type===xr.ElementType.CDATA}cg.isCDATA=JBe;function OBe(e){return e.type===xr.ElementType.Text}cg.isText=OBe;function _Be(e){return e.type===xr.ElementType.Comment}cg.isComment=_Be;function LBe(e){return e.type===xr.ElementType.Directive}cg.isDirective=LBe;function UBe(e){return e.type===xr.ElementType.Root}cg.isDocument=UBe;function qmt(e){return Object.prototype.hasOwnProperty.call(e,"children")}cg.hasChildren=qmt;function p4(e,g){g===void 0&&(g=!1);var i;if(OBe(e))i=new FBe(e.data);else if(_Be(e))i=new DBe(e.data);else if(PBe(e)){var I=g?mD(e.children):[],n=new zBe(e.name,QG({},e.attribs),I);I.forEach(function(a){return a.parent=n}),e.namespace!=null&&(n.namespace=e.namespace),e["x-attribsNamespace"]&&(n["x-attribsNamespace"]=QG({},e["x-attribsNamespace"])),e["x-attribsPrefix"]&&(n["x-attribsPrefix"]=QG({},e["x-attribsPrefix"])),i=n}else if(JBe(e)){var I=g?mD(e.children):[],r=new EBe(I);I.forEach(function(s){return s.parent=r}),i=r}else if(UBe(e)){var I=g?mD(e.children):[],C=new MBe(I);I.forEach(function(s){return s.parent=C}),e["x-mode"]&&(C["x-mode"]=e["x-mode"]),i=C}else if(LBe(e)){var o=new xBe(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}cg.cloneNode=p4;function mD(e){for(var g=e.map(function(I){return p4(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 y4={};Object.defineProperty(y4,"__esModule",{value:!0});y4.default=new Uint16Array("Ȁaglq \x1Bɭ\0\0p;䀦os;䀧t;䀾t;䀼uot;䀢".split("").map(function(e){return e.charCodeAt(0)}));var kz={};(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(r){var C="";return r>65535&&(r-=65536,C+=String.fromCharCode(r>>>10&1023|55296),r=56320|r&1023),C+=String.fromCharCode(r),C};function I(r){var C;return r>=55296&&r<=57343||r>1114111?65533:(C=i.get(r))!==null&&C!==void 0?C:r}e.replaceCodePoint=I;function n(r){return(0,e.fromCodePoint)(I(r))}e.default=n})(kz);(function(e){var g=$e&&$e.__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=$e&&$e.__setModuleDefault||(Object.create?function(S,X){Object.defineProperty(S,"default",{enumerable:!0,value:X})}:function(S,X){S.default=X}),I=$e&&$e.__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=$e&&$e.__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 r=n(b4);e.htmlDecodeTree=r.default;var C=n(y4);e.xmlDecodeTree=C.default;var o=I(kz);e.decodeCodePoint=o.default;var a=kz;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,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 Y=V-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 V=W;W>14;W>14,Y!==0){if(K===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,V=W.result,H=W.decodeTree,Y=(H[V]&l.VALUE_LENGTH)>>14;return this.emitNamedEntityData(V,Y,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}();e.EntityDecoder=b;function p(S){var X="",W=new b(S,function(V){return X+=(0,o.fromCodePoint)(V)});return function(H,Y){for(var K=0,x=0;(x=H.indexOf("&",x))>=0;){X+=H.slice(K,x),W.startEntity(Y);var J=W.write(H,x+1);if(J<0){K=x+W.end();break}K=x+J,x=J===0?K+1:K}var P=X+H.slice(K);return X="",P}}function y(S,X,W,V){var H=(X&l.BRANCH_LENGTH)>>7,Y=X&l.JUMP_TABLE;if(H===0)return Y!==0&&V===Y?W:-1;if(Y){var K=V-Y;return K<0||K>=H?-1:S[W+K]-1}for(var x=W,J=x+H-1;x<=J;){var P=x+J>>>1,ge=S[P];if(geV)J=P-1;else return S[P+H]}return-1}e.determineBranch=y;var Z=p(r.default),B=p(C.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 R(S){return B(S,f.Strict)}e.decodeXML=R})(sh);var lh={},Z4={};Object.defineProperty(Z4,"__esModule",{value:!0});function mV(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,r){return n.codePointAt(r)}:function(n,r){return(n.charCodeAt(r)&64512)===55296?(n.charCodeAt(r)-55296)*1024+n.charCodeAt(r+1)-56320+65536:n.charCodeAt(r)};function i(n){for(var r="",C=0,o;(o=e.xmlReplacer.exec(n))!==null;){var a=o.index,s=n.charCodeAt(a),A=g.get(s);A!==void 0?(r+=n.substring(C,a)+A,C=a+1):(r+="".concat(n.substring(C,a),"&#x").concat((0,e.getCodePoint)(n,a).toString(16),";"),C=e.xmlReplacer.lastIndex+=+((s&64512)===55296))}return r+n.substr(C)}e.encodeXML=i,e.escape=i;function I(n,r){return function(o){for(var a,s=0,A="";a=n.exec(o);)s!==a.index&&(A+=o.substring(s,a.index)),A+=r.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," "]]))})(Fb);var eft=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(lh,"__esModule",{value:!0});lh.encodeNonAsciiHTML=lh.encodeHTML=void 0;var tft=eft(Z4),jBe=Fb,gft=/[\t\n!-,./:-@[-`\f{-}$\x80-\uFFFF]/g;function ift(e){return $Be(gft,e)}lh.encodeHTML=ift;function Ift(e){return $Be(jBe.xmlReplacer,e)}lh.encodeNonAsciiHTML=Ift;function $Be(e,g){for(var i="",I=0,n;(n=e.exec(g))!==null;){var r=n.index;i+=g.substring(I,r);var C=g.charCodeAt(r),o=tft.default.get(C);if(typeof o=="object"){if(r+10&&(I+=EN(e.children,g)),(g.xmlMode||!xne.has(e.name))&&(I+=""))),I}function dft(e){return"<".concat(e.data,">")}function hft(e,g){var i,I=e.data||"";return((i=g.encodeEntities)!==null&&i!==void 0?i:g.decodeEntities)!==!1&&!(!g.xmlMode&&e.parent&&oft.has(e.parent.name))&&(I=g.xmlMode||g.encodeEntities!=="utf8"?(0,kX.encodeXML)(I):(0,kX.escapeText)(I)),I}function mft(e){return"")}function fft(e){return"")}var pft=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(nC,"__esModule",{value:!0});nC.innerText=nC.textContent=nC.getText=nC.getInnerHTML=nC.getOuterHTML=void 0;var uA=En,bft=pft(_0),yft=O0;function eSe(e,g){return(0,bft.default)(e,g)}nC.getOuterHTML=eSe;function Zft(e,g){return(0,uA.hasChildren)(e)?e.children.map(function(i){return eSe(i,g)}).join(""):""}nC.getInnerHTML=Zft;function tW(e){return Array.isArray(e)?e.map(tW).join(""):(0,uA.isTag)(e)?e.name==="br"?` +`:tW(e.children):(0,uA.isCDATA)(e)?tW(e.children):(0,uA.isText)(e)?e.data:""}nC.getText=tW;function Yz(e){return Array.isArray(e)?e.map(Yz).join(""):(0,uA.hasChildren)(e)&&!(0,uA.isComment)(e)?Yz(e.children):(0,uA.isText)(e)?e.data:""}nC.textContent=Yz;function Kz(e){return Array.isArray(e)?e.map(Kz).join(""):(0,uA.hasChildren)(e)&&(e.type===yft.ElementType.Tag||(0,uA.isCDATA)(e))?Kz(e.children):(0,uA.isText)(e)?e.data:""}nC.innerText=Kz;var _I={};Object.defineProperty(_I,"__esModule",{value:!0});_I.prevElementSibling=_I.nextElementSibling=_I.getName=_I.hasAttrib=_I.getAttributeValue=_I.getSiblings=_I.getParent=_I.getChildren=void 0;var G4=En;function tSe(e){return(0,G4.hasChildren)(e)?e.children:[]}_I.getChildren=tSe;function gSe(e){return e.parent||null}_I.getParent=gSe;function Gft(e){var g,i,I=gSe(e);if(I!=null)return tSe(I);for(var n=[e],r=e.prev,C=e.next;r!=null;)n.unshift(r),g=r,r=g.prev;for(;C!=null;)n.push(C),i=C,C=i.next;return n}_I.getSiblings=Gft;function vft(e,g){var i;return(i=e.attribs)===null||i===void 0?void 0:i[g]}_I.getAttributeValue=vft;function Bft(e,g){return e.attribs!=null&&Object.prototype.hasOwnProperty.call(e.attribs,g)&&e.attribs[g]!=null}_I.hasAttrib=Bft;function Sft(e){return e.name}_I.getName=Sft;function wft(e){for(var g,i=e.next;i!==null&&!(0,G4.isTag)(i);)g=i,i=g.next;return i}_I.nextElementSibling=wft;function Rft(e){for(var g,i=e.prev;i!==null&&!(0,G4.isTag)(i);)g=i,i=g.prev;return i}_I.prevElementSibling=Rft;var Xr={};Object.defineProperty(Xr,"__esModule",{value:!0});Xr.prepend=Xr.prependChild=Xr.append=Xr.appendChild=Xr.replaceElement=Xr.removeElement=void 0;function gw(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}Xr.removeElement=gw;function Vft(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 r=n.children;r[r.lastIndexOf(e)]=g,e.parent=null}}Xr.replaceElement=Vft;function Wft(e,g){if(gw(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}Xr.appendChild=Wft;function Xft(e,g){gw(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)}Xr.append=Xft;function Hft(e,g){if(gw(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}Xr.prependChild=Hft;function Tft(e,g){gw(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}Xr.prepend=Tft;var Un={};Object.defineProperty(Un,"__esModule",{value:!0});Un.findAll=Un.existsOne=Un.findOne=Un.findOneChild=Un.find=Un.filter=void 0;var MN=En;function Nft(e,g,i,I){return i===void 0&&(i=!0),I===void 0&&(I=1/0),iSe(e,Array.isArray(g)?g:[g],i,I)}Un.filter=Nft;function iSe(e,g,i,I){for(var n=[],r=[g],C=[0];;){if(C[0]>=r[0].length){if(C.length===1)return n;r.shift(),C.shift();continue}var o=r[0][C[0]++];if(e(o)&&(n.push(o),--I<=0))return n;i&&(0,MN.hasChildren)(o)&&o.children.length>0&&(C.unshift(0),r.unshift(o.children))}}Un.find=iSe;function kft(e,g){return g.find(e)}Un.findOneChild=kft;function ISe(e,g,i){i===void 0&&(i=!0);for(var I=null,n=0;n0&&(I=ISe(e,r.children,!0));else continue}return I}Un.findOne=ISe;function nSe(e,g){return g.some(function(i){return(0,MN.isTag)(i)&&(e(i)||nSe(e,i.children))})}Un.existsOne=nSe;function Yft(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 r=I[0][n[0]++];(0,MN.isTag)(r)&&(e(r)&&i.push(r),r.children.length>0&&(n.unshift(0),I.unshift(r.children)))}}Un.findAll=Yft;var rC={};Object.defineProperty(rC,"__esModule",{value:!0});rC.getElementsByTagType=rC.getElementsByTagName=rC.getElementById=rC.getElements=rC.testElement=void 0;var Id=En,zN=Un,YX={tag_name:function(e){return typeof e=="function"?function(g){return(0,Id.isTag)(g)&&e(g.name)}:e==="*"?Id.isTag:function(g){return(0,Id.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,Id.isText)(g)&&e(g.data)}:function(g){return(0,Id.isText)(g)&&g.data===e}}};function rSe(e,g){return typeof g=="function"?function(i){return(0,Id.isTag)(i)&&g(i.attribs[e])}:function(i){return(0,Id.isTag)(i)&&i.attribs[e]===g}}function Kft(e,g){return function(i){return e(i)||g(i)}}function CSe(e){var g=Object.keys(e).map(function(i){var I=e[i];return Object.prototype.hasOwnProperty.call(YX,i)?YX[i](I):rSe(i,I)});return g.length===0?null:g.reduce(Kft)}function Fft(e,g){var i=CSe(e);return i?i(g):!0}rC.testElement=Fft;function Dft(e,g,i,I){I===void 0&&(I=1/0);var n=CSe(e);return n?(0,zN.filter)(n,g,i,I):[]}rC.getElements=Dft;function xft(e,g,i){return i===void 0&&(i=!0),Array.isArray(g)||(g=[g]),(0,zN.findOne)(rSe("id",e),g,i)}rC.getElementById=xft;function Eft(e,g,i,I){return i===void 0&&(i=!0),I===void 0&&(I=1/0),(0,zN.filter)(YX.tag_name(e),g,i,I)}rC.getElementsByTagName=Eft;function Mft(e,g,i,I){return i===void 0&&(i=!0),I===void 0&&(I=1/0),(0,zN.filter)(YX.tag_type(e),g,i,I)}rC.getElementsByTagType=Mft;var oSe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.uniqueSort=e.compareDocumentPosition=e.DocumentPosition=e.removeSubsets=void 0;var g=En;function i(C){for(var o=C.length;--o>=0;){var a=C[o];if(o>0&&C.lastIndexOf(a,o-1)>=0){C.splice(o,1);continue}for(var s=a.parent;s;s=s.parent)if(C.includes(s)){C.splice(o,1);break}}return C}e.removeSubsets=i;var I;(function(C){C[C.DISCONNECTED=1]="DISCONNECTED",C[C.PRECEDING=2]="PRECEDING",C[C.FOLLOWING=4]="FOLLOWING",C[C.CONTAINS=8]="CONTAINS",C[C.CONTAINED_BY=16]="CONTAINED_BY"})(I=e.DocumentPosition||(e.DocumentPosition={}));function n(C,o){var a=[],s=[];if(C===o)return 0;for(var A=(0,g.hasChildren)(C)?C:C.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===C?I.PRECEDING|I.CONTAINS:I.PRECEDING}e.compareDocumentPosition=n;function r(C){return C=C.filter(function(o,a,s){return!s.includes(o,a+1)}),C.sort(function(o,a){var s=n(o,a);return s&I.PRECEDING?-1:s&I.FOLLOWING?1:0}),C}e.uniqueSort=r})(oSe);var PN={};Object.defineProperty(PN,"__esModule",{value:!0});PN.getFeed=void 0;var zft=nC,iw=rC;function Pft(e){var g=KX(Uft,e);return g?g.name==="feed"?Jft(g):Oft(g):null}PN.getFeed=Pft;function Jft(e){var g,i=e.children,I={type:"atom",items:(0,iw.getElementsByTagName)("entry",i).map(function(C){var o,a=C.children,s={media:aSe(a)};Rr(s,"id","id",a),Rr(s,"title","title",a);var A=(o=KX("link",a))===null||o===void 0?void 0:o.attribs.href;A&&(s.link=A);var l=hc("summary",a)||hc("content",a);l&&(s.description=l);var c=hc("updated",a);return c&&(s.pubDate=new Date(c)),s})};Rr(I,"id","id",i),Rr(I,"title","title",i);var n=(g=KX("link",i))===null||g===void 0?void 0:g.attribs.href;n&&(I.link=n),Rr(I,"description","subtitle",i);var r=hc("updated",i);return r&&(I.updated=new Date(r)),Rr(I,"author","email",i,!0),I}function Oft(e){var g,i,I=(i=(g=KX("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,iw.getElementsByTagName)("item",e.children).map(function(C){var o=C.children,a={media:aSe(o)};Rr(a,"id","guid",o),Rr(a,"title","title",o),Rr(a,"link","link",o),Rr(a,"description","description",o);var s=hc("pubDate",o)||hc("dc:date",o);return s&&(a.pubDate=new Date(s)),a})};Rr(n,"title","title",I),Rr(n,"link","link",I),Rr(n,"description","description",I);var r=hc("lastBuildDate",I);return r&&(n.updated=new Date(r)),Rr(n,"author","managingEditor",I,!0),n}var _ft=["url","type","lang"],Lft=["fileSize","bitrate","framerate","samplingrate","channels","duration","height","width"];function aSe(e){return(0,iw.getElementsByTagName)("media:content",e).map(function(g){for(var i=g.attribs,I={medium:i.medium,isDefault:!!i.isDefault},n=0,r=_ft;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})(su);Object.defineProperty(hI,"__esModule",{value:!0});hI.toggleClass=hI.removeClass=hI.addClass=hI.hasClass=hI.removeAttr=hI.val=hI.data=hI.prop=hI.attr=void 0;var sSe=aI,Pg=su,Mne=ra,Fp=Object.prototype.hasOwnProperty,MB=/\s+/,fD="data-",zne={null:null,true:!0,false:!1},v4=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,opt=/^{[^]*}$|^\[[^]*]$/;function FX(e,g,i){var I;if(!(!e||!(0,Pg.isTag)(e))){if((I=e.attribs)!==null&&I!==void 0||(e.attribs={}),!g)return e.attribs;if(Fp.call(e.attribs,g))return!i&&v4.test(g)?g:e.attribs[g];if(e.name==="option"&&g==="value")return(0,sSe.text)(e.children);if(e.name==="input"&&(e.attribs.type==="radio"||e.attribs.type==="checkbox")&&g==="value")return"on"}}function Dp(e,g,i){i===null?lSe(e,g):e.attribs[g]="".concat(i)}function apt(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,Pg.domEach)(this,function(i,I){(0,Pg.isTag)(i)&&Dp(i,e,g.call(i,I,i.attribs[e]))})}return(0,Pg.domEach)(this,function(i){(0,Pg.isTag)(i)&&(typeof e=="object"?Object.keys(e).forEach(function(I){var n=e[I];Dp(i,I,n)}):Dp(i,e,g))})}return arguments.length>1?this:FX(this[0],e,this.options.xmlMode)}hI.attr=apt;function Pne(e,g,i){return g in e?e[g]:!i&&v4.test(g)?FX(e,g,!1)!==void 0:FX(e,g,i)}function pD(e,g,i,I){g in e?e[g]=i:Dp(e,g,!I&&v4.test(g)?i?"":null:"".concat(i))}function Apt(e,g){var i=this,I;if(typeof e=="string"&&g===void 0){var n=this[0];if(!n||!(0,Pg.isTag)(n))return;switch(e){case"style":{var r=this.css(),C=Object.keys(r);return C.forEach(function(a,s){r[s]=a}),r.length=C.length,r}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,Mne.innerText)(n);case"textContent":return(0,Mne.textContent)(n);case"outerHTML":return this.clone().wrap("").parent().html();case"innerHTML":return this.html();default:return Pne(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,Pg.domEach)(this,function(a,s){(0,Pg.isTag)(a)&&pD(a,e,g.call(a,s,Pne(a,e,i.options.xmlMode)),i.options.xmlMode)})}return(0,Pg.domEach)(this,function(a){(0,Pg.isTag)(a)&&(typeof e=="object"?Object.keys(e).forEach(function(s){var A=e[s];pD(a,s,A,i.options.xmlMode)}):pD(a,e,g,i.options.xmlMode))})}}hI.prop=Apt;function Jne(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 One(e,g){var i,I,n;g==null?(i=Object.keys(e.attribs).filter(function(a){return a.startsWith(fD)}),I=i.map(function(a){return(0,Pg.camelCase)(a.slice(fD.length))})):(i=[fD+(0,Pg.cssCase)(g)],I=[g]);for(var r=0;r-1;){var n=I+e.length;if((I===0||MB.test(i[I-1]))&&(n===i.length||MB.test(i[n])))return!0}return!1})}hI.hasClass=upt;function cSe(e){if(typeof e=="function")return(0,Pg.domEach)(this,function(s,A){if((0,Pg.isTag)(s)){var l=s.attribs.class||"";cSe.call([s],e.call(s,A,l))}});if(!e||typeof e!="string")return this;for(var g=e.split(MB),i=this.length,I=0;I=0&&(r.splice(a,1),C=!0,o--)}C&&(n.attribs.class=r.join(" "))}})}hI.removeClass=uSe;function dSe(e,g){if(typeof e=="function")return(0,Pg.domEach)(this,function(l,c){(0,Pg.isTag)(l)&&dSe.call([l],e.call(l,c,l.attribs.class||"",g),g)});if(!e||typeof e!="string")return this;for(var i=e.split(MB),I=i.length,n=typeof g=="boolean"?g?1:-1:0,r=this.length,C=0;C=0&&A<0?a.push(i[s]):n<=0&&A>=0&&a.splice(A,1)}o.attribs.class=a.join(" ")}}return this}hI.toggleClass=dSe;var Vt={},hSe={},Zg;(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"})(Zg||(Zg={}));const dpt={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 _ne=/^[^\\#]?(?:\\(?:[\da-f]{1,6}\s?|.)|[\w\-\u00b0-\uFFFF])+/,hpt=/\\([\da-f]{1,6}\s?|(\s)|.)/gi,mpt=new Map([[126,Vi.Element],[94,Vi.Start],[36,Vi.End],[42,Vi.Any],[33,Vi.Not],[124,Vi.Hyphen]]),fpt=new Set(["has","not","matches","is","where","host","host-context"]);function mSe(e){switch(e.type){case Zg.Adjacent:case Zg.Child:case Zg.Descendant:case Zg.Parent:case Zg.Sibling:case Zg.ColumnCombinator:return!0;default:return!1}}const ppt=new Set(["contains","icontains"]);function bpt(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 nZ(e){return e.replace(hpt,bpt)}function bD(e){return e===39||e===34}function Lne(e){return e===32||e===9||e===10||e===12||e===13}function ypt(e){const g=[],i=fSe(g,`${e}`,0);if(i0&&i0&&mSe(I[I.length-1]))throw new Error("Did not expect successive traversals.")}function s(c){if(I.length>0&&I[I.length-1].type===Zg.Descendant){I[I.length-1].type=c;return}a(),I.push({type:c})}function A(c,u){I.push({type:Zg.Attribute,name:c,action:u,value:n(1),namespace:null,ignoreCase:"quirks"})}function l(){if(I.length&&I[I.length-1].type===Zg.Descendant&&I.pop(),I.length===0)throw new Error("Empty sub-selector");e.push(I)}if(r(0),g.length===i)return i;e:for(;ie.charCodeAt(0))),Une=new Set(bSe.map(e=>e.charCodeAt(0))),Cp=new Set([...bSe,"~","^","$","*","+","!","|",":","[","]"," ","."].map(e=>e.charCodeAt(0)));function ySe(e){return e.map(g=>g.map(Gpt).join("")).join(", ")}function Gpt(e,g,i){switch(e.type){case Zg.Child:return g===0?"> ":" > ";case Zg.Parent:return g===0?"< ":" < ";case Zg.Sibling:return g===0?"~ ":" ~ ";case Zg.Adjacent:return g===0?"+ ":" + ";case Zg.Descendant:return" ";case Zg.ColumnCombinator:return g===0?"|| ":" || ";case Zg.Universal:return e.namespace==="*"&&g+10?I+e.slice(i):e}const Bpt=Object.freeze(Object.defineProperty({__proto__:null,get AttributeAction(){return Vi},IgnoreCaseMode:dpt,get SelectorType(){return Zg},isTraversal:mSe,parse:ypt,stringify:ySe},Symbol.toStringTag,{value:"Module"})),Iw=qs(Bpt);var Dz={},om={trueFunc:function(){return!0},falseFunc:function(){return!1}},Tc={},L0={};Object.defineProperty(L0,"__esModule",{value:!0});L0.isTraversal=void 0;var iC=Iw,GSe=new Map([[iC.SelectorType.Universal,50],[iC.SelectorType.Tag,30],[iC.SelectorType.Attribute,1],[iC.SelectorType.Pseudo,0]]);function Spt(e){return!GSe.has(e.type)}L0.isTraversal=Spt;var wpt=new Map([[iC.AttributeAction.Exists,10],[iC.AttributeAction.Equals,8],[iC.AttributeAction.Not,7],[iC.AttributeAction.Start,6],[iC.AttributeAction.End,6],[iC.AttributeAction.Any,5]]);function Rpt(e){for(var g=e.map(vSe),i=1;i=0&&I>=1)):e.type===iC.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(vSe))})),I<0&&(I=0)):I=2:I=3),I}var ON={},_N={},Vpt=$e&&$e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_N,"__esModule",{value:!0});_N.attributeRules=void 0;var fV=Vpt(om),Wpt=/[-[\]{}()*+?.,\\^$|#\s]/g;function jne(e){return e.replace(Wpt,"\\$&")}var Xpt=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 Tu(e,g){return typeof e.ignoreCase=="boolean"?e.ignoreCase:e.ignoreCase==="quirks"?!!g.quirksMode:!g.xmlMode&&Xpt.has(e.name)}_N.attributeRules={equals:function(e,g,i){var I=i.adapter,n=g.name,r=g.value;return Tu(g,i)?(r=r.toLowerCase(),function(C){var o=I.getAttributeValue(C,n);return o!=null&&o.length===r.length&&o.toLowerCase()===r&&e(C)}):function(C){return I.getAttributeValue(C,n)===r&&e(C)}},hyphen:function(e,g,i){var I=i.adapter,n=g.name,r=g.value,C=r.length;return Tu(g,i)?(r=r.toLowerCase(),function(a){var s=I.getAttributeValue(a,n);return s!=null&&(s.length===C||s.charAt(C)==="-")&&s.substr(0,C).toLowerCase()===r&&e(a)}):function(a){var s=I.getAttributeValue(a,n);return s!=null&&(s.length===C||s.charAt(C)==="-")&&s.substr(0,C)===r&&e(a)}},element:function(e,g,i){var I=i.adapter,n=g.name,r=g.value;if(/\s/.test(r))return fV.default.falseFunc;var C=new RegExp("(?:^|\\s)".concat(jne(r),"(?:$|\\s)"),Tu(g,i)?"i":"");return function(a){var s=I.getAttributeValue(a,n);return s!=null&&s.length>=r.length&&C.test(s)&&e(a)}},exists:function(e,g,i){var I=g.name,n=i.adapter;return function(r){return n.hasAttrib(r,I)&&e(r)}},start:function(e,g,i){var I=i.adapter,n=g.name,r=g.value,C=r.length;return C===0?fV.default.falseFunc:Tu(g,i)?(r=r.toLowerCase(),function(o){var a=I.getAttributeValue(o,n);return a!=null&&a.length>=C&&a.substr(0,C).toLowerCase()===r&&e(o)}):function(o){var a;return!!(!((a=I.getAttributeValue(o,n))===null||a===void 0)&&a.startsWith(r))&&e(o)}},end:function(e,g,i){var I=i.adapter,n=g.name,r=g.value,C=-r.length;return C===0?fV.default.falseFunc:Tu(g,i)?(r=r.toLowerCase(),function(o){var a;return((a=I.getAttributeValue(o,n))===null||a===void 0?void 0:a.substr(C).toLowerCase())===r&&e(o)}):function(o){var a;return!!(!((a=I.getAttributeValue(o,n))===null||a===void 0)&&a.endsWith(r))&&e(o)}},any:function(e,g,i){var I=i.adapter,n=g.name,r=g.value;if(r==="")return fV.default.falseFunc;if(Tu(g,i)){var C=new RegExp(jne(r),"i");return function(a){var s=I.getAttributeValue(a,n);return s!=null&&s.length>=r.length&&C.test(s)&&e(a)}}return function(o){var a;return!!(!((a=I.getAttributeValue(o,n))===null||a===void 0)&&a.includes(r))&&e(o)}},not:function(e,g,i){var I=i.adapter,n=g.name,r=g.value;return r===""?function(C){return!!I.getAttributeValue(C,n)&&e(C)}:Tu(g,i)?(r=r.toLowerCase(),function(C){var o=I.getAttributeValue(C,n);return(o==null||o.length!==r.length||o.toLowerCase()!==r)&&e(C)}):function(C){return I.getAttributeValue(C,n)!==r&&e(C)}}};var B4={},BSe={},SSe={},LN={};Object.defineProperty(LN,"__esModule",{value:!0});LN.parse=void 0;var Hpt=new Set([9,10,12,13,32]),$ne="0".charCodeAt(0),Tpt="9".charCodeAt(0);function Npt(e){if(e=e.trim().toLowerCase(),e==="even")return[2,0];if(e==="odd")return[2,1];var g=0,i=0,I=r(),n=C();if(g=$ne&&e.charCodeAt(g)<=Tpt;)s=s*10+(e.charCodeAt(g)-$ne),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(r){return r>=i&&r%I===n}:function(r){return r<=i&&r%I===n}}xb.compile=Ypt;function Kpt(e){var g=e[0],i=e[1]-1,I=0;if(g<0){var n=-g,r=(i%n+n)%n;return function(){var C=r+n*I++;return C>i?null:C}}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})}xb.generate=Kpt;(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.sequence=e.generate=e.compile=e.parse=void 0;var g=LN;Object.defineProperty(e,"parse",{enumerable:!0,get:function(){return g.parse}});var i=xb;Object.defineProperty(e,"compile",{enumerable:!0,get:function(){return i.compile}}),Object.defineProperty(e,"generate",{enumerable:!0,get:function(){return i.generate}});function I(r){return(0,i.compile)((0,g.parse)(r))}e.default=I;function n(r){return(0,i.generate)((0,g.parse)(r))}e.sequence=n})(SSe);(function(e){var g=$e&&$e.__importDefault||function(C){return C&&C.__esModule?C:{default:C}};Object.defineProperty(e,"__esModule",{value:!0}),e.filters=void 0;var i=g(SSe),I=g(om);function n(C,o){return function(a){var s=o.getParent(a);return s!=null&&o.isTag(s)&&C(a)}}e.filters={contains:function(C,o,a){var s=a.adapter;return function(l){return C(l)&&s.getText(l).includes(o)}},icontains:function(C,o,a){var s=a.adapter,A=o.toLowerCase();return function(c){return C(c)&&s.getText(c).toLowerCase().includes(A)}},"nth-child":function(C,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(C,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)&&C(u)}},"nth-of-type":function(C,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(C,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)&&C(u)}},root:function(C,o,a){var s=a.adapter;return function(A){var l=s.getParent(A);return(l==null||!s.isTag(l))&&C(A)}},scope:function(C,o,a,s){var A=a.equals;return!s||s.length===0?e.filters.root(C,o,a):s.length===1?function(l){return A(s[0],l)&&C(l)}:function(l){return s.includes(l)&&C(l)}},hover:r("isHovered"),visited:r("isVisited"),active:r("isActive")};function r(C){return function(a,s,A){var l=A.adapter,c=l[C];return typeof c!="function"?I.default.falseFunc:function(d){return c(d)&&a(d)}}}})(BSe);var Eb={};Object.defineProperty(Eb,"__esModule",{value:!0});Eb.verifyPseudoArgs=Eb.pseudos=void 0;Eb.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(r){return i.isTag(r)});return n!=null&&I(e,n)},"last-child":function(e,g){for(var i=g.adapter,I=g.equals,n=i.getSiblings(e),r=n.length-1;r>=0;r--){if(I(e,n[r]))return!0;if(i.isTag(n[r]))break}return!1},"first-of-type":function(e,g){for(var i=g.adapter,I=g.equals,n=i.getSiblings(e),r=i.getName(e),C=0;C=0;C--){var o=n[C];if(I(e,o))return!0;if(i.isTag(o)&&i.getName(o)===r)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(r){return I(e,r)||!i.isTag(r)||i.getName(r)!==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 Fpt(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"))}Eb.verifyPseudoArgs=Fpt;var UN={};Object.defineProperty(UN,"__esModule",{value:!0});UN.aliases=void 0;UN.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 _N={};(function(e){var g=$e&&$e.__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=fD(l,C);)if(e(l))return!0;return!1};var a=new WeakSet;return function(A){for(var l=A;l=fD(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=fD(l,C));return!1};case bo.SelectorType.Parent:return function(A){return C.getChildren(A).some(function(l){return C.isTag(l)&&e(l)})};case bo.SelectorType.Child:return function(A){var l=C.getParent(A);return l!=null&&C.isTag(l)&&e(l)};case bo.SelectorType.Sibling:return function(A){for(var l=C.getSiblings(A),c=0;c0&&(0,kz.isTraversal)(o[0])&&o[0].type!==ms.SelectorType.Descendant))if(n&&!o.some(ySe))o.unshift(Ept);else continue;o.unshift(zpt)}}function bj(e,g,I){var i;e.forEach(kz.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)Ppt(e,g,C);else if(e.some(function(a){return a.length>0&&(0,kz.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!==ms.SelectorType.Pseudo||s.name!=="scope"||(n&&A.type===ms.SelectorType.Descendant?a[1]=Mpt:(A.type===ms.SelectorType.Adjacent||A.type===ms.SelectorType.Sibling)&&(r=!0))}return Jpt(a,g,C)}).reduce(Opt,mc.default.falseFunc);return o.shouldTestNextSiblings=r,o}Tc.compileToken=bj;function Jpt(e,g,I){var i;return e.reduce(function(n,C){return n===mc.default.falseFunc?mc.default.falseFunc:(0,Dpt.compileGeneralSelector)(n,C,g,I,bj)},(i=g.rootFunc)!==null&&i!==void 0?i:mc.default.trueFunc)}function Opt(e,g){return g===mc.default.falseFunc||e===mc.default.trueFunc?e:e===mc.default.falseFunc||g===mc.default.trueFunc?g:function(i){return e(i)||g(i)}}(function(e){var g=$e&&$e.__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=$e&&$e.__setModuleDefault||(Object.create?function(b,p){Object.defineProperty(b,"default",{enumerable:!0,value:p})}:function(b,p){b.default=p}),i=$e&&$e.__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=$e&&$e.__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(Ca),r=n(am),o=Tc,a=_N,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})(yj);Object.defineProperty(Eb,"__esModule",{value:!0});Eb.groupSelectors=Eb.getDocumentRoot=void 0;var _pt=yj;function Lpt(e){for(;e.parent;)e=e.parent;return e}Eb.getDocumentRoot=Lpt;function Upt(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 gw=Zj(function(e,g){for(var I,i=[],n=0;n0})}Rt.has=abt;function Abt(){return this.length>1?this._make(this[0]):this}Rt.first=Abt;function sbt(){return this.length>0?this._make(this[this.length-1]):this}Rt.last=sbt;function lbt(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=lbt;function cbt(e){return e==null?this.toArray():this[e<0?this.length+e:e]}Rt.get=cbt;function ubt(){return Array.prototype.slice.call(this)}Rt.toArray=ubt;function dbt(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,ca.isCheerio)(e)?e[0]:e),Array.prototype.indexOf.call(g,I)}Rt.index=dbt;function hbt(e,g){return this._make(Array.prototype.slice.call(this,e,g))}Rt.slice=hbt;function mbt(){var e;return(e=this.prevObject)!==null&&e!==void 0?e:this._make([])}Rt.end=mbt;function fbt(e,g){var I=this._make(e,g),i=(0,ZA.uniqueSort)(Yz(Yz([],this.get(),!0),I.get(),!0));return this._make(i)}Rt.add=fbt;function pbt(e){return this.prevObject?this.add(e?this.prevObject.filter(e):this.prevObject):this}Rt.addBack=pbt;var ng={},uh={};Object.defineProperty(uh,"__esModule",{value:!0});uh.update=uh.getParse=void 0;var bbt=Ca,Lne=En;function ybt(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,Lne.isDocument)(r))return r;var o=new Lne.Document([]);return ZSe(r,o),o}}uh.getParse=ybt;function ZSe(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 Bbt(e){var g=(0,Ki.isCheerio)(e)?e:this._make(e);return g.append(this),this}ng.appendTo=Bbt;function Sbt(e){var g=(0,Ki.isCheerio)(e)?e:this._make(e);return g.prepend(this),this}ng.prependTo=Sbt;ng.append=GSe(function(e,g,I){cu(g,g.length,0,e,I)});ng.prepend=GSe(function(e,g,I){cu(g,0,0,e,I)});function vSe(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 zb={};Object.defineProperty(zb,"__esModule",{value:!0});zb.serializeArray=zb.serialize=void 0;var zbt=lu,Qne="input,select,textarea,keygen",Pbt=/%20/g,jne=/\r?\n/g;function Jbt(){var e=this.serializeArray(),g=e.map(function(I){return"".concat(encodeURIComponent(I.name),"=").concat(encodeURIComponent(I.value))});return g.join("&").replace(Pbt,"+")}zb.serialize=Jbt;function Obt(){var e=this;return this.map(function(g,I){var i=e._make(I);return(0,zbt.isTag)(I)&&I.name==="form"?i.find(Qne).toArray():i.filter(Qne).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(jne,`\r -`)}}):{name:C,value:r.replace(jne,`\r -`)}}).toArray()}zb.serializeArray=Obt;var _bt=$e&&$e.__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]}),Lbt=$e&&$e.__setModuleDefault||(Object.create?function(e,g){Object.defineProperty(e,"default",{enumerable:!0,value:g})}:function(e,g){e.default=g}),iw=$e&&$e.__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)&&_bt(g,e,I);return Lbt(g,e),g};Object.defineProperty(MN,"__esModule",{value:!0});MN.Cheerio=void 0;var Ubt=iw(hi),Qbt=iw(Rt),jbt=iw(ng),$bt=iw(UN),qbt=iw(zb),nw=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})(jN);var Cw={};(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={}))})(Cw);function r0t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $ne(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,Jn.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===Jn.CODE_POINTS.CARRIAGE_RETURN?Jn.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,Jn.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===Jn.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,Jn.CODE_POINTS.LINE_FEED):I===Jn.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,Jn.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===Jn.CODE_POINTS.LINE_FEED||I===Jn.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,Jn.isControlCodePoint)(I)?this._err(bD.ERR.controlCharacterInInputStream):(0,Jn.isUndefinedCodePoint)(I)&&this._err(bD.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})($N);var nl={};(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})(nl);function c0t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qne(e,g){for(var I=0;I=Ae.CODE_POINTS.DIGIT_0&&e<=Ae.CODE_POINTS.DIGIT_9}function LZ(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_Z}function p0t(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_Z}function Hl(e){return p0t(e)||LZ(e)}function xz(e){return Hl(e)||jG(e)}function RSe(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_F}function WSe(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_F}function b0t(e){return jG(e)||RSe(e)||WSe(e)}function hR(e){return e+32}function XSe(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 y0t(e){return e===Ae.CODE_POINTS.EQUALS_SIGN||xz(e)}function eCe(e){return XSe(e)||e===Ae.CODE_POINTS.SOLIDUS||e===Ae.CODE_POINTS.GREATER_THAN_SIGN}let Z0t=function(){function e(g,I){c0t(this,e),this.options=g,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=Ze.DATA,this.returnState=Ze.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new m0t.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return u0t(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(qe.ERR.endTagWithAttributes),I.selfClosing&&this._err(qe.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 yC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case yC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case yC.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:yC.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=XSe(I)?yC.TokenType.WHITESPACE_CHARACTER:I===Ae.CODE_POINTS.NULL?yC.TokenType.NULL_CHARACTER:yC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(yC.TokenType.CHARACTER,I)}},{key:"_matchNamedCharacterReference",value:function(I){let i=null,n=0,C=!1;for(let r=0,o=Ra.htmlDecodeTree[0];r>=0&&(r=(0,Ra.determineBranch)(Ra.htmlDecodeTree,o,r+1,I),!(r<0));I=this._consume()){n+=1,o=Ra.htmlDecodeTree[r];const a=o&Ra.BinTrieFlags.VALUE_LENGTH;if(a){const s=(a>>14)-1;if(I!==Ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&y0t(this.preprocessor.peek(1))?(i=[Ae.CODE_POINTS.AMPERSAND],r+=s):(i=s===0?[Ra.htmlDecodeTree[r]&~Ra.BinTrieFlags.VALUE_LENGTH]:s===1?[Ra.htmlDecodeTree[++r]]:[Ra.htmlDecodeTree[++r],Ra.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(qe.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===Ze.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===Ze.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===Ze.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 Ze.DATA:{this._stateData(I);break}case Ze.RCDATA:{this._stateRcdata(I);break}case Ze.RAWTEXT:{this._stateRawtext(I);break}case Ze.SCRIPT_DATA:{this._stateScriptData(I);break}case Ze.PLAINTEXT:{this._statePlaintext(I);break}case Ze.TAG_OPEN:{this._stateTagOpen(I);break}case Ze.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case Ze.TAG_NAME:{this._stateTagName(I);break}case Ze.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case Ze.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case Ze.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case Ze.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case Ze.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case Ze.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case Ze.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case Ze.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case Ze.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case Ze.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case Ze.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case Ze.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case Ze.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case Ze.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case Ze.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case Ze.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case Ze.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case Ze.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case Ze.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case Ze.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case Ze.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case Ze.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case Ze.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case Ze.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case Ze.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case Ze.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case Ze.BOGUS_COMMENT:{this._stateBogusComment(I);break}case Ze.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case Ze.COMMENT_START:{this._stateCommentStart(I);break}case Ze.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case Ze.COMMENT:{this._stateComment(I);break}case Ze.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case Ze.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case Ze.COMMENT_END:{this._stateCommentEnd(I);break}case Ze.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case Ze.DOCTYPE:{this._stateDoctype(I);break}case Ze.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case Ze.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case Ze.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case Ze.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case Ze.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case Ze.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case Ze.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case Ze.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case Ze.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case Ze.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case Ze.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case Ze.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case Ze.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case Ze.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case Ze.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case Ze.CDATA_SECTION:{this._stateCdataSection(I);break}case Ze.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case Ze.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case Ze.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case Ze.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case Ze.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case Ze.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case Ze.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case Ze.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case Ze.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case Ze.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=Ze.TAG_OPEN;break}case Ae.CODE_POINTS.AMPERSAND:{this.returnState=Ze.DATA,this.state=Ze.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.RCDATA,this.state=Ze.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ze.RCDATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.RAWTEXT_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.SCRIPT_DATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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(qe.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(Hl(I))this._createStartTagToken(),this.state=Ze.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=Ze.MARKUP_DECLARATION_OPEN;break}case Ae.CODE_POINTS.SOLIDUS:{this.state=Ze.END_TAG_OPEN;break}case Ae.CODE_POINTS.QUESTION_MARK:{this._err(qe.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=Ze.BOGUS_COMMENT,this._stateBogusComment(I);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(qe.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=Ze.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(Hl(I))this._createEndTagToken(),this.state=Ze.TAG_NAME,this._stateTagName(I);else switch(I){case Ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err(qe.ERR.missingEndTagName),this.state=Ze.DATA;break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofBeforeTagName),this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(qe.ERR.unexpectedNullCharacter),this.state=Ze.SCRIPT_DATA_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ze.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?this.state=Ze.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Hl(I)?(this._emitChars("<"),this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=Ze.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){Hl(I)?(this.state=Ze.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(qe.ERR.unexpectedNullCharacter),this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===Ae.CODE_POINTS.SOLIDUS?(this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(Ae.SEQUENCES.SCRIPT,!1)&&eCe(this.preprocessor.peek(Ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err(qe.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isSurrogate)(this.charRefCode))this._err(qe.ERR.surrogateCharacterReference),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isUndefinedCodePoint)(this.charRefCode))this._err(qe.ERR.noncharacterCharacterReference);else if((0,Ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===Ae.CODE_POINTS.CARRIAGE_RETURN){this._err(qe.ERR.controlCharacterReference);const i=f0t.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),e}();dh.Tokenizer=Z0t;var qN={};function G0t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tCe(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(W0t,it.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(R0t,it.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(V0t,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(mR.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(mR.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||mR.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||mR.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(;HSe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;gCe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&gCe.has(this.currentTagId);)this.pop()}}]),e}();qN.OpenElementStack=H0t;var TSe={};(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})(TSe);var ek={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=nl;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 x0t(e){return e.name===NSe&&e.publicId===null&&(e.systemId===null||e.systemId===T0t)}Jb.isConforming=x0t;function D0t(e){if(e.name!==NSe)return Om.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===N0t)return Om.DOCUMENT_MODE.QUIRKS;let{publicId:I}=e;if(I!==null){if(I=I.toLowerCase(),Y0t.has(I))return Om.DOCUMENT_MODE.QUIRKS;let i=g===null?k0t:kSe;if(ICe(I,i))return Om.DOCUMENT_MODE.QUIRKS;if(i=g===null?YSe:K0t,ICe(I,i))return Om.DOCUMENT_MODE.LIMITED_QUIRKS}return Om.DOCUMENT_MODE.NO_QUIRKS}Jb.getDocumentMode=D0t;var Sj={};(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=nl,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=Te.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Te.TEXT,this.originalInsertionMode=Te.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===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===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 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 Oa.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===nCe.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=Te.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=Te.IN_ROW;return}case M.TAG_ID.TBODY:case M.TAG_ID.THEAD:case M.TAG_ID.TFOOT:{this.insertionMode=Te.IN_TABLE_BODY;return}case M.TAG_ID.CAPTION:{this.insertionMode=Te.IN_CAPTION;return}case M.TAG_ID.COLGROUP:{this.insertionMode=Te.IN_COLUMN_GROUP;return}case M.TAG_ID.TABLE:{this.insertionMode=Te.IN_TABLE;return}case M.TAG_ID.BODY:{this.insertionMode=Te.IN_BODY;return}case M.TAG_ID.FRAMESET:{this.insertionMode=Te.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?Te.AFTER_HEAD:Te.BEFORE_HEAD;return}case M.TAG_ID.TD:case M.TAG_ID.TH:{if(I>0){this.insertionMode=Te.IN_CELL;return}break}case M.TAG_ID.HEAD:{if(I>0){this.insertionMode=Te.IN_HEAD;return}break}}this.insertionMode=Te.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=Te.IN_SELECT_IN_TABLE;return}}this.insertionMode=Te.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return xSe.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){SZt(this,I);return}switch(this.insertionMode){case Te.INITIAL:{CZ(this,I);break}case Te.BEFORE_HTML:{$G(this,I);break}case Te.BEFORE_HEAD:{qG(this,I);break}case Te.IN_HEAD:{ev(this,I);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,I);break}case Te.AFTER_HEAD:{gv(this,I);break}case Te.IN_BODY:case Te.IN_CAPTION:case Te.IN_CELL:case Te.IN_TEMPLATE:{FSe(this,I);break}case Te.TEXT:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{ZD(this,I);break}case Te.IN_TABLE_TEXT:{OSe(this,I);break}case Te.IN_COLUMN_GROUP:{K9(this,I);break}case Te.AFTER_BODY:{x9(this,I);break}case Te.AFTER_AFTER_BODY:{q1(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){BZt(this,I);return}switch(this.insertionMode){case Te.INITIAL:{CZ(this,I);break}case Te.BEFORE_HTML:{$G(this,I);break}case Te.BEFORE_HEAD:{qG(this,I);break}case Te.IN_HEAD:{ev(this,I);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,I);break}case Te.AFTER_HEAD:{gv(this,I);break}case Te.TEXT:{this._insertCharacters(I);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{ZD(this,I);break}case Te.IN_COLUMN_GROUP:{K9(this,I);break}case Te.AFTER_BODY:{x9(this,I);break}case Te.AFTER_AFTER_BODY:{q1(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){Dz(this,I);return}switch(this.insertionMode){case Te.INITIAL:case Te.BEFORE_HTML:case Te.BEFORE_HEAD:case Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:case Te.IN_BODY:case Te.IN_TABLE:case Te.IN_CAPTION:case Te.IN_COLUMN_GROUP:case Te.IN_TABLE_BODY:case Te.IN_ROW:case Te.IN_CELL:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:case Te.IN_TEMPLATE:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:{Dz(this,I);break}case Te.IN_TABLE_TEXT:{rZ(this,I);break}case Te.AFTER_BODY:{Iyt(this,I);break}case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{iyt(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case Te.INITIAL:{nyt(this,I);break}case Te.BEFORE_HEAD:case Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:{this._err(I,mn.ERR.misplacedDoctype);break}case Te.IN_TABLE_TEXT:{rZ(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,mn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?wZt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Te.INITIAL:{CZ(this,I);break}case Te.BEFORE_HTML:{Cyt(this,I);break}case Te.BEFORE_HEAD:{oyt(this,I);break}case Te.IN_HEAD:{pa(this,I);break}case Te.IN_HEAD_NO_SCRIPT:{syt(this,I);break}case Te.AFTER_HEAD:{cyt(this,I);break}case Te.IN_BODY:{zn(this,I);break}case Te.IN_TABLE:{Ob(this,I);break}case Te.IN_TABLE_TEXT:{rZ(this,I);break}case Te.IN_CAPTION:{aZt(this,I);break}case Te.IN_COLUMN_GROUP:{Rj(this,I);break}case Te.IN_TABLE_BODY:{Ik(this,I);break}case Te.IN_ROW:{ik(this,I);break}case Te.IN_CELL:{lZt(this,I);break}case Te.IN_SELECT:{USe(this,I);break}case Te.IN_SELECT_IN_TABLE:{uZt(this,I);break}case Te.IN_TEMPLATE:{hZt(this,I);break}case Te.AFTER_BODY:{fZt(this,I);break}case Te.IN_FRAMESET:{pZt(this,I);break}case Te.AFTER_FRAMESET:{yZt(this,I);break}case Te.AFTER_AFTER_BODY:{GZt(this,I);break}case Te.AFTER_AFTER_FRAMESET:{vZt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?VZt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Te.INITIAL:{CZ(this,I);break}case Te.BEFORE_HTML:{ryt(this,I);break}case Te.BEFORE_HEAD:{ayt(this,I);break}case Te.IN_HEAD:{Ayt(this,I);break}case Te.IN_HEAD_NO_SCRIPT:{lyt(this,I);break}case Te.AFTER_HEAD:{uyt(this,I);break}case Te.IN_BODY:{gk(this,I);break}case Te.TEXT:{qyt(this,I);break}case Te.IN_TABLE:{EB(this,I);break}case Te.IN_TABLE_TEXT:{rZ(this,I);break}case Te.IN_CAPTION:{AZt(this,I);break}case Te.IN_COLUMN_GROUP:{sZt(this,I);break}case Te.IN_TABLE_BODY:{Fz(this,I);break}case Te.IN_ROW:{LSe(this,I);break}case Te.IN_CELL:{cZt(this,I);break}case Te.IN_SELECT:{QSe(this,I);break}case Te.IN_SELECT_IN_TABLE:{dZt(this,I);break}case Te.IN_TEMPLATE:{mZt(this,I);break}case Te.AFTER_BODY:{$Se(this,I);break}case Te.IN_FRAMESET:{bZt(this,I);break}case Te.AFTER_FRAMESET:{ZZt(this,I);break}case Te.AFTER_AFTER_BODY:{q1(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case Te.INITIAL:{CZ(this,I);break}case Te.BEFORE_HTML:{$G(this,I);break}case Te.BEFORE_HEAD:{qG(this,I);break}case Te.IN_HEAD:{ev(this,I);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,I);break}case Te.AFTER_HEAD:{gv(this,I);break}case Te.IN_BODY:case Te.IN_TABLE:case Te.IN_CAPTION:case Te.IN_COLUMN_GROUP:case Te.IN_TABLE_BODY:case Te.IN_ROW:case Te.IN_CELL:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:{PSe(this,I);break}case Te.TEXT:{eZt(this,I);break}case Te.IN_TABLE_TEXT:{rZ(this,I);break}case Te.IN_TEMPLATE:{jSe(this,I);break}case Te.AFTER_BODY:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{Vj(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===KSe.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 Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:case Te.TEXT:case Te.IN_COLUMN_GROUP:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:{this._insertCharacters(I);break}case Te.IN_BODY:case Te.IN_CAPTION:case Te.IN_CELL:case Te.IN_TEMPLATE:case Te.AFTER_BODY:case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{DSe(this,I);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{ZD(this,I);break}case Te.IN_TABLE_TEXT:{JSe(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({},rCe),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(Te.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),e}();FB.Parser=Q0t;function j0t(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):zSe(e,g),I}function $0t(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 q0t(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>=L0t;!o||a?(a&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(r)):(r=eyt(e,o),i===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(i),e.treeAdapter.appendChild(r,i),i=r)}return i}function eyt(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 tyt(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 gyt(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 wj(e,g){for(let I=0;I<_0t;I++){const i=j0t(e,g);if(!i)break;const n=$0t(e,i);if(!n)break;e.activeFormattingElements.bookmark=i;const C=q0t(e,n,i.element),r=e.openElements.getCommonAncestor(i.element);e.treeAdapter.detachNode(C),r&&tyt(e,r,C),gyt(e,n,i)}}function Dz(e,g){e._appendCommentNode(g,e.openElements.currentTmplContentOrNode)}function Iyt(e,g){e._appendCommentNode(g,e.openElements.items[0])}function iyt(e,g){e._appendCommentNode(g,e.document)}function Vj(e,g){if(e.stopped=!0,g.location){const I=e.fragmentContext?0:2;for(let i=e.openElements.stackTop;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 nyt(e,g){e._setDocumentType(g);const I=g.forceQuirks?M.DOCUMENT_MODE.QUIRKS:CCe.getDocumentMode(g);CCe.isConforming(g)||e._err(g,mn.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,I),e.insertionMode=Te.BEFORE_HTML}function CZ(e,g){e._err(g,mn.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,M.DOCUMENT_MODE.QUIRKS),e.insertionMode=Te.BEFORE_HTML,e._processToken(g)}function Cyt(e,g){g.tagID===M.TAG_ID.HTML?(e._insertElement(g,M.NS.HTML),e.insertionMode=Te.BEFORE_HEAD):$G(e,g)}function ryt(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)&&$G(e,g)}function $G(e,g){e._insertFakeRootElement(),e.insertionMode=Te.BEFORE_HEAD,e._processToken(g)}function oyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.HEAD:{e._insertElement(g,M.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=Te.IN_HEAD;break}default:qG(e,g)}}function ayt(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?qG(e,g):e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}function qG(e,g){e._insertFakeElement(M.TAG_NAMES.HEAD,M.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=Te.IN_HEAD,e._processToken(g)}function pa(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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=Te.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=Te.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Te.IN_TEMPLATE);break}case M.TAG_ID.HEAD:{e._err(g,mn.ERR.misplacedStartTagForHeadElement);break}default:ev(e,g)}}function Ayt(e,g){switch(g.tagID){case M.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=Te.AFTER_HEAD;break}case M.TAG_ID.BODY:case M.TAG_ID.BR:case M.TAG_ID.HTML:{ev(e,g);break}case M.TAG_ID.TEMPLATE:{Am(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function Am(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==M.TAG_ID.TEMPLATE&&e._err(g,mn.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}function ev(e,g){e.openElements.pop(),e.insertionMode=Te.AFTER_HEAD,e._processToken(g)}function syt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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:{pa(e,g);break}case M.TAG_ID.NOSCRIPT:{e._err(g,mn.ERR.nestedNoscriptInHead);break}default:tv(e,g)}}function lyt(e,g){switch(g.tagID){case M.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=Te.IN_HEAD;break}case M.TAG_ID.BR:{tv(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function tv(e,g){const I=g.type===Vi.TokenType.EOF?mn.ERR.openElementsLeftAfterEof:mn.ERR.disallowedContentInNoscriptInHead;e._err(g,I),e.openElements.pop(),e.insertionMode=Te.IN_HEAD,e._processToken(g)}function cyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.BODY:{e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=Te.IN_BODY;break}case M.TAG_ID.FRAMESET:{e._insertElement(g,M.NS.HTML),e.insertionMode=Te.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,mn.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,M.TAG_ID.HEAD),pa(e,g),e.openElements.remove(e.headElement);break}case M.TAG_ID.HEAD:{e._err(g,mn.ERR.misplacedStartTagForHeadElement);break}default:gv(e,g)}}function uyt(e,g){switch(g.tagID){case M.TAG_ID.BODY:case M.TAG_ID.HTML:case M.TAG_ID.BR:{gv(e,g);break}case M.TAG_ID.TEMPLATE:{Am(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function gv(e,g){e._insertFakeElement(M.TAG_NAMES.BODY,M.TAG_ID.BODY),e.insertionMode=Te.IN_BODY,tk(e,g)}function tk(e,g){switch(g.type){case Vi.TokenType.CHARACTER:{FSe(e,g);break}case Vi.TokenType.WHITESPACE_CHARACTER:{DSe(e,g);break}case Vi.TokenType.COMMENT:{Dz(e,g);break}case Vi.TokenType.START_TAG:{zn(e,g);break}case Vi.TokenType.END_TAG:{gk(e,g);break}case Vi.TokenType.EOF:{PSe(e,g);break}}}function DSe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function FSe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function dyt(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function hyt(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(I,g.attrs))}function myt(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=Te.IN_FRAMESET)}function fyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML)}function pyt(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 byt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function yyt(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 Zyt(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 Gyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.tokenizer.state=jn.TokenizerMode.PLAINTEXT}function vyt(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 Byt(e,g){const I=e.activeFormattingElements.getElementEntryInScopeWithTagName(M.TAG_NAMES.A);I&&(wj(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 Syt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function wyt(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(M.TAG_ID.NOBR)&&(wj(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function Vyt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function Ryt(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=Te.IN_TABLE}function ESe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function MSe(e){const g=(0,Vi.getTokenAttr)(e,M.ATTRS.TYPE);return g!=null&&g.toLowerCase()===O0t}function Wyt(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),MSe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function Xyt(e,g){e._appendElement(g,M.NS.HTML),g.ackSelfClosing=!0}function Hyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function Tyt(e,g){g.tagName=M.TAG_NAMES.IMG,g.tagID=M.TAG_ID.IMG,ESe(e,g)}function Nyt(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=Te.TEXT}function kyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function Yyt(e,g){e.framesetOk=!1,e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function oCe(e,g){e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function Kyt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Te.IN_TABLE||e.insertionMode===Te.IN_CAPTION||e.insertionMode===Te.IN_TABLE_BODY||e.insertionMode===Te.IN_ROW||e.insertionMode===Te.IN_CELL?Te.IN_SELECT_IN_TABLE:Te.IN_SELECT}function xyt(e,g){e.openElements.currentTagId===M.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function Dyt(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,M.NS.HTML)}function Fyt(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.RTC),e._insertElement(g,M.NS.HTML)}function Eyt(e,g){e._reconstructActiveFormattingElements(),Oa.adjustTokenMathMLAttrs(g),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.MATHML):e._insertElement(g,M.NS.MATHML),g.ackSelfClosing=!0}function Myt(e,g){e._reconstructActiveFormattingElements(),Oa.adjustTokenSVGAttrs(g),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.SVG):e._insertElement(g,M.NS.SVG),g.ackSelfClosing=!0}function aCe(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function zn(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:{Syt(e,g);break}case M.TAG_ID.A:{Byt(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:{pyt(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:{fyt(e,g);break}case M.TAG_ID.LI:case M.TAG_ID.DD:case M.TAG_ID.DT:{Zyt(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:{ESe(e,g);break}case M.TAG_ID.HR:{Hyt(e,g);break}case M.TAG_ID.RB:case M.TAG_ID.RTC:{Dyt(e,g);break}case M.TAG_ID.RT:case M.TAG_ID.RP:{Fyt(e,g);break}case M.TAG_ID.PRE:case M.TAG_ID.LISTING:{byt(e,g);break}case M.TAG_ID.XMP:{kyt(e,g);break}case M.TAG_ID.SVG:{Myt(e,g);break}case M.TAG_ID.HTML:{dyt(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:{pa(e,g);break}case M.TAG_ID.BODY:{hyt(e,g);break}case M.TAG_ID.FORM:{yyt(e,g);break}case M.TAG_ID.NOBR:{wyt(e,g);break}case M.TAG_ID.MATH:{Eyt(e,g);break}case M.TAG_ID.TABLE:{Ryt(e,g);break}case M.TAG_ID.INPUT:{Wyt(e,g);break}case M.TAG_ID.PARAM:case M.TAG_ID.TRACK:case M.TAG_ID.SOURCE:{Xyt(e,g);break}case M.TAG_ID.IMAGE:{Tyt(e,g);break}case M.TAG_ID.BUTTON:{vyt(e,g);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{Vyt(e,g);break}case M.TAG_ID.IFRAME:{Yyt(e,g);break}case M.TAG_ID.SELECT:{Kyt(e,g);break}case M.TAG_ID.OPTION:case M.TAG_ID.OPTGROUP:{xyt(e,g);break}case M.TAG_ID.NOEMBED:{oCe(e,g);break}case M.TAG_ID.FRAMESET:{myt(e,g);break}case M.TAG_ID.TEXTAREA:{Nyt(e,g);break}case M.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?oCe(e,g):aCe(e,g);break}case M.TAG_ID.PLAINTEXT:{Gyt(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:aCe(e,g)}}function zyt(e,g){if(e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Te.AFTER_BODY,e.options.sourceCodeLocationInfo)){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e._setEndLocation(I,g)}}function Pyt(e,g){e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Te.AFTER_BODY,$Se(e,g))}function Jyt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I))}function Oyt(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 _yt(e){e.openElements.hasInButtonScope(M.TAG_ID.P)||e._insertFakeElement(M.TAG_NAMES.P,M.TAG_ID.P),e._closePElement()}function Lyt(e){e.openElements.hasInListItemScope(M.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.LI),e.openElements.popUntilTagNamePopped(M.TAG_ID.LI))}function Uyt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.popUntilTagNamePopped(I))}function Qyt(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function jyt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I),e.activeFormattingElements.clearToLastMarker())}function $yt(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(M.TAG_NAMES.BR,M.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function zSe(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 gk(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:{wj(e,g);break}case M.TAG_ID.P:{_yt(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:{Jyt(e,g);break}case M.TAG_ID.LI:{Lyt(e);break}case M.TAG_ID.DD:case M.TAG_ID.DT:{Uyt(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:{Qyt(e);break}case M.TAG_ID.BR:{$yt(e);break}case M.TAG_ID.BODY:{zyt(e,g);break}case M.TAG_ID.HTML:{Pyt(e,g);break}case M.TAG_ID.FORM:{Oyt(e);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{jyt(e,g);break}case M.TAG_ID.TEMPLATE:{Am(e,g);break}default:zSe(e,g)}}function PSe(e,g){e.tmplInsertionModeStack.length>0?jSe(e,g):Vj(e,g)}function qyt(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 eZt(e,g){e._err(g,mn.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function ZD(e,g){if(xSe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Te.IN_TABLE_TEXT,g.type){case Vi.TokenType.CHARACTER:{OSe(e,g);break}case Vi.TokenType.WHITESPACE_CHARACTER:{JSe(e,g);break}}else rw(e,g)}function tZt(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_CAPTION}function gZt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_COLUMN_GROUP}function IZt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.COLGROUP,M.TAG_ID.COLGROUP),e.insertionMode=Te.IN_COLUMN_GROUP,Rj(e,g)}function iZt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_TABLE_BODY}function nZt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.TBODY,M.TAG_ID.TBODY),e.insertionMode=Te.IN_TABLE_BODY,Ik(e,g)}function CZt(e,g){e.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function rZt(e,g){MSe(g)?e._appendElement(g,M.NS.HTML):rw(e,g),g.ackSelfClosing=!0}function oZt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,M.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function Ob(e,g){switch(g.tagID){case M.TAG_ID.TD:case M.TAG_ID.TH:case M.TAG_ID.TR:{nZt(e,g);break}case M.TAG_ID.STYLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.TEMPLATE:{pa(e,g);break}case M.TAG_ID.COL:{IZt(e,g);break}case M.TAG_ID.FORM:{oZt(e,g);break}case M.TAG_ID.TABLE:{CZt(e,g);break}case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{iZt(e,g);break}case M.TAG_ID.INPUT:{rZt(e,g);break}case M.TAG_ID.CAPTION:{tZt(e,g);break}case M.TAG_ID.COLGROUP:{gZt(e,g);break}default:rw(e,g)}}function EB(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:{Am(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:rw(e,g)}}function rw(e,g){const I=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,tk(e,g),e.fosterParentingEnabled=I}function JSe(e,g){e.pendingCharacterTokens.push(g)}function OSe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function rZ(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:{Am(e,g);break}}}function uZt(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)):USe(e,g)}function dZt(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)):QSe(e,g)}function hZt(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:{pa(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]=Te.IN_TABLE,e.insertionMode=Te.IN_TABLE,Ob(e,g);break}case M.TAG_ID.COL:{e.tmplInsertionModeStack[0]=Te.IN_COLUMN_GROUP,e.insertionMode=Te.IN_COLUMN_GROUP,Rj(e,g);break}case M.TAG_ID.TR:{e.tmplInsertionModeStack[0]=Te.IN_TABLE_BODY,e.insertionMode=Te.IN_TABLE_BODY,Ik(e,g);break}case M.TAG_ID.TD:case M.TAG_ID.TH:{e.tmplInsertionModeStack[0]=Te.IN_ROW,e.insertionMode=Te.IN_ROW,ik(e,g);break}default:e.tmplInsertionModeStack[0]=Te.IN_BODY,e.insertionMode=Te.IN_BODY,zn(e,g)}}function mZt(e,g){g.tagID===M.TAG_ID.TEMPLATE&&Am(e,g)}function jSe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):Vj(e,g)}function fZt(e,g){g.tagID===M.TAG_ID.HTML?zn(e,g):x9(e,g)}function $Se(e,g){var I;if(g.tagID===M.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=Te.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 x9(e,g)}function x9(e,g){e.insertionMode=Te.IN_BODY,tk(e,g)}function pZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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:{pa(e,g);break}}}function bZt(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=Te.AFTER_FRAMESET))}function yZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.NOFRAMES:{pa(e,g);break}}}function ZZt(e,g){g.tagID===M.TAG_ID.HTML&&(e.insertionMode=Te.AFTER_AFTER_FRAMESET)}function GZt(e,g){g.tagID===M.TAG_ID.HTML?zn(e,g):q1(e,g)}function q1(e,g){e.insertionMode=Te.IN_BODY,tk(e,g)}function vZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.NOFRAMES:{pa(e,g);break}}}function BZt(e,g){g.chars=KSe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function SZt(e,g){e._insertCharacters(g),e.framesetOk=!1}function qSe(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==M.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function wZt(e,g){if(Oa.causesExit(g))qSe(e),e._startTagOutsideForeignContent(g);else{const I=e._getAdjustedCurrentElement(),i=e.treeAdapter.getNamespaceURI(I);i===M.NS.MATHML?Oa.adjustTokenMathMLAttrs(g):i===M.NS.SVG&&(Oa.adjustTokenSVGTagName(g),Oa.adjustTokenSVGAttrs(g)),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,i):e._insertElement(g,i),g.ackSelfClosing=!0}}function VZt(e,g){if(g.tagID===M.TAG_ID.P||g.tagID===M.TAG_ID.BR){qSe(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 _b={};Object.defineProperty(_b,"__esModule",{value:!0});_b.serializeOuter=_b.serialize=void 0;const CI=nl,ewe=Kb,RZt=ek,WZt=new Set([CI.TAG_NAMES.AREA,CI.TAG_NAMES.BASE,CI.TAG_NAMES.BASEFONT,CI.TAG_NAMES.BGSOUND,CI.TAG_NAMES.BR,CI.TAG_NAMES.COL,CI.TAG_NAMES.EMBED,CI.TAG_NAMES.FRAME,CI.TAG_NAMES.HR,CI.TAG_NAMES.IMG,CI.TAG_NAMES.INPUT,CI.TAG_NAMES.KEYGEN,CI.TAG_NAMES.LINK,CI.TAG_NAMES.META,CI.TAG_NAMES.PARAM,CI.TAG_NAMES.SOURCE,CI.TAG_NAMES.TRACK,CI.TAG_NAMES.WBR]);function twe(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===CI.NS.HTML&&WZt.has(g.treeAdapter.getTagName(e))}const gwe={treeAdapter:RZt.defaultTreeAdapter,scriptingEnabled:!0};function XZt(e,g){const I=Object.assign(Object.assign({},gwe),g);return twe(e,I)?"":Iwe(e,I)}_b.serialize=XZt;function HZt(e,g){const I=Object.assign(Object.assign({},gwe),g);return iwe(e,I)}_b.serializeOuter=HZt;function Iwe(e,g){let I="";const i=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===CI.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===CI.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=iwe(C,g);return I}function iwe(e,g){return g.treeAdapter.isElementNode(e)?TZt(e,g):g.treeAdapter.isTextNode(e)?kZt(e,g):g.treeAdapter.isCommentNode(e)?YZt(e,g):g.treeAdapter.isDocumentTypeNode(e)?KZt(e,g):""}function TZt(e,g){const I=g.treeAdapter.getTagName(e);return`<${I}${NZt(e,g)}>${twe(e,g)?"":`${Iwe(e,g)}`}`}function NZt(e,{treeAdapter:g}){let I="";for(const i of g.getAttrList(e)){if(I+=" ",!i.namespace)I+=i.name;else switch(i.namespace){case CI.NS.XML:{I+=`xml:${i.name}`;break}case CI.NS.XMLNS:{i.name!=="xmlns"&&(I+="xmlns:"),I+=i.name;break}case CI.NS.XLINK:{I+=`xlink:${i.name}`;break}default:I+=`${i.prefix}:${i.name}`}I+=`="${(0,ewe.escapeAttribute)(i.value)}"`}return I}function kZt(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)===CI.NS.HTML&&(0,CI.hasUnescapedText)(C,g.scriptingEnabled)?i:(0,ewe.escapeText)(i)}function YZt(e,{treeAdapter:g}){return``}function KZt(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=FB;var I=ek;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=FB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=_b;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=Cw;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),e.foreignContent=Sj,e.html=nl,e.Token=$N;var r=dh;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})(VSe);var nwe={},Cwe={},MB={},hh={},nk={},Ck={};(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})(Ck);var ow={};(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={}))})(ow);function xZt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ACe(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,On.CODE_POINTS.EOF;const n=this.html.charCodeAt(i);return n===On.CODE_POINTS.CARRIAGE_RETURN?On.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,On.CODE_POINTS.EOF;let I=this.html.charCodeAt(this.pos);return I===On.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,On.CODE_POINTS.LINE_FEED):I===On.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,On.isSurrogate)(I)&&(I=this._processSurrogate(I)),this.handler.onParseError===null||I>31&&I<127||I===On.CODE_POINTS.LINE_FEED||I===On.CODE_POINTS.CARRIAGE_RETURN||I>159&&I<64976||this._checkForProblematicCharacters(I),I)}},{key:"_checkForProblematicCharacters",value:function(I){(0,On.isControlCodePoint)(I)?this._err(GD.ERR.controlCharacterInInputStream):(0,On.isUndefinedCodePoint)(I)&&this._err(GD.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})(rk);var Cl={};(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})(Cl);function PZt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function sCe(e,g){for(var I=0;I=se.CODE_POINTS.DIGIT_0&&e<=se.CODE_POINTS.DIGIT_9}function UZ(e){return e>=se.CODE_POINTS.LATIN_CAPITAL_A&&e<=se.CODE_POINTS.LATIN_CAPITAL_Z}function QZt(e){return e>=se.CODE_POINTS.LATIN_SMALL_A&&e<=se.CODE_POINTS.LATIN_SMALL_Z}function Tl(e){return QZt(e)||UZ(e)}function Ez(e){return Tl(e)||Iv(e)}function rwe(e){return e>=se.CODE_POINTS.LATIN_CAPITAL_A&&e<=se.CODE_POINTS.LATIN_CAPITAL_F}function owe(e){return e>=se.CODE_POINTS.LATIN_SMALL_A&&e<=se.CODE_POINTS.LATIN_SMALL_F}function jZt(e){return Iv(e)||rwe(e)||owe(e)}function fR(e){return e+32}function awe(e){return e===se.CODE_POINTS.SPACE||e===se.CODE_POINTS.LINE_FEED||e===se.CODE_POINTS.TABULATION||e===se.CODE_POINTS.FORM_FEED}function $Zt(e){return e===se.CODE_POINTS.EQUALS_SIGN||Ez(e)}function lCe(e){return awe(e)||e===se.CODE_POINTS.SOLIDUS||e===se.CODE_POINTS.GREATER_THAN_SIGN}let qZt=function(){function e(g,I){PZt(this,e),this.options=g,this.handler=I,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=Ge.DATA,this.returnState=Ge.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new LZt.Preprocessor(I),this.currentLocation=this.getCurrentLocation(-1)}return JZt(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(et.ERR.endTagWithAttributes),I.selfClosing&&this._err(et.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 ZC.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case ZC.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case ZC.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:ZC.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=awe(I)?ZC.TokenType.WHITESPACE_CHARACTER:I===se.CODE_POINTS.NULL?ZC.TokenType.NULL_CHARACTER:ZC.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(i,String.fromCodePoint(I))}},{key:"_emitChars",value:function(I){this._appendCharToCurrentCharacterToken(ZC.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!==se.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&$Zt(this.preprocessor.peek(1))?(i=[se.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!==se.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),C&&!this.preprocessor.endOfChunkHit&&this._err(et.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),i}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===Ge.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===Ge.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===Ge.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 Ge.DATA:{this._stateData(I);break}case Ge.RCDATA:{this._stateRcdata(I);break}case Ge.RAWTEXT:{this._stateRawtext(I);break}case Ge.SCRIPT_DATA:{this._stateScriptData(I);break}case Ge.PLAINTEXT:{this._statePlaintext(I);break}case Ge.TAG_OPEN:{this._stateTagOpen(I);break}case Ge.END_TAG_OPEN:{this._stateEndTagOpen(I);break}case Ge.TAG_NAME:{this._stateTagName(I);break}case Ge.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(I);break}case Ge.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(I);break}case Ge.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(I);break}case Ge.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(I);break}case Ge.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(I);break}case Ge.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(I);break}case Ge.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(I);break}case Ge.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(I);break}case Ge.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(I);break}case Ge.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(I);break}case Ge.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(I);break}case Ge.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(I);break}case Ge.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(I);break}case Ge.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(I);break}case Ge.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(I);break}case Ge.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(I);break}case Ge.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(I);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(I);break}case Ge.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(I);break}case Ge.ATTRIBUTE_NAME:{this._stateAttributeName(I);break}case Ge.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(I);break}case Ge.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(I);break}case Ge.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(I);break}case Ge.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(I);break}case Ge.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(I);break}case Ge.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(I);break}case Ge.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(I);break}case Ge.BOGUS_COMMENT:{this._stateBogusComment(I);break}case Ge.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(I);break}case Ge.COMMENT_START:{this._stateCommentStart(I);break}case Ge.COMMENT_START_DASH:{this._stateCommentStartDash(I);break}case Ge.COMMENT:{this._stateComment(I);break}case Ge.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(I);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(I);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(I);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(I);break}case Ge.COMMENT_END_DASH:{this._stateCommentEndDash(I);break}case Ge.COMMENT_END:{this._stateCommentEnd(I);break}case Ge.COMMENT_END_BANG:{this._stateCommentEndBang(I);break}case Ge.DOCTYPE:{this._stateDoctype(I);break}case Ge.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(I);break}case Ge.DOCTYPE_NAME:{this._stateDoctypeName(I);break}case Ge.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(I);break}case Ge.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(I);break}case Ge.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(I);break}case Ge.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(I);break}case Ge.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(I);break}case Ge.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(I);break}case Ge.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(I);break}case Ge.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(I);break}case Ge.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(I);break}case Ge.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(I);break}case Ge.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(I);break}case Ge.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(I);break}case Ge.BOGUS_DOCTYPE:{this._stateBogusDoctype(I);break}case Ge.CDATA_SECTION:{this._stateCdataSection(I);break}case Ge.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(I);break}case Ge.CDATA_SECTION_END:{this._stateCdataSectionEnd(I);break}case Ge.CHARACTER_REFERENCE:{this._stateCharacterReference(I);break}case Ge.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(I);break}case Ge.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(I);break}case Ge.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(I);break}case Ge.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(I);break}case Ge.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(I);break}case Ge.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(I);break}case Ge.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(I);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(I){switch(I){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.TAG_OPEN;break}case se.CODE_POINTS.AMPERSAND:{this.returnState=Ge.DATA,this.state=Ge.CHARACTER_REFERENCE;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitCodePoint(I);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRcdata",value:function(I){switch(I){case se.CODE_POINTS.AMPERSAND:{this.returnState=Ge.RCDATA,this.state=Ge.CHARACTER_REFERENCE;break}case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.RCDATA_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateRawtext",value:function(I){switch(I){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.RAWTEXT_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateScriptData",value:function(I){switch(I){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.SCRIPT_DATA_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_statePlaintext",value:function(I){switch(I){case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(I)}}},{key:"_stateTagOpen",value:function(I){if(Tl(I))this._createStartTagToken(),this.state=Ge.TAG_NAME,this._stateTagName(I);else switch(I){case se.CODE_POINTS.EXCLAMATION_MARK:{this.state=Ge.MARKUP_DECLARATION_OPEN;break}case se.CODE_POINTS.SOLIDUS:{this.state=Ge.END_TAG_OPEN;break}case se.CODE_POINTS.QUESTION_MARK:{this._err(et.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=Ge.BOGUS_COMMENT,this._stateBogusComment(I);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(et.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=Ge.DATA,this._stateData(I)}}},{key:"_stateEndTagOpen",value:function(I){if(Tl(I))this._createEndTagToken(),this.state=Ge.TAG_NAME,this._stateTagName(I);else switch(I){case se.CODE_POINTS.GREATER_THAN_SIGN:{this._err(et.ERR.missingEndTagName),this.state=Ge.DATA;break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofBeforeTagName),this._emitChars("");break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this.state=Ge.SCRIPT_DATA_ESCAPED,this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ge.SCRIPT_DATA_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(I){I===se.CODE_POINTS.SOLIDUS?this.state=Ge.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Tl(I)?(this._emitChars("<"),this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(I)):(this._emitChars("<"),this.state=Ge.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(I))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(I){Tl(I)?(this.state=Ge.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(I)):(this._emitChars("");break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(I)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(I){I===se.CODE_POINTS.SOLIDUS?(this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(I))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(I){if(this.preprocessor.startsWith(se.SEQUENCES.SCRIPT,!1)&&lCe(this.preprocessor.peek(se.SEQUENCES.SCRIPT.length))){this._emitCodePoint(I);for(let i=0;i1114111)this._err(et.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=se.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,se.isSurrogate)(this.charRefCode))this._err(et.ERR.surrogateCharacterReference),this.charRefCode=se.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,se.isUndefinedCodePoint)(this.charRefCode))this._err(et.ERR.noncharacterCharacterReference);else if((0,se.isControlCodePoint)(this.charRefCode)||this.charRefCode===se.CODE_POINTS.CARRIAGE_RETURN){this._err(et.ERR.controlCharacterReference);const i=UZt.get(this.charRefCode);i!==void 0&&(this.charRefCode=i)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,I)}}]),e}();hh.Tokenizer=qZt;var ok={};function eGt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cCe(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])!==nt.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(rGt,nt.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(CGt,nt.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(nGt,nt.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]===nt.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]===nt.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===nt.NS.HTML)return!0;if(pR.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,nt.isNumberedHeader)(i)&&n===nt.NS.HTML)return!0;if(pR.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===nt.NS.HTML)return!0;if((n===nt.TAG_ID.UL||n===nt.TAG_ID.OL)&&C===nt.NS.HTML||pR.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===nt.NS.HTML)return!0;if(n===nt.TAG_ID.BUTTON&&C===nt.NS.HTML||pR.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])===nt.NS.HTML){if(n===I)return!0;if(n===nt.TAG_ID.TABLE||n===nt.TAG_ID.TEMPLATE||n===nt.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])===nt.NS.HTML){if(i===nt.TAG_ID.TBODY||i===nt.TAG_ID.THEAD||i===nt.TAG_ID.TFOOT)return!0;if(i===nt.TAG_ID.TABLE||i===nt.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])===nt.NS.HTML){if(n===I)return!0;if(n!==nt.TAG_ID.OPTION&&n!==nt.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;Awe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;uCe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(I){for(;this.currentTagId!==I&&uCe.has(this.currentTagId);)this.pop()}}]),e}();ok.OpenElementStack=aGt;var swe={};(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})(swe);var ak={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=Cl;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 dGt(e){return e.name===lwe&&e.publicId===null&&(e.systemId===null||e.systemId===AGt)}Lb.isConforming=dGt;function hGt(e){if(e.name!==lwe)return _m.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===sGt)return _m.DOCUMENT_MODE.QUIRKS;let{publicId:I}=e;if(I!==null){if(I=I.toLowerCase(),cGt.has(I))return _m.DOCUMENT_MODE.QUIRKS;let i=g===null?lGt:cwe;if(dCe(I,i))return _m.DOCUMENT_MODE.QUIRKS;if(i=g===null?uwe:uGt,dCe(I,i))return _m.DOCUMENT_MODE.LIMITED_QUIRKS}return _m.DOCUMENT_MODE.NO_QUIRKS}Lb.getDocumentMode=hGt;var Wj={};(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=Cl,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=Ne.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Ne.TEXT,this.originalInsertionMode=Ne.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)===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=$n.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=$n.TokenizerMode.RAWTEXT;break}case z.TAG_ID.SCRIPT:{this.tokenizer.state=$n.TokenizerMode.SCRIPT_DATA;break}case z.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,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===Ri.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 Ri.TokenType.CHARACTER:{this.onCharacter(I);break}case Ri.TokenType.NULL_CHARACTER:{this.onNullCharacter(I);break}case Ri.TokenType.COMMENT:{this.onComment(I);break}case Ri.TokenType.DOCTYPE:{this.onDoctype(I);break}case Ri.TokenType.START_TAG:{this._processStartTag(I);break}case Ri.TokenType.END_TAG:{this.onEndTag(I);break}case Ri.TokenType.EOF:{this.onEof(I);break}case Ri.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 _a.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===mCe.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=Ne.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=Ne.IN_ROW;return}case z.TAG_ID.TBODY:case z.TAG_ID.THEAD:case z.TAG_ID.TFOOT:{this.insertionMode=Ne.IN_TABLE_BODY;return}case z.TAG_ID.CAPTION:{this.insertionMode=Ne.IN_CAPTION;return}case z.TAG_ID.COLGROUP:{this.insertionMode=Ne.IN_COLUMN_GROUP;return}case z.TAG_ID.TABLE:{this.insertionMode=Ne.IN_TABLE;return}case z.TAG_ID.BODY:{this.insertionMode=Ne.IN_BODY;return}case z.TAG_ID.FRAMESET:{this.insertionMode=Ne.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?Ne.AFTER_HEAD:Ne.BEFORE_HEAD;return}case z.TAG_ID.TD:case z.TAG_ID.TH:{if(I>0){this.insertionMode=Ne.IN_CELL;return}break}case z.TAG_ID.HEAD:{if(I>0){this.insertionMode=Ne.IN_HEAD;return}break}}this.insertionMode=Ne.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=Ne.IN_SELECT_IN_TABLE;return}}this.insertionMode=Ne.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(I){return hwe.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){IBt(this,I);return}switch(this.insertionMode){case Ne.INITIAL:{oZ(this,I);break}case Ne.BEFORE_HTML:{iv(this,I);break}case Ne.BEFORE_HEAD:{nv(this,I);break}case Ne.IN_HEAD:{Cv(this,I);break}case Ne.IN_HEAD_NO_SCRIPT:{rv(this,I);break}case Ne.AFTER_HEAD:{ov(this,I);break}case Ne.IN_BODY:case Ne.IN_CAPTION:case Ne.IN_CELL:case Ne.IN_TEMPLATE:{fwe(this,I);break}case Ne.TEXT:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:{this._insertCharacters(I);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{BD(this,I);break}case Ne.IN_TABLE_TEXT:{vwe(this,I);break}case Ne.IN_COLUMN_GROUP:{D9(this,I);break}case Ne.AFTER_BODY:{F9(this,I);break}case Ne.AFTER_AFTER_BODY:{eW(this,I);break}}}},{key:"onNullCharacter",value:function(I){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){gBt(this,I);return}switch(this.insertionMode){case Ne.INITIAL:{oZ(this,I);break}case Ne.BEFORE_HTML:{iv(this,I);break}case Ne.BEFORE_HEAD:{nv(this,I);break}case Ne.IN_HEAD:{Cv(this,I);break}case Ne.IN_HEAD_NO_SCRIPT:{rv(this,I);break}case Ne.AFTER_HEAD:{ov(this,I);break}case Ne.TEXT:{this._insertCharacters(I);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{BD(this,I);break}case Ne.IN_COLUMN_GROUP:{D9(this,I);break}case Ne.AFTER_BODY:{F9(this,I);break}case Ne.AFTER_AFTER_BODY:{eW(this,I);break}}}},{key:"onComment",value:function(I){if(this.skipNextNewLine=!1,this.currentNotInHTML){Mz(this,I);return}switch(this.insertionMode){case Ne.INITIAL:case Ne.BEFORE_HTML:case Ne.BEFORE_HEAD:case Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:case Ne.IN_BODY:case Ne.IN_TABLE:case Ne.IN_CAPTION:case Ne.IN_COLUMN_GROUP:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:case Ne.IN_CELL:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:case Ne.IN_TEMPLATE:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:{Mz(this,I);break}case Ne.IN_TABLE_TEXT:{aZ(this,I);break}case Ne.AFTER_BODY:{NGt(this,I);break}case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{kGt(this,I);break}}}},{key:"onDoctype",value:function(I){switch(this.skipNextNewLine=!1,this.insertionMode){case Ne.INITIAL:{YGt(this,I);break}case Ne.BEFORE_HEAD:case Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:{this._err(I,fn.ERR.misplacedDoctype);break}case Ne.IN_TABLE_TEXT:{aZ(this,I);break}}}},{key:"onStartTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this._processStartTag(I),I.selfClosing&&!I.ackSelfClosing&&this._err(I,fn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(I){this.shouldProcessStartTagTokenInForeignContent(I)?iBt(this,I):this._startTagOutsideForeignContent(I)}},{key:"_startTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Ne.INITIAL:{oZ(this,I);break}case Ne.BEFORE_HTML:{KGt(this,I);break}case Ne.BEFORE_HEAD:{DGt(this,I);break}case Ne.IN_HEAD:{ba(this,I);break}case Ne.IN_HEAD_NO_SCRIPT:{MGt(this,I);break}case Ne.AFTER_HEAD:{PGt(this,I);break}case Ne.IN_BODY:{Pn(this,I);break}case Ne.IN_TABLE:{Ub(this,I);break}case Ne.IN_TABLE_TEXT:{aZ(this,I);break}case Ne.IN_CAPTION:{Fvt(this,I);break}case Ne.IN_COLUMN_GROUP:{Tj(this,I);break}case Ne.IN_TABLE_BODY:{lk(this,I);break}case Ne.IN_ROW:{ck(this,I);break}case Ne.IN_CELL:{zvt(this,I);break}case Ne.IN_SELECT:{wwe(this,I);break}case Ne.IN_SELECT_IN_TABLE:{Jvt(this,I);break}case Ne.IN_TEMPLATE:{_vt(this,I);break}case Ne.AFTER_BODY:{Uvt(this,I);break}case Ne.IN_FRAMESET:{Qvt(this,I);break}case Ne.AFTER_FRAMESET:{$vt(this,I);break}case Ne.AFTER_AFTER_BODY:{eBt(this,I);break}case Ne.AFTER_AFTER_FRAMESET:{tBt(this,I);break}}}},{key:"onEndTag",value:function(I){this.skipNextNewLine=!1,this.currentToken=I,this.currentNotInHTML?nBt(this,I):this._endTagOutsideForeignContent(I)}},{key:"_endTagOutsideForeignContent",value:function(I){switch(this.insertionMode){case Ne.INITIAL:{oZ(this,I);break}case Ne.BEFORE_HTML:{xGt(this,I);break}case Ne.BEFORE_HEAD:{FGt(this,I);break}case Ne.IN_HEAD:{EGt(this,I);break}case Ne.IN_HEAD_NO_SCRIPT:{zGt(this,I);break}case Ne.AFTER_HEAD:{JGt(this,I);break}case Ne.IN_BODY:{sk(this,I);break}case Ne.TEXT:{Wvt(this,I);break}case Ne.IN_TABLE:{zB(this,I);break}case Ne.IN_TABLE_TEXT:{aZ(this,I);break}case Ne.IN_CAPTION:{Evt(this,I);break}case Ne.IN_COLUMN_GROUP:{Mvt(this,I);break}case Ne.IN_TABLE_BODY:{zz(this,I);break}case Ne.IN_ROW:{Swe(this,I);break}case Ne.IN_CELL:{Pvt(this,I);break}case Ne.IN_SELECT:{Vwe(this,I);break}case Ne.IN_SELECT_IN_TABLE:{Ovt(this,I);break}case Ne.IN_TEMPLATE:{Lvt(this,I);break}case Ne.AFTER_BODY:{Wwe(this,I);break}case Ne.IN_FRAMESET:{jvt(this,I);break}case Ne.AFTER_FRAMESET:{qvt(this,I);break}case Ne.AFTER_AFTER_BODY:{eW(this,I);break}}}},{key:"onEof",value:function(I){switch(this.insertionMode){case Ne.INITIAL:{oZ(this,I);break}case Ne.BEFORE_HTML:{iv(this,I);break}case Ne.BEFORE_HEAD:{nv(this,I);break}case Ne.IN_HEAD:{Cv(this,I);break}case Ne.IN_HEAD_NO_SCRIPT:{rv(this,I);break}case Ne.AFTER_HEAD:{ov(this,I);break}case Ne.IN_BODY:case Ne.IN_TABLE:case Ne.IN_CAPTION:case Ne.IN_COLUMN_GROUP:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:case Ne.IN_CELL:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:{Zwe(this,I);break}case Ne.TEXT:{Xvt(this,I);break}case Ne.IN_TABLE_TEXT:{aZ(this,I);break}case Ne.IN_TEMPLATE:{Rwe(this,I);break}case Ne.AFTER_BODY:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{Hj(this,I);break}}}},{key:"onWhitespaceCharacter",value:function(I){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,I.chars.charCodeAt(0)===dwe.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 Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:case Ne.TEXT:case Ne.IN_COLUMN_GROUP:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:{this._insertCharacters(I);break}case Ne.IN_BODY:case Ne.IN_CAPTION:case Ne.IN_CELL:case Ne.IN_TEMPLATE:case Ne.AFTER_BODY:case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{mwe(this,I);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{BD(this,I);break}case Ne.IN_TABLE_TEXT:{Gwe(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({},pCe),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(Ne.IN_TEMPLATE),r._initTokenizerForFragmentParsing(),r._insertFakeRootElement(),r._resetInsertionMode(),r._findFormInFragmentContext(),r}}]),e}();MB.Parser=wGt;function VGt(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):ywe(e,g),I}function RGt(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 WGt(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>=BGt;!o||a?(a&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(r)):(r=XGt(e,o),i===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(i),e.treeAdapter.appendChild(r,i),i=r)}return i}function XGt(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 HGt(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 TGt(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 Xj(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 YGt(e,g){e._setDocumentType(g);const I=g.forceQuirks?z.DOCUMENT_MODE.QUIRKS:fCe.getDocumentMode(g);fCe.isConforming(g)||e._err(g,fn.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,I),e.insertionMode=Ne.BEFORE_HTML}function oZ(e,g){e._err(g,fn.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,z.DOCUMENT_MODE.QUIRKS),e.insertionMode=Ne.BEFORE_HTML,e._processToken(g)}function KGt(e,g){g.tagID===z.TAG_ID.HTML?(e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.BEFORE_HEAD):iv(e,g)}function xGt(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)&&iv(e,g)}function iv(e,g){e._insertFakeRootElement(),e.insertionMode=Ne.BEFORE_HEAD,e._processToken(g)}function DGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.HEAD:{e._insertElement(g,z.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=Ne.IN_HEAD;break}default:nv(e,g)}}function FGt(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?nv(e,g):e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}function nv(e,g){e._insertFakeElement(z.TAG_NAMES.HEAD,z.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=Ne.IN_HEAD,e._processToken(g)}function ba(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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,$n.TokenizerMode.RCDATA);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?e._switchToTextParsing(g,$n.TokenizerMode.RAWTEXT):(e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_HEAD_NO_SCRIPT);break}case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{e._switchToTextParsing(g,$n.TokenizerMode.RAWTEXT);break}case z.TAG_ID.SCRIPT:{e._switchToTextParsing(g,$n.TokenizerMode.SCRIPT_DATA);break}case z.TAG_ID.TEMPLATE:{e._insertTemplate(g),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Ne.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Ne.IN_TEMPLATE);break}case z.TAG_ID.HEAD:{e._err(g,fn.ERR.misplacedStartTagForHeadElement);break}default:Cv(e,g)}}function EGt(e,g){switch(g.tagID){case z.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=Ne.AFTER_HEAD;break}case z.TAG_ID.BODY:case z.TAG_ID.BR:case z.TAG_ID.HTML:{Cv(e,g);break}case z.TAG_ID.TEMPLATE:{sm(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function sm(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==z.TAG_ID.TEMPLATE&&e._err(g,fn.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}function Cv(e,g){e.openElements.pop(),e.insertionMode=Ne.AFTER_HEAD,e._processToken(g)}function MGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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:{ba(e,g);break}case z.TAG_ID.NOSCRIPT:{e._err(g,fn.ERR.nestedNoscriptInHead);break}default:rv(e,g)}}function zGt(e,g){switch(g.tagID){case z.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=Ne.IN_HEAD;break}case z.TAG_ID.BR:{rv(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function rv(e,g){const I=g.type===Ri.TokenType.EOF?fn.ERR.openElementsLeftAfterEof:fn.ERR.disallowedContentInNoscriptInHead;e._err(g,I),e.openElements.pop(),e.insertionMode=Ne.IN_HEAD,e._processToken(g)}function PGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.BODY:{e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=Ne.IN_BODY;break}case z.TAG_ID.FRAMESET:{e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.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,fn.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,z.TAG_ID.HEAD),ba(e,g),e.openElements.remove(e.headElement);break}case z.TAG_ID.HEAD:{e._err(g,fn.ERR.misplacedStartTagForHeadElement);break}default:ov(e,g)}}function JGt(e,g){switch(g.tagID){case z.TAG_ID.BODY:case z.TAG_ID.HTML:case z.TAG_ID.BR:{ov(e,g);break}case z.TAG_ID.TEMPLATE:{sm(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function ov(e,g){e._insertFakeElement(z.TAG_NAMES.BODY,z.TAG_ID.BODY),e.insertionMode=Ne.IN_BODY,Ak(e,g)}function Ak(e,g){switch(g.type){case Ri.TokenType.CHARACTER:{fwe(e,g);break}case Ri.TokenType.WHITESPACE_CHARACTER:{mwe(e,g);break}case Ri.TokenType.COMMENT:{Mz(e,g);break}case Ri.TokenType.START_TAG:{Pn(e,g);break}case Ri.TokenType.END_TAG:{sk(e,g);break}case Ri.TokenType.EOF:{Zwe(e,g);break}}}function mwe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function fwe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function OGt(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function _Gt(e,g){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(I,g.attrs))}function LGt(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=Ne.IN_FRAMESET)}function UGt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML)}function QGt(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 jGt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function $Gt(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 qGt(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 evt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.tokenizer.state=$n.TokenizerMode.PLAINTEXT}function tvt(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 gvt(e,g){const I=e.activeFormattingElements.getElementEntryInScopeWithTagName(z.TAG_NAMES.A);I&&(Xj(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 Ivt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function ivt(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(z.TAG_ID.NOBR)&&(Xj(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function nvt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function Cvt(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=Ne.IN_TABLE}function pwe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function bwe(e){const g=(0,Ri.getTokenAttr)(e,z.ATTRS.TYPE);return g!=null&&g.toLowerCase()===GGt}function rvt(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),bwe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function ovt(e,g){e._appendElement(g,z.NS.HTML),g.ackSelfClosing=!0}function avt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function Avt(e,g){g.tagName=z.TAG_NAMES.IMG,g.tagID=z.TAG_ID.IMG,pwe(e,g)}function svt(e,g){e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.tokenizer.state=$n.TokenizerMode.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Ne.TEXT}function lvt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,$n.TokenizerMode.RAWTEXT)}function cvt(e,g){e.framesetOk=!1,e._switchToTextParsing(g,$n.TokenizerMode.RAWTEXT)}function bCe(e,g){e._switchToTextParsing(g,$n.TokenizerMode.RAWTEXT)}function uvt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Ne.IN_TABLE||e.insertionMode===Ne.IN_CAPTION||e.insertionMode===Ne.IN_TABLE_BODY||e.insertionMode===Ne.IN_ROW||e.insertionMode===Ne.IN_CELL?Ne.IN_SELECT_IN_TABLE:Ne.IN_SELECT}function dvt(e,g){e.openElements.currentTagId===z.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function hvt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,z.NS.HTML)}function mvt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.RTC),e._insertElement(g,z.NS.HTML)}function fvt(e,g){e._reconstructActiveFormattingElements(),_a.adjustTokenMathMLAttrs(g),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.MATHML):e._insertElement(g,z.NS.MATHML),g.ackSelfClosing=!0}function pvt(e,g){e._reconstructActiveFormattingElements(),_a.adjustTokenSVGAttrs(g),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.SVG):e._insertElement(g,z.NS.SVG),g.ackSelfClosing=!0}function yCe(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function Pn(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:{Ivt(e,g);break}case z.TAG_ID.A:{gvt(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:{QGt(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:{UGt(e,g);break}case z.TAG_ID.LI:case z.TAG_ID.DD:case z.TAG_ID.DT:{qGt(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:{pwe(e,g);break}case z.TAG_ID.HR:{avt(e,g);break}case z.TAG_ID.RB:case z.TAG_ID.RTC:{hvt(e,g);break}case z.TAG_ID.RT:case z.TAG_ID.RP:{mvt(e,g);break}case z.TAG_ID.PRE:case z.TAG_ID.LISTING:{jGt(e,g);break}case z.TAG_ID.XMP:{lvt(e,g);break}case z.TAG_ID.SVG:{pvt(e,g);break}case z.TAG_ID.HTML:{OGt(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:{ba(e,g);break}case z.TAG_ID.BODY:{_Gt(e,g);break}case z.TAG_ID.FORM:{$Gt(e,g);break}case z.TAG_ID.NOBR:{ivt(e,g);break}case z.TAG_ID.MATH:{fvt(e,g);break}case z.TAG_ID.TABLE:{Cvt(e,g);break}case z.TAG_ID.INPUT:{rvt(e,g);break}case z.TAG_ID.PARAM:case z.TAG_ID.TRACK:case z.TAG_ID.SOURCE:{ovt(e,g);break}case z.TAG_ID.IMAGE:{Avt(e,g);break}case z.TAG_ID.BUTTON:{tvt(e,g);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{nvt(e,g);break}case z.TAG_ID.IFRAME:{cvt(e,g);break}case z.TAG_ID.SELECT:{uvt(e,g);break}case z.TAG_ID.OPTION:case z.TAG_ID.OPTGROUP:{dvt(e,g);break}case z.TAG_ID.NOEMBED:{bCe(e,g);break}case z.TAG_ID.FRAMESET:{LGt(e,g);break}case z.TAG_ID.TEXTAREA:{svt(e,g);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?bCe(e,g):yCe(e,g);break}case z.TAG_ID.PLAINTEXT:{evt(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:yCe(e,g)}}function bvt(e,g){if(e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=Ne.AFTER_BODY,e.options.sourceCodeLocationInfo)){const I=e.openElements.tryPeekProperlyNestedBodyElement();I&&e._setEndLocation(I,g)}}function yvt(e,g){e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=Ne.AFTER_BODY,Wwe(e,g))}function Zvt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I))}function Gvt(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 vvt(e){e.openElements.hasInButtonScope(z.TAG_ID.P)||e._insertFakeElement(z.TAG_NAMES.P,z.TAG_ID.P),e._closePElement()}function Bvt(e){e.openElements.hasInListItemScope(z.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.LI),e.openElements.popUntilTagNamePopped(z.TAG_ID.LI))}function Svt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.popUntilTagNamePopped(I))}function wvt(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function Vvt(e,g){const I=g.tagID;e.openElements.hasInScope(I)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(I),e.activeFormattingElements.clearToLastMarker())}function Rvt(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(z.TAG_NAMES.BR,z.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function ywe(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 sk(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:{Xj(e,g);break}case z.TAG_ID.P:{vvt(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:{Zvt(e,g);break}case z.TAG_ID.LI:{Bvt(e);break}case z.TAG_ID.DD:case z.TAG_ID.DT:{Svt(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:{wvt(e);break}case z.TAG_ID.BR:{Rvt(e);break}case z.TAG_ID.BODY:{bvt(e,g);break}case z.TAG_ID.HTML:{yvt(e,g);break}case z.TAG_ID.FORM:{Gvt(e);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{Vvt(e,g);break}case z.TAG_ID.TEMPLATE:{sm(e,g);break}default:ywe(e,g)}}function Zwe(e,g){e.tmplInsertionModeStack.length>0?Rwe(e,g):Hj(e,g)}function Wvt(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 Xvt(e,g){e._err(g,fn.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function BD(e,g){if(hwe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Ne.IN_TABLE_TEXT,g.type){case Ri.TokenType.CHARACTER:{vwe(e,g);break}case Ri.TokenType.WHITESPACE_CHARACTER:{Gwe(e,g);break}}else aw(e,g)}function Hvt(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_CAPTION}function Tvt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_COLUMN_GROUP}function Nvt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.COLGROUP,z.TAG_ID.COLGROUP),e.insertionMode=Ne.IN_COLUMN_GROUP,Tj(e,g)}function kvt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_TABLE_BODY}function Yvt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.TBODY,z.TAG_ID.TBODY),e.insertionMode=Ne.IN_TABLE_BODY,lk(e,g)}function Kvt(e,g){e.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function xvt(e,g){bwe(g)?e._appendElement(g,z.NS.HTML):aw(e,g),g.ackSelfClosing=!0}function Dvt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,z.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function Ub(e,g){switch(g.tagID){case z.TAG_ID.TD:case z.TAG_ID.TH:case z.TAG_ID.TR:{Yvt(e,g);break}case z.TAG_ID.STYLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.TEMPLATE:{ba(e,g);break}case z.TAG_ID.COL:{Nvt(e,g);break}case z.TAG_ID.FORM:{Dvt(e,g);break}case z.TAG_ID.TABLE:{Kvt(e,g);break}case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{kvt(e,g);break}case z.TAG_ID.INPUT:{xvt(e,g);break}case z.TAG_ID.CAPTION:{Hvt(e,g);break}case z.TAG_ID.COLGROUP:{Tvt(e,g);break}default:aw(e,g)}}function zB(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:{sm(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:aw(e,g)}}function aw(e,g){const I=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,Ak(e,g),e.fosterParentingEnabled=I}function Gwe(e,g){e.pendingCharacterTokens.push(g)}function vwe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function aZ(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:{sm(e,g);break}}}function Jvt(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)):wwe(e,g)}function Ovt(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)):Vwe(e,g)}function _vt(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:{ba(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]=Ne.IN_TABLE,e.insertionMode=Ne.IN_TABLE,Ub(e,g);break}case z.TAG_ID.COL:{e.tmplInsertionModeStack[0]=Ne.IN_COLUMN_GROUP,e.insertionMode=Ne.IN_COLUMN_GROUP,Tj(e,g);break}case z.TAG_ID.TR:{e.tmplInsertionModeStack[0]=Ne.IN_TABLE_BODY,e.insertionMode=Ne.IN_TABLE_BODY,lk(e,g);break}case z.TAG_ID.TD:case z.TAG_ID.TH:{e.tmplInsertionModeStack[0]=Ne.IN_ROW,e.insertionMode=Ne.IN_ROW,ck(e,g);break}default:e.tmplInsertionModeStack[0]=Ne.IN_BODY,e.insertionMode=Ne.IN_BODY,Pn(e,g)}}function Lvt(e,g){g.tagID===z.TAG_ID.TEMPLATE&&sm(e,g)}function Rwe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):Hj(e,g)}function Uvt(e,g){g.tagID===z.TAG_ID.HTML?Pn(e,g):F9(e,g)}function Wwe(e,g){var I;if(g.tagID===z.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=Ne.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 F9(e,g)}function F9(e,g){e.insertionMode=Ne.IN_BODY,Ak(e,g)}function Qvt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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:{ba(e,g);break}}}function jvt(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=Ne.AFTER_FRAMESET))}function $vt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.NOFRAMES:{ba(e,g);break}}}function qvt(e,g){g.tagID===z.TAG_ID.HTML&&(e.insertionMode=Ne.AFTER_AFTER_FRAMESET)}function eBt(e,g){g.tagID===z.TAG_ID.HTML?Pn(e,g):eW(e,g)}function eW(e,g){e.insertionMode=Ne.IN_BODY,Ak(e,g)}function tBt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.NOFRAMES:{ba(e,g);break}}}function gBt(e,g){g.chars=dwe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function IBt(e,g){e._insertCharacters(g),e.framesetOk=!1}function Xwe(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==z.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function iBt(e,g){if(_a.causesExit(g))Xwe(e),e._startTagOutsideForeignContent(g);else{const I=e._getAdjustedCurrentElement(),i=e.treeAdapter.getNamespaceURI(I);i===z.NS.MATHML?_a.adjustTokenMathMLAttrs(g):i===z.NS.SVG&&(_a.adjustTokenSVGTagName(g),_a.adjustTokenSVGAttrs(g)),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,i):e._insertElement(g,i),g.ackSelfClosing=!0}}function nBt(e,g){if(g.tagID===z.TAG_ID.P||g.tagID===z.TAG_ID.BR){Xwe(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 Qb={};Object.defineProperty(Qb,"__esModule",{value:!0});Qb.serializeOuter=Qb.serialize=void 0;const rI=Cl,Hwe=Kb,CBt=ak,rBt=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 Twe(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===rI.NS.HTML&&rBt.has(g.treeAdapter.getTagName(e))}const Nwe={treeAdapter:CBt.defaultTreeAdapter,scriptingEnabled:!0};function oBt(e,g){const I=Object.assign(Object.assign({},Nwe),g);return Twe(e,I)?"":kwe(e,I)}Qb.serialize=oBt;function aBt(e,g){const I=Object.assign(Object.assign({},Nwe),g);return Ywe(e,I)}Qb.serializeOuter=aBt;function kwe(e,g){let I="";const i=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===rI.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===rI.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(i);if(n)for(const C of n)I+=Ywe(C,g);return I}function Ywe(e,g){return g.treeAdapter.isElementNode(e)?ABt(e,g):g.treeAdapter.isTextNode(e)?lBt(e,g):g.treeAdapter.isCommentNode(e)?cBt(e,g):g.treeAdapter.isDocumentTypeNode(e)?uBt(e,g):""}function ABt(e,g){const I=g.treeAdapter.getTagName(e);return`<${I}${sBt(e,g)}>${Twe(e,g)?"":`${kwe(e,g)}`}`}function sBt(e,{treeAdapter:g}){let I="";for(const i of g.getAttrList(e)){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,Hwe.escapeAttribute)(i.value)}"`}return I}function lBt(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)===rI.NS.HTML&&(0,rI.hasUnescapedText)(C,g.scriptingEnabled)?i:(0,Hwe.escapeText)(i)}function cBt(e,{treeAdapter:g}){return``}function uBt(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=MB;var I=ak;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return I.defaultTreeAdapter}});var i=MB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return i.Parser}});var n=Qb;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var C=ow;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return C.ERR}}),e.foreignContent=Wj,e.html=Cl,e.Token=rk;var r=hh;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})(Cwe);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.adapter=e.serializeDoctypeContent=void 0;const g=Cwe,I=En;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)}}})(nwe);var dBt=$e&&$e.__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),SCe.has(g)?this.foreignContext.push(!0):wCe.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()),(SCe.has(s)||wCe.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,ZCe.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===bR.QuoteType.Double?'"':g===bR.QuoteType.Single?"'":g===bR.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(BBt),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.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 QN={};(function(e){var g=$e&&$e.__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=yD(l,r);)if(e(l))return!0;return!1};var a=new WeakSet;return function(A){for(var l=A;l=yD(l,r);)if(!a.has(l)){if(r.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=yD(l,r));return!1};case bo.SelectorType.Parent:return function(A){return r.getChildren(A).some(function(l){return r.isTag(l)&&e(l)})};case bo.SelectorType.Child:return function(A){var l=r.getParent(A);return l!=null&&r.isTag(l)&&e(l)};case bo.SelectorType.Sibling:return function(A){for(var l=r.getSiblings(A),c=0;c0&&(0,xz.isTraversal)(o[0])&&o[0].type!==ms.SelectorType.Descendant))if(n&&!o.some(VSe))o.unshift(Lpt);else continue;o.unshift(Qpt)}}function S4(e,g,i){var I;e.forEach(xz.default),i=(I=g.context)!==null&&I!==void 0?I:i;var n=Array.isArray(i),r=i&&(Array.isArray(i)?i:[i]);if(g.relativeSelector!==!1)jpt(e,g,r);else if(e.some(function(a){return a.length>0&&(0,xz.isTraversal)(a[0])}))throw new Error("Relative selectors are not allowed when the `relativeSelector` option is disabled");var C=!1,o=e.map(function(a){if(a.length>=2){var s=a[0],A=a[1];s.type!==ms.SelectorType.Pseudo||s.name!=="scope"||(n&&A.type===ms.SelectorType.Descendant?a[1]=Upt:(A.type===ms.SelectorType.Adjacent||A.type===ms.SelectorType.Sibling)&&(C=!0))}return $pt(a,g,r)}).reduce(qpt,mc.default.falseFunc);return o.shouldTestNextSiblings=C,o}Tc.compileToken=S4;function $pt(e,g,i){var I;return e.reduce(function(n,r){return n===mc.default.falseFunc?mc.default.falseFunc:(0,Opt.compileGeneralSelector)(n,r,g,i,S4)},(I=g.rootFunc)!==null&&I!==void 0?I:mc.default.trueFunc)}function qpt(e,g){return g===mc.default.falseFunc||e===mc.default.trueFunc?e:e===mc.default.falseFunc||g===mc.default.trueFunc?g:function(I){return e(I)||g(I)}}(function(e){var g=$e&&$e.__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=$e&&$e.__setModuleDefault||(Object.create?function(b,p){Object.defineProperty(b,"default",{enumerable:!0,value:p})}:function(b,p){b.default=p}),I=$e&&$e.__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=$e&&$e.__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 r=I(ra),C=n(om),o=Tc,a=QN,s=function(b,p){return b===p},A={adapter:r,equals:s};function l(b){var p,y,Z,B,G=b??A;return(p=G.adapter)!==null&&p!==void 0||(G.adapter=r),(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?C+1:1/0:0;case"lt":return isFinite(C)?C>=0?Math.min(C,r):1/0:0;case"gt":return isFinite(C)?1/0:0;case"odd":return 2*r;case"even":return 2*r-1;case"last":case"not":return 1/0}}e.getLimit=i})(w4);Object.defineProperty(Mb,"__esModule",{value:!0});Mb.groupSelectors=Mb.getDocumentRoot=void 0;var ebt=w4;function tbt(e){for(;e.parent;)e=e.parent;return e}Mb.getDocumentRoot=tbt;function gbt(e){for(var g=[],i=[],I=0,n=e;I0&&R.some((0,o._compileToken)(V,X))||H.some(function(Y){return y(Y,R,X).length>0})}e.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&&C.length>1?i.reduce(function(o,a){return a(o)},C):C)}}}var nw=R4(function(e,g){for(var i,I=[],n=0;n0})}Vt.has=hbt;function mbt(){return this.length>1?this._make(this[0]):this}Vt.first=mbt;function fbt(){return this.length>0?this._make(this[this.length-1]):this}Vt.last=fbt;function pbt(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:[]))}Vt.eq=pbt;function bbt(e){return e==null?this.toArray():this[e<0?this.length+e:e]}Vt.get=bbt;function ybt(){return Array.prototype.slice.call(this)}Vt.toArray=ybt;function Zbt(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,ca.isCheerio)(e)?e[0]:e),Array.prototype.indexOf.call(g,i)}Vt.index=Zbt;function Gbt(e,g){return this._make(Array.prototype.slice.call(this,e,g))}Vt.slice=Gbt;function vbt(){var e;return(e=this.prevObject)!==null&&e!==void 0?e:this._make([])}Vt.end=vbt;function Bbt(e,g){var i=this._make(e,g),I=(0,ZA.uniqueSort)(Ez(Ez([],this.get(),!0),i.get(),!0));return this._make(I)}Vt.add=Bbt;function Sbt(e){return this.prevObject?this.add(e?this.prevObject.filter(e):this.prevObject):this}Vt.addBack=Sbt;var ng={},ch={};Object.defineProperty(ch,"__esModule",{value:!0});ch.update=ch.getParse=void 0;var wbt=ra,ere=En;function Rbt(e){return function(i,I,n,r){if(typeof Buffer<"u"&&Buffer.isBuffer(i)&&(i=i.toString()),typeof i=="string")return e(i,I,n,r);var C=i;if(!Array.isArray(C)&&(0,ere.isDocument)(C))return C;var o=new ere.Document([]);return WSe(C,o),o}}ch.getParse=Rbt;function WSe(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=(r=l.next)!==null&&r!==void 0?r:null),l.next&&(l.next.prev=(C=l.prev)!==null&&C!==void 0?C: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 Hbt(e){var g=(0,KI.isCheerio)(e)?e:this._make(e);return g.append(this),this}ng.appendTo=Hbt;function Tbt(e){var g=(0,KI.isCheerio)(e)?e:this._make(e);return g.prepend(this),this}ng.prependTo=Tbt;ng.append=XSe(function(e,g,i){lu(g,g.length,0,e,i)});ng.prepend=XSe(function(e,g,i){lu(g,0,0,e,i)});function HSe(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=r.slice(0,C).trim(),g[i]=r.slice(C+1).trim()}return g}var Pb={};Object.defineProperty(Pb,"__esModule",{value:!0});Pb.serializeArray=Pb.serialize=void 0;var Qbt=su,gre="input,select,textarea,keygen",jbt=/%20/g,ire=/\r?\n/g;function $bt(){var e=this.serializeArray(),g=e.map(function(i){return"".concat(encodeURIComponent(i.name),"=").concat(encodeURIComponent(i.value))});return g.join("&").replace(jbt,"+")}Pb.serialize=$bt;function qbt(){var e=this;return this.map(function(g,i){var I=e._make(i);return(0,Qbt.isTag)(i)&&i.name==="form"?I.find(gre).toArray():I.filter(gre).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),r=n.attr("name"),C=(I=n.val())!==null&&I!==void 0?I:"";return Array.isArray(C)?C.map(function(o){return{name:r,value:o.replace(ire,`\r +`)}}):{name:r,value:C.replace(ire,`\r +`)}}).toArray()}Pb.serializeArray=qbt;var e0t=$e&&$e.__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]}),t0t=$e&&$e.__setModuleDefault||(Object.create?function(e,g){Object.defineProperty(e,"default",{enumerable:!0,value:g})}:function(e,g){e.default=g}),Cw=$e&&$e.__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)&&e0t(g,e,i);return t0t(g,e),g};Object.defineProperty(JN,"__esModule",{value:!0});JN.Cheerio=void 0;var g0t=Cw(hI),i0t=Cw(Vt),I0t=Cw(ng),n0t=Cw($N),r0t=Cw(Pb),ow=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 r(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}e.isControlCodePoint=r;function C(o){return o>=64976&&o<=65007||g.has(o)}e.isUndefinedCodePoint=C})(ek);var aw={};(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={}))})(aw);function u0t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ire(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,Jn.CODE_POINTS.EOF;const n=this.html.charCodeAt(I);return n===Jn.CODE_POINTS.CARRIAGE_RETURN?Jn.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,Jn.CODE_POINTS.EOF;let i=this.html.charCodeAt(this.pos);return i===Jn.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,Jn.CODE_POINTS.LINE_FEED):i===Jn.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,Jn.isSurrogate)(i)&&(i=this._processSurrogate(i)),this.handler.onParseError===null||i>31&&i<127||i===Jn.CODE_POINTS.LINE_FEED||i===Jn.CODE_POINTS.CARRIAGE_RETURN||i>159&&i<64976||this._checkForProblematicCharacters(i),i)}},{key:"_checkForProblematicCharacters",value:function(i){(0,Jn.isControlCodePoint)(i)?this._err(GD.ERR.controlCharacterInInputStream):(0,Jn.isUndefinedCodePoint)(i)&&this._err(GD.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})(tk);var nl={};(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 r(A){var l;return(l=n.get(A))!==null&&l!==void 0?l:I.UNKNOWN}e.getTagID=r;const C=I;e.SPECIAL_ELEMENTS={[g.HTML]:new Set([C.ADDRESS,C.APPLET,C.AREA,C.ARTICLE,C.ASIDE,C.BASE,C.BASEFONT,C.BGSOUND,C.BLOCKQUOTE,C.BODY,C.BR,C.BUTTON,C.CAPTION,C.CENTER,C.COL,C.COLGROUP,C.DD,C.DETAILS,C.DIR,C.DIV,C.DL,C.DT,C.EMBED,C.FIELDSET,C.FIGCAPTION,C.FIGURE,C.FOOTER,C.FORM,C.FRAME,C.FRAMESET,C.H1,C.H2,C.H3,C.H4,C.H5,C.H6,C.HEAD,C.HEADER,C.HGROUP,C.HR,C.HTML,C.IFRAME,C.IMG,C.INPUT,C.LI,C.LINK,C.LISTING,C.MAIN,C.MARQUEE,C.MENU,C.META,C.NAV,C.NOEMBED,C.NOFRAMES,C.NOSCRIPT,C.OBJECT,C.OL,C.P,C.PARAM,C.PLAINTEXT,C.PRE,C.SCRIPT,C.SECTION,C.SELECT,C.SOURCE,C.STYLE,C.SUMMARY,C.TABLE,C.TBODY,C.TD,C.TEMPLATE,C.TEXTAREA,C.TFOOT,C.TH,C.THEAD,C.TITLE,C.TR,C.TRACK,C.UL,C.WBR,C.XMP]),[g.MATHML]:new Set([C.MI,C.MO,C.MN,C.MS,C.MTEXT,C.ANNOTATION_XML]),[g.SVG]:new Set([C.TITLE,C.FOREIGN_OBJECT,C.DESC]),[g.XLINK]:new Set,[g.XML]:new Set,[g.XMLNS]:new Set};function o(A){return A===C.H1||A===C.H2||A===C.H3||A===C.H4||A===C.H5||A===C.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})(nl);function b0t(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=Ae.CODE_POINTS.DIGIT_0&&e<=Ae.CODE_POINTS.DIGIT_9}function UZ(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_Z}function S0t(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_Z}function Hl(e){return S0t(e)||UZ(e)}function zz(e){return Hl(e)||jG(e)}function KSe(e){return e>=Ae.CODE_POINTS.LATIN_CAPITAL_A&&e<=Ae.CODE_POINTS.LATIN_CAPITAL_F}function FSe(e){return e>=Ae.CODE_POINTS.LATIN_SMALL_A&&e<=Ae.CODE_POINTS.LATIN_SMALL_F}function w0t(e){return jG(e)||KSe(e)||FSe(e)}function pV(e){return e+32}function DSe(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 R0t(e){return e===Ae.CODE_POINTS.EQUALS_SIGN||zz(e)}function rre(e){return DSe(e)||e===Ae.CODE_POINTS.SOLIDUS||e===Ae.CODE_POINTS.GREATER_THAN_SIGN}let V0t=function(){function e(g,i){b0t(this,e),this.options=g,this.handler=i,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=Ze.DATA,this.returnState=Ze.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new v0t.Preprocessor(i),this.currentLocation=this.getCurrentLocation(-1)}return y0t(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(qe.ERR.endTagWithAttributes),i.selfClosing&&this._err(qe.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 br.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case br.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case br.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:br.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=DSe(i)?br.TokenType.WHITESPACE_CHARACTER:i===Ae.CODE_POINTS.NULL?br.TokenType.NULL_CHARACTER:br.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(I,String.fromCodePoint(i))}},{key:"_emitChars",value:function(i){this._appendCharToCurrentCharacterToken(br.TokenType.CHARACTER,i)}},{key:"_matchNamedCharacterReference",value:function(i){let I=null,n=0,r=!1;for(let C=0,o=Va.htmlDecodeTree[0];C>=0&&(C=(0,Va.determineBranch)(Va.htmlDecodeTree,o,C+1,i),!(C<0));i=this._consume()){n+=1,o=Va.htmlDecodeTree[C];const a=o&Va.BinTrieFlags.VALUE_LENGTH;if(a){const s=(a>>14)-1;if(i!==Ae.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&R0t(this.preprocessor.peek(1))?(I=[Ae.CODE_POINTS.AMPERSAND],C+=s):(I=s===0?[Va.htmlDecodeTree[C]&~Va.BinTrieFlags.VALUE_LENGTH]:s===1?[Va.htmlDecodeTree[++C]]:[Va.htmlDecodeTree[++C],Va.htmlDecodeTree[++C]],n=0,r=i!==Ae.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),r&&!this.preprocessor.endOfChunkHit&&this._err(qe.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),I}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===Ze.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===Ze.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===Ze.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 Ze.DATA:{this._stateData(i);break}case Ze.RCDATA:{this._stateRcdata(i);break}case Ze.RAWTEXT:{this._stateRawtext(i);break}case Ze.SCRIPT_DATA:{this._stateScriptData(i);break}case Ze.PLAINTEXT:{this._statePlaintext(i);break}case Ze.TAG_OPEN:{this._stateTagOpen(i);break}case Ze.END_TAG_OPEN:{this._stateEndTagOpen(i);break}case Ze.TAG_NAME:{this._stateTagName(i);break}case Ze.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(i);break}case Ze.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(i);break}case Ze.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(i);break}case Ze.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(i);break}case Ze.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(i);break}case Ze.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(i);break}case Ze.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(i);break}case Ze.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(i);break}case Ze.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(i);break}case Ze.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(i);break}case Ze.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(i);break}case Ze.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(i);break}case Ze.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(i);break}case Ze.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(i);break}case Ze.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(i);break}case Ze.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(i);break}case Ze.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(i);break}case Ze.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(i);break}case Ze.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(i);break}case Ze.ATTRIBUTE_NAME:{this._stateAttributeName(i);break}case Ze.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(i);break}case Ze.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(i);break}case Ze.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(i);break}case Ze.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(i);break}case Ze.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(i);break}case Ze.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(i);break}case Ze.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(i);break}case Ze.BOGUS_COMMENT:{this._stateBogusComment(i);break}case Ze.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(i);break}case Ze.COMMENT_START:{this._stateCommentStart(i);break}case Ze.COMMENT_START_DASH:{this._stateCommentStartDash(i);break}case Ze.COMMENT:{this._stateComment(i);break}case Ze.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(i);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(i);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(i);break}case Ze.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(i);break}case Ze.COMMENT_END_DASH:{this._stateCommentEndDash(i);break}case Ze.COMMENT_END:{this._stateCommentEnd(i);break}case Ze.COMMENT_END_BANG:{this._stateCommentEndBang(i);break}case Ze.DOCTYPE:{this._stateDoctype(i);break}case Ze.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(i);break}case Ze.DOCTYPE_NAME:{this._stateDoctypeName(i);break}case Ze.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(i);break}case Ze.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(i);break}case Ze.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(i);break}case Ze.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(i);break}case Ze.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(i);break}case Ze.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(i);break}case Ze.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(i);break}case Ze.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(i);break}case Ze.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(i);break}case Ze.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(i);break}case Ze.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(i);break}case Ze.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(i);break}case Ze.BOGUS_DOCTYPE:{this._stateBogusDoctype(i);break}case Ze.CDATA_SECTION:{this._stateCdataSection(i);break}case Ze.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(i);break}case Ze.CDATA_SECTION_END:{this._stateCdataSectionEnd(i);break}case Ze.CHARACTER_REFERENCE:{this._stateCharacterReference(i);break}case Ze.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(i);break}case Ze.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(i);break}case Ze.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(i);break}case Ze.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(i);break}case Ze.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(i);break}case Ze.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(i);break}case Ze.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=Ze.TAG_OPEN;break}case Ae.CODE_POINTS.AMPERSAND:{this.returnState=Ze.DATA,this.state=Ze.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.RCDATA,this.state=Ze.CHARACTER_REFERENCE;break}case Ae.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ze.RCDATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.RAWTEXT_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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=Ze.SCRIPT_DATA_LESS_THAN_SIGN;break}case Ae.CODE_POINTS.NULL:{this._err(qe.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(qe.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(Hl(i))this._createStartTagToken(),this.state=Ze.TAG_NAME,this._stateTagName(i);else switch(i){case Ae.CODE_POINTS.EXCLAMATION_MARK:{this.state=Ze.MARKUP_DECLARATION_OPEN;break}case Ae.CODE_POINTS.SOLIDUS:{this.state=Ze.END_TAG_OPEN;break}case Ae.CODE_POINTS.QUESTION_MARK:{this._err(qe.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=Ze.BOGUS_COMMENT,this._stateBogusComment(i);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(qe.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=Ze.DATA,this._stateData(i)}}},{key:"_stateEndTagOpen",value:function(i){if(Hl(i))this._createEndTagToken(),this.state=Ze.TAG_NAME,this._stateTagName(i);else switch(i){case Ae.CODE_POINTS.GREATER_THAN_SIGN:{this._err(qe.ERR.missingEndTagName),this.state=Ze.DATA;break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofBeforeTagName),this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(qe.ERR.unexpectedNullCharacter),this.state=Ze.SCRIPT_DATA_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ze.SCRIPT_DATA_ESCAPED,this._emitCodePoint(i)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(i){i===Ae.CODE_POINTS.SOLIDUS?this.state=Ze.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Hl(i)?(this._emitChars("<"),this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(i)):(this._emitChars("<"),this.state=Ze.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(i))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(i){Hl(i)?(this.state=Ze.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(i)):(this._emitChars("");break}case Ae.CODE_POINTS.NULL:{this._err(qe.ERR.unexpectedNullCharacter),this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(Ae.REPLACEMENT_CHARACTER);break}case Ae.CODE_POINTS.EOF:{this._err(qe.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(i)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(i){i===Ae.CODE_POINTS.SOLIDUS?(this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=Ze.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(i))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(i){if(this.preprocessor.startsWith(Ae.SEQUENCES.SCRIPT,!1)&&rre(this.preprocessor.peek(Ae.SEQUENCES.SCRIPT.length))){this._emitCodePoint(i);for(let I=0;I1114111)this._err(qe.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isSurrogate)(this.charRefCode))this._err(qe.ERR.surrogateCharacterReference),this.charRefCode=Ae.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,Ae.isUndefinedCodePoint)(this.charRefCode))this._err(qe.ERR.noncharacterCharacterReference);else if((0,Ae.isControlCodePoint)(this.charRefCode)||this.charRefCode===Ae.CODE_POINTS.CARRIAGE_RETURN){this._err(qe.ERR.controlCharacterReference);const I=B0t.get(this.charRefCode);I!==void 0&&(this.charRefCode=I)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,i)}}]),e}();uh.Tokenizer=V0t;var gk={};function W0t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Cre(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 r=this._indexOf(i)+1;this.items.splice(r,0,I),this.tagIDs.splice(r,0,n),this.stackTop++,r===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,r===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(K0t,It.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(Y0t,It.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(k0t,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],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===It.NS.HTML)return!0;if(bV.get(n)===r)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(bV.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],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===It.NS.HTML)return!0;if((n===It.TAG_ID.UL||n===It.TAG_ID.OL)&&r===It.NS.HTML||bV.get(n)===r)return!1}return!0}},{key:"hasInButtonScope",value:function(i){for(let I=this.stackTop;I>=0;I--){const n=this.tagIDs[I],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===It.NS.HTML)return!0;if(n===It.TAG_ID.BUTTON&&r===It.NS.HTML||bV.get(n)===r)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(;xSe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;ore.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(i){for(;this.currentTagId!==i&&ore.has(this.currentTagId);)this.pop()}}]),e}();gk.OpenElementStack=D0t;var ESe={};(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>=C&&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})(ESe);var ik={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=nl;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,r){return{nodeName:I,tagName:I,attrs:r,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,r){const C=I.childNodes.indexOf(r);I.childNodes.splice(C,0,n),n.parentNode=I},setTemplateContent(I,n){I.content=n},getTemplateContent(I){return I.content},setDocumentType(I,n,r,C){const o=I.childNodes.find(a=>a.nodeName==="#documentType");if(o)o.name=n,o.publicId=r,o.systemId=C;else{const a={nodeName:"#documentType",name:n,publicId:r,systemId:C,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 r=I.childNodes[I.childNodes.length-1];if(e.defaultTreeAdapter.isTextNode(r)){r.value+=n;return}}e.defaultTreeAdapter.appendChild(I,i(n))},insertTextBefore(I,n,r){const C=I.childNodes[I.childNodes.indexOf(r)-1];C&&e.defaultTreeAdapter.isTextNode(C)?C.value+=n:e.defaultTreeAdapter.insertBefore(I,i(n),r)},adoptAttributes(I,n){const r=new Set(I.attrs.map(C=>C.name));for(let C=0;Ce.startsWith(i))}function J0t(e){return e.name===MSe&&e.publicId===null&&(e.systemId===null||e.systemId===x0t)}Ob.isConforming=J0t;function O0t(e){if(e.name!==MSe)return Jm.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===E0t)return Jm.DOCUMENT_MODE.QUIRKS;let{publicId:i}=e;if(i!==null){if(i=i.toLowerCase(),z0t.has(i))return Jm.DOCUMENT_MODE.QUIRKS;let I=g===null?M0t:zSe;if(are(i,I))return Jm.DOCUMENT_MODE.QUIRKS;if(I=g===null?PSe:P0t,are(i,I))return Jm.DOCUMENT_MODE.LIMITED_QUIRKS}return Jm.DOCUMENT_MODE.NO_QUIRKS}Ob.getDocumentMode=O0t;var H4={};(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=nl,i={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},I="definitionurl",n="definitionURL",r=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])),C=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,r;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(i,this.currentToken),(r=(n=this.treeAdapter).onItemPop)===null||r===void 0||r.call(n,i,this.openElements.current),I){let C,o;this.openElements.stackTop===0&&this.fragmentContext?(C=this.fragmentContext,o=this.fragmentContextID):{current:C,currentTagId:o}=this.openElements,this._setContextModes(C,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=Te.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Te.TEXT,this.originalInsertionMode=Te.IN_BODY,this.tokenizer.state=Qn.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=Qn.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=Qn.TokenizerMode.RAWTEXT;break}case M.TAG_ID.SCRIPT:{this.tokenizer.state=Qn.TokenizerMode.SCRIPT_DATA;break}case M.TAG_ID.PLAINTEXT:{this.tokenizer.state=Qn.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(i){const I=i.name||"",n=i.publicId||"",r=i.systemId||"";if(this.treeAdapter.setDocumentType(this.document,I,n,r),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 r=this.treeAdapter.getChildNodes(I),C=n?r.lastIndexOf(n):r.length,o=r[C-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,r=this.treeAdapter.getTagName(i),C=I.type===RI.TokenType.END_TAG&&r===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,C)}}},{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 RI.TokenType.CHARACTER:{this.onCharacter(i);break}case RI.TokenType.NULL_CHARACTER:{this.onNullCharacter(i);break}case RI.TokenType.COMMENT:{this.onComment(i);break}case RI.TokenType.DOCTYPE:{this.onDoctype(i);break}case RI.TokenType.START_TAG:{this._processStartTag(i);break}case RI.TokenType.END_TAG:{this.onEndTag(i);break}case RI.TokenType.EOF:{this.onEof(i);break}case RI.TokenType.WHITESPACE_CHARACTER:{this.onWhitespaceCharacter(i);break}}}},{key:"_isIntegrationPoint",value:function(i,I,n){const r=this.treeAdapter.getNamespaceURI(I),C=this.treeAdapter.getAttrList(I);return Oa.isIntegrationPoint(i,r,C,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const i=this.activeFormattingElements.entries.length;if(i){const I=this.activeFormattingElements.entries.findIndex(r=>r.type===sre.EntryType.Marker||this.openElements.contains(r.element)),n=I<0?i-1:I-1;for(let r=n;r>=0;r--){const C=this.activeFormattingElements.entries[r];this._insertElement(C.token,this.treeAdapter.getNamespaceURI(C.element)),C.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Te.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=Te.IN_ROW;return}case M.TAG_ID.TBODY:case M.TAG_ID.THEAD:case M.TAG_ID.TFOOT:{this.insertionMode=Te.IN_TABLE_BODY;return}case M.TAG_ID.CAPTION:{this.insertionMode=Te.IN_CAPTION;return}case M.TAG_ID.COLGROUP:{this.insertionMode=Te.IN_COLUMN_GROUP;return}case M.TAG_ID.TABLE:{this.insertionMode=Te.IN_TABLE;return}case M.TAG_ID.BODY:{this.insertionMode=Te.IN_BODY;return}case M.TAG_ID.FRAMESET:{this.insertionMode=Te.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?Te.AFTER_HEAD:Te.BEFORE_HEAD;return}case M.TAG_ID.TD:case M.TAG_ID.TH:{if(i>0){this.insertionMode=Te.IN_CELL;return}break}case M.TAG_ID.HEAD:{if(i>0){this.insertionMode=Te.IN_HEAD;return}break}}this.insertionMode=Te.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=Te.IN_SELECT_IN_TABLE;return}}this.insertionMode=Te.IN_SELECT}},{key:"_isElementCausesFosterParenting",value:function(i){return OSe.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){TZt(this,i);return}switch(this.insertionMode){case Te.INITIAL:{CZ(this,i);break}case Te.BEFORE_HTML:{$G(this,i);break}case Te.BEFORE_HEAD:{qG(this,i);break}case Te.IN_HEAD:{ev(this,i);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,i);break}case Te.AFTER_HEAD:{gv(this,i);break}case Te.IN_BODY:case Te.IN_CAPTION:case Te.IN_CELL:case Te.IN_TEMPLATE:{LSe(this,i);break}case Te.TEXT:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:{this._insertCharacters(i);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{BD(this,i);break}case Te.IN_TABLE_TEXT:{ewe(this,i);break}case Te.IN_COLUMN_GROUP:{xX(this,i);break}case Te.AFTER_BODY:{EX(this,i);break}case Te.AFTER_AFTER_BODY:{gW(this,i);break}}}},{key:"onNullCharacter",value:function(i){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){HZt(this,i);return}switch(this.insertionMode){case Te.INITIAL:{CZ(this,i);break}case Te.BEFORE_HTML:{$G(this,i);break}case Te.BEFORE_HEAD:{qG(this,i);break}case Te.IN_HEAD:{ev(this,i);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,i);break}case Te.AFTER_HEAD:{gv(this,i);break}case Te.TEXT:{this._insertCharacters(i);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{BD(this,i);break}case Te.IN_COLUMN_GROUP:{xX(this,i);break}case Te.AFTER_BODY:{EX(this,i);break}case Te.AFTER_AFTER_BODY:{gW(this,i);break}}}},{key:"onComment",value:function(i){if(this.skipNextNewLine=!1,this.currentNotInHTML){Pz(this,i);return}switch(this.insertionMode){case Te.INITIAL:case Te.BEFORE_HTML:case Te.BEFORE_HEAD:case Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:case Te.IN_BODY:case Te.IN_TABLE:case Te.IN_CAPTION:case Te.IN_COLUMN_GROUP:case Te.IN_TABLE_BODY:case Te.IN_ROW:case Te.IN_CELL:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:case Te.IN_TEMPLATE:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:{Pz(this,i);break}case Te.IN_TABLE_TEXT:{oZ(this,i);break}case Te.AFTER_BODY:{Ayt(this,i);break}case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{syt(this,i);break}}}},{key:"onDoctype",value:function(i){switch(this.skipNextNewLine=!1,this.insertionMode){case Te.INITIAL:{lyt(this,i);break}case Te.BEFORE_HEAD:case Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:{this._err(i,mn.ERR.misplacedDoctype);break}case Te.IN_TABLE_TEXT:{oZ(this,i);break}}}},{key:"onStartTag",value:function(i){this.skipNextNewLine=!1,this.currentToken=i,this._processStartTag(i),i.selfClosing&&!i.ackSelfClosing&&this._err(i,mn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(i){this.shouldProcessStartTagTokenInForeignContent(i)?NZt(this,i):this._startTagOutsideForeignContent(i)}},{key:"_startTagOutsideForeignContent",value:function(i){switch(this.insertionMode){case Te.INITIAL:{CZ(this,i);break}case Te.BEFORE_HTML:{cyt(this,i);break}case Te.BEFORE_HEAD:{dyt(this,i);break}case Te.IN_HEAD:{pa(this,i);break}case Te.IN_HEAD_NO_SCRIPT:{fyt(this,i);break}case Te.AFTER_HEAD:{byt(this,i);break}case Te.IN_BODY:{zn(this,i);break}case Te.IN_TABLE:{_b(this,i);break}case Te.IN_TABLE_TEXT:{oZ(this,i);break}case Te.IN_CAPTION:{hZt(this,i);break}case Te.IN_COLUMN_GROUP:{k4(this,i);break}case Te.IN_TABLE_BODY:{rk(this,i);break}case Te.IN_ROW:{Ck(this,i);break}case Te.IN_CELL:{pZt(this,i);break}case Te.IN_SELECT:{iwe(this,i);break}case Te.IN_SELECT_IN_TABLE:{yZt(this,i);break}case Te.IN_TEMPLATE:{GZt(this,i);break}case Te.AFTER_BODY:{BZt(this,i);break}case Te.IN_FRAMESET:{SZt(this,i);break}case Te.AFTER_FRAMESET:{RZt(this,i);break}case Te.AFTER_AFTER_BODY:{WZt(this,i);break}case Te.AFTER_AFTER_FRAMESET:{XZt(this,i);break}}}},{key:"onEndTag",value:function(i){this.skipNextNewLine=!1,this.currentToken=i,this.currentNotInHTML?kZt(this,i):this._endTagOutsideForeignContent(i)}},{key:"_endTagOutsideForeignContent",value:function(i){switch(this.insertionMode){case Te.INITIAL:{CZ(this,i);break}case Te.BEFORE_HTML:{uyt(this,i);break}case Te.BEFORE_HEAD:{hyt(this,i);break}case Te.IN_HEAD:{myt(this,i);break}case Te.IN_HEAD_NO_SCRIPT:{pyt(this,i);break}case Te.AFTER_HEAD:{yyt(this,i);break}case Te.IN_BODY:{nk(this,i);break}case Te.TEXT:{rZt(this,i);break}case Te.IN_TABLE:{PB(this,i);break}case Te.IN_TABLE_TEXT:{oZ(this,i);break}case Te.IN_CAPTION:{mZt(this,i);break}case Te.IN_COLUMN_GROUP:{fZt(this,i);break}case Te.IN_TABLE_BODY:{Jz(this,i);break}case Te.IN_ROW:{gwe(this,i);break}case Te.IN_CELL:{bZt(this,i);break}case Te.IN_SELECT:{Iwe(this,i);break}case Te.IN_SELECT_IN_TABLE:{ZZt(this,i);break}case Te.IN_TEMPLATE:{vZt(this,i);break}case Te.AFTER_BODY:{rwe(this,i);break}case Te.IN_FRAMESET:{wZt(this,i);break}case Te.AFTER_FRAMESET:{VZt(this,i);break}case Te.AFTER_AFTER_BODY:{gW(this,i);break}}}},{key:"onEof",value:function(i){switch(this.insertionMode){case Te.INITIAL:{CZ(this,i);break}case Te.BEFORE_HTML:{$G(this,i);break}case Te.BEFORE_HEAD:{qG(this,i);break}case Te.IN_HEAD:{ev(this,i);break}case Te.IN_HEAD_NO_SCRIPT:{tv(this,i);break}case Te.AFTER_HEAD:{gv(this,i);break}case Te.IN_BODY:case Te.IN_TABLE:case Te.IN_CAPTION:case Te.IN_COLUMN_GROUP:case Te.IN_TABLE_BODY:case Te.IN_ROW:case Te.IN_CELL:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:{$Se(this,i);break}case Te.TEXT:{CZt(this,i);break}case Te.IN_TABLE_TEXT:{oZ(this,i);break}case Te.IN_TEMPLATE:{nwe(this,i);break}case Te.AFTER_BODY:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{N4(this,i);break}}}},{key:"onWhitespaceCharacter",value:function(i){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,i.chars.charCodeAt(0)===JSe.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 Te.IN_HEAD:case Te.IN_HEAD_NO_SCRIPT:case Te.AFTER_HEAD:case Te.TEXT:case Te.IN_COLUMN_GROUP:case Te.IN_SELECT:case Te.IN_SELECT_IN_TABLE:case Te.IN_FRAMESET:case Te.AFTER_FRAMESET:{this._insertCharacters(i);break}case Te.IN_BODY:case Te.IN_CAPTION:case Te.IN_CELL:case Te.IN_TEMPLATE:case Te.AFTER_BODY:case Te.AFTER_AFTER_BODY:case Te.AFTER_AFTER_FRAMESET:{_Se(this,i);break}case Te.IN_TABLE:case Te.IN_TABLE_BODY:case Te.IN_ROW:{BD(this,i);break}case Te.IN_TABLE_TEXT:{qSe(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({},cre),I);i??(i=n.treeAdapter.createElement(M.TAG_NAMES.TEMPLATE,M.NS.HTML,[]));const r=n.treeAdapter.createElement("documentmock",M.NS.HTML,[]),C=new this(n,r,i);return C.fragmentContextID===M.TAG_ID.TEMPLATE&&C.tmplInsertionModeStack.unshift(Te.IN_TEMPLATE),C._initTokenizerForFragmentParsing(),C._insertFakeRootElement(),C._resetInsertionMode(),C._findFormInFragmentContext(),C}}]),e}();zB.Parser=iyt;function Iyt(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):jSe(e,g),i}function nyt(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 ryt(e,g,i){let I=g,n=e.openElements.getCommonAncestor(g);for(let r=0,C=n;C!==i;r++,C=n){n=e.openElements.getCommonAncestor(C);const o=e.activeFormattingElements.getElementEntry(C),a=o&&r>=tyt;!o||a?(a&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(C)):(C=Cyt(e,o),I===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(I),e.treeAdapter.appendChild(C,I),I=C)}return I}function Cyt(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 oyt(e,g,i){const I=e.treeAdapter.getTagName(g),n=(0,M.getTagID)(I);if(e._isElementCausesFosterParenting(n))e._fosterParentElement(i);else{const r=e.treeAdapter.getNamespaceURI(g);n===M.TAG_ID.TEMPLATE&&r===M.NS.HTML&&(g=e.treeAdapter.getTemplateContent(g)),e.treeAdapter.appendChild(g,i)}}function ayt(e,g,i){const I=e.treeAdapter.getNamespaceURI(i.element),{token:n}=i,r=e.treeAdapter.createElement(n.tagName,I,n.attrs);e._adoptNodes(g,r),e.treeAdapter.appendChild(g,r),e.activeFormattingElements.insertElementAfterBookmark(r,n),e.activeFormattingElements.removeEntry(i),e.openElements.remove(i.element),e.openElements.insertAfter(g,r,n.tagID)}function T4(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 r=e.openElements.items[1],C=e.treeAdapter.getNodeSourceCodeLocation(r);C&&!C.endTag&&e._setEndLocation(r,g)}}}}function lyt(e,g){e._setDocumentType(g);const i=g.forceQuirks?M.DOCUMENT_MODE.QUIRKS:lre.getDocumentMode(g);lre.isConforming(g)||e._err(g,mn.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,i),e.insertionMode=Te.BEFORE_HTML}function CZ(e,g){e._err(g,mn.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,M.DOCUMENT_MODE.QUIRKS),e.insertionMode=Te.BEFORE_HTML,e._processToken(g)}function cyt(e,g){g.tagID===M.TAG_ID.HTML?(e._insertElement(g,M.NS.HTML),e.insertionMode=Te.BEFORE_HEAD):$G(e,g)}function uyt(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)&&$G(e,g)}function $G(e,g){e._insertFakeRootElement(),e.insertionMode=Te.BEFORE_HEAD,e._processToken(g)}function dyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.HEAD:{e._insertElement(g,M.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=Te.IN_HEAD;break}default:qG(e,g)}}function hyt(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?qG(e,g):e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}function qG(e,g){e._insertFakeElement(M.TAG_NAMES.HEAD,M.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=Te.IN_HEAD,e._processToken(g)}function pa(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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,Qn.TokenizerMode.RCDATA);break}case M.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?e._switchToTextParsing(g,Qn.TokenizerMode.RAWTEXT):(e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_HEAD_NO_SCRIPT);break}case M.TAG_ID.NOFRAMES:case M.TAG_ID.STYLE:{e._switchToTextParsing(g,Qn.TokenizerMode.RAWTEXT);break}case M.TAG_ID.SCRIPT:{e._switchToTextParsing(g,Qn.TokenizerMode.SCRIPT_DATA);break}case M.TAG_ID.TEMPLATE:{e._insertTemplate(g),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Te.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Te.IN_TEMPLATE);break}case M.TAG_ID.HEAD:{e._err(g,mn.ERR.misplacedStartTagForHeadElement);break}default:ev(e,g)}}function myt(e,g){switch(g.tagID){case M.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=Te.AFTER_HEAD;break}case M.TAG_ID.BODY:case M.TAG_ID.BR:case M.TAG_ID.HTML:{ev(e,g);break}case M.TAG_ID.TEMPLATE:{am(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function am(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==M.TAG_ID.TEMPLATE&&e._err(g,mn.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}function ev(e,g){e.openElements.pop(),e.insertionMode=Te.AFTER_HEAD,e._processToken(g)}function fyt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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:{pa(e,g);break}case M.TAG_ID.NOSCRIPT:{e._err(g,mn.ERR.nestedNoscriptInHead);break}default:tv(e,g)}}function pyt(e,g){switch(g.tagID){case M.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=Te.IN_HEAD;break}case M.TAG_ID.BR:{tv(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function tv(e,g){const i=g.type===RI.TokenType.EOF?mn.ERR.openElementsLeftAfterEof:mn.ERR.disallowedContentInNoscriptInHead;e._err(g,i),e.openElements.pop(),e.insertionMode=Te.IN_HEAD,e._processToken(g)}function byt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.BODY:{e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=Te.IN_BODY;break}case M.TAG_ID.FRAMESET:{e._insertElement(g,M.NS.HTML),e.insertionMode=Te.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,mn.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,M.TAG_ID.HEAD),pa(e,g),e.openElements.remove(e.headElement);break}case M.TAG_ID.HEAD:{e._err(g,mn.ERR.misplacedStartTagForHeadElement);break}default:gv(e,g)}}function yyt(e,g){switch(g.tagID){case M.TAG_ID.BODY:case M.TAG_ID.HTML:case M.TAG_ID.BR:{gv(e,g);break}case M.TAG_ID.TEMPLATE:{am(e,g);break}default:e._err(g,mn.ERR.endTagWithoutMatchingOpenElement)}}function gv(e,g){e._insertFakeElement(M.TAG_NAMES.BODY,M.TAG_ID.BODY),e.insertionMode=Te.IN_BODY,Ik(e,g)}function Ik(e,g){switch(g.type){case RI.TokenType.CHARACTER:{LSe(e,g);break}case RI.TokenType.WHITESPACE_CHARACTER:{_Se(e,g);break}case RI.TokenType.COMMENT:{Pz(e,g);break}case RI.TokenType.START_TAG:{zn(e,g);break}case RI.TokenType.END_TAG:{nk(e,g);break}case RI.TokenType.EOF:{$Se(e,g);break}}}function _Se(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function LSe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function Zyt(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function Gyt(e,g){const i=e.openElements.tryPeekProperlyNestedBodyElement();i&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(i,g.attrs))}function vyt(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=Te.IN_FRAMESET)}function Byt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML)}function Syt(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 wyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function Ryt(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 Vyt(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 Wyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._insertElement(g,M.NS.HTML),e.tokenizer.state=Qn.TokenizerMode.PLAINTEXT}function Xyt(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 Hyt(e,g){const i=e.activeFormattingElements.getElementEntryInScopeWithTagName(M.TAG_NAMES.A);i&&(T4(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 Tyt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function Nyt(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(M.TAG_ID.NOBR)&&(T4(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function kyt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function Yyt(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=Te.IN_TABLE}function USe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function QSe(e){const g=(0,RI.getTokenAttr)(e,M.ATTRS.TYPE);return g!=null&&g.toLowerCase()===q0t}function Kyt(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,M.NS.HTML),QSe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function Fyt(e,g){e._appendElement(g,M.NS.HTML),g.ackSelfClosing=!0}function Dyt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._appendElement(g,M.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function xyt(e,g){g.tagName=M.TAG_NAMES.IMG,g.tagID=M.TAG_ID.IMG,USe(e,g)}function Eyt(e,g){e._insertElement(g,M.NS.HTML),e.skipNextNewLine=!0,e.tokenizer.state=Qn.TokenizerMode.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Te.TEXT}function Myt(e,g){e.openElements.hasInButtonScope(M.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,Qn.TokenizerMode.RAWTEXT)}function zyt(e,g){e.framesetOk=!1,e._switchToTextParsing(g,Qn.TokenizerMode.RAWTEXT)}function ure(e,g){e._switchToTextParsing(g,Qn.TokenizerMode.RAWTEXT)}function Pyt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Te.IN_TABLE||e.insertionMode===Te.IN_CAPTION||e.insertionMode===Te.IN_TABLE_BODY||e.insertionMode===Te.IN_ROW||e.insertionMode===Te.IN_CELL?Te.IN_SELECT_IN_TABLE:Te.IN_SELECT}function Jyt(e,g){e.openElements.currentTagId===M.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function Oyt(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,M.NS.HTML)}function _yt(e,g){e.openElements.hasInScope(M.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.RTC),e._insertElement(g,M.NS.HTML)}function Lyt(e,g){e._reconstructActiveFormattingElements(),Oa.adjustTokenMathMLAttrs(g),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.MATHML):e._insertElement(g,M.NS.MATHML),g.ackSelfClosing=!0}function Uyt(e,g){e._reconstructActiveFormattingElements(),Oa.adjustTokenSVGAttrs(g),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,M.NS.SVG):e._insertElement(g,M.NS.SVG),g.ackSelfClosing=!0}function dre(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,M.NS.HTML)}function zn(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:{Tyt(e,g);break}case M.TAG_ID.A:{Hyt(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:{Syt(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:{Byt(e,g);break}case M.TAG_ID.LI:case M.TAG_ID.DD:case M.TAG_ID.DT:{Vyt(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:{USe(e,g);break}case M.TAG_ID.HR:{Dyt(e,g);break}case M.TAG_ID.RB:case M.TAG_ID.RTC:{Oyt(e,g);break}case M.TAG_ID.RT:case M.TAG_ID.RP:{_yt(e,g);break}case M.TAG_ID.PRE:case M.TAG_ID.LISTING:{wyt(e,g);break}case M.TAG_ID.XMP:{Myt(e,g);break}case M.TAG_ID.SVG:{Uyt(e,g);break}case M.TAG_ID.HTML:{Zyt(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:{pa(e,g);break}case M.TAG_ID.BODY:{Gyt(e,g);break}case M.TAG_ID.FORM:{Ryt(e,g);break}case M.TAG_ID.NOBR:{Nyt(e,g);break}case M.TAG_ID.MATH:{Lyt(e,g);break}case M.TAG_ID.TABLE:{Yyt(e,g);break}case M.TAG_ID.INPUT:{Kyt(e,g);break}case M.TAG_ID.PARAM:case M.TAG_ID.TRACK:case M.TAG_ID.SOURCE:{Fyt(e,g);break}case M.TAG_ID.IMAGE:{xyt(e,g);break}case M.TAG_ID.BUTTON:{Xyt(e,g);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{kyt(e,g);break}case M.TAG_ID.IFRAME:{zyt(e,g);break}case M.TAG_ID.SELECT:{Pyt(e,g);break}case M.TAG_ID.OPTION:case M.TAG_ID.OPTGROUP:{Jyt(e,g);break}case M.TAG_ID.NOEMBED:{ure(e,g);break}case M.TAG_ID.FRAMESET:{vyt(e,g);break}case M.TAG_ID.TEXTAREA:{Eyt(e,g);break}case M.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?ure(e,g):dre(e,g);break}case M.TAG_ID.PLAINTEXT:{Wyt(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:dre(e,g)}}function Qyt(e,g){if(e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Te.AFTER_BODY,e.options.sourceCodeLocationInfo)){const i=e.openElements.tryPeekProperlyNestedBodyElement();i&&e._setEndLocation(i,g)}}function jyt(e,g){e.openElements.hasInScope(M.TAG_ID.BODY)&&(e.insertionMode=Te.AFTER_BODY,rwe(e,g))}function $yt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(i))}function qyt(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 eZt(e){e.openElements.hasInButtonScope(M.TAG_ID.P)||e._insertFakeElement(M.TAG_NAMES.P,M.TAG_ID.P),e._closePElement()}function tZt(e){e.openElements.hasInListItemScope(M.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(M.TAG_ID.LI),e.openElements.popUntilTagNamePopped(M.TAG_ID.LI))}function gZt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTagsWithExclusion(i),e.openElements.popUntilTagNamePopped(i))}function iZt(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function IZt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(i),e.activeFormattingElements.clearToLastMarker())}function nZt(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(M.TAG_NAMES.BR,M.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function jSe(e,g){const i=g.tagName,I=g.tagID;for(let n=e.openElements.stackTop;n>0;n--){const r=e.openElements.items[n],C=e.openElements.tagIDs[n];if(I===C&&(I!==M.TAG_ID.UNKNOWN||e.treeAdapter.getTagName(r)===i)){e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.stackTop>=n&&e.openElements.shortenToLength(n);break}if(e._isSpecialElement(r,C))break}}function nk(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:{T4(e,g);break}case M.TAG_ID.P:{eZt(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:{$yt(e,g);break}case M.TAG_ID.LI:{tZt(e);break}case M.TAG_ID.DD:case M.TAG_ID.DT:{gZt(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:{iZt(e);break}case M.TAG_ID.BR:{nZt(e);break}case M.TAG_ID.BODY:{Qyt(e,g);break}case M.TAG_ID.HTML:{jyt(e,g);break}case M.TAG_ID.FORM:{qyt(e);break}case M.TAG_ID.APPLET:case M.TAG_ID.OBJECT:case M.TAG_ID.MARQUEE:{IZt(e,g);break}case M.TAG_ID.TEMPLATE:{am(e,g);break}default:jSe(e,g)}}function $Se(e,g){e.tmplInsertionModeStack.length>0?nwe(e,g):N4(e,g)}function rZt(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 CZt(e,g){e._err(g,mn.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function BD(e,g){if(OSe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Te.IN_TABLE_TEXT,g.type){case RI.TokenType.CHARACTER:{ewe(e,g);break}case RI.TokenType.WHITESPACE_CHARACTER:{qSe(e,g);break}}else Aw(e,g)}function oZt(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_CAPTION}function aZt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_COLUMN_GROUP}function AZt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.COLGROUP,M.TAG_ID.COLGROUP),e.insertionMode=Te.IN_COLUMN_GROUP,k4(e,g)}function sZt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,M.NS.HTML),e.insertionMode=Te.IN_TABLE_BODY}function lZt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(M.TAG_NAMES.TBODY,M.TAG_ID.TBODY),e.insertionMode=Te.IN_TABLE_BODY,rk(e,g)}function cZt(e,g){e.openElements.hasInTableScope(M.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(M.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function uZt(e,g){QSe(g)?e._appendElement(g,M.NS.HTML):Aw(e,g),g.ackSelfClosing=!0}function dZt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,M.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function _b(e,g){switch(g.tagID){case M.TAG_ID.TD:case M.TAG_ID.TH:case M.TAG_ID.TR:{lZt(e,g);break}case M.TAG_ID.STYLE:case M.TAG_ID.SCRIPT:case M.TAG_ID.TEMPLATE:{pa(e,g);break}case M.TAG_ID.COL:{AZt(e,g);break}case M.TAG_ID.FORM:{dZt(e,g);break}case M.TAG_ID.TABLE:{cZt(e,g);break}case M.TAG_ID.TBODY:case M.TAG_ID.TFOOT:case M.TAG_ID.THEAD:{sZt(e,g);break}case M.TAG_ID.INPUT:{uZt(e,g);break}case M.TAG_ID.CAPTION:{oZt(e,g);break}case M.TAG_ID.COLGROUP:{aZt(e,g);break}default:Aw(e,g)}}function PB(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:{am(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:Aw(e,g)}}function Aw(e,g){const i=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,Ik(e,g),e.fosterParentingEnabled=i}function qSe(e,g){e.pendingCharacterTokens.push(g)}function ewe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function oZ(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:{am(e,g);break}}}function yZt(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)):iwe(e,g)}function ZZt(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)):Iwe(e,g)}function GZt(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:{pa(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]=Te.IN_TABLE,e.insertionMode=Te.IN_TABLE,_b(e,g);break}case M.TAG_ID.COL:{e.tmplInsertionModeStack[0]=Te.IN_COLUMN_GROUP,e.insertionMode=Te.IN_COLUMN_GROUP,k4(e,g);break}case M.TAG_ID.TR:{e.tmplInsertionModeStack[0]=Te.IN_TABLE_BODY,e.insertionMode=Te.IN_TABLE_BODY,rk(e,g);break}case M.TAG_ID.TD:case M.TAG_ID.TH:{e.tmplInsertionModeStack[0]=Te.IN_ROW,e.insertionMode=Te.IN_ROW,Ck(e,g);break}default:e.tmplInsertionModeStack[0]=Te.IN_BODY,e.insertionMode=Te.IN_BODY,zn(e,g)}}function vZt(e,g){g.tagID===M.TAG_ID.TEMPLATE&&am(e,g)}function nwe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(M.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):N4(e,g)}function BZt(e,g){g.tagID===M.TAG_ID.HTML?zn(e,g):EX(e,g)}function rwe(e,g){var i;if(g.tagID===M.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=Te.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 EX(e,g)}function EX(e,g){e.insertionMode=Te.IN_BODY,Ik(e,g)}function SZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(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:{pa(e,g);break}}}function wZt(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=Te.AFTER_FRAMESET))}function RZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.NOFRAMES:{pa(e,g);break}}}function VZt(e,g){g.tagID===M.TAG_ID.HTML&&(e.insertionMode=Te.AFTER_AFTER_FRAMESET)}function WZt(e,g){g.tagID===M.TAG_ID.HTML?zn(e,g):gW(e,g)}function gW(e,g){e.insertionMode=Te.IN_BODY,Ik(e,g)}function XZt(e,g){switch(g.tagID){case M.TAG_ID.HTML:{zn(e,g);break}case M.TAG_ID.NOFRAMES:{pa(e,g);break}}}function HZt(e,g){g.chars=JSe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function TZt(e,g){e._insertCharacters(g),e.framesetOk=!1}function Cwe(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==M.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function NZt(e,g){if(Oa.causesExit(g))Cwe(e),e._startTagOutsideForeignContent(g);else{const i=e._getAdjustedCurrentElement(),I=e.treeAdapter.getNamespaceURI(i);I===M.NS.MATHML?Oa.adjustTokenMathMLAttrs(g):I===M.NS.SVG&&(Oa.adjustTokenSVGTagName(g),Oa.adjustTokenSVGAttrs(g)),Oa.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,I):e._insertElement(g,I),g.ackSelfClosing=!0}}function kZt(e,g){if(g.tagID===M.TAG_ID.P||g.tagID===M.TAG_ID.BR){Cwe(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 Lb={};Object.defineProperty(Lb,"__esModule",{value:!0});Lb.serializeOuter=Lb.serialize=void 0;const ri=nl,owe=Fb,YZt=ik,KZt=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(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===ri.NS.HTML&&KZt.has(g.treeAdapter.getTagName(e))}const Awe={treeAdapter:YZt.defaultTreeAdapter,scriptingEnabled:!0};function FZt(e,g){const i=Object.assign(Object.assign({},Awe),g);return awe(e,i)?"":swe(e,i)}Lb.serialize=FZt;function DZt(e,g){const i=Object.assign(Object.assign({},Awe),g);return lwe(e,i)}Lb.serializeOuter=DZt;function swe(e,g){let i="";const I=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===ri.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===ri.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(I);if(n)for(const r of n)i+=lwe(r,g);return i}function lwe(e,g){return g.treeAdapter.isElementNode(e)?xZt(e,g):g.treeAdapter.isTextNode(e)?MZt(e,g):g.treeAdapter.isCommentNode(e)?zZt(e,g):g.treeAdapter.isDocumentTypeNode(e)?PZt(e,g):""}function xZt(e,g){const i=g.treeAdapter.getTagName(e);return`<${i}${EZt(e,g)}>${awe(e,g)?"":`${swe(e,g)}`}`}function EZt(e,{treeAdapter:g}){let i="";for(const I of g.getAttrList(e)){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,owe.escapeAttribute)(I.value)}"`}return i}function MZt(e,g){const{treeAdapter:i}=g,I=i.getTextNodeContent(e),n=i.getParentNode(e),r=n&&i.isElementNode(n)&&i.getTagName(n);return r&&i.getNamespaceURI(n)===ri.NS.HTML&&(0,ri.hasUnescapedText)(r,g.scriptingEnabled)?I:(0,owe.escapeText)(I)}function zZt(e,{treeAdapter:g}){return``}function PZt(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=zB;var i=ik;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return i.defaultTreeAdapter}});var I=zB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return I.Parser}});var n=Lb;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var r=aw;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return r.ERR}}),e.foreignContent=H4,e.html=nl,e.Token=tk;var C=uh;Object.defineProperty(e,"Tokenizer",{enumerable:!0,get:function(){return C.Tokenizer}}),Object.defineProperty(e,"TokenizerMode",{enumerable:!0,get:function(){return C.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})(YSe);var cwe={},uwe={},JB={},dh={},ok={},ak={};(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 r(o){return o!==32&&o!==10&&o!==13&&o!==9&&o!==12&&o>=1&&o<=31||o>=127&&o<=159}e.isControlCodePoint=r;function C(o){return o>=64976&&o<=65007||g.has(o)}e.isUndefinedCodePoint=C})(ak);var sw={};(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={}))})(sw);function JZt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function hre(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,On.CODE_POINTS.EOF;const n=this.html.charCodeAt(I);return n===On.CODE_POINTS.CARRIAGE_RETURN?On.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,On.CODE_POINTS.EOF;let i=this.html.charCodeAt(this.pos);return i===On.CODE_POINTS.CARRIAGE_RETURN?(this.isEol=!0,this.skipNextNewLine=!0,On.CODE_POINTS.LINE_FEED):i===On.CODE_POINTS.LINE_FEED&&(this.isEol=!0,this.skipNextNewLine)?(this.line--,this.skipNextNewLine=!1,this._addGap(),this.advance()):(this.skipNextNewLine=!1,(0,On.isSurrogate)(i)&&(i=this._processSurrogate(i)),this.handler.onParseError===null||i>31&&i<127||i===On.CODE_POINTS.LINE_FEED||i===On.CODE_POINTS.CARRIAGE_RETURN||i>159&&i<64976||this._checkForProblematicCharacters(i),i)}},{key:"_checkForProblematicCharacters",value:function(i){(0,On.isControlCodePoint)(i)?this._err(SD.ERR.controlCharacterInInputStream):(0,On.isUndefinedCodePoint)(i)&&this._err(SD.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})(Ak);var rl={};(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 r(A){var l;return(l=n.get(A))!==null&&l!==void 0?l:I.UNKNOWN}e.getTagID=r;const C=I;e.SPECIAL_ELEMENTS={[g.HTML]:new Set([C.ADDRESS,C.APPLET,C.AREA,C.ARTICLE,C.ASIDE,C.BASE,C.BASEFONT,C.BGSOUND,C.BLOCKQUOTE,C.BODY,C.BR,C.BUTTON,C.CAPTION,C.CENTER,C.COL,C.COLGROUP,C.DD,C.DETAILS,C.DIR,C.DIV,C.DL,C.DT,C.EMBED,C.FIELDSET,C.FIGCAPTION,C.FIGURE,C.FOOTER,C.FORM,C.FRAME,C.FRAMESET,C.H1,C.H2,C.H3,C.H4,C.H5,C.H6,C.HEAD,C.HEADER,C.HGROUP,C.HR,C.HTML,C.IFRAME,C.IMG,C.INPUT,C.LI,C.LINK,C.LISTING,C.MAIN,C.MARQUEE,C.MENU,C.META,C.NAV,C.NOEMBED,C.NOFRAMES,C.NOSCRIPT,C.OBJECT,C.OL,C.P,C.PARAM,C.PLAINTEXT,C.PRE,C.SCRIPT,C.SECTION,C.SELECT,C.SOURCE,C.STYLE,C.SUMMARY,C.TABLE,C.TBODY,C.TD,C.TEMPLATE,C.TEXTAREA,C.TFOOT,C.TH,C.THEAD,C.TITLE,C.TR,C.TRACK,C.UL,C.WBR,C.XMP]),[g.MATHML]:new Set([C.MI,C.MO,C.MN,C.MS,C.MTEXT,C.ANNOTATION_XML]),[g.SVG]:new Set([C.TITLE,C.FOREIGN_OBJECT,C.DESC]),[g.XLINK]:new Set,[g.XML]:new Set,[g.XMLNS]:new Set};function o(A){return A===C.H1||A===C.H2||A===C.H3||A===C.H4||A===C.H5||A===C.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})(rl);function jZt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function mre(e,g){for(var i=0;i=se.CODE_POINTS.DIGIT_0&&e<=se.CODE_POINTS.DIGIT_9}function QZ(e){return e>=se.CODE_POINTS.LATIN_CAPITAL_A&&e<=se.CODE_POINTS.LATIN_CAPITAL_Z}function iGt(e){return e>=se.CODE_POINTS.LATIN_SMALL_A&&e<=se.CODE_POINTS.LATIN_SMALL_Z}function Tl(e){return iGt(e)||QZ(e)}function Oz(e){return Tl(e)||iv(e)}function dwe(e){return e>=se.CODE_POINTS.LATIN_CAPITAL_A&&e<=se.CODE_POINTS.LATIN_CAPITAL_F}function hwe(e){return e>=se.CODE_POINTS.LATIN_SMALL_A&&e<=se.CODE_POINTS.LATIN_SMALL_F}function IGt(e){return iv(e)||dwe(e)||hwe(e)}function yV(e){return e+32}function mwe(e){return e===se.CODE_POINTS.SPACE||e===se.CODE_POINTS.LINE_FEED||e===se.CODE_POINTS.TABULATION||e===se.CODE_POINTS.FORM_FEED}function nGt(e){return e===se.CODE_POINTS.EQUALS_SIGN||Oz(e)}function fre(e){return mwe(e)||e===se.CODE_POINTS.SOLIDUS||e===se.CODE_POINTS.GREATER_THAN_SIGN}let rGt=function(){function e(g,i){jZt(this,e),this.options=g,this.handler=i,this.paused=!1,this.inLoop=!1,this.inForeignNode=!1,this.lastStartTagName="",this.active=!1,this.state=Ge.DATA,this.returnState=Ge.DATA,this.charRefCode=-1,this.consumedAfterSnapshot=-1,this.currentCharacterToken=null,this.currentToken=null,this.currentAttr={name:"",value:""},this.preprocessor=new tGt.Preprocessor(i),this.currentLocation=this.getCurrentLocation(-1)}return $Zt(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(et.ERR.endTagWithAttributes),i.selfClosing&&this._err(et.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 yr.TokenType.CHARACTER:{this.handler.onCharacter(this.currentCharacterToken);break}case yr.TokenType.NULL_CHARACTER:{this.handler.onNullCharacter(this.currentCharacterToken);break}case yr.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:yr.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=mwe(i)?yr.TokenType.WHITESPACE_CHARACTER:i===se.CODE_POINTS.NULL?yr.TokenType.NULL_CHARACTER:yr.TokenType.CHARACTER;this._appendCharToCurrentCharacterToken(I,String.fromCodePoint(i))}},{key:"_emitChars",value:function(i){this._appendCharToCurrentCharacterToken(yr.TokenType.CHARACTER,i)}},{key:"_matchNamedCharacterReference",value:function(i){let I=null,n=0,r=!1;for(let C=0,o=Wa.htmlDecodeTree[0];C>=0&&(C=(0,Wa.determineBranch)(Wa.htmlDecodeTree,o,C+1,i),!(C<0));i=this._consume()){n+=1,o=Wa.htmlDecodeTree[C];const a=o&Wa.BinTrieFlags.VALUE_LENGTH;if(a){const s=(a>>14)-1;if(i!==se.CODE_POINTS.SEMICOLON&&this._isCharacterReferenceInAttribute()&&nGt(this.preprocessor.peek(1))?(I=[se.CODE_POINTS.AMPERSAND],C+=s):(I=s===0?[Wa.htmlDecodeTree[C]&~Wa.BinTrieFlags.VALUE_LENGTH]:s===1?[Wa.htmlDecodeTree[++C]]:[Wa.htmlDecodeTree[++C],Wa.htmlDecodeTree[++C]],n=0,r=i!==se.CODE_POINTS.SEMICOLON),s===0){this._consume();break}}}return this._unconsume(n),r&&!this.preprocessor.endOfChunkHit&&this._err(et.ERR.missingSemicolonAfterCharacterReference),this._unconsume(1),I}},{key:"_isCharacterReferenceInAttribute",value:function(){return this.returnState===Ge.ATTRIBUTE_VALUE_DOUBLE_QUOTED||this.returnState===Ge.ATTRIBUTE_VALUE_SINGLE_QUOTED||this.returnState===Ge.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 Ge.DATA:{this._stateData(i);break}case Ge.RCDATA:{this._stateRcdata(i);break}case Ge.RAWTEXT:{this._stateRawtext(i);break}case Ge.SCRIPT_DATA:{this._stateScriptData(i);break}case Ge.PLAINTEXT:{this._statePlaintext(i);break}case Ge.TAG_OPEN:{this._stateTagOpen(i);break}case Ge.END_TAG_OPEN:{this._stateEndTagOpen(i);break}case Ge.TAG_NAME:{this._stateTagName(i);break}case Ge.RCDATA_LESS_THAN_SIGN:{this._stateRcdataLessThanSign(i);break}case Ge.RCDATA_END_TAG_OPEN:{this._stateRcdataEndTagOpen(i);break}case Ge.RCDATA_END_TAG_NAME:{this._stateRcdataEndTagName(i);break}case Ge.RAWTEXT_LESS_THAN_SIGN:{this._stateRawtextLessThanSign(i);break}case Ge.RAWTEXT_END_TAG_OPEN:{this._stateRawtextEndTagOpen(i);break}case Ge.RAWTEXT_END_TAG_NAME:{this._stateRawtextEndTagName(i);break}case Ge.SCRIPT_DATA_LESS_THAN_SIGN:{this._stateScriptDataLessThanSign(i);break}case Ge.SCRIPT_DATA_END_TAG_OPEN:{this._stateScriptDataEndTagOpen(i);break}case Ge.SCRIPT_DATA_END_TAG_NAME:{this._stateScriptDataEndTagName(i);break}case Ge.SCRIPT_DATA_ESCAPE_START:{this._stateScriptDataEscapeStart(i);break}case Ge.SCRIPT_DATA_ESCAPE_START_DASH:{this._stateScriptDataEscapeStartDash(i);break}case Ge.SCRIPT_DATA_ESCAPED:{this._stateScriptDataEscaped(i);break}case Ge.SCRIPT_DATA_ESCAPED_DASH:{this._stateScriptDataEscapedDash(i);break}case Ge.SCRIPT_DATA_ESCAPED_DASH_DASH:{this._stateScriptDataEscapedDashDash(i);break}case Ge.SCRIPT_DATA_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataEscapedLessThanSign(i);break}case Ge.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:{this._stateScriptDataEscapedEndTagOpen(i);break}case Ge.SCRIPT_DATA_ESCAPED_END_TAG_NAME:{this._stateScriptDataEscapedEndTagName(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPE_START:{this._stateScriptDataDoubleEscapeStart(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED:{this._stateScriptDataDoubleEscaped(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_DASH:{this._stateScriptDataDoubleEscapedDash(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_DASH_DASH:{this._stateScriptDataDoubleEscapedDashDash(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPED_LESS_THAN_SIGN:{this._stateScriptDataDoubleEscapedLessThanSign(i);break}case Ge.SCRIPT_DATA_DOUBLE_ESCAPE_END:{this._stateScriptDataDoubleEscapeEnd(i);break}case Ge.BEFORE_ATTRIBUTE_NAME:{this._stateBeforeAttributeName(i);break}case Ge.ATTRIBUTE_NAME:{this._stateAttributeName(i);break}case Ge.AFTER_ATTRIBUTE_NAME:{this._stateAfterAttributeName(i);break}case Ge.BEFORE_ATTRIBUTE_VALUE:{this._stateBeforeAttributeValue(i);break}case Ge.ATTRIBUTE_VALUE_DOUBLE_QUOTED:{this._stateAttributeValueDoubleQuoted(i);break}case Ge.ATTRIBUTE_VALUE_SINGLE_QUOTED:{this._stateAttributeValueSingleQuoted(i);break}case Ge.ATTRIBUTE_VALUE_UNQUOTED:{this._stateAttributeValueUnquoted(i);break}case Ge.AFTER_ATTRIBUTE_VALUE_QUOTED:{this._stateAfterAttributeValueQuoted(i);break}case Ge.SELF_CLOSING_START_TAG:{this._stateSelfClosingStartTag(i);break}case Ge.BOGUS_COMMENT:{this._stateBogusComment(i);break}case Ge.MARKUP_DECLARATION_OPEN:{this._stateMarkupDeclarationOpen(i);break}case Ge.COMMENT_START:{this._stateCommentStart(i);break}case Ge.COMMENT_START_DASH:{this._stateCommentStartDash(i);break}case Ge.COMMENT:{this._stateComment(i);break}case Ge.COMMENT_LESS_THAN_SIGN:{this._stateCommentLessThanSign(i);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG:{this._stateCommentLessThanSignBang(i);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG_DASH:{this._stateCommentLessThanSignBangDash(i);break}case Ge.COMMENT_LESS_THAN_SIGN_BANG_DASH_DASH:{this._stateCommentLessThanSignBangDashDash(i);break}case Ge.COMMENT_END_DASH:{this._stateCommentEndDash(i);break}case Ge.COMMENT_END:{this._stateCommentEnd(i);break}case Ge.COMMENT_END_BANG:{this._stateCommentEndBang(i);break}case Ge.DOCTYPE:{this._stateDoctype(i);break}case Ge.BEFORE_DOCTYPE_NAME:{this._stateBeforeDoctypeName(i);break}case Ge.DOCTYPE_NAME:{this._stateDoctypeName(i);break}case Ge.AFTER_DOCTYPE_NAME:{this._stateAfterDoctypeName(i);break}case Ge.AFTER_DOCTYPE_PUBLIC_KEYWORD:{this._stateAfterDoctypePublicKeyword(i);break}case Ge.BEFORE_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateBeforeDoctypePublicIdentifier(i);break}case Ge.DOCTYPE_PUBLIC_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypePublicIdentifierDoubleQuoted(i);break}case Ge.DOCTYPE_PUBLIC_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypePublicIdentifierSingleQuoted(i);break}case Ge.AFTER_DOCTYPE_PUBLIC_IDENTIFIER:{this._stateAfterDoctypePublicIdentifier(i);break}case Ge.BETWEEN_DOCTYPE_PUBLIC_AND_SYSTEM_IDENTIFIERS:{this._stateBetweenDoctypePublicAndSystemIdentifiers(i);break}case Ge.AFTER_DOCTYPE_SYSTEM_KEYWORD:{this._stateAfterDoctypeSystemKeyword(i);break}case Ge.BEFORE_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateBeforeDoctypeSystemIdentifier(i);break}case Ge.DOCTYPE_SYSTEM_IDENTIFIER_DOUBLE_QUOTED:{this._stateDoctypeSystemIdentifierDoubleQuoted(i);break}case Ge.DOCTYPE_SYSTEM_IDENTIFIER_SINGLE_QUOTED:{this._stateDoctypeSystemIdentifierSingleQuoted(i);break}case Ge.AFTER_DOCTYPE_SYSTEM_IDENTIFIER:{this._stateAfterDoctypeSystemIdentifier(i);break}case Ge.BOGUS_DOCTYPE:{this._stateBogusDoctype(i);break}case Ge.CDATA_SECTION:{this._stateCdataSection(i);break}case Ge.CDATA_SECTION_BRACKET:{this._stateCdataSectionBracket(i);break}case Ge.CDATA_SECTION_END:{this._stateCdataSectionEnd(i);break}case Ge.CHARACTER_REFERENCE:{this._stateCharacterReference(i);break}case Ge.NAMED_CHARACTER_REFERENCE:{this._stateNamedCharacterReference(i);break}case Ge.AMBIGUOUS_AMPERSAND:{this._stateAmbiguousAmpersand(i);break}case Ge.NUMERIC_CHARACTER_REFERENCE:{this._stateNumericCharacterReference(i);break}case Ge.HEXADEMICAL_CHARACTER_REFERENCE_START:{this._stateHexademicalCharacterReferenceStart(i);break}case Ge.HEXADEMICAL_CHARACTER_REFERENCE:{this._stateHexademicalCharacterReference(i);break}case Ge.DECIMAL_CHARACTER_REFERENCE:{this._stateDecimalCharacterReference(i);break}case Ge.NUMERIC_CHARACTER_REFERENCE_END:{this._stateNumericCharacterReferenceEnd(i);break}default:throw new Error("Unknown state")}}},{key:"_stateData",value:function(i){switch(i){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.TAG_OPEN;break}case se.CODE_POINTS.AMPERSAND:{this.returnState=Ge.DATA,this.state=Ge.CHARACTER_REFERENCE;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitCodePoint(i);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(i)}}},{key:"_stateRcdata",value:function(i){switch(i){case se.CODE_POINTS.AMPERSAND:{this.returnState=Ge.RCDATA,this.state=Ge.CHARACTER_REFERENCE;break}case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.RCDATA_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(i)}}},{key:"_stateRawtext",value:function(i){switch(i){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.RAWTEXT_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(i)}}},{key:"_stateScriptData",value:function(i){switch(i){case se.CODE_POINTS.LESS_THAN_SIGN:{this.state=Ge.SCRIPT_DATA_LESS_THAN_SIGN;break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(i)}}},{key:"_statePlaintext",value:function(i){switch(i){case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._emitEOFToken();break}default:this._emitCodePoint(i)}}},{key:"_stateTagOpen",value:function(i){if(Tl(i))this._createStartTagToken(),this.state=Ge.TAG_NAME,this._stateTagName(i);else switch(i){case se.CODE_POINTS.EXCLAMATION_MARK:{this.state=Ge.MARKUP_DECLARATION_OPEN;break}case se.CODE_POINTS.SOLIDUS:{this.state=Ge.END_TAG_OPEN;break}case se.CODE_POINTS.QUESTION_MARK:{this._err(et.ERR.unexpectedQuestionMarkInsteadOfTagName),this._createCommentToken(1),this.state=Ge.BOGUS_COMMENT,this._stateBogusComment(i);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofBeforeTagName),this._emitChars("<"),this._emitEOFToken();break}default:this._err(et.ERR.invalidFirstCharacterOfTagName),this._emitChars("<"),this.state=Ge.DATA,this._stateData(i)}}},{key:"_stateEndTagOpen",value:function(i){if(Tl(i))this._createEndTagToken(),this.state=Ge.TAG_NAME,this._stateTagName(i);else switch(i){case se.CODE_POINTS.GREATER_THAN_SIGN:{this._err(et.ERR.missingEndTagName),this.state=Ge.DATA;break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofBeforeTagName),this._emitChars("");break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this.state=Ge.SCRIPT_DATA_ESCAPED,this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ge.SCRIPT_DATA_ESCAPED,this._emitCodePoint(i)}}},{key:"_stateScriptDataEscapedLessThanSign",value:function(i){i===se.CODE_POINTS.SOLIDUS?this.state=Ge.SCRIPT_DATA_ESCAPED_END_TAG_OPEN:Tl(i)?(this._emitChars("<"),this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPE_START,this._stateScriptDataDoubleEscapeStart(i)):(this._emitChars("<"),this.state=Ge.SCRIPT_DATA_ESCAPED,this._stateScriptDataEscaped(i))}},{key:"_stateScriptDataEscapedEndTagOpen",value:function(i){Tl(i)?(this.state=Ge.SCRIPT_DATA_ESCAPED_END_TAG_NAME,this._stateScriptDataEscapedEndTagName(i)):(this._emitChars("");break}case se.CODE_POINTS.NULL:{this._err(et.ERR.unexpectedNullCharacter),this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitChars(se.REPLACEMENT_CHARACTER);break}case se.CODE_POINTS.EOF:{this._err(et.ERR.eofInScriptHtmlCommentLikeText),this._emitEOFToken();break}default:this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._emitCodePoint(i)}}},{key:"_stateScriptDataDoubleEscapedLessThanSign",value:function(i){i===se.CODE_POINTS.SOLIDUS?(this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPE_END,this._emitChars("/")):(this.state=Ge.SCRIPT_DATA_DOUBLE_ESCAPED,this._stateScriptDataDoubleEscaped(i))}},{key:"_stateScriptDataDoubleEscapeEnd",value:function(i){if(this.preprocessor.startsWith(se.SEQUENCES.SCRIPT,!1)&&fre(this.preprocessor.peek(se.SEQUENCES.SCRIPT.length))){this._emitCodePoint(i);for(let I=0;I1114111)this._err(et.ERR.characterReferenceOutsideUnicodeRange),this.charRefCode=se.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,se.isSurrogate)(this.charRefCode))this._err(et.ERR.surrogateCharacterReference),this.charRefCode=se.CODE_POINTS.REPLACEMENT_CHARACTER;else if((0,se.isUndefinedCodePoint)(this.charRefCode))this._err(et.ERR.noncharacterCharacterReference);else if((0,se.isControlCodePoint)(this.charRefCode)||this.charRefCode===se.CODE_POINTS.CARRIAGE_RETURN){this._err(et.ERR.controlCharacterReference);const I=gGt.get(this.charRefCode);I!==void 0&&(this.charRefCode=I)}this._flushCodePointConsumedAsCharacterReference(this.charRefCode),this._reconsumeInState(this.returnState,i)}}]),e}();dh.Tokenizer=rGt;var sk={};function CGt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function pre(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 r=this._indexOf(i)+1;this.items.splice(r,0,I),this.tagIDs.splice(r,0,n),this.stackTop++,r===this.stackTop&&this._updateCurrentElement(),this.handler.onItemPush(this.current,this.currentTagId,r===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])!==nt.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(uGt,nt.NS.HTML)}},{key:"clearBackToTableBodyContext",value:function(){this.clearBackTo(cGt,nt.NS.HTML)}},{key:"clearBackToTableRowContext",value:function(){this.clearBackTo(lGt,nt.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]===nt.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]===nt.TAG_ID.HTML}},{key:"hasInScope",value:function(i){for(let I=this.stackTop;I>=0;I--){const n=this.tagIDs[I],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===nt.NS.HTML)return!0;if(ZV.get(n)===r)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,nt.isNumberedHeader)(I)&&n===nt.NS.HTML)return!0;if(ZV.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],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===nt.NS.HTML)return!0;if((n===nt.TAG_ID.UL||n===nt.TAG_ID.OL)&&r===nt.NS.HTML||ZV.get(n)===r)return!1}return!0}},{key:"hasInButtonScope",value:function(i){for(let I=this.stackTop;I>=0;I--){const n=this.tagIDs[I],r=this.treeAdapter.getNamespaceURI(this.items[I]);if(n===i&&r===nt.NS.HTML)return!0;if(n===nt.TAG_ID.BUTTON&&r===nt.NS.HTML||ZV.get(n)===r)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])===nt.NS.HTML){if(n===i)return!0;if(n===nt.TAG_ID.TABLE||n===nt.TAG_ID.TEMPLATE||n===nt.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])===nt.NS.HTML){if(I===nt.TAG_ID.TBODY||I===nt.TAG_ID.THEAD||I===nt.TAG_ID.TFOOT)return!0;if(I===nt.TAG_ID.TABLE||I===nt.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])===nt.NS.HTML){if(n===i)return!0;if(n!==nt.TAG_ID.OPTION&&n!==nt.TAG_ID.OPTGROUP)return!1}}return!0}},{key:"generateImpliedEndTags",value:function(){for(;fwe.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsThoroughly",value:function(){for(;bre.has(this.currentTagId);)this.pop()}},{key:"generateImpliedEndTagsWithExclusion",value:function(i){for(;this.currentTagId!==i&&bre.has(this.currentTagId);)this.pop()}}]),e}();sk.OpenElementStack=hGt;var pwe={};(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>=C&&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})(pwe);var lk={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.defaultTreeAdapter=void 0;const g=rl;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,r){return{nodeName:I,tagName:I,attrs:r,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,r){const C=I.childNodes.indexOf(r);I.childNodes.splice(C,0,n),n.parentNode=I},setTemplateContent(I,n){I.content=n},getTemplateContent(I){return I.content},setDocumentType(I,n,r,C){const o=I.childNodes.find(a=>a.nodeName==="#documentType");if(o)o.name=n,o.publicId=r,o.systemId=C;else{const a={nodeName:"#documentType",name:n,publicId:r,systemId:C,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 r=I.childNodes[I.childNodes.length-1];if(e.defaultTreeAdapter.isTextNode(r)){r.value+=n;return}}e.defaultTreeAdapter.appendChild(I,i(n))},insertTextBefore(I,n,r){const C=I.childNodes[I.childNodes.indexOf(r)-1];C&&e.defaultTreeAdapter.isTextNode(C)?C.value+=n:e.defaultTreeAdapter.insertBefore(I,i(n),r)},adoptAttributes(I,n){const r=new Set(I.attrs.map(C=>C.name));for(let C=0;Ce.startsWith(i))}function ZGt(e){return e.name===bwe&&e.publicId===null&&(e.systemId===null||e.systemId===mGt)}Ub.isConforming=ZGt;function GGt(e){if(e.name!==bwe)return Om.DOCUMENT_MODE.QUIRKS;const{systemId:g}=e;if(g&&g.toLowerCase()===fGt)return Om.DOCUMENT_MODE.QUIRKS;let{publicId:i}=e;if(i!==null){if(i=i.toLowerCase(),bGt.has(i))return Om.DOCUMENT_MODE.QUIRKS;let I=g===null?pGt:ywe;if(yre(i,I))return Om.DOCUMENT_MODE.QUIRKS;if(I=g===null?Zwe:yGt,yre(i,I))return Om.DOCUMENT_MODE.LIMITED_QUIRKS}return Om.DOCUMENT_MODE.NO_QUIRKS}Ub.getDocumentMode=GGt;var Y4={};(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=rl,i={TEXT_HTML:"text/html",APPLICATION_XML:"application/xhtml+xml"},I="definitionurl",n="definitionURL",r=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])),C=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,r;if(this.options.sourceCodeLocationInfo&&this._setEndLocation(i,this.currentToken),(r=(n=this.treeAdapter).onItemPop)===null||r===void 0||r.call(n,i,this.openElements.current),I){let C,o;this.openElements.stackTop===0&&this.fragmentContext?(C=this.fragmentContext,o=this.fragmentContextID):{current:C,currentTagId:o}=this.openElements,this._setContextModes(C,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=Ne.TEXT}},{key:"switchToPlaintextParsing",value:function(){this.insertionMode=Ne.TEXT,this.originalInsertionMode=Ne.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)===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=jn.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=jn.TokenizerMode.RAWTEXT;break}case z.TAG_ID.SCRIPT:{this.tokenizer.state=jn.TokenizerMode.SCRIPT_DATA;break}case z.TAG_ID.PLAINTEXT:{this.tokenizer.state=jn.TokenizerMode.PLAINTEXT;break}}}},{key:"_setDocumentType",value:function(i){const I=i.name||"",n=i.publicId||"",r=i.systemId||"";if(this.treeAdapter.setDocumentType(this.document,I,n,r),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 r=this.treeAdapter.getChildNodes(I),C=n?r.lastIndexOf(n):r.length,o=r[C-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,r=this.treeAdapter.getTagName(i),C=I.type===VI.TokenType.END_TAG&&r===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,C)}}},{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 r=this.treeAdapter.getNamespaceURI(I),C=this.treeAdapter.getAttrList(I);return _a.isIntegrationPoint(i,r,C,n)}},{key:"_reconstructActiveFormattingElements",value:function(){const i=this.activeFormattingElements.entries.length;if(i){const I=this.activeFormattingElements.entries.findIndex(r=>r.type===Gre.EntryType.Marker||this.openElements.contains(r.element)),n=I<0?i-1:I-1;for(let r=n;r>=0;r--){const C=this.activeFormattingElements.entries[r];this._insertElement(C.token,this.treeAdapter.getNamespaceURI(C.element)),C.element=this.openElements.current}}}},{key:"_closeTableCell",value:function(){this.openElements.generateImpliedEndTags(),this.openElements.popUntilTableCellPopped(),this.activeFormattingElements.clearToLastMarker(),this.insertionMode=Ne.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=Ne.IN_ROW;return}case z.TAG_ID.TBODY:case z.TAG_ID.THEAD:case z.TAG_ID.TFOOT:{this.insertionMode=Ne.IN_TABLE_BODY;return}case z.TAG_ID.CAPTION:{this.insertionMode=Ne.IN_CAPTION;return}case z.TAG_ID.COLGROUP:{this.insertionMode=Ne.IN_COLUMN_GROUP;return}case z.TAG_ID.TABLE:{this.insertionMode=Ne.IN_TABLE;return}case z.TAG_ID.BODY:{this.insertionMode=Ne.IN_BODY;return}case z.TAG_ID.FRAMESET:{this.insertionMode=Ne.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?Ne.AFTER_HEAD:Ne.BEFORE_HEAD;return}case z.TAG_ID.TD:case z.TAG_ID.TH:{if(i>0){this.insertionMode=Ne.IN_CELL;return}break}case z.TAG_ID.HEAD:{if(i>0){this.insertionMode=Ne.IN_HEAD;return}break}}this.insertionMode=Ne.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=Ne.IN_SELECT_IN_TABLE;return}}this.insertionMode=Ne.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){ABt(this,i);return}switch(this.insertionMode){case Ne.INITIAL:{aZ(this,i);break}case Ne.BEFORE_HTML:{Iv(this,i);break}case Ne.BEFORE_HEAD:{nv(this,i);break}case Ne.IN_HEAD:{rv(this,i);break}case Ne.IN_HEAD_NO_SCRIPT:{Cv(this,i);break}case Ne.AFTER_HEAD:{ov(this,i);break}case Ne.IN_BODY:case Ne.IN_CAPTION:case Ne.IN_CELL:case Ne.IN_TEMPLATE:{Swe(this,i);break}case Ne.TEXT:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:{this._insertCharacters(i);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{RD(this,i);break}case Ne.IN_TABLE_TEXT:{Hwe(this,i);break}case Ne.IN_COLUMN_GROUP:{MX(this,i);break}case Ne.AFTER_BODY:{zX(this,i);break}case Ne.AFTER_AFTER_BODY:{iW(this,i);break}}}},{key:"onNullCharacter",value:function(i){if(this.skipNextNewLine=!1,this.tokenizer.inForeignNode){aBt(this,i);return}switch(this.insertionMode){case Ne.INITIAL:{aZ(this,i);break}case Ne.BEFORE_HTML:{Iv(this,i);break}case Ne.BEFORE_HEAD:{nv(this,i);break}case Ne.IN_HEAD:{rv(this,i);break}case Ne.IN_HEAD_NO_SCRIPT:{Cv(this,i);break}case Ne.AFTER_HEAD:{ov(this,i);break}case Ne.TEXT:{this._insertCharacters(i);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{RD(this,i);break}case Ne.IN_COLUMN_GROUP:{MX(this,i);break}case Ne.AFTER_BODY:{zX(this,i);break}case Ne.AFTER_AFTER_BODY:{iW(this,i);break}}}},{key:"onComment",value:function(i){if(this.skipNextNewLine=!1,this.currentNotInHTML){_z(this,i);return}switch(this.insertionMode){case Ne.INITIAL:case Ne.BEFORE_HTML:case Ne.BEFORE_HEAD:case Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:case Ne.IN_BODY:case Ne.IN_TABLE:case Ne.IN_CAPTION:case Ne.IN_COLUMN_GROUP:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:case Ne.IN_CELL:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:case Ne.IN_TEMPLATE:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:{_z(this,i);break}case Ne.IN_TABLE_TEXT:{AZ(this,i);break}case Ne.AFTER_BODY:{EGt(this,i);break}case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{MGt(this,i);break}}}},{key:"onDoctype",value:function(i){switch(this.skipNextNewLine=!1,this.insertionMode){case Ne.INITIAL:{zGt(this,i);break}case Ne.BEFORE_HEAD:case Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:{this._err(i,fn.ERR.misplacedDoctype);break}case Ne.IN_TABLE_TEXT:{AZ(this,i);break}}}},{key:"onStartTag",value:function(i){this.skipNextNewLine=!1,this.currentToken=i,this._processStartTag(i),i.selfClosing&&!i.ackSelfClosing&&this._err(i,fn.ERR.nonVoidHtmlElementStartTagWithTrailingSolidus)}},{key:"_processStartTag",value:function(i){this.shouldProcessStartTagTokenInForeignContent(i)?sBt(this,i):this._startTagOutsideForeignContent(i)}},{key:"_startTagOutsideForeignContent",value:function(i){switch(this.insertionMode){case Ne.INITIAL:{aZ(this,i);break}case Ne.BEFORE_HTML:{PGt(this,i);break}case Ne.BEFORE_HEAD:{OGt(this,i);break}case Ne.IN_HEAD:{ba(this,i);break}case Ne.IN_HEAD_NO_SCRIPT:{UGt(this,i);break}case Ne.AFTER_HEAD:{jGt(this,i);break}case Ne.IN_BODY:{Pn(this,i);break}case Ne.IN_TABLE:{Qb(this,i);break}case Ne.IN_TABLE_TEXT:{AZ(this,i);break}case Ne.IN_CAPTION:{_vt(this,i);break}case Ne.IN_COLUMN_GROUP:{D4(this,i);break}case Ne.IN_TABLE_BODY:{dk(this,i);break}case Ne.IN_ROW:{hk(this,i);break}case Ne.IN_CELL:{Qvt(this,i);break}case Ne.IN_SELECT:{kwe(this,i);break}case Ne.IN_SELECT_IN_TABLE:{$vt(this,i);break}case Ne.IN_TEMPLATE:{eBt(this,i);break}case Ne.AFTER_BODY:{gBt(this,i);break}case Ne.IN_FRAMESET:{iBt(this,i);break}case Ne.AFTER_FRAMESET:{nBt(this,i);break}case Ne.AFTER_AFTER_BODY:{CBt(this,i);break}case Ne.AFTER_AFTER_FRAMESET:{oBt(this,i);break}}}},{key:"onEndTag",value:function(i){this.skipNextNewLine=!1,this.currentToken=i,this.currentNotInHTML?lBt(this,i):this._endTagOutsideForeignContent(i)}},{key:"_endTagOutsideForeignContent",value:function(i){switch(this.insertionMode){case Ne.INITIAL:{aZ(this,i);break}case Ne.BEFORE_HTML:{JGt(this,i);break}case Ne.BEFORE_HEAD:{_Gt(this,i);break}case Ne.IN_HEAD:{LGt(this,i);break}case Ne.IN_HEAD_NO_SCRIPT:{QGt(this,i);break}case Ne.AFTER_HEAD:{$Gt(this,i);break}case Ne.IN_BODY:{uk(this,i);break}case Ne.TEXT:{Kvt(this,i);break}case Ne.IN_TABLE:{OB(this,i);break}case Ne.IN_TABLE_TEXT:{AZ(this,i);break}case Ne.IN_CAPTION:{Lvt(this,i);break}case Ne.IN_COLUMN_GROUP:{Uvt(this,i);break}case Ne.IN_TABLE_BODY:{Lz(this,i);break}case Ne.IN_ROW:{Nwe(this,i);break}case Ne.IN_CELL:{jvt(this,i);break}case Ne.IN_SELECT:{Ywe(this,i);break}case Ne.IN_SELECT_IN_TABLE:{qvt(this,i);break}case Ne.IN_TEMPLATE:{tBt(this,i);break}case Ne.AFTER_BODY:{Fwe(this,i);break}case Ne.IN_FRAMESET:{IBt(this,i);break}case Ne.AFTER_FRAMESET:{rBt(this,i);break}case Ne.AFTER_AFTER_BODY:{iW(this,i);break}}}},{key:"onEof",value:function(i){switch(this.insertionMode){case Ne.INITIAL:{aZ(this,i);break}case Ne.BEFORE_HTML:{Iv(this,i);break}case Ne.BEFORE_HEAD:{nv(this,i);break}case Ne.IN_HEAD:{rv(this,i);break}case Ne.IN_HEAD_NO_SCRIPT:{Cv(this,i);break}case Ne.AFTER_HEAD:{ov(this,i);break}case Ne.IN_BODY:case Ne.IN_TABLE:case Ne.IN_CAPTION:case Ne.IN_COLUMN_GROUP:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:case Ne.IN_CELL:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:{Wwe(this,i);break}case Ne.TEXT:{Fvt(this,i);break}case Ne.IN_TABLE_TEXT:{AZ(this,i);break}case Ne.IN_TEMPLATE:{Kwe(this,i);break}case Ne.AFTER_BODY:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{F4(this,i);break}}}},{key:"onWhitespaceCharacter",value:function(i){if(this.skipNextNewLine&&(this.skipNextNewLine=!1,i.chars.charCodeAt(0)===Gwe.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 Ne.IN_HEAD:case Ne.IN_HEAD_NO_SCRIPT:case Ne.AFTER_HEAD:case Ne.TEXT:case Ne.IN_COLUMN_GROUP:case Ne.IN_SELECT:case Ne.IN_SELECT_IN_TABLE:case Ne.IN_FRAMESET:case Ne.AFTER_FRAMESET:{this._insertCharacters(i);break}case Ne.IN_BODY:case Ne.IN_CAPTION:case Ne.IN_CELL:case Ne.IN_TEMPLATE:case Ne.AFTER_BODY:case Ne.AFTER_AFTER_BODY:case Ne.AFTER_AFTER_FRAMESET:{Bwe(this,i);break}case Ne.IN_TABLE:case Ne.IN_TABLE_BODY:case Ne.IN_ROW:{RD(this,i);break}case Ne.IN_TABLE_TEXT:{Xwe(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({},Bre),I);i??(i=n.treeAdapter.createElement(z.TAG_NAMES.TEMPLATE,z.NS.HTML,[]));const r=n.treeAdapter.createElement("documentmock",z.NS.HTML,[]),C=new this(n,r,i);return C.fragmentContextID===z.TAG_ID.TEMPLATE&&C.tmplInsertionModeStack.unshift(Ne.IN_TEMPLATE),C._initTokenizerForFragmentParsing(),C._insertFakeRootElement(),C._resetInsertionMode(),C._findFormInFragmentContext(),C}}]),e}();JB.Parser=NGt;function kGt(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):Vwe(e,g),i}function YGt(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 KGt(e,g,i){let I=g,n=e.openElements.getCommonAncestor(g);for(let r=0,C=n;C!==i;r++,C=n){n=e.openElements.getCommonAncestor(C);const o=e.activeFormattingElements.getElementEntry(C),a=o&&r>=HGt;!o||a?(a&&e.activeFormattingElements.removeEntry(o),e.openElements.remove(C)):(C=FGt(e,o),I===g&&(e.activeFormattingElements.bookmark=o),e.treeAdapter.detachNode(I),e.treeAdapter.appendChild(C,I),I=C)}return I}function FGt(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 DGt(e,g,i){const I=e.treeAdapter.getTagName(g),n=(0,z.getTagID)(I);if(e._isElementCausesFosterParenting(n))e._fosterParentElement(i);else{const r=e.treeAdapter.getNamespaceURI(g);n===z.TAG_ID.TEMPLATE&&r===z.NS.HTML&&(g=e.treeAdapter.getTemplateContent(g)),e.treeAdapter.appendChild(g,i)}}function xGt(e,g,i){const I=e.treeAdapter.getNamespaceURI(i.element),{token:n}=i,r=e.treeAdapter.createElement(n.tagName,I,n.attrs);e._adoptNodes(g,r),e.treeAdapter.appendChild(g,r),e.activeFormattingElements.insertElementAfterBookmark(r,n),e.activeFormattingElements.removeEntry(i),e.openElements.remove(i.element),e.openElements.insertAfter(g,r,n.tagID)}function K4(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 r=e.openElements.items[1],C=e.treeAdapter.getNodeSourceCodeLocation(r);C&&!C.endTag&&e._setEndLocation(r,g)}}}}function zGt(e,g){e._setDocumentType(g);const i=g.forceQuirks?z.DOCUMENT_MODE.QUIRKS:vre.getDocumentMode(g);vre.isConforming(g)||e._err(g,fn.ERR.nonConformingDoctype),e.treeAdapter.setDocumentMode(e.document,i),e.insertionMode=Ne.BEFORE_HTML}function aZ(e,g){e._err(g,fn.ERR.missingDoctype,!0),e.treeAdapter.setDocumentMode(e.document,z.DOCUMENT_MODE.QUIRKS),e.insertionMode=Ne.BEFORE_HTML,e._processToken(g)}function PGt(e,g){g.tagID===z.TAG_ID.HTML?(e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.BEFORE_HEAD):Iv(e,g)}function JGt(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)&&Iv(e,g)}function Iv(e,g){e._insertFakeRootElement(),e.insertionMode=Ne.BEFORE_HEAD,e._processToken(g)}function OGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.HEAD:{e._insertElement(g,z.NS.HTML),e.headElement=e.openElements.current,e.insertionMode=Ne.IN_HEAD;break}default:nv(e,g)}}function _Gt(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?nv(e,g):e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}function nv(e,g){e._insertFakeElement(z.TAG_NAMES.HEAD,z.TAG_ID.HEAD),e.headElement=e.openElements.current,e.insertionMode=Ne.IN_HEAD,e._processToken(g)}function ba(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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,jn.TokenizerMode.RCDATA);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT):(e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_HEAD_NO_SCRIPT);break}case z.TAG_ID.NOFRAMES:case z.TAG_ID.STYLE:{e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT);break}case z.TAG_ID.SCRIPT:{e._switchToTextParsing(g,jn.TokenizerMode.SCRIPT_DATA);break}case z.TAG_ID.TEMPLATE:{e._insertTemplate(g),e.activeFormattingElements.insertMarker(),e.framesetOk=!1,e.insertionMode=Ne.IN_TEMPLATE,e.tmplInsertionModeStack.unshift(Ne.IN_TEMPLATE);break}case z.TAG_ID.HEAD:{e._err(g,fn.ERR.misplacedStartTagForHeadElement);break}default:rv(e,g)}}function LGt(e,g){switch(g.tagID){case z.TAG_ID.HEAD:{e.openElements.pop(),e.insertionMode=Ne.AFTER_HEAD;break}case z.TAG_ID.BODY:case z.TAG_ID.BR:case z.TAG_ID.HTML:{rv(e,g);break}case z.TAG_ID.TEMPLATE:{Am(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function Am(e,g){e.openElements.tmplCount>0?(e.openElements.generateImpliedEndTagsThoroughly(),e.openElements.currentTagId!==z.TAG_ID.TEMPLATE&&e._err(g,fn.ERR.closingOfElementWithOpenChildElements),e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode()):e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}function rv(e,g){e.openElements.pop(),e.insertionMode=Ne.AFTER_HEAD,e._processToken(g)}function UGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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:{ba(e,g);break}case z.TAG_ID.NOSCRIPT:{e._err(g,fn.ERR.nestedNoscriptInHead);break}default:Cv(e,g)}}function QGt(e,g){switch(g.tagID){case z.TAG_ID.NOSCRIPT:{e.openElements.pop(),e.insertionMode=Ne.IN_HEAD;break}case z.TAG_ID.BR:{Cv(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function Cv(e,g){const i=g.type===VI.TokenType.EOF?fn.ERR.openElementsLeftAfterEof:fn.ERR.disallowedContentInNoscriptInHead;e._err(g,i),e.openElements.pop(),e.insertionMode=Ne.IN_HEAD,e._processToken(g)}function jGt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.BODY:{e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=Ne.IN_BODY;break}case z.TAG_ID.FRAMESET:{e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.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,fn.ERR.abandonedHeadElementChild),e.openElements.push(e.headElement,z.TAG_ID.HEAD),ba(e,g),e.openElements.remove(e.headElement);break}case z.TAG_ID.HEAD:{e._err(g,fn.ERR.misplacedStartTagForHeadElement);break}default:ov(e,g)}}function $Gt(e,g){switch(g.tagID){case z.TAG_ID.BODY:case z.TAG_ID.HTML:case z.TAG_ID.BR:{ov(e,g);break}case z.TAG_ID.TEMPLATE:{Am(e,g);break}default:e._err(g,fn.ERR.endTagWithoutMatchingOpenElement)}}function ov(e,g){e._insertFakeElement(z.TAG_NAMES.BODY,z.TAG_ID.BODY),e.insertionMode=Ne.IN_BODY,ck(e,g)}function ck(e,g){switch(g.type){case VI.TokenType.CHARACTER:{Swe(e,g);break}case VI.TokenType.WHITESPACE_CHARACTER:{Bwe(e,g);break}case VI.TokenType.COMMENT:{_z(e,g);break}case VI.TokenType.START_TAG:{Pn(e,g);break}case VI.TokenType.END_TAG:{uk(e,g);break}case VI.TokenType.EOF:{Wwe(e,g);break}}}function Bwe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g)}function Swe(e,g){e._reconstructActiveFormattingElements(),e._insertCharacters(g),e.framesetOk=!1}function qGt(e,g){e.openElements.tmplCount===0&&e.treeAdapter.adoptAttributes(e.openElements.items[0],g.attrs)}function evt(e,g){const i=e.openElements.tryPeekProperlyNestedBodyElement();i&&e.openElements.tmplCount===0&&(e.framesetOk=!1,e.treeAdapter.adoptAttributes(i,g.attrs))}function tvt(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=Ne.IN_FRAMESET)}function gvt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML)}function ivt(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 Ivt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.framesetOk=!1}function nvt(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 rvt(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 Cvt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._insertElement(g,z.NS.HTML),e.tokenizer.state=jn.TokenizerMode.PLAINTEXT}function ovt(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 avt(e,g){const i=e.activeFormattingElements.getElementEntryInScopeWithTagName(z.TAG_NAMES.A);i&&(K4(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 Avt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function svt(e,g){e._reconstructActiveFormattingElements(),e.openElements.hasInScope(z.TAG_ID.NOBR)&&(K4(e,g),e._reconstructActiveFormattingElements()),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.pushElement(e.openElements.current,g)}function lvt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.activeFormattingElements.insertMarker(),e.framesetOk=!1}function cvt(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=Ne.IN_TABLE}function wwe(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function Rwe(e){const g=(0,VI.getTokenAttr)(e,z.ATTRS.TYPE);return g!=null&&g.toLowerCase()===WGt}function uvt(e,g){e._reconstructActiveFormattingElements(),e._appendElement(g,z.NS.HTML),Rwe(g)||(e.framesetOk=!1),g.ackSelfClosing=!0}function dvt(e,g){e._appendElement(g,z.NS.HTML),g.ackSelfClosing=!0}function hvt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._appendElement(g,z.NS.HTML),e.framesetOk=!1,g.ackSelfClosing=!0}function mvt(e,g){g.tagName=z.TAG_NAMES.IMG,g.tagID=z.TAG_ID.IMG,wwe(e,g)}function fvt(e,g){e._insertElement(g,z.NS.HTML),e.skipNextNewLine=!0,e.tokenizer.state=jn.TokenizerMode.RCDATA,e.originalInsertionMode=e.insertionMode,e.framesetOk=!1,e.insertionMode=Ne.TEXT}function pvt(e,g){e.openElements.hasInButtonScope(z.TAG_ID.P)&&e._closePElement(),e._reconstructActiveFormattingElements(),e.framesetOk=!1,e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function bvt(e,g){e.framesetOk=!1,e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function Sre(e,g){e._switchToTextParsing(g,jn.TokenizerMode.RAWTEXT)}function yvt(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML),e.framesetOk=!1,e.insertionMode=e.insertionMode===Ne.IN_TABLE||e.insertionMode===Ne.IN_CAPTION||e.insertionMode===Ne.IN_TABLE_BODY||e.insertionMode===Ne.IN_ROW||e.insertionMode===Ne.IN_CELL?Ne.IN_SELECT_IN_TABLE:Ne.IN_SELECT}function Zvt(e,g){e.openElements.currentTagId===z.TAG_ID.OPTION&&e.openElements.pop(),e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function Gvt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTags(),e._insertElement(g,z.NS.HTML)}function vvt(e,g){e.openElements.hasInScope(z.TAG_ID.RUBY)&&e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.RTC),e._insertElement(g,z.NS.HTML)}function Bvt(e,g){e._reconstructActiveFormattingElements(),_a.adjustTokenMathMLAttrs(g),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.MATHML):e._insertElement(g,z.NS.MATHML),g.ackSelfClosing=!0}function Svt(e,g){e._reconstructActiveFormattingElements(),_a.adjustTokenSVGAttrs(g),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,z.NS.SVG):e._insertElement(g,z.NS.SVG),g.ackSelfClosing=!0}function wre(e,g){e._reconstructActiveFormattingElements(),e._insertElement(g,z.NS.HTML)}function Pn(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:{Avt(e,g);break}case z.TAG_ID.A:{avt(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:{ivt(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:{gvt(e,g);break}case z.TAG_ID.LI:case z.TAG_ID.DD:case z.TAG_ID.DT:{rvt(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:{wwe(e,g);break}case z.TAG_ID.HR:{hvt(e,g);break}case z.TAG_ID.RB:case z.TAG_ID.RTC:{Gvt(e,g);break}case z.TAG_ID.RT:case z.TAG_ID.RP:{vvt(e,g);break}case z.TAG_ID.PRE:case z.TAG_ID.LISTING:{Ivt(e,g);break}case z.TAG_ID.XMP:{pvt(e,g);break}case z.TAG_ID.SVG:{Svt(e,g);break}case z.TAG_ID.HTML:{qGt(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:{ba(e,g);break}case z.TAG_ID.BODY:{evt(e,g);break}case z.TAG_ID.FORM:{nvt(e,g);break}case z.TAG_ID.NOBR:{svt(e,g);break}case z.TAG_ID.MATH:{Bvt(e,g);break}case z.TAG_ID.TABLE:{cvt(e,g);break}case z.TAG_ID.INPUT:{uvt(e,g);break}case z.TAG_ID.PARAM:case z.TAG_ID.TRACK:case z.TAG_ID.SOURCE:{dvt(e,g);break}case z.TAG_ID.IMAGE:{mvt(e,g);break}case z.TAG_ID.BUTTON:{ovt(e,g);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{lvt(e,g);break}case z.TAG_ID.IFRAME:{bvt(e,g);break}case z.TAG_ID.SELECT:{yvt(e,g);break}case z.TAG_ID.OPTION:case z.TAG_ID.OPTGROUP:{Zvt(e,g);break}case z.TAG_ID.NOEMBED:{Sre(e,g);break}case z.TAG_ID.FRAMESET:{tvt(e,g);break}case z.TAG_ID.TEXTAREA:{fvt(e,g);break}case z.TAG_ID.NOSCRIPT:{e.options.scriptingEnabled?Sre(e,g):wre(e,g);break}case z.TAG_ID.PLAINTEXT:{Cvt(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:wre(e,g)}}function wvt(e,g){if(e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=Ne.AFTER_BODY,e.options.sourceCodeLocationInfo)){const i=e.openElements.tryPeekProperlyNestedBodyElement();i&&e._setEndLocation(i,g)}}function Rvt(e,g){e.openElements.hasInScope(z.TAG_ID.BODY)&&(e.insertionMode=Ne.AFTER_BODY,Fwe(e,g))}function Vvt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(i))}function Wvt(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 Xvt(e){e.openElements.hasInButtonScope(z.TAG_ID.P)||e._insertFakeElement(z.TAG_NAMES.P,z.TAG_ID.P),e._closePElement()}function Hvt(e){e.openElements.hasInListItemScope(z.TAG_ID.LI)&&(e.openElements.generateImpliedEndTagsWithExclusion(z.TAG_ID.LI),e.openElements.popUntilTagNamePopped(z.TAG_ID.LI))}function Tvt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTagsWithExclusion(i),e.openElements.popUntilTagNamePopped(i))}function Nvt(e){e.openElements.hasNumberedHeaderInScope()&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilNumberedHeaderPopped())}function kvt(e,g){const i=g.tagID;e.openElements.hasInScope(i)&&(e.openElements.generateImpliedEndTags(),e.openElements.popUntilTagNamePopped(i),e.activeFormattingElements.clearToLastMarker())}function Yvt(e){e._reconstructActiveFormattingElements(),e._insertFakeElement(z.TAG_NAMES.BR,z.TAG_ID.BR),e.openElements.pop(),e.framesetOk=!1}function Vwe(e,g){const i=g.tagName,I=g.tagID;for(let n=e.openElements.stackTop;n>0;n--){const r=e.openElements.items[n],C=e.openElements.tagIDs[n];if(I===C&&(I!==z.TAG_ID.UNKNOWN||e.treeAdapter.getTagName(r)===i)){e.openElements.generateImpliedEndTagsWithExclusion(I),e.openElements.stackTop>=n&&e.openElements.shortenToLength(n);break}if(e._isSpecialElement(r,C))break}}function uk(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:{K4(e,g);break}case z.TAG_ID.P:{Xvt(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:{Vvt(e,g);break}case z.TAG_ID.LI:{Hvt(e);break}case z.TAG_ID.DD:case z.TAG_ID.DT:{Tvt(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:{Nvt(e);break}case z.TAG_ID.BR:{Yvt(e);break}case z.TAG_ID.BODY:{wvt(e,g);break}case z.TAG_ID.HTML:{Rvt(e,g);break}case z.TAG_ID.FORM:{Wvt(e);break}case z.TAG_ID.APPLET:case z.TAG_ID.OBJECT:case z.TAG_ID.MARQUEE:{kvt(e,g);break}case z.TAG_ID.TEMPLATE:{Am(e,g);break}default:Vwe(e,g)}}function Wwe(e,g){e.tmplInsertionModeStack.length>0?Kwe(e,g):F4(e,g)}function Kvt(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 Fvt(e,g){e._err(g,fn.ERR.eofInElementThatCanContainOnlyText),e.openElements.pop(),e.insertionMode=e.originalInsertionMode,e.onEof(g)}function RD(e,g){if(vwe.has(e.openElements.currentTagId))switch(e.pendingCharacterTokens.length=0,e.hasNonWhitespacePendingCharacterToken=!1,e.originalInsertionMode=e.insertionMode,e.insertionMode=Ne.IN_TABLE_TEXT,g.type){case VI.TokenType.CHARACTER:{Hwe(e,g);break}case VI.TokenType.WHITESPACE_CHARACTER:{Xwe(e,g);break}}else lw(e,g)}function Dvt(e,g){e.openElements.clearBackToTableContext(),e.activeFormattingElements.insertMarker(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_CAPTION}function xvt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_COLUMN_GROUP}function Evt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.COLGROUP,z.TAG_ID.COLGROUP),e.insertionMode=Ne.IN_COLUMN_GROUP,D4(e,g)}function Mvt(e,g){e.openElements.clearBackToTableContext(),e._insertElement(g,z.NS.HTML),e.insertionMode=Ne.IN_TABLE_BODY}function zvt(e,g){e.openElements.clearBackToTableContext(),e._insertFakeElement(z.TAG_NAMES.TBODY,z.TAG_ID.TBODY),e.insertionMode=Ne.IN_TABLE_BODY,dk(e,g)}function Pvt(e,g){e.openElements.hasInTableScope(z.TAG_ID.TABLE)&&(e.openElements.popUntilTagNamePopped(z.TAG_ID.TABLE),e._resetInsertionMode(),e._processStartTag(g))}function Jvt(e,g){Rwe(g)?e._appendElement(g,z.NS.HTML):lw(e,g),g.ackSelfClosing=!0}function Ovt(e,g){!e.formElement&&e.openElements.tmplCount===0&&(e._insertElement(g,z.NS.HTML),e.formElement=e.openElements.current,e.openElements.pop())}function Qb(e,g){switch(g.tagID){case z.TAG_ID.TD:case z.TAG_ID.TH:case z.TAG_ID.TR:{zvt(e,g);break}case z.TAG_ID.STYLE:case z.TAG_ID.SCRIPT:case z.TAG_ID.TEMPLATE:{ba(e,g);break}case z.TAG_ID.COL:{Evt(e,g);break}case z.TAG_ID.FORM:{Ovt(e,g);break}case z.TAG_ID.TABLE:{Pvt(e,g);break}case z.TAG_ID.TBODY:case z.TAG_ID.TFOOT:case z.TAG_ID.THEAD:{Mvt(e,g);break}case z.TAG_ID.INPUT:{Jvt(e,g);break}case z.TAG_ID.CAPTION:{Dvt(e,g);break}case z.TAG_ID.COLGROUP:{xvt(e,g);break}default:lw(e,g)}}function OB(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:{Am(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:lw(e,g)}}function lw(e,g){const i=e.fosterParentingEnabled;e.fosterParentingEnabled=!0,ck(e,g),e.fosterParentingEnabled=i}function Xwe(e,g){e.pendingCharacterTokens.push(g)}function Hwe(e,g){e.pendingCharacterTokens.push(g),e.hasNonWhitespacePendingCharacterToken=!0}function AZ(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:{Am(e,g);break}}}function $vt(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)):kwe(e,g)}function qvt(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)):Ywe(e,g)}function eBt(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:{ba(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]=Ne.IN_TABLE,e.insertionMode=Ne.IN_TABLE,Qb(e,g);break}case z.TAG_ID.COL:{e.tmplInsertionModeStack[0]=Ne.IN_COLUMN_GROUP,e.insertionMode=Ne.IN_COLUMN_GROUP,D4(e,g);break}case z.TAG_ID.TR:{e.tmplInsertionModeStack[0]=Ne.IN_TABLE_BODY,e.insertionMode=Ne.IN_TABLE_BODY,dk(e,g);break}case z.TAG_ID.TD:case z.TAG_ID.TH:{e.tmplInsertionModeStack[0]=Ne.IN_ROW,e.insertionMode=Ne.IN_ROW,hk(e,g);break}default:e.tmplInsertionModeStack[0]=Ne.IN_BODY,e.insertionMode=Ne.IN_BODY,Pn(e,g)}}function tBt(e,g){g.tagID===z.TAG_ID.TEMPLATE&&Am(e,g)}function Kwe(e,g){e.openElements.tmplCount>0?(e.openElements.popUntilTagNamePopped(z.TAG_ID.TEMPLATE),e.activeFormattingElements.clearToLastMarker(),e.tmplInsertionModeStack.shift(),e._resetInsertionMode(),e.onEof(g)):F4(e,g)}function gBt(e,g){g.tagID===z.TAG_ID.HTML?Pn(e,g):zX(e,g)}function Fwe(e,g){var i;if(g.tagID===z.TAG_ID.HTML){if(e.fragmentContext||(e.insertionMode=Ne.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 zX(e,g)}function zX(e,g){e.insertionMode=Ne.IN_BODY,ck(e,g)}function iBt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(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:{ba(e,g);break}}}function IBt(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=Ne.AFTER_FRAMESET))}function nBt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.NOFRAMES:{ba(e,g);break}}}function rBt(e,g){g.tagID===z.TAG_ID.HTML&&(e.insertionMode=Ne.AFTER_AFTER_FRAMESET)}function CBt(e,g){g.tagID===z.TAG_ID.HTML?Pn(e,g):iW(e,g)}function iW(e,g){e.insertionMode=Ne.IN_BODY,ck(e,g)}function oBt(e,g){switch(g.tagID){case z.TAG_ID.HTML:{Pn(e,g);break}case z.TAG_ID.NOFRAMES:{ba(e,g);break}}}function aBt(e,g){g.chars=Gwe.REPLACEMENT_CHARACTER,e._insertCharacters(g)}function ABt(e,g){e._insertCharacters(g),e.framesetOk=!1}function Dwe(e){for(;e.treeAdapter.getNamespaceURI(e.openElements.current)!==z.NS.HTML&&!e._isIntegrationPoint(e.openElements.currentTagId,e.openElements.current);)e.openElements.pop()}function sBt(e,g){if(_a.causesExit(g))Dwe(e),e._startTagOutsideForeignContent(g);else{const i=e._getAdjustedCurrentElement(),I=e.treeAdapter.getNamespaceURI(i);I===z.NS.MATHML?_a.adjustTokenMathMLAttrs(g):I===z.NS.SVG&&(_a.adjustTokenSVGTagName(g),_a.adjustTokenSVGAttrs(g)),_a.adjustTokenXMLAttrs(g),g.selfClosing?e._appendElement(g,I):e._insertElement(g,I),g.ackSelfClosing=!0}}function lBt(e,g){if(g.tagID===z.TAG_ID.P||g.tagID===z.TAG_ID.BR){Dwe(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 jb={};Object.defineProperty(jb,"__esModule",{value:!0});jb.serializeOuter=jb.serialize=void 0;const Ci=rl,xwe=Fb,cBt=lk,uBt=new Set([Ci.TAG_NAMES.AREA,Ci.TAG_NAMES.BASE,Ci.TAG_NAMES.BASEFONT,Ci.TAG_NAMES.BGSOUND,Ci.TAG_NAMES.BR,Ci.TAG_NAMES.COL,Ci.TAG_NAMES.EMBED,Ci.TAG_NAMES.FRAME,Ci.TAG_NAMES.HR,Ci.TAG_NAMES.IMG,Ci.TAG_NAMES.INPUT,Ci.TAG_NAMES.KEYGEN,Ci.TAG_NAMES.LINK,Ci.TAG_NAMES.META,Ci.TAG_NAMES.PARAM,Ci.TAG_NAMES.SOURCE,Ci.TAG_NAMES.TRACK,Ci.TAG_NAMES.WBR]);function Ewe(e,g){return g.treeAdapter.isElementNode(e)&&g.treeAdapter.getNamespaceURI(e)===Ci.NS.HTML&&uBt.has(g.treeAdapter.getTagName(e))}const Mwe={treeAdapter:cBt.defaultTreeAdapter,scriptingEnabled:!0};function dBt(e,g){const i=Object.assign(Object.assign({},Mwe),g);return Ewe(e,i)?"":zwe(e,i)}jb.serialize=dBt;function hBt(e,g){const i=Object.assign(Object.assign({},Mwe),g);return Pwe(e,i)}jb.serializeOuter=hBt;function zwe(e,g){let i="";const I=g.treeAdapter.isElementNode(e)&&g.treeAdapter.getTagName(e)===Ci.TAG_NAMES.TEMPLATE&&g.treeAdapter.getNamespaceURI(e)===Ci.NS.HTML?g.treeAdapter.getTemplateContent(e):e,n=g.treeAdapter.getChildNodes(I);if(n)for(const r of n)i+=Pwe(r,g);return i}function Pwe(e,g){return g.treeAdapter.isElementNode(e)?mBt(e,g):g.treeAdapter.isTextNode(e)?pBt(e,g):g.treeAdapter.isCommentNode(e)?bBt(e,g):g.treeAdapter.isDocumentTypeNode(e)?yBt(e,g):""}function mBt(e,g){const i=g.treeAdapter.getTagName(e);return`<${i}${fBt(e,g)}>${Ewe(e,g)?"":`${zwe(e,g)}`}`}function fBt(e,{treeAdapter:g}){let i="";for(const I of g.getAttrList(e)){if(i+=" ",!I.namespace)i+=I.name;else switch(I.namespace){case Ci.NS.XML:{i+=`xml:${I.name}`;break}case Ci.NS.XMLNS:{I.name!=="xmlns"&&(i+="xmlns:"),i+=I.name;break}case Ci.NS.XLINK:{i+=`xlink:${I.name}`;break}default:i+=`${I.prefix}:${I.name}`}i+=`="${(0,xwe.escapeAttribute)(I.value)}"`}return i}function pBt(e,g){const{treeAdapter:i}=g,I=i.getTextNodeContent(e),n=i.getParentNode(e),r=n&&i.isElementNode(n)&&i.getTagName(n);return r&&i.getNamespaceURI(n)===Ci.NS.HTML&&(0,Ci.hasUnescapedText)(r,g.scriptingEnabled)?I:(0,xwe.escapeText)(I)}function bBt(e,{treeAdapter:g}){return``}function yBt(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=JB;var i=lk;Object.defineProperty(e,"defaultTreeAdapter",{enumerable:!0,get:function(){return i.defaultTreeAdapter}});var I=JB;Object.defineProperty(e,"Parser",{enumerable:!0,get:function(){return I.Parser}});var n=jb;Object.defineProperty(e,"serialize",{enumerable:!0,get:function(){return n.serialize}}),Object.defineProperty(e,"serializeOuter",{enumerable:!0,get:function(){return n.serializeOuter}});var r=sw;Object.defineProperty(e,"ErrorCodes",{enumerable:!0,get:function(){return r.ERR}}),e.foreignContent=Y4,e.html=rl,e.Token=Ak;var C=dh;Object.defineProperty(e,"Tokenizer",{enumerable:!0,get:function(){return C.Tokenizer}}),Object.defineProperty(e,"TokenizerMode",{enumerable:!0,get:function(){return C.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})(uwe);(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.adapter=e.serializeDoctypeContent=void 0;const g=uwe,i=En;function I(C){return new i.Text(C)}function n(C){const o=C.includes('"')?"'":'"';return o+C+o}function r(C,o,a){let s="!DOCTYPE ";return C&&(s+=C),o?s+=` PUBLIC ${n(o)}`:a&&(s+=" SYSTEM"),a&&(s+=` ${n(a)}`),s}e.serializeDoctypeContent=r,e.adapter={isCommentNode:i.isComment,isElementNode:i.isTag,isTextNode:i.isText,createDocument(){const C=new i.Document([]);return C["x-mode"]=g.html.DOCUMENT_MODE.NO_QUIRKS,C},createDocumentFragment(){return new i.Document([])},createElement(C,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(C,l)),l["x-name"]=o??void 0,l["x-publicId"]=a??void 0,l["x-systemId"]=s??void 0},setDocumentMode(C,o){C["x-mode"]=o},getDocumentMode(C){return C["x-mode"]},detachNode(C){if(C.parent){const o=C.parent.children.indexOf(C),{prev:a,next:s}=C;C.prev=null,C.next=null,a&&(a.next=s),s&&(s.prev=a),C.parent.children.splice(o,1),C.parent=null}},insertText(C,o){const a=C.children[C.children.length-1];a&&(0,i.isText)(a)?a.data+=o:e.adapter.appendChild(C,I(o))},insertTextBefore(C,o,a){const s=C.children[C.children.indexOf(a)-1];s&&(0,i.isText)(s)?s.data+=o:e.adapter.insertBefore(C,I(o),a)},adoptAttributes(C,o){for(let a=0;a"u"&&(C.attribs[s]=o[a].value,C["x-attribsNamespace"][s]=o[a].namespace,C["x-attribsPrefix"][s]=o[a].prefix)}},getFirstChild(C){return C.children[0]},getChildNodes(C){return C.children},getParentNode(C){return C.parent},getAttrList(C){return C.attributes},getTagName(C){return C.name},getNamespaceURI(C){return C.namespace},getTextNodeContent(C){return C.data},getCommentNodeContent(C){return C.data},getDocumentTypeNodeName(C){var o;return(o=C["x-name"])!==null&&o!==void 0?o:""},getDocumentTypeNodePublicId(C){var o;return(o=C["x-publicId"])!==null&&o!==void 0?o:""},getDocumentTypeNodeSystemId(C){var o;return(o=C["x-systemId"])!==null&&o!==void 0?o:""},isDocumentTypeNode(C){return(0,i.isDirective)(C)&&C.name==="!doctype"},setNodeSourceCodeLocation(C,o){o&&(C.startIndex=o.startOffset,C.endIndex=o.endOffset),C.sourceCodeLocation=o},getNodeSourceCodeLocation(C){return C.sourceCodeLocation},updateNodeSourceCodeLocation(C,o){o.endOffset!=null&&(C.endIndex=o.endOffset),C.sourceCodeLocation=Object.assign(Object.assign({},C.sourceCodeLocation),o)}}})(cwe);var ZBt=$e&&$e.__spreadArray||function(e,g,i){if(i||arguments.length===2)for(var I=0,n=g.length,r;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?r(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):C(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):C(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&&C.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),Hre.has(g)?this.foreignContext.push(!0):Tre.has(g)&&this.foreignContext.push(!1)),(r=(n=this.cbs).onopentagname)===null||r===void 0||r.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,r,C,o,a;this.endIndex=i;var s=this.getSlice(g,i);if(this.lowerCaseTagNames&&(s=s.toLowerCase()),(Hre.has(s)||Tre.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"),(C=(r=this.cbs).onopentag)===null||C===void 0||C.call(r,"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,Rre.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===GV.QuoteType.Double?'"':g===GV.QuoteType.Single?"'":g===GV.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(HBt),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,r,C,o;this.endIndex=i,(r=(n=this.cbs).oncomment)===null||r===void 0||r.call(n,this.getSlice(g,i-I)),(o=(C=this.cbs).oncommentend)===null||o===void 0||o.call(C),this.startIndex=i+1},e.prototype.oncdata=function(g,i,I){var n,r,C,o,a,s,A,l,c,u;this.endIndex=i;var d=this.getSlice(g,i-I);this.options.xmlMode||this.options.recognizeCDATA?((r=(n=this.cbs).oncdatastart)===null||r===void 0||r.call(n),(o=(C=this.cbs).ontext)===null||o===void 0||o.call(C,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]:{};kj={},zwe(e)}var Di={},Jz={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})(Jz,Jz.exports);var NBt=Jz.exports,uu={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=C;var g=uk,I=n(g),i=lm;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}})(uu);Object.defineProperty(Di,"__esModule",{value:!0});var kBt=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")}}();Di.propsOfNode=dk;Di.childrenOfNode=Q0;Di.hasClassName=jBt;Di.treeForEach=Yj;Di.treeFilter=Kj;Di.findParentNode=$Bt;Di.pathToNode=Pwe;Di.parentsOfNode=eSt;Di.nodeHasId=tSt;Di.nodeMatchesObjectProps=nSt;Di.getTextFromNode=Jwe;Di.getTextFromHostNodes=Owe;Di.getHTMLFromHostNodes=_we;var YBt=E0,KBt=cm(YBt),xBt=jS,VCe=cm(xBt),DBt=fBe,FBt=cm(DBt),EBt=NBt,MBt=cm(EBt),zBt=sj,PBt=cm(zBt),JBt=Jve,OBt=cm(JBt),_Bt=uu,LBt=cm(_Bt);function cm(e){return e&&e.__esModule?e:{default:e}}function UBt(e,g,I){return g in e?Object.defineProperty(e,g,{value:I,enumerable:!0,configurable:!0,writable:!0}):e[g]=I,e}function QBt(e){if(Array.isArray(e)){for(var g=0,I=Array(e.length);g-1}function Yj(e,g){e&&g(e),Q0(e).forEach(function(I){return Yj(I,g)})}function Kj(e,g){var I=[];return Yj(e,function(i){g(i)&&I.push(i)}),I}function $Bt(e,g){var I=Kj(e,function(i){return i.rendered?Q0(i).indexOf(g)!==-1:!1});return I[0]||null}function qBt(e,g){return e.filter(function(I){return Kj(I,g).length!==0})}function Pwe(e,g){for(var I=[g],i=[],n=function(a){return e===a};I.length;){var C=I.pop(),r=Q0(C);if(C===e)return qBt(i,n);i.push(C),r.length===0&&i.pop(),I.push.apply(I,QBt(r))}return null}function eSt(e,g){return(Pwe(e,g)||[]).reverse()}function tSt(e,g){return dk(e).id===g}var gSt={};function ISt(e){return typeof e<"u"?e:gSt}function iSt(e){return(0,FBt.default)(e).reduce(function(g,I){var i=kBt(I,2),n=i[0],C=i[1];return(0,KBt.default)({},g,UBt({},n,ISt(C)))},{})}function nSt(e,g){return(0,MBt.default)(dk(e),iSt(g))}function CSt(e){return typeof e=="string"?String(e||""):e&&e.textContent||""}function xj(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:Q0(e).map(n).join("")}function Jwe(e){return xj(e,{recurse:Jwe,getCustom:function(){function g(I){var i=I.type;return"<"+String(i.displayName||(0,PBt.default)(i))+" />"}return g}()})}function Owe(e,g){return xj(e,{recurse:function(){function I(i){return Owe(i,g)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(g.nodeToHostNode(i,!0));return n.map(CSt).join("")}return I}()})}function rSt(e){return e==null?null:e.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g,"")}function _we(e,g){return xj(e,{recurse:function(){function I(i){return _we(i,g)}return I}(),handleHostNodes:function(){function I(i){var n=[].concat(g.nodeToHostNode(i,!0));return n.map(rSt).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(x){return typeof x}:function(x){return x&&typeof Symbol=="function"&&x.constructor===Symbol&&x!==Symbol.prototype?"symbol":typeof x},I=function(){function x(T,k){var Ie=[],me=!0,Re=!1,we=void 0;try{for(var je=T[Symbol.iterator](),at;!(me=(at=je.next()).done)&&(Ie.push(at.value),!(k&&Ie.length===k));me=!0);}catch(bt){Re=!0,we=bt}finally{try{!me&&je.return&&je.return()}finally{if(Re)throw we}}return Ie}return function(T,k){if(Array.isArray(T))return T;if(Symbol.iterator in Object(T))return x(T,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.getAdapter=Y,e.makeOptions=F,e.isCustomComponent=J,e.isCustomComponentElement=P,e.propsOfNode=ge,e.typeOfNode=q,e.nodeHasType=$,e.nodeMatches=ne,e.nodeEqual=be,e.containsChildrenSubArray=pe,e.childrenToSimplifiedArray=Be,e.isReactElementAlike=Pe,e.withSetStateAllowed=De,e.AND=Qe,e.displayNameOfNode=_e,e.sym=gt,e.privateSet=lt,e.cloneElement=tt,e.spyMethod=Xe;var i=lBe;Object.defineProperty(e,"shallowEqual",{enumerable:!0,get:function(){function x(){return W(i).default}return x}()}),e.isEmptyValue=ae,e.renderedDive=ye,e.loadCheerioRoot=He;var n=E0,C=W(n),r=aN,o=W(r),a=aj,s=W(a),A=fBe,l=W(A),c=sj,u=W(c),d=z0,h=W(d),m=jS,f=W(m),b=$ve,p=W(b),y=VBe,Z=W(y),B=lu,G=lm,v=Di,w=uu,V=W(w),S=uk,X=W(S);function W(x){return x&&x.__esModule?x:{default:x}}function R(x,T,k){return T in x?Object.defineProperty(x,T,{value:k,enumerable:!0,configurable:!0,writable:!0}):x[T]=k,x}function H(x,T){var k={};for(var Ie in x)T.indexOf(Ie)>=0||Object.prototype.hasOwnProperty.call(x,Ie)&&(k[Ie]=x[Ie]);return k}e.ITERATOR_SYMBOL=typeof Symbol=="function"&&Symbol.iterator;function Y(){var x=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return console.warn("getAdapter from Utils is deprecated; please use ./getAdapter instead"),(0,V.default)(x)}function K(x,T){if(x&&T&&x!==T)throw new TypeError("If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)")}function F(x){var T=(0,G.get)(),k=T.attachTo,Ie=T.hydrateIn,me=H(T,["attachTo","hydrateIn"]);K(k,Ie);var Re=x.attachTo,we=x.hydrateIn;K(Re,we);var je=we||Ie||k||Re||void 0,at=we||Ie||void 0,bt=(0,C.default)({},je&&{attachTo:je},at&&{hydrateIn:at});return(0,C.default)({},me,x,bt)}function J(x,T){return(0,X.default)(T),T.isCustomComponent?!!T.isCustomComponent(x):typeof x=="function"}function P(x,T){return T.isCustomComponentElement?!!T.isCustomComponentElement(x):!!x&&T.isValidElement(x)&&typeof x.type=="function"}function ge(x){return(0,l.default)(x&&x.props||{}).filter(function(T){var k=I(T,2),Ie=k[1];return typeof Ie<"u"}).reduce(function(T,k){var Ie=I(k,2),me=Ie[0],Re=Ie[1];return(0,C.default)(T,R({},me,Re))},{})}function q(x){return x?x.type:null}function $(x,T){if(!T||!x)return!1;var k=(0,V.default)();if(k.displayNameOfNode){var Ie=k.displayNameOfNode(x);return Ie===T}return x.type?typeof x.type=="string"?x.type===T:(typeof x.type=="function"?(0,u.default)(x.type)===T:x.type.name===T)||x.type.displayName===T:!1}function j(x,T,k,Ie){var me=Ie?ne:be;if(x===T)return!0;if(!Array.isArray(x)&&!Array.isArray(T))return me(x,T,k);var Re=(0,f.default)(x,1/0),we=(0,f.default)(T,1/0);if(Re.length!==we.length)return!1;if(Re.length===0&&we.length===0)return!0;for(var je=0;je2&&arguments[2]!==void 0?arguments[2]:s.default;return he(x,T,k,!0)}function be(x,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:s.default;return he(x,T,k,!1)}function pe(x,T,k){var Ie=(0,v.childrenOfNode)(T),me=function(we,je){return ve(x,Ie.slice(je,je+k.length),k)};return Ie.some(me)}function ve(x,T,k){return T.length===k.length&&T.every(function(Ie,me){return x(Ie,k[me])})}function We(x){var T=[],k=function(me){me===null||me===!1||typeof me>"u"||T.push(me)};return Array.isArray(x)?x.forEach(k):k(x),T}function Be(x){for(var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,k=We(x),Ie=[],me=0;me"u"?Ie.push(Re):Je(Re)&&Je(we)?Ie.push(we+Re):(Ie.push(we),Ie.push(Re))}return T?Ie.map(function(je){return typeof je=="string"?(0,p.default)(je):je}):Ie}function Je(x){return typeof x=="string"||typeof x=="number"}function Pe(x,T){return T.isValidElement(x)||Je(x)||Array.isArray(x)}function De(x){var T=!1;typeof globalThis.document>"u"&&(T=!0,globalThis.document={}),x(),T&&(globalThis.document=void 0,delete globalThis.document)}function Qe(x){var T=x.slice().reverse();return function(k){return T.every(function(Ie){return Ie(k)})}}function _e(x){if(!x)return null;var T=x.type;return T?T.displayName||(typeof T=="function"?(0,u.default)(T):T.name||T):null}function gt(x){return typeof Symbol=="function"?Symbol.for("enzyme."+String(x)):x}function lt(x,T,k){Object.defineProperty(x,T,{value:k,enumerable:!1,writable:!0})}function tt(x,T,k){return x.createElement(T.type,(0,C.default)({},T.props,k))}function Xe(x,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:function(){},Ie=void 0,me=x[T],Re=(0,h.default)(x,T),we=void 0;return Re&&(we=Object.getOwnPropertyDescriptor(x,T)),Object.defineProperty(x,T,{configurable:!0,enumerable:!we||!!we.enumerable,value:k(me)||function(){function je(){for(var at=arguments.length,bt=Array(at),ct=0;ct"'`]/g,ASt=RegExp(Lwe.source),sSt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},lSt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,cSt=typeof self=="object"&&self&&self.Object===Object&&self,uSt=lSt||cSt||Function("return this")();function dSt(e){return function(g){return e==null?void 0:e[g]}}var hSt=dSt(sSt),mSt=Object.prototype,fSt=mSt.toString,RCe=uSt.Symbol,WCe=RCe?RCe.prototype:void 0,XCe=WCe?WCe.toString:void 0;function pSt(e){if(typeof e=="string")return e;if(ySt(e))return XCe?XCe.call(e):"";var g=e+"";return g=="0"&&1/e==-oSt?"-0":g}function bSt(e){return!!e&&typeof e=="object"}function ySt(e){return typeof e=="symbol"||bSt(e)&&fSt.call(e)==aSt}function ZSt(e){return e==null?"":pSt(e)}function GSt(e){return e=ZSt(e),e&&ASt.test(e)?e.replace(Lwe,hSt):e}var vSt=GSt,BSt=String.prototype.valueOf,SSt=function(g){try{return BSt.call(g),!0}catch{return!1}},wSt=Object.prototype.toString,VSt="[object String]",RSt=QS(),Uwe=function(g){return typeof g=="string"?!0:typeof g!="object"?!1:RSt?SSt(g):wSt.call(g)===VSt},WSt=Number.prototype.toString,XSt=function(g){try{return WSt.call(g),!0}catch{return!1}},HSt=Object.prototype.toString,TSt="[object Number]",NSt=QS(),kSt=function(g){return typeof g=="number"?!0:typeof g!="object"?!1:NSt?XSt(g):HSt.call(g)===TSt},Qwe=mC,YSt=Qwe("Boolean.prototype.toString"),KSt=Qwe("Object.prototype.toString"),xSt=function(g){try{return YSt(g),!0}catch{return!1}},DSt="[object Boolean]",FSt=QS(),ESt=function(g){return typeof g=="boolean"?!0:g===null||typeof g!="object"?!1:FSt&&Symbol.toStringTag in g?xSt(g):KSt(g)===DSt};Object.defineProperty(du,"__esModule",{value:!0});var HCe=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};du.typeName=qwe;du.spaces=eVe;du.indent=tVe;du.debugNode=Dj;du.debugNodes=rwt;var MSt=vSt,zSt=rl(MSt),PSt=sj,jwe=rl(PSt),JSt=Uwe,OSt=rl(JSt),_St=kSt,LSt=rl(_St),USt=Cj,QSt=rl(USt),jSt=ESt,$St=rl(jSt),qSt=vve,bf=rl(qSt),ewt=z0,Um=rl(ewt),$we=Di,twt=uu,Oz=rl(twt);function rl(e){return e&&e.__esModule?e:{default:e}}var gwt=Function.bind.call(Function.call,Boolean.prototype.valueOf);function qwe(e){var g=(0,Oz.default)();return g.displayNameOfNode?(0,Oz.default)().displayNameOfNode(e)||"Component":typeof e.type=="function"?e.type.displayName||(0,jwe.default)(e.type)||"Component":e.type}function eVe(e){return Array(e+1).join(" ")}function tVe(e,g){return g.split(` -`).map(function(I){return""+String(eVe(e))+String(I)}).join(` -`)}function Iwt(e,g){return(0,OSt.default)(e)?(0,bf.default)(String(e),{quoteStyle:"double"}):(0,LSt.default)(e)?"{"+String((0,bf.default)(Number(e)))+"}":(0,$St.default)(e)?"{"+String((0,bf.default)(gwt(e)))+"}":(0,QSt.default)(e)?"{"+String((0,bf.default)(e))+"}":(typeof e>"u"?"undefined":HCe(e))==="object"?g.verbose?"{"+String((0,bf.default)(e))+"}":"{{...}}":"{["+(typeof e>"u"?"undefined":HCe(e))+"]}"}function iwt(e,g){var I=(0,$we.propsOfNode)(e),i=Object.keys(I).filter(function(n){return n!=="children"});return i.map(function(n){return String(n)+"="+String(Iwt(I[n],g))}).join(" ")}function nwt(e,g){return e.length?` -`+String(e.map(function(I){return tVe(g,I)}).join(` + `);if(!(r instanceof i.default))throw new Error("Enzyme Internal Error: configured enzyme adapter did not inherit from the EnzymeAdapter base class")}})(mk);Object.defineProperty(sm,"__esModule",{value:!0});sm.get=DBt;sm.merge=jwe;sm.reset=xBt;var YBt=M0,Uwe=Qwe(YBt),KBt=mk,FBt=Qwe(KBt);function Qwe(e){return e&&e.__esModule?e:{default:e}}var E4={};function DBt(){return(0,Uwe.default)({},E4)}function jwe(e){e.adapter&&(0,FBt.default)(e.adapter),(0,Uwe.default)(E4,e)}function xBt(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};E4={},jwe(e)}var DI={},Qz={exports:{}};(function(e,g){Object.defineProperty(g,"__esModule",{value:!0});var i=function(I){function n(r,C){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(r){if(!I.propertyIsEnumerable(r))return!1;var C=n[r],o=I[r];return!(typeof C=="object"&&C!==null?!i(o,C):o!==C)})});g.default=i,e.exports=g.default})(Qz,Qz.exports);var EBt=Qz.exports,cu={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=r;var g=mk,i=n(g),I=sm;function n(C){return C&&C.__esModule?C:{default:C}}function r(){var C=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(C.adapter)return(0,i.default)(C.adapter),C.adapter;var o=(0,I.get)(),a=o.adapter;return(0,i.default)(a),a}})(cu);Object.defineProperty(DI,"__esModule",{value:!0});var MBt=function(){function e(g,i){var I=[],n=!0,r=!1,C=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){r=!0,C=s}finally{try{!n&&o.return&&o.return()}finally{if(r)throw C}}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")}}();DI.propsOfNode=fk;DI.childrenOfNode=j0;DI.hasClassName=ISt;DI.treeForEach=M4;DI.treeFilter=z4;DI.findParentNode=nSt;DI.pathToNode=$we;DI.parentsOfNode=CSt;DI.nodeHasId=oSt;DI.nodeMatchesObjectProps=lSt;DI.getTextFromNode=qwe;DI.getTextFromHostNodes=eRe;DI.getHTMLFromHostNodes=tRe;var zBt=M0,PBt=lm(zBt),JBt=ew,Nre=lm(JBt),OBt=SBe,_Bt=lm(OBt),LBt=EBt,UBt=lm(LBt),QBt=m4,jBt=lm(QBt),$Bt=qve,qBt=lm($Bt),eSt=cu,tSt=lm(eSt);function lm(e){return e&&e.__esModule?e:{default:e}}function gSt(e,g,i){return g in e?Object.defineProperty(e,g,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[g]=i,e}function iSt(e){if(Array.isArray(e)){for(var g=0,i=Array(e.length);g-1}function M4(e,g){e&&g(e),j0(e).forEach(function(i){return M4(i,g)})}function z4(e,g){var i=[];return M4(e,function(I){g(I)&&i.push(I)}),i}function nSt(e,g){var i=z4(e,function(I){return I.rendered?j0(I).indexOf(g)!==-1:!1});return i[0]||null}function rSt(e,g){return e.filter(function(i){return z4(i,g).length!==0})}function $we(e,g){for(var i=[g],I=[],n=function(a){return e===a};i.length;){var r=i.pop(),C=j0(r);if(r===e)return rSt(I,n);I.push(r),C.length===0&&I.pop(),i.push.apply(i,iSt(C))}return null}function CSt(e,g){return($we(e,g)||[]).reverse()}function oSt(e,g){return fk(e).id===g}var aSt={};function ASt(e){return typeof e<"u"?e:aSt}function sSt(e){return(0,_Bt.default)(e).reduce(function(g,i){var I=MBt(i,2),n=I[0],r=I[1];return(0,PBt.default)({},g,gSt({},n,ASt(r)))},{})}function lSt(e,g){return(0,UBt.default)(fk(e),sSt(g))}function cSt(e){return typeof e=="string"?String(e||""):e&&e.textContent||""}function P4(e,g){var i=g.getCustom,I=g.handleHostNodes,n=g.recurse,r=g.nullRenderReturnsNull,C=r===void 0?!1:r;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&&C?null:j0(e).map(n).join("")}function qwe(e){return P4(e,{recurse:qwe,getCustom:function(){function g(i){var I=i.type;return"<"+String(I.displayName||(0,jBt.default)(I))+" />"}return g}()})}function eRe(e,g){return P4(e,{recurse:function(){function i(I){return eRe(I,g)}return i}(),handleHostNodes:function(){function i(I){var n=[].concat(g.nodeToHostNode(I,!0));return n.map(cSt).join("")}return i}()})}function uSt(e){return e==null?null:e.outerHTML.replace(/\sdata-(reactid|reactroot)+="([^"]*)+"/g,"")}function tRe(e,g){return P4(e,{recurse:function(){function i(I){return tRe(I,g)}return i}(),handleHostNodes:function(){function i(I){var n=[].concat(g.nodeToHostNode(I,!0));return n.map(uSt).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(F){return typeof F}:function(F){return F&&typeof Symbol=="function"&&F.constructor===Symbol&&F!==Symbol.prototype?"symbol":typeof F},i=function(){function F(T,k){var ie=[],me=!0,Ve=!1,we=void 0;try{for(var je=T[Symbol.iterator](),at;!(me=(at=je.next()).done)&&(ie.push(at.value),!(k&&ie.length===k));me=!0);}catch(bt){Ve=!0,we=bt}finally{try{!me&&je.return&&je.return()}finally{if(Ve)throw we}}return ie}return function(T,k){if(Array.isArray(T))return T;if(Symbol.iterator in Object(T))return F(T,k);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e.getAdapter=Y,e.makeOptions=x,e.isCustomComponent=J,e.isCustomComponentElement=P,e.propsOfNode=ge,e.typeOfNode=q,e.nodeHasType=$,e.nodeMatches=ne,e.nodeEqual=be,e.containsChildrenSubArray=pe,e.childrenToSimplifiedArray=Be,e.isReactElementAlike=Pe,e.withSetStateAllowed=De,e.AND=Qe,e.displayNameOfNode=_e,e.sym=gt,e.privateSet=lt,e.cloneElement=tt,e.spyMethod=Xe;var I=bBe;Object.defineProperty(e,"shallowEqual",{enumerable:!0,get:function(){function F(){return W(I).default}return F}()}),e.isEmptyValue=ae,e.renderedDive=ye,e.loadCheerioRoot=He;var n=M0,r=W(n),C=lN,o=W(C),a=d4,s=W(a),A=SBe,l=W(A),c=m4,u=W(c),d=P0,h=W(d),m=ew,f=W(m),b=rBe,p=W(b),y=YBe,Z=W(y),B=su,G=sm,v=DI,w=cu,R=W(w),S=mk,X=W(S);function W(F){return F&&F.__esModule?F:{default:F}}function V(F,T,k){return T in F?Object.defineProperty(F,T,{value:k,enumerable:!0,configurable:!0,writable:!0}):F[T]=k,F}function H(F,T){var k={};for(var ie in F)T.indexOf(ie)>=0||Object.prototype.hasOwnProperty.call(F,ie)&&(k[ie]=F[ie]);return k}e.ITERATOR_SYMBOL=typeof Symbol=="function"&&Symbol.iterator;function Y(){var F=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return console.warn("getAdapter from Utils is deprecated; please use ./getAdapter instead"),(0,R.default)(F)}function K(F,T){if(F&&T&&F!==T)throw new TypeError("If both the `attachTo` and `hydrateIn` options are provided, they must be === (for backwards compatibility)")}function x(F){var T=(0,G.get)(),k=T.attachTo,ie=T.hydrateIn,me=H(T,["attachTo","hydrateIn"]);K(k,ie);var Ve=F.attachTo,we=F.hydrateIn;K(Ve,we);var je=we||ie||k||Ve||void 0,at=we||ie||void 0,bt=(0,r.default)({},je&&{attachTo:je},at&&{hydrateIn:at});return(0,r.default)({},me,F,bt)}function J(F,T){return(0,X.default)(T),T.isCustomComponent?!!T.isCustomComponent(F):typeof F=="function"}function P(F,T){return T.isCustomComponentElement?!!T.isCustomComponentElement(F):!!F&&T.isValidElement(F)&&typeof F.type=="function"}function ge(F){return(0,l.default)(F&&F.props||{}).filter(function(T){var k=i(T,2),ie=k[1];return typeof ie<"u"}).reduce(function(T,k){var ie=i(k,2),me=ie[0],Ve=ie[1];return(0,r.default)(T,V({},me,Ve))},{})}function q(F){return F?F.type:null}function $(F,T){if(!T||!F)return!1;var k=(0,R.default)();if(k.displayNameOfNode){var ie=k.displayNameOfNode(F);return ie===T}return F.type?typeof F.type=="string"?F.type===T:(typeof F.type=="function"?(0,u.default)(F.type)===T:F.type.name===T)||F.type.displayName===T:!1}function j(F,T,k,ie){var me=ie?ne:be;if(F===T)return!0;if(!Array.isArray(F)&&!Array.isArray(T))return me(F,T,k);var Ve=(0,f.default)(F,1/0),we=(0,f.default)(T,1/0);if(Ve.length!==we.length)return!1;if(Ve.length===0&&we.length===0)return!0;for(var je=0;je2&&arguments[2]!==void 0?arguments[2]:s.default;return he(F,T,k,!0)}function be(F,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:s.default;return he(F,T,k,!1)}function pe(F,T,k){var ie=(0,v.childrenOfNode)(T),me=function(we,je){return ve(F,ie.slice(je,je+k.length),k)};return ie.some(me)}function ve(F,T,k){return T.length===k.length&&T.every(function(ie,me){return F(ie,k[me])})}function We(F){var T=[],k=function(me){me===null||me===!1||typeof me>"u"||T.push(me)};return Array.isArray(F)?F.forEach(k):k(F),T}function Be(F){for(var T=arguments.length>1&&arguments[1]!==void 0?arguments[1]:!1,k=We(F),ie=[],me=0;me"u"?ie.push(Ve):Je(Ve)&&Je(we)?ie.push(we+Ve):(ie.push(we),ie.push(Ve))}return T?ie.map(function(je){return typeof je=="string"?(0,p.default)(je):je}):ie}function Je(F){return typeof F=="string"||typeof F=="number"}function Pe(F,T){return T.isValidElement(F)||Je(F)||Array.isArray(F)}function De(F){var T=!1;typeof globalThis.document>"u"&&(T=!0,globalThis.document={}),F(),T&&(globalThis.document=void 0,delete globalThis.document)}function Qe(F){var T=F.slice().reverse();return function(k){return T.every(function(ie){return ie(k)})}}function _e(F){if(!F)return null;var T=F.type;return T?T.displayName||(typeof T=="function"?(0,u.default)(T):T.name||T):null}function gt(F){return typeof Symbol=="function"?Symbol.for("enzyme."+String(F)):F}function lt(F,T,k){Object.defineProperty(F,T,{value:k,enumerable:!1,writable:!0})}function tt(F,T,k){return F.createElement(T.type,(0,r.default)({},T.props,k))}function Xe(F,T){var k=arguments.length>2&&arguments[2]!==void 0?arguments[2]:function(){},ie=void 0,me=F[T],Ve=(0,h.default)(F,T),we=void 0;return Ve&&(we=Object.getOwnPropertyDescriptor(F,T)),Object.defineProperty(F,T,{configurable:!0,enumerable:!we||!!we.enumerable,value:k(me)||function(){function je(){for(var at=arguments.length,bt=Array(at),ct=0;ct"'`]/g,mSt=RegExp(gRe.source),fSt={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},pSt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,bSt=typeof self=="object"&&self&&self.Object===Object&&self,ySt=pSt||bSt||Function("return this")();function ZSt(e){return function(g){return e==null?void 0:e[g]}}var GSt=ZSt(fSt),vSt=Object.prototype,BSt=vSt.toString,kre=ySt.Symbol,Yre=kre?kre.prototype:void 0,Kre=Yre?Yre.toString:void 0;function SSt(e){if(typeof e=="string")return e;if(RSt(e))return Kre?Kre.call(e):"";var g=e+"";return g=="0"&&1/e==-dSt?"-0":g}function wSt(e){return!!e&&typeof e=="object"}function RSt(e){return typeof e=="symbol"||wSt(e)&&BSt.call(e)==hSt}function VSt(e){return e==null?"":SSt(e)}function WSt(e){return e=VSt(e),e&&mSt.test(e)?e.replace(gRe,GSt):e}var XSt=WSt,HSt=String.prototype.valueOf,TSt=function(g){try{return HSt.call(g),!0}catch{return!1}},NSt=Object.prototype.toString,kSt="[object String]",YSt=qS(),iRe=function(g){return typeof g=="string"?!0:typeof g!="object"?!1:YSt?TSt(g):NSt.call(g)===kSt},KSt=Number.prototype.toString,FSt=function(g){try{return KSt.call(g),!0}catch{return!1}},DSt=Object.prototype.toString,xSt="[object Number]",ESt=qS(),MSt=function(g){return typeof g=="number"?!0:typeof g!="object"?!1:ESt?FSt(g):DSt.call(g)===xSt},IRe=hr,zSt=IRe("Boolean.prototype.toString"),PSt=IRe("Object.prototype.toString"),JSt=function(g){try{return zSt(g),!0}catch{return!1}},OSt="[object Boolean]",_St=qS(),LSt=function(g){return typeof g=="boolean"?!0:g===null||typeof g!="object"?!1:_St&&Symbol.toStringTag in g?JSt(g):PSt(g)===OSt};Object.defineProperty(uu,"__esModule",{value:!0});var Fre=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};uu.typeName=CRe;uu.spaces=oRe;uu.indent=aRe;uu.debugNode=J4;uu.debugNodes=uwt;var USt=XSt,QSt=Cl(USt),jSt=m4,nRe=Cl(jSt),$St=iRe,qSt=Cl($St),ewt=MSt,twt=Cl(ewt),gwt=l4,iwt=Cl(gwt),Iwt=LSt,nwt=Cl(Iwt),rwt=Hve,pf=Cl(rwt),Cwt=P0,Lm=Cl(Cwt),rRe=DI,owt=cu,jz=Cl(owt);function Cl(e){return e&&e.__esModule?e:{default:e}}var awt=Function.bind.call(Function.call,Boolean.prototype.valueOf);function CRe(e){var g=(0,jz.default)();return g.displayNameOfNode?(0,jz.default)().displayNameOfNode(e)||"Component":typeof e.type=="function"?e.type.displayName||(0,nRe.default)(e.type)||"Component":e.type}function oRe(e){return Array(e+1).join(" ")}function aRe(e,g){return g.split(` +`).map(function(i){return""+String(oRe(e))+String(i)}).join(` +`)}function Awt(e,g){return(0,qSt.default)(e)?(0,pf.default)(String(e),{quoteStyle:"double"}):(0,twt.default)(e)?"{"+String((0,pf.default)(Number(e)))+"}":(0,nwt.default)(e)?"{"+String((0,pf.default)(awt(e)))+"}":(0,iwt.default)(e)?"{"+String((0,pf.default)(e))+"}":(typeof e>"u"?"undefined":Fre(e))==="object"?g.verbose?"{"+String((0,pf.default)(e))+"}":"{{...}}":"{["+(typeof e>"u"?"undefined":Fre(e))+"]}"}function swt(e,g){var i=(0,rRe.propsOfNode)(e),I=Object.keys(i).filter(function(n){return n!=="children"});return I.map(function(n){return String(n)+"="+String(Awt(i[n],g))}).join(" ")}function lwt(e,g){return e.length?` +`+String(e.map(function(i){return aRe(g,i)}).join(` `))+` -`:""}function Cwt(e){return(0,Um.default)(e,"nodeType")&&typeof e.nodeType=="string"&&(0,Um.default)(e,"type")&&(0,Um.default)(e,"key")&&(0,Um.default)(e,"ref")&&(0,Um.default)(e,"instance")&&(0,Um.default)(e,"rendered")}function Dj(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,zSt.default)(e);if(typeof e=="function"){var i=(0,jwe.default)(e);return"[function"+(i?" "+String(i):"")+"]"}if(!e)return"";var n=(0,Oz.default)();if(!n.isValidElement(e)&&!Cwt(e))return"{"+String((0,bf.default)(e))+"}";var C=(0,$we.childrenOfNode)(e).map(function(c){return Dj(c,g,I)}).filter(Boolean),r=qwe(e),o=I.ignoreProps?"":iwt(e,I),a=o?" ":"",s=C.length?">":" ",A=nwt(C,g),l=C.length?"":"/>";return"<"+String(r)+a+String(o)+s+String(A)+l}function rwt(e){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return e.map(function(I){return Dj(I,void 0,g)}).join(` +`:""}function cwt(e){return(0,Lm.default)(e,"nodeType")&&typeof e.nodeType=="string"&&(0,Lm.default)(e,"type")&&(0,Lm.default)(e,"key")&&(0,Lm.default)(e,"ref")&&(0,Lm.default)(e,"instance")&&(0,Lm.default)(e,"rendered")}function J4(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,QSt.default)(e);if(typeof e=="function"){var I=(0,nRe.default)(e);return"[function"+(I?" "+String(I):"")+"]"}if(!e)return"";var n=(0,jz.default)();if(!n.isValidElement(e)&&!cwt(e))return"{"+String((0,pf.default)(e))+"}";var r=(0,rRe.childrenOfNode)(e).map(function(c){return J4(c,g,i)}).filter(Boolean),C=CRe(e),o=i.ignoreProps?"":swt(e,i),a=o?" ":"",s=r.length?">":" ",A=lwt(r,g),l=r.length?"":"/>";return"<"+String(C)+a+String(o)+s+String(A)+l}function uwt(e){var g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return e.map(function(i){return J4(i,void 0,g)}).join(` -`)}var j0={},jb={},Fj={};Object.defineProperty(Fj,"__esModule",{value:!0});var TCe=function(g){return JSON.stringify(g)},owt=function(g){var I=g.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+TCe(s.value)+"]";else if(s.type==="pseudoClassSelector")A=":"+s.name,s.parameters.length&&(A+="("+s.parameters.map(TCe).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("")};Fj.default=function(){var e=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(owt(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:e}};var Ej={},gVe={exports:{}};(function(e){(function(g,I){e.exports?e.exports=I():g.nearley=I()})($e,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;u ");else if(s.type==="adjacentSiblingCombinator")I.push(" + ");else if(s.type==="generalSiblingCombinator")I.push(" ~ ");else throw new Error("Unknown token.")}}catch(A){r=!0,C=A}finally{try{!n&&o.return&&o.return()}finally{if(r)throw C}}return I.join("")};return{generate:e}};var _4={},ARe={exports:{}};(function(e){(function(g,i){e.exports?e.exports=i():g.nearley=i()})($e,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,C.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:g}})})(gVe);var awt=gVe.exports,IVe={exports:{}},Awt=1/0,swt=9007199254740991,lwt="[object Arguments]",cwt="[object Function]",uwt="[object GeneratorFunction]",dwt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,hwt=typeof self=="object"&&self&&self.Object===Object&&self,mwt=dwt||hwt||Function("return this")();function fwt(e,g){for(var I=-1,i=g.length,n=e.length;++I0&&I(o)?g>1?nVe(o,g-1,I,i,n):fwt(n,o):i||(n[n.length]=o)}return n}function ywt(e){return vwt(e)||Gwt(e)||!!(kCe&&e&&e[kCe])}function Zwt(e){var g=e?e.length:0;return g?nVe(e,Awt):[]}function Gwt(e){return Swt(e)&&pwt.call(e,"callee")&&(!bwt.call(e,"callee")||iVe.call(e)==lwt)}var vwt=Array.isArray;function Bwt(e){return e!=null&&Vwt(e.length)&&!wwt(e)}function Swt(e){return Wwt(e)&&Bwt(e)}function wwt(e){var g=Rwt(e)?iVe.call(e):"";return g==cwt||g==uwt}function Vwt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=swt}function Rwt(e){var g=typeof e;return!!e&&(g=="object"||g=="function")}function Wwt(e){return!!e&&typeof e=="object"}var Xwt=Zwt;(function(e){(function(){function g(l){return l[0]}var I=Xwt,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})()})(IVe);var Hwt=IVe.exports;Object.defineProperty(Ej,"__esModule",{value:!0});var Twt=awt,Nwt=Hwt,YCe=kwt(Nwt);function kwt(e){return e&&e.__esModule?e:{default:e}}Ej.default=function(){var e=function(I){var i=new Twt.Parser(YCe.default.ParserRules,YCe.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(jb,"__esModule",{value:!0});jb.createParser=jb.createGenerator=void 0;var Ywt=Fj,Kwt=CVe(Ywt),xwt=Ej,Dwt=CVe(xwt);function CVe(e){return e&&e.__esModule?e:{default:e}}jb.createGenerator=Kwt.default;jb.createParser=Dwt.default;var Fwt=M0,rVe=mC,Ewt=rVe("Object.prototype.propertyIsEnumerable"),Mwt=rVe("Array.prototype.push"),oVe=function(g){var I=Fwt(g),i=[];for(var n in I)Ewt(I,n)&&Mwt(i,I[n]);return i},zwt=oVe,aVe=function(){return typeof Object.values=="function"?Object.values:zwt},Pwt=aVe,Jwt=Mn,Owt=function(){var g=Pwt();return Jwt(Object,{values:g},{values:function(){return Object.values!==g}}),g},_wt=Mn,Lwt=il,Uwt=oVe,AVe=aVe,Qwt=Owt,sVe=Lwt(AVe(),Object);_wt(sVe,{getPolyfill:AVe,implementation:Uwt,shim:Qwt});var jwt=sVe,$wt=Yve,qwt=xve(),eVt=Fve(),tVt=US,gVt=Eve(),IVt=rj,iVt=gBe(),nVt=Hve,CVt=IBe,KCe=oj,rVt=mC,oVt=Uwe,xCe=Object("a"),aVt=xCe[0]!=="a"||!(0 in xCe),AVt=rVt("String.prototype.split"),lVe=function(g){var I=CVt(this),i=aVt&&oVt(I)?AVt(I,""):I,n=iVt(i);if(!IVt(g))throw new TypeError("Array.prototype.filter callback must be a function");var C;arguments.length>1&&(C=arguments[1]);for(var r=$wt(I,0),o=0,a=0;o"u")return!1;if(g.type===bVe)return(0,EVt.default)(C,g.name);if((typeof o!="string"||typeof i!="string")&&I!==FCe)return!1;switch(I){case FCe:return(0,DVt.default)(o,i);case iRt:return o.split(" ").indexOf(i)!==-1;case nRt:return o===i||o.startsWith(String(i)+"-");case CRt:return i===""?!1:o.slice(0,i.length)===i;case rRt:return i===""?!1:o.slice(-i.length)===i;case oRt:return i===""?!1:o.indexOf(i)!==-1;default:throw new Error('Enzyme::Selector: Unknown attribute selector operator "'+String(I)+'"')}}function aRt(e,g,I){var i=g.name,n=g.parameters;if(i==="not")return n.every(function(c){return hk(c,e).length===0});if(i==="empty")return(0,AC.treeFilter)(e,function(c){return c!==e}).length===0;if(i==="first-child"){var C=(0,AC.findParentNode)(I,e),r=C.rendered,o=TVt(r,1),a=o[0];return a===e}if(i==="last-child"){var s=(0,AC.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,fVe.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 ARt(e,g,I){if(e===null||typeof e=="string")return!1;switch(g.type){case eRt:return!0;case $Vt:return(0,AC.hasClassName)(e,g.name);case jVt:return(0,mVe.nodeHasType)(e,g.name);case qVt:return(0,AC.nodeHasId)(e,g.name);case bVe:return ECe(e,g);case tRt:return ECe(e,g);case IRt:case gRt:return aRt(e,g,I);default:throw new Error("Unknown token type: "+String(g.type))}}function _z(e,g){return function(I){return e.body.every(function(i){return ARt(I,i,g)})}}function sRt(e){return e.some(function(g){return g.type!==pVe})}function GVe(e){if(typeof e=="string"){var g=ZVe(e);if(sRt(g))throw new TypeError("This method does not support complex CSS selectors");return _z(g[0])}var I=(0,fVe.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":hVe(e))==="object"){if(!Array.isArray(e)&&e!==null&&Object.keys(e).length>0){var n=(0,YVt.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,AC.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 lRt(e,g,I){return e.reduce(function(i,n){var C=(0,AC.findParentNode)(I,n);if(!C)return i;var r=(0,AC.childrenOfNode)(C),o=r.indexOf(n),a=r[o+1];return a&&g(a)&&i.push(a),i},[])}function cRt(e,g,I){return Pj(function(i,n){var C=(0,AC.findParentNode)(I,n);if(!C)return i;var r=(0,AC.childrenOfNode)(C),o=r.indexOf(n),a=r.slice(o+1);return i.concat(a.filter(g))},e)}function uRt(e,g){return Pj(function(I,i){return I.concat((0,AC.childrenOfNode)(i).filter(g))},e)}function dRt(e,g){return Pj(function(I,i){return I.concat((0,AC.treeFilter)(i,g))},(0,zj.default)(e.map(AC.childrenOfNode)))}function hk(e,g){if(typeof e!="string"){var I=(0,zVt.default)(e);if(I.length>0)return(0,zj.default)(I.map(function(A){return hk(A.tag,g)}))}if(typeof e=="function"||(typeof e>"u"?"undefined":hVe(e))==="object")return(0,AC.treeFilter)(g,GVe(e));var i=[];if(typeof e=="string")for(var n=ZVe(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 K(q,$){return(0,u.parentsOfNode)($,Y(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 J=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 Q=(0,s.makeOptions)(te);if(j)(0,s.privateSet)(this,B,j[B]),(0,s.privateSet)(this,v,j),F(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)(Q);if(!ie.isValidElement($))throw new TypeError("ReactWrapper can only wrap valid elements");var he=ie.createRenderer((0,n.default)({mode:"mount"},Q));if((0,s.privateSet)(this,B,he),he.render($,Q.context),(0,s.privateSet)(this,v,this),F(this,this[B].getNode()),(0,s.privateSet)(this,w,Q),(0,s.privateSet)(this,X,[]),(0,s.isCustomComponent)(Q.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 P(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():(F(this,this[B].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[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,Q=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 Q!="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(),Q&&Q()}),this}return $}()},{key:"setState",value:function(){function $(j){var te=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(te.update(),Q){var ie=(0,l.default)(te[w]),he=te.instance();ie.invokeSetStateCallback?ie.invokeSetStateCallback(he,Q):Q.call(he)}}),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]),Q=Array.isArray(j)?function(ie){return(0,s.containsChildrenSubArray)(s.nodeEqual,ie,j.map(function(he){return te.elementToNode(he)}))}:function(ie){return(0,s.nodeEqual)(te.elementToNode(j),ie)};return R(this,Q).length>0}return $}()},{key:"containsMatchingElement",value:function(){function $(j){var te=(0,l.default)(this[w]).elementToNode(j),Q=function(){function ie(he){return(0,s.nodeMatches)(te,he,function(ne,be){return ne<=be})}return ie}();return R(this,Q).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(Q){return te.containsMatchingElement(Q)})}return $}()},{key:"containsAnyMatchingElements",value:function(){function $(j){var te=this;return Array.isArray(j)&&j.some(function(Q){return te.containsMatchingElement(Q)})}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 Q=(0,l.default)(te[w]),ie=Q.elementToNode(j);return(0,s.nodeMatches)(ie,te.getNodeInternal(),function(he,ne){return he<=ne})})}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(Q){return te(Q)})}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(Q){return j(te.wrap(Q))})}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(Q){return!te(Q)})}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,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.single("simulate",function(ie){return te[B].simulateEvent(ie,j,Q),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(Q){if(Q.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 he=Y(te),ne=[Q].concat(K(te,Q));return ie.simulateError(ne,he,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,Q=this[v]===this?this[B].getNode():this.getNodeInternal();if(this.instance()===null||Q.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 Q=this.single("context",function(){return te.instance()});if(Q===null)throw new Error("ReactWrapper::context() can only be called on components with instances");var ie=Q.context;return typeof j<"u"?ie[j]:ie}return $}()},{key:"children",value:function(){function $(j){var te=this.flatMap(function(Q){return(0,u.childrenOfNode)(Q.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(Q){var ie=te.wrap(K(te,Q));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 Q=te.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 ie=arguments.length,he=Array(ie),ne=0;ne"u"?"undefined":g(ne))+"“");return function(){var be=ne.apply(void 0,arguments),pe=Q.wrap(be);return te.wrap(pe,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(Q,ie){return j.call(te,te.wrap(Q),ie)}),this}return $}()},{key:"map",value:function(){function $(j){var te=this;return this.getNodesInternal().map(function(Q,ie){return j.call(te,te.wrap(Q),ie)})}return $}()},{key:"reduce",value:function(){function $(j){var te=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(ie,he,ne){return j.call(te,ie,te.wrap(he),ne)},Q):this.getNodesInternal().reduce(function(ie,he,ne){return j.call(te,ne===1?te.wrap(ie):ie,te.wrap(he),ne)})}return $}()},{key:"reduceRight",value:function(){function $(j){var te=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(ie,he,ne){return j.call(te,ie,te.wrap(he),ne)},Q):this.getNodesInternal().reduceRight(function(ie,he,ne){return j.call(te,ne===1?te.wrap(ie):ie,te.wrap(he),ne)})}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(Q,ie){return j.call(te,te.wrap(Q),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(Q,ie){return j.call(te,te.wrap(Q),ie)})}return $}()},{key:"flatMap",value:function(){function $(j){var te=this,Q=this.getNodesInternal().map(function(he,ne){return j.call(te,te.wrap(he),ne)}),ie=(0,r.default)(Q,1);return this.wrap(ie.filter(Boolean))}return $}()},{key:"findWhere",value:function(){function $(j){var te=this;return R(this,function(Q){var ie=te.wrap(Q);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 Q=typeof j=="string"?j:"unknown",ie=typeof te=="function"?te:j;if(this.length!==1)throw new Error("Method “"+Q+"” 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 Q=arguments.length,ie=Array(Q>2?Q-2:0),he=2;he0&&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}(),P=function(q){b($,q);function $(j,te){p(this,$);var Q=f(this,($.__proto__||Object.getPrototypeOf($)).call(this,te.getNode(),j));return(0,s.privateSet)(Q,v,Q),(0,s.privateSet)(Q,B,te),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}()}]),$}(J);s.ITERATOR_SYMBOL&&Object.defineProperty(J.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 Q(){var ie=j.next();return ie.done?{done:!0}:{done:!1,value:te.nodeToElement(ie.value)}}return Q}()),$}return q}()});function ge(q,$){Object.defineProperty(J.prototype,q,{get:function(){function j(){throw new Error(` +`)},C.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}},C.prototype.getSymbolDisplay=function(s){return o(s)},C.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)},C.prototype.save=function(){var s=this.table[this.current];return s.lexerState=this.lexerState,s},C.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()},C.prototype.rewind=function(s){if(!this.options.keepHistory)throw new Error("set option `keepHistory` to enable rewinding");this.restore(this.table[s])},C.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!==C.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:C,Grammar:n,Rule:g}})})(ARe);var hwt=ARe.exports,sRe={exports:{}},mwt=1/0,fwt=9007199254740991,pwt="[object Arguments]",bwt="[object Function]",ywt="[object GeneratorFunction]",Zwt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis,Gwt=typeof self=="object"&&self&&self.Object===Object&&self,vwt=Zwt||Gwt||Function("return this")();function Bwt(e,g){for(var i=-1,I=g.length,n=e.length;++i0&&i(o)?g>1?cRe(o,g-1,i,I,n):Bwt(n,o):I||(n[n.length]=o)}return n}function Rwt(e){return Xwt(e)||Wwt(e)||!!(Ere&&e&&e[Ere])}function Vwt(e){var g=e?e.length:0;return g?cRe(e,mwt):[]}function Wwt(e){return Twt(e)&&Swt.call(e,"callee")&&(!wwt.call(e,"callee")||lRe.call(e)==pwt)}var Xwt=Array.isArray;function Hwt(e){return e!=null&&kwt(e.length)&&!Nwt(e)}function Twt(e){return Kwt(e)&&Hwt(e)}function Nwt(e){var g=Ywt(e)?lRe.call(e):"";return g==bwt||g==ywt}function kwt(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=fwt}function Ywt(e){var g=typeof e;return!!e&&(g=="object"||g=="function")}function Kwt(e){return!!e&&typeof e=="object"}var Fwt=Vwt;(function(e){(function(){function g(l){return l[0]}var i=Fwt,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)},r={" ":"descendantCombinator","+":"adjacentSiblingCombinator",">":"childCombinator","~":"generalSiblingCombinator"},C=function(c){return(Array.isArray(c[0])?c[0]:[c[0]]).concat({type:r[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:C},{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})()})(sRe);var Dwt=sRe.exports;Object.defineProperty(_4,"__esModule",{value:!0});var xwt=hwt,Ewt=Dwt,Mre=Mwt(Ewt);function Mwt(e){return e&&e.__esModule?e:{default:e}}_4.default=function(){var e=function(i){var I=new xwt.Parser(Mre.default.ParserRules,Mre.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($b,"__esModule",{value:!0});$b.createParser=$b.createGenerator=void 0;var zwt=O4,Pwt=uRe(zwt),Jwt=_4,Owt=uRe(Jwt);function uRe(e){return e&&e.__esModule?e:{default:e}}$b.createGenerator=Pwt.default;$b.createParser=Owt.default;var _wt=z0,dRe=hr,Lwt=dRe("Object.prototype.propertyIsEnumerable"),Uwt=dRe("Array.prototype.push"),hRe=function(g){var i=_wt(g),I=[];for(var n in i)Lwt(i,n)&&Uwt(I,i[n]);return I},Qwt=hRe,mRe=function(){return typeof Object.values=="function"?Object.values:Qwt},jwt=mRe,$wt=Mn,qwt=function(){var g=jwt();return $wt(Object,{values:g},{values:function(){return Object.values!==g}}),g},eRt=Mn,tRt=Il,gRt=hRe,fRe=mRe,iRt=qwt,pRe=tRt(fRe(),Object);eRt(pRe,{getPolyfill:fRe,implementation:gRt,shim:iRt});var IRt=pRe,nRt=Pve,rRt=Ove(),CRt=Lve(),oRt=$S,aRt=Uve(),ARt=c4,sRt=ABe(),lRt=xve,cRt=sBe,zre=u4,uRt=hr,dRt=iRe,Pre=Object("a"),hRt=Pre[0]!=="a"||!(0 in Pre),mRt=uRt("String.prototype.split"),bRe=function(g){var i=cRt(this),I=hRt&&dRt(i)?mRt(i,""):i,n=sRt(I);if(!ARt(g))throw new TypeError("Array.prototype.filter callback must be a function");var r;arguments.length>1&&(r=arguments[1]);for(var C=nRt(i,0),o=0,a=0;o"u")return!1;if(g.type===RRe)return(0,LRt.default)(r,g.name);if((typeof o!="string"||typeof I!="string")&&i!==Ore)return!1;switch(i){case Ore:return(0,ORt.default)(o,I);case sVt:return o.split(" ").indexOf(I)!==-1;case lVt:return o===I||o.startsWith(String(I)+"-");case cVt:return I===""?!1:o.slice(0,I.length)===I;case uVt:return I===""?!1:o.slice(-I.length)===I;case dVt:return I===""?!1:o.indexOf(I)!==-1;default:throw new Error('Enzyme::Selector: Unknown attribute selector operator "'+String(i)+'"')}}function hVt(e,g,i){var I=g.name,n=g.parameters;if(I==="not")return n.every(function(c){return pk(c,e).length===0});if(I==="empty")return(0,ar.treeFilter)(e,function(c){return c!==e}).length===0;if(I==="first-child"){var r=(0,ar.findParentNode)(i,e),C=r.rendered,o=xRt(C,1),a=o[0];return a===e}if(I==="last-child"){var s=(0,ar.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,SRe.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 mVt(e,g,i){if(e===null||typeof e=="string")return!1;switch(g.type){case CVt:return!0;case nVt:return(0,ar.hasClassName)(e,g.name);case IVt:return(0,BRe.nodeHasType)(e,g.name);case rVt:return(0,ar.nodeHasId)(e,g.name);case RRe:return _re(e,g);case oVt:return _re(e,g);case AVt:case aVt:return hVt(e,g,i);default:throw new Error("Unknown token type: "+String(g.type))}}function $z(e,g){return function(i){return e.body.every(function(I){return mVt(i,I,g)})}}function fVt(e){return e.some(function(g){return g.type!==wRe})}function XRe(e){if(typeof e=="string"){var g=WRe(e);if(fVt(g))throw new TypeError("This method does not support complex CSS selectors");return $z(g[0])}var i=(0,SRe.default)(),I=i.isValidElementType?i.isValidElementType(e):typeof e=="function";if(I)return function(r){return i.matchesElementType(r,e)};if((typeof e>"u"?"undefined":vRe(e))==="object"){if(!Array.isArray(e)&&e!==null&&Object.keys(e).length>0){var n=(0,zRt.default)(e).some(function(r){return typeof r>"u"});if(n)throw new TypeError("Enzyme::Props can’t have `undefined` values. Try using ‘findWhere()’ instead.");return function(r){return(0,ar.nodeMatchesObjectProps)(r,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 pVt(e,g,i){return e.reduce(function(I,n){var r=(0,ar.findParentNode)(i,n);if(!r)return I;var C=(0,ar.childrenOfNode)(r),o=C.indexOf(n),a=C[o+1];return a&&g(a)&&I.push(a),I},[])}function bVt(e,g,i){return Q4(function(I,n){var r=(0,ar.findParentNode)(i,n);if(!r)return I;var C=(0,ar.childrenOfNode)(r),o=C.indexOf(n),a=C.slice(o+1);return I.concat(a.filter(g))},e)}function yVt(e,g){return Q4(function(i,I){return i.concat((0,ar.childrenOfNode)(I).filter(g))},e)}function ZVt(e,g){return Q4(function(i,I){return i.concat((0,ar.treeFilter)(I,g))},(0,U4.default)(e.map(ar.childrenOfNode)))}function pk(e,g){if(typeof e!="string"){var i=(0,QRt.default)(e);if(i.length>0)return(0,U4.default)(i.map(function(A){return pk(A.tag,g)}))}if(typeof e=="function"||(typeof e>"u"?"undefined":vRe(e))==="object")return(0,ar.treeFilter)(g,XRe(e));var I=[];if(typeof e=="string")for(var n=WRe(e),r=0;r2&&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[R][0]:q[v][y]}function K(q,$){return(0,u.parentsOfNode)($,Y(q))}function x(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 J=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 Q=(0,s.makeOptions)(te);if(j)(0,s.privateSet)(this,B,j[B]),(0,s.privateSet)(this,v,j),x(this,$),(0,s.privateSet)(this,R,j[Z]),(0,s.privateSet)(this,w,j[w]),(0,s.privateSet)(this,X,[]);else{var Ie=(0,l.default)(Q);if(!Ie.isValidElement($))throw new TypeError("ReactWrapper can only wrap valid elements");var he=Ie.createRenderer((0,n.default)({mode:"mount"},Q));if((0,s.privateSet)(this,B,he),he.render($,Q.context),(0,s.privateSet)(this,v,this),x(this,this[B].getNode()),(0,s.privateSet)(this,w,Q),(0,s.privateSet)(this,X,[]),(0,s.isCustomComponent)(Q.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 P(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():(x(this,this[B].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[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,Q=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 Q!="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(),Q&&Q()}),this}return $}()},{key:"setState",value:function(){function $(j){var te=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(te.update(),Q){var Ie=(0,l.default)(te[w]),he=te.instance();Ie.invokeSetStateCallback?Ie.invokeSetStateCallback(he,Q):Q.call(he)}}),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]),Q=Array.isArray(j)?function(Ie){return(0,s.containsChildrenSubArray)(s.nodeEqual,Ie,j.map(function(he){return te.elementToNode(he)}))}:function(Ie){return(0,s.nodeEqual)(te.elementToNode(j),Ie)};return V(this,Q).length>0}return $}()},{key:"containsMatchingElement",value:function(){function $(j){var te=(0,l.default)(this[w]).elementToNode(j),Q=function(){function Ie(he){return(0,s.nodeMatches)(te,he,function(ne,be){return ne<=be})}return Ie}();return V(this,Q).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(Q){return te.containsMatchingElement(Q)})}return $}()},{key:"containsAnyMatchingElements",value:function(){function $(j){var te=this;return Array.isArray(j)&&j.some(function(Q){return te.containsMatchingElement(Q)})}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 Q=(0,l.default)(te[w]),Ie=Q.elementToNode(j);return(0,s.nodeMatches)(Ie,te.getNodeInternal(),function(he,ne){return he<=ne})})}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(Q){return te(Q)})}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(Q){return j(te.wrap(Q))})}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(Q){return!te(Q)})}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,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};return this.single("simulate",function(Ie){return te[B].simulateEvent(Ie,j,Q),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(Q){if(Q.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 he=Y(te),ne=[Q].concat(K(te,Q));return Ie.simulateError(ne,he,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,Q=this[v]===this?this[B].getNode():this.getNodeInternal();if(this.instance()===null||Q.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 Q=this.single("context",function(){return te.instance()});if(Q===null)throw new Error("ReactWrapper::context() can only be called on components with instances");var Ie=Q.context;return typeof j<"u"?Ie[j]:Ie}return $}()},{key:"children",value:function(){function $(j){var te=this.flatMap(function(Q){return(0,u.childrenOfNode)(Q.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(Q){var Ie=te.wrap(K(te,Q));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 Q=te.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 Ie=arguments.length,he=Array(Ie),ne=0;ne"u"?"undefined":g(ne))+"“");return function(){var be=ne.apply(void 0,arguments),pe=Q.wrap(be);return te.wrap(pe,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(Q,Ie){return j.call(te,te.wrap(Q),Ie)}),this}return $}()},{key:"map",value:function(){function $(j){var te=this;return this.getNodesInternal().map(function(Q,Ie){return j.call(te,te.wrap(Q),Ie)})}return $}()},{key:"reduce",value:function(){function $(j){var te=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(Ie,he,ne){return j.call(te,Ie,te.wrap(he),ne)},Q):this.getNodesInternal().reduce(function(Ie,he,ne){return j.call(te,ne===1?te.wrap(Ie):Ie,te.wrap(he),ne)})}return $}()},{key:"reduceRight",value:function(){function $(j){var te=this,Q=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(Ie,he,ne){return j.call(te,Ie,te.wrap(he),ne)},Q):this.getNodesInternal().reduceRight(function(Ie,he,ne){return j.call(te,ne===1?te.wrap(Ie):Ie,te.wrap(he),ne)})}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(Q,Ie){return j.call(te,te.wrap(Q),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(Q,Ie){return j.call(te,te.wrap(Q),Ie)})}return $}()},{key:"flatMap",value:function(){function $(j){var te=this,Q=this.getNodesInternal().map(function(he,ne){return j.call(te,te.wrap(he),ne)}),Ie=(0,C.default)(Q,1);return this.wrap(Ie.filter(Boolean))}return $}()},{key:"findWhere",value:function(){function $(j){var te=this;return V(this,function(Q){var Ie=te.wrap(Q);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 Q=typeof j=="string"?j:"unknown",Ie=typeof te=="function"?te:j;if(this.length!==1)throw new Error("Method “"+Q+"” 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 Q=arguments.length,Ie=Array(Q>2?Q-2:0),he=2;he0&&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}(),P=function(q){b($,q);function $(j,te){p(this,$);var Q=f(this,($.__proto__||Object.getPrototypeOf($)).call(this,te.getNode(),j));return(0,s.privateSet)(Q,v,Q),(0,s.privateSet)(Q,B,te),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}()}]),$}(J);s.ITERATOR_SYMBOL&&Object.defineProperty(J.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 Q(){var Ie=j.next();return Ie.done?{done:!0}:{done:!1,value:te.nodeToElement(Ie.value)}}return Q}()),$}return q}()});function ge(q,$){Object.defineProperty(J.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})}ge("node","Consider using the getElement() method instead."),ge("nodes","Consider using the getElements() method instead."),ge("renderer",""),ge("options",""),ge("complexSelector",""),e.default=J})(LQ);var Jj={};(function(e){Object.defineProperty(e,"__esModule",{value:!0});var g=function(){function Xe(ae,ye,He){ae===null&&(ae=Function.prototype);var x=Object.getOwnPropertyDescriptor(ae,ye);if(x===void 0){var T=Object.getPrototypeOf(ae);return T===null?void 0:Xe(T,ye,He)}else{if("value"in x)return x.value;var k=x.get;return k===void 0?void 0:k.call(He)}}return Xe}(),I=function(){function Xe(ae,ye){for(var He=0;He2&&arguments[2]!==void 0?arguments[2]:m.treeFilter;return Xe.flatMap(function(He){return ye(He.getNodeInternal(),ae)})}function q(Xe,ae){return Xe.wrap(Xe.getNodesInternal().filter(ae).filter(Boolean))}function $(Xe){var ae=Xe.lifecycleExperimental,ye=Xe.disableLifecycleMethods,He=Xe.enableComponentDidUpdateOnSetState,x=Xe.supportPrevContextArgumentOfComponentDidUpdate,T=Xe.lifecycles;if(typeof ae<"u"&&typeof ae!="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(ae!=null&&ye!=null&&ae===ye)throw new Error("lifecycleExperimental and disableLifecycleMethods cannot be set to the same value");if(typeof He<"u"&&T.componentDidUpdate&&T.componentDidUpdate.onSetState!==He)throw new TypeError("the legacy enableComponentDidUpdateOnSetState option should be matched by `lifecycles: { componentDidUpdate: { onSetState: true } }`, for compatibility");if(typeof x<"u"&&T.componentDidUpdate&&T.componentDidUpdate.prevContext!==x)throw new TypeError("the legacy supportPrevContextArgumentOfComponentDidUpdate option should be matched by `lifecycles: { componentDidUpdate: { prevContext: true } }`, for compatibility")}function j(Xe){var ae=Xe.options,ye=ae.lifecycles,He=ye===void 0?{}:ye,x=ae.enableComponentDidUpdateOnSetState,T=ae.supportPrevContextArgumentOfComponentDidUpdate,k=typeof x<"u",Ie=typeof T<"u",me=k||Ie?(0,C.default)({},k&&{onSetState:!!x},Ie&&{prevContext:!!T}):null,Re=He.getDerivedStateFromProps,we=Re?{hasShouldComponentUpdateBug:!!Re.hasShouldComponentUpdateBug}:!1;return(0,C.default)({},He,{setState:(0,C.default)({},He.setState),getChildContext:(0,C.default)({calledByRenderer:!0},He.getChildContext)},me&&{componentDidUpdate:me},{getDerivedStateFromProps:we})}function te(Xe){return Xe.nodeType==="host"?Xe:Xe.rendered}function Q(Xe){if(Xe[X].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return Xe[X]!==Xe?Xe[H][0]:Xe[X][v]}function ie(Xe,ae){return(0,m.parentsOfNode)(ae,Q(Xe))}function he(Xe,ae){Array.isArray(ae)?((0,c.privateSet)(Xe,v,ae[0]),(0,c.privateSet)(Xe,w,ae)):((0,c.privateSet)(Xe,v,ae),(0,c.privateSet)(Xe,w,[ae])),(0,c.privateSet)(Xe,"length",Xe[w].length)}function ne(Xe,ae,ye,He){return!(0,l.default)(Xe,ae)||!(0,l.default)(ye,He)}function be(Xe){return Xe&&Xe.isPureReactComponent}function pe(Xe,ae,ye){var He=Xe.instance,x=Xe.type,T=(0,c.displayNameOfNode)(Xe);if(i(x.childContextTypes)!=="object")return console.warn(String(T)+".getChildContext(): childContextTypes must be defined in order to use getChildContext()."),{};var k=He.getChildContext();return Object.keys(k).forEach(function(Ie){if(!(Ie in x.childContextTypes))throw new Error(String(T)+'.getChildContext(): key "'+String(Ie)+'" is not defined in childContextTypes.')}),typeof ye.checkPropTypes=="function"&&ye.checkPropTypes(x.childContextTypes,k,"child context",ae),k}function ve(Xe,ae){return!(0,c.isCustomComponentElement)(Xe,ae)||!Xe.type.prototype||typeof Xe.type.prototype.getChildContext!="function"?null:(0,c.spyMethod)(Xe.type.prototype,"getChildContext")}function We(Xe,ae,ye,He,x){var T=ae[V];if(Xe.options.legacyContextMode==="parent")if(x)(0,c.privateSet)(ae,Y,x.getLastReturnValue()),x.restore();else if(typeof ye.getChildContext=="function"){var k=[ae[v]].concat(ie(ae,ae[v])),Ie=pe(He,k,T);(0,c.privateSet)(ae,Y,Ie)}else(0,c.privateSet)(ae,Y,null)}function Be(Xe,ae){var ye=Xe.type.getDerivedStateFromProps;if(typeof ye=="function")var He=Xe.instance,x=(0,c.spyMethod)(He,"shouldComponentUpdate",function(k){return function(){function Ie(){He.state=ae;for(var me=arguments.length,Re=Array(me),we=0;we1&&arguments[1]!==void 0?arguments[1]:{},ye=(0,C.default)({},Xe[W],ae,{context:ae.context||(0,C.default)({},Xe[W].context,Xe[X][Y])});return(0,c.privateSet)(ye,P,Xe[X][P]),ye}var _e=function(){function Xe(ae,ye){var He=this,x=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};B(this,Xe),$(x);var T=De(ae,ye,x,this),k=(0,d.default)(T),Ie=j(k);if(ye)(0,c.privateSet)(this,X,ye),(0,c.privateSet)(this,S,null),(0,c.privateSet)(this,V,ye[V]),he(this,ae),(0,c.privateSet)(this,W,ye[W]),(0,c.privateSet)(this,H,ye[w]),(0,c.privateSet)(this,P,null);else{if(!k.isValidElement(ae))throw new TypeError("ShallowWrapper can only wrap valid elements");var me=Ie.getChildContext.calledByRenderer?ve(ae,k):null;(0,c.privateSet)(this,X,this),(0,c.privateSet)(this,S,ae);var Re=k.createRenderer((0,C.default)({mode:"shallow"},T));(0,c.privateSet)(this,V,Re);var we=new Map(T[P]||[]);this[V].render(ae,T.context,{providerValues:we});var je=this[V].getNode();he(this,te(je)),(0,c.privateSet)(this,W,T),(0,c.privateSet)(this,P,we);var at=je.instance;at&&!T.disableLifecycleMethods&&(Ie.componentDidUpdate.onSetState&&!at[R]&&((0,c.privateSet)(at,R,at.setState),at.setState=function(bt){var ct=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return He.setState.apply(He,Z(ct==null?[bt]:[bt,ct]))}),typeof at.componentDidMount=="function"&&this[V].batchedUpdates(function(){at.componentDidMount()}),We(k,this,at,je,me))}}return I(Xe,[{key:"root",value:function(){function ae(){return this[X]}return ae}()},{key:"getNodeInternal",value:function(){function ae(){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 ae}()},{key:"getNodesInternal",value:function(){function ae(){return this[X]===this&&this.length===1&&this.update(),this[w]}return ae}()},{key:"getElement",value:function(){function ae(){var ye=this;return this.single("getElement",function(He){return(0,d.default)(ye[W]).nodeToElement(He)})}return ae}()},{key:"getElements",value:function(){function ae(){var ye=this;return this.getNodesInternal().map(function(He){return(0,d.default)(ye[W]).nodeToElement(He)})}return ae}()},{key:"getNode",value:function(){function ae(){throw new Error("ShallowWrapper::getNode() is no longer supported. Use ShallowWrapper::getElement() instead")}return ae}()},{key:"getNodes",value:function(){function ae(){throw new Error("ShallowWrapper::getNodes() is no longer supported. Use ShallowWrapper::getElements() instead")}return ae}()},{key:"instance",value:function(){function ae(){if(this[X]!==this)throw new Error("ShallowWrapper::instance() can only be called on the root");return this[V].getNode().instance}return ae}()},{key:"getWrappingComponent",value:function(){function ae(){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[K]}return ae}()},{key:"update",value:function(){function ae(){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 he(this,te(this[V].getNode())),this}return ae}()},{key:"unmount",value:function(){function ae(){return this[V].unmount(),this[X][K]&&this[X][K].unmount(),this}return ae}()},{key:"rerender",value:function(){function ae(ye,He){var x=this,T=(0,d.default)(this[W]);return this.single("rerender",function(){(0,c.withSetStateAllowed)(function(){var k=x[V].getNode(),Ie=k.instance||{},me=k.type||{},Re=Ie.state,we=Ie.props||x[S].props,je=Ie.context||x[W].context,at=He||je;He&&(x[W]=(0,C.default)({},x[W],{context:at})),x[V].batchedUpdates(function(){var bt=j(T),ct=!0,Ht=void 0,Ce=void 0;if(!x[W].disableLifecycleMethods&&Ie){if(typeof Ie.shouldComponentUpdate=="function"){var E=bt.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Be(k,Re),Ht=(0,c.spyMethod)(Ie,"shouldComponentUpdate")}bt.getChildContext.calledByRenderer&&typeof Ie.getChildContext=="function"&&(Ce=(0,c.spyMethod)(Ie,"getChildContext"))}if(!Ht&&be(Ie)&&(ct=ne(we,ye,Re,Ie.state)),ye&&(x[S]=(0,c.cloneElement)(T,x[S],ye)),x[V].render(x[S],at,{providerValues:x[P]}),Ht&&(ct=Ht.getLastReturnValue(),Ht.restore()),ct&&!x[W].disableLifecycleMethods&&Ie)if(We(T,x,Ie,k,Ce),bt.getSnapshotBeforeUpdate){var _=void 0;typeof Ie.getSnapshotBeforeUpdate=="function"&&(_=Ie.getSnapshotBeforeUpdate(we,Re)),bt.componentDidUpdate&&typeof Ie.componentDidUpdate=="function"&&(!Re||(0,l.default)(Re,x.instance().state)||typeof me.getDerivedStateFromProps=="function")&&Ie.componentDidUpdate(we,Re,_)}else bt.componentDidUpdate&&typeof Ie.componentDidUpdate=="function"&&(bt.componentDidUpdate.prevContext?Ie.componentDidUpdate(we,Re,je):(!Re||(0,l.default)(x.instance().state,Re))&&Ie.componentDidUpdate(we,Re));else(0,l.default)(ye,Ie.props)||(Ie.props=(Object.freeze||Object)((0,C.default)({},Ie.props,ye)));x.update()})})}),this}return ae}()},{key:"setProps",value:function(){function ae(ye){var He=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 He!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");return this.rerender(ye),He&&He(),this}return ae}()},{key:"setState",value:function(){function ae(ye){var He=this,x=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 x!="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)(He[W]),k=j(T),Ie=He[V].getNode(),me=Ie.instance,Re=me.props,we=me.state,je=me.context,at=typeof ye=="function"?ye.call(me,we,Re):ye,bt=!k.setState.skipsComponentDidUpdateOnNullish||at!=null,ct=void 0,Ht=void 0,Ce=!0;if(!He[W].disableLifecycleMethods&&me){if(k.componentDidUpdate&&k.componentDidUpdate.onSetState&&typeof me.shouldComponentUpdate=="function"){var E=k.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Be(Ie,ye),ct=(0,c.spyMethod)(me,"shouldComponentUpdate")}k.getChildContext.calledByRenderer&&typeof me.getChildContext=="function"&&(Ht=(0,c.spyMethod)(me,"getChildContext"))}if(!ct&&be(me)&&(Ce=ne(Re,me.props,we,(0,C.default)({},we,at))),me[R]?me[R](at):me.setState(at),ct&&(Ce=ct.getLastReturnValue(),ct.restore()),bt&&Ce&&!He[W].disableLifecycleMethods&&(We(T,He,me,Ie,Ht),k.componentDidUpdate&&k.componentDidUpdate.onSetState))if(k.getSnapshotBeforeUpdate&&typeof me.getSnapshotBeforeUpdate=="function"){var _=me.getSnapshotBeforeUpdate(Re,we);typeof me.componentDidUpdate=="function"&&me.componentDidUpdate(Re,we,_)}else typeof me.componentDidUpdate=="function"&&(k.componentDidUpdate.prevContext?me.componentDidUpdate(Re,we,je):me.componentDidUpdate(Re,we));He.update(),x&&(T.invokeSetStateCallback?T.invokeSetStateCallback(me,x):x.call(me))})}),this}return ae}()},{key:"setContext",value:function(){function ae(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 ae}()},{key:"contains",value:function(){function ae(ye){var He=(0,d.default)(this[W]);if(!(0,c.isReactElementAlike)(ye,He))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 x=Array.isArray(ye)?function(T){return(0,c.containsChildrenSubArray)(c.nodeEqual,T,ye.map(function(k){return He.elementToNode(k)}))}:function(T){return(0,c.nodeEqual)(He.elementToNode(ye),T)};return ge(this,x).length>0}return ae}()},{key:"containsMatchingElement",value:function(){function ae(ye){var He=(0,d.default)(this[W]),x=He.elementToNode(ye),T=function(){function k(Ie){return(0,c.nodeMatches)(x,Ie,function(me,Re){return me<=Re})}return k}();return ge(this,T).length>0}return ae}()},{key:"containsAllMatchingElements",value:function(){function ae(ye){var He=this;if(!Array.isArray(ye))throw new TypeError("nodes should be an Array");return ye.every(function(x){return He.containsMatchingElement(x)})}return ae}()},{key:"containsAnyMatchingElements",value:function(){function ae(ye){var He=this;return Array.isArray(ye)&&ye.some(function(x){return He.containsMatchingElement(x)})}return ae}()},{key:"equals",value:function(){function ae(ye){var He=this;return this.single("equals",function(){return(0,c.nodeEqual)(He.getNodeInternal(),ye)})}return ae}()},{key:"matchesElement",value:function(){function ae(ye){var He=this;return this.single("matchesElement",function(){var x=(0,d.default)(He[W]),T=x.elementToNode(ye);return(0,c.nodeMatches)(T,He.getNodeInternal(),function(k,Ie){return k<=Ie})})}return ae}()},{key:"find",value:function(){function ae(ye){return this.wrap((0,f.reduceTreesBySelector)(ye,this.getNodesInternal()))}return ae}()},{key:"is",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return this.single("is",function(x){return He(x)})}return ae}()},{key:"isEmptyRender",value:function(){function ae(){var ye=this.getNodesInternal();return ye.every(function(He){return(0,c.isEmptyValue)(He)})}return ae}()},{key:"filterWhere",value:function(){function ae(ye){var He=this;return q(this,function(x){return ye(He.wrap(x))})}return ae}()},{key:"filter",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return q(this,He)}return ae}()},{key:"not",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return q(this,function(x){return!He(x)})}return ae}()},{key:"text",value:function(){function ae(){return this.single("text",m.getTextFromNode)}return ae}()},{key:"html",value:function(){function ae(){var ye=this;return this.single("html",function(He){if(ye.type()===null)return null;var x=(0,d.default)(ye[W]),T=x.createRenderer((0,C.default)({},ye[W],{mode:"string"}));return T.render(x.nodeToElement(He))})}return ae}()},{key:"render",value:function(){function ae(){var ye=this.html();return(0,c.loadCheerioRoot)(ye)}return ae}()},{key:"simulate",value:function(){function ae(ye){for(var He=this,x=arguments.length,T=Array(x>1?x-1:0),k=1;k0?He.first():this.findWhere(function(){return!1})}return ae}()},{key:"shallow",value:function(){function ae(){var ye=this,He=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.single("shallow",function(x){var T=Qe(ye,He);return ye.wrap((0,d.default)(ye[W]).nodeToElement(x),null,T)})}return ae}()},{key:"prop",value:function(){function ae(ye){return this.props()[ye]}return ae}()},{key:"invoke",value:function(){function ae(ye){var He=this;return this.single("invoke",function(){var x=He.prop(ye);if(typeof x!="function")throw new TypeError("ShallowWrapper::invoke() requires the name of a prop whose value is a function");return function(){var T=x.apply(void 0,arguments);return He[X].update(),T}})}return ae}()},{key:"renderProp",value:function(){function ae(ye){var He=this,x=(0,d.default)(this[W]);if(typeof x.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=He.props();if(!(0,s.default)(k,ye))throw new Error("ShallowWrapper::renderProp(): no prop called “"+String(ye)+"“ found");var Ie=k[ye];if(typeof Ie!="function")throw new TypeError("ShallowWrapper::renderProp(): expected prop “"+String(ye)+"“ to contain a function, but it holds “"+(typeof Ie>"u"?"undefined":i(Ie))+"“");return function(){var me=Ie.apply(void 0,arguments),Re=x.wrap(me);return He.wrap(Re,null,He[W])}})}return ae}()},{key:"key",value:function(){function ae(){return this.single("key",function(ye){return ye.key===void 0?null:ye.key})}return ae}()},{key:"type",value:function(){function ae(){return this.single("type",function(ye){return(0,c.typeOfNode)(ye)})}return ae}()},{key:"name",value:function(){function ae(){var ye=(0,d.default)(this[W]);return this.single("name",function(He){return ye.displayNameOfNode?ye.displayNameOfNode(He):(0,c.displayNameOfNode)(He)})}return ae}()},{key:"hasClass",value:function(){function ae(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(He){return(0,m.hasClassName)(He,ye)})}return ae}()},{key:"forEach",value:function(){function ae(ye){var He=this;return this.getNodesInternal().forEach(function(x,T){return ye.call(He,He.wrap(x),T)}),this}return ae}()},{key:"map",value:function(){function ae(ye){var He=this;return this.getNodesInternal().map(function(x,T){return ye.call(He,He.wrap(x),T)})}return ae}()},{key:"reduce",value:function(){function ae(ye){var He=this,x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(T,k,Ie){return ye.call(He,T,He.wrap(k),Ie)},x):this.getNodesInternal().reduce(function(T,k,Ie){return ye.call(He,Ie===1?He.wrap(T):T,He.wrap(k),Ie)})}return ae}()},{key:"reduceRight",value:function(){function ae(ye){var He=this,x=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(T,k,Ie){return ye.call(He,T,He.wrap(k),Ie)},x):this.getNodesInternal().reduceRight(function(T,k,Ie){return ye.call(He,Ie===1?He.wrap(T):T,He.wrap(k),Ie)})}return ae}()},{key:"slice",value:function(){function ae(ye,He){return this.wrap(this.getNodesInternal().slice(ye,He))}return ae}()},{key:"some",value:function(){function ae(ye){if(this[X]===this)throw new Error("ShallowWrapper::some() can not be called on the root");var He=(0,f.buildPredicate)(ye);return this.getNodesInternal().some(He)}return ae}()},{key:"someWhere",value:function(){function ae(ye){var He=this;return this.getNodesInternal().some(function(x,T){return ye.call(He,He.wrap(x),T)})}return ae}()},{key:"every",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return this.getNodesInternal().every(He)}return ae}()},{key:"everyWhere",value:function(){function ae(ye){var He=this;return this.getNodesInternal().every(function(x,T){return ye.call(He,He.wrap(x),T)})}return ae}()},{key:"flatMap",value:function(){function ae(ye){var He=this,x=this.getNodesInternal().map(function(k,Ie){return ye.call(He,He.wrap(k),Ie)}),T=(0,o.default)(x,1);return this.wrap(T.filter(Boolean))}return ae}()},{key:"findWhere",value:function(){function ae(ye){var He=this;return ge(this,function(x){var T=He.wrap(x);return T.length>0&&ye(T)})}return ae}()},{key:"get",value:function(){function ae(ye){return this.getElements()[ye]}return ae}()},{key:"at",value:function(){function ae(ye){var He=this.getNodesInternal();return ye0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(ye).exists():this.length>0}return ae}()},{key:"single",value:function(){function ae(ye,He){var x=typeof ye=="string"?ye:"unknown",T=typeof He=="function"?He:ye;if(this.length!==1)throw new Error("Method “"+x+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return T.call(this,this.getNodeInternal())}return ae}()},{key:"wrap",value:function(){function ae(ye){var He=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[X];if(ye instanceof Xe)return ye;for(var x=arguments.length,T=Array(x>2?x-2:0),k=2;k0&&arguments[0]!==void 0?arguments[0]:{};return(0,h.debugNodes)(this.getNodesInternal(),ye)}return ae}()},{key:"tap",value:function(){function ae(ye){return ye(this),this}return ae}()},{key:"dive",value:function(){function ae(){var ye=this,He=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},x=(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 Ie=(0,d.default)(ye[W]).nodeToElement(k);if(!(0,c.isCustomComponentElement)(Ie,x))throw new TypeError("ShallowWrapper::"+T+"() can only be called on components");var me=Qe(ye,He);return ye.wrap(Ie,null,me)})}return ae}()},{key:"hostNodes",value:function(){function ae(){return this.filterWhere(function(ye){return typeof ye.type()=="string"})}return ae}()}]),Xe}();function gt(Xe){var ae=(0,d.default)(Xe[W]),ye=Xe[F],He=ye[V],x=He.getNode(),T=Pe(Xe,ae),k=T.legacyContext,Ie=T.providerValues,me=ye[P];if(ye.setContext((0,C.default)({},Xe[F][W].context,k)),ye[P]=new Map([].concat(Z(me),Z(Ie))),typeof ae.isContextConsumer=="function"&&ae.isContextConsumer(x.type)){var Re=x.type,we=ae.getProviderFromConsumer(Re),je=Ie.get(we),at=me.get(we);je!==at&&ye.rerender()}}var lt=function(Xe){y(ae,Xe);function ae(ye,He,x){B(this,ae);var T=p(this,(ae.__proto__||Object.getPrototypeOf(ae)).call(this,ye));return(0,c.privateSet)(T,F,He),(0,c.privateSet)(T,J,x),T}return I(ae,[{key:"rerender",value:function(){function ye(){for(var He,x=arguments.length,T=Array(x),k=0;k2&&arguments[2]!==void 0?arguments[2]:m.treeFilter;return Xe.flatMap(function(He){return ye(He.getNodeInternal(),ae)})}function q(Xe,ae){return Xe.wrap(Xe.getNodesInternal().filter(ae).filter(Boolean))}function $(Xe){var ae=Xe.lifecycleExperimental,ye=Xe.disableLifecycleMethods,He=Xe.enableComponentDidUpdateOnSetState,F=Xe.supportPrevContextArgumentOfComponentDidUpdate,T=Xe.lifecycles;if(typeof ae<"u"&&typeof ae!="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(ae!=null&&ye!=null&&ae===ye)throw new Error("lifecycleExperimental and disableLifecycleMethods cannot be set to the same value");if(typeof He<"u"&&T.componentDidUpdate&&T.componentDidUpdate.onSetState!==He)throw new TypeError("the legacy enableComponentDidUpdateOnSetState option should be matched by `lifecycles: { componentDidUpdate: { onSetState: true } }`, for compatibility");if(typeof F<"u"&&T.componentDidUpdate&&T.componentDidUpdate.prevContext!==F)throw new TypeError("the legacy supportPrevContextArgumentOfComponentDidUpdate option should be matched by `lifecycles: { componentDidUpdate: { prevContext: true } }`, for compatibility")}function j(Xe){var ae=Xe.options,ye=ae.lifecycles,He=ye===void 0?{}:ye,F=ae.enableComponentDidUpdateOnSetState,T=ae.supportPrevContextArgumentOfComponentDidUpdate,k=typeof F<"u",ie=typeof T<"u",me=k||ie?(0,r.default)({},k&&{onSetState:!!F},ie&&{prevContext:!!T}):null,Ve=He.getDerivedStateFromProps,we=Ve?{hasShouldComponentUpdateBug:!!Ve.hasShouldComponentUpdateBug}:!1;return(0,r.default)({},He,{setState:(0,r.default)({},He.setState),getChildContext:(0,r.default)({calledByRenderer:!0},He.getChildContext)},me&&{componentDidUpdate:me},{getDerivedStateFromProps:we})}function te(Xe){return Xe.nodeType==="host"?Xe:Xe.rendered}function Q(Xe){if(Xe[X].length!==1)throw new Error("getRootNodeInternal(wrapper) can only be called when wrapper wraps one node");return Xe[X]!==Xe?Xe[H][0]:Xe[X][v]}function Ie(Xe,ae){return(0,m.parentsOfNode)(ae,Q(Xe))}function he(Xe,ae){Array.isArray(ae)?((0,c.privateSet)(Xe,v,ae[0]),(0,c.privateSet)(Xe,w,ae)):((0,c.privateSet)(Xe,v,ae),(0,c.privateSet)(Xe,w,[ae])),(0,c.privateSet)(Xe,"length",Xe[w].length)}function ne(Xe,ae,ye,He){return!(0,l.default)(Xe,ae)||!(0,l.default)(ye,He)}function be(Xe){return Xe&&Xe.isPureReactComponent}function pe(Xe,ae,ye){var He=Xe.instance,F=Xe.type,T=(0,c.displayNameOfNode)(Xe);if(I(F.childContextTypes)!=="object")return console.warn(String(T)+".getChildContext(): childContextTypes must be defined in order to use getChildContext()."),{};var k=He.getChildContext();return Object.keys(k).forEach(function(ie){if(!(ie in F.childContextTypes))throw new Error(String(T)+'.getChildContext(): key "'+String(ie)+'" is not defined in childContextTypes.')}),typeof ye.checkPropTypes=="function"&&ye.checkPropTypes(F.childContextTypes,k,"child context",ae),k}function ve(Xe,ae){return!(0,c.isCustomComponentElement)(Xe,ae)||!Xe.type.prototype||typeof Xe.type.prototype.getChildContext!="function"?null:(0,c.spyMethod)(Xe.type.prototype,"getChildContext")}function We(Xe,ae,ye,He,F){var T=ae[R];if(Xe.options.legacyContextMode==="parent")if(F)(0,c.privateSet)(ae,Y,F.getLastReturnValue()),F.restore();else if(typeof ye.getChildContext=="function"){var k=[ae[v]].concat(Ie(ae,ae[v])),ie=pe(He,k,T);(0,c.privateSet)(ae,Y,ie)}else(0,c.privateSet)(ae,Y,null)}function Be(Xe,ae){var ye=Xe.type.getDerivedStateFromProps;if(typeof ye=="function")var He=Xe.instance,F=(0,c.spyMethod)(He,"shouldComponentUpdate",function(k){return function(){function ie(){He.state=ae;for(var me=arguments.length,Ve=Array(me),we=0;we1&&arguments[1]!==void 0?arguments[1]:{},ye=(0,r.default)({},Xe[W],ae,{context:ae.context||(0,r.default)({},Xe[W].context,Xe[X][Y])});return(0,c.privateSet)(ye,P,Xe[X][P]),ye}var _e=function(){function Xe(ae,ye){var He=this,F=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{};B(this,Xe),$(F);var T=De(ae,ye,F,this),k=(0,d.default)(T),ie=j(k);if(ye)(0,c.privateSet)(this,X,ye),(0,c.privateSet)(this,S,null),(0,c.privateSet)(this,R,ye[R]),he(this,ae),(0,c.privateSet)(this,W,ye[W]),(0,c.privateSet)(this,H,ye[w]),(0,c.privateSet)(this,P,null);else{if(!k.isValidElement(ae))throw new TypeError("ShallowWrapper can only wrap valid elements");var me=ie.getChildContext.calledByRenderer?ve(ae,k):null;(0,c.privateSet)(this,X,this),(0,c.privateSet)(this,S,ae);var Ve=k.createRenderer((0,r.default)({mode:"shallow"},T));(0,c.privateSet)(this,R,Ve);var we=new Map(T[P]||[]);this[R].render(ae,T.context,{providerValues:we});var je=this[R].getNode();he(this,te(je)),(0,c.privateSet)(this,W,T),(0,c.privateSet)(this,P,we);var at=je.instance;at&&!T.disableLifecycleMethods&&(ie.componentDidUpdate.onSetState&&!at[V]&&((0,c.privateSet)(at,V,at.setState),at.setState=function(bt){var ct=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return He.setState.apply(He,Z(ct==null?[bt]:[bt,ct]))}),typeof at.componentDidMount=="function"&&this[R].batchedUpdates(function(){at.componentDidMount()}),We(k,this,at,je,me))}}return i(Xe,[{key:"root",value:function(){function ae(){return this[X]}return ae}()},{key:"getNodeInternal",value:function(){function ae(){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 ae}()},{key:"getNodesInternal",value:function(){function ae(){return this[X]===this&&this.length===1&&this.update(),this[w]}return ae}()},{key:"getElement",value:function(){function ae(){var ye=this;return this.single("getElement",function(He){return(0,d.default)(ye[W]).nodeToElement(He)})}return ae}()},{key:"getElements",value:function(){function ae(){var ye=this;return this.getNodesInternal().map(function(He){return(0,d.default)(ye[W]).nodeToElement(He)})}return ae}()},{key:"getNode",value:function(){function ae(){throw new Error("ShallowWrapper::getNode() is no longer supported. Use ShallowWrapper::getElement() instead")}return ae}()},{key:"getNodes",value:function(){function ae(){throw new Error("ShallowWrapper::getNodes() is no longer supported. Use ShallowWrapper::getElements() instead")}return ae}()},{key:"instance",value:function(){function ae(){if(this[X]!==this)throw new Error("ShallowWrapper::instance() can only be called on the root");return this[R].getNode().instance}return ae}()},{key:"getWrappingComponent",value:function(){function ae(){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[K]}return ae}()},{key:"update",value:function(){function ae(){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 he(this,te(this[R].getNode())),this}return ae}()},{key:"unmount",value:function(){function ae(){return this[R].unmount(),this[X][K]&&this[X][K].unmount(),this}return ae}()},{key:"rerender",value:function(){function ae(ye,He){var F=this,T=(0,d.default)(this[W]);return this.single("rerender",function(){(0,c.withSetStateAllowed)(function(){var k=F[R].getNode(),ie=k.instance||{},me=k.type||{},Ve=ie.state,we=ie.props||F[S].props,je=ie.context||F[W].context,at=He||je;He&&(F[W]=(0,r.default)({},F[W],{context:at})),F[R].batchedUpdates(function(){var bt=j(T),ct=!0,Ht=void 0,re=void 0;if(!F[W].disableLifecycleMethods&&ie){if(typeof ie.shouldComponentUpdate=="function"){var E=bt.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Be(k,Ve),Ht=(0,c.spyMethod)(ie,"shouldComponentUpdate")}bt.getChildContext.calledByRenderer&&typeof ie.getChildContext=="function"&&(re=(0,c.spyMethod)(ie,"getChildContext"))}if(!Ht&&be(ie)&&(ct=ne(we,ye,Ve,ie.state)),ye&&(F[S]=(0,c.cloneElement)(T,F[S],ye)),F[R].render(F[S],at,{providerValues:F[P]}),Ht&&(ct=Ht.getLastReturnValue(),Ht.restore()),ct&&!F[W].disableLifecycleMethods&&ie)if(We(T,F,ie,k,re),bt.getSnapshotBeforeUpdate){var _=void 0;typeof ie.getSnapshotBeforeUpdate=="function"&&(_=ie.getSnapshotBeforeUpdate(we,Ve)),bt.componentDidUpdate&&typeof ie.componentDidUpdate=="function"&&(!Ve||(0,l.default)(Ve,F.instance().state)||typeof me.getDerivedStateFromProps=="function")&&ie.componentDidUpdate(we,Ve,_)}else bt.componentDidUpdate&&typeof ie.componentDidUpdate=="function"&&(bt.componentDidUpdate.prevContext?ie.componentDidUpdate(we,Ve,je):(!Ve||(0,l.default)(F.instance().state,Ve))&&ie.componentDidUpdate(we,Ve));else(0,l.default)(ye,ie.props)||(ie.props=(Object.freeze||Object)((0,r.default)({},ie.props,ye)));F.update()})})}),this}return ae}()},{key:"setProps",value:function(){function ae(ye){var He=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 He!="function")throw new TypeError("ReactWrapper::setProps() expects a function as its second argument");return this.rerender(ye),He&&He(),this}return ae}()},{key:"setState",value:function(){function ae(ye){var He=this,F=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 F!="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)(He[W]),k=j(T),ie=He[R].getNode(),me=ie.instance,Ve=me.props,we=me.state,je=me.context,at=typeof ye=="function"?ye.call(me,we,Ve):ye,bt=!k.setState.skipsComponentDidUpdateOnNullish||at!=null,ct=void 0,Ht=void 0,re=!0;if(!He[W].disableLifecycleMethods&&me){if(k.componentDidUpdate&&k.componentDidUpdate.onSetState&&typeof me.shouldComponentUpdate=="function"){var E=k.getDerivedStateFromProps;E&&E.hasShouldComponentUpdateBug&&Be(ie,ye),ct=(0,c.spyMethod)(me,"shouldComponentUpdate")}k.getChildContext.calledByRenderer&&typeof me.getChildContext=="function"&&(Ht=(0,c.spyMethod)(me,"getChildContext"))}if(!ct&&be(me)&&(re=ne(Ve,me.props,we,(0,r.default)({},we,at))),me[V]?me[V](at):me.setState(at),ct&&(re=ct.getLastReturnValue(),ct.restore()),bt&&re&&!He[W].disableLifecycleMethods&&(We(T,He,me,ie,Ht),k.componentDidUpdate&&k.componentDidUpdate.onSetState))if(k.getSnapshotBeforeUpdate&&typeof me.getSnapshotBeforeUpdate=="function"){var _=me.getSnapshotBeforeUpdate(Ve,we);typeof me.componentDidUpdate=="function"&&me.componentDidUpdate(Ve,we,_)}else typeof me.componentDidUpdate=="function"&&(k.componentDidUpdate.prevContext?me.componentDidUpdate(Ve,we,je):me.componentDidUpdate(Ve,we));He.update(),F&&(T.invokeSetStateCallback?T.invokeSetStateCallback(me,F):F.call(me))})}),this}return ae}()},{key:"setContext",value:function(){function ae(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 ae}()},{key:"contains",value:function(){function ae(ye){var He=(0,d.default)(this[W]);if(!(0,c.isReactElementAlike)(ye,He))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 F=Array.isArray(ye)?function(T){return(0,c.containsChildrenSubArray)(c.nodeEqual,T,ye.map(function(k){return He.elementToNode(k)}))}:function(T){return(0,c.nodeEqual)(He.elementToNode(ye),T)};return ge(this,F).length>0}return ae}()},{key:"containsMatchingElement",value:function(){function ae(ye){var He=(0,d.default)(this[W]),F=He.elementToNode(ye),T=function(){function k(ie){return(0,c.nodeMatches)(F,ie,function(me,Ve){return me<=Ve})}return k}();return ge(this,T).length>0}return ae}()},{key:"containsAllMatchingElements",value:function(){function ae(ye){var He=this;if(!Array.isArray(ye))throw new TypeError("nodes should be an Array");return ye.every(function(F){return He.containsMatchingElement(F)})}return ae}()},{key:"containsAnyMatchingElements",value:function(){function ae(ye){var He=this;return Array.isArray(ye)&&ye.some(function(F){return He.containsMatchingElement(F)})}return ae}()},{key:"equals",value:function(){function ae(ye){var He=this;return this.single("equals",function(){return(0,c.nodeEqual)(He.getNodeInternal(),ye)})}return ae}()},{key:"matchesElement",value:function(){function ae(ye){var He=this;return this.single("matchesElement",function(){var F=(0,d.default)(He[W]),T=F.elementToNode(ye);return(0,c.nodeMatches)(T,He.getNodeInternal(),function(k,ie){return k<=ie})})}return ae}()},{key:"find",value:function(){function ae(ye){return this.wrap((0,f.reduceTreesBySelector)(ye,this.getNodesInternal()))}return ae}()},{key:"is",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return this.single("is",function(F){return He(F)})}return ae}()},{key:"isEmptyRender",value:function(){function ae(){var ye=this.getNodesInternal();return ye.every(function(He){return(0,c.isEmptyValue)(He)})}return ae}()},{key:"filterWhere",value:function(){function ae(ye){var He=this;return q(this,function(F){return ye(He.wrap(F))})}return ae}()},{key:"filter",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return q(this,He)}return ae}()},{key:"not",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return q(this,function(F){return!He(F)})}return ae}()},{key:"text",value:function(){function ae(){return this.single("text",m.getTextFromNode)}return ae}()},{key:"html",value:function(){function ae(){var ye=this;return this.single("html",function(He){if(ye.type()===null)return null;var F=(0,d.default)(ye[W]),T=F.createRenderer((0,r.default)({},ye[W],{mode:"string"}));return T.render(F.nodeToElement(He))})}return ae}()},{key:"render",value:function(){function ae(){var ye=this.html();return(0,c.loadCheerioRoot)(ye)}return ae}()},{key:"simulate",value:function(){function ae(ye){for(var He=this,F=arguments.length,T=Array(F>1?F-1:0),k=1;k0?He.first():this.findWhere(function(){return!1})}return ae}()},{key:"shallow",value:function(){function ae(){var ye=this,He=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};return this.single("shallow",function(F){var T=Qe(ye,He);return ye.wrap((0,d.default)(ye[W]).nodeToElement(F),null,T)})}return ae}()},{key:"prop",value:function(){function ae(ye){return this.props()[ye]}return ae}()},{key:"invoke",value:function(){function ae(ye){var He=this;return this.single("invoke",function(){var F=He.prop(ye);if(typeof F!="function")throw new TypeError("ShallowWrapper::invoke() requires the name of a prop whose value is a function");return function(){var T=F.apply(void 0,arguments);return He[X].update(),T}})}return ae}()},{key:"renderProp",value:function(){function ae(ye){var He=this,F=(0,d.default)(this[W]);if(typeof F.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=He.props();if(!(0,s.default)(k,ye))throw new Error("ShallowWrapper::renderProp(): no prop called “"+String(ye)+"“ found");var ie=k[ye];if(typeof ie!="function")throw new TypeError("ShallowWrapper::renderProp(): expected prop “"+String(ye)+"“ to contain a function, but it holds “"+(typeof ie>"u"?"undefined":I(ie))+"“");return function(){var me=ie.apply(void 0,arguments),Ve=F.wrap(me);return He.wrap(Ve,null,He[W])}})}return ae}()},{key:"key",value:function(){function ae(){return this.single("key",function(ye){return ye.key===void 0?null:ye.key})}return ae}()},{key:"type",value:function(){function ae(){return this.single("type",function(ye){return(0,c.typeOfNode)(ye)})}return ae}()},{key:"name",value:function(){function ae(){var ye=(0,d.default)(this[W]);return this.single("name",function(He){return ye.displayNameOfNode?ye.displayNameOfNode(He):(0,c.displayNameOfNode)(He)})}return ae}()},{key:"hasClass",value:function(){function ae(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(He){return(0,m.hasClassName)(He,ye)})}return ae}()},{key:"forEach",value:function(){function ae(ye){var He=this;return this.getNodesInternal().forEach(function(F,T){return ye.call(He,He.wrap(F),T)}),this}return ae}()},{key:"map",value:function(){function ae(ye){var He=this;return this.getNodesInternal().map(function(F,T){return ye.call(He,He.wrap(F),T)})}return ae}()},{key:"reduce",value:function(){function ae(ye){var He=this,F=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduce(function(T,k,ie){return ye.call(He,T,He.wrap(k),ie)},F):this.getNodesInternal().reduce(function(T,k,ie){return ye.call(He,ie===1?He.wrap(T):T,He.wrap(k),ie)})}return ae}()},{key:"reduceRight",value:function(){function ae(ye){var He=this,F=arguments.length>1&&arguments[1]!==void 0?arguments[1]:void 0;return arguments.length>1?this.getNodesInternal().reduceRight(function(T,k,ie){return ye.call(He,T,He.wrap(k),ie)},F):this.getNodesInternal().reduceRight(function(T,k,ie){return ye.call(He,ie===1?He.wrap(T):T,He.wrap(k),ie)})}return ae}()},{key:"slice",value:function(){function ae(ye,He){return this.wrap(this.getNodesInternal().slice(ye,He))}return ae}()},{key:"some",value:function(){function ae(ye){if(this[X]===this)throw new Error("ShallowWrapper::some() can not be called on the root");var He=(0,f.buildPredicate)(ye);return this.getNodesInternal().some(He)}return ae}()},{key:"someWhere",value:function(){function ae(ye){var He=this;return this.getNodesInternal().some(function(F,T){return ye.call(He,He.wrap(F),T)})}return ae}()},{key:"every",value:function(){function ae(ye){var He=(0,f.buildPredicate)(ye);return this.getNodesInternal().every(He)}return ae}()},{key:"everyWhere",value:function(){function ae(ye){var He=this;return this.getNodesInternal().every(function(F,T){return ye.call(He,He.wrap(F),T)})}return ae}()},{key:"flatMap",value:function(){function ae(ye){var He=this,F=this.getNodesInternal().map(function(k,ie){return ye.call(He,He.wrap(k),ie)}),T=(0,o.default)(F,1);return this.wrap(T.filter(Boolean))}return ae}()},{key:"findWhere",value:function(){function ae(ye){var He=this;return ge(this,function(F){var T=He.wrap(F);return T.length>0&&ye(T)})}return ae}()},{key:"get",value:function(){function ae(ye){return this.getElements()[ye]}return ae}()},{key:"at",value:function(){function ae(ye){var He=this.getNodesInternal();return ye0&&arguments[0]!==void 0?arguments[0]:null;return arguments.length>0?this.find(ye).exists():this.length>0}return ae}()},{key:"single",value:function(){function ae(ye,He){var F=typeof ye=="string"?ye:"unknown",T=typeof He=="function"?He:ye;if(this.length!==1)throw new Error("Method “"+F+"” is meant to be run on 1 node. "+String(this.length)+" found instead.");return T.call(this,this.getNodeInternal())}return ae}()},{key:"wrap",value:function(){function ae(ye){var He=arguments.length>1&&arguments[1]!==void 0?arguments[1]:this[X];if(ye instanceof Xe)return ye;for(var F=arguments.length,T=Array(F>2?F-2:0),k=2;k0&&arguments[0]!==void 0?arguments[0]:{};return(0,h.debugNodes)(this.getNodesInternal(),ye)}return ae}()},{key:"tap",value:function(){function ae(ye){return ye(this),this}return ae}()},{key:"dive",value:function(){function ae(){var ye=this,He=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},F=(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 ie=(0,d.default)(ye[W]).nodeToElement(k);if(!(0,c.isCustomComponentElement)(ie,F))throw new TypeError("ShallowWrapper::"+T+"() can only be called on components");var me=Qe(ye,He);return ye.wrap(ie,null,me)})}return ae}()},{key:"hostNodes",value:function(){function ae(){return this.filterWhere(function(ye){return typeof ye.type()=="string"})}return ae}()}]),Xe}();function gt(Xe){var ae=(0,d.default)(Xe[W]),ye=Xe[x],He=ye[R],F=He.getNode(),T=Pe(Xe,ae),k=T.legacyContext,ie=T.providerValues,me=ye[P];if(ye.setContext((0,r.default)({},Xe[x][W].context,k)),ye[P]=new Map([].concat(Z(me),Z(ie))),typeof ae.isContextConsumer=="function"&&ae.isContextConsumer(F.type)){var Ve=F.type,we=ae.getProviderFromConsumer(Ve),je=ie.get(we),at=me.get(we);je!==at&&ye.rerender()}}var lt=function(Xe){y(ae,Xe);function ae(ye,He,F){B(this,ae);var T=p(this,(ae.__proto__||Object.getPrototypeOf(ae)).call(this,ye));return(0,c.privateSet)(T,x,He),(0,c.privateSet)(T,J,F),T}return i(ae,[{key:"rerender",value:function(){function ye(){for(var He,F=arguments.length,T=Array(F),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)}})(SVe);var mRt=LQ,fRt=q0(mRt),pRt=Jj,bRt=q0(pRt),yRt=Fwe,ZRt=q0(yRt),GRt=vVe,vRt=q0(GRt),BRt=BVe,SRt=q0(BRt),wRt=SVe,VRt=q0(wRt),RRt=lm;function q0(e){return e&&e.__esModule?e:{default:e}}var WRt={render:VRt.default,shallow:SRt.default,mount:vRt.default,ShallowWrapper:bRt.default,ReactWrapper:fRt.default,configure:RRt.merge,EnzymeAdapter:ZRt.default};const Oj=100,XRt=(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)},HRt=e=>{for(const g of e.iterateOverTracks())if(gve(e,g.viewId,g.trackId).activeTransitions>0)return!0;return!1},wVe=(e,g)=>{HRt(e)?setTimeout(()=>{wVe(e,g)},Oj):g()},_j=e=>{kB>0?setTimeout(()=>_j(e),Oj):e()},TRt=e=>{for(const g of e.iterateOverTracks()){let I=_Q(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},E9=(e,g)=>{TRt(e)?setTimeout(()=>{E9(e,g)},Oj):g()},VVe=(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=WRt.mount(N.createElement(uy,{options:{bounded:r},viewConfig:I}),{attachTo:a});return s.update(),_j(()=>{if(o){const A=()=>setTimeout(()=>{i()},1e3);E9(s.instance(),A)}else E9(s.instance(),i)}),[a,s]},NRt=e=>{e&&(jI.unmountComponentAtNode(e),document.body.removeChild(e))};async function kRt(e,g,I,i){let n;return await new Promise(C=>{n=VVe(e,g,I,C,i)}),n}var $b=0,QZ=0,AZ=0,RVe=1e3,M9,jZ,z9=0,mh=0,mk=0,JB=typeof performance=="object"&&performance.now?performance:Date,WVe=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Lj(){return mh||(WVe(YRt),mh=JB.now()+mk)}function YRt(){mh=0}function P9(){this._call=this._time=this._next=null}P9.prototype=XVe.prototype={constructor:P9,restart:function(e,g,I){if(typeof e!="function")throw new TypeError("callback is not a function");I=(I==null?Lj():+I)+(g==null?0:+g),!this._next&&jZ!==this&&(jZ?jZ._next=this:M9=this,jZ=this),this._call=e,this._time=I,Lz()},stop:function(){this._call&&(this._call=null,this._time=1/0,Lz())}};function XVe(e,g,I){var i=new P9;return i.restart(e,g,I),i}function KRt(){Lj(),++$b;for(var e=M9,g;e;)(g=mh-e._time)>=0&&e._call.call(void 0,g),e=e._next;--$b}function MCe(){mh=(z9=JB.now())+mk,$b=QZ=0;try{KRt()}finally{$b=0,DRt(),mh=0}}function xRt(){var e=JB.now(),g=e-z9;g>RVe&&(mk-=g,z9=e)}function DRt(){for(var e,g=M9,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:M9=I);jZ=e,Lz(i)}function Lz(e){if(!$b){QZ&&(QZ=clearTimeout(QZ));var g=e-mh;g>24?(e<1/0&&(QZ=setTimeout(MCe,e-JB.now()-mk)),AZ&&(AZ=clearInterval(AZ))):(AZ||(z9=JB.now(),AZ=setInterval(xRt,RVe)),$b=1,WVe(MCe))}}function zCe(e,g,I){var i=new P9;return g=g==null?0:+g,i.restart(n=>{i.stop(),e(n+g)},g,I),i}var FRt=D0("start","end","cancel","interrupt"),ERt=[],HVe=0,Uz=1,Qz=2,tW=3,PCe=4,jz=5,gW=6;function fk(e,g,I,i,n,C){var r=e.__transition;if(!r)e.__transition={};else if(I in r)return;MRt(e,I,{name:g,index:i,group:n,on:FRt,tween:ERt,time:C.time,delay:C.delay,duration:C.duration,ease:C.ease,timer:null,state:HVe})}function Uj(e,g){var I=ya(e,g);if(I.state>HVe)throw new Error("too late; already scheduled");return I}function TA(e,g){var I=ya(e,g);if(I.state>tW)throw new Error("too late; already running");return I}function ya(e,g){var I=e.__transition;if(!I||!(I=I[g]))throw new Error("transition not found");return I}function MRt(e,g,I){var i=e.__transition,n;i[g]=I,I.timer=XVe(C,0,I.time);function C(s){I.state=Uz,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!==Uz)return a();for(A in i)if(u=i[A],u.name===I.name){if(u.state===tW)return zCe(r);u.state===PCe?(u.state=gW,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete i[A]):+AQz&&i.state=0&&(g=g.slice(0,I)),!g||g==="start"})}function f1t(e,g,I){var i,n,C=m1t(g)?Uj:TA;return function(){var r=C(this,e),o=r.on;o!==i&&(n=(i=o).copy()).on(g,I),r.on=n}}function p1t(e,g){var I=this._id;return arguments.length<2?ya(this.node(),I).on.on(e):this.each(f1t(I,e,g))}function b1t(e){return function(){var g=this.parentNode;for(var I in this.__transition)if(+I!==e)return;g&&g.removeChild(this)}}function y1t(){return this.on("end.remove",b1t(this._id))}function Z1t(e){var g=this._name,I=this._id;typeof e!="function"&&(e=NS(e));for(var i=this._groups,n=i.length,C=new Array(n),r=0;rUz&&i.name===g)return new vA([[e]],_1t,g,+n)}return null}const U1t=Object.freeze(Object.defineProperty({__proto__:null,active:L1t,interrupt:av,transition:kVe},Symbol.toStringTag,{value:"Module"})),ZR=e=>()=>e;function Q1t(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 nA(e,g,I){this.k=e,this.x=g,this.y=I}nA.prototype={constructor:nA,scale:function(e){return e===1?this:new nA(this.k*e,this.x,this.y)},translate:function(e,g){return e===0&g===0?this:new nA(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 Ji=new nA(1,0,0);KVe.prototype=nA.prototype;function KVe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Ji;return e.__zoom}function wD(e){e.stopImmediatePropagation()}function sZ(e){e.preventDefault(),e.stopImmediatePropagation()}function j1t(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function $1t(){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 JCe(){return this.__zoom||Ji}function q1t(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function eWt(){return navigator.maxTouchPoints||"ontouchstart"in this}function tWt(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 $z(){var e=j1t,g=$1t,I=tWt,i=q1t,n=eWt,C=[0,1/0],r=[[-1/0,-1/0],[1/0,1/0]],o=250,a=QIt,s=D0("start","zoom","end"),A,l,c,u=500,d=150,h=0,m=10;function f(R){R.property("__zoom",JCe).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,K){var F=R.selection?R.selection():R;F.property("__zoom",JCe),R!==F?Z(R,H,Y,K):F.interrupt().each(function(){B(this,arguments).event(K).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},f.scaleBy=function(R,H,Y,K){f.scaleTo(R,function(){var F=this.__zoom.k,J=typeof H=="function"?H.apply(this,arguments):H;return F*J},Y,K)},f.scaleTo=function(R,H,Y,K){f.transform(R,function(){var F=g.apply(this,arguments),J=this.__zoom,P=Y==null?y(F):typeof Y=="function"?Y.apply(this,arguments):Y,ge=J.invert(P),q=typeof H=="function"?H.apply(this,arguments):H;return I(p(b(J,q),P,ge),F,r)},Y,K)},f.translateBy=function(R,H,Y,K){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,K)},f.translateTo=function(R,H,Y,K,F){f.transform(R,function(){var J=g.apply(this,arguments),P=this.__zoom,ge=K==null?y(J):typeof K=="function"?K.apply(this,arguments):K;return I(Ji.translate(ge[0],ge[1]).scale(P.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof Y=="function"?-Y.apply(this,arguments):-Y),J,r)},K,F)};function b(R,H){return H=Math.max(C[0],Math.min(C[1],H)),H===R.k?R:new nA(H,R.x,R.y)}function p(R,H,Y){var K=H[0]-Y[0]*R.k,F=H[1]-Y[1]*R.k;return K===R.x&&F===R.y?R:new nA(R.k,K,F)}function y(R){return[(+R[0][0]+ +R[1][0])/2,(+R[0][1]+ +R[1][1])/2]}function Z(R,H,Y,K){R.on("start.zoom",function(){B(this,arguments).event(K).start()}).on("interrupt.zoom end.zoom",function(){B(this,arguments).event(K).end()}).tween("zoom",function(){var F=this,J=arguments,P=B(F,J).event(K),ge=g.apply(F,J),q=Y==null?y(ge):typeof Y=="function"?Y.apply(F,J):Y,$=Math.max(ge[1][0]-ge[0][0],ge[1][1]-ge[0][1]),j=F.__zoom,te=typeof H=="function"?H.apply(F,J):H,Q=a(j.invert(q).concat($/j.k),te.invert(q).concat($/te.k));return function(ie){if(ie===1)ie=te;else{var he=Q(ie),ne=$/he[2];ie=new nA(ne,q[0]-he[0]*ne,q[1]-he[1]*ne)}P.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=dg(this.that).datum();s.call(R,this.that,new Q1t(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),K=this.__zoom,F=Math.max(C[0],Math.min(C[1],K.k*Math.pow(2,i.apply(this,arguments)))),J=zg(R);if(Y.wheel)(Y.mouse[0][0]!==J[0]||Y.mouse[0][1]!==J[1])&&(Y.mouse[1]=K.invert(Y.mouse[0]=J)),clearTimeout(Y.wheel);else{if(K.k===F)return;Y.mouse=[J,K.invert(J)],av(this),Y.start()}sZ(R),Y.wheel=setTimeout(P,d),Y.zoom("mouse",I(p(b(K,F),Y.mouse[0],Y.mouse[1]),Y.extent,r));function P(){Y.wheel=null,Y.end()}}function w(R,...H){if(c||!e.apply(this,arguments))return;var Y=R.currentTarget,K=B(this,H,!0).event(R),F=dg(R.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",$,!0),J=zg(R,Y),P=R.clientX,ge=R.clientY;ZN(R.view),wD(R),K.mouse=[J,this.__zoom.invert(J)],av(this),K.start();function q(j){if(sZ(j),!K.moved){var te=j.clientX-P,Q=j.clientY-ge;K.moved=te*te+Q*Q>h}K.event(j).zoom("mouse",I(p(K.that.__zoom,K.mouse[0]=zg(j,Y),K.mouse[1]),K.extent,r))}function $(j){F.on("mousemove.zoom mouseup.zoom",null),GN(j.view,K.moved),sZ(j),K.event(j).end()}}function V(R,...H){if(e.apply(this,arguments)){var Y=this.__zoom,K=zg(R.changedTouches?R.changedTouches[0]:R,this),F=Y.invert(K),J=Y.k*(R.shiftKey?.5:2),P=I(p(b(Y,J),K,F),g.apply(this,H),r);sZ(R),o>0?dg(this).transition().duration(o).call(Z,P,K,R):dg(this).call(f.transform,P,K,R)}}function S(R,...H){if(e.apply(this,arguments)){var Y=R.touches,K=Y.length,F=B(this,H,R.changedTouches.length===K).event(R),J,P,ge,q;for(wD(R),P=0;Pr;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/rWt),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()===gI&&n.lineStyle(n.lineWidth||n._lineStyle.width,Kt("#ffffff")),n.moveTo(0,0),n.lineTo(-(Ei+GC),0),n.moveTo(0,i),n.lineTo(-(Ei+GC),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()===gI&&(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()===gI&&(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${+(Ei+GC)},0`);const r=this.createAxisSVGLine();n.appendChild(r),r.setAttribute("d",`M0,${i} L${+(Ei+GC)},${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])},aWt=(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},DVe=(e,g,I)=>{if(typeof I>"u"&&(I=Number.MAX_SAFE_INTEGER),e.resolutions)return oWt(e.resolutions,g,e.min_pos[0],e.max_pos[0]-2);const i=aWt(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)},AWt=(e,g,I,i,n,C)=>{const r=Math.min(e,n),o=C/2**r,a=1e-7;return xVe(Math.max(0,Math.floor((g.domain()[0]-I)/o)),Math.min(2**r,Math.ceil((g.domain()[1]-I-a)/o)))},sWt=(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=xVe(a,s);return A.length>o&&(console.warn(`Too many visible tiles: ${A.length} truncating to ${o}`),A=A.slice(0,o)),A},lWt=(e,g)=>{if(!e)return[];const I=DVe(e,g,e.max_zoom);if(e.resolutions){const C=e.resolutions.map(a=>+a).sort((a,s)=>s-a);return sWt(C[I],g,e.min_pos[0],e.max_pos[0]).map(a=>[I,a])}return AWt(I,g,e.min_pos[0],e.max_pos[0],e.max_zoom,e.max_width).map(C=>[I,C])},cWt=(e,g)=>{if(e.axis||(e.axis=new pk(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]))},uWt=(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()},dWt=(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),Ji.translate(0,a).scale(o)},hWt=(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 mWt(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 xd={calculate1DVisibleTiles:lWt,calculate1DZoomLevel:DVe,drawAxis:cWt,movedY:uWt,getTilePosAndDimensions:hWt,stretchRects:mWt,zoomedY:dWt},fWt=Object.freeze(Object.defineProperty({__proto__:null,DenseDataExtrema1D:S9,DenseDataExtrema2D:JQ,IS_TRACK_RANGE_SELECTABLE:F0,absToChr:Ti,accessorTransposition:sGe,addArrays:lGe,addClass:UAt,base64ToCanvas:QAt,changeOptions:XRt,chrToAbs:d9,chromInfoBisector:AGe,cloneEvent:cGe,colorDomainToRgbaArray:_c,colorToHex:Kt,colorToRgba:wGe,dataToGenomicLoci:b9,debounce:TQ,decToHexStr:az,dictFromTuples:VGe,dictItems:Tr,dictKeys:Rr,dictValues:Eg,download:PG,expandCombinedTracks:_1,fillInMinWidths:RGe,flatten:Xst,forEach:Hst,forwardEvent:y9,genomeLociToPixels:Tst,genomicRangeToChromosomeChunks:Nst,getAggregationFunction:OQ,getDefaultTrackForDatatype:NQ,getElementDim:YGe,getTiledPlot:Bct,getTrackByUid:Ir,getTrackConfFromHGC:Hlt,getTrackObjById:_Z,getTrackObjectFromHGC:_Q,getTrackPositionByUid:JG,getTrackRenderer:gve,getXylofon:xGe,gradient:DGe,hasClass:u9,hasParent:FGe,hexStrToInt:EGe,intoTheVoid:MGe,isTrackOrChildTrack:zGe,isWithin:MQ,latToY:Elt,lngToX:zlt,loadChromInfos:Mlt,map:FQ,max:Az,maxNonZero:sz,min:PGe,minNonZero:lz,mod:Plt,mountHGComponent:VVe,mountHGComponentAsync:kRt,ndarrayAssign:JGe,ndarrayFlatten:LGe,ndarrayToList:_Ge,numericifyVersion:UGe,objVals:wN,or:_S,parseChromsizesRows:VN,pixiTextToSvg:cz,q:ict,rangeQuery2d:nct,reduce:WGe,relToAbsChromPos:Cct,removeClass:oct,removeHGComponent:NRt,resetD3BrushStyle:kp,rgbToHex:act,scalesCenterAndK:Si,scalesToGenomeLoci:QGe,segmentsToRows:B9,selectedItemsToSize:KB,showMousePosition:sh,some:cct,sum:$l,svgLine:jGe,throttleAndDebounce:$Ge,tileToCanvas:uct,timeout:zQ,toVoid:jo,totalTrackPixelHeight:dct,trackUtils:xd,trimTrailingSlash:RN,valueToColor:PQ,visitPositionedTracks:Is,visitTracks:DQ,waitForJsonComplete:_j,waitForTilesLoaded:E9,waitForTransitionsFinished:wVe},Symbol.toStringTag,{value:"Module"}));function qz(){return qz=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,I)=>N.createElement(bWt,null,i=>N.createElement(e,qz({ref:I},g,{theme:i})))),Jl={"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"},yWt=e=>Xg({[Jl["track-control-active"]]:e.isVisible,[Jl["track-control"]]:!e.isVisible,[Jl["track-control-left"]]:e.isAlignLeft,[Jl["track-control-vertical"]]:e.isVertical,[Jl["track-control-padding-right"]]:e.paddingRight,[Jl["track-control-dark"]]:e.theme===gI}),GR=e=>Xg("no-zoom",Jl["track-control-button"],{[Jl["track-control-button-vertical"]]:e.isVertical});let VD=null,LCe=null;function FVe(e){(!e||!VD||Object.keys(e).some(i=>VD[i]!==e[i]))&&(VD=e,LCe=nz(()=>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:yWt(e)},e.isMoveable&&N.createElement(LCe,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"})))}FVe.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 bk=um(FVe),eP={"center-track":"_center-track_fiu64_1","center-track-container":"_center-track-container_fiu64_6"},Po={"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 ZWt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function UCe(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 J9(e){return J9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},J9(e)}const vR={pointerEvents:"all"};function Qm(e){return e&&e.sourceEvent}let jj=function(e){SWt(I,e);var g=wWt(I);function I(i){var n;return ZWt(this,I),n=g.call(this,i),n.state={isVisible:!1},n.brushBehaviorX=SN().on("brush",n.brushedX.bind(Nl(n))).on("end",n.brushedXEnded.bind(Nl(n))),n.brushBehaviorY=PS().on("brush",n.brushedY.bind(Nl(n))).on("end",n.brushedYEnded.bind(Nl(n))),n.brushBehaviorXY=BQ().on("start",n.brushStarted.bind(Nl(n))).on("brush",n.brushedXY.bind(Nl(n))).on("end",n.brushedXYEnded.bind(Nl(n))),n}return GWt(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),kp(this.brushElX,Po["track-range-selection-group-brush-selection"]),kp(this.brushElY,Po["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,kp(this.brushElXY,Po["track-range-selection-group-brush-selection"]))}},{key:"brushedX",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Qm(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,!(!Qm(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,!(!Qm(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,!(!Qm(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,!(!Qm(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){Qm(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=>F0(s)).reduce(_S,!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=Xg(!this.props.is1dRangeSelection&&Po["track-range-selection-group-inactive"]),a=Xg(this.props.is1dRangeSelection&&Po["track-range-selection-group-inactive"]);return N.createElement("div",{className:Xg(this.props.className,eP["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:Po[r],style:{height:this.props.height,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"},N.createElement("g",{ref:s=>{this.brushElX=dg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElY=dg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElXY=dg(s)},className:a})),this.props.editable&&N.createElement(bk,{imgStyleAdd:vR,imgStyleClose:vR,imgStyleMove:vR,imgStyleSettings:vR,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);jj.defaultProps={className:"center-track",configTrackMenuId:null,is1dRangeSelection:!1,rangeSelectionEnd:L.bool,isRangeSelectionActive:!1,scaleX:e=>e,scaleY:e=>e};jj.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 gP(){return gP=Object.assign?Object.assign.bind():function(e){for(var g=1;g({event:"fake",handler:jo}),unsubscribe:jo,clear:jo},{Provider:WWt,Consumer:XWt}=N.createContext($j),ey=e=>N.forwardRef((g,I)=>N.createElement(XWt,null,i=>N.createElement(e,gP({ref:I},g,{pubSub:i})))),HWt={"drag-listening-div-active":"_drag-listening-div-active_19gkt_1"};function TWt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function QCe(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 O9(e){return O9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},O9(e)}let qj=function(e){KWt(I,e);var g=xWt(I);function I(i){var n;return TWt(this,I),n=g.call(this,i),n.state={dragOnTop:!1},n}return NWt(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:Xg("DragListeningDiv",{[HWt["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:sg.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);qj.defaultProps={enabled:!1,style:{},draggingHappening:{},onTrackDropped:()=>{}};qj.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 BR=ey(qj),ku={"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"},MWt="_horizontalList_1y7td_7",zWt="_list_1y7td_14",PWt="_stylizedList_1y7td_21",JWt="_stylizedItem_1y7td_28",OWt="_stylizedHelper_1y7td_39",_Wt="_horizontalItem_1y7td_44",LWt="_domain_1y7td_60",Jo={"tiled-plot":"_tiled-plot_1y7td_1",horizontalList:MWt,list:zWt,stylizedList:PWt,stylizedItem:JWt,stylizedHelper:OWt,horizontalItem:_Wt,"resizable-track":"_resizable-track_1y7td_55",domain:LWt};function UWt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function jCe(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 _9(e){return _9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_9(e)}const SR={pointerEvents:"all"};let EVe=function(e){qWt(I,e);var g=eXt(I);function I(i){var n;return UWt(this,I),n=g.call(this,i),n.state={hovering:!1},n}return QWt(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:Xg("gallery-tracks",ku["gallery-tracks"])},this.props.tracks&&this.props.tracks.map((n,C)=>N.createElement("div",{key:n.uid||C,className:ku["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:ku["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,left:0,height:n.height}}),N.createElement("div",{className:ku["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,bottom:0,width:n.height}}),N.createElement("div",{className:ku["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{right:0,bottom:0,left:0,height:n.height}}),N.createElement("div",{className:ku["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,bottom:0,left:0,width:n.height}}),N.createElement("div",{className:ku["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(bk,{configMenuVisible:!0,imgStyleAdd:SR,imgStyleClose:SR,imgStyleMove:SR,imgStyleSettings:SR,isMoveable:!1,isVisible:this.state.hovering,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:n.uid||C}))))}}]),I}(N.Component);EVe.propTypes={editable:L.bool,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,tracks:L.array};function iXt(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{}),this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.defaultMouseMoveHandler.bind(this))),this.isLeftModified=!1}return nXt(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]),MQ(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 oXt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qCe(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 qb(e){return qb=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},qb(e)}function fXt(e,g){const I=x0(g,e);return gm(`.${I}`,e)(e)}function pXt(e,g){const I=e.map(C=>+C).sort((C,r)=>r-C),i=I[g],n=I[I.length-1];return fXt(i,n)}function bXt(e,g,I,i){const n=g/(2**e*I);if(!Number.isNaN(n)){const C=g/(2**i*I),r=x0(C,n);return gm(`.${r}`,n)(n)}return console.warn("NaN resolution, screen is probably too small."),""}let fC=function(e){cXt(I,e);var g=uXt(I);function I(i,n){var C;oXt(this,I),C=g.call(this,i,n);const{scene:r}=i;C.scene=r,C.delayDrawing=!1,C.pBase=new ot.PIXI.Graphics,C.pMasked=new ot.PIXI.Graphics,C.pMask=new ot.PIXI.Graphics,C.pMain=new ot.PIXI.Graphics,C.pBorder=new ot.PIXI.Graphics,C.pBackground=new ot.PIXI.Graphics,C.pForeground=new ot.PIXI.Graphics,C.pLabel=new ot.PIXI.Graphics,C.pMobile=new ot.PIXI.Graphics,C.pAxis=new ot.PIXI.Graphics,C.pMouseOver=new ot.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 ot.PIXI.Text(o,{fontSize:`${C.labelTextFontSize}px`,fontFamily:C.labelTextFontFamily,fill:"black"}),C.pLabel.addChild(C.labelText),C.errorText=new ot.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 aXt(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){IW(qb(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&&Nlt(this.tilesetInfo)&&this.tilesetInfo.bins_per_dimension){const d=bXt(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&&klt(this.tilesetInfo)){const d=pXt(this.tilesetInfo.resolutions,this.calculateZoomLevel());s+=` + `)}return ye}(),enumerable:!1,configurable:!1})}tt("node","Consider using the getElement() method instead."),tt("nodes","Consider using the getElements() method instead."),tt("renderer",""),tt("options",""),tt("complexSelector",""),e.default=_e})(j4);var HRe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=n;var g=e4,i=I(g);function I(r){return r&&r.__esModule?r:{default:r}}function n(r,C){return new i.default(r,null,C)}})(HRe);var TRe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=n;var g=j4,i=I(g);function I(r){return r&&r.__esModule?r:{default:r}}function n(r,C){return new i.default(r,null,C)}})(TRe);var NRe={};(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=o;var g=M0,i=C(g),I=cu,n=C(I),r=tw;function C(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,r.loadCheerioRoot)(c)}})(NRe);var vVt=e4,BVt=ey(vVt),SVt=j4,wVt=ey(SVt),RVt=Lwe,VVt=ey(RVt),WVt=HRe,XVt=ey(WVt),HVt=TRe,TVt=ey(HVt),NVt=NRe,kVt=ey(NVt),YVt=sm;function ey(e){return e&&e.__esModule?e:{default:e}}var KVt={render:kVt.default,shallow:TVt.default,mount:XVt.default,ShallowWrapper:wVt.default,ReactWrapper:BVt.default,configure:YVt.merge,EnzymeAdapter:VVt.default};const $4=100,FVt=(e,g,i,I)=>{for(const{viewId:n,trackId:r,track:C}of e.instance().iterateOverTracks())n===g&&r===i&&(C.options={...C.options,...I});e.setState(e.instance().state)},DVt=e=>{for(const g of e.iterateOverTracks())if(Ave(e,g.viewId,g.trackId).activeTransitions>0)return!0;return!1},kRe=(e,g)=>{DVt(e)?setTimeout(()=>{kRe(e,g)},$4):g()},q4=e=>{FB>0?setTimeout(()=>q4(e),$4):e()},xVt=e=>{for(const g of e.iterateOverTracks()){let i=qQ(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},PX=(e,g)=>{xVt(e)?setTimeout(()=>{PX(e,g)},$4):g()},YRe=(e,g,i,I,n={})=>{const{style:r="width:800px; background-color: lightgreen;",bounded:C=!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",r),a.setAttribute("id","simple-hg-component");const s=KVt.mount(N.createElement(dy,{options:{bounded:C},viewConfig:i}),{attachTo:a});return s.update(),q4(()=>{if(o){const A=()=>setTimeout(()=>{I()},1e3);PX(s.instance(),A)}else PX(s.instance(),I)}),[a,s]},EVt=e=>{e&&(ji.unmountComponentAtNode(e),document.body.removeChild(e))};async function MVt(e,g,i,I){let n;return await new Promise(r=>{n=YRe(e,g,i,r,I)}),n}var qb=0,jZ=0,sZ=0,KRe=1e3,JX,$Z,OX=0,hh=0,bk=0,LB=typeof performance=="object"&&performance.now?performance:Date,FRe=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function ej(){return hh||(FRe(zVt),hh=LB.now()+bk)}function zVt(){hh=0}function _X(){this._call=this._time=this._next=null}_X.prototype=DRe.prototype={constructor:_X,restart:function(e,g,i){if(typeof e!="function")throw new TypeError("callback is not a function");i=(i==null?ej():+i)+(g==null?0:+g),!this._next&&$Z!==this&&($Z?$Z._next=this:JX=this,$Z=this),this._call=e,this._time=i,qz()},stop:function(){this._call&&(this._call=null,this._time=1/0,qz())}};function DRe(e,g,i){var I=new _X;return I.restart(e,g,i),I}function PVt(){ej(),++qb;for(var e=JX,g;e;)(g=hh-e._time)>=0&&e._call.call(void 0,g),e=e._next;--qb}function Lre(){hh=(OX=LB.now())+bk,qb=jZ=0;try{PVt()}finally{qb=0,OVt(),hh=0}}function JVt(){var e=LB.now(),g=e-OX;g>KRe&&(bk-=g,OX=e)}function OVt(){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);$Z=e,qz(I)}function qz(e){if(!qb){jZ&&(jZ=clearTimeout(jZ));var g=e-hh;g>24?(e<1/0&&(jZ=setTimeout(Lre,e-LB.now()-bk)),sZ&&(sZ=clearInterval(sZ))):(sZ||(OX=LB.now(),sZ=setInterval(JVt,KRe)),qb=1,FRe(Lre))}}function Ure(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 _Vt=x0("start","end","cancel","interrupt"),LVt=[],xRe=0,eP=1,tP=2,IW=3,Qre=4,gP=5,nW=6;function yk(e,g,i,I,n,r){var C=e.__transition;if(!C)e.__transition={};else if(i in C)return;UVt(e,i,{name:g,index:I,group:n,on:_Vt,tween:LVt,time:r.time,delay:r.delay,duration:r.duration,ease:r.ease,timer:null,state:xRe})}function tj(e,g){var i=ya(e,g);if(i.state>xRe)throw new Error("too late; already scheduled");return i}function TA(e,g){var i=ya(e,g);if(i.state>IW)throw new Error("too late; already running");return i}function ya(e,g){var i=e.__transition;if(!i||!(i=i[g]))throw new Error("transition not found");return i}function UVt(e,g,i){var I=e.__transition,n;I[g]=i,i.timer=DRe(r,0,i.time);function r(s){i.state=eP,i.timer.restart(C,i.delay,i.time),i.delay<=s&&C(s-i.delay)}function C(s){var A,l,c,u;if(i.state!==eP)return a();for(A in I)if(u=I[A],u.name===i.name){if(u.state===IW)return Ure(C);u.state===Qre?(u.state=nW,u.timer.stop(),u.on.call("interrupt",e,e.__data__,u.index,u.group),delete I[A]):+AtP&&I.state=0&&(g=g.slice(0,i)),!g||g==="start"})}function B1t(e,g,i){var I,n,r=v1t(g)?tj:TA;return function(){var C=r(this,e),o=C.on;o!==I&&(n=(I=o).copy()).on(g,i),C.on=n}}function S1t(e,g){var i=this._id;return arguments.length<2?ya(this.node(),i).on.on(e):this.each(B1t(i,e,g))}function w1t(e){return function(){var g=this.parentNode;for(var i in this.__transition)if(+i!==e)return;g&&g.removeChild(this)}}function R1t(){return this.on("end.remove",w1t(this._id))}function V1t(e){var g=this._name,i=this._id;typeof e!="function"&&(e=KS(e));for(var I=this._groups,n=I.length,r=new Array(n),C=0;CeP&&I.name===g)return new vA([[e]],eWt,g,+n)}return null}const gWt=Object.freeze(Object.defineProperty({__proto__:null,active:tWt,interrupt:av,transition:zRe},Symbol.toStringTag,{value:"Module"})),BV=e=>()=>e;function iWt(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 nA(e,g,i){this.k=e,this.x=g,this.y=i}nA.prototype={constructor:nA,scale:function(e){return e===1?this:new nA(this.k*e,this.x,this.y)},translate:function(e,g){return e===0&g===0?this:new nA(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 JI=new nA(1,0,0);JRe.prototype=nA.prototype;function JRe(e){for(;!e.__zoom;)if(!(e=e.parentNode))return JI;return e.__zoom}function WD(e){e.stopImmediatePropagation()}function lZ(e){e.preventDefault(),e.stopImmediatePropagation()}function IWt(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function nWt(){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 jre(){return this.__zoom||JI}function rWt(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function CWt(){return navigator.maxTouchPoints||"ontouchstart"in this}function oWt(e,g,i){var I=e.invertX(g[0][0])-i[0][0],n=e.invertX(g[1][0])-i[1][0],r=e.invertY(g[0][1])-i[0][1],C=e.invertY(g[1][1])-i[1][1];return e.translate(n>I?(I+n)/2:Math.min(0,I)||Math.max(0,n),C>r?(r+C)/2:Math.min(0,r)||Math.max(0,C))}function iP(){var e=IWt,g=nWt,i=oWt,I=rWt,n=CWt,r=[0,1/0],C=[[-1/0,-1/0],[1/0,1/0]],o=250,a=iIt,s=x0("start","zoom","end"),A,l,c,u=500,d=150,h=0,m=10;function f(V){V.property("__zoom",jre).on("wheel.zoom",v,{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,Y,K){var x=V.selection?V.selection():V;x.property("__zoom",jre),V!==x?Z(V,H,Y,K):x.interrupt().each(function(){B(this,arguments).event(K).start().zoom(null,typeof H=="function"?H.apply(this,arguments):H).end()})},f.scaleBy=function(V,H,Y,K){f.scaleTo(V,function(){var x=this.__zoom.k,J=typeof H=="function"?H.apply(this,arguments):H;return x*J},Y,K)},f.scaleTo=function(V,H,Y,K){f.transform(V,function(){var x=g.apply(this,arguments),J=this.__zoom,P=Y==null?y(x):typeof Y=="function"?Y.apply(this,arguments):Y,ge=J.invert(P),q=typeof H=="function"?H.apply(this,arguments):H;return i(p(b(J,q),P,ge),x,C)},Y,K)},f.translateBy=function(V,H,Y,K){f.transform(V,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),C)},null,K)},f.translateTo=function(V,H,Y,K,x){f.transform(V,function(){var J=g.apply(this,arguments),P=this.__zoom,ge=K==null?y(J):typeof K=="function"?K.apply(this,arguments):K;return i(JI.translate(ge[0],ge[1]).scale(P.k).translate(typeof H=="function"?-H.apply(this,arguments):-H,typeof Y=="function"?-Y.apply(this,arguments):-Y),J,C)},K,x)};function b(V,H){return H=Math.max(r[0],Math.min(r[1],H)),H===V.k?V:new nA(H,V.x,V.y)}function p(V,H,Y){var K=H[0]-Y[0]*V.k,x=H[1]-Y[1]*V.k;return K===V.x&&x===V.y?V:new nA(V.k,K,x)}function y(V){return[(+V[0][0]+ +V[1][0])/2,(+V[0][1]+ +V[1][1])/2]}function Z(V,H,Y,K){V.on("start.zoom",function(){B(this,arguments).event(K).start()}).on("interrupt.zoom end.zoom",function(){B(this,arguments).event(K).end()}).tween("zoom",function(){var x=this,J=arguments,P=B(x,J).event(K),ge=g.apply(x,J),q=Y==null?y(ge):typeof Y=="function"?Y.apply(x,J):Y,$=Math.max(ge[1][0]-ge[0][0],ge[1][1]-ge[0][1]),j=x.__zoom,te=typeof H=="function"?H.apply(x,J):H,Q=a(j.invert(q).concat($/j.k),te.invert(q).concat($/te.k));return function(Ie){if(Ie===1)Ie=te;else{var he=Q(Ie),ne=$/he[2];Ie=new nA(ne,q[0]-he[0]*ne,q[1]-he[1]*ne)}P.zoom(null,Ie)}})}function B(V,H,Y){return!Y&&V.__zooming||new G(V,H)}function G(V,H){this.that=V,this.args=H,this.active=0,this.sourceEvent=null,this.extent=g.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=dg(this.that).datum();s.call(V,this.that,new iWt(V,{sourceEvent:this.sourceEvent,target:f,type:V,transform:this.that.__zoom,dispatch:s}),H)}};function v(V,...H){if(!e.apply(this,arguments))return;var Y=B(this,H).event(V),K=this.__zoom,x=Math.max(r[0],Math.min(r[1],K.k*Math.pow(2,I.apply(this,arguments)))),J=zg(V);if(Y.wheel)(Y.mouse[0][0]!==J[0]||Y.mouse[0][1]!==J[1])&&(Y.mouse[1]=K.invert(Y.mouse[0]=J)),clearTimeout(Y.wheel);else{if(K.k===x)return;Y.mouse=[J,K.invert(J)],av(this),Y.start()}lZ(V),Y.wheel=setTimeout(P,d),Y.zoom("mouse",i(p(b(K,x),Y.mouse[0],Y.mouse[1]),Y.extent,C));function P(){Y.wheel=null,Y.end()}}function w(V,...H){if(c||!e.apply(this,arguments))return;var Y=V.currentTarget,K=B(this,H,!0).event(V),x=dg(V.view).on("mousemove.zoom",q,!0).on("mouseup.zoom",$,!0),J=zg(V,Y),P=V.clientX,ge=V.clientY;BN(V.view),WD(V),K.mouse=[J,this.__zoom.invert(J)],av(this),K.start();function q(j){if(lZ(j),!K.moved){var te=j.clientX-P,Q=j.clientY-ge;K.moved=te*te+Q*Q>h}K.event(j).zoom("mouse",i(p(K.that.__zoom,K.mouse[0]=zg(j,Y),K.mouse[1]),K.extent,C))}function $(j){x.on("mousemove.zoom mouseup.zoom",null),SN(j.view,K.moved),lZ(j),K.event(j).end()}}function R(V,...H){if(e.apply(this,arguments)){var Y=this.__zoom,K=zg(V.changedTouches?V.changedTouches[0]:V,this),x=Y.invert(K),J=Y.k*(V.shiftKey?.5:2),P=i(p(b(Y,J),K,x),g.apply(this,H),C);lZ(V),o>0?dg(this).transition().duration(o).call(Z,P,K,V):dg(this).call(f.transform,P,K,V)}}function S(V,...H){if(e.apply(this,arguments)){var Y=V.touches,K=Y.length,x=B(this,H,V.changedTouches.length===K).event(V),J,P,ge,q;for(WD(V),P=0;PC;nthis.tickValues.length;){const C=this.axisTexts.pop();this.pAxis.removeChild(C),C.destroy(!0)}}},{key:"calculateAxisTickValues",value:function(i,I){const n=Math.max(Math.ceil(I/uWt),1);let r=i.ticks(n);return r.length<1&&(r=i.ticks(n+1),r.length>1&&(r=[r[0]])),r}},{key:"drawAxisLeft",value:function(i,I){this.startAxis(I),this.createAxisTexts(i,I);const n=this.pAxis;this.track.getTheme()===gi&&n.lineStyle(n.lineWidth||n._lineStyle.width,Kt("#ffffff")),n.moveTo(0,0),n.lineTo(-(EI+Zr),0),n.moveTo(0,I),n.lineTo(-(EI+Zr),I);for(let r=0;r=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()===gi&&(n="#cccccc");const r=document.createElement("path");return r.setAttribute("fill","transparent"),r.setAttribute("stroke",n),r.setAttribute("id","axis-line"),r.setAttribute("d",`M0,0 L0,${i}`),I.appendChild(r),I}},{key:"createAxisSVGLine",value:function(){let i="black";this.track&&this.track.options.lineStrokeColor&&(i=this.track.options.lineStrokeColor),this.track.getTheme()===gi&&(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),r=this.createAxisSVGLine();n.appendChild(r),r.setAttribute("d",`M0,0 L${+(EI+Zr)},0`);const C=this.createAxisSVGLine();n.appendChild(C),C.setAttribute("d",`M0,${I} L${+(EI+Zr)},${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],r=i.map(o=>(g.domain()[1]-g.domain()[0])/o).map(o=>o/I),C=r.filter(o=>o<1);return C.length===0?0:r.indexOf(C[C.length-1])},hWt=(e,g,i,I)=>{const n=e.range()[1]-e.range()[0],r=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(r)/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},_Re=(e,g,i)=>{if(typeof i>"u"&&(i=Number.MAX_SAFE_INTEGER),e.resolutions)return dWt(e.resolutions,g,e.min_pos[0],e.max_pos[0]-2);const I=hWt(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)},mWt=(e,g,i,I,n,r)=>{const C=Math.min(e,n),o=r/2**C,a=1e-7;return ORe(Math.max(0,Math.floor((g.domain()[0]-i)/o)),Math.min(2**C,Math.ceil((g.domain()[1]-i-a)/o)))},fWt=(e,g,i,I=Number.MAX_VALUE,n=256)=>{const C=e*n,o=20,a=Math.max(0,Math.floor((g.domain()[0]-i)/C)),s=Math.ceil(Math.min(I,g.domain()[1]-i-1e-7)/C);let A=ORe(a,s);return A.length>o&&(console.warn(`Too many visible tiles: ${A.length} truncating to ${o}`),A=A.slice(0,o)),A},pWt=(e,g)=>{if(!e)return[];const i=_Re(e,g,e.max_zoom);if(e.resolutions){const r=e.resolutions.map(a=>+a).sort((a,s)=>s-a);return fWt(r[i],g,e.min_pos[0],e.max_pos[0]).map(a=>[i,a])}return mWt(i,g,e.min_pos[0],e.max_pos[0],e.max_zoom,e.max_width).map(r=>[i,r])},bWt=(e,g)=>{if(e.axis||(e.axis=new Zk(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]))},yWt=(e,g)=>{const i=e.valueScaleTransform,{y:I,k:n}=i,r=e.dimensions[1];I+g/n>-(n-1)*r&&I+g/n<0&&(e.valueScaleTransform=i.translate(0,g/n)),Object.values(e.fetchedTiles).forEach(C=>{C.graphics.position.y=e.valueScaleTransform.y}),e.animate()},ZWt=(e,g,i,I)=>{const n=i.k,r=i.y,C=(e-r)/n,o=Math.max(n/g,1);let a=n*C+r-o*C;return a=Math.max(a,-(o-1)*I),a=Math.min(a,0),JI.translate(0,a).scale(o)},GWt=(e,g)=>{const i=+g.split(".")[0],I=+g.split(".")[1],n=e.max_width,r=e.min_pos[0],C=n/2**i;return{tileX:r+I*C,tileWidth:C}};function vWt(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 r=(i.drawnAtScale.domain()[1]-i.drawnAtScale.domain()[0])/(e._xScale.domain()[1]-e._xScale.domain()[0]);if(r>2||r<.5)e.renderTile(i);else{const o=e._xScale.domain().map(i.drawnAtScale)[0];for(const a of g)a(i).scale.x=r,a(i).x=-o*r}})}const Kd={calculate1DVisibleTiles:pWt,calculate1DZoomLevel:_Re,drawAxis:bWt,movedY:yWt,getTilePosAndDimensions:GWt,stretchRects:vWt,zoomedY:ZWt},BWt=Object.freeze(Object.defineProperty({__proto__:null,DenseDataExtrema1D:VX,DenseDataExtrema2D:jQ,IS_TRACK_RANGE_SELECTABLE:E0,absToChr:TI,accessorTransposition:pGe,addArrays:bGe,addClass:gst,base64ToCanvas:ist,changeOptions:FVt,chrToAbs:fX,chromInfoBisector:fGe,cloneEvent:yGe,colorDomainToRgbaArray:Oc,colorToHex:Kt,colorToRgba:kGe,dataToGenomicLoci:GX,debounce:DQ,decToHexStr:uz,dictFromTuples:YGe,dictItems:HC,dictKeys:RC,dictValues:Eg,download:PG,expandCombinedTracks:Q1,fillInMinWidths:KGe,flatten:Fst,forEach:Dst,forwardEvent:vX,genomeLociToPixels:xst,genomicRangeToChromosomeChunks:Est,getAggregationFunction:$Q,getDefaultTrackForDatatype:xQ,getElementDim:PGe,getTiledPlot:Hct,getTrackByUid:gC,getTrackConfFromHGC:Dlt,getTrackObjById:LZ,getTrackObjectFromHGC:qQ,getTrackPositionByUid:JG,getTrackRenderer:Ave,getXylofon:OGe,gradient:_Ge,hasClass:mX,hasParent:LGe,hexStrToInt:UGe,intoTheVoid:QGe,isTrackOrChildTrack:jGe,isWithin:LQ,latToY:Llt,lngToX:Qlt,loadChromInfos:Ult,map:OQ,max:dz,maxNonZero:hz,min:$Ge,minNonZero:mz,mod:jlt,mountHGComponent:YRe,mountHGComponentAsync:MVt,ndarrayAssign:qGe,ndarrayFlatten:gve,ndarrayToList:tve,numericifyVersion:ive,objVals:WN,or:QS,parseChromsizesRows:XN,pixiTextToSvg:fz,q:sct,rangeQuery2d:lct,reduce:FGe,relToAbsChromPos:cct,removeClass:dct,removeHGComponent:EVt,resetD3BrushStyle:Yp,rgbToHex:hct,scalesCenterAndK:SI,scalesToGenomeLoci:Ive,segmentsToRows:RX,selectedItemsToSize:xB,showMousePosition:Ah,some:bct,sum:$l,svgLine:nve,throttleAndDebounce:rve,tileToCanvas:yct,timeout:UQ,toVoid:jo,totalTrackPixelHeight:Zct,trackUtils:Kd,trimTrailingSlash:HN,valueToColor:QQ,visitPositionedTracks:is,visitTracks:JQ,waitForJsonComplete:q4,waitForTilesLoaded:PX,waitForTransitionsFinished:kRe},Symbol.toStringTag,{value:"Module"}));function IP(){return IP=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,i)=>N.createElement(wWt,null,I=>N.createElement(e,IP({ref:i},g,{theme:I})))),Jl={"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"},RWt=e=>Xg({[Jl["track-control-active"]]:e.isVisible,[Jl["track-control"]]:!e.isVisible,[Jl["track-control-left"]]:e.isAlignLeft,[Jl["track-control-vertical"]]:e.isVertical,[Jl["track-control-padding-right"]]:e.paddingRight,[Jl["track-control-dark"]]:e.theme===gi}),SV=e=>Xg("no-zoom",Jl["track-control-button"],{[Jl["track-control-button-vertical"]]:e.isVertical});let XD=null,eCe=null;function LRe(e){(!e||!XD||Object.keys(e).some(I=>XD[I]!==e[I]))&&(XD=e,eCe=Az(()=>N.createElement("svg",{className:SV(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:RWt(e)},e.isMoveable&&N.createElement(eCe,null),N.createElement("svg",{ref:I=>{g=I},className:SV(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:SV(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:SV(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"})))}LRe.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 Gk=cm(LRe),nP={"center-track":"_center-track_fiu64_1","center-track-container":"_center-track-container_fiu64_6"},Po={"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 VWt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tCe(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 LX(e){return LX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},LX(e)}const wV={pointerEvents:"all"};function Um(e){return e&&e.sourceEvent}let ij=function(e){TWt(i,e);var g=NWt(i);function i(I){var n;return VWt(this,i),n=g.call(this,I),n.state={isVisible:!1},n.brushBehaviorX=VN().on("brush",n.brushedX.bind(Nl(n))).on("end",n.brushedXEnded.bind(Nl(n))),n.brushBehaviorY=_S().on("brush",n.brushedY.bind(Nl(n))).on("end",n.brushedYEnded.bind(Nl(n))),n.brushBehaviorXY=XQ().on("start",n.brushStarted.bind(Nl(n))).on("brush",n.brushedXY.bind(Nl(n))).on("end",n.brushedXYEnded.bind(Nl(n))),n}return WWt(i,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush2d()}},{key:"shouldComponentUpdate",value:function(n,r){if(this.rangeSelectionTriggeredXY){if(this.rangeSelectionTriggeredXY=!1,this.rangeSelectionTriggeredXYEnd){const C=n.rangeSelection[0]||null;this.moveBrushXY([C,n.rangeSelection[1]],!0),this.rangeSelectionTriggeredXYEnd=!1}return this.state!==r}if(this.props.rangeSelection!==n.rangeSelection){const C=n.rangeSelection[0]||null;this.props.is1dRangeSelection?(this.rangeSelectionTriggeredX||this.moveBrushX(C,n.rangeSelectionEnd),this.rangeSelectionTriggeredXEnd&&this.moveBrushX(C,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredY||this.moveBrushY(C,n.rangeSelectionEnd),this.rangeSelectionTriggeredYEnd&&this.moveBrushY(C,n.rangeSelectionEnd,!0),this.rangeSelectionTriggeredX=!1,this.rangeSelectionTriggeredXEnd=!1,this.rangeSelectionTriggeredY=!1,this.rangeSelectionTriggeredYEnd=!1):this.moveBrushXY([C,n.rangeSelection[1]],n.rangeSelectionEnd);const o=this.props.is1dRangeSelection&&!n.is1dRangeSelection&&C===null;return this.state!==r||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),Yp(this.brushElX,Po["track-range-selection-group-brush-selection"]),Yp(this.brushElY,Po["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,Yp(this.brushElXY,Po["track-range-selection-group-brush-selection"]))}},{key:"brushedX",value:function(n){const r=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Um(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||r)&&(this.rangeSelectionTriggeredX=!0,this.props.onRangeSelectionX(n.selection))}},{key:"brushedXEnded",value:function(n){const r=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!Um(n)||!this.props.onRangeSelectionX||!this.props.is1dRangeSelection||r)&&(this.rangeSelectionTriggeredX=!0,this.rangeSelectionTriggeredXEnd=!0,this.props.onRangeSelectionXEnd(n.selection))}},{key:"brushedY",value:function(n){const r=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Um(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||r)&&(this.rangeSelectionTriggeredY=!0,this.props.onRangeSelectionY(n.selection))}},{key:"brushedYEnded",value:function(n){const r=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,!(!Um(n)||!this.props.onRangeSelectionY||!this.props.is1dRangeSelection||r)&&(this.rangeSelectionTriggeredY=!0,this.rangeSelectionTriggeredYEnd=!0,this.props.onRangeSelectionYEnd(n.selection))}},{key:"brushedXY",value:function(n){const r=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Um(n)||!this.props.onRangeSelectionXY||r||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 r=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelectionXY&&!r&&(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){Um(n)&&this.props.onRangeSelectionStart()}},{key:"moveBrushX",value:function(n,r=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const C=n?[this.props.scaleX(n[0]),this.props.scaleX(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,r?this.brushElX.transition().call(this.brushBehaviorX.move,C):this.brushElX.call(this.brushBehaviorX.move,C)}},{key:"moveBrushY",value:function(n,r=!1){if(!this.brushEl)return;this.brushIs2dBound&&(this.removeBrush2d(),this.addBrush1d());const C=n?[this.props.scaleY(n[0]),this.props.scaleY(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,r?this.brushElY.transition().call(this.brushBehaviorY.move,C):this.brushElY.call(this.brushBehaviorY.move,C)}},{key:"moveBrushXY",value:function(n,r=!1){if(!this.brushEl)return;const C=[[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,r?this.brushElXY.transition().call(this.brushBehaviorXY.move,C):this.brushElXY.call(this.brushBehaviorXY.move,C)}},{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=>E0(s)).reduce(QS,!1),r=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 C="track-range-selection";this.props.isRangeSelectionActive&&(C+=this.props.is1dRangeSelection?"-active-secondary":"-active-primary");const o=Xg(!this.props.is1dRangeSelection&&Po["track-range-selection-group-inactive"]),a=Xg(this.props.is1dRangeSelection&&Po["track-range-selection-group-inactive"]);return N.createElement("div",{className:Xg(this.props.className,nP["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:Po[C],style:{height:this.props.height,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"},N.createElement("g",{ref:s=>{this.brushElX=dg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElY=dg(s)},className:o}),N.createElement("g",{ref:s=>{this.brushElXY=dg(s)},className:a})),this.props.editable&&N.createElement(Gk,{imgStyleAdd:wV,imgStyleClose:wV,imgStyleMove:wV,imgStyleSettings:wV,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:r,uid:this.props.uid}))}}]),i}(N.Component);ij.defaultProps={className:"center-track",configTrackMenuId:null,is1dRangeSelection:!1,rangeSelectionEnd:L.bool,isRangeSelectionActive:!1,scaleX:e=>e,scaleY:e=>e};ij.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 CP(){return CP=Object.assign?Object.assign.bind():function(e){for(var g=1;g({event:"fake",handler:jo}),unsubscribe:jo,clear:jo},{Provider:KWt,Consumer:FWt}=N.createContext(Ij),ty=e=>N.forwardRef((g,i)=>N.createElement(FWt,null,I=>N.createElement(e,CP({ref:i},g,{pubSub:I})))),DWt={"drag-listening-div-active":"_drag-listening-div-active_19gkt_1"};function xWt(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 UX(e){return UX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},UX(e)}let nj=function(e){PWt(i,e);var g=JWt(i);function i(I){var n;return xWt(this,i),n=g.call(this,I),n.state={dragOnTop:!1},n}return EWt(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:Xg("DragListeningDiv",{[DWt["drag-listening-div-active"]]:this.props.enabled}),onDragEnter:()=>{this.setState({dragOnTop:!0})},onDragLeave:()=>{this.setState({dragOnTop:!1})},onDragOver:r=>{r.preventDefault()},onDrop:()=>{if(!this.props.enabled)return;const r=this.props.draggingHappening,C={type:this.props.defaultTrackType,uid:sg.nice(),tilesetUid:r.tilesetUid,server:r.server};this.props.onTrackDropped(C),this.props.pubSub.publish("trackDropped",C)},style:{background:n,opacity:.6,...this.props.style}})}}]),i}(N.Component);nj.defaultProps={enabled:!1,style:{},draggingHappening:{},onTrackDropped:()=>{}};nj.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 RV=ty(nj),Nu={"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"},UWt="_horizontalList_1y7td_7",QWt="_list_1y7td_14",jWt="_stylizedList_1y7td_21",$Wt="_stylizedItem_1y7td_28",qWt="_stylizedHelper_1y7td_39",e9t="_horizontalItem_1y7td_44",t9t="_domain_1y7td_60",Jo={"tiled-plot":"_tiled-plot_1y7td_1",horizontalList:UWt,list:QWt,stylizedList:jWt,stylizedItem:$Wt,stylizedHelper:qWt,horizontalItem:e9t,"resizable-track":"_resizable-track_1y7td_55",domain:t9t};function g9t(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 QX(e){return QX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},QX(e)}const VV={pointerEvents:"all"};let URe=function(e){r9t(i,e);var g=C9t(i);function i(I){var n;return g9t(this,i),n=g.call(this,I),n.state={hovering:!1},n}return i9t(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:Xg("gallery-tracks",Nu["gallery-tracks"])},this.props.tracks&&this.props.tracks.map((n,r)=>N.createElement("div",{key:n.uid||r,className:Nu["gallery-track"],onMouseLeave:this.mouseLeaveHandler.bind(this),style:{top:n.height*r,right:n.height*r,bottom:n.height*r,left:n.height*r}},N.createElement("div",{className:Nu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,left:0,height:n.height}}),N.createElement("div",{className:Nu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,right:0,bottom:0,width:n.height}}),N.createElement("div",{className:Nu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{right:0,bottom:0,left:0,height:n.height}}),N.createElement("div",{className:Nu["gallery-sub-track"],onMouseEnter:this.mouseEnterHandler.bind(this),style:{top:0,bottom:0,left:0,width:n.height}}),N.createElement("div",{className:Nu["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(Gk,{configMenuVisible:!0,imgStyleAdd:VV,imgStyleClose:VV,imgStyleMove:VV,imgStyleSettings:VV,isMoveable:!1,isVisible:this.state.hovering,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:n.uid||r}))))}}]),i}(N.Component);URe.propTypes={editable:L.bool,onCloseTrackMenuOpened:L.func.isRequired,onConfigTrackMenuOpened:L.func.isRequired,tracks:L.array};function s9t(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{}),this.pubSubs.push(this.pubSub.subscribe("app.mouseMove",this.defaultMouseMoveHandler.bind(this))),this.isLeftModified=!1}return l9t(e,[{key:"isWithin",value:function(i,I){let n=i,r=I,C=this.position[0],o=this.position[1];return this.isLeftModified&&(n=I,r=i,C=this.position[1],o=this.position[0]),LQ(n,r,C,this.dimensions[0]+C,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 d9t(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"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 e0(e){return e0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},e0(e)}function B9t(e,g){const i=D0(g,e);return tm(`.${i}`,e)(e)}function S9t(e,g){const i=e.map(r=>+r).sort((r,C)=>C-r),I=i[g],n=i[i.length-1];return B9t(I,n)}function w9t(e,g,i,I){const n=g/(2**e*i);if(!Number.isNaN(n)){const r=g/(2**I*i),C=D0(r,n);return tm(`.${C}`,n)(n)}return console.warn("NaN resolution, screen is probably too small."),""}let mr=function(e){b9t(i,e);var g=y9t(i);function i(I,n){var r;d9t(this,i),r=g.call(this,I,n);const{scene:C}=I;r.scene=C,r.delayDrawing=!1,r.pBase=new ot.PIXI.Graphics,r.pMasked=new ot.PIXI.Graphics,r.pMask=new ot.PIXI.Graphics,r.pMain=new ot.PIXI.Graphics,r.pBorder=new ot.PIXI.Graphics,r.pBackground=new ot.PIXI.Graphics,r.pForeground=new ot.PIXI.Graphics,r.pLabel=new ot.PIXI.Graphics,r.pMobile=new ot.PIXI.Graphics,r.pAxis=new ot.PIXI.Graphics,r.pMouseOver=new ot.PIXI.Graphics,r.scene.addChild(r.pBase),r.pBase.addChild(r.pMasked),r.pMasked.addChild(r.pBackground),r.pMasked.addChild(r.pMain),r.pMasked.addChild(r.pMask),r.pMasked.addChild(r.pMobile),r.pMasked.addChild(r.pBorder),r.pMasked.addChild(r.pLabel),r.pMasked.addChild(r.pForeground),r.pMasked.addChild(r.pMouseOver),r.pBase.addChild(r.pAxis),r.pMasked.mask=r.pMask,r.prevOptions="",r.options=Object.assign(r.options,n);const o=r.getName();return r.labelTextFontFamily="Arial",r.labelTextFontSize=12,r.labelXOffset=0,r.labelText=new ot.PIXI.Text(o,{fontSize:`${r.labelTextFontSize}px`,fontFamily:r.labelTextFontFamily,fill:"black"}),r.pLabel.addChild(r.labelText),r.errorText=new ot.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"red"}),r.errorText.anchor.x=.5,r.errorText.anchor.y=.5,r.pLabel.addChild(r.errorText),r.errorTextText="",r.flipText=!1,r.tilesetInfo=void 0,r}return h9t(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){rW(e0(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,r){this.pMask.clear(),this.pMask.beginFill(),this.pMask.drawRect(n[0],n[1],r[0],r[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 r=Kt(this.options.trackBorderColor?this.options.trackBorderColor:"white");n.lineStyle(this.options.trackBorderWidth,r),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 r=1,C=this.options.backgroundColor;this.options.backgroundColor==="transparent"&&(r=0,C="white");const o=Kt(C);n.beginFill(o,r),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:r="white",labelBackgroundOpacity:C=.5}=this.options;n.beginFill(Kt(r),+C);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&&Elt(this.tilesetInfo)&&this.tilesetInfo.bins_per_dimension){const d=w9t(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&&Mlt(this.tilesetInfo)){const d=S9t(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=sg.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 ZXt(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)):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:sg.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=Eg(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"&&BXt(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:sg.nice(),server:this.dataConfig.server,done:A,ids:C.map(l=>`${this.dataConfig.tilesetUid}.${l}`)},this.pubSub,!0)}).then(A=>{const l=Eg(A)[0].tilesetUid,c={};for(let u=0;u=0;)e[g]=0}var RXt=0,MVe=1,WXt=2,XXt=3,HXt=258,e4=29,sw=256,OB=sw+1+e4,Fp=30,t4=19,zVe=2*OB+1,cd=15,RD=16,TXt=7,g4=256,PVe=16,JVe=17,OVe=18,CP=[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],iW=[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],NXt=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],_Ve=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],kXt=512,is=new Array((OB+2)*2);gy(is);var Av=new Array(Fp*2);gy(Av);var _B=new Array(kXt);gy(_B);var LB=new Array(HXt-XXt+1);gy(LB);var I4=new Array(e4);gy(I4);var L9=new Array(Fp);gy(L9);function WD(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 LVe,UVe,QVe;function XD(e,g){this.dyn_tree=e,this.max_code=0,this.stat_desc=g}function jVe(e){return e<256?_B[e]:_B[256+(e>>>7)]}function UB(e,g){e.pending_buf[e.pending++]=g&255,e.pending_buf[e.pending++]=g>>>8&255}function KC(e,g,I){e.bi_valid>RD-I?(e.bi_buf|=g<>RD-e.bi_valid,e.bi_valid+=I-RD):(e.bi_buf|=g<>>=1,I<<=1;while(--g>0);return I>>>1}function YXt(e){e.bi_valid===16?(UB(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 KXt(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<=cd;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 qVe(e,g,I){var i=new Array(cd+1),n=0,C,r;for(C=1;C<=cd;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]=$Ve(i[o]++,o))}}function xXt(){var e,g,I,i,n,C=new Array(cd+1);for(I=0,i=0;i>=7;i8?UB(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 DXt(e,g,I,i){tRe(e),i&&(UB(e,I),UB(e,~I)),SXt.arraySet(e.pending_buf,e.window,g,I,e.pending),e.pending+=I}function Ire(e,g,I,i){var n=g*2,C=I*2;return e[n]>1;r>=1;r--)HD(e,I,r);s=C;do r=e.heap[1],e.heap[1]=e.heap[e.heap_len--],HD(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++,HD(e,I,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],KXt(e,g),qVe(I,a,e.bl_count)}function nre(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[_Ve[g]*2+1]===0;g--);return e.opt_len+=3*(g+1)+5+5+4,g}function EXt(e,g,I,i){var n;for(KC(e,g-257,5),KC(e,I-1,5),KC(e,i-4,4),n=0;n>>=1)if(g&1&&e.dyn_ltree[I*2]!==0)return tre;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return gre;for(I=32;I0?(e.strm.data_type===VXt&&(e.strm.data_type=MXt(e)),rP(e,e.l_desc),rP(e,e.d_desc),r=FXt(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?gRe(e,g,I,i):e.strategy===wXt||C===n?(KC(e,(MVe<<1)+(i?1:0),3),ire(e,is,Av)):(KC(e,(WXt<<1)+(i?1:0),3),EXt(e,e.l_desc.max_code+1,e.d_desc.max_code+1,r+1),ire(e,e.dyn_ltree,e.dyn_dtree)),eRe(e),i&&tRe(e)}function OXt(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[(LB[I]+sw+1)*2]++,e.dyn_dtree[jVe(g)*2]++),e.last_lit===e.lit_bufsize-1}ty._tr_init=zXt;ty._tr_stored_block=gRe;ty._tr_flush_block=JXt;ty._tr_tally=OXt;ty._tr_align=PXt;function _Xt(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 IRe=_Xt;function LXt(){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 UXt=LXt();function QXt(e,g,I,i){var n=UXt,C=i+I;e^=-1;for(var r=i;r>>8^n[(e^g[r])&255];return e^-1}var iRe=QXt,i4={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=ol,eo=ty,nRe=IRe,kl=iRe,jXt=i4,dm=0,$Xt=1,qXt=3,Nc=4,ore=5,Ua=0,are=1,to=-2,e9t=-3,TD=-5,t9t=-1,g9t=1,wR=2,I9t=3,i9t=4,n9t=0,C9t=2,Zk=8,r9t=9,o9t=15,a9t=8,A9t=29,s9t=256,oP=s9t+1+A9t,l9t=30,c9t=19,u9t=2*oP+1,d9t=15,vg=3,fc=258,ra=fc+vg+1,h9t=32,Gk=42,aP=69,nW=73,CW=91,rW=103,ud=113,$Z=666,Ni=1,lw=2,fh=3,Iy=4,m9t=3;function pc(e,g){return e.msg=jXt[g],g}function Are(e){return(e<<1)-(e>4?9:0)}function ql(e){for(var g=e.length;--g>=0;)e[g]=0}function Yl(e){var g=e.state,I=g.pending;I>e.avail_out&&(I=e.avail_out),I!==0&&(qn.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 un(e,g){eo._tr_flush_block(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,g),e.block_start=e.strstart,Yl(e.strm)}function Ng(e,g){e.pending_buf[e.pending++]=g}function lZ(e,g){e.pending_buf[e.pending++]=g>>>8&255,e.pending_buf[e.pending++]=g&255}function f9t(e,g,I,i){var n=e.avail_in;return n>i&&(n=i),n===0?0:(e.avail_in-=n,qn.arraySet(g,e.input,e.next_in,n,I),e.state.wrap===1?e.adler=nRe(e.adler,g,n,I):e.state.wrap===2&&(e.adler=kl(e.adler,g,n,I)),e.next_in+=n,e.total_in+=n,n)}function CRe(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-ra?e.strstart-(e.w_size-ra):0,s=e.window,A=e.w_mask,l=e.prev,c=e.strstart+fc,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 ph(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-ra)){qn.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=f9t(e.strm,e.window,e.strstart+e.lookahead,C),e.lookahead+=i,e.lookahead+e.insert>=vg)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(ph(e),e.lookahead===0&&g===dm)return Ni;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,un(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-ra&&(un(e,!1),e.strm.avail_out===0))return Ni}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?fh:Iy):(e.strstart>e.block_start&&(un(e,!1),e.strm.avail_out===0),Ni)}function ND(e,g){for(var I,i;;){if(e.lookahead=vg&&(e.ins_h=(e.ins_h<=vg)if(i=eo._tr_tally(e,e.strstart-e.match_start,e.match_length-vg),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=vg){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<=vg&&(e.ins_h=(e.ins_h<4096)&&(e.match_length=vg-1)),e.prev_length>=vg&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-vg,i=eo._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-vg),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=n&&(e.ins_h=(e.ins_h<=vg&&e.strstart>0&&(n=e.strstart-1,i=r[n],i===r[++n]&&i===r[++n]&&i===r[++n])){C=e.strstart+fc;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>=vg?(I=eo._tr_tally(e,1,e.match_length-vg),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(I=eo._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),I&&(un(e,!1),e.strm.avail_out===0))return Ni}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?fh:Iy):e.last_lit&&(un(e,!1),e.strm.avail_out===0)?Ni:lw}function y9t(e,g){for(var I;;){if(e.lookahead===0&&(ph(e),e.lookahead===0)){if(g===dm)return Ni;break}if(e.match_length=0,I=eo._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,I&&(un(e,!1),e.strm.avail_out===0))return Ni}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?fh:Iy):e.last_lit&&(un(e,!1),e.strm.avail_out===0)?Ni:lw}function Xa(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 Ap;Ap=[new Xa(0,0,0,0,p9t),new Xa(4,4,8,4,ND),new Xa(4,5,16,8,ND),new Xa(4,6,32,32,ND),new Xa(4,4,16,16,jm),new Xa(8,16,32,32,jm),new Xa(8,16,128,128,jm),new Xa(8,32,128,256,jm),new Xa(32,128,258,1024,jm),new Xa(32,258,258,4096,jm)];function Z9t(e){e.window_size=2*e.w_size,ql(e.head),e.max_lazy_match=Ap[e.level].max_lazy,e.good_match=Ap[e.level].good_length,e.nice_match=Ap[e.level].nice_length,e.max_chain_length=Ap[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=vg-1,e.match_available=0,e.ins_h=0}function G9t(){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=Zk,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(u9t*2),this.dyn_dtree=new qn.Buf16((2*l9t+1)*2),this.bl_tree=new qn.Buf16((2*c9t+1)*2),ql(this.dyn_ltree),ql(this.dyn_dtree),ql(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new qn.Buf16(d9t+1),this.heap=new qn.Buf16(2*oP+1),ql(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new qn.Buf16(2*oP+1),ql(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 rRe(e){var g;return!e||!e.state?pc(e,to):(e.total_in=e.total_out=0,e.data_type=C9t,g=e.state,g.pending=0,g.pending_out=0,g.wrap<0&&(g.wrap=-g.wrap),g.status=g.wrap?Gk:ud,e.adler=g.wrap===2?0:1,g.last_flush=dm,eo._tr_init(g),Ua)}function oRe(e){var g=rRe(e);return g===Ua&&Z9t(e.state),g}function v9t(e,g){return!e||!e.state||e.state.wrap!==2?to:(e.state.gzhead=g,Ua)}function aRe(e,g,I,i,n,C){if(!e)return to;var r=1;if(g===t9t&&(g=6),i<0?(r=0,i=-i):i>15&&(r=2,i-=16),n<1||n>r9t||I!==Zk||i<8||i>15||g<0||g>9||C<0||C>i9t)return pc(e,to);i===8&&(i=9);var o=new G9t;return e.state=o,o.strm=e,o.wrap=r,o.gzhead=null,o.w_bits=i,o.w_size=1<ore||g<0)return e?pc(e,to):to;if(i=e.state,!e.output||!e.input&&e.avail_in!==0||i.status===$Z&&g!==Nc)return pc(e,e.avail_out===0?TD:to);if(i.strm=e,I=i.last_flush,i.last_flush=g,i.status===Gk)if(i.wrap===2)e.adler=0,Ng(i,31),Ng(i,139),Ng(i,8),i.gzhead?(Ng(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)),Ng(i,i.gzhead.time&255),Ng(i,i.gzhead.time>>8&255),Ng(i,i.gzhead.time>>16&255),Ng(i,i.gzhead.time>>24&255),Ng(i,i.level===9?2:i.strategy>=wR||i.level<2?4:0),Ng(i,i.gzhead.os&255),i.gzhead.extra&&i.gzhead.extra.length&&(Ng(i,i.gzhead.extra.length&255),Ng(i,i.gzhead.extra.length>>8&255)),i.gzhead.hcrc&&(e.adler=kl(e.adler,i.pending_buf,i.pending,0)),i.gzindex=0,i.status=aP):(Ng(i,0),Ng(i,0),Ng(i,0),Ng(i,0),Ng(i,0),Ng(i,i.level===9?2:i.strategy>=wR||i.level<2?4:0),Ng(i,m9t),i.status=ud);else{var r=Zk+(i.w_bits-8<<4)<<8,o=-1;i.strategy>=wR||i.level<2?o=0:i.level<6?o=1:i.level===6?o=2:o=3,r|=o<<6,i.strstart!==0&&(r|=h9t),r+=31-r%31,i.status=ud,lZ(i,r),i.strstart!==0&&(lZ(i,e.adler>>>16),lZ(i,e.adler&65535)),e.adler=1}if(i.status===aP)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=kl(e.adler,i.pending_buf,i.pending-n,n)),Yl(e),n=i.pending,i.pending===i.pending_buf_size));)Ng(i,i.gzhead.extra[i.gzindex]&255),i.gzindex++;i.gzhead.hcrc&&i.pending>n&&(e.adler=kl(e.adler,i.pending_buf,i.pending-n,n)),i.gzindex===i.gzhead.extra.length&&(i.gzindex=0,i.status=nW)}else i.status=nW;if(i.status===nW)if(i.gzhead.name){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(e.adler=kl(e.adler,i.pending_buf,i.pending-n,n)),Yl(e),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(e.adler=kl(e.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.gzindex=0,i.status=CW)}else i.status=CW;if(i.status===CW)if(i.gzhead.comment){n=i.pending;do{if(i.pending===i.pending_buf_size&&(i.gzhead.hcrc&&i.pending>n&&(e.adler=kl(e.adler,i.pending_buf,i.pending-n,n)),Yl(e),n=i.pending,i.pending===i.pending_buf_size)){C=1;break}i.gzindexn&&(e.adler=kl(e.adler,i.pending_buf,i.pending-n,n)),C===0&&(i.status=rW)}else i.status=rW;if(i.status===rW&&(i.gzhead.hcrc?(i.pending+2>i.pending_buf_size&&Yl(e),i.pending+2<=i.pending_buf_size&&(Ng(i,e.adler&255),Ng(i,e.adler>>8&255),e.adler=0,i.status=ud)):i.status=ud),i.pending!==0){if(Yl(e),e.avail_out===0)return i.last_flush=-1,Ua}else if(e.avail_in===0&&Are(g)<=Are(I)&&g!==Nc)return pc(e,TD);if(i.status===$Z&&e.avail_in!==0)return pc(e,TD);if(e.avail_in!==0||i.lookahead!==0||g!==dm&&i.status!==$Z){var a=i.strategy===wR?y9t(i,g):i.strategy===I9t?b9t(i,g):Ap[i.level].func(i,g);if((a===fh||a===Iy)&&(i.status=$Z),a===Ni||a===fh)return e.avail_out===0&&(i.last_flush=-1),Ua;if(a===lw&&(g===$Xt?eo._tr_align(i):g!==ore&&(eo._tr_stored_block(i,0,0,!1),g===qXt&&(ql(i.head),i.lookahead===0&&(i.strstart=0,i.block_start=0,i.insert=0))),Yl(e),e.avail_out===0))return i.last_flush=-1,Ua}return g!==Nc?Ua:i.wrap<=0?are:(i.wrap===2?(Ng(i,e.adler&255),Ng(i,e.adler>>8&255),Ng(i,e.adler>>16&255),Ng(i,e.adler>>24&255),Ng(i,e.total_in&255),Ng(i,e.total_in>>8&255),Ng(i,e.total_in>>16&255),Ng(i,e.total_in>>24&255)):(lZ(i,e.adler>>>16),lZ(i,e.adler&65535)),Yl(e),i.wrap>0&&(i.wrap=-i.wrap),i.pending!==0?Ua:are)}function w9t(e){var g;return!e||!e.state?to:(g=e.state.status,g!==Gk&&g!==aP&&g!==nW&&g!==CW&&g!==rW&&g!==ud&&g!==$Z?pc(e,to):(e.state=null,g===ud?pc(e,e9t):Ua))}function V9t(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!==Gk||i.lookahead))return to;for(r===1&&(e.adler=nRe(e.adler,g,I,0)),i.wrap=0,I>=i.w_size&&(r===0&&(ql(i.head),i.strstart=0,i.block_start=0,i.insert=0),A=new qn.Buf8(i.w_size),qn.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,ph(i);i.lookahead>=vg;){n=i.strstart,C=i.lookahead-(vg-1);do i.ins_h=(i.ins_h<=252?6:Gl>=248?5:Gl>=240?4:Gl>=224?3:Gl>=192?2:1;QB[254]=QB[254]=1;hm.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 lRe(e,g){if(g<65534&&(e.subarray&&sRe||!e.subarray&&ARe))return String.fromCharCode.apply(null,vk.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 lRe(o,i)};hm.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+QB[e[I]]>g?I:g};function R9t(){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 cRe=R9t,sv=NA,lv=ol,AP=hm,sP=i4,W9t=cRe,uRe=Object.prototype.toString,X9t=0,kD=4,Ep=0,sre=1,lre=2,H9t=-1,T9t=0,N9t=8;function bh(e){if(!(this instanceof bh))return new bh(e);this.options=lv.assign({level:H9t,method:N9t,chunkSize:16384,windowBits:15,memLevel:8,strategy:T9t,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 W9t,this.strm.avail_out=0;var I=sv.deflateInit2(this.strm,g.level,g.method,g.windowBits,g.memLevel,g.strategy);if(I!==Ep)throw new Error(sP[I]);if(g.header&&sv.deflateSetHeader(this.strm,g.header),g.dictionary){var i;if(typeof g.dictionary=="string"?i=AP.string2buf(g.dictionary):uRe.call(g.dictionary)==="[object ArrayBuffer]"?i=new Uint8Array(g.dictionary):i=g.dictionary,I=sv.deflateSetDictionary(this.strm,i),I!==Ep)throw new Error(sP[I]);this._dict_set=!0}}bh.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?kD:X9t,typeof e=="string"?I.input=AP.string2buf(e):uRe.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 lv.Buf8(i),I.next_out=0,I.avail_out=i),n=sv.deflate(I,C),n!==sre&&n!==Ep)return this.onEnd(n),this.ended=!0,!1;(I.avail_out===0||I.avail_in===0&&(C===kD||C===lre))&&(this.options.to==="string"?this.onData(AP.buf2binstring(lv.shrinkBuf(I.output,I.next_out))):this.onData(lv.shrinkBuf(I.output,I.next_out)))}while((I.avail_in>0||I.avail_out===0)&&n!==sre);return C===kD?(n=sv.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Ep):(C===lre&&(this.onEnd(Ep),I.avail_out=0),!0)};bh.prototype.onData=function(e){this.chunks.push(e)};bh.prototype.onEnd=function(e){e===Ep&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=lv.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function n4(e,g){var I=new bh(g);if(I.push(e,!0),I.err)throw I.msg||sP[I.err];return I.result}function k9t(e,g){return g=g||{},g.raw=!0,n4(e,g)}function Y9t(e,g){return g=g||{},g.gzip=!0,n4(e,g)}Aw.Deflate=bh;Aw.deflate=n4;Aw.deflateRaw=k9t;Aw.gzip=Y9t;var cw={},Za={},VR=30,K9t=12,x9t=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=VR;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=VR;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=VR;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===hre||u!==1))return-1;for(W[1]=0,A=1;A<$m;A++)W[A+1]=W[A]+X[A];for(l=0;lure||g===mre&&b>dre)return 1;for(;;){Y=A-m,o[l]S?(K=R[H+o[l]],F=w[V+o[l]]):(K=32+64,F=0),y=1<>m)+Z]=Y<<24|K<<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)!==B){for(m===0&&(m=d),v+=c,h=A-m,f=1<ure||g===mre&&b>dre)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},cr=ol,lP=IRe,Ha=iRe,P9t=x9t,cv=z9t,J9t=0,dRe=1,hRe=2,fre=4,O9t=5,RR=6,yh=0,_9t=1,L9t=2,ro=-2,mRe=-3,fRe=-4,U9t=-5,pre=8,pRe=1,bre=2,yre=3,Zre=4,Gre=5,vre=6,Bre=7,Sre=8,wre=9,Vre=10,U9=11,PA=12,KD=13,Rre=14,xD=15,Wre=16,Xre=17,Hre=18,Tre=19,WR=20,XR=21,Nre=22,kre=23,Yre=24,Kre=25,xre=26,DD=27,Dre=28,Fre=29,GI=30,bRe=31,Q9t=32,j9t=852,$9t=592,q9t=15,e2t=q9t;function Ere(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function t2t(){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 yRe(e){var g;return!e||!e.state?ro:(g=e.state,e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=pRe,g.last=0,g.havedict=0,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new cr.Buf32(j9t),g.distcode=g.distdyn=new cr.Buf32($9t),g.sane=1,g.back=-1,yh)}function ZRe(e){var g;return!e||!e.state?ro:(g=e.state,g.wsize=0,g.whave=0,g.wnext=0,yRe(e))}function GRe(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))?ro:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,ZRe(e))}function vRe(e,g){var I,i;return e?(i=new t2t,e.state=i,i.window=null,I=GRe(e,g),I!==yh&&(e.state=null),I):ro}function g2t(e){return vRe(e,e2t)}var Mre=!0,FD,ED;function I2t(e){if(Mre){var g;for(FD=new cr.Buf32(512),ED=new cr.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(cv(dRe,e.lens,0,288,FD,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;cv(hRe,e.lens,0,32,ED,0,e.work,{bits:5}),Mre=!1}e.lencode=FD,e.lenbits=9,e.distcode=ED,e.distbits=5}function BRe(e,g,I,i){var n,C=e.state;return C.window===null&&(C.wsize=1<=C.wsize?(cr.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),cr.arraySet(C.window,g,I-i,n,C.wnext),i-=n,i?(cr.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=Ha(I.check,w,2,0),s=0,A=0,I.mode=bre;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=GI;break}if((s&15)!==pre){e.msg="unknown compression method",I.mode=GI;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=GI;break}I.dmax=1<>8&1),I.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,I.check=Ha(I.check,w,2,0)),s=0,A=0,I.mode=yre;case yre: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=Ha(I.check,w,4,0)),s=0,A=0,I.mode=Zre;case Zre: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=Ha(I.check,w,2,0)),s=0,A=0,I.mode=Gre;case Gre:if(I.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Ha(I.check,w,2,0)),s=0,A=0}else I.head&&(I.head.extra=null);I.mode=vre;case vre: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=Ha(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=Bre;case Bre: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=PA;break;case Vre:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>=A&7,A-=A&7,I.mode=DD;break}for(;A<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,A-=1,s&3){case 0:I.mode=Rre;break;case 1:if(I2t(I),I.mode=WR,g===RR){s>>>=2,A-=2;break e}break;case 2:I.mode=Xre;break;case 3:e.msg="invalid block type",I.mode=GI}s>>>=2,A-=2;break;case Rre: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=xD,g===RR)break e;case xD:I.mode=Wre;case Wre: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=PA;break;case Xre: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=Hre;case Hre: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=cv(J9t,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=Tre;case Tre: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=cv(dRe,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=cv(hRe,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=WR,g===RR)break e;case WR:I.mode=XR;case XR: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,P9t(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===PA&&(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=xre;break}if(b&32){I.back=-1,I.mode=PA;break}if(b&64){e.msg="invalid literal/length code",I.mode=GI;break}I.extra=b&15,I.mode=Nre;case Nre:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=kre;case kre: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=Yre;case Yre: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=Kre;case Kre: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=XR);break;case xre:if(a===0)break e;n[r++]=I.length,a--,I.mode=XR;break;case DD: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 A2t,this.strm.avail_out=0;var I=Mp.inflateInit2(this.strm,g.windowBits);if(I!==ii.Z_OK)throw new Error(cP[I]);if(this.header=new s2t,Mp.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=oW.string2buf(g.dictionary):wRe.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=Mp.inflateSetDictionary(this.strm,g.dictionary),I!==ii.Z_OK)))throw new Error(cP[I])}Zh.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?ii.Z_FINISH:ii.Z_NO_FLUSH,typeof e=="string"?I.input=oW.binstring2buf(e):wRe.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 uv.Buf8(i),I.next_out=0,I.avail_out=i),C=Mp.inflate(I,ii.Z_NO_FLUSH),C===ii.Z_NEED_DICT&&n&&(C=Mp.inflateSetDictionary(this.strm,n)),C===ii.Z_BUF_ERROR&&A===!0&&(C=ii.Z_OK,A=!1),C!==ii.Z_STREAM_END&&C!==ii.Z_OK)return this.onEnd(C),this.ended=!0,!1;I.next_out&&(I.avail_out===0||C===ii.Z_STREAM_END||I.avail_in===0&&(r===ii.Z_FINISH||r===ii.Z_SYNC_FLUSH))&&(this.options.to==="string"?(o=oW.utf8border(I.output,I.next_out),a=I.next_out-o,s=oW.buf2string(I.output,o),I.next_out=a,I.avail_out=i-a,a&&uv.arraySet(I.output,I.output,o,a,0),this.onData(s)):this.onData(uv.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!==ii.Z_STREAM_END);return C===ii.Z_STREAM_END&&(r=ii.Z_FINISH),r===ii.Z_FINISH?(C=Mp.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,C===ii.Z_OK):(r===ii.Z_SYNC_FLUSH&&(this.onEnd(ii.Z_OK),I.avail_out=0),!0)};Zh.prototype.onData=function(e){this.chunks.push(e)};Zh.prototype.onEnd=function(e){e===ii.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=uv.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function C4(e,g){var I=new Zh(g);if(I.push(e,!0),I.err)throw I.msg||cP[I.err];return I.result}function l2t(e,g){return g=g||{},g.raw=!0,C4(e,g)}cw.Inflate=Zh;cw.inflate=C4;cw.inflateRaw=l2t;cw.ungzip=C4;var c2t=ol.assign,u2t=Aw,d2t=cw,h2t=SRe,VRe={};c2t(VRe,u2t,d2t,h2t);var m2t=VRe;const f2t=JC(m2t);var p2t=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];const b2t=p2t;function y2t(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),K=X(R),F=S(R);if(H===n.END_SEQUENCE_TAG||F?(r=H,o=null):K&&(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 J=I.references||[];I.references=J,J.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 W2t(e){return e.type==="filler"}function X2t(e){const g=e.end-e.start,I=e.strand===1?"+":"-",i=sg.nice();return W2t(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 H2t(e){const g=v2t(e),I=R2t(g[0].features.filter(i=>i.type!=="source").sort((i,n)=>i.start-n.start));return{json:g,features:I}}async function T2t(e,{gzipped:g}){if(!g)return e.text();const I=await e.arrayBuffer();return f2t.inflate(I,{to:"string"})}let WRe=function(){function e(g){B2t(this,e),this.dataConfig=g,this.trackUid=sg.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=>T2t(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=>H2t(i))}return S2t(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=Pre(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(X2t))}}]),e}();function N2t(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`localtile.${r}`);xQ(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 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;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&&M2t(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 P2t=new z2t;function J2t(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 fs(e){return fs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},fs(e)}function eHt(e,g,I,i,n){const C=e||n,r=0;return C==="log"&&g>0?["log",ru().range([254,0]).domain([g+r,i+r])]:["linear",tg().range([254,0]).domain([g,i])]}let mm=function(e){Q2t(I,e);var g=j2t(I);function I(i,n){var C;J2t(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=P2t,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 yk(o,C.pubSub),C.tilesetInfo=null,C.uuid=sg.nice(),C.trackNotFoundText=new ot.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"black"}),C.pLabel.addChild(C.trackNotFoundText),C.refreshTilesDebounced=$Ge(C.refreshTiles.bind(dP(C)),m9,m9),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=VN(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:",dP(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 O2t(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){dd(fs(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){dd(fs(I.prototype),"setPosition",this).call(this,n)}},{key:"setDimensions",value:function(n){dd(fs(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="",dd(fs(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=H7(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]-ACh(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=t9().domain([...h]).range(CC(u,d,(d-u)/256));return m.ticks=f=>Ch(u,d,f),[m,0]}else a=tg().domain([n,r]).range([c,l]);return[a,s]}}]),I}(fC);function tHt(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 kI(e){return kI=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},kI(e)}const Ure=200,Kl=10,qZ=40,Tn=10,xl=Tn,Qre=4,yf=1,Dl=4,jre=5,AHt=256,cZ=Kl+qZ+Tn+yf+xl+Dl;let uw=function(e){CHt(I,e);var g=rHt(I);function I(i,n){var C;tHt(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=sg.nice(),C.scaleBrush=PS(),C.onTrackOptionsChanged=A,C.isShowGlobalMousePosition=c,C.isValueScaleLocked=u,C.pColorbarArea=new ot.PIXI.Graphics,C.pMasked.addChild(C.pColorbarArea),C.pColorbar=new ot.PIXI.Graphics,C.pColorbarArea.addChild(C.pColorbar),C.axis=new pk(aW(C)),C.pColorbarArea.addChild(C.axis.pAxis),C.colorScale=Tb,n&&n.colorRange&&(C.colorScale=_c(n.colorRange)),C.gBase=dg(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(aW(C)),C.onMouseMoveZoom&&C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandlerBound)),C.options&&C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=sh(aW(C),C.is2d,C.isShowGlobalMousePosition())),C.prevOptions=JSON.stringify(n),C}return gHt(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=PQ(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=>Ti(f,this.chromInfo).slice(0,2)),h=h.map(f=>Ti(f,this.chromInfo).slice(0,2)),m=m.map(f=>Ti(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=sh(this,this.is2d,this.isShowGlobalMousePosition())))}},{key:"drawLabel",value:function(){this.options.labelPosition===this.options.colorbarPosition?this.labelXOffset=cZ:this.labelXOffset=0,ni(kI(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:LGe(n)};PG("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){ni(kI(I.prototype),"refXScale",this).call(this,n),this.draw()}},{key:"refYScale",value:function(n){ni(kI(I.prototype),"refYScale",this).call(this,n),this.draw()}},{key:"draw",value:function(){ni(kI(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(jre),C.scaleEndPercent=A.toFixed(jre),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]-Qre/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){ni(kI(I.prototype),"setPosition",this).call(this,n),this.drawColorbar()}},{key:"setDimensions",value:function(n){ni(kI(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,Ure);if(this.colorbarHeight=n-2*Tn,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([[Dl,0],[xl,this.colorbarHeight]]):this.scaleBrush.extent([[0,0],[xl-Dl,this.colorbarHeight]]),this.options.colorbarPosition==="topLeft"&&([this.pColorbarArea.x,this.pColorbarArea.y]=this.position,this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=Dl+xl+yf+Kl,this.pColorbar.x=Dl+xl+yf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+Dl},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="topRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-cZ,this.pColorbarArea.y=this.position[1],this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=qZ+Tn,this.pColorbar.x=qZ+Tn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Kl+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-cZ,this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=qZ+Tn,this.pColorbar.x=qZ+Tn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Kl+yf},${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=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=Dl+xl+yf+Kl,this.pColorbar.x=Dl+xl+yf,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,cZ,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",xl).attr("height",Qre).style("fill","#666").style("stroke","white"),this.flipText&&this.northHandle.attr("cursor","ew-resize"),this.gColorscaleBrush.call(this.scaleBrush.move,[a,o]));const s=tg().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,K=Math.min(m+b,W)-X,F=Math.max(V-h,0),J=Math.max(X-m,0),P=Y-R,ge=K-H;if(!(P<0||ge<0)){if(y.mirrored&&R>H){const q=R;R=H,H=q}JGe(p.hi(J+ge,F+P).lo(J,F),y.dataArray.hi(H+ge,R+P).lo(H,R))}}),p}},{key:"initTile",value:function(n){ni(kI(I.prototype),"initTile",this).call(this,n),n.tileData.dense.length===this.binsPerTile()**2&&(n.dataArray=Np(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(),ni(kI(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=ot.PIXI.VERSION[0]==="4"?ot.PIXI.Texture.fromCanvas(o,ot.PIXI.SCALE_MODES.NEAREST):ot.PIXI.Texture.from(o,{scaleMode:ot.PIXI.SCALE_MODES.NEAREST}),s=new ot.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?wGe(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,ni(kI(I.prototype),"remove",this).call(this)}},{key:"refScalesChanged",value:function(n,C){ni(kI(I.prototype),"refScalesChanged",this).call(this,n,C),wN(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 ni(kI(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;ni(kI(I.prototype),"exportSVG",this)?[C,n]=ni(kI(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=tg().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=tg().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?ni(kI(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?ni(kI(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;ni(kI(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=Ti(s,this.chromInfo),d=Ti(A,this.chromInfo),h=m=>dr(`.${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${dr(".3f")(Math.log(c)/Math.log(10))}`:c===0?`${l}Value: 0`:`${l}Value: N/A`:`${l}Value: ${dr(".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=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}(mm);function sHt(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 Q9(e){return Q9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Q9(e)}function HRe(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 TRe(e){const g=e.graphics;e.textGraphics=new ot.PIXI.Graphics,e.mirrored?e.text=new ot.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 ot.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 NRe=function(e){dHt(I,e);var g=hHt(I);function I(){return sHt(this,I),g.apply(this,arguments)}return lHt(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){TRe.bind(this)(n),this.drawTile(n)}},{key:"destroyTile",value:function(n,C){}},{key:"drawTile",value:function(n){HRe.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}(uw);function bHt(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 Gh(e){return Gh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Gh(e)}const RHt=1024;let r4=function(e){BHt(I,e);var g=SHt(I);function I(i,n){var C;bHt(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(kRe(C)))),C}return yHt(I,[{key:"initTile",value:function(n){dv(Gh(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||RHt,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=tg().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=tg().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){dv(Gh(I.prototype),"zoomed",this).call(this,...n),this.mouseMoveZoomHandler()}}]),I}(mm);function WHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function eoe(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 ps(e){return ps=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ps(e)}let iy=function(e){kHt(I,e);var g=YHt(I);function I(i,n){var C;WHt(this,I),C=g.call(this,i,n);const{animate:r,isShowGlobalMousePosition:o}=i;return C.constIndicator=new ot.PIXI.Graphics,C.pMain.addChild(C.constIndicator),C.axis=new pk(bP(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=sh(bP(C),C.is2d,C.isShowGlobalMousePosition())),C}return XHt(I,[{key:"rerender",value:function(n,C){const r=JSON.stringify(n);!C&&r===this.prevOptions||(hd(ps(I.prototype),"rerender",this).call(this,n,C),this.prevOptions=r,this.options=n,this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=sh(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(){hd(ps(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 ot.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;hd(ps(I.prototype),"exportSVG",this)?[C,n]=hd(ps(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}(r4);function DHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function toe(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 e0(e){return e0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},e0(e)}let YRe=function(e){PHt(I,e);var g=JHt(I);function I(i,n){var C;return DHt(this,I),C=g.call(this,i,n),C.pMain=C.pMobile,C}return FHt(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new ot.PIXI.Graphics,n.text=new ot.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(AW(e0(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}(iy);function UHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function goe(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 KRe=function(e){eTt(I,e);var g=tTt(I);function I(){return UHt(this,I),g.apply(this,arguments)}return QHt(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){sW(t0(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}(r4);function nTt(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 g0(e){return g0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},g0(e)}let xRe=function(e){ATt(I,e);var g=sTt(I);function I(){return nTt(this,I),g.apply(this,arguments)}return CTt(I,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const C=n.graphics;n.textGraphics=new ot.PIXI.Graphics,n.text=new ot.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(lW(g0(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}(KRe);var MD=Array.prototype.slice;function dTt(e){return e}var cW=1,uW=2,vP=3,eG=4,ioe=1e-6;function hTt(e){return"translate("+e+",0)"}function mTt(e){return"translate(0,"+e+")"}function fTt(e){return g=>+e(g)}function pTt(e,g){return g=Math.max(0,e.bandwidth()-g*2)/2,e.round()&&(g=Math.round(g)),I=>+e(I)+g}function bTt(){return!this.__axis}function Bk(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===cW||e===eG?-1:1,A=e===eG||e===uW?"x":"y",l=e===cW||e===vP?hTt:mTt;function c(u){var d=i??(g.ticks?g.ticks.apply(g,I):g.domain()),h=n??(g.tickFormat?g.tickFormat.apply(g,I):dTt),m=Math.max(C,0)+o,f=g.range(),b=+f[0]+a,p=+f[f.length-1]+a,y=(g.bandwidth?pTt:fTt)(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===cW?"0em":e===vP?"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",ioe).attr("transform",function(X){return isFinite(X=y(X))?l(X+a):this.getAttribute("transform")}),w.attr("opacity",ioe).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===eG||e===uW?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(bTt).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",e===uW?"start":e===eG?"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=MD.call(arguments),c},c.tickArguments=function(u){return arguments.length?(I=u==null?[]:MD.call(u),c):I.slice()},c.tickValues=function(u){return arguments.length?(i=u==null?null:MD.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 DRe(e){return Bk(cW,e)}function yTt(e){return Bk(uW,e)}function ZTt(e){return Bk(vP,e)}function FRe(e){return Bk(eG,e)}const GTt=Object.freeze(Object.defineProperty({__proto__:null,axisBottom:ZTt,axisLeft:FRe,axisRight:yTt,axisTop:DRe},Symbol.toStringTag,{value:"Module"}));function vTt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function noe(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 j9(e){return j9=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},j9(e)}let fm=function(e){VTt(I,e);var g=RTt(I);function I(i,n){var C;vTt(this,I),C=g.call(this,i,n);const{svgElement:r}=i;return C.gMain=dg(r).append("g"),C.clipUid=sg.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 BTt(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}(Dp);function TTt(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 vh(e){return vh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},vh(e)}let ERe=function(e){xTt(I,e);var g=DTt(I);function I(i,n){var C;return TTt(this,I),C=g.call(this,i,n),C.axis=DRe(C._xScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return NTt(I,[{key:"setDimensions",value:function(n){hv(vh(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){hv(vh(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(fm);function zTt(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 Bh(e){return Bh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Bh(e)}let MRe=function(e){LTt(I,e);var g=UTt(I);function I(i,n){var C;return zTt(this,I),C=g.call(this,i,n),C.axis=FRe(C._yScale),C.gAxis=C.gMain.append("g"),C.tilesetInfo=!0,C}return PTt(I,[{key:"setDimensions",value:function(n){mv(Bh(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){mv(Bh(I.prototype),"zoomed",this).call(this,n,C),this.draw()}}]),I}(fm);var Ag={},XI={},o4=32;XI.INT_BITS=o4;XI.INT_MAX=2147483647;XI.INT_MIN=-1<0)-(e<0)};XI.abs=function(e){var g=e>>o4-1;return(e^g)-g};XI.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};XI.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};XI.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function zRe(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}XI.countTrailingZeros=zRe;XI.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};XI.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};XI.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var tG=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|tG[e>>>16&255]<<8|tG[e>>>24&255]};XI.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};XI.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};XI.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};XI.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};XI.nextCombination=function(e){var g=e|e-1;return g+1|(~g&-~g)-1>>>zRe(e)+1};function PRe(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 qTt(e|0,g);break;case"object":if(typeof e.length=="number")return PRe(e,g,0);break}return[]}var tNt=eNt,JRe={},Sk={};Sk.byteLength=iNt;Sk.toByteArray=CNt;Sk.fromByteArray=aNt;var Qa=[],Xr=[],gNt=typeof Uint8Array<"u"?Uint8Array:Array,zD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var qm=0,INt=zD.length;qm0)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 iNt(e){var g=ORe(e),I=g[0],i=g[1];return(I+i)*3/4-i}function nNt(e,g,I){return(g+I)*3/4-I}function CNt(e){var g,I=ORe(e),i=I[0],n=I[1],C=new gNt(nNt(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=Xr[e.charCodeAt(a)]<<2|Xr[e.charCodeAt(a+1)]>>4,C[r++]=g&255),n===1&&(g=Xr[e.charCodeAt(a)]<<10|Xr[e.charCodeAt(a+1)]<<4|Xr[e.charCodeAt(a+2)]>>2,C[r++]=g>>8&255,C[r++]=g&255),C}function rNt(e){return Qa[e>>18&63]+Qa[e>>12&63]+Qa[e>>6&63]+Qa[e&63]}function oNt(e,g,I){for(var i,n=[],C=g;Co?o:r+C));return i===1?(g=e[I-1],n.push(Qa[g>>2]+Qa[g<<4&63]+"==")):i===2&&(g=(e[I-2]<<8)+e[I-1],n.push(Qa[g>>10]+Qa[g>>4&63]+Qa[g<<2&63]+"=")),n.join("")}var a4={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */a4.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)};a4.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};/*! +[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"),r=document.createElement("rect");r.setAttribute("x",`${this.position[0]}`),r.setAttribute("y",`${this.position[1]}`),r.setAttribute("width",`${this.dimensions[0]}`),r.setAttribute("height",`${this.dimensions[1]}`),this.options&&this.options.backgroundColor?r.setAttribute("fill",this.options.backgroundColor):r.setAttribute("fill-opacity","0");const C=document.createElement("g");C.setAttribute("class","g-clipped"),n.appendChild(C),C.appendChild(r);const o=document.createElement("g");C.setAttribute("class","g-track"),C.appendChild(o);const a=document.createElement("g");C.setAttribute("class","g-labels"),C.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=sg.nice();s.setAttribute("id",l),C.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 V9t(e,[{key:"registerFileUrl",value:async function({server:i,url:I,filetype:n,coordSystem:r}){const C=`${HN(i)}/register_url/`;return fetch(C,{method:"POST",body:JSON.stringify({fileurl:I,filetype:n,coordSystem:r}),headers:{"Content-Type":"application/json; charset=utf-8"}})}},{key:"tilesetInfo",value:function(i){const{server:I,url:n,filetype:r,coordSystem:C}=this.dataConfig;return I&&n&&r?this.registerFileUrl({server:I,url:n,filetype:r,coordSystem:C}).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(r=>{n.tilesetInfo(r)}));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,r=>{this.dataConfig.tilesetInfo=r[n],i(r[n],n)},r=>{this.tilesetInfoLoading=!1,i({error:r})},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:sg.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=Eg(o)[0].tilesetUid,s={};for(let A=0;Anew Promise(o=>{C.fetchTilesDebounced(o,I)})))??[];return Promise.all(r).then(C=>{if(this.dataConfig.type==="divided"&&H9t(C)){const o=this.makeDivided(C,I);return i(o),o}return console.warn("Unimplemented dataConfig type. Returning first data source.",this.dataConfig),i(C[0]),C[0]})}},{key:"divideData",value:function(i,I){const n=new Float32Array(i.length);for(let r=0;r+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?C.push(!1):C.push(!0);const f=`${c}.${m[0]}.${m[1]}`;r.push(f)}return new Promise(A=>{vt.fetchTilesDebounced({id:sg.nice(),server:this.dataConfig.server,done:A,ids:r.map(l=>`${this.dataConfig.tilesetUid}.${l}`)},this.pubSub,!0)}).then(A=>{const l=Eg(A)[0].tilesetUid,c={};for(let u=0;u=0;)e[g]=0}var Y9t=0,QRe=1,K9t=2,F9t=3,D9t=258,rj=29,uw=256,UB=uw+1+rj,Ep=30,Cj=19,jRe=2*UB+1,ld=15,HD=16,x9t=7,oj=256,$Re=16,qRe=17,eVe=18,sP=[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],CW=[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],E9t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],tVe=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],M9t=512,Is=new Array((UB+2)*2);iy(Is);var Av=new Array(Ep*2);iy(Av);var QB=new Array(M9t);iy(QB);var jB=new Array(D9t-F9t+1);iy(jB);var aj=new Array(rj);iy(aj);var jX=new Array(Ep);iy(jX);function TD(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 gVe,iVe,IVe;function ND(e,g){this.dyn_tree=e,this.max_code=0,this.stat_desc=g}function nVe(e){return e<256?QB[e]:QB[256+(e>>>7)]}function $B(e,g){e.pending_buf[e.pending++]=g&255,e.pending_buf[e.pending++]=g>>>8&255}function Yr(e,g,i){e.bi_valid>HD-i?(e.bi_buf|=g<>HD-e.bi_valid,e.bi_valid+=i-HD):(e.bi_buf|=g<>>=1,i<<=1;while(--g>0);return i>>>1}function z9t(e){e.bi_valid===16?($B(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 P9t(e,g){var i=g.dyn_tree,I=g.max_code,n=g.stat_desc.static_tree,r=g.stat_desc.has_stree,C=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<=ld;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=C[A-o]),d=i[A*2],e.opt_len+=d*(c+u),r&&(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 CVe(e,g,i){var I=new Array(ld+1),n=0,r,C;for(r=1;r<=ld;r++)I[r]=n=n+i[r-1]<<1;for(C=0;C<=g;C++){var o=e[C*2+1];o!==0&&(e[C*2]=rVe(I[o]++,o))}}function J9t(){var e,g,i,I,n,r=new Array(ld+1);for(i=0,I=0;I>=7;I8?$B(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 O9t(e,g,i,I){aVe(e),I&&($B(e,i),$B(e,~i)),T9t.arraySet(e.pending_buf,e.window,g,i,e.pending),e.pending+=i}function aCe(e,g,i,I){var n=g*2,r=i*2;return e[n]>1;C>=1;C--)kD(e,i,C);s=r;do C=e.heap[1],e.heap[1]=e.heap[e.heap_len--],kD(e,i,1),o=e.heap[1],e.heap[--e.heap_max]=C,e.heap[--e.heap_max]=o,i[s*2]=i[C*2]+i[o*2],e.depth[s]=(e.depth[C]>=e.depth[o]?e.depth[C]:e.depth[o])+1,i[C*2+1]=i[o*2+1]=s,e.heap[1]=s++,kD(e,i,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],P9t(e,g),CVe(i,a,e.bl_count)}function sCe(e,g,i){var I,n=-1,r,C=g[0*2+1],o=0,a=7,s=4;for(C===0&&(a=138,s=3),g[(i+1)*2+1]=65535,I=0;I<=i;I++)r=C,C=g[(I+1)*2+1],!(++o=3&&e.bl_tree[tVe[g]*2+1]===0;g--);return e.opt_len+=3*(g+1)+5+5+4,g}function L9t(e,g,i,I){var n;for(Yr(e,g-257,5),Yr(e,i-1,5),Yr(e,I-4,4),n=0;n>>=1)if(g&1&&e.dyn_ltree[i*2]!==0)return CCe;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return oCe;for(i=32;i0?(e.strm.data_type===k9t&&(e.strm.data_type=U9t(e)),lP(e,e.l_desc),lP(e,e.d_desc),C=_9t(e),n=e.opt_len+3+7>>>3,r=e.static_len+3+7>>>3,r<=n&&(n=r)):n=r=i+5,i+4<=n&&g!==-1?AVe(e,g,i,I):e.strategy===N9t||r===n?(Yr(e,(QRe<<1)+(I?1:0),3),ACe(e,Is,Av)):(Yr(e,(K9t<<1)+(I?1:0),3),L9t(e,e.l_desc.max_code+1,e.d_desc.max_code+1,C+1),ACe(e,e.dyn_ltree,e.dyn_dtree)),oVe(e),I&&aVe(e)}function q9t(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[(jB[i]+uw+1)*2]++,e.dyn_dtree[nVe(g)*2]++),e.last_lit===e.lit_bufsize-1}gy._tr_init=Q9t;gy._tr_stored_block=AVe;gy._tr_flush_block=$9t;gy._tr_tally=q9t;gy._tr_align=j9t;function eXt(e,g,i,I){for(var n=e&65535|0,r=e>>>16&65535|0,C=0;i!==0;){C=i>2e3?2e3:i,i-=C;do n=n+g[I++]|0,r=r+n|0;while(--C);n%=65521,r%=65521}return n|r<<16|0}var sVe=eXt;function tXt(){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 gXt=tXt();function iXt(e,g,i,I){var n=gXt,r=I+i;e^=-1;for(var C=I;C>>8^n[(e^g[C])&255];return e^-1}var lVe=iXt,Aj={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=ol,qC=gy,cVe=sVe,kl=lVe,IXt=Aj,um=0,nXt=1,rXt=3,Nc=4,uCe=5,Ua=0,dCe=1,eo=-2,CXt=-3,YD=-5,oXt=-1,aXt=1,WV=2,AXt=3,sXt=4,lXt=0,cXt=2,Bk=8,uXt=9,dXt=15,hXt=8,mXt=29,fXt=256,cP=fXt+1+mXt,pXt=30,bXt=19,yXt=2*cP+1,ZXt=15,vg=3,fc=258,Ca=fc+vg+1,GXt=32,Sk=42,uP=69,oW=73,aW=91,AW=103,cd=113,qZ=666,NI=1,dw=2,mh=3,Iy=4,vXt=3;function pc(e,g){return e.msg=IXt[g],g}function hCe(e){return(e<<1)-(e>4?9:0)}function ql(e){for(var g=e.length;--g>=0;)e[g]=0}function Yl(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 un(e,g){qC._tr_flush_block(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,g),e.block_start=e.strstart,Yl(e.strm)}function Ng(e,g){e.pending_buf[e.pending++]=g}function cZ(e,g){e.pending_buf[e.pending++]=g>>>8&255,e.pending_buf[e.pending++]=g&255}function BXt(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=cVe(e.adler,g,n,i):e.state.wrap===2&&(e.adler=kl(e.adler,g,n,i)),e.next_in+=n,e.total_in+=n,n)}function uVe(e,g){var i=e.max_chain_length,I=e.strstart,n,r,C=e.prev_length,o=e.nice_match,a=e.strstart>e.w_size-Ca?e.strstart-(e.w_size-Ca):0,s=e.window,A=e.w_mask,l=e.prev,c=e.strstart+fc,u=s[I+C-1],d=s[I+C];e.prev_length>=e.good_match&&(i>>=2),o>e.lookahead&&(o=e.lookahead);do if(n=g,!(s[n+C]!==d||s[n+C-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]&&IC){if(e.match_start=g,C=r,r>=o)break;u=s[I+C-1],d=s[I+C]}}while((g=l[g&A])>a&&--i!==0);return C<=e.lookahead?C:e.lookahead}function fh(e){var g=e.w_size,i,I,n,r,C;do{if(r=e.window_size-e.lookahead-e.strstart,e.strstart>=g+(g-Ca)){$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);r+=g}if(e.strm.avail_in===0)break;if(I=BXt(e.strm,e.window,e.strstart+e.lookahead,r),e.lookahead+=I,e.lookahead+e.insert>=vg)for(C=e.strstart-e.insert,e.ins_h=e.window[C],e.ins_h=(e.ins_h<e.pending_buf_size-5&&(i=e.pending_buf_size-5);;){if(e.lookahead<=1){if(fh(e),e.lookahead===0&&g===um)return NI;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,un(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-Ca&&(un(e,!1),e.strm.avail_out===0))return NI}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?mh:Iy):(e.strstart>e.block_start&&(un(e,!1),e.strm.avail_out===0),NI)}function KD(e,g){for(var i,I;;){if(e.lookahead=vg&&(e.ins_h=(e.ins_h<=vg)if(I=qC._tr_tally(e,e.strstart-e.match_start,e.match_length-vg),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=vg){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<=vg&&(e.ins_h=(e.ins_h<4096)&&(e.match_length=vg-1)),e.prev_length>=vg&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-vg,I=qC._tr_tally(e,e.strstart-1-e.prev_match,e.prev_length-vg),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=n&&(e.ins_h=(e.ins_h<=vg&&e.strstart>0&&(n=e.strstart-1,I=C[n],I===C[++n]&&I===C[++n]&&I===C[++n])){r=e.strstart+fc;do;while(I===C[++n]&&I===C[++n]&&I===C[++n]&&I===C[++n]&&I===C[++n]&&I===C[++n]&&I===C[++n]&&I===C[++n]&&ne.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=vg?(i=qC._tr_tally(e,1,e.match_length-vg),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(i=qC._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),i&&(un(e,!1),e.strm.avail_out===0))return NI}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?mh:Iy):e.last_lit&&(un(e,!1),e.strm.avail_out===0)?NI:dw}function RXt(e,g){for(var i;;){if(e.lookahead===0&&(fh(e),e.lookahead===0)){if(g===um)return NI;break}if(e.match_length=0,i=qC._tr_tally(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,i&&(un(e,!1),e.strm.avail_out===0))return NI}return e.insert=0,g===Nc?(un(e,!0),e.strm.avail_out===0?mh:Iy):e.last_lit&&(un(e,!1),e.strm.avail_out===0)?NI:dw}function Xa(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 ap;ap=[new Xa(0,0,0,0,SXt),new Xa(4,4,8,4,KD),new Xa(4,5,16,8,KD),new Xa(4,6,32,32,KD),new Xa(4,4,16,16,Qm),new Xa(8,16,32,32,Qm),new Xa(8,16,128,128,Qm),new Xa(8,32,128,256,Qm),new Xa(32,128,258,1024,Qm),new Xa(32,258,258,4096,Qm)];function VXt(e){e.window_size=2*e.w_size,ql(e.head),e.max_lazy_match=ap[e.level].max_lazy,e.good_match=ap[e.level].good_length,e.nice_match=ap[e.level].nice_length,e.max_chain_length=ap[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=vg-1,e.match_available=0,e.ins_h=0}function WXt(){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=Bk,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(yXt*2),this.dyn_dtree=new $n.Buf16((2*pXt+1)*2),this.bl_tree=new $n.Buf16((2*bXt+1)*2),ql(this.dyn_ltree),ql(this.dyn_dtree),ql(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new $n.Buf16(ZXt+1),this.heap=new $n.Buf16(2*cP+1),ql(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new $n.Buf16(2*cP+1),ql(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 dVe(e){var g;return!e||!e.state?pc(e,eo):(e.total_in=e.total_out=0,e.data_type=cXt,g=e.state,g.pending=0,g.pending_out=0,g.wrap<0&&(g.wrap=-g.wrap),g.status=g.wrap?Sk:cd,e.adler=g.wrap===2?0:1,g.last_flush=um,qC._tr_init(g),Ua)}function hVe(e){var g=dVe(e);return g===Ua&&VXt(e.state),g}function XXt(e,g){return!e||!e.state||e.state.wrap!==2?eo:(e.state.gzhead=g,Ua)}function mVe(e,g,i,I,n,r){if(!e)return eo;var C=1;if(g===oXt&&(g=6),I<0?(C=0,I=-I):I>15&&(C=2,I-=16),n<1||n>uXt||i!==Bk||I<8||I>15||g<0||g>9||r<0||r>sXt)return pc(e,eo);I===8&&(I=9);var o=new WXt;return e.state=o,o.strm=e,o.wrap=C,o.gzhead=null,o.w_bits=I,o.w_size=1<uCe||g<0)return e?pc(e,eo):eo;if(I=e.state,!e.output||!e.input&&e.avail_in!==0||I.status===qZ&&g!==Nc)return pc(e,e.avail_out===0?YD:eo);if(I.strm=e,i=I.last_flush,I.last_flush=g,I.status===Sk)if(I.wrap===2)e.adler=0,Ng(I,31),Ng(I,139),Ng(I,8),I.gzhead?(Ng(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)),Ng(I,I.gzhead.time&255),Ng(I,I.gzhead.time>>8&255),Ng(I,I.gzhead.time>>16&255),Ng(I,I.gzhead.time>>24&255),Ng(I,I.level===9?2:I.strategy>=WV||I.level<2?4:0),Ng(I,I.gzhead.os&255),I.gzhead.extra&&I.gzhead.extra.length&&(Ng(I,I.gzhead.extra.length&255),Ng(I,I.gzhead.extra.length>>8&255)),I.gzhead.hcrc&&(e.adler=kl(e.adler,I.pending_buf,I.pending,0)),I.gzindex=0,I.status=uP):(Ng(I,0),Ng(I,0),Ng(I,0),Ng(I,0),Ng(I,0),Ng(I,I.level===9?2:I.strategy>=WV||I.level<2?4:0),Ng(I,vXt),I.status=cd);else{var C=Bk+(I.w_bits-8<<4)<<8,o=-1;I.strategy>=WV||I.level<2?o=0:I.level<6?o=1:I.level===6?o=2:o=3,C|=o<<6,I.strstart!==0&&(C|=GXt),C+=31-C%31,I.status=cd,cZ(I,C),I.strstart!==0&&(cZ(I,e.adler>>>16),cZ(I,e.adler&65535)),e.adler=1}if(I.status===uP)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=kl(e.adler,I.pending_buf,I.pending-n,n)),Yl(e),n=I.pending,I.pending===I.pending_buf_size));)Ng(I,I.gzhead.extra[I.gzindex]&255),I.gzindex++;I.gzhead.hcrc&&I.pending>n&&(e.adler=kl(e.adler,I.pending_buf,I.pending-n,n)),I.gzindex===I.gzhead.extra.length&&(I.gzindex=0,I.status=oW)}else I.status=oW;if(I.status===oW)if(I.gzhead.name){n=I.pending;do{if(I.pending===I.pending_buf_size&&(I.gzhead.hcrc&&I.pending>n&&(e.adler=kl(e.adler,I.pending_buf,I.pending-n,n)),Yl(e),n=I.pending,I.pending===I.pending_buf_size)){r=1;break}I.gzindexn&&(e.adler=kl(e.adler,I.pending_buf,I.pending-n,n)),r===0&&(I.gzindex=0,I.status=aW)}else I.status=aW;if(I.status===aW)if(I.gzhead.comment){n=I.pending;do{if(I.pending===I.pending_buf_size&&(I.gzhead.hcrc&&I.pending>n&&(e.adler=kl(e.adler,I.pending_buf,I.pending-n,n)),Yl(e),n=I.pending,I.pending===I.pending_buf_size)){r=1;break}I.gzindexn&&(e.adler=kl(e.adler,I.pending_buf,I.pending-n,n)),r===0&&(I.status=AW)}else I.status=AW;if(I.status===AW&&(I.gzhead.hcrc?(I.pending+2>I.pending_buf_size&&Yl(e),I.pending+2<=I.pending_buf_size&&(Ng(I,e.adler&255),Ng(I,e.adler>>8&255),e.adler=0,I.status=cd)):I.status=cd),I.pending!==0){if(Yl(e),e.avail_out===0)return I.last_flush=-1,Ua}else if(e.avail_in===0&&hCe(g)<=hCe(i)&&g!==Nc)return pc(e,YD);if(I.status===qZ&&e.avail_in!==0)return pc(e,YD);if(e.avail_in!==0||I.lookahead!==0||g!==um&&I.status!==qZ){var a=I.strategy===WV?RXt(I,g):I.strategy===AXt?wXt(I,g):ap[I.level].func(I,g);if((a===mh||a===Iy)&&(I.status=qZ),a===NI||a===mh)return e.avail_out===0&&(I.last_flush=-1),Ua;if(a===dw&&(g===nXt?qC._tr_align(I):g!==uCe&&(qC._tr_stored_block(I,0,0,!1),g===rXt&&(ql(I.head),I.lookahead===0&&(I.strstart=0,I.block_start=0,I.insert=0))),Yl(e),e.avail_out===0))return I.last_flush=-1,Ua}return g!==Nc?Ua:I.wrap<=0?dCe:(I.wrap===2?(Ng(I,e.adler&255),Ng(I,e.adler>>8&255),Ng(I,e.adler>>16&255),Ng(I,e.adler>>24&255),Ng(I,e.total_in&255),Ng(I,e.total_in>>8&255),Ng(I,e.total_in>>16&255),Ng(I,e.total_in>>24&255)):(cZ(I,e.adler>>>16),cZ(I,e.adler&65535)),Yl(e),I.wrap>0&&(I.wrap=-I.wrap),I.pending!==0?Ua:dCe)}function NXt(e){var g;return!e||!e.state?eo:(g=e.state.status,g!==Sk&&g!==uP&&g!==oW&&g!==aW&&g!==AW&&g!==cd&&g!==qZ?pc(e,eo):(e.state=null,g===cd?pc(e,CXt):Ua))}function kXt(e,g){var i=g.length,I,n,r,C,o,a,s,A;if(!e||!e.state||(I=e.state,C=I.wrap,C===2||C===1&&I.status!==Sk||I.lookahead))return eo;for(C===1&&(e.adler=cVe(e.adler,g,i,0)),I.wrap=0,i>=I.w_size&&(C===0&&(ql(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,fh(I);I.lookahead>=vg;){n=I.strstart,r=I.lookahead-(vg-1);do I.ins_h=(I.ins_h<=252?6:Gl>=248?5:Gl>=240?4:Gl>=224?3:Gl>=192?2:1;qB[254]=qB[254]=1;dm.string2buf=function(e){var g,i,I,n,r,C=e.length,o=0;for(n=0;n>>6,g[r++]=128|i&63):i<65536?(g[r++]=224|i>>>12,g[r++]=128|i>>>6&63,g[r++]=128|i&63):(g[r++]=240|i>>>18,g[r++]=128|i>>>12&63,g[r++]=128|i>>>6&63,g[r++]=128|i&63);return g};function bVe(e,g){if(g<65534&&(e.subarray&&pVe||!e.subarray&&fVe))return String.fromCharCode.apply(null,wk.shrinkBuf(e,g));for(var i="",I=0;I4){o[I++]=65533,i+=r-1;continue}for(n&=r===2?31:r===3?15:7;r>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 bVe(o,I)};dm.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+qB[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 yVe=YXt,sv=NA,lv=ol,dP=dm,hP=Aj,KXt=yVe,ZVe=Object.prototype.toString,FXt=0,FD=4,Mp=0,mCe=1,fCe=2,DXt=-1,xXt=0,EXt=8;function ph(e){if(!(this instanceof ph))return new ph(e);this.options=lv.assign({level:DXt,method:EXt,chunkSize:16384,windowBits:15,memLevel:8,strategy:xXt,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 KXt,this.strm.avail_out=0;var i=sv.deflateInit2(this.strm,g.level,g.method,g.windowBits,g.memLevel,g.strategy);if(i!==Mp)throw new Error(hP[i]);if(g.header&&sv.deflateSetHeader(this.strm,g.header),g.dictionary){var I;if(typeof g.dictionary=="string"?I=dP.string2buf(g.dictionary):ZVe.call(g.dictionary)==="[object ArrayBuffer]"?I=new Uint8Array(g.dictionary):I=g.dictionary,i=sv.deflateSetDictionary(this.strm,I),i!==Mp)throw new Error(hP[i]);this._dict_set=!0}}ph.prototype.push=function(e,g){var i=this.strm,I=this.options.chunkSize,n,r;if(this.ended)return!1;r=g===~~g?g:g===!0?FD:FXt,typeof e=="string"?i.input=dP.string2buf(e):ZVe.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 lv.Buf8(I),i.next_out=0,i.avail_out=I),n=sv.deflate(i,r),n!==mCe&&n!==Mp)return this.onEnd(n),this.ended=!0,!1;(i.avail_out===0||i.avail_in===0&&(r===FD||r===fCe))&&(this.options.to==="string"?this.onData(dP.buf2binstring(lv.shrinkBuf(i.output,i.next_out))):this.onData(lv.shrinkBuf(i.output,i.next_out)))}while((i.avail_in>0||i.avail_out===0)&&n!==mCe);return r===FD?(n=sv.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Mp):(r===fCe&&(this.onEnd(Mp),i.avail_out=0),!0)};ph.prototype.onData=function(e){this.chunks.push(e)};ph.prototype.onEnd=function(e){e===Mp&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=lv.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function sj(e,g){var i=new ph(g);if(i.push(e,!0),i.err)throw i.msg||hP[i.err];return i.result}function MXt(e,g){return g=g||{},g.raw=!0,sj(e,g)}function zXt(e,g){return g=g||{},g.gzip=!0,sj(e,g)}cw.Deflate=ph;cw.deflate=sj;cw.deflateRaw=MXt;cw.gzip=zXt;var hw={},Za={},XV=30,PXt=12,JXt=function(g,i){var I,n,r,C,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,R,S;I=g.state,n=g.next_in,R=g.input,r=n+(g.avail_in-5),C=g.next_out,S=g.output,o=C-(i-g.avail_out),a=C+(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[C++]=y&65535;else if(Z&16){B=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){g.msg="invalid distance too far back",I.mode=XV;break e}if(d>>>=Z,h-=Z,Z=C-o,G>Z){if(Z=G-Z,Z>l&&I.sane){g.msg="invalid distance too far back",I.mode=XV;break e}if(v=0,w=u,c===0){if(v+=A-Z,Z2;)S[C++]=w[v++],S[C++]=w[v++],S[C++]=w[v++],B-=3;B&&(S[C++]=w[v++],B>1&&(S[C++]=w[v++]))}else{v=C-G;do S[C++]=S[v++],S[C++]=S[v++],S[C++]=S[v++],B-=3;while(B>2);B&&(S[C++]=S[v++],B>1&&(S[C++]=S[v++]))}}else if(Z&64){g.msg="invalid distance code",I.mode=XV;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 r[C++]=1<<24|64<<16|0,r[C++]=1<<24|64<<16|0,a.bits=1,0;for(c=1;c0&&(g===ZCe||u!==1))return-1;for(W[1]=0,A=1;AbCe||g===GCe&&b>yCe)return 1;for(;;){Y=A-m,o[l]S?(K=V[H+o[l]],x=w[R+o[l]]):(K=32+64,x=0),y=1<>m)+Z]=Y<<24|K<<16|x|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<bCe||g===GCe&&b>yCe)return 1;B=p&G,r[B]=d<<24|h<<16|v-C|0}}return p!==0&&(r[v+p]=A-m<<24|64<<16|0),a.bits=d,0},lC=ol,mP=sVe,Ha=lVe,jXt=JXt,cv=QXt,$Xt=0,GVe=1,vVe=2,vCe=4,qXt=5,HV=6,bh=0,e2t=1,t2t=2,Co=-2,BVe=-3,SVe=-4,g2t=-5,BCe=8,wVe=1,SCe=2,wCe=3,RCe=4,VCe=5,WCe=6,XCe=7,HCe=8,TCe=9,NCe=10,$X=11,PA=12,xD=13,kCe=14,ED=15,YCe=16,KCe=17,FCe=18,DCe=19,TV=20,NV=21,xCe=22,ECe=23,MCe=24,zCe=25,PCe=26,MD=27,JCe=28,OCe=29,Gi=30,RVe=31,i2t=32,I2t=852,n2t=592,r2t=15,C2t=r2t;function _Ce(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function o2t(){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 lC.Buf16(320),this.work=new lC.Buf16(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function VVe(e){var g;return!e||!e.state?Co:(g=e.state,e.total_in=e.total_out=g.total=0,e.msg="",g.wrap&&(e.adler=g.wrap&1),g.mode=wVe,g.last=0,g.havedict=0,g.dmax=32768,g.head=null,g.hold=0,g.bits=0,g.lencode=g.lendyn=new lC.Buf32(I2t),g.distcode=g.distdyn=new lC.Buf32(n2t),g.sane=1,g.back=-1,bh)}function WVe(e){var g;return!e||!e.state?Co:(g=e.state,g.wsize=0,g.whave=0,g.wnext=0,VVe(e))}function XVe(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))?Co:(I.window!==null&&I.wbits!==g&&(I.window=null),I.wrap=i,I.wbits=g,WVe(e))}function HVe(e,g){var i,I;return e?(I=new o2t,e.state=I,I.window=null,i=XVe(e,g),i!==bh&&(e.state=null),i):Co}function a2t(e){return HVe(e,C2t)}var LCe=!0,zD,PD;function A2t(e){if(LCe){var g;for(zD=new lC.Buf32(512),PD=new lC.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(cv(GVe,e.lens,0,288,zD,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;cv(vVe,e.lens,0,32,PD,0,e.work,{bits:5}),LCe=!1}e.lencode=zD,e.lenbits=9,e.distcode=PD,e.distbits=5}function TVe(e,g,i,I){var n,r=e.state;return r.window===null&&(r.wsize=1<=r.wsize?(lC.arraySet(r.window,g,i-r.wsize,r.wsize,0),r.wnext=0,r.whave=r.wsize):(n=r.wsize-r.wnext,n>I&&(n=I),lC.arraySet(r.window,g,i-I,n,r.wnext),I-=n,I?(lC.arraySet(r.window,g,i-I,I,0),r.wnext=I,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whave>>8&255,i.check=Ha(i.check,w,2,0),s=0,A=0,i.mode=SCe;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=Gi;break}if((s&15)!==BCe){e.msg="unknown compression method",i.mode=Gi;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=Gi;break}i.dmax=1<>8&1),i.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,i.check=Ha(i.check,w,2,0)),s=0,A=0,i.mode=wCe;case wCe:for(;A<32;){if(o===0)break e;o--,s+=I[r++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,i.check=Ha(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[r++]<>8),i.flags&512&&(w[0]=s&255,w[1]=s>>>8&255,i.check=Ha(i.check,w,2,0)),s=0,A=0,i.mode=VCe;case VCe:if(i.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=I[r++]<>>8&255,i.check=Ha(i.check,w,2,0)),s=0,A=0}else i.head&&(i.head.extra=null);i.mode=WCe;case WCe: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)),lC.arraySet(i.head.extra,I,r,u,G)),i.flags&512&&(i.check=Ha(i.check,I,u,r)),o-=u,r+=u,i.length-=u),i.length))break e;i.length=0,i.mode=XCe;case XCe:if(i.flags&2048){if(o===0)break e;u=0;do G=I[r+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=PA;break;case NCe:for(;A<32;){if(o===0)break e;o--,s+=I[r++]<>>=A&7,A-=A&7,i.mode=MD;break}for(;A<3;){if(o===0)break e;o--,s+=I[r++]<>>=1,A-=1,s&3){case 0:i.mode=kCe;break;case 1:if(A2t(i),i.mode=TV,g===HV){s>>>=2,A-=2;break e}break;case 2:i.mode=KCe;break;case 3:e.msg="invalid block type",i.mode=Gi}s>>>=2,A-=2;break;case kCe:for(s>>>=A&7,A-=A&7;A<32;){if(o===0)break e;o--,s+=I[r++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=Gi;break}if(i.length=s&65535,s=0,A=0,i.mode=ED,g===HV)break e;case ED:i.mode=YCe;case YCe:if(u=i.length,u){if(u>o&&(u=o),u>a&&(u=a),u===0)break e;lC.arraySet(n,I,r,u,C),o-=u,r+=u,a-=u,C+=u,i.length-=u;break}i.mode=PA;break;case KCe:for(;A<14;){if(o===0)break e;o--,s+=I[r++]<>>=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=FCe;case FCe: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},v=cv($Xt,i.lens,0,19,i.lencode,0,i.work,R),i.lenbits=R.bits,v){e.msg="invalid code lengths set",i.mode=Gi;break}i.have=0,i.mode=DCe;case DCe:for(;i.have>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=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,R={bits:i.lenbits},v=cv(GVe,i.lens,0,i.nlen,i.lencode,0,i.work,R),i.lenbits=R.bits,v){e.msg="invalid literal/lengths set",i.mode=Gi;break}if(i.distbits=6,i.distcode=i.distdyn,R={bits:i.distbits},v=cv(vVe,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,R),i.distbits=R.bits,v){e.msg="invalid distances set",i.mode=Gi;break}if(i.mode=TV,g===HV)break e;case TV:i.mode=NV;case NV:if(o>=6&&a>=258){e.next_out=C,e.avail_out=a,e.next_in=r,e.avail_in=o,i.hold=s,i.bits=A,jXt(e,c),C=e.next_out,n=e.output,a=e.avail_out,r=e.next_in,I=e.input,o=e.avail_in,s=i.hold,A=i.bits,i.mode===PA&&(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[r++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=y,A-=y,i.back+=y}if(s>>>=f,A-=f,i.back+=f,i.length=p,b===0){i.mode=PCe;break}if(b&32){i.back=-1,i.mode=PA;break}if(b&64){e.msg="invalid literal/length code",i.mode=Gi;break}i.extra=b&15,i.mode=xCe;case xCe:if(i.extra){for(S=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=ECe;case ECe:for(;m=i.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=I[r++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=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=MCe;case MCe: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=zCe;case zCe: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=C-i.offset,u=i.length;u>a&&(u=a),a-=u,i.length-=u;do n[C++]=h[d++];while(--u);i.length===0&&(i.mode=NV);break;case PCe:if(a===0)break e;n[C++]=i.length,a--,i.mode=NV;break;case MD:if(i.wrap){for(;A<32;){if(o===0)break e;o--,s|=I[r++]<=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 m2t,this.strm.avail_out=0;var i=zp.inflateInit2(this.strm,g.windowBits);if(i!==II.Z_OK)throw new Error(fP[i]);if(this.header=new f2t,zp.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=sW.string2buf(g.dictionary):kVe.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(i=zp.inflateSetDictionary(this.strm,g.dictionary),i!==II.Z_OK)))throw new Error(fP[i])}yh.prototype.push=function(e,g){var i=this.strm,I=this.options.chunkSize,n=this.options.dictionary,r,C,o,a,s,A=!1;if(this.ended)return!1;C=g===~~g?g:g===!0?II.Z_FINISH:II.Z_NO_FLUSH,typeof e=="string"?i.input=sW.binstring2buf(e):kVe.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 uv.Buf8(I),i.next_out=0,i.avail_out=I),r=zp.inflate(i,II.Z_NO_FLUSH),r===II.Z_NEED_DICT&&n&&(r=zp.inflateSetDictionary(this.strm,n)),r===II.Z_BUF_ERROR&&A===!0&&(r=II.Z_OK,A=!1),r!==II.Z_STREAM_END&&r!==II.Z_OK)return this.onEnd(r),this.ended=!0,!1;i.next_out&&(i.avail_out===0||r===II.Z_STREAM_END||i.avail_in===0&&(C===II.Z_FINISH||C===II.Z_SYNC_FLUSH))&&(this.options.to==="string"?(o=sW.utf8border(i.output,i.next_out),a=i.next_out-o,s=sW.buf2string(i.output,o),i.next_out=a,i.avail_out=I-a,a&&uv.arraySet(i.output,i.output,o,a,0),this.onData(s)):this.onData(uv.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)&&r!==II.Z_STREAM_END);return r===II.Z_STREAM_END&&(C=II.Z_FINISH),C===II.Z_FINISH?(r=zp.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,r===II.Z_OK):(C===II.Z_SYNC_FLUSH&&(this.onEnd(II.Z_OK),i.avail_out=0),!0)};yh.prototype.onData=function(e){this.chunks.push(e)};yh.prototype.onEnd=function(e){e===II.Z_OK&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=uv.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function lj(e,g){var i=new yh(g);if(i.push(e,!0),i.err)throw i.msg||fP[i.err];return i.result}function p2t(e,g){return g=g||{},g.raw=!0,lj(e,g)}hw.Inflate=yh;hw.inflate=lj;hw.inflateRaw=p2t;hw.ungzip=lj;var b2t=ol.assign,y2t=cw,Z2t=hw,G2t=NVe,YVe={};b2t(YVe,y2t,Z2t,G2t);var v2t=YVe;const B2t=Pr(v2t);var S2t=["JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"];const w2t=S2t;function R2t(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:"//"},r=e.split(/\r?\n/),C,o,a,s,A,l=!1;for(let V of r){if(V===null)break;let H=v(V),Y=R(V),K=X(V),x=S(V);if(H===n.END_SEQUENCE_TAG||x?(C=H,o=null):K&&(o=H),!(V.trim()===""||H===";")){if(!l&&C!==n.LOCUS_TAG)break;switch(C){case n.LOCUS_TAG:l=!0,m(V);break;case n.FEATURES_TAG:p(V,H,Y);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(C,V,C.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 J=i.references||[];i.references=J,J.push({})}b(V,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 V=0;V0;g--){const i=Math.floor(Math.random()*(g+1)),I=e[g];e[g]=e[i],e[i]=I}return e}function K2t(e){return e.type==="filler"}function F2t(e){const g=e.end-e.start,i=e.strand===1?"+":"-",I=sg.nice();return K2t(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 D2t(e){const g=X2t(e),i=Y2t(g[0].features.filter(I=>I.type!=="source").sort((I,n)=>I.start-n.start));return{json:g,features:i}}async function x2t(e,{gzipped:g}){if(!g)return e.text();const i=await e.arrayBuffer();return B2t.inflate(i,{to:"string"})}let FVe=function(){function e(g){H2t(this,e),this.dataConfig=g,this.trackUid=sg.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=>x2t(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=>D2t(I))}return T2t(e,[{key:"tilesetInfo",value:function(i){return this.tilesetInfoLoading=!0,this.gbDataPromise.then(I=>{this.tilesetInfoLoading=!1;const n=1024,r={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(r),r}).catch(I=>{this.tilesetInfoLoading=!1,i&&i({error:`Error parsing genbank: ${I}`})})}},{key:"fetchTilesDebounced",value:async function(i,I){const n={},r=[],C=[];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}r.push(a),C.push(this.tile(A,l))}const o=await Promise.all(C);for(let a=0;ah.end>o&&h.starth.strand===1),A,"+"),c=QCe(s.filter(h=>h.strand!==1),A,"-"),u=[],d=20;for(let h=0;h=d);h++)r.features[h].end>=o&&r.features[h].start<=a&&u.push(r.features[h]);return[u,l,c].flatMap(h=>h.map(F2t))}}]),e}();function E2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function jCe(e,g){for(var i=0;i`localtile.${C}`);PQ(this.tilesData,"",r);for(const C of I)n[C]=this.tilesData[`localtile.${C}`];return i(n),n}},{key:"tile",value:function(i,I){}}]),e}();function J2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $Ce(e,g){for(var i=0;ir.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&&U2t(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 j2t=new Q2t;function $2t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qCe(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 fs(e){return fs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},fs(e)}function CHt(e,g,i,I,n){const r=e||n,C=0;return r==="log"&&g>0?["log",ru().range([254,0]).domain([g+C,I+C])]:["linear",tg().range([254,0]).domain([g,I])]}let hm=function(e){iHt(i,e);var g=IHt(i);function i(I,n){var r;$2t(this,i),r=g.call(this,I,n);const{pubSub:C,dataConfig:o,handleTilesetInfoReceived:a,animate:s,onValueScaleChanged:A}=I;return r.renderVersion=1,r.visibleTiles=new Set,r.visibleTileIds=new Set,r.renderingTiles=new Set,r.fetching=new Set,r.scale={},r.fetchedTiles={},r.tileGraphics={},r.maxZoom=0,r.medianVisibleValue=null,r.backgroundTaskScheduler=j2t,r.continuousScaling="requestIdleCallback"in window,r.valueScaleMin=null,r.fixedValueScaleMin=null,r.valueScaleMax=null,r.fixedValueScaleMax=null,r.listeners={},r.pubSub=C,r.animate=s,r.onValueScaleChanged=A,r.prevValueScale=null,I.dataFetcher?r.dataFetcher=I.dataFetcher:r.dataFetcher=new vk(o,r.pubSub),r.tilesetInfo=null,r.uuid=sg.nice(),r.trackNotFoundText=new ot.PIXI.Text("",{fontSize:"12px",fontFamily:"Arial",fill:"black"}),r.pLabel.addChild(r.trackNotFoundText),r.refreshTilesDebounced=rve(r.refreshTiles.bind(bP(r)),bX,bX),r.dataFetcher.tilesetInfo((l,c)=>{if(l){if(r.tilesetInfo=l,r.dataFetcher.dataConfig.tilesetUid||(r.dataFetcher.dataConfig.tilesetUid=c),r.tilesetUid=r.dataFetcher.dataConfig.tilesetUid,r.server=r.dataFetcher.dataConfig.server||"unknown",r.tilesetInfo&&r.tilesetInfo.chromsizes&&(r.chromInfo=XN(r.tilesetInfo.chromsizes)),"error"in r.tilesetInfo){console.warn("Error retrieving tilesetInfo:",o,r.tilesetInfo.error),r.tilesetInfo=null,r.setError(r.tilesetInfo.error);return}r.tilesetInfo.resolutions?r.maxZoom=r.tilesetInfo.resolutions.length:r.maxZoom=+r.tilesetInfo.max_zoom,r.options&&r.options.maxZoom&&(r.options.maxZoom>=0?r.maxZoom=Math.min(r.options.maxZoom,r.maxZoom):console.error("Invalid maxZoom on track:",bP(r))),r.refreshTiles(),a&&a(l),r.options||(r.options={}),r.options.name=r.options.name||l.name,r.checkValueScaleLimits(),r.draw(),r.drawLabel(),r.animate()}}),r}return q2t(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,r){this.listeners[n]||(this.listeners[n]=[]),this.listeners[n].push(r)}},{key:"off",value:function(n,r){const C=this.listeners[n].indexOf(r);C===-1||C>=this.listeners[n].length||this.listeners[n].splice(C,1)}},{key:"rerender",value:function(n){ud(fs(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(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r),mirrored:r.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.tileId))}},{key:"removeOldTiles",value:function(){this.calculateVisibleTiles();const r=[...new Set(Object.keys(this.fetchedTiles))].filter(C=>!this.visibleTileIds.has(C));this.removeTiles(r)}},{key:"refreshTiles",value:function(){if(!this.tilesetInfo)return;this.calculateVisibleTiles();const n=new Set(Object.keys(this.fetchedTiles)),r=[...this.visibleTiles].filter(C=>!this.fetching.has(C.remoteId)&&!n.has(C.tileId));for(let C=0;C0;)if(C-=1,o=o.map(s=>Math.floor(s/2)),`${r}.${C}.${o.join(".")}`in this.fetchedTiles)return!0;return!1}},{key:"parentTileId",value:function(n){const r=n.tileData.zoomLevel-1,C=n.tileData.tilePos.map(a=>Math.floor(a/2));return`${n.tileData.tilesetUid}.${r}.${C.join(".")}`}},{key:"removeTiles",value:function(n){!n.length||!this.areAllVisibleTilesLoaded()||this.renderingTiles.size||(n.forEach(r=>{const C=r;this.destroyTile(this.fetchedTiles[C]),C in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[C]),delete this.tileGraphics[C]),delete this.fetchedTiles[C]}),this.synchronizeTilesAndGraphics(),this.draw())}},{key:"zoomed",value:function(n,r,C=1,o=0,a=0){this.xScale(n),this.yScale(r),this.refreshTilesDebounced(),this.pMobile.position.x=o,this.pMobile.position.y=this.position[1],this.pMobile.scale.x=C,this.pMobile.scale.y=1}},{key:"setPosition",value:function(n){ud(fs(i.prototype),"setPosition",this).call(this,n)}},{key:"setDimensions",value:function(n){ud(fs(i.prototype),"setDimensions",this).call(this,n)}},{key:"areAllVisibleTilesLoaded",value:function(){const n=new Set(Object.keys(this.fetchedTiles)),r=[...this.visibleTileIds];for(let C=0;Cr.tileData))}},{key:"loadTileData",value:function(n,r){let C=this.lruCache.get(n.tileId);return C||(C=r(n.data,n.type),this.lruCache.put(n.tileId,C)),C}},{key:"fetchNewTiles",value:function(n){if(n.length>0){const r=[...new Set(n.map(C=>C.remoteId))];this.dataFetcher.fetchTilesDebounced(this.receivedTiles.bind(this),r)}}},{key:"receivedTiles",value:function(n){for(let r=0;rNumber.isNaN(+a)).forEach(a=>{this.fetchedTiles[C].tileData[a]=o[a]})}else this.fetchedTiles[C].tileData={...n[this.visibleTiles[r].remoteId]};this.fetchedTiles[C].tileData.error&&console.warn("Error in loaded tile",C,this.fetchedTiles[C].tileData)}}for(const r in n)if(n[r]){const C=n[r].tilePositionId;this.fetching.has(C)&&this.fetching.delete(C)}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(r=>r.tileData&&r.tileData.error&&`${r.tileId}: ${r.tileData.error}`).filter(r=>r);n.length?this.errorTextText=n.join(` +`):this.errorTextText="",ud(fs(i.prototype),"draw",this).call(this),Object.keys(this.fetchedTiles).forEach(r=>{this.drawTile(this.fetchedTiles[r])}),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 r=[].concat(...n.filter(C=>this.fetchedTiles[C].tileData.dense).map(C=>Array.from(this.fetchedTiles[C].tileData.dense))).filter(C=>C>0);return this.medianVisibleValue=F7(r),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 r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));let C=Math.min(...r.map(o=>this.fetchedTiles[o].tileData.minNonZero));return C===Number.MAX_SAFE_INTEGER&&(C=null),n?C:this.valueScaleMin!==null?this.valueScaleMin:C}},{key:"maxVisibleValue",value:function(n=!1){return this.maxVisibleValueInTiles(n)}},{key:"maxVisibleValueInTiles",value:function(n=!1){let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));let C=Math.max(...r.map(o=>this.fetchedTiles[o].tileData.maxNonZero));return C===Number.MIN_SAFE_INTEGER&&(C=null),n?C:this.valueScaleMax!==null?this.valueScaleMax:C}},{key:"makeValueScale",value:function(n,r,C,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]-Anh(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=IX().domain([...h]).range(nr(u,d,(d-u)/256));return m.ticks=f=>nh(u,d,f),[m,0]}else a=tg().domain([n,C]).range([c,l]);return[a,s]}}]),i}(mr);function oHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function eoe(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 ki(e){return ki=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},ki(e)}const toe=200,Kl=10,eG=40,Tn=10,Fl=Tn,goe=4,bf=1,Dl=4,ioe=5,mHt=256,uZ=Kl+eG+Tn+bf+Fl+Dl;let mw=function(e){cHt(i,e);var g=uHt(i);function i(I,n){var r;oHt(this,i);const C={...I};C.onValueScaleChanged=()=>{I.onValueScaleChanged(),r.drawColorbar()},r=g.call(this,C,n);const{pubSub:o,animate:a,svgElement:s,onTrackOptionsChanged:A,onMouseMoveZoom:l,isShowGlobalMousePosition:c,isValueScaleLocked:u}=I;return r.pubSub=o,r.is2d=!0,r.animate=a,r.uid=sg.nice(),r.scaleBrush=_S(),r.onTrackOptionsChanged=A,r.isShowGlobalMousePosition=c,r.isValueScaleLocked=u,r.pColorbarArea=new ot.PIXI.Graphics,r.pMasked.addChild(r.pColorbarArea),r.pColorbar=new ot.PIXI.Graphics,r.pColorbarArea.addChild(r.pColorbar),r.axis=new Zk(lW(r)),r.pColorbarArea.addChild(r.axis.pAxis),r.colorScale=Nb,n&&n.colorRange&&(r.colorScale=Oc(n.colorRange)),r.gBase=dg(s).append("g"),r.gMain=r.gBase.append("g"),r.gColorscaleBrush=r.gMain.append("g"),r.brushing=!1,r.prevOptions="",r.prevIndUpperLeftTile="",r.onMouseMoveZoom=l,r.setDataLensSize(11),r.dataLens=new Float32Array(r.dataLensSize**2),r.mouseMoveHandlerBound=r.mouseMoveHandler.bind(lW(r)),r.onMouseMoveZoom&&r.pubSubs.push(r.pubSub.subscribe("app.mouseMove",r.mouseMoveHandlerBound)),r.options&&r.options.showMousePosition&&!r.hideMousePosition&&(r.hideMousePosition=Ah(lW(r),r.is2d,r.isShowGlobalMousePosition())),r.prevOptions=JSON.stringify(n),r}return aHt(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,r=this.mouseY){if(typeof n>"u"||typeof r>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;const C=n-this.position[0],o=r-this.position[1];let a,s;try{s=this.getVisibleRectangleData(C-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=QQ(this.limitedValueScale,this.colorScale,this.valueScale.domain()[0])}catch{return}if(!l)return;const c=Math.round(this._xScale.invert(C)),u=Math.round(this._yScale.invert(o));let d=[c,u],h=[Math.round(this._xScale.invert(C-this.dataLensPadding)),Math.round(this._xScale.invert(C+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=>TI(f,this.chromInfo).slice(0,2)),h=h.map(f=>TI(f,this.chromInfo).slice(0,2)),m=m.map(f=>TI(f,this.chromInfo).slice(0,2))),this.onMouseMoveZoom({trackId:this.id,data:a,absX:n,absY:r,relX:C,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,r,C){const{tileX:o,tileY:a,tileWidth:s,tileHeight:A}=this.getTilePosAndDimensions(n,r),l={};return l.width=this._refXScale(o+s)-this._refXScale(o),l.height=this._refYScale(a+A)-this._refYScale(a),C?(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(),r=this.maxValue();const C=1e-6;n!=null&&r!==void 0&&r!==null&&Math.abs(n-r)this.renderTile(o)),this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),this.options&&this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=Ah(this,this.is2d,this.isShowGlobalMousePosition())))}},{key:"drawLabel",value:function(){this.options.labelPosition===this.options.colorbarPosition?this.labelXOffset=uZ:this.labelXOffset=0,nI(ki(i.prototype),"drawLabel",this).call(this)}},{key:"tileDataToCanvas",value:function(n){const r=document.createElement("canvas");r.width=this.binsPerTile(),r.height=this.binsPerTile();const C=r.getContext("2d");C.fillStyle="transparent",C.fillRect(0,0,r.width,r.height);const o=new ImageData(n,r.width,r.height);return C.putImageData(o,0,0),r}},{key:"exportData",value:function(){if(this.tilesetInfo){const n=this.getVisibleRectangleData(0,0,this.dimensions[0],this.dimensions[1]),r={bounds:[this._xScale.domain(),this._yScale.domain()],dimensions:n.shape,data:gve(n)};PG("data.json",JSON.stringify(r))}}},{key:"setSpriteProperties",value:function(n,r,C,o){const a=this.getAbsTileDim(r,C,o);n.width=a.width,n.height=a.height,n.x=a.x,n.y=a.y,o&&C[0]!==C[1]&&(n.rotation=-Math.PI/2,n.scale.x=Math.abs(n.scale.x)*-1)}},{key:"refXScale",value:function(n){nI(ki(i.prototype),"refXScale",this).call(this,n),this.draw()}},{key:"refYScale",value:function(n){nI(ki(i.prototype),"refYScale",this).call(this,n),this.draw()}},{key:"draw",value:function(){nI(ki(i.prototype),"draw",this).call(this)}},{key:"newBrushOptions",value:function(n){const r=JSON.parse(JSON.stringify(this.options)),C=this.valueScale.copy().range([this.colorbarHeight,0]),o=C.invert(n[0]),s=(C.invert(n[1])-C.domain()[0])/(C.domain()[1]-C.domain()[0]),A=(o-C.domain()[0])/(C.domain()[1]-C.domain()[0]);return r.scaleStartPercent=s.toFixed(ioe),r.scaleEndPercent=A.toFixed(ioe),r}},{key:"brushStart",value:function(){this.brushing=!0}},{key:"brushMoved",value:function(n){if(!n.selection)return;const r=this.newBrushOptions(n.selection),C=JSON.stringify(r);this.gColorscaleBrush.selectAll(".handle--custom").attr("y",o=>o.type==="n"?n.selection[0]:n.selection[1]-goe/2),C!==this.prevOptions&&(this.prevOptions=C,this.rerender(r,!0),this.onTrackOptionsChanged(r),this.isValueScaleLocked()&&this.onValueScaleChanged())}},{key:"brushEnd",value:function(){this.brushing=!1}},{key:"setPosition",value:function(n){nI(ki(i.prototype),"setPosition",this).call(this,n),this.drawColorbar()}},{key:"setDimensions",value:function(n){nI(ki(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,toe);if(this.colorbarHeight=n-2*Tn,this.colorbarHeight<0){this.removeColorbar();return}if(this.valueScale.domain()[1]===this.valueScale.domain()[0]){this.removeColorbar();return}const r=this.valueScale.copy().range([this.colorbarHeight,0]);this.options.colorbarPosition==="topLeft"||this.options.colorbarPosition==="bottomLeft"?this.scaleBrush.extent([[Dl,0],[Fl,this.colorbarHeight]]):this.scaleBrush.extent([[0,0],[Fl-Dl,this.colorbarHeight]]),this.options.colorbarPosition==="topLeft"&&([this.pColorbarArea.x,this.pColorbarArea.y]=this.position,this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=Dl+Fl+bf+Kl,this.pColorbar.x=Dl+Fl+bf,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+Dl},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="topRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-uZ,this.pColorbarArea.y=this.position[1],this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=eG+Tn,this.pColorbar.x=eG+Tn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Kl+2},${this.pColorbarArea.y+this.pColorbar.y-1})`)),this.options.colorbarPosition==="bottomRight"&&(this.pColorbarArea.x=this.position[0]+this.dimensions[0]-uZ,this.pColorbarArea.y=this.position[1]+this.dimensions[1]-n,this.pColorbar.y=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=eG+Tn,this.pColorbar.x=eG+Tn,this.gColorscaleBrush.attr("transform",`translate(${this.pColorbarArea.x+this.pColorbar.x+Kl+bf},${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=Tn,this.axis.pAxis.y=Tn,this.axis.pAxis.x=Dl+Fl+bf+Kl,this.pColorbar.x=Dl+Fl+bf,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,uZ,n),this.options?(this.options.scaleStartPercent||(this.options.scaleStartPercent=0),this.options.scaleEndPercent||(this.options.scaleEndPercent=1)):this.options={scaleStartPercent:0,scaleEndPercent:1};const C=r.domain()[1]-r.domain()[0],o=r(this.options.scaleStartPercent*C+r.domain()[0]),a=r(this.options.scaleEndPercent*C+r.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",Fl).attr("height",goe).style("fill","#666").style("stroke","white"),this.flipText&&this.northHandle.attr("cursor","ew-resize"),this.gColorscaleBrush.call(this.scaleBrush.move,[a,o]));const s=tg().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()),R=Math.floor(B/A),S=Math.floor((B+v)/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 Y=Math.min(h+f,S)-R,K=Math.min(m+b,W)-X,x=Math.max(R-h,0),J=Math.max(X-m,0),P=Y-V,ge=K-H;if(!(P<0||ge<0)){if(y.mirrored&&V>H){const q=V;V=H,H=q}qGe(p.hi(J+ge,x+P).lo(J,x),y.dataArray.hi(H+ge,V+P).lo(H,V))}}),p}},{key:"initTile",value:function(n){nI(ki(i.prototype),"initTile",this).call(this,n),n.tileData.dense.length===this.binsPerTile()**2&&(n.dataArray=kp(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(),nI(ki(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,r){if(r){const{graphics:C}=n,o=this.tileDataToCanvas(r.pixData);n.sprite&&n.sprite.destroy(!0);const a=ot.PIXI.VERSION[0]==="4"?ot.PIXI.Texture.fromCanvas(o,ot.PIXI.SCALE_MODES.NEAREST):ot.PIXI.Texture.from(o,{scaleMode:ot.PIXI.SCALE_MODES.NEAREST}),s=new ot.PIXI.Sprite(a);n.sprite=s,n.texture=a,n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),C.removeChildren(),C.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"renderTile",value:function(n){const[r]=this.updateValueScale(),C=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?kGe(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,nI(ki(i.prototype),"remove",this).call(this)}},{key:"refScalesChanged",value:function(n,r){nI(ki(i.prototype),"refScalesChanged",this).call(this,n,r),WN(this.fetchedTiles).filter(C=>C.sprite).forEach(C=>this.setSpriteProperties(C.sprite,C.tileData.zoomLevel,C.tileData.tilePos,C.mirrored))}},{key:"superSVG",value:function(){return nI(ki(i.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,r=null;nI(ki(i.prototype),"exportSVG",this)?[r,n]=nI(ki(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");n.appendChild(C),C.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),C.appendChild(A)}const o=this.exportColorBarSVG();return n.appendChild(o),[r,r]}},{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 r=n[0];for(let d=0;dd.tileId===r[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 r=this._xScale.range(),C=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=tg().domain([0,this.binsPerTile()]).range([a,a+A]),u=Math.max(0,Math.round(c.invert(this._xScale.invert(r[0])))-1),d=Math.min(this.binsPerTile(),Math.round(c.invert(this._xScale.invert(r[1])))),h=tg().domain([0,this.binsPerTile()]).range([s,s+l]),m=Math.max(0,Math.round(h.invert(this._yScale.invert(C[0])))-1),f=Math.min(this.binsPerTile(),Math.round(h.invert(this._yScale.invert(C[1]))));return n.mirrored&&o[0]!==o[1]?[m,u,f,d]:[u,m,d,f]}},{key:"minVisibleValue",value:function(n=!1){const r=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const a=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMinNonZeroInSubset(a)});if(r.length===0&&this.valueScaleMax===null)return null;const C=Math.min.apply(null,r);return C===Number.MAX_SAFE_INTEGER?nI(ki(i.prototype),"minVisibleValue",this).call(this,n):n?C:this.valueScaleMin!==null?this.valueScaleMin:C}},{key:"maxVisibleValue",value:function(n=!1){const r=this.visibleAndFetchedTiles().map(o=>{if(o.tileData.denseDataExtrema===void 0)return null;const a=this.getIndicesOfVisibleDataInTile(o);return o.tileData.denseDataExtrema.getMaxNonZeroInSubset(a)});if(r.length===0&&this.valueScaleMax===null)return null;const C=Math.max.apply(null,r);return C===Number.MIN_SAFE_INTEGER?nI(ki(i.prototype),"maxVisibleValue",this).call(this,n):n?C:this.valueScaleMax!==null?this.valueScaleMax:C}},{key:"zoomed",value:function(n,r,C,o,a){if(this.brushing)return;nI(ki(i.prototype),"zoomed",this).call(this,n,r),this.pMain.position.x=o,this.pMain.position.y=a,this.pMain.scale.x=C,this.pMain.scale.y=C;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,r,C,o,a,s=!1){const A=[r,C,o];A.mirrored=s,A.dataTransform=a,n.push(A)}},{key:"tilesToId",value:function(n,r,C){const o=n,a=r,s=this.options&&this.options.dataTransform||"default",A=[];for(let l=0;l=a[c]?this.options.extent!=="lower-left"&&this.addTileId(A,C,a[c],o[l],s,!0):this.options.extent!=="upper-right"&&this.addTileId(A,C,o[l],a[c],s),o[l]===a[c]&&this.options.extent==="lower-left"&&this.addTileId(A,C,o[l],a[c],s)):this.addTileId(A,C,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(r=>+r).sort((r,C)=>C-r);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,r){if(!this.options||!this.options.showTooltip||!this.tilesetInfo)return"";const C=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/C)/Math.log(10));this.setDataLensSize(1);const s=this._xScale.invert(n),A=this._yScale.invert(r);let l="Position: ";if(this.chromInfo){const u=TI(s,this.chromInfo),d=TI(A,this.chromInfo),h=m=>uC(`.${a}s`)(m);l+=`${u[0]}:${h(u[1])} & ${d[0]}:${h(d[1])}`,l+="
"}let c=null;try{c=this.getVisibleRectangleData(n,r,1,1).get(0,0)}catch{return""}return this.options&&this.options.heatmapValueScaling==="log"?c>0?`${l}Value: 1e${uC(".3f")(Math.log(c)/Math.log(10))}`:c===0?`${l}Value: 0`:`${l}Value: N/A`:`${l}Value: ${uC(".3f")(c)}`}},{key:"getTilePosAndDimensions",value:function(n,r,C){const o=C||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*r[0],Z=f*o*r[1];return{tileX:y,tileY:Z,tileWidth:b,tileHeight:p}}const a=r[0],s=r[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],r=this.tilesetInfo.max_pos[0],C=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,r),A=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._yScale,C,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 r=n.split(".");return r.slice(0,r.length-1).join(".")}}]),i}(hm);function fHt(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 qX(e){return qX=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},qX(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 r=1/((this._xScale(1)-this._xScale(0))/(this._refXScale(1)-this._refXScale(0))),C=1/((this._yScale(1)-this._yScale(0))/(this._refYScale(1)-this._refYScale(0)));e.text.scale.x=r,e.text.scale.y=C;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*r,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 EVe(e){const g=e.graphics;e.textGraphics=new ot.PIXI.Graphics,e.mirrored?e.text=new ot.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 ot.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 MVe=function(e){ZHt(i,e);var g=GHt(i);function i(){return fHt(this,i),g.apply(this,arguments)}return pHt(i,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){EVe.bind(this)(n),this.drawTile(n)}},{key:"destroyTile",value:function(n,r){}},{key:"drawTile",value:function(n){xVe.bind(this)(n)}},{key:"fetchNewTiles",value:function(n){n.forEach(r=>{const o=r.remoteId.split("."),a={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[r.tileId]=r,this.fetchedTiles[r.tileId].tileData=a,this.fetching.has(r.remoteId)&&this.fetching.delete(r.remoteId)}),this.synchronizeTilesAndGraphics()}}]),i}(mw);function wHt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function noe(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 Zh(e){return Zh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Zh(e)}const YHt=1024;let cj=function(e){HHt(i,e);var g=THt(i);function i(I,n){var r;wHt(this,i),r=g.call(this,I,n);const{onMouseMoveZoom:C,isValueScaleLocked:o,getLockGroupExtrema:a}=I;return r.onMouseMoveZoom=C,r.isValueScaleLocked=o,r.getLockGroupExtrema=a,r.onMouseMoveZoom&&r.pubSubs.push(r.pubSub.subscribe("app.mouseMove",r.mouseMoveHandler.bind(zVe(r)))),r}return RHt(i,[{key:"initTile",value:function(n){dv(Zh(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(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r)})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.tileId))}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const C=this.tilesetInfo.resolutions.map(s=>+s).sort((s,A)=>A-s),a=vt.calculateTilesFromResolution(C[this.zoomLevel],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]).map(s=>[this.zoomLevel,s]);this.setVisibleTiles(a);return}const r=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(C=>[this.zoomLevel,C]);this.setVisibleTiles(r)}},{key:"getTilePosAndDimensions",value:function(n,r,C){const o=r[0],a=r[0];if(this.tilesetInfo.resolutions){const f=C||YHt,p=this.tilesetInfo.resolutions.map(v=>+v).sort((v,w)=>w-v)[n],y=p*f,Z=y,B=p*f*r[0],G=p*f*r[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 r=this._xScale.range();if(!this.tilesetInfo)return[null,null];const{tileX:C,tileWidth:o}=this.getTilePosAndDimensions(n.tileData.zoomLevel,n.tileData.tilePos,this.tilesetInfo.bins_per_dimension||this.tilesetInfo.tile_size),a=tg().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([C,C+o]),s=Math.max(0,Math.round(a.invert(this._xScale.invert(r[0])))),A=Math.min(n.tileData.dense.length,Math.round(a.invert(this._xScale.invert(r[1]))));return[s,A]}},{key:"minVisibleValue",value:function(n=!1){let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));const C=r.map(a=>this.fetchedTiles[a]).map(a=>{const s=this.getIndicesOfVisibleDataInTile(a);return a.tileData.denseDataExtrema.getMinNonZeroInSubset(s)}),o=Math.min(...C);return n?o:this.valueScaleMin!==null?this.valueScaleMin:o}},{key:"maxVisibleValue",value:function(n=!1){let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));const C=r.map(a=>this.fetchedTiles[a]).map(a=>{const s=this.getIndicesOfVisibleDataInTile(a);return a.tileData.denseDataExtrema.getMaxNonZeroInSubset(s)}),o=Math.max(...C);return n?o:this.valueScaleMax!==null?this.valueScaleMax:o}},{key:"getAggregatedVisibleValue",value:function(n="max"){const r=n==="min"?Math.min:Math.max,C=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=tg().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)=>r(s,...A),C)}},{key:"getDataAtPos",value:function(n){let r;if(!this.tilesetInfo)return r;const C=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,C,this.tilesetInfo.tile_size),a=this._xScale.invert(n)/o,s=this.tileToLocalId([C,Math.floor(a)]),A=this.fetchedTiles[s];if(!A)return r;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:r}={}){this.isWithin(n,r)&&(this.mouseX=n,this.mouseY=r,this.mouseMoveZoomHandler())}},{key:"mouseMoveZoomHandler",value:function(){}},{key:"zoomed",value:function(...n){dv(Zh(i.prototype),"zoomed",this).call(this,...n),this.mouseMoveZoomHandler()}}]),i}(hm);function KHt(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 ps(e){return ps=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},ps(e)}let ny=function(e){MHt(i,e);var g=zHt(i);function i(I,n){var r;KHt(this,i),r=g.call(this,I,n);const{animate:C,isShowGlobalMousePosition:o}=I;return r.constIndicator=new ot.PIXI.Graphics,r.pMain.addChild(r.constIndicator),r.axis=new Zk(BP(r)),r.pBase.addChild(r.axis.pAxis),r.animate=C,r.options=n,r.isShowGlobalMousePosition=o,r.pubSubs=[],r.options.showMousePosition&&!r.hideMousePosition&&(r.hideMousePosition=Ah(BP(r),r.is2d,r.isShowGlobalMousePosition())),r}return FHt(i,[{key:"rerender",value:function(n,r){const C=JSON.stringify(n);!r&&C===this.prevOptions||(dd(ps(i.prototype),"rerender",this).call(this,n,r),this.prevOptions=C,this.options=n,this.options.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=Ah(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 r=Math.min(n,this.maxZoom);return r=Math.max(r,0),r}},{key:"relevantScale",value:function(){return this._xScale}},{key:"draw",value:function(){dd(ps(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 r=this.options.axisMargin||0;this.options.axisPositionHorizontal==="left"||this.options.axisPositionVertical==="top"?(this.axis.pAxis.position.x=this.position[0]+r,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]+r,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]-r,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]-r,this.axis.pAxis.position.y=this.position[1],this.axis.drawAxisRight(n,this.dimensions[1]))}},{key:"mouseMoveZoomHandler",value:function(n=this.mouseX,r=this.mouseY){if(typeof n>"u"||!this.areAllVisibleTilesLoaded()||!this.tilesetInfo)return;let C=0,o=0,a="1d-horizontal";this.isLeftModified?(C=r-this.position[1],o=n-this.position[0],a="1d-vertical"):(C=n-this.position[0],o=r-this.position[1]);const s=n-this.position[0],A=r-this.position[1],l=this._xScale.invert(C),c=this._yScale.invert(o),u=this.getDataAtPos(C);u&&this.onMouseMoveZoom({trackId:this.id,data:u,absX:n,absY:r,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:r=1,label:C=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,r);const d=this.valueScale(l);let h=0,m=0;if(C){const f=new ot.PIXI.Text(C,{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,r=null;dd(ps(i.prototype),"exportSVG",this)?[r,n]=dd(ps(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r),r.setAttribute("class","horizontal-tiled-1d-track");const C=document.createElement("g");return n.appendChild(C),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}C.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),C.appendChild(m)}),[r,n]}}]),i}(cj);function OHt(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 t0(e){return t0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},t0(e)}let PVe=function(e){jHt(i,e);var g=$Ht(i);function i(I,n){var r;return OHt(this,i),r=g.call(this,I,n),r.pMain=r.pMobile,r}return _Ht(i,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const r=n.graphics;n.textGraphics=new ot.PIXI.Graphics,n.text=new ot.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,r.addChild(n.textGraphics),this.drawTile(n)}},{key:"destroyTile",value:function(n){}},{key:"drawTile",value:function(n){if(cW(t0(i.prototype),"drawTile",this).call(this,n),!n.graphics)return;const r=n.graphics,{tileX:C,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,r.clear();const s=this.dimensions[1],A=this._refXScale(C+o)-this._refXScale(C);n.textGraphics.position.x=this._refXScale(C)+A/2,n.textGraphics.position.y=s/2;const l=this._refXScale(C);r.lineStyle(4*a,255,1),r.beginFill(16740363,.4),r.alpha=.5,r.moveTo(l,0),r.lineTo(l,s),r.moveTo(l+A,0),r.lineTo(l+A,s),r.lineStyle(0,255,1),r.drawRect(l,0,A,s)}}]),i}(ny);function gTt(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 g0(e){return g0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},g0(e)}let JVe=function(e){CTt(i,e);var g=oTt(i);function i(){return gTt(this,i),g.apply(this,arguments)}return iTt(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,r){uW(g0(i.prototype),"zoomed",this).call(this,n,r);const C=1,o=(r(1)-r(0))/(this._refYScale(1)-this._refYScale(0)),a=this.position[0],s=r(0)+this.position[1]-this._refYScale(1)*o;this.pMain.position.x=a,this.pMain.position.y=s,this.pMain.scale.x=C,this.pMain.scale.y=o}}]),i}(cj);function lTt(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 i0(e){return i0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},i0(e)}let OVe=function(e){mTt(i,e);var g=fTt(i);function i(){return lTt(this,i),g.apply(this,arguments)}return cTt(i,[{key:"areAllVisibleTilesLoaded",value:function(){return!0}},{key:"initTile",value:function(n){const r=n.graphics;n.textGraphics=new ot.PIXI.Graphics,n.text=new ot.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,r.addChild(n.textGraphics),this.drawTile(n,r)}},{key:"destroyTile",value:function(n,r){}},{key:"drawTile",value:function(n){if(dW(i0(i.prototype),"drawTile",this).call(this,n),!n.graphics)return;const r=n.graphics,{tileY:C,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,r.clear(),r.lineStyle(4*a,255,1),r.beginFill(16740363,.4),r.alpha=.5;const s=this.dimensions[0],A=this._refYScale(C+o)-this._refYScale(C);n.textGraphics.position.x=s/2,n.textGraphics.position.y=this._refYScale(C)+A/2,r.drawRect(0,this._refYScale(C),s,A)}},{key:"fetchNewTiles",value:function(n){n.forEach(r=>{const o=r.remoteId.split("."),a={zoomLevel:o[1],tilePos:o.slice(2,o.length).map(s=>+s)};this.fetchedTiles[r.tileId]=r,this.fetchedTiles[r.tileId].tileData=a,this.fetching.has(r.remoteId)&&this.fetching.delete(r.remoteId)}),this.synchronizeTilesAndGraphics()}}]),i}(JVe);var JD=Array.prototype.slice;function ZTt(e){return e}var hW=1,mW=2,VP=3,tG=4,Aoe=1e-6;function GTt(e){return"translate("+e+",0)"}function vTt(e){return"translate(0,"+e+")"}function BTt(e){return g=>+e(g)}function STt(e,g){return g=Math.max(0,e.bandwidth()-g*2)/2,e.round()&&(g=Math.round(g)),i=>+e(i)+g}function wTt(){return!this.__axis}function Rk(e,g){var i=[],I=null,n=null,r=6,C=6,o=3,a=typeof window<"u"&&window.devicePixelRatio>1?0:.5,s=e===hW||e===tG?-1:1,A=e===tG||e===mW?"x":"y",l=e===hW||e===VP?GTt:vTt;function c(u){var d=I??(g.ticks?g.ticks.apply(g,i):g.domain()),h=n??(g.tickFormat?g.tickFormat.apply(g,i):ZTt),m=Math.max(r,0)+o,f=g.range(),b=+f[0]+a,p=+f[f.length-1]+a,y=(g.bandwidth?STt:BTt)(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"),R=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),R=R.merge(w.append("line").attr("stroke","currentColor").attr(A+"2",s*r)),S=S.merge(w.append("text").attr("fill","currentColor").attr(A,s*m).attr("dy",e===hW?"0em":e===VP?"0.71em":"0.32em")),u!==Z&&(B=B.transition(u),G=G.transition(u),R=R.transition(u),S=S.transition(u),v=v.transition(u).attr("opacity",Aoe).attr("transform",function(X){return isFinite(X=y(X))?l(X+a):this.getAttribute("transform")}),w.attr("opacity",Aoe).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===tG||e===mW?C?"M"+s*C+","+b+"H"+a+"V"+p+"H"+s*C:"M"+a+","+b+"V"+p:C?"M"+b+","+s*C+"V"+a+"H"+p+"V"+s*C:"M"+b+","+a+"H"+p),G.attr("opacity",1).attr("transform",function(X){return l(y(X)+a)}),R.attr(A+"2",s*r),S.attr(A,s*m).text(h),Z.filter(wTt).attr("fill","none").attr("font-size",10).attr("font-family","sans-serif").attr("text-anchor",e===mW?"start":e===tG?"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=JD.call(arguments),c},c.tickArguments=function(u){return arguments.length?(i=u==null?[]:JD.call(u),c):i.slice()},c.tickValues=function(u){return arguments.length?(I=u==null?null:JD.call(u),c):I&&I.slice()},c.tickFormat=function(u){return arguments.length?(n=u,c):n},c.tickSize=function(u){return arguments.length?(r=C=+u,c):r},c.tickSizeInner=function(u){return arguments.length?(r=+u,c):r},c.tickSizeOuter=function(u){return arguments.length?(C=+u,c):C},c.tickPadding=function(u){return arguments.length?(o=+u,c):o},c.offset=function(u){return arguments.length?(a=+u,c):a},c}function _Ve(e){return Rk(hW,e)}function RTt(e){return Rk(mW,e)}function VTt(e){return Rk(VP,e)}function LVe(e){return Rk(tG,e)}const WTt=Object.freeze(Object.defineProperty({__proto__:null,axisBottom:VTt,axisLeft:LVe,axisRight:RTt,axisTop:_Ve},Symbol.toStringTag,{value:"Module"}));function XTt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function soe(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 mm=function(e){kTt(i,e);var g=YTt(i);function i(I,n){var r;XTt(this,i),r=g.call(this,I,n);const{svgElement:C}=I;return r.gMain=dg(C).append("g"),r.clipUid=sg.nice(),r.clipRect=r.gMain.append("clipPath").attr("id",`track-bounds-${r.clipUid}`).append("rect"),r.gMain.attr("clip-path",`url(#track-bounds-${r.clipUid})`),r}return HTt(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}(xp);function xTt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function loe(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 Gh(e){return Gh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Gh(e)}let UVe=function(e){JTt(i,e);var g=OTt(i);function i(I,n){var r;return xTt(this,i),r=g.call(this,I,n),r.axis=_Ve(r._xScale),r.gAxis=r.gMain.append("g"),r.tilesetInfo=!0,r}return ETt(i,[{key:"setDimensions",value:function(n){hv(Gh(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,r){hv(Gh(i.prototype),"zoomed",this).call(this,n,r),this.draw()}}]),i}(mm);function QTt(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 vh(e){return vh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},vh(e)}let QVe=function(e){tNt(i,e);var g=gNt(i);function i(I,n){var r;return QTt(this,i),r=g.call(this,I,n),r.axis=LVe(r._yScale),r.gAxis=r.gMain.append("g"),r.tilesetInfo=!0,r}return jTt(i,[{key:"setDimensions",value:function(n){mv(vh(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,r){mv(vh(i.prototype),"zoomed",this).call(this,n,r),this.draw()}}]),i}(mm);var Ag={},Xi={},uj=32;Xi.INT_BITS=uj;Xi.INT_MAX=2147483647;Xi.INT_MIN=-1<0)-(e<0)};Xi.abs=function(e){var g=e>>uj-1;return(e^g)-g};Xi.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};Xi.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};Xi.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function jVe(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}Xi.countTrailingZeros=jVe;Xi.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};Xi.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};Xi.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var gG=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|gG[e>>>16&255]<<8|gG[e>>>24&255]};Xi.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};Xi.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};Xi.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};Xi.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};Xi.nextCombination=function(e){var g=e|e-1;return g+1|(~g&-~g)-1>>>jVe(e)+1};function $Ve(e,g,i){var I=e[i]|0;if(I<=0)return[];var n=new Array(I),r;if(i===e.length-1)for(r=0;r"u"&&(g=0),typeof e){case"number":if(e>0)return rNt(e|0,g);break;case"object":if(typeof e.length=="number")return $Ve(e,g,0);break}return[]}var oNt=CNt,qVe={},Vk={};Vk.byteLength=sNt;Vk.toByteArray=cNt;Vk.fromByteArray=hNt;var Qa=[],WC=[],aNt=typeof Uint8Array<"u"?Uint8Array:Array,OD="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var $m=0,ANt=OD.length;$m0)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 sNt(e){var g=e1e(e),i=g[0],I=g[1];return(i+I)*3/4-I}function lNt(e,g,i){return(g+i)*3/4-i}function cNt(e){var g,i=e1e(e),I=i[0],n=i[1],r=new aNt(lNt(e,I,n)),C=0,o=n>0?I-4:I,a;for(a=0;a>16&255,r[C++]=g>>8&255,r[C++]=g&255;return n===2&&(g=WC[e.charCodeAt(a)]<<2|WC[e.charCodeAt(a+1)]>>4,r[C++]=g&255),n===1&&(g=WC[e.charCodeAt(a)]<<10|WC[e.charCodeAt(a+1)]<<4|WC[e.charCodeAt(a+2)]>>2,r[C++]=g>>8&255,r[C++]=g&255),r}function uNt(e){return Qa[e>>18&63]+Qa[e>>12&63]+Qa[e>>6&63]+Qa[e&63]}function dNt(e,g,i){for(var I,n=[],r=g;ro?o:C+r));return I===1?(g=e[i-1],n.push(Qa[g>>2]+Qa[g<<4&63]+"==")):I===2&&(g=(e[i-2]<<8)+e[i-1],n.push(Qa[g>>10]+Qa[g>>4&63]+Qa[g<<2&63]+"=")),n.join("")}var dj={};/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */dj.read=function(e,g,i,I,n){var r,C,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,r=u&(1<<-A)-1,u>>=-A,A+=o;A>0;r=r*256+e[g+l],l+=c,A-=8);for(C=r&(1<<-A)-1,r>>=-A,A+=I;A>0;C=C*256+e[g+l],l+=c,A-=8);if(r===0)r=1-s;else{if(r===a)return C?NaN:(u?-1:1)*(1/0);C=C+Math.pow(2,I),r=r-s}return(u?-1:1)*C*Math.pow(2,r-I)};dj.write=function(e,g,i,I,n,r){var C,o,a,s=r*8-n-1,A=(1<>1,c=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=I?0:r-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,C=A):(C=Math.floor(Math.log(g)/Math.LN2),g*(a=Math.pow(2,-C))<1&&(C--,a*=2),C+l>=1?g+=c/a:g+=c*Math.pow(2,1-l),g*a>=2&&(C++,a/=2),C+l>=A?(o=0,C=A):C+l>=1?(o=(g*a-1)*Math.pow(2,n),C=C+l):(o=g*Math.pow(2,l-1)*Math.pow(2,n),C=0));n>=8;e[i+u]=o&255,u+=d,o/=256,n-=8);for(C=C<0;e[i+u]=C&255,u+=d,C/=256,s-=8);e[i+u-d]|=h*128};/*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT - */(function(e){function g(Ce,E){if(!(Ce instanceof E))throw new TypeError("Cannot call a class as a function")}function I(Ce,E){for(var _=0;_"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(Ce){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(_){return _.__proto__||Object.getPrototypeOf(_)},c(Ce)}const u=Sk,d=a4,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 Ce=new Uint8Array(1),E={foo:function(){return 42}};return Object.setPrototypeOf(E,Uint8Array.prototype),Object.setPrototypeOf(Ce,E),Ce.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(Ce){if(Ce>m)throw new RangeError('The value "'+Ce+'" is invalid for option "size"');const E=new Uint8Array(Ce);return Object.setPrototypeOf(E,p.prototype),E}function p(Ce,E,_){if(typeof Ce=="number"){if(typeof E=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return G(Ce)}return y(Ce,E,_)}p.poolSize=8192;function y(Ce,E,_){if(typeof Ce=="string")return v(Ce,E);if(ArrayBuffer.isView(Ce))return V(Ce);if(Ce==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof Ce);if(je(Ce,ArrayBuffer)||Ce&&je(Ce.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(je(Ce,SharedArrayBuffer)||Ce&&je(Ce.buffer,SharedArrayBuffer)))return S(Ce,E,_);if(typeof Ce=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const fe=Ce.valueOf&&Ce.valueOf();if(fe!=null&&fe!==Ce)return p.from(fe,E,_);const Ye=X(Ce);if(Ye)return Ye;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof Ce[Symbol.toPrimitive]=="function")return p.from(Ce[Symbol.toPrimitive]("string"),E,_);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof Ce)}p.from=function(Ce,E,_){return y(Ce,E,_)},Object.setPrototypeOf(p.prototype,Uint8Array.prototype),Object.setPrototypeOf(p,Uint8Array);function Z(Ce){if(typeof Ce!="number")throw new TypeError('"size" argument must be of type number');if(Ce<0)throw new RangeError('The value "'+Ce+'" is invalid for option "size"')}function B(Ce,E,_){return Z(Ce),Ce<=0?b(Ce):E!==void 0?typeof _=="string"?b(Ce).fill(E,_):b(Ce).fill(E):b(Ce)}p.alloc=function(Ce,E,_){return B(Ce,E,_)};function G(Ce){return Z(Ce),b(Ce<0?0:W(Ce)|0)}p.allocUnsafe=function(Ce){return G(Ce)},p.allocUnsafeSlow=function(Ce){return G(Ce)};function v(Ce,E){if((typeof E!="string"||E==="")&&(E="utf8"),!p.isEncoding(E))throw new TypeError("Unknown encoding: "+E);const _=H(Ce,E)|0;let fe=b(_);const Ye=fe.write(Ce,E);return Ye!==_&&(fe=fe.slice(0,Ye)),fe}function w(Ce){const E=Ce.length<0?0:W(Ce.length)|0,_=b(E);for(let fe=0;fe=m)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+m.toString(16)+" bytes");return Ce|0}function R(Ce){return+Ce!=Ce&&(Ce=0),p.alloc(+Ce)}p.isBuffer=function(E){return E!=null&&E._isBuffer===!0&&E!==p.prototype},p.compare=function(E,_){if(je(E,Uint8Array)&&(E=p.from(E,E.offset,E.byteLength)),je(_,Uint8Array)&&(_=p.from(_,_.offset,_.byteLength)),!p.isBuffer(E)||!p.isBuffer(_))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(E===_)return 0;let fe=E.length,Ye=_.length;for(let ue=0,le=Math.min(fe,Ye);ueYe.length?(p.isBuffer(le)||(le=p.from(le)),le.copy(Ye,ue)):Uint8Array.prototype.set.call(Ye,le,ue);else if(p.isBuffer(le))le.copy(Ye,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=le.length}return Ye};function H(Ce,E){if(p.isBuffer(Ce))return Ce.length;if(ArrayBuffer.isView(Ce)||je(Ce,ArrayBuffer))return Ce.byteLength;if(typeof Ce!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof Ce);const _=Ce.length,fe=arguments.length>2&&arguments[2]===!0;if(!fe&&_===0)return 0;let Ye=!1;for(;;)switch(E){case"ascii":case"latin1":case"binary":return _;case"utf8":case"utf-8":return k(Ce).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _*2;case"hex":return _>>>1;case"base64":return Re(Ce).length;default:if(Ye)return fe?-1:k(Ce).length;E=(""+E).toLowerCase(),Ye=!0}}p.byteLength=H;function Y(Ce,E,_){let fe=!1;if((E===void 0||E<0)&&(E=0),E>this.length||((_===void 0||_>this.length)&&(_=this.length),_<=0)||(_>>>=0,E>>>=0,_<=E))return"";for(Ce||(Ce="utf8");;)switch(Ce){case"hex":return pe(this,E,_);case"utf8":case"utf-8":return Q(this,E,_);case"ascii":return ne(this,E,_);case"latin1":case"binary":return be(this,E,_);case"base64":return te(this,E,_);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ve(this,E,_);default:if(fe)throw new TypeError("Unknown encoding: "+Ce);Ce=(Ce+"").toLowerCase(),fe=!0}}p.prototype._isBuffer=!0;function K(Ce,E,_){const fe=Ce[E];Ce[E]=Ce[_],Ce[_]=fe}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 _=0;__&&(E+=" ... "),""},h&&(p.prototype[h]=p.prototype.inspect),p.prototype.compare=function(E,_,fe,Ye,ue){if(je(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(_===void 0&&(_=0),fe===void 0&&(fe=E?E.length:0),Ye===void 0&&(Ye=0),ue===void 0&&(ue=this.length),_<0||fe>E.length||Ye<0||ue>this.length)throw new RangeError("out of range index");if(Ye>=ue&&_>=fe)return 0;if(Ye>=ue)return-1;if(_>=fe)return 1;if(_>>>=0,fe>>>=0,Ye>>>=0,ue>>>=0,this===E)return 0;let le=ue-Ye,re=fe-_;const oe=Math.min(le,re),Ve=this.slice(Ye,ue),Fe=E.slice(_,fe);for(let xe=0;xe2147483647?_=2147483647:_<-2147483648&&(_=-2147483648),_=+_,at(_)&&(_=Ye?0:Ce.length-1),_<0&&(_=Ce.length+_),_>=Ce.length){if(Ye)return-1;_=Ce.length-1}else if(_<0)if(Ye)_=0;else return-1;if(typeof E=="string"&&(E=p.from(E,fe)),p.isBuffer(E))return E.length===0?-1:J(Ce,E,_,fe,Ye);if(typeof E=="number")return E=E&255,typeof Uint8Array.prototype.indexOf=="function"?Ye?Uint8Array.prototype.indexOf.call(Ce,E,_):Uint8Array.prototype.lastIndexOf.call(Ce,E,_):J(Ce,[E],_,fe,Ye);throw new TypeError("val must be string, number or Buffer")}function J(Ce,E,_,fe,Ye){let ue=1,le=Ce.length,re=E.length;if(fe!==void 0&&(fe=String(fe).toLowerCase(),fe==="ucs2"||fe==="ucs-2"||fe==="utf16le"||fe==="utf-16le")){if(Ce.length<2||E.length<2)return-1;ue=2,le/=2,re/=2,_/=2}function oe(Fe,xe){return ue===1?Fe[xe]:Fe.readUInt16BE(xe*ue)}let Ve;if(Ye){let Fe=-1;for(Ve=_;Vele&&(_=le-re),Ve=_;Ve>=0;Ve--){let Fe=!0;for(let xe=0;xeYe&&(fe=Ye)):fe=Ye;const ue=E.length;fe>ue/2&&(fe=ue/2);let le;for(le=0;le>>0,isFinite(fe)?(fe=fe>>>0,Ye===void 0&&(Ye="utf8")):(Ye=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),E.length>0&&(fe<0||_<0)||_>this.length)throw new RangeError("Attempt to write outside buffer bounds");Ye||(Ye="utf8");let le=!1;for(;;)switch(Ye){case"hex":return P(this,E,_,fe);case"utf8":case"utf-8":return ge(this,E,_,fe);case"ascii":case"latin1":case"binary":return q(this,E,_,fe);case"base64":return $(this,E,_,fe);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,E,_,fe);default:if(le)throw new TypeError("Unknown encoding: "+Ye);Ye=(""+Ye).toLowerCase(),le=!0}},p.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function te(Ce,E,_){return E===0&&_===Ce.length?u.fromByteArray(Ce):u.fromByteArray(Ce.slice(E,_))}function Q(Ce,E,_){_=Math.min(Ce.length,_);const fe=[];let Ye=E;for(;Ye<_;){const ue=Ce[Ye];let le=null,re=ue>239?4:ue>223?3:ue>191?2:1;if(Ye+re<=_){let oe,Ve,Fe,xe;switch(re){case 1:ue<128&&(le=ue);break;case 2:oe=Ce[Ye+1],(oe&192)===128&&(xe=(ue&31)<<6|oe&63,xe>127&&(le=xe));break;case 3:oe=Ce[Ye+1],Ve=Ce[Ye+2],(oe&192)===128&&(Ve&192)===128&&(xe=(ue&15)<<12|(oe&63)<<6|Ve&63,xe>2047&&(xe<55296||xe>57343)&&(le=xe));break;case 4:oe=Ce[Ye+1],Ve=Ce[Ye+2],Fe=Ce[Ye+3],(oe&192)===128&&(Ve&192)===128&&(Fe&192)===128&&(xe=(ue&15)<<18|(oe&63)<<12|(Ve&63)<<6|Fe&63,xe>65535&&xe<1114112&&(le=xe))}}le===null?(le=65533,re=1):le>65535&&(le-=65536,fe.push(le>>>10&1023|55296),le=56320|le&1023),fe.push(le),Ye+=re}return he(fe)}const ie=4096;function he(Ce){const E=Ce.length;if(E<=ie)return String.fromCharCode.apply(String,Ce);let _="",fe=0;for(;fefe)&&(_=fe);let Ye="";for(let ue=E;ue<_;++ue)Ye+=bt[Ce[ue]];return Ye}function ve(Ce,E,_){const fe=Ce.slice(E,_);let Ye="";for(let ue=0;uefe&&(E=fe),_<0?(_+=fe,_<0&&(_=0)):_>fe&&(_=fe),__)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUintLE=p.prototype.readUIntLE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E],ue=1,le=0;for(;++le<_&&(ue*=256);)Ye+=this[E+le]*ue;return Ye},p.prototype.readUintBE=p.prototype.readUIntBE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E+--_],ue=1;for(;_>0&&(ue*=256);)Ye+=this[E+--_]*ue;return Ye},p.prototype.readUint8=p.prototype.readUInt8=function(E,_){return E=E>>>0,_||We(E,1,this.length),this[E]},p.prototype.readUint16LE=p.prototype.readUInt16LE=function(E,_){return E=E>>>0,_||We(E,2,this.length),this[E]|this[E+1]<<8},p.prototype.readUint16BE=p.prototype.readUInt16BE=function(E,_){return E=E>>>0,_||We(E,2,this.length),this[E]<<8|this[E+1]},p.prototype.readUint32LE=p.prototype.readUInt32LE=function(E,_){return E=E>>>0,_||We(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,_){return E=E>>>0,_||We(E,4,this.length),this[E]*16777216+(this[E+1]<<16|this[E+2]<<8|this[E+3])},p.prototype.readBigUInt64LE=ct(function(E){E=E>>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=_+this[++E]*2**8+this[++E]*2**16+this[++E]*2**24,ue=this[++E]+this[++E]*2**8+this[++E]*2**16+fe*2**24;return BigInt(Ye)+(BigInt(ue)<>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=_*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+fe;return(BigInt(Ye)<>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E],ue=1,le=0;for(;++le<_&&(ue*=256);)Ye+=this[E+le]*ue;return ue*=128,Ye>=ue&&(Ye-=Math.pow(2,8*_)),Ye},p.prototype.readIntBE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=_,ue=1,le=this[E+--Ye];for(;Ye>0&&(ue*=256);)le+=this[E+--Ye]*ue;return ue*=128,le>=ue&&(le-=Math.pow(2,8*_)),le},p.prototype.readInt8=function(E,_){return E=E>>>0,_||We(E,1,this.length),this[E]&128?(255-this[E]+1)*-1:this[E]},p.prototype.readInt16LE=function(E,_){E=E>>>0,_||We(E,2,this.length);const fe=this[E]|this[E+1]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt16BE=function(E,_){E=E>>>0,_||We(E,2,this.length);const fe=this[E+1]|this[E]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt32LE=function(E,_){return E=E>>>0,_||We(E,4,this.length),this[E]|this[E+1]<<8|this[E+2]<<16|this[E+3]<<24},p.prototype.readInt32BE=function(E,_){return E=E>>>0,_||We(E,4,this.length),this[E]<<24|this[E+1]<<16|this[E+2]<<8|this[E+3]},p.prototype.readBigInt64LE=ct(function(E){E=E>>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=this[E+4]+this[E+5]*2**8+this[E+6]*2**16+(fe<<24);return(BigInt(Ye)<>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=(_<<24)+this[++E]*2**16+this[++E]*2**8+this[++E];return(BigInt(Ye)<>>0,_||We(E,4,this.length),d.read(this,E,!0,23,4)},p.prototype.readFloatBE=function(E,_){return E=E>>>0,_||We(E,4,this.length),d.read(this,E,!1,23,4)},p.prototype.readDoubleLE=function(E,_){return E=E>>>0,_||We(E,8,this.length),d.read(this,E,!0,52,8)},p.prototype.readDoubleBE=function(E,_){return E=E>>>0,_||We(E,8,this.length),d.read(this,E,!1,52,8)};function Be(Ce,E,_,fe,Ye,ue){if(!p.isBuffer(Ce))throw new TypeError('"buffer" argument must be a Buffer instance');if(E>Ye||ECe.length)throw new RangeError("Index out of range")}p.prototype.writeUintLE=p.prototype.writeUIntLE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,fe=fe>>>0,!Ye){const re=Math.pow(2,8*fe)-1;Be(this,E,_,fe,re,0)}let ue=1,le=0;for(this[_]=E&255;++le>>0,fe=fe>>>0,!Ye){const re=Math.pow(2,8*fe)-1;Be(this,E,_,fe,re,0)}let ue=fe-1,le=1;for(this[_+ue]=E&255;--ue>=0&&(le*=256);)this[_+ue]=E/le&255;return _+fe},p.prototype.writeUint8=p.prototype.writeUInt8=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,1,255,0),this[_]=E&255,_+1},p.prototype.writeUint16LE=p.prototype.writeUInt16LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,65535,0),this[_]=E&255,this[_+1]=E>>>8,_+2},p.prototype.writeUint16BE=p.prototype.writeUInt16BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,65535,0),this[_]=E>>>8,this[_+1]=E&255,_+2},p.prototype.writeUint32LE=p.prototype.writeUInt32LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,4294967295,0),this[_+3]=E>>>24,this[_+2]=E>>>16,this[_+1]=E>>>8,this[_]=E&255,_+4},p.prototype.writeUint32BE=p.prototype.writeUInt32BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,4294967295,0),this[_]=E>>>24,this[_+1]=E>>>16,this[_+2]=E>>>8,this[_+3]=E&255,_+4};function Je(Ce,E,_,fe,Ye){ae(E,fe,Ye,Ce,_,7);let ue=Number(E&BigInt(4294967295));Ce[_++]=ue,ue=ue>>8,Ce[_++]=ue,ue=ue>>8,Ce[_++]=ue,ue=ue>>8,Ce[_++]=ue;let le=Number(E>>BigInt(32)&BigInt(4294967295));return Ce[_++]=le,le=le>>8,Ce[_++]=le,le=le>>8,Ce[_++]=le,le=le>>8,Ce[_++]=le,_}function Pe(Ce,E,_,fe,Ye){ae(E,fe,Ye,Ce,_,7);let ue=Number(E&BigInt(4294967295));Ce[_+7]=ue,ue=ue>>8,Ce[_+6]=ue,ue=ue>>8,Ce[_+5]=ue,ue=ue>>8,Ce[_+4]=ue;let le=Number(E>>BigInt(32)&BigInt(4294967295));return Ce[_+3]=le,le=le>>8,Ce[_+2]=le,le=le>>8,Ce[_+1]=le,le=le>>8,Ce[_]=le,_+8}p.prototype.writeBigUInt64LE=ct(function(E,_=0){return Je(this,E,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeBigUInt64BE=ct(function(E,_=0){return Pe(this,E,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeIntLE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,!Ye){const oe=Math.pow(2,8*fe-1);Be(this,E,_,fe,oe-1,-oe)}let ue=0,le=1,re=0;for(this[_]=E&255;++ue>0)-re&255;return _+fe},p.prototype.writeIntBE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,!Ye){const oe=Math.pow(2,8*fe-1);Be(this,E,_,fe,oe-1,-oe)}let ue=fe-1,le=1,re=0;for(this[_+ue]=E&255;--ue>=0&&(le*=256);)E<0&&re===0&&this[_+ue+1]!==0&&(re=1),this[_+ue]=(E/le>>0)-re&255;return _+fe},p.prototype.writeInt8=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,1,127,-128),E<0&&(E=255+E+1),this[_]=E&255,_+1},p.prototype.writeInt16LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,32767,-32768),this[_]=E&255,this[_+1]=E>>>8,_+2},p.prototype.writeInt16BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,32767,-32768),this[_]=E>>>8,this[_+1]=E&255,_+2},p.prototype.writeInt32LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,2147483647,-2147483648),this[_]=E&255,this[_+1]=E>>>8,this[_+2]=E>>>16,this[_+3]=E>>>24,_+4},p.prototype.writeInt32BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,2147483647,-2147483648),E<0&&(E=4294967295+E+1),this[_]=E>>>24,this[_+1]=E>>>16,this[_+2]=E>>>8,this[_+3]=E&255,_+4},p.prototype.writeBigInt64LE=ct(function(E,_=0){return Je(this,E,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),p.prototype.writeBigInt64BE=ct(function(E,_=0){return Pe(this,E,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function De(Ce,E,_,fe,Ye,ue){if(_+fe>Ce.length)throw new RangeError("Index out of range");if(_<0)throw new RangeError("Index out of range")}function Qe(Ce,E,_,fe,Ye){return E=+E,_=_>>>0,Ye||De(Ce,E,_,4),d.write(Ce,E,_,fe,23,4),_+4}p.prototype.writeFloatLE=function(E,_,fe){return Qe(this,E,_,!0,fe)},p.prototype.writeFloatBE=function(E,_,fe){return Qe(this,E,_,!1,fe)};function _e(Ce,E,_,fe,Ye){return E=+E,_=_>>>0,Ye||De(Ce,E,_,8),d.write(Ce,E,_,fe,52,8),_+8}p.prototype.writeDoubleLE=function(E,_,fe){return _e(this,E,_,!0,fe)},p.prototype.writeDoubleBE=function(E,_,fe){return _e(this,E,_,!1,fe)},p.prototype.copy=function(E,_,fe,Ye){if(!p.isBuffer(E))throw new TypeError("argument should be a Buffer");if(fe||(fe=0),!Ye&&Ye!==0&&(Ye=this.length),_>=E.length&&(_=E.length),_||(_=0),Ye>0&&Ye=this.length)throw new RangeError("Index out of range");if(Ye<0)throw new RangeError("sourceEnd out of bounds");Ye>this.length&&(Ye=this.length),E.length-_>>0,fe=fe===void 0?this.length:fe>>>0,E||(E=0);let ue;if(typeof E=="number")for(ue=_;ue2**32?Ye=tt(String(_)):typeof _=="bigint"&&(Ye=String(_),(_>BigInt(2)**BigInt(32)||_<-(BigInt(2)**BigInt(32)))&&(Ye=tt(Ye)),Ye+="n"),fe+=` It must be ${E}. Received ${Ye}`,fe},RangeError);function tt(Ce){let E="",_=Ce.length;const fe=Ce[0]==="-"?1:0;for(;_>=fe+4;_-=3)E=`_${Ce.slice(_-3,_)}${E}`;return`${Ce.slice(0,_)}${E}`}function Xe(Ce,E,_){ye(E,"offset"),(Ce[E]===void 0||Ce[E+_]===void 0)&&He(E,Ce.length-(_+1))}function ae(Ce,E,_,fe,Ye,ue){if(Ce>_||Ce3?E===0||E===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=`>= ${E}${le} and <= ${_}${le}`,new gt.ERR_OUT_OF_RANGE("value",re,Ce)}Xe(fe,Ye,ue)}function ye(Ce,E){if(typeof Ce!="number")throw new gt.ERR_INVALID_ARG_TYPE(E,"number",Ce)}function He(Ce,E,_){throw Math.floor(Ce)!==Ce?(ye(Ce,_),new gt.ERR_OUT_OF_RANGE(_||"offset","an integer",Ce)):E<0?new gt.ERR_BUFFER_OUT_OF_BOUNDS:new gt.ERR_OUT_OF_RANGE(_||"offset",`>= ${_?1:0} and <= ${E}`,Ce)}const x=/[^+/0-9A-Za-z-_]/g;function T(Ce){if(Ce=Ce.split("=")[0],Ce=Ce.trim().replace(x,""),Ce.length<2)return"";for(;Ce.length%4!==0;)Ce=Ce+"=";return Ce}function k(Ce,E){E=E||1/0;let _;const fe=Ce.length;let Ye=null;const ue=[];for(let le=0;le55295&&_<57344){if(!Ye){if(_>56319){(E-=3)>-1&&ue.push(239,191,189);continue}else if(le+1===fe){(E-=3)>-1&&ue.push(239,191,189);continue}Ye=_;continue}if(_<56320){(E-=3)>-1&&ue.push(239,191,189),Ye=_;continue}_=(Ye-55296<<10|_-56320)+65536}else Ye&&(E-=3)>-1&&ue.push(239,191,189);if(Ye=null,_<128){if((E-=1)<0)break;ue.push(_)}else if(_<2048){if((E-=2)<0)break;ue.push(_>>6|192,_&63|128)}else if(_<65536){if((E-=3)<0)break;ue.push(_>>12|224,_>>6&63|128,_&63|128)}else if(_<1114112){if((E-=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 Ie(Ce){const E=[];for(let _=0;_>8,Ye=_%256,ue.push(Ye),ue.push(fe);return ue}function Re(Ce){return u.toByteArray(T(Ce))}function we(Ce,E,_,fe){let Ye;for(Ye=0;Ye=E.length||Ye>=Ce.length);++Ye)E[Ye+_]=Ce[Ye];return Ye}function je(Ce,E){return Ce instanceof E||Ce!=null&&Ce.constructor!=null&&Ce.constructor.name!=null&&Ce.constructor.name===E.name}function at(Ce){return Ce!==Ce}const bt=function(){const Ce="0123456789abcdef",E=new Array(256);for(let _=0;_<16;++_){const fe=_*16;for(let Ye=0;Ye<16;++Ye)E[fe+Ye]=Ce[_]+Ce[Ye]}return E}();function ct(Ce){return typeof BigInt>"u"?Ht:Ce}function Ht(){throw new Error("BigInt not supported")}})(JRe);var Lc=XI,rn=tNt,_Re=JRe.Buffer;globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:rn([32,0]),UINT16:rn([32,0]),UINT32:rn([32,0]),BIGUINT64:rn([32,0]),INT8:rn([32,0]),INT16:rn([32,0]),INT32:rn([32,0]),BIGINT64:rn([32,0]),FLOAT:rn([32,0]),DOUBLE:rn([32,0]),DATA:rn([32,0]),UINT8C:rn([32,0]),BUFFER:rn([32,0])});var ANt=typeof Uint8ClampedArray<"u",sNt=typeof BigUint64Array<"u",lNt=typeof BigInt64Array<"u",oi=globalThis.__TYPEDARRAY_POOL;oi.UINT8C||(oi.UINT8C=rn([32,0]));oi.BIGUINT64||(oi.BIGUINT64=rn([32,0]));oi.BIGINT64||(oi.BIGINT64=rn([32,0]));oi.BUFFER||(oi.BUFFER=rn([32,0]));var wk=oi.DATA,Vk=oi.BUFFER;Ag.free=function(g){if(_Re.isBuffer(g))Vk[Lc.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=Lc.log2(I)|0;wk[i].push(g)}};function LRe(e){if(e){var g=e.length||e.byteLength,I=Lc.log2(g);wk[I].push(e)}}function cNt(e){LRe(e.buffer)}Ag.freeUint8=Ag.freeUint16=Ag.freeUint32=Ag.freeBigUint64=Ag.freeInt8=Ag.freeInt16=Ag.freeInt32=Ag.freeBigInt64=Ag.freeFloat32=Ag.freeFloat=Ag.freeFloat64=Ag.freeDouble=Ag.freeUint8Clamped=Ag.freeDataView=cNt;Ag.freeArrayBuffer=LRe;Ag.freeBuffer=function(g){Vk[Lc.log2(g.length)].push(g)};Ag.malloc=function(g,I){if(I===void 0||I==="arraybuffer")return OC(g);switch(I){case"uint8":return A4(g);case"uint16":return URe(g);case"uint32":return QRe(g);case"int8":return jRe(g);case"int16":return $Re(g);case"int32":return qRe(g);case"float":case"float32":return e1e(g);case"double":case"float64":return t1e(g);case"uint8_clamped":return g1e(g);case"bigint64":return i1e(g);case"biguint64":return I1e(g);case"buffer":return C1e(g);case"data":case"dataview":return n1e(g);default:return null}return null};function OC(g){var g=Lc.nextPow2(g),I=Lc.log2(g),i=wk[I];return i.length>0?i.pop():new ArrayBuffer(g)}Ag.mallocArrayBuffer=OC;function A4(e){return new Uint8Array(OC(e),0,e)}Ag.mallocUint8=A4;function URe(e){return new Uint16Array(OC(2*e),0,e)}Ag.mallocUint16=URe;function QRe(e){return new Uint32Array(OC(4*e),0,e)}Ag.mallocUint32=QRe;function jRe(e){return new Int8Array(OC(e),0,e)}Ag.mallocInt8=jRe;function $Re(e){return new Int16Array(OC(2*e),0,e)}Ag.mallocInt16=$Re;function qRe(e){return new Int32Array(OC(4*e),0,e)}Ag.mallocInt32=qRe;function e1e(e){return new Float32Array(OC(4*e),0,e)}Ag.mallocFloat32=Ag.mallocFloat=e1e;function t1e(e){return new Float64Array(OC(8*e),0,e)}Ag.mallocFloat64=Ag.mallocDouble=t1e;function g1e(e){return ANt?new Uint8ClampedArray(OC(e),0,e):A4(e)}Ag.mallocUint8Clamped=g1e;function I1e(e){return sNt?new BigUint64Array(OC(8*e),0,e):null}Ag.mallocBigUint64=I1e;function i1e(e){return lNt?new BigInt64Array(OC(8*e),0,e):null}Ag.mallocBigInt64=i1e;function n1e(e){return new DataView(OC(e),0,e)}Ag.mallocDataView=n1e;function C1e(e){e=Lc.nextPow2(e);var g=Lc.log2(e),I=Vk[g];return I.length>0?I.pop():new _Re(e)}Ag.mallocBuffer=C1e;Ag.clearCache=function(){for(var g=0;g<32;++g)oi.UINT8[g].length=0,oi.UINT16[g].length=0,oi.UINT32[g].length=0,oi.INT8[g].length=0,oi.INT16[g].length=0,oi.INT32[g].length=0,oi.FLOAT[g].length=0,oi.DOUBLE[g].length=0,oi.BIGUINT64[g].length=0,oi.BIGINT64[g].length=0,oi.UINT8C[g].length=0,wk[g].length=0,Vk[g].length=0};var uNt=dNt,dW=32;function dNt(e,g){g<=4*dW?hW(0,g-1,e):mW(0,g-1,e)}function hW(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 HR(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;JA(s,A,I)&&(m=s,s=A,A=m),JA(c,u,I)&&(m=c,c=u,u=m),JA(s,l,I)&&(m=s,s=l,l=m),JA(A,l,I)&&(m=A,A=l,l=m),JA(s,c,I)&&(m=s,s=c,c=m),JA(l,c,I)&&(m=l,l=c,c=m),JA(A,u,I)&&(m=A,A=u,u=m),JA(A,l,I)&&(m=A,A=l,l=m),JA(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}aoe(o,e,I),aoe(a,g,I);for(var H=d;H<=h;++H)if(HR(H,f,b,I))H!==d&&ooe(H,d,I),++d;else if(!HR(H,p,y,I))for(;;)if(HR(h,p,y,I)){HR(h,f,b,I)?(hNt(H,d,h,I),++d,--h):(ooe(H,h,I),--h);break}else{if(--h>>1;Rk(rg,b);for(var p=0,y=0,d=0;d=or)Z=Z-or|0,Pp(Ws,Dd,y--,Z);else if(Z>=0)Pp(sn,Rs,p--,Z);else if(Z<=-or){Z=-Z-or|0;for(var B=0;B>>1;Rk(rg,b);for(var p=0,y=0,Z=0,d=0;d>1===rg[2*d+3]>>1&&(G=2,d+=1),B<0){for(var v=-(B>>1)-1,w=0;w>1)-1;G===0?Pp(sn,Rs,p--,v):G===1?Pp(Ws,Dd,y--,v):G===2&&Pp(zp,fv,Z--,v)}}}function yNt(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=or:m=or;for(var b=n;b>>1;Rk(rg,B);for(var G=0,b=0;b=or?(w=!i,p-=or):(w=!!i,p-=1),w)Jp(sn,Rs,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(rg,p);for(var y=0,h=0;h=or)sn[y++]=m-or;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(sn[V]===m){for(var R=V+1;R"+c4+"-"+q9+"){"),e?(C(!0,!1),n.push("}else{"),C(!1,!1)):(n.push("if("+PD+"){"),C(!0,!0),n.push("}else{"),C(!0,!1),n.push("}}else{if("+PD+"){"),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()}s4.partial=s1e(!1);s4.full=s1e(!0);var l1e=BNt,vNt="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 BNt(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(vNt.replace("_",i.join()).replace("$",e)),Function.apply(void 0,I)}var SNt=WNt,wNt=l1e,soe=wNt("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"]),coe=ny("lo===p0",["p0"]),xNt=ny("lo0;){s-=1;var c=s*u4,u=eC[c],d=eC[c+1],h=eC[c+2],m=eC[c+3],f=eC[c+4],b=eC[c+5],p=s*d4,y=Fd[p],Z=Fd[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=xNt(e,u,d,h,v,w,Z),d>=h))&&!(b&4&&(d=DNt(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=Bl.mallocDouble(2*r*n),s=Bl.mallocInt32(n);if(n=doe(e,r,a,s),n>0){if(r===1&&i)TR.init(n),o=TR.sweepComplete(r,I,0,n,a,s,0,n,a,s);else{var A=Bl.mallocDouble(2*r*C),l=Bl.mallocInt32(C);C=doe(g,r,A,l),C>0&&(TR.init(n+C),r===1?o=TR.sweepBipartite(r,I,0,n,a,s,0,C,A,l):o=ONt(r,I,i,n,a,s,C,A,l),Bl.free(A),Bl.free(l))}Bl.free(a),Bl.free(s)}return o}}}var jB;function d1e(e,g){jB.push([e,g])}function LNt(e){return jB=[],e2(e,e,d1e,!0),jB}function UNt(e,g){return jB=[],e2(e,g,d1e,!1),jB}function QNt(e,g,I){switch(arguments.length){case 1:return LNt(e);case 2:return typeof g=="function"?e2(e,e,g,!0):UNt(e,g);case 3:return e2(e,g,I,!1);default:throw new Error("box-intersect: Invalid arguments")}}const dw=JC(JNt);var h1e={exports:{}},m1e=jNt,hoe=+(Math.pow(2,27)+1);function jNt(e,g,I){var i=e*g,n=hoe*e,C=n-e,r=n-C,o=e-r,a=hoe*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 $Nt=ekt;function qNt(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 ekt(e,g){var I=e.length|0,i=g.length|0;if(I===1&&i===1)return qNt(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],K=w*W,F=V*X,J=V*S,P=v*W,ge=v*X,q=w*S,$=R*(K-F)+H*(J-P)+Y*(ge-q),j=(Math.abs(K)+Math.abs(F))*Math.abs(R)+(Math.abs(J)+Math.abs(P))*Math.abs(H)+(Math.abs(ge)+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),K=0;K0;){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 kr(e){return kr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},kr(e)}const foe=16,poe=50,UD=5e3,boe=5,Zkt=14,Yu={fontSize:`${Zkt}px`,fontFamily:"Arial",stroke:"white",strokeThickness:2,fontWeight:400,dropShadow:!0,dropShadowColor:"white",dropShadowDistance:0,dropShadowBlur:2};let p1e=function(e){mkt(I,e);var g=fkt(I);function I(i,n){var C;return lkt(this,I),C=g.call(this,i,n),C.valueScaleTransform=Ji,C}return ckt(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=_c(this.options.colorRange):this.colorScale=Tb),this.initialized=!0)}},{key:"initTile",value:function(n){n.texts={},n.rectGraphics=new ot.PIXI.Graphics,n.textGraphics=new ot.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=B9(o.filter(a=>a.strand==="+")),r=B9(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||poe))return;const A=new ot.PIXI.Text(s[3],{...Yu,fontSize:+this.options.fontSize||Yu.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){Ya(kr(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){Ya(kr(I.prototype),"rerender",this).call(this,n,C),this.valueScale=null,this.drawnRects={},this.options.colorRange?this.colorScale=_c(this.options.colorRange):this.colorScale=Tb;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||poe)||!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={...Yu,fill:W,fontSize:+this.options.fontSize||Yu.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)}xd.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,UD).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,UD).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,UD).map(a=>+a.fields[n-1]))).filter(o=>o>0);this.medianVisibleValue=H7(r)}},{key:"draw",value:function(){Ya(kr(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;xd.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){dw(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){Ya(kr(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){Ya(kr(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;Ya(kr(I.prototype),"exportSVG",this)?[C,n]=Ya(kr(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=xd.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 Tkt=(e,g,I,i,n)=>{n.drawRect(e,g,I,i)},Nkt=(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",`#${az(C)}`),A.setAttribute("fill-opacity",r),A.setAttribute("stroke",`#${az(o)}`),A.setAttribute("stroke-opacity",s),A.setAttribute("stroke-width",a),n.appendChild(A)},Ta=(e,g,I,i,n,C)=>{n instanceof HTMLElement?Nkt(e,g,I,i,n,C):Tkt(e,g,I,i,n)},Zoe=(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?Ta(g-d,I-h,i+d*2,h,m,f):b==="bottom"&&!a||b==="right"&&a?Ta(g-d,I+n,i+d*2,h,m,f):b==="left"&&!a||b==="top"&&a?Ta(g-d,I-h,d,n+h*2,m,f):(b==="right"&&!a||b==="bottom"&&a)&&Ta(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,Ta(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?(Ta(g,I,i,p,m,f),l+=p,u-=p):y==="bottom"&&!a||y==="right"&&a?(Ta(g,I+n-p,i,p,m,f),u-=p):y==="left"&&!a||y==="top"&&a?(Ta(g,I,b,n,m,f),A+=b,c-=b):(y==="right"&&!a||y==="bottom"&&a)&&(Ta(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,Ta(A,l,c,u,m,f)};let b1e=function(e){Vkt(I,e);var g=Rkt(I);function I(i,n){var C;return Gkt(this,I),C=g.call(this,i,n),C.options=n||{},C.drawnRects={},C}return vkt(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){ec(ja(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){ec(ja(I.prototype),"setDimensions",this).call(this,n),this.draw()}},{key:"exportSVG",value:function(){let n=null,C=null;ec(ja(I.prototype),"exportSVG",this)?[C,n]=ec(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}(fC);function kkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Goe(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 er(e){return er=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},er(e)}let Cy=function(e){Fkt(I,e);var g=Ekt(I);function I(){return kkt(this,I),g.apply(this,arguments)}return Ykt(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=dr(".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(Fo(er(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){Fo(er(I.prototype),"rerender",this).call(this,n,C),this.options=n,Fo(er(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(Fo(er(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=tg().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){Fo(er(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 Fo(er(I.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,C=null;Fo(er(I.prototype),"exportSVG",this)?[C,n]=Fo(er(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}(iy);function Jkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function voe(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 bs(e){return bs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},bs(e)}let y1e=function(e){Qkt(I,e);var g=jkt(I);function I(){return Jkt(this,I),g.apply(this,arguments)}return Okt(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),md(bs(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=ru().domain([h,this.maxValue()+h]).range([this.dimensions[1],0]),s=h}else this.valueScale=tg().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=tg().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(){md(bs(I.prototype),"draw",this).call(this);for(const n of Eg(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){md(bs(I.prototype),"zoomed",this).call(this,n,C)}},{key:"exportSVG",value:function(){let n=null,C=null;[C,n]=md(bs(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 gYt=(e,g)=>{const I=KB(e,g);return tYt(e.map(i=>(Array.isArray(i)&&g?i.length:1)/I))};function IYt(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 Sh(e){return Sh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Sh(e)}let Z1e=function(e){oYt(I,e);var g=aYt(I);function I(i,n){var C;return IYt(this,I),C=g.call(this,i,n),C.pMain=C.pMobile,C.continuousScaling=!1,C.updateDataFetcher(n),C}return iYt(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),pv(Sh(I.prototype),"rerender",this).call(this,n,C),n.selectRows&&(this.selectRowsCumWeights=gYt(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=KB(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){pv(Sh(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=KB(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=OQ(this.options.selectRowsAggregationMode),y=b.map(Z=>m.tileData.dense[Z]);f=dr(".3f")(p(y)),f+="
",f+=`${b.length}-item ${this.options.selectRowsAggregationMode}`}else f=dr(".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}(uw);function cYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Soe(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 Oo(e){return Oo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Oo(e)}const GYt=Kt("#FFFFFF");let h4=function(e){fYt(I,e);var g=pYt(I);function I(...i){var n;return cYt(this,I),n=g.call(this,...i),n.zeroLine=new ot.PIXI.Graphics,n.pMain.addChild(n.zeroLine),n.valueScaleTransform=Ji,n.options&&n.options.colorRange&&(n.options.colorRangeGradient?n.setColorGradient(n.options.colorRange):n.setColorScale(n.options.colorRange)),n.initialized=!0,n}return uYt(I,[{key:"setColorScale",value:function(n){n&&(this.colorScale=_c(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&&ns(Oo(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&&ns(Oo(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=tg().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 ot.PIXI.Graphics,G.beginFill(GYt,1);const w=DGe(this.colorGradientColors,1,this.dimensions[1],0,0,0,this.dimensions[1]);v=new ot.PIXI.Sprite(ot.PIXI.Texture.fromCanvas(w,ot.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=ot.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)),ns(Oo(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&&(ns(Oo(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){ns(Oo(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]=ns(Oo(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 t2(e){return t2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},t2(e)}let G1e=function(e){VYt(I,e);var g=RYt(I);function I(){return vYt(this,I),g.apply(this,arguments)}return BYt(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=ru().domain([p,this.maxValue()+p]).range([this.dimensions[1],0]),s=p}else this.valueScale=tg().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=tg().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}(h4);function TYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Voe(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 v1e=function(e){xYt(I,e);var g=DYt(I);function I(i,n){var C;return TYt(this,I),C=g.call(this,i,n),C.setColorScale(n.colorRange),C.opacity=n.opacity||1,C}return NYt(I,[{key:"setColorScale",value:function(n){this.colorScale=n?_c(n):Tb,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,fW(I0(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=tg().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 zYt(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 g2(e){return g2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},g2(e)}let B1e=function(e){_Yt(I,e);var g=LYt(I);function I(i,n){var C;return zYt(this,I),C=g.call(this,i,n),C.seen=new Set,C.pMain=C.pMobile,C.rows=[],C}return PYt(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=B9(r);this.rows=o,this.draw()}},{key:"draw",value:function(){const n=this.rows;if(!n)return;const C=YS().range([0,this.dimensions[1]]).padding(.1).domain(CC(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}(iy);function $Yt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Woe(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 c(re){return c=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(_){return _.__proto__||Object.getPrototypeOf(_)},c(re)}const u=Vk,d=dj,h=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=p,e.SlowBuffer=V,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 re=new Uint8Array(1),E={foo:function(){return 42}};return Object.setPrototypeOf(E,Uint8Array.prototype),Object.setPrototypeOf(re,E),re.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(re){if(re>m)throw new RangeError('The value "'+re+'" is invalid for option "size"');const E=new Uint8Array(re);return Object.setPrototypeOf(E,p.prototype),E}function p(re,E,_){if(typeof re=="number"){if(typeof E=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return G(re)}return y(re,E,_)}p.poolSize=8192;function y(re,E,_){if(typeof re=="string")return v(re,E);if(ArrayBuffer.isView(re))return R(re);if(re==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof re);if(je(re,ArrayBuffer)||re&&je(re.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(je(re,SharedArrayBuffer)||re&&je(re.buffer,SharedArrayBuffer)))return S(re,E,_);if(typeof re=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');const fe=re.valueOf&&re.valueOf();if(fe!=null&&fe!==re)return p.from(fe,E,_);const Ye=X(re);if(Ye)return Ye;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof re[Symbol.toPrimitive]=="function")return p.from(re[Symbol.toPrimitive]("string"),E,_);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof re)}p.from=function(re,E,_){return y(re,E,_)},Object.setPrototypeOf(p.prototype,Uint8Array.prototype),Object.setPrototypeOf(p,Uint8Array);function Z(re){if(typeof re!="number")throw new TypeError('"size" argument must be of type number');if(re<0)throw new RangeError('The value "'+re+'" is invalid for option "size"')}function B(re,E,_){return Z(re),re<=0?b(re):E!==void 0?typeof _=="string"?b(re).fill(E,_):b(re).fill(E):b(re)}p.alloc=function(re,E,_){return B(re,E,_)};function G(re){return Z(re),b(re<0?0:W(re)|0)}p.allocUnsafe=function(re){return G(re)},p.allocUnsafeSlow=function(re){return G(re)};function v(re,E){if((typeof E!="string"||E==="")&&(E="utf8"),!p.isEncoding(E))throw new TypeError("Unknown encoding: "+E);const _=H(re,E)|0;let fe=b(_);const Ye=fe.write(re,E);return Ye!==_&&(fe=fe.slice(0,Ye)),fe}function w(re){const E=re.length<0?0:W(re.length)|0,_=b(E);for(let fe=0;fe=m)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+m.toString(16)+" bytes");return re|0}function V(re){return+re!=re&&(re=0),p.alloc(+re)}p.isBuffer=function(E){return E!=null&&E._isBuffer===!0&&E!==p.prototype},p.compare=function(E,_){if(je(E,Uint8Array)&&(E=p.from(E,E.offset,E.byteLength)),je(_,Uint8Array)&&(_=p.from(_,_.offset,_.byteLength)),!p.isBuffer(E)||!p.isBuffer(_))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(E===_)return 0;let fe=E.length,Ye=_.length;for(let ue=0,le=Math.min(fe,Ye);ueYe.length?(p.isBuffer(le)||(le=p.from(le)),le.copy(Ye,ue)):Uint8Array.prototype.set.call(Ye,le,ue);else if(p.isBuffer(le))le.copy(Ye,ue);else throw new TypeError('"list" argument must be an Array of Buffers');ue+=le.length}return Ye};function H(re,E){if(p.isBuffer(re))return re.length;if(ArrayBuffer.isView(re)||je(re,ArrayBuffer))return re.byteLength;if(typeof re!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof re);const _=re.length,fe=arguments.length>2&&arguments[2]===!0;if(!fe&&_===0)return 0;let Ye=!1;for(;;)switch(E){case"ascii":case"latin1":case"binary":return _;case"utf8":case"utf-8":return k(re).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _*2;case"hex":return _>>>1;case"base64":return Ve(re).length;default:if(Ye)return fe?-1:k(re).length;E=(""+E).toLowerCase(),Ye=!0}}p.byteLength=H;function Y(re,E,_){let fe=!1;if((E===void 0||E<0)&&(E=0),E>this.length||((_===void 0||_>this.length)&&(_=this.length),_<=0)||(_>>>=0,E>>>=0,_<=E))return"";for(re||(re="utf8");;)switch(re){case"hex":return pe(this,E,_);case"utf8":case"utf-8":return Q(this,E,_);case"ascii":return ne(this,E,_);case"latin1":case"binary":return be(this,E,_);case"base64":return te(this,E,_);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ve(this,E,_);default:if(fe)throw new TypeError("Unknown encoding: "+re);re=(re+"").toLowerCase(),fe=!0}}p.prototype._isBuffer=!0;function K(re,E,_){const fe=re[E];re[E]=re[_],re[_]=fe}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 _=0;__&&(E+=" ... "),""},h&&(p.prototype[h]=p.prototype.inspect),p.prototype.compare=function(E,_,fe,Ye,ue){if(je(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(_===void 0&&(_=0),fe===void 0&&(fe=E?E.length:0),Ye===void 0&&(Ye=0),ue===void 0&&(ue=this.length),_<0||fe>E.length||Ye<0||ue>this.length)throw new RangeError("out of range index");if(Ye>=ue&&_>=fe)return 0;if(Ye>=ue)return-1;if(_>=fe)return 1;if(_>>>=0,fe>>>=0,Ye>>>=0,ue>>>=0,this===E)return 0;let le=ue-Ye,Ce=fe-_;const oe=Math.min(le,Ce),Re=this.slice(Ye,ue),xe=E.slice(_,fe);for(let Fe=0;Fe2147483647?_=2147483647:_<-2147483648&&(_=-2147483648),_=+_,at(_)&&(_=Ye?0:re.length-1),_<0&&(_=re.length+_),_>=re.length){if(Ye)return-1;_=re.length-1}else if(_<0)if(Ye)_=0;else return-1;if(typeof E=="string"&&(E=p.from(E,fe)),p.isBuffer(E))return E.length===0?-1:J(re,E,_,fe,Ye);if(typeof E=="number")return E=E&255,typeof Uint8Array.prototype.indexOf=="function"?Ye?Uint8Array.prototype.indexOf.call(re,E,_):Uint8Array.prototype.lastIndexOf.call(re,E,_):J(re,[E],_,fe,Ye);throw new TypeError("val must be string, number or Buffer")}function J(re,E,_,fe,Ye){let ue=1,le=re.length,Ce=E.length;if(fe!==void 0&&(fe=String(fe).toLowerCase(),fe==="ucs2"||fe==="ucs-2"||fe==="utf16le"||fe==="utf-16le")){if(re.length<2||E.length<2)return-1;ue=2,le/=2,Ce/=2,_/=2}function oe(xe,Fe){return ue===1?xe[Fe]:xe.readUInt16BE(Fe*ue)}let Re;if(Ye){let xe=-1;for(Re=_;Rele&&(_=le-Ce),Re=_;Re>=0;Re--){let xe=!0;for(let Fe=0;FeYe&&(fe=Ye)):fe=Ye;const ue=E.length;fe>ue/2&&(fe=ue/2);let le;for(le=0;le>>0,isFinite(fe)?(fe=fe>>>0,Ye===void 0&&(Ye="utf8")):(Ye=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),E.length>0&&(fe<0||_<0)||_>this.length)throw new RangeError("Attempt to write outside buffer bounds");Ye||(Ye="utf8");let le=!1;for(;;)switch(Ye){case"hex":return P(this,E,_,fe);case"utf8":case"utf-8":return ge(this,E,_,fe);case"ascii":case"latin1":case"binary":return q(this,E,_,fe);case"base64":return $(this,E,_,fe);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,E,_,fe);default:if(le)throw new TypeError("Unknown encoding: "+Ye);Ye=(""+Ye).toLowerCase(),le=!0}},p.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function te(re,E,_){return E===0&&_===re.length?u.fromByteArray(re):u.fromByteArray(re.slice(E,_))}function Q(re,E,_){_=Math.min(re.length,_);const fe=[];let Ye=E;for(;Ye<_;){const ue=re[Ye];let le=null,Ce=ue>239?4:ue>223?3:ue>191?2:1;if(Ye+Ce<=_){let oe,Re,xe,Fe;switch(Ce){case 1:ue<128&&(le=ue);break;case 2:oe=re[Ye+1],(oe&192)===128&&(Fe=(ue&31)<<6|oe&63,Fe>127&&(le=Fe));break;case 3:oe=re[Ye+1],Re=re[Ye+2],(oe&192)===128&&(Re&192)===128&&(Fe=(ue&15)<<12|(oe&63)<<6|Re&63,Fe>2047&&(Fe<55296||Fe>57343)&&(le=Fe));break;case 4:oe=re[Ye+1],Re=re[Ye+2],xe=re[Ye+3],(oe&192)===128&&(Re&192)===128&&(xe&192)===128&&(Fe=(ue&15)<<18|(oe&63)<<12|(Re&63)<<6|xe&63,Fe>65535&&Fe<1114112&&(le=Fe))}}le===null?(le=65533,Ce=1):le>65535&&(le-=65536,fe.push(le>>>10&1023|55296),le=56320|le&1023),fe.push(le),Ye+=Ce}return he(fe)}const Ie=4096;function he(re){const E=re.length;if(E<=Ie)return String.fromCharCode.apply(String,re);let _="",fe=0;for(;fefe)&&(_=fe);let Ye="";for(let ue=E;ue<_;++ue)Ye+=bt[re[ue]];return Ye}function ve(re,E,_){const fe=re.slice(E,_);let Ye="";for(let ue=0;uefe&&(E=fe),_<0?(_+=fe,_<0&&(_=0)):_>fe&&(_=fe),__)throw new RangeError("Trying to access beyond buffer length")}p.prototype.readUintLE=p.prototype.readUIntLE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E],ue=1,le=0;for(;++le<_&&(ue*=256);)Ye+=this[E+le]*ue;return Ye},p.prototype.readUintBE=p.prototype.readUIntBE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E+--_],ue=1;for(;_>0&&(ue*=256);)Ye+=this[E+--_]*ue;return Ye},p.prototype.readUint8=p.prototype.readUInt8=function(E,_){return E=E>>>0,_||We(E,1,this.length),this[E]},p.prototype.readUint16LE=p.prototype.readUInt16LE=function(E,_){return E=E>>>0,_||We(E,2,this.length),this[E]|this[E+1]<<8},p.prototype.readUint16BE=p.prototype.readUInt16BE=function(E,_){return E=E>>>0,_||We(E,2,this.length),this[E]<<8|this[E+1]},p.prototype.readUint32LE=p.prototype.readUInt32LE=function(E,_){return E=E>>>0,_||We(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,_){return E=E>>>0,_||We(E,4,this.length),this[E]*16777216+(this[E+1]<<16|this[E+2]<<8|this[E+3])},p.prototype.readBigUInt64LE=ct(function(E){E=E>>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=_+this[++E]*2**8+this[++E]*2**16+this[++E]*2**24,ue=this[++E]+this[++E]*2**8+this[++E]*2**16+fe*2**24;return BigInt(Ye)+(BigInt(ue)<>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=_*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+fe;return(BigInt(Ye)<>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=this[E],ue=1,le=0;for(;++le<_&&(ue*=256);)Ye+=this[E+le]*ue;return ue*=128,Ye>=ue&&(Ye-=Math.pow(2,8*_)),Ye},p.prototype.readIntBE=function(E,_,fe){E=E>>>0,_=_>>>0,fe||We(E,_,this.length);let Ye=_,ue=1,le=this[E+--Ye];for(;Ye>0&&(ue*=256);)le+=this[E+--Ye]*ue;return ue*=128,le>=ue&&(le-=Math.pow(2,8*_)),le},p.prototype.readInt8=function(E,_){return E=E>>>0,_||We(E,1,this.length),this[E]&128?(255-this[E]+1)*-1:this[E]},p.prototype.readInt16LE=function(E,_){E=E>>>0,_||We(E,2,this.length);const fe=this[E]|this[E+1]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt16BE=function(E,_){E=E>>>0,_||We(E,2,this.length);const fe=this[E+1]|this[E]<<8;return fe&32768?fe|4294901760:fe},p.prototype.readInt32LE=function(E,_){return E=E>>>0,_||We(E,4,this.length),this[E]|this[E+1]<<8|this[E+2]<<16|this[E+3]<<24},p.prototype.readInt32BE=function(E,_){return E=E>>>0,_||We(E,4,this.length),this[E]<<24|this[E+1]<<16|this[E+2]<<8|this[E+3]},p.prototype.readBigInt64LE=ct(function(E){E=E>>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=this[E+4]+this[E+5]*2**8+this[E+6]*2**16+(fe<<24);return(BigInt(Ye)<>>0,ye(E,"offset");const _=this[E],fe=this[E+7];(_===void 0||fe===void 0)&&He(E,this.length-8);const Ye=(_<<24)+this[++E]*2**16+this[++E]*2**8+this[++E];return(BigInt(Ye)<>>0,_||We(E,4,this.length),d.read(this,E,!0,23,4)},p.prototype.readFloatBE=function(E,_){return E=E>>>0,_||We(E,4,this.length),d.read(this,E,!1,23,4)},p.prototype.readDoubleLE=function(E,_){return E=E>>>0,_||We(E,8,this.length),d.read(this,E,!0,52,8)},p.prototype.readDoubleBE=function(E,_){return E=E>>>0,_||We(E,8,this.length),d.read(this,E,!1,52,8)};function Be(re,E,_,fe,Ye,ue){if(!p.isBuffer(re))throw new TypeError('"buffer" argument must be a Buffer instance');if(E>Ye||Ere.length)throw new RangeError("Index out of range")}p.prototype.writeUintLE=p.prototype.writeUIntLE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,fe=fe>>>0,!Ye){const Ce=Math.pow(2,8*fe)-1;Be(this,E,_,fe,Ce,0)}let ue=1,le=0;for(this[_]=E&255;++le>>0,fe=fe>>>0,!Ye){const Ce=Math.pow(2,8*fe)-1;Be(this,E,_,fe,Ce,0)}let ue=fe-1,le=1;for(this[_+ue]=E&255;--ue>=0&&(le*=256);)this[_+ue]=E/le&255;return _+fe},p.prototype.writeUint8=p.prototype.writeUInt8=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,1,255,0),this[_]=E&255,_+1},p.prototype.writeUint16LE=p.prototype.writeUInt16LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,65535,0),this[_]=E&255,this[_+1]=E>>>8,_+2},p.prototype.writeUint16BE=p.prototype.writeUInt16BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,65535,0),this[_]=E>>>8,this[_+1]=E&255,_+2},p.prototype.writeUint32LE=p.prototype.writeUInt32LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,4294967295,0),this[_+3]=E>>>24,this[_+2]=E>>>16,this[_+1]=E>>>8,this[_]=E&255,_+4},p.prototype.writeUint32BE=p.prototype.writeUInt32BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,4294967295,0),this[_]=E>>>24,this[_+1]=E>>>16,this[_+2]=E>>>8,this[_+3]=E&255,_+4};function Je(re,E,_,fe,Ye){ae(E,fe,Ye,re,_,7);let ue=Number(E&BigInt(4294967295));re[_++]=ue,ue=ue>>8,re[_++]=ue,ue=ue>>8,re[_++]=ue,ue=ue>>8,re[_++]=ue;let le=Number(E>>BigInt(32)&BigInt(4294967295));return re[_++]=le,le=le>>8,re[_++]=le,le=le>>8,re[_++]=le,le=le>>8,re[_++]=le,_}function Pe(re,E,_,fe,Ye){ae(E,fe,Ye,re,_,7);let ue=Number(E&BigInt(4294967295));re[_+7]=ue,ue=ue>>8,re[_+6]=ue,ue=ue>>8,re[_+5]=ue,ue=ue>>8,re[_+4]=ue;let le=Number(E>>BigInt(32)&BigInt(4294967295));return re[_+3]=le,le=le>>8,re[_+2]=le,le=le>>8,re[_+1]=le,le=le>>8,re[_]=le,_+8}p.prototype.writeBigUInt64LE=ct(function(E,_=0){return Je(this,E,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeBigUInt64BE=ct(function(E,_=0){return Pe(this,E,_,BigInt(0),BigInt("0xffffffffffffffff"))}),p.prototype.writeIntLE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,!Ye){const oe=Math.pow(2,8*fe-1);Be(this,E,_,fe,oe-1,-oe)}let ue=0,le=1,Ce=0;for(this[_]=E&255;++ue>0)-Ce&255;return _+fe},p.prototype.writeIntBE=function(E,_,fe,Ye){if(E=+E,_=_>>>0,!Ye){const oe=Math.pow(2,8*fe-1);Be(this,E,_,fe,oe-1,-oe)}let ue=fe-1,le=1,Ce=0;for(this[_+ue]=E&255;--ue>=0&&(le*=256);)E<0&&Ce===0&&this[_+ue+1]!==0&&(Ce=1),this[_+ue]=(E/le>>0)-Ce&255;return _+fe},p.prototype.writeInt8=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,1,127,-128),E<0&&(E=255+E+1),this[_]=E&255,_+1},p.prototype.writeInt16LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,32767,-32768),this[_]=E&255,this[_+1]=E>>>8,_+2},p.prototype.writeInt16BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,2,32767,-32768),this[_]=E>>>8,this[_+1]=E&255,_+2},p.prototype.writeInt32LE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,2147483647,-2147483648),this[_]=E&255,this[_+1]=E>>>8,this[_+2]=E>>>16,this[_+3]=E>>>24,_+4},p.prototype.writeInt32BE=function(E,_,fe){return E=+E,_=_>>>0,fe||Be(this,E,_,4,2147483647,-2147483648),E<0&&(E=4294967295+E+1),this[_]=E>>>24,this[_+1]=E>>>16,this[_+2]=E>>>8,this[_+3]=E&255,_+4},p.prototype.writeBigInt64LE=ct(function(E,_=0){return Je(this,E,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),p.prototype.writeBigInt64BE=ct(function(E,_=0){return Pe(this,E,_,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function De(re,E,_,fe,Ye,ue){if(_+fe>re.length)throw new RangeError("Index out of range");if(_<0)throw new RangeError("Index out of range")}function Qe(re,E,_,fe,Ye){return E=+E,_=_>>>0,Ye||De(re,E,_,4),d.write(re,E,_,fe,23,4),_+4}p.prototype.writeFloatLE=function(E,_,fe){return Qe(this,E,_,!0,fe)},p.prototype.writeFloatBE=function(E,_,fe){return Qe(this,E,_,!1,fe)};function _e(re,E,_,fe,Ye){return E=+E,_=_>>>0,Ye||De(re,E,_,8),d.write(re,E,_,fe,52,8),_+8}p.prototype.writeDoubleLE=function(E,_,fe){return _e(this,E,_,!0,fe)},p.prototype.writeDoubleBE=function(E,_,fe){return _e(this,E,_,!1,fe)},p.prototype.copy=function(E,_,fe,Ye){if(!p.isBuffer(E))throw new TypeError("argument should be a Buffer");if(fe||(fe=0),!Ye&&Ye!==0&&(Ye=this.length),_>=E.length&&(_=E.length),_||(_=0),Ye>0&&Ye=this.length)throw new RangeError("Index out of range");if(Ye<0)throw new RangeError("sourceEnd out of bounds");Ye>this.length&&(Ye=this.length),E.length-_>>0,fe=fe===void 0?this.length:fe>>>0,E||(E=0);let ue;if(typeof E=="number")for(ue=_;ue2**32?Ye=tt(String(_)):typeof _=="bigint"&&(Ye=String(_),(_>BigInt(2)**BigInt(32)||_<-(BigInt(2)**BigInt(32)))&&(Ye=tt(Ye)),Ye+="n"),fe+=` It must be ${E}. Received ${Ye}`,fe},RangeError);function tt(re){let E="",_=re.length;const fe=re[0]==="-"?1:0;for(;_>=fe+4;_-=3)E=`_${re.slice(_-3,_)}${E}`;return`${re.slice(0,_)}${E}`}function Xe(re,E,_){ye(E,"offset"),(re[E]===void 0||re[E+_]===void 0)&&He(E,re.length-(_+1))}function ae(re,E,_,fe,Ye,ue){if(re>_||re3?E===0||E===BigInt(0)?Ce=`>= 0${le} and < 2${le} ** ${(ue+1)*8}${le}`:Ce=`>= -(2${le} ** ${(ue+1)*8-1}${le}) and < 2 ** ${(ue+1)*8-1}${le}`:Ce=`>= ${E}${le} and <= ${_}${le}`,new gt.ERR_OUT_OF_RANGE("value",Ce,re)}Xe(fe,Ye,ue)}function ye(re,E){if(typeof re!="number")throw new gt.ERR_INVALID_ARG_TYPE(E,"number",re)}function He(re,E,_){throw Math.floor(re)!==re?(ye(re,_),new gt.ERR_OUT_OF_RANGE(_||"offset","an integer",re)):E<0?new gt.ERR_BUFFER_OUT_OF_BOUNDS:new gt.ERR_OUT_OF_RANGE(_||"offset",`>= ${_?1:0} and <= ${E}`,re)}const F=/[^+/0-9A-Za-z-_]/g;function T(re){if(re=re.split("=")[0],re=re.trim().replace(F,""),re.length<2)return"";for(;re.length%4!==0;)re=re+"=";return re}function k(re,E){E=E||1/0;let _;const fe=re.length;let Ye=null;const ue=[];for(let le=0;le55295&&_<57344){if(!Ye){if(_>56319){(E-=3)>-1&&ue.push(239,191,189);continue}else if(le+1===fe){(E-=3)>-1&&ue.push(239,191,189);continue}Ye=_;continue}if(_<56320){(E-=3)>-1&&ue.push(239,191,189),Ye=_;continue}_=(Ye-55296<<10|_-56320)+65536}else Ye&&(E-=3)>-1&&ue.push(239,191,189);if(Ye=null,_<128){if((E-=1)<0)break;ue.push(_)}else if(_<2048){if((E-=2)<0)break;ue.push(_>>6|192,_&63|128)}else if(_<65536){if((E-=3)<0)break;ue.push(_>>12|224,_>>6&63|128,_&63|128)}else if(_<1114112){if((E-=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 ie(re){const E=[];for(let _=0;_>8,Ye=_%256,ue.push(Ye),ue.push(fe);return ue}function Ve(re){return u.toByteArray(T(re))}function we(re,E,_,fe){let Ye;for(Ye=0;Ye=E.length||Ye>=re.length);++Ye)E[Ye+_]=re[Ye];return Ye}function je(re,E){return re instanceof E||re!=null&&re.constructor!=null&&re.constructor.name!=null&&re.constructor.name===E.name}function at(re){return re!==re}const bt=function(){const re="0123456789abcdef",E=new Array(256);for(let _=0;_<16;++_){const fe=_*16;for(let Ye=0;Ye<16;++Ye)E[fe+Ye]=re[_]+re[Ye]}return E}();function ct(re){return typeof BigInt>"u"?Ht:re}function Ht(){throw new Error("BigInt not supported")}})(qVe);var _c=Xi,Cn=oNt,t1e=qVe.Buffer;globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:Cn([32,0]),UINT16:Cn([32,0]),UINT32:Cn([32,0]),BIGUINT64:Cn([32,0]),INT8:Cn([32,0]),INT16:Cn([32,0]),INT32:Cn([32,0]),BIGINT64:Cn([32,0]),FLOAT:Cn([32,0]),DOUBLE:Cn([32,0]),DATA:Cn([32,0]),UINT8C:Cn([32,0]),BUFFER:Cn([32,0])});var mNt=typeof Uint8ClampedArray<"u",fNt=typeof BigUint64Array<"u",pNt=typeof BigInt64Array<"u",oI=globalThis.__TYPEDARRAY_POOL;oI.UINT8C||(oI.UINT8C=Cn([32,0]));oI.BIGUINT64||(oI.BIGUINT64=Cn([32,0]));oI.BIGINT64||(oI.BIGINT64=Cn([32,0]));oI.BUFFER||(oI.BUFFER=Cn([32,0]));var Wk=oI.DATA,Xk=oI.BUFFER;Ag.free=function(g){if(t1e.isBuffer(g))Xk[_c.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=_c.log2(i)|0;Wk[I].push(g)}};function g1e(e){if(e){var g=e.length||e.byteLength,i=_c.log2(g);Wk[i].push(e)}}function bNt(e){g1e(e.buffer)}Ag.freeUint8=Ag.freeUint16=Ag.freeUint32=Ag.freeBigUint64=Ag.freeInt8=Ag.freeInt16=Ag.freeInt32=Ag.freeBigInt64=Ag.freeFloat32=Ag.freeFloat=Ag.freeFloat64=Ag.freeDouble=Ag.freeUint8Clamped=Ag.freeDataView=bNt;Ag.freeArrayBuffer=g1e;Ag.freeBuffer=function(g){Xk[_c.log2(g.length)].push(g)};Ag.malloc=function(g,i){if(i===void 0||i==="arraybuffer")return Jr(g);switch(i){case"uint8":return hj(g);case"uint16":return i1e(g);case"uint32":return I1e(g);case"int8":return n1e(g);case"int16":return r1e(g);case"int32":return C1e(g);case"float":case"float32":return o1e(g);case"double":case"float64":return a1e(g);case"uint8_clamped":return A1e(g);case"bigint64":return l1e(g);case"biguint64":return s1e(g);case"buffer":return u1e(g);case"data":case"dataview":return c1e(g);default:return null}return null};function Jr(g){var g=_c.nextPow2(g),i=_c.log2(g),I=Wk[i];return I.length>0?I.pop():new ArrayBuffer(g)}Ag.mallocArrayBuffer=Jr;function hj(e){return new Uint8Array(Jr(e),0,e)}Ag.mallocUint8=hj;function i1e(e){return new Uint16Array(Jr(2*e),0,e)}Ag.mallocUint16=i1e;function I1e(e){return new Uint32Array(Jr(4*e),0,e)}Ag.mallocUint32=I1e;function n1e(e){return new Int8Array(Jr(e),0,e)}Ag.mallocInt8=n1e;function r1e(e){return new Int16Array(Jr(2*e),0,e)}Ag.mallocInt16=r1e;function C1e(e){return new Int32Array(Jr(4*e),0,e)}Ag.mallocInt32=C1e;function o1e(e){return new Float32Array(Jr(4*e),0,e)}Ag.mallocFloat32=Ag.mallocFloat=o1e;function a1e(e){return new Float64Array(Jr(8*e),0,e)}Ag.mallocFloat64=Ag.mallocDouble=a1e;function A1e(e){return mNt?new Uint8ClampedArray(Jr(e),0,e):hj(e)}Ag.mallocUint8Clamped=A1e;function s1e(e){return fNt?new BigUint64Array(Jr(8*e),0,e):null}Ag.mallocBigUint64=s1e;function l1e(e){return pNt?new BigInt64Array(Jr(8*e),0,e):null}Ag.mallocBigInt64=l1e;function c1e(e){return new DataView(Jr(e),0,e)}Ag.mallocDataView=c1e;function u1e(e){e=_c.nextPow2(e);var g=_c.log2(e),i=Xk[g];return i.length>0?i.pop():new t1e(e)}Ag.mallocBuffer=u1e;Ag.clearCache=function(){for(var g=0;g<32;++g)oI.UINT8[g].length=0,oI.UINT16[g].length=0,oI.UINT32[g].length=0,oI.INT8[g].length=0,oI.INT16[g].length=0,oI.INT32[g].length=0,oI.FLOAT[g].length=0,oI.DOUBLE[g].length=0,oI.BIGUINT64[g].length=0,oI.BIGINT64[g].length=0,oI.UINT8C[g].length=0,Wk[g].length=0,Xk[g].length=0};var yNt=ZNt,fW=32;function ZNt(e,g){g<=4*fW?pW(0,g-1,e):bW(0,g-1,e)}function pW(e,g,i){for(var I=2*(e+1),n=e+1;n<=g;++n){for(var r=i[I++],C=i[I++],o=n,a=I-2;o-- >e;){var s=i[a-2],A=i[a-1];if(si[g+1]:!0}function kV(e,g,i,I){e*=2;var n=I[e];return n>1,o=C-I,a=C+I,s=n,A=o,l=C,c=a,u=r,d=e+1,h=g-1,m=0;JA(s,A,i)&&(m=s,s=A,A=m),JA(c,u,i)&&(m=c,c=u,u=m),JA(s,l,i)&&(m=s,s=l,l=m),JA(A,l,i)&&(m=A,A=l,l=m),JA(s,c,i)&&(m=s,s=c,c=m),JA(l,c,i)&&(m=l,l=c,c=m),JA(A,u,i)&&(m=A,A=u,u=m),JA(A,l,i)&&(m=A,A=l,l=m),JA(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*C,R=2*r,S=0;S<2;++S){var X=i[Z+S],W=i[B+S],V=i[G+S];i[v+S]=X,i[w+S]=W,i[R+S]=V}doe(o,e,i),doe(a,g,i);for(var H=d;H<=h;++H)if(kV(H,f,b,i))H!==d&&uoe(H,d,i),++d;else if(!kV(H,p,y,i))for(;;)if(kV(h,p,y,i)){kV(h,f,b,i)?(GNt(H,d,h,i),++d,--h):(uoe(H,h,i),--h);break}else{if(--h>>1;Hk(Cg,b);for(var p=0,y=0,d=0;d=CC)Z=Z-CC|0,Jp(Ws,Fd,y--,Z);else if(Z>=0)Jp(sn,Vs,p--,Z);else if(Z<=-CC){Z=-Z-CC|0;for(var B=0;B>>1;Hk(Cg,b);for(var p=0,y=0,Z=0,d=0;d>1===Cg[2*d+3]>>1&&(G=2,d+=1),B<0){for(var v=-(B>>1)-1,w=0;w>1)-1;G===0?Jp(sn,Vs,p--,v):G===1?Jp(Ws,Fd,y--,v):G===2&&Jp(Pp,fv,Z--,v)}}}function RNt(e,g,i,I,n,r,C,o,a,s,A,l){var c=0,u=2*e,d=g,h=g+e,m=1,f=1;I?f=CC:m=CC;for(var b=n;b>>1;Hk(Cg,B);for(var G=0,b=0;b=CC?(w=!I,p-=CC):(w=!!I,p-=1),w)Op(sn,Vs,G++,p);else{var R=l[p],S=u*p,X=A[S+g+1],W=A[S+g+1+e];e:for(var V=0;V>>1;Hk(Cg,p);for(var y=0,h=0;h=CC)sn[y++]=m-CC;else{m-=1;var B=A[m],G=c*m,v=s[G+g+1],w=s[G+g+1+e];e:for(var R=0;R=0;--R)if(sn[R]===m){for(var V=R+1;V"+pj+"-"+g2+"){"),e?(r(!0,!1),n.push("}else{"),r(!1,!1)):(n.push("if("+_D+"){"),r(!0,!0),n.push("}else{"),r(!0,!1),n.push("}}else{if("+_D+"){"),r(!1,!0),n.push("}else{"),r(!1,!1),n.push("}")),n.push("}}return "+g);var C=i.join("")+n.join(""),o=new Function(C);return o()}mj.partial=p1e(!1);mj.full=p1e(!0);var b1e=HNt,XNt="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 HNt(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(XNt.replace("_",I.join()).replace("$",e)),Function.apply(void 0,i)}var TNt=KNt,NNt=b1e,moe=NNt("loi&&n[l+g]>s;--A,l-=C){for(var c=l,u=l+C,d=0;d>>1,s=2*e,A=a,l=n[s*a+g];C=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"]),poe=ry("lo===p0",["p0"]),JNt=ry("lo0;){s-=1;var c=s*bj,u=qn[c],d=qn[c+1],h=qn[c+2],m=qn[c+3],f=qn[c+4],b=qn[c+5],p=s*yj,y=Dd[p],Z=Dd[p+1],B=b&1,G=!!(b&16),v=n,w=r,R=o,S=a;if(B&&(v=o,w=a,R=n,S=r),!(b&2&&(h=JNt(e,u,d,h,v,w,Z),d>=h))&&!(b&4&&(d=ONt(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(!(C<=0)){var o,a=Bl.mallocDouble(2*C*n),s=Bl.mallocInt32(n);if(n=yoe(e,C,a,s),n>0){if(C===1&&I)YV.init(n),o=YV.sweepComplete(C,i,0,n,a,s,0,n,a,s);else{var A=Bl.mallocDouble(2*C*r),l=Bl.mallocInt32(r);r=yoe(g,C,A,l),r>0&&(YV.init(n+r),C===1?o=YV.sweepBipartite(C,i,0,n,a,s,0,r,A,l):o=qNt(C,i,I,n,a,s,r,A,l),Bl.free(A),Bl.free(l))}Bl.free(a),Bl.free(s)}return o}}}var eS;function G1e(e,g){eS.push([e,g])}function tkt(e){return eS=[],i2(e,e,G1e,!0),eS}function gkt(e,g){return eS=[],i2(e,g,G1e,!1),eS}function ikt(e,g,i){switch(arguments.length){case 1:return tkt(e);case 2:return typeof g=="function"?i2(e,e,g,!0):gkt(e,g);case 3:return i2(e,g,i,!1);default:throw new Error("box-intersect: Invalid arguments")}}const fw=Pr($Nt);var v1e={exports:{}},B1e=Ikt,Zoe=+(Math.pow(2,27)+1);function Ikt(e,g,i){var I=e*g,n=Zoe*e,r=n-e,C=n-r,o=e-C,a=Zoe*g,s=a-g,A=a-s,l=g-A,c=I-C*A,u=c-o*A,d=u-C*l,h=o*l-d;return i?(i[0]=h,i[1]=I,i):[h,I]}var nkt=Ckt;function rkt(e,g){var i=e+g,I=i-e,n=i-I,r=g-I,C=e-n,o=C+r;return o?[o,i]:[i]}function Ckt(e,g){var i=e.length|0,I=g.length|0;if(i===1&&I===1)return rkt(e[0],g[0]);var n=i+I,r=new Array(n),C=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;R=G+v}else if(G<0){if(v>=0)return w;R=-(G+v)}else return w;var S=o*R;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],R=B[0]-G[0],S=y[1]-G[1],X=Z[1]-G[1],W=B[1]-G[1],V=y[2]-G[2],H=Z[2]-G[2],Y=B[2]-G[2],K=w*W,x=R*X,J=R*S,P=v*W,ge=v*X,q=w*S,$=V*(K-x)+H*(J-P)+Y*(ge-q),j=(Math.abs(K)+Math.abs(x))*Math.abs(V)+(Math.abs(J)+Math.abs(P))*Math.abs(H)+(Math.abs(ge)+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,V,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,V);case 5:return w(S,X,W,V,H)}for(var Y=new Array(arguments.length),K=0;K0;){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;C=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 NC(e){return NC=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},NC(e)}const voe=16,Boe=50,$D=5e3,Soe=5,Vkt=14,ku={fontSize:`${Vkt}px`,fontFamily:"Arial",stroke:"white",strokeThickness:2,fontWeight:400,dropShadow:!0,dropShadowColor:"white",dropShadowDistance:0,dropShadowBlur:2};let w1e=function(e){vkt(i,e);var g=Bkt(i);function i(I,n){var r;return pkt(this,i),r=g.call(this,I,n),r.valueScaleTransform=JI,r}return bkt(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=Oc(this.options.colorRange):this.colorScale=Nb),this.initialized=!0)}},{key:"initTile",value:function(n){n.texts={},n.rectGraphics=new ot.PIXI.Graphics,n.textGraphics=new ot.PIXI.Graphics,n.graphics.addChild(n.rectGraphics),n.graphics.addChild(n.textGraphics);let r=[],C=[];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]==="-"?"-":"+"}});r=RX(o.filter(a=>a.strand==="+")),C=RX(o.filter(a=>a.strand==="-"))}else r=[n.tileData.map(o=>({value:o}))];n.plusStrandRows=r,n.minusStrandRows=C,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||Boe))return;const A=new ot.PIXI.Text(s[3],{...ku,fontSize:+this.options.fontSize||ku.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 r=+n.tileId.split(".")[0];n.rectGraphics.clear(),n.rendered=!1,n.tileData&&n.tileData.length&&n.tileData.forEach((C,o)=>{this.drawnRects[r]&&this.drawnRects[r][C.uid]&&this.drawnRects[r][C.uid][2]===n.tileId&&delete this.drawnRects[r][C.uid]})}},{key:"destroyTile",value:function(n){this.removeTileRects(n),n.graphics.removeChild(n.textGraphics),n.graphics.removeChild(n.rectGraphics)}},{key:"removeTiles",value:function(n){Ya(NC(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,r){Ya(NC(i.prototype),"rerender",this).call(this,n,r),this.valueScale=null,this.drawnRects={},this.options.colorRange?this.colorScale=Oc(this.options.colorRange):this.colorScale=Nb;for(const C of this.visibleAndFetchedTiles())this.destroyTile(C),this.initTile(C),this.renderTile(C)}},{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 r=Object.values(n).sort((a,s)=>a.from-s.from);let C=0,o=0;for(let a=0;a=0&&r.length;a--)r[a].staggeredStartPosition=(o+C-a)%2;return n}},{key:"drawSegmentStyle",value:function(n,r,C,o,a,s){const l=o+a/2,c=[r,o,r+2*.1,o,r+2*.1,l-.1,C-2*.1,l-.1,C-2*.1,o,C,o,C,o+a,C-2*.1,o+a,C-2*.1,l+.1,r+2*.1,l+.1,r+2*.1,o+a,r,o+a];return n.rectGraphics.drawPolygon(c),c}},{key:"drawPoly",value:function(n,r,C,o,a,s){let A=null;return this.options.annotationStyle==="segment"?this.drawSegmentStyle(n,r,C,o,a,s):((s==="+"||s==="-")&&C-r=(+this.options.maxTexts||Boe)||!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={...ku,fill:W,fontSize:+this.options.fontSize||ku.fontSize},!(m[3]in n.textWidths)){X.updateTransform();const V=X.getBounds().width,H=X.getBounds().height,Y=5;n.textWidths[m[3]]=V,n.textHeights[m[3]]=H-Y}}}},{key:"renderTile",value:function(n){let r=n.plusStrandRows?n.plusStrandRows.length:1,C=n.minusStrandRows?n.minusStrandRows.length:1;for(const o of this.visibleAndFetchedTiles()){if(!o.initialized)return;!o.plusStrandRows&&!o.minusStrandRows||(r=Math.max(o.plusStrandRows.length,r),C=Math.max(o.minusStrandRows.length,C))}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=r*this.dimensions[1]/(r+C)-s/2:A=this.dimensions[1],this.renderRows(n,n.plusStrandRows,r,0,A,o),this.renderRows(n,n.minusStrandRows,C,this.options.separatePlusMinusStrands?A+s/2:0,this.dimensions[1],a)}Kd.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 r=Math.min(n,this.maxZoom);return r=Math.max(r,0),r}},{key:"minVisibleValueInTiles",value:function(n){let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));let C=Math.min.apply(null,r.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,$D).map(a=>+a.fields[n-1]).filter(a=>!Number.isNaN(a)))));return C===Number.MAX_SAFE_INTEGER&&(C=null),C}},{key:"maxVisibleValueInTiles",value:function(n){let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));let C=Math.max.apply(null,r.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,$D).map(a=>+a.fields[n-1]).filter(a=>!Number.isNaN(a)))));return C===Number.MIN_SAFE_INTEGER&&(C=null),C}},{key:"calculateMedianVisibleValue",value:function(n){this.areAllVisibleTilesLoaded()&&this.allTilesLoaded();let r=this.visibleAndFetchedIds();r.length===0&&(r=Object.keys(this.fetchedTiles));const C=[].concat(...r.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,$D).map(a=>+a.fields[n-1]))).filter(o=>o>0);this.medianVisibleValue=F7(C)}},{key:"draw",value:function(){Ya(NC(i.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];for(const n in this.fetchedTiles){const r=this.fetchedTiles[n];if(r.rectGraphics.scale.y=this.vertK,r.rectGraphics.position.y=this.vertY,!r.drawnAtScale)return;Kd.stretchRects(this,[o=>o.rectGraphics]);const C=this.parentInFetched(r);r.initialized&&r.tileData&&r.tileData.length&&r.tileData.forEach(o=>{if(!r.texts)return;const a=o.fields,s=a[3],A=r.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,!C&&!A.alreadyDrawn){A.visible=!0;const h=3;this.allBoxes.push([A.position.x-h,A.position.y-r.textHeights[a[3]]/2,A.position.x+r.textWidths[a[3]]+h,A.position.y+r.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,r){fw(n,(C,o)=>{r[C].importance>r[o].importance?r[C].text.visible&&(r[o].text.visible=!1):r[o].text.visible&&(r[C].text.visible=!1)})}},{key:"setPosition",value:function(n){Ya(NC(i.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){Ya(NC(i.prototype),"setDimensions",this).call(this,n)}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.refreshTiles(),this.draw()}},{key:"exportSVG",value:function(){let n=null,r=null;Ya(NC(i.prototype),"exportSVG",this)?[r,n]=Ya(NC(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(C);const o=document.createElement("g"),a=document.createElement("g");C.appendChild(o),C.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 C=this.valueScaleTransform,{y:o,k:a}=C,s=this.dimensions[1];o+n/a>-(a-1)*s&&o+n/a<0&&(this.valueScaleTransform=C.translate(0,n/a)),r.rectGraphics.position.y=this.valueScaleTransform.y,this.vertY=this.valueScaleTransform.y}),this.animate()}},{key:"zoomedY",value:function(n,r){const C=Kd.zoomedY(n,r,this.valueScaleTransform,this.dimensions[1]);this.valueScaleTransform=C;let o=C.k;const a=C.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,r){if(!this.tilesetInfo)return"";const C=this.calculateZoomLevel(),o=[n,r];if(this.drawnRects[C]){const a=Object.values(this.drawnRects[C]);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 xkt=(e,g,i,I,n)=>{n.drawRect(e,g,i,I)},Ekt=(e,g,i,I,n,{fill:r=0,fillOpacity:C=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",`#${uz(r)}`),A.setAttribute("fill-opacity",C),A.setAttribute("stroke",`#${uz(o)}`),A.setAttribute("stroke-opacity",s),A.setAttribute("stroke-width",a),n.appendChild(A)},Ta=(e,g,i,I,n,r)=>{n instanceof HTMLElement?Ekt(e,g,i,I,n,r):xkt(e,g,i,I,n)},Roe=(e,g,i,I,n,r,C,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?Ta(g-d,i-h,I+d*2,h,m,f):b==="bottom"&&!a||b==="right"&&a?Ta(g-d,i+n,I+d*2,h,m,f):b==="left"&&!a||b==="top"&&a?Ta(g-d,i-h,d,n+h*2,m,f):(b==="right"&&!a||b==="bottom"&&a)&&Ta(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,Ta(g-d,i-h,I+d*2,n+h*2,m,f)),C.positions&&C.positions.length){e.lineStyle(1,0,0),e.beginFill(C.color,C.opacity);const b=C.width*2>I?I/2:C.width,p=C.width*2>n?n/2:C.width;f.fill=C.color,f.fillOpacity=C.opacity,f.stroke=0,f.strokeOpacity=0,f.strokeWidth=1,C.positions.forEach(y=>{y==="top"&&!a||y==="left"&&a?(Ta(g,i,I,p,m,f),l+=p,u-=p):y==="bottom"&&!a||y==="right"&&a?(Ta(g,i+n-p,I,p,m,f),u-=p):y==="left"&&!a||y==="top"&&a?(Ta(g,i,b,n,m,f),A+=b,c-=b):(y==="right"&&!a||y==="bottom"&&a)&&(Ta(g+I-b,i,b,n,m,f),c-=b)})}else e.lineStyle(C.width,C.color,C.opacity),f.stroke=C.color,f.strokeOpacity=C.opacity,f.strokeWidth=C.width;e.beginFill(r.color,r.opacity),f.fill=r.color,f.fillOpacity=r.opacity,Ta(A,l,c,u,m,f)};let R1e=function(e){kkt(i,e);var g=Ykt(i);function i(I,n){var r;return Wkt(this,i),r=g.call(this,I,n),r.options=n||{},r.drawnRects={},r}return Xkt(i,[{key:"drawHorizontalOverlay",value:function(n,r,C,o=0,a,s,A,l){if(!C||C.length<2)return;let c=this.position[0]+r.left+this._xScale(C[0]);const u=this.position[1]+r.top,d=r.height;let h=this._xScale(C[1])-this._xScale(C[0]);h=4?C[2]:C[0]);const d=this.position[1]+r.top,h=this.position[1]+r.top+r.height;if(u>h)return;u=4?C[3]:C[1])-u+r.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(r,l.position,c,s,C,o,a,n)),(l.orientation==="1d-vertical"||l.orientation==="2d")&&this.options.extent.forEach(c=>this.drawVerticalOverlay(r,l.position,c,A,C,o,a,n))})}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"setPosition",value:function(n){ec(ja(i.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){ec(ja(i.prototype),"setDimensions",this).call(this,n),this.draw()}},{key:"exportSVG",value:function(){let n=null,r=null;ec(ja(i.prototype),"exportSVG",this)?[r,n]=ec(ja(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");return n.appendChild(C),this.draw({svg:C}),[r,n]}}]),i}(mr);function Mkt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Voe(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 qr(e){return qr=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},qr(e)}let Cy=function(e){_kt(i,e);var g=Lkt(i);function i(){return Mkt(this,i),g.apply(this,arguments)}return zkt(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 r=this.getDataAtPos(n);let C="";r&&(C=uC(".3f")(r));const o=this.pMouseOver,a=0,s=this.valueScale(r);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(),`${C}`}},{key:"initTile",value:function(n){if(xo(qr(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 r=this.getLockGroupExtrema();r!==null&&(this.minValue(r[0]),this.maxValue(r[1]))}this.drawTile(n)}},{key:"rerender",value:function(n,r){xo(qr(i.prototype),"rerender",this).call(this,n,r),this.options=n,xo(qr(i.prototype),"draw",this).call(this),this.visibleAndFetchedTiles().forEach(C=>{this.renderTile(C)})}},{key:"renderTile",value:function(n){this.drawTile(n),this.drawAxis(this.valueScale)}},{key:"drawTile",value:function(n){if(xo(qr(i.prototype),"drawTile",this).call(this,n),!n.graphics||!n.tileData||!n.tileData.dense)return;const r=n.graphics,{tileX:C,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,r.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=tg().domain([0,c]).range([C,C+o]),d=this.options.lineStrokeWidth?this.options.lineStrokeWidth:1;r.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);r.moveTo(f[0],f[1]);for(const p of b)r.lineTo(p[0],p[1])}}},{key:"setPosition",value:function(n){xo(qr(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,r){this.xScale(n),this.yScale(r),this.refreshTiles(),this.draw();const C=this.isValueScaleLocked();if(this.continuousScaling&&this.minValue()!==void 0&&this.maxValue()!==void 0){if(this.valueScaleMin===null&&this.valueScaleMax===null&&!C){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())}C&&this.onValueScaleChanged()}}},{key:"superSVG",value:function(){return xo(qr(i.prototype),"exportSVG",this).call(this)}},{key:"exportSVG",value:function(){let n=null,r=null;xo(qr(i.prototype),"exportSVG",this)?[r,n]=xo(qr(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r),r.setAttribute("class","exported-line-track");const C=document.createElement("g");n.appendChild(C),C.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),C.appendChild(A)});const a=document.createElement("g");if(a.setAttribute("id","axis"),r.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[r,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}(ny);function $kt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Woe(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 bs(e){return bs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},bs(e)}let V1e=function(e){iYt(i,e);var g=IYt(i);function i(){return $kt(this,i),g.apply(this,arguments)}return qkt(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),hd(bs(i.prototype),"initTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const r=n.graphics,{tileX:C,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=ru().domain([h,this.maxValue()+h]).range([this.dimensions[1],0]),s=h}else this.valueScale=tg().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(r.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=tg().domain([0,this.tilesetInfo.tile_size]).range([C,C+o]),c=0;r.lineStyle(c,A,1);const u=this.options.pointSize?this.options.pointSize:3,d=Kt(this.options.pointColor?this.options.pointColor:"red");r.beginFill(d,1),n.drawnAtScale=this._xScale.copy();for(let h=0;hthis.tilesetInfo.max_pos[0])break;r.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(){hd(bs(i.prototype),"draw",this).call(this);for(const n of Eg(this.fetchedTiles)){const r=(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=r,n.graphics.position.x=-o*r}}},{key:"zoomed",value:function(n,r,C,o,a){hd(bs(i.prototype),"zoomed",this).call(this,n,r)}},{key:"exportSVG",value:function(){let n=null,r=null;[r,n]=hd(bs(i.prototype),"superSVG",this).call(this),r.setAttribute("class","exported-line-track");const C=document.createElement("g");n.appendChild(C),C.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 aYt=(e,g)=>{const i=xB(e,g);return oYt(e.map(I=>(Array.isArray(I)&&g?I.length:1)/i))};function AYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Xoe(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)}let W1e=function(e){dYt(i,e);var g=hYt(i);function i(I,n){var r;return AYt(this,i),r=g.call(this,I,n),r.pMain=r.pMobile,r.continuousScaling=!1,r.updateDataFetcher(n),r}return sYt(i,[{key:"updateDataFetcher",value:function(n){if(n&&n.selectRows&&n.selectRowsAggregationMethod==="server"){const{pubSub:r,dataFetcher:C}=this,o=C.dataConfig.options,a={aggGroups:n.selectRows,aggFunc:n.selectRowsAggregationMode};if(JSON.stringify(o)!==JSON.stringify(a)){const s={...C.dataConfig,options:a};this.dataFetcher=new C.constructor(s,r),this.dataFetcher.dataConfig.tilesetUid&&this.fetchNewTiles(Object.keys(this.fetchedTiles).map(A=>({tileId:A,remoteId:A})))}}}},{key:"rerender",value:function(n,r){this.updateDataFetcher(n),pv(Bh(i.prototype),"rerender",this).call(this,n,r),n.selectRows&&(this.selectRowsCumWeights=aYt(n.selectRows,n.selectRowsAggregationWithRelativeHeight))}},{key:"tileDataToCanvas",value:function(n){const r=document.createElement("canvas");this.options.selectRows&&this.tilesetInfo.shape?(r.width=this.tilesetInfo.shape[0],r.height=xB(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight)):this.tilesetInfo.shape?(r.width=this.tilesetInfo.shape[0],r.height=this.tilesetInfo.shape[1]):(r.width=this.tilesetInfo.tile_size,r.height=1);const C=r.getContext("2d");if(C.fillStyle="transparent",C.fillRect(0,0,r.width,r.height),n.length!==0&&n.length===4*r.width*r.height){const o=new ImageData(n,r.width,r.height);C.putImageData(o,0,0)}else console.warn("HorizontalMultivecTrack: pixData has an incorrect length.");return r}},{key:"setSpriteProperties",value:function(n,r,C){const{tileX:o,tileWidth:a}=this.getTilePosAndDimensions(r,C,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,r,C,o,a){const s=this._xScale(0)-C*this._refXScale(0);this.pMobile.position.x=s+this.position[0],this.pMobile.position.y=this.position[1],this.pMobile.scale.x=C,this.pMobile.scale.y=1}},{key:"zoomed",value:function(n,r,C,o){pv(Bh(i.prototype),"zoomed",this).call(this,n,r),this.pMain.position.x=o,this.pMain.position.y=this.position[1],this.pMain.scale.x=C,this.pMain.scale.y=1,this.drawColorbar()}},{key:"calculateVisibleTiles",value:function(){if(!this.tilesetInfo)return;if(this.zoomLevel=this.calculateZoomLevel(),this.tilesetInfo.resolutions){const r=this.tilesetInfo.resolutions.map(C=>+C).sort((C,o)=>o-C);this.xTiles=vt.calculateTilesFromResolution(r[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(r=>[this.zoomLevel,r]);this.setVisibleTiles(n)}},{key:"calculateZoomLevel",value:function(){if(!this.tilesetInfo)return;const n=this.tilesetInfo.min_pos[0];let r=null;return this.tilesetInfo.resolutions?r=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,n):r=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),r}},{key:"tileToLocalId",value:function(n){return n.join(".")}},{key:"tileToRemoteId",value:function(n){return n.join(".")}},{key:"getTilePosAtPosition",value:function(n,r){if(!this.tilesetInfo)return;const C=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,C,this.tilesetInfo.tile_size),a=this._xScale.invert(n)/o;return[C,Math.floor(a)]}},{key:"getVisibleData",value:function(n,r){const C=this.calculateZoomLevel(),o=vt.calculateTileWidth(this.tilesetInfo,C,this.tilesetInfo.tile_size),a=this._xScale.invert(n)/o;let s=this.tilesetInfo.shape?this.tilesetInfo.shape[1]:1;this.options.selectRows&&(s=xB(this.options.selectRows,this.options.selectRowsAggregationWithRelativeHeight));let A=this.tilesetInfo.tile_size*(a-Math.floor(a));const l=r/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([C,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=$Q(this.options.selectRowsAggregationMode),y=b.map(Z=>m.tileData.dense[Z]);f=uC(".3f")(p(y)),f+="
",f+=`${b.length}-item ${this.options.selectRowsAggregationMode}`}else f=uC(".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,r)}
`,o+=`Zoom level: ${C[0]} tile position: ${C[1]}`;return o}}]),i}(mw);function bYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Hoe(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 Oo(e){return Oo=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Oo(e)}const WYt=Kt("#FFFFFF");let Zj=function(e){BYt(i,e);var g=SYt(i);function i(...I){var n;return bYt(this,i),n=g.call(this,...I),n.zeroLine=new ot.PIXI.Graphics,n.pMain.addChild(n.zeroLine),n.valueScaleTransform=JI,n.options&&n.options.colorRange&&(n.options.colorRangeGradient?n.setColorGradient(n.options.colorRange):n.setColorScale(n.options.colorRange)),n.initialized=!0,n}return yYt(i,[{key:"setColorScale",value:function(n){n&&(this.colorScale=Oc(n),this.colorScale=this.colorScale.map(r=>r.map(C=>C/255)))}},{key:"setColorGradient",value:function(n){if(!n)return;const r=n.length-1;this.colorGradientColors=this.options.align==="bottom"?n.slice().reverse().map((C,o)=>({from:o/r,color:C})):n.map((C,o)=>({from:o/r,color:C}))}},{key:"initTile",value:function(n){this.initialized&&ns(Oo(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&&ns(Oo(i.prototype),"renderTile",this).call(this,n)}},{key:"drawTile",value:function(n){if(!n.graphics||!n.tileData||!n.tileData.dense)return;const{graphics:r}=n;n.svgData=void 0;const{tileX:C,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),r.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=tg().domain([0,this.tilesetInfo.tile_size||this.tilesetInfo.bins_per_dimension]).range([C,C+o]),d=0;r.lineStyle(d,c,1);const h=this.options.barFillColor||"grey",m=Kt(h),f="barOpacity"in this.options?this.options.barOpacity:1;r.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 ot.PIXI.Graphics,G.beginFill(WYt,1);const w=_Ge(this.colorGradientColors,1,this.dimensions[1],0,0,0,this.dimensions[1]);v=new ot.PIXI.Sprite(ot.PIXI.Texture.fromCanvas(w,ot.PIXI.SCALE_MODES.NEAREST)),v.x=this._xScale(C),v.width=this._xScale(C+o)-v.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=ot.PIXI.utils.rgb2hex(S);r.beginFill(X,f)}(G||r).drawRect(p,Z,y,B)}this.colorGradientColors&&(v.mask=G,r.removeChildren(),r.addChild(v,G))}},{key:"rerender",value:function(n,r){n&&n.colorRange&&(n.colorRangeGradient?this.setColorGradient(n.colorRange):this.setColorScale(n.colorRange)),ns(Oo(i.prototype),"rerender",this).call(this,n,r)}},{key:"drawZeroLine",value:function(){this.zeroLine.clear();const n=Kt(this.options.barFillColor||"grey"),r=+this.options.barOpacity||1,C=this.options.zeroLineColor?Kt(this.options.zeroLineColor):n,o=Number.isNaN(+this.options.zeroLineOpacity)?r:+this.options.zeroLineOpacity;this.zeroLine.beginFill(C,o),this.zeroLine.drawRect(0,this.dimensions[1]-1,this.dimensions[0],1)}},{key:"drawZeroLineSvg",value:function(n){const r=document.createElement("rect");r.setAttribute("id","zero-line"),r.setAttribute("x",0),r.setAttribute("y",this.dimensions[1]-1),r.setAttribute("height",1),r.setAttribute("width",this.dimensions[0]),r.setAttribute("fill",this.options.zeroLineColor||this.options.barFillColor),r.setAttribute("fill-opacity",this.options.zeroLineOpacity||this.options.barOpacity),n.appendChild(r)}},{key:"getXScaleAndOffset",value:function(n){const r=n.domain(),C=this._xScale.domain(),o=(r[1]-r[0])/(C[1]-C[0]),s=this._xScale.domain().map(n)[0];return[o,-s*o]}},{key:"draw",value:function(){this.initialized&&(ns(Oo(i.prototype),"draw",this).call(this),this.options.zeroLineVisible?this.drawZeroLine():this.zeroLine.clear(),Object.values(this.fetchedTiles).forEach(n=>{const[r,C]=this.getXScaleAndOffset(n.drawnAtScale);n.graphics.scale.x=r,n.graphics.position.x=C}))}},{key:"zoomed",value:function(n,r){ns(Oo(i.prototype),"zoomed",this).call(this,n,r)}},{key:"movedY",value:function(n){}},{key:"zoomedY",value:function(n,r){}},{key:"addSVGInfo",value:function(n,r,C,o,a,s){n.svgData?(n.svgData.barXValues.push(r),n.svgData.barYValues.push(C),n.svgData.barWidths.push(o),n.svgData.barHeights.push(a),n.svgData.barColors.push(s)):n.svgData={barXValues:[r],barYValues:[C],barWidths:[o],barHeights:[a],barColors:[s]}}},{key:"exportSVG",value:function(){let n=null,r=null;[r,n]=ns(Oo(i.prototype),"superSVG",this).call(this),r.setAttribute("class","exported-line-track");const C=document.createElement("g");n.appendChild(C),C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.options.zeroLine&&this.drawZeroLineSvg(C),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 I2(e){return I2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},I2(e)}let X1e=function(e){kYt(i,e);var g=YYt(i);function i(){return XYt(this,i),g.apply(this,arguments)}return HYt(i,[{key:"drawTile",value:function(n){this.renderTile(n)}},{key:"renderTile",value:function(n){if(!n.graphics)return;const r=n.graphics,{tileX:C,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=ru().domain([p,this.maxValue()+p]).range([this.dimensions[1],0]),s=p}else this.valueScale=tg().domain([this.minValue(),this.maxValue()]).range([this.dimensions[1],0]);if(r.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=tg().domain([0,this.tilesetInfo.tile_size]).range([C,C+o]),c=0;r.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?(r.beginFill(m,f),this.addSVGInfo(n,y,b,B,Z-b,d)):(r.beginFill(h,f),this.addSVGInfo(n,y,Z,B,b-Z,u)),l(p)>this.tilesetInfo.max_pos[0])break;r.drawRect(y,n.svgData.barYValues[p],B,n.svgData.barHeights[p])}}}]),i}(Zj);function xYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Noe(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 H1e=function(e){JYt(i,e);var g=OYt(i);function i(I,n){var r;return xYt(this,i),r=g.call(this,I,n),r.setColorScale(n.colorRange),r.opacity=n.opacity||1,r}return EYt(i,[{key:"setColorScale",value:function(n){this.colorScale=n?Oc(n):Nb,this.colorScale=this.colorScale.map(r=>r.map(C=>C/255))}},{key:"rerender",value:function(n){n&&n.colorRange&&this.setColorScale(n.colorRange),this.opacity=n.opacity||1,yW(I0(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 r=n.graphics,{tileX:C,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,r.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=tg().domain([0,this.tilesetInfo.tile_size]).range([C,C+o]);r.lineStyle(0,0,0);for(let c=0;cthis.tilesetInfo.max_pos[0])break;a[c]!==0&&r.drawRect(d,0,h,m)}}}}]),i}(Cy);function QYt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function koe(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)}let T1e=function(e){eKt(i,e);var g=tKt(i);function i(I,n){var r;return QYt(this,i),r=g.call(this,I,n),r.seen=new Set,r.pMain=r.pMobile,r.rows=[],r}return jYt(i,[{key:"uid",value:function(n){return n[n.length-2]}},{key:"segmentOverlap",value:function(n,r){}},{key:"drawAll",value:function(n){this.pMain.clear();const r=new Set,C=n.map(a=>r.has(this.uid(a))?null:(r.add(this.uid(a)),{from:+a[1],to:+a[2],type:a[4],uid:this.uid(a)})).filter(a=>a),o=RX(C);this.rows=o,this.draw()}},{key:"draw",value:function(){const n=this.rows;if(!n)return;const r=DS().range([0,this.dimensions[1]]).padding(.1).domain(nr(0,this.maxRows())),C=this.pMain;C.clear(),C.lineStyle(1,255,0),C.beginFill(16740363,.8);for(let o=0;othis.fetchedTiles[o].tileData.discrete),C=[].concat(...r);this.drawAll(C)}},{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(r=>{const C=r[r.length-2];this.seen.has(C)&&this.seen.delete(C)})}},{key:"drawTile",value:function(n){}}]),i}(ny);function nKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Yoe(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]}}]),e}();function gKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Hoe(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 _o(e){return _o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},_o(e)}const Toe=11,QD="Arial",Noe="outside",DP=10,lKt=4,cKt=20,uKt=Kt("#ffffff"),kR=2,dKt=2*DP/3,gf=2*dKt/3,hKt=50,mKt=5e3,FP="blue",EP="red",m4=(e,g,I)=>{I.type!=="filler"&&g.pubSub.publish("app.click",{type:"gene-annotation",event:e,payload:I})},koe=(e,g)=>{const I=e.concat(g),i=I.map(n=>[n.xStart,1,n.xEnd,1]);dw(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 fKt(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 ot.PIXI.Graphics,g.textBgGraphics=new ot.PIXI.Graphics,g.textGraphics=new ot.PIXI.Graphics,g.rectMaskGraphics=new ot.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||FP;if(b==="-"&&(p=o||EP),g.textWidths={},g.textHeights={},d>=A)return;const y=new ot.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 Yoe(e,g,I,i,n,C,r,o,a){const s=o-a/2,A=0;e.forEach(l=>{const c=new ot.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=>m4(d,g,l),c.drawPolygon(u),I.allRects.push([u,l.strand,l])})}function pKt(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-kR/2,u+h,m-kR/2,u+h,m+kR/2,u,m+kR/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 ot.PIXI.Graphics;I.rectGraphics.addChild(u),u.beginFill(C,r),u.interactive=!0,u.buttonMode=!0,u.mouseup=m=>m4(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 yKt(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 ot.PIXI.Graphics;I.rectGraphics.addChild(d),d.beginFill(C,r),d.interactive=!0,d.buttonMode=!0,d.mouseup=h=>m4(h,g,s),I.allRects=I.allRects.concat(pKt(g,d,s.xStart,s.xEnd,c,u,l,o,a,s.strand||s.fields[5]).map(h=>[h,s.strand,s]))})}function Koe(e,g,I,i,n,C,r,o,a){bKt(e,g,I,i,n,C,r,o,a),yKt(e,g,I,i,n,C,r,o,a)}function ZKt(e,g){const{tileX:I,tileWidth:i}=xd.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 S1e=function(e){rKt(I,e);var g=oKt(I);function I(i,n){var C;gKt(this,I),C=g.call(this,i,n);const{animate:r}=i;return C.animate=r,C.options=n,C.fontSize=+C.options.fontSize||Toe,C.geneLabelPos=C.options.geneLabelPosition||Noe,C.geneRectHeight=+C.options.geneAnnotationHeight||DP,C.geneRectHeight-=2,C.geneStrandSpacing=+C.options.geneStrandSpacing||lKt,C.geneStrandHSpacing=C.geneStrandSpacing/2,C.geneRectHHeight=C.geneRectHeight/2,C}return IKt(I,[{key:"initTile",value:function(n){fKt(this,n,{flipText:this.flipText,fontSize:this.fontSize,fontFamily:QD,plusStrandColor:this.options.plusStrandColor,minusStrandColor:this.options.minusStrandColor,maxGeneEntries:hKt,maxFillerEntries:mKt,maxTexts:cKt}),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||(Cs(_o(I.prototype),"rerender",this).call(this,n,C),this.fontSize=+this.options.fontSize||Toe,this.geneLabelPos=this.options.geneLabelPosition||Noe,this.geneRectHeight=+this.options.geneAnnotationHeight||DP,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||FP),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]==="-"));koe(A,a),koe(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];Yoe(a,...h),Yoe(s,...m),h[5]=o,m[5]=o,Koe(A,...h),Koe(l,...m),ZKt(this,n),xd.stretchRects(this,[f=>f.rectGraphics,f=>f.rectMaskGraphics]);for(const f of Object.values(n.texts))f.style={fontSize:`${this.fontSize}px`,FONT_FAMILY:QD,fill:Kt(f.strand==="-"?this.options.minusStrandColor||EP:this.options.plusStrandColor||FP)}}},{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(){Cs(_o(I.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];const n=[];this.geneAreaHeight=this.geneRectHeight;const C=this.fontSize/2;xd.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):uKt);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){dw(n,(r,o)=>{C[r].importance>C[o].importance?C[o].text.visible=!1:C[r].text.visible=!1})}},{key:"setPosition",value:function(n){Cs(_o(I.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){Cs(_o(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 aKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Foe(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 _o(e){return _o=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},_o(e)}const Doe=11,qD="Arial",xoe="outside",PP=10,pKt=4,bKt=20,yKt=Kt("#ffffff"),FV=2,ZKt=2*PP/3,tf=2*ZKt/3,GKt=50,vKt=5e3,JP="blue",OP="red",Gj=(e,g,i)=>{i.type!=="filler"&&g.pubSub.publish("app.click",{type:"gene-annotation",event:e,payload:i})},Eoe=(e,g)=>{const i=e.concat(g),I=i.map(n=>[n.xStart,1,n.xEnd,1]);fw(I,(n,r)=>{let C=null,o=null;if(i[n].type==="filler"?C=i[n]:o=i[n],i[r].type==="filler"){if(C)return;C=i[r]}else{if(!C)return;o=i[r]}C.xStart>=o.xStart&&C.xEnd<=o.xEnd&&(C.hide=!0)})};function BKt(e,g,i){const{flipText:I,fontSize:n,fontFamily:r,plusStrandColor:C,minusStrandColor:o,maxGeneEntries:a,maxFillerEntries:s,maxTexts:A}=i;if(g.texts={},g.rectGraphics=new ot.PIXI.Graphics,g.textBgGraphics=new ot.PIXI.Graphics,g.textGraphics=new ot.PIXI.Graphics,g.rectMaskGraphics=new ot.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=C||JP;if(b==="-"&&(p=o||OP),g.textWidths={},g.textHeights={},d>=A)return;const y=new ot.PIXI.Text(m,{fontSize:`${n}px`,fontFamily:r,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 Moe(e,g,i,I,n,r,C,o,a){const s=o-a/2,A=0;e.forEach(l=>{const c=new ot.PIXI.Graphics;i.rectGraphics.addChild(c),c.beginFill(r,.1),c.lineStyle(0,r);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=>Gj(d,g,l),c.drawPolygon(u),i.allRects.push([u,l.strand,l])})}function SKt(e,g,i,I,n,r,C,o,a,s){const A=o-a/2,l=n.split(",").map(y=>+y+C),c=r.split(",").map(y=>+y+C),u=e._xScale(i),d=e._xScale(I),h=d-u,m=o,f=[];let b=[u,m-FV/2,u+h,m-FV/2,u+h,m+FV/2,u,m+FV/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 ot.PIXI.Graphics;i.rectGraphics.addChild(u),u.beginFill(r,C),u.interactive=!0,u.buttonMode=!0,u.mouseup=m=>Gj(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 RKt(e,g,i,I,n,r,C,o,a){e.forEach(s=>{const A=s.fields,l=+s.chrOffset,c=A[12],u=A[13],d=new ot.PIXI.Graphics;i.rectGraphics.addChild(d),d.beginFill(r,C),d.interactive=!0,d.buttonMode=!0,d.mouseup=h=>Gj(h,g,s),i.allRects=i.allRects.concat(SKt(g,d,s.xStart,s.xEnd,c,u,l,o,a,s.strand||s.fields[5]).map(h=>[h,s.strand,s]))})}function zoe(e,g,i,I,n,r,C,o,a){wKt(e,g,i,I,n,r,C,o,a),RKt(e,g,i,I,n,r,C,o,a)}function VKt(e,g){const{tileX:i,tileWidth:I}=Kd.getTilePosAndDimensions(e.tilesetInfo,g.tileId);g.rectMaskGraphics.clear();const n=Math.floor(Math.random()*16**6);g.rectMaskGraphics.beginFill(n,.3);const r=e._xScale(i),C=0,o=e._xScale(i+I)-e._xScale(i),a=e.dimensions[1];g.rectMaskGraphics.drawRect(r,C,o,a)}let N1e=function(e){uKt(i,e);var g=dKt(i);function i(I,n){var r;aKt(this,i),r=g.call(this,I,n);const{animate:C}=I;return r.animate=C,r.options=n,r.fontSize=+r.options.fontSize||Doe,r.geneLabelPos=r.options.geneLabelPosition||xoe,r.geneRectHeight=+r.options.geneAnnotationHeight||PP,r.geneRectHeight-=2,r.geneStrandSpacing=+r.options.geneStrandSpacing||pKt,r.geneStrandHSpacing=r.geneStrandSpacing/2,r.geneRectHHeight=r.geneRectHeight/2,r}return AKt(i,[{key:"initTile",value:function(n){BKt(this,n,{flipText:this.flipText,fontSize:this.fontSize,fontFamily:qD,plusStrandColor:this.options.plusStrandColor,minusStrandColor:this.options.minusStrandColor,maxGeneEntries:GKt,maxFillerEntries:vKt,maxTexts:bKt}),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,r){const C=JSON.stringify(n);!r&&C===this.prevOptions||(rs(_o(i.prototype),"rerender",this).call(this,n,r),this.fontSize=+this.options.fontSize||Doe,this.geneLabelPos=this.options.geneLabelPosition||xoe,this.geneRectHeight=+this.options.geneAnnotationHeight||PP,this.geneStrandHSpacing=this.geneStrandSpacing/2,this.geneRectHHeight=this.geneRectHeight/2,this.prevOptions=C,this.visibleAndFetchedTiles().forEach(o=>{this.renderTile(o)}))}},{key:"drawTile",value:function(){}},{key:"geneId",value:function(n,r){return`${r}_${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 r={},C=.3,o=.3;r["+"]=Kt(this.options.plusStrandColor||JP),r["-"]=Kt(this.options.minusStrandColor||OP);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]==="-"));Eoe(A,a),Eoe(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,r["+"],C,u,this.geneRectHeight],m=[this,n,n.rectGraphics,this._xScale,r["-"],C,d,this.geneRectHeight];Moe(a,...h),Moe(s,...m),h[5]=o,m[5]=o,zoe(A,...h),zoe(l,...m),VKt(this,n),Kd.stretchRects(this,[f=>f.rectGraphics,f=>f.rectMaskGraphics]);for(const f of Object.values(n.texts))f.style={fontSize:`${this.fontSize}px`,FONT_FAMILY:qD,fill:Kt(f.strand==="-"?this.options.minusStrandColor||OP:this.options.plusStrandColor||JP)}}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let r=Math.min(n,this.maxZoom);return r=Math.max(r,0),r}},{key:"draw",value:function(){rs(_o(i.prototype),"draw",this).call(this),this.allTexts=[],this.allBoxes=[];const n=[];this.geneAreaHeight=this.geneRectHeight;const r=this.fontSize/2;Kd.stretchRects(this,[C=>C.rectGraphics,C=>C.rectMaskGraphics]),Object.values(this.fetchedTiles).filter(C=>C.drawnAtScale).forEach(C=>{C.textBgGraphics.clear(),C.textBgGraphics.beginFill(typeof this.options.labelBackgroundColor<"u"?Kt(this.options.labelBackgroundColor):yKt);const o=this.parentInFetched(C);C.initialized&&C.tileData.forEach(a=>{if(!C.texts||a.type==="filler")return;const s=a.fields,A=s[3],l=this.geneId(s,a.type),c=C.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,!C.textWidths[l]){const p=c.getBounds().width,y=c.getBounds().height;C.textHeights[l]=y,C.textWidths[l]=p}if(o)c.visible=!1;else{c.visible=!0;const p=2;this.flipText?this.allBoxes.push([c.position.x-C.textHeights[l]/2-p,f-r-1,c.position.x+C.textHeights[l]/2+p,f+r-1,A]):this.allBoxes.push([c.position.x-C.textWidths[l]/2-p,f-r-1,c.position.x+C.textWidths[l]/2+p,f+r-1,A]),this.allTexts.push({importance:+s[4],text:c,caption:A,strand:s[5]}),n.push(C.textBgGraphics)}})}),this.hideOverlaps(this.allBoxes,this.allTexts),this.renderTextBg(this.allBoxes,this.allTexts,n)}},{key:"renderTextBg",value:function(n,r,C){r.forEach((o,a)=>{if(o.text.visible&&n[a]&&C[a]){const[s,A,l,c]=n[a],u=l-s,d=c-A;C[a].drawRect(s-u/2,A-d/2,u,d)}})}},{key:"hideOverlaps",value:function(n,r){fw(n,(C,o)=>{r[C].importance>r[o].importance?r[o].text.visible=!1:r[C].text.visible=!1})}},{key:"setPosition",value:function(n){rs(_o(i.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"setDimensions",value:function(n){rs(_o(i.prototype),"setDimensions",this).call(this,n),this.halfRectHHeight=this.dimensions[1]/2,this.visibleAndFetchedTiles().forEach(r=>{this.renderTile(r)})}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.refreshTiles(),this.draw()}},{key:"getMouseOverHtml",value:function(n,r){if(!this.tilesetInfo)return"";const C=[n,r];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;Cs(_o(I.prototype),"exportSVG",this)?[C,n]=Cs(_o(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,r=null;rs(_o(i.prototype),"exportSVG",this)?[r,n]=rs(_o(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");return C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(C),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",QD),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}(iy);function GKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function xoe(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 ys(e){return ys=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},ys(e)}function Doe(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 w1e=function(e){VKt(I,e);var g=RKt(I);function I(...i){var n;GKt(this,I),n=g.call(this,...i),n.drawnRects={};const{publish:C,subscribe:r,unsubscribe:o}=yN();return n.publish=C,n.subscribe=r,n.unsubscribe=o,n}return vKt(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=>{Doe(this,C,d,a,A,l,c,u,s,this.options.flipDiagonal==="yes"),this.options.flipDiagonal&&this.options.flipDiagonal==="copy"&&Doe(this,C,d,a,A,l,c,u,s,!0)})}},{key:"exportSVG",value:function(){let n=null,C=null;fd(ys(I.prototype),"exportSVG",this)?[C,n]=fd(ys(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){fd(ys(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}(mm);function TKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Foe(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 Zs(e){return Zs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Zs(e)}const MKt=250;let R1e=function(e){xKt(I,e);var g=DKt(I);function I(i,n){var C;TKt(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}=yN();return C.publish=o,C.subscribe=a,C.unsubscribe=s,C.sT=0,C.annoSelectedBound=C.annoSelected.bind(V1e(C)),C.pubSubs.push(r.subscribe("annoSelected",C.annoSelectedBound)),C}return NKt(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 PGe(Az(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=Az(.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<=MKt&&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;pd(Zs(I.prototype),"exportSVG",this)?[C,n]=pd(Zs(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){pd(Zs(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}(mm);function zKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Eoe(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 wh(e){return wh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},wh(e)}let JP=function(e){LKt(I,e);var g=UKt(I);function I(i,n,C){var r;return zKt(this,I),r=g.call(this,i,n),r.pubSub=i.pubSub,r.options=n,r.isVertical=C,r.rects={},r.defaultColor=Hi("red"),r}return PKt(I,[{key:"draw",value:function(){const n=typeof this.options.minRectWidth<"u"?this.options.minRectWidth:10,C=typeof this.options.fill<"u"?Hi(this.options.fill):this.defaultColor,r=typeof this.options.fillOpacity<"u"?+this.options.fillOpacity:.2,o=typeof this.options.stroke<"u"?Hi(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]),bv(wh(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 ot.PIXI.Graphics},l.addChild(this.rects[d].graphics)),this.rects[d].timeStamp=c;const h=Hi(u[2])||C;let m=Hi(u[3])||o;m||(m=h);const f=ot.PIXI.utils.rgb2hex([h.r/255,h.g/255,h.b/255]),b=ot.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 ot.PIXI.Rectangle(0,y,this.dimensions[0],B)):(l.drawRect(y,0,B,this.dimensions[1]),this.rects[d].graphics.hitArea=new ot.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){bv(wh(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}(fC);function qKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Moe(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 W1e=function(e){i5t(I,e);var g=n5t(I);function I(i,n){var C;return qKt(this,I),C=g.call(this,i,n),C.drawnRects=new Set,C.pMain=C.pMobile,C}return e5t(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){tc($a(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(),tc($a(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){tc($a(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){tc($a(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){tc($a(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}(mm);function a5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function zoe(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 Vh(e){return Vh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Vh(e)}let X1e=function(e){u5t(I,e);var g=d5t(I);function I(i,n){var C;return a5t(this,I),C=g.call(this,i,n),C.drawnRects=new Set,C}return A5t(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?Ti(n,i):null,i.chrToAbs=([n,C]=[])=>i.chrPositions?d9(n,C,i):null,vt.text(e,(n,C)=>{if(n)g&&g(null);else{const r=YQ(C),o=VN(r);Object.keys(o).forEach(a=>{i[a]=o[a]}),g&&g(i)}},I).then(()=>i)}function p5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Poe(e,g){for(var I=0;II.pos).left}return b5t(e,[{key:"scalesToPositionText",value:function(I,i,n=!1){if(this.chromInfo===null||!I||!i)return"";const C=Ti(I.domain()[0],this.chromInfo),r=Ti(I.domain()[1],this.chromInfo),o=Ti(i.domain()[0],this.chromInfo),a=Ti(i.domain()[1],this.chromInfo);let s=null;const A=dr(",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 G5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Joe(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 n0(e){return n0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},n0(e)}let H1e=function(e){V5t(I,e);var g=R5t(I);function I(i,n){var C;G5t(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 Js(l,c=>{C.chromInfo=c,C.searchField=new i0(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]}),dw(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=0:n[r].text.visible=0})}},{key:"setPosition",value:function(n){pW(n0(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}(fC);function T5t(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 kc(e){return kc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},kc(e)}let iG=function(e){x5t(I,e);var g=D5t(I);function I(i,n){var C;T5t(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}`),Js(c,u=>{C.chromInfo=u,C.searchField=new i0(C.chromInfo),C.texts=[],C.lineGraphics=new ot.PIXI.Graphics,C.lineGraphics1dH=new ot.PIXI.Graphics,C.lineGraphics1dV=new ot.PIXI.Graphics,C.lineGraphics2d=new ot.PIXI.Graphics,C.mask1dH=new ot.PIXI.Graphics,C.mask1dV=new ot.PIXI.Graphics,C.mask2d=new ot.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 N5t(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 Rh(e){return Rh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Rh(e)}const q5t=300;let T1e=function(e){L5t(I,e);var g=U5t(I);function I(i,n){var C;z5t(this,I),C=g.call(this,i,n);const{chromInfoPath:r,pubSub:o}=i;return C.pubSub=o,C.rects={},Js(r,a=>{C.chromInfo=a,C.draw()},C.pubSub),C}return P5t(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;Zv(Rh(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 ot.PIXI.Graphics},r.addChild(this.rects[s].graphics)),this.rects[s].timeStamp=o;const A=Hi(a[6]);let l=Hi(a[7]);l||(l=A);const c=ot.PIXI.utils.rgb2hex([A.r/255,A.g/255,A.b/255]),u=ot.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 Gs(e){return Gs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Gs(e)}const axt=200,Axt=6,sxt=2,Uoe=7829367;let k1e=function(e){nxt(I,e);var g=Cxt(I);function I(i,n){var C;ext(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 ot.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()===gI?"#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=axt,C.tickHeight=Axt,C.tickTextSeparation=sxt,C.tickColor=C.options.tickColor?Kt(C.options.tickColor):Uoe,C.animate=o,C.pubSubs=[],C.options.showMousePosition&&!C.hideMousePosition&&(C.hideMousePosition=sh(N1e(C),C.is2d,C.isShowGlobalMousePosition()));let A=a;return A||(A=`${r.server}/chrom-sizes/?id=${r.tilesetUid}`),Js(A,l=>{C.chromInfo=l,C.searchField=new i0(C.chromInfo),C.rerender(C.options,!0),C.draw(),C.animate()},C.pubSub),C}return txt(I,[{key:"initBoundsTicks",value:function(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new ot.PIXI.Graphics,this.leftBoundTick=new ot.PIXI.Text("",this.pixiTextConfig),this.rightBoundTick=new ot.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 ot.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]}),dw(C,(r,o)=>{n[r].importance>n[o].importance?n[o].text.visible=!1:n[r].text.visible=!1})}},{key:"setPosition",value:function(n){bd(Gs(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;bd(Gs(I.prototype),"exportSVG",this)?[C,n]=bd(Gs(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=cz(o.text);r.appendChild(a)}),Object.values(this.tickTexts).forEach(o=>{o.filter(a=>a.visible).forEach(a=>{let s=cz(a);r.appendChild(s),s=jGe(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}(fC);function lxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Qoe(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 qa(e){return qa=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},qa(e)}let Y1e=function(e){mxt(I,e);var g=fxt(I);function I(i,n){var C;lxt(this,I),C=g.call(this,i,n);const{animate:r}=i;return C.pMain=C.pMobile,C.colorScale=Tb,C.continuousScaling=!1,n&&n.colorRange&&(C.colorScale=_c(n.colorRange)),C.animate=r,C.options=n,C.pubSubs=[],C}return cxt(I,[{key:"rerender",value:function(n,C){gc(qa(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=ot.PIXI.VERSION[0]==="4"?ot.PIXI.Texture.fromCanvas(o,ot.PIXI.SCALE_MODES.NEAREST):ot.PIXI.Texture.from(o,{scaleMode:ot.PIXI.SCALE_MODES.NEAREST});n.sprite=new ot.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){gc(qa(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){gc(qa(I.prototype),"zoomed",this).call(this,n,C,r,o,a),gc(qa(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]=gc(qa(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}(uw);function Zxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function joe(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 I2(e){return I2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},I2(e)}let $oe=function(e){Sxt(I,e);var g=wxt(I);function I(i,n){var C;return Zxt(this,I),C=g.call(this,i,n),C.tilesetInfo={},C.errorTextText=`Unknown track type: ${n.type}`,C}return Gxt(I,[{key:"zoomed",value:function(){this.draw()}}]),I}(fC);function Xxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function qoe(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 i2(e){return i2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},i2(e)}let x1e=function(e){kxt(I,e);var g=Yxt(I);function I(i,n){var C;return Xxt(this,I),C=g.call(this,i,n),C.axis=new pk(K1e(C)),C.pBase.addChild(C.axis.pAxis),C}return Hxt(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=ru().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}(Cy);function Dxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function eae(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 Yc(e){return Yc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Yc(e)}let D1e=function(e){Pxt(I,e);var g=Jxt(I);function I(i,n){var C;Dxt(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:a}=i,s=sg.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=BQ().on("brush",C.brushed.bind(gJ(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(gJ(C))),C.rerender(),C.draw(),C}return Fxt(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),_p(Yc(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){_p(Yc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){_p(Yc(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}(fm);function Lxt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tae(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 Kc(e){return Kc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Kc(e)}let F1e=function(e){qxt(I,e);var g=eDt(I);function I(i,n){var C;Lxt(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:a}=i,s=sg.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=SN().on("brush",C.brushed.bind(iJ(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(iJ(C))),C.rerender(),C.draw(),C}return Uxt(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),Lp(Kc(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){Lp(Kc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Lp(Kc(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}(fm);function IDt(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 xc(e){return xc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},xc(e)}let E1e=function(e){oDt(I,e);var g=aDt(I);function I(i,n){var C;IDt(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o,setDomainsCallback:a}=i,s=sg.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=PS().on("brush",C.brushed.bind(CJ(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(CJ(C))),C.rerender(),C.draw(),C}return iDt(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),Up(xc(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){Up(xc(I.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Up(xc(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}(fm);function Iae(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function iae(e,g){for(var I=0;Ie[oJ]||e,uDt=(e,g)=>{const I=g(e);return I.prototype[rJ]=M1e(g),I},dDt=(e,g)=>e.hasOwnProperty(rJ)&&e[rJ]===M1e(g),hDt=(e,g)=>{for(;e!==null;){if(dDt(e,g))return!0;e=Object.getPrototypeOf(e)}return!1},f4=(e,g)=>(Object.setPrototypeOf(g,e),e[oJ]||(e[oJ]=e),g),jD="__mixwith_cachedApplications",mDt=e=>f4(e,g=>{let I=g[jD];I||(g[jD]=new Map,I=g[jD]);let i=I.get(e);return i||(i=e(g),I.set(e,i)),i}),fDt=e=>f4(e,g=>hDt(g.prototype,e)?g:e(g)),pDt=e=>f4(e,g=>uDt(g,e)),Wk=e=>fDt(mDt(pDt(e)));let bDt=function(){function e(g){Iae(this,e),this.superclass=g||function(){function I(){Iae(this,I)}return nae(I)}()}return nae(e,[{key:"with",value:function(...I){return I.reduce((i,n)=>n(i),this.superclass)}}]),e}();const ry=e=>new bDt(e);function yDt(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 Wh(e){return Wh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Wh(e)}const p4=Wk(e=>function(g){SDt(i,g);var I=wDt(i);function i(n,C){var r;yDt(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(z1e(r)))),r}return ZDt(i,[{key:"setPosition",value:function(C){Gv(Wh(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){Gv(Wh(i.prototype),"zoomed",this).call(this,C,r),this.draw()}},{key:"respondsToPosition",value:function(){return this.highlighted}}]),i}(e));function vv(){return typeof Reflect<"u"&&Reflect.get?vv=Reflect.get.bind():vv=function(g,I,i){var n=WDt(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},vv.apply(this,arguments)}function WDt(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=Xh(e),e!==null););return e}function P1e(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 Xh(e){return Xh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Xh(e)}const YDt=Wk(e=>function(g){O1e(i,g);var I=_1e(i);function i(){return P1e(this,i),I.apply(this,arguments)}return J1e(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 Hh(e){return Hh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Hh(e)}const q1e=Wk(e=>function(g){j1e(i,g);var I=$1e(i);function i(){return U1e(this,i),I.apply(this,arguments)}return Q1e(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 Th(e){return Th=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},Th(e)}let tWe=function(e){LDt(I,e);var g=UDt(I);function I(i,n){var C;zDt(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 PDt(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 eA(e){return eA=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},eA(e)}let hw=function(e){iFt(I,e);var g=nFt(I);function I(i,n){var C;qDt(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=sg.nice(),C.refreshTilesDebounced=TQ(C.refreshTiles.bind(gWe(C)),m9),C}return eFt(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 C0(e){return C0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},C0(e)}let IWe=function(e){cFt(I,e);var g=uFt(I);function I(){return oFt(this,I),g.apply(this,arguments)}return aFt(I,[{key:"initTile",value:function(n){TRe.bind(this)(n),this.drawTile(n)}},{key:"drawTile",value:function(n){HRe.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(){bW(C0(I.prototype),"draw",this).call(this)}}]),I}(hw);function fFt(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 r0(e){return r0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},r0(e)}let iWe=function(e){GFt(I,e);var g=vFt(I);function I(i,n){var C;return fFt(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 pFt(I,[{key:"rerender",value:function(n){yW(r0(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}(hw);function VFt(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 n2(e){return n2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},n2(e)}let nWe=function(e){HFt(I,e);var g=TFt(I);function I(i,n){var C;return VFt(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 RFt(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}(hw);const KFt=(e,g,I,i=_2)=>{const n=I[e.type];return n?new n.dataFetcher(i,e,g):e.type==="genbank"?new WRe(e,g):e.type==="local-tiles"?new XRe(e,g):new yk(e,g)};var zt=1e-6,$B=1e-12,og=Math.PI,QI=og/2,C2=og/4,sC=og*2,tI=180/og,Ot=og/180,Vg=Math.abs,oy=Math.atan,lC=Math.atan2,Tt=Math.cos,YR=Math.ceil,CWe=Math.exp,mJ=Math.hypot,r2=Math.log,$D=Math.pow,Bt=Math.sin,Ur=Math.sign||function(e){return e>0?1:e<0?-1:0},ji=Math.sqrt,b4=Math.tan;function rWe(e){return e>1?0:e<-1?og:Math.acos(e)}function cC(e){return e>1?QI:e<-1?-QI:Math.asin(e)}function uae(e){return(e=Bt(e/2))*e}function FI(){}function o2(e,g){e&&hae.hasOwnProperty(e.type)&&hae[e.type](e,g)}var dae={Feature:function(e,g){o2(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=yJ*r,a=bJ*C+o*Tt(n),s=o*i*Bt(n);a2.add(lC(s,a)),pJ=e,bJ=C,yJ=r}function EFt(e){return A2=new Yi,Lo(e,BA),A2*2}function s2(e){return[lC(e[1],e[0]),cC(e[2])]}function Nh(e){var g=e[0],I=e[1],i=Tt(I);return[i*Tt(g),i*Bt(g),Bt(I)]}function KR(e,g){return e[0]*g[0]+e[1]*g[1]+e[2]*g[2]}function o0(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 qD(e,g){e[0]+=g[0],e[1]+=g[1],e[2]+=g[2]}function xR(e,g){return[e[0]*g,e[1]*g,e[2]*g]}function l2(e){var g=ji(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=g,e[1]/=g,e[2]/=g}var YI,TC,LI,nr,qu,sWe,lWe,Qp,wv,Ol,Os,rs={point:ZJ,lineStart:fae,lineEnd:pae,polygonStart:function(){rs.point=uWe,rs.lineStart=MFt,rs.lineEnd=zFt,wv=new Yi,BA.polygonStart()},polygonEnd:function(){BA.polygonEnd(),rs.point=ZJ,rs.lineStart=fae,rs.lineEnd=pae,a2<0?(YI=-(LI=180),TC=-(nr=90)):wv>zt?nr=90:wv<-zt&&(TC=-90),Os[0]=YI,Os[1]=LI},sphere:function(){YI=-(LI=180),TC=-(nr=90)}};function ZJ(e,g){Ol.push(Os=[YI=e,LI=e]),gnr&&(nr=g)}function cWe(e,g){var I=Nh([e*Ot,g*Ot]);if(Qp){var i=o0(Qp,I),n=[i[1],-i[0],0],C=o0(n,i);l2(C),C=s2(C);var r=e-qu,o=r>0?1:-1,a=C[0]*tI*o,s,A=Vg(r)>180;A^(o*qunr&&(nr=s)):(a=(a+360)%360-180,A^(o*qunr&&(nr=g))),A?etr(YI,LI)&&(LI=e):tr(e,LI)>tr(YI,LI)&&(YI=e):LI>=YI?(eLI&&(LI=e)):e>qu?tr(YI,e)>tr(YI,LI)&&(LI=e):tr(e,LI)>tr(YI,LI)&&(YI=e)}else Ol.push(Os=[YI=e,LI=e]);gnr&&(nr=g),Qp=I,qu=e}function fae(){rs.point=cWe}function pae(){Os[0]=YI,Os[1]=LI,rs.point=ZJ,Qp=null}function uWe(e,g){if(Qp){var I=e-qu;wv.add(Vg(I)>180?I+(I>0?360:-360):I)}else sWe=e,lWe=g;BA.point(e,g),cWe(e,g)}function MFt(){BA.lineStart()}function zFt(){uWe(sWe,lWe),BA.lineEnd(),Vg(wv)>zt&&(YI=-(LI=180)),Os[0]=YI,Os[1]=LI,Qp=null}function tr(e,g){return(g-=e)<0?g+360:g}function PFt(e,g){return e[0]-g[0]}function bae(e,g){return e[0]<=e[1]?e[0]<=g&&g<=e[1]:gtr(i[0],i[1])&&(i[1]=n[1]),tr(n[0],i[1])>tr(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=tr(i[1],n[0]))>r&&(r=o,YI=n[0],LI=i[1])}return Ol=Os=null,YI===1/0||TC===1/0?[[NaN,NaN],[NaN,NaN]]:[[YI,TC],[LI,nr]]}var nG,c2,u2,d2,h2,m2,f2,p2,GJ,vJ,BJ,dWe,hWe,tC,gC,IC,$o={sphere:FI,point:y4,lineStart:yae,lineEnd:Zae,polygonStart:function(){$o.lineStart=LFt,$o.lineEnd=UFt},polygonEnd:function(){$o.lineStart=yae,$o.lineEnd=Zae}};function y4(e,g){e*=Ot,g*=Ot;var I=Tt(g);mw(I*Tt(e),I*Bt(e),Bt(g))}function mw(e,g,I){++nG,u2+=(e-u2)/nG,d2+=(g-d2)/nG,h2+=(I-h2)/nG}function yae(){$o.point=OFt}function OFt(e,g){e*=Ot,g*=Ot;var I=Tt(g);tC=I*Tt(e),gC=I*Bt(e),IC=Bt(g),$o.point=_Ft,mw(tC,gC,IC)}function _Ft(e,g){e*=Ot,g*=Ot;var I=Tt(g),i=I*Tt(e),n=I*Bt(e),C=Bt(g),r=lC(ji((r=gC*C-IC*n)*r+(r=IC*i-tC*C)*r+(r=tC*n-gC*i)*r),tC*i+gC*n+IC*C);c2+=r,m2+=r*(tC+(tC=i)),f2+=r*(gC+(gC=n)),p2+=r*(IC+(IC=C)),mw(tC,gC,IC)}function Zae(){$o.point=y4}function LFt(){$o.point=QFt}function UFt(){mWe(dWe,hWe),$o.point=y4}function QFt(e,g){dWe=e,hWe=g,e*=Ot,g*=Ot,$o.point=mWe;var I=Tt(g);tC=I*Tt(e),gC=I*Bt(e),IC=Bt(g),mw(tC,gC,IC)}function mWe(e,g){e*=Ot,g*=Ot;var I=Tt(g),i=I*Tt(e),n=I*Bt(e),C=Bt(g),r=gC*C-IC*n,o=IC*i-tC*C,a=tC*n-gC*i,s=mJ(r,o,a),A=cC(s),l=s&&-A/s;GJ.add(l*r),vJ.add(l*o),BJ.add(l*a),c2+=A,m2+=A*(tC+(tC=i)),f2+=A*(gC+(gC=n)),p2+=A*(IC+(IC=C)),mw(tC,gC,IC)}function jFt(e){nG=c2=u2=d2=h2=m2=f2=p2=0,GJ=new Yi,vJ=new Yi,BJ=new Yi,Lo(e,$o);var g=+GJ,I=+vJ,i=+BJ,n=mJ(g,I,i);return n<$B&&(g=m2,I=f2,i=p2,c2og?e+Math.round(-e/sC)*sC:e,g]}wJ.invert=wJ;function Z4(e,g,I){return(e%=sC)?g||I?SJ(vae(e),Bae(g,I)):vae(e):g||I?Bae(g,I):wJ}function Gae(e){return function(g,I){return g+=e,[g>og?g-sC:g<-og?g+sC:g,I]}}function vae(e){var g=Gae(e);return g.invert=Gae(-e),g}function Bae(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[lC(l*n-u*C,A*I-c*i),cC(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[lC(l*n+c*C,A*I+u*i),cC(u*I-A*i)]},r}function fWe(e){e=Z4(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]*=tI,I[1]*=tI,I}return g.invert=function(I){return I=e.invert(I[0]*Ot,I[1]*Ot),I[0]*=tI,I[1]*=tI,I},g}function pWe(e,g,I,i,n,C){if(I){var r=Tt(g),o=Bt(g),a=i*I;n==null?(n=g+i*sC,C=g-a/2):(n=Sae(r,n),C=Sae(r,C),(i>0?nC)&&(n+=i*sC));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 ZW(e,g){return Vg(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 wae(e){if(g=e.length){for(var g,I=0,i=e[0],n;++I=0?1:-1,V=w*v,S=V>og,X=m*B;if(a.add(lC(X*w*Bt(V),f*G+X*Tt(V))),r+=S?v+w*sC:v,S^d>=I^y>=I){var W=o0(Nh(u),Nh(p));l2(W);var R=o0(C,W);l2(R);var H=(S^v>=0?-1:1)*cC(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(qFt))}}return c}}function qFt(e){return e.length>1}function eEt(e,g){return((e=e.x)[0]<0?e[1]-QI-zt:QI-e[1])-((g=g.x)[0]<0?g[1]-QI-zt:QI-g[1])}const VJ=GWe(function(){return!0},tEt,IEt,[-og,-QI]);function tEt(e){var g=NaN,I=NaN,i=NaN,n;return{lineStart:function(){e.lineStart(),n=1},point:function(C,r){var o=C>0?og:-og,a=Vg(C-g);Vg(a-og)0?QI:-QI),e.point(i,I),e.lineEnd(),e.lineStart(),e.point(o,I),e.point(C,I),n=0):i!==o&&a>=og&&(Vg(g-i)zt?oy((Bt(g)*(C=Tt(i))*Bt(I)-Bt(i)*(n=Tt(g))*Bt(e))/(n*C*r)):(g+i)/2}function IEt(e,g,I,i){var n;if(e==null)n=I*QI,i.point(-og,n),i.point(0,n),i.point(og,n),i.point(og,0),i.point(og,-n),i.point(0,-n),i.point(-og,-n),i.point(-og,0),i.point(-og,n);else if(Vg(e[0]-g[0])>zt){var C=e[0]0,n=Vg(g)>zt;function C(A,l,c,u){pWe(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?og:-og),f):0;if(!l&&(d=u=y)&&A.lineStart(),y!==u&&(p=a(l,b),(!p||ZW(l,p)||ZW(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||!ZW(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=Nh(A),d=Nh(l),h=[1,0,0],m=o0(u,d),f=KR(m,m),b=m[0],p=f-b*b;if(!p)return!c&&A;var y=g*f/p,Z=-g*b/p,B=o0(h,m),G=xR(h,y),v=xR(m,Z);qD(G,v);var w=B,V=KR(G,w),S=KR(w,w),X=V*V-S*(KR(G,G)-1);if(!(X<0)){var W=ji(X),R=xR(w,(-V-W)/S);if(qD(R,G),R=s2(R),!c)return R;var H=A[0],Y=l[0],K=A[1],F=l[1],J;Y0^R[1]<(Vg(R[0]-H)og^(H<=R[0]&&R[0]<=Y)){var $=xR(w,(-V+W)/S);return qD($,G),[R,s2($)]}}}function s(A,l){var c=i?e:og-e,u=0;return A<-c?u|=1:A>c&&(u|=2),l<-c?u|=4:l>c&&(u|=8),u}return GWe(r,o,C,i?[0,-e]:[-og,e-og])}function iEt(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 CG=1e9,FR=-CG;function Xk(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 Vg(s[0]-e)0?0:3:Vg(s[0]-I)0?2:1:Vg(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=bWe(),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,K=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,K=(c=T7(c)).length;(Y||K)&&(s.polygonStart(),Y&&(s.lineStart(),C(null,null,1,s),s.lineEnd()),K&&yWe(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 K=n(H,Y);if(u&&d.push([H,Y]),Z)h=H,m=Y,f=K,Z=!1,K&&(A.lineStart(),A.point(H,Y));else if(K&&y)A.point(H,Y);else{var F=[b=Math.max(FR,Math.min(CG,b)),p=Math.max(FR,Math.min(CG,p))],J=[H=Math.max(FR,Math.min(CG,H)),Y=Math.max(FR,Math.min(CG,Y))];iEt(F,J,e,g,I,i)?(y||(A.lineStart(),A.point(F[0],F[1])),A.point(J[0],J[1]),K||A.lineEnd(),B=!1):K&&(A.lineStart(),A.point(H,Y),B=!1)}b=H,p=Y,y=K}return G}}function nEt(){var e=0,g=0,I=960,i=500,n,C,r;return r={stream:function(o){return n&&C===o?n:n=Xk(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 RJ,WJ,GW,vW,a0={sphere:FI,point:FI,lineStart:CEt,lineEnd:FI,polygonStart:FI,polygonEnd:FI};function CEt(){a0.point=oEt,a0.lineEnd=rEt}function rEt(){a0.point=a0.lineEnd=FI}function oEt(e,g){e*=Ot,g*=Ot,WJ=e,GW=Bt(g),vW=Tt(g),a0.point=aEt}function aEt(e,g){e*=Ot,g*=Ot;var I=Bt(g),i=Tt(g),n=Vg(e-WJ),C=Tt(n),r=Bt(n),o=i*r,a=vW*I-GW*i*C,s=GW*I+vW*i*C;RJ.add(lC(ji(o*o+a*a),s)),WJ=e,GW=I,vW=i}function BWe(e){return RJ=new Yi,Lo(e,a0),+RJ}var XJ=[null,null],AEt={type:"LineString",coordinates:XJ};function b2(e,g){return XJ[0]=e,XJ[1]=g,BWe(AEt)}var Vae={Feature:function(e,g){return y2(e.geometry,g)},FeatureCollection:function(e,g){for(var I=e.features,i=-1,n=I.length;++i0&&(n=b2(e[C],e[C-1]),n>0&&I<=n&&i<=n&&(I+i-n)*(1-Math.pow((I-i)/n,2))<$B*n))return!0;I=i}return!1}function Hae(e,g){return!!ZWe(e.map(sEt),SWe(g))}function sEt(e){return e=e.map(SWe),e.pop(),e}function SWe(e){return[e[0]*Ot,e[1]*Ot]}function lEt(e,g){return(e&&Vae.hasOwnProperty(e.type)?Vae[e.type]:y2)(e,g)}function Tae(e,g,I){var i=CC(e,g-zt,I).concat(g);return function(n){return i.map(function(C){return[n,C]})}}function Nae(e,g,I){var i=CC(e,g-zt,I).concat(g);return function(n){return i.map(function(C){return[C,n]})}}function wWe(){var e,g,I,i,n,C,r,o,a=10,s=a,A=90,l=360,c,u,d,h,m=2.5;function f(){return{type:"MultiLineString",coordinates:b()}}function b(){return CC(YR(i/A)*A,I,A).map(d).concat(CC(YR(o/l)*l,r,l).map(h)).concat(CC(YR(g/a)*a,e,a).filter(function(p){return Vg(p%A)>zt}).map(c)).concat(CC(YR(C/s)*s,n,s).filter(function(p){return Vg(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=Tae(C,n,90),u=Nae(g,e,m),d=Tae(o,r,90),h=Nae(i,I,m),f):m},f.extentMajor([[-180,-90+zt],[180,90-zt]]).extentMinor([[-180,-80-zt],[180,80+zt]])}function cEt(){return wWe()()}function uEt(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*cC(ji(uae(C-i)+r*a*uae(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[lC(Z,y)*tI,lC(B,ji(y*y+Z*Z))*tI]}:function(){return[I*tI,i*tI]};return m.distance=d,m}const qB=e=>e;var tF=new Yi,HJ=new Yi,VWe,RWe,TJ,NJ,ic={point:FI,lineStart:FI,lineEnd:FI,polygonStart:function(){ic.lineStart=dEt,ic.lineEnd=mEt},polygonEnd:function(){ic.lineStart=ic.lineEnd=ic.point=FI,tF.add(Vg(HJ)),HJ=new Yi},result:function(){var e=tF/2;return tF=new Yi,e}};function dEt(){ic.point=hEt}function hEt(e,g){ic.point=WWe,VWe=TJ=e,RWe=NJ=g}function WWe(e,g){HJ.add(NJ*e-TJ*g),TJ=e,NJ=g}function mEt(){WWe(VWe,RWe)}const kae=ic;var A0=1/0,Z2=A0,eS=-A0,G2=eS,fEt={point:pEt,lineStart:FI,lineEnd:FI,polygonStart:FI,polygonEnd:FI,result:function(){var e=[[A0,Z2],[eS,G2]];return eS=G2=-(Z2=A0=1/0),e}};function pEt(e,g){eeS&&(eS=e),gG2&&(G2=g)}const v2=fEt;var kJ=0,YJ=0,rG=0,B2=0,S2=0,lp=0,KJ=0,xJ=0,oG=0,XWe,HWe,tA,gA,Uo={point:kh,lineStart:Yae,lineEnd:Kae,polygonStart:function(){Uo.lineStart=ZEt,Uo.lineEnd=GEt},polygonEnd:function(){Uo.point=kh,Uo.lineStart=Yae,Uo.lineEnd=Kae},result:function(){var e=oG?[KJ/oG,xJ/oG]:lp?[B2/lp,S2/lp]:rG?[kJ/rG,YJ/rG]:[NaN,NaN];return kJ=YJ=rG=B2=S2=lp=KJ=xJ=oG=0,e}};function kh(e,g){kJ+=e,YJ+=g,++rG}function Yae(){Uo.point=bEt}function bEt(e,g){Uo.point=yEt,kh(tA=e,gA=g)}function yEt(e,g){var I=e-tA,i=g-gA,n=ji(I*I+i*i);B2+=n*(tA+e)/2,S2+=n*(gA+g)/2,lp+=n,kh(tA=e,gA=g)}function Kae(){Uo.point=kh}function ZEt(){Uo.point=vEt}function GEt(){TWe(XWe,HWe)}function vEt(e,g){Uo.point=TWe,kh(XWe=tA=e,HWe=gA=g)}function TWe(e,g){var I=e-tA,i=g-gA,n=ji(I*I+i*i);B2+=n*(tA+e)/2,S2+=n*(gA+g)/2,lp+=n,n=gA*e-tA*g,KJ+=n*(tA+e),xJ+=n*(gA+g),oG+=n*3,kh(tA=e,gA=g)}const xae=Uo;function NWe(e){this._context=e}NWe.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,sC);break}}},result:FI};var DJ=new Yi,gF,kWe,YWe,aG,AG,w2={point:FI,lineStart:function(){w2.point=BEt},lineEnd:function(){gF&&KWe(kWe,YWe),w2.point=FI},polygonStart:function(){gF=!0},polygonEnd:function(){gF=null},result:function(){var e=+DJ;return DJ=new Yi,e}};function BEt(e,g){w2.point=KWe,kWe=aG=e,YWe=AG=g}function KWe(e,g){aG-=e,AG-=g,DJ.add(ji(aG*aG+AG*AG)),aG=e,AG=g}const Dae=w2;function xWe(){this._string=[]}xWe.prototype={_radius:4.5,_circle:Fae(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=Fae(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 Fae(e){return"m0,"+e+"a"+e+","+e+" 0 1,1 0,"+-2*e+"a"+e+","+e+" 0 1,1 0,"+2*e+"z"}function SEt(e,g){var I=4.5,i,n;function C(r){return r&&(typeof I=="function"&&n.pointRadius(+I.apply(this,arguments)),Lo(r,i(n))),n.result()}return C.area=function(r){return Lo(r,i(kae)),kae.result()},C.measure=function(r){return Lo(r,i(Dae)),Dae.result()},C.bounds=function(r){return Lo(r,i(v2)),v2.result()},C.centroid=function(r){return Lo(r,i(xae)),xae.result()},C.projection=function(r){return arguments.length?(i=r==null?(e=null,qB):(e=r).stream,C):e},C.context=function(r){return arguments.length?(n=r==null?(g=null,new xWe):new NWe(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 wEt(e){return{stream:fw(e)}}function fw(e){return function(g){var I=new FJ;for(var i in e)I[i]=e[i];return I.stream=g,I}}function FJ(){}FJ.prototype={constructor:FJ,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 G4(e,g,I){var i=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),i!=null&&e.clipExtent(null),Lo(I,e.stream(v2)),g(v2.result()),i!=null&&e.clipExtent(i),e}function Hk(e,g,I){return G4(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 v4(e,g,I){return Hk(e,[[0,0],g],I)}function B4(e,g,I){return G4(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 S4(e,g,I){return G4(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 Eae=16,VEt=Tt(30*Ot);function Mae(e,g){return+g?WEt(e,g):REt(e)}function REt(e){return fw({point:function(g,I){g=e(g,I),this.stream.point(g[0],g[1])}})}function WEt(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=ji(y*y+Z*Z+B*B),v=cC(B/=G),w=Vg(Vg(B)-1)g||Vg((f*W+b*R)/p-.5)>.3||r*c+o*u+a*d2?H[2]%360*Ot:0,W()):[o*tI,a*tI,s*tI]},S.angle=function(H){return arguments.length?(l=H%360*Ot,W()):l*tI},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=Mae(G,Z=H*H),R()):ji(Z)},S.fitExtent=function(H,Y){return Hk(S,H,Y)},S.fitSize=function(H,Y){return v4(S,H,Y)},S.fitWidth=function(H,Y){return B4(S,H,Y)},S.fitHeight=function(H,Y){return S4(S,H,Y)};function W(){var H=zae(I,0,0,c,u,l).apply(null,g(C,r)),Y=zae(I,i-H[0],n-H[1],c,u,l);return A=Z4(o,a,s),G=SJ(g,Y),v=SJ(A,G),B=Mae(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 V4(e){var g=0,I=og/3,i=w4(e),n=i(g,I);return n.parallels=function(C){return arguments.length?i(g=C[0]*Ot,I=C[1]*Ot):[g*tI,I*tI]},n}function NEt(e){var g=Tt(e);function I(i,n){return[i*g,Bt(n)/g]}return I.invert=function(i,n){return[i/g,cC(n*g)]},I}function DWe(e,g){var I=Bt(e),i=(I+Bt(g))/2;if(Vg(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=kEt([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 Hk(A,c,u)},A.fitSize=function(c,u){return v4(A,c,u)},A.fitWidth=function(c,u){return B4(A,c,u)},A.fitHeight=function(c,u){return S4(A,c,u)};function l(){return e=g=null,A}return A.scale(1070)}function EWe(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 pw(e){return function(g,I){var i=ji(g*g+I*I),n=e(i),C=Bt(n),r=Tt(n);return[lC(g*C,i*r),cC(i&&I*C/i)]}}var R4=EWe(function(e){return ji(2/(1+e))});R4.invert=pw(function(e){return 2*cC(e/2)});function KEt(){return kA(R4).scale(124.75).clipAngle(180-.001)}var W4=EWe(function(e){return(e=rWe(e))&&e/Bt(e)});W4.invert=pw(function(e){return e});function xEt(){return kA(W4).scale(79.4188).clipAngle(180-.001)}function bw(e,g){return[e,r2(b4((QI+g)/2))]}bw.invert=function(e,g){return[e,2*oy(CWe(g))-QI]};function DEt(){return MWe(bw).scale(961/sC)}function MWe(e){var g=kA(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=og*i(),c=g(fWe(g.rotate()).invert([0,0]));return C(r==null?[[c[0]-l,c[1]-l],[c[0]+l,c[1]+l]]:e===bw?[[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 ER(e){return b4((QI+e)/2)}function zWe(e,g){var I=Tt(e),i=e===g?Bt(e):r2(I/Tt(g))/r2(ER(g)/ER(e)),n=I*$D(ER(e),i)/i;if(!i)return bw;function C(r,o){n>0?o<-QI+zt&&(o=-QI+zt):o>QI-zt&&(o=QI-zt);var a=n/$D(ER(o),i);return[a*Bt(i*r),n-a*Tt(i*r)]}return C.invert=function(r,o){var a=n-o,s=Ur(i)*ji(r*r+a*a),A=lC(r,Vg(a))*Ur(a);return a*i<0&&(A-=og*Ur(r)*Ur(a)),[A/i,2*oy($D(n/s,1/i))-QI]},C}function FEt(){return V4(zWe).scale(109.5).parallels([30,30])}function tS(e,g){return[e,g]}tS.invert=tS;function EEt(){return kA(tS).scale(152.63)}function PWe(e,g){var I=Tt(e),i=e===g?Bt(e):(I-Tt(g))/(g-e),n=I/i+e;if(Vg(i)zt&&--i>0);return[e/(.8707+(C=I*I)*(-.131979+C*(-.013791+C*C*C*(.003971-.001529*C)))),I]};function _Et(){return kA(T4).scale(175.295)}function N4(e,g){return[Tt(g)*Bt(e),Bt(g)]}N4.invert=pw(cC);function LEt(){return kA(N4).scale(249.5).clipAngle(90+zt)}function k4(e,g){var I=Tt(g),i=1+Tt(e)*I;return[I*Bt(e)/i,Bt(g)/i]}k4.invert=pw(function(e){return 2*oy(e)});function UEt(){return kA(k4).scale(250).clipAngle(142)}function Y4(e,g){return[r2(b4((QI+g)/2)),-e]}Y4.invert=function(e,g){return[-g,2*oy(CWe(e))-QI]};function QEt(){var e=MWe(Y4),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 jEt=Object.freeze(Object.defineProperty({__proto__:null,geoAlbers:FWe,geoAlbersUsa:YEt,geoArea:EFt,geoAzimuthalEqualArea:KEt,geoAzimuthalEqualAreaRaw:R4,geoAzimuthalEquidistant:xEt,geoAzimuthalEquidistantRaw:W4,geoBounds:JFt,geoCentroid:jFt,geoCircle:$Ft,geoClipAntimeridian:VJ,geoClipCircle:vWe,geoClipExtent:nEt,geoClipRectangle:Xk,geoConicConformal:FEt,geoConicConformalRaw:zWe,geoConicEqualArea:V2,geoConicEqualAreaRaw:DWe,geoConicEquidistant:MEt,geoConicEquidistantRaw:PWe,geoContains:lEt,geoDistance:b2,geoEqualEarth:PEt,geoEqualEarthRaw:X4,geoEquirectangular:EEt,geoEquirectangularRaw:tS,geoGnomonic:JEt,geoGnomonicRaw:H4,geoGraticule:wWe,geoGraticule10:cEt,geoIdentity:OEt,geoInterpolate:uEt,geoLength:BWe,geoMercator:DEt,geoMercatorRaw:bw,geoNaturalEarth1:_Et,geoNaturalEarth1Raw:T4,geoOrthographic:LEt,geoOrthographicRaw:N4,geoPath:SEt,geoProjection:kA,geoProjectionMutator:w4,geoRotation:fWe,geoStereographic:UEt,geoStereographicRaw:k4,geoStream:Lo,geoTransform:wEt,geoTransverseMercator:QEt,geoTransverseMercatorRaw:Y4},Symbol.toStringTag,{value:"Module"}));var $Et=[].slice,qEt={};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=OWe.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=$Et.call(arguments,1);return g.push(e),++this._waiting,this._tasks.push(g),JWe(this),this},abort:function(){return this._error==null&&K4(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))},W2(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,W2(this),this}};function JWe(e){if(!e._start)try{eMt(e)}catch(g){if(e._tasks[e._ended+e._active-1])K4(e,g);else if(!e._data)throw g}}function eMt(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,W2(e)}function W2(e){if(!e._active&&e._call){var g=e._data;e._data=void 0,e._call(e._error,g)}}function OWe(e){if(e==null)e=1/0;else if(!((e=+e)>=1))throw new Error("invalid concurrency");return new EJ(e)}const gMt=Object.freeze(Object.defineProperty({__proto__:null,queue:OWe},Symbol.toStringTag,{value:"Module"}));var Sr="$";function X2(){}X2.prototype=x4.prototype={constructor:X2,has:function(e){return Sr+e in this},get:function(e){return this[Sr+e]},set:function(e,g){return this[Sr+e]=g,this},remove:function(e){var g=Sr+e;return g in this&&delete this[g]},clear:function(){for(var e in this)e[0]===Sr&&delete this[e]},keys:function(){var e=[];for(var g in this)g[0]===Sr&&e.push(g.slice(1));return e},values:function(){var e=[];for(var g in this)g[0]===Sr&&e.push(this[g]);return e},entries:function(){var e=[];for(var g in this)g[0]===Sr&&e.push({key:g.slice(1),value:this[g]});return e},size:function(){var e=0;for(var g in this)g[0]===Sr&&++e;return e},empty:function(){for(var e in this)if(e[0]===Sr)return!1;return!0},each:function(e){for(var g in this)g[0]===Sr&&e(this[g],g.slice(1),this)}};function x4(e,g){var I=new X2;if(e instanceof X2)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}})}BW.prototype=_We.prototype={constructor:BW,on:function(e,g){var I=this._,i=iMt(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&&rMt(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=CMt(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 CMt(e){return function(g,I){e(g==null?I:null)}}function rMt(e){var g=e.responseType;return g&&g!=="text"?e.response:e.responseText}function Tk(e,g){return function(I,i){var n=D4(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 oMt=Tk("text/html",function(e){return document.createRange().createContextualFragment(e.responseText)}),aMt=Tk("application/json",function(e){return JSON.parse(e.responseText)}),AMt=Tk("text/plain",function(e){return e.responseText}),sMt=Tk("application/xml",function(e){var g=e.responseXML;if(!g)throw new Error("parse error");return g});var Oae={},IF={},iF=34,dZ=10,nF=13;function LWe(e){return new Function("d","return {"+e.map(function(g,I){return JSON.stringify(g)+": d["+I+'] || ""'}).join(",")+"}")}function lMt(e,g){var I=LWe(e);return function(i,n){return g(I(i),n,e)}}function _ae(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 wC(e,g){var I=e+"",i=I.length;return i9999?"+"+wC(e,6):wC(e,4)}function uMt(e){var g=e.getUTCHours(),I=e.getUTCMinutes(),i=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":cMt(e.getUTCFullYear())+"-"+wC(e.getUTCMonth()+1,2)+"-"+wC(e.getUTCDate(),2)+(n?"T"+wC(g,2)+":"+wC(I,2)+":"+wC(i,2)+"."+wC(n,3)+"Z":i?"T"+wC(g,2)+":"+wC(I,2)+":"+wC(i,2)+"Z":I||g?"T"+wC(g,2)+":"+wC(I,2)+"Z":"")}function UWe(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?lMt(m,c):LWe(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)===dZ&&--d,l.charCodeAt(d-1)===nF&&--d;function y(){if(b)return IF;if(p)return p=!1,Oae;var B,G=h,v;if(l.charCodeAt(G)===iF){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===dZ?p=!0:v===nF&&(p=!0,l.charCodeAt(h)===dZ&&++h),l.slice(G+1,B-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",qD),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)`),C.appendChild(a)}),[r,r]}}]),i}(ny);function WKt(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 ys(e){return ys=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},ys(e)}function Joe(e,g,i,I,n,r,C,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&&bC&&f.yC&&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 k1e=function(e){kKt(i,e);var g=YKt(i);function i(...I){var n;WKt(this,i),n=g.call(this,...I),n.drawnRects={};const{publish:r,subscribe:C,unsubscribe:o}=vN();return n.publish=r,n.subscribe=C,n.unsubscribe=o,n}return XKt(i,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const r=n.split(".");return r.slice(0,r.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=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]);let C=Math.max(n,r);return C=Math.min(C,this.maxZoom),C}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r)})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.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,r=this.yTiles,C=this.zoomLevel,o=[];for(let a=0;a!(d.uid in this.drawnRects)).forEach(d=>{Joe(this,r,d,a,A,l,c,u,s,this.options.flipDiagonal==="yes"),this.options.flipDiagonal&&this.options.flipDiagonal==="copy"&&Joe(this,r,d,a,A,l,c,u,s,!0)})}},{key:"exportSVG",value:function(){let n=null,r=null;md(ys(i.prototype),"exportSVG",this)?[r,n]=md(ys(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(C);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})`),C.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[r,r]}},{key:"setPosition",value:function(n){md(ys(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,r){this.xScale().domain()[0]===n.domain()[0]&&this.xScale().domain()[1]===n.domain()[1]&&this.yScale().domain()[0]===r.domain()[0]&&this.yScale().domain()[1]===r.domain()[1]||(this.xScale(n),this.yScale(r),this.refreshTiles(),this.draw())}},{key:"leftTrackDraw",value:function(){this.draw()}}]),i}(hm);function xKt(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 Zs(e){return Zs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Zs(e)}const UKt=250;let K1e=function(e){JKt(i,e);var g=OKt(i);function i(I,n){var r;xKt(this,i),r=g.call(this,I,n);const{pubSub:C}=I;r.drawnAnnotations={},r.drawnAnnoGfx={},r.selectedAnno=null,r.options.minSquareSize=+r.options.minSquareSize;const{publish:o,subscribe:a,unsubscribe:s}=vN();return r.publish=o,r.subscribe=a,r.unsubscribe=s,r.sT=0,r.annoSelectedBound=r.annoSelected.bind(Y1e(r)),r.pubSubs.push(C.subscribe("annoSelected",r.annoSelectedBound)),r}return EKt(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,r]){return[this._xScale(n),this._yScale(r)]}},{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const r=n.split(".");return r.slice(0,r.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.minX,this.maxX),r=vt.calculateZoomLevel(this._yScale,this.minY,this.maxY);return $Ge(dz(n,r),this.maxZoom)}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r)})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.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,r=[];for(let C=0;C!(a.uid in this.drawnAnnotations)||r).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),C)})}},{key:"prepAnnotation",value:function(n,r,C,o,a,s,A){let l;try{l=JSON.parse(A.fields)}catch{}return{graphics:n,id:A.id,uid:r,annotation:{x:C,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:r,uid:C,annotation:o,dataPos:a,importance:s,info:A},l){this.options.minSquareSize&&(o.widththis.hover(u,c,C),u.mouseout=()=>this.blur(u,c,C),u.mousedown=()=>this.mouseDown(),u.mouseup=h=>this.mouseUp(u,c,C,h,d),l||this.publish("annotationDrawn",{trackUuids:this.uuid,annotationUuid:C,annotationId:r,viewPos:c,dataPos:a,importance:s,info:A})}},{key:"_drawRect",value:function(n,r,C){let o=this.options.rectangleDomainStrokeColor,a=this.options.rectangleDomainStrokeWidth,s=this.options.rectangleDomainStrokeOpacity,A=this.options.rectangleDomainFillColor,l=this.options.rectangleDomainFillOpacity;this.hoveredAnno===C&&(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===C&&(o=this.options.selectColor,a=this.options.rectangleDomainStrokeWidth+1||2,s=1,A=this.options.selectColor,l=dz(.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(...r)),this.setBorderStyle(n,o,a,s),this.setFill(n,A,l),n.drawRect(...r),n.__viewPos__=r}},{key:"context",value:function(n,r,C){return o=>o(n,r,C)}},{key:"click",value:function(n,r,C,o,a){this.select(n,r,C),this.pubSub.publish("app.click",{type:"annotation",event:o,payload:a})}},{key:"mouseDown",value:function(){this.sT=performance.now()}},{key:"mouseUp",value:function(n,r,C,o,a){performance.now()-this.sT<=UKt&&this.click(n,r,C,o,a)}},{key:"hover",value:function(n,r,C){this.hoveredAnno=C,this._drawRect(n,r,C),this.animate()}},{key:"focus",value:function(n,r,C){this._drawRect(n,r,C),this.animate()}},{key:"blur",value:function(n,r,C){this.hoveredAnno=null,this._drawRect(n,r,C),this.animate()}},{key:"select",value:function(n,r,C,o=!1){let a=null,s=null;this.selectedAnno&&(a=this.selectedAnno.graphics,s=this.selectedAnno.uid),this.selectedAnno={graphics:n,uid:C},this.focus(n,r,C),this.options.onSelect&&!o&&(window[this.options.onSelect](C),this.pubSub.publish("annoSelected",C)),a&&s&&this.blur(a,a.__viewPos__,s)}},{key:"unselect",value:function(){const n=this.selectedAnno.graphics,r=this.selectedAnno.uid;this.selectedAnno=null,this.blur(n,n.__viewPos__,r)}},{key:"annoSelected",value:function(n){if(!this.selectedAnno||this.selectedAnno.uid!==n){this.selectedAnno&&this.unselect();const r=this.drawnAnnoGfx[n];r&&this.select(r,r.__viewPos__,n,!0)}}},{key:"exportSVG",value:function(){let n=null,r=null;fd(Zs(i.prototype),"exportSVG",this)?[r,n]=fd(Zs(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r);const C=document.createElement("g");return C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),n.appendChild(C),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})`),C.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)}}),[r,r]}},{key:"setBorderStyle",value:function(n,r=this.options.rectangleDomainStrokeColor,C=this.options.rectangleDomainStrokeWidth,o=this.options.rectangleDomainStrokeOpacity){n.lineStyle(typeof C<"u"?C:1,Kt(r||"black"),typeof o<"u"?o:1)}},{key:"setFill",value:function(n,r=this.options.rectangleDomainFillColor,C=this.options.rectangleDomainFillOpacity){n.beginFill(Kt(r||"grey"),typeof C<"u"?C:.4)}},{key:"setPosition",value:function(n){fd(Zs(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,r){this.xScale(n),this.yScale(r),this.refreshTiles(),this.draw()}}]),i}(hm);function QKt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function _oe(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 Sh(e){return Sh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Sh(e)}let QP=function(e){t5t(i,e);var g=g5t(i);function i(I,n,r){var C;return QKt(this,i),C=g.call(this,I,n),C.pubSub=I.pubSub,C.options=n,C.isVertical=r,C.rects={},C.defaultColor=HI("red"),C}return jKt(i,[{key:"draw",value:function(){const n=typeof this.options.minRectWidth<"u"?this.options.minRectWidth:10,r=typeof this.options.fill<"u"?HI(this.options.fill):this.defaultColor,C=typeof this.options.fillOpacity<"u"?+this.options.fillOpacity:.2,o=typeof this.options.stroke<"u"?HI(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]),bv(Sh(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 ot.PIXI.Graphics},l.addChild(this.rects[d].graphics)),this.rects[d].timeStamp=c;const h=HI(u[2])||r;let m=HI(u[3])||o;m||(m=h);const f=ot.PIXI.utils.rgb2hex([h.r/255,h.g/255,h.b/255]),b=ot.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]||C));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]||C),this.isVertical?(l.drawRect(0,y,this.dimensions[0],B),this.rects[d].graphics.hitArea=new ot.PIXI.Rectangle(0,y,this.dimensions[0],B)):(l.drawRect(y,0,B,this.dimensions[1]),this.rects[d].graphics.hitArea=new ot.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){bv(Sh(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,r){this.xScale(n),this.yScale(r),this.draw()}}]),i}(mr);function r5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Loe(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 F1e=function(e){s5t(i,e);var g=l5t(i);function i(I,n){var r;return r5t(this,i),r=g.call(this,I,n),r.drawnRects=new Set,r.pMain=r.pMobile,r}return C5t(i,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const r=n.split(".");return r.slice(0,r.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=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]);let C=Math.max(n,r);return C=Math.min(C,this.maxZoom),this.options&&this.options.maxZoom&&(this.options.maxZoom>=0?C=Math.min(this.options.maxZoom,C):console.error("Invalid maxZoom on track:",this)),C}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r)})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.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 r=this.xTiles,C=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,A=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,r[l],C[c]];d.mirrored=!1,A.push(d)}this.setVisibleTiles(A)}},{key:"initTile",value:function(n){tc($a(i.prototype),"initTile",this).call(this,n),this.drawTile(n)}},{key:"destroyTile",value:function(n,r){}},{key:"draw",value:function(){this.delayDrawing||this.drawnRects.clear(),tc($a(i.prototype),"draw",this).call(this)}},{key:"drawTile",value:function(n){if(!n.graphics)return;const r=n.graphics;r.clear();const C=Kt(this.options.rectangleDomainStrokeColor?this.options.rectangleDomainStrokeColor:"black"),o=Kt(this.options.rectangleDomainFillColor?this.options.rectangleDomainFillColor:"grey");if(r.lineStyle(1/this.pMain.scale.x,C,1),r.beginFill(o,.4),r.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),r.drawRect(s,l,A-s,c-l),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)}}},{key:"setPosition",value:function(n){tc($a(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,r){tc($a(i.prototype),"refScalesChanged",this).call(this,n,r);for(const C in this.fetchedTiles){const o=this.fetchedTiles[C];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,r,C,o,a){tc($a(i.prototype),"zoomed",this).call(this,n,r,C,o,a),this.pMain.position.x=o,this.pMain.position.y=this.position[1]+this.dimensions[1],this.pMain.scale.x=C,this.pMain.scale.y=C,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-C,this.pMain.position.y=this.position[1]),this.draw()}},{key:"leftTrackDraw",value:function(){this.draw()}}]),i}(hm);function h5t(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 wh(e){return wh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},wh(e)}let D1e=function(e){y5t(i,e);var g=Z5t(i);function i(I,n){var r;return h5t(this,i),r=g.call(this,I,n),r.drawnRects=new Set,r}return m5t(i,[{key:"tileToLocalId",value:function(n){return`${n.join(".")}`}},{key:"tileToRemoteId",value:function(n){return`${n.join(".")}`}},{key:"localToRemoteId",value:function(n){const r=n.split(".");return r.slice(0,r.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=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]);let C=Math.max(n,r);return C=Math.min(C,this.maxZoom),C}},{key:"setVisibleTiles",value:function(n){this.visibleTiles=n.map(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r)})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.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 r=this.xTiles,C=this.yTiles,o=this.zoomLevel,a=[];for(let s=0;sI.chrPositions?TI(n,I):null,I.chrToAbs=([n,r]=[])=>I.chrPositions?fX(n,r,I):null,vt.text(e,(n,r)=>{if(n)g&&g(null);else{const C=MQ(r),o=XN(C);Object.keys(o).forEach(a=>{I[a]=o[a]}),g&&g(I)}},i).then(()=>I)}function S5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Qoe(e,g){for(var i=0;ii.pos).left}return w5t(e,[{key:"scalesToPositionText",value:function(i,I,n=!1){if(this.chromInfo===null||!i||!I)return"";const r=TI(i.domain()[0],this.chromInfo),C=TI(i.domain()[1],this.chromInfo),o=TI(I.domain()[0],this.chromInfo),a=TI(I.domain()[1],this.chromInfo);let s=null;const A=uC(",d");return r[0]!==C[0]?s=`${r[0]}:${A(Math.floor(r[1]))}-${C[0]}:${A(Math.ceil(C[1]))}`:s=`${r[0]}:${A(Math.floor(r[1]))}-${A(Math.ceil(C[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]))}`),(r[2]<=0||C[2]>0||n&&(o[2]<=0||a[2]>0))&&(s+=` [offset ${r[2]},${C[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,r=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(".")&&(r=I.length-1-I.indexOf("."),I=(+I.replace(".","")).toString());const C=n-r;return C<0?i:(I+="0".repeat(C),I)}},{key:"parsePosition",value:function(i,I=null){const n=i.split(":");let r=null,C=0;n.length>1?(r=n[0],C=+this.convertNumberNotation(n[1].replace(/,/g,""))):n[0]in this.chromInfo.chrPositions?(r=n[0],C=0,I!==null&&(C=+this.chromInfo.chromLengths[r])):(C=+this.convertNumberNotation(n[0].replace(/,/g,"")),r=null,I&&(r=I));let o=null;return r===null?(r=I,o=C):r in this.chromInfo.chrPositions&&(o=this.chromInfo.chrPositions[r].pos+C),[r,C,o]}},{key:"matchRangesToLarger",value:function(i,I){if(i[1]-i[0]r.length>0);let n=null;if(I[0].indexOf("-")===0&&(I[0]=I[0].slice(3,I[0].length)),I.length>1){let[r,C,o]=this.parsePosition(I[0]),[a,s,A]=this.parsePosition(I[1],r);const l=[o,A];[r,C,o]=this.parsePosition(I[1]),[a,s,A]=this.parsePosition(I[0],r),r===null&&a!==null&&([r,C,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 r=+this.chromInfo.chrPositions[I[0]].pos;n=[r,r+ +this.chromInfo.chromLengths[I[0]]]}else{const[r,C,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 C=I[0].split(",");return[[+C[0],+C[1]],[0,0]]}const n=I[0].split(","),r=I[1].split(",");return[[+n[0],+n[1]],[+r[0],+r[1]]]}},{key:"searchPosition",value:function(i){let I=null,n=null;i=i.trim();const r=/\[offset (.+?)\]/.exec(i);let C=[[0,0],[0,0]];r&&(i=i.replace(r[0],""),C=this.parseOffset(r[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]+=C[0][0],I[1]+=C[0][1]),n&&(n[0]+=C[1][0],n[1]+=C[1][1]),[I,n]}}]),e}();function W5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function joe(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 r0(e){return r0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},r0(e)}let x1e=function(e){k5t(i,e);var g=Y5t(i);function i(I,n){var r;W5t(this,i),r=g.call(this,I,n);const{dataConfig:C,animate:o,pubSub:a}=I;r.searchField=null,r.chromInfo=null,r.animate=o;const s=C.server,A=C.tilesetUid,l=`${s}/chrom-sizes/?id=${A}`;return Js(l,c=>{r.chromInfo=c,r.searchField=new n0(r.chromInfo),r.draw(),r.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 r=[];r=n.map(C=>{const o=C.text;o.updateTransform();const a=o.getBounds();return[a.x,a.y,a.x+a.width,a.y+a.height]}),fw(r,(C,o)=>{n[C].importance>n[o].importance?n[o].text.visible=0:n[C].text.visible=0})}},{key:"setPosition",value:function(n){ZW(r0(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,r){this.xScale(n),this.yScale(r),this.draw()}}]),i}(mr);function x5t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $oe(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 kc(e){return kc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},kc(e)}let nG=function(e){J5t(i,e);var g=O5t(i);function i(I,n){var r;x5t(this,i),r=g.call(this,I,n);const{chromInfoPath:C,dataConfig:o,animate:a,pubSub:s,orientation:A="2d",isOverlay:l=!1}=I;r.searchField=null,r.chromInfo=null,r.animate=a,r.orientation=A,r.isOverlay=l;let c=C;return c||(c=`${o.server}/chrom-sizes/?id=${o.tilesetUid}`),Js(c,u=>{r.chromInfo=u,r.searchField=new n0(r.chromInfo),r.texts=[],r.lineGraphics=new ot.PIXI.Graphics,r.lineGraphics1dH=new ot.PIXI.Graphics,r.lineGraphics1dV=new ot.PIXI.Graphics,r.lineGraphics2d=new ot.PIXI.Graphics,r.mask1dH=new ot.PIXI.Graphics,r.mask1dV=new ot.PIXI.Graphics,r.mask2d=new ot.PIXI.Graphics,r.lineGraphics.addChild(r.lineGraphics1dH),r.lineGraphics1dH.addChild(r.mask1dH),r.lineGraphics.addChild(r.lineGraphics1dV),r.lineGraphics1dV.addChild(r.mask1dV),r.lineGraphics.addChild(r.lineGraphics2d),r.lineGraphics2d.addChild(r.mask2d),r.pMain.addChild(r.lineGraphics),r.draw(),r.animate()},s),r}return E5t(i,[{key:"drawLines",value:function(n=this.orientation,r=0,C=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)+r,C),o.lineTo(this._xScale(0)+r,this.dimensions[1]+C)),(n==="2d"||n==="1d-vertical")&&(o.moveTo(r,this._yScale(0)+C),o.lineTo(this.dimensions[0]+r,this._yScale(0)+C));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 Rh(e){return Rh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Rh(e)}const rFt=300;let E1e=function(e){tFt(i,e);var g=gFt(i);function i(I,n){var r;Q5t(this,i),r=g.call(this,I,n);const{chromInfoPath:C,pubSub:o}=I;return r.pubSub=o,r.rects={},Js(C,a=>{r.chromInfo=a,r.draw()},r.pubSub),r}return j5t(i,[{key:"draw",value:function(){if(!this.chromInfo)return;const n=this.options.minRectWidth?this.options.minRectWidth:10,r=this.options.minRectWidth?this.options.minRectHeight:10;Zv(Rh(i.prototype),"draw",this).call(this);const C=this.pMain;C.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 ot.PIXI.Graphics},C.addChild(this.rects[s].graphics)),this.rects[s].timeStamp=o;const A=HI(a[6]);let l=HI(a[7]);l||(l=A);const c=ot.PIXI.utils.rgb2hex([A.r/255,A.g/255,A.b/255]),u=ot.PIXI.utils.rgb2hex([l.r/255,l.g/255,l.b/255]);C.lineStyle(1,u,l.opacity),C.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]:r;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 Gs(e){return Gs=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Gs(e)}const hFt=200,mFt=6,fFt=2,tae=7829367;let z1e=function(e){lFt(i,e);var g=cFt(i);function i(I,n){var r;CFt(this,i),r=g.call(this,I,n);const{dataConfig:C,animate:o,chromInfoPath:a,isShowGlobalMousePosition:s}=I;r.searchField=null,r.chromInfo=null,r.dataConfig=C,r.pTicks=new ot.PIXI.Graphics,r.pMain.addChild(r.pTicks),r.gTicks={},r.tickTexts={},r.options=n,r.isShowGlobalMousePosition=s,r.textFontSize=12,r.textFontFamily="Arial",r.textFontColor="#808080",r.textStrokeColor=r.getTheme()===gi?"#000000":"#ffffff",r.pixiTextConfig={fontSize:+r.options.fontSize?`${+r.options.fontSize}px`:`${r.textFontSize}px`,fontFamily:r.textFontFamily,fill:r.options.color||r.textFontColor,lineJoin:"round",stroke:r.options.stroke||r.textStrokeColor,strokeThickness:2},r.stroke=Kt(r.pixiTextConfig.stroke),r.tickWidth=hFt,r.tickHeight=mFt,r.tickTextSeparation=fFt,r.tickColor=r.options.tickColor?Kt(r.options.tickColor):tae,r.animate=o,r.pubSubs=[],r.options.showMousePosition&&!r.hideMousePosition&&(r.hideMousePosition=Ah(M1e(r),r.is2d,r.isShowGlobalMousePosition()));let A=a;return A||(A=`${C.server}/chrom-sizes/?id=${C.tilesetUid}`),Js(A,l=>{r.chromInfo=l,r.searchField=new n0(r.chromInfo),r.rerender(r.options,!0),r.draw(),r.animate()},r.pubSub),r}return oFt(i,[{key:"initBoundsTicks",value:function(){this.pTicks&&(this.pMain.removeChild(this.pTicks),this.pTicks=null),this.gBoundTicks||(this.gBoundTicks=new ot.PIXI.Graphics,this.leftBoundTick=new ot.PIXI.Text("",this.pixiTextConfig),this.rightBoundTick=new ot.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 ot.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{C.updateTransform();const a=C.getBounds();return[a.x,a.y,a.x+a.width,a.y+a.height]}),fw(r,(C,o)=>{n[C].importance>n[o].importance?n[o].text.visible=!1:n[C].text.visible=!1})}},{key:"setPosition",value:function(n){pd(Gs(i.prototype),"setPosition",this).call(this,n),[this.pMain.position.x,this.pMain.position.y]=this.position}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"exportSVG",value:function(){let n=null,r=null;pd(Gs(i.prototype),"exportSVG",this)?[r,n]=pd(Gs(i.prototype),"exportSVG",this).call(this):(r=document.createElement("g"),n=r),r.setAttribute("class","chromosome-labels");const C=document.createElement("g");return n.appendChild(C),C.setAttribute("transform",`translate(${this.position[0]},${this.position[1]})`),this.allTexts.filter(o=>o.text.visible).forEach(o=>{const a=fz(o.text);C.appendChild(a)}),Object.values(this.tickTexts).forEach(o=>{o.filter(a=>a.visible).forEach(a=>{let s=fz(a);C.appendChild(s),s=nve(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"),C.appendChild(s),C.appendChild(A)})}),[r,n]}}]),i}(mr);function pFt(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 qa(e){return qa=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},qa(e)}let P1e=function(e){vFt(i,e);var g=BFt(i);function i(I,n){var r;pFt(this,i),r=g.call(this,I,n);const{animate:C}=I;return r.pMain=r.pMobile,r.colorScale=Nb,r.continuousScaling=!1,n&&n.colorRange&&(r.colorScale=Oc(n.colorRange)),r.animate=C,r.options=n,r.pubSubs=[],r}return bFt(i,[{key:"rerender",value:function(n,r){gc(qa(i.prototype),"rerender",this).call(this,n,r),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 r=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]),C=vt.calculateZoomLevelFromResolutions(this.tilesetInfo.resolutions,this._xScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1]);n=Math.min(r,C)}else{const r=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]);n=Math.max(r,C),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 r=this.xTiles,C=this.yTiles,o=this.zoomLevel,s=this.tilesetInfo.max_width/2**o,A=[];for(let l=0;lthis.dimensions[1])continue;const d=[o,r[l],C[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 r=document.createElement("canvas");r.width=256,r.height=256;const C=r.getContext("2d");C.fillStyle="transparent",C.fillRect(0,0,r.width,r.height);const o=new ImageData(n,r.width,r.height);return C.putImageData(o,0,0),r}},{key:"setSpriteProperties",value:function(n,r,C,o){const{tileX:a,tileY:s,tileWidth:A,tileHeight:l}=this.getTilePosAndDimensions(r,C),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,r){if(r){const C=n.graphics,o=this.tileDataToCanvas(r.pixData),a=ot.PIXI.VERSION[0]==="4"?ot.PIXI.Texture.fromCanvas(o,ot.PIXI.SCALE_MODES.NEAREST):ot.PIXI.Texture.from(o,{scaleMode:ot.PIXI.SCALE_MODES.NEAREST});n.sprite=new ot.PIXI.Sprite(a),n.canvas=o,this.setSpriteProperties(n.sprite,n.tileData.zoomLevel,n.tileData.tilePos,n.mirrored),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,C.removeChildren(),C.addChild(n.sprite)}this.renderingTiles.delete(n.tileId)}},{key:"refScalesChanged",value:function(n,r){gc(qa(i.prototype),"refScalesChanged",this).call(this,n,r);for(const C in this.fetchedTiles){const o=this.fetchedTiles[C];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,r,C,o,a){gc(qa(i.prototype),"zoomed",this).call(this,n,r,C,o,a),gc(qa(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=C,this.pMain.scale.y=C,this.options.oneDHeatmapFlipped&&(this.pMain.scale.y=-C,this.pMain.position.y=this.position[1])}},{key:"leftTrackDraw",value:function(){this.draw()}},{key:"exportSVG",value:function(){let n=null,r=null;[r,n]=gc(qa(i.prototype),"superSVG",this).call(this);const C=document.createElement("g");n.appendChild(C),C.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),C.appendChild(s)}const o=this.exportColorBarSVG();return n.appendChild(o),[r,r]}}]),i}(mw);function VFt(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 r2(e){return r2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},r2(e)}let Iae=function(e){TFt(i,e);var g=NFt(i);function i(I,n){var r;return VFt(this,i),r=g.call(this,I,n),r.tilesetInfo={},r.errorTextText=`Unknown track type: ${n.type}`,r}return WFt(i,[{key:"zoomed",value:function(){this.draw()}}]),i}(mr);function FFt(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 C2(e){return C2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},C2(e)}let O1e=function(e){MFt(i,e);var g=zFt(i);function i(I,n){var r;return FFt(this,i),r=g.call(this,I,n),r.axis=new Zk(J1e(r)),r.pBase.addChild(r.axis.pAxis),r}return DFt(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 r=n.graphics,C=6,o=4;r.clear(),this.valueScale=ru().domain([this.minValue()+.01,this.maxValue()]).range([this.dimensions[1]-C/2,C/2]);const a=Kt("black");r.lineStyle(1,a,.3),r.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;r.drawRect(p-f/2,b-C/2,f,C)})}},{key:"minVisibleValueInTiles",value:function(){let n=this.visibleAndFetchedIds();return n.length===0&&(n=Object.keys(this.fetchedTiles)),Math.min.apply(null,n.map(C=>+Math.min(...this.fetchedTiles[C].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(C=>+Math.max(...this.fetchedTiles[C].tileData.filter(o=>!Number.isNaN(o.fields[3])).map(o=>+o.fields[3]))))}}]),i}(Cy);function OFt(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 Yc(e){return Yc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Yc(e)}let _1e=function(e){jFt(i,e);var g=$Ft(i);function i(I,n){var r;OFt(this,i),r=g.call(this,I,n);const{registerViewportChanged:C,removeViewportChanged:o,setDomainsCallback:a}=I,s=sg.nice();return r.uid=s,r.options=n,r.hasFromView=!I.projectionXDomain||!I.projectionYDomain,r.removeViewportChanged=o,r.setDomainsCallback=a,r.viewportXDomain=r.hasFromView?null:I.projectionXDomain,r.viewportYDomain=r.hasFromView?null:I.projectionYDomain,r.brush=XQ().on("brush",r.brushed.bind(CJ(r))),r.gBrush=r.gMain.append("g").attr("id",`brush-${r.uid}`).call(r.brush),r.gBrush.selectAll(".overlay").style("pointer-events","none"),r.gBrush.selectAll(".handle--n").style("pointer-events","none"),r.gBrush.selectAll(".handle--s").style("pointer-events","none"),r.gBrush.selectAll(".handle--w").style("pointer-events","none"),r.gBrush.selectAll(".handle--e").style("pointer-events","none"),C(s,r.viewportChanged.bind(CJ(r))),r.rerender(),r.draw(),r}return _Ft(i,[{key:"brushed",value:function(n){const r=n.selection;if(!this._xScale||!this._yScale)return;const C=[this._xScale.invert(r[0][0]),this._xScale.invert(r[1][0])],o=[this._yScale.invert(r[0][1]),this._yScale.invert(r[1][1])];this.hasFromView||(this.viewportXDomain=C,this.viewportYDomain=o),this.setDomainsCallback(C,o)}},{key:"viewportChanged",value:function(n,r){const C=n.domain(),o=r.domain();this.viewportXDomain=C,this.viewportYDomain=o,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Lp(Yc(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]),r=this._yScale(this.viewportYDomain[0]),C=this._xScale(this.viewportXDomain[1]),o=this._yScale(this.viewportYDomain[1]),a=[[n,r],[C,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,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"setPosition",value:function(n){Lp(Yc(i.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Lp(Yc(i.prototype),"setDimensions",this).call(this,n);const r=this._xScale.range(),C=this._yScale.range(),o=r[1]-r[0],a=C[1]-C[0];this.brush.extent([[r[0]-o,C[0]-a],[r[1]+o,C[1]+a]]),this.gBrush.call(this.brush),this.draw()}}]),i}(mm);function tDt(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 Kc(e){return Kc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Kc(e)}let L1e=function(e){rDt(i,e);var g=CDt(i);function i(I,n){var r;tDt(this,i),r=g.call(this,I,n);const{registerViewportChanged:C,removeViewportChanged:o,setDomainsCallback:a}=I,s=sg.nice();return r.uid=s,r.options=n,r.hasFromView=!I.projectionXDomain,r.removeViewportChanged=o,r.setDomainsCallback=a,r.viewportXDomain=r.hasFromView?null:I.projectionXDomain,r.viewportYDomain=r.hasFromView?null:[0,0],r.brush=VN().on("brush",r.brushed.bind(aJ(r))),r.gBrush=r.gMain.append("g").attr("id",`brush-${r.uid}`).call(r.brush),r.gBrush.selectAll(".overlay").style("pointer-events","none"),r.gBrush.selectAll(".handle--ne").style("pointer-events","none"),r.gBrush.selectAll(".handle--nw").style("pointer-events","none"),r.gBrush.selectAll(".handle--sw").style("pointer-events","none"),r.gBrush.selectAll(".handle--se").style("pointer-events","none"),r.gBrush.selectAll(".handle--n").style("pointer-events","none"),r.gBrush.selectAll(".handle--s").style("pointer-events","none"),C(s,r.viewportChanged.bind(aJ(r))),r.rerender(),r.draw(),r}return gDt(i,[{key:"brushed",value:function(n){const r=n.selection;if(!this._xScale||!this._yScale)return;const C=[this._xScale.invert(r[0]),this._xScale.invert(r[1])],o=this.viewportYDomain;this.hasFromView||(this.viewportXDomain=C),this.setDomainsCallback(C,o)}},{key:"viewportChanged",value:function(n,r,C=!0){const o=n.domain(),a=r.domain();this.viewportXDomain=o,this.viewportYDomain=a,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Up(Kc(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]),r=this._xScale(this.viewportXDomain[1]),C=[n,r];this.brush.on("brush",null),this.gBrush.call(this.brush.move,C),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"setPosition",value:function(n){Up(Kc(i.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Up(Kc(i.prototype),"setDimensions",this).call(this,n);const r=this._xScale.range(),C=this._yScale.range(),o=r[1]-r[0];this.brush.extent([[r[0]-o,C[0]],[r[1]+o,C[1]]]),this.gBrush.call(this.brush),this.draw()}}]),i}(mm);function ADt(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 Fc(e){return Fc=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Fc(e)}let U1e=function(e){dDt(i,e);var g=hDt(i);function i(I,n){var r;ADt(this,i),r=g.call(this,I,n);const{registerViewportChanged:C,removeViewportChanged:o,setDomainsCallback:a}=I,s=sg.nice();return r.uid=s,r.options=n,r.hasFromView=!I.projectionYDomain,r.removeViewportChanged=o,r.setDomainsCallback=a,r.viewportXDomain=r.hasFromView?null:[0,0],r.viewportYDomain=r.hasFromView?null:I.projectionYDomain,r.brush=_S().on("brush",r.brushed.bind(sJ(r))),r.gBrush=r.gMain.append("g").attr("id",`brush-${r.uid}`).call(r.brush),r.gBrush.selectAll(".overlay").style("pointer-events","none"),r.gBrush.selectAll(".handle--ne").style("pointer-events","none"),r.gBrush.selectAll(".handle--nw").style("pointer-events","none"),r.gBrush.selectAll(".handle--sw").style("pointer-events","none"),r.gBrush.selectAll(".handle--se").style("pointer-events","none"),r.gBrush.selectAll(".handle--e").style("pointer-events","none"),r.gBrush.selectAll(".handle--w").style("pointer-events","none"),C(s,r.viewportChanged.bind(sJ(r))),r.rerender(),r.draw(),r}return sDt(i,[{key:"brushed",value:function(n){const r=n.selection;if(!this._xScale||!this._yScale)return;const C=this.viewportXDomain,o=[this._yScale.invert(r[0]),this._yScale.invert(r[1])];this.hasFromView||(this.viewportYDomain=o),this.setDomainsCallback(C,o)}},{key:"viewportChanged",value:function(n,r,C=!0){const o=n.domain(),a=r.domain();this.viewportXDomain=o,this.viewportYDomain=a,this.draw()}},{key:"remove",value:function(){this.removeViewportChanged(this.uid),Qp(Fc(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]),r=this._yScale(this.viewportYDomain[1]),C=[n,r];this.brush.on("brush",null),this.gBrush.call(this.brush.move,C),this.brush.on("brush",this.brushed.bind(this))}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"setPosition",value:function(n){Qp(Fc(i.prototype),"setPosition",this).call(this,n),this.draw()}},{key:"setDimensions",value:function(n){Qp(Fc(i.prototype),"setDimensions",this).call(this,n);const r=this._xScale.range(),C=this._yScale.range(),o=C[1]-C[0];this.brush.extent([[r[0],C[0]-o],[r[1],C[1]+o]]),this.gBrush.call(this.brush),this.draw()}}]),i}(mm);function aae(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Aae(e,g){for(var i=0;ie[cJ]||e,yDt=(e,g)=>{const i=g(e);return i.prototype[lJ]=Q1e(g),i},ZDt=(e,g)=>e.hasOwnProperty(lJ)&&e[lJ]===Q1e(g),GDt=(e,g)=>{for(;e!==null;){if(ZDt(e,g))return!0;e=Object.getPrototypeOf(e)}return!1},vj=(e,g)=>(Object.setPrototypeOf(g,e),e[cJ]||(e[cJ]=e),g),ex="__mixwith_cachedApplications",vDt=e=>vj(e,g=>{let i=g[ex];i||(g[ex]=new Map,i=g[ex]);let I=i.get(e);return I||(I=e(g),i.set(e,I)),I}),BDt=e=>vj(e,g=>GDt(g.prototype,e)?g:e(g)),SDt=e=>vj(e,g=>yDt(g,e)),Tk=e=>BDt(vDt(SDt(e)));let wDt=function(){function e(g){aae(this,e),this.superclass=g||function(){function i(){aae(this,i)}return sae(i)}()}return sae(e,[{key:"with",value:function(...i){return i.reduce((I,n)=>n(I),this.superclass)}}]),e}();const oy=e=>new wDt(e);function RDt(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 Vh(e){return Vh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Vh(e)}const Bj=Tk(e=>function(g){TDt(I,g);var i=NDt(I);function I(n,r){var C;RDt(this,I),C=i.call(this,n,r);const{animate:o}=n;return C.highlighted=!1,C.animate=o,C.MOUSEOVER_RADIUS=4,C.pubSub=n.pubSub,C.pubSubs.push(C.pubSub.subscribe("app.mouseMove",C.mouseMoveHandler.bind(j1e(C)))),C}return VDt(I,[{key:"setPosition",value:function(r){Gv(Vh(I.prototype),"setPosition",this).call(this,r),this.pMain.position.x=this.position[0],this.pMain.position.y=this.position[1]}},{key:"zoomed",value:function(r,C){Gv(Vh(I.prototype),"zoomed",this).call(this,r,C),this.draw()}},{key:"respondsToPosition",value:function(){return this.highlighted}}]),I}(e));function vv(){return typeof Reflect<"u"&&Reflect.get?vv=Reflect.get.bind():vv=function(g,i,I){var n=KDt(g,i);if(n){var r=Object.getOwnPropertyDescriptor(n,i);return r.get?r.get.call(arguments.length<3?g:I):r.value}},vv.apply(this,arguments)}function KDt(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=Wh(e),e!==null););return e}function $1e(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 Wh(e){return Wh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Wh(e)}const zDt=Tk(e=>function(g){eWe(I,g);var i=tWe(I);function I(){return $1e(this,I),i.apply(this,arguments)}return q1e(I,[{key:"drawHorizontalRule",value:function(r){let C=Kt(this.options.color||"black");this.highlighted&&(C=Kt("red")),r.lineStyle(this.strokeWidth,C,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(e){return Xh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Xh(e)}const CWe=Tk(e=>function(g){nWe(I,g);var i=rWe(I);function I(){return iWe(this,I),i.apply(this,arguments)}return IWe(I,[{key:"drawVerticalRule",value:function(r){let C=Kt(this.options.color||"black");this.highlighted&&(C=Kt("red")),r.lineStyle(this.strokeWidth,C,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 Hh(e){return Hh=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},Hh(e)}let aWe=function(e){txt(i,e);var g=gxt(i);function i(I,n){var r;QDt(this,i),r=g.call(this,I,n);const{x:C,y:o}=I;return r.xPosition=C,r.yPosition=o,r.strokeWidth=2,r.strokeOpacity=1,r.dashLength=5,r.dashGap=3,r}return jDt(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 r=Kt(this.options.color||"black");this.highlighted&&(r=Kt("red")),n.lineStyle(this.strokeWidth,r,this.strokeOpacity);let C=0;for(;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 eA(e){return eA=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},eA(e)}let pw=function(e){sxt(i,e);var g=lxt(i);function i(I,n){var r;rxt(this,i),r=g.call(this,I,n);const{animate:C}=I;return r.visibleTiles=new Set,r.visibleTileIds=new Set,r.fetching=new Set,r.fetchedTiles={},r.tileGraphics={},r.minX=typeof r.options.minPos<"u"&&!Number.isNaN(+r.options.minPos)?+r.options.minPos:-180,r.maxX=+r.options.maxPos||180,r.maxX=typeof r.options.maxPos<"u"&&!Number.isNaN(+r.options.maxPos)?+r.options.maxPos:180,r.minY=r.options.minY||r.minX,r.maxY=r.options.maxY||r.maxX,r.maxZoom=19,r.maxWidth=r.maxX-r.minX,r.animate=C,r.uuid=sg.nice(),r.refreshTilesDebounced=DQ(r.refreshTiles.bind(AWe(r)),bX),r}return Cxt(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(r=>({tileId:this.tileToLocalId(r),remoteId:this.tileToRemoteId(r),mirrored:r.mirrored})),this.visibleTileIds=new Set(this.visibleTiles.map(r=>r.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)),r=[...this.visibleTiles].filter(o=>!this.fetching.has(o.remoteId)&&!n.has(o.tileId));for(let o=0;o!this.visibleTileIds.has(o));this.removeTiles(C),this.fetchNewTiles(r)}},{key:"removeTiles",value:function(n){n.length&&this.areAllVisibleTilesLoaded()&&(n.forEach(r=>{const C=r;this.destroyTile(this.fetchedTiles[C]),C in this.tileGraphics&&(this.pMain.removeChild(this.tileGraphics[C]),delete this.tileGraphics[C]),delete this.fetchedTiles[C]}),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 r=n.split(".");return r.slice(0,r.length-1).join(".")}},{key:"calculateZoomLevel",value:function(){const n=vt.calculateZoomLevel(this._xScale,this.minX,this.maxX),r=vt.calculateZoomLevel(this._xScale,this.minY,this.maxY);let C=Math.min(Math.max(n,r),this.maxZoom);return this.options.maxZoom&&(this.options.maxZoom>=0?C=Math.min(this.options.maxZoom,C):console.error("Invalid maxZoom on track:",this)),C}},{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,r=this.yTiles,C=this.zoomLevel,o=[];for(let a=0;a0){const r=[...new Set(n.map(C=>C.remoteId))];for(const C of r){const o=C.split("."),a=this.getTileUrl(o),s=new Image;s.crossOrigin="Anonymous",s.src=a,s.onload=()=>{const A={};A[C]={tileId:C,img:s,zoomLevel:+o[0],tilePos:[+o[1],+o[2]],tileSrc:a},this.receivedTiles(A)}}}}},{key:"receivedTiles",value:function(n){for(let r=0;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 C0(e){return C0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},C0(e)}let sWe=function(e){bxt(i,e);var g=yxt(i);function i(){return dxt(this,i),g.apply(this,arguments)}return hxt(i,[{key:"initTile",value:function(n){EVe.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(r=>{const o=r.remoteId.split("."),a={zoomLevel:o[0],tilePos:o.slice(1,o.length).map(s=>+s)};this.fetchedTiles[r.tileId]=r,this.fetchedTiles[r.tileId].tileData=a,this.fetching.has(r.remoteId)&&this.fetching.delete(r.remoteId)}),this.synchronizeTilesAndGraphics(),this.draw(),this.animate()}},{key:"draw",value:function(){GW(C0(i.prototype),"draw",this).call(this)}}]),i}(pw);function Bxt(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 o0(e){return o0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},o0(e)}let lWe=function(e){Wxt(i,e);var g=Xxt(i);function i(I,n){var r;return Bxt(this,i),r=g.call(this,I,n),r.style=n.style,r.options.accessToken||(r.errorTextText="No access token provided in the viewconf's track options ('accessToken' option).",r.drawError()),r}return Sxt(i,[{key:"rerender",value:function(n){vW(o0(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 r=this.options&&this.options.style?this.options.style:"streets-v10",C=this.options&&+this.options.tileSize?+this.options.tileSize:256;return`https://api.mapbox.com/styles/v1/mapbox/${r}/tiles/${C}/${n[0]}/${n[1]}/${n[2]}?access_token=${this.options.accessToken}`}}]),i}(pw);function kxt(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 o2(e){return o2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},o2(e)}let cWe=function(e){Dxt(i,e);var g=xxt(i);function i(I,n){var r;return kxt(this,i),r=g.call(this,I,n),r.style=n.style,r.options.tileSource||(r.errorTextText="No tile source string provided in the options. It should be in the form of http://a.com/{z}/{x}/{y}",r.drawError()),r}return Yxt(i,[{key:"getTileUrl",value:function(n){let r=this.options.tileSource.replace("{z}",n[0]);return r=r.replace("{x}",n[1]),r=r.replace("{y}",n[2]),r}}]),i}(pw);const Pxt=(e,g,i,I=Q2)=>{const n=i[e.type];return n?new n.dataFetcher(I,e,g):e.type==="genbank"?new FVe(e,g):e.type==="local-tiles"?new DVe(e,g):new vk(e,g)};var zt=1e-6,tS=1e-12,og=Math.PI,Qi=og/2,a2=og/4,Ar=og*2,ti=180/og,Ot=og/180,Rg=Math.abs,ay=Math.atan,sr=Math.atan2,Tt=Math.cos,DV=Math.ceil,uWe=Math.exp,ZJ=Math.hypot,A2=Math.log,tx=Math.pow,Bt=Math.sin,LC=Math.sign||function(e){return e>0?1:e<0?-1:0},jI=Math.sqrt,Sj=Math.tan;function dWe(e){return e>1?0:e<-1?og:Math.acos(e)}function lr(e){return e>1?Qi:e<-1?-Qi:Math.asin(e)}function bae(e){return(e=Bt(e/2))*e}function xi(){}function s2(e,g){e&&Zae.hasOwnProperty(e.type)&&Zae[e.type](e,g)}var yae={Feature:function(e,g){s2(e.geometry,g)},FeatureCollection:function(e,g){for(var i=e.features,I=-1,n=i.length;++I=0?1:-1,n=I*i,r=Tt(g),C=Bt(g),o=SJ*C,a=BJ*r+o*Tt(n),s=o*I*Bt(n);l2.add(sr(s,a)),vJ=e,BJ=r,SJ=C}function Lxt(e){return c2=new YI,Lo(e,BA),c2*2}function u2(e){return[sr(e[1],e[0]),lr(e[2])]}function Th(e){var g=e[0],i=e[1],I=Tt(i);return[I*Tt(g),I*Bt(g),Bt(i)]}function xV(e,g){return e[0]*g[0]+e[1]*g[1]+e[2]*g[2]}function a0(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 gx(e,g){e[0]+=g[0],e[1]+=g[1],e[2]+=g[2]}function EV(e,g){return[e[0]*g,e[1]*g,e[2]*g]}function d2(e){var g=jI(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]/=g,e[1]/=g,e[2]/=g}var Yi,Hr,Li,IC,$u,pWe,bWe,jp,wv,Ol,Os,Cs={point:wJ,lineStart:vae,lineEnd:Bae,polygonStart:function(){Cs.point=ZWe,Cs.lineStart=Uxt,Cs.lineEnd=Qxt,wv=new YI,BA.polygonStart()},polygonEnd:function(){BA.polygonEnd(),Cs.point=wJ,Cs.lineStart=vae,Cs.lineEnd=Bae,l2<0?(Yi=-(Li=180),Hr=-(IC=90)):wv>zt?IC=90:wv<-zt&&(Hr=-90),Os[0]=Yi,Os[1]=Li},sphere:function(){Yi=-(Li=180),Hr=-(IC=90)}};function wJ(e,g){Ol.push(Os=[Yi=e,Li=e]),gIC&&(IC=g)}function yWe(e,g){var i=Th([e*Ot,g*Ot]);if(jp){var I=a0(jp,i),n=[I[1],-I[0],0],r=a0(n,I);d2(r),r=u2(r);var C=e-$u,o=C>0?1:-1,a=r[0]*ti*o,s,A=Rg(C)>180;A^(o*$uIC&&(IC=s)):(a=(a+360)%360-180,A^(o*$uIC&&(IC=g))),A?e<$u?eC(Yi,e)>eC(Yi,Li)&&(Li=e):eC(e,Li)>eC(Yi,Li)&&(Yi=e):Li>=Yi?(eLi&&(Li=e)):e>$u?eC(Yi,e)>eC(Yi,Li)&&(Li=e):eC(e,Li)>eC(Yi,Li)&&(Yi=e)}else Ol.push(Os=[Yi=e,Li=e]);gIC&&(IC=g),jp=i,$u=e}function vae(){Cs.point=yWe}function Bae(){Os[0]=Yi,Os[1]=Li,Cs.point=wJ,jp=null}function ZWe(e,g){if(jp){var i=e-$u;wv.add(Rg(i)>180?i+(i>0?360:-360):i)}else pWe=e,bWe=g;BA.point(e,g),yWe(e,g)}function Uxt(){BA.lineStart()}function Qxt(){ZWe(pWe,bWe),BA.lineEnd(),Rg(wv)>zt&&(Yi=-(Li=180)),Os[0]=Yi,Os[1]=Li,jp=null}function eC(e,g){return(g-=e)<0?g+360:g}function jxt(e,g){return e[0]-g[0]}function Sae(e,g){return e[0]<=e[1]?e[0]<=g&&g<=e[1]:geC(I[0],I[1])&&(I[1]=n[1]),eC(n[0],I[1])>eC(I[0],I[1])&&(I[0]=n[0])):r.push(I=n);for(C=-1/0,i=r.length-1,g=0,I=r[i];g<=i;I=n,++g)n=r[g],(o=eC(I[1],n[0]))>C&&(C=o,Yi=n[0],Li=I[1])}return Ol=Os=null,Yi===1/0||Hr===1/0?[[NaN,NaN],[NaN,NaN]]:[[Yi,Hr],[Li,IC]]}var rG,h2,m2,f2,p2,b2,y2,Z2,RJ,VJ,WJ,GWe,vWe,er,tr,gr,$o={sphere:xi,point:wj,lineStart:wae,lineEnd:Rae,polygonStart:function(){$o.lineStart=tEt,$o.lineEnd=gEt},polygonEnd:function(){$o.lineStart=wae,$o.lineEnd=Rae}};function wj(e,g){e*=Ot,g*=Ot;var i=Tt(g);bw(i*Tt(e),i*Bt(e),Bt(g))}function bw(e,g,i){++rG,m2+=(e-m2)/rG,f2+=(g-f2)/rG,p2+=(i-p2)/rG}function wae(){$o.point=qxt}function qxt(e,g){e*=Ot,g*=Ot;var i=Tt(g);er=i*Tt(e),tr=i*Bt(e),gr=Bt(g),$o.point=eEt,bw(er,tr,gr)}function eEt(e,g){e*=Ot,g*=Ot;var i=Tt(g),I=i*Tt(e),n=i*Bt(e),r=Bt(g),C=sr(jI((C=tr*r-gr*n)*C+(C=gr*I-er*r)*C+(C=er*n-tr*I)*C),er*I+tr*n+gr*r);h2+=C,b2+=C*(er+(er=I)),y2+=C*(tr+(tr=n)),Z2+=C*(gr+(gr=r)),bw(er,tr,gr)}function Rae(){$o.point=wj}function tEt(){$o.point=iEt}function gEt(){BWe(GWe,vWe),$o.point=wj}function iEt(e,g){GWe=e,vWe=g,e*=Ot,g*=Ot,$o.point=BWe;var i=Tt(g);er=i*Tt(e),tr=i*Bt(e),gr=Bt(g),bw(er,tr,gr)}function BWe(e,g){e*=Ot,g*=Ot;var i=Tt(g),I=i*Tt(e),n=i*Bt(e),r=Bt(g),C=tr*r-gr*n,o=gr*I-er*r,a=er*n-tr*I,s=ZJ(C,o,a),A=lr(s),l=s&&-A/s;RJ.add(l*C),VJ.add(l*o),WJ.add(l*a),h2+=A,b2+=A*(er+(er=I)),y2+=A*(tr+(tr=n)),Z2+=A*(gr+(gr=r)),bw(er,tr,gr)}function IEt(e){rG=h2=m2=f2=p2=b2=y2=Z2=0,RJ=new YI,VJ=new YI,WJ=new YI,Lo(e,$o);var g=+RJ,i=+VJ,I=+WJ,n=ZJ(g,i,I);return nog?e+Math.round(-e/Ar)*Ar:e,g]}HJ.invert=HJ;function Rj(e,g,i){return(e%=Ar)?g||i?XJ(Wae(e),Xae(g,i)):Wae(e):g||i?Xae(g,i):HJ}function Vae(e){return function(g,i){return g+=e,[g>og?g-Ar:g<-og?g+Ar:g,i]}}function Wae(e){var g=Vae(e);return g.invert=Vae(-e),g}function Xae(e,g){var i=Tt(e),I=Bt(e),n=Tt(g),r=Bt(g);function C(o,a){var s=Tt(a),A=Tt(o)*s,l=Bt(o)*s,c=Bt(a),u=c*i+A*I;return[sr(l*n-u*r,A*i-c*I),lr(u*n+l*r)]}return C.invert=function(o,a){var s=Tt(a),A=Tt(o)*s,l=Bt(o)*s,c=Bt(a),u=c*n-l*r;return[sr(l*n+c*r,A*i+u*I),lr(u*i-A*I)]},C}function SWe(e){e=Rj(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]*=ti,i[1]*=ti,i}return g.invert=function(i){return i=e.invert(i[0]*Ot,i[1]*Ot),i[0]*=ti,i[1]*=ti,i},g}function wWe(e,g,i,I,n,r){if(i){var C=Tt(g),o=Bt(g),a=I*i;n==null?(n=g+I*Ar,r=g-a/2):(n=Hae(C,n),r=Hae(C,r),(I>0?nr)&&(n+=I*Ar));for(var s,A=n;I>0?A>r:A1&&e.push(e.pop().concat(e.shift()))},result:function(){var i=e;return e=[],g=null,i}}}function BW(e,g){return Rg(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 Tae(e){if(g=e.length){for(var g,i=0,I=e[0],n;++i=0?1:-1,R=w*v,S=R>og,X=m*B;if(a.add(sr(X*w*Bt(R),f*G+X*Tt(R))),C+=S?v+w*Ar:v,S^d>=i^y>=i){var W=a0(Th(u),Th(p));d2(W);var V=a0(r,W);d2(V);var H=(S^v>=0?-1:1)*lr(V[2]);(I>H||I===H&&(W[0]||W[1]))&&(o+=S^v>=0?1:-1)}}return(C<-zt||C0){for(a||(n.polygonStart(),a=!0),n.lineStart(),B=0;B1&&y&2&&Z.push(Z.pop().concat(Z.shift())),A.push(Z.filter(rEt))}}return c}}function rEt(e){return e.length>1}function CEt(e,g){return((e=e.x)[0]<0?e[1]-Qi-zt:Qi-e[1])-((g=g.x)[0]<0?g[1]-Qi-zt:Qi-g[1])}const TJ=XWe(function(){return!0},oEt,AEt,[-og,-Qi]);function oEt(e){var g=NaN,i=NaN,I=NaN,n;return{lineStart:function(){e.lineStart(),n=1},point:function(r,C){var o=r>0?og:-og,a=Rg(r-g);Rg(a-og)0?Qi:-Qi),e.point(I,i),e.lineEnd(),e.lineStart(),e.point(o,i),e.point(r,i),n=0):I!==o&&a>=og&&(Rg(g-I)zt?ay((Bt(g)*(r=Tt(I))*Bt(i)-Bt(I)*(n=Tt(g))*Bt(e))/(n*r*C)):(g+I)/2}function AEt(e,g,i,I){var n;if(e==null)n=i*Qi,I.point(-og,n),I.point(0,n),I.point(og,n),I.point(og,0),I.point(og,-n),I.point(0,-n),I.point(-og,-n),I.point(-og,0),I.point(-og,n);else if(Rg(e[0]-g[0])>zt){var r=e[0]0,n=Rg(g)>zt;function r(A,l,c,u){wWe(u,e,i,c,A,l)}function C(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=C(m,f),Z=I?y?0:s(m,f):y?s(m+(m<0?og:-og),f):0;if(!l&&(d=u=y)&&A.lineStart(),y!==u&&(p=a(l,b),(!p||BW(l,p)||BW(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||!BW(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=Th(A),d=Th(l),h=[1,0,0],m=a0(u,d),f=xV(m,m),b=m[0],p=f-b*b;if(!p)return!c&&A;var y=g*f/p,Z=-g*b/p,B=a0(h,m),G=EV(h,y),v=EV(m,Z);gx(G,v);var w=B,R=xV(G,w),S=xV(w,w),X=R*R-S*(xV(G,G)-1);if(!(X<0)){var W=jI(X),V=EV(w,(-R-W)/S);if(gx(V,G),V=u2(V),!c)return V;var H=A[0],Y=l[0],K=A[1],x=l[1],J;Y0^V[1]<(Rg(V[0]-H)og^(H<=V[0]&&V[0]<=Y)){var $=EV(w,(-R+W)/S);return gx($,G),[V,u2($)]}}}function s(A,l){var c=I?e:og-e,u=0;return A<-c?u|=1:A>c&&(u|=2),l<-c?u|=4:l>c&&(u|=8),u}return XWe(C,o,r,I?[0,-e]:[-og,e-og])}function sEt(e,g,i,I,n,r){var C=e[0],o=e[1],a=g[0],s=g[1],A=0,l=1,c=a-C,u=s-o,d;if(d=i-C,!(!c&&d>0)){if(d/=c,c<0){if(d0){if(d>l)return;d>A&&(A=d)}if(d=n-C,!(!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=r-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]=C+A*c,e[1]=o+A*u),l<1&&(g[0]=C+l*c,g[1]=o+l*u),!0}}}}}var CG=1e9,zV=-CG;function Nk(e,g,i,I){function n(s,A){return e<=s&&s<=i&&g<=A&&A<=I}function r(s,A,l,c){var u=0,d=0;if(s==null||(u=C(s,l))!==(d=C(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 C(s,A){return Rg(s[0]-e)0?0:3:Rg(s[0]-i)0?2:1:Rg(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=C(s,1),c=C(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,B,G={point:v,lineStart:X,lineEnd:W,polygonStart:R,polygonEnd:S};function v(H,Y){n(H,Y)&&A.point(H,Y)}function w(){for(var H=0,Y=0,K=u.length;YI&&(j-q)*(I-$)>(te-$)*(e-q)&&++H:te<=I&&(j-q)*(I-$)<(te-$)*(e-q)&&--H;return H}function R(){A=l,c=[],u=[],B=!0}function S(){var H=w(),Y=B&&H,K=(c=D7(c)).length;(Y||K)&&(s.polygonStart(),Y&&(s.lineStart(),r(null,null,1,s),s.lineEnd()),K&&VWe(c,o,H,r,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=v,y&&A.lineEnd()}function V(H,Y){var K=n(H,Y);if(u&&d.push([H,Y]),Z)h=H,m=Y,f=K,Z=!1,K&&(A.lineStart(),A.point(H,Y));else if(K&&y)A.point(H,Y);else{var x=[b=Math.max(zV,Math.min(CG,b)),p=Math.max(zV,Math.min(CG,p))],J=[H=Math.max(zV,Math.min(CG,H)),Y=Math.max(zV,Math.min(CG,Y))];sEt(x,J,e,g,i,I)?(y||(A.lineStart(),A.point(x[0],x[1])),A.point(J[0],J[1]),K||A.lineEnd(),B=!1):K&&(A.lineStart(),A.point(H,Y),B=!1)}b=H,p=Y,y=K}return G}}function lEt(){var e=0,g=0,i=960,I=500,n,r,C;return C={stream:function(o){return n&&r===o?n:n=Nk(e,g,i,I)(r=o)},extent:function(o){return arguments.length?(e=+o[0][0],g=+o[0][1],i=+o[1][0],I=+o[1][1],n=r=null,C):[[e,g],[i,I]]}}}var NJ,kJ,SW,wW,A0={sphere:xi,point:xi,lineStart:cEt,lineEnd:xi,polygonStart:xi,polygonEnd:xi};function cEt(){A0.point=dEt,A0.lineEnd=uEt}function uEt(){A0.point=A0.lineEnd=xi}function dEt(e,g){e*=Ot,g*=Ot,kJ=e,SW=Bt(g),wW=Tt(g),A0.point=hEt}function hEt(e,g){e*=Ot,g*=Ot;var i=Bt(g),I=Tt(g),n=Rg(e-kJ),r=Tt(n),C=Bt(n),o=I*C,a=wW*i-SW*I*r,s=SW*i+wW*I*r;NJ.add(sr(jI(o*o+a*a),s)),kJ=e,SW=i,wW=I}function TWe(e){return NJ=new YI,Lo(e,A0),+NJ}var YJ=[null,null],mEt={type:"LineString",coordinates:YJ};function G2(e,g){return YJ[0]=e,YJ[1]=g,TWe(mEt)}var Nae={Feature:function(e,g){return v2(e.geometry,g)},FeatureCollection:function(e,g){for(var i=e.features,I=-1,n=i.length;++I0&&(n=G2(e[r],e[r-1]),n>0&&i<=n&&I<=n&&(i+I-n)*(1-Math.pow((i-I)/n,2))zt}).map(c)).concat(nr(DV(r/s)*s,n,s).filter(function(p){return Rg(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(C).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],C=+p[1][1],I>i&&(p=I,I=i,i=p),o>C&&(p=o,o=C,C=p),f.precision(m)):[[I,o],[i,C]]},f.extentMinor=function(p){return arguments.length?(g=+p[0][0],e=+p[1][0],r=+p[0][1],n=+p[1][1],g>e&&(p=g,g=e,e=p),r>n&&(p=r,r=n,n=p),f.precision(m)):[[g,r],[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=Dae(r,n,90),u=xae(g,e,m),d=Dae(o,C,90),h=xae(I,i,m),f):m},f.extentMajor([[-180,-90+zt],[180,90-zt]]).extentMinor([[-180,-80-zt],[180,80+zt]])}function bEt(){return kWe()()}function yEt(e,g){var i=e[0]*Ot,I=e[1]*Ot,n=g[0]*Ot,r=g[1]*Ot,C=Tt(I),o=Bt(I),a=Tt(r),s=Bt(r),A=C*Tt(i),l=C*Bt(i),c=a*Tt(n),u=a*Bt(n),d=2*lr(jI(bae(r-I)+C*a*bae(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[sr(Z,y)*ti,sr(B,jI(y*y+Z*Z))*ti]}:function(){return[i*ti,I*ti]};return m.distance=d,m}const gS=e=>e;var Ix=new YI,KJ=new YI,YWe,KWe,FJ,DJ,Ic={point:xi,lineStart:xi,lineEnd:xi,polygonStart:function(){Ic.lineStart=ZEt,Ic.lineEnd=vEt},polygonEnd:function(){Ic.lineStart=Ic.lineEnd=Ic.point=xi,Ix.add(Rg(KJ)),KJ=new YI},result:function(){var e=Ix/2;return Ix=new YI,e}};function ZEt(){Ic.point=GEt}function GEt(e,g){Ic.point=FWe,YWe=FJ=e,KWe=DJ=g}function FWe(e,g){KJ.add(DJ*e-FJ*g),FJ=e,DJ=g}function vEt(){FWe(YWe,KWe)}const Eae=Ic;var s0=1/0,B2=s0,iS=-s0,S2=iS,BEt={point:SEt,lineStart:xi,lineEnd:xi,polygonStart:xi,polygonEnd:xi,result:function(){var e=[[s0,B2],[iS,S2]];return iS=S2=-(B2=s0=1/0),e}};function SEt(e,g){eiS&&(iS=e),gS2&&(S2=g)}const w2=BEt;var xJ=0,EJ=0,oG=0,R2=0,V2=0,sp=0,MJ=0,zJ=0,aG=0,DWe,xWe,tA,gA,Uo={point:Nh,lineStart:Mae,lineEnd:zae,polygonStart:function(){Uo.lineStart=VEt,Uo.lineEnd=WEt},polygonEnd:function(){Uo.point=Nh,Uo.lineStart=Mae,Uo.lineEnd=zae},result:function(){var e=aG?[MJ/aG,zJ/aG]:sp?[R2/sp,V2/sp]:oG?[xJ/oG,EJ/oG]:[NaN,NaN];return xJ=EJ=oG=R2=V2=sp=MJ=zJ=aG=0,e}};function Nh(e,g){xJ+=e,EJ+=g,++oG}function Mae(){Uo.point=wEt}function wEt(e,g){Uo.point=REt,Nh(tA=e,gA=g)}function REt(e,g){var i=e-tA,I=g-gA,n=jI(i*i+I*I);R2+=n*(tA+e)/2,V2+=n*(gA+g)/2,sp+=n,Nh(tA=e,gA=g)}function zae(){Uo.point=Nh}function VEt(){Uo.point=XEt}function WEt(){EWe(DWe,xWe)}function XEt(e,g){Uo.point=EWe,Nh(DWe=tA=e,xWe=gA=g)}function EWe(e,g){var i=e-tA,I=g-gA,n=jI(i*i+I*I);R2+=n*(tA+e)/2,V2+=n*(gA+g)/2,sp+=n,n=gA*e-tA*g,MJ+=n*(tA+e),zJ+=n*(gA+g),aG+=n*3,Nh(tA=e,gA=g)}const Pae=Uo;function MWe(e){this._context=e}MWe.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,Ar);break}}},result:xi};var PJ=new YI,nx,zWe,PWe,AG,sG,W2={point:xi,lineStart:function(){W2.point=HEt},lineEnd:function(){nx&&JWe(zWe,PWe),W2.point=xi},polygonStart:function(){nx=!0},polygonEnd:function(){nx=null},result:function(){var e=+PJ;return PJ=new YI,e}};function HEt(e,g){W2.point=JWe,zWe=AG=e,PWe=sG=g}function JWe(e,g){AG-=e,sG-=g,PJ.add(jI(AG*AG+sG*sG)),AG=e,sG=g}const Jae=W2;function OWe(){this._string=[]}OWe.prototype={_radius:4.5,_circle:Oae(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=Oae(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 Oae(e){return"m0,"+e+"a"+e+","+e+" 0 1,1 0,"+-2*e+"a"+e+","+e+" 0 1,1 0,"+2*e+"z"}function TEt(e,g){var i=4.5,I,n;function r(C){return C&&(typeof i=="function"&&n.pointRadius(+i.apply(this,arguments)),Lo(C,I(n))),n.result()}return r.area=function(C){return Lo(C,I(Eae)),Eae.result()},r.measure=function(C){return Lo(C,I(Jae)),Jae.result()},r.bounds=function(C){return Lo(C,I(w2)),w2.result()},r.centroid=function(C){return Lo(C,I(Pae)),Pae.result()},r.projection=function(C){return arguments.length?(I=C==null?(e=null,gS):(e=C).stream,r):e},r.context=function(C){return arguments.length?(n=C==null?(g=null,new OWe):new MWe(g=C),typeof i!="function"&&n.pointRadius(i),r):g},r.pointRadius=function(C){return arguments.length?(i=typeof C=="function"?C:(n.pointRadius(+C),+C),r):i},r.projection(e).context(g)}function NEt(e){return{stream:yw(e)}}function yw(e){return function(g){var i=new JJ;for(var I in e)i[I]=e[I];return i.stream=g,i}}function JJ(){}JJ.prototype={constructor:JJ,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 Vj(e,g,i){var I=e.clipExtent&&e.clipExtent();return e.scale(150).translate([0,0]),I!=null&&e.clipExtent(null),Lo(i,e.stream(w2)),g(w2.result()),I!=null&&e.clipExtent(I),e}function kk(e,g,i){return Vj(e,function(I){var n=g[1][0]-g[0][0],r=g[1][1]-g[0][1],C=Math.min(n/(I[1][0]-I[0][0]),r/(I[1][1]-I[0][1])),o=+g[0][0]+(n-C*(I[1][0]+I[0][0]))/2,a=+g[0][1]+(r-C*(I[1][1]+I[0][1]))/2;e.scale(150*C).translate([o,a])},i)}function Wj(e,g,i){return kk(e,[[0,0],g],i)}function Xj(e,g,i){return Vj(e,function(I){var n=+g,r=n/(I[1][0]-I[0][0]),C=(n-r*(I[1][0]+I[0][0]))/2,o=-r*I[0][1];e.scale(150*r).translate([C,o])},i)}function Hj(e,g,i){return Vj(e,function(I){var n=+g,r=n/(I[1][1]-I[0][1]),C=-r*I[0][0],o=(n-r*(I[1][1]+I[0][1]))/2;e.scale(150*r).translate([C,o])},i)}var _ae=16,kEt=Tt(30*Ot);function Lae(e,g){return+g?KEt(e,g):YEt(e)}function YEt(e){return yw({point:function(g,i){g=e(g,i),this.stream.point(g[0],g[1])}})}function KEt(e,g){function i(I,n,r,C,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=C+c,Z=o+u,B=a+d,G=jI(y*y+Z*Z+B*B),v=lr(B/=G),w=Rg(Rg(B)-1)g||Rg((f*W+b*V)/p-.5)>.3||C*c+o*u+a*d2?H[2]%360*Ot:0,W()):[o*ti,a*ti,s*ti]},S.angle=function(H){return arguments.length?(l=H%360*Ot,W()):l*ti},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=Lae(G,Z=H*H),V()):jI(Z)},S.fitExtent=function(H,Y){return kk(S,H,Y)},S.fitSize=function(H,Y){return Wj(S,H,Y)},S.fitWidth=function(H,Y){return Xj(S,H,Y)},S.fitHeight=function(H,Y){return Hj(S,H,Y)};function W(){var H=Uae(i,0,0,c,u,l).apply(null,g(r,C)),Y=Uae(i,I-H[0],n-H[1],c,u,l);return A=Rj(o,a,s),G=XJ(g,Y),v=XJ(A,G),B=Lae(G,Z),V()}function V(){return w=R=null,S}return function(){return g=e.apply(this,arguments),S.invert=g.invert&&X,W()}}function Nj(e){var g=0,i=og/3,I=Tj(e),n=I(g,i);return n.parallels=function(r){return arguments.length?I(g=r[0]*Ot,i=r[1]*Ot):[g*ti,i*ti]},n}function EEt(e){var g=Tt(e);function i(I,n){return[I*g,Bt(n)/g]}return i.invert=function(I,n){return[I/g,lr(n*g)]},i}function _We(e,g){var i=Bt(e),I=(i+Bt(g))/2;if(Rg(I)=.12&&m<.234&&h>=-.425&&h<-.214?n:m>=.166&&m<.234&&h>=-.214&&h<-.115?C:i).invert(c)},A.stream=function(c){return e&&g===c?e:e=MEt([i.stream(g=c),n.stream(c),C.stream(c)])},A.precision=function(c){return arguments.length?(i.precision(c),n.precision(c),C.precision(c),l()):i.precision()},A.scale=function(c){return arguments.length?(i.scale(c),n.scale(c*.35),C.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),r=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=C.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 kk(A,c,u)},A.fitSize=function(c,u){return Wj(A,c,u)},A.fitWidth=function(c,u){return Xj(A,c,u)},A.fitHeight=function(c,u){return Hj(A,c,u)};function l(){return e=g=null,A}return A.scale(1070)}function UWe(e){return function(g,i){var I=Tt(g),n=Tt(i),r=e(I*n);return r===1/0?[2,0]:[r*n*Bt(g),r*Bt(i)]}}function Zw(e){return function(g,i){var I=jI(g*g+i*i),n=e(I),r=Bt(n),C=Tt(n);return[sr(g*r,I*C),lr(I&&i*r/I)]}}var kj=UWe(function(e){return jI(2/(1+e))});kj.invert=Zw(function(e){return 2*lr(e/2)});function PEt(){return kA(kj).scale(124.75).clipAngle(180-.001)}var Yj=UWe(function(e){return(e=dWe(e))&&e/Bt(e)});Yj.invert=Zw(function(e){return e});function JEt(){return kA(Yj).scale(79.4188).clipAngle(180-.001)}function Gw(e,g){return[e,A2(Sj((Qi+g)/2))]}Gw.invert=function(e,g){return[e,2*ay(uWe(g))-Qi]};function OEt(){return QWe(Gw).scale(961/Ar)}function QWe(e){var g=kA(e),i=g.center,I=g.scale,n=g.translate,r=g.clipExtent,C=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?C=o=a=s=null:(C=+l[0][0],o=+l[0][1],a=+l[1][0],s=+l[1][1]),A()):C==null?null:[[C,o],[a,s]]};function A(){var l=og*I(),c=g(SWe(g.rotate()).invert([0,0]));return r(C==null?[[c[0]-l,c[1]-l],[c[0]+l,c[1]+l]]:e===Gw?[[Math.max(c[0]-l,C),o],[Math.min(c[0]+l,a),s]]:[[C,Math.max(c[1]-l,o)],[a,Math.min(c[1]+l,s)]])}return A()}function PV(e){return Sj((Qi+e)/2)}function jWe(e,g){var i=Tt(e),I=e===g?Bt(e):A2(i/Tt(g))/A2(PV(g)/PV(e)),n=i*tx(PV(e),I)/I;if(!I)return Gw;function r(C,o){n>0?o<-Qi+zt&&(o=-Qi+zt):o>Qi-zt&&(o=Qi-zt);var a=n/tx(PV(o),I);return[a*Bt(I*C),n-a*Tt(I*C)]}return r.invert=function(C,o){var a=n-o,s=LC(I)*jI(C*C+a*a),A=sr(C,Rg(a))*LC(a);return a*I<0&&(A-=og*LC(C)*LC(a)),[A/I,2*ay(tx(n/s,1/I))-Qi]},r}function _Et(){return Nj(jWe).scale(109.5).parallels([30,30])}function IS(e,g){return[e,g]}IS.invert=IS;function LEt(){return kA(IS).scale(152.63)}function $We(e,g){var i=Tt(e),I=e===g?Bt(e):(i-Tt(g))/(g-e),n=i/I+e;if(Rg(I)zt&&--I>0);return[e/(.8707+(r=i*i)*(-.131979+r*(-.013791+r*r*r*(.003971-.001529*r)))),i]};function eMt(){return kA(Dj).scale(175.295)}function xj(e,g){return[Tt(g)*Bt(e),Bt(g)]}xj.invert=Zw(lr);function tMt(){return kA(xj).scale(249.5).clipAngle(90+zt)}function Ej(e,g){var i=Tt(g),I=1+Tt(e)*i;return[i*Bt(e)/I,Bt(g)/I]}Ej.invert=Zw(function(e){return 2*ay(e)});function gMt(){return kA(Ej).scale(250).clipAngle(142)}function Mj(e,g){return[A2(Sj((Qi+g)/2)),-e]}Mj.invert=function(e,g){return[-g,2*ay(uWe(e))-Qi]};function iMt(){var e=QWe(Mj),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 IMt=Object.freeze(Object.defineProperty({__proto__:null,geoAlbers:LWe,geoAlbersUsa:zEt,geoArea:Lxt,geoAzimuthalEqualArea:PEt,geoAzimuthalEqualAreaRaw:kj,geoAzimuthalEquidistant:JEt,geoAzimuthalEquidistantRaw:Yj,geoBounds:$xt,geoCentroid:IEt,geoCircle:nEt,geoClipAntimeridian:TJ,geoClipCircle:HWe,geoClipExtent:lEt,geoClipRectangle:Nk,geoConicConformal:_Et,geoConicConformalRaw:jWe,geoConicEqualArea:X2,geoConicEqualAreaRaw:_We,geoConicEquidistant:UEt,geoConicEquidistantRaw:$We,geoContains:pEt,geoDistance:G2,geoEqualEarth:jEt,geoEqualEarthRaw:Kj,geoEquirectangular:LEt,geoEquirectangularRaw:IS,geoGnomonic:$Et,geoGnomonicRaw:Fj,geoGraticule:kWe,geoGraticule10:bEt,geoIdentity:qEt,geoInterpolate:yEt,geoLength:TWe,geoMercator:OEt,geoMercatorRaw:Gw,geoNaturalEarth1:eMt,geoNaturalEarth1Raw:Dj,geoOrthographic:tMt,geoOrthographicRaw:xj,geoPath:TEt,geoProjection:kA,geoProjectionMutator:Tj,geoRotation:SWe,geoStereographic:gMt,geoStereographicRaw:Ej,geoStream:Lo,geoTransform:NEt,geoTransverseMercator:iMt,geoTransverseMercatorRaw:Mj},Symbol.toStringTag,{value:"Module"}));var nMt=[].slice,rMt={};function OJ(e){this._size=e,this._call=this._error=null,this._tasks=[],this._data=[],this._waiting=this._active=this._ended=this._start=0}OJ.prototype=e9e.prototype={constructor:OJ,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=nMt.call(arguments,1);return g.push(e),++this._waiting,this._tasks.push(g),qWe(this),this},abort:function(){return this._error==null&&zj(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))},T2(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,T2(this),this}};function qWe(e){if(!e._start)try{CMt(e)}catch(g){if(e._tasks[e._ended+e._active-1])zj(e,g);else if(!e._data)throw g}}function CMt(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,T2(e)}function T2(e){if(!e._active&&e._call){var g=e._data;e._data=void 0,e._call(e._error,g)}}function e9e(e){if(e==null)e=1/0;else if(!((e=+e)>=1))throw new Error("invalid concurrency");return new OJ(e)}const aMt=Object.freeze(Object.defineProperty({__proto__:null,queue:e9e},Symbol.toStringTag,{value:"Module"}));var BC="$";function N2(){}N2.prototype=Pj.prototype={constructor:N2,has:function(e){return BC+e in this},get:function(e){return this[BC+e]},set:function(e,g){return this[BC+e]=g,this},remove:function(e){var g=BC+e;return g in this&&delete this[g]},clear:function(){for(var e in this)e[0]===BC&&delete this[e]},keys:function(){var e=[];for(var g in this)g[0]===BC&&e.push(g.slice(1));return e},values:function(){var e=[];for(var g in this)g[0]===BC&&e.push(this[g]);return e},entries:function(){var e=[];for(var g in this)g[0]===BC&&e.push({key:g.slice(1),value:this[g]});return e},size:function(){var e=0;for(var g in this)g[0]===BC&&++e;return e},empty:function(){for(var e in this)if(e[0]===BC)return!1;return!0},each:function(e){for(var g in this)g[0]===BC&&e(this[g],g.slice(1),this)}};function Pj(e,g){var i=new N2;if(e instanceof N2)e.each(function(o,a){i.set(a,o)});else if(Array.isArray(e)){var I=-1,n=e.length,r;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}})}RW.prototype=t9e.prototype={constructor:RW,on:function(e,g){var i=this._,I=sMt(e+"",i),n,r=-1,C=I.length;if(arguments.length<2){for(;++r0)for(var i=new Array(n),I=0,n,r;I3&&c(u)};function c(u){var d=C.status,h;if(!d&&uMt(C)||d>=200&&d<300||d===304){if(s)try{h=s.call(i,C)}catch(m){I.call("error",i,m);return}else h=C;I.call("load",i,h)}else I.call("error",i,u)}if(C.onprogress=function(u){I.call("progress",i,u)},i={header:function(u,d){return u=(u+"").toLowerCase(),arguments.length<2?r.get(u):(d==null?r.remove(u):r.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 C.open(u,e,!0,o,a),n!=null&&!r.has("accept")&&r.set("accept",n+",*/*"),C.setRequestHeader&&r.each(function(m,f){C.setRequestHeader(f,m)}),n!=null&&C.overrideMimeType&&C.overrideMimeType(n),A!=null&&(C.responseType=A),l>0&&(C.timeout=l),h==null&&typeof d=="function"&&(h=d,d=null),h!=null&&h.length===1&&(h=cMt(h)),h!=null&&i.on("error",h).on("load",function(m){h(null,m)}),I.call("beforesend",i,C),C.send(d??null),i},abort:function(){return C.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 cMt(e){return function(g,i){e(g==null?i:null)}}function uMt(e){var g=e.responseType;return g&&g!=="text"?e.response:e.responseText}function Yk(e,g){return function(i,I){var n=Jj(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 dMt=Yk("text/html",function(e){return document.createRange().createContextualFragment(e.responseText)}),hMt=Yk("application/json",function(e){return JSON.parse(e.responseText)}),mMt=Yk("text/plain",function(e){return e.responseText}),fMt=Yk("application/xml",function(e){var g=e.responseXML;if(!g)throw new Error("parse error");return g});var $ae={},rx={},Cx=34,hZ=10,ox=13;function g9e(e){return new Function("d","return {"+e.map(function(g,i){return JSON.stringify(g)+": d["+i+'] || ""'}).join(",")+"}")}function pMt(e,g){var i=g9e(e);return function(I,n){return g(i(I),n,e)}}function qae(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 Sr(e,g){var i=e+"",I=i.length;return I9999?"+"+Sr(e,6):Sr(e,4)}function yMt(e){var g=e.getUTCHours(),i=e.getUTCMinutes(),I=e.getUTCSeconds(),n=e.getUTCMilliseconds();return isNaN(e)?"Invalid Date":bMt(e.getUTCFullYear())+"-"+Sr(e.getUTCMonth()+1,2)+"-"+Sr(e.getUTCDate(),2)+(n?"T"+Sr(g,2)+":"+Sr(i,2)+":"+Sr(I,2)+"."+Sr(n,3)+"Z":I?"T"+Sr(g,2)+":"+Sr(i,2)+":"+Sr(I,2)+"Z":i||g?"T"+Sr(g,2)+":"+Sr(i,2)+"Z":"")}function i9e(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?pMt(m,c):g9e(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)===hZ&&--d,l.charCodeAt(d-1)===ox&&--d;function y(){if(b)return rx;if(p)return p=!1,$ae;var B,G=h,v;if(l.charCodeAt(G)===Cx){for(;h++=d?b=!0:(v=l.charCodeAt(h++))===hZ?p=!0:v===ox&&(p=!0,l.charCodeAt(h)===hZ&&++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 H2(e){return H2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},H2(e)}let Nk=function(e){wMt(I,e);var g=VMt(I);function I({items:i}){var n;return GMt(this,I),n=g.call(this),n.state={items:i,isSorting:!1},n}return vMt(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:RAt(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,MJ({},this.props,o,{ref:a=>{this.ref=a}}))}}]),I}(N.Component);Nk.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};Nk.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 HMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Uae(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 T2(e){return T2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},T2(e)}let jWe=function(e){YMt(I,e);var g=KMt(I);function I(i){var n;return HMt(this,I),n=g.call(this,i),n.dragTopRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopRightFunc.bind(nn(n))),n.dragTopLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopLeftFunc.bind(nn(n))),n.dragBottomRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomRightFunc.bind(nn(n))),n.dragBottomLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomLeftFunc.bind(nn(n))),n.dragBottom=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomFunc.bind(nn(n))),n.dragTop=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopFunc.bind(nn(n))),n.dragLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragLeftFunc.bind(nn(n))),n.dragRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragRightFunc.bind(nn(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=dg("body").node(),n}return TMt(I,[{key:"componentDidMount",value:function(){dg(this.bottomHandle).call(this.dragBottom),dg(this.topHandle).call(this.dragTop),dg(this.leftHandle).call(this.dragLeft),dg(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=zg(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=zg(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=zg(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=zg(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=zg(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=zg(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=zg(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=zg(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=zg(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===gI?"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:Xg(this.props.className,CF["draggable-div"]),style:C},l)}}]),I}(N.Component);jWe.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 FMt=um(jWe);function EMt(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 N2(e){return N2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},N2(e)}let $We=function(e){JMt(I,e);var g=OMt(I);function I(i){var n;return EMt(this,I),n=g.call(this,i),n.state={controlsVisible:!1},n}return MMt(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=nz(()=>N.createElement("svg",{className:"no-zoom",height:"10px",onClick:()=>{},style:this.getMoveImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#move"}))):n=nz(()=>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=jI.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=jI.findDOMNode(this.imgClose).getBoundingClientRect();this.props.onCloseTrackMenuOpened(this.props.uid,r)},style:this.getCloseImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cross"})))}}]),I}(N.Component);$We.propTypes={configMenuOpen:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,uid:L.string};function QMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function jae(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 kk=function(e){e3t(I,e);var g=t3t(I);function I(i){var n;return QMt(this,I),n=g.call(this,i),n.moveable=!0,n}return jMt(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(FMt,{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}($We);kk.propTypes={className:L.string,uid:L.string,item:L.object,height:L.number,width:L.number};function n3t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $ae(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)}const MR={pointerEvents:"all"};let qWe=function(e){a3t(I,e);var g=A3t(I);function I(){return n3t(this,I),g.apply(this,arguments)}return C3t(I,[{key:"getControls",value:function(n){return N.createElement(bk,{configMenuVisible:this.props.item.configMenuVisible,imgStyleAdd:MR,imgStyleClose:MR,imgStyleMove:MR,imgStyleSettings:MR,isMoveable:this.moveable,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),I}(kk);const u3t=aGe(e=>N.createElement(qWe,{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 LJ(){return LJ=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",LJ({className:e,style:{height:o,width:a,background:"transparent"}},r),b)}),d3t={"horizontal-tiled-plot":"_horizontal-tiled-plot_1bqkg_1"};function h3t(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 K2(e){return K2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},K2(e)}function eAe(e){return e&&e.sourceEvent}let x2=function(e){b3t(I,e);var g=y3t(I);function I(i){var n;return h3t(this,I),n=g.call(this,i),n.brushBehavior=SN().on("start",n.brushStarted.bind(SW(n))).on("brush",n.brushed.bind(SW(n))).on("end",n.brushedEnded.bind(SW(n))),n}return m3t(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,kp(this.brushEl,Po["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!eAe(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!eAe(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($l,0),C=this.props.tracks.map(o=>F0(o)).reduce(_S,!1),r=this.props.isRangeSelectionActive?Po["track-range-selection-active"]:Po["track-range-selection"];return N.createElement("div",{className:Xg("horizontal-tiled-plot",d3t["horizontal-tiled-plot"])},C&&N.createElement("svg",{ref:o=>{this.brushEl=dg(o)},className:r,style:{height:n,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(Nk,{className:Xg(Jo.list,Jo.stylizedList),component:eXe,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:n,helperClass:Jo.stylizedHelper,itemClass:Jo.stylizedItem,itemReactClass:u3t,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||sg.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);x2.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 v3t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tAe(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)}const zR={pointerEvents:"all"};let tXe=function(e){V3t(I,e);var g=R3t(I);function I(){return v3t(this,I),g.apply(this,arguments)}return B3t(I,[{key:"getControls",value:function(n){return N.createElement(bk,{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}(kk);function T3t(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 s0(e){return s0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},s0(e)}let M3t=function(e){x3t(I,e);var g=D3t(I);function I(i,n){var C;T3t(this,I),C=g.call(this,i,n);const{registerViewportChanged:r,removeViewportChanged:o}=i,a=sg.nice();return C.uid=a,C.removeViewportChanged=o,C.viewportXDomain=null,C.viewportYDomain=null,r(a,C.viewportChanged.bind(gXe(C))),C}return N3t(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){wW(s0(I.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.draw()}}]),I}(fC);function IXe(e){this.size=0,this.limit=e,this._keymap={}}function z3t(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 P3t(){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 J3t(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 O3t(e){return this._keymap[e]}function _3t(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 L3t(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 U3t(){this.head=void 0,this.tail=void 0,this.size=0,this._keymap={}}function Q3t(){return Object.keys(this._keymap)}function j3t(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 $3t(){const e=[];let g=this.head;for(;g;)e.push({key:g.key.toJSON(),value:g.value.toJSON()}),g=g.newer;return e}function q3t(){let e="",g=this.head;for(;g;)e+=`${String(g.key)}:${g.value}`,g=g.newer,g&&(e+=" < ");return e}Object.assign(IXe.prototype,{put:z3t,get:J3t,find:O3t,keys:Q3t,set:_3t,shift:P3t,remove:L3t,removeAll:U3t,forEach:j3t,toJSON:$3t,toString:q3t});const iXe="1.13.3",ezt="_button_1wnjn_1",rF={button:ezt,"button-shortcut":"_button-shortcut_1wnjn_35"},Xs=N.forwardRef((e,g)=>N.createElement("button",{ref:g,className:rF[e.styleName]??rF.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:rF["button-shortcut"]},e.shortcut)));Xs.defaultProps={onClick:()=>{},styleName:"",type:"button"};Xs.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 tzt="_cross_2ke8w_1",gzt={cross:tzt};function nXe(){return N.createElement("div",{className:gzt.cross})}function $J(){return $J=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,I)=>N.createElement(izt,null,i=>N.createElement(e,$J({ref:I},g,{modal:i})))),nf={"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 F4(e){const g=()=>{e.modal.close(),e.onClose&&e.onClose()};return N.createElement("div",{className:Xg(nf["modal-background"],{[nf["modal-hide"]]:e.hide})},N.createElement("div",{className:nf["modal-wrap"]},N.createElement("div",{className:Xg(nf["modal-window"],{[nf["modal-window-max-height"]]:e.maxHeight})},e.closeButton&&N.createElement(Xs,{onClick:g},N.createElement(nXe,null)),N.createElement("div",{className:nf["modal-content"]},e.children))))}F4.defaultProps={closeButton:!0,hide:!1,maxHeight:!1};F4.propTypes={children:L.element.isRequired,closeButton:L.bool,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,onClose:L.func};const nzt=Yk(F4),oF={"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 E4(e){const g=()=>{e.modal.close(),e.onCancel&&e.onCancel()},I=()=>{e.modal.close(),e.onOkay&&e.onOkay()};return N.createElement(nzt,{closeButton:!1,hide:e.hide,maxHeight:e.maxHeight},N.createElement(N.Fragment,null,N.createElement("header",{className:oF["dialog-header"]},N.createElement("h3",null,e.title),N.createElement(Xs,{onClick:g},N.createElement(nXe,null))),e.maxHeight?N.createElement("main",{className:Xg(e.maxHeight&&oF["dialog-main-max-height"])},e.children):N.createElement("main",null,e.children),N.createElement("footer",{className:oF[e.maxHeight?"dialog-footer-max-height":"dialog-footer"]},e.okayOnly?N.createElement("div",null):N.createElement(Xs,{onClick:g,shortcut:e.cancelShortcut},e.cancelTitle),N.createElement(Xs,{onClick:I,shortcut:e.okayShortcut},e.okayTitle))))}E4.defaultProps={cancelTitle:"Cancel",hide:!1,maxHeight:!1,okayOnly:!1,okayTitle:"Ok"};E4.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=Yk(E4);var Pr={},Zw={},Czt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;const CXe=Czt;var rzt=typeof self=="object"&&self&&self.Object===Object&&self,ozt=CXe||rzt||Function("return this")();const Ga=ozt;var azt=Ga.Symbol;const SA=azt;var rXe=Object.prototype,Azt=rXe.hasOwnProperty,szt=rXe.toString,hZ=SA?SA.toStringTag:void 0;function lzt(e){var g=Azt.call(e,hZ),I=e[hZ];try{e[hZ]=void 0;var i=!0}catch{}var n=szt.call(e);return i&&(g?e[hZ]=I:delete e[hZ]),n}var czt=Object.prototype,uzt=czt.toString;function dzt(e){return uzt.call(e)}var hzt="[object Null]",mzt="[object Undefined]",IAe=SA?SA.toStringTag:void 0;function hu(e){return e==null?e===void 0?mzt:hzt:IAe&&IAe in Object(e)?lzt(e):dzt(e)}var fzt=Array.isArray;const uC=fzt;function ua(e){return e!=null&&typeof e=="object"}var pzt="[object String]";function bzt(e){return typeof e=="string"||!uC(e)&&ua(e)&&hu(e)==pzt}const yzt=Object.freeze(Object.defineProperty({__proto__:null,default:bzt},Symbol.toStringTag,{value:"Module"})),Zzt=qs(yzt);function Gzt(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 vzt=Gzt();const oXe=vzt;function Bzt(e,g){for(var I=-1,i=Array(e);++I-1&&e%1==0&&e-1&&e%1==0&&e<=Yzt}var Kzt="[object Arguments]",xzt="[object Array]",Dzt="[object Boolean]",Fzt="[object Date]",Ezt="[object Error]",Mzt="[object Function]",zzt="[object Map]",Pzt="[object Number]",Jzt="[object Object]",Ozt="[object RegExp]",_zt="[object Set]",Lzt="[object String]",Uzt="[object WeakMap]",Qzt="[object ArrayBuffer]",jzt="[object DataView]",$zt="[object Float32Array]",qzt="[object Float64Array]",ePt="[object Int8Array]",tPt="[object Int16Array]",gPt="[object Int32Array]",IPt="[object Uint8Array]",iPt="[object Uint8ClampedArray]",nPt="[object Uint16Array]",CPt="[object Uint32Array]",hI={};hI[$zt]=hI[qzt]=hI[ePt]=hI[tPt]=hI[gPt]=hI[IPt]=hI[iPt]=hI[nPt]=hI[CPt]=!0;hI[Kzt]=hI[xzt]=hI[Qzt]=hI[Dzt]=hI[jzt]=hI[Fzt]=hI[Ezt]=hI[Mzt]=hI[zzt]=hI[Pzt]=hI[Jzt]=hI[Ozt]=hI[_zt]=hI[Lzt]=hI[Uzt]=!1;function rPt(e){return ua(e)&&z4(e.length)&&!!hI[hu(e)]}function P4(e){return function(g){return e(g)}}var sXe=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Hv=sXe&&typeof module=="object"&&module&&!module.nodeType&&module,oPt=Hv&&Hv.exports===sXe,aF=oPt&&CXe.process,aPt=function(){try{var e=Hv&&Hv.require&&Hv.require("util").types;return e||aF&&aF.binding&&aF.binding("util")}catch{}}();const l0=aPt;var rAe=l0&&l0.isTypedArray,APt=rAe?P4(rAe):rPt;const J4=APt;var sPt=Object.prototype,lPt=sPt.hasOwnProperty;function lXe(e,g){var I=uC(e),i=!I&&F2(e),n=!I&&!i&&gS(e),C=!I&&!i&&!n&&J4(e),r=I||i||n||C,o=r?Bzt(e.length,String):[],a=o.length;for(var s in e)(g||lPt.call(e,s))&&!(r&&(s=="length"||n&&(s=="offset"||s=="parent")||C&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||M4(s,a)))&&o.push(s);return o}var cPt=Object.prototype;function O4(e){var g=e&&e.constructor,I=typeof g=="function"&&g.prototype||cPt;return e===I}function cXe(e,g){return function(I){return e(g(I))}}var uPt=cXe(Object.keys,Object);const dPt=uPt;var hPt=Object.prototype,mPt=hPt.hasOwnProperty;function fPt(e){if(!O4(e))return dPt(e);var g=[];for(var I in Object(e))mPt.call(e,I)&&I!="constructor"&&g.push(I);return g}function pr(e){var g=typeof e;return e!=null&&(g=="object"||g=="function")}var pPt="[object AsyncFunction]",bPt="[object Function]",yPt="[object GeneratorFunction]",ZPt="[object Proxy]";function _4(e){if(!pr(e))return!1;var g=hu(e);return g==bPt||g==yPt||g==pPt||g==ZPt}function ay(e){return e!=null&&z4(e.length)&&!_4(e)}function Gw(e){return ay(e)?lXe(e):fPt(e)}function uXe(e,g){return e&&oXe(e,g,Gw)}function Kk(e){return e}function dXe(e){return typeof e=="function"?e:Kk}function GPt(e,g){return e&&uXe(e,dXe(g))}const vPt=Object.freeze(Object.defineProperty({__proto__:null,default:GPt},Symbol.toStringTag,{value:"Module"})),L4=qs(vPt);var BPt=cXe(Object.getPrototypeOf,Object);const U4=BPt;var SPt="[object Object]",wPt=Function.prototype,VPt=Object.prototype,hXe=wPt.toString,RPt=VPt.hasOwnProperty,WPt=hXe.call(Object);function mXe(e){if(!ua(e)||hu(e)!=SPt)return!1;var g=U4(e);if(g===null)return!0;var I=RPt.call(g,"constructor")&&g.constructor;return typeof I=="function"&&I instanceof I&&hXe.call(I)==WPt}const XPt=Object.freeze(Object.defineProperty({__proto__:null,default:mXe},Symbol.toStringTag,{value:"Module"})),HPt=qs(XPt);function fXe(e,g){for(var I=-1,i=e==null?0:e.length,n=Array(i);++I-1}function DPt(e,g){var I=this.__data__,i=xk(I,e);return i<0?(++this.size,I.push([e,g])):I[i][1]=g,this}function al(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&WJt?new E2:void 0;for(C.set(e,g),C.set(g,e);++l0&&arguments[0]!==void 0?arguments[0]:[],I=[];return(0,g_t.default)(g,function(i){Array.isArray(i)?e(i).map(function(n){return I.push(n)}):(0,e_t.default)(i)?(0,$Ot.default)(i,function(n,C){n===!0&&I.push(C),I.push(C+"-"+n)}):(0,QOt.default)(i)&&I.push(i)}),I};Zw.default=I_t;var Bw={};function RXe(e,g){for(var I=-1,i=e==null?0:e.length;++I1&&arguments[1]!==void 0?arguments[1]:[],i=g.default&&(0,YLt.default)(g.default)||{};return I.map(function(n){var C=g[n];return C&&(0,NLt.default)(C,function(r,o){i[o]||(i[o]={}),i[o]=KLt({},i[o],C[o])}),n}),i};Bw.default=xLt;var Vw={};Object.defineProperty(Vw,"__esModule",{value:!0});Vw.autoprefix=void 0;var DLt=L4,RAe=ELt(DLt),FLt=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){LLt(n,i);function n(){var C,r,o,a;_Lt(this,n);for(var s=arguments.length,A=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){eUt(n,i);function n(){var C,r,o,a;qLt(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};g$.default=gUt;Object.defineProperty(Pr,"__esModule",{value:!0});Pr.ReactCSS=Pr.loop=Pr.handleActive=I$=Pr.handleHover=Pr.hover=void 0;var IUt=Zw,iUt=Ay(IUt),nUt=Bw,CUt=Ay(nUt),rUt=Vw,oUt=Ay(rUt),aUt=Rw,EXe=Ay(aUt),AUt=Ww,sUt=Ay(AUt),lUt=g$,cUt=Ay(lUt);function Ay(e){return e&&e.__esModule?e:{default:e}}Pr.hover=EXe.default;var I$=Pr.handleHover=EXe.default;Pr.handleActive=sUt.default;Pr.loop=cUt.default;var uUt=Pr.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},uF={},hUt=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},mUt=function(g,I,i,n){var C=g+"-"+I+"-"+i+(n?"-server":"");if(uF[C])return uF[C];var r=hUt(g,I,i,n);return uF[C]=r,r},HAe=Object.assign||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 k2(e){return k2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},k2(e)}let Kk=function(e){NMt(i,e);var g=kMt(i);function i({items:I}){var n;return WMt(this,i),n=g.call(this),n.state={items:I,isSorting:!1},n}return XMt(i,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){this.setState({items:n.items})}},{key:"onSortStart",value:function({node:n,index:r,collection:C},o){o.stopImmediatePropagation();const{onSortStart:a}=this.props;this.setState({isSorting:!0}),a&&a(this.ref),this.sortingIndex=r,this.sortStartTop=o.offsetTop,this.sortStartLeft=o.offsetLeft}},{key:"onSortMove",value:function(){}},{key:"onSortEnd",value:function({oldIndex:n,newIndex:r}){const{onSortEnd:C}=this.props,{items:o}=this.state;this.setState({items:YAt(o,n,r),isSorting:!1}),C&&C(this.state.items),this.sortingIndex=null}},{key:"render",value:function(){const n=this.props.component,{items:r,isSorting:C}=this.state,o={isSorting:C,items:r,onSortEnd:this.onSortEnd.bind(this),onSortStart:this.onSortStart.bind(this),onSortMove:this.onSortMove.bind(this)};return N.createElement(n,_J({},this.props,o,{ref:a=>{this.ref=a}}))}}]),i}(N.Component);Kk.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};Kk.defaultProps={className:"list stylizedList",itemClass:"item stylizedItem",width:400,height:600};const ax={"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 DMt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tAe(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 n9e=function(e){zMt(i,e);var g=PMt(i);function i(I){var n;return DMt(this,i),n=g.call(this,I),n.dragTopRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopRightFunc.bind(nn(n))),n.dragTopLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopLeftFunc.bind(nn(n))),n.dragBottomRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomRightFunc.bind(nn(n))),n.dragBottomLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomLeftFunc.bind(nn(n))),n.dragBottom=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragBottomFunc.bind(nn(n))),n.dragTop=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragTopFunc.bind(nn(n))),n.dragLeft=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragLeftFunc.bind(nn(n))),n.dragRight=QA().on("start",n.dragStart.bind(nn(n))).on("drag",n.dragRightFunc.bind(nn(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=dg("body").node(),n}return xMt(i,[{key:"componentDidMount",value:function(){dg(this.bottomHandle).call(this.dragBottom),dg(this.topHandle).call(this.dragTop),dg(this.leftHandle).call(this.dragLeft),dg(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 r=zg(n,this.domBody);let C=this.dragStartHeight+(r[1]-this.dragStartMousePos[1]);C=C>this.minHeight?C:this.minHeight,this.setState({height:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragLeftFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartWidth-(r[0]-this.dragStartMousePos[0]);C=C>this.minWidth?C:this.minWidth;let o=this.dragStartLeft+r[0]-this.dragStartMousePos[0];o=C>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:o,width:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartHeight-(r[1]-this.dragStartMousePos[1]);C=C>this.minHeight?C:this.minHeight;let o=this.dragStartTop+r[1]-this.dragStartMousePos[1];o=C>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:o,height:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragRightFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartWidth+(r[0]-this.dragStartMousePos[0]);C=C>this.minWidth?C:this.minWidth,this.setState({width:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomLeftFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartHeight+(r[1]-this.dragStartMousePos[1]);C=C>this.minHeight?C:this.minHeight;let o=this.dragStartWidth-(r[0]-this.dragStartMousePos[0]);o=o>this.minWidth?o:this.minWidth;let a=this.dragStartLeft+r[0]-this.dragStartMousePos[0];a=o>this.minWidth?a:this.dragStartLeft+this.dragStartWidth-this.minWidth,this.setState({left:a,width:o,height:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragBottomRightFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartWidth+(r[0]-this.dragStartMousePos[0]);C=C>this.minWidth?C:this.minWidth;let o=this.dragStartHeight+(r[1]-this.dragStartMousePos[1]);o=o>this.minHeight?o:this.minHeight,this.setState({width:C,height:o}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopRightFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartHeight-(r[1]-this.dragStartMousePos[1]);C=C>this.minHeight?C:this.minHeight;let o=this.dragStartTop+r[1]-this.dragStartMousePos[1];o=C>this.minHeight?o:this.dragStartTop+this.dragStartHeight-this.minHeight;let a=this.dragStartWidth+(r[0]-this.dragStartMousePos[0]);a=a>this.minWidth?a:this.minWidth,this.setState({top:o,width:a,height:C}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragTopLeftFunc",value:function(n){const r=zg(n,this.domBody);let C=this.dragStartWidth-(r[0]-this.dragStartMousePos[0]);C=C>this.minWidth?C:this.minWidth;let o=this.dragStartLeft+r[0]-this.dragStartMousePos[0];o=C>this.minWidth?o:this.dragStartLeft+this.dragStartWidth-this.minWidth;let a=this.dragStartHeight-(r[1]-this.dragStartMousePos[1]);a=a>this.minHeight?a:this.minHeight;let s=this.dragStartTop+r[1]-this.dragStartMousePos[1];s=a>this.minHeight?s:this.dragStartTop+this.dragStartHeight-this.minHeight,this.setState({top:s,left:o,width:C,height:a}),n.sourceEvent.stopPropagation(),this.sizeChanged()}},{key:"dragStart",value:function(n){this.dragStartMousePos=zg(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===gi?"white":"black",r={top:this.state.top,left:this.state.left,width:this.state.width,height:this.state.height,opacity:this.props.opacity},C=24,o=24,a={left:this.state.width/2-C/2,width:C},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:ax[`${c}-draggable-handle`],style:A[c],title:"Resize track"},N.createElement("div",{className:ax[`${c}-draggable-handle-grabber`],style:{borderColor:n}})));return N.createElement("div",{ref:c=>{this.divContainer=c},className:Xg(this.props.className,ax["draggable-div"]),style:r},l)}}]),i}(N.Component);n9e.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 _Mt=cm(n9e);function LMt(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 K2(e){return K2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},K2(e)}let r9e=function(e){$Mt(i,e);var g=qMt(i);function i(I){var n;return LMt(this,i),n=g.call(this,I),n.state={controlsVisible:!1},n}return UMt(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=Az(()=>N.createElement("svg",{className:"no-zoom",height:"10px",onClick:()=>{},style:this.getMoveImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#move"}))):n=Az(()=>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:r=>{this.imgConfig=r},className:"no-zoom",height:"10px",onClick:()=>{const C=ji.findDOMNode(this.imgConfig).getBoundingClientRect();this.props.onConfigTrackMenuOpened(this.props.uid,C)},style:this.getSettingsImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cog"})),N.createElement("svg",{ref:r=>{this.imgAdd=r},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:r=>{this.imgClose=r},className:"no-zoom",height:"10px",onClick:()=>{const C=ji.findDOMNode(this.imgClose).getBoundingClientRect();this.props.onCloseTrackMenuOpened(this.props.uid,C)},style:this.getCloseImgStyle(),width:"10px"},N.createElement("use",{xlinkHref:"#cross"})))}}]),i}(N.Component);r9e.propTypes={configMenuOpen:L.bool,onConfigTrackMenuOpened:L.func,onCloseTrackMenuOpened:L.func,onAddSeries:L.func,uid:L.string};function i3t(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 F2(e){return F2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},F2(e)}let Fk=function(e){C3t(i,e);var g=o3t(i);function i(I){var n;return i3t(this,i),n=g.call(this,I),n.moveable=!0,n}return I3t(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(_Mt,{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}(r9e);Fk.propTypes={className:L.string,uid:L.string,item:L.object,height:L.number,width:L.number};function l3t(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)}const JV={pointerEvents:"all"};let C9e=function(e){h3t(i,e);var g=m3t(i);function i(){return l3t(this,i),g.apply(this,arguments)}return c3t(i,[{key:"getControls",value:function(n){return N.createElement(Gk,{configMenuVisible:this.props.item.configMenuVisible,imgStyleAdd:JV,imgStyleClose:JV,imgStyleMove:JV,imgStyleSettings:JV,isMoveable:this.moveable,isVisible:n,onAddSeries:this.props.onAddSeries,onCloseTrackMenuOpened:this.props.onCloseTrackMenuOpened,onConfigTrackMenuOpened:this.props.onConfigTrackMenuOpened,uid:this.props.uid})}}]),i}(Fk);const y3t=mGe(e=>N.createElement(C9e,{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 qJ(){return qJ=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:r,onCloseTrack:s,onCloseTrackMenuOpened:A,onConfigTrackMenuOpened:l,onAddSeries:c,handleConfigTrack:u,editable:d,handleResizeTrack:m,resizeHandles:f}));return N.createElement("div",qJ({className:e,style:{height:o,width:a,background:"transparent"}},C),b)}),Z3t={"horizontal-tiled-plot":"_horizontal-tiled-plot_1bqkg_1"};function G3t(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 x2(e){return x2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},x2(e)}function rAe(e){return e&&e.sourceEvent}let E2=function(e){w3t(i,e);var g=R3t(i);function i(I){var n;return G3t(this,i),n=g.call(this,I),n.brushBehavior=VN().on("start",n.brushStarted.bind(VW(n))).on("brush",n.brushed.bind(VW(n))).on("end",n.brushedEnded.bind(VW(n))),n}return v3t(i,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,r){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!==r):this.props.rangeSelection!==n.rangeSelection?(this.moveBrush(n.rangeSelection[0]?n.rangeSelection[0]:null,n.rangeSelectionEnd),this.state!==r):!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,Yp(this.brushEl,Po["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const r=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!rAe(n)||!this.props.onRangeSelection||r)&&(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 r=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!r&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,r=!1){if(!this.brushEl)return;const C=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,r?this.brushEl.transition().call(this.brushBehavior.move,C):this.brushEl.call(this.brushBehavior.move,C)}},{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($l,0),r=this.props.tracks.map(o=>E0(o)).reduce(QS,!1),C=this.props.isRangeSelectionActive?Po["track-range-selection-active"]:Po["track-range-selection"];return N.createElement("div",{className:Xg("horizontal-tiled-plot",Z3t["horizontal-tiled-plot"])},r&&N.createElement("svg",{ref:o=>{this.brushEl=dg(o)},className:C,style:{height:n,width:this.props.width},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(Kk,{className:Xg(Jo.list,Jo.stylizedList),component:o9e,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:n,helperClass:Jo.stylizedHelper,itemClass:Jo.stylizedItem,itemReactClass:y3t,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||sg.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);E2.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 X3t(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)}const OV={pointerEvents:"all"};let a9e=function(e){k3t(i,e);var g=Y3t(i);function i(){return X3t(this,i),g.apply(this,arguments)}return H3t(i,[{key:"getControls",value:function(n){return N.createElement(Gk,{imgStyleAdd:OV,imgStyleClose:OV,imgStyleMove:OV,imgStyleSettings:OV,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}(Fk);function x3t(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 l0(e){return l0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},l0(e)}let U3t=function(e){J3t(i,e);var g=O3t(i);function i(I,n){var r;x3t(this,i),r=g.call(this,I,n);const{registerViewportChanged:C,removeViewportChanged:o}=I,a=sg.nice();return r.uid=a,r.removeViewportChanged=o,r.viewportXDomain=null,r.viewportYDomain=null,C(a,r.viewportChanged.bind(A9e(r))),r}return E3t(i,[{key:"viewportChanged",value:function(n,r){const C=n.domain(),o=r.domain();this.viewportXDomain=C,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 r=this._xScale(this.viewportXDomain[0]),C=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(r,C,o,a)}},{key:"zoomed",value:function(n,r){this.xScale(n),this.yScale(r),this.draw()}},{key:"setPosition",value:function(n){WW(l0(i.prototype),"setPosition",this).call(this,n),this.pMain.position.y=this.position[1],this.pMain.position.x=this.position[0],this.draw()}}]),i}(mr);function s9e(e){this.size=0,this.limit=e,this._keymap={}}function Q3t(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 j3t(){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 $3t(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 q3t(e){return this._keymap[e]}function ezt(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 tzt(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 gzt(){this.head=void 0,this.tail=void 0,this.size=0,this._keymap={}}function izt(){return Object.keys(this._keymap)}function Izt(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 nzt(){const e=[];let g=this.head;for(;g;)e.push({key:g.key.toJSON(),value:g.value.toJSON()}),g=g.newer;return e}function rzt(){let e="",g=this.head;for(;g;)e+=`${String(g.key)}:${g.value}`,g=g.newer,g&&(e+=" < ");return e}Object.assign(s9e.prototype,{put:Q3t,get:$3t,find:q3t,keys:izt,set:ezt,shift:j3t,remove:tzt,removeAll:gzt,forEach:Izt,toJSON:nzt,toString:rzt});const l9e="1.13.3",Czt="_button_1wnjn_1",Ax={button:Czt,"button-shortcut":"_button-shortcut_1wnjn_35"},Xs=N.forwardRef((e,g)=>N.createElement("button",{ref:g,className:Ax[e.styleName]??Ax.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:Ax["button-shortcut"]},e.shortcut)));Xs.defaultProps={onClick:()=>{},styleName:"",type:"button"};Xs.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 ozt="_cross_2ke8w_1",azt={cross:ozt};function c9e(){return N.createElement("div",{className:azt.cross})}function iO(){return iO=Object.assign?Object.assign.bind():function(e){for(var g=1;gN.forwardRef((g,i)=>N.createElement(szt,null,I=>N.createElement(e,iO({ref:i},g,{modal:I})))),If={"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 Oj(e){const g=()=>{e.modal.close(),e.onClose&&e.onClose()};return N.createElement("div",{className:Xg(If["modal-background"],{[If["modal-hide"]]:e.hide})},N.createElement("div",{className:If["modal-wrap"]},N.createElement("div",{className:Xg(If["modal-window"],{[If["modal-window-max-height"]]:e.maxHeight})},e.closeButton&&N.createElement(Xs,{onClick:g},N.createElement(c9e,null)),N.createElement("div",{className:If["modal-content"]},e.children))))}Oj.defaultProps={closeButton:!0,hide:!1,maxHeight:!1};Oj.propTypes={children:L.element.isRequired,closeButton:L.bool,hide:L.bool,maxHeight:L.bool,modal:L.object.isRequired,onClose:L.func};const lzt=Dk(Oj),sx={"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 _j(e){const g=()=>{e.modal.close(),e.onCancel&&e.onCancel()},i=()=>{e.modal.close(),e.onOkay&&e.onOkay()};return N.createElement(lzt,{closeButton:!1,hide:e.hide,maxHeight:e.maxHeight},N.createElement(N.Fragment,null,N.createElement("header",{className:sx["dialog-header"]},N.createElement("h3",null,e.title),N.createElement(Xs,{onClick:g},N.createElement(c9e,null))),e.maxHeight?N.createElement("main",{className:Xg(e.maxHeight&&sx["dialog-main-max-height"])},e.children):N.createElement("main",null,e.children),N.createElement("footer",{className:sx[e.maxHeight?"dialog-footer-max-height":"dialog-footer"]},e.okayOnly?N.createElement("div",null):N.createElement(Xs,{onClick:g,shortcut:e.cancelShortcut},e.cancelTitle),N.createElement(Xs,{onClick:i,shortcut:e.okayShortcut},e.okayTitle))))}_j.defaultProps={cancelTitle:"Cancel",hide:!1,maxHeight:!1,okayOnly:!1,okayTitle:"Ok"};_j.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 vw=Dk(_j);var zC={},Bw={},czt=typeof globalThis=="object"&&globalThis&&globalThis.Object===Object&&globalThis;const u9e=czt;var uzt=typeof self=="object"&&self&&self.Object===Object&&self,dzt=u9e||uzt||Function("return this")();const Ga=dzt;var hzt=Ga.Symbol;const SA=hzt;var d9e=Object.prototype,mzt=d9e.hasOwnProperty,fzt=d9e.toString,mZ=SA?SA.toStringTag:void 0;function pzt(e){var g=mzt.call(e,mZ),i=e[mZ];try{e[mZ]=void 0;var I=!0}catch{}var n=fzt.call(e);return I&&(g?e[mZ]=i:delete e[mZ]),n}var bzt=Object.prototype,yzt=bzt.toString;function Zzt(e){return yzt.call(e)}var Gzt="[object Null]",vzt="[object Undefined]",aAe=SA?SA.toStringTag:void 0;function du(e){return e==null?e===void 0?vzt:Gzt:aAe&&aAe in Object(e)?pzt(e):Zzt(e)}var Bzt=Array.isArray;const cr=Bzt;function ua(e){return e!=null&&typeof e=="object"}var Szt="[object String]";function wzt(e){return typeof e=="string"||!cr(e)&&ua(e)&&du(e)==Szt}const Rzt=Object.freeze(Object.defineProperty({__proto__:null,default:wzt},Symbol.toStringTag,{value:"Module"})),Vzt=qs(Rzt);function Wzt(e){return function(g,i,I){for(var n=-1,r=Object(g),C=I(g),o=C.length;o--;){var a=C[e?o:++n];if(i(r[a],a,r)===!1)break}return g}}var Xzt=Wzt();const h9e=Xzt;function Hzt(e,g){for(var i=-1,I=Array(e);++i-1&&e%1==0&&e-1&&e%1==0&&e<=zzt}var Pzt="[object Arguments]",Jzt="[object Array]",Ozt="[object Boolean]",_zt="[object Date]",Lzt="[object Error]",Uzt="[object Function]",Qzt="[object Map]",jzt="[object Number]",$zt="[object Object]",qzt="[object RegExp]",ePt="[object Set]",tPt="[object String]",gPt="[object WeakMap]",iPt="[object ArrayBuffer]",IPt="[object DataView]",nPt="[object Float32Array]",rPt="[object Float64Array]",CPt="[object Int8Array]",oPt="[object Int16Array]",aPt="[object Int32Array]",APt="[object Uint8Array]",sPt="[object Uint8ClampedArray]",lPt="[object Uint16Array]",cPt="[object Uint32Array]",hi={};hi[nPt]=hi[rPt]=hi[CPt]=hi[oPt]=hi[aPt]=hi[APt]=hi[sPt]=hi[lPt]=hi[cPt]=!0;hi[Pzt]=hi[Jzt]=hi[iPt]=hi[Ozt]=hi[IPt]=hi[_zt]=hi[Lzt]=hi[Uzt]=hi[Qzt]=hi[jzt]=hi[$zt]=hi[qzt]=hi[ePt]=hi[tPt]=hi[gPt]=!1;function uPt(e){return ua(e)&&Uj(e.length)&&!!hi[du(e)]}function Qj(e){return function(g){return e(g)}}var p9e=typeof exports=="object"&&exports&&!exports.nodeType&&exports,Hv=p9e&&typeof module=="object"&&module&&!module.nodeType&&module,dPt=Hv&&Hv.exports===p9e,lx=dPt&&u9e.process,hPt=function(){try{var e=Hv&&Hv.require&&Hv.require("util").types;return e||lx&&lx.binding&&lx.binding("util")}catch{}}();const c0=hPt;var cAe=c0&&c0.isTypedArray,mPt=cAe?Qj(cAe):uPt;const jj=mPt;var fPt=Object.prototype,pPt=fPt.hasOwnProperty;function b9e(e,g){var i=cr(e),I=!i&&z2(e),n=!i&&!I&&nS(e),r=!i&&!I&&!n&&jj(e),C=i||I||n||r,o=C?Hzt(e.length,String):[],a=o.length;for(var s in e)(g||pPt.call(e,s))&&!(C&&(s=="length"||n&&(s=="offset"||s=="parent")||r&&(s=="buffer"||s=="byteLength"||s=="byteOffset")||Lj(s,a)))&&o.push(s);return o}var bPt=Object.prototype;function $j(e){var g=e&&e.constructor,i=typeof g=="function"&&g.prototype||bPt;return e===i}function y9e(e,g){return function(i){return e(g(i))}}var yPt=y9e(Object.keys,Object);const ZPt=yPt;var GPt=Object.prototype,vPt=GPt.hasOwnProperty;function BPt(e){if(!$j(e))return ZPt(e);var g=[];for(var i in Object(e))vPt.call(e,i)&&i!="constructor"&&g.push(i);return g}function fC(e){var g=typeof e;return e!=null&&(g=="object"||g=="function")}var SPt="[object AsyncFunction]",wPt="[object Function]",RPt="[object GeneratorFunction]",VPt="[object Proxy]";function qj(e){if(!fC(e))return!1;var g=du(e);return g==wPt||g==RPt||g==SPt||g==VPt}function Ay(e){return e!=null&&Uj(e.length)&&!qj(e)}function Sw(e){return Ay(e)?b9e(e):BPt(e)}function Z9e(e,g){return e&&h9e(e,g,Sw)}function xk(e){return e}function G9e(e){return typeof e=="function"?e:xk}function WPt(e,g){return e&&Z9e(e,G9e(g))}const XPt=Object.freeze(Object.defineProperty({__proto__:null,default:WPt},Symbol.toStringTag,{value:"Module"})),e$=qs(XPt);var HPt=y9e(Object.getPrototypeOf,Object);const t$=HPt;var TPt="[object Object]",NPt=Function.prototype,kPt=Object.prototype,v9e=NPt.toString,YPt=kPt.hasOwnProperty,KPt=v9e.call(Object);function B9e(e){if(!ua(e)||du(e)!=TPt)return!1;var g=t$(e);if(g===null)return!0;var i=YPt.call(g,"constructor")&&g.constructor;return typeof i=="function"&&i instanceof i&&v9e.call(i)==KPt}const FPt=Object.freeze(Object.defineProperty({__proto__:null,default:B9e},Symbol.toStringTag,{value:"Module"})),DPt=qs(FPt);function S9e(e,g){for(var i=-1,I=e==null?0:e.length,n=Array(I);++i-1}function OPt(e,g){var i=this.__data__,I=Ek(i,e);return I<0?(++this.size,i.push([e,g])):i[I][1]=g,this}function al(e){var g=-1,i=e==null?0:e.length;for(this.clear();++go))return!1;var s=r.get(e),A=r.get(g);if(s&&A)return s==g&&A==e;var l=-1,c=!0,u=i&KJt?new P2:void 0;for(r.set(e,g),r.set(g,e);++l0&&arguments[0]!==void 0?arguments[0]:[],i=[];return(0,a_t.default)(g,function(I){Array.isArray(I)?e(I).map(function(n){return i.push(n)}):(0,C_t.default)(I)?(0,n_t.default)(I,function(n,r){n===!0&&i.push(r),i.push(r+"-"+n)}):(0,i_t.default)(I)&&i.push(I)}),i};Bw.default=A_t;var Rw={};function K9e(e,g){for(var i=-1,I=e==null?0:e.length;++i1&&arguments[1]!==void 0?arguments[1]:[],I=g.default&&(0,zLt.default)(g.default)||{};return i.map(function(n){var r=g[n];return r&&(0,ELt.default)(r,function(C,o){I[o]||(I[o]={}),I[o]=PLt({},I[o],r[o])}),n}),I};Rw.default=JLt;var Xw={};Object.defineProperty(Xw,"__esModule",{value:!0});Xw.autoprefix=void 0;var OLt=e$,kAe=LLt(OLt),_Lt=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(I){tUt(n,I);function n(){var r,C,o,a;eUt(this,n);for(var s=arguments.length,A=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:"span";return function(I){CUt(n,I);function n(){var r,C,o,a;rUt(this,n);for(var s=arguments.length,A=Array(s),l=0;l1&&arguments[1]!==void 0?arguments[1]:!0;I[C]=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};o$.default=aUt;Object.defineProperty(zC,"__esModule",{value:!0});zC.ReactCSS=zC.loop=zC.handleActive=a$=zC.handleHover=zC.hover=void 0;var AUt=Bw,sUt=sy(AUt),lUt=Rw,cUt=sy(lUt),uUt=Xw,dUt=sy(uUt),hUt=Hw,U9e=sy(hUt),mUt=Tw,fUt=sy(mUt),pUt=o$,bUt=sy(pUt);function sy(e){return e&&e.__esModule?e:{default:e}}zC.hover=U9e.default;var a$=zC.handleHover=U9e.default;zC.handleActive=fUt.default;zC.loop=bUt.default;var yUt=zC.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>C?u=1:u=Math.round(A*100/C)/100,n!==u)return{h:i.h,s:i.s,l:i.l,a:u,source:"rgb"}}return null},mx={},GUt=function(g,i,I,n){if(typeof document>"u"&&!n)return null;var r=n?new n:document.createElement("canvas");r.width=I*2,r.height=I*2;var C=r.getContext("2d");return C?(C.fillStyle=g,C.fillRect(0,0,r.width,r.height),C.fillStyle=i,C.fillRect(0,0,I,I),C.translate(I,I),C.fillRect(0,0,I,I),r.toDataURL()):null},vUt=function(g,i,I,n){var r=g+"-"+i+"-"+I+(n?"-server":"");if(mx[r])return mx[r];var C=GUt(g,i,I,n);return mx[r]=C,C},FAe=Object.assign||function(e){for(var g=1;g-1},XUt=function(g){return Number(String(g).replace(/%/g,""))},HUt=1,Bg=function(e){SUt(g,e);function g(I){vUt(this,g);var i=BUt(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=XUt(n.target.value);if(!isNaN(C)&&WUt(n.keyCode)){var r=i.getArrowOffset(),o=n.keyCode===MXe?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-"+HUt++,i}return ZUt(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 GUt({},this.props.label,i)}},{key:"getArrowOffset",value:function(){return this.props.arrowOffset||wUt}},{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=jt({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}(U.PureComponent||U.Component),TUt=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},NUt=function(){function e(g,I){for(var i=0;i-1},FUt=function(g){return Number(String(g).replace(/%/g,""))},DUt=1,Bg=function(e){TUt(g,e);function g(i){XUt(this,g);var I=HUt(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 r=FUt(n.target.value);if(!isNaN(r)&&KUt(n.keyCode)){var C=I.getArrowOffset(),o=n.keyCode===Q9e?r+C:r-C;I.setUpdatedValue(o,n)}},I.handleDrag=function(n){if(I.props.dragLabel){var r=Math.round(I.props.value+n.movementX);r>=0&&r<=I.props.dragMax&&I.props.onChange&&I.props.onChange(I.getValueObjectWithLabel(r),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-"+DUt++,I}return VUt(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 WUt({},this.props.label,I)}},{key:"getArrowOffset",value:function(){return this.props.arrowOffset||NUt}},{key:"setUpdatedValue",value:function(I,n){var r=this.props.label?this.getValueObjectWithLabel(I):I;this.props.onChange&&this.props.onChange(r,n),this.setState({value:I})}},{key:"render",value:function(){var I=this,n=jt({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(C){return I.input=C},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}(U.PureComponent||U.Component),xUt=function(g,i,I,n){var r=n.clientWidth,C=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>C)l=0;else{var c=-(A*100/C)+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>r)u=359;else{var d=s*100/r;u=360*d/100}if(I.h!==u)return{h:u,s:I.s,l:I.l,a:I.a,source:"hsl"}}return null},EUt=function(){function e(g,i){for(var I=0;I0){if(++g>=JUt)return arguments[0]}else g=0;return e.apply(void 0,arguments)}}var UUt=LUt(PUt);const QUt=UUt;function jUt(e,g){return QUt(EUt(e,g,Kk),e+"")}function $Ut(e,g,I){if(!pr(I))return!1;var i=typeof g;return(i=="number"?ay(I)&&M4(g,I.length):i=="string"&&g in I)?vw(I[g],e):!1}function qUt(e){return jUt(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&&$Ut(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=dF();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(dF())}function Z(){var B=dF(),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 c7t="Expected a function";function u7t(e,g,I){var i=!0,n=!0;if(typeof e!="function")throw new TypeError(c7t);return pr(I)&&(i="leading"in I?!!I.leading:i,n="trailing"in I?!!I.trailing:n),PXe(e,g,{leading:i,maxWait:g,trailing:n})}var d7t=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"}},h7t=function(){function e(g,I){for(var i=0;i0){if(++g>=$Ut)return arguments[0]}else g=0;return e.apply(void 0,arguments)}}var g7t=t7t(jUt);const i7t=g7t;function I7t(e,g){return i7t(LUt(e,g,xk),e+"")}function n7t(e,g,i){if(!fC(i))return!1;var I=typeof g;return(I=="number"?Ay(i)&&Lj(g,i.length):I=="string"&&g in i)?ww(i[g],e):!1}function r7t(e){return I7t(function(g,i){var I=-1,n=i.length,r=n>1?i[n-1]:void 0,C=n>2?i[2]:void 0;for(r=e.length>3&&typeof r=="function"?(n--,r):void 0,C&&n7t(i[0],i[1],C)&&(r=n<3?void 0:r,n=1),g=Object(g);++I=g||G<0||l&&v>=r}function f(){var B=fx();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,C)}function p(){o!==void 0&&clearTimeout(o),s=0,I=a=n=o=void 0}function y(){return o===void 0?C:b(fx())}function Z(){var B=fx(),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)),C}return Z.cancel=p,Z.flush=y,Z}var b7t="Expected a function";function y7t(e,g,i){var I=!0,n=!0;if(typeof e!="function")throw new TypeError(b7t);return fC(i)&&(I="leading"in i?!!i.leading:I,n="trailing"in i?!!i.trailing:n),$9e(e,g,{leading:I,maxWait:g,trailing:n})}var Z7t=function(g,i,I){var n=I.getBoundingClientRect(),r=n.width,C=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>r&&(s=r),A<0?A=0:A>C&&(A=C);var l=s/r,c=1-A/C;return{h:i.h,s:l,v:c,a:i.a,source:"hsv"}},G7t=function(){function e(g,i){for(var I=0;I=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(X7t,arguments)},brighten:function(){return this._applyModification(H7t,arguments)},darken:function(){return this._applyModification(T7t,arguments)},desaturate:function(){return this._applyModification(V7t,arguments)},saturate:function(){return this._applyModification(R7t,arguments)},greyscale:function(){return this._applyModification(W7t,arguments)},spin:function(){return this._applyModification(N7t,arguments)},_applyCombination:function(g,I){return g.apply(null,[this].concat([].slice.call(I)))},analogous:function(){return this._applyCombination(K7t,arguments)},complement:function(){return this._applyCombination(k7t,arguments)},monochromatic:function(){return this._applyCombination(x7t,arguments)},splitcomplement:function(){return this._applyCombination(Y7t,arguments)},triad:function(){return this._applyCombination(MAe,[3])},tetrad:function(){return this._applyCombination(MAe,[4])}};Nt.fromRatio=function(e,g){if(P2(e)=="object"){var I={};for(var i in e)e.hasOwnProperty(i)&&(i==="a"?I[i]=e[i]:I[i]=sG(e[i]));e=I}return Nt(e,g)};function G7t(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=z7t(e)),P2(e)=="object"&&(OA(e.r)&&OA(e.g)&&OA(e.b)?(g=v7t(e.r,e.g,e.b),r=!0,o=String(e.r).substr(-1)==="%"?"prgb":"rgb"):OA(e.h)&&OA(e.s)&&OA(e.v)?(i=sG(e.s),n=sG(e.v),g=S7t(e.h,i,n),r=!0,o="hsv"):OA(e.h)&&OA(e.s)&&OA(e.l)&&(i=sG(e.s),C=sG(e.l),g=B7t(e.h,i,C),r=!0,o="hsl"),e.hasOwnProperty("a")&&(I=e.a)),I=JXe(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 v7t(e,g,I){return{r:VI(e,255)*255,g:VI(g,255)*255,b:VI(I,255)*255}}function xAe(e,g,I){e=VI(e,255),g=VI(g,255),I=VI(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 DAe(e,g,I){e=VI(e,255),g=VI(g,255),I=VI(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 x7t(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=P7t(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 CO=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"},D7t=Nt.hexNames=F7t(CO);function F7t(e){var g={};for(var I in e)e.hasOwnProperty(I)&&(g[e[I]]=I);return g}function JXe(e){return e=parseFloat(e),(isNaN(e)||e<0||e>1)&&(e=1),e}function VI(e,g){E7t(e)&&(e="100%");var I=M7t(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 Pk(e){return Math.min(1,Math.max(0,e))}function $C(e){return parseInt(e,16)}function E7t(e){return typeof e=="string"&&e.indexOf(".")!=-1&&parseFloat(e)===1}function M7t(e){return typeof e=="string"&&e.indexOf("%")!=-1}function qo(e){return e.length==1?"0"+e:""+e}function sG(e){return e<=1&&(e=e*100+"%"),e}function OXe(e){return Math.round(parseFloat(e)*255).toString(16)}function zAe(e){return $C(e)/255}var Yo=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 OA(e){return!!Yo.CSS_UNIT.exec(e)}function z7t(e){e=e.replace(y7t,"").replace(Z7t,"").toLowerCase();var g=!1;if(CO[e])e=CO[e],g=!0;else if(e=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var I;return(I=Yo.rgb.exec(e))?{r:I[1],g:I[2],b:I[3]}:(I=Yo.rgba.exec(e))?{r:I[1],g:I[2],b:I[3],a:I[4]}:(I=Yo.hsl.exec(e))?{h:I[1],s:I[2],l:I[3]}:(I=Yo.hsla.exec(e))?{h:I[1],s:I[2],l:I[3],a:I[4]}:(I=Yo.hsv.exec(e))?{h:I[1],s:I[2],v:I[3]}:(I=Yo.hsva.exec(e))?{h:I[1],s:I[2],v:I[3],a:I[4]}:(I=Yo.hex8.exec(e))?{r:$C(I[1]),g:$C(I[2]),b:$C(I[3]),a:zAe(I[4]),format:g?"name":"hex8"}:(I=Yo.hex6.exec(e))?{r:$C(I[1]),g:$C(I[2]),b:$C(I[3]),format:g?"name":"hex"}:(I=Yo.hex4.exec(e))?{r:$C(I[1]+""+I[1]),g:$C(I[2]+""+I[2]),b:$C(I[3]+""+I[3]),a:zAe(I[4]+""+I[4]),format:g?"name":"hex8"}:(I=Yo.hex3.exec(e))?{r:$C(I[1]+""+I[1]),g:$C(I[2]+""+I[2]),b:$C(I[3]+""+I[3]),format:g?"name":"hex"}:!1}function P7t(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 PAe=function(g){var I=["r","g","b","a","h","s","l","v"],i=0,n=0;return b7t(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},lG=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}},fu=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()},n$=function(g){if(!g)return"#fff";var I=lG(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"},hF=function(g,I){var i=g.replace("°","");return Nt(I+" ("+i+")")._ok},mZ=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(i){$7t(n,i);function n(){var C,r,o,a;j7t(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 JR=24,aQt=UXe.default=function(e){var g=e.fill,I=g===void 0?"currentColor":g,i=e.width,n=i===void 0?JR:i,C=e.height,r=C===void 0?JR:C,o=e.style,a=o===void 0?{}:o,s=oQt(e,["fill","width","height","style"]);return UAe.default.createElement("svg",LAe({viewBox:"0 0 "+JR+" "+JR,style:LAe({fill:I,width:n,height:r},a)},s),UAe.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"}))},AQt=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(_Ae(n.s)?i.props.hsl.s:n.s),l:Number(_Ae(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 AQt(g,[{key:"render",value:function(){var i=this,n=jt({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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(Bg,{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(aQt,{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);QXe.defaultProps={view:"hex"};var QAe=function(){var g=jt({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})},uQt=function(){var g=jt({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})},o$=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=jt(_C({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(zk,{style:h.Saturation,hsl:r,hsv:o,pointer:uQt,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(sy,{renderers:s}))),N.createElement("div",{style:h.toggles},N.createElement("div",{style:h.hue},N.createElement(ly,{style:h.Hue,hsl:r,pointer:QAe,onChange:i})),N.createElement("div",{style:h.alpha},N.createElement(i$,{style:h.Alpha,rgb:C,hsl:r,pointer:QAe,renderers:s,onChange:i})))),N.createElement(QXe,{rgb:C,hsl:r,hex:a,view:d,onChange:i,disableAlpha:n})))};o$.propTypes={width:L.oneOfType([L.string,L.number]),disableAlpha:L.bool,styles:L.object,defaultView:L.oneOf(["hex","rgb","hsl"])};o$.defaultProps={width:225,disableAlpha:!1,styles:{}};LC(o$);var dQt=function(g){var I=g.color,i=g.onClick,n=i===void 0?function(){}:i,C=g.onSwatchHover,r=g.active,o=jt({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:n$(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(Zm,{style:o.color,color:I,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:o.dot}))},hQt=function(g){var I=g.hex,i=g.rgb,n=g.onChange,C=jt({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(Bg,{style:{wrap:C.HEXwrap,input:C.HEXinput,label:C.HEXlabel},label:"hex",value:I,onChange:r}),N.createElement(Bg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"r",value:i.r,onChange:r}),N.createElement(Bg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"g",value:i.g,onChange:r}),N.createElement(Bg,{style:{wrap:C.RGBwrap,input:C.RGBinput,label:C.RGBlabel},label:"b",value:i.b,onChange:r}))},a$=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=jt(_C({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?fu(d.hex)&&I({hex:d.hex,source:"hex"},h):I(d,h)};return N.createElement(Xw,{style:l.Compact,styles:a},N.createElement("div",{style:l.compact,className:"compact-picker "+A},N.createElement("div",null,mu(n,function(u){return N.createElement(dQt,{key:u,color:u,active:u.toLowerCase()===C,onClick:c,onSwatchHover:i})}),N.createElement("div",{style:l.clear})),N.createElement(hQt,{hex:C,rgb:r,onChange:c})))};a$.propTypes={colors:L.arrayOf(L.string),styles:L.object};a$.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:{}};LC(a$);var mQt=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=jt({default:{swatch:{width:"25px",height:"25px",fontSize:"0"}},hover:{swatch:r}},{hover:I});return N.createElement("div",{style:o.swatch},N.createElement(Zm,{color:i,onClick:n,onHover:C,focusStyle:r}))};const fQt=I$(mQt);var A$=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=jt(_C({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}),mu(i,function(u){return N.createElement(fQt,{color:u,key:u,onClick:c,onSwatchHover:C})}))};A$.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};A$.defaultProps={width:200,colors:["#B80000","#DB3E00","#FCCB00","#008B02","#006B76","#1273DE","#004DCF","#5300EB","#EB9694","#FAD0C3","#FEF3BD","#C1E1C5","#BEDADC","#C4DEF6","#BED3F3","#D4C4FB"],triangle:"top-left",styles:{}};LC(A$);var pQt=function(g){var I=g.direction,i=jt({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})},bQt=Object.assign||function(e){for(var g=1;g.5});return N.createElement("div",{style:i.picker})},vQt=function(){var g=jt({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})))},jAe=function(g){var I=g.onClick,i=g.label,n=g.children,C=g.active,r=jt({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)},BQt=function(g){var I=g.rgb,i=g.currentColor,n=jt({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"))},SQt=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(Bg,{style:{input:o.input,label:o.label},label:"hex",value:C.replace("#",""),onChange:a})),N.createElement("div",{style:o.single},N.createElement(Bg,{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(Bg,{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(Bg,{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(Bg,{style:{input:o.input,label:o.label},label:"a",value:Math.round(i.a*100),onChange:a,dragLabel:"true",dragMax:"100"})))},XQt=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}var OR=24,DQt=$Xe.default=function(e){var g=e.fill,I=g===void 0?"currentColor":g,i=e.width,n=i===void 0?OR:i,C=e.height,r=C===void 0?OR:C,o=e.style,a=o===void 0?{}:o,s=xQt(e,["fill","width","height","style"]);return qAe.default.createElement("svg",$Ae({viewBox:"0 0 "+OR+" "+OR,style:$Ae({fill:I,width:n,height:r},a)},s),qAe.default.createElement("path",{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}))},FQt=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=jt({default:{color:{width:"40px",height:"24px",cursor:"pointer",background:I,marginBottom:"1px"},check:{color:n$(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(Zm,{color:I,style:s.color,onClick:n,onHover:C,focusStyle:{boxShadow:"0 0 4px "+I}},N.createElement("div",{style:s.check},N.createElement(DQt,null)))},EQt=function(g){var I=g.onClick,i=g.onSwatchHover,n=g.group,C=g.active,r=jt({default:{group:{paddingBottom:"10px",width:"40px",float:"left",marginRight:"10px"}}});return N.createElement("div",{style:r.group},mu(n,function(o,a){return N.createElement(FQt,{key:o,color:o,active:o.toLowerCase()===C,first:a===0,last:a===n.length-1,onClick:I,onSwatchHover:i})}))},d$=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=jt(_C({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(Xw,null,N.createElement("div",{style:c.overflow},N.createElement("div",{style:c.body},mu(r,function(d){return N.createElement(EQt,{key:d.toString(),group:d,active:o,onClick:u,onSwatchHover:C})}),N.createElement("div",{style:c.clear})))))};d$.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};d$.defaultProps={width:320,height:240,colors:[[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]],[Wf[900],Wf[700],Wf[500],Wf[300],Wf[100]],[Xf[900],Xf[700],Xf[500],Xf[300],Xf[100]],["#194D33",cG[700],cG[500],cG[300],cG[100]],[Hf[900],Hf[700],Hf[500],Hf[300],Hf[100]],[Tf[900],Tf[700],Tf[500],Tf[300],Tf[100]],[Nf[900],Nf[700],Nf[500],Nf[300],Nf[100]],[kf[900],kf[700],kf[500],kf[300],kf[100]],[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]],["#000000","#525252","#969696","#D9D9D9","#FFFFFF"]],styles:{}};LC(d$);var h$=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=jt(_C({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){fu(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},mu(C,function(d,h){return N.createElement(Zm,{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(Bg,{label:null,style:{input:c.input},value:n.replace("#",""),onChange:u}),N.createElement("div",{style:c.clear})))};h$.propTypes={width:L.oneOfType([L.string,L.number]),triangle:L.oneOf(["hide","top-left","top-right"]),colors:L.arrayOf(L.string),styles:L.object};h$.defaultProps={width:276,colors:["#FF6900","#FCB900","#7BDCB5","#00D084","#8ED1FC","#0693E3","#ABB8C3","#EB144C","#F78DA7","#9900EF"],triangle:"top-left",styles:{}};LC(h$);var m$=function(g){var I=jt({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})};m$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};m$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var f$=function(g){var I=jt({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})};f$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};f$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var MQt=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)fu(u.hex)&&I({hex:u.hex,source:"hex"},d);else if(u.rgb){var h=u.rgb.split(",");hF(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(",");hF(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(",");hF(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=jt({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(Bg,{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(Bg,{style:{input:a.input2,label:a.label2},label:"rgb",value:s,onChange:o})),N.createElement("div",{style:a.single},N.createElement(Bg,{style:{input:a.input2,label:a.label2},label:"hsv",value:l,onChange:o})),N.createElement("div",{style:a.single},N.createElement(Bg,{style:{input:a.input2,label:a.label2},label:"hsl",value:A,onChange:o})))))},p$=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=jt(_C({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(zk,{hsl:C,hsv:r,pointer:m$,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(ly,{style:u.Hue,hsl:C,radius:"4px",pointer:f$,onChange:i}))),N.createElement(MQt,{rgb:n,hsl:C,hex:o,hsv:r,onChange:i})))};p$.propTypes={width:L.oneOfType([L.string,L.number]),styles:L.object,header:L.string};p$.defaultProps={width:652,styles:{},header:"Color picker"};LC(p$);function zQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ese(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 qXe=function(e){_Qt(I,e);var g=LQt(I);function I(i){var n;zQt(this,I),n=g.call(this,i);const C=Bb(i.color);return n.state={displayColorPicker:!1,color:{r:C.r,g:C.g,b:C.b,a:C.opacity}},n}return PQt(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=jt({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(TQt,{color:this.state.color,onChange:this.handleChange.bind(this)})):null)}}]),I}(N.Component);qXe.propTypes={color:L.string,onChange:L.func};function $Qt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function tse(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 aO=function(e){gjt(I,e);var g=Ijt(I);function I(i){var n;return $Qt(this,I),n=g.call(this,i),n.state={colors:i.track.options.colorRange.slice()},n}return qQt(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(qXe,{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(uy,{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);aO.propTypes={handleCancel:L.func,onCancel:L.func,onSubmit:L.func,track:L.object,xScale:L.object,yScale:L.object};const gse=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),{}),QC={yes:{name:"Yes",value:!0},no:{name:"No",value:!1}},NI={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"}},rjt={use_stroke:{name:"Glyph color",value:"[glyph-color]"}},uG=c0([1,2,3,5,8,13,21]),ojt=Object.assign(uG,{none:{name:"none",value:"none"}}),_R=c0([0,2,4,8,16,32,64,128,256]),Sl=c0([0,.2,.4,.6,.8,1],"%",100),ajt=c0([.2,.4,.6,.8,1],"%",100),an={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:_R},labelRightMargin:{name:"Label Right Margin",inlineOptions:_R},labelTopMargin:{name:"Label Top Margin",inlineOptions:_R},labelBottomMargin:{name:"Label Bottom Margin",inlineOptions:_R},labelShowResolution:{name:"Label Show Resolution",inlineOptions:QC},labelShowAssembly:{name:"Label Show Assembly",inlineOptions:QC},lineStrokeWidth:{name:"Stroke Width",inlineOptions:uG},strokeWidth:{name:"Stroke Width",inlineOptions:uG},trackBorderWidth:{name:"Track Border Width",inlineOptions:uG},separatePlusMinusStrands:{name:"Separate +/- strands",inlineOptions:QC},sortLargestOnTop:{name:"Sort Largest On Top",inlineOptions:QC},showTexts:{name:"Show texts",inlineOptions:QC},staggered:{name:"Staggered",inlineOptions:QC},minSquareSize:{name:"Minimum size",inlineOptions:ojt},pointSize:{name:"Point Size",inlineOptions:uG},pointColor:{name:"Point Color",inlineOptions:NI},trackBorderColor:{name:"Track Border Color",inlineOptions:NI},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:NI},plusStrandColor:{name:"+ Strand Color",inlineOptions:NI},lineStrokeColor:{name:"Stroke color",inlineOptions:NI},projectionStrokeColor:{name:"Stroke color",inlineOptions:NI},projectionFillColor:{name:"Fill color",inlineOptions:NI},stroke:{name:"Stroke Color",inlineOptions:NI},strokeColor:{name:"Stroke color",inlineOptions:NI},fill:{name:"Fill Color",inlineOptions:NI},color:{name:"Color",inlineOptions:NI},fontColor:{name:"Font color",inlineOptions:NI},fillColor:{name:"Fill color",inlineOptions:NI},barFillColor:{name:"Fill color",inlineOptions:NI},barFillColorTop:{name:"Top Fill color",inlineOptions:NI},barFillColorBottom:{name:"Bottom Fill color",inlineOptions:NI},barOpacity:{name:"Bar opacity",inlineOptions:Sl},zeroLineVisible:{name:"Zero line visible",inlineOptions:QC},zeroLineColor:{name:"Zero line color",inlineOptions:NI},zeroLineOpacity:{name:"Zero line opacity",inlineOptions:ajt},fillOpacity:{name:"Fill Opacity",inlineOptions:Sl},strokeOpacity:{name:"Stroke Opacity",inlineOptions:Sl},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:QC},scaledHeight:{name:"Scaled height",inlineOptions:QC},rectangleDomainStrokeColor:{name:"Stroke color",inlineOptions:NI},rectangleDomainFillColor:{name:"Fill color",inlineOptions:NI},rectangleDomainFillOpacity:{name:"Fill opacity",inlineOptions:Sl},rectangleDomainOpacity:{name:"Opacity",inlineOptions:Sl},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:QC},showTooltip:{name:"Show Tooltip",inlineOptions:QC},fontSize:{name:"Font Size",inlineOptions:c0([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:gse},fontIsAligned:{name:"Left-Align Font",inlineOptions:QC},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:c0([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:NI},colorbarBackgroundOpacity:{name:"Colorbar Background Opacity",inlineOptions:Sl},colorbarLabelsPosition:{name:"Colorbar Labels Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},labelColor:{name:"Label Color",inlineOptions:{...NI,...rjt}},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:Sl},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:NI},labelBackgroundOpacity:{name:"Label Background Opacity",inlineOptions:Sl},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:aO,"horizontal-heatmap":aO}}}},align:{name:"Align",inlineOptions:{white:{name:"Top",value:"top"},lightGrey:{name:"Bottom",value:"bottom"}}},colorRangeGradient:{name:"Color Gradient",inlineOptions:QC},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=x0(r,o),A=gm(`.${a}`,o)(o);g.push({name:A,value:I.toString()})}return g}return[]}},valueColumn:{name:"Value column",inlineOptions:{none:{name:"None",value:null}},generateOptions:gse},zeroValueColor:{name:"Zero Value Color",inlineOptions:NI}},e9e={...Wst,IS_TRACK_RANGE_SELECTABLE:F0,OPTIONS_INFO:an},Ajt={d3Array:bIt,d3Axis:GTt,d3Brush:hAt,d3Color:NIt,d3Drag:Lot,d3Dsv:qst,d3Format:oit,d3Geo:jEt,d3Queue:gMt,d3Request:ZMt,d3Scale:Knt,d3Selection:pgt,d3Transition:U1t,d3Zoom:gWt,PIXI:e9e.GLOBALS.PIXI,mix:ry,slugid:sg},sjt={Annotations1dTrack:JP,Annotations2dTrack:R1e,ArrowheadDomainsTrack:w1e,BarTrack:h4,BedLikeTrack:p1e,CNVIntervalTrack:B1e,Chromosome2DAnnotations:T1e,Chromosome2DLabels:H1e,ChromosomeGrid:iG,CombinedTrack:EQ,CrossRule:tWe,DivergentBarTrack:G1e,HeatmapTiledPixiTrack:uw,Horizontal1dHeatmapTrack:v1e,Horizontal2DDomainsTrack:W1e,HorizontalChromosomeLabels:k1e,HorizontalGeneAnnotationsTrack:S1e,HorizontalHeatmapTrack:Y1e,HorizontalLine1DPixiTrack:Cy,HorizontalMultivecTrack:Z1e,HorizontalPoint1DPixiTrack:y1e,HorizontalRule:L1e,HorizontalTiled1DPixiTrack:iy,HorizontalTiledPlot:x2,HorizontalTrack:qWe,Id2DTiledPixiTrack:NRe,IdHorizontal1DTiledPixiTrack:YRe,IdVertical1DTiledPixiTrack:xRe,LeftAxisTrack:MRe,MapboxTilesTrack:iWe,MoveableTrack:kk,OSMTileIdsTrack:IWe,OSMTilesTrack:hw,OverlayTrack:b1e,PixiTrack:fC,RasterTilesTrack:nWe,SVGTrack:fm,SquareMarkersTrack:X1e,Tiled1DPixiTrack:r4,TiledPixiTrack:mm,TopAxisTrack:ERe,Track:Dp,ValueIntervalTrack:x1e,VerticalRule:eWe,VerticalTiled1DPixiTrack:KRe,VerticalTrack:tXe,ViewportTracker2D:D1e,ViewportTracker2DPixi:M3t,ViewportTrackerHorizontal:F1e,ViewportTrackerVertical:E1e},ljt={ContextMenuItem:Ig,DataFetcher:yk,LruCache:IXe},cjt={ChromosomeInfo:Js,SearchField:i0},ujt={DataFetcher:yk,GBKDataFetcher:WRe,LocalDataFetcher:XRe,getDataFetcher:KFt},_2={chromosomes:cjt,libraries:Ajt,tracks:sjt,dataFetchers:ujt,factories:ljt,services:Xlt,utils:fWt,configs:e9e,VERSION:iXe},mF={"track-renderer":"_track-renderer_11dwb_1","track-renderer-element":"_track-renderer-element_11dwb_5","track-renderer-events":"_track-renderer-events_11dwb_6"};function djt(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 L2(e){return L2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},L2(e)}const{getDataFetcher:Gjt}=_2.dataFetchers,vjt=100;let b$=function(e){pjt(I,e);var g=bjt(I);function I(i){var n;if(djt(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=Ji,n.windowScrolledBound=n.windowScrolled.bind(Ko(n)),n.zoomStartedBound=n.zoomStarted.bind(Ko(n)),n.zoomedBound=n.zoomed.bind(Ko(n)),n.zoomEndedBound=n.zoomEnded.bind(Ko(n)),n.uid=sg.nice(),n.viewUid=n.props.uid,n.availableForPlugins={..._2,services:{..._2.services,pubSub:n.props.pubSub,pixiRenderer:n.props.pixiRenderer}},n.mounted=!1,n.emptyZoomBehavior=$z(),n.currentProps=i,n.prevPropsStr="",n.zoomBehavior=$z().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=Ji,n.prevZoomTransform=Ji,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)Qg[C]=window.higlassTracksByType[C].config;return n.boundForwardEvent=n.forwardEvent.bind(Ko(n)),n.boundScrollEvent=n.scrollEvent.bind(Ko(n)),n.boundForwardContextMenu=n.forwardContextMenu.bind(Ko(n)),n.dispatchEventBound=n.dispatchEvent.bind(Ko(n)),n.zoomToDataPosHandlerBound=n.zoomToDataPosHandler.bind(Ko(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(Ko(n)),n.elementPos={height:0,width:0,left:0,top:0},n.elementSelection=null,n}return hjt(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=dg(this.element),this.pStage=new ot.PIXI.Graphics,this.pMask=new ot.PIXI.Graphics,this.pOutline=new ot.PIXI.Graphics,this.pBackground=new ot.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),O1(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=Ji),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&&y9(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===gI?"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()},vjt)}},{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=Ji,this.prevZoomTransform=Ji,this.cumCenterYOffset=0,this.cumCenterXOffset=0,this.drawableToDomainX=tg().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=tg().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=tg().domain(s).range([0,this.currentProps.width]),this._yScale=tg().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=Tr(this.trackDefObjects);for(const[,{trackDef:r,trackObject:o}]of C){if(o===n)return r.track;if(O1(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=Tr(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=Ji.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,Ji.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(!Tlt(n.sourceEvent))return;const r=n.sourceEvent.deltaY,o=n.sourceEvent.deltaMode,s=((l,c)=>l*(c?120:1)/500)(r,o),A=zg(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=Qg[A.type])!=null&&C.orientation&&(r=Qg[A.type].orientation),s instanceof Xoe&&(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:Ji,this.prevZoomTransform.k!==this.zoomTransform.k||(r==="1d-horizontal"?this.zoomTransform=Ji.translate(this.zoomTransform.x,this.prevZoomTransform.y).scale(this.zoomTransform.k):r==="1d-vertical"&&(this.zoomTransform=Ji.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=zg(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=tg().domain([r,r+C.centerWidth].map(this.zoomedXScale.invert)).range([0,C.centerWidth]),s=tg().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(Qg[c.track.type]&&(u=Qg[c.track.type].orientation),u==="whole"){const d=tg().domain([C.paddingLeft,C.width-C.paddingLeft].map(this.zoomedXScale.invert)).range([0,C.width-2*C.paddingLeft]),h=tg().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=tg().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=tg().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 $oe(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")&&Qg[n.type].orientation==="1d-horizontal"?new Xoe(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=Gjt(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 MRe(o,n.options);case"top-axis":return new ERe(o,n.options);case"heatmap":return new uw(o,n.options);case"multivec":case"vector-heatmap":case"horizontal-multivec":case"horizontal-vector-heatmap":case"vertical-multivec":case"vertical-vector-heatmap":return new Z1e(o,n.options);case"1d-heatmap":case"horizontal-1d-heatmap":case"vertical-1d-heatmap":return new v1e(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 y1e(o,n.options);case"bar":case"horizontal-bar":case"vertical-bar":return new h4(o,n.options);case"divergent-bar":case"horizontal-divergent-bar":case"vertical-divergent-bar":return new G1e(o,n.options);case"horizontal-1d-tiles":return new YRe(o,n.options);case"vertical-1d-tiles":return new xRe(o,n.options);case"2d-tiles":return new NRe(o,n.options);case"stacked-interval":case"top-stacked-interval":case"left-stacked-interval":return new B1e(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 D1e(o,n.options)):new Dp(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 F1e(o,n.options)):new Dp(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 E1e(o,n.options)):new Dp(o,{});case"gene-annotations":case"horizontal-gene-annotations":case"vertical-gene-annotations":return new S1e(o,n.options);case"2d-rectangle-domains":case"arrowhead-domains":return new w1e(o,n.options);case"horizontal-1d-annotations":return new JP(o,n.options);case"vertical-1d-annotations":return new JP(o,n.options,!0);case"2d-annotations":return new R1e(o,n.options);case"linear-2d-rectangle-domains":case"horizontal-2d-rectangle-domains":case"vertical-2d-rectangle-domains":return new W1e(o,n.options);case"square-markers":return new X1e(o,n.options);case"combined":return o.tracks=n.contents,o.createTrackObject=this.createTrackObject.bind(this),new EQ(o);case"2d-chromosome-labels":return new H1e(o,n.options);case"horizontal-chromosome-grid":return o.orientation="1d-horizontal",new iG(o,n.options);case"vertical-chromosome-grid":return o.orientation="1d-vertical",new iG(o,n.options);case"2d-chromosome-grid":return new iG(o,n.options);case"chromosome-labels":case"horizontal-chromosome-labels":case"vertical-chromosome-labels":return new k1e(o,n.options);case"linear-heatmap":case"horizontal-heatmap":case"vertical-heatmap":return new Y1e(o,n.options);case"2d-chromosome-annotations":return new T1e(o,n.options);case"1d-value-interval":case"horizontal-1d-value-interval":case"vertical-1d-value-interval":return new x1e(o,n.options);case"osm":case"osm-tiles":return new hw(o,n.options);case"osm-2d-tile-ids":return new IWe(o,n.options);case"mapbox":case"mapbox-tiles":return new iWe(o,n.options);case"raster-tiles":return new nWe(o,n.options);case"bedlike":case"vertical-bedlike":return new p1e(o,n.options);case"overlay-track":return new b1e(o,n.options);case"overlay-chromosome-grid-track":return o.isOverlay=!0,new iG(o,n.options);case"horizontal-rule":return new L1e(o,n.options);case"vertical-rule":return new eWe(o,n.options);case"cross-rule":return o.x=n.x,o.y=n.y,new tWe(o,n.options);case"simple-svg":return new fm(o,n.options);case"empty":{const a=n.options;return new fC(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 $oe(o,{name:"Unknown Track Type",type:n.type})}}}},{key:"zoomToDataPos",value:function(n,C,r,o,a=3e3,s=null){const[A,l,c]=Si(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:Xg("track-renderer-div",mF["track-renderer"]),style:{height:this.currentProps.height,width:this.currentProps.width}},N.createElement("div",{ref:n=>{this.element=n},className:Xg("track-renderer-element",mF["track-renderer-element"])}),N.createElement("div",{ref:n=>{this.eventTracker=n},className:Xg("track-renderer-events",mF["track-renderer-events"])},this.currentProps.children))}}]),I}(N.Component);b$.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:[]};b$.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 Bjt=ey(um(b$));var t9e={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,K=(H=H==b?y:H)==y,F=R==H;if(F&&m(B)){if(!m(G))return!1;X=!0,Y=!1}if(F&&!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 J=Y&&Z.call(B,"__wrapped__"),P=K&&Z.call(G,"__wrapped__");if(J||P){var ge=J?B.value():B,q=P?G.value():G;return S||(S=new A),V(ge,q,v,w,S)}}return!!F&&(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},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:()=>Ye,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 Me,ke=w(oe);if(Ve){var Ee=w(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return v(this,Me)});function xe(){return Z(this,xe),Fe.apply(this,arguments)}return le=xe,(re=[{key:"render",value:function(){var Me=this.props,ke=Me.children,Ee=Me.title,O=function(D,ee){if(D==null)return{};var ce,de,Le=function(dt,yt){if(dt==null)return{};var kt,ht,Vt={},Ft=Object.keys(dt);for(ht=0;ht=0||(Vt[kt]=dt[kt]);return Vt}(D,ee);if(Object.getOwnPropertySymbols){var Ue=Object.getOwnPropertySymbols(D);for(de=0;de=0||Object.prototype.propertyIsEnumerable.call(D,ce)&&(Le[ce]=D[ce])}return Le}(Me,p);return f().createElement("button",y({"aria-label":Ee,title:Ee,type:"button"},O),ke)}}])&&B(le.prototype,re),Object.defineProperty(le,"prototype",{writable:!1}),xe}(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(Ve){return Object.getOwnPropertyDescriptor(ue,Ve).enumerable})),re.push.apply(re,oe)}return re}function K(ue,le,re){return le in ue?Object.defineProperty(ue,le,{value:re,enumerable:!0,configurable:!0,writable:!0}):ue[le]=re,ue}function F(ue,le){if(!(ue instanceof le))throw new TypeError("Cannot call a class as a function")}function J(ue,le){for(var re=0;re1&&arguments[1]!==void 0?arguments[1]:{};F(this,ue),this.props=oe,this.flatNodes=Ve}var le,re;return le=ue,re=[{key:"setProps",value:function(oe){this.props=oe}},{key:"clone",value:function(){var oe=this,Ve={};return Object.keys(this.flatNodes).forEach(function(Fe){var xe=oe.flatNodes[Fe];Ve[Fe]=function(Me){for(var ke=1;ke1&&arguments[1]!==void 0?arguments[1]:{},xe=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;if(Array.isArray(oe)&&oe.length!==0){var Me=this.props,ke=Me.disabled,Ee=Me.noCascade;oe.forEach(function(O,D){var ee=Ve.nodeHasChildren(O);if(Ve.flatNodes[O.value]!==void 0)throw new H("Duplicate value '".concat(O.value,"' detected. All node values must be unique."));Ve.flatNodes[O.value]={label:O.label,value:O.value,children:O.children,parent:Fe,isChild:Fe.value!==void 0,isParent:ee,isLeaf:!ee,showCheckbox:O.showCheckbox===void 0||O.showCheckbox,disabled:Ve.getDisabledState(O,Fe,ke,Ee),treeDepth:xe,index:D},Ve.flattenNodes(O.children,O,xe+1)})}}},{key:"nodeHasChildren",value:function(oe){return Array.isArray(oe.children)}},{key:"getDisabledState",value:function(oe,Ve,Fe,xe){return!!Fe||!(xe||!Ve.disabled)||!!oe.disabled}},{key:"deserializeLists",value:function(oe){var Ve=this,Fe=["checked","expanded"];Object.keys(this.flatNodes).forEach(function(xe){Fe.forEach(function(Me){Ve.flatNodes[xe][Me]=!1})}),Fe.forEach(function(xe){oe[xe].forEach(function(Me){Ve.flatNodes[Me]!==void 0&&(Ve.flatNodes[Me][xe]=!0)})})}},{key:"serializeList",value:function(oe){var Ve=this,Fe=[];return Object.keys(this.flatNodes).forEach(function(xe){Ve.flatNodes[xe][oe]&&Fe.push(xe)}),Fe}},{key:"expandAllNodes",value:function(oe){var Ve=this;return Object.keys(this.flatNodes).forEach(function(Fe){Ve.flatNodes[Fe].isParent&&(Ve.flatNodes[Fe].expanded=oe)}),this}},{key:"toggleChecked",value:function(oe,Ve,Fe,xe){var Me=this,ke=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],Ee=this.flatNodes[oe.value],O=[P.PARENT,P.ALL].indexOf(Fe)>-1,D=[P.LEAF,P.ALL].indexOf(Fe)>-1;if(Ee.isLeaf||xe){if(oe.disabled)return this;this.toggleNode(oe.value,"checked",Ve)}else(O||Ee.children.length===0)&&this.toggleNode(oe.value,"checked",Ve),D&&Ee.children.forEach(function(ee){Me.toggleChecked(ee,Ve,Fe,xe,!1)});return ke&&!xe&&Ee.isChild&&O&&this.toggleParentStatus(Ee.parent,Fe),this}},{key:"toggleParentStatus",value:function(oe,Ve){var Fe=this.flatNodes[oe.value];Fe.isChild?(Ve===P.ALL&&this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Fe)),this.toggleParentStatus(Fe.parent,Ve)):this.toggleNode(oe.value,"checked",this.isEveryChildChecked(Fe))}},{key:"isEveryChildChecked",value:function(oe){var Ve=this;return oe.children.every(function(Fe){return Ve.getNode(Fe.value).checked})}},{key:"toggleNode",value:function(oe,Ve,Fe){return this.flatNodes[oe][Ve]=Fe,this}}],re&&J(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 Me,ke=ne(oe);if(Ve){var Ee=ne(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return he(this,Me)});function xe(){return te(this,xe),Fe.apply(this,arguments)}return le=xe,re=[{key:"componentDidMount",value:function(){this.updateDeterminateProperty()}},{key:"componentDidUpdate",value:function(){this.updateDeterminateProperty()}},{key:"updateDeterminateProperty",value:function(){var Me=this.props.indeterminate;this.checkbox.indeterminate=Me}},{key:"render",value:function(){var Me=this,ke=function(Ee){for(var O=1;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(){var Me,ke=gt(oe);if(Ve){var Ee=gt(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return Qe(this,Me)});function xe(Me){var ke;return function(Ee,O){if(!(Ee instanceof O))throw new TypeError("Cannot call a class as a function")}(this,xe),(ke=Fe.call(this,Me)).onCheck=ke.onCheck.bind(_e(ke)),ke.onCheckboxKeyPress=ke.onCheckboxKeyPress.bind(_e(ke)),ke.onCheckboxKeyUp=ke.onCheckboxKeyUp.bind(_e(ke)),ke.onClick=ke.onClick.bind(_e(ke)),ke.onExpand=ke.onExpand.bind(_e(ke)),ke}return le=xe,(re=[{key:"onCheck",value:function(){var Me=this.props,ke=Me.value;(0,Me.onCheck)({value:ke,checked:this.getCheckState({toggle:!0})})}},{key:"onCheckboxKeyPress",value:function(Me){Me.which===32&&Me.preventDefault()}},{key:"onCheckboxKeyUp",value:function(Me){var ke=Me.keyCode;[13,32].includes(ke)&&this.onCheck()}},{key:"onClick",value:function(){var Me=this.props,ke=Me.expandOnClick,Ee=Me.isParent,O=Me.value,D=Me.onClick;Ee&&ke&&this.onExpand(),D({value:O,checked:this.getCheckState({toggle:!1})})}},{key:"onExpand",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.value;(0,Me.onExpand)({value:Ee,expanded:!ke})}},{key:"getCheckState",value:function(Me){var ke=Me.toggle,Ee=this.props,O=Ee.checked,D=Ee.optimisticToggle;return!(O!==0||!ke)||O===1&&!ke||O===2&&D}},{key:"renderCollapseButton",value:function(){var Me=this.props,ke=Me.expandDisabled,Ee=Me.isLeaf,O=Me.lang;return Ee?f().createElement("span",{className:"rct-collapse"},f().createElement("span",{className:"rct-icon"})):f().createElement(X,{className:"rct-collapse rct-collapse-btn",disabled:ke,title:O.toggle,onClick:this.onExpand},this.renderCollapseIcon())}},{key:"renderCollapseIcon",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.icons,O=Ee.expandClose,D=Ee.expandOpen;return ke?D:O}},{key:"renderCheckboxIcon",value:function(){var Me=this.props,ke=Me.checked,Ee=Me.icons,O=Ee.uncheck,D=Ee.check,ee=Ee.halfCheck;return ke===0?O:ke===1?D:ee}},{key:"renderNodeIcon",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.icon,O=Me.icons,D=O.leaf,ee=O.parentClose,ce=O.parentOpen,de=Me.isLeaf;return Ee!==null?Ee:de?D:ke?ce:ee}},{key:"renderBareLabel",value:function(Me){var ke=this.props,Ee=ke.onClick,O=ke.title,D=Ee!==null;return f().createElement("span",{className:"rct-bare-label",title:O},D?f().createElement("span",{className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"button",tabIndex:0},Me):Me)}},{key:"renderCheckboxLabel",value:function(Me){var ke=this.props,Ee=ke.checked,O=ke.disabled,D=ke.title,ee=ke.treeId,ce=ke.value,de=ke.onClick!==null,Le="".concat(ee,"-").concat(String(ce).split(" ").join("_")),Ue=[f().createElement("label",{key:0,htmlFor:Le,title:D},f().createElement(ve,{checked:Ee===1,disabled:O,id:Le,indeterminate:Ee===2,onClick:this.onCheck,onChange:function(){}}),f().createElement("span",{"aria-checked":Ee===1,"aria-disabled":O,className:"rct-checkbox",role:"checkbox",tabIndex:0,onKeyPress:this.onCheckboxKeyPress,onKeyUp:this.onCheckboxKeyUp},this.renderCheckboxIcon()),de?null:Me)];return de&&Ue.push(f().createElement("span",{key:1,className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"link",tabIndex:0},Me)),Ue}},{key:"renderLabel",value:function(){var Me=this.props,ke=Me.label,Ee=Me.showCheckbox,O=[Me.showNodeIcon?f().createElement("span",{key:0,className:"rct-node-icon"},this.renderNodeIcon()):null,f().createElement("span",{key:1,className:"rct-title"},ke)];return Ee?this.renderCheckboxLabel(O):this.renderBareLabel(O)}},{key:"renderChildren",value:function(){return this.props.expanded?this.props.children:null}},{key:"render",value:function(){var Me=this.props,ke=Me.className,Ee=Me.disabled,O=Me.expanded,D=Me.isLeaf,ee=a()({"rct-node":!0,"rct-node-leaf":D,"rct-node-parent":!D,"rct-node-expanded":!D&&O,"rct-node-collapsed":!D&&!O,"rct-disabled":Ee},ke);return f().createElement("li",{className:ee},f().createElement("span",{className:"rct-text"},this.renderCollapseButton(),this.renderLabel()),this.renderChildren())}}])&&Pe(le.prototype,re),Object.defineProperty(le,"prototype",{writable:!1}),xe}(f().PureComponent);lt(tt,"propTypes",{checked:h().number.isRequired,disabled:h().bool.isRequired,expandDisabled:h().bool.isRequired,expanded:h().bool.isRequired,icons:We.isRequired,isLeaf:h().bool.isRequired,isParent:h().bool.isRequired,label:h().node.isRequired,lang:Be.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}),lt(tt,"defaultProps",{children:null,className:null,expandOnClick:!1,icon:null,showCheckbox:!0,title:null,onClick:function(){}});const Xe=tt,ae=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(Ve){return Object.getOwnPropertyDescriptor(ue,Ve).enumerable})),re.push.apply(re,oe)}return re}function He(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 ke,Ee=ct(Ve);if(Fe){var O=ct(this).constructor;ke=Reflect.construct(Ee,arguments,O)}else ke=Ee.apply(this,arguments);return at(this,ke)});function Me(ke){var Ee;(function(D,ee){if(!(D instanceof ee))throw new TypeError("Cannot call a class as a function")})(this,Me),Ee=xe.call(this,ke);var O=new ge(ke);return O.flattenNodes(ke.nodes),O.deserializeLists({checked:ke.checked,expanded:ke.expanded}),Ee.state={id:ke.id||"rct-".concat(u()),model:O,prevProps:ke},Ee.onCheck=Ee.onCheck.bind(bt(Ee)),Ee.onExpand=Ee.onExpand.bind(bt(Ee)),Ee.onNodeClick=Ee.onNodeClick.bind(bt(Ee)),Ee.onExpandAll=Ee.onExpandAll.bind(bt(Ee)),Ee.onCollapseAll=Ee.onCollapseAll.bind(bt(Ee)),Ee.combineMemorized=c()(function(D,ee){return Re(Re({},D),ee)}).bind(bt(Ee)),Ee}return le=Me,re=[{key:"onCheck",value:function(ke){var Ee=this.props,O=Ee.checkModel,D=Ee.noCascade,ee=Ee.onCheck,ce=this.state.model.clone(),de=ce.getNode(ke.value);ce.toggleChecked(ke,ke.checked,O,D),ee(ce.serializeList("checked"),Re(Re({},de),ke))}},{key:"onExpand",value:function(ke){var Ee=this.props.onExpand,O=this.state.model.clone(),D=O.getNode(ke.value);O.toggleNode(ke.value,"expanded",ke.expanded),Ee(O.serializeList("expanded"),Re(Re({},D),ke))}},{key:"onNodeClick",value:function(ke){(0,this.props.onClick)(Re(Re({},this.state.model.getNode(ke.value)),ke))}},{key:"onExpandAll",value:function(){this.expandAllNodes()}},{key:"onCollapseAll",value:function(){this.expandAllNodes(!1)}},{key:"expandAllNodes",value:function(){var ke=!(arguments.length>0&&arguments[0]!==void 0)||arguments[0],Ee=this.props.onExpand;Ee(this.state.model.clone().expandAllNodes(ke).serializeList("expanded"))}},{key:"determineShallowCheckState",value:function(ke,Ee){var O=this.state.model.getNode(ke.value);return O.isLeaf||Ee||ke.children.length===0?O.checked?1:0:this.isEveryChildChecked(ke)?1:this.isSomeChildChecked(ke)?2:0}},{key:"isEveryChildChecked",value:function(ke){var Ee=this;return ke.children.every(function(O){return Ee.state.model.getNode(O.value).checkState===1})}},{key:"isSomeChildChecked",value:function(ke){var Ee=this;return ke.children.some(function(O){return Ee.state.model.getNode(O.value).checkState>0})}},{key:"renderTreeNodes",value:function(ke){var Ee=this,O=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},D=this.props,ee=D.expandDisabled,ce=D.expandOnClick,de=D.icons,Le=D.lang,Ue=D.noCascade,dt=D.onClick,yt=D.onlyLeafCheckboxes,kt=D.optimisticToggle,ht=D.showNodeTitle,Vt=D.showNodeIcon,Ft=this.state,At=Ft.id,Xt=Ft.model,Pt=Me.defaultProps.icons,xt=ke.map(function(Rg){var qg=Rg.value,It=Xt.getNode(Rg.value),Zt=It.isParent?Ee.renderTreeNodes(Rg.children,Rg):null;It.checkState=Ee.determineShallowCheckState(Rg,Ue);var Lt=yt?It.isLeaf:It.showCheckbox;return!O.value||Xt.getNode(O.value).expanded?f().createElement(Xe,{key:qg,checked:It.checkState,className:Rg.className,disabled:It.disabled,expandDisabled:ee,expandOnClick:ce,expanded:It.expanded,icon:Rg.icon,icons:Ee.combineMemorized(Pt,de),label:Rg.label,lang:Le,optimisticToggle:kt,isLeaf:It.isLeaf,isParent:It.isParent,showCheckbox:Lt,showNodeIcon:Vt,title:ht?Rg.title||Rg.label:Rg.title,treeId:At,value:Rg.value,onCheck:Ee.onCheck,onClick:dt&&Ee.onNodeClick,onExpand:Ee.onExpand},Zt):null});return f().createElement("ol",null,xt)}},{key:"renderExpandAll",value:function(){var ke=this.props,Ee=ke.icons,O=Ee.expandAll,D=Ee.collapseAll,ee=ke.lang;return ke.showExpandAll?f().createElement("div",{className:"rct-options"},f().createElement(X,{className:"rct-option rct-option-expand-all",title:ee.expandAll,onClick:this.onExpandAll},O),f().createElement(X,{className:"rct-option rct-option-collapse-all",title:ee.collapseAll,onClick:this.onCollapseAll},D)):null}},{key:"renderHiddenInput",value:function(){var ke=this.props,Ee=ke.name,O=ke.nameAsArray;return Ee===void 0?null:O?this.renderArrayHiddenInput():this.renderJoinedHiddenInput()}},{key:"renderArrayHiddenInput",value:function(){var ke=this.props,Ee=ke.checked,O=ke.name;return Ee.map(function(D){var ee="".concat(O,"[]");return f().createElement("input",{key:D,name:ee,type:"hidden",value:D})})}},{key:"renderJoinedHiddenInput",value:function(){var ke=this.props,Ee=ke.checked,O=ke.name,D=Ee.join(",");return f().createElement("input",{name:O,type:"hidden",value:D})}},{key:"render",value:function(){var ke,Ee=this.props,O=Ee.direction,D=Ee.disabled,ee=Ee.iconsClass,ce=Ee.nodes,de=Ee.nativeCheckboxes,Le=this.state.id,Ue=this.renderTreeNodes(ce),dt=a()((Ht(ke={"react-checkbox-tree":!0,"rct-disabled":D},"rct-icons-".concat(ee),!0),Ht(ke,"rct-native-display",de),Ht(ke,"rct-direction-rtl",O==="rtl"),ke));return f().createElement("div",{className:dt,id:Le},this.renderExpandAll(),this.renderHiddenInput(),Ue)}}],oe=[{key:"getDerivedStateFromProps",value:function(ke,Ee){var O=Ee.model,D=Ee.prevProps,ee=ke.disabled,ce=ke.id,de=ke.nodes,Le=Re(Re({},Ee),{},{prevProps:ke});return O.setProps(ke),A()(D.nodes,de)&&D.disabled===ee||(O.reset(),O.flattenNodes(de)),ce!==null&&(Le=Re(Re({},Le),{},{id:ce})),O.deserializeLists({checked:ke.checked,expanded:ke.expanded}),Le}}],re&&we(le.prototype,re),oe&&we(le,oe),Object.defineProperty(le,"prototype",{writable:!1}),Me}(f().Component);function E(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(Ve){Ve.children&&(oe=[].concat(E(oe),[Ve.value],E(fe(Ve.children,le,re+1))))}),oe}Ht(Ce,"propTypes",{nodes:h().arrayOf(k).isRequired,checkModel:h().oneOf([W.LEAF,W.ALL]),checked:ae,direction:h().string,disabled:h().bool,expandDisabled:h().bool,expandOnClick:h().bool,expanded:ae,icons:We,iconsClass:h().string,id:h().string,lang:Be,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(Ce,"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 Ye=Ce})(),r})())})(t9e);var Sjt=t9e.exports;const wjt=JC(Sjt);function Vjt(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 U2(e){return U2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},U2(e)}let g9e=function(e){Hjt(I,e);var g=Tjt(I);function I(i){var n;Vjt(this,I),n=g.call(this,i),n.localTracks=Ah.filter(a=>a.local&&!a.hidden).map(a=>{const s={...a};return s.datatype=a.datatype[0],s}),n.augmentedTracksInfo=Ah,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=sg.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 Rjt(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:sg.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(wjt,{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);g9e.propTypes={datatype:L.string,orientation:L.string,onDoubleClick:L.func,pubSub:L.object.isRequired,selectedTilesetChanged:L.func,trackSourceServers:L.array};const Kjt=ey(g9e);function xjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function nse(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 I9e=function(e){Mjt(I,e);var g=zjt(I);function I(i){var n;return xjt(this,I),n=g.call(this,i),n.DATATYPE_TO_TRACK_TYPE=XQ(n.props.orientation),n.AVAILABLE_TRACK_TYPES=p9(n.props.datatypes,n.props.orientation),n.state={selectedPlotType:n.AVAILABLE_TRACK_TYPES[0]},n}return Djt(I,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(this.AVAILABLE_TRACK_TYPES=p9(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=NQ(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 Ah.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);I9e.propTypes={allTracksSameDatatype:L.bool,datatypes:L.array,orientation:L.string,onPlotTypeSelected:L.func,position:L.string};function _jt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Cse(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 $2=function(e){jjt(I,e);var g=$jt(I);function I(i){var n;return _jt(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 Ljt(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=p9([s],A),c=NQ(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(Kjt,{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(I9e,{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);$2.defaultProps={position:"top"};$2.propTypes={datatype:L.string,host:L.string,onCancel:L.func.isRequired,onTracksChosen:L.func.isRequired,position:L.string,trackSourceServers:L.array.isRequired};function uO(){return uO=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 q2(e){return q2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},q2(e)}let y$=function(e){n4t(I,e);var g=C4t(I);function I(){return t4t(this,I),g.apply(this,arguments)}return g4t(I,[{key:"render",value:function(){const n=[];return this.props.children.forEach((C,r)=>{const o=`customTrackDialog_${r}`;n.push(N.createElement(C,uO({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);y$.defaultProps={};y$.propTypes={onCancel:L.func.isRequired,title:L.string,bodyProps:L.array,children:L.array};function A4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ose(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 ase=20;let pu=function(e){u4t(I,e);var g=d4t(I);function I(i){var n;return A4t(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 s4t(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=jI.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+ase:(o=C.top-n.height+ase,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:Xg("context-menu-item",Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),style:r},this.props.children)}}]),I}(N.Component);pu.propTypes={children:L.node,orientation:L.string,parentBbox:L.object,position:L.object,theme:L.symbol.isRequired};function p4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ase(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)}let fO=function(e){G4t(I,e);var g=v4t(I);function I(){return p4t(this,I),g.apply(this,arguments)}return b4t(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(Ig,{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:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),style:{left:this.state.left,top:this.state.top}},n,this.getSubmenu())}}]),I}(pu);function V4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function sse(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 gH(e){return gH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},gH(e)}let K4t=function(e){H4t(I,e);var g=T4t(I);function I(){return V4t(this,I),g.apply(this,arguments)}return R4t(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))an[s]=a[s];if(!Qg[r.type]||!Qg[r.type].availableOptions)return null;for(const s of Qg[r.type].availableOptions)if(s in an){if(o[s]={name:an[s].name},an[s].generateOptions){const A=an[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(an[s].inlineOptions)for(const A in an[s].inlineOptions){const l=an[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 an[s].componentPickers&&an[s].componentPickers[r.type]&&(o[s].handler=()=>{this.props.onConfigureTrack(r,an[s].componentPickers[r.type]),this.props.closeMenu()})}return N.createElement(fO,{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=>{Qg[l]=window.higlassTracksByType[l].config});let{datatype:o}=r,a=null;r.type in Qg&&(o||(o=Qg[r.type].datatype[0]),{orientation:a}=Qg[r.type]);const s=Object.values(Qg).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(fO,{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(Ig,{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(Ig,{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;Qg[this.props.series.type]&&Qg[this.props.series.type].exportable&&(n=N.createElement(Ig,{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(Ig,{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:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),"data-menu-type":"SeriesListMenu",onMouseLeave:this.props.handleMouseLeave,style:{left:this.state.left,top:this.state.top}},N.createElement(Ig,{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(Ig,{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(Ig,{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}(pu);const i9e=e=>{let g=[];for(const I of e)I.contents?g=g.concat(I.contents):g.push(I);return g},Z$=(e,g,I,i)=>e?(window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(n=>{Qg[n]=window.higlassTracksByType[n].config}),i9e(e).map(n=>{const C=Qg[n.type]?Qg[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(Ig,{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 x4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function lse(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 IH(e){return IH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},IH(e)}const n9e=Wk(e=>function(g){M4t(i,g);var I=z4t(i);function i(){return x4t(this,i),I.apply(this,arguments)}return D4t(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=i9e(this.props.tracks).filter(A=>A.uid===this.state.submenuShown.uid)[0],s=a&&a.position!=="whole";return N.createElement(K4t,{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 _4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cse(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 u0(e){return u0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},u0(e)}let I$t=function(e){$4t(I,e);var g=q4t(I);function I(i){var n;return _4t(this,I),n=g.call(this,i),n.seriesRefs={},n.seriesListMenu=null,n}return L4t(I,[{key:"componentDidMount",value:function(){WW(u0(I.prototype),"componentDidMount",this).call(this)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),"data-menu-type":"ConfigTrackMenu",style:{left:this.state.left,top:this.state.top}},Z$(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this),null),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{contextMenu:this,onClick:()=>this.props.onLockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Lock Value Scale With"),N.createElement(Ig,{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(Ig,{contextMenu:this,onClick:()=>this.props.onAddSeries(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Add Series"),N.createElement(Ig,{onClick:()=>this.props.onCloseTrack(this.props.tracks[0].uid)},"Close Track"),N.createElement(Ig,{onClick:()=>{this.props.onReplaceTrack(this.props.tracks[0].uid,this.props.trackOrientation)}},"Replace Track"),this.getSubmenu())}}]),I}(ry(pu).with(n9e));function C9e(e){return N.createElement("div",null,Z$(e.tracks,null,null,e.onCloseTrack),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:()=>e.onCloseTrack(e.tracks[0].uid)},"Close all series"))}C9e.propTypes={onCloseTrack:L.func.isRequired,tracks:L.array.isRequired};function i$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function use(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 iH(e){return iH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},iH(e)}let Dc=function(e){o$t(I,e);var g=a$t(I);function I(i){var n;return i$t(this,I),n=g.call(this,i),n.clickHandlerBound=n.clickHandler.bind(XW(n)),n.contextMenuHandlerBound=n.contextMenuHandler.bind(XW(n)),n.resizeHandlerBound=n.resizeHandler.bind(XW(n)),n}return n$t(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),jI.unmountComponentAtNode(this.popup),document.body.removeChild(this.popup)}},{key:"_renderLayer",value:function(){jI.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);Dc.defaultProps={onMenuClosed:MGe};Dc.propTypes={children:L.node.isRequired,onMenuClosed:L.func};const l$t=aGe(e=>N.createElement(tXe,{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})),c$t={"vertical-tiled-plot":"_vertical-tiled-plot_f3ho8_1"};function u$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function dse(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 nH(e){return nH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},nH(e)}function hse(e){return e&&e.sourceEvent}let vO=function(e){f$t(I,e);var g=p$t(I);function I(i){var n;return u$t(this,I),n=g.call(this,i),n.brushBehavior=PS().on("start",n.brushStarted.bind(HW(n))).on("brush",n.brushed.bind(HW(n))).on("end",n.brushedEnded.bind(HW(n))),n}return d$t(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,kp(this.brushEl,Po["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const C=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!hse(n)||!this.props.onRangeSelection||C)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!hse(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($l,0),C=this.props.tracks.map(o=>F0(o)).reduce(_S,!1),r=Po[this.props.isRangeSelectionActive?"track-range-selection-active":"track-range-selection"];return N.createElement("div",{className:c$t["vertical-tiled-plot"]},C&&N.createElement("svg",{ref:o=>{this.brushEl=dg(o)},className:r,style:{height:this.props.height,width:n},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(Nk,{axis:"x",className:Xg(Jo.list,Jo.stylizedList,Jo.horizontalList),component:eXe,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:this.props.height,helperClass:Jo.stylizedHelper,itemClass:Xg(Jo.stylizedItem,Jo.horizontalItem),itemControlAlignLeft:this.props.tracksControlAlignLeft,itemReactClass:l$t,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||sg.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);vO.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 Z$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function mse(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 r9e=function(e){S$t(I,e);var g=w$t(I);function I(){return Z$t(this,I),g.apply(this,arguments)}return G$t(I,[{key:"render",value:function(){const n=Z$(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:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),"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(Ig,{onClick:()=>this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Rule"),N.createElement(Ig,{onClick:()=>this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Rule"),N.createElement(Ig,{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(Ig,{onClick:this.handleAddHorizontalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Horizontal Cross Section"),this.hasMatrixTrack(this.props.tracks)&&N.createElement(Ig,{onClick:this.handleAddVerticalSection.bind(this),onMouseEnter:r=>this.handleOtherMouseEnter(r)},"Add Vertical Cross Section"),this.getSubmenu())}},{key:"hasMatrixTrack",value:function(n){return _1(this.props.tracks).filter(r=>r.type==="heatmap").length>0}},{key:"handleAddHorizontalSection",value:function(){const C=_1(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=_1(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}(ry(pu).with(n9e));r9e.propTypes={coords:L.array,customItems:L.array};function X$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function fse(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 rH(e){return rH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},rH(e)}let G$=function(e){k$t(I,e);var g=Y$t(I);function I(i){var n;X$t(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=>{Qg[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(Cn(n)),n.handleNoTrackAddedBound=n.handleNoTrackAdded.bind(Cn(n)),n.handleTracksAddedBound=n.handleTracksAdded.bind(Cn(n)),n.closeMenusBound=n.closeMenus.bind(Cn(n)),n.handleAddDivisorBound=n.handleAddDivisor.bind(Cn(n)),n.handleAddSeriesBound=n.handleAddSeries.bind(Cn(n)),n.handleChangeTrackDataBound=n.handleChangeTrackData.bind(Cn(n)),n.handleChangeTrackTypeBound=n.handleChangeTrackType.bind(Cn(n)),n.handleCloseTrackBound=n.handleCloseTrack.bind(Cn(n)),n.handleConfigureTrackBound=n.handleConfigureTrack.bind(Cn(n)),n.handleExportTrackDataBound=n.handleExportTrackData.bind(Cn(n)),n.handleLockValueScaleBound=n.handleLockValueScale.bind(Cn(n)),n.handleReplaceTrackBound=n.handleReplaceTrack.bind(Cn(n)),n.handleTrackOptionsChangedBound=n.handleTrackOptionsChanged.bind(Cn(n)),n.handleUnlockValueScaleBound=n.handleUnlockValueScale.bind(Cn(n)),n.onAddTrack=n.handleAddTrack.bind(Cn(n)),n}return H$t(I,[{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const C=jI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=jI.findDOMNode(this),this.canvasElement=jI.findDOMNode(this.props.canvasElement),this.waitForDOMAttachment(()=>{A9.ElementQueries.listen(),this.resizeSensor=new A9.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,Is(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=>b9(...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(y$,{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($2,{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($2,{datatype:Qg[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||sg.nice()})})}},{key:"contextMenuHandler",value:function(n){if(!this.divTiledPlot)return;const C=this.divTiledPlot.getBoundingClientRect();if(!MQ(n.clientX,n.clientY,C.left,C.left+C.width,C.top,C.top+C.height))return;const o=[n.clientX,n.clientY],a=zg(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(Ig,{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=Ir(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=JG(this.props.tracks,n),r=Ir(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||sg.nice(),includes:r.includes,type:o,options:Object.assign(r.options,{orientationsAndPositions:r.includes.map(s=>{const A=Ir(this.props.tracks,s);if(!A)return console.warn(`OverlayTrack included uid (${s}) not found in the track list`),null;const l=JG(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=Ir(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(Dc,{onMenuClosed:this.closeMenusBound},N.createElement(r9e,{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 NB)&&!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=NB[C]||{};if(n.defaultTracks)for(const S of n.defaultTracks)if(!Qg[S])console.warn("unknown track type",S);else for(const X of r[Qg[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(BR,{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(BR,{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(BR,{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(BR,{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($l,0):0,this.topHeightNoGallery=this.props.tracks.top.map(p=>p.height).reduce($l,0),this.topHeight=this.topHeightNoGallery+this.galleryDim,this.bottomHeightNoGallery=this.props.tracks.bottom.map(p=>p.height).reduce($l,0),this.bottomHeight=this.bottomHeightNoGallery+this.galleryDim,this.leftWidthNoGallery=this.props.tracks.left.map(p=>p.width).reduce($l,0),this.leftWidth=this.leftWidthNoGallery+this.galleryDim,this.rightWidthNoGallery=this.props.tracks.right.map(p=>p.width).reduce($l,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(x2,{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===Mr,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(vO,{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===Mr,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(vO,{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===Mr,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(x2,{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===Mr,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(EVe,{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",eP["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",eP["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(jj,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===Mr,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(Bjt,{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===Mr,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(Dc,{onMenuClosed:this.closeMenusBound},N.createElement(I$t,{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:JG(this.props.tracks,this.state.configTrackMenuId),tracks:[Ir(this.props.tracks,this.state.configTrackMenuId)]}))),this.state.closeTrackMenuId&&(m=N.createElement(Dc,{onMenuClosed:this.handleCloseTrackMenuClosed.bind(this)},N.createElement(pu,{position:this.state.closeTrackMenuLocation,theme:this.props.theme},N.createElement(C9e,{onCloseTrack:this.handleCloseTrack.bind(this),tracks:[Ir(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",Jo["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);G$.defaultProps={isShowGlobalMousePosition:!1,pluginDataFetchers:{},pluginTracks:{},metaTracks:[],zoomable:!0};G$.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 D$t=ey(Yk(um(G$)));var F$t=Object.assign||function(e){for(var g=1;g"u"?"undefined":E$t(g))==="object"){for(var n in g)g.hasOwnProperty(n)&&jp(e,n,g[n]);return}if(typeof i<"u"){typeof i=="number"&&(i+="px"),e.style[g]=i;return}return Kh(e,g)}v$(["width","height"],function(e){var g=e.charAt(0).toUpperCase()+e.slice(1);CA["outer"+g]=function(i,n){return i&&bse(i,e,n?j$t:WO)};var I=e==="width"?["Left","Right"]:["Top","Bottom"];CA[e]=function(i,n){if(n!==void 0){if(i){Kh(i);var C=A9e(i);return C&&(n+=dG(i,["padding","border"],I)),jp(i,e,n)}return}return i&&bse(i,e,RO)}});function e8t(e,g){jp(e,"position")==="static"&&(e.style.position="relative");var I=a9e(e),i={},n=void 0,C=void 0;for(C in g)g.hasOwnProperty(C)&&(n=parseFloat(jp(e,C))||0,i[C]=n+g[C]-I[C]);jp(e,i)}var t8t=F$t({getWindow:function(g){var I=g.ownerDocument||g;return I.defaultView||I.parentWindow},offset:function(g,I){if(typeof I<"u")e8t(g,I);else return a9e(g)},isWindow:TW,each:v$,css:jp,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(TW(g)){if(I===void 0)return wO(g);window.scrollTo(I,VO(g))}else{if(I===void 0)return g.scrollLeft;g.scrollLeft=I}},scrollTop:function(g,I){if(TW(g)){if(I===void 0)return VO(g);window.scrollTo(wO(g),I)}else{if(I===void 0)return g.scrollTop;g.scrollTop=I}},viewportWidth:0,viewportHeight:0},CA),II=t8t;function g8t(e,g,I){I=I||{},g.nodeType===9&&(g=II.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=II.isWindow(g),c=II.offset(e),u=II.outerHeight(e),d=II.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=II.height(Z),G=II.width(Z),B={left:II.scrollLeft(Z),top:II.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=II.offset(g),m=g.clientHeight,f=g.clientWidth,b={left:g.scrollLeft,top:g.scrollTop},p={left:c.left-(h.left+(parseFloat(II.css(g,"borderLeftWidth"))||0))-a,top:c.top-(h.top+(parseFloat(II.css(g,"borderTopWidth"))||0))-o},y={left:c.left+d-(h.left+f+(parseFloat(II.css(g,"borderRightWidth"))||0))+A,top:c.top+u-(h.top+m+(parseFloat(II.css(g,"borderBottomWidth"))||0))+s}),p.top<0||y.top>0?C===!0?II.scrollTop(g,b.top+p.top):C===!1?II.scrollTop(g,b.top+y.top):p.top<0?II.scrollTop(g,b.top+p.top):II.scrollTop(g,b.top+y.top):n||(C=C===void 0?!0:!!C,C?II.scrollTop(g,b.top+p.top):II.scrollTop(g,b.top+y.top)),i&&(p.left<0||y.left>0?r===!0?II.scrollLeft(g,b.left+p.left):r===!1?II.scrollLeft(g,b.left+y.left):p.left<0?II.scrollLeft(g,b.left+p.left):II.scrollLeft(g,b.left+y.left):n||(r=r===void 0?!0:!!r,r?II.scrollLeft(g,b.left+p.left):II.scrollLeft(g,b.left+y.left)))}var I8t=g8t,i8t=I8t;const n8t=JC(i8t);function oH(){return oH=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 aH(e){return aH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},aH(e)}const pZ=[];let B$=function(e){A8t(I,e);var g=s8t(I);function I(i){var n;return C8t(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 r8t(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&&n8t(Aa.findDOMNode(n),Aa.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&&pZ.push({id:pZ.length,state:this.state});const{inputProps:n}=this.props;return N.createElement("div",oH({style:{...this.props.wrapperStyle}},this.props.wrapperProps),N.createElement("input",oH({},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(pZ.slice(pZ.length-5,pZ.length),null,2)))}}]),I}(N.Component);B$.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(){}};B$.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 d8t="_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:d8t,"btn-sm":"_btn-sm_1l2sx_116","btn-default":"_btn-default_1l2sx_122"};function h8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Zse(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 AH(e){return AH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},AH(e)}let l9e=function(e){b8t(I,e);var g=y8t(I);function I(i){var n;return h8t(this,I),n=g.call(this,i),n.mounted=!1,n.uid=sg.nice(),n.chromInfo=null,n.searchField=null,n.autocompleteMenu=null,n.xScale=null,n.yScale=null,n.prevParts=[],n.props.registerViewportChangedListener(n.scalesChanged.bind(s9e(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 m8t(I,[{key:"componentDidMount",value:function(){this.mounted=!0,dg(this.autocompleteMenu.inputEl).on("keypress",this.autocompleteKeyPress.bind(this)),this.findAvailableAutocompleteSources(),this.findAvailableChromSizes(),this.props.chromInfoPath&&(this.searchPosition=!0,Js(this.props.chromInfoPath,n=>{if(!n){this.searchPosition=null;return}this.chromInfo=n,this.searchField=new i0(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(Rr(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){Js(`${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 i0(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]=Si(s,A);n&&this.props.onGeneSearch({geneSymbol:n,range:o,centerX:l,centerY:c}),this.props.setCenters(l,c,u,fGe)}})}},{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:Xg({[Cf["genome-position-search-focus"]]:this.state.isFocused,[Cf["genome-position-search"]]:!this.state.isFocused,[Cf["genome-position-search-dark"]]:this.props.theme===gI})},!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(B$,{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(BGe,{onClick:this.buttonClick.bind(this),theStyle:"multitrack-header-icon"}))}}]),I}(N.Component);l9e.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 v8t=ey(um(l9e)),B8t={"export-link-dialog-wrapper":"_export-link-dialog-wrapper_p9gxw_1"};function S8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Gse(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 sH(e){return sH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},sH(e)}let S$=function(e){W8t(I,e);var g=X8t(I);function I(){return S8t(this,I),g.apply(this,arguments)}return w8t(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:B8t["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(Xs,{onClick:n=>{this.input.select(),document.execCommand("copy")}},"Copy")))}}]),I}(N.Component);S$.defaultProps={onDone:()=>{},url:""};S$.propTypes={onDone:L.func,url:L.string};function k8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function vse(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)}let c9e=function(e){D8t(I,e);var g=F8t(I);function I(i){var n;return k8t(this,I),n=g.call(this,i),n.state={submenuShown:!1},n}return Y8t(I,[{key:"getConfigureViewMenu",value:function(n,C){const r=["backgroundColor"],o={},a={};for(const s of r)if(s in Object.keys(an)&&(o[s]={name:an[s].name},an[s].inlineOptions))for(const A in an[s].inlineOptions){const l=an[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(fO,{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:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gI}),"data-menu-type":"ConfigViewMenu",style:{left:this.state.left,top:this.state.top}},N.createElement(Ig,{onClick:n=>this.props.onTogglePositionSearchBox(n)},"Toggle position search box"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:n=>this.props.onZoomToData(n)},"Zoom to data extent"),N.createElement(Ig,{onClick:n=>this.props.onClearView(n)},"Clear View"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:n=>this.props.onYankZoom(n)},"Take zoom from"),N.createElement(Ig,{onClick:n=>this.props.onYankLocation(n)},"Take location from"),N.createElement(Ig,{onClick:n=>this.props.onYankZoomAndLocation(n)},"Take zoom and location from"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:this.props.onLockZoom},"Lock zoom with"),N.createElement(Ig,{onClick:this.props.onLockLocation},"Lock location with"),N.createElement(Ig,{onClick:this.props.onLockZoomAndLocation},"Lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:this.props.onTakeAndLockZoomAndLocation},"Take and lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:n=>this.props.onUnlockZoom(n)},"Unlock zoom"),N.createElement(Ig,{onClick:n=>this.props.onUnlockLocation(n)},"Unlock location"),N.createElement(Ig,{onClick:n=>this.props.onUnlockZoomAndLocation(n)},"Unlock zoom and location"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:n=>this.props.onProjectViewport(n)},"Show this viewport on"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:n=>this.props.onEditViewConfig(n)},"Edit view config"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(Ig,{onClick:()=>this.props.onExportSVG()},"Export views as SVG"),N.createElement(Ig,{onClick:()=>this.props.onExportPNG()},"Export views as PNG"),N.createElement(Ig,{onClick:()=>this.props.onExportViewAsJSON()},"Export views as JSON"),N.createElement(Ig,{onClick:()=>this.props.onExportViewAsLink()},"Export views as Link"),this.getSubmenu())}}]),I}(pu);c9e.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 Br={"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 u9e(e){return N.createElement("div",null,N.createElement("div",{className:Br["add-track-position-span"]},"Add Track..."),N.createElement("table",{className:Xg(Br["add-track-position-table"],{[Br["add-track-position-table-dark"]]:e.theme===gI})},N.createElement("tbody",null,N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:Br["add-track-position-other"]}),N.createElement("td",{className:Br["add-track-position-top-center"],onClick:()=>e.onTrackPositionChosen("top")},"top"),N.createElement("td",{"aria-hidden":"true",className:Br["add-track-position-other"]})),N.createElement("tr",{style:{height:"80px"}},N.createElement("td",{className:Br["add-track-position-middle-left"],onClick:()=>e.onTrackPositionChosen("left")},"left"),N.createElement("td",{className:Br["add-track-position-middle-middle"],onClick:()=>e.onTrackPositionChosen("center")},"center"),N.createElement("td",{className:Br["add-track-position-middle-right"],onClick:()=>e.onTrackPositionChosen("right")},"right")),N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:Br["add-track-position-other"]}),N.createElement("td",{className:Br["add-track-position-bottom-middle"],onClick:()=>e.onTrackPositionChosen("bottom")},"bottom"),N.createElement("td",{"aria-hidden":"true",className:Br["add-track-position-other"]})))))}u9e.propTypes={onTrackPositionChosen:L.func.isRequired,theme:L.symbol.isRequired};const P8t=um(u9e);function J8t(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 cH(e){return cH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},cH(e)}let w$=function(e){U8t(I,e);var g=Q8t(I);function I(i){var n;return J8t(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(d9e(n)),n}return O8t(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(Dc,{onMenuClosed:()=>{this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},N.createElement(pu,{orientation:"left",position:this.state.addTrackPositionMenuPosition,theme:this.props.theme},N.createElement(P8t,{onTrackPositionChosen:this.handleTrackPositionChosenBound})))),this.state.configMenuUid&&(n=N.createElement(Dc,{onMenuClosed:()=>this.setState({configMenuUid:null})},N.createElement(c9e,{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=Xg(this.state.isFocused?Vr["multitrack-header-focus"]:Vr["multitrack-header"],{[Vr["multitrack-header-dark"]]:this.props.theme===gI}),a=this.state.width<=pGe?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===Mr&&N.createElement("svg",{className:Xg(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>bGe&&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);w$.defaultProps={isGenomePositionSearchBoxVisible:!1};w$.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 q8t=um(w$);var h9e={};Object.defineProperty(h9e,"__esModule",{value:!0});var wl=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,i)&&(I[i]=e[i]);return I}function i6t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Sse(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 n6t(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 C6t=13,r6t=9,o6t=8,a6t=89,LR=90,A6t=77,wse=57,Vse=219,Rse=222,Wse=192,s6t=27,Xse=100,l6t=3e3,c6t="navigator"in globalThis&&/Win/i.test(navigator.platform),bF="navigator"in globalThis&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),NW="npm__react-simple-code-editor__textarea",u6t=` + `),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}(U.PureComponent||U.Component);function w7t(e,g){var i=cr(e)?K9e:Y9e;return i(e,G9e(g))}function _2(e){"@babel/helpers - typeof";return _2=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},_2(e)}var R7t=/^\s+/,V7t=/\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=W7t(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,r,C,o;return i=g.r/255,I=g.g/255,n=g.b/255,i<=.03928?r=i/12.92:r=Math.pow((i+.055)/1.055,2.4),I<=.03928?C=I/12.92:C=Math.pow((I+.055)/1.055,2.4),n<=.03928?o=n/12.92:o=Math.pow((n+.055)/1.055,2.4),.2126*r+.7152*C+.0722*o},setAlpha:function(g){return this._a=q9e(g),this._roundA=Math.round(100*this._a)/100,this},toHsv:function(){var g=JAe(this._r,this._g,this._b);return{h:g.h*360,s:g.s,v:g.v,a:this._a}},toHsvString: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.v*100);return this._a==1?"hsv("+i+", "+I+"%, "+n+"%)":"hsva("+i+", "+I+"%, "+n+"%, "+this._roundA+")"},toHsl:function(){var g=PAe(this._r,this._g,this._b);return{h:g.h*360,s:g.s,l:g.l,a:this._a}},toHslString:function(){var g=PAe(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 OAe(this._r,this._g,this._b,g)},toHexString:function(g){return"#"+this.toHex(g)},toHex8:function(g){return N7t(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(Ri(this._r,255)*100)+"%",g:Math.round(Ri(this._g,255)*100)+"%",b:Math.round(Ri(this._b,255)*100)+"%",a:this._a}},toPercentageRgbString:function(){return this._a==1?"rgb("+Math.round(Ri(this._r,255)*100)+"%, "+Math.round(Ri(this._g,255)*100)+"%, "+Math.round(Ri(this._b,255)*100)+"%)":"rgba("+Math.round(Ri(this._r,255)*100)+"%, "+Math.round(Ri(this._g,255)*100)+"%, "+Math.round(Ri(this._b,255)*100)+"%, "+this._roundA+")"},toName:function(){return this._a===0?"transparent":this._a<1?!1:O7t[OAe(this._r,this._g,this._b,!0)]||!1},toFilter:function(g){var i="#"+_Ae(this._r,this._g,this._b,this._a),I=i,n=this._gradientType?"GradientType = 1, ":"";if(g){var r=Nt(g);I="#"+_Ae(r._r,r._g,r._b,r._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,r=!i&&n&&(g==="hex"||g==="hex6"||g==="hex3"||g==="hex4"||g==="hex8"||g==="name");return r?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(F7t,arguments)},brighten:function(){return this._applyModification(D7t,arguments)},darken:function(){return this._applyModification(x7t,arguments)},desaturate:function(){return this._applyModification(k7t,arguments)},saturate:function(){return this._applyModification(Y7t,arguments)},greyscale:function(){return this._applyModification(K7t,arguments)},spin:function(){return this._applyModification(E7t,arguments)},_applyCombination:function(g,i){return g.apply(null,[this].concat([].slice.call(i)))},analogous:function(){return this._applyCombination(P7t,arguments)},complement:function(){return this._applyCombination(M7t,arguments)},monochromatic:function(){return this._applyCombination(J7t,arguments)},splitcomplement:function(){return this._applyCombination(z7t,arguments)},triad:function(){return this._applyCombination(LAe,[3])},tetrad:function(){return this._applyCombination(LAe,[4])}};Nt.fromRatio=function(e,g){if(_2(e)=="object"){var i={};for(var I in e)e.hasOwnProperty(I)&&(I==="a"?i[I]=e[I]:i[I]=lG(e[I]));e=i}return Nt(e,g)};function W7t(e){var g={r:0,g:0,b:0},i=1,I=null,n=null,r=null,C=!1,o=!1;return typeof e=="string"&&(e=Q7t(e)),_2(e)=="object"&&(OA(e.r)&&OA(e.g)&&OA(e.b)?(g=X7t(e.r,e.g,e.b),C=!0,o=String(e.r).substr(-1)==="%"?"prgb":"rgb"):OA(e.h)&&OA(e.s)&&OA(e.v)?(I=lG(e.s),n=lG(e.v),g=T7t(e.h,I,n),C=!0,o="hsv"):OA(e.h)&&OA(e.s)&&OA(e.l)&&(I=lG(e.s),r=lG(e.l),g=H7t(e.h,I,r),C=!0,o="hsl"),e.hasOwnProperty("a")&&(i=e.a)),i=q9e(i),{ok:C,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 X7t(e,g,i){return{r:Ri(e,255)*255,g:Ri(g,255)*255,b:Ri(i,255)*255}}function PAe(e,g,i){e=Ri(e,255),g=Ri(g,255),i=Ri(i,255);var I=Math.max(e,g,i),n=Math.min(e,g,i),r,C,o=(I+n)/2;if(I==n)r=C=0;else{var a=I-n;switch(C=o>.5?a/(2-I-n):a/(I+n),I){case e:r=(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=r=i;else{var o=i<.5?i*(1+g):i+g-i*g,a=2*i-o;I=C(a,o,e+1/3),n=C(a,o,e),r=C(a,o,e-1/3)}return{r:I*255,g:n*255,b:r*255}}function JAe(e,g,i){e=Ri(e,255),g=Ri(g,255),i=Ri(i,255);var I=Math.max(e,g,i),n=Math.min(e,g,i),r,C,o=I,a=I-n;if(C=I===0?0:a/I,I==n)r=0;else{switch(I){case e:r=(g-i)/a+(g>1)+720)%360;--g;)I.h=(I.h+n)%360,r.push(Nt(I));return r}function J7t(e,g){g=g||6;for(var i=Nt(e).toHsv(),I=i.h,n=i.s,r=i.v,C=[],o=1/g;g--;)C.push(Nt({h:I,s:n,v:r})),r=(r+o)%1;return C}Nt.mix=function(e,g,i){i=i===0?0:i||50;var I=Nt(e).toRgb(),n=Nt(g).toRgb(),r=i/100,C={r:(n.r-I.r)*r+I.r,g:(n.g-I.g)*r+I.g,b:(n.b-I.b)*r+I.b,a:(n.a-I.a)*r+I.a};return Nt(C)};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,r;switch(r=!1,n=j7t(i),n.level+n.size){case"AAsmall":case"AAAlarge":r=I>=4.5;break;case"AAlarge":r=I>=3;break;case"AAAsmall":r=I>=7;break}return r};Nt.mostReadable=function(e,g,i){var I=null,n=0,r,C,o,a;i=i||{},C=i.includeFallbackColors,o=i.level,a=i.size;for(var s=0;sn&&(n=r,I=Nt(g[s]));return Nt.isReadable(e,I,{level:o,size:a})||!C?I:(i.includeFallbackColors=!1,Nt.mostReadable(e,["#fff","#000"],i))};var sO=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"},O7t=Nt.hexNames=_7t(sO);function _7t(e){var g={};for(var i in e)e.hasOwnProperty(i)&&(g[e[i]]=i);return g}function q9e(e){return e=parseFloat(e),(isNaN(e)||e<0||e>1)&&(e=1),e}function Ri(e,g){L7t(e)&&(e="100%");var i=U7t(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 _k(e){return Math.min(1,Math.max(0,e))}function jr(e){return parseInt(e,16)}function L7t(e){return typeof e=="string"&&e.indexOf(".")!=-1&&parseFloat(e)===1}function U7t(e){return typeof e=="string"&&e.indexOf("%")!=-1}function qo(e){return e.length==1?"0"+e:""+e}function lG(e){return e<=1&&(e=e*100+"%"),e}function eXe(e){return Math.round(parseFloat(e)*255).toString(16)}function UAe(e){return jr(e)/255}var Yo=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 OA(e){return!!Yo.CSS_UNIT.exec(e)}function Q7t(e){e=e.replace(R7t,"").replace(V7t,"").toLowerCase();var g=!1;if(sO[e])e=sO[e],g=!0;else if(e=="transparent")return{r:0,g:0,b:0,a:0,format:"name"};var i;return(i=Yo.rgb.exec(e))?{r:i[1],g:i[2],b:i[3]}:(i=Yo.rgba.exec(e))?{r:i[1],g:i[2],b:i[3],a:i[4]}:(i=Yo.hsl.exec(e))?{h:i[1],s:i[2],l:i[3]}:(i=Yo.hsla.exec(e))?{h:i[1],s:i[2],l:i[3],a:i[4]}:(i=Yo.hsv.exec(e))?{h:i[1],s:i[2],v:i[3]}:(i=Yo.hsva.exec(e))?{h:i[1],s:i[2],v:i[3],a:i[4]}:(i=Yo.hex8.exec(e))?{r:jr(i[1]),g:jr(i[2]),b:jr(i[3]),a:UAe(i[4]),format:g?"name":"hex8"}:(i=Yo.hex6.exec(e))?{r:jr(i[1]),g:jr(i[2]),b:jr(i[3]),format:g?"name":"hex"}:(i=Yo.hex4.exec(e))?{r:jr(i[1]+""+i[1]),g:jr(i[2]+""+i[2]),b:jr(i[3]+""+i[3]),a:UAe(i[4]+""+i[4]),format:g?"name":"hex8"}:(i=Yo.hex3.exec(e))?{r:jr(i[1]+""+i[1]),g:jr(i[2]+""+i[2]),b:jr(i[3]+""+i[3]),format:g?"name":"hex"}:!1}function j7t(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 QAe=function(g){var i=["r","g","b","a","h","s","l","v"],I=0,n=0;return w7t(i,function(r){if(g[r]&&(I+=1,isNaN(g[r])||(n+=1),r==="s"||r==="l")){var C=/^\d+%$/;C.test(g[r])&&(n+=1)}}),I===n?g:!1},cG=function(g,i){var I=g.hex?Nt(g.hex):Nt(g),n=I.toHsl(),r=I.toHsv(),C=I.toRgb(),o=I.toHex();n.s===0&&(n.h=i||0,r.h=i||0);var a=o==="000000"&&C.a===0;return{hsl:n,hex:a?"transparent":"#"+o,rgb:C,hsv:r,oldHue:g.h||i||n.h,source:g.source}},mu=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()},s$=function(g){if(!g)return"#fff";var i=cG(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"},px=function(g,i){var I=g.replace("°","");return Nt(i+" ("+I+")")._ok},fZ=Object.assign||function(e){for(var g=1;g1&&arguments[1]!==void 0?arguments[1]:"span";return function(I){nQt(n,I);function n(){var r,C,o,a;IQt(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 LV=24,hQt=iXe.default=function(e){var g=e.fill,i=g===void 0?"currentColor":g,I=e.width,n=I===void 0?LV:I,r=e.height,C=r===void 0?LV:r,o=e.style,a=o===void 0?{}:o,s=dQt(e,["fill","width","height","style"]);return tse.default.createElement("svg",ese({viewBox:"0 0 "+LV+" "+LV,style:ese({fill:i,width:n,height:C},a)},s),tse.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"}))},mQt=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"},r)):(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(qAe(n.s)?I.props.hsl.s:n.s),l:Number(qAe(n.l)?I.props.hsl.l:n.l),source:"hsl"},r))},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 mQt(g,[{key:"render",value:function(){var I=this,n=jt({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),r=void 0;return this.state.view==="hex"?r=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Bg,{style:{input:n.input,label:n.label},label:"hex",value:this.props.hex,onChange:this.handleChange}))):this.state.view==="rgb"?r=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Bg,{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(Bg,{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(Bg,{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(Bg,{style:{input:n.input,label:n.label},label:"a",value:this.props.rgb.a,arrowOffset:.01,onChange:this.handleChange}))):this.state.view==="hsl"&&(r=N.createElement("div",{style:n.fields,className:"flexbox-fix"},N.createElement("div",{style:n.field},N.createElement(Bg,{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(Bg,{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(Bg,{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(Bg,{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"},r,N.createElement("div",{style:n.toggle},N.createElement("div",{style:n.icon,onClick:this.toggleViews,ref:function(o){return I.icon=o}},N.createElement(hQt,{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);IXe.defaultProps={view:"hex"};var gse=function(){var g=jt({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})},yQt=function(){var g=jt({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})},u$=function(g){var i=g.width,I=g.onChange,n=g.disableAlpha,r=g.rgb,C=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=jt(Or({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("+r.r+", "+r.g+", "+r.b+", "+r.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(Ok,{style:h.Saturation,hsl:C,hsv:o,pointer:yQt,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(ly,{renderers:s}))),N.createElement("div",{style:h.toggles},N.createElement("div",{style:h.hue},N.createElement(cy,{style:h.Hue,hsl:C,pointer:gse,onChange:I})),N.createElement("div",{style:h.alpha},N.createElement(A$,{style:h.Alpha,rgb:r,hsl:C,pointer:gse,renderers:s,onChange:I})))),N.createElement(IXe,{rgb:r,hsl:C,hex:a,view:d,onChange:I,disableAlpha:n})))};u$.propTypes={width:L.oneOfType([L.string,L.number]),disableAlpha:L.bool,styles:L.object,defaultView:L.oneOf(["hex","rgb","hsl"])};u$.defaultProps={width:225,disableAlpha:!1,styles:{}};_r(u$);var ZQt=function(g){var i=g.color,I=g.onClick,n=I===void 0?function(){}:I,r=g.onSwatchHover,C=g.active,o=jt({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:s$(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:C,"color-#FFFFFF":i==="#FFFFFF",transparent:i==="transparent"});return N.createElement(ym,{style:o.color,color:i,onClick:n,onHover:r,focusStyle:{boxShadow:"0 0 4px "+i}},N.createElement("div",{style:o.dot}))},GQt=function(g){var i=g.hex,I=g.rgb,n=g.onChange,r=jt({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"}}}),C=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:r.fields,className:"flexbox-fix"},N.createElement("div",{style:r.active}),N.createElement(Bg,{style:{wrap:r.HEXwrap,input:r.HEXinput,label:r.HEXlabel},label:"hex",value:i,onChange:C}),N.createElement(Bg,{style:{wrap:r.RGBwrap,input:r.RGBinput,label:r.RGBlabel},label:"r",value:I.r,onChange:C}),N.createElement(Bg,{style:{wrap:r.RGBwrap,input:r.RGBinput,label:r.RGBlabel},label:"g",value:I.g,onChange:C}),N.createElement(Bg,{style:{wrap:r.RGBwrap,input:r.RGBinput,label:r.RGBlabel},label:"b",value:I.b,onChange:C}))},d$=function(g){var i=g.onChange,I=g.onSwatchHover,n=g.colors,r=g.hex,C=g.rgb,o=g.styles,a=o===void 0?{}:o,s=g.className,A=s===void 0?"":s,l=jt(Or({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?mu(d.hex)&&i({hex:d.hex,source:"hex"},h):i(d,h)};return N.createElement(Nw,{style:l.Compact,styles:a},N.createElement("div",{style:l.compact,className:"compact-picker "+A},N.createElement("div",null,hu(n,function(u){return N.createElement(ZQt,{key:u,color:u,active:u.toLowerCase()===r,onClick:c,onSwatchHover:I})}),N.createElement("div",{style:l.clear})),N.createElement(GQt,{hex:r,rgb:C,onChange:c})))};d$.propTypes={colors:L.arrayOf(L.string),styles:L.object};d$.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:{}};_r(d$);var vQt=function(g){var i=g.hover,I=g.color,n=g.onClick,r=g.onSwatchHover,C={position:"relative",zIndex:"2",outline:"2px solid #fff",boxShadow:"0 0 5px 2px rgba(0,0,0,0.25)"},o=jt({default:{swatch:{width:"25px",height:"25px",fontSize:"0"}},hover:{swatch:C}},{hover:i});return N.createElement("div",{style:o.swatch},N.createElement(ym,{color:I,onClick:n,onHover:r,focusStyle:C}))};const BQt=a$(vQt);var h$=function(g){var i=g.width,I=g.colors,n=g.onChange,r=g.onSwatchHover,C=g.triangle,o=g.styles,a=o===void 0?{}:o,s=g.className,A=s===void 0?"":s,l=jt(Or({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":C==="hide","top-left-triangle":C==="top-left","top-right-triangle":C==="top-right","bottom-left-triangle":C==="bottom-left","bottom-right-triangle":C==="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}),hu(I,function(u){return N.createElement(BQt,{color:u,key:u,onClick:c,onSwatchHover:r})}))};h$.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};h$.defaultProps={width:200,colors:["#B80000","#DB3E00","#FCCB00","#008B02","#006B76","#1273DE","#004DCF","#5300EB","#EB9694","#FAD0C3","#FEF3BD","#C1E1C5","#BEDADC","#C4DEF6","#BED3F3","#D4C4FB"],triangle:"top-left",styles:{}};_r(h$);var SQt=function(g){var i=g.direction,I=jt({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})},wQt=Object.assign||function(e){for(var g=1;g.5});return N.createElement("div",{style:I.picker})},XQt=function(){var g=jt({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})))},ise=function(g){var i=g.onClick,I=g.label,n=g.children,r=g.active,C=jt({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:r});return N.createElement("div",{style:C.button,onClick:i},I||n)},HQt=function(g){var i=g.rgb,I=g.currentColor,n=jt({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"))},TQt=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(Bg,{style:{input:o.input,label:o.label},label:"hex",value:r.replace("#",""),onChange:a})),N.createElement("div",{style:o.single},N.createElement(Bg,{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(Bg,{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(Bg,{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(Bg,{style:{input:o.input,label:o.label},label:"a",value:Math.round(I.a*100),onChange:a,dragLabel:"true",dragMax:"100"})))},FQt=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,I)&&(i[I]=e[I]);return i}var UV=24,OQt=rXe.default=function(e){var g=e.fill,i=g===void 0?"currentColor":g,I=e.width,n=I===void 0?UV:I,r=e.height,C=r===void 0?UV:r,o=e.style,a=o===void 0?{}:o,s=JQt(e,["fill","width","height","style"]);return nse.default.createElement("svg",Ise({viewBox:"0 0 "+UV+" "+UV,style:Ise({fill:i,width:n,height:C},a)},s),nse.default.createElement("path",{d:"M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z"}))},_Qt=function(g){var i=g.color,I=g.onClick,n=I===void 0?function(){}:I,r=g.onSwatchHover,C=g.first,o=g.last,a=g.active,s=jt({default:{color:{width:"40px",height:"24px",cursor:"pointer",background:i,marginBottom:"1px"},check:{color:s$(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:C,last:o,active:a,"color-#FFFFFF":i==="#FFFFFF",transparent:i==="transparent"});return N.createElement(ym,{color:i,style:s.color,onClick:n,onHover:r,focusStyle:{boxShadow:"0 0 4px "+i}},N.createElement("div",{style:s.check},N.createElement(OQt,null)))},LQt=function(g){var i=g.onClick,I=g.onSwatchHover,n=g.group,r=g.active,C=jt({default:{group:{paddingBottom:"10px",width:"40px",float:"left",marginRight:"10px"}}});return N.createElement("div",{style:C.group},hu(n,function(o,a){return N.createElement(_Qt,{key:o,color:o,active:o.toLowerCase()===r,first:a===0,last:a===n.length-1,onClick:i,onSwatchHover:I})}))},y$=function(g){var i=g.width,I=g.height,n=g.onChange,r=g.onSwatchHover,C=g.colors,o=g.hex,a=g.styles,s=a===void 0?{}:a,A=g.className,l=A===void 0?"":A,c=jt(Or({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(Nw,null,N.createElement("div",{style:c.overflow},N.createElement("div",{style:c.body},hu(C,function(d){return N.createElement(LQt,{key:d.toString(),group:d,active:o,onClick:u,onSwatchHover:r})}),N.createElement("div",{style:c.clear})))))};y$.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};y$.defaultProps={width:320,height:240,colors:[[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]],[Rf[900],Rf[700],Rf[500],Rf[300],Rf[100]],[Vf[900],Vf[700],Vf[500],Vf[300],Vf[100]],[Wf[900],Wf[700],Wf[500],Wf[300],Wf[100]],["#194D33",uG[700],uG[500],uG[300],uG[100]],[Xf[900],Xf[700],Xf[500],Xf[300],Xf[100]],[Hf[900],Hf[700],Hf[500],Hf[300],Hf[100]],[Tf[900],Tf[700],Tf[500],Tf[300],Tf[100]],[Nf[900],Nf[700],Nf[500],Nf[300],Nf[100]],[kf[900],kf[700],kf[500],kf[300],kf[100]],[Yf[900],Yf[700],Yf[500],Yf[300],Yf[100]],[Kf[900],Kf[700],Kf[500],Kf[300],Kf[100]],[Ff[900],Ff[700],Ff[500],Ff[300],Ff[100]],["#000000","#525252","#969696","#D9D9D9","#FFFFFF"]],styles:{}};_r(y$);var Z$=function(g){var i=g.onChange,I=g.onSwatchHover,n=g.hex,r=g.colors,C=g.width,o=g.triangle,a=g.styles,s=a===void 0?{}:a,A=g.className,l=A===void 0?"":A,c=jt(Or({default:{card:{width:C,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){mu(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},hu(r,function(d,h){return N.createElement(ym,{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(Bg,{label:null,style:{input:c.input},value:n.replace("#",""),onChange:u}),N.createElement("div",{style:c.clear})))};Z$.propTypes={width:L.oneOfType([L.string,L.number]),triangle:L.oneOf(["hide","top-left","top-right"]),colors:L.arrayOf(L.string),styles:L.object};Z$.defaultProps={width:276,colors:["#FF6900","#FCB900","#7BDCB5","#00D084","#8ED1FC","#0693E3","#ABB8C3","#EB144C","#F78DA7","#9900EF"],triangle:"top-left",styles:{}};_r(Z$);var G$=function(g){var i=jt({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})};G$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};G$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var v$=function(g){var i=jt({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})};v$.propTypes={hsl:L.shape({h:L.number,s:L.number,l:L.number,a:L.number})};v$.defaultProps={hsl:{a:1,h:249.94,l:.2,s:.5}};var UQt=function(g){var i=g.onChange,I=g.rgb,n=g.hsl,r=g.hex,C=g.hsv,o=function(u,d){if(u.hex)mu(u.hex)&&i({hex:u.hex,source:"hex"},d);else if(u.rgb){var h=u.rgb.split(",");px(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(",");px(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(",");px(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=jt({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(C.h)+"°, "+Math.round(C.s*100)+"%, "+Math.round(C.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(Bg,{style:{input:a.input,label:a.label},label:"hex",value:r,onChange:o})),N.createElement("div",{style:a.column},N.createElement("div",{style:a.single},N.createElement(Bg,{style:{input:a.input2,label:a.label2},label:"rgb",value:s,onChange:o})),N.createElement("div",{style:a.single},N.createElement(Bg,{style:{input:a.input2,label:a.label2},label:"hsv",value:l,onChange:o})),N.createElement("div",{style:a.single},N.createElement(Bg,{style:{input:a.input2,label:a.label2},label:"hsl",value:A,onChange:o})))))},B$=function(g){var i=g.width,I=g.onChange,n=g.rgb,r=g.hsl,C=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=jt(Or({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(Ok,{hsl:r,hsv:C,pointer:G$,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(cy,{style:u.Hue,hsl:r,radius:"4px",pointer:v$,onChange:I}))),N.createElement(UQt,{rgb:n,hsl:r,hex:o,hsv:C,onChange:I})))};B$.propTypes={width:L.oneOfType([L.string,L.number]),styles:L.object,header:L.string};B$.defaultProps={width:652,styles:{},header:"Color picker"};_r(B$);function QQt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function rse(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 L2(e){return L2=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},L2(e)}let CXe=function(e){e4t(i,e);var g=t4t(i);function i(I){var n;QQt(this,i),n=g.call(this,I);const r=Sb(I.color);return n.state={displayColorPicker:!1,color:{r:r.r,g:r.g,b:r.b,a:r.opacity}},n}return jQt(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 r=n.rgb,C=`rgba(${r.r},${r.g},${r.b},${r.a})`;this.props.onChange(C),this.setState({color:n.rgb})}},{key:"render",value:function(){const n=jt({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(xQt,{color:this.state.color,onChange:this.handleChange.bind(this)})):null)}}]),i}(N.Component);CXe.propTypes={color:L.string,onChange:L.func};function n4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Cse(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 uO=function(e){a4t(i,e);var g=A4t(i);function i(I){var n;return n4t(this,i),n=g.call(this,I),n.state={colors:I.track.options.colorRange.slice()},n}return r4t(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(r=>({colors:r.colors.slice(0,n).concat(r.colors.slice(n+1))}))}},{key:"render",value:function(){const n=JSON.parse(JSON.stringify(this.props.track)),r=Object.assign(n,{options:{colorRange:this.state.colors}}),C={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:[r]},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(CXe,{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(vw,{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(dy,{options:{bounded:!1},viewConfig:C}))))))),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);uO.propTypes={handleCancel:L.func,onCancel:L.func,onSubmit:L.func,track:L.object,xScale:L.object,yScale:L.object};const ose=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),{}),Ur={yes:{name:"Yes",value:!0},no:{name:"No",value:!1}},Ni={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"}},u4t={use_stroke:{name:"Glyph color",value:"[glyph-color]"}},dG=u0([1,2,3,5,8,13,21]),d4t=Object.assign(dG,{none:{name:"none",value:"none"}}),QV=u0([0,2,4,8,16,32,64,128,256]),Sl=u0([0,.2,.4,.6,.8,1],"%",100),h4t=u0([.2,.4,.6,.8,1],"%",100),an={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:QV},labelRightMargin:{name:"Label Right Margin",inlineOptions:QV},labelTopMargin:{name:"Label Top Margin",inlineOptions:QV},labelBottomMargin:{name:"Label Bottom Margin",inlineOptions:QV},labelShowResolution:{name:"Label Show Resolution",inlineOptions:Ur},labelShowAssembly:{name:"Label Show Assembly",inlineOptions:Ur},lineStrokeWidth:{name:"Stroke Width",inlineOptions:dG},strokeWidth:{name:"Stroke Width",inlineOptions:dG},trackBorderWidth:{name:"Track Border Width",inlineOptions:dG},separatePlusMinusStrands:{name:"Separate +/- strands",inlineOptions:Ur},sortLargestOnTop:{name:"Sort Largest On Top",inlineOptions:Ur},showTexts:{name:"Show texts",inlineOptions:Ur},staggered:{name:"Staggered",inlineOptions:Ur},minSquareSize:{name:"Minimum size",inlineOptions:d4t},pointSize:{name:"Point Size",inlineOptions:dG},pointColor:{name:"Point Color",inlineOptions:Ni},trackBorderColor:{name:"Track Border Color",inlineOptions:Ni},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:Ni},plusStrandColor:{name:"+ Strand Color",inlineOptions:Ni},lineStrokeColor:{name:"Stroke color",inlineOptions:Ni},projectionStrokeColor:{name:"Stroke color",inlineOptions:Ni},projectionFillColor:{name:"Fill color",inlineOptions:Ni},stroke:{name:"Stroke Color",inlineOptions:Ni},strokeColor:{name:"Stroke color",inlineOptions:Ni},fill:{name:"Fill Color",inlineOptions:Ni},color:{name:"Color",inlineOptions:Ni},fontColor:{name:"Font color",inlineOptions:Ni},fillColor:{name:"Fill color",inlineOptions:Ni},barFillColor:{name:"Fill color",inlineOptions:Ni},barFillColorTop:{name:"Top Fill color",inlineOptions:Ni},barFillColorBottom:{name:"Bottom Fill color",inlineOptions:Ni},barOpacity:{name:"Bar opacity",inlineOptions:Sl},zeroLineVisible:{name:"Zero line visible",inlineOptions:Ur},zeroLineColor:{name:"Zero line color",inlineOptions:Ni},zeroLineOpacity:{name:"Zero line opacity",inlineOptions:h4t},fillOpacity:{name:"Fill Opacity",inlineOptions:Sl},strokeOpacity:{name:"Stroke Opacity",inlineOptions:Sl},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:Ur},scaledHeight:{name:"Scaled height",inlineOptions:Ur},rectangleDomainStrokeColor:{name:"Stroke color",inlineOptions:Ni},rectangleDomainFillColor:{name:"Fill color",inlineOptions:Ni},rectangleDomainFillOpacity:{name:"Fill opacity",inlineOptions:Sl},rectangleDomainOpacity:{name:"Opacity",inlineOptions:Sl},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:Ur},showTooltip:{name:"Show Tooltip",inlineOptions:Ur},fontSize:{name:"Font Size",inlineOptions:u0([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:ose},fontIsAligned:{name:"Left-Align Font",inlineOptions:Ur},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:u0([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:Ni},colorbarBackgroundOpacity:{name:"Colorbar Background Opacity",inlineOptions:Sl},colorbarLabelsPosition:{name:"Colorbar Labels Position",inlineOptions:{inside:{name:"Inside",value:"inside"},outside:{name:"Outside",value:"outside"}}},labelColor:{name:"Label Color",inlineOptions:{...Ni,...u4t}},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:Sl},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:Ni},labelBackgroundOpacity:{name:"Label Background Opacity",inlineOptions:Sl},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:uO,"horizontal-heatmap":uO}}}},align:{name:"Align",inlineOptions:{white:{name:"Top",value:"top"},lightGrey:{name:"Bottom",value:"bottom"}}},colorRangeGradient:{name:"Color Gradient",inlineOptions:Ur},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:r}=e;let C=1,o=1;if(e.resolutions){const l=e.resolutions.map(c=>+c).sort((c,u)=>u-c);[C]=l,o=l[i]}else o=e.maxWidth/(2**i*e.binsPerDimension),C=I/(2**r*n);const a=D0(C,o),A=tm(`.${a}`,o)(o);g.push({name:A,value:i.toString()})}return g}return[]}},valueColumn:{name:"Value column",inlineOptions:{none:{name:"None",value:null}},generateOptions:ose},zeroValueColor:{name:"Zero Value Color",inlineOptions:Ni}},oXe={...Kst,IS_TRACK_RANGE_SELECTABLE:E0,OPTIONS_INFO:an},m4t={d3Array:wit,d3Axis:WTt,d3Brush:GAt,d3Color:Eit,d3Drag:tat,d3Dsv:rlt,d3Format:dIt,d3Geo:IMt,d3Queue:aMt,d3Request:VMt,d3Scale:Pnt,d3Selection:Sgt,d3Transition:gWt,d3Zoom:aWt,PIXI:oXe.GLOBALS.PIXI,mix:oy,slugid:sg},f4t={Annotations1dTrack:QP,Annotations2dTrack:K1e,ArrowheadDomainsTrack:k1e,BarTrack:Zj,BedLikeTrack:w1e,CNVIntervalTrack:T1e,Chromosome2DAnnotations:E1e,Chromosome2DLabels:x1e,ChromosomeGrid:nG,CombinedTrack:_Q,CrossRule:aWe,DivergentBarTrack:X1e,HeatmapTiledPixiTrack:mw,Horizontal1dHeatmapTrack:H1e,Horizontal2DDomainsTrack:F1e,HorizontalChromosomeLabels:z1e,HorizontalGeneAnnotationsTrack:N1e,HorizontalHeatmapTrack:P1e,HorizontalLine1DPixiTrack:Cy,HorizontalMultivecTrack:W1e,HorizontalPoint1DPixiTrack:V1e,HorizontalRule:gWe,HorizontalTiled1DPixiTrack:ny,HorizontalTiledPlot:E2,HorizontalTrack:C9e,Id2DTiledPixiTrack:MVe,IdHorizontal1DTiledPixiTrack:PVe,IdVertical1DTiledPixiTrack:OVe,LeftAxisTrack:QVe,MapboxTilesTrack:lWe,MoveableTrack:Fk,OSMTileIdsTrack:sWe,OSMTilesTrack:pw,OverlayTrack:R1e,PixiTrack:mr,RasterTilesTrack:cWe,SVGTrack:mm,SquareMarkersTrack:D1e,Tiled1DPixiTrack:cj,TiledPixiTrack:hm,TopAxisTrack:UVe,Track:xp,ValueIntervalTrack:O1e,VerticalRule:oWe,VerticalTiled1DPixiTrack:JVe,VerticalTrack:a9e,ViewportTracker2D:_1e,ViewportTracker2DPixi:U3t,ViewportTrackerHorizontal:L1e,ViewportTrackerVertical:U1e},p4t={ContextMenuItem:ig,DataFetcher:vk,LruCache:s9e},b4t={ChromosomeInfo:Js,SearchField:n0},y4t={DataFetcher:vk,GBKDataFetcher:FVe,LocalDataFetcher:DVe,getDataFetcher:Pxt},Q2={chromosomes:b4t,libraries:m4t,tracks:f4t,dataFetchers:y4t,factories:p4t,services:Flt,utils:BWt,configs:oXe,VERSION:l9e},bx={"track-renderer":"_track-renderer_11dwb_1","track-renderer-element":"_track-renderer-element_11dwb_5","track-renderer-events":"_track-renderer-events_11dwb_6"};function Z4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ase(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)}const{getDataFetcher:W4t}=Q2.dataFetchers,X4t=100;let S$=function(e){S4t(i,e);var g=w4t(i);function i(I){var n;if(Z4t(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=JI,n.windowScrolledBound=n.windowScrolled.bind(Ko(n)),n.zoomStartedBound=n.zoomStarted.bind(Ko(n)),n.zoomedBound=n.zoomed.bind(Ko(n)),n.zoomEndedBound=n.zoomEnded.bind(Ko(n)),n.uid=sg.nice(),n.viewUid=n.props.uid,n.availableForPlugins={...Q2,services:{...Q2.services,pubSub:n.props.pubSub,pixiRenderer:n.props.pixiRenderer}},n.mounted=!1,n.emptyZoomBehavior=iP(),n.currentProps=I,n.prevPropsStr="",n.zoomBehavior=iP().filter(r=>!(r.target.classList.contains("no-zoom")||r.target.classList.contains("react-resizable-handle"))).on("start",n.zoomStartedBound).on("zoom",n.zoomedBound).on("end",n.zoomEndedBound),n.zoomTransform=JI,n.prevZoomTransform=JI,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 r in window.higlassTracksByType)Qg[r]=window.higlassTracksByType[r].config;return n.boundForwardEvent=n.forwardEvent.bind(Ko(n)),n.boundScrollEvent=n.scrollEvent.bind(Ko(n)),n.boundForwardContextMenu=n.forwardContextMenu.bind(Ko(n)),n.dispatchEventBound=n.dispatchEvent.bind(Ko(n)),n.zoomToDataPosHandlerBound=n.zoomToDataPosHandler.bind(Ko(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(Ko(n)),n.elementPos={height:0,width:0,left:0,top:0},n.elementSelection=null,n}return G4t(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=dg(this.element),this.pStage=new ot.PIXI.Graphics,this.pMask=new ot.PIXI.Graphics,this.pOutline=new ot.PIXI.Graphics,this.pBackground=new ot.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])]],r=this.svgElement.getBoundingClientRect(),C=[[Math.max(n[0][0],0),Math.max(n[0][1],0)],[Math.min(n[1][0],r.width),Math.min(n[1][1],r.height)]];this.zoomBehavior.extent(C).translateExtent(n).scaleExtent(this.zoomLimits)}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(!n.svgElement||!n.canvasElement)return;const r=this.updatablePropsToString(n);if(this.currentProps=n,this.prevPropsStr===r)return;this.setBackground();for(const s in this.trackDefObjects){const A=this.trackDefObjects[s].trackObject;A.delayDrawing=!0}this.prevPropsStr=r,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 C=[[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(C[0][0],0),Math.max(C[0][1],0)],[Math.min(C[1][0],o.width),Math.min(C[1][1],o.height)]];this.zoomBehavior.extent(a).translateExtent(C).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),U1(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=JI),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,r;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),(r=this.pStage)==null||r.destroy(!0),this.pubSubs.forEach(C=>this.props.pubSub.unsubscribe(C)),this.pubSubs=[],this.removeEventTracker()}},{key:"dispatchEvent",value:function(n){n.sourceUid===this.uid&&n.type!=="contextmenu"&&this.element&&vX(n,this.element)}},{key:"isWithin",value:function(n,r){const C=n>=this.elementPos.left&&n<=this.elementPos.width+this.elementPos.left,o=r>=this.elementPos.top&&r<=this.elementPos.height+this.elementPos.top;return C&&o}},{key:"zoomToDataPosHandler",value:function({pos:n,animateTime:r}){this.zoomToDataPos(...n,r)}},{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,r,C,o;(n=this.pMask)==null||n.clear(),(r=this.pMask)==null||r.beginFill(),(C=this.pMask)==null||C.drawRect(this.xPositionOffset,this.yPositionOffset,this.currentProps.width,this.currentProps.height),(o=this.pMask)==null||o.endFill()}},{key:"setBackground",value:function(){var n,r,C,o,a;const s=this.props.theme===gi?"black":"white",A=Kt(((n=this.currentProps.viewOptions)==null?void 0:n.backgroundColor)??s);(r=this.pBackground)==null||r.clear(),(C=this.pBackground)==null||C.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()},X4t)}},{key:"setUpInitialScales",value:function(n=[0,1],r=[0,1],C=[-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=(r[0]+r[1])/2;if(r[0]=A-s/2,r[1]=A+s/2,n[0]===this.initialXDomain[0]&&n[1]===this.initialXDomain[1]&&r[0]===this.initialYDomain[0]&&r[1]===this.initialYDomain[1]&&C[0]===this.xDomainLimits[0]&&C[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=r,this.xDomainLimits=C,this.yDomainLimits=o,this.zoomLimits=a,this.zoomTransform=JI,this.prevZoomTransform=JI,this.cumCenterYOffset=0,this.cumCenterXOffset=0,this.drawableToDomainX=tg().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=tg().domain([l,c]).range([r[0],r[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 r=this.currentProps.paddingLeft+this.currentProps.leftWidth+this.currentProps.centerWidth/2,C=this.currentProps.paddingTop+this.currentProps.topHeight+this.currentProps.centerHeight/2;if(!this.drawableToDomainX||!this.drawableToDomainY)return;const o=(this.drawableToDomainX(r)-this.drawableToDomainX(this.prevCenterX))/this.zoomTransform.k,a=(this.drawableToDomainY(C)-this.drawableToDomainY(this.prevCenterY))/this.zoomTransform.k;this.cumCenterYOffset+=a,this.cumCenterXOffset+=o,this.prevCenterY=C,this.prevCenterX=r;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=tg().domain(s).range([0,this.currentProps.width]),this._yScale=tg().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 r=HC(this.trackDefObjects);for(const[,{trackDef:C,trackObject:o}]of r){if(o===n)return C.track;if(U1(C.track)){for(const a of C.track.contents)if(o.createdTracks[a.uid]===n)return a}}return null}},{key:"getTrackObject",value:function(n){const r=HC(this.trackDefObjects);for(let C=0;Co.uid));this.addMetaTracks(n.filter(o=>!this.metaTracks[o.uid])),this.updateMetaTracks(n.filter(o=>this.metaTracks[o.uid])),this.removeMetaTracks(r.filter(o=>!C.has(o)))}},{key:"syncTrackObjects",value:function(n){this.prevTrackDefinitions=JSON.stringify(n);const r={};for(let l=0;l!C.has(l))),s=new Set([...C].filter(l=>!o.has(l))),A=new Set([...o].filter(l=>C.has(l)));this.updateExistingTrackDefs([...A].map(l=>r[l])),this.addNewTracks([...a].map(l=>r[l])),this.updateExistingTrackDefs([...a].map(l=>r[l])),this.removeTracks([...s])}},{key:"addMetaTracks",value:function(n){n.filter(r=>!this.metaTracks[r.uid]).forEach(r=>{this.metaTracks[r.uid]={trackDef:r,trackObject:this.createMetaTrack(r)}})}},{key:"addNewTracks",value:function(n){if(this.currentProps.pixiStage){for(let r=0;r{this.metaTracks[r].trackObject.remove(),this.metaTracks[r]=void 0,delete this.metaTracks[r]})}},{key:"removeTracks",value:function(n){for(let r=0;r{const p=JI.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,JI.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 r of this.getTracksAtPosition(...this.zoomStartPos))r.movedY(n);this.zoomStartTransform&&(this.zoomTransform=this.zoomStartTransform)}}},{key:"valueScaleZoom",value:function(n,r){if(!xlt(n.sourceEvent))return;const C=n.sourceEvent.deltaY,o=n.sourceEvent.deltaMode,s=((l,c)=>l*(c?120:1)/500)(C,o),A=zg(n.sourceEvent,this.props.canvasElement);for(const l of this.getTracksAtPosition(...A)){const c=r==="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 r;let C=null;if(this.zoomStartPos){const a=this.getTracksAtPosition(...this.zoomStartPos);if(a.length){const s=a[0],A=this.getTrackDef(s);if(!A)return;(r=Qg[A.type])!=null&&r.orientation&&(C=Qg[A.type].orientation),s instanceof Koe&&(C="1d-vertical")}}if(C&&n.sourceEvent){if(n.shiftKey||this.valueScaleZooming){if(n.sourceEvent.deltaY!==void 0){this.valueScaleZoom(n,C);return}C==="1d-horizontal"?this.valueScaleMove(n.sourceEvent.movementY):C==="1d-vertical"&&this.valueScaleMove(n.sourceEvent.movementX)}C==="1d-horizontal"&&n.sourceEvent.movementY?this.valueScaleMove(n.sourceEvent.movementY):C==="1d-vertical"&&n.sourceEvent.movementX&&this.valueScaleMove(n.sourceEvent.movementX)}this.zoomTransform=this.currentProps.zoomable?n.transform:JI,this.prevZoomTransform.k!==this.zoomTransform.k||(C==="1d-horizontal"?this.zoomTransform=JI.translate(this.zoomTransform.x,this.prevZoomTransform.y).scale(this.zoomTransform.k):C==="1d-vertical"&&(this.zoomTransform=JI.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,r){const C=[];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]<=r&&r<=a.position[1]+a.dimensions[1];s&&A&&C.push(a)}return C}},{key:"zoomStarted",value:function(n){this.zooming=!0,n&&n.sourceEvent&&(this.zoomStartPos=zg(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 r=this.currentProps,C=r.paddingLeft+r.leftWidth,o=r.paddingTop+r.topHeight;if(!this.xScale||!this.yScale)return;this.zoomedXScale=this.zoomTransform.rescaleX(this.xScale),this.zoomedYScale=this.zoomTransform.rescaleY(this.yScale);const a=tg().domain([C,C+r.centerWidth].map(this.zoomedXScale.invert)).range([0,r.centerWidth]),s=tg().domain([o,o+r.centerHeight].map(this.zoomedYScale.invert)).range([0,r.centerHeight]);for(const A in this.trackDefObjects){const l=this.trackDefObjects[A].trackObject,c=this.trackDefObjects[A].trackDef;let u="unknown";if(Qg[c.track.type]&&(u=Qg[c.track.type].orientation),u==="whole"){const d=tg().domain([r.paddingLeft,r.width-r.paddingLeft].map(this.zoomedXScale.invert)).range([0,r.width-2*r.paddingLeft]),h=tg().domain([r.paddingTop,r.height-r.paddingTop].map(this.zoomedYScale.invert)).range([0,r.height-2*r.paddingTop]);l.zoomed(d,h);continue}if(this.trackDefObjects[A].trackDef.track.position==="gallery"){const d=tg().domain([r.paddingLeft+r.leftWidthNoGallery,r.paddingLeft+r.leftWidth+r.centerWidth+r.galleryDim].map(this.zoomedXScale.invert)).range([0,r.centerWidth+2*r.galleryDim]),h=tg().domain([r.paddingTop+r.topHeightNoGallery,r.paddingTop+r.topHeight+r.centerHeight+r.galleryDim].map(this.zoomedYScale.invert)).range([0,r.centerHeight-2*r.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,r.paddingLeft+r.leftWidth,r.paddingTop+r.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 r=this.props.pluginTracks[n.type];if(r!=null&&r.isMetaTrack){const C={getTrackObject:this.getTrackObject.bind(this),onNewTilesLoaded:()=>{this.currentProps.onNewTilesLoaded(n.uid)},definition:n};try{return new r.track(this.availableForPlugins,C,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 Iae(this.pStage,{name:"Unknown Track Type",type:n.type})}}}},{key:"createTrackObject",value:function(n){const r=this.createLocationAgnosticTrackObject(n);return(n.position==="left"||n.position==="right")&&Qg[n.type].orientation==="1d-horizontal"?new Koe(r):r}},{key:"createLocationAgnosticTrackObject",value:function(n){let r=n.data;r||(r={server:HN(n.server),tilesetUid:n.tilesetUid}),n.coordSystem&&(r.coordSystem=n.coordSystem);const C=W4t(r,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:r,dataFetcher:C,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 QVe(o,n.options);case"top-axis":return new UVe(o,n.options);case"heatmap":return new mw(o,n.options);case"multivec":case"vector-heatmap":case"horizontal-multivec":case"horizontal-vector-heatmap":case"vertical-multivec":case"vertical-vector-heatmap":return new W1e(o,n.options);case"1d-heatmap":case"horizontal-1d-heatmap":case"vertical-1d-heatmap":return new H1e(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 V1e(o,n.options);case"bar":case"horizontal-bar":case"vertical-bar":return new Zj(o,n.options);case"divergent-bar":case"horizontal-divergent-bar":case"vertical-divergent-bar":return new X1e(o,n.options);case"horizontal-1d-tiles":return new PVe(o,n.options);case"vertical-1d-tiles":return new OVe(o,n.options);case"2d-tiles":return new MVe(o,n.options);case"stacked-interval":case"top-stacked-interval":case"left-stacked-interval":return new T1e(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 xp(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 L1e(o,n.options)):new xp(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 U1e(o,n.options)):new xp(o,{});case"gene-annotations":case"horizontal-gene-annotations":case"vertical-gene-annotations":return new N1e(o,n.options);case"2d-rectangle-domains":case"arrowhead-domains":return new k1e(o,n.options);case"horizontal-1d-annotations":return new QP(o,n.options);case"vertical-1d-annotations":return new QP(o,n.options,!0);case"2d-annotations":return new K1e(o,n.options);case"linear-2d-rectangle-domains":case"horizontal-2d-rectangle-domains":case"vertical-2d-rectangle-domains":return new F1e(o,n.options);case"square-markers":return new D1e(o,n.options);case"combined":return o.tracks=n.contents,o.createTrackObject=this.createTrackObject.bind(this),new _Q(o);case"2d-chromosome-labels":return new x1e(o,n.options);case"horizontal-chromosome-grid":return o.orientation="1d-horizontal",new nG(o,n.options);case"vertical-chromosome-grid":return o.orientation="1d-vertical",new nG(o,n.options);case"2d-chromosome-grid":return new nG(o,n.options);case"chromosome-labels":case"horizontal-chromosome-labels":case"vertical-chromosome-labels":return new z1e(o,n.options);case"linear-heatmap":case"horizontal-heatmap":case"vertical-heatmap":return new P1e(o,n.options);case"2d-chromosome-annotations":return new E1e(o,n.options);case"1d-value-interval":case"horizontal-1d-value-interval":case"vertical-1d-value-interval":return new O1e(o,n.options);case"osm":case"osm-tiles":return new pw(o,n.options);case"osm-2d-tile-ids":return new sWe(o,n.options);case"mapbox":case"mapbox-tiles":return new lWe(o,n.options);case"raster-tiles":return new cWe(o,n.options);case"bedlike":case"vertical-bedlike":return new w1e(o,n.options);case"overlay-track":return new R1e(o,n.options);case"overlay-chromosome-grid-track":return o.isOverlay=!0,new nG(o,n.options);case"horizontal-rule":return new gWe(o,n.options);case"vertical-rule":return new oWe(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 mm(o,n.options);case"empty":{const a=n.options;return new mr(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 Iae(o,{name:"Unknown Track Type",type:n.type})}}}},{key:"zoomToDataPos",value:function(n,r,C,o,a=3e3,s=null){const[A,l,c]=SI(this.xScale.copy().domain([n,r]),this.yScale.copy().domain([C,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:Xg("track-renderer-div",bx["track-renderer"]),style:{height:this.currentProps.height,width:this.currentProps.width}},N.createElement("div",{ref:n=>{this.element=n},className:Xg("track-renderer-element",bx["track-renderer-element"])}),N.createElement("div",{ref:n=>{this.eventTracker=n},className:Xg("track-renderer-events",bx["track-renderer-events"])},this.currentProps.children))}}]),i}(N.Component);S$.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:[]};S$.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 H4t=ty(cm(S$));var aXe={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 R in f)!b&&!m.call(f,R)||G&&(R=="length"||Z&&(R=="offset"||R=="parent")||B&&(R=="buffer"||R=="byteLength"||R=="byteOffset")||d(R,w))||v.push(R);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,R,S){var X=h(B),W=h(G),V=X?p:d(B),H=W?p:d(G),Y=(V=V==b?y:V)==y,K=(H=H==b?y:H)==y,x=V==H;if(x&&m(B)){if(!m(G))return!1;X=!0,Y=!1}if(x&&!Y)return S||(S=new A),X||f(B)?l(B,G,v,w,R,S):c(B,G,V,v,w,R,S);if(!(1&v)){var J=Y&&Z.call(B,"__wrapped__"),P=K&&Z.call(G,"__wrapped__");if(J||P){var ge=J?B.value():B,q=P?G.value():G;return S||(S=new A),R(ge,q,v,w,S)}}return!!x&&(S||(S=new A),u(B,G,v,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 B=b.get(u),G=b.get(d);if(B&&G)return B==d&&G==u;var v=-1,w=!0,R=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 R=1&Z;if(w||(w=h),b.size!=p.size&&!R)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 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]",B=m(A),G=m(l),v=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 B:return Z;case G:return f;case v: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 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 r(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,r),s.loaded=!0,s.exports}r.n=o=>{var a=o&&o.__esModule?()=>o.default:()=>o;return r.d(a,{a}),a},r.d=(o,a)=>{for(var s in a)r.o(a,s)&&!r.o(o,s)&&Object.defineProperty(o,s,{enumerable:!0,get:a[s]})},r.g=function(){if(typeof globalThis=="object")return globalThis;try{return this||new Function("return this")()}catch{if(typeof window=="object")return window}}(),r.o=(o,a)=>Object.prototype.hasOwnProperty.call(o,a),r.r=o=>{typeof Symbol<"u"&&Symbol.toStringTag&&Object.defineProperty(o,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(o,"__esModule",{value:!0})},r.nmd=o=>(o.paths=[],o.children||(o.children=[]),o);var C={};return(()=>{r.r(C),r.d(C,{default:()=>Ye,expandNodesToLevel:()=>fe});var o=r(4184),a=r.n(o),s=r(8446),A=r.n(s),l=r(8306),c=r.n(l);let u=(ue=21)=>crypto.getRandomValues(new Uint8Array(ue)).reduce((le,Ce)=>le+((Ce&=63)<36?Ce.toString(36):Ce<62?(Ce-26).toString(36).toUpperCase():Ce>62?"-":"_"),"");var d=r(5697),h=r.n(d),m=r(9787),f=r.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 Me,ke=w(oe);if(Re){var Ee=w(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return v(this,Me)});function Fe(){return Z(this,Fe),xe.apply(this,arguments)}return le=Fe,(Ce=[{key:"render",value:function(){var Me=this.props,ke=Me.children,Ee=Me.title,O=function(D,ee){if(D==null)return{};var ce,de,Le=function(dt,yt){if(dt==null)return{};var kt,ht,Rt={},xt=Object.keys(dt);for(ht=0;ht=0||(Rt[kt]=dt[kt]);return Rt}(D,ee);if(Object.getOwnPropertySymbols){var Ue=Object.getOwnPropertySymbols(D);for(de=0;de=0||Object.prototype.propertyIsEnumerable.call(D,ce)&&(Le[ce]=D[ce])}return Le}(Me,p);return f().createElement("button",y({"aria-label":Ee,title:Ee,type:"button"},O),ke)}}])&&B(le.prototype,Ce),Object.defineProperty(le,"prototype",{writable:!1}),Fe}(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 Y(ue,le){var Ce=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);le&&(oe=oe.filter(function(Re){return Object.getOwnPropertyDescriptor(ue,Re).enumerable})),Ce.push.apply(Ce,oe)}return Ce}function K(ue,le,Ce){return le in ue?Object.defineProperty(ue,le,{value:Ce,enumerable:!0,configurable:!0,writable:!0}):ue[le]=Ce,ue}function x(ue,le){if(!(ue instanceof le))throw new TypeError("Cannot call a class as a function")}function J(ue,le){for(var Ce=0;Ce1&&arguments[1]!==void 0?arguments[1]:{};x(this,ue),this.props=oe,this.flatNodes=Re}var le,Ce;return le=ue,Ce=[{key:"setProps",value:function(oe){this.props=oe}},{key:"clone",value:function(){var oe=this,Re={};return Object.keys(this.flatNodes).forEach(function(xe){var Fe=oe.flatNodes[xe];Re[xe]=function(Me){for(var ke=1;ke1&&arguments[1]!==void 0?arguments[1]:{},Fe=arguments.length>2&&arguments[2]!==void 0?arguments[2]:0;if(Array.isArray(oe)&&oe.length!==0){var Me=this.props,ke=Me.disabled,Ee=Me.noCascade;oe.forEach(function(O,D){var ee=Re.nodeHasChildren(O);if(Re.flatNodes[O.value]!==void 0)throw new H("Duplicate value '".concat(O.value,"' detected. All node values must be unique."));Re.flatNodes[O.value]={label:O.label,value:O.value,children:O.children,parent:xe,isChild:xe.value!==void 0,isParent:ee,isLeaf:!ee,showCheckbox:O.showCheckbox===void 0||O.showCheckbox,disabled:Re.getDisabledState(O,xe,ke,Ee),treeDepth:Fe,index:D},Re.flattenNodes(O.children,O,Fe+1)})}}},{key:"nodeHasChildren",value:function(oe){return Array.isArray(oe.children)}},{key:"getDisabledState",value:function(oe,Re,xe,Fe){return!!xe||!(Fe||!Re.disabled)||!!oe.disabled}},{key:"deserializeLists",value:function(oe){var Re=this,xe=["checked","expanded"];Object.keys(this.flatNodes).forEach(function(Fe){xe.forEach(function(Me){Re.flatNodes[Fe][Me]=!1})}),xe.forEach(function(Fe){oe[Fe].forEach(function(Me){Re.flatNodes[Me]!==void 0&&(Re.flatNodes[Me][Fe]=!0)})})}},{key:"serializeList",value:function(oe){var Re=this,xe=[];return Object.keys(this.flatNodes).forEach(function(Fe){Re.flatNodes[Fe][oe]&&xe.push(Fe)}),xe}},{key:"expandAllNodes",value:function(oe){var Re=this;return Object.keys(this.flatNodes).forEach(function(xe){Re.flatNodes[xe].isParent&&(Re.flatNodes[xe].expanded=oe)}),this}},{key:"toggleChecked",value:function(oe,Re,xe,Fe){var Me=this,ke=!(arguments.length>4&&arguments[4]!==void 0)||arguments[4],Ee=this.flatNodes[oe.value],O=[P.PARENT,P.ALL].indexOf(xe)>-1,D=[P.LEAF,P.ALL].indexOf(xe)>-1;if(Ee.isLeaf||Fe){if(oe.disabled)return this;this.toggleNode(oe.value,"checked",Re)}else(O||Ee.children.length===0)&&this.toggleNode(oe.value,"checked",Re),D&&Ee.children.forEach(function(ee){Me.toggleChecked(ee,Re,xe,Fe,!1)});return ke&&!Fe&&Ee.isChild&&O&&this.toggleParentStatus(Ee.parent,xe),this}},{key:"toggleParentStatus",value:function(oe,Re){var xe=this.flatNodes[oe.value];xe.isChild?(Re===P.ALL&&this.toggleNode(oe.value,"checked",this.isEveryChildChecked(xe)),this.toggleParentStatus(xe.parent,Re)):this.toggleNode(oe.value,"checked",this.isEveryChildChecked(xe))}},{key:"isEveryChildChecked",value:function(oe){var Re=this;return oe.children.every(function(xe){return Re.getNode(xe.value).checked})}},{key:"toggleNode",value:function(oe,Re,xe){return this.flatNodes[oe][Re]=xe,this}}],Ce&&J(le.prototype,Ce),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 Me,ke=ne(oe);if(Re){var Ee=ne(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return he(this,Me)});function Fe(){return te(this,Fe),xe.apply(this,arguments)}return le=Fe,Ce=[{key:"componentDidMount",value:function(){this.updateDeterminateProperty()}},{key:"componentDidUpdate",value:function(){this.updateDeterminateProperty()}},{key:"updateDeterminateProperty",value:function(){var Me=this.props.indeterminate;this.checkbox.indeterminate=Me}},{key:"render",value:function(){var Me=this,ke=function(Ee){for(var O=1;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(){var Me,ke=gt(oe);if(Re){var Ee=gt(this).constructor;Me=Reflect.construct(ke,arguments,Ee)}else Me=ke.apply(this,arguments);return Qe(this,Me)});function Fe(Me){var ke;return function(Ee,O){if(!(Ee instanceof O))throw new TypeError("Cannot call a class as a function")}(this,Fe),(ke=xe.call(this,Me)).onCheck=ke.onCheck.bind(_e(ke)),ke.onCheckboxKeyPress=ke.onCheckboxKeyPress.bind(_e(ke)),ke.onCheckboxKeyUp=ke.onCheckboxKeyUp.bind(_e(ke)),ke.onClick=ke.onClick.bind(_e(ke)),ke.onExpand=ke.onExpand.bind(_e(ke)),ke}return le=Fe,(Ce=[{key:"onCheck",value:function(){var Me=this.props,ke=Me.value;(0,Me.onCheck)({value:ke,checked:this.getCheckState({toggle:!0})})}},{key:"onCheckboxKeyPress",value:function(Me){Me.which===32&&Me.preventDefault()}},{key:"onCheckboxKeyUp",value:function(Me){var ke=Me.keyCode;[13,32].includes(ke)&&this.onCheck()}},{key:"onClick",value:function(){var Me=this.props,ke=Me.expandOnClick,Ee=Me.isParent,O=Me.value,D=Me.onClick;Ee&&ke&&this.onExpand(),D({value:O,checked:this.getCheckState({toggle:!1})})}},{key:"onExpand",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.value;(0,Me.onExpand)({value:Ee,expanded:!ke})}},{key:"getCheckState",value:function(Me){var ke=Me.toggle,Ee=this.props,O=Ee.checked,D=Ee.optimisticToggle;return!(O!==0||!ke)||O===1&&!ke||O===2&&D}},{key:"renderCollapseButton",value:function(){var Me=this.props,ke=Me.expandDisabled,Ee=Me.isLeaf,O=Me.lang;return Ee?f().createElement("span",{className:"rct-collapse"},f().createElement("span",{className:"rct-icon"})):f().createElement(X,{className:"rct-collapse rct-collapse-btn",disabled:ke,title:O.toggle,onClick:this.onExpand},this.renderCollapseIcon())}},{key:"renderCollapseIcon",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.icons,O=Ee.expandClose,D=Ee.expandOpen;return ke?D:O}},{key:"renderCheckboxIcon",value:function(){var Me=this.props,ke=Me.checked,Ee=Me.icons,O=Ee.uncheck,D=Ee.check,ee=Ee.halfCheck;return ke===0?O:ke===1?D:ee}},{key:"renderNodeIcon",value:function(){var Me=this.props,ke=Me.expanded,Ee=Me.icon,O=Me.icons,D=O.leaf,ee=O.parentClose,ce=O.parentOpen,de=Me.isLeaf;return Ee!==null?Ee:de?D:ke?ce:ee}},{key:"renderBareLabel",value:function(Me){var ke=this.props,Ee=ke.onClick,O=ke.title,D=Ee!==null;return f().createElement("span",{className:"rct-bare-label",title:O},D?f().createElement("span",{className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"button",tabIndex:0},Me):Me)}},{key:"renderCheckboxLabel",value:function(Me){var ke=this.props,Ee=ke.checked,O=ke.disabled,D=ke.title,ee=ke.treeId,ce=ke.value,de=ke.onClick!==null,Le="".concat(ee,"-").concat(String(ce).split(" ").join("_")),Ue=[f().createElement("label",{key:0,htmlFor:Le,title:D},f().createElement(ve,{checked:Ee===1,disabled:O,id:Le,indeterminate:Ee===2,onClick:this.onCheck,onChange:function(){}}),f().createElement("span",{"aria-checked":Ee===1,"aria-disabled":O,className:"rct-checkbox",role:"checkbox",tabIndex:0,onKeyPress:this.onCheckboxKeyPress,onKeyUp:this.onCheckboxKeyUp},this.renderCheckboxIcon()),de?null:Me)];return de&&Ue.push(f().createElement("span",{key:1,className:"rct-node-clickable",onClick:this.onClick,onKeyPress:this.onClick,role:"link",tabIndex:0},Me)),Ue}},{key:"renderLabel",value:function(){var Me=this.props,ke=Me.label,Ee=Me.showCheckbox,O=[Me.showNodeIcon?f().createElement("span",{key:0,className:"rct-node-icon"},this.renderNodeIcon()):null,f().createElement("span",{key:1,className:"rct-title"},ke)];return Ee?this.renderCheckboxLabel(O):this.renderBareLabel(O)}},{key:"renderChildren",value:function(){return this.props.expanded?this.props.children:null}},{key:"render",value:function(){var Me=this.props,ke=Me.className,Ee=Me.disabled,O=Me.expanded,D=Me.isLeaf,ee=a()({"rct-node":!0,"rct-node-leaf":D,"rct-node-parent":!D,"rct-node-expanded":!D&&O,"rct-node-collapsed":!D&&!O,"rct-disabled":Ee},ke);return f().createElement("li",{className:ee},f().createElement("span",{className:"rct-text"},this.renderCollapseButton(),this.renderLabel()),this.renderChildren())}}])&&Pe(le.prototype,Ce),Object.defineProperty(le,"prototype",{writable:!1}),Fe}(f().PureComponent);lt(tt,"propTypes",{checked:h().number.isRequired,disabled:h().bool.isRequired,expandDisabled:h().bool.isRequired,expanded:h().bool.isRequired,icons:We.isRequired,isLeaf:h().bool.isRequired,isParent:h().bool.isRequired,label:h().node.isRequired,lang:Be.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}),lt(tt,"defaultProps",{children:null,className:null,expandOnClick:!1,icon:null,showCheckbox:!0,title:null,onClick:function(){}});const Xe=tt,ae=h().oneOfType([h().arrayOf(h().string),h().arrayOf(h().number)]);function ye(ue,le){var Ce=Object.keys(ue);if(Object.getOwnPropertySymbols){var oe=Object.getOwnPropertySymbols(ue);le&&(oe=oe.filter(function(Re){return Object.getOwnPropertyDescriptor(ue,Re).enumerable})),Ce.push.apply(Ce,oe)}return Ce}function He(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 ke,Ee=ct(Re);if(xe){var O=ct(this).constructor;ke=Reflect.construct(Ee,arguments,O)}else ke=Ee.apply(this,arguments);return at(this,ke)});function Me(ke){var Ee;(function(D,ee){if(!(D instanceof ee))throw new TypeError("Cannot call a class as a function")})(this,Me),Ee=Fe.call(this,ke);var O=new ge(ke);return O.flattenNodes(ke.nodes),O.deserializeLists({checked:ke.checked,expanded:ke.expanded}),Ee.state={id:ke.id||"rct-".concat(u()),model:O,prevProps:ke},Ee.onCheck=Ee.onCheck.bind(bt(Ee)),Ee.onExpand=Ee.onExpand.bind(bt(Ee)),Ee.onNodeClick=Ee.onNodeClick.bind(bt(Ee)),Ee.onExpandAll=Ee.onExpandAll.bind(bt(Ee)),Ee.onCollapseAll=Ee.onCollapseAll.bind(bt(Ee)),Ee.combineMemorized=c()(function(D,ee){return Ve(Ve({},D),ee)}).bind(bt(Ee)),Ee}return le=Me,Ce=[{key:"onCheck",value:function(ke){var Ee=this.props,O=Ee.checkModel,D=Ee.noCascade,ee=Ee.onCheck,ce=this.state.model.clone(),de=ce.getNode(ke.value);ce.toggleChecked(ke,ke.checked,O,D),ee(ce.serializeList("checked"),Ve(Ve({},de),ke))}},{key:"onExpand",value:function(ke){var Ee=this.props.onExpand,O=this.state.model.clone(),D=O.getNode(ke.value);O.toggleNode(ke.value,"expanded",ke.expanded),Ee(O.serializeList("expanded"),Ve(Ve({},D),ke))}},{key:"onNodeClick",value:function(ke){(0,this.props.onClick)(Ve(Ve({},this.state.model.getNode(ke.value)),ke))}},{key:"onExpandAll",value:function(){this.expandAllNodes()}},{key:"onCollapseAll",value:function(){this.expandAllNodes(!1)}},{key:"expandAllNodes",value:function(){var ke=!(arguments.length>0&&arguments[0]!==void 0)||arguments[0],Ee=this.props.onExpand;Ee(this.state.model.clone().expandAllNodes(ke).serializeList("expanded"))}},{key:"determineShallowCheckState",value:function(ke,Ee){var O=this.state.model.getNode(ke.value);return O.isLeaf||Ee||ke.children.length===0?O.checked?1:0:this.isEveryChildChecked(ke)?1:this.isSomeChildChecked(ke)?2:0}},{key:"isEveryChildChecked",value:function(ke){var Ee=this;return ke.children.every(function(O){return Ee.state.model.getNode(O.value).checkState===1})}},{key:"isSomeChildChecked",value:function(ke){var Ee=this;return ke.children.some(function(O){return Ee.state.model.getNode(O.value).checkState>0})}},{key:"renderTreeNodes",value:function(ke){var Ee=this,O=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},D=this.props,ee=D.expandDisabled,ce=D.expandOnClick,de=D.icons,Le=D.lang,Ue=D.noCascade,dt=D.onClick,yt=D.onlyLeafCheckboxes,kt=D.optimisticToggle,ht=D.showNodeTitle,Rt=D.showNodeIcon,xt=this.state,At=xt.id,Xt=xt.model,Pt=Me.defaultProps.icons,Ft=ke.map(function(Vg){var qg=Vg.value,it=Xt.getNode(Vg.value),Zt=it.isParent?Ee.renderTreeNodes(Vg.children,Vg):null;it.checkState=Ee.determineShallowCheckState(Vg,Ue);var Lt=yt?it.isLeaf:it.showCheckbox;return!O.value||Xt.getNode(O.value).expanded?f().createElement(Xe,{key:qg,checked:it.checkState,className:Vg.className,disabled:it.disabled,expandDisabled:ee,expandOnClick:ce,expanded:it.expanded,icon:Vg.icon,icons:Ee.combineMemorized(Pt,de),label:Vg.label,lang:Le,optimisticToggle:kt,isLeaf:it.isLeaf,isParent:it.isParent,showCheckbox:Lt,showNodeIcon:Rt,title:ht?Vg.title||Vg.label:Vg.title,treeId:At,value:Vg.value,onCheck:Ee.onCheck,onClick:dt&&Ee.onNodeClick,onExpand:Ee.onExpand},Zt):null});return f().createElement("ol",null,Ft)}},{key:"renderExpandAll",value:function(){var ke=this.props,Ee=ke.icons,O=Ee.expandAll,D=Ee.collapseAll,ee=ke.lang;return ke.showExpandAll?f().createElement("div",{className:"rct-options"},f().createElement(X,{className:"rct-option rct-option-expand-all",title:ee.expandAll,onClick:this.onExpandAll},O),f().createElement(X,{className:"rct-option rct-option-collapse-all",title:ee.collapseAll,onClick:this.onCollapseAll},D)):null}},{key:"renderHiddenInput",value:function(){var ke=this.props,Ee=ke.name,O=ke.nameAsArray;return Ee===void 0?null:O?this.renderArrayHiddenInput():this.renderJoinedHiddenInput()}},{key:"renderArrayHiddenInput",value:function(){var ke=this.props,Ee=ke.checked,O=ke.name;return Ee.map(function(D){var ee="".concat(O,"[]");return f().createElement("input",{key:D,name:ee,type:"hidden",value:D})})}},{key:"renderJoinedHiddenInput",value:function(){var ke=this.props,Ee=ke.checked,O=ke.name,D=Ee.join(",");return f().createElement("input",{name:O,type:"hidden",value:D})}},{key:"render",value:function(){var ke,Ee=this.props,O=Ee.direction,D=Ee.disabled,ee=Ee.iconsClass,ce=Ee.nodes,de=Ee.nativeCheckboxes,Le=this.state.id,Ue=this.renderTreeNodes(ce),dt=a()((Ht(ke={"react-checkbox-tree":!0,"rct-disabled":D},"rct-icons-".concat(ee),!0),Ht(ke,"rct-native-display",de),Ht(ke,"rct-direction-rtl",O==="rtl"),ke));return f().createElement("div",{className:dt,id:Le},this.renderExpandAll(),this.renderHiddenInput(),Ue)}}],oe=[{key:"getDerivedStateFromProps",value:function(ke,Ee){var O=Ee.model,D=Ee.prevProps,ee=ke.disabled,ce=ke.id,de=ke.nodes,Le=Ve(Ve({},Ee),{},{prevProps:ke});return O.setProps(ke),A()(D.nodes,de)&&D.disabled===ee||(O.reset(),O.flattenNodes(de)),ce!==null&&(Le=Ve(Ve({},Le),{},{id:ce})),O.deserializeLists({checked:ke.checked,expanded:ke.expanded}),Le}}],Ce&&we(le.prototype,Ce),oe&&we(le,oe),Object.defineProperty(le,"prototype",{writable:!1}),Me}(f().Component);function E(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,Ce){if(le){if(typeof le=="string")return _(le,Ce);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,Ce):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 Ce=0,oe=new Array(le);Ce2&&arguments[2]!==void 0?arguments[2]:0;if(Ce>le)return[];var oe=[];return ue.forEach(function(Re){Re.children&&(oe=[].concat(E(oe),[Re.value],E(fe(Re.children,le,Ce+1))))}),oe}Ht(re,"propTypes",{nodes:h().arrayOf(k).isRequired,checkModel:h().oneOf([W.LEAF,W.ALL]),checked:ae,direction:h().string,disabled:h().bool,expandDisabled:h().bool,expandOnClick:h().bool,expanded:ae,icons:We,iconsClass:h().string,id:h().string,lang:Be,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(re,"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 Ye=re})(),C})())})(aXe);var T4t=aXe.exports;const N4t=Pr(T4t);function k4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ase(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 AXe=function(e){D4t(i,e);var g=x4t(i);function i(I){var n;k4t(this,i),n=g.call(this,I),n.localTracks=ah.filter(a=>a.local&&!a.hidden).map(a=>{const s={...a};return s.datatype=a.datatype[0],s}),n.augmentedTracksInfo=ah,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=sg.nice()});const r=n.prepareNewEntries("",n.localTracks,{}),C=Object.keys(r),o=C.length?[C[0]]:null;return n.mounted=!1,n.state={selectedUuid:o,options:r,filter:"",checked:[],expanded:[]},n.requestTilesetLists(),n}return Y4t(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,r,C){const o=C;return r.map(s=>({...s,server:n,tilesetUid:s.uuid,serverUidKey:this.serverUidKey(n,s.uuid),datatype:s.datatype,name:s.name,uid:sg.nice()})).forEach(s=>{o[s.serverUidKey]=s}),o}},{key:"serverUidKey",value:function(n,r){return`${n}/${r}`}},{key:"requestTilesetLists",value:function(){let n=null;if(this.props.datatype?n=`dt=${this.props.datatype}`:n=[...new Set([].concat(...this.augmentedTracksInfo.filter(C=>C.datatype).filter(C=>C.orientation===this.props.orientation||this.props.orientation==="1d-vertical"&&C.orientation==="1d-horizontal").map(C=>C.datatype)))].map(C=>`dt=${C}`).join("&"),!this.props.trackSourceServers){console.warn("No track source servers specified in the viewconf");return}this.props.trackSourceServers.forEach(r=>{vt.json(`${r}/tilesets/?limit=10000&${n}`,(C,o)=>{if(C)console.error("ERROR:",C);else{const a=this.prepareNewEntries(r,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 r=this.state.options[n.target.value];this.props.onDoubleClick(r)}},{key:"handleSelectedOptions",value:function(n){const r=[],C=[];for(let o=0;os.label.toLowerCase().localeCompare(A.label.toLowerCase(),"en")),o.push(C[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 r=this.partitionByGroup(this.state.options,this.state.filter),C={width:15,height:15,top:2,right:2,position:"relative"},o=JSON.parse(JSON.stringify(C));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(N4t,{checked:this.state.checked,expanded:this.state.expanded,icons:{uncheck:N.createElement("svg",{style:C},N.createElement("use",{xlinkHref:"#square_o"})),check:N.createElement("svg",{style:C},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:C},N.createElement("use",{xlinkHref:"#file_o"})),expandClose:N.createElement("svg",{style:C},N.createElement("use",{xlinkHref:"#chevron_right"})),expandOpen:N.createElement("svg",{style:C},N.createElement("use",{xlinkHref:"#chevron_down"})),parentClose:N.createElement("svg",{style:C},N.createElement("use",{xlinkHref:"#folder_o"})),parentOpen:N.createElement("svg",{style:C},N.createElement("use",{xlinkHref:"#folder_open_o"}))},nodes:r,onCheck:this.handleChecked.bind(this),onExpand:this.handleExpanded.bind(this)})));return N.createElement("div",null,a)}}]),i}(N.Component);AXe.propTypes={datatype:L.string,orientation:L.string,onDoubleClick:L.func,pubSub:L.object.isRequired,selectedTilesetChanged:L.func,trackSourceServers:L.array};const P4t=ty(AXe);function J4t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function sse(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 sXe=function(e){U4t(i,e);var g=Q4t(i);function i(I){var n;return J4t(this,i),n=g.call(this,I),n.DATATYPE_TO_TRACK_TYPE=KQ(n.props.orientation),n.AVAILABLE_TRACK_TYPES=ZX(n.props.datatypes,n.props.orientation),n.state={selectedPlotType:n.AVAILABLE_TRACK_TYPES[0]},n}return O4t(i,[{key:"UNSAFE_componentWillReceiveProps",value:function(n){if(this.AVAILABLE_TRACK_TYPES=ZX(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 r=xQ(n.datatypes[0][0],this.props.position,this.AVAILABLE_TRACK_TYPES);this.handlePlotTypeSelected(r)}}},{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 r={};return ah.forEach(C=>{r[C.type]=C}),this.AVAILABLE_TRACK_TYPES&&(n=this.AVAILABLE_TRACK_TYPES.sort((C,o)=>C.type{const o=r[C.type].thumbnail,a=this.state.selectedPlotType.type===C.type?"plot-type-item plot-type-selected":"plot-type-item",s=r[C.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:C.type,className:a,onClick:A=>{this.setState({selectedPlotType:C}),this.props.onPlotTypeSelected(C.type)},style:{listStyle:"none",paddingLeft:5,paddingBottom:0}},s,N.createElement("span",{style:{verticalAlign:"middle"}},C.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);sXe.propTypes={allTracksSameDatatype:L.bool,datatypes:L.array,orientation:L.string,onPlotTypeSelected:L.func,position:L.string};function ejt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function lse(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)}let tH=function(e){Ijt(i,e);var g=njt(i);function i(I){var n;return ejt(this,i),n=g.call(this,I),n.options={},n.state={selectedTilesets:[{datatype:"none"}],allTracksSameDatatype:!0},n.handleSubmitBound=n.handleSubmit.bind(HW(n)),n.handleTilesetPickerDoubleClickBound=n.handleTilesetPickerDoubleClick.bind(HW(n)),n.selectedTilesetsChangedBound=n.selectedTilesetsChanged.bind(HW(n)),n}return tjt(i,[{key:"getOrientation",value:function(n){let r=null;return n==="top"||n==="bottom"?r="1d-horizontal":n==="left"||n==="right"?r="1d-vertical":r="2d",r}},{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:r}=this.state;for(const C of r)C.type=n;this.selectedPlotType=n,this.setState({selectedTilesets:r})}},{key:"selectedTilesetsChanged",value:function(n){let r=null;n.length===0?r=[{datatype:"none"}]:r=n;let C=!0;const o=r[0].datatype;for(const a of r)a.datatype!==o&&(C=!1);if(C)for(const a of r)a.type=this.selectedPlotType;else for(const a of r){let s=[a.datatype];const A=this.getOrientation(this.props.position);a.filetype==="cooler"&&(s=[a.datatype,"chromsizes"]);const l=ZX([s],A),c=xQ(s[0],this.props.position,l);a.type=c.type}this.setState({selectedTilesets:r,allTracksSameDatatype:C})}},{key:"render",value:function(){const n=this.getOrientation(this.props.position),r=N.createElement("div",null,N.createElement(P4t,{ref:C=>{this.tilesetFinder=C},datatype:this.props.datatype,onDoubleClick:this.handleTilesetPickerDoubleClick.bind(this),onTracksChosen:C=>this.props.onTracksChosen(C,this.props.position),orientation:n,selectedTilesetChanged:this.selectedTilesetsChanged.bind(this),trackSourceServers:this.props.trackSourceServers}));return N.createElement(vw,{maxHeight:!0,okayTitle:"Submit",onCancel:this.props.onCancel,onOkay:this.handleSubmitBound,title:"Add Track"},N.createElement(N.Fragment,null,r,N.createElement(sXe,{ref:C=>{this.plotTypeChooser=C},allTracksSameDatatype:this.state.allTracksSameDatatype,datatypes:this.state.selectedTilesets.map(C=>C.filetype==="cooler"?[C.datatype,"chromsizes"]:[C.datatype]),onPlotTypeSelected:this.handlePlotTypeSelected.bind(this),orientation:n,position:this.props.position})))}}]),i}(N.Component);tH.defaultProps={position:"top"};tH.propTypes={datatype:L.string,host:L.string,onCancel:L.func.isRequired,onTracksChosen:L.func.isRequired,position:L.string,trackSourceServers:L.array.isRequired};function pO(){return pO=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 gH(e){return gH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},gH(e)}let w$=function(e){ljt(i,e);var g=cjt(i);function i(){return ojt(this,i),g.apply(this,arguments)}return ajt(i,[{key:"render",value:function(){const n=[];return this.props.children.forEach((r,C)=>{const o=`customTrackDialog_${C}`;n.push(N.createElement(r,pO({key:o},this.props.bodyProps[C])))}),N.createElement(vw,{maxHeight:!0,okayOnly:!0,okayTitle:"Close",onCancel:this.props.onCancel,onOkay:this.props.onCancel,title:this.props.title},n)}}]),i}(N.PureComponent);w$.defaultProps={};w$.propTypes={onCancel:L.func.isRequired,title:L.string,bodyProps:L.array,children:L.array};function mjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function use(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 iH(e){return iH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},iH(e)}const dse=20;let fu=function(e){yjt(i,e);var g=Zjt(i);function i(I){var n;return mjt(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 fjt(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,r){this.setState({submenuShown:r,submenuSourceBbox:n})}},{key:"handleItemMouseEnter",value:function(n,r){this.handleItemMouseEnterWithRect(n.currentTarget.getBoundingClientRect(),r)}},{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=ji.findDOMNode(this.div);const n=this.divDom.getBoundingClientRect(),r=this.props.parentBbox?this.props.parentBbox:{top:this.props.position.top,left:this.props.position.left,width:0,height:0};let C=this.state.orientation,o=r.top;if(r.top+n.height>window.innerHeight&&(r.top-n.height>0?o=r.top-n.height+dse:(o=r.top-n.height+dse,o-=o+n.height-window.innerHeight)),this.state.orientation==="left"){let a=r.left-n.width;a<0&&(r.left+r.width+n.width>window.innerWidth?a=0:(a=r.left+r.width,C="right")),this.setState({left:a,top:o,orientation:C})}else{let a=r.left+r.width;r.left+r.width+n.width>window.innerWidth&&(r.left-n.width<0?(a=0,C="right"):(a=r.left-n.width,C="left")),this.setState({left:a,top:o,orientation:C})}}},{key:"render",value:function(){const n=this.state.left?{left:this.state.left}:{right:this.state.right},r={top:this.state.top},C=Object.assign(n,r);return N.createElement("div",{ref:o=>{this.div=o},className:Xg("context-menu-item",Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),style:C},this.props.children)}}]),i}(N.Component);fu.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 hse(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 IH(e){return IH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},IH(e)}let GO=function(e){Wjt(i,e);var g=Xjt(i);function i(){return Sjt(this,i),g.apply(this,arguments)}return wjt(i,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,r=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},C=this.state.submenuShown;return N.createElement(i,{menuItems:C.children,orientation:this.state.orientation,parentBbox:n,position:r,theme:this.props.theme})}return N.createElement("div",null)}},{key:"componentWillUnmount",value:function(){}},{key:"render",value:function(){const n=[];for(const r in this.props.menuItems){const C=this.props.menuItems[r];n.push(N.createElement(ig,{key:r,onClick:C.handler?C.handler:()=>null,onMouseEnter:C.children?o=>this.handleItemMouseEnter(o,C):this.handleOtherMouseEnter.bind(this),onMouseLeave:this.handleMouseLeave},C.name,C.children&&N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))))}return N.createElement("div",{ref:r=>{this.div=r},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),style:{left:this.state.left,top:this.state.top}},n,this.getSubmenu())}}]),i}(fu);function kjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function mse(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 nH(e){return nH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},nH(e)}let Pjt=function(e){Djt(i,e);var g=xjt(i);function i(){return kjt(this,i),g.apply(this,arguments)}return Yjt(i,[{key:"getConfigureSeriesMenu",value:function(n,r,C){const o={},a=window.higlassTracksByType&&window.higlassTracksByType[C.type]&&window.higlassTracksByType[C.type].config&&window.higlassTracksByType[C.type].config.optionsInfo;if(a)for(const s of Object.keys(a))an[s]=a[s];if(!Qg[C.type]||!Qg[C.type].availableOptions)return null;for(const s of Qg[C.type].availableOptions)if(s in an){if(o[s]={name:an[s].name},an[s].generateOptions){const A=an[s].generateOptions(C);o[s].children||(o[s].children={});for(const l of A){const c={name:l.name,value:l.value,handler:()=>{C.options[s]=l.value,this.props.onTrackOptionsChanged(C.uid,C.options),this.props.closeMenu()}};o[s].children[l.value]=c}}if(an[s].inlineOptions)for(const A in an[s].inlineOptions){const l=an[s].inlineOptions[A];o[s].children||(o[s].children={});const c={name:l.name,value:l.value};l.componentPickers&&l.componentPickers[C.type]?c.handler=()=>{this.props.onConfigureTrack(C,l.componentPickers[C.type]),this.props.closeMenu()}:c.handler=()=>{C.options[s]=l.value,this.props.onTrackOptionsChanged(C.uid,C.options),this.props.closeMenu()},o[s].children[A]=c}else an[s].componentPickers&&an[s].componentPickers[C.type]&&(o[s].handler=()=>{this.props.onConfigureTrack(C,an[s].componentPickers[C.type]),this.props.closeMenu()})}return N.createElement(GO,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:r,position:n,theme:this.props.theme})}},{key:"getTrackTypeItems",value:function(n,r,C){window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(l=>{Qg[l]=window.higlassTracksByType[l].config});let{datatype:o}=C,a=null;C.type in Qg&&(o||(o=Qg[C.type].datatype[0]),{orientation:a}=Qg[C.type]);const s=Object.values(Qg).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(C.uid,s[l])}};return N.createElement(GO,{key:"track-type-items",closeMenu:this.props.closeMenu,menuItems:A,orientation:this.state.orientation,parentBbox:r,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,r=this.state.orientation==="left"?{left:this.state.left,top:n.top}:{left:this.state.left+n.width+7,top:n.top},C=this.state.submenuShown,o=C.value;return C.option==="track-type"?this.getTrackTypeItems(r,n,o):this.getConfigureSeriesMenu(r,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(ig,{className:Ut["context-menu-item"],onClick:()=>this.props.onChangeTrackData(this.props.series.uid,n),onMouseEnter:r=>this.handleOtherMouseEnter(r)},N.createElement("span",{className:Ut["context-menu-span"]},"Remove divisor"))}return N.createElement(ig,{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;Qg[this.props.series.type]&&Qg[this.props.series.type].exportable&&(n=N.createElement(ig,{className:Ut["context-menu-item"],onClick:()=>this.props.onExportData(this.props.hostTrack.uid,this.props.track.uid),onMouseEnter:C=>this.handleOtherMouseEnter(C)},N.createElement("span",{className:Ut["context-menu-span"]},"Export Data")));const r=this.props.onAddSeries?N.createElement(ig,{className:Ut["context-menu-item"],onClick:()=>{this.props.onCloseTrack(this.props.series.uid),this.props.onAddSeries(this.props.hostTrack.uid)},onMouseEnter:C=>this.handleOtherMouseEnter(C)},N.createElement("span",{className:Ut["context-menu-span"]},"Replace Series")):null;return N.createElement("div",{ref:C=>{this.div=C},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),"data-menu-type":"SeriesListMenu",onMouseLeave:this.props.handleMouseLeave,style:{left:this.state.left,top:this.state.top}},N.createElement(ig,{onClick:()=>{},onMouseEnter:C=>this.handleItemMouseEnter(C,{option:"configure-series",value:this.props.track}),onMouseLeave:C=>this.handleMouseLeave(C)},"Configure Series",N.createElement("svg",{className:Ut["play-icon"]},N.createElement("use",{xlinkHref:"#play"}))),N.createElement(ig,{className:Ut["context-menu-item"],onClick:()=>{},onMouseEnter:C=>this.handleItemMouseEnter(C,{option:"track-type",value:this.props.track}),onMouseLeave:C=>this.handleMouseLeave(C)},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(ig,{className:Ut["context-menu-item"],onClick:this.props.onCloseTrack,onMouseEnter:C=>this.handleOtherMouseEnter(C)},N.createElement("span",{className:Ut["context-menu-span"]},"Close Series")),r,this.getSubmenu())}}]),i}(fu);const lXe=e=>{let g=[];for(const i of e)i.contents?g=g.concat(i.contents):g.push(i);return g},R$=(e,g,i,I)=>e?(window.higlassTracksByType&&Object.keys(window.higlassTracksByType).forEach(n=>{Qg[n]=window.higlassTracksByType[n].config}),lXe(e).map(n=>{const r=Qg[n.type]?Qg[n.type].thumbnail:null,C=r?N.createElement("div",{className:Ut["context-menu-icon"],dangerouslySetInnerHTML:{__html:r.outerHTML}}):N.createElement("div",{className:Ut["context-menu-icon"]},N.createElement("svg",null));return N.createElement(ig,{key:n.uid,className:Ut["context-menu-item"],onClick:()=>{I&&I(n.uid)},onMouseEnter:o=>{g&&g(o,n)},onMouseLeave:o=>{i&&i(o)}},C,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 Jjt(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function fse(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 rH(e){return rH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},rH(e)}const cXe=Tk(e=>function(g){Ujt(I,g);var i=Qjt(I);function I(){return Jjt(this,I),i.apply(this,arguments)}return Ojt(I,[{key:"getSubmenu",value:function(){if(this.state.submenuShown){const r=this.state.submenuSourceBbox;let C=null;this.state.orientation==="left"?C={left:this.state.left,top:r.top}:C={left:this.state.left+r.width+7,top:r.top};const a=lXe(this.props.tracks).filter(A=>A.uid===this.state.submenuShown.uid)[0],s=a&&a.position!=="whole";return N.createElement(Pjt,{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:r,position:C,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 e$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function pse(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 d0(e){return d0=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},d0(e)}let A$t=function(e){n$t(i,e);var g=r$t(i);function i(I){var n;return e$t(this,i),n=g.call(this,I),n.seriesRefs={},n.seriesListMenu=null,n}return t$t(i,[{key:"componentDidMount",value:function(){TW(d0(i.prototype),"componentDidMount",this).call(this)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),"data-menu-type":"ConfigTrackMenu",style:{left:this.state.left,top:this.state.top}},R$(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this),null),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{contextMenu:this,onClick:()=>this.props.onLockValueScale(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Lock Value Scale With"),N.createElement(ig,{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(ig,{contextMenu:this,onClick:()=>this.props.onAddSeries(this.props.tracks[0].uid),onMouseEnter:n=>this.handleOtherMouseEnter(n)},"Add Series"),N.createElement(ig,{onClick:()=>this.props.onCloseTrack(this.props.tracks[0].uid)},"Close Track"),N.createElement(ig,{onClick:()=>{this.props.onReplaceTrack(this.props.tracks[0].uid,this.props.trackOrientation)}},"Replace Track"),this.getSubmenu())}}]),i}(oy(fu).with(cXe));function uXe(e){return N.createElement("div",null,R$(e.tracks,null,null,e.onCloseTrack),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:()=>e.onCloseTrack(e.tracks[0].uid)},"Close all series"))}uXe.propTypes={onCloseTrack:L.func.isRequired,tracks:L.array.isRequired};function s$t(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 CH(e){return CH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},CH(e)}let Dc=function(e){d$t(i,e);var g=h$t(i);function i(I){var n;return s$t(this,i),n=g.call(this,I),n.clickHandlerBound=n.clickHandler.bind(NW(n)),n.contextMenuHandlerBound=n.contextMenuHandler.bind(NW(n)),n.resizeHandlerBound=n.resizeHandler.bind(NW(n)),n}return l$t(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),ji.unmountComponentAtNode(this.popup),document.body.removeChild(this.popup)}},{key:"_renderLayer",value:function(){ji.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);Dc.defaultProps={onMenuClosed:QGe};Dc.propTypes={children:L.node.isRequired,onMenuClosed:L.func};const p$t=mGe(e=>N.createElement(a9e,{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})),b$t={"vertical-tiled-plot":"_vertical-tiled-plot_f3ho8_1"};function y$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function yse(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 oH(e){return oH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},oH(e)}function Zse(e){return e&&e.sourceEvent}let VO=function(e){B$t(i,e);var g=S$t(i);function i(I){var n;return y$t(this,i),n=g.call(this,I),n.brushBehavior=_S().on("start",n.brushStarted.bind(kW(n))).on("brush",n.brushed.bind(kW(n))).on("end",n.brushedEnded.bind(kW(n))),n}return Z$t(i,[{key:"componentDidMount",value:function(){this.props.isRangeSelectionActive&&this.addBrush()}},{key:"shouldComponentUpdate",value:function(n,r){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!==r;if(this.props.rangeSelection!==n.rangeSelection){const C=this.props.is1dRangeSelection?0:1;return this.moveBrush(n.rangeSelection[C]?n.rangeSelection[C]:null,n.rangeSelectionEnd),this.state!==r}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,Yp(this.brushEl,Po["track-range-selection-group-brush-selection"]))}},{key:"brushed",value:function(n){const r=this.rangeSelectionMoved;this.rangeSelectionMoved=!1,!(!Zse(n)||!this.props.onRangeSelection||r)&&(this.rangeSelectionTriggered=!0,this.props.onRangeSelection(n.selection))}},{key:"brushStarted",value:function(n){!Zse(n)||!n.selection||this.props.onRangeSelectionStart()}},{key:"brushedEnded",value:function(n){if(!this.props.is1dRangeSelection)return;const r=this.rangeSelectionMovedEnd;this.rangeSelectionMovedEnd=!1,n.selection&&n.sourceEvent&&this.props.onRangeSelection&&!r&&(this.rangeSelectionTriggered=!0,this.rangeSelectionTriggeredEnd=!0,this.props.onRangeSelectionEnd(n.selection)),n.selection||(this.rangeSelectionTriggered=!0,this.props.onRangeSelectionReset())}},{key:"moveBrush",value:function(n,r=!1){if(!this.brushEl)return;const C=n?[this.props.scale(n[0]),this.props.scale(n[1])]:null;this.rangeSelectionMoved=!0,this.rangeSelectionMovedEnd=!0,r?this.brushEl.transition().call(this.brushBehavior.move,C):this.brushEl.call(this.brushBehavior.move,C)}},{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($l,0),r=this.props.tracks.map(o=>E0(o)).reduce(QS,!1),C=Po[this.props.isRangeSelectionActive?"track-range-selection-active":"track-range-selection"];return N.createElement("div",{className:b$t["vertical-tiled-plot"]},r&&N.createElement("svg",{ref:o=>{this.brushEl=dg(o)},className:C,style:{height:this.props.height,width:n},xmlns:"http://www.w3.org/2000/svg"}),N.createElement(Kk,{axis:"x",className:Xg(Jo.list,Jo.stylizedList,Jo.horizontalList),component:o9e,editable:this.props.editable,handleConfigTrack:this.props.handleConfigTrack,handleResizeTrack:this.props.handleResizeTrack,height:this.props.height,helperClass:Jo.stylizedHelper,itemClass:Xg(Jo.stylizedItem,Jo.horizontalItem),itemControlAlignLeft:this.props.tracksControlAlignLeft,itemReactClass:p$t,items:this.props.tracks.map(o=>({configMenuVisible:o.uid===this.props.configTrackMenuId,uid:o.uid||sg.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);VO.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 V$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Gse(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 aH(e){return aH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},aH(e)}let dXe=function(e){T$t(i,e);var g=N$t(i);function i(){return V$t(this,i),g.apply(this,arguments)}return W$t(i,[{key:"render",value:function(){const n=R$(this.props.tracks,this.handleItemMouseEnter.bind(this),this.handleMouseLeave.bind(this)),r=this.props.customItems?N.Children.map(this.props.customItems,C=>N.cloneElement(C,{onMouseEnter:o=>{this.handleOtherMouseEnter(o)}})):null;return N.createElement("div",{ref:C=>{this.div=C},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),"data-menu-type":"ViewContextMenu",style:{left:this.state.left,top:this.state.top}},r,r&&N.createElement("hr",{className:Ut["context-menu-hr"]}),n,n&&N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:()=>this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),onMouseEnter:C=>this.handleOtherMouseEnter(C)},"Add Horizontal Rule"),N.createElement(ig,{onClick:()=>this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),onMouseEnter:C=>this.handleOtherMouseEnter(C)},"Add Vertical Rule"),N.createElement(ig,{onClick:()=>this.props.onAddTrack({type:"cross-rule",x:this.props.coords[0],y:this.props.coords[1],position:"whole"}),onMouseEnter:C=>this.handleOtherMouseEnter(C)},"Add Cross Rule"),N.createElement("hr",{className:Ut["context-menu-hr"]}),this.hasMatrixTrack(this.props.tracks)&&N.createElement(ig,{onClick:this.handleAddHorizontalSection.bind(this),onMouseEnter:C=>this.handleOtherMouseEnter(C)},"Add Horizontal Cross Section"),this.hasMatrixTrack(this.props.tracks)&&N.createElement(ig,{onClick:this.handleAddVerticalSection.bind(this),onMouseEnter:C=>this.handleOtherMouseEnter(C)},"Add Vertical Cross Section"),this.getSubmenu())}},{key:"hasMatrixTrack",value:function(n){return Q1(this.props.tracks).filter(C=>C.type==="heatmap").length>0}},{key:"handleAddHorizontalSection",value:function(){const r=Q1(this.props.tracks).filter(C=>C.type==="heatmap")[0];this.props.onAddTrack({type:"horizontal-rule",y:this.props.coords[1],position:"whole"}),this.props.onAddTrack({data:{type:"horizontal-section",server:r.server,tilesetUid:r.tilesetUid,slicePos:this.props.coords[1]},options:{valueScaling:"log"},type:"horizontal-bar",height:30,position:"top"})}},{key:"handleAddVerticalSection",value:function(){const r=Q1(this.props.tracks).filter(C=>C.type==="heatmap")[0];this.props.onAddTrack({type:"vertical-rule",x:this.props.coords[0],position:"whole"}),this.props.onAddTrack({data:{type:"vertical-section",server:r.server,tilesetUid:r.tilesetUid,slicePos:this.props.coords[0]},options:{valueScaling:"log"},type:"vertical-bar",height:30,position:"left"})}}]),i}(oy(fu).with(cXe));dXe.propTypes={coords:L.array,customItems:L.array};function F$t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function vse(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 AH(e){return AH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},AH(e)}let V$=function(e){M$t(i,e);var g=z$t(i);function i(I){var n;F$t(this,i),n=g.call(this,I),n.closing=!1;const{tracks:r}=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(C=>{C.type==="combined"?C.contents.forEach(o=>{n.tracksByUidInit[o.uid]=!1}):n.tracksByUidInit[C.uid]=!1}),n.xScale=null,n.yScale=null,n.addUidsToTracks(r),n.trackToReplace=null,n.trackRenderer=null,n.configTrackMenu=null,n.state={sizeMeasured:!1,height:10,width:10,tracks:r,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(C=>{Qg[C]=window.higlassTracksByType[C].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(rn(n)),n.handleNoTrackAddedBound=n.handleNoTrackAdded.bind(rn(n)),n.handleTracksAddedBound=n.handleTracksAdded.bind(rn(n)),n.closeMenusBound=n.closeMenus.bind(rn(n)),n.handleAddDivisorBound=n.handleAddDivisor.bind(rn(n)),n.handleAddSeriesBound=n.handleAddSeries.bind(rn(n)),n.handleChangeTrackDataBound=n.handleChangeTrackData.bind(rn(n)),n.handleChangeTrackTypeBound=n.handleChangeTrackType.bind(rn(n)),n.handleCloseTrackBound=n.handleCloseTrack.bind(rn(n)),n.handleConfigureTrackBound=n.handleConfigureTrack.bind(rn(n)),n.handleExportTrackDataBound=n.handleExportTrackData.bind(rn(n)),n.handleLockValueScaleBound=n.handleLockValueScale.bind(rn(n)),n.handleReplaceTrackBound=n.handleReplaceTrack.bind(rn(n)),n.handleTrackOptionsChangedBound=n.handleTrackOptionsChanged.bind(rn(n)),n.handleUnlockValueScaleBound=n.handleUnlockValueScale.bind(rn(n)),n.onAddTrack=n.handleAddTrack.bind(rn(n)),n}return D$t(i,[{key:"waitForDOMAttachment",value:function(n){if(!this.mounted)return;const r=ji.findDOMNode(this);document.body.contains(r)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=ji.findDOMNode(this),this.canvasElement=ji.findDOMNode(this.props.canvasElement),this.waitForDOMAttachment(()=>{cX.ElementQueries.listen(),this.resizeSensor=new cX.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,r){const C=this.previousPropsStr,o=this.updatablePropsToString(n),a=JSON.stringify(this.state),s=JSON.stringify(r),A=C!==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,is(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,r){if(r.rangeSelection!==this.state.rangeSelection){let C=[null,null];this.state.defaultChromSizes&&this.state.rangeSelection.every(o=>o&&o.length)&&(C=this.state.rangeSelection.map(o=>GX(...o,this.state.defaultChromSizes))),this.props.onRangeSelection({dataRange:this.state.rangeSelection,genomicRange:C})}if(this.state.customDialog||this.props.customDialog){const C=this.state.customDialog||this.props.customDialog;if(C.length>0){const o=[],a=[];C.forEach(s=>{o.push(s.bodyComponent),a.push(s.bodyProps)}),this.props.modal.open(N.createElement(w$,{children:o,bodyProps:a,onCancel:this.props.closeCustomDialog,title:C[0].title}))}}if(n.tracks.center,this.props.tracks.center,(this.state.addTrackPosition||this.props.addTrackPosition)&&this.props.modal.open(N.createElement(tH,{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 C=this.state.addDivisorDialog;this.props.modal.open(N.createElement(tH,{datatype:Qg[C.type].datatype[0],host:this.state.addTrackHost,onCancel:()=>{this.setState({addDivisorDialog:null})},onTracksChosen:o=>{this.handleDivisorChosen(C,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(r=>{n[r].forEach(C=>{C.uid=C.uid||sg.nice()})})}},{key:"contextMenuHandler",value:function(n){if(!this.divTiledPlot)return;const r=this.divTiledPlot.getBoundingClientRect();if(!LQ(n.clientX,n.clientY,r.left,r.left+r.width,r.top,r.top+r.height))return;const o=[n.clientX,n.clientY],a=zg(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(ig,{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,r){return this.props.onTrackOptionsChanged(n,r)}},{key:"handleScalesChanged",value:function(n,r){this.xScale=n,this.yScale=r,this.props.onScalesChanged(n,r)}},{key:"handleTilesetInfoReceived",value:function(n,r){const C=gC(this.props.tracks,n);if(!C){console.warn("Strange, track not found:",n);return}this.tracksByUidInit[C.uid]=!0,this.checkAllTilesetInfoReceived(),C.options||(C.options={}),C.name=r.name,C.maxWidth=r.max_width,C.transforms=r.transforms,C.aggregationModes=r.aggregation_modes,C.header=r.header,C.binsPerDimension=r.bins_per_dimension,r.resolutions?(C.maxZoom=r.resolutions.length-1,C.resolutions=r.resolutions):C.maxZoom=r.max_zoom,C.coordSystem=r.coordSystem,C.datatype=r.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(C=>{const o=this.trackRenderer.trackDefObjects[C].trackObject;return o.childTracks?o.childTracks:o}).reduce((C,o)=>C.concat(o),[]).filter(({tilesetInfo:C})=>typeof C<"u"&&C!==!0),r=Object.values(this.tracksByUidInit).filter(C=>C).length;n.length===r&&(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,r){this.setState({addDivisorDialog:null});const C=n.data?{server:n.data.server,tilesetUid:n.data.tilesetUid}:{server:n.server,tilesetUid:n.tilesetUid},o={server:r[0].server,tilesetUid:r[0].uuid};this.handleChangeTrackData(n.uid,{type:"divided",children:[C,o]})}},{key:"handleDivideSeries",value:function(n){}},{key:"handleAddSeries",value:function(n){const r=JG(this.props.tracks,n),C=gC(this.props.tracks,n);this.setState({addTrackPosition:r,addTrackHost:C})}},{key:"handleReplaceTrack",value:function(n,r){this.trackToReplace=n,this.handleAddTrack(r)}},{key:"handleAddTrack",value:function(n){this.setState({addTrackPosition:n,addTrackHost:null})}},{key:"handleResizeTrack",value:function(n,r,C){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=r,A[0].height=C)}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,r){this.closeMenus(),this.props.onChangeTrackType(n,r)}},{key:"handleChangeTrackData",value:function(n,r){this.closeMenus(),this.props.onChangeTrackData(n,r)}},{key:"handleTracksAdded",value:function(n,r,C){return this.trackToReplace&&(this.handleCloseTrack(this.trackToReplace),this.trackToReplace=null),this.props.onTracksAdded(n,r,C),this.setState({addTrackPosition:null,addTrackHost:null}),n}},{key:"handleCloseTrackMenuOpened",value:function(n,r){this.setState({closeTrackMenuId:n,closeTrackMenuLocation:r})}},{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,r){this.closeMenus(),this.setState({configTrackMenuId:n,configTrackMenuLocation:r})}},{key:"handleConfigureTrack",value:function(n,r){this.setState({configTrackMenuId:null,trackOptions:{track:n,configComponent:r}}),this.closeMenus()}},{key:"handleSortEnd",value:function(n){this.setState(r=>{const C=r.tracks,o={};for(let a=0;a{r[C]&&r[C].forEach(o=>{o.contents&&o.contents.forEach(a=>{a.position=C}),o.position=C,n.push({track:o,location:C})})}),n}},{key:"calculateTrackPosition",value:function(n,r){let C=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(r){case"top":a+=this.leftWidth;for(let d=0;dC.includes&&C.includes.length).map(C=>{const o=C.type?`overlay-${C.type}-track`:"overlay-track",a={...C,uid:C.uid||sg.nice(),includes:C.includes,type:o,options:Object.assign(C.options,{orientationsAndPositions:C.includes.map(s=>{const A=gC(this.props.tracks,s);if(!A)return console.warn(`OverlayTrack included uid (${s}) not found in the track list`),null;const l=JG(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:r,location:C})=>this.calculateTrackPosition(r,C))}},{key:"createTrackPositionTexts",value:function(){const n=this.positionedTracks();return this.createTracksAndLocations(),n.map(C=>{const{track:o}=C;return N.createElement("div",{key:o.uid,style:{left:C.left,top:C.top,width:C.width,height:C.height,position:"absolute"}},o.uid.slice(0,2))})}},{key:"handleExportTrackData",value:function(n,r){const C=gC(this.props.tracks,r);let o=null;n!==r?o=this.trackRenderer.trackDefObjects[n].trackObject.createdTracks[C.uid]:{trackObject:o}=this.trackRenderer.trackDefObjects[n],o.exportData(),this.closeMenus()}},{key:"listTracksAtPosition",value:function(n,r,C=!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,r))if(C){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(),C[0]Number.MIN_SAFE_INTEGER&&(A=[C[0],o[0]]),C[1]Number.MIN_SAFE_INTEGER&&(c=[C[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,r){return r?[parseInt(r.invert(n[0]),10),parseInt(r.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 r=n==="x"?this.xScale:this.yScale;return C=>{this.setState(o=>{const a=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!this.state.is1dRangeSelection&&n==="y"?1:0;let A=this.rangeViewToDataLoci(C,r);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 r=n==="x"?this.xScale:this.yScale;return C=>{this.setState(o=>{const a=o.is1dRangeSelection?[null,null]:o.rangeSelection.slice(),s=!o.is1dRangeSelection&&n==="y"?1:0;return a[s]=this.rangeViewToDataLoci(C,r),{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 r=this.rangeViewToDataLoci(n[0],this.xScale),C=this.rangeViewToDataLoci(n[1],this.yScale);let o=[r,C];const a=r[1]-r[0],s=C[1]-C[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(Dc,{onMenuClosed:this.closeMenusBound},N.createElement(dXe,{closeMenu:this.closeMenusBound,coords:[this.state.contextMenuDataX,this.state.contextMenuDataY],customItems:this.state.contextMenuCustomItems,onAddDivisor:this.handleAddDivisorBound,onAddSeries:this.handleAddSeriesBound,onAddTrack:r=>{this.props.onTracksAdded([r],r.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,r=n.datatype;if(!(r in KB)&&!n.defaultTracks){console.warn("unknown data type:",n.higlassTrack);return}const C={"1d-horizontal":["top","bottom","left","right"],"2d":["center"],"1d-vertical":["left","right"]},o=KB[r]||{};if(n.defaultTracks)for(const S of n.defaultTracks)if(!Qg[S])console.warn("unknown track type",S);else for(const X of C[Qg[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(RV,{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(RV,{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(RV,{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(RV,{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(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?R:null),m?G:null))}},{key:"render",value:function(){this.galleryDim=this.props.tracks.gallery?this.props.tracks.gallery.map(p=>p.height).reduce($l,0):0,this.topHeightNoGallery=this.props.tracks.top.map(p=>p.height).reduce($l,0),this.topHeight=this.topHeightNoGallery+this.galleryDim,this.bottomHeightNoGallery=this.props.tracks.bottom.map(p=>p.height).reduce($l,0),this.bottomHeight=this.bottomHeightNoGallery+this.galleryDim,this.leftWidthNoGallery=this.props.tracks.left.map(p=>p.width).reduce($l,0),this.leftWidth=this.leftWidthNoGallery+this.galleryDim,this.rightWidthNoGallery=this.props.tracks.right.map(p=>p.width).reduce($l,0),this.rightWidth=this.rightWidthNoGallery+this.galleryDim;const n=this.props.paddingTop+this.props.paddingBottom,r=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-r);const C="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:C,position:"absolute"}},N.createElement(E2,{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===EC,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:C,position:"absolute"}},N.createElement(VO,{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===EC,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:C,position:"absolute"}},N.createElement(VO,{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===EC,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:C,position:"absolute"}},N.createElement(E2,{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===EC,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:C,position:"absolute"}},N.createElement(URe,{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",nP["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.bottomHeight,outline:C}});this.props.tracks.center.length&&(c=N.createElement("div",{className:["center-track-container",nP["center-track-container"]].join(" "),style:{left:this.leftWidth+this.props.paddingLeft,top:this.topHeight+this.props.paddingTop,width:this.centerWidth,height:this.centerHeight,outline:C}},N.createElement(ij,{configTrackMenuId:this.state.configTrackMenuId,editable:this.props.editable,height:this.centerHeight,is1dRangeSelection:this.state.is1dRangeSelection,isRangeSelectionActive:this.props.mouseTool===EC,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(H4t,{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===EC,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(Dc,{onMenuClosed:this.closeMenusBound},N.createElement(A$t,{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:JG(this.props.tracks,this.state.configTrackMenuId),tracks:[gC(this.props.tracks,this.state.configTrackMenuId)]}))),this.state.closeTrackMenuId&&(m=N.createElement(Dc,{onMenuClosed:this.handleCloseTrackMenuClosed.bind(this)},N.createElement(fu,{position:this.state.closeTrackMenuLocation,theme:this.props.theme},N.createElement(uXe,{onCloseTrack:this.handleCloseTrack.bind(this),tracks:[gC(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",Jo["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);V$.defaultProps={isShowGlobalMousePosition:!1,pluginDataFetchers:{},pluginTracks:{},metaTracks:[],zoomable:!0};V$.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 O$t=ty(Dk(cm(V$)));var _$t=Object.assign||function(e){for(var g=1;g"u"?"undefined":L$t(g))==="object"){for(var n in g)g.hasOwnProperty(n)&&$p(e,n,g[n]);return}if(typeof I<"u"){typeof I=="number"&&(I+="px"),e.style[g]=I;return}return Yh(e,g)}W$(["width","height"],function(e){var g=e.charAt(0).toUpperCase()+e.slice(1);rA["outer"+g]=function(I,n){return I&&Sse(I,e,n?I8t:kO)};var i=e==="width"?["Left","Right"]:["Top","Bottom"];rA[e]=function(I,n){if(n!==void 0){if(I){Yh(I);var r=fXe(I);return r&&(n+=hG(I,["padding","border"],i)),$p(I,e,n)}return}return I&&Sse(I,e,NO)}});function C8t(e,g){$p(e,"position")==="static"&&(e.style.position="relative");var i=mXe(e),I={},n=void 0,r=void 0;for(r in g)g.hasOwnProperty(r)&&(n=parseFloat($p(e,r))||0,I[r]=n+g[r]-i[r]);$p(e,I)}var o8t=_$t({getWindow:function(g){var i=g.ownerDocument||g;return i.defaultView||i.parentWindow},offset:function(g,i){if(typeof i<"u")C8t(g,i);else return mXe(g)},isWindow:YW,each:W$,css:$p,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(YW(g)){if(i===void 0)return HO(g);window.scrollTo(i,TO(g))}else{if(i===void 0)return g.scrollLeft;g.scrollLeft=i}},scrollTop:function(g,i){if(YW(g)){if(i===void 0)return TO(g);window.scrollTo(HO(g),i)}else{if(i===void 0)return g.scrollTop;g.scrollTop=i}},viewportWidth:0,viewportHeight:0},rA),ii=o8t;function a8t(e,g,i){i=i||{},g.nodeType===9&&(g=ii.getWindow(g));var I=i.allowHorizontalScroll,n=i.onlyScrollIfNeeded,r=i.alignWithTop,C=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(g),c=ii.offset(e),u=ii.outerHeight(e),d=ii.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=ii.height(Z),G=ii.width(Z),B={left:ii.scrollLeft(Z),top:ii.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=ii.offset(g),m=g.clientHeight,f=g.clientWidth,b={left:g.scrollLeft,top:g.scrollTop},p={left:c.left-(h.left+(parseFloat(ii.css(g,"borderLeftWidth"))||0))-a,top:c.top-(h.top+(parseFloat(ii.css(g,"borderTopWidth"))||0))-o},y={left:c.left+d-(h.left+f+(parseFloat(ii.css(g,"borderRightWidth"))||0))+A,top:c.top+u-(h.top+m+(parseFloat(ii.css(g,"borderBottomWidth"))||0))+s}),p.top<0||y.top>0?r===!0?ii.scrollTop(g,b.top+p.top):r===!1?ii.scrollTop(g,b.top+y.top):p.top<0?ii.scrollTop(g,b.top+p.top):ii.scrollTop(g,b.top+y.top):n||(r=r===void 0?!0:!!r,r?ii.scrollTop(g,b.top+p.top):ii.scrollTop(g,b.top+y.top)),I&&(p.left<0||y.left>0?C===!0?ii.scrollLeft(g,b.left+p.left):C===!1?ii.scrollLeft(g,b.left+y.left):p.left<0?ii.scrollLeft(g,b.left+p.left):ii.scrollLeft(g,b.left+y.left):n||(C=C===void 0?!0:!!C,C?ii.scrollLeft(g,b.left+p.left):ii.scrollLeft(g,b.left+y.left)))}var A8t=a8t,s8t=A8t;const l8t=Pr(s8t);function sH(){return sH=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 lH(e){return lH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},lH(e)}const bZ=[];let X$=function(e){m8t(i,e);var g=f8t(i);function i(I){var n;return c8t(this,i),n=g.call(this,I),n.state={highlightedIndex:null,menuTop:0,menuLeft:0,menuWidth:0,isOpen:!1},n.keyDownHandlers={ArrowDown(r){r.preventDefault();const C=this.getFilteredItems().length;if(!C)return;const{highlightedIndex:o}=this.state,a=o===null||o===C-1?0:o+1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:a,isOpen:!0})},ArrowUp(r){r.preventDefault();const C=this.getFilteredItems().length;if(!C)return;const{highlightedIndex:o}=this.state,a=o===0||o===null?C-1:o-1;this._performAutoCompleteOnKeyUp=!0,this.setState({highlightedIndex:a,isOpen:!0})},Enter(r){if(this.state.isOpen!==!1)if(this.state.highlightedIndex===null)this.setState({isOpen:!1},()=>{this.inputEl.select()});else{r.preventDefault();const C=this.getFilteredItems()[this.state.highlightedIndex],o=this.props.getItemValue(C);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.inputEl.setSelectionRange(o.length,o.length),this.props.onSelect(o,C)})}},Escape(){this.setState({highlightedIndex:null,isOpen:!1})}},n}return u8t(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,r){this.state.isOpen===!0&&r.isOpen===!1&&this.setMenuPositions(),this.state.isOpen&&this._performAutoCompleteOnUpdate&&(this._performAutoCompleteOnUpdate=!1,this.maybeAutoCompleteText()),this.maybeScrollItemIntoView(),r.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}`],r=this.refs.menu;n&&l8t(Aa.findDOMNode(n),Aa.findDOMNode(r),{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(r=>this.props.shouldItemRender(r,this.props.value))),this.props.sortItems&&n.sort((r,C)=>this.props.sortItems(r,C,this.props.value)),n}},{key:"maybeAutoCompleteText",value:function(){if(!this.props.autoHighlight||this.props.value==="")return;const{highlightedIndex:n}=this.state,r=this.getFilteredItems();if(r.length===0)return;const C=n!==null?r[n]:r[0];this.props.getItemValue(C).toLowerCase().indexOf(this.props.value.toLowerCase())===0&&n===null&&this.setState({highlightedIndex:0})}},{key:"setMenuPositions",value:function(){const n=this.inputEl,r=n.getBoundingClientRect(),C=globalThis.window.getComputedStyle(n),o=parseInt(C.marginBottom,10)||0,a=parseInt(C.marginLeft,10)||0,s=parseInt(C.marginRight,10)||0;this.setState({menuTop:r.bottom+o,menuLeft:r.left+a,menuWidth:r.width+a+s})}},{key:"highlightItemFromMouse",value:function(n){this.setState({highlightedIndex:n})}},{key:"selectItemFromMouse",value:function(n){const r=this.props.getItemValue(n);this.setState({isOpen:!1,highlightedIndex:null},()=>{this.props.onSelect(r,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}`})}),r={left:this.state.menuLeft,top:this.state.menuTop,minWidth:this.state.menuWidth};if(!n.length)return null;const C=this.props.renderMenu(n,this.props.value,r);return N.cloneElement(C,{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,r){return r?C=>{n(C),r(C)}:n}},{key:"render",value:function(){this.props.debug&&bZ.push({id:bZ.length,state:this.state});const{inputProps:n}=this.props;return N.createElement("div",sH({style:{...this.props.wrapperStyle}},this.props.wrapperProps),N.createElement("input",sH({},n,{ref:r=>{this.inputEl=r},"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(bZ.slice(bZ.length-5,bZ.length),null,2)))}}]),i}(N.Component);X$.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(){}};X$.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 Z8t="_btn_1l2sx_95",nf={"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:Z8t,"btn-sm":"_btn-sm_1l2sx_116","btn-default":"_btn-default_1l2sx_122"};function G8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Rse(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 bXe=function(e){w8t(i,e);var g=R8t(i);function i(I){var n;return G8t(this,i),n=g.call(this,I),n.mounted=!1,n.uid=sg.nice(),n.chromInfo=null,n.searchField=null,n.autocompleteMenu=null,n.xScale=null,n.yScale=null,n.prevParts=[],n.props.registerViewportChangedListener(n.scalesChanged.bind(pXe(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 v8t(i,[{key:"componentDidMount",value:function(){this.mounted=!0,dg(this.autocompleteMenu.inputEl).on("keypress",this.autocompleteKeyPress.bind(this)),this.findAvailableAutocompleteSources(),this.findAvailableChromSizes(),this.props.chromInfoPath&&(this.searchPosition=!0,Js(this.props.chromInfoPath,n=>{if(!n){this.searchPosition=null;return}this.chromInfo=n,this.searchField=new n0(this.chromInfo),this.setPositionText()})),this.setPositionText()}},{key:"componentWillUnmount",value:function(){this.mounted=!1,this.props.removeViewportChangedListener()}},{key:"onAutocompleteChange",value:function(n,r){this.positionText=r,this.setState({value:r,loading:!0}),this.changedPart=null;const C=r.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(RC(this.availableChromSizes)),r=new Set([...n]);this.gpsbForm&&this.setState({availableAssemblies:[...r]})}},{key:"setSelectedAssembly",value:function(n){if(!this.mounted||!this.availableChromSizes[n])return;const r=[...this.availableChromSizes[n]][0];this.setState({autocompleteServer:r.server});const{server:C}=r;if(this.availableAutocompletes[n]){const o=[...this.availableAutocompletes[n]][0].acId;this.props.onSelectedAssemblyChanged(n,o,C),this.gpsbForm&&this.setState({autocompleteId:o})}else this.props.onSelectedAssemblyChanged(n,null,C),this.gpsbForm&&this.setState({autocompleteId:null});this.fetchChromInfo(r.uuid,r.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,r){this.xScale=n,this.yScale=r,this.setPositionText()}},{key:"findAvailableChromSizes",value:function(){this.props.trackSourceServers&&this.props.trackSourceServers.forEach(n=>{vt.json(`${n}/available-chrom-sizes/`,(r,C)=>{r?console.error(r):(C.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`,(r,C)=>{r?console.error(r):(C.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,r){Js(`${r}/chrom-sizes/?id=${n}`,C=>{C&&(vt.json(`${r}/tileset_info/?d=${n}`,(o,a)=>{o||this.gpsbForm&&this.setState({selectedAssembly:a[n].coordSystem})},this.props.pubSub),this.chromInfo=C,this.searchField=new n0(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 r=this.positionText,C=r.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 r=this.positionText;if(this.searchField!==null){const C=this.searchField.searchPosition(r),o=C[0];let a=C[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]=SI(s,A);n&&this.props.onGeneSearch({geneSymbol:n,range:o,centerX:l,centerY:c}),this.props.setCenters(l,c,u,SGe)}})}},{key:"searchFieldSubmit",value:function(){this.buttonClick()}},{key:"pathJoin",value:function(n,r){const C=r||"/",o=new RegExp(`${C}{1,}`,"g");return n.join(C).replace(o,C)}},{key:"geneSelected",value:function(n,r){const C=this.positionText.split(" ");let o=this.changedPart;for(let a=0;as.length-1)o-=s.length;else{if(s[o]=r.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:r,value:r},r));return N.createElement("div",{ref:r=>{this.gpsbForm=r},className:Xg({[nf["genome-position-search-focus"]]:this.state.isFocused,[nf["genome-position-search"]]:!this.state.isFocused,[nf["genome-position-search-dark"]]:this.props.theme===gi})},!this.props.hideAvailableAssemblies&&N.createElement("select",{ref:r=>{this.assemblyPickButton=r},className:nf["genome-position-search-bar-button"],id:this.uid,onChange:this.handleAssemblySelectEvt.bind(this),value:this.state.selectedAssembly||void 0},n),N.createElement(X$,{ref:r=>{this.autocompleteMenu=r},getItemValue:r=>r.geneName,inputProps:{className:nf["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:(r,C)=>this.geneSelected(r,C),onSubmit:this.searchFieldSubmit.bind(this),renderItem:(r,C)=>N.createElement("div",{key:r.refseqid,id:r.refseqid,style:C?this.styles.highlightedItem:this.styles.item},r.geneName),renderMenu:this.handleRenderMenu.bind(this),value:this.state.selectedAssembly?this.positionText:"No valid assembly selected",wrapperStyle:{width:"100%"}}),N.createElement(TGe,{onClick:this.buttonClick.bind(this),theStyle:"multitrack-header-icon"}))}}]),i}(N.Component);bXe.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 X8t=ty(cm(bXe)),H8t={"export-link-dialog-wrapper":"_export-link-dialog-wrapper_p9gxw_1"};function T8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Vse(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 H$=function(e){K8t(i,e);var g=F8t(i);function i(){return T8t(this,i),g.apply(this,arguments)}return N8t(i,[{key:"render",value:function(){return N.createElement(vw,{okayOnly:!0,okayTitle:"Done",onOkay:this.props.onDone,title:"Share view link"},N.createElement("div",{className:H8t["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(Xs,{onClick:n=>{this.input.select(),document.execCommand("copy")}},"Copy")))}}]),i}(N.Component);H$.defaultProps={onDone:()=>{},url:""};H$.propTypes={onDone:L.func,url:L.string};function M8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Wse(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 yXe=function(e){O8t(i,e);var g=_8t(i);function i(I){var n;return M8t(this,i),n=g.call(this,I),n.state={submenuShown:!1},n}return z8t(i,[{key:"getConfigureViewMenu",value:function(n,r){const C=["backgroundColor"],o={},a={};for(const s of C)if(s in Object.keys(an)&&(o[s]={name:an[s].name},an[s].inlineOptions))for(const A in an[s].inlineOptions){const l=an[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(GO,{key:"config-series-menu",closeMenu:this.props.closeMenu,menuItems:o,orientation:this.state.orientation,parentBbox:r,position:n,theme:this.props.theme})}},{key:"getSubmenu",value:function(){if(this.state.submenuShown){const n=this.state.submenuSourceBbox,r=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(r,n):N.createElement("div",null)}return N.createElement("div",null)}},{key:"render",value:function(){return N.createElement("div",{ref:n=>{this.div=n},className:Xg(Ut["context-menu"],{[Ut["context-menu-dark"]]:this.props.theme===gi}),"data-menu-type":"ConfigViewMenu",style:{left:this.state.left,top:this.state.top}},N.createElement(ig,{onClick:n=>this.props.onTogglePositionSearchBox(n)},"Toggle position search box"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:n=>this.props.onZoomToData(n)},"Zoom to data extent"),N.createElement(ig,{onClick:n=>this.props.onClearView(n)},"Clear View"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:n=>this.props.onYankZoom(n)},"Take zoom from"),N.createElement(ig,{onClick:n=>this.props.onYankLocation(n)},"Take location from"),N.createElement(ig,{onClick:n=>this.props.onYankZoomAndLocation(n)},"Take zoom and location from"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:this.props.onLockZoom},"Lock zoom with"),N.createElement(ig,{onClick:this.props.onLockLocation},"Lock location with"),N.createElement(ig,{onClick:this.props.onLockZoomAndLocation},"Lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:this.props.onTakeAndLockZoomAndLocation},"Take and lock zoom and location with"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:n=>this.props.onUnlockZoom(n)},"Unlock zoom"),N.createElement(ig,{onClick:n=>this.props.onUnlockLocation(n)},"Unlock location"),N.createElement(ig,{onClick:n=>this.props.onUnlockZoomAndLocation(n)},"Unlock zoom and location"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:n=>this.props.onProjectViewport(n)},"Show this viewport on"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:n=>this.props.onEditViewConfig(n)},"Edit view config"),N.createElement("hr",{className:Ut["context-menu-hr"]}),N.createElement(ig,{onClick:()=>this.props.onExportSVG()},"Export views as SVG"),N.createElement(ig,{onClick:()=>this.props.onExportPNG()},"Export views as PNG"),N.createElement(ig,{onClick:()=>this.props.onExportViewAsJSON()},"Export views as JSON"),N.createElement(ig,{onClick:()=>this.props.onExportViewAsLink()},"Export views as Link"),this.getSubmenu())}}]),i}(fu);yXe.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 vC={"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 ZXe(e){return N.createElement("div",null,N.createElement("div",{className:vC["add-track-position-span"]},"Add Track..."),N.createElement("table",{className:Xg(vC["add-track-position-table"],{[vC["add-track-position-table-dark"]]:e.theme===gi})},N.createElement("tbody",null,N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:vC["add-track-position-other"]}),N.createElement("td",{className:vC["add-track-position-top-center"],onClick:()=>e.onTrackPositionChosen("top")},"top"),N.createElement("td",{"aria-hidden":"true",className:vC["add-track-position-other"]})),N.createElement("tr",{style:{height:"80px"}},N.createElement("td",{className:vC["add-track-position-middle-left"],onClick:()=>e.onTrackPositionChosen("left")},"left"),N.createElement("td",{className:vC["add-track-position-middle-middle"],onClick:()=>e.onTrackPositionChosen("center")},"center"),N.createElement("td",{className:vC["add-track-position-middle-right"],onClick:()=>e.onTrackPositionChosen("right")},"right")),N.createElement("tr",{style:{height:"30px"}},N.createElement("td",{"aria-hidden":"true",className:vC["add-track-position-other"]}),N.createElement("td",{className:vC["add-track-position-bottom-middle"],onClick:()=>e.onTrackPositionChosen("bottom")},"bottom"),N.createElement("td",{"aria-hidden":"true",className:vC["add-track-position-other"]})))))}ZXe.propTypes={onTrackPositionChosen:L.func.isRequired,theme:L.symbol.isRequired};const j8t=cm(ZXe);function $8t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Xse(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 T$=function(e){g6t(i,e);var g=i6t(i);function i(I){var n;return $8t(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(GXe(n)),n}return q8t(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,r=null;this.state.addTrackPositionMenuPosition&&(r=N.createElement(Dc,{onMenuClosed:()=>{this.setState({addTrackPositionMenuUid:null,addTrackPositionMenuPosition:null})}},N.createElement(fu,{orientation:"left",position:this.state.addTrackPositionMenuPosition,theme:this.props.theme},N.createElement(j8t,{onTrackPositionChosen:this.handleTrackPositionChosenBound})))),this.state.configMenuUid&&(n=N.createElement(Dc,{onMenuClosed:()=>this.setState({configMenuUid:null})},N.createElement(yXe,{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 C=this.props.getGenomePositionSearchBox(this.state.isFocused,s=>{this.setState({isFocused:s})}),o=Xg(this.state.isFocused?wC["multitrack-header-focus"]:wC["multitrack-header"],{[wC["multitrack-header-dark"]]:this.props.theme===gi}),a=this.state.width<=wGe?wC["multitrack-header-icon-squeazed"]:wC["multitrack-header-icon"];return N.createElement("div",{ref:s=>{this.el=s},className:o},N.createElement("div",{className:wC["multitrack-header-left"]},this.props.mouseTool===EC&&N.createElement("svg",{className:Xg(wC["mouse-tool-selection"],a),title:"Selection tool active"},N.createElement("use",{xlinkHref:"#select"})),N.createElement("div",{className:wC["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:wC["multitrack-header-search"]},this.props.isGenomePositionSearchBoxVisible&&C)),N.createElement("nav",{className:wC["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,r)}}]),i}(N.Component);T$.defaultProps={isGenomePositionSearchBoxVisible:!1};T$.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 r6t=cm(T$);var vXe={};Object.defineProperty(vXe,"__esModule",{value:!0});var wl=Object.assign||function(e){for(var g=1;g=0||Object.prototype.hasOwnProperty.call(e,I)&&(i[I]=e[I]);return i}function s6t(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Hse(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 l6t(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 c6t=13,u6t=9,d6t=8,h6t=89,jV=90,m6t=77,Tse=57,Nse=219,kse=222,Yse=192,f6t=27,Kse=100,p6t=3e3,b6t="navigator"in globalThis&&/Win/i.test(navigator.platform),Gx="navigator"in globalThis&&/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform),KW="npm__react-simple-code-editor__textarea",y6t=` /** * Reset the text fill color so that placeholder is visible */ -.`+NW+`:empty { +.`+KW+`:empty { -webkit-text-fill-color: inherit !important; } @@ -1940,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 */ - .`+NW+` { + .`+KW+` { color: transparent !important; } - .`+NW+`::selection { + .`+KW+`::selection { background-color: #accef7 !important; color: transparent !important; } } -`,m9e=function(e){n6t(g,e);function g(){var I,i,n,C;i6t(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>Xse){var h=d-Xse;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.timestamp1&&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>Kse){var h=d-Kse;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===o6t){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===C6t){if(f===b){var K=n._getLines(m,f).pop(),F=K.match(/^\s+/);if(F&&F[0]){s.preventDefault();var J=` -`+F[0],P=f+J.length;n._applyEdits({value:m.substring(0,f)+J+m.substring(b),selectionStart:P,selectionEnd:P})}}}else if(s.keyCode===wse||s.keyCode===Vse||s.keyCode===Rse||s.keyCode===Wse){var ge=void 0;s.keyCode===wse&&s.shiftKey?ge=["(",")"]:s.keyCode===Vse?s.shiftKey?ge=["{","}"]:ge=["[","]"]:s.keyCode===Rse?s.shiftKey?ge=['"','"']:ge=["'","'"]:s.keyCode===Wse&&!s.shiftKey&&(ge=["`","`"]),f!==b&&ge&&(s.preventDefault(),n._applyEdits({value:m.substring(0,f)+ge[0]+m.substring(f,b)+ge[1]+m.substring(b),selectionStart:f,selectionEnd:b+2}))}else(bF?s.metaKey&&s.keyCode===LR:s.ctrlKey&&s.keyCode===LR)&&!s.shiftKey&&!s.altKey?(s.preventDefault(),n._undoEdit()):(bF?s.metaKey&&s.keyCode===LR&&s.shiftKey:c6t?s.ctrlKey&&s.keyCode===a6t:s.ctrlKey&&s.keyCode===LR&&s.shiftKey)&&!s.altKey?(s.preventDefault(),n._redoEdit()):s.keyCode===A6t&&s.ctrlKey&&(!bF||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),Sse(n,C)}return e6t(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=I6t(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 bZ.createElement("div",wl({},G,{style:wl({},yZ.container,r)}),bZ.createElement("textarea",{ref:function(S){return i._input=S},style:wl({},yZ.editor,yZ.textarea,v),className:NW,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}),bZ.createElement("pre",wl({"aria-hidden":"true",style:wl({},yZ.editor,yZ.highlight,v)},typeof w=="string"?{dangerouslySetInnerHTML:{__html:w+"
"}}:{children:w})),bZ.createElement("style",{type:"text/css",dangerouslySetInnerHTML:{__html:u6t}}))}},{key:"session",get:function(){return{history:this._history}},set:function(i){this._history=i.history}}]),g}(bZ.Component);m9e.defaultProps={tabSize:2,insertSpaces:!0,ignoreTabKey:!1,padding:0};var d6t=h9e.default=m9e,yZ={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"}},f9e={exports:{}};(function(e){var g=typeof window<"u"?window:typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope?self:{};/** +`);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),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===d6t){var V=f!==b,H=m.substring(0,f);if(H.endsWith(p)&&!V){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===c6t){if(f===b){var K=n._getLines(m,f).pop(),x=K.match(/^\s+/);if(x&&x[0]){s.preventDefault();var J=` +`+x[0],P=f+J.length;n._applyEdits({value:m.substring(0,f)+J+m.substring(b),selectionStart:P,selectionEnd:P})}}}else if(s.keyCode===Tse||s.keyCode===Nse||s.keyCode===kse||s.keyCode===Yse){var ge=void 0;s.keyCode===Tse&&s.shiftKey?ge=["(",")"]:s.keyCode===Nse?s.shiftKey?ge=["{","}"]:ge=["[","]"]:s.keyCode===kse?s.shiftKey?ge=['"','"']:ge=["'","'"]:s.keyCode===Yse&&!s.shiftKey&&(ge=["`","`"]),f!==b&&ge&&(s.preventDefault(),n._applyEdits({value:m.substring(0,f)+ge[0]+m.substring(f,b)+ge[1]+m.substring(b),selectionStart:f,selectionEnd:b+2}))}else(Gx?s.metaKey&&s.keyCode===jV:s.ctrlKey&&s.keyCode===jV)&&!s.shiftKey&&!s.altKey?(s.preventDefault(),n._undoEdit()):(Gx?s.metaKey&&s.keyCode===jV&&s.shiftKey:b6t?s.ctrlKey&&s.keyCode===h6t:s.ctrlKey&&s.keyCode===jV&&s.shiftKey)&&!s.altKey?(s.preventDefault(),n._redoEdit()):s.keyCode===m6t&&s.ctrlKey&&(!Gx||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),Hse(n,r)}return C6t(g,[{key:"componentDidMount",value:function(){this._recordCurrentState()}},{key:"render",value:function(){var I=this,n=this.props,r=n.value,C=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=A6t(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(r);return yZ.createElement("div",wl({},G,{style:wl({},ZZ.container,C)}),yZ.createElement("textarea",{ref:function(S){return I._input=S},style:wl({},ZZ.editor,ZZ.textarea,v),className:KW,id:s,value:r,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}),yZ.createElement("pre",wl({"aria-hidden":"true",style:wl({},ZZ.editor,ZZ.highlight,v)},typeof w=="string"?{dangerouslySetInnerHTML:{__html:w+"
"}}:{children:w})),yZ.createElement("style",{type:"text/css",dangerouslySetInnerHTML:{__html:y6t}}))}},{key:"session",get:function(){return{history:this._history}},set:function(I){this._history=I.history}}]),g}(yZ.Component);BXe.defaultProps={tabSize:2,insertSpaces:!0,ignoreTabKey:!1,padding:0};var Z6t=vXe.default=BXe,ZZ={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"}},SXe={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 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);J+=F.value.length,F=F.next){var P=F.value;if(p.length>b.length)return;if(!(P instanceof a)){var ge=1,q;if(R){if(q=s(K,J,b,W),!q||q.index>=b.length)break;var Q=q.index,$=q.index+q[0].length,j=J;for(j+=F.value.length;Q>=j;)F=F.next,j+=F.value.length;if(j-=F.value.length,J=j,F.value instanceof a)continue;for(var te=F;te!==p.tail&&(j<$||typeof te.value=="string");te=te.next)ge++,j+=te.value.length;ge--,P=b.slice(J,j),q.index-=J}else if(q=s(K,0,P,W),!q)continue;var Q=q.index,ie=q[0],he=P.slice(0,Q),ne=P.slice(Q+ie.length),be=J+P.length;G&&be>G.reach&&(G.reach=be);var pe=F.prev;he&&(pe=c(p,pe,he),J+=he.length),u(p,pe,ge);var ve=new a(v,X?o.tokenize(ie,X):ie,H,ie);if(F=c(p,pe,ve),ne&&c(p,F,ne),ge>1){var We={cause:v+","+V,reach:be};A(b,p,y,F.prev,J,We),G&&We.reach>G.reach&&(G.reach=We.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){D[0]=D[0].slice(0,-1);for(var ce=D.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(O){throw new RangeError(V[O])}function H(O,D){for(var ee=[],ce=O.length;ce--;)ee[ce]=D(O[ce]);return ee}function Y(O,D){var ee=O.split("@"),ce="";ee.length>1&&(ce=ee[0]+"@",O=ee[1]),O=O.replace(w,".");var de=O.split("."),Le=H(de,D).join(".");return ce+Le}function K(O){for(var D=[],ee=0,ce=O.length;ee=55296&&de<=56319&&ee>1,D+=X(D/ee);D>S*f>>1;de+=h)D=X(D/S);return X(de+(S+1)*D/(D+b))},q=function(D){var ee=[],ce=D.length,de=0,Le=Z,Ue=y,dt=D.lastIndexOf(B);dt<0&&(dt=0);for(var yt=0;yt=128&&R("not-basic"),ee.push(D.charCodeAt(yt));for(var kt=dt>0?dt+1:0;kt=ce&&R("invalid-input");var At=J(D.charCodeAt(kt++));(At>=h||At>X((d-de)/Vt))&&R("overflow"),de+=At*Vt;var Xt=Ft<=Ue?m:Ft>=Ue+f?f:Ft-Ue;if(AtX(d/Pt)&&R("overflow"),Vt*=Pt}var xt=ee.length+1;Ue=ge(de-ht,xt,ht==0),X(de/xt)>d-Le&&R("overflow"),Le+=X(de/xt),de%=xt,ee.splice(de++,0,Le)}return String.fromCodePoint.apply(String,ee)},$=function(D){var ee=[];D=K(D);var ce=D.length,de=Z,Le=0,Ue=y,dt=!0,yt=!1,kt=void 0;try{for(var ht=D[Symbol.iterator](),Vt;!(dt=(Vt=ht.next()).done);dt=!0){var Ft=Vt.value;Ft<128&&ee.push(W(Ft))}}catch(pC){yt=!0,kt=pC}finally{try{!dt&&ht.return&&ht.return()}finally{if(yt)throw kt}}var At=ee.length,Xt=At;for(At&&ee.push(B);Xt=de&&LtX((d-Le)/Yt)&&R("overflow"),Le+=(Pt-de)*Yt,de=Pt;var Wt=!0,eg=!1,_t=void 0;try{for(var $t=D[Symbol.iterator](),ag;!(Wt=(ag=$t.next()).done);Wt=!0){var Wg=ag.value;if(Wgd&&R("overflow"),Wg==de){for(var hg=Le,PI=h;;PI+=h){var en=PI<=Ue?m:PI>=Ue+f?f:PI-Ue;if(hg>6|192).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase():ee="%"+(D>>12|224).toString(16).toUpperCase()+"%"+(D>>6&63|128).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase(),ee}function ne(O){for(var D="",ee=0,ce=O.length;ee=194&&de<224){if(ce-ee>=6){var Le=parseInt(O.substr(ee+4,2),16);D+=String.fromCharCode((de&31)<<6|Le&63)}else D+=O.substr(ee,6);ee+=6}else if(de>=224){if(ce-ee>=9){var Ue=parseInt(O.substr(ee+4,2),16),dt=parseInt(O.substr(ee+7,2),16);D+=String.fromCharCode((de&15)<<12|(Ue&63)<<6|dt&63)}else D+=O.substr(ee,9);ee+=9}else D+=O.substr(ee,3),ee+=3}return D}function be(O,D){function ee(ce){var de=ne(ce);return de.match(D.UNRESERVED)?de:ce}return O.scheme&&(O.scheme=String(O.scheme).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_SCHEME,"")),O.userinfo!==void 0&&(O.userinfo=String(O.userinfo).replace(D.PCT_ENCODED,ee).replace(D.NOT_USERINFO,he).replace(D.PCT_ENCODED,r)),O.host!==void 0&&(O.host=String(O.host).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_HOST,he).replace(D.PCT_ENCODED,r)),O.path!==void 0&&(O.path=String(O.path).replace(D.PCT_ENCODED,ee).replace(O.scheme?D.NOT_PATH:D.NOT_PATH_NOSCHEME,he).replace(D.PCT_ENCODED,r)),O.query!==void 0&&(O.query=String(O.query).replace(D.PCT_ENCODED,ee).replace(D.NOT_QUERY,he).replace(D.PCT_ENCODED,r)),O.fragment!==void 0&&(O.fragment=String(O.fragment).replace(D.PCT_ENCODED,ee).replace(D.NOT_FRAGMENT,he).replace(D.PCT_ENCODED,r)),O}function pe(O){return O.replace(/^0*(.*)/,"$1")||"0"}function ve(O,D){var ee=O.match(D.IPV4ADDRESS)||[],ce=c(ee,2),de=ce[1];return de?de.split(".").map(pe).join("."):O}function We(O,D){var ee=O.match(D.IPV6ADDRESS)||[],ce=c(ee,3),de=ce[1],Le=ce[2];if(de){for(var Ue=de.toLowerCase().split("::").reverse(),dt=c(Ue,2),yt=dt[0],kt=dt[1],ht=kt?kt.split(":").map(pe):[],Vt=yt.split(":").map(pe),Ft=D.IPV4ADDRESS.test(Vt[Vt.length-1]),At=Ft?7:8,Xt=Vt.length-At,Pt=Array(At),xt=0;xt1){var Zt=Pt.slice(0,qg.index),Lt=Pt.slice(qg.index+qg.length);It=Zt.join(":")+"::"+Lt.join(":")}else It=Pt.join(":");return Le&&(It+="%"+Le),It}else return O}var Be=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function Pe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee={},ce=D.iri!==!1?l:A;D.reference==="suffix"&&(O=(D.scheme?D.scheme+":":"")+"//"+O);var de=O.match(Be);if(de){Je?(ee.scheme=de[1],ee.userinfo=de[3],ee.host=de[4],ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=de[7],ee.fragment=de[8],isNaN(ee.port)&&(ee.port=de[5])):(ee.scheme=de[1]||void 0,ee.userinfo=O.indexOf("@")!==-1?de[3]:void 0,ee.host=O.indexOf("//")!==-1?de[4]:void 0,ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=O.indexOf("?")!==-1?de[7]:void 0,ee.fragment=O.indexOf("#")!==-1?de[8]:void 0,isNaN(ee.port)&&(ee.port=O.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),ee.host&&(ee.host=We(ve(ee.host,ce),ce)),ee.scheme===void 0&&ee.userinfo===void 0&&ee.host===void 0&&ee.port===void 0&&!ee.path&&ee.query===void 0?ee.reference="same-document":ee.scheme===void 0?ee.reference="relative":ee.fragment===void 0?ee.reference="absolute":ee.reference="uri",D.reference&&D.reference!=="suffix"&&D.reference!==ee.reference&&(ee.error=ee.error||"URI is not a "+D.reference+" reference.");var Le=ie[(D.scheme||ee.scheme||"").toLowerCase()];if(!D.unicodeSupport&&(!Le||!Le.unicodeSupport)){if(ee.host&&(D.domainHost||Le&&Le.domainHost))try{ee.host=Q.toASCII(ee.host.replace(ce.PCT_ENCODED,ne).toLowerCase())}catch(Ue){ee.error=ee.error||"Host's domain name can not be converted to ASCII via punycode: "+Ue}be(ee,A)}else be(ee,ce);Le&&Le.parse&&Le.parse(ee,D)}else ee.error=ee.error||"URI can not be parsed.";return ee}function De(O,D){var ee=D.iri!==!1?l:A,ce=[];return O.userinfo!==void 0&&(ce.push(O.userinfo),ce.push("@")),O.host!==void 0&&ce.push(We(ve(String(O.host),ee),ee).replace(ee.IPV6ADDRESS,function(de,Le,Ue){return"["+Le+(Ue?"%25"+Ue:"")+"]"})),(typeof O.port=="number"||typeof O.port=="string")&&(ce.push(":"),ce.push(String(O.port))),ce.length?ce.join(""):void 0}var Qe=/^\.\.?\//,_e=/^\/\.(\/|$)/,gt=/^\/\.\.(\/|$)/,lt=/^\/?(?:.|\n)*?(?=\/|$)/;function tt(O){for(var D=[];O.length;)if(O.match(Qe))O=O.replace(Qe,"");else if(O.match(_e))O=O.replace(_e,"/");else if(O.match(gt))O=O.replace(gt,"/"),D.pop();else if(O==="."||O==="..")O="";else{var ee=O.match(lt);if(ee){var ce=ee[0];O=O.slice(ce.length),D.push(ce)}else throw new Error("Unexpected dot segment condition")}return D.join("")}function Xe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee=D.iri?l:A,ce=[],de=ie[(D.scheme||O.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(O,D),O.host&&!ee.IPV6ADDRESS.test(O.host)){if(D.domainHost||de&&de.domainHost)try{O.host=D.iri?Q.toUnicode(O.host):Q.toASCII(O.host.replace(ee.PCT_ENCODED,ne).toLowerCase())}catch(dt){O.error=O.error||"Host's domain name can not be converted to "+(D.iri?"Unicode":"ASCII")+" via punycode: "+dt}}be(O,ee),D.reference!=="suffix"&&O.scheme&&(ce.push(O.scheme),ce.push(":"));var Le=De(O,D);if(Le!==void 0&&(D.reference!=="suffix"&&ce.push("//"),ce.push(Le),O.path&&O.path.charAt(0)!=="/"&&ce.push("/")),O.path!==void 0){var Ue=O.path;!D.absolutePath&&(!de||!de.absolutePath)&&(Ue=tt(Ue)),Le===void 0&&(Ue=Ue.replace(/^\/\//,"/%2F")),ce.push(Ue)}return O.query!==void 0&&(ce.push("?"),ce.push(O.query)),O.fragment!==void 0&&(ce.push("#"),ce.push(O.fragment)),ce.join("")}function ae(O,D){var ee=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(O=Pe(Xe(O,ee),ee),D=Pe(Xe(D,ee),ee)),ee=ee||{},!ee.tolerant&&D.scheme?(de.scheme=D.scheme,de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.userinfo!==void 0||D.host!==void 0||D.port!==void 0?(de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.path?(D.path.charAt(0)==="/"?de.path=tt(D.path):((O.userinfo!==void 0||O.host!==void 0||O.port!==void 0)&&!O.path?de.path="/"+D.path:O.path?de.path=O.path.slice(0,O.path.lastIndexOf("/")+1)+D.path:de.path=D.path,de.path=tt(de.path)),de.query=D.query):(de.path=O.path,D.query!==void 0?de.query=D.query:de.query=O.query),de.userinfo=O.userinfo,de.host=O.host,de.port=O.port),de.scheme=O.scheme),de.fragment=D.fragment,de}function ye(O,D,ee){var ce=a({scheme:"null"},ee);return Xe(ae(Pe(O,ce),Pe(D,ce),ce,!0),ce)}function He(O,D){return typeof O=="string"?O=Xe(Pe(O,D),D):C(O)==="object"&&(O=Pe(Xe(O,D),D)),O}function x(O,D,ee){return typeof O=="string"?O=Xe(Pe(O,ee),ee):C(O)==="object"&&(O=Xe(O,ee)),typeof D=="string"?D=Xe(Pe(D,ee),ee):C(D)==="object"&&(D=Xe(D,ee)),O===D}function T(O,D){return O&&O.toString().replace(!D||!D.iri?A.ESCAPE:l.ESCAPE,he)}function k(O,D){return O&&O.toString().replace(!D||!D.iri?A.PCT_ENCODED:l.PCT_ENCODED,ne)}var Ie={scheme:"http",domainHost:!0,parse:function(D,ee){return D.host||(D.error=D.error||"HTTP URIs must have a host."),D},serialize:function(D,ee){var ce=String(D.scheme).toLowerCase()==="https";return(D.port===(ce?443:80)||D.port==="")&&(D.port=void 0),D.path||(D.path="/"),D}},me={scheme:"https",domainHost:Ie.domainHost,parse:Ie.parse,serialize:Ie.serialize};function Re(O){return typeof O.secure=="boolean"?O.secure:String(O.scheme).toLowerCase()==="wss"}var we={scheme:"ws",domainHost:!0,parse:function(D,ee){var ce=D;return ce.secure=Re(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(D,ee){if((D.port===(Re(D)?443:80)||D.port==="")&&(D.port=void 0),typeof D.secure=="boolean"&&(D.scheme=D.secure?"wss":"ws",D.secure=void 0),D.resourceName){var ce=D.resourceName.split("?"),de=c(ce,2),Le=de[0],Ue=de[1];D.path=Le&&Le!=="/"?Le:void 0,D.query=Ue,D.resourceName=void 0}return D.fragment=void 0,D}},je={scheme:"wss",domainHost:we.domainHost,parse:we.parse,serialize:we.serialize},at={},bt="[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)),Ce="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=i(E,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ye=new RegExp(bt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(i("[^]",Ce,"[\\.]",'[\\"]',_),"g"),re=new RegExp(i("[^]",bt,fe),"g"),oe=re;function Ve(O){var D=ne(O);return D.match(Ye)?D:O}var Fe={scheme:"mailto",parse:function(D,ee){var ce=D,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Le=!1,Ue={},dt=ce.query.split("&"),yt=0,kt=dt.length;yt=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 $6t(e,g,I){var i=w9e.call(this,e,g,I);i>=0&&this._compilations.splice(i,1)}function w9e(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,X9e=/^(?:(?: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,H9e=/^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i,T9e=/^(?:\/(?:[^~/]|~0|~1)*)*$/,N9e=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,k9e=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,Aqt=Lk;function Lk(e){return e=e=="full"?"full":"fast",iqt.copy(Lk[e])}Lk.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":W9e,url:X9e,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:R9e,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:x9e,uuid:H9e,"json-pointer":T9e,"json-pointer-uri-fragment":N9e,"relative-json-pointer":k9e};Lk.full={date:Y9e,time:K9e,"date-time":cqt,uri:dqt,"uri-reference":aqt,"uri-template":W9e,url:X9e,email:/^[a-z0-9!#$%&'*+/=?^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a-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:x9e,uuid:H9e,"json-pointer":T9e,"json-pointer-uri-fragment":N9e,"relative-json-pointer":k9e};function sqt(e){return e%4===0&&(e%100!==0||e%400===0)}function Y9e(e){var g=e.match(nqt);if(!g)return!1;var I=+g[1],i=+g[2],n=+g[3];return i>=1&&i<=12&&n>=1&&n<=(i==2&&sqt(I)?29:Cqt[i])}function K9e(e,g){var I=e.match(rqt);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 lqt=/t|\s/i;function cqt(e){var g=e.split(lqt);return g.length==2&&Y9e(g[0])&&K9e(g[1],!0)}var uqt=/\/|:/;function dqt(e){return uqt.test(e)&&oqt.test(e)}var hqt=/[^\\]\\Z/;function x9e(e){if(hqt.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var mqt=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},fqt=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},pqt=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},Gqt=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=P,n+=" } ",A&&(n+=" if ("+h+") { ",d+="}"))}return A&&(n+=" "+d+" if ("+c+" == errors) {"),n},vqt=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},Bqt=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},Sqt=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},wqt=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},Kse=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},xse=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},Dse=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},Fse=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},Vqt=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},Rqt=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},Wqt=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},Xqt=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},Hqt=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(F),B=g.schema.patternProperties||{},G=Object.keys(B).filter(F),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 J=Z;if(J)for(var P,ge=-1,q=J.length-1;ge0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var gt=g.util.getProperty(P),We=l+gt,lt=Je&&_e.default!==void 0;u.schema=_e,u.schemaPath=a+gt,u.errSchemaPath=s+"/"+g.util.escapeFragment(P),u.errorPath=g.util.getPath(g.errorPath,P,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(P);var Be=g.validate(u);if(u.baseId=H,g.util.varOccurences(Be,p)<2){Be=g.util.varReplace(Be,p,We);var tt=We}else{var tt=p;n+=" var "+p+" = "+We+"; "}if(lt)n+=" "+Be+" ";else{if(K&&K[P]){n+=" if ( "+tt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = false; ";var ie=g.errorPath,ne=s,Xe=g.util.escapeQuotes(P);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(ie,P,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var be=be||[];be.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Xe+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Xe+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+a+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var pe=n;n=be.pop(),!g.compositeRule&&A?g.async?n+=" throw new ValidationError(["+pe+"]); ":n+=" validate.errors = ["+pe+"]; return false; ":n+=" var err = "+pe+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=ne,g.errorPath=ie,n+=" } else { "}else A?(n+=" if ( "+tt+" === undefined ",R&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+tt+" !== undefined ",R&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=" ) { ");n+=" "+Be+" } "}}A&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var ae=G;if(ae)for(var j,ye=-1,He=ae.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 We=l+"["+m+"]";u.dataPathArr[b]=m;var Be=g.validate(u);u.baseId=H,g.util.varOccurences(Be,p)<2?n+=" "+g.util.varReplace(Be,p,We)+" ":n+=" var "+p+" = "+We+"; "+Be+" ",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},Tqt=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},Yqt={$ref:mqt,allOf:fqt,anyOf:pqt,$comment:bqt,const:yqt,contains:Zqt,dependencies:Gqt,enum:vqt,format:Bqt,if:Sqt,items:wqt,maximum:Kse,minimum:Kse,maxItems:xse,minItems:xse,maxLength:Dse,minLength:Dse,maxProperties:Fse,minProperties:Fse,multipleOf:Vqt,not:Rqt,oneOf:Wqt,pattern:Xqt,properties:Hqt,propertyNames:Tqt,required:Nqt,uniqueItems:kqt,validate:B9e},Ese=Yqt,ZF=cy.toHash,Kqt=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=ZF(I),g.types=ZF(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:Ese[r],implements:o};return s}),g.all.$comment={keyword:"$comment",code:Ese.$comment},C.type&&(g.types[C.type]=C)}),g.keywords=ZF(I.concat(i)),g.custom={},g},Mse=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],xqt=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 pH(e){return pH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},pH(e)}let Q9e=function(e){etg(I,e);var g=ttg(I);function I(i){var n;return Qeg(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(Fl(n)),n.handleKeyDownBound=n.handleKeyDown.bind(Fl(n)),n.handleKeyUpBound=n.handleKeyUp.bind(Fl(n)),n.handleSubmitBound=n.handleSubmit.bind(Fl(n)),n.hideBound=n.hide.bind(Fl(n)),n.showBound=n.show.bind(Fl(n)),n.toggleLogBound=n.toggleLog.bind(Fl(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 jeg(I,[{key:"componentDidMount",value:async function(){this.editor&&(this.editor._input.focus(),this.editor._input.setSelectionRange(0,0),await zQ(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 L9e().compile(U9e);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:Xg(Du.title,Du[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:Du["view-config-editor-header"]},N.createElement(Xs,{onBlur:this.showBound,onMouseDown:this.hideBound,onMouseOut:this.showBound,onMouseUp:this.showBound},"Hide While Mousedown"),N.createElement(Xs,{onClick:()=>{this.props.onChange(this.state.code)},shortcut:"⌘+S"},"Save")),N.createElement("div",{ref:C=>{this.editorWrap=C},className:Du["view-config-editor"]},N.createElement(d6t,{ref:C=>{this.editor=C},highlight:C=>Hse.highlight(C,Hse.languages.json),onValueChange:this.handleChangeBound,padding:10,style:{fontFamily:'"Fira code", "Fira Mono", monospace',fontSize:"inherit"},value:this.state.code})),N.createElement("div",{className:Du["view-config-log"],style:{height:this.state.showLog?"50%":"30px"}},N.createElement("div",{className:Du["view-config-log-header"],onClick:()=>this.toggleLogBound()},`Log Messages (${this.state.logMsgs.filter(C=>C.type!=="Success").length})`),N.createElement("div",{className:Du["view-config-log-msg"],style:{padding:this.state.showLog?"10px":0}},N.createElement("table",null,N.createElement("tbody",null,n))))))}}]),I}(N.Component);Q9e.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 itg=ey(Yk(Q9e));function ntg(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 Ctg=e=>{e.setState(e.state)},rtg=function(g,I){const i=g;let n=[];const C=yN(),r=()=>{n.forEach(o=>I.unsubscribe(o)),n=[]};return{destroy:r,publish:C.publish,stack:C.stack,public:{get version(){return iXe},setBroadcastMousePositionGlobally(o=!1){i.setBroadcastMousePositionGlobally(o)},setShowGlobalMousePosition(o=!1){i.setShowGlobalMousePosition(o)},setGlobalMousePosition(o=!1){i.setBroadcastMousePositionGlobally(o),i.setShowGlobalMousePosition(o)},setAuthHeader(o){YB(o),i.reload()},getAuthHeader(){return YB()},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(),jI.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 L9e().compile(U9e),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(Mr);break;default:i.setMouseTool(h9);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),_Q(i,s,A)},option(o,a){if(typeof a>"u")return i.props.options[o];switch(o){case"sizeMode":i.props.options[o]=a,Ctg(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}}}}},otg="_higlass_1uoq8_1",rf={higlass:otg,"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 atg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Ose(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 _se=12,mtg=12,ftg=20,ptg="default",Lse="bounded",Use="overflow",ZZ="scroll";let uy=function(e){ctg(I,e);var g=utg(I);function I(i){var n;atg(this,I),n=g.call(this,i),UGe(N.version)<15.6&&console.warn("HiGlass requires React v15.6 or higher. Current version: ",N.version),n.pubSub=yN(),n.domEvent=HGe(n.pubSub),n.pubSubs=[],n.minHorizontalHeight=20,n.minVerticalWidth=20,n.resizeSensor=null,n.uid=sg.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={},ot.PIXI=i.options&&i.options.PIXI||dpe,n.viewMarginTop=+i.options.viewMarginTop>=0?+i.options.viewMarginTop:zZ,n.viewMarginBottom=+i.options.viewMarginBottom>=0?+i.options.viewMarginBottom:zZ,n.viewMarginLeft=+i.options.viewMarginLeft>=0?+i.options.viewMarginLeft:zZ,n.viewMarginRight=+i.options.viewMarginRight>=0?+i.options.viewMarginRight:zZ,n.viewPaddingTop=+i.options.viewPaddingTop>=0?+i.options.viewPaddingTop:PZ,n.viewPaddingBottom=+i.options.viewPaddingBottom>=0?+i.options.viewPaddingBottom:PZ,n.viewPaddingLeft=+i.options.viewPaddingLeft>=0?+i.options.viewPaddingLeft:PZ,n.viewPaddingRight=+i.options.viewPaddingRight>=0?+i.options.viewPaddingRight:PZ,n.genomePositionSearchBox=null,n.viewHeaders={},n.boundRefreshView=()=>{n.refreshView(JZ)},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&&YB(i.options.authToken),n.pixiRoot=new ot.PIXI.Container,n.pixiRoot.interactive=!0,n.pixiStage=new ot.PIXI.Container,n.pixiStage.interactive=!0,n.pixiRoot.addChild(n.pixiStage),n.pixiMask=new ot.PIXI.Graphics,n.pixiRoot.addChild(n.pixiMask),n.pixiStage.mask=n.pixiMask,n.element=null,n.scrollTop=0;let o=h9;if(n.props.options)switch(n.props.options.mouseTool){case Mr:o=Mr;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}=rtg(eI(n),n.pubSub);return n.api=l,n.apiDestroy=c,n.apiPublish=u,n.apiStack=d,n.viewChangeListener=[],n.triggerViewChangeDb=TQ(n.triggerViewChange.bind(eI(n)),250),n.pubSubs=[],n.rangeSelection=[null,null],n.prevMouseHoverTrack=null,n.zooming=!1,n.appClickHandlerBound=n.appClickHandler.bind(eI(n)),n.canvasClickHandlerBound=n.canvasClickHandler.bind(eI(n)),n.keyDownHandlerBound=n.keyDownHandler.bind(eI(n)),n.keyUpHandlerBound=n.keyUpHandler.bind(eI(n)),n.resizeHandlerBound=n.resizeHandler.bind(eI(n)),n.resizeHandlerBound=n.resizeHandler.bind(eI(n)),n.dispatchEventBound=n.dispatchEvent.bind(eI(n)),n.animateOnMouseMoveHandlerBound=n.animateOnMouseMoveHandler.bind(eI(n)),n.zoomStartHandlerBound=n.zoomStartHandler.bind(eI(n)),n.zoomEndHandlerBound=n.zoomEndHandler.bind(eI(n)),n.zoomHandlerBound=n.zoomHandler.bind(eI(n)),n.trackDroppedHandlerBound=n.trackDroppedHandler.bind(eI(n)),n.trackDimensionsModifiedHandlerBound=n.trackDimensionsModifiedHandler.bind(eI(n)),n.animateBound=n.animate.bind(eI(n)),n.animateOnGlobalEventBound=n.animateOnGlobalEvent.bind(eI(n)),n.requestReceivedHandlerBound=n.requestReceivedHandler.bind(eI(n)),n.wheelHandlerBound=n.wheelHandler.bind(eI(n)),n.mouseMoveHandlerBound=n.mouseMoveHandler.bind(eI(n)),n.onMouseLeaveHandlerBound=n.onMouseLeaveHandler.bind(eI(n)),n.onBlurHandlerBound=n.onBlurHandler.bind(eI(n)),n.openModalBound=n.openModal.bind(eI(n)),n.closeModalBound=n.closeModal.bind(eI(n)),n.handleEditViewConfigBound=n.handleEditViewConfig.bind(eI(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(eI(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 Atg(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":ptg: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=zG.subscribe("higlass.mouseMove",this.animateOnGlobalEventBound),this.pubSubs.push(this.globalMousePositionListener)),this.isShowGlobalMousePosition&&!this.globalMousePositionListener){const C=this.pubSubs.findIndex(r=>r===this.globalMousePositionListener);zG.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=jI.findDOMNode(this);document.body.contains(C)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=jI.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(bfe[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 ot.PIXI.CanvasRenderer(n):this.pixiRenderer=new ot.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 ot.PIXI.CanvasRenderer(n):this.pixiRenderer=new ot.PIXI.Renderer(n)),this.fitPixiToParentContainer(),this.setState({svgElement:this.svgElement,canvasElement:this.canvasElement}),this.waitForDOMAttachment(()=>{A9.ElementQueries.listen(),this.resizeSensor=new A9.ResizeSensor(this.element.parentNode,this.updateAfterResize.bind(this)),this.updateAfterResize()}),this.handleDragStart(),this.handleDragStop(),this.animate();const r=dg(this.element).append("svg").style("display","none");ust.forEach(o=>ntg(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){YB(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 Eg(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=gI;break;case"light":case void 0:this.theme=f9;break;default:console.warn(`Unknown theme "${n}". Using light theme.`),this.theme=f9;break}}},{key:"dispatchEvent",value:function(n){this.canvasElement&&y9(n,this.canvasElement)}},{key:"trackDroppedHandler",value:function(){this.setState({draggingHappening:null})}},{key:"requestReceivedHandler",value:function(){!this.viewconfLoaded&&kB===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:Mr})}},{key:"keyUpHandler",value:function(n){this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:h9})}},{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(itg,{onCancel:()=>{const{viewConfigTmp:C}=this.state,r=this.processViewConfig(C);for(const o of Eg(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 Eg(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 Eg(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]=YGe(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(JZ),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=Ir(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){Eg(this.draggingChangedListeners).forEach(C=>{Eg(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 Eg(this.tiledPlots))if(C){for(const r of Eg(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=Sot.xml(new window.XMLSerializer().serializeToString(n));return C=C.replace(/ + */var i=function(I){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,r=0,C={},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:C,plaintext:C,text:C,txt:C,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 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,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],R=o.util.type(w);R==="Object"&&!B[G(w)]?(B[G(w)]=!0,b(w,y,null,B)):R==="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 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 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(R){Z+=b(R,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 R=0;R=G.reach);J+=x.value.length,x=x.next){var P=x.value;if(p.length>b.length)return;if(!(P instanceof a)){var ge=1,q;if(V){if(q=s(K,J,b,W),!q||q.index>=b.length)break;var Q=q.index,$=q.index+q[0].length,j=J;for(j+=x.value.length;Q>=j;)x=x.next,j+=x.value.length;if(j-=x.value.length,J=j,x.value instanceof a)continue;for(var te=x;te!==p.tail&&(j<$||typeof te.value=="string");te=te.next)ge++,j+=te.value.length;ge--,P=b.slice(J,j),q.index-=J}else if(q=s(K,0,P,W),!q)continue;var Q=q.index,Ie=q[0],he=P.slice(0,Q),ne=P.slice(Q+Ie.length),be=J+P.length;G&&be>G.reach&&(G.reach=be);var pe=x.prev;he&&(pe=c(p,pe,he),J+=he.length),u(p,pe,ge);var ve=new a(v,X?o.tokenize(Ie,X):Ie,H,Ie);if(x=c(p,pe,ve),ne&&c(p,x,ne),ge>1){var We={cause:v+","+R,reach:be};A(b,p,y,x.prev,J,We),G&&We.reach>G.reach&&(G.reach=We.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){D[0]=D[0].slice(0,-1);for(var ce=D.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(O){throw new RangeError(R[O])}function H(O,D){for(var ee=[],ce=O.length;ce--;)ee[ce]=D(O[ce]);return ee}function Y(O,D){var ee=O.split("@"),ce="";ee.length>1&&(ce=ee[0]+"@",O=ee[1]),O=O.replace(w,".");var de=O.split("."),Le=H(de,D).join(".");return ce+Le}function K(O){for(var D=[],ee=0,ce=O.length;ee=55296&&de<=56319&&ee>1,D+=X(D/ee);D>S*f>>1;de+=h)D=X(D/S);return X(de+(S+1)*D/(D+b))},q=function(D){var ee=[],ce=D.length,de=0,Le=Z,Ue=y,dt=D.lastIndexOf(B);dt<0&&(dt=0);for(var yt=0;yt=128&&V("not-basic"),ee.push(D.charCodeAt(yt));for(var kt=dt>0?dt+1:0;kt=ce&&V("invalid-input");var At=J(D.charCodeAt(kt++));(At>=h||At>X((d-de)/Rt))&&V("overflow"),de+=At*Rt;var Xt=xt<=Ue?m:xt>=Ue+f?f:xt-Ue;if(AtX(d/Pt)&&V("overflow"),Rt*=Pt}var Ft=ee.length+1;Ue=ge(de-ht,Ft,ht==0),X(de/Ft)>d-Le&&V("overflow"),Le+=X(de/Ft),de%=Ft,ee.splice(de++,0,Le)}return String.fromCodePoint.apply(String,ee)},$=function(D){var ee=[];D=K(D);var ce=D.length,de=Z,Le=0,Ue=y,dt=!0,yt=!1,kt=void 0;try{for(var ht=D[Symbol.iterator](),Rt;!(dt=(Rt=ht.next()).done);dt=!0){var xt=Rt.value;xt<128&&ee.push(W(xt))}}catch(fr){yt=!0,kt=fr}finally{try{!dt&&ht.return&&ht.return()}finally{if(yt)throw kt}}var At=ee.length,Xt=At;for(At&&ee.push(B);Xt=de&&LtX((d-Le)/Yt)&&V("overflow"),Le+=(Pt-de)*Yt,de=Pt;var Wt=!0,eg=!1,_t=void 0;try{for(var $t=D[Symbol.iterator](),ag;!(Wt=(ag=$t.next()).done);Wt=!0){var Wg=ag.value;if(Wgd&&V("overflow"),Wg==de){for(var hg=Le,Pi=h;;Pi+=h){var en=Pi<=Ue?m:Pi>=Ue+f?f:Pi-Ue;if(hg>6|192).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase():ee="%"+(D>>12|224).toString(16).toUpperCase()+"%"+(D>>6&63|128).toString(16).toUpperCase()+"%"+(D&63|128).toString(16).toUpperCase(),ee}function ne(O){for(var D="",ee=0,ce=O.length;ee=194&&de<224){if(ce-ee>=6){var Le=parseInt(O.substr(ee+4,2),16);D+=String.fromCharCode((de&31)<<6|Le&63)}else D+=O.substr(ee,6);ee+=6}else if(de>=224){if(ce-ee>=9){var Ue=parseInt(O.substr(ee+4,2),16),dt=parseInt(O.substr(ee+7,2),16);D+=String.fromCharCode((de&15)<<12|(Ue&63)<<6|dt&63)}else D+=O.substr(ee,9);ee+=9}else D+=O.substr(ee,3),ee+=3}return D}function be(O,D){function ee(ce){var de=ne(ce);return de.match(D.UNRESERVED)?de:ce}return O.scheme&&(O.scheme=String(O.scheme).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_SCHEME,"")),O.userinfo!==void 0&&(O.userinfo=String(O.userinfo).replace(D.PCT_ENCODED,ee).replace(D.NOT_USERINFO,he).replace(D.PCT_ENCODED,C)),O.host!==void 0&&(O.host=String(O.host).replace(D.PCT_ENCODED,ee).toLowerCase().replace(D.NOT_HOST,he).replace(D.PCT_ENCODED,C)),O.path!==void 0&&(O.path=String(O.path).replace(D.PCT_ENCODED,ee).replace(O.scheme?D.NOT_PATH:D.NOT_PATH_NOSCHEME,he).replace(D.PCT_ENCODED,C)),O.query!==void 0&&(O.query=String(O.query).replace(D.PCT_ENCODED,ee).replace(D.NOT_QUERY,he).replace(D.PCT_ENCODED,C)),O.fragment!==void 0&&(O.fragment=String(O.fragment).replace(D.PCT_ENCODED,ee).replace(D.NOT_FRAGMENT,he).replace(D.PCT_ENCODED,C)),O}function pe(O){return O.replace(/^0*(.*)/,"$1")||"0"}function ve(O,D){var ee=O.match(D.IPV4ADDRESS)||[],ce=c(ee,2),de=ce[1];return de?de.split(".").map(pe).join("."):O}function We(O,D){var ee=O.match(D.IPV6ADDRESS)||[],ce=c(ee,3),de=ce[1],Le=ce[2];if(de){for(var Ue=de.toLowerCase().split("::").reverse(),dt=c(Ue,2),yt=dt[0],kt=dt[1],ht=kt?kt.split(":").map(pe):[],Rt=yt.split(":").map(pe),xt=D.IPV4ADDRESS.test(Rt[Rt.length-1]),At=xt?7:8,Xt=Rt.length-At,Pt=Array(At),Ft=0;Ft1){var Zt=Pt.slice(0,qg.index),Lt=Pt.slice(qg.index+qg.length);it=Zt.join(":")+"::"+Lt.join(":")}else it=Pt.join(":");return Le&&(it+="%"+Le),it}else return O}var Be=/^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i,Je="".match(/(){0}/)[1]===void 0;function Pe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee={},ce=D.iri!==!1?l:A;D.reference==="suffix"&&(O=(D.scheme?D.scheme+":":"")+"//"+O);var de=O.match(Be);if(de){Je?(ee.scheme=de[1],ee.userinfo=de[3],ee.host=de[4],ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=de[7],ee.fragment=de[8],isNaN(ee.port)&&(ee.port=de[5])):(ee.scheme=de[1]||void 0,ee.userinfo=O.indexOf("@")!==-1?de[3]:void 0,ee.host=O.indexOf("//")!==-1?de[4]:void 0,ee.port=parseInt(de[5],10),ee.path=de[6]||"",ee.query=O.indexOf("?")!==-1?de[7]:void 0,ee.fragment=O.indexOf("#")!==-1?de[8]:void 0,isNaN(ee.port)&&(ee.port=O.match(/\/\/(?:.|\n)*\:(?:\/|\?|\#|$)/)?de[4]:void 0)),ee.host&&(ee.host=We(ve(ee.host,ce),ce)),ee.scheme===void 0&&ee.userinfo===void 0&&ee.host===void 0&&ee.port===void 0&&!ee.path&&ee.query===void 0?ee.reference="same-document":ee.scheme===void 0?ee.reference="relative":ee.fragment===void 0?ee.reference="absolute":ee.reference="uri",D.reference&&D.reference!=="suffix"&&D.reference!==ee.reference&&(ee.error=ee.error||"URI is not a "+D.reference+" reference.");var Le=Ie[(D.scheme||ee.scheme||"").toLowerCase()];if(!D.unicodeSupport&&(!Le||!Le.unicodeSupport)){if(ee.host&&(D.domainHost||Le&&Le.domainHost))try{ee.host=Q.toASCII(ee.host.replace(ce.PCT_ENCODED,ne).toLowerCase())}catch(Ue){ee.error=ee.error||"Host's domain name can not be converted to ASCII via punycode: "+Ue}be(ee,A)}else be(ee,ce);Le&&Le.parse&&Le.parse(ee,D)}else ee.error=ee.error||"URI can not be parsed.";return ee}function De(O,D){var ee=D.iri!==!1?l:A,ce=[];return O.userinfo!==void 0&&(ce.push(O.userinfo),ce.push("@")),O.host!==void 0&&ce.push(We(ve(String(O.host),ee),ee).replace(ee.IPV6ADDRESS,function(de,Le,Ue){return"["+Le+(Ue?"%25"+Ue:"")+"]"})),(typeof O.port=="number"||typeof O.port=="string")&&(ce.push(":"),ce.push(String(O.port))),ce.length?ce.join(""):void 0}var Qe=/^\.\.?\//,_e=/^\/\.(\/|$)/,gt=/^\/\.\.(\/|$)/,lt=/^\/?(?:.|\n)*?(?=\/|$)/;function tt(O){for(var D=[];O.length;)if(O.match(Qe))O=O.replace(Qe,"");else if(O.match(_e))O=O.replace(_e,"/");else if(O.match(gt))O=O.replace(gt,"/"),D.pop();else if(O==="."||O==="..")O="";else{var ee=O.match(lt);if(ee){var ce=ee[0];O=O.slice(ce.length),D.push(ce)}else throw new Error("Unexpected dot segment condition")}return D.join("")}function Xe(O){var D=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},ee=D.iri?l:A,ce=[],de=Ie[(D.scheme||O.scheme||"").toLowerCase()];if(de&&de.serialize&&de.serialize(O,D),O.host&&!ee.IPV6ADDRESS.test(O.host)){if(D.domainHost||de&&de.domainHost)try{O.host=D.iri?Q.toUnicode(O.host):Q.toASCII(O.host.replace(ee.PCT_ENCODED,ne).toLowerCase())}catch(dt){O.error=O.error||"Host's domain name can not be converted to "+(D.iri?"Unicode":"ASCII")+" via punycode: "+dt}}be(O,ee),D.reference!=="suffix"&&O.scheme&&(ce.push(O.scheme),ce.push(":"));var Le=De(O,D);if(Le!==void 0&&(D.reference!=="suffix"&&ce.push("//"),ce.push(Le),O.path&&O.path.charAt(0)!=="/"&&ce.push("/")),O.path!==void 0){var Ue=O.path;!D.absolutePath&&(!de||!de.absolutePath)&&(Ue=tt(Ue)),Le===void 0&&(Ue=Ue.replace(/^\/\//,"/%2F")),ce.push(Ue)}return O.query!==void 0&&(ce.push("?"),ce.push(O.query)),O.fragment!==void 0&&(ce.push("#"),ce.push(O.fragment)),ce.join("")}function ae(O,D){var ee=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},ce=arguments[3],de={};return ce||(O=Pe(Xe(O,ee),ee),D=Pe(Xe(D,ee),ee)),ee=ee||{},!ee.tolerant&&D.scheme?(de.scheme=D.scheme,de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.userinfo!==void 0||D.host!==void 0||D.port!==void 0?(de.userinfo=D.userinfo,de.host=D.host,de.port=D.port,de.path=tt(D.path||""),de.query=D.query):(D.path?(D.path.charAt(0)==="/"?de.path=tt(D.path):((O.userinfo!==void 0||O.host!==void 0||O.port!==void 0)&&!O.path?de.path="/"+D.path:O.path?de.path=O.path.slice(0,O.path.lastIndexOf("/")+1)+D.path:de.path=D.path,de.path=tt(de.path)),de.query=D.query):(de.path=O.path,D.query!==void 0?de.query=D.query:de.query=O.query),de.userinfo=O.userinfo,de.host=O.host,de.port=O.port),de.scheme=O.scheme),de.fragment=D.fragment,de}function ye(O,D,ee){var ce=a({scheme:"null"},ee);return Xe(ae(Pe(O,ce),Pe(D,ce),ce,!0),ce)}function He(O,D){return typeof O=="string"?O=Xe(Pe(O,D),D):r(O)==="object"&&(O=Pe(Xe(O,D),D)),O}function F(O,D,ee){return typeof O=="string"?O=Xe(Pe(O,ee),ee):r(O)==="object"&&(O=Xe(O,ee)),typeof D=="string"?D=Xe(Pe(D,ee),ee):r(D)==="object"&&(D=Xe(D,ee)),O===D}function T(O,D){return O&&O.toString().replace(!D||!D.iri?A.ESCAPE:l.ESCAPE,he)}function k(O,D){return O&&O.toString().replace(!D||!D.iri?A.PCT_ENCODED:l.PCT_ENCODED,ne)}var ie={scheme:"http",domainHost:!0,parse:function(D,ee){return D.host||(D.error=D.error||"HTTP URIs must have a host."),D},serialize:function(D,ee){var ce=String(D.scheme).toLowerCase()==="https";return(D.port===(ce?443:80)||D.port==="")&&(D.port=void 0),D.path||(D.path="/"),D}},me={scheme:"https",domainHost:ie.domainHost,parse:ie.parse,serialize:ie.serialize};function Ve(O){return typeof O.secure=="boolean"?O.secure:String(O.scheme).toLowerCase()==="wss"}var we={scheme:"ws",domainHost:!0,parse:function(D,ee){var ce=D;return ce.secure=Ve(ce),ce.resourceName=(ce.path||"/")+(ce.query?"?"+ce.query:""),ce.path=void 0,ce.query=void 0,ce},serialize:function(D,ee){if((D.port===(Ve(D)?443:80)||D.port==="")&&(D.port=void 0),typeof D.secure=="boolean"&&(D.scheme=D.secure?"wss":"ws",D.secure=void 0),D.resourceName){var ce=D.resourceName.split("?"),de=c(ce,2),Le=de[0],Ue=de[1];D.path=Le&&Le!=="/"?Le:void 0,D.query=Ue,D.resourceName=void 0}return D.fragment=void 0,D}},je={scheme:"wss",domainHost:we.domainHost,parse:we.parse,serialize:we.serialize},at={},bt="[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)),re="[A-Za-z0-9\\!\\$\\%\\'\\*\\+\\-\\^\\_\\`\\{\\|\\}\\~]",E="[\\!\\$\\%\\'\\(\\)\\*\\+\\,\\-\\.0-9\\<\\>A-Z\\x5E-\\x7E]",_=I(E,'[\\"\\\\]'),fe="[\\!\\$\\'\\(\\)\\*\\+\\,\\;\\:\\@]",Ye=new RegExp(bt,"g"),ue=new RegExp(Ht,"g"),le=new RegExp(I("[^]",re,"[\\.]",'[\\"]',_),"g"),Ce=new RegExp(I("[^]",bt,fe),"g"),oe=Ce;function Re(O){var D=ne(O);return D.match(Ye)?D:O}var xe={scheme:"mailto",parse:function(D,ee){var ce=D,de=ce.to=ce.path?ce.path.split(","):[];if(ce.path=void 0,ce.query){for(var Le=!1,Ue={},dt=ce.query.split("&"),yt=0,kt=dt.length;yt=55296&&r<=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(r="data"+(g-I||""),!n)return r}for(var o=r,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 nqt(e,g,i){var I=kXe.call(this,e,g,i);I>=0&&this._compilations.splice(I,1)}function kXe(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,DXe=/^(?:(?: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,EXe=/^(?:\/(?:[^~/]|~0|~1)*)*$/,MXe=/^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i,zXe=/^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/,mqt=jk;function jk(e){return e=e=="full"?"full":"fast",sqt.copy(jk[e])}jk.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":FXe,url:DXe,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:KXe,ipv4:/^(?:(?:25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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:OXe,uuid:xXe,"json-pointer":EXe,"json-pointer-uri-fragment":MXe,"relative-json-pointer":zXe};jk.full={date:PXe,time:JXe,"date-time":bqt,uri:Zqt,"uri-reference":hqt,"uri-template":FXe,url:DXe,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:KXe,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:OXe,uuid:xXe,"json-pointer":EXe,"json-pointer-uri-fragment":MXe,"relative-json-pointer":zXe};function fqt(e){return e%4===0&&(e%100!==0||e%400===0)}function PXe(e){var g=e.match(lqt);if(!g)return!1;var i=+g[1],I=+g[2],n=+g[3];return I>=1&&I<=12&&n>=1&&n<=(I==2&&fqt(i)?29:cqt[I])}function JXe(e,g){var i=e.match(uqt);if(!i)return!1;var I=i[1],n=i[2],r=i[3],C=i[5];return(I<=23&&n<=59&&r<=59||I==23&&n==59&&r==60)&&(!g||C)}var pqt=/t|\s/i;function bqt(e){var g=e.split(pqt);return g.length==2&&PXe(g[0])&&JXe(g[1],!0)}var yqt=/\/|:/;function Zqt(e){return yqt.test(e)&&dqt.test(e)}var Gqt=/[^\\]\\Z/;function OXe(e){if(Gqt.test(e))return!1;try{return new RegExp(e),!0}catch{return!1}}var vqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.errSchemaPath+"/"+i,s=!g.opts.allErrors,A="data"+(C||""),l="valid"+r,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=C?"data"+(C-1||""):"parentData",B=C?g.dataPathArr[C]:"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},Bqt=function(g,i,I){var n=" ",r=g.schema[i],C=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=r;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=C+"["+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},Sqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,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 R=n;return n=w.pop(),!g.compositeRule&&A?g.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; } "),g.opts.allErrors&&(n+=" } "),n},Wqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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"+r+";";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,R=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=P,n+=" } ",A&&(n+=" if ("+h+") { ",d+="}"))}return A&&(n+=" "+d+" if ("+c+" == errors) {"),n},Xqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u=g.opts.$data&&o&&o.$data;u&&(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ");var d="i"+r,h="schema"+r;u||(n+=" var "+h+" = validate.schema"+a+";"),n+="var "+c+";",u&&(n+=" if (schema"+r+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+r+")) "+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"+r+" } ",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},Hqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||"");if(g.opts.format===!1)return A&&(n+=" if (true) { "),n;var c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):u=o;var d=g.opts.unknownFormats,h=Array.isArray(d);if(c){var m="format"+r,f="isObject"+r,b="formatType"+r;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"+r+" = "+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"+r+" ? 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},Tqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,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"+r,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"+r,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},Nqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f="i"+r,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 R,S=-1,X=w.length-1;S0||R===!1:g.util.schemaHasRules(R,g.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=g.util.getPathExpr(g.errorPath,S,g.opts.jsonPointers,!0),d.dataPathArr[b]=S;var V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",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 V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",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 V=g.validate(d);d.baseId=y,g.util.varOccurences(V,p)<2?n+=" "+g.util.varReplace(V,p,W)+" ":n+=" var "+p+" = "+W+"; "+V+" ",A&&(n+=" if (!"+m+") break; "),n+=" }"}return A&&(n+=" "+h+" if ("+u+" == errors) {"),n},zse=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,y,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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,C,g.dataPathArr),B="exclusive"+r,G="exclType"+r,v="exclIsNumber"+r,w="op"+r,R="' + "+w+" + '";n+=" var schemaExcl"+r+" = "+Z+"; ",Z="schemaExcl"+r,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"+r+" = "+B+" ? '"+b+"' : '"+b+"='; ",o===void 0&&(y=h,s=g.errSchemaPath+"/"+h,u=Z,c=f)}else{var v=typeof m=="number",R=b;if(v&&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{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,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="",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 "+R+" ",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},Pse=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},Jse=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},Ose=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,h,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},kqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;if(c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):u=o,!(c||typeof o=="number"))throw new Error(i+" must be number");n+="var division"+r+";if (",c&&(n+=" "+u+" !== undefined && ( typeof "+u+" != 'number' || "),n+=" (division"+r+" = "+l+" / "+u+", ",g.opts.multipleOfPrecision?n+=" Math.abs(Math.round(division"+r+") - division"+r+") > 1e-"+g.opts.multipleOfPrecision+" ":n+=" division"+r+" !== parseInt(division"+r+") ",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},Yqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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},Kqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="valid"+r,u="errs__"+r,d=g.util.copy(g),h="";d.level++;var m="valid"+d.level,f=d.baseId,b="prevValid"+r,p="passingSchemas"+r;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},Fqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c=g.opts.$data&&o&&o.$data,u;c?(n+=" var schema"+r+" = "+g.util.getData(o.$data,C,g.dataPathArr)+"; ",u="schema"+r):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},Dqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,u=g.util.copy(g),d="";u.level++;var h="valid"+u.level,m="key"+r,f="idx"+r,b=u.dataLevel=g.dataLevel+1,p="data"+b,y="dataProperties"+r,Z=Object.keys(o||{}).filter(x),B=g.schema.patternProperties||{},G=Object.keys(B).filter(x),v=g.schema.additionalProperties,w=Z.length||G.length,R=v===!1,S=typeof v=="object"&&Object.keys(v).length,X=g.opts.removeAdditional,W=R||S||X,V=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 J=Z;if(J)for(var P,ge=-1,q=J.length-1;ge0||_e===!1:g.util.schemaHasRules(_e,g.RULES.all)){var gt=g.util.getProperty(P),We=l+gt,lt=Je&&_e.default!==void 0;u.schema=_e,u.schemaPath=a+gt,u.errSchemaPath=s+"/"+g.util.escapeFragment(P),u.errorPath=g.util.getPath(g.errorPath,P,g.opts.jsonPointers),u.dataPathArr[b]=g.util.toQuotedString(P);var Be=g.validate(u);if(u.baseId=H,g.util.varOccurences(Be,p)<2){Be=g.util.varReplace(Be,p,We);var tt=We}else{var tt=p;n+=" var "+p+" = "+We+"; "}if(lt)n+=" "+Be+" ";else{if(K&&K[P]){n+=" if ( "+tt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = false; ";var Ie=g.errorPath,ne=s,Xe=g.util.escapeQuotes(P);g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPath(Ie,P,g.opts.jsonPointers)),s=g.errSchemaPath+"/required";var be=be||[];be.push(n),n="",g.createErrors!==!1?(n+=" { keyword: 'required' , dataPath: (dataPath || '') + "+g.errorPath+" , schemaPath: "+g.util.toQuotedString(s)+" , params: { missingProperty: '"+Xe+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+Xe+"\\'",n+="' "),g.opts.verbose&&(n+=" , schema: validate.schema"+a+" , parentSchema: validate.schema"+g.schemaPath+" , data: "+l+" "),n+=" } "):n+=" {} ";var pe=n;n=be.pop(),!g.compositeRule&&A?g.async?n+=" throw new ValidationError(["+pe+"]); ":n+=" validate.errors = ["+pe+"]; return false; ":n+=" var err = "+pe+"; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ",s=ne,g.errorPath=Ie,n+=" } else { "}else A?(n+=" if ( "+tt+" === undefined ",V&&(n+=" || ! Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=") { "+h+" = true; } else { "):(n+=" if ("+tt+" !== undefined ",V&&(n+=" && Object.prototype.hasOwnProperty.call("+l+", '"+g.util.escapeQuotes(P)+"') "),n+=" ) { ");n+=" "+Be+" } "}}A&&(n+=" if ("+h+") { ",d+="}")}}if(G.length){var ae=G;if(ae)for(var j,ye=-1,He=ae.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),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 ("+g.usePattern(j)+".test("+m+")) { ",u.errorPath=g.util.getPathExpr(g.errorPath,m,g.opts.jsonPointers);var We=l+"["+m+"]";u.dataPathArr[b]=m;var Be=g.validate(u);u.baseId=H,g.util.varOccurences(Be,p)<2?n+=" "+g.util.varReplace(Be,p,We)+" ":n+=" var "+p+" = "+We+"; "+Be+" ",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},xqt=function(g,i,I){var n=" ",r=g.level,C=g.dataLevel,o=g.schema[i],a=g.schemaPath+g.util.getProperty(i),s=g.errSchemaPath+"/"+i,A=!g.opts.allErrors,l="data"+(C||""),c="errs__"+r,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"+r,f="idx"+r,b="i"+r,p="' + "+m+" + '",y=u.dataLevel=g.dataLevel+1,Z="data"+y,B="dataProperties"+r,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"+r+" = errors; ";var w=m,R=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=R,n+=" if (!"+h+") { for (var "+b+"=startErrs"+r+"; "+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"+r+"; ",B){u||(n+=" var "+d+" = validate.schema"+a+"; ");var v="i"+r,w="schema"+r+"["+v+"]",R="' + "+w+" + '";g.opts._errorDataPathProperty&&(g.errorPath=g.util.getPathExpr(Z,w,g.opts.jsonPointers)),n+=" var "+c+" = true; ",u&&(n+=" if (schema"+r+" === undefined) "+c+" = true; else if (!Array.isArray(schema"+r+")) "+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: '"+R+"' } ",g.opts.messages!==!1&&(n+=" , message: '",g.opts._errorDataPathProperty?n+="is a required property":n+="should have required property \\'"+R+"\\'",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 V,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},zqt={$ref:vqt,allOf:Bqt,anyOf:Sqt,$comment:wqt,const:Rqt,contains:Vqt,dependencies:Wqt,enum:Xqt,format:Hqt,if:Tqt,items:Nqt,maximum:zse,minimum:zse,maxItems:Pse,minItems:Pse,maxLength:Jse,minLength:Jse,maxProperties:Ose,minProperties:Ose,multipleOf:kqt,not:Yqt,oneOf:Kqt,pattern:Fqt,properties:Dqt,propertyNames:xqt,required:Eqt,uniqueItems:Mqt,validate:TXe},_se=zqt,Bx=uy.toHash,Pqt=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=Bx(i),g.types=Bx(n),g.forEach(function(r){r.rules=r.rules.map(function(C){var o;if(typeof C=="object"){var a=Object.keys(C)[0];o=C[a],C=a,o.forEach(function(A){i.push(A),g.all[A]=!0})}i.push(C);var s=g.all[C]={keyword:C,code:_se[C],implements:o};return s}),g.all.$comment={keyword:"$comment",code:_se.$comment},r.type&&(g.types[r.type]=r)}),g.keywords=Bx(i.concat(I)),g.custom={},g},Lse=["multipleOf","maximum","exclusiveMaximum","minimum","exclusiveMinimum","maxLength","minLength","pattern","additionalItems","maxItems","minItems","uniqueItems","maxProperties","minProperties","required","additionalProperties","enum","format","const"],Jqt=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 ZH(e){return ZH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},ZH(e)}let I2e=function(e){Ctg(i,e);var g=otg(i);function i(I){var n;return itg(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(xl(n)),n.handleKeyDownBound=n.handleKeyDown.bind(xl(n)),n.handleKeyUpBound=n.handleKeyUp.bind(xl(n)),n.handleSubmitBound=n.handleSubmit.bind(xl(n)),n.hideBound=n.hide.bind(xl(n)),n.showBound=n.show.bind(xl(n)),n.toggleLogBound=n.toggleLog.bind(xl(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 Itg(i,[{key:"componentDidMount",value:async function(){this.editor&&(this.editor._input.focus(),this.editor._input.setSelectionRange(0,0),await UQ(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 r=this.getLogMsgs(n);this.setState({code:n,logMsgs:r})}},{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 r=[];let C;try{C=JSON.parse(n)}catch(s){return console.warn(s),r.push({type:"Error",msg:s.toString()}),r}const o=new g2e().compile(i2e);return o(C)||(console.warn("Invalid viewconf"),r.push({type:"Warning",msg:"Invalid viewconf"})),o.errors&&(console.warn(JSON.stringify(o.errors,null,2)),o.errors.forEach(s=>{r.push({type:"Warning",msg:JSON.stringify(s,null,2)})})),r.length===0&&r.push({type:"Success",msg:"No error or warnings"}),r}},{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((r,C)=>{const o=`${C}-${r.msg}`;return N.createElement("tr",{key:o},N.createElement("td",{className:Xg(Fu.title,Fu[r.type])},`[${C}] ${r.type}`),N.createElement("td",null,N.createElement("pre",null,r.msg)))});return N.createElement(vw,{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:Fu["view-config-editor-header"]},N.createElement(Xs,{onBlur:this.showBound,onMouseDown:this.hideBound,onMouseOut:this.showBound,onMouseUp:this.showBound},"Hide While Mousedown"),N.createElement(Xs,{onClick:()=>{this.props.onChange(this.state.code)},shortcut:"⌘+S"},"Save")),N.createElement("div",{ref:r=>{this.editorWrap=r},className:Fu["view-config-editor"]},N.createElement(Z6t,{ref:r=>{this.editor=r},highlight:r=>Fse.highlight(r,Fse.languages.json),onValueChange:this.handleChangeBound,padding:10,style:{fontFamily:'"Fira code", "Fira Mono", monospace',fontSize:"inherit"},value:this.state.code})),N.createElement("div",{className:Fu["view-config-log"],style:{height:this.state.showLog?"50%":"30px"}},N.createElement("div",{className:Fu["view-config-log-header"],onClick:()=>this.toggleLogBound()},`Log Messages (${this.state.logMsgs.filter(r=>r.type!=="Success").length})`),N.createElement("div",{className:Fu["view-config-log-msg"],style:{padding:this.state.showLog?"10px":0}},N.createElement("table",null,N.createElement("tbody",null,n))))))}}]),i}(N.Component);I2e.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 stg=ty(Dk(I2e));function ltg(e,g,i,I){const n=e.append("symbol").attr("id",g).attr("viewBox",I);i.forEach(r=>n.append("path").attr("d",r).attr("fill","currentColor"))}const ctg=e=>{e.setState(e.state)},utg=function(g,i){const I=g;let n=[];const r=vN(),C=()=>{n.forEach(o=>i.unsubscribe(o)),n=[]};return{destroy:C,publish:r.publish,stack:r.stack,public:{get version(){return l9e},setBroadcastMousePositionGlobally(o=!1){I.setBroadcastMousePositionGlobally(o)},setShowGlobalMousePosition(o=!1){I.setShowGlobalMousePosition(o)},setGlobalMousePosition(o=!1){I.setBroadcastMousePositionGlobally(o),I.setShowGlobalMousePosition(o)},setAuthHeader(o){DB(o),I.reload()},getAuthHeader(){return DB()},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(){C(),ji.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 g2e().compile(i2e),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(EC);break;default:I.setMouseTool(pX);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),qQ(I,s,A)},option(o,a){if(typeof a>"u")return I.props.options[o];switch(o){case"sizeMode":I.props.options[o]=a,ctg(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":r.unsubscribe("click",A);break;case"cursorLocation":r.unsubscribe("cursorLocation",A);break;case"location":I.offLocationChange(s,a);break;case"mouseMoveZoom":r.unsubscribe("mouseMoveZoom",A);break;case"wheel":r.unsubscribe("wheel",A);break;case"rangeSelection":r.unsubscribe("rangeSelection",A);break;case"viewConfig":I.offViewChange(a);break;case"createSVG":I.offPostCreateSVG();break;case"geneSearch":r.unsubscribe("geneSearch",A);break}},on(o,a,s,A){switch(o){case"click":return r.subscribe("click",a);case"cursorLocation":return r.subscribe("cursorLocation",a);case"location":return I.onLocationChange(s,a,A);case"mouseMoveZoom":return r.subscribe("mouseMoveZoom",a);case"wheel":return r.subscribe("wheel",a);case"rangeSelection":return r.subscribe("rangeSelection",a);case"viewConfig":return I.onViewChange(a);case"createSVG":return I.onPostCreateSVG(a);case"geneSearch":return r.subscribe("geneSearch",a);default:return}}}}},dtg="_higlass_1uoq8_1",rf={higlass:dtg,"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 htg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function $se(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 GH(e){return GH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},GH(e)}const qse=12,vtg=12,Btg=20,Stg="default",ele="bounded",tle="overflow",GZ="scroll";let dy=function(e){btg(i,e);var g=ytg(i);function i(I){var n;htg(this,i),n=g.call(this,I),ive(N.version)<15.6&&console.warn("HiGlass requires React v15.6 or higher. Current version: ",N.version),n.pubSub=vN(),n.domEvent=xGe(n.pubSub),n.pubSubs=[],n.minHorizontalHeight=20,n.minVerticalWidth=20,n.resizeSensor=null,n.uid=sg.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={},ot.PIXI=I.options&&I.options.PIXI||Gpe,n.viewMarginTop=+I.options.viewMarginTop>=0?+I.options.viewMarginTop:PZ,n.viewMarginBottom=+I.options.viewMarginBottom>=0?+I.options.viewMarginBottom:PZ,n.viewMarginLeft=+I.options.viewMarginLeft>=0?+I.options.viewMarginLeft:PZ,n.viewMarginRight=+I.options.viewMarginRight>=0?+I.options.viewMarginRight:PZ,n.viewPaddingTop=+I.options.viewPaddingTop>=0?+I.options.viewPaddingTop:JZ,n.viewPaddingBottom=+I.options.viewPaddingBottom>=0?+I.options.viewPaddingBottom:JZ,n.viewPaddingLeft=+I.options.viewPaddingLeft>=0?+I.options.viewPaddingLeft:JZ,n.viewPaddingRight=+I.options.viewPaddingRight>=0?+I.options.viewPaddingRight:JZ,n.genomePositionSearchBox=null,n.viewHeaders={},n.boundRefreshView=()=>{n.refreshView(OZ)},n.unsetOnLocationChange=[],n.setTheme(I.options.theme,I.options.isDarkTheme),n.viewconfLoaded=!1;const{viewConfig:r}=n.props,C=n.loadIfRemoteViewConfig(n.props.viewConfig);I.options.authToken&&DB(I.options.authToken),n.pixiRoot=new ot.PIXI.Container,n.pixiRoot.interactive=!0,n.pixiStage=new ot.PIXI.Container,n.pixiStage.interactive=!0,n.pixiRoot.addChild(n.pixiStage),n.pixiMask=new ot.PIXI.Graphics,n.pixiRoot.addChild(n.pixiMask),n.pixiStage.mask=n.pixiMask,n.element=null,n.scrollTop=0;let o=pX;if(n.props.options)switch(n.props.options.mouseTool){case EC:o=EC;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:C,viewConfig:r,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}=utg(ei(n),n.pubSub);return n.api=l,n.apiDestroy=c,n.apiPublish=u,n.apiStack=d,n.viewChangeListener=[],n.triggerViewChangeDb=DQ(n.triggerViewChange.bind(ei(n)),250),n.pubSubs=[],n.rangeSelection=[null,null],n.prevMouseHoverTrack=null,n.zooming=!1,n.appClickHandlerBound=n.appClickHandler.bind(ei(n)),n.canvasClickHandlerBound=n.canvasClickHandler.bind(ei(n)),n.keyDownHandlerBound=n.keyDownHandler.bind(ei(n)),n.keyUpHandlerBound=n.keyUpHandler.bind(ei(n)),n.resizeHandlerBound=n.resizeHandler.bind(ei(n)),n.resizeHandlerBound=n.resizeHandler.bind(ei(n)),n.dispatchEventBound=n.dispatchEvent.bind(ei(n)),n.animateOnMouseMoveHandlerBound=n.animateOnMouseMoveHandler.bind(ei(n)),n.zoomStartHandlerBound=n.zoomStartHandler.bind(ei(n)),n.zoomEndHandlerBound=n.zoomEndHandler.bind(ei(n)),n.zoomHandlerBound=n.zoomHandler.bind(ei(n)),n.trackDroppedHandlerBound=n.trackDroppedHandler.bind(ei(n)),n.trackDimensionsModifiedHandlerBound=n.trackDimensionsModifiedHandler.bind(ei(n)),n.animateBound=n.animate.bind(ei(n)),n.animateOnGlobalEventBound=n.animateOnGlobalEvent.bind(ei(n)),n.requestReceivedHandlerBound=n.requestReceivedHandler.bind(ei(n)),n.wheelHandlerBound=n.wheelHandler.bind(ei(n)),n.mouseMoveHandlerBound=n.mouseMoveHandler.bind(ei(n)),n.onMouseLeaveHandlerBound=n.onMouseLeaveHandler.bind(ei(n)),n.onBlurHandlerBound=n.onBlurHandler.bind(ei(n)),n.openModalBound=n.openModal.bind(ei(n)),n.closeModalBound=n.closeModal.bind(ei(n)),n.handleEditViewConfigBound=n.handleEditViewConfig.bind(ei(n)),n.onScrollHandlerBound=n.onScrollHandler.bind(ei(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 mtg(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":Stg: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=zG.subscribe("higlass.mouseMove",this.animateOnGlobalEventBound),this.pubSubs.push(this.globalMousePositionListener)),this.isShowGlobalMousePosition&&!this.globalMousePositionListener){const r=this.pubSubs.findIndex(C=>C===this.globalMousePositionListener);zG.unsubscribe(this.globalMousePositionListener),r>=0&&this.pubSubs.splice(r,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 r=ji.findDOMNode(this);document.body.contains(r)?n():requestAnimationFrame(()=>this.waitForDOMAttachment(n))}},{key:"componentDidMount",value:function(){this.mounted=!0,this.element=ji.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},r=parseInt(Rfe[0],10);r===4?(console.warn("Deprecation warning: please update Pixi.js to version 5 or above!"),this.props.options.renderer==="canvas"?this.pixiRenderer=new ot.PIXI.CanvasRenderer(n):this.pixiRenderer=new ot.PIXI.WebGLRenderer(n)):(r<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 ot.PIXI.CanvasRenderer(n):this.pixiRenderer=new ot.PIXI.Renderer(n)),this.fitPixiToParentContainer(),this.setState({svgElement:this.svgElement,canvasElement:this.canvasElement}),this.waitForDOMAttachment(()=>{cX.ElementQueries.listen(),this.resizeSensor=new cX.ResizeSensor(this.element.parentNode,this.updateAfterResize.bind(this)),this.updateAfterResize()}),this.handleDragStart(),this.handleDragStop(),this.animate();const C=dg(this.element).append("svg").style("display","none");yst.forEach(o=>ltg(C,o.id,o.paths,o.viewBox))}},{key:"getTrackObject",value:function(n,r){return this.tiledPlots[n].trackRenderer.getTrackObject(r)}},{key:"getTrackRenderer",value:function(n){return this.tiledPlots[n].trackRenderer}},{key:"loadIfRemoteViewConfig",value:function(n){let r={};return typeof n=="string"?vt.json(n,(C,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):(r=this.processViewConfig(JSON.parse(JSON.stringify(n))),this.mounted&&this.setState({viewConfig:n})),r}},{key:"UNSAFE_componentWillReceiveProps",value:function(n){const r=this.loadIfRemoteViewConfig(n.viewConfig);if(n.options.authToken!==this.prevAuthToken){DB(n.options.authToken);for(const C of this.iterateOverViews()){const o=this.getTrackRenderer(C),a=JSON.parse(o.prevTrackDefinitions);o.syncTrackObjects([]),o.syncTrackObjects(a)}this.prevAuthToken=n.options.authToken}for(const C of Eg(r))this.adjustLayoutToTrackSizes(C);this.setState({views:r})}},{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,r=this.props.options.isDarkTheme){if(typeof r<"u")console.warn("The option `isDarkTheme` is deprecated. Please use `theme` instead."),this.theme=r?"dark":"light";else switch(n){case"dark":this.theme=gi;break;case"light":case void 0:this.theme=yX;break;default:console.warn(`Unknown theme "${n}". Using light theme.`),this.theme=yX;break}}},{key:"dispatchEvent",value:function(n){this.canvasElement&&vX(n,this.canvasElement)}},{key:"trackDroppedHandler",value:function(){this.setState({draggingHappening:null})}},{key:"requestReceivedHandler",value:function(){!this.viewconfLoaded&&FB===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,r=this.element.parentNode.clientHeight;this.pixiMask.beginFill(16777215).drawRect(0,0,n,r).endFill(),this.pixiRenderer.resize(n,r),this.pixiRenderer.view.style.width=`${n}px`,this.pixiRenderer.view.style.height=`${r}px`,this.pixiRenderer.render(this.pixiRoot)}},{key:"addDefaultTrackOptions",value:function(n){const r=this.getTrackInfo(n.type);if(!r)return;typeof n.options>"u"&&(n.options={});const C=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(r.defaultOptions){const o=r.defaultOptionsByTheme&&r.defaultOptionsByTheme[this.theme]?r.defaultOptionsByTheme[this.theme]:{},a={...r.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=C}},{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 r=750;this.typedTextTimeout&&clearTimeout(this.typedTextTimeout),this.typedTextTimeout=setTimeout(()=>{this.typedText=""},r)}},{key:"keyDownHandler",value:function(n){this.typedTextHandler(n),this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:EC})}},{key:"keyUpHandler",value:function(n){this.props.options.rangeSelectionOnAlt&&n.key==="Alt"&&this.setState({mouseTool:pX})}},{key:"openModal",value:function(n){this.setState({modal:N.cloneElement(n,{ref:r=>{this.modalRef=r}})})}},{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(stg,{onCancel:()=>{const{viewConfigTmp:r}=this.state,C=this.processViewConfig(r);for(const o of Eg(C))this.adjustLayoutToTrackSizes(o);this.setState({views:C,viewConfig:r,viewConfigTmp:null})},onChange:r=>{const C=JSON.parse(r),o=this.processViewConfig(C);for(const a of Eg(o))this.adjustLayoutToTrackSizes(a);this.setState({views:o,viewConfig:C})},onSave:r=>{const C=JSON.parse(r),o=this.processViewConfig(C);for(const a of Eg(o))this.adjustLayoutToTrackSizes(a);this.setState({views:o,viewConfig:C,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,r]=PGe(this.element);n>0&&r>0&&this.setState({sizeMeasured:!0,width:n,height:r})}},{key:"updateAfterResize",value:function(){this.measureSize(),this.updateRowHeight(),this.fitPixiToParentContainer(),this.refreshView(OZ),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:r=>this.handleLocationLockChosen(n,r),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 r in Object.keys(this.state.views))n.push(r);return n}},{key:"iterateOverTracksInView",value:function(n){const r=[],{tracks:C}=this.state.views[n];for(const o in C)for(const a of C[o])if(a.type==="combined"&&a.contents)for(const s of a.contents)r.push({viewId:n,trackId:s.uid,track:s});else r.push({viewId:n,trackId:a.uid,track:a});return r}},{key:"iterateOverTracks",value:function(){const n=[];for(const r in this.state.views){const{tracks:C}=this.state.views[r];for(const o in C)for(const a of C[o])if(a.type==="combined"&&a.contents)for(const s of a.contents)n.push({viewId:r,trackId:s.uid,track:s});else n.push({viewId:r,trackId:a.uid,track:a})}return n}},{key:"setMouseTool",value:function(n){this.setState({mouseTool:n})}},{key:"isValueScaleLocked",value:function(n,r){const C=this.combineViewAndTrackUid(n,r);return this.state.views[n]?!!this.valueScaleLocks[C]:!1}},{key:"getLockGroupExtrema",value:function(n,r){const C=this.combineViewAndTrackUid(n,r);if(!this.state.views[n]||!this.valueScaleLocks[C])return null;const o=this.valueScaleLocks[C],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,r){const C=this.combineViewAndTrackUid(n,r);if(!this.state.views[n])return;const o=gC(this.state.views[n].tracks,r);if(this.valueScaleLocks[C]){const a=this.valueScaleLocks[C],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,r);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,r){this.animate()}},{key:"notifyDragChangedListeners",value:function(n){Eg(this.draggingChangedListeners).forEach(r=>{Eg(r).forEach(C=>C(n))})}},{key:"addDraggingChangedListener",value:function(n,r,C){this.draggingChangedListeners.hasOwnProperty(n)||(this.draggingChangedListeners[n]={}),this.draggingChangedListeners[n][r]=C,C(!0),C(!1)}},{key:"removeDraggingChangedListener",value:function(n,r){if(this.draggingChangedListeners.hasOwnProperty(n)){const C=this.draggingChangedListeners[n];C.hasOwnProperty(r)&&(C[r](!1),delete C[r])}}},{key:"addScalesChangedListener",value:function(n,r,C){this.scalesChangedListeners[n]||(this.scalesChangedListeners[n]={}),this.scalesChangedListeners[n][r]=C,!(!this.xScales[n]||!this.yScales[n])&&C(this.xScales[n],this.yScales[n])}},{key:"removeScalesChangedListener",value:function(n,r){if(this.scalesChangedListeners[n]){const C=this.scalesChangedListeners[n];C[r]&&delete C[r]}}},{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 r of Eg(this.tiledPlots))if(r){for(const C of Eg(r.trackRenderer.trackDefObjects))if(C.trackObject.exportSVG){const o=C.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 r=Tot.xml(new window.XMLSerializer().serializeToString(n));return r=r.replace(/ -${C}`}},{key:"handleExportSVG",value:function(){PG("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=>{PG("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&&Eg(this.scalesChangedListeners[n]).forEach(a=>{a(C,r)}),this.zoomLocks[n]){const a=this.zoomLocks[n],s=Tr(a),[A,l,c]=Si(this.xScales[n],this.yScales[n]);for(let u=0;u{G(Z,B)})}}if(this.locationLocks[n]){const a=this.locationLocks[n],s=Tr(a),[A,l,c]=Si(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=Tr(a),A=this.locationLocksAxisWise.x[n].axis!=="x",[l,c,u]=Si(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=Tr(a),A=this.locationLocksAxisWise.y[n].axis!=="y",[l,c,u]=Si(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=Rr(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):Si(this.xScales[n],this.yScales[n])}},{key:"addLock",value:function(n,C,r,o){let a=[],s=[];r[n]?a=Tr(r[n]).filter(c=>o(c[0])).map(c=>[c[0],o(c[0])]):a=[[n,o.bind(this)(n)]],r[C]?s=Tr(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=VGe(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=Ir(this.state.views[C].tracks,r),s=JG(this.state.views[C].tracks,r);o=sg.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]=Si(a,s),[u,d,h]=Si(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]=Si(a,s),[u,d,h]=Si(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!==Lse||this.props.options.pixelPreciseMarginPadding)return;const n=this.element.parentNode.clientHeight;let C=0;for(const l of Eg(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(JZ))}},{key:"clearDragTimeout",value:function(){this.dragTimeout&&(clearTimeout(this.dragTimeout),this.dragTimeout=null)}},{key:"getTrackInfo",value:function(n){if(Qg[n])return Qg[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=mGe){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)},JZ)}},{key:"resizeHandler",value:function(){wN(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&&Eg(n.tracks.top).length>1||n.tracks.bottom&&Eg(n.tracks.bottom).length>1)&&(n.tracks.left&&Eg(n.tracks.left).length||n.tracks.right&&Eg(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:_se,h:mtg},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){Eg(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:sg.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=Ir(o.tracks,C),s=a.uid;a.uid=sg.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=Ir(o.tracks,C);a.uid=sg.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=sg.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(Is(s,()=>A++),r==="left"||r==="top")s[r].unshift(C);else if(r==="center")if(s.center.length===0){const l={uid:sg.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:sg.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){Is(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+=ftg);const{totalHeight:o}=this.calculateViewDimensions(n);r+=o;const a=this.isEditable()?10:0;r+=a;const s=this.state.rowHeight+a;this.sizeMode!==Lse&&(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=Rr(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=Rr(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=Rr(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=tg().domain(a).range(this.xScales[o].range()),l=tg().domain(s).range(this.yScales[o].range()),[c,u,d]=Si(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 Rr(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 Rr(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 Rr(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 Rr(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 Rr(n)){let a=n[o]&&n[o].uid;a||(a=sg.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 Is(r.tracks,o=>{if(o.server){const a=Fot(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();PG("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(S$,{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]=tg().domain(C),this.yScales[n]=tg().domain(r),this.zoomLocks[n]){const a=this.zoomLocks[n],s=Tr(a);for(let A=0;A_se)return!1;const A=Eg(this.state.views);for(let l=0;lc&&Cu)return!1}return!0}},{key:"handleAddView",value:function(n){const C=Eg(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=sg.nice(),s.layout.i=s.uid,Is(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:rz,chromInfoServer:rz,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={};Is(C.tracks,s=>{s.coordSystem&&(r[s.coordSystem]||(r[s.coordSystem]=0),r[s.coordSystem]+=1)});const o=Tr(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=Ir(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(Rr(n));for(const r of Eg(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&&RGe(o.tracks),o.uid||(o.uid=sg.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]=tg().domain(o.initialXDomain)),this.yScales[o.uid]||(this.yScales[o.uid]=tg().domain(o.initialYDomain)),Is(o.tracks,a=>{if(a.uid||(a.uid=sg.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 KQ.get(this.state.views[n].chromInfoPath).then(C=>QGe(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 +${r}`}},{key:"handleExportSVG",value:function(){PG("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 r=this.createSVGString(),C=new Image(this.canvasElement.width,this.canvasElement.height);C.src=`data:image/svg+xml;base64,${btoa(r)}`,C.onload=()=>{const o=document.createElement("canvas");o.width=this.canvasElement.width/2,o.height=this.canvasElement.height/2,o.getContext("2d").drawImage(C,0,0),o.toBlob(a=>{n(a)})}})}},{key:"handleExportPNG",value:function(){this.createPNGBlobPromise().then(n=>{PG("export.png",n)})}},{key:"handleScalesChanged",value:function(n,r,C,o=!0){if(this.xScales[n]=r,this.yScales[n]=C,o&&n in this.scalesChangedListeners&&Eg(this.scalesChangedListeners[n]).forEach(a=>{a(r,C)}),this.zoomLocks[n]){const a=this.zoomLocks[n],s=HC(a),[A,l,c]=SI(this.xScales[n],this.yScales[n]);for(let u=0;u{G(Z,B)})}}if(this.locationLocks[n]){const a=this.locationLocks[n],s=HC(a),[A,l,c]=SI(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=HC(a),A=this.locationLocksAxisWise.x[n].axis!=="x",[l,c,u]=SI(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=HC(a),A=this.locationLocksAxisWise.y[n].axis!=="y",[l,c,u]=SI(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:(r,C)=>this.handleViewportProjected(n,r,C)})}},{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(r=>r.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(r=>r.resetViewport())}},{key:"handleYankFunction",value:function(n,r){this.setState({chooseViewHandler:C=>r(n,C),mouseOverOverlayUid:n})}},{key:"handleUnlock",value:function(n,r){const C=r[n],o=RC(C);if(o.length===2){delete r[o[0]],delete r[o[1]];return}r[n]&&r[n][n]&&delete r[n][n],r[n]&&delete r[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):SI(this.xScales[n],this.yScales[n])}},{key:"addLock",value:function(n,r,C,o){let a=[],s=[];C[n]?a=HC(C[n]).filter(c=>o(c[0])).map(c=>[c[0],o(c[0])]):a=[[n,o.bind(this)(n)]],C[r]?s=HC(C[r]).filter(c=>o.bind(this)(c[0])).map(c=>[c[0],o.bind(this)(c[0])]):s=[[r,o.bind(this)(r)]];const A=a.concat(s),l=YGe(A);A.forEach(c=>{C[c[0]]=l})}},{key:"handleLocationLockChosen",value:function(n,r){if(n===r){this.setState({chooseViewHandler:null});return}this.addLock(n,r,this.locationLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleZoomLockChosen",value:function(n,r){if(n===r){this.setState({chooseViewHandler:null});return}this.addLock(n,r,this.zoomLocks,this.viewScalesLockData.bind(this)),this.setState({chooseViewHandler:null})}},{key:"handleViewportProjected",value:function(n,r,C){let o=null;if(n===r)console.warn("A view can not show its own viewport.");else{const a=gC(this.state.views[r].tracks,C),s=JG(this.state.views[r].tracks,C);o=sg.nice();const l={uid:o,type:`viewport-projection-${{top:"horizontal",bottom:"horizontal",center:"center",left:"vertical",right:"vertical"}[s]}`,fromViewUid:n};this.addCallbacks(r,l),this.handleTrackAdded(r,l,s,a)}return this.setState({chooseTrackHandler:null}),o}},{key:"handleLocationYanked",value:function(n,r){const C=this.xScales[r],o=this.yScales[r],a=this.xScales[n],s=this.yScales[n],[A,l,c]=SI(a,s),[u,d,h]=SI(C,o);this.setCenters[n](u,d,c,!0),this.setState({chooseViewHandler:null})}},{key:"handleZoomYanked",value:function(n,r){const C=this.xScales[r],o=this.yScales[r],a=this.xScales[n],s=this.yScales[n],[A,l,c]=SI(a,s),[u,d,h]=SI(C,o);this.setCenters[n](A,l,h,!0),this.setState({chooseViewHandler:null})}},{key:"handleTrackPositionChosen",value:function(n,r){this.setState({addTrackPosition:r,addTrackPositionView:n})}},{key:"updateRowHeight",value:function(){if(!this.props.options||this.sizeMode!==ele||this.props.options.pixelPreciseMarginPadding)return;const n=this.element.parentNode.clientHeight;let r=0;for(const l of Eg(this.state.views))r=Math.max(r,l.layout.y+l.layout.h);this.handleDragStart(),this.handleDragStop();const o=(this.isEditable()?10:0)*r-1,s=(n-o)/r,A=Math.floor(s);this.setState({rowHeight:A})}},{key:"handleLayoutChange",value:function(n){this.element&&(n.forEach(r=>{const C=this.state.views[r.i];C&&(C.layout.x=r.x,C.layout.y=r.y,C.layout.w=r.w,C.layout.h=r.h,C.layout.i=r.i)}),this.updateRowHeight(),this.refreshView(OZ))}},{key:"clearDragTimeout",value:function(){this.dragTimeout&&(clearTimeout(this.dragTimeout),this.dragTimeout=null)}},{key:"getTrackInfo",value:function(n){if(Qg[n])return Qg[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=BGe){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)},OZ)}},{key:"resizeHandler",value:function(){WN(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&&Eg(n.tracks.top).length>1||n.tracks.bottom&&Eg(n.tracks.bottom).length>1)&&(n.tracks.left&&Eg(n.tracks.left).length||n.tracks.right&&Eg(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,r){const C=[0,1/0],o=n.zoomLimits||[1,null],a=r[1]-r[0];if(o.length!==2)return C;if(o[0]!==null&&o[0]>0){const s=a/o[0];C[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];C[0]=Math.min(s,1),s>1&&console.warn(`Invalid zoom limits. Upper limit set to ${a}`)}return C}},{key:"generateViewLayout",value:function(n){let r=null;return"layout"in n?{layout:r}=n.layout:r={x:0,y:0,w:qse,h:vtg},r}},{key:"handleClearView",value:function(n){const{views:r}=this.state;r[n].tracks.top=[],r[n].tracks.bottom=[],r[n].tracks.center=[],r[n].tracks.left=[],r[n].tracks.right=[],r[n].tracks.whole=[],this.setState({views:r})}},{key:"handleCloseView",value:function(n){Eg(this.state.views).length!==1&&(this.handleUnlock(n,this.zoomLocks),this.setState(r=>(delete r.views[n],{views:this.removeInvalidTracks(r.views)})))}},{key:"handleSeriesAdded",value:function(n,r,C,o){const{tracks:a}=this.state.views[n];if(o.type==="combined")o.contents.push(r),r.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(r,o);else{const s={type:"combined",uid:sg.nice(),height:o.height,width:o.width,contents:[o,r]},A=a[C];for(let l=0;l({views:s.views}))}},{key:"handleNoTrackAdded",value:function(){this.state.addTrackPosition&&this.setState({addTrackPosition:null})}},{key:"handleTracksAdded",value:function(n,r,C,o){this.storeTrackSizes(n);for(const a of r)this.handleTrackAdded(n,a,C,o)}},{key:"handleChangeTrackType",value:function(n,r,C){const o=this.state.views[n],a=gC(o.tracks,r),s=a.uid;a.uid=sg.nice(),a.type=C;const A=a.uid;this.updateTrackLocks(n,s,A),this.setState(l=>({views:l.views}))}},{key:"handleChangeTrackData",value:function(n,r,C){const o=this.state.views[n],a=gC(o.tracks,r);a.uid=sg.nice(),a.data=C,this.setState(s=>({views:s.views}))}},{key:"handleTrackAdded",value:function(n,r,C,o=null){if(this.addDefaultTrackOptions(r),r.uid||(r.uid=sg.nice()),r.contents)for(const l of r.contents)this.addDefaultTrackOptions(l);if(this.state.addTrackPosition&&this.setState({addTrackPosition:null}),o)return this.handleSeriesAdded(n,r,C,o),null;r.position=C;const a=this.getTrackInfo(r.type);r.width=a.defaultWidth||a.defaultOptions&&a.defaultOptions.minWidth||this.minVerticalWidth,r.height=a.defaultHeight||a.defaultOptions&&a.defaultOptions.minHeight||this.minHorizontalHeight;const{tracks:s}=this.state.views[n];let A=0;if(is(s,()=>A++),C==="left"||C==="top")s[C].unshift(r);else if(C==="center")if(s.center.length===0){const l={uid:sg.nice(),type:"combined",contents:[r]};s.center=[l]}else if(s.center[0].type==="combined")s.center[0].contents.push(r),r.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(r,s.center[0]);else{const l={uid:sg.nice(),type:"combined",contents:[s.center[0],r]};s.center=[l],r.type==="heatmap"&&this.compatibilityfyStackedHeatmaps(r,l)}else s[C]||(s[C]=[]),s[C].push(r);return this.adjustLayoutToTrackSizes(this.state.views[n]),Object.keys(this.state.views).length===1&&A===0&&(this.handleZoomToData(n),this.zoomToDataExtentOnInit.add(n)),r}},{key:"compatibilityfyStackedHeatmaps",value:function(n,r){let C;r.contents.some(a=>(C=a,a.type==="heatmap"))&&(n.options.backgroundColor="transparent",n.options.showTooltip=C.options.showTooltip,n.options.showMousePosition=C.options.showMousePosition,n.options.mousePositionColor=C.options.mousePositionColor)}},{key:"storeTrackSizes",value:function(n){is(this.state.views[n].tracks,r=>{const C=this.tiledPlots[n].trackRenderer.getTrackObject(r.uid);C&&([r.width,r.height]=C.dimensions)})}},{key:"adjustLayoutToTrackSizes",value:function(n){if(!n.layout)return;const r=this.isEditable();let C=0;r&&(C+=Btg);const{totalHeight:o}=this.calculateViewDimensions(n);C+=o;const a=this.isEditable()?10:0;C+=a;const s=this.state.rowHeight+a;this.sizeMode!==ele&&(n.layout.h=Math.ceil(C/s))}},{key:"handleCloseTrack",value:function(n,r){const{tracks:C}=this.state.views[n];this.handleUnlockValueScale(n,r);for(const o in C){const a=C[o],s=a.filter(A=>A.uid!==r);s.length===a.length?s.filter(l=>l.type==="combined").forEach(l=>{l.contents=l.contents.filter(c=>c.uid!==r)}):C[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,r){this.setState({chooseTrackHandler:(C,o)=>this.handleValueScaleLocked(n,r,C,o)})}},{key:"combineViewAndTrackUid",value:function(n,r){const C=`${n}.${r}`;if(this.combinedUidToViewTrack[C]={view:n,track:r},this.viewTrackUidsToCombinedUid[n]){if(this.viewTrackUidsToCombinedUid[r])return this.viewTrackUidsToCombinedUid[n][r];this.viewTrackUidsToCombinedUid[n][r]=C}else this.viewTrackUidsToCombinedUid[n]={},this.viewTrackUidsToCombinedUid[n][r]=C;return C}},{key:"updateTrackLocks",value:function(n,r,C){const o=this.combineViewAndTrackUid(n,r),a=this.combineViewAndTrackUid(n,C);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=C,delete this.valueScaleLocks[s][o]}}},{key:"handleUnlockValueScale",value:function(n,r){if(this.tiledPlots[n].trackRenderer.getTrackObject(r).createdTracks){const C=RC(this.tiledPlots[n].trackRenderer.getTrackObject(r).createdTracks);for(const o of C)this.handleUnlock(this.combineViewAndTrackUid(n,o),this.valueScaleLocks)}else this.handleUnlock(this.combineViewAndTrackUid(n,r),this.valueScaleLocks)}},{key:"handleValueScaleLocked",value:function(n,r,C,o){if(this.tiledPlots[n].trackRenderer.getTrackObject(r).createdTracks){const A=RC(this.tiledPlots[n].trackRenderer.getTrackObject(r).createdTracks);for(const l of A)this.handleValueScaleLocked(n,l,C,o);return}if(this.tiledPlots[C].trackRenderer.getTrackObject(o).createdTracks){const A=RC(this.tiledPlots[C].trackRenderer.getTrackObject(o).createdTracks);for(const l of A)this.handleValueScaleLocked(n,r,C,l);return}const a=this.combineViewAndTrackUid(n,r),s=this.combineViewAndTrackUid(C,o);this.addLock(a,s,this.valueScaleLocks,A=>this.combinedUidToViewTrack[A]),this.syncValueScales(n,r),this.setState({chooseTrackHandler:null})}},{key:"addCallbacks",value:function(n,r){const C=this.getTrackInfo(r.type);if(r.type==="viewport-projection-center"||r.type==="viewport-projection-horizontal"||r.type==="viewport-projection-vertical"||C&&C.projection){const o=r.fromViewUid;r.registerViewportChanged=(a,s)=>this.addScalesChangedListener(o,a,s),r.removeViewportChanged=a=>this.removeScalesChangedListener(o,a),r.setDomainsCallback=(a,s)=>{if(!o){this.projectionXDomains[n]||(this.projectionXDomains[n]={}),this.projectionYDomains[n]||(this.projectionYDomains[n]={}),(r.type==="viewport-projection-horizontal"||r.type==="viewport-projection-center")&&(this.projectionXDomains[n][r.uid]=a),(r.type==="viewport-projection-vertical"||r.type==="viewport-projection-center")&&(this.projectionYDomains[n][r.uid]=s),this.triggerViewChangeDb();return}const A=tg().domain(a).range(this.xScales[o].range()),l=tg().domain(s).range(this.yScales[o].range()),[c,u,d]=SI(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 r=[];for(const C of RC(n))(!n[C]||!n[C][C])&&r.push(C);for(const C of r)n[C]&&(console.warn(`View ${C} not present in lock group. Removing...`),this.handleUnlock(C,n),delete n[C])}},{key:"deserializeLocationLocks",value:function(n){if(this.locationLocks={},n.locationLocks)for(const r of RC(n.locationLocks.locksByViewUid))if(typeof n.locationLocks.locksByViewUid[r]!="object")this.locationLocks[r]=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[r]];else{if("x"in n.locationLocks.locksByViewUid[r]){const C=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[r].x.lock];this.locationLocksAxisWise.x[r]={lock:C,axis:n.locationLocks.locksByViewUid[r].x.axis}}if("y"in n.locationLocks.locksByViewUid[r]){const C=n.locationLocks.locksDict[n.locationLocks.locksByViewUid[r].y.lock];this.locationLocksAxisWise.y[r]={lock:C,axis:n.locationLocks.locksByViewUid[r].y.axis}}}this.validateLocks(this.locationLocks)}},{key:"deserializeZoomLocks",value:function(n){if(this.zoomLocks={},n.zoomLocks)for(const r of RC(n.zoomLocks.locksByViewUid))this.zoomLocks[r]=n.zoomLocks.locksDict[n.zoomLocks.locksByViewUid[r]];this.validateLocks(this.zoomLocks)}},{key:"deserializeValueScaleLocks",value:function(n){if(this.valueScaleLocks={},n.valueScaleLocks)for(const r of RC(n.valueScaleLocks.locksByViewUid))this.valueScaleLocks[r]=n.valueScaleLocks.locksDict[n.valueScaleLocks.locksByViewUid[r]]}},{key:"serializeLocks",value:function(n){const r={},C={};for(const o of RC(n)){let a=n[o]&&n[o].uid;a||(a=sg.nice()),n[o].uid=a,r[a]=n[o],C[o]=n[o].uid}return{locksByViewUid:C,locksDict:r}}},{key:"getViewsAsJson",value:function(){const n=JSON.parse(JSON.stringify(this.state.viewConfig));return n.views=Object.values(this.state.views).map(r=>{const C=JSON.parse(JSON.stringify(r));return is(C.tracks,o=>{if(o.server){const a=_ot(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[r.uid]&&this.projectionXDomains[r.uid][o.uid]&&(o.projectionXDomain=this.projectionXDomains[r.uid][o.uid]),(o.type==="viewport-projection-center"||o.type==="viewport-projection-vertical")&&this.projectionYDomains[r.uid]&&this.projectionYDomains[r.uid][o.uid]&&(o.projectionYDomain=this.projectionYDomains[r.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}),C.uid=r.uid,C.initialXDomain=this.xScales[r.uid].domain(),C.initialYDomain=this.yScales[r.uid].domain(),delete C.layout.i,C}),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();PG("viewconf.json",n)}},{key:"handleExportViewsAsLink",value:function(n=this.state.viewConfig.exportViewUrl,r=!1){const C=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:`${C.origin}/l/?d=${a.uid}`}));return r||o.then(a=>{this.openModal(N.createElement(H$,{onDone:()=>{this.closeModalBound()},url:a.url}))}).catch(a=>console.error("Exporting view config as link failed:",a)),o}},{key:"handleDataDomainChanged",value:function(n,r,C){const{views:o}=this.state;if(o[n].initialXDomain=r,o[n].initialYDomain=C,this.xScales[n]=tg().domain(r),this.yScales[n]=tg().domain(C),this.zoomLocks[n]){const a=this.zoomLocks[n],s=HC(a);for(let A=0;Aqse)return!1;const A=Eg(this.state.views);for(let l=0;lc&&ru)return!1}return!0}},{key:"handleAddView",value:function(n){const r=Eg(this.state.views),C=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(C),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=sg.nice(),s.layout.i=s.uid,is(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,r,C,o){const{views:a}=this.state;a[n].genomePositionSearchBox.chromInfoId=r,a[n].genomePositionSearchBox.autocompleteId=C,a[n].genomePositionSearchBox.autocompleteServer=o}},{key:"createGenomePostionSearchBoxEntry",value:function(n,r){let C=n;const o={autocompleteServer:lz,chromInfoServer:lz,visible:!1};return C||(C=JSON.parse(JSON.stringify(o))),C.autocompleteServer||(C.autocompleteServer=o.autocompleteServer),C.chromInfoId||(C.chromInfoId=r),C.chromInfoServer||(C.chromInfoServer=o.chromInfoServer),C.visible||(C.visible=!1),C}},{key:"handleTogglePositionSearchBox",value:function(n){const r=this.state.views[n];r.genomePositionSearchBoxVisible=!r.genomePositionSearchBoxVisible;const C={};is(r.tracks,s=>{s.coordSystem&&(C[s.coordSystem]||(C[s.coordSystem]=0),C[s.coordSystem]+=1)});const o=HC(C).sort((s,A)=>A[1]-s[1]);let a="hg19";o.length&&(a=o[0][0]),r.genomePositionSearchBox=this.createGenomePostionSearchBoxEntry(r.genomePositionSearchBox,a),r.genomePositionSearchBox.visible=!r.genomePositionSearchBox.visible,this.refreshView(),this.setState({configMenuUid:null})}},{key:"handleTrackOptionsChanged",value:function(n,r,C){const o=this.state.views[n],a=gC(o.tracks,r);a&&(a.options=Object.assign(a.options,C),this.mounted&&(this.setState(s=>({views:s.views})),this.adjustSplitHeatmapTrackOptions(a,C,o.tracks,n)))}},{key:"adjustSplitHeatmapTrackOptions",value:function(n,r,C,o){n.type==="heatmap"&&(r.extent==="upper-right"&&C.center[0].type==="combined"&&C.center[0].contents.length>1&&C.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={...r,labelPosition:"topRight",colorbarPosition:"topRight"};return this.handleTrackOptionsChanged(o,a.uid,s),this.handleTrackOptionsChanged(o,n.uid,A),!0}return!1}),r.extent==="lower-left"&&r.extent==="lower-left"&&C.center[0].type==="combined"&&C.center[0].contents.length>1&&C.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={...r,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,r){const C=this.state.views[n];C&&(C.options=Object.assign(C.options||{},r),this.mounted&&this.setState(o=>({views:o.views})))}},{key:"isTrackValid",value:function(n,r){return!(n.type==="viewport-projection-center"&&!r.has(n.fromViewUid))}},{key:"removeInvalidTracks",value:function(n){const r=new Set(RC(n));for(const C of Eg(n))for(const o of["left","top","center","right","bottom"])C.tracks&&C.tracks.hasOwnProperty(o)&&(C.tracks[o]=C.tracks[o].filter(a=>this.isTrackValid(a,r)),C.tracks[o].forEach(a=>{a.type==="combined"&&(a.contents=a.contents.filter(s=>this.isTrackValid(s,r)))}));return n}},{key:"processViewConfig",value:function(n){let{views:r}=n,C={};return(!n.views||n.views.length===0)&&(console.warn("No views provided in viewConfig"),r=[{editable:!0,tracks:{}}]),r.forEach(o=>{o.tracks&&KGe(o.tracks),o.uid||(o.uid=sg.nice()),C[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]=tg().domain(o.initialXDomain)),this.yScales[o.uid]||(this.yScales[o.uid]=tg().domain(o.initialYDomain)),is(o.tracks,a=>{if(a.uid||(a.uid=sg.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),C=this.removeInvalidTracks(C),C}},{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 zQ.get(this.state.views[n].chromInfoPath).then(r=>Ive(this.xScales[n],this.yScales[n],r))}},{key:"offLocationChange",value:function(n,r){this.removeScalesChangedListener(n,r)}},{key:"zoomTo",value:function(n,r,C,o,a,s){if(!(n in this.setCenters))throw Error(`Invalid viewUid. Current uuids: ${Object.keys(this.setCenters).join(",")}`);if(Number.isNaN(+r)||Number.isNaN(+C)){const u=[r,C].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]=Si(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;Js(this.state.views[n].chromInfoPath,u=>{const d=u.chrToAbs([A,l])-r,h=u.chrToAbs([A,c])+r,[m,f,b]=Si(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,jo,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(OZ)===0).map(l=>parseInt(l.slice(OZ.length+1),10)).reduce((l,c)=>Math.max(l,c),0)+1),this.addScalesChangedListener(a.uid,`${OZ}.${A}`,s),r&&r(`${OZ}.${A}`),A}},{key:"getTiledPlotAtPosition",value:function(n,C){let r;const o=Eg(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=zg(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,zG.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=_Z(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=dg("body").selectAll(".track-mouseover-menu").data(r);o.exit().remove(),o.enter().append("div").classed("track-mouseover-menu",!0).classed(rf["track-mouseover-menu"],!0),o=dg("body").selectAll(".track-mouseover-menu");const a=zg(n.origEvt,dg("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(){dg("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=zg(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=_Z(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=_Z(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===ZZ&&(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=_Z(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){Js(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===ZZ||n&&n.zoomFixed}},{key:"trackDimensionsModifiedHandler",value:function(n){const C=this.state.views[n.viewId];if(!C)return;const r=Ir(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===ZZ)return;const C=n.nativeEvent||n,r=n.target===this.canvasElement;if(!FGe(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=zg(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&&(y9(C,A.eventTracker),C.preventDefault())}}},{key:"render",value:function(){this.tiledAreasDivs={},this.tiledAreas=N.createElement("div",{className:rf["tiled-area"]}),this.mounted&&(this.tiledAreas=Eg(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(D$t,{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(v8t,{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(q8t,{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:rf["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()?uGe:0,r=this.isEditable()?dGe: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(yot,{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:Xg("higlass",{"higlass-dark-theme":this.theme===gI,"higlass-container-overflow":this.props.options.sizeMode===Use||this.props.options.sizeMode===ZZ}),onMouseLeave:this.onMouseLeaveHandlerBound,onMouseMove:this.mouseMoveHandlerBound},N.createElement(WWt,{value:this.pubSub},N.createElement(Izt,{value:this.modal},N.createElement(pWt,{value:this.theme},this.state.modal,N.createElement("canvas",{key:this.uid,ref:A=>{this.canvasElement=A},onClick:this.canvasClickHandlerBound,className:rf["higlass-canvas"]}),N.createElement("div",{ref:A=>{this.scrollContainer=A},className:Xg("higlass-scroll-container",{"higlass-scroll-container-overflow":this.props.options.sizeMode===Use,"higlass-scroll-container-scroll":this.props.options.sizeMode===ZZ}),onScroll:this.onScrollHandlerBound},N.createElement("div",{ref:A=>{this.divDrawingSurface=A},className:Xg("higlass-drawing-surface",rf["higlass-drawing-surface"])},s),N.createElement("svg",{ref:A=>{this.svgElement=A},className:rf["higlass-svg"],style:{position:"absolute",width:"100%",height:"100%",left:0,top:0,pointerEvents:"none"}}))))))}}]),I}(N.Component);uy.defaultProps={options:{},zoomFixed:!1,compactLayout:!0};uy.propTypes={getApi:L.func,options:L.object,viewConfig:L.oneOfType([L.string,L.object]).isRequired,zoomFixed:L.bool,compactLayout:L.bool};function btg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function Qse(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 yH(e){return yH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(I){return I.__proto__||Object.getPrototypeOf(I)},yH(e)}const Rtg=(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=Htg(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 Wtg=function(e){vtg(I,e);var g=Btg(I);function I(i){var n;return btg(this,I),n=g.call(this,i),n.id=`id-${Math.random()}`,n}return ytg(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}=Rtg(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);Wtg.propTypes={trackConfig:L.object,width:L.number,height:L.number,x:L.number,y:L.number};const Xtg=(e,g,I)=>{const i=N.createRef();return jI.render(N.createElement(uy,{ref:i,options:I||{},viewConfig:g}),e),i.current},Htg=(e,g,I)=>Xtg(e,g,I).api;var j9e={exports:{}};(function(e,g){(function(I,i){e.exports=i()})(typeof window<"u"?window:yI,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 F in K)K.hasOwnProperty(F)&&(R[K[F]]?this.element.setAttribute(K[F],R[K[F]].substr(1)):this.element.removeAttribute(K[F]))}}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: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[P].minWidth&&(J=P);if(J||(J=S),X!==J)if(W[J])v[X].style.display="none",v[J].style.display="block",X=J;else{var ge=new Image;ge.onload=function(){v[J].src=V[J],v[X].style.display="none",v[J].style.display="block",W[J]=!0,X=J},ge.src=V[J]}else v[J].src=V[J]}G.resizeSensorInstance=new I(G,F),F()}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?Ntg(e,g,{enumerable:!0,configurable:!0,writable:!0,value:I}):e[g]=I,rt=(e,g,I)=>(ktg(e,typeof g!="symbol"?g+"":g,I),I),K$=(e,g,I)=>{if(!g.has(e))throw TypeError("Cannot "+I)},Dt=(e,g,I)=>(K$(e,g,"read from private field"),I?I.call(e):g.get(e)),fg=(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)},WC=(e,g,I,i)=>(K$(e,g,"write to private field"),i?i.call(e,I):g.set(e,I),I),SI=(e,g,I)=>(K$(e,g,"access private method"),I),hG,CS,rS,Md,ZH,GH,_O,e2e,x$,t2e,vH,LO,UO,g2e,QO,I2e,jO,i2e,jA;const Ytg="#/definitions/GoslingSpec",Ktg="http://json-schema.org/draft-07/schema#",xtg={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 + coordinates).`].join(" "));return}(Number.isNaN(+o)||Number.isNaN(+a)||o===null||a===null)&&(o=r,a=C);const[A,l,c]=SI(this.xScales[n].copy().domain([r,C]),this.yScales[n].copy().domain([o,a]));this.setCenters[n](A,l,c,!1,s)}},{key:"zoomToGene",value:function(n,r,C,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,r,a=>{if(a){const s=a.find(A=>A.geneName.toLowerCase()===r.toLowerCase());if(s){const{chr:A,txStart:l,txEnd:c}=s;Js(this.state.views[n].chromInfoPath,u=>{const d=u.chrToAbs([A,l])-C,h=u.chrToAbs([A,c])+C,[m,f,b]=SI(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: ${r}`)}})}},{key:"suggestGene",value:function(n,r,C){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=${r.toLowerCase()}`;vt.json(s,jo,this.pubSub).then(A=>{C(A)}).catch(A=>console.error(A))}},{key:"onLocationChange",value:function(n,r,C){const o=Object.keys(this.state.views);if(!o.length)return this.unsetOnLocationChange.push({viewId:n,callback:r,callbackId:C}),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)=>{r({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(_Z)===0).map(l=>parseInt(l.slice(_Z.length+1),10)).reduce((l,c)=>Math.max(l,c),0)+1),this.addScalesChangedListener(a.uid,`${_Z}.${A}`,s),C&&C(`${_Z}.${A}`),A}},{key:"getTiledPlotAtPosition",value:function(n,r){let C;const o=Eg(this.state.views);for(let a=0;a=c&&n<=d,m=r>=l&&r<=u;if(h&&m){C=s;break}}return C}},{key:"mouseMoveHandler",value:function(n){if(!this.topDiv||this.state.modal)return;const r=n.clientX,C=n.clientY,o=zg(n,this.topDiv);o[1]+=this.scrollTop;const a=this.getTiledPlotAtPosition(r,C),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,zG.publish("higlass.mouseMove",h)}this.apiPublish("cursorLocation",{absX:r,absY:C,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,r,C,o){const a=LZ(this.tiledPlots,n,r);if(!a){console.warn(`Track with ID: ${r} not found!`);return}if(!a.minVisibleValueInTiles||!a.maxVisibleValueInTiles){console.warn(`Track ${r} doesn't support the retrieval of min or max values.`);return}return C&&a.getAggregatedVisibleValue?[a.getAggregatedVisibleValue("min"),a.getAggregatedVisibleValue("max")]:[a.minVisibleValueInTiles(o),a.maxVisibleValueInTiles(o)]}},{key:"showHoverMenu",value:function(n){const r=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 C=r&&r.length?[1]:[];let o=dg("body").selectAll(".track-mouseover-menu").data(C);o.exit().remove(),o.enter().append("div").classed("track-mouseover-menu",!0).classed(rf["track-mouseover-menu"],!0),o=dg("body").selectAll(".track-mouseover-menu");const a=zg(n.origEvt,dg("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(r)}},{key:"hideHoverMenu",value:function(){dg("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 r=n.nativeEvent||n,C=r.clientX,o=r.clientY,a=this.getTiledPlotAtPosition(C,o),s=zg(r,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=LZ(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=LZ(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===GZ&&(this.scrollTop=this.scrollContainer.scrollTop,this.pixiStage.y=-this.scrollTop,this.pubSub.publish("app.scroll",this.scrollTop),this.animate())}},{key:"setTrackValueScaleLimits",value:function(n,r,C,o){const a=LZ(this.tiledPlots,n,r);if(!a){console.warn(`Could't find track: ${r}`);return}a.setFixedValueScaleMin&&a.setFixedValueScaleMax?(a.setFixedValueScaleMin(C),a.setFixedValueScaleMax(o),a.rerender(a.options,!0),a.animate()):console.warn("Track doesn't support fixed value scales.")}},{key:"setChromInfo",value:function(n,r){Js(n,C=>{this.chromInfo=C,r()},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===GZ||n&&n.zoomFixed}},{key:"trackDimensionsModifiedHandler",value:function(n){const r=this.state.views[n.viewId];if(!r)return;const C=gC(r.tracks,n.trackId);C&&(n.height!==void 0&&(C.height=n.height),n.width!==void 0&&(C.width=n.width),this.adjustLayoutToTrackSizes(r),this.setState(o=>({views:o.views})))}},{key:"wheelHandler",value:function(n){if(this.state.modal||this.props.options.sizeMode===GZ)return;const r=n.nativeEvent||n,C=n.target===this.canvasElement;if(!LGe(r.target,this.topDiv)||this.isZoomFixed())return;const o=r.clientX,a=r.clientY,s=this.getTiledPlotAtPosition(o,a);if(this.apiStack.wheel&&this.apiStack.wheel.length>0){const A=zg(r,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:r,sourceUid:this.uid,hoveredTracks:l,noHoveredTracks:l.length===0};this.apiPublish("wheel",d)}if(r.forwarded||C){n.stopPropagation(),n.preventDefault();return}if(n.preventDefault(),s){const{trackRenderer:A}=s;r.forwarded=!0,r&&(vX(r,A.eventTracker),r.preventDefault())}}},{key:"render",value:function(){this.tiledAreasDivs={},this.tiledAreas=N.createElement("div",{className:rf["tiled-area"]}),this.mounted&&(this.tiledAreas=Eg(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(O$t,{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(X8t,{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(r6t,{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:rf["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 r=this.isEditable()?ZGe:0,C=this.isEditable()?GGe:0,o=+this.props.options.containerPaddingX>=0?+this.props.options.containerPaddingX:r,a=+this.props.options.containerPaddingY>=0?+this.props.options.containerPaddingY:C,s=N.createElement(Rot,{ref:A=>{this.gridLayout=A},cols:12,containerPadding:[o,a],draggableHandle:`.${wC["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:Xg("higlass",{"higlass-dark-theme":this.theme===gi,"higlass-container-overflow":this.props.options.sizeMode===tle||this.props.options.sizeMode===GZ}),onMouseLeave:this.onMouseLeaveHandlerBound,onMouseMove:this.mouseMoveHandlerBound},N.createElement(KWt,{value:this.pubSub},N.createElement(Azt,{value:this.modal},N.createElement(SWt,{value:this.theme},this.state.modal,N.createElement("canvas",{key:this.uid,ref:A=>{this.canvasElement=A},onClick:this.canvasClickHandlerBound,className:rf["higlass-canvas"]}),N.createElement("div",{ref:A=>{this.scrollContainer=A},className:Xg("higlass-scroll-container",{"higlass-scroll-container-overflow":this.props.options.sizeMode===tle,"higlass-scroll-container-scroll":this.props.options.sizeMode===GZ}),onScroll:this.onScrollHandlerBound},N.createElement("div",{ref:A=>{this.divDrawingSurface=A},className:Xg("higlass-drawing-surface",rf["higlass-drawing-surface"])},s),N.createElement("svg",{ref:A=>{this.svgElement=A},className:rf["higlass-svg"],style:{position:"absolute",width:"100%",height:"100%",left:0,top:0,pointerEvents:"none"}}))))))}}]),i}(N.Component);dy.defaultProps={options:{},zoomFixed:!1,compactLayout:!0};dy.propTypes={getApi:L.func,options:L.object,viewConfig:L.oneOfType([L.string,L.object]).isRequired,zoomFixed:L.bool,compactLayout:L.bool};function wtg(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function gle(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 vH(e){return vH=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(i){return i.__proto__||Object.getPrototypeOf(i)},vH(e)}const Ytg=(e,[g,i,I,n],r)=>{r.options.colorbarPosition||(r.options.colorbarPosition="hidden"),r.options.labelPosition||(r.options.labelPosition="hidden");const C="arbitary-id",a=Dtg(e,{editable:!1,zoomFixed:!1,views:[{uid:C,initialXDomain:[g,i],initialYDomain:[I,n],tracks:{center:[r]},layout:{w:12,h:12,x:0,y:0,moved:!1,static:!1}}]},{sizeMode:"bounded"});return{id:C,hgApi:a}};let Ktg=function(e){Xtg(i,e);var g=Htg(i);function i(I){var n;return wtg(this,i),n=g.call(this,I),n.id=`id-${Math.random()}`,n}return Rtg(i,[{key:"componentDidMount",value:function(){this.initTrackViewer()}},{key:"shouldComponentUpdate",value:function(n){const{x:r,y:C,width:o,height:a}=n;return this.zoomTo(r,C,o,a),!1}},{key:"initTrackViewer",value:function(){const{trackConfig:n,x:r,y:C,width:o,height:a}=this.props,s=document.getElementById(this.id),{id:A,hgApi:l}=Ytg(s,[r,r+o,C,C+a],n);this.viewUid=A,this.viewer=l}},{key:"zoomTo",value:function(n,r,C,o){this.viewer.zoomTo(this.viewUid,n,n+C,r,r+o)}},{key:"render",value:function(){return N.createElement("div",{id:this.id,style:{height:"100%",width:"100%"}})}}]),i}(N.Component);Ktg.propTypes={trackConfig:L.object,width:L.number,height:L.number,x:L.number,y:L.number};const Ftg=(e,g,i)=>{const I=N.createRef();return ji.render(N.createElement(dy,{ref:I,options:i||{},viewConfig:g}),e),I.current},Dtg=(e,g,i)=>Ftg(e,g,i).api;var n2e={exports:{}};(function(e,g){(function(i,I){e.exports=I()})(typeof window<"u"?window:yi,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 r(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[Y]||(V[Y]=""),H&&(" "+V[Y]+" ").indexOf(" "+H+" ")===-1&&(V[Y]+=" "+H));for(var x in K)K.hasOwnProperty(x)&&(V[K[x]]?this.element.setAttribute(K[x],V[K[x]].substr(1)):this.element.removeAttribute(K[x]))}}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,R){if(typeof C[G]>"u"){C[G]=[];var S=o.length;r.innerHTML+=` +`+G+" {animation: 0.1s element-queries;}",r.innerHTML+=` +`+G+" > .resize-sensor {min-width: "+S+"px;}",o.push(G)}C[G].push({mode:v,property:w,value:R})}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 C)if(C.hasOwnProperty(w))for(var R=v(w,G),S=0,X=R.length;Sw[P].minWidth&&(J=P);if(J||(J=S),X!==J)if(W[J])v[X].style.display="none",v[J].style.display="block",X=J;else{var ge=new Image;ge.onload=function(){v[J].src=R[J],v[X].style.display="none",v[J].style.display="block",W[J]=!0,X=J},ge.src=R[J]}else v[J].src=R[J]}G.resizeSensorInstance=new i(G,x),x()}function f(){for(var G=d(),v=G("[data-responsive-image],[responsive-image]"),w=0,R=v.length;w img, [data-responsive-image] {overflow: hidden; padding: 0; } [responsive-image] > img, [data-responsive-image] > img {width: 100%;}",r.innerHTML+=` +@keyframes element-queries { 0% { visibility: inherit; } }`,document.getElementsByTagName("head")[0].appendChild(r),B=!0);for(var v=0,w=document.styleSheets.length;vg in e?Etg(e,g,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[g]=i,Ct=(e,g,i)=>(Mtg(e,typeof g!="symbol"?g+"":g,i),i),z$=(e,g,i)=>{if(!g.has(e))throw TypeError("Cannot "+i)},Dt=(e,g,i)=>(z$(e,g,"read from private field"),i?i.call(e):g.get(e)),fg=(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)},Vr=(e,g,i,I)=>(z$(e,g,"write to private field"),I?I.call(e,i):g.set(e,i),i),Si=(e,g,i)=>(z$(e,g,"access private method"),i),mG,aS,AS,Ed,BH,SH,$O,o2e,P$,a2e,wH,qO,e_,A2e,t_,s2e,g_,l2e,jA;const ztg="#/definitions/GoslingSpec",Ptg="http://json-schema.org/draft-07/schema#",Jtg={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" @@ -1985,11 +1985,11 @@ ${C}`}},{key:"handleExportSVG",value:function(){PG("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"}},Dtg={$ref:Ytg,$schema:Ktg,definitions:xtg};function Ftg(e){return n2e(Dtg,e)}function n2e(e,g,I=!1){const i=new e6e({extendRefs:!0}).compile(e),n=i(g);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 C2e(e){let g=!0;const I=[];return T0(e).forEach(n=>{!D$(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"&&ut(C)&&C.type==="quantitative"&&(I.push("`line` mark cannot be used with `quantitative` value"),g=!1)}),{valid:g,errorMessages:I}}function D$(e){let g;return["x","y","xe","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];ut(i)&&i.type==="genomic"&&(g=i)}),g}function r2e(e){let g;return["x","xe","y","ye","x1","y1","x1e","y1e"].reverse().forEach(I=>{const i=e[I];ut(i)&&i.type==="genomic"&&(g=I)}),g}const Etg=[{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 Mtg(e,g){EX(e,(I,i,n)=>{var C,r;if(!b4e(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 $se=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Zo={color:$se[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:$se,quantitativeSizeRange:[2,6]},ztg={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:{...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:"normal"},brush:{...Zo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},qse=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Ptg={color:qse[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:qse,quantitativeSizeRange:[2,6]},Go={...Ptg,stroke:"white"},Jtg={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:{...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:"lightgray",opacity:.3,stroke:"white",strokeWidth:1}},ele=["#D19000","#008F67","#005F96","#B86E97","#B55100","#4793BF","#C9C03"],vo={color:ele[0],size:1,stroke:"#3C3C3C",strokeWidth:0,opacity:1,nominalColorRange:ele,quantitativeSizeRange:[2,6]},Otg={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:{...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:"#3C3C3C",strokeWidth:1}},tle=["#F66A62","#05B230","#5692FF","#D764D6","#86E9D4","#6E6AD7","#FFFB00"],Bo={color:tle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:tle,quantitativeSizeRange:[2,6]},_tg={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:{...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:"bold"},brush:{...Bo,color:"black",opacity:.3,stroke:"black",strokeWidth:1}},gle=["#37E649","#ED2D44","#AEAFEA","#EBAEAE","#CE7B3D","#8743E0","#5233F0"],So={color:gle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:gle,quantitativeSizeRange:[2,6]},Ltg={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:{...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:"bold"},brush:{...So,color:"white",opacity:.3,stroke:"black",strokeWidth:1}},Ile=["#CD9B1D","#8A668B","#40E0D0","#FF6969","#666666","#FAC902","#FE0000","#CC96CD","#D9D9D9"],wo={color:Ile[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Ile,quantitativeSizeRange:[2,6]},Utg={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:{...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:"gray",opacity:.3,stroke:"black",strokeWidth:1}},ile=["#3A62FE","#F85353","#3A62FE","#F85353","#DCA326","#03BF06","#BABABA"],Vo={color:ile[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ile,quantitativeSizeRange:[2,6]},Qtg={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}},nle=["#3A5FCD","#FFA54E","#8FBC8F","#B6709B","#EE6A50","#CCB79E","#DADA8F","#00CDCC","#EED5D2","#CD8EDD","#9ACD31","#D1BEA8","#FFB6C0"],Ro={color:nle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:nle,quantitativeSizeRange:[2,6]},jtg={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:{...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}},Cle=["#6E12AC","#15C250","#E70FB1","#FF8E55","#A3B8F3","#DE5E59","#77AAAA","#F5CCCA"],Wo={color:Cle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Cle,quantitativeSizeRange:[2,6]},$tg={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:{...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:"gray",opacity:.3,stroke:"gray",strokeWidth:1}},rle=["#ED7D31","#4472C4","#FFC207","#76AE4F","#9E480E","#A5A5A5","#4472C4","#264378","#76AE4F","#5B9CD5"],Xo={color:rle[0],size:1,stroke:"#5A5A5A",strokeWidth:0,opacity:1,nominalColorRange:rle,quantitativeSizeRange:[2,6]},qtg={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:{...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:"#5A5A5A",opacity:.3,stroke:"#5A5A5A",strokeWidth:1}},ole=["#4185f4","#DB4437","#F4B400","#0D9D58","#AA30C3","#FF6E02","#CBC74C"],Ho={color:ole[0],size:2,stroke:"black",strokeWidth:.3,opacity:1,nominalColorRange:ole,quantitativeSizeRange:[2,6]},egg={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:{...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:"#999999",opacity:.3,stroke:"black",strokeWidth:.7}},$O={light:ztg,dark:Jtg,warm:Otg,ggplot:_tg,igv:Ltg,ensembl:Utg,jbrowse:Qtg,ucsc:jtg,washu:$tg,excel:qtg,google:egg};function qO(e){return Object.keys($O).indexOf(e)!==-1}function mG(e){return qO(e)?$O[e]:$O.light}function F$(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 tgg=200,ggg=6,Igg=2,o2e=7829367,igg=' ',ngg={type:"axis-track",datatype:["multivec","epilogos"],local:!1,orientation:"1d-horizontal",thumbnail:new DOMParser().parseFromString(igg,"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:o2e}},Cgg=(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),rt(this,"allTexts"),rt(this,"searchField"),rt(this,"chromInfo"),rt(this,"dataConfig"),rt(this,"pTicksCircular"),rt(this,"pTicks"),rt(this,"gTicks"),rt(this,"tickTexts"),rt(this,"isShowGlobalMousePosition"),rt(this,"pixiTextConfig"),rt(this,"stroke"),rt(this,"tickWidth"),rt(this,"tickHeight"),rt(this,"tickTextSeparation"),rt(this,"tickColor"),rt(this,"animate"),rt(this,"hideMousePosition"),rt(this,"gBoundTicks"),rt(this,"leftBoundTick"),rt(this,"rightBoundTick"),rt(this,"is2d"),rt(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=xs({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=tgg,this.tickHeight=ggg,this.tickTextSeparation=Igg,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={...bI(m).size},p=[];Object.keys(bI(m).size).forEach(y=>{f[y]={chr:y,pos:bI(m).size[y]}}),Object.keys(bI(m).interval).forEach(y=>{p.push({chr:y,pos:bI(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):o2e,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=_6e(l,u),h=n0e(","),m=C0e(`,.${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=eh().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 T6e;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},ale=F$(ngg,Cgg);function e_(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),rt(this,"circularBrushData"),rt(this,"prevExtent");const[o,a]=n,{registerViewportChanged:s,removeViewportChanged:A,setDomainsCallback:l}=o;this.uid=ln(),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=iqe().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<=gn&&r<=gn||C>=Math.PI*2-gn&&r>=Math.PI*2-gn){this.gBrush.attr("visibility","hidden");return}CMath.PI*2-gn&&(C=Math.PI*2-gn),rMath.PI*2-gn&&(r=Math.PI*2-gn),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=jg(n,r,this.options.startAngle,this.options.endAngle)+Math.PI/2,a=jg(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 rgg=' ';e_.config={type:"brush-track",datatype:["projection"],local:!1,projection:!0,orientation:"2d",thumbnail:new DOMParser().parseFromString(rgg,"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 Ale=3,ogg={color:"#777",stroke:"#777",strokeWidth:1,strokeOpacity:.7,opacity:.3};class agg{constructor(g,I,i={}){rt(this,"brushSelection"),rt(this,"style"),rt(this,"range"),rt(this,"data"),rt(this,"startEvent"),rt(this,"prevExtent"),rt(this,"offset"),rt(this,"size"),rt(this,"externals"),rt(this,"emitter"),this.emitter=nqe(),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({},ogg,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-Ale,end:g},{type:"end",cursor:"ew-resize",start:I,end:I+Ale}]}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 Agg=([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,lgg=(e,g,I=5)=>t_(e,g-I)&&t_(e,g+I),cgg=(e,g)=>g.filter((I,i)=>i%2===0).every(I=>t_(e,I)),ugg=([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 hgg{constructor(){rt(this,"data"),this.data=[]}size(){return this.data.length}addPolygonBasedEvent(g,I){this.data.push({uid:ln(),type:"polygon",value:g,polygon:I})}addPointBasedEvent(g,I){this.data.push({uid:ln(),type:"point",value:g,polygon:I})}addLineBasedEvent(g,I){this.data.push({uid:ln(),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 sgg([I,i],g.polygon);case"line":return ugg([I,i],g.polygon);case"polygon":default:return dgg([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 lgg([I,i],g.polygon[0],g.polygon[2]);case"line":case"polygon":default:return cgg([I,i],g.polygon)}}}const a2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcm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VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMyldOwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgPj4gMTYgJiAyNTU7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCA+PiA4ICYgMjU1OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDIpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDIgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAxKV0gPj4gNDsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICBpZiAocGxhY2VIb2xkZXJzTGVuID09PSAxKSB7CiAgICAgICAgICB0bXAgPSByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIpXSA8PCAxMCB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDEpXSA8PCA0IHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMildID4+IDI7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCA+PiA4ICYgMjU1OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhcnI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJpcGxldFRvQmFzZTY0KG51bSkgewogICAgICAgIHJldHVybiBsb29rdXBbbnVtID4+IDE4ICYgNjNdICsgbG9va3VwW251bSA+PiAxMiAmIDYzXSArIGxvb2t1cFtudW0gPj4gNiAmIDYzXSArIGxvb2t1cFtudW0gJiA2M107CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZW5jb2RlQ2h1bmsodWludDgsIHN0YXJ0LCBlbmQpIHsKICAgICAgICB2YXIgd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5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMud3JpdGUgPSBmdW5jdGlvbihidWZmZXIsIHZhbHVlLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtLCBjOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgcnQgPSBtTGVuID09PSAyMyA/IE1hdGgucG93KDIsIC0yNCkgLSBNYXRoLnBvdygyLCAtNzcpIDogMDsKICAgICAgICB2YXIgaSA9IGlzTEUgPyAwIDogbkJ5dGVzIC0gMTsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAxIDogLTE7CiAgICAgICAgdmFyIHMgPSB2YWx1ZSA8IDAgfHwgdmFsdWUgPT09IDAgJiYgMSAvIHZhbHVlIDwgMCA/IDEgOiAwOwogICAgICAgIHZhbHVlID0gTWF0aC5hYnModmFsdWUpOwogICAgICAgIGlmIChpc05hTih2YWx1ZSkgfHwgdmFsdWUgPT09IEluZmluaXR5KSB7CiAgICAgICAgICBtID0gaXNOYU4odmFsdWUpID8gMSA6IDA7CiAgICAgICAgICBlID0gZU1heDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZSA9IE1hdGguZmxvb3IoTWF0aC5sb2codmFsdWUpIC8gTWF0aC5MTjIpOwogICAgICAgICAgaWYgKHZhbHVlICogKGMgPSBNYXRoLnBvdygyLCAtZSkpIDwgMSkgewogICAgICAgICAgICBlLS07CiAgICAgICAgICAgIGMgKj0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICB2YWx1ZSArPSBydCAvIGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWx1ZSArPSBydCAqIE1hdGgucG93KDIsIDEgLSBlQmlhcyk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodmFsdWUgKiBjID49IDIpIHsKICAgICAgICAgICAgZSsrOwogICAgICAgICAgICBjIC89IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IGVNYXgpIHsKICAgICAgICAgICAgbSA9IDA7CiAgICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgICAgfSBlbHNlIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICBtID0gKHZhbHVlICogYyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSBlICsgZUJpYXM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtID0gdmFs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Bwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXI4LnByb3RvdHlwZSwgInBhcmVudCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjgucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ5dGVPZmZzZXQ7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgZnVuY3Rpb24gY3JlYXRlQnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPiBLX01BWF9MRU5HVEgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCdUaGUgdmFsdWUgIicgKyBsZW5ndGggKyAnIiBpcyBpbnZhbGlkIGZvciBvcHRpb24gInNpemUiJyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGJ1ZiA9IG5ldyBVaW50OEFycmF5KGxlbmd0aCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1ZiwgQnVmZmVyOC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBid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0ZU9mZnNldCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJ1ZiA9IG5ldyBVaW50OEFycmF5KGFycmF5LCBieXRlT2Zmc2V0LCBsZW5ndGgpOwogICAgICAgIH0KICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXI4LnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tT2JqZWN0KG9iaikgewogICAgICAgIGlmIChCdWZmZXI4LmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19N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0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjguaXNFbmNvZGluZyA9IGZ1bmN0aW9uIGlzRW5jb2RpbmcoZW5jb2RpbmcpIHsKICAgICAgICBzd2l0Y2ggKFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKSkgewogICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICByZXR1cm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YXRjaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjguYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5faXNCdWZmZXIgPSB0cnVlOwogICAgICBmdW5jdGlvbiBzd2FwKGIsIG4sIG0pIHsKICAgICAgICBjb25zdCBpID0gYltuXTsKICAgICAgICBiW25dID0gYlttXTsKICAgICAgICBiW21dID0gaTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID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ICAgICAgICAgc3dhcCh0aGlzLCBpLCBpICsgNyk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAxLCBpICsgNik7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAyLCBpICsgNSk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAzLCBpICsgNCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b0xvY2FsZVN0cmluZyA9IEJ1ZmZlcjgucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICBCdWZmZXI4LnByb3RvdHlwZS5lcXVhbHMgPSBmdW5jdGlvbiBlcXVhbHMoYikgewogICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcihiKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkFyZ3VtZW50IG11c3QgYmUgYSBCdWZmZXIiKTsKICAgICAgICBpZiAodGhpcyA9PT0gYikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHJldHVybiBCdWZmZXI4LmNvbXBhcmUodGhpcywgYikgPT09IDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmluc3BlY3QgPSBmdW5jdGlvbiBpbnNwZWN0KCkgewogICAgICAgIGxldCBzdHIgPSA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5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb3B5ID0gdGhpcy5zbGljZSh0aGlzU3RhcnQsIHRoaXNFbmQpOwogICAgICAgIGNvbnN0IHRhcmdldENvcHkgPSB0YXJnZXQuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKHRoaXNDb3B5W2ldICE9PSB0YXJnZXRDb3B5W2ldKSB7CiAgICAgICAgICAgIHggPSB0aGlzQ29weVtpXTsKICAgICAgICAgICAgeSA9IHRhcmdldENvcHlbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJpZGlyZWN0aW9uYWxJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgaWYgKGJ1ZmZlci5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHR5cGVvZiBieXRlT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBieXRlT2Zmc2V0OwogICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0ID4gMjE0NzQ4MzY0NykgewogICAgICAgICAgYnl0ZU9mZnNldCA9IDIxNDc0ODM2NDc7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgLTIxNDc0ODM2NDgpIHsKICAgICAgICAgIGJ5dGVPZmZzZXQgPSAtMjE0NzQ4MzY0ODsKICAgICAgICB9CiAgICAgICAgYnl0ZU9mZnNldCA9ICtieXRlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyOC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcih2YWwpKSB7CiAgICAgICAgICBpZiAodmFsLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gYXJyYXlJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgICBpZiAodHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mLmNhbGwoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5sYXN0SW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIFt2YWxdLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigidmFsIG11c3QgYmUgc3RyaW5nLCBudW1iZXIgb3IgQnVmZmVyIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXJyYXlJbmRleE9mKGFyciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgbGV0IGluZGV4U2l6ZSA9IDE7CiAgICAgICAgbGV0IGFyckxlbmd0aCA9IGFyci5sZW5ndGg7CiAgICAgICAgbGV0IHZhbExlbmd0aCA9IHZhbC5sZW5ndGg7CiAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDApIHsKICAgICAgICAgIGVuY29kaW5nID0gU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidWNzMiIgfHwgZW5jb2RpbmcgPT09ICJ1Y3MtMiIgfHwgZW5jb2RpbmcgPT09ICJ1dGYxNmxlIiB8fCBlbmNvZGluZyA9PT0gInV0Zi0xNmxlIikgewogICAgICAgICAgICBpZiAoYXJyLmxlbmd0aCA8IDIgfHwgdmFsLmxlbmd0aCA8IDIpIHsKICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW5kZXhTaXplID0gMjsKICAgICAgICAgICAgYXJyTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIHZhbExlbmd0aCAvPSAyOwogICAgICAgICAgICBieXRlT2Zmc2V0IC89IDI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHJlYWQoYnVmLCBpMikgewogICAgICAgICAgaWYgKGluZGV4U2l6ZSA9PT0gMSkgewogICAgICAgICAgICByZXR1cm4gYnVmW2kyXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBidWYucmVhZFVJbnQxNkJFKGkyICogaW5kZXhTaXplKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgbGV0IGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPCBhcnJMZW5ndGg7IGkrKykgewogICAgICAgICAgICBpZiAocmVhZChhcnIsIGkpID09PSByZWFkKHZhbCwgZm91bmRJbmRleCA9PT0gLTEgPyAwIDogaSAtIGZvdW5kSW5kZXgpKSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggPT09IC0xKQogICAgICAgICAgICAgICAgZm91bmRJbmRleCA9IGk7CiAgICAgICAgICAgICAgaWYgKGkgLSBmb3VuZEluZGV4ICsgMSA9PT0gdmFsTGVuZ3RoKQogICAgICAgICAgICAgICAgcmV0dXJuIGZvdW5kSW5kZXggKiBpbmRleFNpemU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggIT09IC0xKQogICAgICAgICAgICAgICAgaSAtPSBpIC0gZm91bmRJbmRleDsKICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGJ5dGVPZmZzZXQgKyB2YWxMZW5ndGggPiBhcnJMZW5ndGgpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSBhcnJMZW5ndGggLSB2YWxMZW5ndGg7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpID49IDA7IGktLSkgewogICAgICAgICAgICBsZXQgZm91bmQgPSB0cnVlOwogICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHZhbExlbmd0aDsgaisrKSB7CiAgICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpICsgaikgIT09IHJlYWQodmFsLCBqKSkgewogICAgICAgICAgICAgICAgZm91bmQgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZm91bmQpCiAgICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5pbmNsdWRlcyA9IGZ1bmN0aW9uIGluY2x1ZGVzKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gdGhpcy5pbmRleE9mKHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcpICE9PSAtMTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUubGFzdEluZGV4T2YgPSBmdW5jdGlvbiBsYXN0SW5kZXhPZih2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nKSB7CiAgICAgICAgcmV0dXJuIGJpZGlyZWN0aW9uYWxJbmRleE9mKHRoaXMsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGZhbHNlKTsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gaGV4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgb2Zmc2V0ID0gTnVtYmVyKG9mZnNldCkgfHwgMDsKICAgICAgICBjb25zdCByZW1haW5pbmcgPSBidWYubGVuZ3RoIC0gb2Zmc2V0OwogICAgICAgIGlmICghbGVuZ3RoKSB7CiAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGxlbmd0aCA9IE51bWJlcihsZW5ndGgpOwogICAgICAgICAgaWYgKGxlbmd0aCA+IHJlbWFpbmluZykgewogICAgICAgICAgICBsZW5ndGggPSByZW1haW5pbmc7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IHN0ckxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA+IHN0ckxlbiAvIDIpIHsKICAgICAgICAgIGxlbmd0aCA9IHN0ckxlbiAvIDI7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29uc3QgcGFyc2VkID0gcGFyc2VJbnQoc3RyaW5nLnN1YnN0cihpICogMiwgMiksIDE2KTsKICAgICAgICAgIGlmIChudW1iZXJJc05hTihwYXJzZWQpKQogICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIGJ1ZltvZmZzZXQgKyBpXSA9IHBhcnNlZDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIHJldHVybiBibGl0Qn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GV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAg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2UgPD0gZW5kKSB7CiAgICAgICAgICAgIGxldCBzZWNvbmRCeXRlLCB0aGlyZEJ5dGUsIGZvdXJ0aEJ5dGUsIHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgIHN3aXRjaCAoYnl0ZXNQZXJTZXF1ZW5jZSkgewogICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIGlmIChmaXJzdEJ5dGUgPCAxMjgpIHsKICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyOC5wcm90b3R5cGUuc2xpY2UgPSBmdW5jdGlvbiBzbGljZShzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgc3RhcnQgPSB+fnN0YXJ0OwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gbGVuIDogfn5lbmQ7CiAgICAgICAgaWYgKHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgKz0gbGVuOwogICAgICAgICAgaWYgKHN0YXJ0IDwgMCkKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAoc3RhcnQgPiBsZW4pIHsKICAgICAgICAgIHN0YXJ0ID0gbGVuOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDwgMCkgewogICAgICAgICAgZW5kICs9IGxlbjsKICAgICAgICAgIGlmIChlbmQgPCAwKQogICAgICAgICAgICBlbmQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAoZW5kID4gbGVuKSB7CiAgICAgICAgICBlbmQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCBzdGFydCkKICAgICAgICAgIGVuZCA9IHN0YXJ0OwogICAgICAgIGNvbnN0IG5ld0J1ZiA9IHRoaXMuc3ViYXJyYXkoc3RhcnQsIGVuZCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKG5ld0J1ZiwgQnVmZmVyOC5wcm90b3R5cGUpOwogICAgICAgIHJldH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lLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIDcpOwogICAgICAgIGxldCBsbyA9IE51bWJlcih2YWx1ZSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGxvOwogICAgICAgIGxldCBoaSA9IE51bWJlcih2YWx1ZSA+PiBCaWdJbnQoMzIpICYgQmlnSW50KDQyOTQ5NjcyOTUpKTsKICAgICAgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgcmV0dXJuIG9mZnNldDsKICAgICAgfQogICAgICBmdW5jdGlvbiB3cnRCaWdVSW50NjRCRShidWYsIHZhbHVlLCBvZmZzZXQsIG1pbiwgbWF4KSB7CiAgICAgICAgY2hlY2tJbnRCSSh2YWx1ZSwgbWluLCBtYXgsIGJ1Ziwgb2Zmc2V0LCA3KTsKICAgICAgICBsZXQgbG8gPSBOdW1iZXIodmFsdWUgJiBCaWdJbnQoNDI5NDk2NzI5NSkpOwogICAgICAgIGJ1ZltvZmZzZXQgKyA3XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNl0gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDVdID0gbG87CiAgICAgIC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5kID4gMCAmJiBlbmQgPCBzdGFydCkKICAgICAgICAgIGVuZCA9IHN0YXJ0OwogICAgICAgIGlmIChlbmQgPT09IHN0YXJ0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggPT09IDAgfHwgdGhpcy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBpZiAodGFyZ2V0U3RhcnQgPCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigidGFyZ2V0U3RhcnQgb3V0IG9mIGJvdW5kcyIpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IHN0YXJ0ID49IHRoaXMubGVuZ3RoKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkluZGV4IG91dCBvZiByYW5nZSIpOwogICAgICAgIGlmIChlbmQgPCAwKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoInNvdXJjZUVuZCBvdXQgb2YgYm91bmRzIik7CiAgICAgICAgaWYgKGVuZCA+IHRoaXMubGVuZ3RoKQogICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggLSB0YXJnZXRTdGFydCA8IGVuZCAtIHN0YXJ0KSB7CiAgICAgICAgICBlbmQgPSB0YXJnZXQubGVuZ3RoIC0gdGFyZ2V0U3RhcnQgKyBzdGFydDsKICAgICAgICB9CiAgICAgICAgY29uc3QgbGVuID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCAmJiB0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuY29weVdpdGhpbiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgdGhpcy5jb3B5V2l0aGluKHRhcmdldFN0YXJ0LCBzdGFydCwgZW5kKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLmZpbGwgPSBmdW5jdGlvbiBmaWxsKHZhbCwgc3RhcnQsIGVuZCwgZW5jb2RpbmcpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygc3RhcnQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gc3RhcnQ7CiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBlbmQgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIGVuY29kaW5nID0gZW5kOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwICYmIHR5cGVvZiBlbmNvZGluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiZW5jb2RpbmcgbXVzdCBiZSBhIHN0cmluZyIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZyA9PT0gInN0cmluZyIgJiYgIUJ1ZmZlcjguaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjguaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjguZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICAgIGNvbnN0IGxlbiA9IGJ5dGVzLmxlbmd0aDsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlIHZhbHVlICInICsgdmFsICsgJyIgaXMgaW52YWxpZCBmb3IgYXJndW1lbnQgInZhbHVlIicpOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGVuZCAtIHN0YXJ0OyArK2kpIHsKICAgICAgICAgICAgdGhpc1tpICsgc3RhcnRdID0gYnl0ZXNbaSAlIGxlbl07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICB2YXIgZXJyb3JzID0ge307CiAgICAgIGZ1bmN0aW9uIEUoc3ltLCBnZXRNZXNzYWdlLCBCYXNlKSB7CiAgICAgICAgZXJyb3JzW3N5bV0gPSBjbGFzcyBOb2RlRXJyb3IgZXh0ZW5kcyBCYXNlIHsKICAgICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICBzdXBlcigpOwogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIm1lc3NhZ2UiLCB7CiAgICAgICAgICAgICAgdmFsdWU6IGdldE1lc3NhZ2UuYXBwbHkodGhpcywgYXJndW1lbnRzKSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMubmFtZSA9IGAke3RoaXMubmFtZX0gWyR7c3ltfV1gOwogICAgICAgICAgICB0aGlzLnN0YWNrOwogICAgICAgICAgICBkZWxldGUgdGhpcy5uYW1lOwogICAgICAgICAgfQogICAgICAgICAgZ2V0IGNvZGUoKSB7CiAgICAgICAgICAgIHJldHVybiBzeW07CiAgICAgICAgICB9CiAgICAgICAgICBzZXQgY29kZSh2YWx1ZSkgewogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGh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oSU5WQUxJRF9CQVNFNjRfUkUsICIiKTsKICAgICAgICBpZiAoc3RyLmxlbmd0aCA8IDIpCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgd2hpbGUgKHN0ci5sZW5ndGggJSA0ICE9PSAwKSB7CiAgICAgICAgICBzdHIgPSBzdHIgKyAiPSI7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzdHI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmOFRvQnl0ZXMoc3RyaW5nLCB1bml0cykgewogICAgICAgIHVuaXRzID0gdW5pdHMgfHwgSW5maW5pdHk7CiAgICAgICAgbGV0IGNvZGVQb2ludDsKICAgICAgICBjb25zdCBsZW5ndGggPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGxldCBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICBjb25zdCBieXRlcyA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvZGVQb2ludCA9IHN0cmluZy5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU1Mjk1ICYmIGNvZGVQb2ludCA8IDU3MzQ0KSB7CiAgICAgICAgICAgIGlmICghbGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NjMxOSkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChpICsgMSA9PT0gbGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY29kZVBvaW50IDwgNTYzMjApIHsKICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29kZVBvaW50ID0gKGxlYWRTdXJyb2dhdGUgLSA1NTI5NiA8PCAxMCB8IGNvZGVQb2ludCAtIDU2MzIwKSArIDY1NTM2OwogICAgICAgICAgfSBlbHNlIGlmIChsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgfQogICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgICBpZiAoY29kZVBvaW50IDwgMTI4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMSkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDIwNDgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDYgfCAxOTIsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgNjU1MzYpIHsKICAgICAgICAgICAgaWY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c2FnZSksIHsKICAgICAgICAgICAgbmFtZTogbWVzc2FnZS5uYW1lLAogICAgICAgICAgICBzdGFjazogbWVzc2FnZS5zdGFjawogICAgICAgICAgfSk7CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoZXJyb3IpIHsKICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIF9fZXJyb3JfbWFya2VyOiAiJCRlcnJvciIsCiAgICAgICAgICAgIG1lc3NhZ2U6IGVycm9yLm1lc3NhZ2UsCiAgICAgICAgICAgIG5hbWU6IGVycm9yLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBlcnJvci5zdGFjawogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBpc1NlcmlhbGl6ZWRFcnJvciA9ICh0aGluZykgPT4gdGhpbmcgJiYgdHlwZW9mIHRoaW5nID09PSAib2JqZWN0IiAmJiAiX19lcnJvcl9tYXJrZXIiIGluIHRoaW5nICYmIHRoaW5nLl9fZXJyb3JfbWFya2VyID09PSAiJCRlcnJvciI7CiAgICAgIGV4cG9ydHMuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICA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B2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMgJiYgZXhwb3J0cy5fX2ltcG9ydERlZmF1bHQgfHwgZnVuY3Rpb24obW9kKSB7CiAgICAgICAgcmV0dXJuIG1vZ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ICAgY29uc3Qgam9iVUlEID0gbWVzc2FnZURhdGEudWlkOwogICAgICAgICAgICBjb25zdCBzdWJzY3JpcHRpb24gPSBhY3RpdmVTdWJzY3JpcHRpb25zLmdldChqb2JVSUQpOwogICAgICAgICAgICBpZiAoc3Vic2NyaXB0aW9uKSB7CiAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnVuc3Vic2NyaWJlKCk7CiAgICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5kZWxldGUoam9iVUlEKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGV4cG9ydHMuZXhwb3NlID0gZXhwb3NlMjsKICAgICAgaWYgKHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2Ygc2VsZi5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iICYmIGltcGxlbWVudGF0aW9uXzEuZGVmYXVsdC5pc1dvcmtlclJ1bnRpbWUoKSkgewogICAgICAgIHNlbGYuYWRkRXZlbnRMaXN0ZW5lcigiZXJyb3IiLCAoZXZlbnQpID0+IHsKICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gcG9zdFVuY2F1Z2h0RXJyb3JNZXNzYWdlKGV2ZW50LmVycm9yIHx8IGV2ZW50KSwgMjUwKTsKICAgICAgICB9KTsKICAgICAgICBzZWxmLmFkZEV2ZW50TGlzdGVuZXIoInVuaGFuZGxlZHJlamVjdGlvbiIsIChldmVudCkgPT4gewogICAgICAgICAgY29uc3QgZXJyb3IgPSBldmVudC5yZWFzb247CiAgICAgICAgICBpZiAoZXJyb3IgJiYgdHlwZW9mIGVycm9yLm1lc3NhZ2UgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHNldFRpbWVvdXQoKCkgPT4gcG9zdFVuY2F1Z2h0RXJyb3JNZXNzYWdlKGVycm9yKSwgMjUwKTsKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfQog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cnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNpemUpKTsKICAgICAgIC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AgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gdGhpcy5sb3cgPj4+IDAgOiB0aGlzLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b051bWJlciA9IGZ1bmN0aW9uIHRvTnVtYmVyKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuICh0aGlzLmhpZ2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TG93Qml0cyA9IGZ1bmN0aW9uIGdldExvd0JpdHMoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldExvd0JpdHNVbnNpZ25lZCA9IGZ1bmN0a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FkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyLm5lZygpKTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkubXVsKG11bHRp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gJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGEzMiAqIGIwMDsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGExNiAqIGIxNjsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzMyICs9IGEwMCAqIGIzMjsKICAgICAgICBjNDggKz0gYzMyID4+PiAxNjsKICAgICAgICBjMzIgJj0gNjU1MzU7CiAgICAgICAgYzQ4ICs9IGE0OCAqIGIwMCArIGEzMiAqIGIxNiArIGExNiAqIGIzMiArIGEwMCAqIGI0ODsKICAgICAgICBjNDggJj0gNjU1MzU7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKGMxNiA8PCAxNiB8IGMwMCwgYzQ4IDw8IDE2IHwgYzMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWwgPSBMb25nUHJvdG90eXBlLm11bHRpcGx5OwogICAgICBMb25nUHJvdG90eXBlLmRpdmlkZSA9IGZ1bmN0aW9uIGRpdmlkZShkaXZpc29yKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB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lzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiBudW1CaXRzIC0gMzIsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHJ1ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hyX3UgPSBMb25nUHJvdG90eXBlLnNoaWZ0UmlnaHRVbnNpZ25lZDsKICAgICAgTG9uZ1Byb3RvdHlwZS50b1NpZ25lZCA9IGZ1bmN0aW9uIHRvU2lnbmVkKCkgewogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdywgdGhpcy5oaWdoLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9VbnNpZ25lZCA9IGZ1bmN0aW9uIHRvVW5zaWduZWQoKSB7CiAgICAgICAgaWYgKHRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgdHJ1ZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlcyA9IGZ1bmN0aW9uIHRvQnl0ZXMobGUpIHsKICAgICAgICByZXR1cm4gbGUgPyB0aGlzLnRvQnl0ZXNMRSgpIDogdGhpcy50b0J5dGVzQkUoKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAg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gIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0cy5zaHJpbmtCdWYgPSBmdW5jdGlvbihidWYsIHNpemUpIHsKICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gc2l6ZSkgewogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSkgewogICAgICAgICAgcmV0dXJuIGJ1Zi5zdWJhcnJheSgwLCBzaXplKTsKICAgICAgICB9CiAgICAgICAgYnVmLmxlbmd0aCA9IHNpemU7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgdmFyIGZuVHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBpZiAoc3JjLnN1YmFycmF5ICYmIGRlc3Quc3ViYXJyYXkpIHsKICAgICAgICAgICAgZGVzdC5zZXQoc3JjLnN1YmFycmF5KHNyY19vZmZzLCBzcmNfb2ZmcyArIGxlbiksIGRlc3Rfb2Zmcyk7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICB2YXIgaSwgbCwgbGVuLCBwb3MsIGNodW5rLCByZXN1bHQ7CiAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgbGVuICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXN1bHQgPSBuZXcgVWludDhBcnJheShsZW4pOwogICAgICAgICAgcG9zID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGNodW5rID0gY2h1bmtzW2ldOwogICAgICAgICAgICByZXN1bHQuc2V0KGNodW5rLCBwb3MpOwogICAgICAgICAgICBwb3MgKz0gY2h1bmsubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBmblVudHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgcmV0dXJuIFtdLmNvbmNhdC5hcHBseShbXSwgY2h1bmtzKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0cy5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMTYgPSBVaW50MTZBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5UeXBlZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGV4cG9ydHMuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYzMiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQoVFlQRURfT0spOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMKICB2YXIgcmVxdWlyZV90cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBaX0ZJWEVEID0gNDsKICAgICAgdmFyIFpfQklOQVJZID0gMDsKICAgICAgdmFyIFpfVEVYVCA9IDE7CiAgICAgIHZhciBaX1VOS05PV04gPSAyOwogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIHZhciBTVE9SRURfQkxPQ0sgPSAwOwogICAgICB2YXIgU1RBVElDX1RSRUVTID0gMTsKICAgICAgdmFyIERZTl9UUkVFUyA9IDI7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTEVOR1RIX0NPREVTID0gMjk7CiAgICAgIHZhciBMSVRFUkFMUyA9IDI1NjsKICAgICAgdmFyIExfQ09ERVMgPSBMSVRFUkFMUyArIDEgKyBMRU5HVEhfQ09ERVM7CiAgICAgIHZhciBEX0NPREVTID0gMzA7CiAgICAgIHZhciBCTF9DT0RFUyA9IDE5OwogICAgICB2YXIgSEVBUF9TSVpFID0gMiAqIExfQ09ERVMgKyAxOwogICAgICB2YXIgTUFYX0JJVFMgPSAxNTsKICAgICAgdmFyIEJ1Zl9zaXplID0gMTY7CiAgICAgIHZhciBNQVhfQkxfQklUUyA9IDc7CiAgICAgIHZhciBFTkRfQkxPQ0sgPSAyNTY7CiAgICAgIHZhciBSRVBfM182ID0g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vbiBiaV9mbHVzaChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPT09IDE2KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID49IDgpIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWYgJiAyNTU7CiAgICAgICAgICBzLmJpX2J1ZiA+Pj0gODsKICAgICAgICAgIHMuYmlfdmFsaWQgLT0gODsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2JpdGxlbihzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBtYXhfY29kZSA9IGRlc2MubWF4X2NvZGU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZXh0cmEgPSBkZXNjLnN0YXRfZGVzYy5leHRyYV9iaXRzOwogICAgICAgIHZhciBiYXNlID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYmFzZTsKICAgICAgICB2YXIgbWF4X2xlbmd0aCA9IGRlc2Muc3RhdF9kZXNjLm1heF9sZW5ndGg7CiAgICAgICAgdmFyIGg7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIHhiaXRzOwogICAgICAgIHZhciBmOwogICAgICAgIHZhciBvdmVyZmxvdyA9IDA7CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgdHJlZVtzLmhlYXBbcy5oZWFwX21heF0gKiAyICsgMV0gPSAwOwogICAgICAgIGZvciAoaCA9IHMuaGVhcF9tYXggKyAxOyBoIDwgSEVBUF9TSVpFOyBoKyspIHsKICAgICAgICAgIG4gPSBzLmhlYXBbaF07CiAgICAgICAgICBiaXRzID0gdHJlZVt0cmVlW24gKiAyICsgMV0gKiAyICsgMV0gKyAxOwogICAgICAgICAgaWYgKGJpdHMgPiBtYXhfbGVuZ3RoKSB7CiAgICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoOwogICAgICAgICAgICBvdmVyZmxvdysrOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gYml0czsKICAgICAgICAgIGlmIChuID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdKys7CiAgICAgICAgICB4Yml0cyA9IDA7CiAgICAgICAgICBpZiAobiA+PSBiYXNlKSB7CiAgICAgICAgICAgIHhiaXRzID0gZXh0cmFbbiAtIGJhc2VdOwogICAgICAgICAgfQogICAgICAgICAgZiA9IHRyZWVbbiAqIDJdOwogICAgICAgICAgcy5vcHRfbGVuICs9IGYgKiAoYml0cyArIHhiaXRzKTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuICs9IGYgKiAoc3RyZWVbbiAqIDIgKyAxXSArIHhiaXRzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG92ZXJmbG93ID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGRvIHsKICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoIC0gMTsKICAgICAgICAgIHdoaWxlIChzLmJsX2NvdW50W2JpdHNdID09PSAwKSB7CiAgICAgICAgICAgIGJpdHMtLTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10tLTsKICAgICAgICAgIHMuYmxfY291bnRbYml0cyArIDFdICs9IDI7CiAgICAgICAgICBzLmJsX2NvdW50W21heF9sZW5ndGhdLS07CiAgICAgICAgICBvdmVyZmxvdyAtPSAyOwogICAgICAgIH0gd2hpbGUgKG92ZXJmbG93ID4gMCk7CiAgICAgICAgZm9yIChiaXRzID0gbWF4X2xlbmd0aDsgYml0cyAhPT0gMDsgYml0cy0tKSB7CiAgICAgICAgICBuID0gcy5ibF9jb3VudFtiaXRzXTsKICAgICAgICAgIHdoaWxlIChuICE9PSAwKSB7CiAgICAgICAgICAgIG0gPSBzLmhlYXBbLS1oXTsKICAgICAgICAgICAgaWYgKG0gPiBtYXhfY29kZSkgewogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0cmVlW20gKiAyICsgMV0gIT09IGJpdHMpIHsKICAgICAgICAgICAgICBzLm9wdF9sZW4gKz0gKGJpdHMgLSB0cmVlW20gKiAyICsgMV0pICogdHJlZVttICogMl07CiAgICAgICAgICAgICAgdHJlZVttICogMiArIDFdID0gYml0czsKICAgICAgICAgICAgfQogICAgICAgICAgICBuLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgYmxfY291bnQpIHsKICAgICAgICB2YXIgbmV4dF9jb2RlID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgdmFyIGNvZGUgPSAwOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAoYml0cyA9IDE7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgbmV4dF9jb2RlW2JpdHNdID0gY29kZSA9IGNvZGUgKyBibF9jb3VudFtiaXRzIC0gMV0gPDwgMTsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICB2YXIgbGVuID0gdHJlZVtuICogMiArIDFdOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuZXh0X2NvZGVbbGVuXSsrLCBsZW4pOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiB0cl9zdGF0aWNfaW5pdCgpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGVuZ3RoOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBibF9jb3VudCA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIGxlbmd0aCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IExFTkdUSF9DT0RFUyAtIDE7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9sZW5ndGhbY29kZV0gPSBsZW5ndGg7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9sYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGgrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoIC0gMV0gPSBjb2RlOwogICAgICAgIGRpc3QgPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCAxNjsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlW2Rpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkaXN0ID4+PSA3OwogICAgICAgIGZvciAoOyBjb2RlIDwgRF9DT0RFUzsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0IDw8IDc7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXSAtIDc7IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlWzI1NiArIGRpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIGJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgbiA9IDA7CiAgICAgICAgd2hpbGUgKG4gPD0gMTQzKSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNTUpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gOTsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzldKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI3OSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA3OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbN10rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjg3KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICBnZW5fY29kZXMoc3RhdGljX2x0cmVlLCBMX0NPREVTICsgMSwgYmxfY291bnQpOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMiArIDFdID0gNTsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG4sIDUpOwogICAgICAgIH0KICAgICAgICBzdGF0aWNfbF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19sdHJlZSwgZXh0cmFfbGJpdHMsIExJVEVSQUxTICsgMSwgTF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19kX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2R0cmVlLCBleHRyYV9kYml0cywgMCwgRF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19ibF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKG5ldyBBcnJheSgwKSwgZXh0cmFfYmxiaXRzLCAwLCBCTF9DT0RFUywgTUFYX0JMX0JJVFMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluaXRfYmxvY2socykgewogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2x0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2R0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBCTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmJsX3RyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgcy5keW5fbHRyZWVbRU5EX0JMT0NLICogMl0gPSAxOwogICAgICAgIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgcy5sYXN0X2xpdCA9IHMubWF0Y2hlcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfd2luZHVwKHMpIHsKICAgICAgICBpZiAocy5iaV92YWxpZCA+IDgpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID4gMCkgewogICAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBzLmJpX2J1ZjsKICAgICAgICB9CiAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvcHlfYmxvY2socywgYnVmLCBsZW4sIGhlYWRlcikgewogICAgICAgIGJpX3dpbmR1cChzKTsKICAgICAgICBpZiAoaGVhZGVyKSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgbGVuKTsKICAgICAgICAgIHB1dF9zaG9ydChzLCB+bGVuKTsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQocy5wZW5kaW5nX2J1Ziwgcy53aW5kb3csIGJ1ZiwgbGVuLCBzLnBlbmRpbmcpOwogICAgICAgIHMucGVuZGluZyArPSBsZW47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc21hbGxlcih0cmVlLCBuLCBtLCBkZXB0aCkgewogICAgICAgIHZhciBfbjIgPSBuICogMjsKICAgICAgICB2YXIgX20yID0gbSAqIDI7CiAgICAgICAgcmV0dXJuIHRyZWVbX24yXSA8IHRyZWVbX20yXSB8fCB0cmVlW19uMl0gPT09IHRyZWVbX20yXSAmJiBkZXB0aFtuXSA8PSBkZXB0aFttXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwcWRvd25oZWFwKHMsIHRyZWUsIGspIHsKICAgICAgICB2YXIgdiA9IHMuaGVhcFtrXTsKICAgICAgICB2YXIgaiA9IGsgPDwgMTsKICAgICAgICB3aGlsZSAoaiA8PSBzLmhlYXBfbGVuKSB7CiAgICAgICAgICBpZiAoaiA8IHMuaGVhcF9sZW4gJiYgc21hbGxlcih0cmVlLCBzLmhlYXBbaiArIDFdLCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzbWFsbGVyKHRyZWUsIHYsIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBzLmhlYXBba10gPSBzLmhlYXBbal07CiAgICAgICAgICBrID0gajsKICAgICAgICAgIGogPDw9IDE7CiAgICAgICAgfQogICAgICAgIHMuaGVhcFtrXSA9IHY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29tcHJlc3NfYmxvY2socywgbHRyZWUsIGR0cmVlKSB7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGxjOwogICAgICAgIHZhciBseCA9IDA7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGV4dHJhOwogICAgICAgIGlmIChzLmxhc3RfbGl0ICE9PSAwKSB7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGRpc3QgPSBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDJdIDw8IDggfCBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDIgKyAxXTsKICAgICAgICAgICAgbGMgPSBzLnBlbmRpbmdfYnVmW3MubF9idWYgKyBseF07CiAgICAgICAgICAgIGx4Kys7CiAgICAgICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGxjLCBsdHJlZSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29kZSA9IF9sZW5ndGhfY29kZVtsY107CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUgKyBMSVRFUkFMUyArIDEsIGx0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2xiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgbGMgLT0gYmFzZV9sZW5ndGhbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgbGMsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZGlzdC0tOwogICAgICAgICAgICAgIGNvZGUgPSBkX2NvZGUoZGlzdCk7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUsIGR0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2RiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgZGlzdCAtPSBiYXNlX2Rpc3RbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgZGlzdCwgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAobHggPCBzLmxhc3RfbGl0KTsKICAgICAgICB9CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgbHRyZWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX3RyZWUocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5zdGF0aWNfdHJlZTsKICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBlbGVtcyA9IGRlc2Muc3RhdF9kZXNjLmVsZW1zOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBtYXhfY29kZSA9IC0xOwogICAgICAgIHZhciBub2RlOwogICAgICAgIHMuaGVhcF9sZW4gPSAwOwogICAgICAgIHMuaGVhcF9tYXggPSBIRUFQX1NJWkU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IGVsZW1zOyBuKyspIHsKICAgICAgICAgIGlmICh0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlID0gbjsKICAgICAgICAgICAgcy5kZXB0aFtuXSA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZSAocy5oZWFwX2xlbiA8IDIpIHsKICAgICAgICAgIG5vZGUgPSBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlIDwgMiA/ICsrbWF4X2NvZGUgOiAwOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSAxOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IDA7CiAgICAgICAgICBzLm9wdF9sZW4tLTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuIC09IHN0cmVlW25vZGUgKiAyICsgMV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlc2MubWF4X2NvZGUgPSBtYXhfY29kZTsKICAgICAgICBmb3IgKG4gPSBzLmhlYXBfbGVuID4+IDE7IG4gPj0gMTsgbi0tKSB7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIG4pOwogICAgICAgIH0KICAgICAgICBub2RlID0gZWxlbXM7CiAgICAgICAgZG8gewogICAgICAgICAgbiA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFsxXSA9IHMuaGVhcFtzLmhlYXBfbGVuLS1dOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICAgIG0gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG47CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG07CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IHRyZWVbbiAqIDJdICsgdHJlZVttICogMl07CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gKHMuZGVwdGhbbl0gPj0gcy5kZXB0aFttXSA/IHMuZGVwdGhbbl0gOiBzLmRlcHRoW21dKSArIDE7CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSB0cmVlW20gKiAyICsgMV0gPSBub2RlOwogICAgICAgICAgcy5oZWFwWzFdID0gbm9kZSsrOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICB9IHdoaWxlIChzLmhlYXBfbGVuID49IDIpOwogICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gcy5oZWFwWzFdOwogICAgICAgIGdlbl9iaXRsZW4ocywgZGVzYyk7CiAgICAgICAgZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBzLmJsX2NvdW50KTsKICAgICAgfQogICAgICBmdW5jdGlvbiBzY2FuX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgdHJlZVsobWF4X2NvZGUgKyAxKSAqIDIgKyAxXSA9IDY1NTM1OwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSArPSBjb3VudDsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLmJsX3RyZWVbUkVQXzNfNiAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzNfMTAgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0rKzsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICB9IHdoaWxlICgtLWNvdW50ICE9PSAwKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICAgIGNvdW50LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUF8zXzYsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDIpOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8zXzEwLCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAzKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzExXzEzOCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMTEsIDcpOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF9ibF90cmVlKHMpIHsKICAgICAgICB2YXIgbWF4X2JsaW5kZXg7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2x0cmVlLCBzLmxfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2R0cmVlLCBzLmRfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgYnVpbGRfdHJlZShzLCBzLmJsX2Rlc2MpOwogICAgICAgIGZvciAobWF4X2JsaW5kZXggPSBCTF9DT0RFUyAtIDE7IG1heF9ibGluZGV4ID49IDM7IG1heF9ibGluZGV4LS0pIHsKICAgICAgICAgIGlmIChzLmJsX3RyZWVbYmxfb3JkZXJbbWF4X2JsaW5kZXhdICogMiArIDFdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLm9wdF9sZW4gKz0gMyAqIChtYXhfYmxpbmRleCArIDEpICsgNSArIDUgKyA0OwogICAgICAgIHJldHVybiBtYXhfYmxpbmRleDsKICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2FsbF90cmVlcyhzLCBsY29kZXMsIGRjb2RlcywgYmxjb2RlcykgewogICAgICAgIHZhciByYW5rOwogICAgICAgIHNlbmRfYml0cyhzLCBsY29kZXMgLSAyNTcsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBkY29kZXMgLSAxLCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgYmxjb2RlcyAtIDQsIDQpOwogICAgICAgIGZvciAocmFuayA9IDA7IHJhbmsgPCBibGNvZGVzOyByYW5rKyspIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCBzLmJsX3RyZWVbYmxfb3JkZXJbcmFua10gKiAyICsgMV0sIDMpOwogICAgICAgIH0KICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fbHRyZWUsIGxjb2RlcyAtIDEpOwogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9kdHJlZSwgZGNvZGVzIC0gMSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGV0ZWN0X2RhdGFfdHlwZShzKSB7CiAgICAgICAgdmFyIGJsYWNrX21hc2sgPSA0MDkzNjI0NDQ3OwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gMzE7IG4rKywgYmxhY2tfbWFzayA+Pj49IDEpIHsKICAgICAgICAgIGlmIChibGFja19tYXNrICYgMSAmJiBzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5keW5fbHRyZWVbOSAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEwICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTMgKiAyXSAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMzI7IG4gPCBMSVRFUkFMUzsgbisrKSB7CiAgICAgICAgICBpZiAocy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgfQogICAgICB2YXIgc3RhdGljX2luaXRfZG9uZSA9IGZhbHNlOwogICAgICBmdW5jdGlvbiBfdHJfaW5pdChzKSB7CiAgICAgICAgaWYgKCFzdGF0aWNfaW5pdF9kb25lKSB7CiAgICAgICAgICB0cl9zdGF0aWNfaW5pdCgpOwogICAgICAgICAgc3RhdGljX2luaXRfZG9uZSA9IHRydWU7CiAgICAgICAgfQogICAgICAgIHMubF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuZHluX2x0cmVlLCBzdGF0aWNfbF9kZXNjKTsKICAgICAgICBzLmRfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9kdHJlZSwgc3RhdGljX2RfZGVzYyk7CiAgICAgICAgcy5ibF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuYmxfdHJlZSwgc3RhdGljX2JsX2Rlc2MpOwogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl9zdG9yZWRfYmxvY2socywgYnVmLCBzdG9yZWRfbGVuLCBsYXN0KSB7CiAgICAgICAgc2VuZF9iaXRzKHMsIChTVE9SRURfQkxPQ0sgPDwgMSkgKyAobGFzdCA/IDEgOiAwKSwgMyk7CiAgICAgICAgY29weV9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIHRydWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl9hbG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YgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIyKGNyYywgYnVmLCBsZW4sIHBvcykgewogICAgICAgIHZhciB0ID0gY3JjVGFibGUsIGVuZCA9IHBvcyArIGxlbjsKICAgICAgICBjcmMgXj0gLTE7CiAgICAgICAgZm9yICh2YXIgaSA9IHBvczsgaSA8IGVuZDsgaSsrKSB7CiAgICAgICAgICBjcmMgPSBjcmMgPj4+IDggXiB0WyhjcmMgXiBidWZbaV0pICYgMjU1XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNyYyBeIC0xOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gY3JjMzIyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMKICB2YXIgcmVxdWlyZV9tZXNzYWdlczIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAg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FSVEVEID0gMzsKICAgICAgdmFyIEJTX0ZJTklTSF9ET05FID0gNDsKICAgICAgdmFyIE9TX0NPREUgPSAzOwogICAgICBmdW5jdGlvbiBlcnIoc3RybSwgZXJyb3JDb2RlKSB7CiAgICAgICAgc3RybS5tc2cgPSBtc2dbZXJyb3JDb2RlXTsKICAgICAgICByZXR1cm4gZXJyb3JDb2RlOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHJhbmsoZikgewogICAgICAgIHJldHVybiAoZiA8PCAxKSAtIChmID4gNCA/IDkgOiAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX3BlbmRpbmcoc3RybSkgewogICAgICAgIHZhciBzID0gc3RybS5zdGF0ZTsKICAgICAgICB2YXIgbGVuID0gcy5wZW5kaW5nOwogICAgICAgIGlmIChsZW4gPiBzdHJtLmF2YWlsX291dCkgewogICAgICAgICAgbGVuID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHMucGVuZGluZ19idWYsIHMucGVuZGluZ19vdXQsIGxlbiwgc3RybS5uZXh0X291dCk7CiAgICAgICAgc3RybS5uZXh0X291dCArPSBsZW47CiAgICAgICAgcy5wZW5kaW5nX291dCArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gbGVuOwogICAgICAgIHN0cm0uYXZhaWxfb3V0IC09IGxlbjsKICAgICAgICBzLnBlbmRpbmcgLT0gbGVuOwogICAgICAgIGlmIChzLnBlbmRpbmcgPT09IDApIHsKICAgICAgICAgIHMucGVuZGluZ19vdXQgPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9ibG9ja19vbmx5KHMsIGxhc3QpIHsKICAgICAgICB0cmVlcy5fdHJfZmx1c2hfYmxvY2socywgcy5ibG9ja19zdGFydCA+PSAwID8gcy5ibG9ja19zdGFydCA6IC0xLCBzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCwgbGFzdCk7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgZmx1c2hfcGVuZGluZyhzLnN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHB1dF9ieXRlKHMsIGIpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0U2hvcnRNU0IocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiA+Pj4gOCAmIDI1NTsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGIgJiAyNTU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmVhZF9idWYoc3RybSwgYnVmLCBzdGFydCwgc2l6ZSkgewogICAgICAgIHZhciBsZW4gPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGlmIChsZW4gPiBzaXplKSB7CiAgICAgICAgICBsZW4gPSBzaXplOwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgc3RybS5hdmFpbF9pbiAtPSBsZW47CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoYnVmLCBzdHJtLmlucHV0LCBzdHJtLm5leHRfaW4sIGxlbiwgc3RhcnQpOwogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMy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gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgcy5wcmV2X2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ewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSBmdW5jOwogICAgICB9CiAgICAgI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mljZV9sZW5ndGg7CiAgICAgICAgcy5tYXhfY2hhaW5fbGVuZ3RoID0gY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5tYXhfY2hhaW47CiAgICAgICAgcy5zdHJzdGFydCA9IDA7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAg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kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKIC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1c2gpIHsKICAgICAgICB2YXIgb2xkX2ZsdXNoLCBzOwogICAgICAgIHZhciBiZWcsIHZhbDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgZmx1c2ggPiBaX0JMT0NLIHx8IGZsdXNoIDwgMCkgewogICAgICAgICAgcmV0dXJuIHN0cm0gPyBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpIDogWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhW3MuZ3ppbmRleF0gJiAyNTUpOwogICAgICAgICAgICAgIHMuZ3ppbmRleCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IENPTU1FTlRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5jb21tZW50KSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBGS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NoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN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1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgICAgICAg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yKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzLmJ1ZjJiaW5zdHJpbmcgPSBmdW5jdGlvbihidWYpIHsKICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyhidWYsIGJ1Zi5sZW5ndGgpOwogICAgICB9OwogICAgICBleHBvcnRzLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0cy51dGY4Ym9yZGVyID0gZnVuY3Rpb24oYnVmLCBtYXgpIHsKICAgICAgICB2YXIgcG9zOwogICAgICAgIG1heCA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIGlmIChtYXggPiBidWYubGVuZ3RoKSB7CiAgICAgICAgICBtYXggPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBwb3MgPSBtYXggLSAxOwogICAgICAgIHdoaWxlIChwb3MgPj0gMCAmJiAoYnVmW3Bvc10gJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgIHBvcy0tOwogICAgICAgIH0KICAgICAgICBpZiAocG9zIDwgMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBvcyArIF91dGY4bGVuW2J1Zltwb3NdXSA+IG1heCA/IHBvcyA6IG1heDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMKICB2YXIgcmVxdWlyZV96c3RyZWFtID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gWlN0cmVhbSgpIHsKICAgICAgICB0aGlzLmlucHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfaW4gPSAwOwogICAgICAgIHRoaXMuYXZhaWxfaW4gPSAwOwogICAgICAgIHRoaXMudG90YWxfaW4gPSAwOwogICAgICAgIHRoaXMub3V0cHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfb3V0ID0gMDsKICAgICAgICB0aGlzLmF2YWlsX291dCA9IDA7CiAgICAgICAgdGhpcy50b3RhbF9vdXQgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5zdGF0ZSA9IG51bGw7CiAgICAgIC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IHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmIChvcHQuZ3ppcCAmJiBvcHQud2luZG93Qml0cyA+IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMTY7CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQubGV2ZWwsIG9wdC5tZXRob2QsIG9wdC53aW5kb3dCaXRzLCBvcHQubWVtTGV2ZWwsIG9wdC5zdHJhdGVneSk7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC5oZWFkZXIpIHsKICAgICAgICAgIHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0SGVhZGVyKHRoaXMuc3RybSwgb3B0LmhlYWRlcik7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgdmFyIGRpY3Q7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBkaWN0ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfH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ZG1heDsKICAgICAgICB2YXIgd3NpemU7CiAgICAgICAgdmFyIHdoYXZlOwogICAgICAgIHZhciB3bmV4dDsKICAgICAgICB2YXIgc193aW5kb3c7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxjb2RlOwogICAgICAgIHZhciBkY29kZTsKICAgICAgICB2YXIgbG1hc2s7CiAgICAgICAgdmFyIGRtYXNrOwogICAgICAgIHZhciBoZXJlOwogICAgICAgIHZhciBvcDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaW5wdXQsIG91dHB1dDsKICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgX2luID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBsYXN0ID0gX2luICsgKHN0cm0uYXZhaWxfaW4gLSA1KTsKICAgICAgICBfb3V0ID0gc3RybS5uZXh0X291dDsKICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICBiZWcgPSBfb3V0IC0gKHN0YXJ0IC0gc3RybS5hdmFpbF9vdXQpOwogICAgICAgIGVuZCA9IF9vdXQgKyAoc3RybS5hdmFpbF9vdXQgLSAyNTcpOwogICAgICAgIGRtYXggPSBzdGF0ZS5kbWF4OwogICAgICAgIHdzaXplID0gc3RhdGUud3NpemU7CiAgICAgICAgd2hhdmUgPSBzdGF0ZS53aGF2ZTsKICAgICAgICB3bmV4dCA9IHN0YXRlLnduZXh0OwogICAgICAgIHNfd2luZG93ID0gc3RhdGUud2luZG93OwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIGxjb2RlID0gc3RhdGUubGVuY29kZTsKICAgICAgICBkY29kZSA9IHN0YXRlLmRpc3Rjb2RlOwogICAgICAgIGxtYXNrID0gKDEgPDwgc3RhdGUubGVuYml0cykgLSAxOwogICAgICAgIGRtYXNrID0gKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMTsKICAgICAgICB0b3A6CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZXJlID0gbGNvZGVbaG9sZCAmIGxtYXNrXTsKICAgICAgICAgICAgZG9sZW46CiAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgbGVuID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgaWYgKG9wKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGVuICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbaG9sZCAmIGRtYXNrXTsKICAgICAgICAgICAgICAgICAgZG9kaXN0OgogICAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgICAgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IGRtYXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnNhbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplIC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHduZXh0IDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgLT0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuID4gMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgZG9kaXN0OwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSBjb2RlIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDMyKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChfaW4gPCBsYXN0ICYmIF9vdXQgPCBlbmQpOwogICAgICAgIGxlbiA9IGJpdHMgPj4gMzsKICAgICAgICBfaW4gLT0gbGVuOwogICAgICAgIGJpdHMgLT0gbGVuIDw8IDM7CiAgICAgICAgaG9sZCAmPSAoMSA8PCBiaXRzKSAtIDE7CiAgICAgICAgc3RybS5uZXh0X2luID0gX2luOwogICAgICAgIHN0cm0ubmV4dF9vdXQgPSBfb3V0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBfaW4gPCBsYXN0ID8gNSArIChsYXN0IC0gX2luKSA6IDUgLSAoX2luIC0gbGFzdCk7CiAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBfb3V0IDwgZW5kID8gMjU3ICsgKGVuZCAtIF9vdXQpIDogMjU3IC0gKF9vdXQgLSBlbmQpOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIHJldHVybjsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzCiAgdmFyIHJlcXVpcmVfaW5mdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdCA9IDA7CiAgICAgICAgdmFyIGN1cnIgPSAwOwogICAgICAgIHZhciBkcm9wID0gMDsKICAgICAgICB2YXIgbGVmdCA9IDA7CiAgICAgICAgdmFyIHVzZWQgPSAwOwogICAgICAgIHZhciBodWZmID0gMDsKICAgICAgICB2YXIgaW5jcjsKICAgICAgICB2YXIgZmlsbDsKICAgICAgICB2YXIgbG93OwogICAgICAgIHZhciBtYXNrOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBiYXNlID0gbnVsbDsKICAgICAgICB2YXIgYmFzZV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgY291bnQgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBvZmZzID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgZXh0cmEgPSBudWxsOwogICAgICAgIHZhciBleHRyYV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgZm9yIChsZW4gPSAwOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGNvdW50W2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgY291bnRbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rKzsKICAgICAgICB9CiAgICAgICAgcm9vdCA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA+IG1heCkgewogICAgICAgICAgcm9vdCA9IG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKG1heCA9PT0gMCkgewogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgb3B0cy5iaXRzID0gMTsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG1pbiA9IDE7IG1pbiA8IG1heDsgbWluKyspIHsKICAgICAgICAgIGlmIChjb3VudFttaW5dICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA8IG1pbikgewogICAgICAgICAgcm9vdCA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3Q7CiAgICAgICAgZHJvcCA9IDA7CiAgICAgICAgbG93ID0gLTE7CiAgICAgICAgdXNlZCA9IDEgPDwgcm9vdDsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmV4dCArPSBtaW47CiAgICAgICAgICAgIGN1cnIgPSBsZW4gLSBkcm9wOwogICAgICAgICAgICBsZWZ0ID0gMSA8PCBjdXJyOwogICAgICAgICAgICB3aGlsZSAoY3VyciArIGRyb3AgPCBtYXgpIHsKICAgICAgICAgICAgICBsZWZ0IC09IGNvdW50W2N1cnIgKyBkcm9wXTsKICAgICAgICAgICAgICBpZiAobGVmdCA8PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY3VycisrOwogICAgICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZCArPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIGlmICh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUyB8fCB0eXBlID09PSBESVNUUyAmJiB1c2VkID4gRU5PVUdIX0RJU1RTKSB7CiAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG93ID0gaHVmZiAmIG1hc2s7CiAgICAgICAgICAgIHRhYmxlW2xvd10gPSByb290IDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290OwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMjIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYgMTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubW9kZSA9IEhFQUQ7CiAgICAgICAgc3RhdGUubGFzdCA9IDA7CiAgIC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pZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+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/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICA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PT09IENPUFlfID8gMjU2IDogMCk7CiAgICAgICAgaWYgKChfaW4gPT09IDAgJiYgX291dCA9PT0gMCB8fCBmbHVzaCA9PT0gWl9GSU5JU0gpICYmIHJldCA9PT0gWl9PSykgewogICAgICAgICAgcmV0ID0gWl9CVUZfRVJST1I7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUVuZChzdHJtKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdykgewogICAgICAgICAgc3RhdGUud2luZG93ID0gbnVsbDsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUdldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKChzdGF0ZS53cmFwICYgMikgPT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGVhZCA9IGhlYWQ7CiAgICAgICAgaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBkaWN0aWQ7CiAgICAgICAgdmFyIHJldDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53cmFwICE9PSAwICYmIHN0YXRlLm1vZGUgIT09IERJQ1QpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IERJQ1QpIHsKICAgICAgICAgIGRpY3RpZCA9IDE7CiAgICAgICAgICBkaWN0aWQgPSBhZGxlcjMyKGRpY3RpZCwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgMCk7CiAgICAgICAgICBpZiAoZGljdGlkICE9PSBzdGF0ZS5jaGVjaykgewogICAgICAgICAgICByZXR1cm4gWl9EQVRBX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXQgPSB1cGRhdGV3aW5kb3coc3RybSwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgZGljdExlbmd0aCk7CiAgICAgICAgaWYgKHJldCkgewogICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgIHJldHVybiBaX01FTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGF2ZWRpY3QgPSAxOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMuaW5mbGF0ZVJlc2V0ID0gaW5mbGF0ZVJlc2V0OwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldDIgPSBpbmZsYXRlUmVzZXQyOwogICAgICBleHBvcnRzLmluZmxhdGVSZXNldEtlZXAgPSBpbmZsYXRlUmVzZXRLZWVwOwogICAgICBleHBvcn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ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBHWmhlYWRlcigpIHsKICAgICAgICB0aGlzLnRleHQgPSAwOwogICAgICAgIHRoaXMudGltZSA9IDA7CiAgICAgICAgdGhpcy54ZmxhZ3MgPSAwOwogICAgICAgIHRoaXMub3MgPSAwOwogICAgICAgIHRoaXMuZXh0cmEgPSBudWxsOwog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YXRlMihvcHRpb25zKTsKICAgICAgICB0aGlzLm9wdGlvbnMgPSB1dGlscy5hc3NpZ24oewogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDAsCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYgJiYgIShvcHRpb25zICYmIG9wdGlvbnMud2luZG93Qml0cykpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDMyOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPiAxNSAmJiBvcHQud2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICBpZiAoKG9wdC53aW5kb3dCaXRzICYgMTUpID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzIHw9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LndpbmRvd0JpdHMpOwogICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5oZWFkZXIgPSBuZXcgR1poZWFkZXIoKTsKICAgICAgICB6bGliX2luZmxhdGUuaW5mbGF0ZUdldEhlYWRlcih0aGlzLnN0cm0sIHRoaXMuaGVhZGVyKTsKICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygb3B0LmRpY3Rpb25hcnkgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIG9wdC5kaWN0aW9uYXJ5ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAob3B0LnJhdykgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLnB1c2ggPSBmdW5jdGlvbihkYXRhLCBtb2RlKSB7CiAgICAgICAgdmFyIHN0cm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0LCBzdHJtLm5leHRfb3V0KTsKICAgICAgICAgICAgICAgIHRhaWwgPSBzdHJtLm5leHRfb3V0IC0gbmV4dF9vdXRfdXRmODsKICAgICAgICAgICAgICAgIHV0ZjhzdHIgPSBzdHJpbmdzLmJ1ZjJzdHJpbmcoc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgpOwogICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHRhaWw7CiAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZSAtIHRhaWw7CiAgICAgICAgICAgICAgICBpZiAodGFpbCkgewogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgsIHRhaWwsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRmOHN0cik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgYWxsb3dCdWZFcnJvciA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EKTsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCkgewogICAgICAgICAgX21vZGUgPSBjLlpfRklOSVNIOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IGMuWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkgewogICAgICAgICAgdGhpcy5vbkVuZChjLlpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRW5kID0gZnVuY3Rpb24oc3RhdHVzKSB7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgaW5mbGF0b3IgPSBuZXcgSW5mbG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ICAgICAgIDIyMjcwNjEyMTQsCiAgICAgICAgNDUwNTQ4ODYxLAogICAgICAgIDE4NDMyNTg2MDMsCiAgICAgICAgNDEwNzU4MDc1MywKICAgICAgICAyMjExNjc3NjM5LAogICAgICAgIDMyNTg4Mzk5MCwKICAgICAgICAxNjg0Nzc3MTUyLAogICAgICAgIDQyNTExMjIwNDIsCiAgICAgICAgMjMyMTkyNjYzNiwKICAgICAgICAzMzU2MzM0ODcsCiAgICAgICAgMTY2MTM2NTQ2NSwKICAgICAgICA0MTk1MzAyNzU1LAogICAgICAgIDIzNjYxMTUzMTcsCiAgICAgICAgOTk3MDczMDk2LAogICAgICAgIDEyODE5NTM4ODYsCiAgICAgICAgMzU3OTg1NTMzMiwKICAgICAgICAyNzI0Njg4MjQyLAogICAgICAgIDEwMDY4ODgxNDUsCiAgICAgICAgMTI1ODYwNzY4NywKICAgICAgICAzNTI0MTAxNjI5LAogICAgICAgIDI3Njg5NDI0NDMsCiAgICAgICAgOTAxMDk3NzIyLAogICAgICAgIDExMTkwMDA2ODQsCiAgICAgICAgMzY4NjUxNzIwNiwKICAgICAgICAyODk4MDY1NzI4LAogICAgICAgIDg1MzA0NDQ1MSwKICAgICAgICAxMTcyMjY2MTAxLAogICAgICAgIDM3MDUwMTU3NTksCiAgICAgICAgMjg4MjYxNjY2NSwKICAgICAgICA2NTE3Njc5ODAsCiAgICAgICAgMTM3MzUwMzU0NiwKICAgICAgICAzMzY5NTU0MzA0LAogICAgICAgIDMyMTgxMDQ1OTgsCiAgICAgICAgNTY1NTA3MjUzLAogICAgICAgIDE0NTQ2MjE3MzEsCiAgICAgICAgMzQ4NTExMTcwNSwKICAgICAgICAzMDk5NDM2MzAzLAogICAgICAgIDY3MTI2Njk3NCwKICAgICAgICAxNTk0MTk4MDI0LAogICAgICAgIDMzMjI3MzA5MzAsCiAgICAgICAgMjk3MDM0NzgxMiwKICAgICAgICA3OTU4MzU1MjcsCiAgICAgICAgMTQ4MzIzMDIyNSwKICAgICAgICAzMjQ0MzY3Mjc1LAogICAgICAgIDMwNjAxNDk1NjUsCiAgICAgICAgMTk5NDE0NjE5MiwKICAgICAgICAzMTE1ODUzNCwKICAgICAgICAyNTYzOTA3NzcyLAogICAgICAgIDQwMjM3MTc5MzAsCiAgICAgICAgMTkwNzQ1OTQ2NSwKICAgICAgICAxMTI2MzcyMTUsCiAgICAgICAgMjY4MDE1MzI1MywKICAgICAgICAzOTA0NDI3MDU5LAogICAgICAgIDIwMTM3NzYyOTAsCiAgICAgICAgMjUxNzIyMDM2LAogICAgICAgIDI1MTcyMTUzNzQsCiAgICAgICAgMzc3NTgzMDA0MCwKICAgICAgICAyMTM3NjU2NzYzLAogICAgICAgIDE0MTM3NjgxMywKICAgICAgICAyNDM5Mjc3NzE5LAogICAgICAgIDM4NjUyNzEyOTcsCiAgICAgICAgMTgwMjE5NTQ0NCwKICAgICAgICA0NzY4NjQ4NjYsCiAgICAgICAgMjIzODAwMTM2OCwKICAgICAgICA0MDY2NTA4ODc4LAogICAgICAgIDE4MTIzNzA5MjUsCiAgICAgICAgNDUzMDkyNzMxLAogICAgICAgIDIxODE2MjUwMjUsCiAgICAgICAgNDExMTQ1MTIyMywKICAgICAgICAxNzA2MDg4OTAyLAogICAgICAgIDMxNDA0MjcwNCwKICAgICAgICAyMzQ0NTMyMjAyLAogICAgICAgIDQyNDAwMTc1MzIsCiAgICAgICAgMTY1ODY1ODI3MSwKICAgICAgICAzNjY2MTk5NzcsCiAgICAgICAgMjM2MjY3MDMyMywKICAgICAgICA0MjI0OTk0NDA1LAogICAgICAgIDEzMDM1MzU5NjAsCiAgICAgICAgOTg0OTYxNDg2LAogICAgICAgIDI3NDcwMDcwOTIsCiAgICAgICAgMzU2OTAzNzUzOCwKICAgICAgICAxMjU2MTcwODE3LAogICAgICAgIDEwMzc2MDQzMTEsCiAgICAgICAgMjc2NTIxMDczMywKICAgICAgICAzNTU0MDc5OTk1LAogICAgICAgIDExMzEwMTQ1MDYsCiAgICAgICAgODc5Njc5OTk2LAogICAgICAgIDI5MDkyNDM0NjIsCiAgICAgICAgMzY2Mzc3MTg1NiwKICAgICAgICAxMTQxMTI0NDY3LAogICAgICAgIDg1NTg0MjI3NywKICAgICAgICAyODUyODAxNjMxLAogICAgICAgIDM3MDg2NDg2NDksCiAgICAgICAgMTM0MjUzMzk0OCwKICAgICAgICA2NTQ0NTkzMDYsCiAgICAgICAgMzE4ODM5NjA0OCwKICAgICAgICAzMzczMDE1MTc0LAogICAgICAgIDE0NjY0Nzk5MDksCiAgICAgICAgNTQ0MTc5NjM1LAogICAgICAgIDMxMTA1MjM5MTMsCiAgICAgICAgMzQ2MjUyMjAxNSwKICAgICAgICAxNTkxNjcxMDU0LAogICAgICAgIDcwMjEzODc3NiwKICAgICAgICAyOTY2NDYwNDUwLAogICAgICAgIDMzNTI3OTk0MTIsCiAgICAgICAgMTUwNDkxODgwNywKICAgICAgICA3ODM1NTE4NzMsCiAgICAgICAgMzA4MjY0MDQ0MywKICAgICAgICAzMjMzNDQyOTg5LAogICAgICAgIDM5ODgyOTIzODQsCiAgICAgICAgMjU5NjI1NDY0NiwKICAgICAgICA2MjMxNzA2OCwKICAgICAgICAxOTU3ODEwODQyLAogICAgICAgIDM5Mzk4NDU5NDUsCiAgICAgICAgMjY0NzgxNjExMSwKICAgICAgICA4MTQ3MDk5NywKICAgICAgICAxOTQzODAzNTIzLAogICAgICAgIDM4MTQ5MTg5MzAsCiAgICAgICAgMjQ4OTU5NjgwNCwKICAgICAgICAyMjUyNzQ0MzAsCiAgICAgICAgMjA1Mzc5MDM3NiwKICAgICAgICAzODI2MTc1NzU1LAogICAgICAgIDI0NjY5MDYwMTMsCiAgICAgICAgMTY3ODE2NzQzLAogICAgICAgIDIwOTc2NTEzNzcsCiAgICAgICAgNDAyNzU1MjU4MCwKICAgICAgICAyMjY1NDkwMzg2LAogICAgICAgIDUwMzQ0NDA3MiwKICAgICAgICAxNzYyMDUwODE0LAogICAgICAgIDQxNTA0MTcyNDUsCiAgICAgICAgMjE1NDEyOTM1NSwKICAgICAgICA0MjY1MjIyMjUsCiAgICAgICAgMTg1MjUwNzg3OSwKICAgICAgICA0Mjc1MzEzNTI2LAogICAgICAgIDIzMTIzMTc5MjAsCiAgICAgICAgMjgyNzUzNjI2LAogICAgICAgIDE3NDI1NTU4NTIsCiAgICAgICAgNDE4OTcwODE0MywKICAgICAgICAyMzk0ODc3OTQ1LAogICAgICAgIDM5NzkxNzc2MywKICAgICAgICAxNjIyMTgzNjM3LAogICAgICAgIDM2MDQzOTA4ODgsCiAgICAgICAgMjcxNDg2NjU1OCwKICAgICAgICA5NTM3Mjk3MzIsCiAgICAgICAgMTM0MDA3NjYyNiwKICAgICAgICAzNTE4NzE5OTg1LAogICAgICAgIDI3OTczNjA5OTksCiAgICAgICAgMTA2ODgyODM4MSwKICAgICAgICAxMjE5NjM4ODU5LAogICAgICAgIDM2MjQ3NDE4NTAsCiAgICAgICAgMjkzNjY3NTE0OCwKICAgICAgICA5MDYxODU0NjIsCiAgICAgICAgMTA5MDgxMjUxMiwKICAgICAgICAzNzQ3NjcyMDAzLAogICAgICAgIDI4MjUzNzk2NjksCiAgICAgICAgODI5MzI5MTM1LAogICAgICAgIDExODEzMzUxNjEsCiAgICAgICAgMzQxMjE3NzgwNCwKICAgICAgICAzMTYwODM0ODQyLAogICAgICAgIDYyODA4NTQwOCwKICAgICAgICAxMzgyNjA1MzY2LAogICAgICAgIDM0MjMzNjkxMDksCiAgICAgICAgMzEzODA3ODQ2NywKICAgICAgICA1NzA1NjIyMzMsCiAgICAgICAgMTQyNjQwMDgxNSwKICAgICAgICAzMzE3MzE2NTQyLAogICAgICAgIDI5OTg3MzM2MDgsCiAgICAgICAgNzMzMjM5OTU0LAogICAgICAgIDE1NTUyNjE5NTYsCiAgICAgICAgMzI2ODkzNTU5MSwKICAgICAgICAzMDUwMzYwNjI1LAogICAgICAgIDc1MjQ1OTQwMywKICAgICAgICAxNTQxMzIwMjIxLAogICAgICAgIDI2MDcwNzE5MjAsCiAgICAgICAgMzk2NTk3MzAzMCwKICAgICAgICAxOTY5OTIyOTcyLAogICAgICAgIDQwNzM1NDk4LAogICAgICAgIDI2MTc4MzcyMjUsCiAgICAgICAgMzk0MzU3NzE1MSwKICAgICAgICAxOTEzMDg3ODc3LAogICAgICAgIDgzOTA4MzcxLAogICAgICAgIDI1MTIzNDE2MzQsCiAgICAgICAgMzgwMzc0MDY5MiwKICAgICAgICAyMDc1MjA4NjIyLAogICAgICAgIDIxMzI2MTExMiwKICAgICAgICAyNDYzMjcyNjAzLAogICAgICAgIDM4NTU5OTAyODUsCiAgICAgICAgMjA5NDg1NDA3MSwKICAgICAgICAxOTg5NTg4ODEsCiAgICAgICAgMjI2MjAyOTAxMiwKICAgICAgICA0MDU3MjYwNjEwLAogICAgICAgIDE3NTkzNTk5OTIsCiAgICAgICAgNTM0NDE0MTkwLAogICAgICAgIDIxNzY3MTg1NDEsCiAgICAgICAgNDEzOTMyOTExNSwKICAgICAgICAxODczODM2MDAxLAogICAgICAgIDQxNDY2NDU2NywKICAgICAgICAyMjgyMjQ4OTM0LAogICAgICAgIDQyNzkyMDAzNjgsCiAgICAgICAgMTcxMTY4NDU1NCwKICAgICAgICAyODUyODExMTYsCiAgICAgICAgMjQwNTgwMTcyNywKICAgICAgICA0MTY3MjE2NzQ1LAogICAgICAgIDE2MzQ0Njc3OTUsCiAgICAgICAgMzc2MjI5NzAxLAogICAgICAgIDI2ODUwNjc4OTYsCiAgICAgICAgMzYwODAwNzQwNiwKICAgICAgICAxMzA4OTE4NjEyLAogICAgICAgIDk1NjU0MzkzOCwKICAgICAgICAyODA4NTU1MTA1LAogICAgICAgIDM0OTU5NTgyNjMsCiAgICAgICAgMTIzMTYzNjMwMSwKICAgICAgICAxMDQ3NDI3MDM1LAogICAgICAgIDI5MzI5NTk4MTgsCiAgICAgICAgMzY1NDcwMzgzNiwKICAgICAgICAxMDg4MzU5MjcwLAogICAgICAgIDkzNjkxOGUzLAogICAgICAgIDI4NDc3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CA9IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiBfY3JjMzIuYXBwbHkobnVsbCwgYXJndW1lbnRzKTsKICAgICAgfTsKICAgICAgY3JjMzIyLnVuc2lnbmVkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIF9jcmMzMi5hcHBseShudWxsLCBhcmd1bWVudHMpID4+PiAwOwogICAgICB9OwogICAgICBtb2R1bGUuZXhwb3J0cyA9IGNyYzMyMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL29iamVjdC5lbnRyaWVzLXBvbnlmaWxsQDEuMC4xL25vZGVfbW9kdWxlcy9vYmplY3QuZW50cmllcy1wb255ZmlsbC9lbnRyaWVzLmpzCiAgdmFyIHJlcXVpcmVfZW50cmllcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9vYmplY3QuZW50cmllcy1wb255ZmlsbEAxLjAuMS9ub2RlX21vZHVsZXMvb2JqZWN0LmVudHJpZXMtcG9ueWZpbGwvZW50cmllcy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgaGFzID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICB2YXIgaXNFbnVtZXJhYmxlID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICBmdW5jdGlvbiBlbnRyaWVzMihvYmopIHsKICAgICAgICBpZiAob2JqID09IG51bGwpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIk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iua2V5LCBkZXNjcmlwdG9yKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2NyZWF0ZUNsYXNzKENvbnN0cnVjdG9yLCBwcm90b1Byb3BzLCBzdGF0aWNQcm9wcykgewogICAgICAgIGlmIChwcm90b1Byb3BzKQogICAgICAgICAgX2RlZmluZVByb3BlcnRpZXMoQ29uc3RydWN0b3IucHJvdG90eXBlLCBwcm90b1Byb3BzKTsKICAgICAgICBpZiAoc3RhdGljUHJvcHMpCiAgICAgICAgICBfZGVmaW5lUHJvcGVydGllcyhDb25zdHJ1Y3Rvciwgc3RhdGljUHJvcHMpOwogICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShDb25zdHJ1Y3RvciwgInByb3RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyID09PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBSZWZlcmVuY2VFcnJvcigidGhpcyBoYXNuJ3QgYmVlbiBpbml0aWFsaXNlZCAtIHN1cGVyKCkgaGFzbid0IGJlZW4gY2FsbGVkIik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzZWxmMjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybihzZWxmMiwgY2FsbCkgewogICAgICAgIGlmIChjYWxsICYmICh0eXBlb2YgY2FsbCA9PT0gIm9iamVjdCIgfHwgdHlwZW9mIGNhbGwgPT09ICJmdW5jdGlvbiIpKSB7CiAgICAgICAgICByZXR1cm4gY2FsbDsKICAgICAgICB9IGVsc2UgaWYgKGNhbGwgIT09IHZvaWQgMCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiRGVyaXZlZCBjb25zdHJ1Y3RvcnMgbWF5IG9ubHkgcmV0dXJuIG9iamVjdCBvciB1bmRlZmluZWQiKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9hc3NlcnRUaGlzSW5p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9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9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XF1ZXN0ICYmICFSZXF1ZXN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eSgic2lnbmFsIikgfHwgX19GT1JDRV9JTlNUQUxMX0FCT1JUQ09OVFJPTExFUl9QT0xZRklMTCkgewogICAgICAgICAgUmVxdWVzdCA9IGZ1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2gyOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWxGZXRjaChpbnB1dC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5zaWduYWxzLmFkZChzaWduYWwpOwogICAgICAgICAgaWYgKHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgKCkgPT4gewogICAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaGFuZGxlQWJvcnRlZChzaWduYWwpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscy5kZWxldGUoc2lnbmFsKTsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbHMuc2l6ZSA9PT0gMCkgewogICAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2lnbmFsKCkgewogICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRDb250cm9sbGVyLnNpZ25hbDsKICAgICAgICB9CiAgICAgICAgYWJvcnQoKSB7CiAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0cy5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZWdhdGVTdGF0dXNSZXBvcnRlci5qcwogIHZhciByZXF1aXJlX0FnZ3JlZ2F0ZVN0YXR1c1JlcG9ydGVyID0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GlmICh0aGlzLmNhY2hlLmdldChrZXkpID09PSBlbnRyeSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmaWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgIC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Y2hlMi5jaGVja1NpbmdsZVByb21pc2UoY2FjaGVFbnRyeS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5maWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gZGVsZXRlQ291bnQ7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzLmRlZmF1bHQgPSBBYm9ydGFibGVQcm9taXNlQ2FjaGUyOwogICAgfQogIH0pOw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i4wLjAvbm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUzID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKG9wdGlvbnMgPSB7fSkgewogICAgICAgICAgaWYgKCEob3B0aW9ucy5tYXhTaXplICYmIG9wdGlvbnMubWF4U2l6ZSA+IDApKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImBtYXhTaXplYCBtdXN0IGJlIGEgbnVtYmVyIGdyZWF0ZXIgdGhhbiAwIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLm1heFNpemUgPSBvcHRpb25zLm1heFNpemU7CiAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgdGhpcy5fc2l6ZSsrOwogICAgICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0KGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICBjb25zdCB2YWx1ZSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSkgfHwgdGhpcy5vbGRDYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgcGVlayhrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlbGV0ZShrZXkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgaWYgKGRlbGV0ZWQpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZS0tOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZGVsZXRlKGtleSkgfHwgZGVsZXRlZDsKICAgICAgICB9CiAgICAgICAgY2xlYXIoKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgKmtleXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFtrZXldIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQga2V5OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqdmFsdWVzKCkgewogICAgICAgICAgZm9yIChjb25zdCBbLCB2YWx1ZV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKltTeW1ib2wuaXRlcmF0b3JdKCkgewogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLm9sZENhY2hlKSB7CiAgICAgICAgICAgIGNvbnN0IFtrZXldID0gaXRlbTsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQgc2l6ZSgpIHsKICAgICAgICAgIGxldCBvbGRDYWNoZVNpemUgPSAwOwogICAgICAgICAgZm9yIChjb25zdCBrZXkgb2YgdGhpcy5vbGRDYWNoZS5rZXlzKCkpIHsKICAgICAgICAgICAgaWYgKCF0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgICAgb2xkQ2FjaGVTaXplKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLl9zaXplICsgb2xkQ2FjaGVTaXplOwogICAgICAgIH0KIC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gIGFycmF5QnVmZmVyOiAiQXJyYXlCdWZmZXIiIGluIHNlbGYyCiAgICAgICAgICB9OwogICAgICAgICAgZnVuY3Rpb24gaXNEYXRhVmlldyhvYmopIHsKICAgICAgICAgICAgcmV0dXJuIG9iaiAmJiBEYXRhVmlldy5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihvYmopOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN1cHBvcnQuYXJyYXlCdWZmZXIpIHsKICAgICAgICAgICAgdmFyIHZpZXdDbGFzc2VzID0gWwogICAgICAgICAgICAgICJbb2JqZWN0IEludDhBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IFVpbnQ4QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50OENsYW1wZWRBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDE2QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MTZBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDMyQXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0NjRBcnJheV0iCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHZhciBpc0FycmF5QnVmZmVyVmlldyA9IEFycmF5QnVmZmVyLmlzVmlldyB8fCBmdW5jdGlvbihvYmopIHsKICAgICAgICAgICAgICByZXR1cm4gb2JqICYmIHZpZXdDbGFzc2VzLmluZGV4T2YoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaikpID4gLTE7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBub3JtYWxpemVOYW1lKG5hbWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiBuYW1lICE9PSAic3RyaW5nIikgewogICAgICAgICAgICAgIG5hbWUgPSBTdHJpbmcobmFtZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKC9bXmEtejAtOVwtIyQlJicqKy5eX2B8fl0vaS50ZXN0KG5hbWUpKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiSW52YWxpZCBjaGFyYWN0ZXIgaW4gaGVhZGVyIGZpZWxkIG5hbWUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gbm9ybWFsaXplVmFsdWUodmFsdWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB2YWx1ZSA9IFN0cmluZyh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gaXRlcmF0b3JGb3IoaXRlbXMpIHsKICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gewogICAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gaXRlbXMuc2hpZnQoKTsKICAgICAgICAgICAgICAgIHJldHVybiB7IGRvbmU6IHZhbHVlID09PSB2b2lkIDAsIHZhbHVlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5pdGVyYWJsZSkgewogICAgICAgICAgICAgIGl0ZXJhdG9yW1N5bWJvbC5pdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEhlYWRlcnMoaGVhZGVycykgewogICAgICAgICAgICB0aGlzLm1hcCA9IHt9OwogICAgICAgICAgICBpZiAoaGVhZGVycyBpbnN0YW5jZW9mIEhlYWRlcnMpIHsKICAgICAgICAgICAgICBoZWFkZXJzLmZvckVhY2goZnVuY3Rpb24odmFsdWUsIG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIHZhbHVlKTsKICAgICAgICAgICAgICB9LCB0aGlzKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGhlYWRlcnMpKSB7CiAgICAgICAgICAgICAgaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKGhlYWRlcikgewogICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaGVhZGVyWzBdLCBoZWFkZXJbMV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRlcnMpIHsKICAgICAgICAgICAgICBPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhoZWFkZXJzKS5mb3JFYWNoKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIGhlYWRlcnNbbmFtZV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5hcHBlbmQgPSBmdW5jdGlvbihuYW1lLCB2YWx1ZSkgewogICAgICAgICAgICBuYW1lID0gbm9ybWFsaXplTmFtZShuYW1lKTsKICAgICAgICAgICAgdmFsdWUgPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICAgIHZhciBvbGRWYWx1ZSA9IHRoaXMubWFwW25hbWVdOwogICAgICAgICAgICB0aGlzLm1hcFtuYW1lXSA9IG9sZFZhbHVlID8gb2xkVmFsdWUgKyAiLCAiICsgdmFsdWUgOiB2YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZVsiZGVsZXRlIl0gPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm1hcFtub3JtYWxpemVOYW1lKG5hbWUpXTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIG5hbWUgPSBub3JtYWxpemVOYW1lKG5hbWUpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5oYXMobmFtZSkgPyB0aGlzLm1hcFtuYW1lXSA6IG51bGw7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24obmFtZSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5tYXAuaGFzT3duUHJvcGVydHkobm9ybWFsaXplTmFtZShuYW1lKSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAgICAgICAgdGhpcy5tYXBbbm9ybWFsaXplTmFtZShuYW1lKV0gPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uKGNhbGxiYWNrLCB0aGlzQXJnKSB7CiAgICAgICAgICAgIGZvciAodmFyIG5hbWUgaW4gdGhpcy5tYXApIHsKICAgICAgICAgICAgICBpZiAodGhpcy5tYXAuaGFzT3duUHJvcGVydHkobmFtZSkpIHsKICAgICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwodGhpc0FyZywgdGhpcy5tYXBbbmFtZV0sIG5hbWUsIHRoaXMpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmtleXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2gobmFtZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLnZhbHVlcyA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgaXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgICAgaXRlbXMucHVzaCh2YWx1ZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmVudHJpZXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2goW25hbWUsIHZhbHVlXSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChzdXBwb3J0Lml0ZXJhYmxlKSB7CiAgICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlW1N5bWJvbC5pdGVyYXRvcl0gPSBIZWFkZXJzLnByb3RvdHlwZS5lbnRyaWVzOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gY29uc3VtZWQoYm9keSkgewogICAgICAgICAgICBpZiAoYm9keS5ib2R5VXNlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYm9keS5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmaWxlUmVhZGVyUmVhZHkocmVhZGVyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICByZWFkZXIub25sb2FkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKHJlYWRlci5yZXN1bHQpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgcmVhZGVyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChyZWFkZXIuZXJyb3IpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVhZEJsb2JBc0FycmF5QnVmZmVyKGJsb2IpIHsKICAgICAgICAgICAgdmFyIHJlYWRlciA9IG5ldyBGaWxlUmVhZGVyKCk7CiAgICAgICAgICAgIHZhciBwcm9taXNlID0gZmlsZVJlYWRlclJlYWR5KHJlYWRlcik7CiAgICAgICAgICAgIHJlYWRlci5yZWFkQXNBcnJheUJ1ZmZlcihibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQmxvYkFzVGV4dChibG9iKSB7CiAgICAgICAgICAgIHZhciByZWFkZXIgPSBuZXcgRmlsZVJlYWRlcigpOwogICAgICAgICAgICB2YXIgcHJvbWlzZSA9IGZpbGVSZWFkZXJSZWFkeShyZWFkZXIpOwogICAgICAgICAgICByZWFkZXIucmVhZEFzVGV4dChibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQXJyYXlCdWZmZXJBc1RleHQoYnVmKSB7CiAgICAgICAgICAgIHZhciB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYnVmKTsKICAgICAgICAgICAgdmFyIGNoYXJzID0gbmV3IEFycmF5KHZpZXcubGVuZ3RoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2aWV3Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgY2hhcnNbaV0gPSBTdHJpbmcuZnJvbUNoYXJDb2RlKHZpZXdbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBjaGFycy5qb2luKCIiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIGJ1ZmZlckNsb25lKGJ1ZikgewogICAgICAgICAgICBpZiAoYnVmLnNsaWNlKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGJ1Zi5zbGljZSgwKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YXIgdmlldyA9IG5ldyBVaW50OEFycmF5KGJ1Zi5ieXRlTGVuZ3RoKTsKICAgICAgICAgICAgICB2aWV3LnNldChuZXcgVWludDhBcnJheShidWYpKTsKICAgICAgICAgICAgICByZXR1cm4gdmlldy5idWZmZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEJvZHkoKSB7CiAgICAgICAgICAgIHRoaXMuYm9keVVzZWQgPSBmYWxzZTsKICAgICAgICAgICAgdGhpcy5faW5pdEJvZHkgPSBmdW5jdGlvbihib2R5KSB7CiAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBib2R5OwogICAgICAgICAgICAgIGlmICghYm9keSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSAiIjsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBib2R5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSBib2R5OwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5ibG9iICYmIEJsb2IucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlCbG9iID0gYm9keTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN1cHBvcnQuZm9ybURhdGEgJiYgRm9ybURhdGEucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlGb3JtRGF0YSA9IGJvZHk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlUZXh0ID0gYm9keS50b1N0cmluZygpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5hcnJheUJ1ZmZlciAmJiBzdXBwb3J0LmJsb2IgJiYgaXNEYXRhVmlldyhib2R5KSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keUFycmF5QnVmZmVyID0gYnVmZmVyQ2xvbmUoYm9keS5idWZmZXIpOwogICAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBuZXcgQmxvYihbdGhpcy5fYm9keUFycmF5QnVmZmVyXSk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LmFycmF5QnVmZmVyICYmIChBcnJheUJ1ZmZlci5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihib2R5KSB8fCBpc0FycmF5QnVmZmVyVmlldyhib2R5KSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlBcnJheUJ1ZmZlciA9IGJ1ZmZlckNsb25lKGJvZHkpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLl9ib2R5VGV4dCA9IGJvZHkgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoYm9keSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmICghdGhpcy5oZWFkZXJzLmdldCgiY29udGVudC10eXBlIikpIHsKICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgYm9keSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ib2R5QmxvYiAmJiB0aGlzLl9ib2R5QmxvYi50eXBlKSB7CiAgICAgICAgICAgICAgICAgIHRoaXMuaGVhZGVycy5zZXQoImNvbnRlbnQtdHlwZSIsIHRoaXMuX2JvZHlCbG9iLnR5cGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5ibG9iKSB7CiAgICAgICAgICAgICAgdGhpcy5ibG9iID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICAgIGlmIChyZWplY3RlZCkgewogICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0ZWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUJsb2IpIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5QmxvYik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlBcnJheUJ1ZmZlcikgewogICAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKG5ldyBCbG9iKFt0aGlzLl9ib2R5QXJyYXlCdWZmZXJdKSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNvdWxkIG5vdCByZWFkIEZvcm1EYXRhIGJvZHkgYXMgYmxvYiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShuZXcgQmxvYihbdGhpcy5fYm9keVRleHRdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB0aGlzLmFycmF5QnVmZmVyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiBjb25zdW1lZCh0aGlzKSB8fCBQcm9taXNlLnJlc29sdmUodGhpcy5fYm9keUFycmF5QnVmZmVyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmJsb2IoKS50aGVuKHJlYWRCbG9iQXNBcnJheUJ1ZmZlcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnRleHQgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICBpZiAocmVqZWN0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHRoaXMuX2JvZHlCbG9iKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZEJsb2JBc1RleHQodGhpcy5fYm9keUJsb2IpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHJlYWRBcnJheUJ1ZmZlckFzVGV4dCh0aGlzLl9ib2R5QXJyYXlCdWZmZXIpKTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjb3VsZCBub3QgcmVhZCBGb3JtRGF0YSBib2R5IGFzIHRleHQiKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5VGV4dCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5mb3JtRGF0YSkgewogICAgICAgICAgICAgIHRoaXMuZm9ybURhdGEgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnRleHQoKS50aGVuKGRlY29kZSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmpzb24gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy50ZXh0KCkudGhlbihKU09OLnBhcnNlKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbWV0aG9kcyA9IFsiREVMRVRFIiwgIkdFVCIsICJIRUFEIiwgIk9QVElPTlMiLCAiUE9TVCIsICJQVVQiXTsKICAgICAgICAgIGZ1bmN0aW9uIG5vcm1hbGl6ZU1ldGhvZChtZXRob2QpIHsKICAgICAgICAgICAgdmFyIHVwY2FzZWQgPSBtZXRob2QudG9VcHBlckNhc2UoKTsKICAgICAgICAgICAgcmV0dXJuIG1ldGhvZHMuaW5kZXhPZih1cGNhc2VkKSA+IC0xID8gdXBjYXNlZCA6IG1ldGhvZDsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIFJlcXVlc3QoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgICAgIHZhciBib2R5ID0gb3B0aW9ucy5ib2R5OwogICAgICAgICAgICBpZiAoaW5wdXQgaW5zdGFuY2VvZiBSZXF1ZXN0KSB7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmJvZHlVc2VkKSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy51cmwgPSBpbnB1dC51cmw7CiAgICAgICAgICAgICAgdGhpcy5jcmVkZW50aWFscyA9IGlucHV0LmNyZWRlbnRpYWxzOwogICAgICAgICAgICAgIGlmICghb3B0aW9ucy5oZWFkZXJzKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhpbnB1dC5oZWFkZXJzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBpbnB1dC5tZXRob2Q7CiAgICAgICAgICAgICAgdGhpcy5tb2RlID0gaW5wdXQubW9kZTsKICAgICAgICAgICAgICB0aGlzLnNpZ25hbCA9IGlucHV0LnNpZ25hbDsKICAgICAgICAgICAgICBpZiAoIWJvZHkgJiYgaW5wdXQuX2JvZHlJbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIGJvZHkgPSBpbnB1dC5fYm9keUluaXQ7CiAgICAgICAgICAgICAgICBpbnB1dC5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMudXJsID0gU3RyaW5nKGlucHV0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNyZWRlbnRpYWxzID0gb3B0aW9ucy5jcmVkZW50aWFscyB8fCB0aGlzLmNyZWRlbnRpYWxzIHx8ICJzYW1lLW9yaWdpbiI7CiAgICAgICAgICAgIGlmIChvcHRpb25zLmhlYWRlcnMgfHwgIXRoaXMuaGVhZGVycykgewogICAgICAgICAgICAgIHRoaXMuaGVhZGVycyA9IG5ldyBIZWFkZXJzKG9wdGlvbnMuaGVhZGVycyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBub3JtYWxpemVNZXRob2Qob3B0aW9ucy5tZXRob2QgfHwgdGhpcy5tZXRob2QgfHwgIkdFVCIpOwogICAgICAgICAgICB0aGlzLm1vZGUgPSBvcHRpb25zLm1vZGUgfHwgdGhpcy5tb2RlIHx8IG51bGw7CiAgICAgICAgICAgIHRoaXMuc2lnbmFsID0gb3B0aW9ucy5zaWduYWwgfHwgdGhpcy5zaWduYWw7CiAgICAgICAgICAgIHRoaXMucmVmZXJyZXIgPSBudWxsOwogICAgICAgICAgICBpZiAoKHRoaXMubWV0aG9kID09PSAiR0VUIiB8fCB0aGlzLm1ldGhvZCA9PT0gIkhFQUQiKSAmJiBib2R5KSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiQm9keSBub3QgYWxsb3dlZCBmb3IgR0VUIG9yIEhFQUQgcmVxdWVzdHMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5KTsKICAgICAgICAgIH0KICAgICAgICAgIFJlcXVlc3QucHJvdG90eXBlLmNsb25lID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUmVxdWVzdCh0aGlzLCB7IGJvZHk6IHRoaXMuX2JvZHlJbml0IH0pOwogICAgICAgICAgfTsKICAgICAgICAgIGZ1bmN0aW9uIGRlY29kZShib2R5KSB7CiAgICAgICAgICAgIHZhciBmb3JtID0gbmV3IEZvcm1EYXRhKCk7CiAgICAgICAgICAgIGJvZHkudHJpbSgpLnNwbGl0KCImIikuZm9yRWFjaChmdW5jdGlvbihieXRlcykgewogICAgICAgICAgICAgIGlmIChieXRlcykgewogICAgICAgICAgICAgICAgdmFyIHNwbGl0ID0gYnl0ZXMuc3BsaXQoIj0iKTsKICAgICAgICAgICAgICAgIHZhciBuYW1lID0gc3BsaXQuc2hpZnQoKS5yZXBsYWNlKC9cKy9nLCAiICIpOwogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc3BsaXQuam9pbigiPSIpLnJlcGxhY2UoL1wrL2csICIgIik7CiAgICAgICAgICAgICAgICBmb3JtLmFwcGVuZChkZWNvZGVVUklDb21wb25lbnQobmFtZSksIGRlY29kZVVSSUNvbXBvbmVudCh2YWx1ZSkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiBmb3JtOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcGFyc2VIZWFkZXJzKHJhd0hlYWRlcnMpIHsKICAgICAgICAgICAgdmFyIGhlYWRlcnMgPSBuZXcgSGVhZGVycygpOwogICAgICAgICAgICB2YXIgcHJlUHJvY2Vzc2VkSGVhZGVycyA9IHJhd0hlYWRlcnMucmVwbGFjZSgvXHI/XG5bXHQgXSsvZywgIiAiKTsKICAgICAgICAgICAgcHJlUHJvY2Vzc2VkSGVhZGVycy5zcGxpdCgvXHI/XG4vKS5mb3JFYWNoKGZ1bmN0aW9uKGxpbmUpIHsKICAgICAgICAgICAgICB2YXIgcGFydHMgPSBsaW5lLnNwbGl0KCI6Iik7CiAgICAgICAgICAgICAgdmFyIGtleSA9IHBhcnRzLnNoaWZ0KCkudHJpbSgpOwogICAgICAgICAgICAgIGlmIChrZXkpIHsKICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHBhcnRzLmpvaW4oIjoiKS50cmltKCk7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmFwcGVuZChrZXksIHZhbHVlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaGVhZGVyczsKICAgICAgICAgIH0KICAgICAgICAgIEJvZHkuY2FsbChSZXF1ZXN0LnByb3RvdHlwZSk7CiAgICAgICAgICBmdW5jdGlvbiBSZXNwb25zZShib2R5SW5pdCwgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoIW9wdGlvbnMpIHsKICAgICAgICAgICAgICBvcHRpb25zID0ge307CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy50eXBlID0gImRlZmF1bHQiOwogICAgICAgICAgICB0aGlzLnN0YXR1cyA9IG9wdGlvbnMuc3RhdHVzID09PSB2b2lkIDAgPyAyMDAgOiBvcHRpb25zLnN0YXR1czsKICAgICAgICAgICAgdGhpcy5vayA9IHRoaXMuc3RhdHVzID49IDIwMCAmJiB0aGlzLnN0YXR1cyA8IDMwMDsKICAgICAgICAgICAgdGhpcy5zdGF0dXNUZXh0ID0gInN0YXR1c1RleHQiIGluIG9wdGlvbnMgPyBvcHRpb25zLnN0YXR1c1RleHQgOiAiT0siOwogICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhvcHRpb25zLmhlYWRlcnMpOwogICAgICAgICAgICB0aGlzLnVybCA9IG9wdGlvbnMudXJsIHx8ICIiOwogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5SW5pdCk7CiAgICAgICAgICB9CiAgICAgICAgICBCb2R5LmNhbGwoUmVzcG9uc2UucHJvdG90eXBlKTsKICAgICAgICAgIFJlc3BvbnNlLnByb3RvdHlwZS5jbG9uZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKHRoaXMuX2JvZHlJbml0LCB7CiAgICAgICAgICAgICAgc3RhdHVzOiB0aGlzLnN0YXR1cywKICAgICAgICAgICAgICBzdGF0dXNUZXh0OiB0aGlzLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgaGVhZGVyczogbmV3IEhlYWRlcnModGhpcy5oZWFkZXJzKSwKICAgICAgICAgICAgICB1cmw6IHRoaXMudXJsCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfTsKICAgICAgICAgIFJlc3BvbnNlLmVycm9yID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciByZXNwb25zZSA9IG5ldyBSZXNwb25zZShudWxsLCB7IHN0YXR1czogMCwgc3RhdHVzVGV4dDogIiIgfSk7CiAgICAgICAgICAgIHJlc3BvbnNlLnR5cGUgPSAiZXJyb3IiOwogICAgICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICAgICAgICB9OwogICAgICAgICAgdmFyIHJlZGlyZWN0U3RhdHVzZXMgPSBbMzAxLCAzMDIsIDMwMywgMzA3LCAzMDhdOwogICAgICAgICAgUmVzcG9uc2UucmVkaXJlY3QgPSBmdW5jdGlvbih1cmwsIHN0YXR1cykgewogICAgICAgICAgICBpZiAocmVkaXJlY3RTdGF0dXNlcy5pbmRleE9mKHN0YXR1cykgPT09IC0xKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkludmFsaWQgc3RhdHVzIGNvZGUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKG51bGwsIHsgc3RhdHVzLCBoZWFkZXJzOiB7IGxvY2F0aW9uOiB1cmwgfSB9KTsKICAgICAgICAgIH07CiAgICAgICAgICBleHBvcnRzMi5ET01FeGNlcHRpb24gPSBzZWxmMi5ET01FeGNlcHRpb247CiAgICAgICAgICB0cnkgewogICAgICAgICAgICBuZXcgZXhwb3J0czIuRE9NRXhjZXB0aW9uKCk7CiAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZXhwb3J0czIuRE9NRXhjZXB0aW9uID0gZnVuY3Rpb24obWVzc2FnZSwgbmFtZSkgewogICAgICAgICAgICAgIHRoaXMubWVzc2FnZSA9IG1lc3NhZ2U7CiAgICAgICAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICAgICAgICB2YXIgZXJyb3IgPSBFcnJvcihtZXNzYWdlKTsKICAgICAgICAgICAgICB0aGlzLnN0YWNrID0gZXJyb3Iuc3RhY2s7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKEVycm9yLnByb3RvdHlwZSk7CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUuY29uc3RydWN0b3IgPSBleHBvcnRzMi5ET01FeGNlcHRpb247CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmZXRjaDIoaW5wdXQsIGluaXQyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICB2YXIgcmVxdWVzdCA9IG5ldyBSZXF1ZXN0KGlucHV0LCBpbml0Mik7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsICYmIHJlcXVlc3Quc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QobmV3IGV4cG9ydHMyLkRPTUV4Y2VwdGlvbigiQWJvcnRlZCIsICJBYm9ydEVycm9yIikpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgZnVuY3Rpb24gYWJvcnRYaHIoKSB7CiAgICAgICAgICAgICAgICB4aHIuYWJvcnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgeGhyLm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIG9wdGlvbnMgPSB7CiAgICAgICAgICAgICAgICAgIHN0YXR1czogeGhyLnN0YXR1cywKICAgICAgICAgICAgICAgICAgc3RhdHVzVGV4dDogeGhyLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHBhcnNlSGVhZGVycyh4aHIuZ2V0QWxsUmVzcG9uc2VIZWFkZXJzKCkgfHwgIiIpCiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgb3B0aW9ucy51cmwgPSAicmVzcG9uc2VVUkwiIGluIHhociA/IHhoci5yZXNwb25zZVVSTCA6IG9wdGlvbnMuaGVhZGVycy5nZXQoIlgtUmVxdWVzdC1VUkwiKTsKICAgICAgICAgICAgICAgIHZhciBib2R5ID0gInJlc3BvbnNlIiBpbiB4aHIgPyB4aHIucmVzcG9uc2UgOiB4aHIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgcmVzb2x2ZShuZXcgUmVzcG9uc2UoYm9keSwgb3B0aW9ucykpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChuZXcgVHlwZUVycm9yKCJOZXR3b3JrIHJlcXVlc3QgZmFpbGVkIikpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9udGltZW91dCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBUeXBlRXJyb3IoIk5ldHdvcmsgcmVxdWVzdCBmYWlsZWQiKSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB4aHIub25hYm9ydCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBleHBvcnRzMi5ET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpKTsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHhoci5vcGVuKHJlcXVlc3QubWV0aG9kLCByZXF1ZXN0LnVybCwgdHJ1ZSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3QuY3JlZGVudGlhbHMgPT09ICJpbmNsdWRlIikgewogICAgICAgICAgICAgICAgeGhyLndpdGhDcmVkZW50aWFscyA9IHRydWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXF1ZXN0LmNyZWRlbnRpYWxzID09PSAib21pdCIpIHsKICAgICAgICAgICAgICAgIHhoci53aXRoQ3JlZGVudGlhbHMgPSBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKCJyZXNwb25zZVR5cGUiIGluIHhociAmJiBzdXBwb3J0LmJsb2IpIHsKICAgICAgICAgICAgICAgIHhoci5yZXNwb25zZVR5cGUgPSAiYmxvYiI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHJlcXVlc3QuaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcihuYW1lLCB2YWx1ZSk7CiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsKSB7CiAgICAgICAgICAgICAgICByZXF1ZXN0LnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGFib3J0WGhyKTsKICAgICAgICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgaWYgKHhoci5yZWFkeVN0YXRlID09PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdC5zaWduYWwucmVtb3ZlRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCBhYm9ydFhocik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHhoci5zZW5kKHR5cGVvZiByZXF1ZXN0Ll9ib2R5SW5pdCA9PT0gInVuZGVmaW5lZCIgPyBudWxsIDogcmVxdWVzdC5fYm9keUluaXQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIGZldGNoMi5wb2x5ZmlsbCA9IHRydWU7CiAgICAgICAgICBpZiAoIXNlbGYyLmZldGNoKSB7CiAgICAgICAgICAgIHNlbGYyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgICBzZWxmMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgICAgc2VsZjIuUmVxdWVzdCA9IFJlcXVlc3Q7CiAgICAgICAgICAgIHNlbGYyLlJlc3BvbnNlID0gUmVzcG9uc2U7CiAgICAgICAgICB9CiAgICAgICAgICBleHBvcnRzMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgIGV4cG9ydHMyLlJlcXVlc3QgPSBSZXF1ZXN0OwogICAgICAgICAgZXhwb3J0czIuUmVzcG9uc2UgPSBSZXNwb25zZTsKICAgICAgICAgIGV4cG9ydHMyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KGV4cG9ydHMyLCAiX19lc01vZHVsZSIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgICAgICByZXR1cm4gZXhwb3J0czI7CiAgICAgICAgfSh7fSk7CiAgICAgIH0pKHR5cGVvZiBzZWxmICE9PSAidW5kZWZpbmVkIiA/IHNlbGYgOiBleHBvcnRzKTsKICAgIH0KICB9KTsKCiAgLy8gc3JjL2RhdGEtZmV0Y2hlcnMvYmFtL2JhbS13b3JrZXIudHM/d29ya2VyJmlubGluZT93b3JrZXJfZmlsZQogIGluaXRfYnVmZmVyX3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GFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK2JhbUAxLjEuMTgvbm9kZV9tb2R1bGVzL0BnbW9kL2JhbS9lc20vYmFpLmpzCiAgdmFyIEJBSV9NQUdJQyA9IDIxNTc4MDUwOwogIGZ1bmN0aW9uIHJvdW5kRG93bihuLCBtdWx0aXBsZSkgewogICAgcmV0dXJuIG4gLSBuICUgbXVsdGlwbGU7CiAgfQogIGZ1bmN0aW9uIHJvdW5kVXAobiwgbXVsdGlwbGUpIHsKICAgIHJldHVybiBuIC0gbiAlIG11bHRpcGxlICsgbXVsdGlwbGU7CiAgfQogIHZhciBCQUkgPSBjbGFzcyBleHRlbmRzIEluZGV4RmlsZSB7CiAgICBwYXJzZVBzZXVkb0JpbihieXRlcywgb2Zmc2V0KSB7CiAgICAgIGNvbnN0IGxpbmVDb3VudCA9IGxvbmdUb051bWJlcihpbXBvcnRfbG9uZy5kZWZhdWx0LmZyb21CeXRlc0xFKEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGJ5dGVzLCBvZmZzZXQgKyAxNiwgb2Zmc2V0ICsgMjQpLCB0cnVlKSk7CiAgICAgIHJldHVybiB7IGxpbmVDb3VudCB9OwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgcHJvbSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGNvbnN0IGluZGV4ID0gcHJvbS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpbmRleCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCByZXQgPSBpbmRleC5zdGF0cyB8fCB7fTsKICAgICAgcmV0dXJuIHJldC5saW5lQ291bnQgPT09IHZvaWQgMCA/IC0xIDogcmV0LmxpbmVDb3VudDsKICAgIH0KICAgIGZldGNoQmFpKG9wdHMgPSB7fSkgewogICAgICBpZiAoIXRoaXMuYmFpUCkgewogICAgICAgIHRoaXMuYmFpUCA9IHRoaXMuZmlsZWhhbmRsZS5yZWFkRmlsZShvcHRzKS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgdGhpcy5iYWlQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5iYWlQOwogICAgfQogICAgYXN5bmMgX3BhcnNlKCkgewogICAgICBjb25zdCBkYXRhID0geyBiYWk6IHRydWUsIG1heEJsb2NrU2l6ZTogMSA8PCAxNiB9OwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHRoaXMuZmV0Y2hCYWkoKTsKICAgICAgaWYgKGJ5dGVzLnJlYWRVSW50MzJMRSgwKSAhPT0gQkFJX01BR0lDKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJOb3QgYSBCQUkgZmlsZSIpOwogICAgICB9CiAgICAgIGRhdGEucmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSg0KTsKICAgICAgY29uc3QgZGVwdGggP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AgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIHRoaXMuX2ZpbmRGaXJzdERhdGEoZGF0YSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICBkYXRhLmluZGljZXNbaV0gPSB7IGJpbkluZGV4LCBsaW5lYXJJbmRleCwgc3RhdHMgfTsKICAgICAgfQogICAgICByZXR1cm4gZGF0YTsKICAgIH0KICAgIGFzeW5jIGluZGV4Q292KHNlcUlkL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lbnRQb3MgPSBsaW5lYXJJbmRleFtzIC8gdl0uYmxvY2tQb3NpdGlvbjsKICAgICAgZm9yIChsZXQgaSA9IHMgLyB2LCBqID0gMDsgaSA8IGUgLyB2OyBpKyssIGorKykgewogICAgICAgIGRlcHRoc1tqXSA9IHsKICAgICAgICAgIHNjb3JlOiBsaW5lYXJJbmRleFtpICsgMV0uYmxvY2tQb3NpdGlvbiAtIGN1cnJlbnRQb3MsCiAgICAgICAgICBzdGFydDogaSAqIHYsCiAgICAgICAgICBlbmQ6IGkgKiB2ICsgdgogICAgICAgIH07CiAgICAgICAgY3VycmVudFBvcyA9IGxpbmVhckluZGV4W2kgKyAxXS5ibG9ja1Bvc2l0aW9uOwogICAgICB9CiAgICAgIHJldHVybiBkZXB0aHMubWFwKChkKSA9PiB7CiAgICAgICAgcmV0dXJuIHsgLi4uZCwgc2NvcmU6IGQuc2NvcmUgKiBzdGF0cy5saW5lQ291bnQgLyB0b3RhbFNpemUgfTsKICAgICAgfSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBlbmQgLT0gMTsKICAgICAgcmV0dXJuIFsKICAgICAgICBbMCwgMF0sCiAgICAgICAgWzEgKyAoYmVnID4+IDI2KSwgMSArIChlbmQgPj4gMjYpXSwKICAgICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICAgIFs3MyArIChiZWcgPj4gMjApLCA3MyArIChlbmQgPj4gMjApXSwKICAgICAgICBbNTg1ICsgKGJlZyA+PiAxNyksIDU4NSArIChlbmQgPj4gMTcpXSwKICAgICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICAgIF07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZJZCwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgbmludHYgPSBiYS5saW5lYXJJbmRleC5sZW5ndGg7CiAgICAgIGxldCBsb3dlc3QgPSBudWxsOwogICAgICBjb25zdCBtaW5MaW4gPSBNYXRoLm1pbihtaW4gPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGNvbnN0IG1heExpbiA9IE1hdGgubWluKG1heCA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgZm9yIChsZXQgaSA9IG1pbkxpbjsgaSA8PSBtYXhMaW47ICsraSkgewogICAgICAgIGNvbnN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BvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcihgSFRUUCAke3Jlc3BvbnNlLnN0YXR1c30gZmV0Y2hpbmcgJHt0aGlzLnVybH1gKSwgewogICAgICAgICAgc3RhdHVzOiByZXNwb25zZS5zdGF0dXMKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IikgewogICAgICAgIHJldHVybiByZXNwb25zZS50ZXh0KCk7CiAgICAgIH0KICAgICAgaWYgKGVuY29kaW5nKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKGB1bnN1cHBvcnRlZCBlbmNvZGluZzogJHtlbmNvZGluZ31gKTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5nZXRCdWZmZX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mZmVyNCA9IF9fdG9Nb2R1bGUocmVxdWlyZV9idWZmZXIoKSk7CiAgdmFyIGltcG9ydF9wYWtvID0gX190b01vZHVsZShyZXF1aXJlX3Bha28oKSk7CiAgYXN5bmMgZnVuY3Rpb24gdW56aXAoaW5wdXREYXRhKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgbGV0IHBvcyA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGxldCB0b3RhbFNpemUgPSAwOwogICAgICBsZXQgaW5mbGF0b3I7CiAgICAgIGRvIHsKICAgICAgICBjb25zdCByZW1haW5pbmdJbnB1dCA9IGlucHV0RGF0YS5zdWJhcnJheShwb3MpOwogICAgICAgIGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgcG9zICs9IHN0cm0ubmV4dF9pbjsKICAgICAgICBjaHVua3NbaV0gPSBpbmZsYXRvci5yZXN1bHQ7CiAgICAgICAgdG90YWxTaXplICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgaSArPSAxOwogICAgICB9IHdoaWxlIChzdHJtLmF2YWlsX2luKTsKICAgICAgY29uc3QgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkodG90YWxTaXplKTsKICAgICAgZm9yIChsZXQgaTIgPSAwLCBvZmZzZXQgPSAwOyBpMiA8IGNodW5rcy5sZW5ndGg7IGkyKyspIHsKICAgICAgICByZXN1bHQuc2V0KGNodW5rc1tpMl0sIG9mZnNldCk7CiAgIC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lmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChvcmlnQ3BvcyA+PSBtYXh2LmJsb2NrUG9zaXRpb24pIHsKICAgICAgICAgIGNodW5rc1tpXSA9IGNodW5rc1tpXS5zdWJhcnJheSgwLCBtYXh2LmJsb2NrUG9zaXRpb24gPT09IG1pbnYuYmxvY2tQb3NpdGlvbiA/IG1heHYuZGF0YVBvc2l0aW9uIC0gbWludi5kYXRhUG9zaXRpb24gKyAxIDogbWF4di5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIGNwb3NpdGlvbnMucHVzaChjcG9zKTsKICAgICAgICAgIGRwb3NpdGlvbnMucHVzaChkcG9zKTsKICAgICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ub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vQGdtb2QvYmFtL2VzbS9jc2kuanMKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZklkKSB7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2UoKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgaWR4ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWlkeCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCB7IHN0YXRzIH0gPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmIChzdGF0cykgewogICAgICAgIHJldHVybiBzdGF0cy5saW5lQ291bnQ7CiAgICAgIH0KICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3YoKSB7CiAgICAgIHJldHVybiBbXTsKICAgIH0KICAgIHBhcnNlQXV4RGF0YShieXRlcywgb2Zmc2V0LCBhdXhMZW5ndGgpIHsKICAgICAgaWYgKGF1eExlbmd0aCA8IDMwKSB7CiAg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gICAgICAgYXdhaXQgYWJvcnRCcmVha1BvaW50KG9wdHMuc2lnbmFsKTsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRhdGEuaW5kaWNlc1tpXSA9IHsgYmluSW5kZXgsIHN0YXRzIH07CiAgICAgIH0KICAgICAgcmV0dXJuIGRhdGE7CiAgICB9CiAgICBwYXJzZVBzZXVkb0JpbihieXRlcywgb2Zmc2V0KSB7CiAgICAgIGNvbnN0IGxpbmVDb3VudCA9IGxvbmdUb051bWJlcihpbXBvcnRfbG9uZzMuZGVmYXVsdC5mcm9tQnl0ZXNMRShBcnJheS5wcm90b3R5cGUuc2xpY2UuY2FsbChieXRlcywgb2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZklkLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YSA9PT0gbnVsbCB8fCBpbmRleERhdGEgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYmlucy5sZW5ndGggPiB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JheS5yZWFkSW50MzJMRShzdGFydCArIDQpOwogICAgICB0aGlzLmRhdGEuc3RhcnQgPSBieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyA4KTsKICAgICAgdGhpcy5mbGFncyA9IChieXRlQXJyYXkucmVhZEludDMyTEUoc3RhcnQgKyAxNikgJiA0Mjk0OTAxNzYwKSA+PiAxNjsKICAgIH0KICAgIGdldChmaWVsZCkgewogICAgICBpZiAodGhpc1tmaWVsZF0pIHsKICAgICAgICBpZiAodGhpcy5kYXRhW2ZpZWxkXSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuZGF0YVtmaWVsZF07CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzW2ZpZWxkXSgpOwogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLl9nZXQoZmllbGQudG9Mb3dlckNhc2UoKSk7CiAgICB9CiAgICBlbmQoKSB7CiAgICAgIHJldHVybiB0aGlzLmdldCgic3RhcnQiKSArIHRoaXMuZ2V0KCJsZW5ndGhfb25fcmVmIik7CiAgICB9CiAgICBzZXFfaWQoKSB7CiAgICAgIHJldHVybiB0aGlzLl9yZWZJRDsKICAgIH0KICAgIF9nZXQoZmllbGQpIHsKICAgICAgaWYgKGZpZWxkIGluIHRoaXMuZGF0YSkgewogICAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgICB9CiAgICAgIHRoaXMuZGF0YVtmaWVsZF0gPSB0aGlzLl9wYXJzZVRhZyhmaWVsZCk7CiAgICAgIHJldHVybiB0aGlzLmRhdGFbZmllbGRdOwogICAgfQogICAgX3RhZ3MoKSB7CiAgICAgIHRoaXMuX3BhcnNlQWxsVGFncygpOwogICAgICBsZXQgdGFncyA9IFsic2VxIl07CiAgICAgIGlmICghdGhpcy5pc1NlZ21lbnRVbm1hcHBlZCgpKSB7CiAgICAgICAgdGFncy5wdXNoKCJzdGF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pOwogICAgICAgIHAgKz0gMzsKICAgICAgICBsZXQgdmFsdWU7CiAgICAgICAgc3dpdGNoICh0eXBlKSB7CiAgICAgICAgICBjYXNlICJBIjoKICAgICAgICAgICAgdmFsdWUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ5dGVBcnJheVtwXSk7CiAgICAgICAgICAgIHAgKz0gMTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJpIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJJIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZFVJbnQzMkxFKHApOwogICAgICAgICAgICBwICs9IDQ7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiYyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRJbnQ4KHApOwogICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRVSW50OChwKTsKICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgInMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgcCArPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgIlMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJmIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEZsb2F0TEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJaIjoKICAgICAgICAgIGNhc2UgIkgiOgogICAgICAgICAgICB2YWx1ZSA9ICIiOwogICAgICAgICAgICB3aGlsZSAocCA8PSBibG9ja0VuZCkgewogICAgICAgICAgICAgIGNvbnN0IGNjID0gYnl0ZUFycmF5W3ArK107CiAgICAgICAgICAgICAgaWYgKGNjID09PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShjYyk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQiI6IHsKICAgICAgICAgICAgdmFsdWUgPSAiIjsKICAgICAgICAgICAgY29uc3QgY2MgPSBieXRlQXJyYXlbcCsrXTsKICAgICAgICAgICAgY29uc3QgQnR5cGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGNjKTsKICAgICAgICAgICAgY29uc3QgbGltaXQgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiaSIpIHsKICAgICAgICAgICAgICBpZiAodGFnID09PSAiQ0ciKSB7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgICAgY29uc3QgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShwKTsKICAgICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJJIikgewogICAgICAgICAgICAgIGlmICh0YWcgPT09ICJDRyIpIHsKICAgICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgICBjb25zdCBjaWdvcCA9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAicyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9ICIsIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiUyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gImMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZEludDgocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gIkMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZFVJbnQ4KHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJmIikgewogICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gYnl0ZUFycmF5LnJlYWRGbG9hdExFKHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIGNvbnNvbGUud2FybihgVW5rbm93biBCQU0gdGFnIHR5cGUgJyR7dHlwZX0nLCB0YWdzIG1heSBiZSBpbmNvbXBsZXRlYCk7CiAgICAgICAgICAgIHZhbHVlID0gdm9pZCAwOwogICAgICAgICAgICBwID0gYmxvY2tFbmQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuX3RhZ09mZnNldCA9IHA7CiAgICAgICAgdGhpcy5fdGFnTGlzdC5wdXNoKHRhZyk7CiAgICAgICAgaWYgKGxjVGFnID09PSB0YWdOYW1lKSB7CiAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YVtsY1RhZ10gPSB2YWx1ZTsKICAgICAgfQogICAgICB0aGlzLl9hbGxUYW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IGNpZ29wID0gYnl0ZUFycmF5LnJlYWRJbnQzMkxFKHApOwogICAgICBsZXQgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgbGV0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgaWYgKG9wID09PSAiUyIgJiYgbG9wID09PSBzZXFMZW4pIHsKICAgICAgICBwICs9IDQ7CiAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgbG9wID0gY2lnb3AgPj4gNDsKICAgICAgICBvcCA9IENJR0FSX0RFQ09ERVJbY2lnb3AgJiAxNV07CiAgICAgICAgaWYgKG9wICE9PSAiTiIpIHsKICAgICAgICAgIGNvbnNvbGUud2FybigiQ0cgdGFnIHdpdGggbm8gTiB0YWciKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5kYXRhLmxlbmd0aF9vbl9yZWYgPSBsb3A7CiAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KCJDRyIpOwogICAgICB9IGVsc2UgewogICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgbnVtQ2lnYXJPcHM7ICsrYykgewogICAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICBsb3AgPSBjaWdvcCA+PiA0OwogICAgICAgICAgb3AgPSBDSUdBUl9ERUNPREVSW2NpZ29wICYgMTVdOwogICAgICAgICAgY2lnYXIgKz0gbG9wICsgb3A7CiAgICAgICAgICBpZiAob3AgIT09ICJIIiAmJiBvcCAhPT0gIlMiICYmIG9wICE9PSAiSSIpIHsKICAgICAgICAgICAgbHJlZiArPSBsb3A7CiAgICAgICAgICB9CiAgICAgICAgICBwICs9IDQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YS5sZW5ndGhfb25fcmVmID0gbHJlZjsKICAgICAgICByZXR1cm4gY2lnYXI7CiAgICAgIH0KICAgIH0KICAgIF9mbGFncygpIHsKICAgIH0KICAgIGxlbmd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ICYgMjQwKSA+PiA0XTsKICAgICAgICBpKys7CiAgICAgICAgaWYgKGkgPCBsZW4pIHsKICAgICAgICAgIGJ1ZiArPSBTRVFSRVRfREVDT0RFUltzYiAmIDE1XTsKICAgICAgICAgIGkrKzsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGJ1ZjsKICAgIH0KICAgIGdldFBhaXJPcmllbnRhdGlvbigpIHsKICAgICAgaWYgKCF0aGlzLmlzU2VnbWVudFVubWFwcGVkKCkgJiYgIXRoaXMuaXNNYXRlVW5tYXBwZWQoKSAmJiB0aGlzLl9yZWZJRCA9PT0gdGhpcy5fbmV4dF9yZWZpZCgpKSB7CiAgICAgICAgY29uc3QgczEgPSB0aGlzLmlzUmV2ZXJzZUNvbXBsZW1lbnRlZCgpID8gIlIiIDogIkYiOwogICAgICAgIGNvbnN0IHMyID0gdGhpcy5pc01hdGVSZXZlcnNlQ29tcGxlbWVudGVkKCkgPyAiUiIgOiAiRiI7CiAgICAgICAgbGV0IG8xID0gIiAiOwogICAgICAgIGxldCBvMiA9ICIgIjsKICAgICAgICBpZiAodGhpcy5pc1JlYWQxKCkpIHsKICAgICAgICAgIG8xID0gIjEiOwogICAgICAgICAgbzIgPSAiMiI7CiAgICAgICAgfSBlbHNlIGlmICh0aGlzLmlzUmVhZDIoKSkgewogICAgICAgICAgbzEgPSAiMiI7CiAgICAgICAgICBvMiA9ICIxIjsKICAgICAgICB9CiAgICAgICAgY29uc3QgdG1wID0gW107CiAgICAgICAgY29uc3QgaXNpemUgPSB0aGlzLnRlbXBsYXRlX2xlbmd0aCgpOwogICAgICAgIGlmIChpc2l6ZSA+IDApIHsKICAgICAgICAgIHRtcFswXSA9IHMxOwogICAgICAgICAgdG1wWzFdID0gbzE7CiAgICAgICAgICB0bXBbMl0gPSBzMjsKICAgICAgICAgIHRtcFszXSA9IG8yOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB0bXBbMl0gPSBzMTsKICAgICAgICAgIHRtcFszXSA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KGZlYXR1cmUuZ2V0KCJzdGFydCIpID49IG1heCkgewogICAgICAgICAgICAgIGRvbmUgPSB0cnVlOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZlYXR1cmUuZ2V0KCJlbmQiKSA+PSBtaW4pIHsKICAgICAgICAgICAgICByZWNzLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmVhdHMucHVzaChyZWNzKTsKICAgICAgICB5aWVsZCByZWNzOwogICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIGlmICh2aWV3QXNQYWlycykgewogICAgICAgIHlpZWxkIHRoaXMuZmV0Y2hQYWlycyhjaHJJZCwgZmVhdHMsIG9wdHMpOwogICAgICB9CiAgICB9CiAgICBhc3luYyBmZXRjaFBhaXJzKGNocklkLCBmZWF0cywgb3B0cykgewogICAgICBjb25zdCB7IHBhaXJBY3Jvc3NDaHIgPSBmYWxzZSwgbWF4SW5zZXJ0U2l6ZSA9IDJlNSB9ID0gb3B0czsKICAgICAgY29uc3QgdW5tYXRlZFBhaXJzID0ge307CiAgICAgIGNvbnN0IHJlYWRJZHMgPSB7fTsKICAgICAgZmVhdHMubWFwKChyZXQpID0+IHsKICAgICAgICBjb25zdCByZWFkTmFtZXMgPSB7fTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJldC5sZW5ndGg7IGkrKykgewogICAgICAgICAgY29uc3QgbmFtZSA9IHJldFtpXS5uYW1lKCk7CiAgICAgICAgICBjb25zdCBpZCA9IHJldFtpXS5pZCgpOwogICAgICAgICAgaWYgKCFyZWFkTmFtZXNbbmFtZV0pIHsKICAgICAgICAgICAgcmVhZE5hbWVzW25hbWVdID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHJlYWROY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NvbnN0IGJsb2NrRW5kID0gYmxvY2tTdGFydCArIDQgKyBibG9ja1NpemUgLSAxOwogICAgICAgIGlmIChkcG9zaXRpb25zKSB7CiAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uID49IGRwb3NpdGlvbnNbcG9zKytdKSB7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKGJsb2NrRW5kIDwgYmEubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gbmV3IEJhbVJlY29yZCh7CiAgICAgICAgICAgIGJ5dGVzOiB7CiAgICAgICAgICAgICAgYnl0ZUFycmF5OiBiYSwKICAgICAgICAgICAgICBzdGFydDogYmxvY2tTdGFydCwKICAgICAgICAgICAgICBlbmQ6IGJsb2NrRW5kCiAgICAgICAgICAgIH0sCiAgICAgICAgICAgIGZpbGVPZmZzZXQ6IGNwb3NpdGlvbnMgPyBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uICsgMSA6IGltcG9ydF9idWZmZXJfY3JjMzIuZGVmYXVsdC5zaWduZWQoYmEuc2xpY2UoYmxvY2tTdGFydCwgYmxvY2tFbmQpKQogICAgICAgICAgfSk7CiAgICAgICAgICBzaW5rLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRocmVhZFRpbWUgJiYgK0RhdGUubm93KCkgLSBsYXN0ID4gdGhpcy55aWVsZFRocmVhZFRpbWUpIHsKICAgICAgICAgICAgYXdhaXQgdGltZW91dCgxKTsKICAgICAgICAgICAgbGFzdCA9ICtEYXRlLm5vdygpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9ja1N0YXJ0ID0gYmxvY2tFbmQgKyAxOwogICAgICB9CiAgICAgIHJ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sdWUpIHsKICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5fZW1pdEV2aWN0aW9ucyh0aGlzLm9sZENhY2hlKTsKICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICB9CiAgICB9CiAgICBfbW92ZVRvUmVjZW50KGtleSwgaXRlbSkgewogICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICB0aGlzLl9zZXQoa2V5LCBpdGVtKTsKICAgIH0KICAgICpfZW50cmllc0FzY2VuZGluZygpIHsKICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICAgIGlmIChkZWxldGVkID09PSBmYWxzZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgIGNvbnN0IFtrZXksIHZhbHVlXSA9IGl0ZW07CiAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgfQogICAgICB9CiAgIC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ksIHRoaXMuY2FjaGUuZ2V0KGtleSkpOwogICAgICB9CiAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgcmV0dXJuICF0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB0aGlzLm9sZENhY2hlLmdldChrZXkpKTsKICAgICAgfQogICAgICByZXR1cm4gZmFsc2U7CiAgICB9CiAgICBwZWVrKGtleSkgewogICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgIHJldHVybiB0aGlzLl9wZWVrKGtleSwgdGhpcy5jYWNoZSk7CiAgICAgIH0KICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICByZXR1cm4gdGhpcy5fcGVlayhrZXksIHRoaXMub2xkQ2FjaGUpOwogICAgICB9CiAgICB9CiAgICBkZWxldGUoa2V5KSB7CiAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgfQogICAgY2xlYXIoKSB7CiAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICB0aGlzLl9zaXplID0gMDsKICAgIH0KICAgIHJlc2l6ZShuZXdTaXplKSB7CiAgICAgIGlmICghKG5ld1NpemUgJiYgbmV3U2l6ZSA+IDApKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgfQogICAgICBjb25zdCBpdGVtcyA9IFsuLi50aGlzLl9lbnRyaWVzQXNjZW5kaW5nKCldOwogICAgICBjb25zdCByZW1vd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ID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5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ogICAgICAgIGN1cnJOdW0gPSBjdXJyTnVtICogMTAgKyArbWRTdHJpbmdbaV07CiAgICAgICAgZGVsZXRpb25FbmNvdW50ZXJlZCA9IGZhbHNlOwogICAgICB9IGVsc2UgaWYgKG1kU3RyaW5nW2ldID09PSAiXiIpIHsKICAgICAgICBkZWxldGlvbkVuY291bnRlcmVkID0gdHJ1ZTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjdXJyUG9zICs9IGN1cnJOdW07CiAgICAgICAgaWYgKHVzZUNvdW50cykgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgbGVuZ3RoOiBjdXJyTnVtLAogICAgICAgICAgICB0eXBlOiBtZFN0cmluZ1tpXQogICAgICAgICAgfSk7CiAgICAgICAgfSBlbHNlIGlmIChkZWxldGlvbkVuY291bnRlcmVkKSB7CiAgICAgICAgICBiYW1TZXFTaGlmdCAtPSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGJhc2U6IG1kU3RyaW5nW2ldLAogICAgICAgICAgICBsZW5ndGg6IDEsCiAgICAgICAgICAgIGJhbVNlcVNoaWZ0CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgY3Vyck51bSA9IDA7CiAgICAgICAgY3VyclBvcyArPSAxOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc3Vic3RpdHV0aW9uczsKICB9CiAgZnVuY3Rpb24gZ2V0U3Vic3RpdHV0aW9ucyhzZWdtZW50LCBzZXEpIHsKICAgIGxldCBzdWJzdGl0dXRpb25zID0gW107CiAgICBsZXQgc29mdENsaXBwaW5nQXRSZWFkU3RhcnQgPSBudWxsOwogICAgaWYgKHNlZ21lbnQuY2lnYXIpIHsKICAgICAgY29uc3QgY2lnYXJTdWJzID0gcGFyc2VNRChzZWdtZW50LmNpZ2FyLCB0cnVlKTsKICAgICAgbGV0IGN1cnJQb3MgPSAwOwogICAgICBmb3IgKGNvbnN0IHN1YiBvZiBjaWdhclN1YnMpIHsKICAgICAgICBpZiAoc3ViLnR5cGUgPT09ICJYIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJYIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIkkiKSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGxlbmd0aDogc3ViLmxlbmd0aCwKICAgICAgICAgICAgdHlwZTogIkkiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgaWYgKHN1Yi50eXBlID09PSAiRCIpIHsKICAgICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICAgIHBvczogY3VyclBvcywKICAgICAgICAgICAgbGVuZ3RoOiBzdWIubGVuZ3RoLAogICAgICAgICAgICB0eXBlOiAiRCIKICAgICAgICAgIH0pOwogICAgICAgICAgY3VyclBvcyArPSBzdWIubGVuZ3RoOwogICAgICAgIH0gZWxzZSBpZiAoc3ViLnR5cGUgPT09ICJOIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJOIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIj0iIHx8IHN1Yi50eXBlID09PSAiTSIpIHsKICAgICAgICAgIGN1cnJQb3MgKz0gc3ViLmxlbmd0aDsKICAgICAgICB9IGVsc2UgewogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBmaXJzdFN1YiA9IGNpZ2FyU3Vic1swXTsKICAgICAgY29uc3QgbGFzdFN1YiA9IGNpZ2FyU3Vic1tjaWdhclN1YnMubGVuZ3RoIC0gMV07CiAgICAgIGlmIChmaXJzdFN1Yi50eXBlID09PSAiUyIpIHsKICAgICAgICBzb2Z0Q2xpcHBpbmdBdFJlYWRTdGFydCA9IGZpcnN0U3ViOwogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IC1maXJzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIsCiAgICAgICAgICBsZW5ndGg6IGZpcnN0U3ViLmxlbmd0aAogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChsYXN0U3ViLnR5cGUgPT09ICJTIikgewogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IHNlZ21lbnQuZW5kIC0gc2VnbWVudC5zdGFydCwKICAgICAgICAgIGxlbmd0aDogbGFzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZmlyc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogLWZpcnN0U3ViLmxlbmd0aCwKICAgICAgICAgIHR5cGU6ICJIIiwKICAgICAgICAgIGxlbmd0aDogZmlyc3RTdWIubGVuZ3RoCiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKGxhc3RTdWIudHlwZSA9PT0gIkgiKSB7CiAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgIHBvczogc2VnbWVudC5lbmQgLSBzZWdtZW50LnN0YXJ0LAogICAgICAgICA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9YCwgdGlsZVZhbHVlcy5nZXQoYCR7dWlkfS4ke3p9LiR7eH1gKS5jb25jYXQobWFwcGVkUmVjb3JkcykpOwogICAgICAgICAgICByZXR1cm4gW107CiAgICAgICAgICB9KSk7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHJldHVybiBQcm9taXNlLmFsbChyZWNvcmRQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHJldHVybiB2YWx1ZXMuZmxhdCgpOwogICAgfSk7CiAgfTsKICB2YXIgZmV0Y2hUaWxlc0RlYm91bmNlZCA9IGFzeW5jICh1aWQsIHRpbGVJZHMpID0+IHsKICAgIGNvbnN0IHRpbGVzID0ge307CiAgICBjb25zdCB2YWxpZFRpbGVJZHMgPSBbXTsKICAgIGNvbnN0IHRpbGVQcm9taXNlcyA9IFtdOwogICAgZm9yIChjb25zdCB0aWxlSWQgb2YgdGlsZUlkcykgewogICAgICBjb25zdCBwYXJ0cyA9IHRpbGVJZC5zcGxpdCgiLiIpOwogICAgICBjb25zdCB6ID0gcGFyc2VJbnQocGFydHNbMF0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzKSA9PiB7CiAgICAgIHZhbHVlcy5mb3JFYWNoKChkLCBpKSA9PiB7CiAgICAgICAgY29uc3Qg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gICAgIGNvbnN0IGluc2VydFNpemUgPSBNYXRoLm1heCgwLCArci5zdGFydCAtICtsLmVuZCk7CiAgICAgICAgY29uc3QgbGFyZ2VJbnNlcnRTaXplID0gaW5zZXJ0U2l6ZSA+PSBtYXhJbnNlcnRTaXplOwogICAgICAgIGxldCBzdlR5cGU7CiAgICAgICAgaWYgKCFsYXJnZUluc2VydFNpemUpIHsKICAgICAgICAgIHN2VHlwZSA9ICJub3JtYWwgcmVhZCI7CiAgICAgICAgfSBlbHNlIGlmIChsLnN0cmFuZCA9PT0gIisiICYmIHIuc3RyYW5kID09PSAiLSIpIHsKICAgICAgICAgIHN2VHlwZSA9ICJkZWxldGlvbiAoKy0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiKyIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoKyspIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICItIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoLS0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImR1cGxpY2F0aW9uICgtKykiOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdlR5cGUgPSBgKCR7bC5zdHJhbmR9JHtyLnN0cmFuZH0pYDsKICAgICAgICB9CiAgICAgICAgW3JlYWQsIG1hdGVdLmZvckVhY2goKGQpID0+IHsKICAgICAgICAgIGQuZm91bmRNYXRlID0gdHJ1ZTsKICAgICAgICAgIGQuaW5zZXJ0U2l6ZSA9IGluc2VydFNpemU7CiAgICAgICAgICBkLmxhcmdlSW5zZXJ0U2l6ZSA9IGxhcmdlSW5zZXJ0U2l6ZTsKICAgICAgICAgIGQuc3ZUeXBlID0gc3ZUeXBlOwogICAgICAgICA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XJ0IDwgZG9uICYmIGFjYyA8IHNlZ21lbnQuZW5kKSB7CiAgICAgICAgICBjb25zdCBqID0ganVuY3Rpb25zLmZpbmQoKGQpID0+IGQuc3RhcnQgPT09IGRvbiAmJiBkLmVuZCA9PT0gYWNjKTsKICAgICAgICAgIGlmIChqKSB7CiAgICAgICAgICAgIGouc2NvcmUgKz0gMTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGp1bmN0aW9ucy5wdXNoKHsgc3RhcnQ6IGRvbiwgZW5kOiBhY2MsIHNjb3JlOiAxIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfSk7CiAgICB9KTsKICAgIHJldHVybiBqdW5jdGlvbnMuZmlsdGVyKChkKSA9PiBkLnNjb3JlID49IG1pbkNvdmVyYWdlKTsKICB9OwogIHZhciB0aWxlRnVuY3Rpb25zID0gewogICAgaW5pdCwKICAgIHRpbGVzZXRJbmZvLAogICAgZmV0Y2hUaWxlc0RlYm91bmNlZCwKICAgIHRpbGUsCiAgICBnZXRUYWJ1bGFyRGF0YQogIH07CiAgZXhwb3NlKHRpbGVGdW5jdGlvbnMpOwp9KSgpOwovKiEKICogVGhlIGJ1ZmZlciBtb2R1bGUgZnJvbSBub2RlLmpzLCBmb3IgdGhlIGJyb3dzZXIuCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCg==",sle=typeof window<"u"&&window.Blob&&new Blob([atob(a2e)],{type:"text/javascript;charset=utf-8"});function mgg(){const e=sle&&(window.URL||window.webkitURL).createObjectURL(sle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+a2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const fgg=200;class BH{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"fetchTimeout"),rt(this,"toFetch"),rt(this,"MAX_TILE_WIDTH",2e4),rt(this,"worker"),rt(this,"track"),this.uid=g.libraries.slugid.nice(),this.toFetch=new Set;const{url:i,indexUrl:n,assembly:C,...r}=I;this.worker=JT(new mgg).then(async o=>{const a=Object.entries(bI(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()},fgg)}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))}}rt(BH,"config",{type:"bam"});const A2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gK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sKICAgICAgICB9CiAgICAgICAgaWYgKHBsYWNlSG9sZGVyc0xlbiA9PT0gMikgewogICAgICAgICAgdG1wID0gcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMiB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDEpXSA+PiA0OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIGlmIChwbGFjZUhvbGRlcnNMZW4gPT09IDEpIHsKICAgICAgICAgIHRtcCA9IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMildIDw8IDEwIHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMSldIDw8IDQgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAyKV0gPj4gMjsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wID4+IDggJiAyNTU7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFycjsKICAgICAgfQogICAgICBmdW5jdGlvbiB0cmlwbGV0VG9CYXNlNjQobnVtKSB7CiAgICAgICAgcmV0dXJuIGxvb2t1cFtudW0gPj4gMTggJiA2M10gKyBsb29rdXBbbnVtID4+IDEyICYgNjNdICsgbG9va3VwW251bSA+PiA2ICYgNjNdICsgbG9va3VwW251bSAmIDYzXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBlbmNvZGVDaHVuayh1aW50OCwgc3RhcnQsIGVuZCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIG91dHB1dCA9IFtdOwogICAgICAgIGZvciAodmFyIGkyID0gc3RhcnQ7IGkyIDwgZW5kOyBpMiArPSAzKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbaTJdIDw8IDE2ICYgMTY3MTE2ODApICsgKHVpbnQ4W2kyICsgMV0gPDwgOCAmIDY1MjgwKSAr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pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcGFydHMuam9pbigiIik7CiAgICAgIH0KICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2llZWU3NTRAMS4yLjEvbm9kZV9tb2R1bGVzL2llZWU3NTQvaW5kZXguanMKICB2YXIgcmVxdWlyZV9pZWVlNzU0ID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2llZWU3NTRAMS4yLjEvbm9kZV9tb2R1bGVzL2llZWU3NTQvaW5kZXguanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgZXhwb3J0czIucmVhZCA9IGZ1bmN0aW9uKGJ1ZmZlciwgb2Zmc2V0LCBpc0xFLCBtTGVuLCBuQnl0ZXMpIHsKICAgICAgICB2YXIgZSwgbTsKICAgICAgICB2YXIgZUxlbiA9IG5CeXRlcyAqIDggLSBtTGVuIC0gMTsKICAgICAgICB2YXIgZU1heCA9ICgxIDw8IGVMZW4pIC0gMTsKICAgICAgICB2YXIgZUJpYXMgPSBlTWF4ID4+IDE7CiAgICAgICAgdmFyIG5CaXRzID0gLTc7CiAgICAgICAgdmFyIGkgPSBpc0xFID8gbkJ5dGVzIC0gMSA6IDA7CiAgICAgICAgdmFyIGQgPSBpc0xFID8gLTEgOiAxOwogICAgICAgIHZhciBzID0gYnVmZmVyW29mZnNldCArIGldOwogICAgICAgIGkgKz0gZDsKICAgICAgICBlID0gcyAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIHMgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBlTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IGUgPSBlICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgbSA9IGUgJiAoMSA8PCAtbkJpdHMpIC0gMTsKICAgICAgICBlID4+PSAtbkJpdHM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mFicyh2YWx1ZSk7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSB8fCB2YWx1ZSA9PT0gSW5maW5pdHkpIHsKICAgICAgICAgIG0gPSBpc05hTih2YWx1ZSkgPyAxIDogMDsKICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBlID0gTWF0aC5mbG9vcihNYXRoLmxvZyh2YWx1ZSkgLyBNYXRoLkxOMik7CiAgICAgICAgICBpZiAodmFsdWUgKiAoYyA9IE1hdGgucG93KDIsIC1lKSkgPCAxKSB7CiAgICAgICAgICAgIGUtLTsKICAgICAgICAgICAgYyAqPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0IC8gYzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHZhbHVlICs9IHJ0ICogTWF0aC5wb3coMiwgMSAtIGVCaWFzKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWx1ZSAqIGMgPj0gMikgewogICAgICAgICAgICBlKys7CiAgICAgICAgICAgIGMgLz0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gZU1heCkgewogICAgICAgICAgICBtID0gMDsKICAgICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgICB9IGVsc2UgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIG0gPSAodmFsdWUgKiBjIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IGUgKyBlQmlhczsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG0gPSB2YWx1ZSAqIE1hdGgucG93KDIsIGVCaWFzIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoOyBtTGVuID49IDg7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Y3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAicGFyZW50IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjEwLnByb3RvdHlwZSwgIm9mZnNldCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKHRoaXMpKQogICAgICAgICAgICByZXR1cm4gdm9pZCAwOwogICAgICAgICAgcmV0dXJuIHRoaXMuYnl0ZU9mZnNldDsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBmdW5jdGlvbiBjcmVhdGVCdWZmZXIobGVuZ3RoKSB7CiAgICAgICAgaWYgKGxlbmd0aCA+IEtfTUFYX0xFTkdUSCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoJ1RoZSB2YWx1ZSAiJyArIGxlbmd0aCArICciIGlzIGludmFsaWQgZm9yIG9wdGlvbiAic2l6ZSInKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmID0gbmV3IFVpbnQ4QXJyYXkobGVuZ3RoKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYnVmLCBCdWZmZXIxMC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gQnVmZmVyMTAoYXJnLCBlbmNvZGluZ09yT2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBpZiAodHlwZW9mIGFyZyA9PT0gIm51bWJl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H0KICAgICAgICBpZiAoYSA9PT0gYikKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gYS5sZW5ndGg7CiAgICAgICAgbGV0IHkgPSBiLmxlbmd0aDsKICAgICAgICBmb3IgKGxldCBpID0gMCwgbGVuID0gTWF0aC5taW4oeCwgeSk7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKGFbaV0gIT09IGJbaV0pIHsKICAgICAgICAgICAgeCA9IGFbaV07CiAgICAgICAgICAgIHkgPSBiW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHggPCB5KQogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIGlmICh5IDwgeCkKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5pc0VuY29kaW5nID0gZnVuY3Rpb24gaXNFbmNvZGluZyhlbmNvZGluZykgewogICAgICAgIHN3aXRjaCAoU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpKSB7CiAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyMTAuYWxsb2MoMCk7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChsZW5ndGggPT09IHZvaWQgMCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIGxlbmd0aCArPSBsaXN0W2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyID0gQnVmZmVyMTAuYWxsb2NVbnNhZmUobGVuZ3RoKTsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGlzdC5sZW5ndGg7ICsraSkgewogICAgICAgICAgbGV0IGJ1ZiA9IGxpc3RbaV07CiAgICAgICAgICBpZiAoaXNJbnN0YW5jZShidWYsIFVpbnQ4QXJyYXkpKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyBidWYubGVuZ3RoID4gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjEwLmZyb20oYnVmKTsKICAgICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwoYnVmZmVyLCBidWYsIHBv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ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmJ5dGVMZW5ndGggPSBieXRlTGVuZ3RoOwogICAgICBmdW5jdGlvbiBzbG93VG9TdHJpbmcoZW5jb2RpbmcsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCB8fCBzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA9PT0gdm9pZCAwIHx8IGVuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgfQogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKCFlbmNvZGluZykKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gbGF0aW4xU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiB1dGYxNmxlU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKQogICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgICAgICBlbmNvZGluZyA9IChlbmNvZGluZyArICIiKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLl9pc0J1ZmZlciA9IHRydWU7CiAgICAgIGZ1bmN0aW9uIHN3YXAoYiwgbiwgbSkgewogICAgICAgIGNvbnN0IGkgPSBiW25dOwogICAgICAgIGJbbl0gPSBiW21dOwogICAgICAgIGJbbV0gPSBpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiA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2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb3B5ID0gdGhpcy5zbGljZSh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2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyMTAuZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICB9CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkpIHsKICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBkaXIpOwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpIHsKICAgICAgICAgIHZhbCA9IHZhbCAmIDI1NTsKICAgICAgICAgIGlmICh0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBpZiAoZGlyK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ogICAgICAgICAgICBpbmRleFNpemUgPSAyOwogICAgICAgICAgICBhcnJMZW5ndGggLz0gMjsKICAgICAgICAgICAgdmFsTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIGJ5dGVPZmZzZXQgLz0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcmVhZChidWYsIGkyKSB7CiAgICAgICAgICBpZiAoaW5kZXhTaXplID09PSAxKSB7CiAgICAgICAgICAgIHJldHVybiBidWZbaTJdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIGJ1Zi5yZWFkVUludDE2QkUoaTIgKiBpbmRleFNpemUpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICBsZXQgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA8IGFyckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSkgPT09IHJlYWQodmFsLCBmb3VuZEluZGV4ID09PSAtMSA/IDAgOiBpIC0gZm91bmRJbmRleCkpIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCA9PT0gLTEpCiAgICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gaTsKICAgICAgICAgICAgICBpZiAoaSAtIGZvdW5kSW5kZXggKyAxID09PSB2YWxMZW5ndGgpCiAgICAgICAgICAgICAgICByZXR1cm4gZm91bmRJbmRleCAqIGluZGV4U2l6ZTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCAhPT0gLTEpCiAgICAgICAgICAgICAgICBpIC09IGkgLSBmb3VuZEluZGV4OwogICAgICAgICAgICAgIGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoYnl0ZU9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W5jb2RpbmcpIHsKICAgICAgICByZXR1cm4gYmlkaXJlY3Rpb25hbEluZGV4T2YodGhpcywgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZmFsc2UpOwogICAgICB9OwogICAgICBmdW5jdGlvbiBoZXhXcml0ZShidWYsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBvZmZzZXQgPSBOdW1iZXIob2Zmc2V0KSB8fCAwOwogICAgICAgIGNvbnN0IHJlbWFpbmluZyA9IGJ1Zi5sZW5ndGggLSBvZmZzZXQ7CiAgICAgICAgaWYgKCFsZW5ndGgpIHsKICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGVuZ3RoID0gTnVtYmVyKGxlbmd0aCk7CiAgICAgICAgICBpZiAobGVuZ3RoID4gcmVtYWluaW5nKSB7CiAgICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3Qgc3RyTGVuID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBpZiAobGVuZ3RoID4gc3RyTGVuIC8gMikgewogICAgICAgICAgbGVuZ3RoID0gc3RyTGVuIC8gMjsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb25zdCBwYXJzZWQgPSBwYXJzZUludChzdHJpbmcuc3Vic3RyKGkgKiAyLCAyKSwgMTYpOwogICAgICAgICAgaWYgKG51bWJlcklzTmFOKHBhcnNlZCkpCiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgYnVmW29mZnNldCArIGldID0gcGFyc2VkOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4V3JpdGUoYnVmLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAg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AidXRmOCI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRv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yBieXRlc1BlclNlcXVlbmNlIDw9IGVuZCkgewogICAgICAgICAgICBsZXQgc2Vjb25kQnl0ZSwgdGhpcmRCeXRlLCBmb3VydGhCeXRlLCB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICBzd2l0Y2ggKGJ5dGVzUGVyU2VxdWVuY2UpIHsKICAgICAgICAgICAgICBjYXNlIDE6CiAgICAgICAgICAgICAgICBpZiAoZmlyc3RCeXRlIDwgMTI4KSB7CiAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IGZpcnN0Qnl0ZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMzEpIDw8IDYgfCBzZWNvbmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMTI3KSB7CiAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTIgfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCA2IHwgdGhpcmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMjA0NyAmJiAodGVtcENvZGVQb2ludCA8IDU1Mjk2IHx8IHRlbXBDb2RlUG9pbnQgPiA1NzM0MykpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBmb3VydGhCeXRlID0gYnVmW2kgKyAzXTsKICAgICAgICAgICAgICAgIGlmICgoc2Vjb25kQnl0ZSAmIDE5MikgPT09IDEyOCAmJiAodGhpcmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmIChmb3VydGhCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMTUpIDw8IDE4IHwgKHNlY29uZEJ5dGUgJiA2MykgPDwgMTIgfCAodGhpcmRCeXRlICYgNjMpIDw8IDYgfCBmb3VydGhCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gNjU1MzUgJiYgdGVtcENvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChjb2RlUG9pbnQgPT09IG51bGwpIHsKICAgICAgICAgICAgY29kZVBvaW50ID0gNjU1MzM7CiAgICAgICAgICAgIGJ5dGVzUGVyU2VxdWVuY2UgPSAxOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPiA2NTUzNSkgewogICAgICAgICAgICBjb2RlUG9pbnQgLT0gNjU1MzY7CiAgICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCA+Pj4gMTAgJiAxMDIzIHwgNTUyOTYpOwogICAgICAgICAgICBjb2RlUG9pbnQgPSA1NjMyMCB8IGNvZGVQb2ludCAmIDEwMjM7CiAgICAgICAgICB9CiAgICAgICAgICByZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgaSArPSBieXRlc1BlclNlcXVlbmNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZGVjb2RlQ29kZVBvaW50c0FycmF5KHJlcyk7CiAgICAgIH0KICAgICAgdmFyIE1BWF9BUkdVTUVOVFNfTEVOR1RIID0gNDA5NjsKICAgICAgZnVuY3Rpb24gZGVjb2RlQ29kZVBvaW50c0FycmF5KGNvZGVQb2ludHMpIHsKICAgICAgICBjb25zdCBsZW4gPSBjb2RlUG9pbnRzLmxlbmd0aDsKICAgICAgICBpZiAobGVuIDw9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSB7CiAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMpOwogICAgICAgIH0KICAgICAgICBsZXQgcmVzID0gIiI7CiAgICAgICAgbGV0IGkgPSAwOwogICAgICAgIHdoaWxlIChpIDwgbGVuKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShTdHJpbmcsIGNvZGVQb2ludHMuc2xpY2UoaSwgaSArPSBNQVhfQVJHVU1FTlRTX0xFTkdUSCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFzY2lpU2xpY2UoYnVmLCBzdGFydC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ewogICAgICAgIGNvbnN0IGJ5dGVzID0gYnVmLnNsaWNlKHN0YXJ0LCBlbmQpOwogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGJ5dGVzLmxlbmd0aCAtIDE7IGkgKz0gMikgewogICAgICAgICAgcmVzICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnl0ZXNbaV0gKyBieXRlc1tpICsgMV0gKiAyNTYpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmVzOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zbGljZSA9IGZ1bmN0aW9uIHNsaWNlKHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBzdGFydCA9IH5+c3RhcnQ7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyBsZW4gOiB+fmVuZDsKICAgICAgICBpZiAoc3RhcnQgPCAwKSB7CiAgICAgICAgICBzdGFydCArPSBsZW47CiAgICAgICAgICBpZiAoc3RhcnQgPCAwKQogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydCA+IGxlbikgewogICAgICAgICAgc3RhcnQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCAwKSB7CiAgICAgICAgICBlbmQgKz0gbGVuOwogICAgICAgICAgaWYgKGVuZCA8IDApCiAgICAgICAgICAgIGVuZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChlbmQgPiBsZW4pIHsKICAgICAgICAgIGVuZCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IHN0YXJ0KQogICAgICAgICAgZW5kID0gc3RhcnQ7CiAgICAgICAgY29uc3QgbmV3QnVmID0gdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YobmV3QnVmLCBCdWZmZXI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XVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQ4ID0gZnVuY3Rpb24gcmVhZEludDgob2Zmc2V0LCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBpZiAoIW5vQXNzZXJ0KQogICAgICAgICAgY2hlY2tPZmZzZXQob2Zmc2V0LCAxLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgaWYgKCEodGhpc1tvZmZzZXRdICYgMTI4KSkKICAgICAgICAgIHJldHVybiB0aGlzW29mZnNldF07CiAgICAgICAgcmV0dXJuICgyNTUgLSB0aGlzW29mZnNldF0gKyAxKSAqIC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUucmVhZEludDE2TEUgPSBmdW5jdGlvbiByZWFkSW50MTZMRShvZmZzZXQsIG5vQXNzZXJ0KSB7CiAgICAgICAgb2Zmc2V0ID0gb2Zmc2V0ID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIDIsIHRoaXMubGVuZ3RoKTsKICAgICAgICBjb25zdCB2YWwgPSB0aGlzW29mZnNldF0gfCB0aGlzW29mZnNldCArIDFdIDw8IDg7CiAgICAgICAgcmV0dXJuIHZhbCAmIDMyNzY4ID8gdmFsIHwgNDI5NDkwMTc2MCA6IHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnQxNkJFID0gZnVuY3Rpb24gcmVhZEludDE2QkUob2Zmc2V0LCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgIC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nZXRTdGFydCwgc3RhcnQsIGVuZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIFVpbnQ4QXJyYXkucHJvdG90eXBlLnNldC5jYWxsKHRhcmdldCwgdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKSwgdGFyZ2V0U3RhcnQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuZmlsbCA9IGZ1bmN0aW9uIGZpbGwodmFsLCBzdGFydCwgZW5kLCBlbmNvZGluZykgewogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgaWYgKHR5cGVvZiBzdGFydCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBzdGFydDsKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGVuZCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBlbmQ7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDAgJiYgdHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJlbmNvZGluZyBtdXN0IGJlIGEgc3RyaW5nIik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nID09PSAic3RyaW5nIiAmJiAhQnVmZmVyMTAuaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkgPyB2YWwgOiBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgICAgY29uc3QgbGVuID0gYnl0ZXMubGVuZ3RoOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgdmFsdWUgIicgKyB2YWwgKyAnIiBpcyBpbnZhbGlkIGZvciBhcmd1bWVudCAidmFsdWUiJyk7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZW5kIC0gc3RhcnQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2kgKyBzdGFydF0gPSBieXRlc1tpICUgbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIHZhciBlcnJvcnMgPSB7fTsKICAgICAgZnVuY3Rpb24gRShzeW0sIGdldE1lc3NhZ2UsIEJhc2UpIHsKICAgICAgICBlcnJvcnNbc3ltXSA9IGNsYXNzIE5vZGVFcnJvciBleHRlbmRzIEJhc2UgewogICAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHN1cGVyKCk7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAibWVzc2FnZSIsIHsKICAgICAgICAgICAgICB2YWx1ZTogZ2V0TWVzc2FnZS5hcHBseSh0aGlzLCBhcmd1bWVudHMpLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgICAgdGhpcy5uYW1lID0gYCR7dGhpcy5uYW1lfSBbJHtzeW19XWA7CiAgICAgICAgICAgIHRoaXMuc3RhY2s7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm5hbWU7CiAgICAgICAgICB9CiAgICAgICAgICBnZXQgY29kZSgpIHsKICAgICAgICAgICAgcmV0dXJuIHN5bTsKICAgICAgICAgIH0KICAgICAgICAgIHNldCBjb2RlKHZhbHVlKSB7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAiY29kZSIsIHsKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICB2YWx1ZSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gYCR7dGhpcy5uYW1lfSBbJHtzeW19XTogJHt0aGlzLm1lc3NhZ2V9YDsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIEUoIkVSUl9CVUZGRVJfT1VUX09GX0JPVU5EUyIsIGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICBpZiAobmFtZSkgewogICAgICAgICAgcmV0dXJuIGAke25hbWV9IGlzIG91dHNpZGUgb2YgYnVmZmVyIGJvdW5kc2A7CiAgICAgICAgfQogICAgICAgIHJldHVybiAiQXR0ZW1wdCB0byBhY2Nlc3MgbWVtb3J5IG91dHNpZGUgYnVmZmVyIGJvdW5kcyI7CiAgICAgIH0sIFJhbmdlRXJyb3IpOwogICAgICBFKCJFUlJfSU5WQUxJRF9BUkdfVFlQRSIsIGZ1bmN0aW9uKG5hbWUsIGFjdHVhbCkgewogICAgICAgIHJldHVybiBgVGhlICIke25hbWV9IiBhcmd1bWVudCBtdXN0IGJlIG9mIHR5cGUgbnVtYmVyLiBSZWNlaXZlZCB0eXBlICR7dHlwZW9mIGFjdHVhbH1gOwogICAgICB9LCBUeXBlRXJyb3IpOwogICAgICBFKCJFUlJfT1VUX09GX1JBTkdFIiwgZnVuY3Rpb24oc3RyLCByYW5nZSwgaW5wdXQpIHsKICAgICAgICBsZXQgbXNnID0gYFRoZSB2YWx1ZSBvZiAiJHtzdHJ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ZXN9YDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpIHsKICAgICAgICB2YWxpZGF0ZU51bWJlcihvZmZzZXQsICJvZmZzZXQiKTsKICAgICAgICBpZiAoYnVmW29mZnNldF0gPT09IHZvaWQgMCB8fCBidWZbb2Zmc2V0ICsgYnl0ZUxlbmd0aDJdID09PSB2b2lkIDApIHsKICAgICAgICAgIGJvdW5kc0Vycm9yKG9mZnNldCwgYnVmLmxlbmd0aCAtIChieXRlTGVuZ3RoMiArIDEpKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY2hlY2tJbnRCSSh2YWx1ZSwgbWluLCBtYXgsIGJ1Ziwgb2Zmc2V0LCBieXRlTGVuZ3RoMikgewogICAgICAgIGlmICh2YWx1ZSA+IG1heCB8fCB2YWx1ZSA8IG1pbikgewogICAgICAgICAgY29uc3QgbiA9IHR5cGVvZiBtaW4gPT09ICJiaWdpbnQiID8gIm4iIDogIiI7CiAgICAgICAgICBsZXQgcmFuZ2U7CiAgICAgICAgICBpZiAoYnl0ZUxlbmd0aDIgPiAzKSB7CiAgICAgICAgICAgIGlmIChtaW4gPT09IDAgfHwgbWluID09PSBCaWdJbnQoMCkpIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAwJHtufSBhbmQgPCAyJHtufSAqKiAkeyhieXRlTGVuZ3RoMiArIDEpICogOH0ke259YDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByYW5nZSA9IGA+PSAtKDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259KSBhbmQgPCAyICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4IC0gMX0ke259YDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmFuZ2UgPSBgPj0gJHttaW59JHtufSBhbmQgPD0gJHttYXh9JHtufWA7C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2U2NGNsZWFuKHN0cikgewogICAgICAgIHN0ciA9IHN0ci5zcGxpdCgiPSIpWzBdOwogICAgICAgIHN0ciA9IHN0ci50cmltKCkucmVwbGFjZShJTlZBTElEX0JBU0U2NF9SRSwgIiIpOwogICAgICAgIGlmIChzdHIubGVuZ3RoIDwgMikKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB3aGlsZSAoc3RyLmxlbmd0aCAlIDQgIT09IDApIHsKICAgICAgICAgIHN0ciA9IHN0ciArICI9IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHN0cjsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGY4VG9CeXRlcyhzdHJpbmcsIHVuaXRzKSB7CiAgICAgICAgdW5pdHMgPSB1bml0cyB8fCBJbmZpbml0eTsKICAgICAgICBsZXQgY29kZVBvaW50OwogICAgICAgIGNvbnN0IGxlbmd0aCA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgbGV0IGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgIGNvbnN0IGJ5dGVzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29kZVBvaW50ID0gc3RyaW5nLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTUyOTUgJiYgY29kZVBvaW50IDwgNTczNDQpIHsKICAgICAgICAgICAgaWYgKCFsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU2MzE5KSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKGkgKyAxID09PSBsZW5ndGgpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCA1NjMyMCkgewogICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb2RlUG9pbnQgPSAobGVhZFN1cnJvZ2F0ZSAtIDU1Mjk2IDw8IDEwIHwgY29kZVBvaW50IC0gNTYzMjApICsgNjU1MzY7CiAgICAgICAgICB9IGVsc2UgaWYgKGxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICB9CiAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCAxMjgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAxKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMjA0OCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gNiB8IDE5MiwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCA2NTUzNikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTIgfCAyMjQsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDQpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTggfCAyNDAsIGNvZGVQb2ludCA+PiAxMiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIkludmFsaWQgY29kZSBwb2ludCIpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlUb0J5dGVzKHN0cikgewogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChzdHIuY2hhckNvZGVBdChpKSAmIDI1NSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmMTZsZVRvQnl0ZXMoc3RyLCB1bml0cykgewogICAgICAgIGxldCBjLCBoaSwgbG87CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGhpID0gYyA+PiA4OwogICAgICAgICAgbG8gPSBjICUgMjU2OwogICAgICAgICAgYnl0ZUFycmF5LnB1c2gobG8pOwogICAgICAgICAgYnl0ZUFycmF5LnB1c2goaGkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFRvQnl0ZXMoc3RyKSB7CiAgICAgICAgcmV0dXJuIGJhc2U2NC50b0J5dGVBcnJheShiYXNlNjRjbGVhbihzdHIpKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBibGl0QnVmZmVyKHNyYywgZHN0LCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKGkgKyBvZmZzZXQgPj0gZHN0Lmxlbmd0aCB8fCBpID49IHNyYy5sZW5ndGgpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgZHN0W2kgKyBvZmZzZXRdID0gc3JjW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc0luc3RhbmNlKG9iaiwgdHlwZSkgewogICAgICAgIHJldHVybiBvYmogaW5zdGFuY2VvZiB0eXBlIHx8IG9iaiAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3RvciAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgPT09IHR5cGUubmFtZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBudW1iZXJJc05hTihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICE9PSBvYmo7CiAgICAgIH0KICAgICAgdmFyIGhleFNsaWNlTG9va3VwVGFibGUgPSBmdW5jdGlvbigpIHsKICAgICAgICBjb25zdCBhbHBoYWJldCA9ICIwMTIzNDU2Nzg5YWJjZGVmIjsKICAgICAgICBjb25zdCB0YWJsZSA9IG5ldyBBcnJheSgyNTYpOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgMTY7ICsraSkgewogICAgICAgICAgY29uc3QgaTE2ID0gaSAqIDE2OwogICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCAxNjsgKytqKSB7CiAgICAgICAgICAgIHRhYmxlW2kxNiArIGpdID0gYWxwaGFiZXRbaV0gKyBhbHBoYWJldFtqXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9KCk7CiAgICAgIGZ1bmN0aW9uIGRlZmluZUJpZ0ludE1ldGhvZChmbikgewogICAgICAgIHJldHVybiB0eXBlb2YgQmlnSW50ID09PSAidW5kZWZpbmVkIiA/IEJ1ZmZlckJpZ0ludE5vdERlZmluZWQgOiBmbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXJCaWdJbnROb3REZWZpbmVkKCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiQmlnSW50IG5vdCBzdXBwb3J0ZWQiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMKICB2YXIgaW1wb3J0X2J1ZmZlcjsKICB2YXIgaW5pdF9idWZmZXJfc2hpbSA9IF9fZXNtKHsKICAgICJzcmMvYWxpYXMvYnVmZmVyLXNoaW0uanMiKCkgewogICAgICBpbXBvcnRfYnVmZmVyID0gX190b01vZHVsZShyZXF1aXJlX2J1ZmZlcigpKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0Y29udHJ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gICAgdmFsdWU6IHN1YkNsYXNzLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHN1YkNsYXNzLCAicHJvdG90eXBlIiwgewogICAgICAgICAgd3JpdGFibGU6IGZhbHNlCiAgICAgICAgfSk7CiAgICAgICAgaWYgKHN1cGVyQ2xhc3MpCiAgICAgICAgICBfc2V0UHJvdG90eXBlT2Yoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZihvKSB7CiAgICAgICAgX2dldFByb3RvdHlwZU9mID0gT2JqZWN0LnNldFByb3RvdHlwZU9mID8gT2JqZWN0LmdldFByb3RvdHlwZU9mLmJpbmQoKSA6IGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZjIobzIpIHsKICAgICAgICAgIHJldHVybiBvMi5fX3Byb3RvX18gfHwgT2JqZWN0LmdldFByb3RvdHlwZU9mKG8yKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiBfZ2V0UHJvdG90eXBlT2Yobyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mKG8sIHApIHsKICAgICAgICBfc2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3Quc2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mMihvMiwgcDIpIHsKICAgICAgICAgIG8yLl9fcHJvdG9fXyA9IHAyOwogICAgICAgICAgcmV0dXJuIG8yOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9zZXRQcm90b3R5cGVPZihvLCBwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCA9PT0gInVuZGVmaW5lZCIgfHwgIVJlZmxlY3QuY29uc3RydWN0KQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChSZWZsZWN0LmNvbnN0cnVjdC5zaGFtKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmICh0eXBlb2YgUHJveHkgPT09ICJmdW5jdGlvbiIpCiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB0cnkgewogICAgICAgICAgQm9vbGVhbi5wcm90b3R5cGUudmFsdWVPZi5jYWxsKFJlZmxlY3QuY29uc3RydWN0KEJvb2xlYW4sIFtdLCBmdW5jdGlvbigpIHsKICAgICAgICAgIH0pKTsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2Fzc2VydFRoaXNJbml0aWFsaXplZChzZWxmMikgewogICAgICAgIGlmIChzZWxmMiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmVmZXJlbmNlRXJyb3IoInRoaXMgaGFzbid0IGJlZW4gaW5pdGlhbGlzZWQgLSBzdXBlcigpIGhhc24ndCBiZWVuIGNhbGxlZCIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc2VsZjI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4oc2VsZjIsIGNhbGwpIHsKICAgICAgICBpZiAoY2FsbCAmJiAodHlwZW9mIGNhbGwgPT09ICJvYmplY3QiIHx8IHR5cGVvZiBjYWxsID09PSAiZnVuY3Rpb24iKSkgewogICAgICAgICAgcmV0dXJuIGNhbGw7CiAgICAgICAgfSBlbHNlIGlmIChjYWxsICE9PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyB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wZU9mKG9iamVjdCk7CiAgICAgICAgICBpZiAob2JqZWN0ID09PSBudWxsKQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iamVjdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfZ2V0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCAhPT0gInVuZGVmaW5lZCIgJiYgUmVmbGVjdC5nZXQpIHsKICAgICAgICAgIF9nZXQgPSBSZWZsZWN0LmdldC5iaW5kKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIF9nZXQgPSBmdW5jdGlvbiBfZ2V0Mih0YXJnZXQsIHByb3BlcnR5LCByZWNlaXZlcikgewogICAgICAgICAgICB2YXIgYmFzZSA9IF9zdXBlclByb3BCYXNlKHRhcmdldCwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoIWJhc2UpCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB2YXIgZGVzYyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IoYmFzZSwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoZGVzYy5nZXQpIHsKICAgICAgICAgICAgICByZXR1cm4gZGVzYy5nZXQuY2FsbChhcmd1bWVudHMubGVuZ3RoIDwgMyA/IHRhcmdldCA6IHJlY2VpdmVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gZGVzYy52YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHJldHVybiBfZ2V0LmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH0KICAgICAgdmFyIEVtaXR0ZXIgPSAvKiBAX19QVVJFX18gKi8gZnVuY3Rpb24oKSB7CiAgICAgICAgZnVuY3Rpb24gRW1pdHRlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgRW1pdHRlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJsaXN0ZW5lcnMiLCB7CiAgICAgICAgICAgIHZhbHVlOiB7fSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhFbWl0dGVyMiwgW3sKICAgICAgICAgIGtleTogImFkZEV2ZW50TGlzdGVuZXIiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFkZEV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMpIHsKICAgICAgICAgICAgaWYgKCEodHlwZSBpbiB0aGlzLmxpc3RlbmVycykpIHsKICAgICAgICAgICAgICB0aGlzLmxpc3RlbmVyc1t0eXBlXSA9IFtdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdLnB1c2goewogICAgICAgICAgICAgIGNhbGxiYWNrLAogICAgICAgICAgICAgIG9wdGlvbnMKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAicmVtb3ZlRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gcmVtb3ZlRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1t0eXBlXTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFjay5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICBpZiAoc3RhY2tbaV0uY2FsbGJhY2sgPT09IGNhbGxiYWNrKSB7CiAgICAgICAgICAgICAgICBzdGFjay5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAiZGlzcGF0Y2hFdmVudCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gZGlzcGF0Y2hFdmVudChldmVudCkgewogICAgICAgICAgICBpZiAoIShldmVudC50eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1tldmVudC50eXBlXTsKICAgICAgICAgICAgdmFyIHN0YWNrVG9DYWxsID0gc3RhY2suc2xpY2UoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFja1RvQ2FsbC5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICB2YXIgbGlzdGVuZXIgPSBzdGFja1RvQ2FsbFtpXTsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGlzdGVuZXIuY2FsbGJhY2suY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkudGhlbihmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAobGlzdGVuZXIub3B0aW9ucyAmJiBsaXN0ZW5lci5vcHRpb25zLm9uY2UpIHsKICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlRXZlbnRMaXN0ZW5lcihldmVudC50eXBlLCBsaXN0ZW5lci5jYWxsYmFjayk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAhZXZlbnQuZGVmYXVsdFByZXZlbnRlZDsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEVtaXR0ZXIyOwogICAgICB9KCk7CiAgICAgIHZhciBBYm9ydFNpZ25hbCA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbihfRW1pdHRlcikgewogICAgICAgIF9pbmhlcml0cyhBYm9ydFNpZ25hbDIsIF9FbWl0dGVyKTsKICAgICAgICB2YXIgX3N1cGVyID0gX2NyZWF0ZVN1cGVyKEFib3J0U2lnbmFsMik7CiAgICAgICAgZnVuY3Rpb24gQWJvcnRTaWduYWwyKCkgewogICAgICAgICAgdmFyIF90aGlzOwogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0U2lnbmFsMik7CiAgICAgICAgICBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMpOwogICAgICAgICAgaWYgKCFfdGhpcy5saXN0ZW5lcnMpIHsKICAgICAgICAgICAgRW1pdHRlci5jYWxsKF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpKTsKICAgICAgICAgIH0KICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgImFib3J0ZWQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBmYWxzZSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJvbmFib3J0IiwgewogICAgICAgICAgICB2YWx1ZTogbnVsbCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJyZWFzb24iLCB7CiAgICAgICAgICAgIHZhbHVlOiB2b2lkIDAsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0pOwogICAgICAgICAgcmV0dXJuIF90aGlzOwogICAgICAgIH0KICAgICAgICBfY3JlYXRlQ2xhc3MoQWJvcnRTaWduYWwyLCBbewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRTaWduYWxdIjsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmIChldmVudC50eXBlID09PSAiYWJvcnQiKSB7CiAgICAgICAgICAgICAgdGhpcy5hYm9ydGVkID0gdHJ1ZTsKICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25hYm9ydCA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgdGhpcy5vbmFib3J0LmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBfZ2V0KF9nZXRQcm90b3R5cGVPZihBYm9ydFNpZ25hbDIucHJvdG90eXBlKSwgImRpc3BhdGNoRXZlbnQiLCB0aGlzKS5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEFib3J0U2lnbmFsMjsKICAgICAgfShFbWl0dGVyKTsKICAgICAgdmFyIEFib3J0Q29udHJvbGxlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBBYm9ydENvbnRyb2xsZXIyKCkgewogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0Q29udHJvbGxlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJzaWduYWwiLCB7CiAgICAgICAgICAgIHZhbHVlOiBuZXcgQWJvcnRTaWduYWwoKSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydENvbnRyb2xsZXIyLCBbewogICAgICAgICAga2V5OiAiYWJvcnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFib3J0KHJlYXNvbikgewogICAgICAgICAgICB2YXIgZXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgZXZlbnQgPSBuZXcgRXZlbnQoImFib3J0Iik7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICBpZiAodHlwZW9mIGRvY3VtZW50ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5jcmVhdGVFdmVudCkgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50T2JqZWN0KCk7CiAgICAgICAgICAgICAgICAgIGV2ZW50LnR5cGUgPSAiYWJvcnQiOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZXZlbnQgPSBkb2N1bWVudC5jcmVhdGVFdmVudCgiRXZlbnQiKTsKICAgICAgICAgICAgICAgICAgZXZlbnQuaW5pdEV2ZW50KCJhYm9ydCIsIGZhbHNlLCBmYWxzZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGV2ZW50ID0gewogICAgICAgICAgICAgICAgICB0eXBlOiAiYWJvcnQiLAogICAgICAgICAgICAgICAgICBidWJibGVzOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZTogZmFsc2UKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzaWduYWxSZWFzb24gPSByZWFzb247CiAgICAgICAgICAgIGlmIChzaWduYWxSZWFzb24gPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgPT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24ubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uID0gbmV3IERPTUV4Y2VwdGlvbigic2lnbmFsIGlzIGFib3J0ZWQgd2l0aG91dCByZWFzb24iKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnNpZ25hbC5yZWFzb24gPSBzaWduYWxSZWFzb247CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLmRpc3BhdGNoRXZlbnQoZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogInRvU3RyaW5n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AgICAgICAgfQogICAgICAgIHZhciBSZXF1ZXN0ID0gTmF0aXZlUmVxdWVzdDsKICAgICAgICBpZiAoUmVxdWVzdCAmJiAhUmVxdWVzdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkoInNpZ25hbCIpIHx8IF9fRk9SQ0VfSU5TVEFMTF9BQk9SVENPTlRST0xMRVJfUE9MWUZJTEwpIHsKICAgICAgICAgIFJlcXVlc3QgPSBmdW5jdGlvbiBSZXF1ZXN0MihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgICAgdmFyIHNpZ25hbDsKICAgICAgICAgICAgaWYgKGluaXQyICYmIGluaXQyLnNpZ25hbCkgewogICAgICAgICAgICAgIHNpZ25hbCA9IGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciByZXF1ZXN0ID0gbmV3IE5hdGl2ZVJlcXVlc3QoaW5wdXQsIGluaXQyKTsKICAgICAgICAgICAgaWYgKHNpZ25hbCkgewogICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShyZXF1ZXN0LCAic2lnbmFsIiwgewogICAgICAgICAgICAgICAgd3JpdGFibGU6IGZhbHNlLAogICAgICAgICAgICAgICAgZW51bWVyYWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgICB2YWx1ZTogc2lnbmFsCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlcXVlc3Q7CiAgICAgICAgICB9OwogICAgICAgICAgUmVxdWVzdC5wcm90b3R5cGUgPSBOYXRpdmVSZXF1ZXN0LnByb3RvdHlwZTsKICAgICAgICB9CiAgICAgICAgdmFyIHJlYWxGZXRjaCA9IGZldGNoOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAg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WRkIGEgc2lnbmFsLCBhbHJlYWR5IGFib3J0ZWQhIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLnNpZ25hbHMuYWRkKHNpZ25hbCk7CiAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBoYW5kbGVBYm9ydGVkKHNpZ25hbCkgewogICAgICAgICAgdGhpcy5zaWduYWxzLmRlbGV0ZShzaWduYWwpOwogICAgICAgICAgaWYgKHRoaXMuc2lnbmFscy5zaXplID09PSAwKSB7CiAgICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaWduYWwoKSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5hYm9ydENvbnRyb2xsZXIuc2lnbmFsOwogICAgICAgIH0KICAgICAgICBhYm9ydCgpIHsKICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyLmFib3J0KCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5kZWZhdWx0ID0gQWdncmVnYXRlQWJvcnRDb250cm9sbGVyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9BZ2dyZW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WdlID09PSAiRXJyb3I6IGFib3J0ZWQiOwogICAgICAgIH0KICAgICAgICBldmljdChrZXksIGVudHJ5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5nZXQoa2V5KSA9PT0gZW50cnkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGNvbnN0IGFib3J0ZXIgPSBuZXcgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyXzEuZGVmYXVsdCgpOwogICAgICAgICAgY29uc3Qgc3RhdHVzUmVwb3J0ZXIgPSBuZXcgQWdncmVnYXRlU3RhdHVzUmVwb3J0ZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBzdGF0dXNSZXBvcnRlci5hZGRDYWxsYmFjayhzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICBjb25zdCBuZXdFbnRyeSA9IHsKICAgICAgICAgICAgYWJvcnRlciwKICAgICAgICAgICAgcHJvbWlzZTogdGhpcy5maWxsQ2FsbGJhY2soZGF0YSwgYWJvcnRlci5zaWduYWwsIChtZXNzYWdlKSA9PiB7CiAgICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIuY2FsbGJhY2sobWVzc2FnZSk7CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBzZXR0bGVkOiBmYWxzZSwKICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIsCiAgICAgICAgICAgIGdldCBhYm9ydGVkKCkgewogICAgICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0ZXIuc2lnbmFsLmFib3J0ZWQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgbmV3RW50cnkuYWJvcnRlci5zaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgIGlmICghbmV3RW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgICAgbmV3RW50cnkucHJvbWlzZS50aGVuKCgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgIG5ld0VudHJ5LnNldHRsZWQgPSB0cnVlOwogICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgbmV3RW50cnkpOwogICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTsKICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgIH0pOwogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyBjaGVja1NpbmdsZVByb21pc2UocHJvbWlzZSwgc2lnbmFsKSB7CiAgICAgICAgICBmdW5jdGlvbiBjaGVja0ZvclNpbmdsZUFib3J0KCkgewogICAgICAgICAgICBpZiAoc2lnbmFsICYmIHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgICAgdGhyb3cgT2JqZWN0LmFzc2lnbihuZXcgRXJyb3IoImFib3J0ZWQiKSwgeyBjb2RlOiAiRVJSX0FCT1JURUQiIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcHJvbWlzZS50aGVuKChyZXN1bHQpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgfSwgKGVycm9yKSA9PiB7CiAgICAgICAgICAgIGNoZWNrRm9yU2luZ2xlQWJvcnQoKTsKICAgICAgICAgICAgdGhyb3cgZXJyb3I7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIGdldChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGlmICghc2lnbmFsICYmIGRhdGEgaW5zdGFuY2VvZiBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMS5BYm9ydFNpZ25hbCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJzZWNvbmQgZ2V0IGFyZ3VtZW50IGFwcGVhcnMgdG8gYmUgYW4gQWJvcnRTaWduYWwsIHBlcmhhcHMgeW91IG1lYW50IHRvIHBhc3MgYG51bGxgIGZvciB0aGUgZmlsbCBkYXRhPyIpOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgY2FjaGVFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVFbnRyeSkgewogICAgICAgICAgICBpZiAoY2FjaGVFbnRyeS5hYm9ydGVkICYmICFjYWNoZUVudHJ5LnNldHRsZWQpIHsKICAgICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgY2FjaGVFbnRyeSk7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNhY2hlRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHJldHVybiBjYWNoZUVudHJ5LnByb21pc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2FjaGVFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBjYWNoZUVudHJ5LnN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKGNhY2hlRW50cnkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKHRoaXMuY2FjaGUuZ2V0KGtleSkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgY2FjaGVkRW50cnkgPSB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgaWYgKGNhY2hlZEVudHJ5KSB7CiAgICAgICAgICAgIGlmICghY2FjaGVkRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIGNhY2hlZEVudHJ5LmFib3J0ZXIuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIGNvbnN0IGtleUl0ZXIgPSB0aGlzLmNhY2hlLmtleXMoKTsKICAgICAgICAgIGxldCBkZWxldGVDb3VudCA9IDA7CiAgICAgICAgICBmb3IgKGxldCByZXN1bHQgPSBrZXlJdGVyLm5leHQoKTsgIXJlc3VsdC5kb25lOyByZXN1bHQgPSBrZXlJdGVyLm5leHQoKSkgewogICAgICAgICAgICB0aGlzLmRlbGV0ZShyZXN1bHQudmFsdWUpOwogICAgICAgICAgICBkZWxldGVDb3VudCArPSAxOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGRlbGV0ZUNvdW50OwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhw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yZV9xdWlja19scnUgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcXVpY2stbHJ1QDQuMC4xL25vZGVfbW9kdWxlcy9xdWljay1scnUvaW5kZXguanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgUXVpY2tMUlUgPSBjbGFzcyB7CiAgICAgICAgY29uc3RydWN0b3Iob3B0aW9ucyA9IHt9KSB7CiAgICAgICAgICBpZiAoIShvcHRpb25zLm1heFNpemUgJiYgb3B0aW9ucy5tYXhTaXplID4gMCkpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMubWF4U2l6ZSA9IG9wdGlvbnMubWF4U2l6ZTsKICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgIF9zZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB0aGlzLl9zaXplKys7CiAgICAgICAgICBpZiAodGhpcy5fc2l6ZSA+PSB0aGlzLm1heFNpemUpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSB0aGlzLmNhY2hlOwogICAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIGNvbnN0IHZhbHVlID0gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNldChrZXksIHZhbHVlKSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KSB8fCB0aGlzLm9sZENhY2hlLmhhcyhrZXkpOwogICAgICAgIH0KICAgICAgICBwZWVrKGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgICAgICB0aGlzLl9zaXplLS07CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICAqa2V5cygpIHsKICAgICAgICAgIGZvciAoY29uc3QgW2tleV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCBrZXk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICp2YWx1ZXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqW1N5bWJvbC5pdGVyYXRvcl0oKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICAgICAgY29uc3QgW2tleV0gPSBpdGVtOwogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaXplKCkgewogICAgICAgICAgbGV0IG9sZENhY2hlU2l6ZSA9IDA7CiAgICAgICAgICBmb3IgKGNvbnN0IGtleSBvZiB0aGlzLm9sZENhY2hlLmtleXMoKSkgewogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICBvbGRDY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9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzMi5hc3NpZ24gPSBmdW5jdGlvbihvYmopIHsKICAgICAgICB2YXIgc291cmNlcyA9IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7CiAgICAgICAgd2hpbGUgKHNvdXJjZXMubGVuZ3RoKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlcy5zaGlmdCgpOwogICAgICAgICAgaWYgKCFzb3VyY2UpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIHNvdXJjZSAhPT0gIm9iamVjdCIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihzb3VyY2UgKyAibXVzdCBiZSBub24tb2JqZWN0Iik7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBwIGluIHNvdXJjZSkgewogICAgICAgICAgICBpZiAoX2hhcyhzb3VyY2UsIHApKSB7CiAgICAgICAgICAgICAgb2JqW3BdID0gc291cmNlW3BdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBvYmo7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNocmlua0J1ZiA9IGZ1bmN0aW9uKGJ1Ziwgc2l6ZSkgewogICAgICAgIGlmIChidWYubGVuZ3RoID09PSBzaXplKSB7CiAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgIH0KICAgICAgICBpZiAoYnVmLnN1YmFycmF5KSB7CiAgICAgICAgICByZXR1cm4gYnVmLnN1YmFycmF5KDAsIHNpemUpOwogICAgICAgIH0KICAgICAgICBidWYubGVuZ3RoID0gc2l6ZTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9OwogICAgICB2YXIgZm5UeXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGlmIChzcmMuc3ViYXJyYXkgJiYgZGVzdC5zdWJhcnJheSkgewogICAgICAgICAgICBkZXN0LnNldChzcmMuc3ViYXJyYXkoc3JjX29mZnMsIHNyY19vZmZzICsgbGVuKSwgZGVzdF9vZmZzKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHZhciBpLCBsLCBsZW4sIHBvcywgY2h1bmssIHJlc3VsdDsKICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBsZW4gKz0gY2h1bmtzW2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJlc3VsdCA9IG5ldyBVaW50OEFycmF5KGxlbik7CiAgICAgICAgICBwb3MgPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgY2h1bmsgPSBjaHVua3NbaV07CiAgICAgICAgICAgIHJlc3VsdC5zZXQoY2h1bmssIHBvcyk7CiAgICAgICAgICAgIHBvcyArPSBjaHVuay5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGZuVW50eXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICByZXR1cm4gW10uY29uY2F0LmFwcGx5KFtdLCBjaHVua3MpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IFVpbnQ4QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IFVpbnQxNkFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0czIuYXNzaWduKGV4cG9ydHMyLCBmblR5cGVkKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMTYgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjMyID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVW50eXBlZCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZChUWVBFRF9PSyk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcwogIHZhciByZXF1aXJlX3RyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBt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ICAgICB0cmVlW3MuaGVhcFtzLmhlYXBfbWF4XSAqIDIgKyAxXSA9IDA7CiAgICAgICAgZm9yIChoID0gcy5oZWFwX21heCArIDE7IGggPCBIRUFQX1NJWkU7IGgrKykgewogICAgICAgICAgbiA9IHMuaGVhcFtoXTsKICAgICAgICAgIGJpdHMgPSB0cmVlW3RyZWVbbiAqIDIgKyAxXSAqIDIgKyAxXSArIDE7CiAgICAgICAgICBpZiAoYml0cyA+IG1heF9sZW5ndGgpIHsKICAgICAgICAgICAgYml0cyA9IG1heF9sZW5ndGg7CiAgICAgICAgICAgIG92ZXJmbG93Kys7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgaWYgKG4gPiBtYXhfY29kZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10rKzsKICAgICAgICAgIHhiaXRzID0gMDsKICAgICAgICAgIGlmIChuID49IGJhc2UpIHsKICAgICAgICAgICAgeGJpdHMgPSBleHRyYVtuIC0gYmFzZV07CiAgICAgICAgICB9CiAgICAgICAgICBmID0gdHJlZVtuICogMl07CiAgICAgICAgICBzLm9wdF9sZW4gKz0gZiAqIChiaXRzICsgeGJpdHMpOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gKz0gZiAqIChzdHJlZVtuICogMiArIDFdICsgeGJpdHMpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3ZlcmZsb3cgPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgYml0cyA9IG1heF9sZW5ndGggLSAxOwogICAgICAgICAgd2hpbGUgKHMuYmxfY291bnRbYml0c10gPT09IDApIHsKICAgICAgICAgICAgYml0cy0tOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXS0tOwogICAgICAgICAgcy5ibF9jb3VudFtiaXRzICsgMV0gKz0gMjsKICAgICAgICAgIHMuYmxfY291bnRbbWF4X2xlbmd0aF0tLTsKICAgICAgICAgIG92ZXJmbG93IC09IDI7CiAgICAgICAgfSB3aGlsZSAob3ZlcmZsb3cgPiAwKTsKICAgICAgICBmb3IgKGJpdHMgPSBtYXhfbGVuZ3RoOyBiaXRzICE9PSAwOyBiaXRzLS0pIHsKICAgICAgICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdOwogICAgICAgICAgd2hpbGUgKG4gIT09IDApIHsKICAgICAgICAgICAgbSA9IHMuaGVhcFstLWhdOwogICAgICAgICAgICBpZiAobSA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRyZWVbbSAqIDIgKyAxXSAhPT0gYml0cykgewogICAgICAgICAgICAgIHMub3B0X2xlbiArPSAoYml0cyAtIHRyZWVbbSAqIDIgKyAxXSkgKiB0cmVlW20gKiAyXTsKICAgICAgICAgICAgICB0cmVlW20gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG4tLTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBibF9jb3VudCkgewogICAgICAgIHZhciBuZXh0X2NvZGUgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICB2YXIgY29kZSA9IDA7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChiaXRzID0gMTsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBuZXh0X2NvZGVbYml0c10gPSBjb2RlID0gY29kZSArIGJsX2NvdW50W2JpdHMgLSAxXSA8PCAxOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIHZhciBsZW4gPSB0cmVlW24gKiAyICsgMV07CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG5leHRfY29kZVtsZW5dKyssIGxlbik7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyX3N0YXRpY19pbml0KCkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsZW5ndGg7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGJsX2NvdW50ID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgTEVOR1RIX0NPREVTIC0gMTsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2xlbmd0aFtjb2RlXSA9IGxlbmd0aDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2xiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGggLSAxXSA9IGNvZGU7CiAgICAgICAgZGlzdCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IDE2OyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3Q7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRpc3QgPj49IDc7CiAgICAgICAgZm9yICg7IGNvZGUgPCBEX0NPREVTOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3QgPDwgNzsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdIC0gNzsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbMjU2ICsgZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICBuID0gMDsKICAgICAgICB3aGlsZSAobiA8PSAxNDMpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI1NSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA5OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOV0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjc5KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDc7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs3XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyODcpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIGdlbl9jb2RlcyhzdGF0aWNfbHRyZWUsIExfQ09ERVMgKyAxLCBibF9jb3VudCk7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyICsgMV0gPSA1OwogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobiwgNSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpY19sX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2x0cmVlLCBleHRyYV9sYml0cywgTElURVJBTFMgKyAxLCBMX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2RfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfZHRyZWUsIGV4dHJhX2RiaXRzLCAwLCBEX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2JsX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2MobmV3IEFycmF5KDApLCBleHRyYV9ibGJpdHMsIDAsIEJMX0NPREVTLCBNQVhfQkxfQklUUyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5pdF9ibG9jayhzKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8IExfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fbHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fZHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuYmxfdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXSA9IDE7CiAgICAgICAgcy5vcHRfbGVuID0gcy5zdGF0aWNfbGVuID0gMDsKICAgICAgICBzLmxhc3RfbGl0ID0gcy5tYXRjaGVzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV93aW5kdXAocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gOCkgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICB9IGVsc2UgaWYgKHMuYmlfdmFsaWQgPiAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmOwogICAgICAgIH0KICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29weV9ibG9jayhzLCBidWYsIGxlbiwgaGVhZGVyKSB7CiAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIGlmIChoZWFkZXIpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBsZW4pOwogICAgICAgICAgcHV0X3Nob3J0KHMsIH5sZW4pOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzLnBlbmRpbmdfYnVmLCBzLndpbmRvdywgYnVmLCBsZW4sIHMucGVuZGluZyk7CiAgICAgICAgcy5wZW5kaW5nICs9IGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBzbWFsbGVyKHRyZWUsIG4sIG0sIGRlcHRoKSB7CiAgICAgICAgdmFyIF9uMiA9IG4gKiAyOwogICAgICAgIHZhciBfbTIgPSBtICogMjsKICAgICAgICByZXR1cm4gdHJlZVtfbjJdIDwgdHJlZVtfbTJdIHx8IHRyZWVbX24yXSA9PT0gdHJlZVtfbTJdICYmIGRlcHRoW25dIDw9IGRlcHRoW21dOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBxZG93bmhlYXAocywgdHJlZSwgaykgewogICAgICAgIHZhciB2ID0gcy5oZWFwW2tdOwogICAgICAgIHZhciBqID0gayA8PCAxOwogICAgICAgIHdoaWxlIChqIDw9IHMuaGVhcF9sZW4pIHsKICAgICAgICAgIGlmIChqIDwgcy5oZWFwX2xlbiAmJiBzbWFsbGVyKHRyZWUsIHMuaGVhcFtqICsgMV0sIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgaisrOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHNtYWxsZXIodHJlZSwgdiwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHMuaGVhcFtrXSA9IHMuaGVhcFtqXTsKICAgICAgICAgIGsgPSBqOwogICAgICAgICAgaiA8PD0gMTsKICAgICAgICB9CiAgICAgICAgcy5oZWFwW2tdID0gdjsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb21wcmVzc19ibG9jayhzLCBsdHJlZSwgZHRyZWUpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgbGM7CiAgICAgICAgdmFyIGx4ID0gMDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZXh0cmE7CiAgICAgICAgaWYgKHMubGFzdF9saXQgIT09IDApIHsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZGlzdCA9IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMl0gPDwgOCB8IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMiArIDFdOwogICAgICAgICAgICBsYyA9IHMucGVuZGluZ19idWZbcy5sX2J1ZiArIGx4XTsKICAgICAgICAgICAgbHgrKzsKICAgICAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgbGMsIGx0cmVlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBjb2RlID0gX2xlbmd0aF9jb2RlW2xjXTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSArIExJVEVSQUxTICsgMSwgbHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfbGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsYyAtPSBiYXNlX2xlbmd0aFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBsYywgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBkaXN0LS07CiAgICAgICAgICAgICAgY29kZSA9IGRfY29kZShkaXN0KTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSwgZHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfZGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBkaXN0IC09IGJhc2VfZGlzdFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBkaXN0LCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChseCA8IHMubGFzdF9saXQpOwogICAgICAgIH0KICAgICAgICBzZW5kX2NvZGUocywgRU5EX0JMT0NLLCBsdHJlZSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfdHJlZShzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGVsZW1zID0gZGVzYy5zdGF0X2Rlc2MuZWxlbXM7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIG1heF9jb2RlID0gLTE7CiAgICAgICAgdmFyIG5vZGU7CiAgICAgICAgcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgcy5oZWFwX21heCA9IEhFQVBfU0laRTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgZWxlbXM7IG4rKykgewogICAgICAgICAgaWYgKHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPSBuOwogICAgICAgICAgICBzLmRlcHRoW25dID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdoaWxlIChzLmhlYXBfbGVuIDwgMikgewogICAgICAgICAgbm9kZSA9IHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPCAyID8gKyttYXhfY29kZSA6IDA7CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IDE7CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gMDsKICAgICAgICAgIHMub3B0X2xlbi0tOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gLT0gc3RyZWVbbm9kZSAqIDIgKyAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVzYy5tYXhfY29kZSA9IG1heF9jb2RlOwogICAgICAgIGZvciAobiA9IHMuaGVhcF9sZW4gPj4gMTsgbiA+PSAxOyBuLS0pIHsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgbik7CiAgICAgICAgfQogICAgICAgIG5vZGUgPSBlbGVtczsKICAgICAgICBkbyB7CiAgICAgICAgICBuID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWzFdID0gcy5oZWFwW3MuaGVhcF9sZW4tLV07CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgICAgbSA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbjsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbTsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gdHJlZVtuICogMl0gKyB0cmVlW20gKiAyXTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAocy5kZXB0aFtuXSA+PSBzLmRlcHRoW21dID8gcy5kZXB0aFtuXSA6IHMuZGVwdGhbbV0pICsgMTsKICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IHRyZWVbbSAqIDIgKyAxXSA9IG5vZGU7CiAgICAgICAgICBzLmhlYXBbMV0gPSBub2RlKys7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgIH0gd2hpbGUgKHMuaGVhcF9sZW4gPj0gMik7CiAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBzLmhlYXBbMV07CiAgICAgICAgZ2VuX2JpdGxlbihzLCBkZXNjKTsKICAgICAgICBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIHMuYmxfY291bnQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNjYW5fdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdID0gNjU1MzU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdICs9IGNvdW50OwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBfM182ICogMl0rKzsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8xMV8xMzggKiAyXSsrOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIH0gd2hpbGUgKC0tY291bnQgIT09IDApOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgICAgY291bnQtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQXzNfNiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzNfMTAsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDMpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfMTFfMTM4LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAxMSwgNyk7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX2JsX3RyZWUocykgewogICAgICAgIHZhciBtYXhfYmxpbmRleDsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fbHRyZWUsIHMubF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fZHRyZWUsIHMuZF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBidWlsZF90cmVlKHMsIHMuYmxfZGVzYyk7CiAgICAgICAgZm9yIChtYXhfYmxpbmRleCA9IEJMX0NPREVTIC0gMTsgbWF4X2JsaW5kZXggPj0gMzsgbWF4X2JsaW5kZXgtLSkgewogICAgICAgICAgaWYgKHMuYmxfdHJlZVtibF9vcmRlclttYXhfYmxpbmRleF0gKiAyICsgMV0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMub3B0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KICAgICAgICBzZW5kX2JpdHMocywgU1RBVElDX1RSRUVTIDw8IDEsIDMpOwogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIHN0YXRpY19sdHJlZSk7CiAgICAgICAgYmlfZmx1c2gocyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3RyX2ZsdXNoX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCkgewogICAgICAgIHZhciBvcHRfbGVuYiwgc3RhdGljX2xlbmI7CiAgICAgICAgdmFyIG1heF9ibGluZGV4ID0gMDsKICAgICAgICBpZiAocy5sZXZlbCA+IDApIHsKICAgICAgICAgIGlmIChzLnN0cm0uZGF0YV90eXBlID09PSBaX1VOS05PV04pIHsKICAgICAgICAgICAgcy5zdHJtLmRhdGFfdHlwZSA9IGRldGVjdF9kYXRhX3R5cGUocyk7CiAgICAgICAgICB9CiAgICAgICAgICBidWlsZF90cmVlKHMsIHMubF9kZXNjKTsKICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5kX2Rlc2MpOwogICAgICAgICAgbWF4X2JsaW5kZXggPSBidWlsZF9ibF90cmVlKHMpOwogICAgICAgICAgb3B0X2xlbmIgPSBzLm9wdF9sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIHN0YXRpY19sZW5iID0gcy5zdGF0aWNfbGVuICsgMyArIDcgPj4+IDM7CiAgICAgICAgICBpZiAoc3RhdGljX2xlbmIgPD0gb3B0X2xlbmIpIHsKICAgICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYiA9IHN0b3JlZF9sZW4gKyA1OwogICAgICAgIH0KICAgICAgICBpZiAoc3RvcmVkX2xlbiArIDQgPD0gb3B0X2xlbmIgJiYgYnVmICE9PSAtMSkgewogICAgICAgICAgX3RyX3N0b3JlZF9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIGxhc3QpOwogICAgICAgIH0gZWxzZSBpZiAocy5zdHJhdGVneSA9PT0gWl9GSVhFRCB8fCBzdGF0aWNfbGVuYiA9PT0gb3B0X2xlbmIpIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoU1RBVElDX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgc3RhdGljX2x0cmVlLCBzdGF0aWNfZHRyZWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgKERZTl9UUkVFUyA8PCAxKSArIChsYXN0ID8gMSA6IDApLCAzKTsKICAgICAgICAgIHNlbmRfYWxsX3RyZWVzKHMsIHMubF9kZXNjLm1heF9jb2RlICsgMSwgcy5kX2Rlc2MubWF4X2NvZGUgKyAxLCBtYXhfYmxpbmRleCArIDEpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgcy5keW5fbHRyZWUsIHMuZHluX2R0cmVlKTsKICAgICAgICB9CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgICBpZiAobGFzdCkgewogICAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfdGFsbHkocywgZGlzdCwgbGMpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBzLmxhc3RfbGl0ICogMl0gPSBkaXN0ID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyICsgMV0gPSBkaXN0ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5sX2J1ZiArIHMubGFzdF9saXRdID0gbGMgJiAyNTU7CiAgICAgICAgcy5sYXN0X2xpdCsrOwogICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtsYyAqIDJdKys7CiAgICA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GlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gYWRsZXIzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NyYzMyLmpzCiAgdmFyIHJlcXVpcmVfY3JjMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogIC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mFyIFpfUkxFID0gMzsKICAgICAgdmFyIFpfRklYRUQgPSA0OwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfVU5LTk9XTiA9IDI7CiAgICAgIHZhciBaX0RFRkxBVEVEID0gODsKICAgICAgdmFyIE1BWF9NRU1fTEVWRUwgPSA5OwogICAgICB2YXIgTUFYX1dCSVRTID0gMTU7CiAgICAgIHZhciBERUZfTUVNX0xFVkVMID0gODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBNSU5fTUFUQ0ggPSAzOwogICAgICB2YXIgTUFYX01BVENIID0gMjU4OwogICAgICB2YXIgTUlOX0xPT0tBSEVBRCA9IE1BWF9NQVRDSCArIE1JTl9NQVRDSCArIDE7CiAgICAgIHZhciBQUkVTRVRfRElDVCA9IDMyOwogICAgICB2YXIgSU5JVF9TVEFURSA9IDQyOwogICAgICB2YXIgRVhUUkFfU1RBVEUgPSA2OTsKICAgICAgdmFyIE5BTUVfU1RBVEUgPSA3MzsKICAgICAgdmFyIENPTU1FTlRfU1RBVEUgPSA5MTsKICAgICAgdmFyIEhDUkNfU1RBVEUgPSAxMDM7CiAgICAgIHZhciBCVVNZX1NUQVRFID0gMTEzOwogICAgICB2YXIgRklOSVNIX1NUQVRFID0gNjY2OwogICAgICB2YXIgQlNfTkVFRF9NT1JFID0gMTsKICAgICAgdmFyIEJTX0JMT0NLX0RPTkUgPSAyOwogICAgICB2YXIgQlNfRklOSVNIX1NUQVJURUQgPSAzOwogICAgICB2YXIgQlNfRklOSVNIX0RPTkUgPSA0OwogICAgICB2YXIgT1NfQ09ERSA9IDM7CiAgICAgIGZ1bmN0aW9uIGVycihzdHJtLCBlcnJvckNvZGUpIHsKICAgICAgICBzdHJtLm1zZyA9IG1zZ1tlcnJvckNvZGVdOwogICAgICAgIHJldHVybiBlcnJvckNvZGU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmFuayhmKSB7CiAgICAgICAgcmV0dXJuIChmIDw8IDEpIC0gKGYgPiA0ID8gOSA6IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHplcm8oYnVmKSB7CiAgICAgICAgdmFyIGxlbiA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgd2hpbGUgKC0tbGVuID49IDApIHsKICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmx1c2hfcGVuZGluZyhzdHJtKSB7CiAgICAgICAgdmFyIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHZhciBsZW4gPSBzLnBlbmRpbmc7CiAgICAgICAgaWYgKGxlbiA+IHN0cm0uYXZhaWxfb3V0KSB7CiAgICAgICAgICBsZW4gPSBzdHJtLmF2YWlsX291dDsKICAgICAgICB9CiAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nX291dCwgbGVuLCBzdHJtLm5leHRfb3V0KTsKICAgICAgICBzdHJtLm5leHRfb3V0ICs9IGxlbjsKICAgICAgICBzLnBlbmRpbmdfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX291dCArPSBsZW47CiAgICAgICAgc3RybS5hdmFpbF9vdXQgLT0gbGVuOwogICAgICAgIHMucGVuZGluZyAtPSBsZW47CiAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gMCkgewogICAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX2Jsb2NrX29ubHkocywgbGFzdCkgewogICAgICAgIHRyZWVzLl90cl9mbHVzaF9ibG9jayhzLCBzLmJsb2NrX3N0YXJ0ID49IDAgPyBzLmJsb2NrX3N0YXJ0IDogLTEsIHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0LCBsYXN0KTsKICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gcy5zdHJzdGFydDsKICAgICAgICBmbHVzaF9wZW5kaW5nKHMuc3RybSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0X2J5dGUocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYjsKICAgICAgfQogICAgICBmdW5jdGlvbiBwdXRTaG9ydE1TQihzLCBiKSB7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBiID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiAmIDI1NTsKICAgICAgfQogICAgICBmdW5jdGlvbiByZWFkX2J1ZihzdHJtLCBidWYsIHN0YXJ0LCBzaXplKSB7CiAgICAgICAgdmFyIGxlbiA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgaWYgKGxlbiA+IHNpemUpIHsKICAgICAgICAgIGxlbiA9IHNpemU7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBzdHJtLmF2YWlsX2luIC09IGxlbjsKICAgICAgICB1dGlscy5hcnJheVNldChidWYsIHN0cm0uaW5wdXQsIHN0cm0ubmV4dF9pbiwgbGVuLCBzdGFydCk7CiAgICAgICAgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMSkgewogICAgICAgICAgc3RybS5hZGxlciA9IGFkb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NoKSB7CiAgICAgICAgICBjaGFpbl9sZW5ndGggPj49IDI7CiAgICAgICAgfQogICAgICAgIGlmIChuaWNlX21hdGNoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIG5pY2VfbWF0Y2ggPSBzLmxvb2thaGVhZDsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgbWF0Y2ggPSBjdXJfbWF0Y2g7CiAgICAgICAgICBpZiAoX3dpblttYXRjaCArIGJlc3RfbGVuXSAhPT0gc2Nhbl9lbmQgfHwgX3dpblttYXRjaCArIGJlc3RfbGVuIC0gMV0gIT09IHNjYW5fZW5kMSB8fCBfd2luW21hdGNoXSAhPT0gX3dpbltzY2FuXSB8fCBfd2luWysrbWF0Y2hdICE9PSBfd2luW3NjYW4gKyAxXSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHNjYW4gKz0gMjsKICAgICAgICAgIG1hdGNoKys7CiAgICAgICAgICBkbyB7CiAgICAgICAgICB9IHdoaWxlIChfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIHNjYW4gPCBzdHJlbmQpOwogICAgICAgICAgbGVuID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pOwogICAgICAgICAgc2NhbiA9IHN0cmVuZCAtIE1BWF9NQVRDSDsKICAgICAgICAgIGlmIChsZW4gPiBiZXN0X2xlbikgewogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoOwogICAgICAgICAgICBiZXN0X2xlbiA9IGxlbjsKICAgICAgICAgICAgaWYgKGxlbiA+PSBuaWNlX21hdGNoKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICAgICAgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKGN1cl9tYXRjaCA9IHByZXZbY3VyX21hdGNoICYgd21hc2tdKSA+IGxpbWl0ICYmIC0tY2hhaW5fbGVuZ3RoICE9PSAwKTsKICAgICAgICBpZiAoYmVzdF9sZW4gPD0gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBiZXN0X2xlbjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubG9va2FoZWFkOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZpbGxfd2luZG93KHMpIHsKICAgICAgICB2YXIgX3dfc2l6ZSA9IHMud19zaXplOwogICAgICAgIHZhciBwLCBuLCBtLCBtb3JlLCBzdHI7CiAgICAgICAgZG8gewogICAgICAgICAgbW9yZSA9IHMud2luZG93X3NpemUgLSBzLmxvb2thaGVhZCAtIHMuc3Ryc3RhcnQ7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA+PSBfd19zaXplICsgKF93X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzLndpbmRvdywgcy53aW5kb3csIF93X3NpemUsIF93X3NpemUsIDApOwogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBuID0gcy5oYXNoX3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMuaGVhZFstLXBdOwogICAgICAgICAgICAgIHMuaGVhZFtwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbiA9IF93X3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMucHJldlstLXBdOwogICAgICAgICAgICAgIHMucHJldltwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbW9yZSArPSBfd19zaXplOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9pbiA9PT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIG4gPSByZWFkX2J1ZihzLnN0cm0sIHMud2luZG93LCBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQsIG1vcmUpOwogICAgICAgICAgcy5sb29rYWhlYWQgKz0gbjsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0ID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0IC0gcy5pbnNlcnQ7CiAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzdHJdOwogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHdoaWxlIChzLmluc2VydCkgewogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICBzLnByZXZbc3RyICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgICBzdHIrKzsKICAgICAgICAgICAgICBzLmluc2VydC0tOwogICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0IDwgTUlOX01BVENIKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgcy5zdHJtLmF2YWlsX2luICE9PSAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3N0b3JlZChzLCBmbHVzaCkgewogICAgICAgIHZhciBtYXhfYmxvY2tfc2l6ZSA9IDY1NTM1OwogICAgICAgIGlmIChtYXhfYmxvY2tfc2l6ZSA+IHMucGVuZGluZ19idWZfc2l6ZSAtIDUpIHsKICAgICAgICAgIG1heF9ibG9ja19zaXplID0gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNTsKICAgICAgICB9CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5zdHJzdGFydCArPSBzLmxvb2thaGVhZDsKICAgICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICAgIHZhciBtYXhfc3RhcnQgPSBzLmJsb2NrX3N0YXJ0ICsgbWF4X2Jsb2NrX3NpemU7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA9PT0gMCB8fCBzLnN0cnN0YXJ0ID49IG1heF9zdGFydCkgewogICAgICAgICAgICBzLmxvb2thaGVhZCA9IHMuc3Ryc3RhcnQgLSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9mYXN0KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAgfQogICAgICAgICAgaWYgKGhhc2h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cnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzLnN0cnN0YXJ0XTsKICAgICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSBzLnN0cnN0YXJ0IDwgTUlOX01BVENIIC0gMSA/IHMuc3Ryc3RhcnQgOiBNSU5fTUFUQ0ggLSAxOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc2xvdyhzLCBmbHVzaCkgewogICAgICAgIHZhciBoYXNoX2hlYWQ7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICB2YXIgbWF4X2luc2VydDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBoYXNoX2hlYWQgPSAwOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgIH0KICAgICAgICAgIHMucHJldl9sZW5nd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sKICAgICAgICAgICAgICBpZiAoKytzLnN0cnN0YXJ0IDw9IG1heF9pbnNlcnQpIHsKICAgICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICgtLXMucHJldl9sZW5ndGggIT09IDApOwogICAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKHMubWF0Y2hfYXZhaWxhYmxlKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9ybGUocywgZmx1c2gpIHsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBwcmV2OwogICAgICAgIHZhciBzY2FuLCBzdHJlbmQ7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0gpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0ggJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7CiAgICAgICAgICAgIHNjYW4gPSBzLnN0cnN0YXJ0IC0gMTsKICAgICAgICAgICAgcHJldiA9IF93aW5bc2Nhbl07CiAgICAgICAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkgewogICAgICAgICAgICAgIHN0cmVuZCA9IHMuc3Ryc3RhcnQgKyBNQVhfTUFUQ0g7CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5sb29rYWhlYWQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAxLCBzLm1hdGNoX2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfaHVmZihzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgaWYgKGJmbHVzaCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBDb25maWcoZ29vZF9sZW5ndGgsIG1heF9sYXp5LCBuaWNlX2xlbmd0aCwgbWF4X2NoYWluLCBmdW5jKSB7CiAgICAgICAgdGhpcy5nb29kX2xlbmd0aCA9IGdvb2RfbGVuZ3RoOwogICAgICAgIHRoaXMubWF4X2xhenkgPSBtYXhfbGF6eTsKICAgICAgICB0aGlzLm5pY2VfbGVuZ3RoID0gbmljZV9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfY2hhaW4gPSBtYXhfY2hhaW47CiAgICAgICAgdGhpcy5mdW5jID0gZnVuYzsKICAgICAgfQogICAgICB2YXIgY29uZm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m5pY2VfbGVuZ3RoOwogICAgICAgIHMubWF4X2NoYWluX2xlbmd0aCA9IGNvbmZpZ3VyYXRpb25fdGFibGVbcy5sZXZlbF0ubWF4X2NoYWluOwogICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSAwOwogICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLnByZXZfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgcy5pbnNfaCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gRGVmbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMuc3RybSA9IG51bGw7CiAgICAgICAgdGhpcy5zdGF0dXMgPSAwOwogICAgICAgIHRoaXMucGVuZGluZ19idWYgPSBudWxsOwogICAgICAgIHRoaXMucGVuZGluZ19idWZfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nID0gMDsKICAgICAgICB0aGlzLndyYXAgPSAwOwogICAgICAgIHRoaXMuZ3poZWFkID0gbnVsbDsKICAgICAgICB0aGlzLmd6aW5kZXggPSAwOwogICAgICAgIHRoaXMubWV0aG9kID0gWl9ERUZMQVRFRDsKICAgICAgICB0aGlzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICB0aGlzLndfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy53X2JpdHMgPSAwOwogICAgICAgIHRoaXMud19tYXNrID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy53aW5kb3dfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wcmV2ID0gbnVsbDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuaW5zX2ggPSA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AgICAgIHMucGVuZGluZyA9IDA7CiAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgaWYgKHMud3JhcCA8IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHMuc3RhdHVzID0gcy53cmFwID8gSU5JVF9TVEFURSA6IEJVU1lfU1RBVEU7CiAgICAgICAgc3RybS5hZGxlciA9IHMud3JhcCA9PT0gMiA/IDAgOiAxOwogICAgICAgIHMubGFzdF9mbHVzaCA9IFpfTk9fRkxVU0g7CiAgICAgICAgdHJlZXMuX3RyX2luaXQocyk7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgcmV0ID0gZGVmbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgICBpZiAocmV0ID09PSBaX09LKSB7CiAgICAgICAgICBsbV9pbml0KHN0cm0uc3RhdGUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RybS5zdGF0ZS53cmFwICE9PSAyKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUuZ3poZWFkID0gaGVhZDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlSW5pdDIoc3RybSwgbGV2ZWwsIG1ldGhvZCwgd2luZG93Qml0cywgbWVtTGV2ZWwsIHN0cmF0ZWd5KSB7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciB3cmFwID0gMTsKICAgICAgICBpZiAobGV2ZWwgPT09IFpfREVGQVVMVF9DT01QUkVTU0lPTikgewogICAgICAgICAgbGV2ZWwgPSA2OwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAod2luZG93Qml0cyA+IDE1KSB7CiAgICAgICAgICB3cmFwID0gMjsKICAgICAgICAgIHdpbmRvd0JpdHMgLT0gMTY7CiAgICAgICAgfQogICAgICAgIGlmIChtZW1MZXZlbCA8IDEgfHwgbWVtTGV2ZWwgPiBNQVhfTUVNX0xFVkVMIHx8IG1ldGhvZCAhPT0gWl9ERUZMQVRFRCB8fCB3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUgfHwgbGV2ZWwgPCAwIHx8IGxldmVsID4gOSB8fCBzdHJhdGVneSA8IDAgfHwgc3RyYXRlZ3kgPiBaX0ZJWEVEKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfU1RSRUFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHdpbmRvd0JpdHMgPT09IDgpIHsKICAgICAgICAgIHdpbmRvd0JpdHMgPSA5OwogICAgICAgIH0KICAgICAgICB2YXIgcyA9IG5ldyBEZWZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gczsKICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIHMud3JhcCA9IHdyYXA7CiAgICAgICAgcy5nemhlYWQgPSBudWxsOwogICAgICAgIHMud19iaXRzID0gd2luZG93Qml0czsKICAgICAgICBzLndfc2l6ZSA9IDEgPDwgcy53X2JpdHM7CiAgICAgICAgcy53X21hc2sgPSBzLndfc2l6ZSAtIDE7C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AgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIE9TX0NPREUpOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICsgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNikpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAxNiAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAyNCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLm9zICYgMjU1KTsKICAgICAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggJiAyNTUpOwogICAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoID4+IDggJiAyNTUpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmFbcy5nemluZGV4XSAmIDI1NSk7CiAgICAgICAgICAgICAgcy5nemluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemluZGV4ID09PSBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gTkFNRV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IE5BTUVfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5uYW1lKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHZhbCA9PT0gMCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gQ09NTUVOVF9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQuY29tbWVudC5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnBlbmRpbmcgIT09IDApIHsKICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIHJldHVybiBaX09LOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiByYW5rKGZsdXNoKSA8PSByYW5rKG9sZF9mbHVzaCkgJiYgZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09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GZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKH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fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgIC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lmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCAxMjgpIHsKICAgICAgICAgICAgYnVmW2krK10gPSBjOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgMjA0OCkgewogICAgICAgICAgICBidWZbaSsrXSA9IDE5MiB8IGMgPj4+IDY7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgNjU1MzYpIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyMjQgfCBjID4+PiAxMjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiA2ICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyNDAgfCBjID4+PiAxODsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiAxMiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ1ZjJiaW5zdHJpbmcoYnVmLCBsZW4pIHsKICAgICAgICBpZiAobGVuIDwgNjU1MzQpIHsKICAgICAgICAgIGlmIChidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX1VJQV9PSyB8fCAhYnVmLnN1YmFycmF5ICYmIFNUUl9BUFBMWV9PSykgewogICAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShudWxsLCB1dGlscy5zaHJpbmtCdWYoYnVmLCBsZW4pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ1ZltpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KICAgICAgZXhwb3J0czIuYnVmMmJpbnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZikgewogICAgICAgIHJldHVybiBidWYyYmluc3RyaW5nKGJ1ZiwgYnVmLmxlbmd0aCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJ1ZjJzdHJpbmcgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBpLCBvdXQsIGMsIGNfbGVuOwogICAgICAgIHZhciBsZW4gPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICB2YXIgdXRmMTZidWYgPSBuZXcgQXJyYXkobGVuICogMik7CiAgICAgICAgZm9yIChvdXQgPSAwLCBpID0gMDsgaSA8IGxlbjsgKSB7CiAgICAgICAgICBjID0gYnVmW2krK107CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGNfbGVuID0gX3V0ZjhsZW5bY107CiAgICAgICAgICBpZiAoY19sZW4gPiA0KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IDY1NTMzOwogICAgICAgICAgICBpICs9IGNfbGVuIC0gMTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBjICY9IGNfbGVuID09PSAyID8gMzEgOiBjX2xlbiA9PT0gMyA/IDE1IDogNzsKICAgICAgICAgIHdoaWxlIChjX2xlbiA+IDEgJiYgaSA8IGxlbikgewogICAgICAgICAgICBjID0gYyA8PCA2IHwgYnVmW2krK10gJiA2MzsKICAgICAgICAgICAgY19sZW4tLTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChjX2xlbiA+IDEpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYyAtPSA2NTUzNjsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTUyOTYgfCBjID4+IDEwICYgMTAyMzsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTYzMjAgfCBjICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcodXRmMTZidWYsIG91dCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnV0Zjhib3JkZXIgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBwb3M7CiAgICAgICAgbWF4ID0gbWF4IHx8IGJ1Zi5sZW5ndGg7CiAgICAgICAgaWYgKG1heCA+IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIG1heCA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHBvcyA9IG1heCAtIDE7CiAgICAgICAgd2hpbGUgKHBvcyA+PSAwICYmIChidWZbcG9zXSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgcG9zLS07CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPCAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAocG9zID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcG9zICsgX3V0ZjhsZW5bYnVmW3Bvc11dID4gbWF4ID8gcG9zIDogbWF4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcwogIHZhciByZXF1aXJlX3pzdHJlYW0gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIFpTdHJlYW0oKSB7CiAgICAgICAgdGhpcy5pbnB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X2luID0gMDsKICAgICAgICB0aGlzLmF2YWlsX2luID0gMDsKICAgICAgICB0aGlzLnRvdGFsX2luID0gMDsKICAgICAgICB0aGlzLm91dHB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X291dCA9IDA7CiAgICAgICAgdGhpcy5hdmFpbF9vdXQgPSAwOwogICAgICAgIHRoaXMudG90YWxfb3V0ID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuc3RhdGUgPSBud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ZShvcHRpb25zKSB7CiAgICAgICAgaWYgKCEodGhpcyBpbnN0YW5jZW9mIERlZmxhdGUpKQogICAgICAgICAgcmV0dXJuIG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBsZXZlbDogWl9ERUZBVUxUX0NPTVBSRVNTSU9OLAogICAgICAgICAgbWV0aG9kOiBaX0RFRkxBVEVELAogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDE1LAogICAgICAgICAgbWVtTGV2ZWw6IDgsCiAgICAgICAgICBzdHJhdGVneTogWl9ERUZBVUxUX1NUUkFURUdZLAogICAgICAgICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+IDApIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAob3B0Lmd6aXAgJiYgb3B0LndpbmRvd0JpdHMgPiAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDE2OwogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LmxldmVsLCBvcHQubWV0aG9kLCB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ICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgc3RhdHVzLCBfbW9kZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gWl9GSU5JU0ggOiBaX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLnN0cmluZzJidWYoZGF0YSk7CiAgICAgICAgfSBlbHNlIGlmICh0b1N0cmluZy5jYWxsKGRhdGEpID09PSAiW29iamVjdCBBcnJheUJ1ZmZlcl0iKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gbmV3IFVpbnQ4QXJyYXkoZGF0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZShzdHJtLCBfbW9kZSk7CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQgJiYgc3RhdHVzICE9PSBaX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gWl9GSU5JU0ggfHwgX21vZGUgPT09IFpfU1lOQ19GTFVTSDIpKSB7CiAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgdGhpcy5vbkRhdGEoc3RyaW5ncy5idWYyYmluc3RyaW5nKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChfbW9kZSA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikgewogICAgICAgICAgdGhpcy5vbkVuZChaX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBaX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgZGVmbGF0b3IgPSBuZXcgRGVmbGF0ZShvcHRpb25zKTsKICAgICAgICBkZWZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoZGVmbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBkZWZsYXRvci5tc2cgfHwgbXNnW2RlZmxhdG9yLmVycl07CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWZsYXRvci5yZXN1bHQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJhdyhpbnB1dCwgb3B0aW9ucykgewogIC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7CiAgICAgICAgdmFyIGJlZzsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBkbWF4OwogICAgICAgIHZhciB3c2l6ZTsKICAgICAgICB2YXIgd2hhdmU7CiAgICAgICAgdmFyIHduZXh0OwogICAgICAgIHZhciBzX3dpbmRvdzsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGNvZGU7CiAgICAgICAgdmFyIGRjb2RlOwogICAgICAgIHZhciBsbWFzazsKICAgICAgICB2YXIgZG1hc2s7CiAgICAgICAgdmFyIGhlcmU7CiAgICAgICAgdmFyIG9wOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGZyb207CiAgICAgICAgdmFyIGZyb21fc291cmNlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBfaW4gPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGxhc3QgPSBfaW4gKyAoc3RybS5hdmFpbF9pbiAtIDUpOwogICAgICAgIF9vdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGJlZyA9IF9vdXQgLSAoc3RhcnQgLSBzdHJtLmF2YWlsX291dCk7CiAgICAgICAgZW5kID0gX291dCArIChzdHJtLmF2YWlsX291dCAtIDI1Nyk7CiAgICAgICAgZG1heCA9IHN0YXRlLmRtYXg7CiAgICAgICAgd3NpemUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB3aGF2ZSA9IHN0YXRlLndoYXZlOwogICAgICAgIHduZXh0ID0gc3RhdGUud25leHQ7CiAgICAgICAgc193aW5kb3cgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgaG9sZCA9IHN0YXRlLmhvbGQ7CiAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgbGNvZGUgPSBzdGF0ZS5sZW5jb2RlOwogICAgICAgIGRjb2RlID0gc3RhdGUuZGlzdGNvZGU7CiAgICAgICAgbG1hc2sgPSAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDE7CiAgICAgICAgZG1hc2sgPSAoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxOwogICAgICAgIHRvcDoKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlcmUgPSBsY29kZVtob2xkICYgbG1hc2tdOwogICAgICAgICAgICBkb2xlbjoKICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgIGlmIChvcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICBsZW4gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICBpZiAob3ApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZW4gKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdOwogICAgICAgICAgICAgICAgICBkb2Rpc3Q6CiAgICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gZGlzdCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA+IHdoYXZlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdzsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod25leHQgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSArIHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGxlbiA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgY29udGludWUgZG9sZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKF9pbiA8IGxhc3QgJiYgX291dCA8IGVuZCk7CiAgICAgICAgbGVuID0gYml0cyA+PiAzOwogICAgICAgIF9pbiAtPSBsZW47CiAgICAgICAgYml0cyAtPSBsZW4gPDwgMzsKICAgICAgICBob2xkICY9ICgxIDw8IGJpdHMpIC0gMTsKICAgICAgICBzdHJtLm5leHRfaW4gPSBfaW47CiAgICAgICAgc3RybS5uZXh0X291dCA9IF9vdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IF9pbiA8IGxhc3QgPyA1ICsgKGxhc3QgLSBfaW4pIDogNSAtIChfaW4gLSBsYXN0KTsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IF9vdXQgPCBlbmQgPyAyNTcgKyAoZW5kIC0gX291dCkgOiAyNTcgLSAoX291dCAtIGVuZCk7CiAgICAgICAgc3RhdGUuaG9sZCA9IGhvbGQ7CiAgICAgICAgc3RhdGUuYml0cyA9IGJpdHM7CiAgICAgICAgcmV0dXJuOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMKICB2YXIgcmVxdWlyZV9pbmZ0cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV90YWJsZSh0eXBlLCBsZW5zLCBsZW5zX2luZGV4LCBjb2RlcywgdGFibGUsIHRhYmxlX2luZGV4LCB3b3JrLCBvcHRzKSB7CiAgICAgICAgdmFyIGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgdmFyIGxlbiA9IDA7CiAgICAgICAgdmFyIHN5bSA9IDA7CiAgICAgICAgdmFyIG1pbiA9IDAsIG1heCA9IDA7CiAgICAgICAgdmFyIHJvb3QyID0gMDsKICAgICAgICB2YXIgY3VyciA9IDA7CiAgICAgICAgdmFyIGRyb3AgPSAwOwogICAgICAgIHZhciBsZWZ0ID0gMDsKICAgICAgICB2YXIgdXNlZCA9IDA7CiAgICAgICAgdmFyIGh1ZmYgPSAwOwogICAgICAgIHZhciBpbmNyOwogICAgICAgIHZhciBmaWxsOwogICAgICAgIHZhciBsb3c7CiAgICAgICAgdmFyIG1hc2s7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGJhc2UgPSBudWxsOwogICAgICAgIHZhciBiYXNlX2luZGV4ID0gMDsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBjb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIG9mZnMgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBleHRyYSA9IG51bGw7CiAgICAgICAgdmFyIGV4dHJhX2luZGV4ID0gMDsKICAgICAgICB2YXIgaGVyZV9iaXRzLCBoZXJlX29wLCBoZXJlX3ZhbDsKICAgICAgICBmb3IgKGxlbiA9IDA7IGxlbiA8PSBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgY291bnRbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBjb3VudFtsZW5zW2xlbnNfaW5kZXggKyBzeW1dXSsrOwogICAgICAgIH0KICAgICAgICByb290MiA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdDIgPiBtYXgpIHsKICAgICAgICAgIHJvb3QyID0gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAobWF4ID09PSAwKSB7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICBvcHRzLmJpdHMgPSAxOwogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvciAobWluID0gMTsgbWluIDwgbWF4OyBtaW4rKykgewogICAgICAgICAgaWYgKGNvdW50W21pbl0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA8IG1pbikgewogICAgICAgICAgcm9vdDIgPSBtaW47CiAgICAgICAgfQogICAgICAgIGxlZnQgPSAxOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgbGVmdCAtPSBjb3VudFtsZW5dOwogICAgICAgICAgaWYgKGxlZnQgPCAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxlZnQgPiAwICYmICh0eXBlID09PSBDT0RFUyB8fCBtYXggIT09IDEpKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIG9mZnNbMV0gPSAwOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDwgTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIG9mZnNbbGVuICsgMV0gPSBvZmZzW2xlbl0gKyBjb3VudFtsZW5dOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgaWYgKGxlbnNbbGVuc19pbmRleCArIHN5bV0gIT09IDApIHsKICAgICAgICAgICAgd29ya1tvZmZzW2xlbnNbbGVuc19pbmRleCArIHN5bV1dKytdID0gc3ltOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodHlwZSA9PT0gQ09ERVMpIHsKICAgICAgICAgIGJhc2UgPSBleHRyYSA9IHdvcms7CiAgICAgICAgICBlbmQgPSAxOTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09IExFTlMpIHsKICAgICAgICAgIGJhc2UgPSBsYmFzZTsKICAgICAgICAgIGJhc2VfaW5kZXggLT0gMjU3OwogICAgICAgICAgZXh0cmEgPSBsZXh0OwogICAgICAgICAgZXh0cmFfaW5kZXggLT0gMjU3OwogICAgICAgICAgZW5kID0gMjU2OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBiYXNlID0gZGJhc2U7CiAgICAgICAgICBleHRyYSA9IGRleHQ7CiAgICAgICAgICBlbmQgPSAtMTsKICAgICAgICB9CiAgICAgICAgaHVmZiA9IDA7CiAgICAgICAgc3ltID0gMDsKICAgICAgICBsZW4gPSBtaW47CiAgICAgICAgbmV4dCA9IHRhYmxlX2luZGV4OwogICAgICAgIGN1cnIgPSByb290MjsKICAgICAgICBkcm9wID0gMDsKICAgICAgICBsb3cgPSAtMTsKICAgICAgICB1c2VkID0gMSA8PCByb290MjsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QyICYmIChodWZmICYgbWFzaykgIT09IGxvdykgewogICAgICAgICAgICBpZiAoZHJvcCA9PT0gMCkgewogICAgICAgICAgICAgIGRyb3AgPSByb290MjsKICAgICAgICAgICAgfQogICAgICAgICAgICBuZXh0ICs9IG1pbjsKICAgICAgICAgICAgY3VyciA9IGxlbiAtIGRyb3A7CiAgICAgICAgICAgIGxlZnQgPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIHdoaWxlIChjdXJyICsgZHJvcCA8IG1heCkgewogICAgICAgICAgICAgIGxlZnQgLT0gY291bnRbY3VyciArIGRyb3BdOwogICAgICAgICAgICAgIGlmIChsZWZ0IDw9IDApIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjdXJyKys7CiAgICAgICAgICAgICAgbGVmdCA8PD0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1c2VkICs9IDEgPDwgY3VycjsKICAgICAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsb3cgPSBodWZmICYgbWFzazsKICAgICAgICAgICAgdGFibGVbbG93XSA9IHJvb3QyIDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290MjsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMKICB2YXIgcmVxdWlyZV9pbmZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgYWRsZXIzMiA9IHJlcXVpcmVfYWRsZXIzMigpOwogICAgICB2YXIgY3JjMzIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0aGlzLndhcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgc3RybS50b3RhbF9pbiA9IHN0cm0udG90YWxfb3V0ID0gc3RhdGUudG90YWwgPSAwOwogICAgICAgIHN0cm0ubXNnID0gIiI7CiAgICAgICAgaWYgKHN0YXRlLndyYXApIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBzdGF0ZS53cmFwICYg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ZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+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+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IGxlZnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W3B1dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWNvcHkpOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBMSVQ6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgbGVmdC0tOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgQ0hFQ0s6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0IC09IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLnRvdGFsICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIGlmIChfb3V0KSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gc3RhdGUuZmxhZ3MgPyBjcmMzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICA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gPT09IExFTl8gfHwgc3RhdGUubW9kZSA9PT0gQ09QWV8gPyAyNTYgOiAwKTsKICAgICAgICBpZiAoKF9pbiA9PT0gMCAmJiBfb3V0ID09PSAwIHx8IGZsdXNoID09PSBaX0ZJTklTSCkgJiYgcmV0ID09PSBaX09LKSB7CiAgICAgICAgICByZXQgPSBaX0JVRl9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlRW5kKHN0cm0pIHsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud2luZG93KSB7CiAgICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlR2V0SGVhZGVyKHN0cm0sIGhlYWQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoKHN0YXRlLndyYXAgJiAyKSA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5oZWFkID0gaGVhZDsKICAgICAgICBoZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlU2V0RGljdGlvbmFyeShzdHJtLCBkaWN0aW9uYXJ5K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SRUVTOiA2LAogICAgICAgIFpfT0s6IDAsCiAgICAgICAgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIEdaaGVhZGVyKCkgewogICAgICAgIHRoaXMudGV4dCA9IDA7CiAgICAgICAgdGhpcy50aW1lID0gMDsKICAgICA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ucykgewogICAgICAgIGlmICghKHRoaXMgaW5zdGFuY2VvZiBJbmZsYXRlMikpCiAgICAgICAgICByZXR1cm4gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMCwKICAgICAgICAgIHRvOiAiIgogICAgICAgIH0sIG9wdGlvbnMgfHwge30pOwogICAgICAgIHZhciBvcHQgPSB0aGlzLm9wdGlvbnM7CiAgICAgICAgaWYgKG9wdC5yYXcgJiYgb3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2KSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC1vcHQud2luZG93Qml0czsKICAgICAgICAgIGlmIChvcHQud2luZG93Qml0cyA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC0xNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNiAmJiAhKG9wdGlvbnMgJiYgb3B0aW9ucy53aW5kb3dCaXRzKSkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMzI7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+IDE1ICYmIG9wdC53aW5kb3dCaXRzIDwgNDgpIHsKICAgICAgICAgIGlmICgob3B0LndpbmRvd0JpdHMgJiAxNSkgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgfD0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA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gfQogICAgICBJbmZsYXRlMi5wcm90b3R5cGUucHVzaCA9IGZ1bmN0aW9uKGRhdGEsIG1vZGUpIHsKICAgICAgICB2YXIgc3RybSA9IHRoaXMuc3RybTsKICAgICAgICB2YXIgY2h1bmtTaXplID0gdGhpcy5vcHRpb25zLmNodW5rU2l6ZTsKICAgICAgICB2YXIgZGljdGlvbmFyeSA9IHRoaXMub3B0aW9ucy5kaWN0aW9uYXJ5OwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIHZhciBuZXh0X291dF91dGY4LCB0YWlsLCB1dGY4c3RyOwogICAgICAgIHZhciBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgaWYgKHRoaXMuZW5kZWQpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgICAgX21vZGUgPSBtb2RlID09PSB+fm1vZGUgPyBtb2RlIDogbW9kZSA9PT0gdHJ1ZSA/IGMuWl9GSU5JU0ggOiBjLlpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3MuYmluc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlKHN0cm0sIGMuWl9OT19GTFVTSCk7CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfTkVFRF9ESUNUICYmIGRpY3Rpb25hcnkpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfQlVGX0VSUk9SICYmIGFsbG93QnVmRXJyb3IgPT09IHRydWUpIHsKICAgICAgICAgICAgc3RhdHVzID0gYy5aX09LOwogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5uZXh0X291dCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDAgfHwgc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCB8fCBfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpKSB7CiAgICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIG5leHRfb3V0X3V0ZjggPSBzdHJpbmdzLnV0Zjhib3JkZXIoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpOwogICAgICAgICAgICAgICAgdGFpbCA9IHN0cm0ubmV4dF9vdXQgLSBuZXh0X291dF91dGY4OwogICAgICAgICAgICAgICAgdXRmOHN0ciA9IHN0cmluZ3MuYnVmMnN0cmluZyhzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCk7CiAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gdGFpbDsKICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplIC0gdGFpbDsKICAgICAgICAgICAgICAgIGlmICh0YWlsKSB7CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCwgdGFpbCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGY4c3RyKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiBzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoc3RybS5hdmFpbF9pbiA+IDAgfHwgc3RybS5hdmFpbF9vdXQgPT09IDApICYmIHN0YXR1cyAhPT0gYy5aX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EKSB7CiAgICAgICAgICBfbW9kZSA9IGMuWl9GSU5JU0g7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gYy5aX09LOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKGMuWl9PSyk7CiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb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lID0gcmVxdWlyZV9kZWZsYXRlMigpOwogICAgICB2YXIgaW5mbGF0ZSA9IHJlcXVpcmVfaW5mbGF0ZTIoKTsKICAgICAgdmFyIGNvbnN0YW50cyA9IHJlcXVpcmVfY29uc3RhbnRzKCk7CiAgICAgIHZhciBwYWtvID0ge307CiAgICAgIGFzc2lnbihwYWtvLCBkZWZsYXRlLCBpbmZsYXRlLCBjb25zdGFudHMpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBwYWtvOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbHVlID0gcGFyc2VJbnQoc3RyLnN1YnN0cmluZyhpLCBpICsgc2l6ZSksIHJhZGl4KTsKICAgICAgICAgIGlmIChzaXplIDwgOCkgewogICAgICAgICAgICB2YXIgcG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIHNpemUpKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChwb3dlcikuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IHJlc3VsdC5tdWwocmFkaXhUb1Bvd2VyKTsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0LmFkZChmcm9tTnVtYmVyKHZhbHVlKSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJlc3VsdC51bnNpZ25lZCA9IHVuc2lnbmVkOwogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KIC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b3cgPj4+IDApOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcocmFkaXgpIHsKICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgaWYgKHRoaXMuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gIjAiOwogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICB2YXIgcmFkaXhMb25nID0gZnJvbU51bWJlcihyYWRpeCksIGRpdiA9IHRoaXMuZGl2KHJhZGl4TG9uZyksIHJlbTEgPSBkaXYubXVsKHJhZGl4TG9uZykuc3ViKHRoaXMpOwogICAgICAgICAgICByZXR1cm4gZGl2LnRvU3RyaW5nKHJhZGl4KSArIHJlbTEudG9JbnQoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgICB9IGVsc2UKICAgICAgICAgICAgcmV0dXJuICItIiArIHRoaXMubmVnKCkudG9TdHJpbmcocmFkaXgpOwogICAgICAgIH0KICAgICAgICB2YXIgcmFkaXhUb1Bvd2VyID0gZnJvbU51bWJlcihwb3dfZGJsKHJhZGl4LCA2KSwgdGhpcy51bnNpZ25lZCksIHJlbSA9IHRoaXM7CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICB2YXIgcmVtRGl2ID0gcmVtLmRpdihyYWRpeFRvUG93ZXIpLCBpbnR2YWwgPSByZW0uc3ViKHJlbURpdi5tdWwocmFkaXhUb1Bvd2VyKSkudG9JbnQoKSA+Pj4gMCwgZGlnaXRzID0gaW50dmFsLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIHJlbSA9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XNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICBpZiAodGhpcy51bnNpZ25lZCAhPT0gb3RoZXIudW5zaWduZWQgJiYgdGhpcy5oaWdoID4+PiAzMSA9PT0gMSAmJiBvdGhlci5oaWdoID4+PiAzMSA9PT0gMSkKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSBvdGhlci5oaWdoICYmIHRoaXMubG93ID09PSBvdGhlci5sb3c7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXEgPSBMb25nUHJvdG90eXBlLmVxdWFsczsKICAgICAgTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHMgPSBmdW5jdGlvbiBub3RFcXVhbHMob3RoZXIpIHsKICAgICAgICByZXR1cm4gIXRoaXMuZXEob3RoZXIpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lcSA9IExvbmdQcm90b3R5cGUubm90RXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5lID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW4gPSBmdW5jdGlvbiBsZXNzVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpIDwgMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdCA9IExvbmdQcm90b3R5cGUubGVzc1RoYW47CiAgICAgIExvbmdQcm90b3R5cGUubGVzc1RoYW5PckVxdWFsID0gZnVuY3Rpb24gbGVzc1RoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPD0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5sdGUgPSBMb25nUHJvdG90eXBlLmxlc3NUaGFuT3JFcXVhbDsKICAgICAgTG9uZ1Byb3RvdHlwZS5s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kZGVuZC5sb3cgJiA2NTUzNTsKICAgICAgICB2YXIgYzQ4ID0gMCwgYzMyID0gMCwgYzE2ID0gMCwgYzAwID0gMDsKICAgICAgICBjMDAgKz0gYTAwICsgYjAwOwogICAgICAgIGMxNiArPSBjMDAgPj4+IDE2OwogICAgICAgIGMwMCAmPSA2NTUzNTsKICAgICAgICBjMTYgKz0gYTE2ICsgYjE2OwogICAgICAgIGMzMiArPSBjMTYgPj4+IDE2OwogICAgICAgIGMxNiAmPSA2NTUzNTsKICAgICAgICBjMzIgKz0gYTMyICsgYjMyOwogICAgICAgIGM0OCArPSBjMzIgPj4+IDE2OwogICAgICAgIGMzMiAmPSA2NTUzNTsKICAgICAgICBjNDggKz0gYTQ4ICsgYjQ4OwogICAgICAgIGM0OCAmPSA2NTUzNTsKICAgICAgICByZXR1cm4gZnJvbUJpdHMoYzE2IDw8IDE2IHwgYzAwLCBjNDggPDwgMTYgfCBjMzIsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnN1YnRyYWN0ID0gZnVuY3Rpb24gc3VidHJhY3Qoc3VidHJhaGVuZCkgewogICAgICAgIGlmICghaXNMb25nKHN1YnRyYWhlbmQpKQogICAgICAgICAgc3VidHJhaGVuZCA9IGZyb21WYWx1ZShzdWJ0cmFoZW5kKTsKICAgICAgICByZXR1cm4gdGhpcy5hZGQoc3VidHJhaGVuZC5uZWcoKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3ViID0gTG9uZ1Byb3RvdHlwZS5zdWJ0cmFjdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWx0aXBseSA9IGZ1bmN0aW9uIG11bHRpcGx5KG11bHRpcGxpZXIpIHsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICghaXNMb25nKG11bHRpcGxpZXIpKQogICAgICAgICAgbXVsdGlwbGllciA9IGZyb21WYWx1ZSht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XIgYXBwcm94LCByZW0sIHJlczsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpIHsKICAgICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuZXEoT05FKSB8fCBkaXZpc29yLmVxKE5FR19PTkUpKQogICAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICAgIGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgICByZXR1cm4gT05FOwogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICB2YXIgaGFsZlRoaXMgPSB0aGlzLnNocigxKTsKICAgICAgICAgICAgICBhcHByb3ggPSBoYWxmVGhpcy5kaXYoZGl2aXNvcikuc2hsKDEpOwogICAgICAgICAgICAgIGlmIChhcHByb3guZXEoWkVSTykpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkaXZpc29yLmlzTmVnYXRpdmUoKSA/IE9ORSA6IE5FR19PTkU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlbSA9IHRoaXMuc3ViKGRpdmlzb3IubXVsKGFwcHJveCkpOwogICAgICAgICAgICAgICAgcmVzID0gYXBwcm94LmFkZChyZW0uZGl2KGRpdmlzb3IpKTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgICBpZiAodGhpcy5pc05lZ2F0aXZlKCkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLmRpdihkaXZpc29yLm5lZygpKTsKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IpLm5lZygpOwogICAgICAgICAgfSBlbHNlIGlmIChkaXZpc29yLmlzTmVnYXRpdmUoKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMuZGl2KGRpdmlzb3IubmVnKCkpLm5lZygpOwogICAgICAgICAgcmVzID0gWkVSTzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCFkaXZpc29yLnVuc2lnbmVkKQogICAgICAgICAgICBkaXZpc29yID0gZGl2aXNvci50b1Vuc2lnbmVkKCk7CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIFVaRVJPOwogICAgICAgICAgaWYgKGRpdmlzb3IuZ3QodGhpcy5zaHJ1KDEpKSkKICAgICAgICAgICAgcmV0dXJuIFVPTkU7CiAgICAgICAgICByZXMgPSBVWkVSTzsKICAgICAgICB9CiAgICAgICAgcmVtID0gdGhpczsKICAgICAgICB3aGlsZSAocmVtLmd0ZShkaXZpc29yKSkgewogICAgICAgICAgYXBwcm94ID0gTWF0aC5tYXgoMSwgTWF0aC5mbG9vcihyZW0udG9OdW1iZXIoKSAvIGRpdmlzb3IudG9OdW1iZXIoKSkpOwogICAgICAgICAgdmFyIGxvZzIgPSBNYXRoLmNlaWwoTWF0aC5sb2coYXBwcm94KSAvIE1hdGguTE4yKSwgZGVsdGEgPSBsb2cyIDw9IDQ4ID8gMSA6IHBvd19kYmwoMiwgbG9nMiAtIDQ4KSwgYXBwcm94UmVzID0gZnJvbU51bWJlcihhcHByb3gpLCBhcHByb3hSZW0gPSBhcHByb3hSZXMubXVsKGRpdmlzb3IpOwogICAgICAgICAgd2hpbGUgKGFwcHJveFJlbS5pc05lZ2F0aXZlKCkgfHwgYXBwcm94UmVtLmd0KHJlbSkpIHsKICAgICAgICAgICAgYXBwcm94IC09IGRlbHRhOwogICAgICAgICAgICBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICAgIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYXBwcm94UmVzLmlzWmVybygpKQogICAgICAgICAgICBhcHByb3hSZXMgPSBPTkU7CiAgICAgICAgICByZXMgPSByZXMuYWRkKGFwcHJveFJlcyk7CiAgICAgICAgICByZW0gPSByZW0uc3ViKGFwcHJveFJlbSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZGl2ID0gTG9uZ1Byb3RvdHlwZS5kaXZpZGU7CiAgICAgIExvbmdQcm90b3R5cGUubW9kdWxvID0gZnVuY3Rpb24gbW9kdWxvKGRpdmlzb3IpIHsKICAgICAgICBpZiAoIWlzTG9uZyhkaXZpc29yKSkKICAgICAgICAgIGRpdmlzb3IgPSBmcm9tVmFsdWUoZGl2aXNvcik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgICAgICAgIHZhciBsb3cgPSAodGhpcy51bnNpZ25lZCA/IHdhc20ucmVtX3UgOiB3YXNtLnJlbV9zKSh0aGlzLmxvdywgdGhpcy5oaWdoLCBkaXZpc29yLmxvdywgZGl2aXNvci5oaWdoKTsKICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3csIHdhc20uZ2V0X2hpZ2goKSwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzLnN1Yih0aGlzLmRpdihkaXZpc29yKS5tdWwoZGl2aXNvcikpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm1vZCA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLnJlbSA9IExvbmdQcm90b3R5cGUubW9kdWxvOwogICAgICBMb25nUHJvdG90eXBlLm5vdCA9IGZ1bmN0aW9uIG5vdCgpIHsKICAgICAgICByZXR1cm4gZnJvbUJp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VkID0gZnVuY3Rpb24gc2hpZnRSaWdodFVuc2lnbmVkKG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBudW1CaXRzICY9IDYzOwogICAgICAgIGlmIChudW1CaXRzID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSB7CiAgICAgICAgICB2YXIgaGlnaCA9IHRoaXMuaGlnaDsKICAgICAgICAgIGlmIChudW1CaXRzIDwgMzIpIHsKICAgICAgICAgICAgdmFyIGxvdyA9IHRoaXMubG93OwogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93ID4+PiBudW1CaXRzIHwgaGlnaCA8PCAzMiAtIG51bUJpdHMsIGhpZ2ggPj4+IG51bUJpdHMsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgfSBlbHNlIGlmIChudW1CaXRzID09PSAzMikKICAgICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGhpZ2gsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCA+Pj4gbnVtQml0cyAtIDMyLCAwLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hydSA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkOwogICAgICBMb25nUHJvdG90eXBlLnNocl91ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUudG9TaWduZWQgPSBmdW5jdGlvbiB0b1NpZ25lZCgpIHsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgZmFsc2UpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvVW5zaWduZWQgPSBmdW5jdGlvbiB0b1Vuc2lnbmVkKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93LCB0aGlzLmhpZ2gsIHRydWUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXMgPSBmdW5jdGlvbiB0b0J5dGVzKGxlKSB7CiAgICAgICAgcmV0dXJuIGxlID8gdGhpcy50b0J5dGVzTEUoKSA6IHRoaXMudG9CeXRlc0JFKCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0xFID0gZnVuY3Rpb24gdG9CeXRlc0xFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgbG8gJiAyNTUsCiAgICAgICAgICBsbyA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGhpICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMTYgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gMjQKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXNCRSA9IGZ1bmN0aW9uIHRvQnl0ZXNCRSgpIHsKICAgICAgICB2YXIgaGkgPSB0aGlzLmhpZ2gsIGxvID0gdGhpcy5sb3c7CiAgICAgICAgcmV0dXJuIFsKICAgICAgICAgIGhpID4+PiAyNCwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiA4ICYgMjU1LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBsbyA+P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NzYWdlKSwgewogICAgICAgICAgICBuYW1lOiBtZXNzYWdlLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBtZXNzYWdlLnN0YWNrCiAgICAgICAgICB9KTsKICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShlcnJvcikgewogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgX19lcnJvcl9tYXJrZXI6ICIkJGVycm9yIiwKICAgICAgICAgICAgbWVzc2FnZTogZXJyb3IubWVzc2FnZSwKICAgICAgICAgICAgbmFtZTogZXJyb3IubmFtZSwKICAgICAgICAgICAgc3RhY2s6IGVycm9yLnN0YWNrCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGlzU2VyaWFsaXplZEVycm9yID0gKHRoaW5nKSA9PiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmICJfX2Vycm9yX21hcmtlciIgaW4gdGhpbmcgJiYgdGhpbmcuX19lcnJvcl9tYXJrZXIgPT09ICIkJGVycm9yIjsKICAgICAgZXhwb3J0czIuRGVmYXVsdFNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgaWYgKGlzU2VyaWFsaXplZEVycm9yKG1lc3NhZ2UpKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLmRlc2VyaWFsaXplKG1lc3NhZ2UpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIG1lc3NhZ2U7CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgIGlmIChpbnB1dCBpbnN0YW5jZW9mIEVycm9yKSB7CiAgICAgICAgICAgIHJldHVybiBEZWZhdWx0RXJyb3JTZXJpYWxpemVyLnNlcmlhbGl6ZShpbnB1dCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgIC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iB2YWx1ZSBpbnN0YW5jZW9mIFAgPyB2YWx1ZSA6IG5ldyBQKGZ1bmN0aW9uKHJlc29sdmUpIHsKICAgICAgICAgICAgcmVzb2x2ZSh2YWx1ZSk7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yLm5leHQodmFsdWUpKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIHJlamVjdChlKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVqZWN0ZWQodmFsdWUpIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgewogICAgICAgICAgICByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsKICAgICAgICAgIH0KICAgICAgICAgIHN0ZXAoKGdlbmVyYXRvciA9IGdlbmVyYXRvci5hcHBseSh0aGlzQXJnLCBfYXJndW1lbnRzIHx8IFtdKSkubmV4dCgpKTsKICAgICAgICB9KTsKICAgICAgfTsKICAgICAgdmFyIF9faW1wb3J0RGVmYXVsdCA9IGV4cG9ydHMyICYmIGV4cG9ydHMyLl9faW1wb3J0RGVmYXVsdCB8fCBmdW5jdGlvb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IGNvbnN0IGpvYlVJRCA9IG1lc3NhZ2VEYXRhLnVpZDsKICAgICAgICAgICAgY29uc3Qgc3Vic2NyaXB0aW9uID0gYWN0aXZlU3Vic2NyaXB0aW9ucy5nZXQoam9iVUlEKTsKICAgICAgICAgICAgaWYgKHN1YnNjcmlwdGlvbikgewogICAgICAgICAgICAgIHN1YnNjcmlwdGlvbi51bnN1YnNjcmliZSgpOwogICAgICAgICAgICAgIGFjdGl2ZVN1YnNjcmlwdGlvbnMuZGVsZXRlKGpvYlVJRCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfQogICAgICBleHBvcnRzMi5leHBvc2UgPSBleHBvc2UyOwogICAgICBpZiAodHlwZW9mIHNlbGYgIT09ICJ1bmRlZmluZWQiICYmIHR5cGVvZiBzZWxmLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIgJiYgaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgc2VsZi5hZGRFdmVudExpc3RlbmVyKCJlcnJvciIsIChldmVudCkgPT4gewogICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXZlbnQuZXJyb3IgfHwgZXZlbnQpLCAyNTApOwogICAgICAgIH0pOwogICAgICAgIHNlbGYuYWRkRXZlbnRMaXN0ZW5lcigidW5oYW5kbGVkcmVqZWN0aW9uIiwgKGV2ZW50KSA9PiB7CiAgICAgICAgICBjb25zdCBlcnJvciA9IGV2ZW50LnJlYXNvbjsKICAgICAgICAgIGlmIChlcnJvciAmJiB0eXBlb2YgZXJyb3IubWVzc2FnZSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXJyb3IpLCAyNTApOwogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAg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m91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWRlcy5oZWFkZXJzCiAgICAgICAgfSwKICAgICAgICBtZXRob2Q6ICJHRVQiLAogICAgICAgIHJlZGlyZWN0OiAiZm9sbG93IiwKICAgICAgICBtb2RlOiA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jaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuY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GRlY29tcHJlc3NpbmcgYmxvY2s6IGluY29ycmVjdCBnemlwIGhlYWRlciBjaGVjayIpOwogICAgICB9CiAgICAgIHRocm93IGU7CiAgICB9CiAgfQogIGFzeW5jIGZ1bmN0aW9uIHVuemlwQ2h1bmtTbGljZShpbnB1dERhdGEsIGNodW5rKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgY29uc3QgeyBtaW52LCBtYXh2IH0gPSBjaHVuazsKICAgICAgbGV0IGNwb3MgPSBtaW52LmJsb2NrUG9zaXRpb247CiAgICAgIGxldCBkcG9zID0gbWludi5kYXRhUG9zaXRpb247CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBjb25zdCBjcG9zaXRpb25zID0gW107CiAgICAgIGNvbnN0IGRwb3NpdGlvbnMgPSBbXTsKICAgICAgbGV0IHRvdGFsU2l6ZSA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgZG8gewogICAgICAgIGNvbnN0IHJlbWFpbmluZ0lucHV0ID0gaW5wdXREYXRhLnN1YmFycmF5KGNwb3MgLSBtaW52LmJsb2NrUG9zaXRpb24pOwogICAgICAgIGNvbnN0IGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyMiA9IGluZmxhdG9yLnJlc3VsdDsKICAgICAgICBjaHVua3MucHVzaChidWZmZXIyKTsKICAgICAgICBsZXQgbGVuID0gYnVmZmVyMi5sZW5ndGg7CiAgICAgICAgY3Bvc2l0aW9ucy5wdXNoKGNwb3MpO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0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK3RhYml4QDEuNS4xMS9ub2RlX21vZHVsZXMvQGdtb2QvdGFiaXgvZXNtL3RiaS5qcwogIGluaXRfYnVmZmVyX3NoaW0oKTsKICB2YXIgaW1wb3J0X2xvbmcyID0gX190b01vZHVsZShyZXF1aXJlX2xvbmcoKSk7Cgog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zID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNiAqIGNodW5rQ291bnQ7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZ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aSA9IDA7IGkgPCBuYW1lc0J5dGVzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKCFuYW1lc0J5dGVzW2ldKSB7CiAgICAgICAgICBpZiAoY3Vyck5hbWVTdGFydCA8IGkpIHsKICAgICAgICAgICAgbGV0IHJlZk5hbWUgPSBuYW1lc0J5dGVzLnRvU3RyaW5nKCJ1dGY4IiwgY3Vyck5hbWVTdGFydCwgaSk7CiAgICAgICAgICAgIHJlZk5hbWUgPSB0aGlzLnJlbmFtZVJlZlNlcShyZWZOYW1lKTsKICAgICAgICAgICAgcmVmSWRUb05hbWVbY3VyclJlZklkXSA9IHJlZk5hbWU7CiAgICAgICAgICAgIHJlZk5hbWVUb0lkW3JlZk5hbWVdID0gY3VyclJlZklkOwogICAgICAgICAgfQogICAgICAgICAgY3Vyck5hbWVTdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VyclJlZklkICs9IDE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHJlZk5hbWVUb0lkLCByZWZJZFRvTmFtZSB9OwogICAgfQogICAgYXN5bmMgYmxvY2tzRm9yUmFuZ2UocmVmTmFtZSwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGJhID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWJhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IG1pbk9mZnNldCA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4W21pbiA+PiBUQURfTElEWF9TSElGVCA+PSBiYS5saW5lYXJJbmRleC5sZW5ndGggPyBiYS5saW5lYXJJbmRleC5sZW5ndGggLSAxIDogbWluID4+IFRBRF9MSURYX1NISUZUXSA6IG5ldyBWaXJ0dWFsT2Zmc2V0KDAsIDApOwogICAgICBpZiAoIW1pbk9mZnNldCkgewogICAgICAgIGNvbnNvbGUud2FybigicXVlcnlpbmcgb3V0c2lkZSBvZiBwb3NzaWJsZSB0YWJpeCByYW5nZSIpOwogICAgICB9CiAgICAgIGNvbnN0IG92ZXJsYXBwaW5nQmlucyA9IHJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBuaW50diA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aDsKICAgICAgbGV0IGxvd2VzdCA9IG51bGw7CiAgICAgIGNvbnN0IG1pbkxpbiA9IE1hdGgubWluKG1pbiA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgY29uc3QgbWF4TGluID0gTWF0aC5taW4obWF4ID4+IDE0LCBuaW50diAtIDEpOwogICAgICBmb3IgKGxldCBpID0gbWluTGluOyBpIDw9IG1heExpbjsgKytpKSB7CiAgICAgICAgY29uc3QgdnAgPSBiYS5saW5lYXJJbmRleFtpXTsKICAgICAgICBpZiAodnApIHsKICAgICAgICAgIGlmICghbG93ZXN0IHx8IHZwLmNvbXBhcmVUbyhsb3dlc3QpIDwgMCkgewogICAgICAgICAgICBsb3dlc3QgPSB2cDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KTsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vY3NpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzMgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2Fp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KICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBmaXJzdERhdGFMaW5lID0gdGhpcy5fZmluZEZpcnN0RGF0YShmaXJzdERhdGFMaW5lLCBsb2Zmc2V0KTsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQgKyAxMik7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICBjaHVua3Nba10gPSBuZXcgQ2h1bmsodSwgdiwgYmluKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiaW5JbmRleFtiaW5dID0gY2h1bmtzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgc3RhdHMgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiB7CiAgICAgICAgLi4uYXV4LAogICAgICAgIGNzaTogdHJ1ZSwKICAgICAgICByZWZDb3VudCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjc2lWZXJzaW9uLAogICAgICAgIGluZGljZXMsCiAgICAgICAgZGVwdGg6IHRoaXMuZGVwdGgsCiAgICAgICAgbWF4QmluTnVtYmVyOiB0aGlzLm1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMy5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDI4LCBvZmZzZXQgKyAzNiksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCkpOwogICAgfQogICAgcmVnMmJpbnMoYmVnLCBlbmQpIHsKICAgICAgYmVnIC09IDE7CiAgICAgIGlmIChiZWcgPCAxKSB7CiAgICAgICAgYmVnID0gMTsKICAgICAgfQogICAgICBpZiAoZW5kID4gMiAqKiA1MCkgewogICAgICAgIGVuZCA9IDIgKiogMzQ7CiAgICAgIH0KICAgICAgZW5kIC09IDE7CiAgICAgIGxldCBsID0gMDsKICAgICAgbGV0IHQgPSAwOwogICAgICBsZXQgcyA9IHRoaXMubWluU2hpZnQgKyB0aGlzLmRlcHRoICogMzsKICAgICAgY29uc3QgYmlucyA9IFtdOwogICAgICBmb3IgKDsgbCA8PSB0aGlzLmRlcHRoOyBzIC09IDMsIHQgKz0gbHNoaWZ0KDEsIGwgKiAzKSwgbCArPSAxKSB7CiAgICAgIC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cGVvZiBvcHRzID09PSAidW5kZWZpbmVkIikgewogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImxpbmUgY2FsbGJhY2sgbXVzdCBiZSBwcm92aWRlZCIpOwogICAgICB9CiAgICAgIGlmICh0eXBlb2Ygb3B0cyA9PT0gImZ1bmN0aW9uIikgewogICAgICAgIGNhbGxiYWNrID0gb3B0czsKICAgICAgfSBlbHNlIHsKICAgICAgICBvcHRpb25zID0gb3B0czsKICAgICAgICBjYWxsYmFjayA9IG9wdHMubGluZUNhbGxiYWNrOwogICAgICB9CiAgICAgIGlmIChyZWZOYW1lID09PSB2b2lkIDApIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJtdXN0IHByb3ZpZGUgYSByZWZlcmVuY2Ugc2VxdWVuY2UgbmFtZSIpOwogICAgICB9CiAgICAgIGlmICghY2FsbGJhY2spIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJsaW5lIGNhbGxiYWNrIG11c3QgYmUgcHJvdmlkZWQiKTsKICAgICAgfQogICAgICBjb25zdCBtZXRhZGF0YSA9IGF3YWl0IHRoaXMuaW5kZXguZ2V0TWV0YWRhdGEob3B0aW9ucyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgaWYgKCFzdGFydCkgewogICAgICAgIHN0YXJ0ID0gMDsKICAgICAgfQogICAgICBpZiAoIWVuZCkgewogICAgICAgIGVuZCA9IG1ldGFkYXRhLm1heFJlZkxlbmd0aDsKICAgICAgfQogICAgICBpZiAoIShzdGFydCA8PSBlbmQpKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiaW52YWxpZCBzdGFydCBhbmQgZW5kIGNvb3JkaW5hdGVzLiBzdGFydCBtdXN0IGJlIGxlc3MgdGhhbiBvciBlcXVhbCB0byBlbmQiKTsKICAgICAgfQogICAgICBpZiAoc3RhcnQgPT09IGVuZCkgewogICAgICAgIHJldHVybjsKICAgICAgfQog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b25zdCBuID0gYnVmZmVyLmluZGV4T2YoIlxuIiwgYmxvY2tTdGFydCk7CiAgICAgICAgICBpZiAobiA9PT0gLTEpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBiID0gYnVmZmVyLnNsaWNlKGJsb2NrU3RhcnQsIG4pOwogICAgICAgICAgY29uc3QgbGluZSA9IChkZWNvZGVyID09PSBudWxsIHx8IGRlY29kZXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGRlY29kZXIuZGVjb2RlKGIpKSB8fCBiLnRvU3RyaW5nKCk7CiAgICAgICAgICBpZiAoZHBvc2l0aW9ucykgewogICAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGMubWludi5kYXRhUG9zaXRpb24gPj0gZHBvc2l0aW9uc1twb3MrK10pIHsKICAgICAgICAgICAgfQogICAgICAgICAgICBwb3MtLTsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwcyB9ID0gdGhpcy5jaGVja0xpbmUobWV0YWRhdGEsIHJlZk5hbWUsIHN0YXJ0LCBlbmQsIGxpbmUpOwogICAgICAgICAgaWYgKHByZXZpb3VzU3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgcHJldmlvdXNTdGFydENvb3JkaW5hdGUgPiBzdGFydENvb3JkaW5hdGUpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBMaW5lcyBub3Qgc29ydGVkIGJ5IHN0YXJ0IGNvb3JkaW5hdGUgKCR7cHJldmlvdXNTdGFydENvb3JkaW5hdGV9ID4gJHtzdGFydENvb3JkaW5hdGV9KSwgdGhpcyBmaWxlIGlzIG5vdCB1c2FibGUgd2l0aCBUYWJpeC5gKTsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZpb3VzU3RhcnRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlOwogICAgICAgICAgaWYgKG92ZXJsYXBzKSB7CiAgICAgICAgICAgIGNhbGxiYWNrKGxpbmUudHJpbSgpLCBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGMubWludi5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlID49IGVuZCkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRpbWUgJiYgbGFzdCAtIERhdGUubm93KCkgPiB0aGlzLnlpZWxkVGltZSkgewogICAgICAgICAgICBsYXN0ID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBhd2FpdCB0aW1lb3V0KDEpOwogICAgICAgICAgfQogICAgICAgICAgYmxvY2tTdGFydCA9IG4gKyAxOwogICAgICAgIH0KICAgICAgfQogICAgfQogICAgYXN5bmMgZ2V0TWV0YWRhdGEob3B0cyA9IHt9KSB7CiAgICAgIHJldHVybiB0aGlzLmluZGV4LmdldE1ldGFkYXRhKG9wdHMpOwogICAgfQogICAgYXN5bmMgZ2V0SGVhZGVyQnVmZmVyKG9wdHMgPSB7fSkgewogICAgICBjb25zdCB7IGZpcnN0RGF0YUxpbmUsIG1ldGFDaGFyLCBtYXhCbG9ja1NpemUgfSA9IGF3YWl0IHRoaXMuZ2V0TWV0YWRhdGEob3B0cyk7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBjb25zdCBtYXhGZXRjaCA9ICgoZmlyc3REYXRhTGluZSA9PT0gbnVsbCB8fCBmaXJzdERhdGFMaW5lID09PSB2b2lkIDAgPyB2b2lkIDAgOiBmaXJzdERhdGFMaW5lLmJsb2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ICIiOwogICAgICBsZXQgc3RhcnRDb29yZGluYXRlID0gLUluZmluaXR5OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmUubGVuZ3RoICsgMTsgaSArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbaV0gPT09ICIJIiB8fCBpID09PSBsaW5lLmxlbmd0aCkgewogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHJlZikgewogICAgICAgICAgICBpZiAodGhpcy5yZW5hbWVSZWZTZXEobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpKSAhPT0gcmVnaW9uUmVmTmFtZSkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICBpZiAoY29vcmRpbmF0ZVR5cGUgPT09ICIxLWJhc2VkLWNsb3NlZCIpIHsKICAgICAgICAgICAgICBzdGFydENvb3JkaW5hdGUgLT0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlID49IHJlZ2lvbkVuZCkgewogICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGVuZCA9PT0gMCB8fCBlbmQgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgICAgaWYgKHN0YXJ0Q29vcmRpbmF0ZSArIDEgPD0gcmVnaW9uU3RhcnQpIHsKICAgICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGZvcm1hdCA9PT0gIlZDRiIgJiYgY3VycmVudENvbHVtbk51bWJlciA9PT0gNCkgewogICAgICAgICAgICByZWZTZXEgPSBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IGVuZCkgewogICAgICAgICAgICBsZXQgZW5kQ29vcmRpbmF0ZTsKICAgICAgICAgICAgaWYgKGZvcm1hdCA9PT0gIlZDRiIpIHsKICAgICAgICAgICAgICBlbmRDb29yZGluYXRlID0gdGhpcy5fZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSBwYXJzZUludChsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSksIDEwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kQ29vcmRpbmF0ZSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyZW50Q29sdW1uU3RhcnQgPSBpICsgMTsKICAgICAgICAgIGN1cnJlbnRDb2x1bW5OdW1iZXIgKz0gMTsKICAgICAgICAgIGlmIChjdXJyZW50Q29sdW1uTnVtYmVyID4gbWF4Q29sdW1uKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4geyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzOiB0cnVlIH07CiAgICB9CiAgICBfZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBpbmZvKSB7CiAgICAgIGxldCBlbmRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlICsgcmVmU2VxLmxlbmd0aDsKICAgICAgY29uc3QgaXNUUkEgPSBpbmZvLmluZGV4T2YoIlNWVFlQRT1UUkEiKSAhPT0gLTE7CiAgICAgIGlmIChpbmZvWzBdICE9PSAiLiIgJiYgIWlzVFJBKSB7CiAgICAgICAgbGV0IHByZXZDaGFyID0gIjsiOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5mby5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgaWYgKHByZXZDaGFyID09PSAiOyIgJiYgaW5mby5zbGljZShqLCBqICsgNCkgPT09ICJFTkQ9IikgewogICAgICAgICAgICBsZXQgdmFsdWVFbmQgPSBpbmZvLmluZGV4T2YoIjsiLCBqKTsKICAgICAgICAgICAgaWYgKHZhbHVlRW5kID09PSAtMSkgewogICAgICAgICAgICAgIHZhbHVlRW5kID0gaW5mby5sZW5ndGg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGluZm8uc2xpY2UoaiArIDQsIHZhbHVlRW5kKSwgMTApOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZDaGFyID0gaW5mb1tqXTsKICAgICAgICB9CiAgICAgIH0gZWxzZSBpZiAoaXNUUkEpIHsKICAgICAgICByZXR1cm4gc3RhcnRDb29yZGluYXRlICsgMTsKICAgICAgfQogICAgICByZXR1cm4gZW5kQ29vcmRpbmF0ZTsKICAgIH0KICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgcmV0dXJuIHRoaXMuaW5kZXgubGluZUNvdW50KHJlZk5hbWUsIG9wdHMpOwogICAgfQogICAgYXN5bmMgX3JlYWRSZWdpb24ocG9zLCBzaXplLCBv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5IGRhdGEsIG5vdCBjYWxsZWQgZ2Vub3R5cGVzKSIKICAgICAgfSwKICAgICAgQU46IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiVG90YWwgbnVtYmVyIG9mIGFsbGVsZXMgaW4gY2FsbGVkIGdlbm90eXBlcyIKICAgICAgfSwKICAgICAgQlE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJNUyBiYXNlIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIENJR0FSOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJGbG9hdCIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDaWdhciBzdHJpbmcgZGVzY3JpYmluZyBob3cgdG8gYWxpZ24gYW4gYWx0ZXJuYXRlIGFsbGVsZSB0byB0aGUgcmVmZXJlbmNlIGFsbGVsZSIKICAgICAgfSwKICAgICAgREI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiZGJTTlAgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiY29tYmluZWQgZGVwdGggYWNyb3NzIHNhbXBsZXMiCiAgICAgIH0sCiAgICAgIEVORDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFbmQgcG9zaXRpb24gKGZvciB1c2Ugd2l0aCBzeW1ib2xpYyBhbGxlbGVzKSIKICAgICAgfSwKICAgICAgSDI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSGFwTWFwMiBtZW1iZXJzaGlwIgogICAgICB9LAogICAgICBIMzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBNYXAzIG1lbWJlcnNoaXAiCiAgICAgIH0sCiAgICAgIE1ROiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6IG51bGwsCiAgICAgICAgRGVzY3JpcHRpb246ICJSTVMgbWFwcGluZyBxdWFsaXR5IgogICAgICB9LAogICAgICBNUTA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIE1BUFEgPT0gMCByZWFkcyIKICAgICAgfSwKICAgICAgTlM6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIHNhbXBsZXMgd2l0aCBkYXRhIgogICAgICB9LAogICAgICBTQjogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTdHJhbmQgYmlhcyIKICAgICAgfSwKICAgICAgU09NQVRJQzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTb21hdGljIG11dGF0aW9uIChmb3IgY2FuY2VyIGdlbm9taWNzKSIKICAgICAgfSwKICAgICAgVkFMSURBVEVEOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlZhbGlkYXRlZCBieSBmb2xsb3ctdXAgZXhwZXJpbWVudCIKICAgICAgfSwKICAgICAgIjEwMDBHIjogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICIxMDAwIEdlbm9tZXMgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgSU1QUkVDSVNFOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkltcHJlY2lzZSBzdHJ1Y3R1cmFsIHZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgTk9WRUw6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSW5kaWNhdGVzIGEgbm92ZWwgc3RydWN0dXJhbCB2YXJpYXRpb24iCiAgICAgIH0sCiAgICAgIFNWVFlQRTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlR5cGUgb2Ygc3RydWN0dXJhbCB2YXJpYW50IgogICAgICB9LAogICAgICBTVkxFTjogewogICAgICAgIE51bWJlcjogbnVsbCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJEaWZmZXJlbmNlIGluIGxlbmd0aCBiZXR3ZWVuIFJFRiBhbmQgQUxUIGFsbGVsZXMiCiAgICAgIH0sCiAgICAgIENJUE9TOiB7CiAgICAgICAgTnVtYmVyOiAyLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvbmZpZGVuY2UgaW50ZXJ2YWwgYXJvdW5kIFBPUyBmb3IgaW1wcmVjaXNlIHZhcmlhbnRzIgogICAgICB9LAogICAgICBDSUVORDogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBFTkQgZm9yIGltcHJlY2lzZSB2YXJpYW50cyIKICAgICAgfSwKICAgICAgSE9NTEVOOiB7CiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTGVuZ3RoIG9mIGJhc2UgcGFpciBpZGVudGljYWwgbWljcm8taG9tb2xvZ3kgYXQgZXZlbnQgYnJlYWtwb2ludHMiCiAgICAgIH0sCiAgICAgIEhPTVNFUTogewogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiU2VxdWVuY2Ugb2YgYmFzZSBwYWlyIGlkZW50aWNhbCBtaWNyby1ob21vbG9neSBhdCBldmVudCBicmVha3BvaW50cyIKICAgICAgfSwKICAgICAgQktQVElEOiB7CiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiB0aGUgYXNzZW1ibGVkIGFsdGVybmF0ZSBhbGxlbGUgaW4gdGhlIGFzc2VtYmx5IGZpbGUiCiAgICAgIH0sCiAgICAgIE1FSU5GTzogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIk1vYmlsZSBlbGVtZW50IGluZm8gb2YgdGhlIGZvcm0gTkFNRSxTVEFSVCxFTkQsUE9MQVJJVFkiCiAgICAgIH0sCiAgICAgIE1FVFJBTlM6IHsKICAgICAgICBOdW1iZXI6IDQsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJNb2JpbGUgZWxlbWVudCB0cmFuc2R1Y3Rpb24gaW5mbyBvZiB0aGUgZm9ybSBDSFIsU1RBUlQsRU5ELFBPTEFSSVRZIgogICAgICB9LAogICAgICBER1ZJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEYXRhYmFzZSBvZiBHZW5vbWljIFZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgREJWQVJJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlZBUiIKICAgICAgfSwKICAgICAgREJSSVBJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlJJUCIKICAgICAgfSwKICAgICAgTUFURUlEOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgbWF0ZSBicmVha2VuZHMiCiAgICAgIH0sCiAgICAgIFBBUklEOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgcGFydG5lciBicmVha2VuZCIKICAgICAgfSwKICAgICAgRVZFTlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiBldmVudCBhc3NvY2lhdGVkIHRvIGJyZWFrZW5kIgogICAgICB9LAogICAgICBDSUxFTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCB0aGUgaW5zZXJ0ZWQgbWF0ZXJpYWwgYmV0d2VlbiBicmVha2VuZCIKICAgICAgfSwKICAgICAgRFBBREo6IHsgVHlwZTogIkludGVnZXIiLCBEZXNjcmlwdGlvbjogIlJlYWQgRGVwdGggb2YgYWRqYWNlbmN5IiB9LAogICAgICBDTjogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb3B5IG51bWJlciBvZiBzZWdtZW50IGNvbnRhaW5pbmcgYnJlYWtlbmQiCiAgICAgIH0sCiAgICAgIENOQURKOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvcHkgbnVtYmVyIG9mIGFkamFjZW5jeSIKICAgICAgfSwKICAgICAgQ0lDTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBjb3B5IG51bWJlciBmb3IgdGhlIHNlZ21lbnQiCiAgICAgIH0sCiAgICAgIENJQ05BREo6IHsKICAgICAgICBOdW1iZXI6IG51bGwsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiQ29uZmlkZW5jZSBpbnRlcnZhbCBhcm91bmQgY29weSBudW1iZXIgZm9yIHRoZSBhZGphY2VuY3kiCiAgICAgIH0KICAgIH0sCiAgICBHZW5vdHlwZUZpZWxkczogewogICAgICBBRDogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIgogICAgICB9LAogICAgICBBREY6IHsKICAgICAgICBOdW1iZXI6ICJSIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJSZWFkIGRlcHRoIGZvciBlYWNoIGFsbGVsZSBvbiB0aGUgZm9yd2FyZCBzdHJhbmQiCiAgICAgIH0sCiAgICAgIEFEUjogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIG9uIHRoZSByZXZlcnNlIHN0cmFuZCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUmVhZCBkZXB0aCIKICAgICAgfSwKICAgICAgRUM6IHsKICAgICAgICBOdW1iZXI6ICJBIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFeHBlY3RlZCBhbHRlcm5hdGUgYWxsZWxlIGNvdW50cyIKICAgICAgfSwKICAgICAgRlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICdGaWx0ZXIgaW5kaWNhdGluZyBpZiB0aGlzIGdlbm90eXBlIHdhcyAiY2FsbGVkIicKICAgICAgfSwKICAgICAgR0w6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiRmxvYXQiLAogICAgICAgIERlc2NyaXB0aW9uOiAiR2Vub3R5cGUgbGlrZWxpaG9vZHMiCiAgICAgIH0sCiAgICAgIEdQOiB7CiAgICAgICAgTnVtYmVyOiAiRyIsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIHBvc3RlcmlvciBwcm9iYWJpbGl0aWVzIgogICAgICB9LAogICAgICBHUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25kaXRpb25hbCBnZW5vdHlwZSBxdWFsaXR5IgogICAgICB9LAogICAgICBHVDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIgogICAgICB9LAogICAgICBIUTogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBsb3R5cGUgcXVhbGl0eSIKICAgICAgfSwKICAgICAgTVE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUk1TIG1hcHBpbmcgcXVhbGl0eSIKICAgICAgfSwKICAgICAgUEw6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaHJlZC1zY2FsZWQgZ2Vub3R5cGUgbGlrZWxpaG9vZHMgcm91bmRlZCB0byB0aGUgY2xvc2VzdCBpbnRlZ2VyIgogICAgICB9LAogICAgICBQUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaGFzaW5nIHF1YWxpdHkiCiAgICAgIH0sCiAgICAgIFBTOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlBoYXNlIHNldCIKICAgICAgfQogICAgfSwKICAgIEFsdFR5cGVzOiB7CiAgICAgIERFTDogewogICAgICAgIERlc2NyaXB0aW9uOiAiRGVsZXRpb24gcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgSU5TOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJJbnNlcnRpb24gb2Ygbm92ZWwgc2VxdWVuY2UgcmVsYXRpdmUgdG8gdGhlIHJlZmVyZW5jZSIKICAgICAgfSwKICAgICAgRFVQOiB7CiAgICAgICAgRGVzY3JpcHRpb246ICJSZW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Jlc2VydmVkX2RlZmF1bHQuQWx0VHlwZXMsCiAgICAgICAgRklMVEVSOiB2Y2ZSZXNlcnZlZF9kZWZhdWx0LkZpbHRlclR5cGVzCiAgICAgIH0pKTsKICAgICAgbGV0IGxhc3RMaW5lOwogICAgICBoZWFkZXJMaW5lcy5mb3JFYWNoKChsaW5lKSA9PiB7CiAgICAgICAgaWYgKCFsaW5lLnN0YXJ0c1dpdGgoIiMiKSkgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBCYWQgbGluZSBpbiBoZWFkZXI6CiR7bGluZX1gKTsKICAgICAgICB9IGVsc2UgaWYgKGxpbmUuc3RhcnRzV2l0aCgiIyMiKSkgewogICAgICAgICAgdGhpcy5fcGFyc2VNZXRhZGF0YShsaW5lKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbGFzdExpbmUgPSBsaW5lOwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGlmICghbGFzdExpbmUpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIk5vIGZvcm1hdCBsaW5lIGZvdW5kIGluIGhlYWRlciIpOwogICAgICB9CiAgICAgIGNvbnN0IGZpZWxkcyA9IGxhc3RMaW5lLnRyaW0oKS5zcGxpdCgiCSIpOwogICAgICBjb25zdCB0aGlzSGVhZGVyID0gZmllbGRzLnNsaWNlKDAsIDgpOwogICAgICBjb25zdCBjb3JyZWN0SGVhZGVyID0gWwogICAgICAgICIjQ0hST00iLAogICAgICAgICJQT1MiLAogICAgICAgICJJRCIsCiAgICAgICAgIlJFRiIsCiAgICAgICAgIkFMVCIsCiAgICAgICAgIlFVQUwiLAogICAgICAgICJGSUxURVIiLAogICAgICAgICJJTkZPIgogICAgICBdOwogICAgICBpZiAoZmllbGRzLmxlbmd0aCA8IDgpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYFZDRiBoZWFkZXIgbWlzc2luZyBjb2x1bW5zOgoke2xhc3RMaW5lfWApOwogICAgICB9IGVsc2UgaWYgKHRo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aWx0ZXJlZE1ldGFkYXRhKSB7CiAgICAgICAgICByZXR1cm4gZmlsdGVyZWRNZXRhZGF0YTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIGZpbHRlcmVkTWV0YWRhdGE7CiAgICB9CiAgICBfcGFyc2VLZXlWYWx1ZShzdHIsIHBhaXJTZXBhcmF0b3IgPSAiOyIpIHsKICAgICAgY29uc3QgZGF0YSA9IHt9OwogICAgICBsZXQgY3VycktleSA9ICIiOwogICAgICBsZXQgY3VyclZhbHVlID0gIiI7CiAgICAgIGxldCBzdGF0ZSA9IDE7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKHN0YXRlID09PSAxKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSAiPSIpIHsKICAgICAgICAgICAgc3RhdGUgPSAyOwogICAgICAgICAgfSBlbHNlIGlmIChzdHJbaV0gIT09IHBhaXJTZXBhcmF0b3IpIHsKICAgICAgICAgICAgY3VycktleSArPSBzdHJbaV07CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJWYWx1ZSA9PT0gIiIpIHsKICAgICAgICAgICAgZGF0YVtjdXJyS2V5XSA9IG51bGw7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAyKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSBwYWlyU2VwYXJhdG9yKSB7CiAgICAgICAgICAgIGRhdGFbY3VycktleV0gPSBjdXJyVmFsdWU7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgICAgY3VyclZhbHVlID0gIiI7CiAgICAgICAgICAgIHN0YXRlID0gMTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RyW2ldID09PSAnIicpIHsKICAgICAgICAgICAgc3RhdGUgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAzKSB7CiAgICAgICAgICBpZiAoc3RyW2ldICE9PSAnIicpIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlID0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKHN0YXRlID09PSAyIHx8IHN0YXRlID09PSAzKSB7CiAgICAgICAgZGF0YVtjdXJyS2V5XSA9IGN1cnJWYWx1ZTsKICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gMSkgewogICAgICAgIGRhdGFbY3VycktleV0gPSBudWxsOwogICAgICB9CiAgICAgIHJldHVybiBkYXRhOwogICAgfQogICAgcGFyc2VMaW5lKGxpbmUpIHsKICAgICAgbGluZSA9IGxpbmUudHJpbSgpOwogICAgICBpZiAoIWxpbmUubGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgfQogICAgICBjb25zdCBwYXJzZXIgPSB0aGlzOwogICAgICBsZXQgY3VyckNoYXIgPSAwOwogICAgICBmb3IgKGxldCBjdXJyRmllbGQgPSAwOyBjdXJyQ2hhciA8IGxpbmUubGVuZ3RoOyBjdXJyQ2hhciArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbY3VyckNoYXJdID09PSAiCSIpIHsKICAgICAgICAgIGN1cnJGaWVsZCArPSAxOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyckZpZWxkID09PSA5KSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgZmllbGRzID0gbGluZS5zdWJzdHIoMCwgY3VyckNoYXIpLnNwbGl0KCIJIik7CiAgICAgIGNvbnN0IHJlc3QgPSBsaW5lLnN1YnN0cihjdXJyQ2hhciArIDEpOwogICAgICBjb25zdCBbQ0hST00sIFBPUywgSUQsIFJFRiwgQUxULCBRVUFMLCBGSUxURVJdID0gZmllbGRzOwogICAgICBjb25zdCBjaHJvbSA9IENIUk9NOwogICAgICBjb25zdCBwb3MgPSArUE9TOwogICAgICBjb25zdCBpZCA9IElEID09PSAiLiIgPyBudWxsIDogSUQuc3BsaXQoIjsiKTsKICAgICAgY29uc3QgcmVmID0gUkVGOwogICAgICBjb25zdCBhbHQgPSBBTFQgPT09ICIuIiA/IG51bGwgOiBBTFQuc3BsaXQoIiwiKTsKICAgICAgY29uc3QgcXVhbCA9IFFVQUwgPT09ICIuIiA/IG51bGwgOiArUVVBTDsKICAgICAgY29uc3QgZmlsdGVyID0gRklMVEVSID09PSAiLiIgPyBudWxsIDogRklMVEVSLnNwbGl0KCI7Iik7CiAgICAgIGlmICh0aGlzLnN0cmljdCAmJiBmaWVsZHNbN10gPT09IHZvaWQgMCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigibm8gSU5GTyBmaWVsZCBzcGVjaWZpZWQsIG11c3QgY29udGFpbiBhdCBsZWFzdCBhICcuJyAodHVybiBvZmYgc3RyaWN0IG1vZGUgdG8gYWxsb3cpIik7CiAgICAgIH0KICAgICAgY29uc3QgaW5mbyA9IGZpZWxkc1s3XSA9PT0gdm9pZCAwIHx8IGZpZWxkc1s3XSA9PT0gIi4iID8ge30gOiB0aGlzLl9wYXJzZUtleVZhbHVlKGZpZWxkc1s3XSk7CiAgICAgIE9iamVjdC5rZXlzKGluZm8pLmZvckVhY2goKGtleSkgPT4gewogICAgICAgIGxldCBpdGVtczsKICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICBpdGVtcyA9IGluZm9ba2V5XS5zcGxpdCgiLCIpLm1hcCgodmFsKSA9PiB2YWwgPT09ICIuIiA/IG51bGwgOiB2YWwpLm1hcCgoZikgPT4gZiA/IGRlY29kZVVSSUNvbXBvbmVudE5vVGhyb3coZikgOiBmKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaXRlbXMgPSBpbmZvW2tleV07CiAgICAgICAgfQogICAgICAgIGNvbnN0IGl0ZW1UeXBlID0gdGhpcy5nZXRNZXRhZGF0YSgiSU5GTyIsIGtleSwgIlR5cGUiKTsKICAgICAgICBpZiAoaXRlbVR5cGUpIHsKICAgICAgICAgIGlmIChpdGVtVHlwZSA9PT0gIkludGVnZXIiIHx8IGl0ZW1UeXBlID09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgIGl0ZW1zID0gaXRlbXMubWFwKCh2YWwpID0+IHsKICAgICAgICAgICAgICBpZiAodmFsID09PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcmV0dXJuIE51bWJlcih2YWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbVR5cGUgPT09ICJGbGFnIikgewogICAgICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBJbmZvIGZpZWxkICR7a2V5fSBpcyBhIEZsYWcgYW5kIHNob3VsZCBub3QgaGF2ZSBhIHZhbHVlIChnb3QgdmFsdWUgJHtpbmZvW2tleV19KWApOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGl0ZW1zID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbmZvW2tleV0gPSBpdGVtczsKICAgICAgfSk7CiAgICAgIGNvbnN0IHZhcmlhbnQgPSBuZXcgVmFyaWFudCh7CiAgICAgICAgQ0hST006IGNocm9tLAogICAgICAgIFBPUzogcG9zLAogICAgICAgIEFMVDogYWx0LAogICAgICAgIElORk86IGluZm8sCiAgICAgICAgUkVGOiByZWYsCiAgICAgICAgRklMVEVSOiBmaWx0ZXIgJiYgZmlsdGVyLmxlbmd0aCA9PT0gMSAmJiBmaWx0ZXJbMF0gPT09ICJQQVNTIiA/ICJQQVNTIiA6IGZpbH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AgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIH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ogICAgcmV0dXJuICJ1bmtub3duIjsKICB9OwogIHZhciBnZXRTdWJzdGl0dXRpb25UeXBlID0gKHJlZiwgYWx0KSA9PiB7CiAgICBzd2l0Y2ggKHJlZiArIGFsdCkgewogICAgICBjYXNlICJDQSI6CiAgICAgIGNhc2UgIkdUIjoKICAgICAgICByZXR1cm4gIkM+QSI7CiAgICAgIGNhc2UgIkNHIjoKICAgICAgY2FzZSAiR0MiOgogICAgICAgIHJldHVybiAiQz5HIjsKICAgICAgY2FzZSAiQ1QiOgogICAgICBjYXNlICJHQSI6CiAgICAgICAgcmV0dXJuICJDPlQiOwogICAgICBjYXNlICJUQSI6CiAgICAgIGNhc2UgIkFUIjoKICAgICAgICByZXR1cm4gIlQ+QSI7CiAgICAgIGNhc2UgIlRDIjoKICAgICAgY2FzZSAiQUciOgogICAgICAgIHJldHVybiAiVD5DIjsKICAgICAgY2FzZSAiVEciOgogICAgICBjYXNlICJBQyI6CiAgICAgICAgcmV0dXJuICJUPkciOwogICAgICBkZWZhdWx0OgogICAgICAgIHJldHVybiAidW5rbm93biI7CiAgICB9CiAgfTsKICBmdW5jdGlvbiByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJQb3MsIHByZXZBYnNQb3MpIHsKICAgIGNvbnN0IGFic1BvcyA9IGNoclBvcyArIHZjZlJlY29yZC5QT1MgKyAxOwogICAgbGV0IEFMVDsKICAgIGlmIChBcnJheS5pc0FycmF5KHZjZlJlY29yZC5BTFQpICYmIHZjZlJlY29yZC5BTFQubGVuZ3RoID4gMCkgewogICAgICBBTFQgPSB2Y2ZSZWNvcmQuQUxUWzBdOwogICAgfQogICAgY29uc3QgRElTVFBSRVYgPSAhcHJldkFic1BvcyA/IG51bGwgOiBhYnNQb3MgLSBwcmV2QWJzUG9zOwogICAgY29uc3QgRElTVFBSRVZMT0dFID0gIXByZXZBYnNQb3MgPyBudWxsIDogTWF0aC5sb2coYWJzUG9zIC0gcHJldkFic1Bvcyk7CiAgICBjb25zdCBN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ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbGV0IHN0YXJ0UG9zLCBlbmRQb3M7CiAgICAgICAgaWYgKGNocm9tU3RhcnQgPiBjdXJNaW5YIHx8IGN1ck1pblggPj0gY2hyb21FbmQpIHsKICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBsZXQgcHJldlBPUzsKICAgICAgICBjb25zdCB0aWxlc1Byb21pc2UgPSBuZXcgUHJvbWlzZSgocmVzb2x2ZSkgPT4gewogICAgICAgICAgY29uc3QgdGlsZXMgPSBbXTsKICAgICAgICAgIGNvbnN0IGxpbmVDYWxsYmFjayA9IChsaW5lKSA9PiB7CiAgICAgICAgICAgIGNvbnN0IHZjZlJlY29yZCA9IHBhcnNlci5wYXJzZUxpbmUobGluZSk7CiAgICAgICAgICAgIGNvbnN0IHZjZlRpbGUgPSByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJvbVN0YXJ0LCBwcmV2UE9TKTsKICAgICAgICAgICAgcHJldlBPUyA9IHZjZlRpbGUuUE9TOwogICAgICAgICAgICB0aWxlcy5wdXNoKHZjZlRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWl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pamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCi8qKgogKiBAbGljZW5zZQogKiBMb2Rhc2ggKEN1c3RvbSBCdWlsZCkgPGh0dHBzOi8vbG9kYXNoLmNvbS8+CiAqIEJ1aWxkOiBgbG9kYXNoIG1vZHVsYXJpemUgZXhwb3J0cz0iZXMiIC1vIC4vYAogKiBDb3B5cmlnaHQgT3BlbkpTIEZvdW5kYXRpb24gYW5kIG90aGVyIGNvbnRyaWJ1dG9ycyA8aHR0cHM6Ly9vcGVuanNmLm9yZy8+CiAqIFJlbGVhc2VkIHVuZGVyIE1JVCBsaWNlbnNlIDxodHRwczovL2xvZGFzaC5jb20vbGljZW5zZT4KICogQmFzZWQgb24gVW5kZXJzY29yZS5qcyAxLjguMyA8aHR0cDovL3VuZGVyc2NvcmVqcy5vcmcvTElDRU5TRT4KICogQ29weXJpZ2h0IEplcmVteSBBc2hrZW5hcywgRG9jdW1lbnRDbG91ZCBhbmQgSW52ZXN0aWdhdGl2ZSBSZXBvcnRlcnMgJiBFZGl0b3JzCiAqLwo=",lle=typeof window<"u"&&window.Blob&&new Blob([atob(A2e)],{type:"text/javascript;charset=utf-8"});function pgg(){const e=lle&&(window.URL||window.webkitURL).createObjectURL(lle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+A2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const bgg=200;class s2e{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"prevRequestTime"),rt(this,"track"),rt(this,"toFetch"),rt(this,"fetchTimeout"),rt(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=JT(new pgg).then(async o=>{const a=Object.entries(bI(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()},bgg)}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))}}rt(s2e,"config",{type:"vcf"});const Qk=BigInt(32);function ygg(e,g,I){const i=+!!I,n=+!I;return BigInt(e.getInt32(g,I)*n+e.getInt32(g+4,I)*i)<>Qk),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 vgg(e,g,I,i){const n=Number(I>>Qk),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 ygg(this,e,g)});"getBigUint64"in DataView||(DataView.prototype.getBigUint64=function(e,g){return Zgg(this,e,g)});"setBigInt64"in DataView||(DataView.prototype.setBigInt64=function(e,g,I){Ggg(this,e,g,I)});"setBigUint64"in DataView||(DataView.prototype.setBigUint64=function(e,g,I){vgg(this,e,g,I)});class Bgg{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 To=new Map,Fu="___parser_",No={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},$R={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"},qR={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(g,I){const i=$R[g],n=qR[g];I.pushCode(`${I.generateVariable(this.varName)} = dataView.get${i}(offset, ${n});`),I.pushCode(`offset += ${No[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 To.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"&&!To.has(I.type)&&!(I.type in No))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"&&!To.has(C)&&!(C in No))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 kg)&&!To.has(I.type))throw new Error("type must be a known parser name or a Parser object.");if(!(I.type instanceof kg)&&!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 No)&&!To.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 Bgg(g,this.useContextVariables);return I.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(I),I.pushCode(`return ${Fu+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 ${Fu+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=To.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(No).indexOf(this.type)>=0)g=No[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=No[this.options.type]:this.options.type instanceof kg&&(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 kg;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(To.get(n)){const A=g.generateTmpVariable();if(g.pushCode(`var ${A} = ${Fu+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=$R[n],l=qR[n];g.pushCode(`var ${o} = dataView.get${A}(offset, ${l});`),g.pushCode(`offset += ${No[n]};`)}else if(n instanceof kg){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(To.has(i)){const C=g.generateTmpVariable();g.pushCode(`var ${C} = ${Fu+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=$R[i],r=qR[i];g.pushCode(`${n} = dataView.get${C}(offset, ${r});`),g.pushCode(`offset += ${No[i]}`)}}else i instanceof kg&&(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 kg){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(To.has(this.options.type)){const i=g.generateTmpVariable();if(g.pushCode(`var ${i} = ${Fu+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 kg)this.varName&&g.pushCode(`${I} = {};`),g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName);else if(To.has(this.options.type)){const a=g.generateTmpVariable();g.pushCode(`var ${a} = ${Fu+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 kg){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(To.has(this.options.type)){const r=g.generateTmpVariable();if(g.pushCode(`var ${r} = ${Fu+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(No).indexOf(this.options.type)>=0){const r=$R[I],o=qR[I];g.pushCode(`${C} = dataView.get${r}(offset, ${o});`),g.pushCode(`offset += ${No[I]};`)}g.pushCode(`offset = ${n};`)}generateSaveOffset(g){const I=g.generateVariable(this.varName);g.pushCode(`${I} = offset`)}}var l2e={},E$={},xh={},Tw={};Object.defineProperty(Tw,"__esModule",{value:!0});function M$(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function cle(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 fG(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function Vgg(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 fG(e)}function Rgg(e){var g=wgg();return function(){var i=d0(e),n;if(g){var C=d0(this).constructor;n=Reflect.construct(i,arguments,C)}else n=i.apply(this,arguments);return Vgg(this,n)}}function Wgg(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=d0(e),e!==null););return e}function YW(){return typeof Reflect<"u"&&Reflect.get?YW=Reflect.get.bind():YW=function(g,I,i){var n=Wgg(g,I);if(n){var C=Object.getOwnPropertyDescriptor(n,I);return C.get?C.get.call(arguments.length<3?g:i):C.value}},YW.apply(this,arguments)}var ule=function(){function e(){M$(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return z$(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&&(c2e.prototype[Symbol.toStringTag]="AbortController",P$.prototype[Symbol.toStringTag]="AbortSignal");function Xgg(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 Hgg(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(!Xgg({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}}Tw.AbortController=c2e;Tw.AbortSignal=P$;Tw.abortableFetch=Hgg;Object.defineProperty(xh,"__esModule",{value:!0});xh.AbortSignal=xh.AbortController=void 0;const u2e=Tw;var SH=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof Ih<"u")return Ih;throw new Error("unable to locate global object")};let Tgg=typeof SH().AbortController>"u"?u2e.AbortController:SH().AbortController;xh.AbortController=Tgg;let Ngg=typeof SH().AbortController>"u"?u2e.AbortSignal:SH().AbortSignal;xh.AbortSignal=Ngg;var J$={};Object.defineProperty(J$,"__esModule",{value:!0});const kgg=xh;class Ygg{}class Kgg{constructor(){this.signals=new Set,this.abortController=new kgg.AbortController}addSignal(g=new Ygg){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()}}J$.default=Kgg;var O$={};Object.defineProperty(O$,"__esModule",{value:!0});class xgg{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)})}}O$.default=xgg;var d2e=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(E$,"__esModule",{value:!0});const Dgg=xh,Fgg=d2e(J$),Egg=d2e(O$);class wH{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 Fgg.default,r=new Egg.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 Dgg.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),wH.checkSinglePromise(C.promise,i)):(this.fill(g,I,i,n),wH.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}}E$.default=wH;var Mgg=Ih&&Ih.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(l2e,"__esModule",{value:!0});const zgg=Mgg(E$);var Pgg=l2e.default=zgg.default;class nc{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 nc(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 nc(n.min(),r.max()))}return i.push(n),i.length===1?i[0]:new nc(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 nc(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 nc(A)}coverage(){let g=0;const I=this.ranges();for(let i=0;in.min()?1:i.max()i.max()?1:0}}function dy(e){let g=e.length;for(;--g>=0;)e[g]=0}const Jgg=3,Ogg=258,h2e=29,_gg=256,Lgg=_gg+1+h2e,m2e=30,Ugg=512,Qgg=new Array((Lgg+2)*2);dy(Qgg);const jgg=new Array(m2e*2);dy(jgg);const $gg=new Array(Ugg);dy($gg);const qgg=new Array(Ogg-Jgg+1);dy(qgg);const eIg=new Array(h2e);dy(eIg);const tIg=new Array(m2e);dy(tIg);const gIg=(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 I_=gIg;const IIg=()=>{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},iIg=new Uint32Array(IIg()),nIg=(e,g,I,i)=>{const n=iIg,C=i+I;e^=-1;for(let r=i;r>>8^n[(e^g[r])&255];return e^-1};var Na=nIg,i_={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"},_$={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 CIg=(e,g)=>Object.prototype.hasOwnProperty.call(e,g);var rIg=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)CIg(I,i)&&(e[i]=I[i])}}return e},oIg=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;oS[254]=oS[254]=1;var aIg=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 AIg=(e,g)=>{if(g<65534&&e.subarray&&p2e)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 AIg(C,n)},lIg=(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+oS[e[I]]>g?I:g},n_={string2buf:aIg,buf2string:sIg,utf8border:lIg};function cIg(){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 uIg=cIg;const e1=16209,dIg=16191;var hIg=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=e1;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=e1;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=e1;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(of+1),S=new Uint16Array(of+1);let X=null,W,R,H;for(s=0;s<=of;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===mle||c!==1))return-1;for(S[1]=0,s=1;sdle||e===fle&&f>hle)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<dle||e===fle&&f>hle)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 Tv=yIg;const ZIg=0,b2e=1,y2e=2,{Z_FINISH:ple,Z_BLOCK:GIg,Z_TREES:t1,Z_OK:Dh,Z_STREAM_END:vIg,Z_NEED_DICT:BIg,Z_STREAM_ERROR:oo,Z_DATA_ERROR:Z2e,Z_MEM_ERROR:G2e,Z_BUF_ERROR:SIg,Z_DEFLATED:ble}=_$,jk=16180,yle=16181,Zle=16182,Gle=16183,vle=16184,Ble=16185,Sle=16186,wle=16187,Vle=16188,Rle=16189,VH=16190,_A=16191,BF=16192,Wle=16193,SF=16194,Xle=16195,Hle=16196,Tle=16197,Nle=16198,g1=16199,I1=16200,kle=16201,Yle=16202,Kle=16203,xle=16204,Dle=16205,wF=16206,Fle=16207,Ele=16208,vI=16209,v2e=16210,B2e=16211,wIg=852,VIg=592,RIg=15,WIg=RIg,Mle=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function XIg(){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 Gm=e=>{if(!e)return 1;const g=e.state;return!g||g.strm!==e||g.modeB2e?1:0},S2e=e=>{if(Gm(e))return oo;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=jk,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(wIg),g.distcode=g.distdyn=new Int32Array(VIg),g.sane=1,g.back=-1,Dh},w2e=e=>{if(Gm(e))return oo;const g=e.state;return g.wsize=0,g.whave=0,g.wnext=0,S2e(e)},V2e=(e,g)=>{let I;if(Gm(e))return oo;const i=e.state;return g<0?(I=0,g=-g):(I=(g>>4)+5,g<48&&(g&=15)),g&&(g<8||g>15)?oo:(i.window!==null&&i.wbits!==g&&(i.window=null),i.wrap=I,i.wbits=g,w2e(e))},R2e=(e,g)=>{if(!e)return oo;const I=new XIg;e.state=I,I.strm=e,I.window=null,I.mode=jk;const i=V2e(e,g);return i!==Dh&&(e.state=null),i},HIg=e=>R2e(e,WIg);let zle=!0,VF,RF;const TIg=e=>{if(zle){VF=new Int32Array(512),RF=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(Tv(b2e,e.lens,0,288,VF,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;Tv(y2e,e.lens,0,32,RF,0,e.work,{bits:5}),zle=!1}e.lencode=VF,e.lenbits=9,e.distcode=RF,e.distbits=5},W2e=(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(Gm(e)||!e.output||!e.input&&e.avail_in!==0)return oo;I=e.state,I.mode===_A&&(I.mode=BF),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=Dh;e:for(;;)switch(I.mode){case jk:if(I.wrap===0){I.mode=BF;break}for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0),s=0,A=0,I.mode=yle;break}if(I.head&&(I.head.done=!1),!(I.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",I.mode=vI;break}if((s&15)!==ble){e.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){e.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=Na(I.check,w,2,0)),s=0,A=0,I.mode=Zle;case Zle: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=Na(I.check,w,4,0)),s=0,A=0,I.mode=Gle;case Gle: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=Na(I.check,w,2,0)),s=0,A=0,I.mode=vle;case vle:if(I.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=i[C++]<>>8&255,I.check=Na(I.check,w,2,0)),s=0,A=0}else I.head&&(I.head.extra=null);I.mode=Ble;case Ble: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=Na(I.check,i,u,C)),o-=u,C+=u,I.length-=u),I.length))break e;I.length=0,I.mode=Sle;case Sle: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=_A;break;case Rle:for(;A<32;){if(o===0)break e;o--,s+=i[C++]<>>=A&7,A-=A&7,I.mode=wF;break}for(;A<3;){if(o===0)break e;o--,s+=i[C++]<>>=1,A-=1,s&3){case 0:I.mode=Wle;break;case 1:if(TIg(I),I.mode=g1,g===t1){s>>>=2,A-=2;break e}break;case 2:I.mode=Hle;break;case 3:e.msg="invalid block type",I.mode=vI}s>>>=2,A-=2;break;case Wle: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=vI;break}if(I.length=s&65535,s=0,A=0,I.mode=SF,g===t1)break e;case SF:I.mode=Xle;case Xle: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=_A;break;case Hle: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=vI;break}I.have=0,I.mode=Tle;case Tle: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=Tv(ZIg,I.lens,0,19,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid code lengths set",I.mode=vI;break}I.have=0,I.mode=Nle;case Nle: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=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){e.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){e.msg="invalid code -- missing end-of-block",I.mode=vI;break}if(I.lenbits=9,V={bits:I.lenbits},v=Tv(b2e,I.lens,0,I.nlen,I.lencode,0,I.work,V),I.lenbits=V.bits,v){e.msg="invalid literal/lengths set",I.mode=vI;break}if(I.distbits=6,I.distcode=I.distdyn,V={bits:I.distbits},v=Tv(y2e,I.lens,I.nlen,I.ndist,I.distcode,0,I.work,V),I.distbits=V.bits,v){e.msg="invalid distances set",I.mode=vI;break}if(I.mode=g1,g===t1)break e;case g1:I.mode=I1;case I1: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,hIg(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===_A&&(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=Dle;break}if(b&32){I.back=-1,I.mode=_A;break}if(b&64){e.msg="invalid literal/length code",I.mode=vI;break}I.extra=b&15,I.mode=kle;case kle:if(I.extra){for(S=I.extra;A>>=I.extra,A-=I.extra,I.back+=I.extra}I.was=I.length,I.mode=Yle;case Yle: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=vI;break}I.offset=p,I.extra=b&15,I.mode=Kle;case Kle: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=vI;break}I.mode=xle;case xle: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=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=I1);break;case Dle:if(a===0)break e;n[r++]=I.length,a--,I.mode=I1;break;case wF:if(I.wrap){for(;A<32;){if(o===0)break e;o--,s|=i[C++]<{if(Gm(e))return oo;let g=e.state;return g.window&&(g.window=null),e.state=null,Dh},YIg=(e,g)=>{if(Gm(e))return oo;const I=e.state;return I.wrap&2?(I.head=g,g.done=!1,Dh):oo},KIg=(e,g)=>{const I=g.length;let i,n,C;return Gm(e)||(i=e.state,i.wrap!==0&&i.mode!==VH)?oo:i.mode===VH&&(n=1,n=I_(n,g,I,0),n!==i.check)?Z2e:(C=W2e(e,g,I,I),C?(i.mode=v2e,G2e):(i.havedict=1,Dh))};var xIg=w2e,DIg=V2e,FIg=S2e,EIg=HIg,MIg=R2e,zIg=NIg,PIg=kIg,JIg=YIg,OIg=KIg,_Ig="pako inflate (from Nodeca project)",os={inflateReset:xIg,inflateReset2:DIg,inflateResetKeep:FIg,inflateInit:EIg,inflateInit2:MIg,inflate:zIg,inflateEnd:PIg,inflateGetHeader:JIg,inflateSetDictionary:OIg,inflateInfo:_Ig};function LIg(){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 UIg=LIg;const X2e=Object.prototype.toString,{Z_NO_FLUSH:QIg,Z_FINISH:jIg,Z_OK:aS,Z_STREAM_END:WF,Z_NEED_DICT:XF,Z_STREAM_ERROR:$Ig,Z_DATA_ERROR:Ple,Z_MEM_ERROR:qIg}=_$;function Nw(e){this.options=f2e.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 uIg,this.strm.avail_out=0;let I=os.inflateInit2(this.strm,g.windowBits);if(I!==aS)throw new Error(i_[I]);if(this.header=new UIg,os.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=n_.string2buf(g.dictionary):X2e.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(I=os.inflateSetDictionary(this.strm,g.dictionary),I!==aS)))throw new Error(i_[I])}Nw.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?jIg:QIg,X2e.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=os.inflate(I,r),C===XF&&n&&(C=os.inflateSetDictionary(I,n),C===aS?C=os.inflate(I,r):C===Ple&&(C=XF));I.avail_in>0&&C===WF&&I.state.wrap>0&&e[I.next_in]!==0;)os.inflateReset(I),C=os.inflate(I,r);switch(C){case $Ig:case Ple:case XF:case qIg:return this.onEnd(C),this.ended=!0,!1}if(o=I.avail_out,I.next_out&&(I.avail_out===0||C===WF))if(this.options.to==="string"){let a=n_.utf8border(I.output,I.next_out),s=I.next_out-a,A=n_.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===aS&&o===0)){if(C===WF)return C=os.inflateEnd(this.strm),this.onEnd(C),this.ended=!0,!0;if(I.avail_in===0)break}}return!0};Nw.prototype.onData=function(e){this.chunks.push(e)};Nw.prototype.onEnd=function(e){e===aS&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=f2e.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function L$(e,g){const I=new Nw(g);if(I.push(e),I.err)throw I.msg||i_[I.err];return I.result}function eig(e,g){return g=g||{},g.raw=!0,L$(e,g)}var tig=Nw,gig=L$,Iig=eig,iig=L$,nig=_$,Cig={Inflate:tig,inflate:gig,inflateRaw:Iig,ungzip:iig,constants:nig};const{Inflate:Cpg,inflate:rpg,inflateRaw:rig,ungzip:opg}=Cig;var oig=rig;function aig(e){return oig(e.subarray(2))}class Aig extends Error{constructor(g){super(g),this.code="ERR_ABORTED"}}function sig(e){e.sort((n,C)=>Number(n.offset)-Number(C.offset));const g=[];let I,i;for(let n=0;n=I}function dig(e){const g=e?"big":"little",I=new kg().endianess(g).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),i=new kg().endianess(g).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new kg().endianess(g).array("blocksToFetch",{length:"cnt",type:new kg().endianess(g).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(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new kg().endianess(g).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new kg().endianess(g).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[uig]:new kg().array("items",{length:"itemCount",type:new kg().floatle("score")}),[cig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").floatle("score")}),[lig]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:I,leafParser:i}}class H2e{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 Pgg({cache:new Ret({maxSize:1e3}),fill:async(a,s)=>{const A=Number(a.length),l=Number(a.offset),{buffer:c}=await this.bbi.read(gh.Buffer.alloc(A),0,A,l,{signal:s});return c}}),!(i>=0))throw new Error("invalid cirTreeOffset!");const o=dig(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(gh.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 nc(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(;CHF(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;uHF(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=sig(I);i1(r),await Promise.all(a.map(async s=>{i1(r);const{length:A,offset:l}=s,c=await this.featureCache.get(`${A}_${l}`,s,r);s.blocks.forEach(u=>{i1(r);let d=Number(u.offset)-Number(s.offset),h=c;switch(C&&(h=aig(c.subarray(d)),d=0),i1(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 C_=function(e,g){return C_=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])},C_(e,g)};function U$(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Class extends value "+String(g)+" is not a constructor or null");C_(e,g);function I(){this.constructor=e}e.prototype=g===null?Object.create(g):(I.prototype=g.prototype,new I)}function Jle(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 r_(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 o_(e,g,I){if(I||arguments.length===2)for(var i=0,n=g.length,C;i=2,!1,!0))}var Yig=function(e,g){return e.push(g),e};function Kig(){return Y2e(function(e,g){kig(Yig,[])(e).subscribe(g)})}const Qle=-2003829722,kF=-2021002517;function xig(e){return new TextDecoder().decode(e)}function jle(e){const g=e?"big":"little",I=new kg().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 kg().endianess(g).uint32("reductionLevel").uint32("reserved").uint64("dataOffset").uint64("indexOffset")}),i=new kg().endianess(g).uint64("basesCovered").doublele("scoreMin").doublele("scoreMax").doublele("scoreSum").doublele("scoreSumSquares"),n=new kg().endianess(g).uint32("magic").uint32("blockSize").uint32("keySize").uint32("valSize").uint64("itemCount"),C=new kg().endianess(g).uint8("isLeafNode").skip(1).uint16("cnt").saveOffset("offset");return{chromTreeParser:n,totalSummaryParser:i,headerParser:I,isLeafNode:C}}class Dig{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 cbe(C);else if(n)this.bbi=new mme(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(gh.Buffer.alloc(I),0,I,0,g),n=this._isBigEndian(i),C=jle(n),r=C.headerParser.parse(i),{magic:o,asOffset:a,totalSummaryOffset:s}=r;if(r.fileType=o===kF?"bigbed":"bigwig",a>I||s>I)return this._getMainHeader(g,I*2);if(a){const A=Number(r.asOffset);r.autoSql=xig(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===Qle||I===kF)return!1;if(I=g.readInt32BE(0),I===Qle||I===kF)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(gh.Buffer.alloc(s),0,s,Number(a),I),l=jle(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 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 Sig(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 Tig(C.pipe(Kig()))).flat()}}class Fig extends Dig{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 H2e(this.bbi,n,c,r,o>0,"summary")}}return this.getUnzoomedView(I)}}function K2e(e,g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');const I=class{constructor(){rt(this,"dataConfig"),rt(this,"bwFileHeader"),rt(this,"bwFile"),rt(this,"TILE_SIZE"),rt(this,"errorTxt"),rt(this,"dataPromises"),rt(this,"chromSizes"),rt(this,"assembly"),rt(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=bI(this.assembly).size,C=[],r={};let o=0;Object.keys(bI(this.assembly).size).forEach((a,s)=>{const A={id:s,chr:a,pos:o};C.push(A),r[a]=A,o+=bI(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 Fig({filehandle:new $be(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}K2e.config={type:"bigwig"};function x2e(e,g){const{field:I,not:i}=e;let n=Array.from(g);if(G4e(e)){const{oneOf:C}=e;n=n.filter(r=>i?C.indexOf(r[I])===-1:C.indexOf(r[I])!==-1)}else if(v4e(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(B4e(e)){const{include:C}=e;n=n.filter(r=>i?`${r[I]}`.includes(C):!`${r[I]}`.includes(C))}return n}function Eig(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 Mig(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 zig(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 Pig(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 Jig(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 Oig(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 _ig(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 Lig(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=bI(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 Uig(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 Qig(e,g){if(V4e(e).length===0)return g;const I=s5(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(!ut(i))return g;const n=i.field;if(!n)return g;const C=[...s5(e,"quantitative"),...s5(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(!ut(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 jig{constructor(g){fg(this,_O),fg(this,x$),fg(this,vH),fg(this,UO),fg(this,QO),fg(this,jO),rt(this,"dataConfig"),rt(this,"tilesetInfoLoading"),fg(this,hG,void 0),fg(this,CS,void 0),fg(this,rS,void 0),fg(this,Md,void 0),fg(this,ZH,void 0),fg(this,GH,void 0),this.dataConfig=g,this.tilesetInfoLoading=!1,WC(this,Md,this.dataConfig.assembly),WC(this,ZH,this.dataConfig.filter),g.url||console.error("Please provide the `url` of the data");const{urlFetchOptions:I,url:i}=g;WC(this,GH,new $be(i,{overrides:I})),WC(this,CS,SI(this,jO,i2e).call(this)),WC(this,hG,SI(this,_O,e2e).call(this))}tilesetInfo(g){if(Dt(this,hG))return this.tilesetInfoLoading=!0,Dt(this,hG).then(()=>SI(this,UO,g2e).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(SI(this,QO,I2e).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)})}}hG=new WeakMap;CS=new WeakMap;rS=new WeakMap;Md=new WeakMap;ZH=new WeakMap;GH=new WeakMap;_O=new WeakSet;e2e=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 Dt(this,GH).readFile()).toString(),A=n?`${n.join(o)} -${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).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))}),WC(this,rS,Object.keys(u).map(d=>u[d]))}else WC(this,rS,l)}catch(a){console.error("[Gosling Data Fetcher] Error fetching data",a)}};x$=new WeakSet;t2e=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(SI(this,vH,LO).call(this,r,a))})}):I&&i&&i.forEach(n=>{const C=e[n],r=e[I];e[n]=String(SI(this,vH,LO).call(this,r,C))}),e}catch{return}};vH=new WeakSet;LO=function(e,g){if(Dt(this,Md)!=="unknown"){const I=m3(e,Dt(this,Md),this.dataConfig.chromosomePrefix);return bI(Dt(this,Md)).interval[I][0]+ +g}else return g};UO=new WeakSet;g2e=function(e){this.tilesetInfoLoading=!1;const g=1024,I=Dt(this,CS).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};QO=new WeakSet;I2e=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=jbe(Dt(this,rS),[o,a],this.dataConfig);(i=Dt(this,ZH))==null||i.forEach(l=>{s=x2e(l,s)});const A=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>A?e7(s,A):s,server:null,tilePos:[g,I],zoomLevel:e}};jO=new WeakSet;i2e=function(){const e=bI(Dt(this,Md)).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)=>Dt(this,CS).chrPositions[n].pos+C,cumPositions:g,chrPositions:I,totalLength:i,chromLengths:e}};function D2e(e,g,I){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new jig(g)}D2e.config={type:"csv"};function F2e(e,...g){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');class I{constructor(n){rt(this,"dataConfig"),rt(this,"tilesetInfoLoading"),rt(this,"chromSizes"),rt(this,"values"),rt(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=bI(this.assembly).size,o=[],a={};let s=0;Object.keys(bI(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),a[u]=h,s+=bI(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=m3(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=m3(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=jbe(this.values,[A,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const a=Object.entries(bI(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()},qig)}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))}}rt(M2e,"config",{type:"gff"});const z2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29tbW9uSlMgPSAoY2IsIG1vZCkgPT4gZnVuY3Rpb24gX19yZXF1aXJlKCkgewogICAgcmV0dXJuIG1vZCB8fCAoMCwgY2JbT2JqZWN0LmtleXMoY2IpWzBdXSkoKG1vZCA9IHsgZXhwb3J0czoge30gfSkuZXhwb3J0cywgbW9kKSwgbW9kLmV4cG9ydHM7CiAgfTsKICB2YXIgX19leHBvcnQgPSAodGFyZ2V0LCBhbGwpID0+IHsKICAgIF9fbWFya0FzTW9kdWxlKHRhcm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3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMTAgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAxKV0gPDwgNCB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDIpXSA+PiAyOwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgPj4gOCAmIDI1NTsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICByZXR1cm4gYXJyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyaXBsZXRUb0Jhc2U2NChudW0pIHsKICAgICAgICByZXR1cm4gbG9va3VwW251bSA+PiAxOCAmIDYzXSArIGxvb2t1cFtudW0gPj4gMTIgJiA2M10gKyBsb29rdXBbbnVtID4+IDYgJiA2M10gKyBsb29rdXBbbnVtICYgNjNdOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGVuY29kZUNodW5rKHVpbnQ4LCBzdGFydCwgZW5kKSB7CiAgICAgICAgdmFyIHRtcDsKICAgICAgICB2YXIgb3V0cHV0ID0gW107CiAgICAgICAgZm9yICh2YXIgaTIgPSBzdGFydDsgaTIgPCBlbmQ7IGkyICs9IDMpIHsKICAgICAgICAgIHRtcCA9ICh1aW50OFtpMl0gPDwgMTYgJiAxNjcxMTY4MCkgKyAodWludDhbaTIgKyAxXSA8PCA4ICYgNjUyODApICsgKHVpbnQ4W2kyICsgMl0gJiAyNTUpOwogICAgICAgICAgb3V0cHV0LnB1c2godHJpcGxldFRvQmFzZTY0KHRtcCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArI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AgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbSA9IHZhbHVlICogTWF0aC5wb3coMiwgZUJpYXMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yICg7IG1MZW4gPj0gODsgYnVmZmVyW29mZnNldCArIGldID0gbSAmIDI1NSwgaSArPSBkLCBtIC89IDI1NiwgbUxlbiAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGUgPSBlIDw8IG1MZW4gfCBtOwogICAgICAgIGVMZW4gKz0gbUxlbjsKICAgICAgICBmb3IgKDsgZUxlbiA+IDA7IGJ1ZmZlcltvZmZzZXQgKyBpXSA9IGUgJiAyNTUsIGkgKz0gZCwgZSAvPSAyNTYsIGVMZW4gLT0gOCkgewogICAgICAgIH0KICAgICAgICBidWZmZXJbb2Zmc2V0ICsgaSAtIGRdIHw9IHMgKiAxMjg7CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vI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AgICAgICBjb25zb2xlLmVycm9yKCJUaGlzIGJyb3dzZXIgbGFja3MgdHlwZWQgYXJyYXkgKFVpbnQ4QXJyYXkpIHN1cHBvcnQgd2hpY2ggaXMgcmVxdWlyZWQgYnkgYGJ1ZmZlcmAgdjUueC4gVXNlIGBidWZmZXJgIHY0LnggaWYgeW91IHJlcXVpcmUgb2xkIGJyb3dzZXIgc3VwcG9ydC4iKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB0eXBlZEFycmF5U3VwcG9ydCgpIHsKICAgICAgICB0cnkgewogICAgICAgICAgY29uc3QgYXJyID0gbmV3IFVpbnQ4QXJyYXkoMSk7CiAgICAgICAgICBjb25zdCBwcm90byA9IHsgZm9vOiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgcmV0dXJuIDQyOwogICAgICAgICAgfSB9OwogICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKHByb3RvLCBVaW50OEFycmF5LnByb3RvdHlwZSk7CiAgICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXIxMC5wcm90b3R5cGUsICJwYXJlbnQiLCB7CiAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIHN0cmluZy4gUmVjZWl2ZWQgdHlwZSBudW1iZXInKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShhcmcpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbShhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCk7CiAgICAgIH0KICAgICAgQnVmZm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ICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0gPSBhcnJheVtpXSAmIDI1NTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQXJyYXlWaWV3KGFycmF5VmlldykgewogICAgICAgIGlmIChpc0luc3RhbmNlKGFycmF5VmlldywgVWludDhBcnJheSkpIHsKICAgICAgICAgIGNvbnN0IGNvcHkgPSBuZXcgVWludDhBcnJheShhcnJheVZpZXcpOwogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUJ1ZmZlcihjb3B5LmJ1ZmZlciwgY29weS5ieXRlT2Zmc2V0LCBjb3B5LmJ5dGVMZW5ndGgpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbUFycmF5TGlrZShhcnJheVZpZXcpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21BcnJheUJ1ZmZlcihhcnJheSwgYnl0ZU9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwIHx8IGFycmF5LmJ5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ogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuZ3RoIHwgMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBTbG93QnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmICgrbGVuZ3RoICE9IGxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJ1ZmZlcjEwLmFsbG9jKCtsZW5ndGgpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmlzQnVmZmVyID0gZnVuY3Rpb24gaXNCdWZmZXIyKGIpIHsKICAgICAgICByZXR1cm4gYiAhPSBudWxsICYmIGIuX2lzQnVmZmVyID09PSB0cnVlICYmIGIgIT09IEJ1ZmZlcjEwLnByb3RvdHlwZTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29tcGFyZSA9IGZ1bmN0aW9uIGNvbXBhcmUoYSwgYikgewogICAgICAgIGlmIChpc0luc3RhbmNlKGEsIFVpbnQ4QXJyYXkpKQogICAgICAgICAgYSA9IEJ1ZmZlcjEwLmZyb20oYSwgYS5vZmZzZXQsIGEuYnl0ZUxlbmd0aCk7CiAgICAgICAgaWYgKGlzSW5zdGFuY2UoYiwgVWludDhBcnJheSkpCiAgICAgICAgICBiID0gQnVmZmVyMTAuZnJvbShiLCBiLm9mZnNldCwgYi5ieXRlTGVuZ3RoKTsKICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKGEpIHx8ICFCdWZmZXIxMC5pc0J1ZmZlcihiKSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlICJidWYxIiwgImJ1ZjIiIGFyZ3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgMCwgbGVuZ3RoKTsKICAgICAgICByZ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KHRoaXNTdGFydCA+PSB0aGlzRW5kICYmIHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCkgewogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPj0gZW5kKSB7CiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgdGhpc1N0YXJ0ID4+Pj0gMDsKICAgICAgICB0aGlzRW5kID4+Pj0gMDsKICAgICAgICBpZiAodGhpcyA9PT0gdGFyZ2V0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSB0aGlzRW5kIC0gdGhpc1N0YXJ0OwogICAgICAgIGxldCB5ID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgY29uc3QgbGVuID0gTWF0aC5taW4oeCwgeSk7CiAgICAgICAgY29uc3QgdGhpc0NvcHkgPSB0aGlzLnNsaWNlKHRoaXNTdGFydCwgdGhpc0VuZCk7CiAgICAgICAgY29uc3QgdGFyZ2V0Q29weSA9IHRhcmdldC5zbGljZShzdGFydCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAodGhpc0NvcHlbaV0gIT09IHRhcmdldENvcHlbaV0pIHsKICAgICAgICAgICAgeCA9IHRoaXNDb3B5W2ldOwogICAgICAgICAgICB5ID0gdGFyZ2V0Q29weVtpXTsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh4IDwgeSkKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICBpZiAoeSA8IHgpCiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYm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ZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBsZW5ndGggPSBOdW1iZXIobGVuZ3RoKTsKICAgICAgICAgIGlmIChsZW5ndGggPiByZW1haW5pbmcpIHsKICAgICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAg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HN0cmluZywgb2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICByZXR1cm4gYmxpdEJ1ZmZlcih1dGYxNmxlVG9CeXRlcyhzdHJpbmcsIGJ1Zi5sZW5ndGggLSBvZmZzZXQpLCBidWYsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUud3JpdGUgPSBmdW5jdGlvbiB3cml0ZShzdHJpbmcsIG9mZnNldCwgbGVuZ3RoLCBlbmNvZGluZykgewogICAgICAgIGlmIChvZmZzZXQgPT09IHZvaWQgMCkgewogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgICBsZW5ndGggPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIG9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChsZW5ndGggPT09IHZvaWQgMCAmJiB0eXBlb2Ygb2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBvZmZzZXQ7CiAgICAgICAgICBsZW5ndGggPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIG9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChpc0Zpbml0ZShvZmZzZXQpKSB7CiAgICAgICAgICBvZmZzZXQgPSBvZmZzZXQgPj4+IDA7CiAgICAgICAgICBpZiAoaXNGaW5pdGUobGVuZ3RoKSkgewogICAgICAgICAgICBsZW5ndGggPSBsZW5ndGggPj4+IDA7CiAgICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gdm9pZCAwKQogICAgICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5nLCBlbmNvZGluZywgb2Zmc2V0WywgbGVuZ3RoXSkgaXMgbm8gbG9uZ2VyIHN1cHBvcnRlZCIpOwogICAgICAgIH0KICAgICAgICBjb25zdCByZW1haW5pbmcgPSB0aGlzLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAobGVuZ3RoID09PSB2b2lkIDAgfHwgbGVuZ3RoID4gcmVtYWluaW5nKQogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIGlmIChzdHJpbmcubGVuZ3RoID4gMCAmJiAobGVuZ3RoIDwgMCB8fCBvZmZzZXQgPCAwKSB8fCBvZmZzZXQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkF0dGVtcHQgdG8gd3JpdGUgb3V0c2lkZSBidWZmZXIgYm91bmRzIik7CiAgICAgICAgfQogICAgICAgIGlmICghZW5jb2RpbmcpCiAgICAgICAgICBlbmNvZGluZyA9ICJ1dGY4IjsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHRoaXMuX2FyciB8fCB0aGlzLCAwKQogICAgICAgIH07CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFNsaWNlKGJ1Ziwgc3RhcnQsIGVuZCkgewogICAgICAgIGlmIChzdGFydCA9PT0gMCAmJiBlbmQgPT09IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiBiYXNlNjQuZnJvbUJ5dGVBcnJheShidWYpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gYmFzZ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JiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IGxl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ICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIHJldHVybiBvZmZzZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gd3J0QmlnVUludDY0QkUoYnVmLCB2YWx1ZSwgb2Zmc2V0LCBtaW4sIG1heCkgewogICAgICAgIGNoZWNrSW50QkkodmFsdWUsIG1pbiwgbWF4LCBidWYsIG9mZnNldCwgNyk7CiAgICAgICAgbGV0IGxvID0gTnVtYmVyKHZhbHVlICYgQmlnSW50KDQyOTQ5NjcyOTUpKTsKICAgICAgICBidWZbb2Zmc2V0ICsgN10gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDZdID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyA1XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNF0gPSBsbzsKICAgICAgICBsZXQgaGkgPSBOdW1iZXIodmFsdWUgPj4gQmlnSW50KDMyKSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCArIDNdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyAyXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgMV0gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldF0gPSBoaTsKICAgICAgICByZXR1cm4gb2Zmc2V0ICsgODsKICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUud3JpdGVCaWdVSW50NjRMRSA9IGRlZmluZUJpZ0lud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YW5nZSIpOwogICAgICAgIGlmIChlbmQgPCAwKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoInNvdXJjZUVuZCBvdXQgb2YgYm91bmRzIik7CiAgICAgICAgaWYgKGVuZCA+IHRoaXMubGVuZ3RoKQogICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKHRhcmdldC5sZW5ndGggLSB0YXJnZXRTdGFydCA8IGVuZCAtIHN0YXJ0KSB7CiAgICAgICAgICBlbmQgPSB0YXJnZXQubGVuZ3RoIC0gdGFyZ2V0U3RhcnQgKyBzdGFydDsKICAgICAgICB9CiAgICAgICAgY29uc3QgbGVuID0gZW5kIC0gc3RhcnQ7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCAmJiB0eXBlb2YgVWludDhBcnJheS5wcm90b3R5cGUuY29weVdpdGhpbiA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgdGhpcy5jb3B5V2l0aGluKHRhcmdldFN0YXJ0LCBzdGFydCwgZW5kKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5maWxsID0gZnVuY3Rpb24gZmlsbCh2YWwsIHN0YXJ0LCBlbmQsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAiYm9vbGVhbiIpIHsKICAgICAgICAgIHZhbCA9IE51bWJlcih2YWwpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IHRoaXMubGVuZ3RoIDwgc3RhcnQgfHwgdGhpcy5sZW5ndGggPCBlbmQpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJPdXQgb2YgcmFuZ2UgaW5kZXgiKTsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID0gc3RhcnQgPj4+IDA7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyB0aGlzLmxlbmd0aCA6IGVuZCA+Pj4gMDsKICAgICAgICBpZiAoIXZhbCkKICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICBmb3IgKGkgPSBzdGFydDsgaSA8IGVuZDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaV0gPSB2YWw7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGNvbnN0IGJ5dGVzID0gQnVmZmVyMTAuaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjEwLmZyb20odmFsLCBlbmNvZGluZyk7CiAgICAgICAgICBjb25zdCBsZW4gPSBieXRlcy5sZW5ndGg7CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSB2YWx1ZSAiJyArIHZhbCArICciIGlzIGludmFsaWQgZm9yIGFyZ3VtZW50ICJ2YWx1ZSInKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBlbmQgLSBzdGFydDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaSArIHN0YXJ0XSA9IGJ5dGVzW2kgJSBsZW5dOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgdmFyIGVycm9ycyA9IHt9OwogICAgICBmdW5jdGlvbiBFKHN5bSwgZ2V0TWVzc2FnZSwgQmFzZSkgewogICAgICAgIGVycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiBgJHt0aGlzLm5hbWV9IFske3N5bX1dOiAke3RoaXMubWVzc2FnZX1gOwogICAgICAgICAgfQogICAgICAgIH07CiAgICAgIH0KICAgICAgRSgiRVJSX0JVRkZFUl9PVVRfT0ZfQk9VTkRTIiwgZnVuY3Rpb24obmFtZSkgewogICAgICAgIGlmIChuYW1lKSB7CiAgICAgICAgICByZXR1cm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A9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8PSAke21heH0ke259YDsKICAgICAgICAgIH0KICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX09VVF9PRl9SQU5HRSgidmFsdWUiLCByYW5nZSwgdmFsdWUpOwogICAgICAgIH0KICAgICAgICBjaGVja0JvdW5kcyhidWYsIG9mZnNldCwgYnl0ZUxlbmd0aDIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHZhbGlkYXRlTnVtYmVyKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gIm51bWJlciIpIHsKICAgICAgICAgIHRocm93IG5ldyBlcnJvcnMuRVJSX0lOVkFMSURfQVJHX1RZUEUobmFtZSwgIm51bWJlciIsIHZhbHVlKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYm91bmRzRXJyb3IodmFsdWUsIGxlbmd0aCwgdHlwZSkgewogICAgICAgIGlmIChNYXRoLmZsb29yKHZhbHVlKSAhPT0gdmFsdWUpIHsKICAgICAgICAgIHZ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uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmFzZTY0VG9CeXRlcyhzdHIpIHsKICAgICAgICByZXR1cm4gYmFzZTY0LnRvQnl0ZUFycmF5KGJhc2U2NGNsZWFuKHN0cikpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJsaXRCdWZmZXIoc3JjLCBkc3QsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBpZiAoaSArIG9mZnNldCA+PSBkc3QubGVuZ3RoIHx8IGkgPj0gc3JjLmxlbmd0aCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBkc3RbaSArIG9mZnNldF0gPSBzcmNbaV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGlzSW5zdGFuY2Uob2JqLCB0eXBlKSB7CiAgICAgICAgcmV0dXJuIG9iaiBpbnN0YW5jZW9mIHR5cGUgfHwgb2JqICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgIT0gbnVsbCAmJiBvYmouY29uc3RydWN0b3IubmFtZSA9PT0gdHlwZS5uYW1lOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIG51bWJlcklzTmFOKG9iaikgewogICAgICAgIHJldHVybiBvYmogIT09IG9iajsKICAgICAgfQogICAgICB2YXIgaGV4U2xpY2VMb29rdXBUYWJsZSA9IGZ1bmN0aW9uKCkgewogICAgICAgIGNvbnN0IGFscGhhYmV0ID0gIjAxMjM0NTY3ODlhYmNkZWYiOwogICAgICAgIGNvbnN0IHRhYmxlID0gbmV3IEFycmF5KDI1Nik7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCAxNjsgKytpKSB7CiAgICAgICAgICBjb25zdCBpMTYgPSBpICogMTY7CiAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDE2OyArK2opIHsKICAgICAgICAgICAgdGFibGVbaTE2ICsgal0gPSBhbHBoYWJldFtpXSArIGFscGhhYmV0W2pdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGFibGU7CiAgICAgIH0oKTsKICAgICAgZnVuY3Rpb24gZGVmaW5lQmlnSW50TWV0aG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RvdHlwZSIsIHsKICAgICAgICAgIHdyaXRhYmxlOiBmYWxzZQogICAgICAgIH0pOwogICAgICAgIHJldHVybiBDb25zdHJ1Y3RvcjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaW5oZXJpdHMoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZX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FByb3RvdHlwZU9mKHRoaXMpLmNvbnN0cnVjdG9yOwogICAgICAgICAgICByZXN1bHQgPSBSZWZsZWN0LmNvbnN0cnVjdChTdXBlciwgYXJndW1lbnRzLCBOZXdUYXJnZXQpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2wudG9TdHJpbmdUYWcpIHsKICAgICAgICBBYm9ydENvbnRyb2xsZXIucHJvdG90eXBlW1N5bWJvbC50b1N0cmluZ1RhZ10gPSAiQWJvcnRDb250cm9sbGVyIjsKICAgICAgICBBYm9ydFNpZ25hbC5wcm90b3R5cGVbU3ltYm9sLnRvU3RyaW5nVGFnXSA9ICJBYm9ydFNpZ25hbCI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcG9seWZpbGxOZWVkZWQoc2VsZjIpIHsKICAgICA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aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc2lnbmFsOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJhY2UoW2NhbmNlbGxhdGlvbiwgcmVhbEZldGNoKGlucHV0LCBpbml0MildKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZWFsRmV0Y2goaW5wdXQsIGluaXQyKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiB7CiAgICAgICAgICBmZXRjaDogYWJvcnRhYmxlRmV0Y2gsCiAgICAgICAgICBSZXF1ZXN0CiAgICAgICAgfTsKICAgICAgfQogICAgICBleHBvcnRzMi5BYm9ydENvbnRyb2xsZXIgPSBBYm9ydENvbnRyb2xsZXI7CiAgICAgIGV4cG9ydHMyLkFib3J0U2lnbmFsID0gQWJvcnRTaWduYWw7CiAgICAgIGV4cG9ydHMyLmFib3J0YWJsZUZldGNoID0gYWJvcnRhYmxlRmV0Y2hEZWNvcmF0b3I7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9hYm9ydGFibG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iAgICAgIHZhciBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMSA9IHJlcXVpcmVfYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsKCk7CiAgICAgIHZhciBOdWxsU2lnbmFsID0gY2xhc3MgewogICAgICB9OwogICAgICB2YXIgQWdncmVnYXRlQWJvcnRDb250cm9sbGVyID0gY2xhc3MgewogICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgdGhpcy5zaWduYWxzID0gbmV3IFNldCgpOwogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIgPSBuZXcgYWJvcnRjb250cm9sbGVyX3BvbnlmaWxsXzEuQWJvcnRDb250cm9sbGVyKCk7CiAgICAgICAgfQogICAgICAgIGFkZFNpZ25hbChzaWduYWwgPSBuZXcgTnVsbFNpZ25hbCgpKSB7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGhhbmRsZUFib3J0ZWQoc2lnbmFsKSB7CiAgICAgICAgICB0aGlzLnNpZ25hbHMuZGVsZXRlKH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0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiYgZGF0YSBpbnN0YW5jZW9mIGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0U2lnbmFsKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInNlY29uZCBnZXQgYXJndW1lbnQgYXBwZWFycyB0byBiZSBhbiBBYm9ydFNpZ25hbCwgcGVyaGFwcyB5b3UgbWVhbnQgdG8gcGFzcyBgbnVsbGAgZm9yIHRoZSBmaWxsIGRhdGE/Iik7CiAgICAgICAgICB9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gdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIG9sZENhY2hlU2l6ZSsrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5fc2l6ZSArIG9sZENhY2hlU2l6ZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IFF1aWNrTFJVOwogICAgfQogIH0pOwoKICAvLyAoZGlzYWJsZWQpOm5vZGVfbW9kdWxlcy8ucG5wbS9nZW5lcmljLWZpbGVoYW5kbGVAMy4xLjEvbm9kZV9tb2R1bGVzL2dlbmVyaWMtZmlsZWhhbmRsZS9lc20vbG9jYWxGaWxlCiAgdmFyIHJlcXVpcmVfbG9jYWxGaWxlID0gX19jb21tb25KUyh7CiAgICAiKGRpc2FibGVkKTpub2RlX21vZHVsZXMvLnBucG0vZ2VuZXJpYy1maWxlaGFuZGxlQDMuMS4xL25vZGVfbW9kdWxlcy9nZW5lcmljLWZpbGVoYW5kbGUvZXNtL2xvY2FsRmlsZSIoKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi91dGlscy9jb21tb24uanMKICB2YXIgcmVxdWlyZV9jb21tb24gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3V0aWxzL2NvbW1vbi5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciBUWVBFRF9PSyA9IHR5cGVvZiBVaW50OEFycmF5ICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2YgVWludDE2QXJyYXkgIT09ICJ1bmRlZmluZWQiICYmIHR5cGVvZiBJbnQzMkFycmF5ICE9PSAidW5kZWZpbmVkIjsKICAgICAgZnVuY3Rpb24gX2hhcyhvYmosIGtleSkgewogICAgICAgIHJldHVybiBPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwob2JqLCBrZXkpOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHJldHVybiBbXS5jb25jYXQuYXBwbHkoW10sIGNodW5rcyk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZCA9IGZ1bmN0aW9uKG9uKSB7CiAgICAgICAgaWYgKG9uKSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjE2ID0gVWludDE2QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYzMiA9IEludDMyQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVHlwZWQpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLmFzc2lnbihleHBvcnRzMiwgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNldFR5cGVkKFRZUEVEX09LKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3RyZWVzLmpzCiAgdmFyIHJlcXVpcmVfdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgWl9GSVhFRCA9IDQ7CiAgICAgIHZhciBaX0JJTkFSWSA9IDA7CiAgICAgIHZhciBaX1RFWFQgPSAxOwogICAgICB2YXIgWl9VTktOT1dOID0gMjsKICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICB2YXIgU1RPUkVEX0J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gICAgICAgICBzLmJpX2J1ZiB8PSB2YWx1ZSA8PCBzLmJpX3ZhbGlkICYgNjU1MzU7CiAgICAgICAgICBzLmJpX3ZhbGlkICs9IGxlbmd0aDsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9jb2RlKHMsIGMsIHRyZWUpIHsKICAgICAgICBzZW5kX2JpdHMocywgdHJlZVtjICogMl0sIHRyZWVbYyAqIDIgKyAxXSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfcmV2ZXJzZShjb2RlLCBsZW4pIHsKICAgICAgICB2YXIgcmVzID0gMDsKICAgICAgICBkbyB7CiAgICAgICAgICByZXMgfD0gY29kZSAmIDE7CiAgICAgICAgICBjb2RlID4+Pj0gMTsKICAgICAgICAgIHJlcyA8PD0gMTsKICAgICAgICB9IHdoaWxlICgtLWxlbiA+IDApOwogICAgICAgIHJldHVybiByZXMgPj4+IDE7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfZmx1c2gocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID09PSAxNikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+PSA4KSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDIgKyAxXSA9IDU7CiAgICAgICAgICBzdGF0aWNfZHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuLCA1KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljX2xfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfbHRyZWUsIGV4dHJhX2xiaXRzLCBMSVRFUkFMUyArIDEsIExfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfZF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19kdHJlZSwgZXh0cmFfZGJpdHMsIDAsIERfQ09ERVMsIE1BWF9CSVRTKTsKICAgICAgICBzdGF0aWNfYmxfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhuZXcgQXJyYXkoMCksIGV4dHJhX2JsYml0cywgMCwgQkxfQ09ERVMsIE1BWF9CTF9CSVRTKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbml0X2Jsb2NrKHMpIHsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmR5bl9kdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDwgQkxfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5ibF90cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuZHluX2x0cmVlW0VORF9CTE9DSyAqIDJdID0gMTsKICAgICAgICBzLm9wdF9sZW4gPSBzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHMubGFzdF9saXQgPSBzLm1hdGNoZXMgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2RvbmUgPSBmYWxzZTsKICAgICAgZnVuY3Rpb24gX3RyX2luaXQocykgewogICAgICAgIGlmICghc3RhdGljX2luaXRfZG9uZSkgewogICAgICAgICAgdHJfc3RhdGljX2luaXQoKTsKICAgICAgICAgIHN0YXRpY19pbml0X2RvbmUgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBzLmxfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9sdHJlZSwgc3RhdGljX2xfZGVzYyk7CiAgICAgICAgcy5kX2Rlc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wogICAgICAgIH0KICAgICAgICBpbml0X2Jsb2NrKHMpOwogICAgICAgIGlmIChsYXN0KSB7CiAgICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIF90cl90YWxseShzLCBkaXN0LCBsYykgewogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyXSA9IGRpc3QgPj4+IDggJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgcy5sYXN0X2xpdCAqIDIgKyAxXSA9IGRpc3QgJiAyNTU7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgcy5sYXN0X2xpdF0gPSBsYyAmIDI1NTsKICAgICAgICBzLmxhc3RfbGl0Kys7CiAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgIHMuZHluX2x0cmVlW2xjICogMl0rKzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcy5tYXRjaGVzKys7CiAgICAgICAgICBkaXN0LS07CiAgICAgICAgICBzLmR5bl9sdHJlZVsoX2xlbmd0aF9jb2RlW2xjXSArIExJVEVSQUxTICsgMSkgKiAyXSsrOwogICAgICAgICAgcy5keW5fZHRyZWVbZF9jb2RlKGRpc3QpICogMl0rKzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubGFzdF9saXQgPT09IHMubGl0X2J1ZnNpemUgLSAxOwogICAgICB9CiAgICAgIGV4cG9ydHMyLl90cl9pbml0ID0gX3RyX2luaXQ7CiAgICAgIGV4cG9ydHMyLl90cl9zdG9yZWRfYmxvY2sgPSBfdHJfc3RvcmVkX2Jsb2NrOwogICAgICBleHBvcnRzMi5fdHJfZmx1c2hfYmxvY2sgPSBfdHJfZmx1c2hfYmxvY2s7CiAgICAgIGV4cG9ydHMyLl90cl90YWxseSA9IF90cl90YWxseTsKICAgICAgZXhwb3J0czIuX3RyX2FsaWduID0gX3RyX2FsaWduOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcwogIHZhciByZXF1aXJlX2FkbGVyMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIGFkbGVyMzIoYWRsZXIsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgczEgPSBhZGxlciAmIDY1NTM1IHwgMCwgczIgPSBhZGxlciA+Pj4gMTYgJiA2NTUzNSB8IDAsIG4gPSAwOwogICAgICAgIHdoaWxlIChsZW4gIT09IDApIHsKICAgICAgICAgIG4gPSBsZW4gPiAyZTMgPyAyZTMgOiBsZW47CiAgICAgICAgICBsZW4gLT0gbjsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgczEgPSBzMSArIGJ1Zltwb3MrK10gfCAwOwogICAgICAgICAgICBzMiA9IHMyICsgczEgfCAwOwogICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgIHMxICU9IDY1NTIxOwogICAgICAgICAgczIgJT0gNjU1MjE7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdW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sKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgdHJlZXMgPSByZXF1aXJlX3RyZWVzKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMiA9IHJlcXVpcmVfY3JjMzIoKTsKICAgICAgd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9NQVRDSCA9IDM7CiAgICAgIHZhciBNQVhfTUFUQ0ggPSAyNTg7CiAgICAgIHZhciBNSU5fTE9PS0FIRUFEID0gTUFYX01BVENIICsgTUlOX01BVENIICsgMTsKICAgICAgdmFyIFBSRVNFVF9ESUNUID0gMzI7CiAgICAgIHZhciBJTklUX1NUQVRFID0gNDI7CiAgICAgIHZhciBFWFRSQV9TVEFURSA9IDY5OwogICAgICB2YXIgTkFNRV9TVEFURSA9IDczOwogICAgICB2YXIgQ09NTUVOVF9TVEFURSA9IDkxOwogICAgICB2YXIgSENSQ19TVEFURSA9IDEwMzsKICAgICAgdmFyIEJVU1lfU1RBVEUgPSAxMTM7CiAgICAgIHZhciBGSU5JU0hfU1RBVEUgPSA2NjY7CiAgICAgIHZhciBCU19ORUVEX01PUkUgPSAxOwogICAgICB2YXIgQlNfQkxPQ0tfRE9ORSA9IDI7CiAgICAgIHZhciBCU19GSU5JU0hfU1RBUlRFRCA9IDM7CiAgICAgIHZhciBCU19GSU5JU0hfRE9ORSA9IDQ7CiAgICAgIHZhciBPU19DT0RFID0gMzsKICAgICAgZnVuY3Rpb24gZXJyKHN0cm0sIGVycm9yQ29kZSkgewogICAgICAgIHN0cm0ubXNnID0gbXNnW2Vycm9yQ29kZV07CiAgICAgICAgcmV0dXJuIGVycm9yQ29kZTsKICAgICAgfQogICAgICBmdW5jdGlvbiByYW5rKGYpIHsKICAgICAgICByZXR1cm4gKGYgPDwgMSkgLSAoZiA+IDQgPyA5IDogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmFyI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5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICA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F0Y2hfc3RhcnQgPiA0MDk2KSkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMucHJldl9sZW5ndGggPj0gTUlOX01BVENIICYmIHMubWF0Y2hfbGVuZ3RoIDw9IHMucHJldl9sZW5ndGgpIHsKICAgICAgICAgICAgbWF4X2luc2VydCA9IHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCAtIE1JTl9NQVRDSDsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIHMuc3Ryc3RhcnQgLSAxIC0gcy5wcmV2X21hdGNoLCBzLnByZXZfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5wcmV2X2xlbmd0aCAtIDE7CiAgICAgICAgICAgIHMucHJldl9sZW5ndGggLT0gMjsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICB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gdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVyb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fHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgKiAyKTsKICAgICAgICBzLmhlYWQgPSBuZXcgdXRpbHMuQnVmMTYocy5oYXNoX3NpemUpOwogICAgICAgIHMucHJldiA9IG5ldyB1dGlscy5CdWYxNihzLndfc2l6ZSk7CiAgICAgICAgcy5saXRfYnVmc2l6ZSA9IDEgPDwgbWVtTGV2ZWwgKyA2OwogICAgICAgIHMucGVuZGluZ19idWZfc2l6ZSA9IHMubGl0X2J1ZnNpemUgKiA0OwogICAgICAgIHMucGVuZGluZ19idWYgPSBuZXcgdXRp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1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciA+Pj4gMTYpOwogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICB9CiAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICBpZiAocy53cmFwID4gMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMucGVuZGluZyAhPT0gMCA/IFpfT0sgOiBaX1NUUkVBTV9FTkQ7CiAgICAgIH0KICAgIC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zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICAgI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1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwb3MgKyBfdXRmOGxlbltidWZbcG9zXV0gPiBtYXggPyBwb3MgOiBtYXg7CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi96c3RyZWFtLmpzCiAgdmFyIHJlcXVpcmVfenN0cmVhbSA9IF9fY29tbW9uSlMoewogICAgIm5vZGVf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X2NvbW1vbigpOwogICAgICB2YXIgc3RyaW5ncyA9IHJlcXVpcmVfc3RyaW5ncygpOwogICAgICB2YXIgbXNnID0gcmVxdWlyZV9tZXNzYWdlcygpOwogICAgICB2YXIgWlN0cmVhbSA9IHJlcXVpcmVfenN0cmVhbSgpOwogICAgICB2YXIgdG9TdHJpbmcgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICB2YXIgWl9OT19GTFVTSCA9IDA7CiAgICAgIHZhciBaX0ZJTklTSCA9IDQ7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX1NZTkNfRkxVU0gyID0gMjsKICAgICAgdmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xOwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICBmdW5jdGlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gM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ljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAg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MC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzCiAgdmFyIHJlcXVpcmVfaW5mZmFzdCA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZmYXN0LmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX2Zhc3Qoc3RybSwgc3RhcnQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIF9pbjsKICAgICAgICB2YXIgbGFzdDsKICAgICAgICB2YXIgX291dDsKICAgICAgICB2YXIgYmVnOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGRtYXg7CiAgICAgICAgdmFyIHdzaXplOwogICAgICAgIHZhciB3aGF2ZTsKICAgICAgICB2YXIgd25leHQ7CiAgICAgICAgdmFyIHNfd2luZG93OwogICAgICAgIHZhciBob2xkOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsY29kZTsKICAgICAgICB2YXIgZGNvZGU7CiAgICAgICAgdmFyIGxtYXNrOwogICAgICAgIHZhciBkbWFzazsKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgICAgIHJldHVybiAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxvdyA9IGh1ZmYgJiBtYXNrOwogICAgICAgICAgICB0YWJsZVtsb3ddID0gcm9vdDIgPDwgMjQgfCBjdXJyIDw8IDE2IHwgbmV4dCAtIHRhYmxlX2luZGV4IHwgMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGh1ZmYgIT09IDApIHsKICAgICAgICAgIHRhYmxlW25leHQgKyBodWZmXSA9IGxlbiAtIGRyb3AgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgfQogICAgICAgIG9wdHMuYml0cyA9IHJvb3QyOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9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IgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+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/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdGF0ZS5tb2RlICE9PSBESUNUKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBESUNUKSB7CiAgICAgICAgICBkaWN0aWQgPSAxOwogICAgICAgICAgZGljdGlkID0gYWRsZXIzMihkaWN0aWQsIG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gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NvbnN0YW50cy5qcwogIHZhciByZXF1aXJlX2NvbnN0YW50cyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jb25zdGFudHMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgWl9OT19GTFVTSDogMCwKICAgICAgICBaX1BBUlRJQUxfRkxVU0g6IDEsCiAgICAgICAgWl9TWU5DX0ZMVVNIOiAyLAogICAgICAgIFpfRlVMTF9GTFVTSDogMywKICAgICAgICBaX0ZJTklTSDogNCwKICAgICAgICBaX0JMT0NLOiA1LAogICAgICAgIFpfVFJFRVM6IDYsCiAgICAgICAgWl9PSzogMCwKICAgICAgICBaX1NUUkVBTV9FTkQ6IDEsCiAgICAgICAgWl9ORUVEX0RJQ1Q6IDIsCiAgICAgICAgWl9FUlJOTzogLTEsCiAgICAgICAgWl9TVFJFQU1fRVJST1I6IC0yLAogICAgICAgIFpfREFUQV9FUlJPUjogLTMsCiAgICAgICAgWl9CVUZfRVJST1I6IC01LAogICAgICAgIFpfTk9fQ09NUFJFU1NJT046IDAsCiAgICAgICAgWl9CRVNUX1NQRUVEOiAxLAogICAgICAgIFpfQkVTVF9DT01QUkVTU0lPTjogOSwKICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6IDA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ICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5zdHJtID0gbmV3IFpTdHJlYW0oKTsKICAgICAgICB0aGlzLnN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICB2YXIgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVJbml0Mih0aGlzLnN0cm0sIG9wdC53aW5kb3dCaXRzKTsKICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfT0spIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgfQogICAgICAgIHRoaXMuaGVhZGVyID0gbmV3IEdaaGVhZGVyKCk7CiAgICAgICAgemxpYl9pbmZsYXRlLmluZmxhdGVHZXRIZWFkZXIodGhpcy5zdHJtLCB0aGlzLmhlYWRlcik7CiAgICAgICAgaWYgKG9wdC5kaWN0aW9uYXJ5KSB7CiAgICAgICAgICBpZiAodHlwZW9mIG9wdC5kaWN0aW9uYXJ5ID09PSAic3RyaW5nIikgewogICAgIC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cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aGlzLnN0cm0ubXNnOwogICAgICB9OwogICAgICBmdW5jdGlvbiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgdmFyIGluZmxhdG9yID0gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIGluZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGluZmxhdG9yLm1zZyB8fCBtc2dbaW5mbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGluZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgb3B0aW9ucy5yYXcgPSB0cnVlOwogICAgICAgIHJldHVybiBpbmZsYXRlKGlucHV0LCBvcHRpb25zKTsKICAgICAgfQogICAgICBleHBvcnRzMi5JbmZ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ogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmluZyh2YWwsIHVuc2lnbmVkKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsLmxvdywgdmFsLmhpZ2gsIHR5cGVvZiB1bnNpZ25lZCA9PT0gImJvb2xlYW4iID8gdW5zaWduZWQgOiB2YWwudW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21WYWx1ZSA9IGZyb21WYWx1ZTsKICAgICAgdmFyIFRXT19QV1JfMTZfREJMID0gMSA8PCAxNjsKICAgICAgdmFyIFRXT19QV1JfMj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VkFMVUUgPSBNSU5fVkFMVUU7CiAgICAgIHZhciBMb25nUHJvdG90eXBlID0gTG9uZzQucHJvdG90eXBlOwogICAgICBMb25nUHJvdG90eXBlLnRvSW50ID0gZnVuY3Rpb24gdG9JbnQoKSB7CiAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyB0aGlzLmxvdyA+Pj4gMCA6IHRoaXMubG93OwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvTnVtYmVyID0gZnVuY3Rpb24gdG9OdW1iZXIyKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuICh0aGlzLmhpZ2ggPj4+IDApICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggKiBUV09fUFdSXzMyX0RCTCArICh0aGlzLmxvdyA+Pj4gMCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0SGlnaEJpdHMgPSBmdW5jdGlvbiBnZXRIaWdoQml0cygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmdldEhpZ2hCaXRzVW5zaWduZWQgPSBmdW5jdGlvbiBnZXRIaWdoQml0c1Vuc2lnbmVkKCkgewogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPj4+IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZ2V0TG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dG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkICE9PSBvdGhlci51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPj4+IDMxID09PSAxICYmIG90aGVyLmhpZ2ggPj4+IDMxID09PSAxKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPT09IG90aGVyLmhpZ2ggJiYgdGhpcy5sb3cgPT09IG90aGVyLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5lcSA9IExvbmdQcm90b3R5cGUuZXF1YWxzOwogICAgICBMb25nUHJvdG90eXBlLm5vdEVxdWFscyA9IGZ1bmN0aW9uIG5vdEVxdWFscyhvdGhlcikgewogICAgICAgIHJldHVybiAhdGhpcy5lcShvdGhlcik7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubmVxID0gTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHM7CiAgICAgIExvbmdQcm90b3R5cGUubmUgPSBMb25nUHJvdG90eXBlLm5v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0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ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gZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbnVtQml0cywgdGhpcy5oaWdoIDw8IG51bUJpdHMgfCB0aGlzLmxvdyA+Pj4gMzIgLSBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoMCwgdGhpcy5sb3cgPDwgbnVtQml0cyAtIDMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGwgPSBMb25nUHJvdG90eXBlLnNoaWZ0TGVmdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiB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bGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4dGVuZFNlcmlhbGl6ZXIgPSBleHRlbmRTZXJpYWxpemVyOwogICAgICB2YXIgRGVmYXVsdEVycm9yU2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICByZXR1cm4gT2JqZWN0LmFzc2lnbihFcnJvcihtZXNzYWdlLm1lc3NhZ2UpLCB7CiAgICAgICAgICAgIG5hbWU6IG1lc3NhZ2UubmFtZSwKICAgICAgICAgICAgc3RhY2s6IG1lc3NhZ2Uuc3RhY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlK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N0L3dvcmtlci9pbmRleC5qcwogIHZhciByZXF1aXJlX3dvcmtlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS90aHJlYWRzQDEuNy4wL25vZGVfbW9kdWxlcy90aHJlYWRzL2Rpc3Qvd29ya2VyL2luZGV4LmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIF9fYXdhaXRlciA9IGV4cG9ydHMyICYmIGV4cG9ydHMyLl9fYXdhaXRlciB8fCBmdW5jdGlvbih0aGlzQXJnLCBfYXJndW1lbnRzLCBQLCBnZW5lcmF0b3IpIHsKICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgewogICAgICAgICAgcmV0dXJuIHZhbHVlIGluc3RhbmNlb2YgUCA/IHZhbHVlIDogbmV3IFAoZnVuY3Rpb24ocmVzb2x2ZSkgewogICAgICAgICAgICByZXNvbHZlKHZhbHVlKTsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbmV3IChQIHx8IChQID0gUHJvbWlzZSkpKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkgewogICAgICAgICAgZnVuY3Rpb24gZnVsZmlsbGVkKHZhbHVlKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yWyJ0aHJvdyJdKHZhbHVlKSk7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICByZWplY3QoZSk7CiAg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QpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIGluIHRoZSBtYXN0ZXIgdGhyZWFkLiIpOwogICAgICAgIH0KICAgICAgICBpZiAoZXhwb3NlQ2FsbGVkKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIG1vcmUgdGhhbiBvbmNlLiBUaGlzIGlzIG5vdCBwb3NzaWJsZS4gUGFzcyBhbiBvYmplY3QgdG8gZXhwb3NlKCkgaWYgeW91IHdhbnQgdG8gZXhwb3NlIG11bHRpcGxlIGZ1bmN0a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50TGlzdGVuZXIoImVycm9yIiwgKGV2ZW50KSA9PiB7CiAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShldmVudC5lcnJvciB8fCBldmVudCksIDI1MCk7CiAgICAgICAgfSk7CiAgICAgICAgc2VsZi5hZGRFdmVudExpc3RlbmVyKCJ1bmhhbmRsZWRyZWplY3Rpb24iLCAoZXZlbnQpID0+IHsKICAgICAgICAgIGNvbnN0IGVycm9yID0gZXZlbnQucmVhc29uOwogICAgICAgICAgaWYgKGVycm9yICYmIHR5cGVvZiBlcnJvci5tZXNzYWdlID09PSAic3RyaW5nIikgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKHR5cGVvZiBwcm9jZXNzICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2YgcHJvY2Vzcy5vbiA9PT0gImZ1bmN0aW9uIiAmJiBpbXBsZW1lbnRhdGlvbl8xLmRlZmF1bHQuaXNXb3JrZXJSdW50aW1lKCkpIHsKICAgICAgICBwcm9jZXNzLm9uKCJ1bmNhdWdodEV4Y2VwdGlvbiIsIChlcnJvcikgPT4gewogICAgICAgICAgc2V0VGltZW91dCgoKSA9PiBwb3N0VW5jYXVnaHRFcnJvck1lc3NhZ2UoZXJyb3IpLCAyNTApOwogICAgICAgIH0pOwogICAgICAgIHByb2Nlc3Mub24oInVuaGFuZGxlZFJlamVjdGlvbiIsIChlcnJvcikgPT4gewogICAgICAgICAgaWYgKGVycm9yICYmIHR5cGVvZiBlcnJvci5tZXNzYWdlID09PSAic3RyaW5nIikgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgIC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gICAgICAgZW5kOiBmdW5jdGlvbihleHBlY3RhdGlvbikgewogICAgICAgICAgICByZXR1cm4gImVuZCBvZiBpbnB1dCI7CiAgICAgICAgICB9LAogICAgICAgICAgb3RoZXI6IGZ1bmN0aW9uKGV4cGVjdGF0aW9uKSB7CiAgICAgICAgICAgIHJldHVybiBleHBlY3RhdGlvbi5kZXNjcmlwdGlvbjsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICAgIGZ1bmN0aW9uIGhleChjaCkgewogICAgICAgICAgcmV0dXJuIGNoLmNoYXJDb2RlQXQoMCkudG9TdHJpbmcoMTYpLnRvVXBwZXJDYXNlKCk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGxpdGVyYWxFc2NhcGUocykgewogICAgICAgICAgcmV0dXJuIHMucmVwbGFjZSgvXFwvZywgIlxcXFwiKS5yZXBsYWNlKC8iL2csICdcXCInKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGNsYXNzRXNjYXBlKHMpIHsKICAgICAgICAgIHJldHVybiBzLnJlcGxhY2UoL1xcL2csICJcXFxcIikucmVwbGFjZSgvXF0vZywgIlxcXSIpLnJlcGxhY2UoL1xeL2csICJcXF4iKS5yZXBsYWNlKC8tL2csICJcXC0iKS5yZXBsYWNlKC9cMC9nLCAiXFwwIikucmVwbGFjZSgvXHQvZywgIlxcdCIpLnJlcGxhY2UoL1xuL2csICJcXG4iKS5yZXBsYWNlKC9cci9nLCAiXFxyIikucmVwbGFjZSgvW1x4MDAtXHgwRl0vZywgZnVuY3Rpb24oY2gpIHsKICAgICAgICAgICAgcmV0dXJuICJcXHgwIiArIGhleChjaCk7CiAgICAgICAgICB9KS5yZXBsYWNlKC9bXHgxMC1ceDFGXHg3Ri1ceDlGXS9nLCBmdW5jdGlvbihjaCkgewogICAgICAgICAgICByZXR1cm4gIlxceCIgKyBoZXgoY2gpOwogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIGRlc2NyaWJlRXhwZWN0YXRpb24oZXhwZWN0YXRpb24pIHsKICAgICAgICAgIHJldHVybiBERVNDUklCRV9FWFBFQ1RBVElPTl9GTlNbZXhwZWN0YXRpb24udHlwZV0oZXhwZWN0YXRpb24pOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBkZXNjcmliZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9ucy5sZW5ndGggLSAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gZGVzY3JpYmVGb3VuZChmb3VuZDIpIHsKICAgICAgICAgIHJldHVybiBmb3VuZDIgPyAnIicgKyBsaXRlcmFsRXNjYXBlKGZvdW5kMikgKyAnIicgOiAiZW5kIG9mIGlucHV0IjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJFeHBlY3RlZCAiICsgZGVzY3JpYmVFeHBlY3RlZChleHBlY3RlZCkgKyAiIGJ1dCAiICsgZGVzY3JpYmVGb3VuZChmb3VuZCkgKyAiIGZvdW5kLiI7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIG9wdGlvbnMgPSBvcHRpb25zICE9PSB2b2lkIDAgPyBvcHRpb25zIDoge307CiAgICAgICAgdmFyIHBlZyRGQUlMRUQgPSB7fSwgcGVnJHN0YXJ0UnVsZUZ1bmN0aW9ucyA9IHsg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AgICBmdW5jdGlvbiBwZWckbGl0ZXJhbEV4cGVjdGF0aW9uKHRleHQyLCBpZ25vcmVDYXNlKSB7CiAgICAgICAgICByZXR1cm4geyB0eXBlOiAibGl0ZXJhbCIsIHRleHQ6IHRleHQyLCBpZ25vcmVDYXNlIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRjbGFzc0V4cGVjdGF0aW9uKHBhcnRzLCBpbnZlcnRlZCwgaWdub3JlQ2FzZSkgewogICAgICAgICAgcmV0dXJuIHsgdHlwZTogImNsYXNzIiwgcGFydHMsIGludmVydGVkLCBpZ25vcmVDYXNlIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRhbnlFeHBlY3RhdGlvbigpIHsKICAgICAgICAgIHJldHVybiB7IHR5cGU6ICJhbnkiIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRlbmRFeHBlY3RhdGlvbigpIHsKICAgICAgICAgIHJldHVybiB7IHR5cGU6ICJlbmQiIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRvdGhlckV4cGVjdGF0aW9uKGRlc2NyaXB0aW9uKSB7CiAgICAgICAgICByZXR1cm4geyB0eXBlOiAib3RoZXIiLCBkZXNjcmlwdGlvbiB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckY29tcHV0ZVBvc0RldGFpbHMocG9zKSB7CiAgICAgICAgICB2YXIgZGV0YWlscyA9IHBlZyRwb3NEZXRhaWxzQ2FjaGVbcG9zXSwgcDsKICAgICAgICAgIGlmIChkZXRhaWxzKSB7CiAgICAgICAgICAgIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcGVnJEZBSUxFRCAmJiBwZWckY3VyclBvcyA9PT0gaW5wdXQubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gcGVnJHJlc3VsdDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHBlZyRyZXN1bHQgIT09IHBlZyRGQUlMRUQgJiYgcGVnJGN1cnJQb3MgPCBpbnB1dC5sZW5ndGgpIHsKICAgICAgICAgICAgcGVnJGZhaWwocGVnJGVuZEV4cGVjdGF0aW9uKCkpOwogICAgICAgICAgfQogICAgICAgICAgdGhyb3cgcGVnJGJ1aWxkU3RydWN0dXJlZEVycm9yKHBlZyRtYXhGYWlsRXhwZWN0ZWQsIHBlZyRtYXhGYWlsUG9zIDwgaW5wdXQubGVuZ3RoID8gaW5wdXQuY2hhckF0KHBlZyRtYXhGYWlsUG9zKSA6IG51bGwsIHBlZyRtYXhGYWlsUG9zIDwgaW5wdXQubGVuZ3RoID8gcGVnJGNvbXB1dGVMb2NhdGlvbihwZWckbWF4RmFpbFBvcywgcGVnJG1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bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChvcm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VzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgIGlmIChiaW4gPiBtYXhCaW5OdW1iZXIgKyAxKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigidGFiaXggaW5kZXggY29udGFpbnMgdG9vIG1hbnkgYmlucywgcGxlYXNlIHVzZSBhIENTSSBpbmRleCIpOwogICAgICAgICAgfSBlbHNlIGlmIChiaW4gPT09IG1heEJpbk51bWJlciArIDEpIHsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGlmIChjaHVua0NvdW50ID09PSAyKSB7CiAgICAgICAgICAgICAgc3RhdHMgPSB0aGlzLnBhcnNlUHNldWRvQmluKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwTGlu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VmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogICAgICAgICAgaWYgKCFsb3dlc3QgfHwgdnAuY29tcGFyZVRvKGxvd2VzdCkgPCAwKSB7CiAgICAgICAgICAgIGxvd2VzdCA9IHZwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBsb3dlc3QpOwogICAgfQogIH07CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9AZ21vZCt0YWJpeEAxLjUuMTEvbm9kZV9tb2R1bGVzL0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2KSA6IHsKICAgICAgICByZWZJZFRvTmFtZTogW10sCiAgICAgICAgcmVmTmFtZVRvSWQ6IHt9LAogICAgICAgIG1ldGFDaGFyOiBudWxsLAogICAgICAgIGNvbHVtbk51bWJlcnM6IHsgcmVmOiAwLCBzdGFydDogMSwgZW5kOiAyIH0sCiAgICAgICAgY29vcmRpbmF0ZVR5cGU6ICJ6ZXJvLWJhc2VkLWhhbGYtb3BlbiIsCiAgICAgICAgZm9ybWF0OiAiZ2VuZXJpYyIKICAgICAgfTsKICAgICAgY29uc3QgcmVmQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRSgxNiArIGF1eExlbmd0aCk7CiAgICAgIGxldCBmaXJzdERhdGFMaW5lOwogICAgICBsZXQgY3Vyck9mZnNldCA9IDE2ICsgYXV4TGVuZ3RoICsgNDsKICAgICAgY29uc3QgaW5kaWNlcyA9IG5ldyBBcnJheShyZWZDb3VudCkuZmlsbCgwKS5tYXAoKCkgPT4gewogICAgICAgIGNvbnN0IGJpbkNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGJpbkluZGV4ID0ge307CiAgICAgICAgbGV0IHN0YXRzOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgYmluQ291bnQ7IGogKz0gMSkgewogICAgICAgICAgY29uc3QgYmluID0gYnl0ZXMucmVhZFVJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAgICB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Vua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID0gdGhpcy5taW5TaGlmdCArIHRoaXMuZGVwdGggKiAzOwogICAgICBjb25zdCBiaW5zID0gW107CiAgICAgIGZvciAoOyBsIDw9IHRoaXMuZGVwdGg7IHMgLT0gMywgdCArPSBsc2hpZnQoMSwgbCAqIDMpLCBsICs9IDEpIHsKICAgICAgICBjb25zdCBiID0gdCArIHJzaGlmdChiZWcsIHMpOwogICAgICAgIGNvbnN0IGUgPSB0ICsgcnNoaWZ0KGVuZCwgcyk7CiAgICAgICAgaWYgKGUgLSBiICsgYmlucy5sZW5ndGggPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBxdWVyeSAke2JlZ30tJHtlbmR9IGlzIHRvbyBsYXJnZSBmb3IgY3VycmVudCBiaW5uaW5nIHNjaGVtZSAoc2hpZnQgJHt0aGlzLm1pblNoaWZ0fSwgZGVwdGggJHt0aGlzLmRlcHRofSksIHRyeSBhIHNtYWxsZXIgcXVlcnkgb3IgYSBjb2Fyc2VyIGluZGV4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KICAgIH0KICAgIGNoZWNrTGluZShtZXRhZGF0YSwgcmVnaW9uUmVmTmFtZSwgcmVnaW9uU3RhcnQsIHJlZ2lvbkVuZCwgbGluZSkgewogICAgICBjb25zdCB7IGNvbHVtbk51bWJlcnMsIG1ldGFDaGFyLCBjb29yZGluYXRlVHlwZSwgZm9ybWF0IH0gPSBtZXRhZGF0YTsKICAgICAgaWYgKGxpbmUuY2hhckF0KDApID09PSBtZXRhQ2hhcikgewogICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICB9CiAgICAgIGxldCB7IHJlZiwgc3RhcnQsIGVuZCB9ID0gY29sdW1uTnVtYmVyczsKICAgICAgaWYgKCFyZWYpIHsKICAgICAgICByZWYgPSAwOwogICAgICB9CiAgICAgIGlmICghc3RhcnQpIHsKICAgICAgICBzdGFydCA9IDA7CiAgICAgIH0KICAgICAgaWYgKCFlbmQpIHsKICAgICAgICBlbmQgPSAwOwogICAgICB9CiAgICAgIGlmIChmb3JtYXQgPT09ICJWQ0YiKSB7CiAgICAgICAgZW5kID0gODsKICAgICAgfQogICAgICBjb25zdCBtYXhDb2x1bW4gPSBNYXRoLm1heChyZWYsIHN0YXJ0LCBlbmQpOwogICAgICBsZXQgY3VycmVudENvbHVtbk51bWJlciA9IDE7CiAgICAgIGxldCBjdXJyZW50Q29sdW1uU3RhcnQgPSAwOwogICAgICBsZXQgcmVmU2VxID0gIiI7CiAgICAgIGxldCBzdGFydENvb3JkaW5hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3JkaW5hdGUgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBlbmRDb29yZGluYXRlOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmTmFtZSwgb3B0cyk7CiAgICB9CiAgICBhc3luYyBfcmVhZFJlZ2lvbihwb3MsIHNpemUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBiID0gaW1wb3J0X2J1ZmZlcjcuQnVmZmVyLmFsbG9jKHNpemUpOwogICAgICBjb25zdCB7IGJ5dGVzUmVhZCwgYnVmZmVyIH0gPSBhd2FpdCB0aGlzLmZpbGVoYW5kbGUucmVhZChiLCAwLCBzaXplLCBwb3MsIG9wdHMpOwogICAgICByZXR1cm4gYnVmZmVyLnNsaWNlKDAsIGJ5dGVzUmVhZCk7CiAgICB9CiAgICBhc3luYyByZWFkQ2h1bmsoYywgb3B0cyA9IHt9KSB7CiAgICAgIGNvbnN0IGRhdG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BudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBmaWxlOwogICAgICB0aGlzLm9wdGlvbnMgPSBvcHRpb25zOwogICAgICB0aGlzLmNocm9tSW5mbyA9IHNpemVzVG9DaHJvbUluZm8oY2hyb21TaXplcyk7CiAgICAgIHRoaXMudGlsZXNldEluZm8gPSB0aWxlc2V0SW5mb0Zyb21DaHJvbUluZm8odGhpcy5jaHJvbUluZm8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2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlzTnVtZXJpYykgewogICAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLm1hcCgoc3RyKSA9PiBOdW1iZXIoc3RyKSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZlYXR1cmVbbmFtZV0gPSBjb2x1bW5WYWw7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9IGVsc2UgewogICAgICAgIGNvbnN0IGZpZWxkTmFtZXMgPSBbImNocm9tIiwgImNocm9tU3RhcnQiLCAiY2hyb21FbmQiLCAibmFtZSJdOwogICAgICAgIGZlYXR1cmUgPSBPYmplY3QuZnJvbUVudHJpZXMoZmllbGRzLm1hcCgoZiwgaSkgPT4gW2ZpZWxkTmFtZXNbaV0gfHwgImZpZWxkIiArIGksIGZdKSk7CiAgICAgICAgZmVhdHVyZS5jaHJvbVN0YXJ0ID0gK2ZlYXR1cmUuY2hyb21TdGFydDsKICAgICAgICBmZWF0dXJlLmNocm9tRW5kID0gK2ZlYXR1cmUuY2hyb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ZWRSZWNvcmQ7CiAgICB9CiAgICBjb25zdHJ1Y3RCZWRBdXRvU3FsKCkgewogICAgICBjb25zdCBBVVRPX1NRTF9IRUFERVIgPSBgdGFibGUgY3VzdG9tQmVkU2NoZW1hCiJCRUQxMiIKICAgICgKYDsKICAgICAgY29uc3QgQVVUT19TUUxfRk9PVEVSID0gIlxuICAgICkiOwogICAgICBjb25zdCBhdXRvU3FsRmllbGRzID0gdGhpcy4jZ2VuZXJhdGVBdXRvU1FMRmllbGRzKCk7CiAgICAgIHJldHVybiBTdHJpbmcucHJvdG90eXBlLmNvbmNhdChBVVRPX1NRTF9IRUFERVIsIGF1dG9TcWxGaWVsZHMsIEFVVE9fU1FMX0ZPT1RFUik7CiAgICB9CiAgICAjZ2VuZXJhdGVBdXRvU1FMRmllbGRzKCkgewogICAgICBjb25zdCBCRUQxMkZpZWxkcyA9IFsKICAgICAgICBbInN0cmluZyIsICJjaHJvbSJdLAogICAgICAgIFsidWludCIsICJjaHJvbVN0YXJ0Il0sCiAgICAgICAgWyJ1aW50IiwgImNocm9tRW5kIl0sCiAgICAgICAgWyJzdHJpbmciLCAibmFtZSJdLAogICAgICAgIFsiZmxvYXQiLCAic2NvcmUiXSwKICAgICAgICBbImNoYXIiLCAic3RyYW5kIl0sCiAgICAgICAgWyJ1aW50IiwgInRoaWNrU3RhcnQiXSwKICAgICAgICBbInVpbnQiLCAidGhpY2tFbmQiXSwKICAgICAgICBbInN0cmluZyIsICJpdGVtUmdiIl0sCiAgICAgICAgWyJ1aW50IiwgImJsb2NrQ291bnQiXSwKICAgICAgICBbInVpbnRbYmxvY2tDb3VudF0iLCAiYmxvY2tTaXplcyJdLAogICAgICAgIFsidWludFtibG9ja0NvdW50XSIsICJibG9ja1N0YXJ0cyJdCiAgICAgIF07CiAgICAgIGlmICghdGhpcy4jbl9jb2x1bW5zKQogICAgICAgIHRocm93IG5ldyBFcnJvcigiTnVtYmVyIG9mIGNvbHVtbnMgd2FzIG5vdCBhYmxlIHRvI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mFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIHN0YXJ0UG9zLCBlbmRQb3MsIGxpbmVDYWxsYmFjaykudGhlbigoKSA9PiB7CiAgICAgICAgICAgIHJlc29sdmUodGlsZXMpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgYWxsVGlsZXMucHVzaCh0aWxlc1Byb21pc2UpOwogICAgICAgIGlmIChtYXhYIDw9IGNocm9tRW5kKSB7CiAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgY3VyTWluWCA9IGNocm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G9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",qle=typeof window<"u"&&window.Blob&&new Blob([atob(z2e)],{type:"text/javascript;charset=utf-8"});function eng(){const e=qle&&(window.URL||window.webkitURL).createObjectURL(qle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+z2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const tng=200;class P2e{constructor(g,I){rt(this,"dataConfig",{}),rt(this,"uid"),rt(this,"prevRequestTime"),rt(this,"track"),rt(this,"toFetch"),rt(this,"fetchTimeout"),rt(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=JT(new eng).then(async o=>{const a=Object.entries(bI(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()},tng)}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))}}rt(P2e,"config",{type:"bed"});const gng=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:BH,BedDataFetcher:P2e,BigWigDataFetcher:K2e,CsvDataFetcher:D2e,GffDataFetcher:M2e,JsonDataFetcher:F2e,VcfDataFetcher:s2e},Symbol.toStringTag,{value:"Module"})),Ing="gosling-data-row-uid";function ing(e,g){var I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f;const b=[];if(!i7(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,K=Number.MIN_SAFE_INTEGER,F=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((J,P)=>{if(p===1){const ge=y[P]/(W==="mean"?B:1);b.push({[G]:ge,[v]:g.tileX+(P+.5)*B,[w]:g.tileX+P*B,[V]:g.tileX+(P+1)*B,[S]:ge,[X]:ge})}else if(P%p===0)R=H=Y=y[P],K=P,F=P+p;else if(P%p===p-1)b.push({[G]:R/p/(W==="mean"?B:1),[v]:g.tileX+(K+p/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+F*B,[S]:H,[X]:Y});else if(P===Z-1){const ge=Z%p,q=K+ge;b.push({[G]:R/ge/(W==="mean"?B:1),[v]:g.tileX+(K+ge/2)*B,[w]:g.tileX+K*B,[V]:g.tileX+q*B,[S]:H,[X]:Y})}else R+=y[P],H>y[P]&&(H=y[P]),Y{let J=0,P=Number.MIN_SAFE_INTEGER,ge=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 Q=B[G*F+te]/(Y==="mean"?v:1);b.push({[w]:K,[V]:Q,[S]:g.tileX+(te+.5)*v,[X]:g.tileX+te*v,[W]:g.tileX+(te+1)*v,[R]:Q,[H]:Q})}else if(te%p===0)J=q=$=B[G*F+te],P=te,ge=te+p;else if(te%p===p-1)b.push({[w]:K,[V]:Y==="mean"?J/p/v:J,[S]:g.tileX+(P+p/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ge*v,[R]:q,[H]:$});else if(te===G-1){const Q=G%p,ie=P+Q;b.push({[w]:K,[V]:Y==="mean"?J/Q/v:J,[S]:g.tileX+(P+Q/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ie*v,[R]:q,[H]:$})}else{const Q=B[G*F+te];J+=Q,q>Q&&(q=Q),$"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[Ing]=`${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 K=R[Y];if(b.push({...V,[S.name]:+H+v,[X.name]:+K+v,type:"exon"}),Y+1n===e.chromosome))){if(m4e(e))return[I[e.chromosome][0]+1,I[e.chromosome][1]];if(f4e(e))return e.interval;if(p4e(e)){const i=I[e.chromosome][0],[n,C]=e.interval;return[i+n,i+C]}}}function ang(e,g){const I={},i=Hd;e.forEach(n=>{i.forEach(C=>{const r=n.spec()[C];if(!ut(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];ut(r)&&r.type==="genomic"||(n.setChannelDomain(C,I[C],g),n.generateScales())}),n.updateChannelValue()})}const Ang={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,sng=e=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:C6e(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,bI(e).total],initialYDomain:[0,bI(e).total],zoomFixed:!1});class lng{constructor(){rt(this,"assembly"),rt(this,"orientation"),rt(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({...sng(I),uid:g}))),this}setAssembly(g){return this.assembly=g,this.setChromInfoPath(bI(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:ln(),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 n2e(ong,this.spec(),g).state==="success"}setDomain(g,I){return g&&(this.getLastView().initialXDomain=a_(g,this.getAssembly())),I&&(this.getLastView().initialYDomain=a_(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:ln()}-${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]:Qr};if(g==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=Lje(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=Ang}}function pG(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 ung{constructor(g,I,i){rt(this,"id"),rt(this,"theme"),rt(this,"specOriginal"),rt(this,"specComplete"),rt(this,"dataAggregated"),rt(this,"channelScales"),rt(this,"mouseEventModel"),this.id=ln(),this.theme=i??J2e(),this.dataAggregated=I,this.specOriginal=g,this.specComplete=structuredClone(g),this.channelScales={},this.mouseEventModel=new hgg;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=Qig(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=ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"),I==="y"&&(i=ut(g.y)&&g.y.axis!==void 0&&g.y.axis!=="none"),g.layout!=="circular"?ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"&&(g.height-=Qr):I==="x"&&i&&ut(g.x)&&g.x.axis==="top"?g.outerRadius=g.outerRadius-Qr:I==="x"&&i&&ut(g.x)&&g.x.axis==="bottom"&&(g.innerRadius=g.innerRadius+Qr),Hd.forEach(n=>{const C=g[n];ut(C)&&!("zeroBaseline"in C)&&C.type==="quantitative"&&(C.zeroBaseline=!0)}),this.addScaleMaterials(g)}flipRanges(g){ut(g.y)&&g.y.flip&&Array.isArray(g.y.range)&&(g.y.range=g.y.range.reverse())}getGenomicChannelKey(){return r2e(this.spec())}getGenomicChannel(){return D$(this.spec())}setChannelDomain(g,I,i){const n=this.originalSpec()[g];if(!i&&ut(n)&&n.domain!==void 0)return;const C=this.specComplete[g];ut(C)&&(C.domain=I)}updateChannelValue(){if(this.originalSpec().y===void 0){const g=this.spec().y,I=this.getChannelDomainArray("row");g&&N1(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=ut(n)?n.type:N1(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&&pG(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=pG(I.width+l,r,Math.abs(d-h),s))}else A==="width"&&typeof o=="number"&&(I!=null&&I.width)?u=pG(I.width+l,r,o,s):A==="zoomLevel"&&typeof o=="number"&&(I!=null&&I.zoomLevel)&&(u=pG(I.zoomLevel,r,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(g,I){const i=I!==void 0?pI(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 Fje(this,g,I,i);case"point":case"text":return Kje(this,g,I);case"rect":return zje(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}Hd.forEach(n=>{var C,r,o,a;const s=g[n];if(w4e(g,n)&&ut(s)){const A=yT(I,c=>c[i.field]),l=[...A.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:X1(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0)))),u=FG(l.map(d=>Oee(A.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=g.row,u=ut(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=ut(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(ut(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=X1(I.map(m=>+m[s.field])))!=null?o:0,h=(a=FG(I.map(m=>+m[s.field])))!=null?a:0;s.domain=[d,h]}else s.type==="genomic"&&!Kte(s.domain)&&(s.domain=a_(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=cng.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(ut(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"&&ut(g.x)&&ut(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(ut(o)&&ut(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=X1([o.domain[0],a.domain[0]]),A=FG([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();Hd.forEach(I=>{const i=g[I];if(N1(i))this.channelScales[I]=()=>i.value;else if(ut(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]=eh().domain(n).range(C);break;case"color":case"stroke":let r=sbe;Object.keys(NX).includes(C)&&(r=NX[C]),this.channelScales[I]=Xpe(r).domain(n);break}else if(i.type==="nominal")switch(I){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[I]=Zpe().domain(n).range(C);break;case"size":this.channelScales[I]=wX().domain(n).range(C);break;case"color":case"stroke":this.channelScales[I]=wX(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 ut(g.y)&&g.y.axis!=="none"&&g.y.type==="quantitative"&&!!I&&!!i}getChannelDomainArray(g){const I=this.spec()[g];return ut(I)&&Kte(I.domain)?I.domain:void 0}getChannelRangeArray(g){const I=this.spec()[g];return ut(I)&&S4e(I.range)?I.range:void 0}validateSpec(){return C2e(this.originalSpec())}}function Hr(e,g){G7.publish(e,g)}function dng(e,g){G7.subscribe(e,g)}function hng(e){G7.unsubscribe(e)}const ece={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function mng(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const fng={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:mG("light")}},png=(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,K,F,J;const{tileProxy:P}=e.services,{BarTrack:ge}=e.tracks,q=xs({color:"black",size:12}),$=class A_ extends ge{constructor(){var Q,ie,he,ne,be,pe;super(g,I),fg(this,d),fg(this,m),fg(this,b),fg(this,y),fg(this,B),fg(this,v),fg(this,V),fg(this,X),fg(this,R),fg(this,Y),fg(this,F),rt(this,"tileSize"),rt(this,"mRangeBrush"),fg(this,i,void 0),fg(this,n,void 0),rt(this,"firstDraw",!0),rt(this,"gLegend",e.libraries.d3Selection.select(g.svgElement).append("g")),rt(this,"displayedLegends",[]),rt(this,"textGraphics",[]),rt(this,"textsBeingUsed",0),rt(this,"pMouseHover",new e.libraries.PIXI.Graphics),rt(this,"pMouseSelection",new e.libraries.PIXI.Graphics),fg(this,C,0),fg(this,r,0),fg(this,o,!1),fg(this,a,e.libraries.d3Selection.select(g.svgElement).append("g")),fg(this,s,new e.libraries.PIXI.TextStyle(q)),fg(this,A,new e.libraries.PIXI.Graphics),fg(this,l,new e.libraries.PIXI.Text("",q)),rt(this,"prevVisibleAndFetchedTiles"),rt(this,"resolvedTracks"),rt(this,"hideMousePosition"),g.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(Be=>({...Be,_renderingId:ln()})):this.options.spec._renderingId=ln(),this.fetchedTiles={},this.tileSize=(ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024;const{valid:ve,errorMessages:We}=C2e(this.options.spec);ve||console.warn("The specification of the following track is invalid",We,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new agg(Dt(this,a),e.libraries,(he=this.options.spec.style)==null?void 0:he.brush),this.mRangeBrush.on("brush",SI(this,R,H).bind(this)),this.pMask.on("mousedown",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,b,p).call(this,Je,Pe,Be.data.originalEvent.altKey)}),this.pMask.on("mouseup",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);SI(this,B,G).call(this,Je,Pe)}),this.pMask.on("mousemove",Be=>{const{x:Je}=Be.data.getLocalPosition(this.pMain);SI(this,y,Z).call(this,Je)}),this.pMask.on("mouseout",SI(this,v,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(ne=this.options)!=null&&ne.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=e.utils.showMousePosition(this,nC(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),Dt(this,l).anchor.x=1,Dt(this,l).anchor.y=1,this.pLabel.addChild(Dt(this,A)),this.pLabel.addChild(Dt(this,l)),e.libraries.PIXI.GRAPHICS_CURVES.adaptive=(pe=(be=this.options.spec.style)==null?void 0:be.enableSmoothPath)!=null?pe:!1,e.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(e.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,e.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var Q,ie;this.clearMouseEventData(),this.textsBeingUsed=0,(Q=this.pMouseHover)==null||Q.clear();const he=()=>{const ne=this.dataFetcher instanceof BH;this.processAllTiles(ne),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};PV(this.dataFetcher)&&!abe(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,he):he(),(ie=this.mRangeBrush)==null||ie.drawBrush(!0),this.firstDraw&&(SI(this,F,J).call(this),this.firstDraw=!1)}initTile(Q){this.drawTile(Q)}updateTile(){}renderTile(){}drawTile(Q){var ie,he;Q.drawnAtScale=this._xScale.copy();const ne=Dt(this,n)[Q.tileId];ne&&((ie=Q.graphics)==null||ie.clear(),(he=Q.graphics)==null||he.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],ne.goslingModels.forEach(be=>{const pe=this.dimensions[0],ve=this._xScale.invert(pe)-this._xScale.invert(0);be.trackVisibility({zoomLevel:ve})&&(A4e(e,this,Q,be,this.options.theme),a4e(e,this,Q,be),s4e(e,this,Q,be,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 ie,he;return(he=(ie=Dt(this,n)[Q.tileId])==null?void 0:ie.goslingModels)!=null?he:[]})}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,ie){const he=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(he?[Q(this._xScale.invert(he[0])),Q(this._xScale.invert(he[1]))]:null),this.xScale(Q),this.yScale(ie),this.refreshTiles(),this.draw(),this.forceDraw();const ne=Q.domain().map(be=>Uu(be,Dt(this,i),!0));Hr("location",{id:g.viewUid,genomicRange:ne})}setMask(Q,ie){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[he,ne]=this.position,[be,pe]=this.dimensions,ve=he+be/2,We=ne+pe/2,Be=this.options.spec.outerRadius;this.pMask.drawCircle(ve,We,Be)}else this.pMask.drawRect(Q[0],Q[1],ie[0],ie[1]);this.pMask.endFill()}processAllTiles(Q=!1){var ie,he;this.tileSize=(he=(ie=this.tilesetInfo)==null?void 0:ie.tile_size)!=null?he:1024;const ne=this.visibleAndFetchedTiles();ne.forEach(ve=>SI(this,m,f).call(this,ve,Q)),this.combineAllTilesIfNeeded();const be=ne.flatMap(ve=>this.transformDataAndCreateModels(ve));ang(be);const pe=[].concat(...be.map(ve=>ve.data()));pe.length!==0&&this.options.siblingIds.forEach(ve=>Hr("rawData",{id:ve,data:pe}))}async updateTileAsync(Q,ie){if(!this.tilesetInfo)return;const he=this.visibleAndFetchedTiles(),ne=await Q.getTabularData(Object.values(he).map(pe=>pe.remoteId)),be=this.tilesetInfo;he.forEach((pe,ve)=>{if(ve===0){const[We]=e.utils.trackUtils.calculate1DVisibleTiles(be,this._xScale);pe.tileData.zoomLevel=We[0],pe.tileData.tilePos=[We[1],We[1]],pe.tileData.tabularData=ne}else pe.tileData.tabularData=[]}),ie()}calculateVisibleTiles(){var Q,ie,he,ne,be;if(this.tilesetInfo)if(PV(this.dataFetcher)){const pe=e.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),ve=(ie=(Q=this.tilesetInfo.max_tile_width)!=null?Q:this.dataFetcher.MAX_TILE_WIDTH)!=null?ie:Number.MAX_SAFE_INTEGER;for(const We of pe){const{tileWidth:Be}=this.getTilePosAndDimensions(We[0],[We[1],We[1]]);if(this.forceDraw(),Be>ve)return}this.setVisibleTiles(pe)}else{if(!this.tilesetInfo)return;const pe=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const ve=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe),We=P.calculateTilesFromResolution(ve[pe],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Be;nC(this.getResolvedTracks()[0])&&(Be=P.calculateTilesFromResolution(ve[pe],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Je=SI(he=A_,c,u).call(he,We,Be,pe);this.setVisibleTiles(Je)}else{const ve=P.calculateTiles(pe,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let We;nC(this.getResolvedTracks()[0])&&(We=P.calculateTiles(pe,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(ne=this.tilesetInfo.max_width1)!=null?ne:this.tilesetInfo.max_width));const Be=SI(be=A_,c,u).call(be,ve,We,pe);this.setVisibleTiles(Be)}}}getTilePosAndDimensions(Q,ie){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const ne=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe)[Q],[be,pe]=ie,ve=ne*Dt(this,d,h),We=ve,Be=ve*be,Je=We*pe;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}else{const[he,ne]=ie,be=this.tilesetInfo.min_pos[0],pe=this.tilesetInfo.min_pos[1],ve=this.tilesetInfo.max_width/2**Q,We=this.tilesetInfo.max_width/2**Q,Be=be+he*ve,Je=pe+ne*We;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}}getIndicesOfVisibleDataInTile(Q){const ie=this._xScale.range();if(!this.tilesetInfo||!Q.tileData.tilePos||!("dense"in Q.tileData))return[0,0];const{tileX:he,tileWidth:ne}=this.getTilePosAndDimensions(Q.tileData.zoomLevel,Q.tileData.tilePos),be=e.libraries.d3Scale.scaleLinear().domain([0,Dt(this,d,h)]).range([he,he+ne]),pe=Math.max(0,Math.round(be.invert(this._xScale.invert(ie[0])))),ve=Math.min(Q.tileData.dense.length,Math.round(be.invert(this._xScale.invert(ie[1]))));return[pe,ve]}receivedTiles(Q){super.receivedTiles(Q),PV(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),PV(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var Q,ie,he;if(!this.shouldCombineTiles())return;const ne=this.visibleAndFetchedTiles();if(!ne||ne.length<=1)return;this.tileSize=((ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?ie:1024)*ne.length;let be=[];ne.forEach((ve,We)=>{const Be=Dt(this,n)[ve.tileId];Be&&(be=[...be,...Be.tabularData],Be.skipRendering=We!==0)});const pe=Dt(this,n)[ne[0].tileId];pe.tabularData=be,(he=pe.tabularData[0])!=null&&he.uid&&(pe.tabularData=nje(pe.tabularData,"uid"))}shouldCombineTiles(){const Q=l4e(this.options.spec,"displace"),ie=()=>{const ne=this.visibleAndFetchedTiles();return ne.length>=1&&"dense"in ne[0].tileData},he=this.dataFetcher instanceof BH;return Q&&!ie()&&!he}getResolvedTracks(Q=!1){if(Q||!this.resolvedTracks){const ie=structuredClone(this.options.spec),he=T0(ie).filter(ne=>ne.mark!=="brush");he.forEach(ne=>{"values"in ne.data&&(ne.data.values=[])}),this.resolvedTracks=he}return this.resolvedTracks}transformDataAndCreateModels(Q){const ie=Dt(this,n)[Q.tileId];return!ie||ie.skipRendering?[]:(ie.goslingModels=[],this.getResolvedTracks().forEach(ne=>{var be;let pe=Array.from(ie.tabularData);(be=ne.dataTransform)==null||be.forEach(_e=>{switch(_e.type){case"filter":pe=x2e(_e,pe);break;case"concat":pe=Eig(_e,pe);break;case"replace":pe=Mig(_e,pe);break;case"log":pe=zig(_e,pe);break;case"exonSplit":pe=Lig(_e,pe,ne.assembly);break;case"genomicLength":pe=Pig(_e,pe);break;case"svType":pe=Jig(_e,pe);break;case"coverage":pe=Oig(_e,pe,this._xScale.copy());break;case"subjson":pe=Uig(_e,pe);break;case"displace":pe=_ig(_e,pe,this._xScale.copy());break}});try{if(PubSub){const gt=pe.length;PubSub.publish("data-preview",{id:g.viewUid,dataConfig:JSON.stringify({data:ne.data}),data:100>gt?pe:e7(pe,100)})}}catch{}const[ve,We]=this.dimensions,Be=kX(ne)?Qr:0,[Je,Pe]=[ve,We+Be],De=Math.min(Je,Pe)/Math.min(ne.width,ne.height);ne.innerRadius&&(ne.innerRadius=ne.innerRadius*De),ne.outerRadius&&(ne.outerRadius=ne.outerRadius*De),ne.width=Je,ne.height=Pe;const Qe=new ung(ne,pe,this.options.theme);ie.goslingModels.push(Qe)}),ie.goslingModels)}getMouseOverHtml(Q,ie){var he,ne,be,pe,ve;if(SI(this,X,W).call(this,"trackMouseOver",Q,ie),Dt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const We=Uu(Math.floor(this._xScale.invert(Q)),Dt(this,i)),Be=SI(this,V,S).call(this,Q,ie);if(Be.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Be.length!==0){const Je=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents;if(!!Je||Ym(Je)&&!!Je.mouseOver){const _e=this.pMouseHover;((be=(ne=this.options.spec.style)==null?void 0:ne.mouseOver)==null?void 0:be.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),SI(this,Y,K).call(this,_e,Be,Object.assign({},ece,(pe=this.options.spec.style)==null?void 0:pe.mouseOver)),Hr("mouseOver",{id:g.viewUid,genomicPosition:We,data:Be.map(gt=>gt.value)})}const Qe=(ve=this.visibleAndFetchedGoslingModels().find(_e=>{var gt;return _e.spec().tooltip&&((gt=_e.spec().tooltip)==null?void 0:gt.length)!==0}))==null?void 0:ve.spec().tooltip;if(Qe){let _e=Qe.map(gt=>{var lt;const tt=Be[0].value[gt.field];let Xe=tt;if(gt.type==="quantitative"&>.format)Xe=e.libraries.d3Format.format(gt.format)(+tt);else if(gt.type==="genomic"){const{chromosome:ae,position:ye}=Uu(+tt,Dt(this,i));Xe=`${ae}:${e.libraries.d3Format.format(",")(ye)}`}return`${(lt=gt.alt)!=null?lt:gt.field}${Xe}`}).join("");return _e=`${_e}
`,Be.length>1&&(_e+=`
${Be.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(" ")}`;Dt(this,l).text=ie,Dt(this,l).x=this.position[0]+this.dimensions[0]-6/2,Dt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const he=e.libraries.PIXI.TextMetrics.measureText(ie,Dt(this,s)),{width:ne,height:be}=he;Dt(this,A).clear(),Dt(this,A).lineStyle(1,pt("grey"),1,.5),Dt(this,A).beginFill(pt("white"),.8),Dt(this,A).drawRect(this.position[0]+this.dimensions[0]-ne-6-1,this.position[1]+this.dimensions[1]-be-6-1,ne+6,be+6),Dt(this,l).visible=!0,Dt(this,A).visible=!0}else Dt(this,l).visible=!1,Dt(this,A).visible=!1}updateScaleOffsetFromOriginalSpec(Q,ie,he){this.getResolvedTracks().map(ne=>{if(ne._renderingId===Q){const be=ne[he];ut(be)&&(be.scaleOffset=ie)}})}shareScaleOffsetAcrossTracksAndTiles(Q,ie){this.visibleAndFetchedGoslingModels().forEach(ne=>{const be=ne.spec()[ie];ut(be)&&(be.scaleOffset=Q);const pe=ne.originalSpec()[ie];ut(pe)&&(pe.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(te,Q,ie){if(!Q)return te.map(ne=>[ie,ne]);const he=[];return te.forEach(ne=>Q.forEach(be=>he.push([ie,ne,be]))),he},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,Q=!1){if(Dt(this,n)[te.tileId]&&!Q||!te.tileData.tilePos)return;const ie=mng(),he=this.getResolvedTracks();if(he.length===0)return[];const ne=he[0];if("tabularData"in te.tileData)ie.tabularData=te.tileData.tabularData;else{const{tileX:be,tileY:pe,tileWidth:ve,tileHeight:We}=this.getTilePosAndDimensions(te.tileData.zoomLevel,te.tileData.tilePos),Be="length"in te.tileData?Array.from(te.tileData):[],Je=Object.assign({},te.tileData,{sparse:Be,tileX:be,tileY:pe,tileWidth:ve,tileHeight:We,tileSize:this.tileSize}),Pe=ing(ne,Je);Pe&&(ie.tabularData=Pe)}Dt(this,n)[te.tileId]=ie},b=new WeakSet,p=function(te,Q,ie){var he;WC(this,C,te),WC(this,r,Q);const ne=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents,be=!!ne||Ym(ne)&&!!ne.rangeSelect;WC(this,o,be&&ie),this.pMouseHover.clear()},y=new WeakSet,Z=function(te){this.options.spec.layout!=="circular"&&Dt(this,o)&&this.mRangeBrush.updateRange([te,Dt(this,C)]).drawBrush().visible().disable()},B=new WeakSet,G=function(te,Q){var ie;SI(this,X,W).call(this,"trackClick",te,Q);const he=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,ne=!!he||Ym(he)&&!!he.click,be=Math.sqrt((Dt(this,C)-te)**2+(Dt(this,r)-Q)**2)>1;if(!Dt(this,o)&&!be?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),WC(this,o,!1),!!this.tilesetInfo&&!be&&ne){const pe=Uu(Math.floor(this._xScale.invert(te)),Dt(this,i)),ve=SI(this,V,S).call(this,te,Q);ve.length!==0&&this.options.siblingIds.forEach(We=>Hr("click",{id:We,genomicPosition:pe,data:ve.map(Be=>Be.value)}))}},v=new WeakSet,w=function(){WC(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},V=new WeakSet,S=function(te,Q){var ie;const he=this.visibleAndFetchedGoslingModels(),ne=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,be=Ym(ne)&&ne.enableMouseOverOnMultipleMarks,pe=Ym(ne)&&ne.groupMarksByField,ve=he.map(We=>We.getMouseEventModel().findAll(te,Q,!0)).flat();if(be||ve.splice(1,ve.length-1),ve.length!==0&&pe){const We=Array.from(ve);he.forEach(Be=>{const Je=Be.getMouseEventModel().getSiblings(We,pe);ve.push(...Je)})}return ve},X=new WeakSet,W=function(te,Q,ie){const[he,ne]=this.position,[be,pe]=this.dimensions;if(this.options.spec.layout==="circular"){const ve=he+be/2,We=ne+pe/2,Be=this.options.spec.innerRadius,Je=this.options.spec.outerRadius,Pe=this.options.spec.startAngle,De=this.options.spec.endAngle;Agg([Q,ie],[be/2,pe/2],[Be,Je],[Pe,De])&&Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe,cx:ve,cy:We,innerRadius:Be,outerRadius:Je,startAngle:Pe,endAngle:De}})}else Hr(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe}})},R=new WeakSet,H=function(te,Q=!1){var ie,he,ne,be;if(this.pMouseSelection.clear(),te===null){Q||Hr("rangeSelect",{id:g.viewUid,genomicRange:null,data:[]});return}const pe=this.visibleAndFetchedGoslingModels(),[ve,We]=te;let Be=pe.map(De=>De.getMouseEventModel().findAllWithinRange(ve,We,!0)).flat();const Je=(ie=this.options.spec.experimental)==null?void 0:ie.mouseEvents,Pe=Ym(Je)&&Je.groupMarksByField;if(Be.length!==0&&Pe&&pe.forEach(De=>{const Qe=De.getMouseEventModel().getSiblings(Be,Pe),_e=Array.from(new Set(Qe.map(gt=>gt.value[Pe])));Be=Be.filter(gt=>_e.indexOf(gt.value[Pe])===-1)}),Be.length!==0){const De=this.pMouseSelection;((ne=(he=this.options.spec.style)==null?void 0:he.select)==null?void 0:ne.arrange)!=="behind"&&(this.pMain.removeChild(De),this.pMain.addChild(De)),SI(this,Y,K).call(this,De,Be,Object.assign({},ece,(be=this.options.spec.style)==null?void 0:be.select))}if(!Q){const De=[Uu(Math.floor(this._xScale.invert(ve)),Dt(this,i)),Uu(Math.floor(this._xScale.invert(We)),Dt(this,i))];Hr("rangeSelect",{id:g.viewUid,genomicRange:De,data:Be.map(Qe=>Qe.value)})}this.forceDraw()},Y=new WeakSet,K=function(te,Q,ie){te.lineStyle(ie.strokeWidth,pt(ie.stroke),ie.strokeOpacity,.5),te.beginFill(pt(ie.color),ie.color==="none"?0:ie.opacity),Q.forEach(he=>{if(he.type==="point"){const[ne,be,pe=3]=he.polygon;te.drawCircle(ne,be,pe)}else he.type==="line"?(te.moveTo(he.polygon[0],he.polygon[1]),Uje(he.polygon).map(ne=>te.lineTo(ne[0],ne[1]))):te.drawPolygon(he.polygon)})},F=new WeakSet,J=function(){Hr("onNewTrack",{id:g.viewUid})},fg($,c);let j=$;return new j},C1=F$(fng,png),bng={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},yng=(e,g,I)=>{var i,n,C,r;const{SVGTrack:o}=e.tracks;class a extends o{constructor(){super(g,I),fg(this,i),fg(this,C),SI(this,i,n).call(this),SI(this,C,r).call(this),Hr("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},tce=F$(bng,yng);let gce=!1;function Zng(){if(!gce){Vu({name:"GoslingTrack",track:C1,config:C1.config}),Vu({name:"Gosling2DTrack",track:C1,config:{...C1.config,type:"gosling-2d-track",orientation:"2d"}}),Vu({name:"AxisTrack",track:ale,config:ale.config}),Vu({name:"TextTrack",track:b3,config:b3.config}),Vu({name:"BrushTrack",track:e_,config:e_.config}),Vu({name:"DummyTrack",track:tce,config:tce.config});for(const e of Object.values(gng)){const{config:g}=e;Vu({dataFetcher:e,config:g},{pluginType:"dataFetcher"})}gce=!0}}function O2e(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:vng({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 s_(e,g,I=0,i=0,n=!0){let C=0,r=0,o=!0,a=!1;pb(e,c=>{a=!0,c.layout!=="circular"&&(o=!1)});let s=!0;Ube(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)=>{ice([u])===1&&(u.width+=Qr),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)=>{ice([u])===1&&(u.height+=Qr);const m=T0(u);m.length>0&&nC(m[0])&&Gng([u])===1&&(C+=Qr),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:T1;e.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=s_(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:T1,Z=s_(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:T1,h=Tje,m=e.centerRadius!==void 0?e.centerRadius:ube,f=C/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,B;if(VS(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&&ui(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 ice(e){return e.filter(g=>kX(g)).length}function Gng(e){return e.filter(g=>R4e(g)).length}const vng=(e,g,I)=>JSON.parse(JSON.stringify({mark:"header",width:e.width,height:e.height,title:g,subtitle:I}));function Bng(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 Sng(e,g,I,i,n,C,r){var o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z;if(VS(g))return e.addDefaultView(g.id).setDummyTrack(g).setLayout(i),e;const B=T0(g),G=B[0],v=(o=G.id)!=null?o:ln();G.id||(G.id=v),B.forEach(V=>{V.id&&C.addMapping(V.id,v)});const w=G.assembly;if(Yte(G.data)){let V,S;if(i7(G.data)){const ge=Bng(G.data.url);V=ge.server,S=ge.tilesetUid}const X=D$(G),W=r2e(G),H=(W==="x"||W==="xe")&&ut(X)?X.domain:void 0,Y=nC(G)&&ut(G.y)?G.y.domain:void 0,K=I.width-(G.layout!=="circular"&&G.orientation==="vertical"&&kX(G)?Qr:0),F=I.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&kX(G)?Qr:0),J={uid:`${v}-track`,type:nC(G)?"gosling-2d-track":"gosling-track",server:V,tilesetUid:S,width:K,height:F,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&&Yte(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 ge=te=>{const Q=G[te];return Q&&ut(Q)?Q.field:void 0},q={x:ge("x"),xe:ge("xe"),x1:ge("x1"),x1e:ge("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])||{};J.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(Z4e(G)){J.type="heatmap";const ge=ut(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";J.options.colorRange=c4e(ge),J.options.trackBorderWidth=(s=(a=G.style)==null?void 0:a.outlineWidth)!=null?s:n.track.outlineWidth,J.options.trackBorderColor=(l=(A=G.style)==null?void 0:A.outline)!=null?l:n.track.outline,J.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",J.options.colorbarPosition=(d=G.color)!=null&&d.legend?J.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?e.setViewOrientation(G.orientation).addTrackToCombined(J):e.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(v,w).setDomain(H,Y??H).adjustDomain(G.orientation,K,F).setMainTrack(J).addTrackSourceServers(V).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(i);const P=(ge,q="horizontal",$,j)=>q==="horizontal"?ge==="x"&&$<=200||ge==="y"&&j<=200?"narrower":ge==="x"&&$<=400||ge==="y"&&j<=400?"narrow":"regular":ge==="x"&&j<=200||ge==="y"&&$<=200?"narrower":ge==="x"&&j<=400||ge==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(ge=>{const q=G[ge];if(ut(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=P(ge,g.orientation,I.width,I.height);e.setAxisTrack(q.axis,$,{id:`${v}-${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})}}),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)+TX,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:C3.fontFamily),typeof G.subtitle=="string"&&e.setTextTrack(I.width,((p=n.root.subtitleFontSize)!=null?p:14)+TX,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:C3.fontFamily));return e}function wng(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;T0(p).forEach(Z=>{Hd.forEach(B=>{var G,v,w,V;const S=Z[B];if(ut(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 Vng{constructor(){fg(this,jA,{})}addMapping(g,I){Dt(this,jA)[g]&&Dt(this,jA)[g]!==I&&console.warn(`The track ID ${g} already exists but overwriting with a different ID.`),Dt(this,jA)[g]=I}getTable(){return Dt(this,jA)}getGoslingIds(){return Object.keys(Dt(this,jA))}getHiGlassId(g){return Dt(this,jA)[g]}getSiblingGoslingIds(g){return Object.entries(Dt(this,jA)).filter(([,I])=>I===g).map(([I])=>I)}}jA=new WeakMap;function Rng(e){const g=new Set;return e.id&&g.add(e.id),pb(e,I=>{("views"in I||"tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Wng(e){const g=new Set;return pb(e,I=>{!("views"in I)&&!("tracks"in I)&&I.id&&g.add(I.id)}),Array.from(g)}function Xng(e,g){let I;return e.id===g&&(I=e),pb(e,i=>{i.id===g&&(I=i)}),I}function Hng(e,g){return Rng(e).map(I=>{const i=Xng(e,I),n=Wng(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;Sng(C,u,d,h,i,r,n)});const o=wng(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"||VS(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=Hng(e,s),l=[...s.map(c=>({...c,type:"track"})),...A.map(c=>({...c,type:"view"}))];I(C.spec(),O2e(g),e,l,r.getTable())}function _2e(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(Nng(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=_2e(l,g,I,i,n)||C}),C}function Nng(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&&pG((a==="container"?I:g)[C],r,o)===1}),i}function kng(e,g,I,i,n,C){var r,o;const a=JSON.parse(JSON.stringify(e));i6e(a),Mtg(a,I),h3(a);const s=Ice(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;_2e(a,d,h,m,f)&&(h3(a),A=Ice(a,i).trackInfos),Hr("specProcessed",{id:a.id,spec:a}),Tng(a,A,g,i,C)}Zng();const L2e=U.forwardRef((e,g)=>{var I;const[i,n]=U.useState((I=e.id)!=null?I:ln());U.useEffect(()=>{var u;n((u=e.id)!=null?u:ln())},[e.id]);const C=e.viewConfig||{},r=!1,o=U.useMemo(()=>N.createElement(uy,{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)))});L2e.displayName="HiGlassComponentWrapper";function Yng(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=Ys.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:dng,unsubscribe:hng,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=A(d))==null?void 0:b.spec.assembly,Z=u7.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,bI(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 s5e(()=>import("./jspdf.es.min-5cd5e647.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{I7(I)&&g.forEach(i=>{delete I[i]})})}const Kng=(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)}})},xng=300,U2e=U.forwardRef((e,g)=>{var I,i,n;const[C,r]=U.useState(),[o,a]=U.useState({width:200,height:200}),s=U.useRef(),A=U.useRef(),l=U.useRef(),c=U.useRef([]),u=U.useRef({}),d=U.useRef(null),h=J2e(e.theme||"light"),m=(I=e.id)!=null?I:ln(),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=>{Hr("onNewView",{id:V.id})})};U.useImperativeHandle(g,()=>{const Z=Cce(d),B=Cce(c);return{api:Yng(Z,C,B,h,u.current),hgApi:Z}},[C,h]);const b=U.useCallback(()=>{if(e.spec){if(Ftg(e.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}kng(e.spec,(B,G,v,w,V)=>{var S,X;if(l.current&&abe(nce(l.current,["linkingId"]),nce(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;Kng(B,(R=d.current)==null?void 0:R.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(B)},xng):r(B),f(w),l.current=v,c.current=w,u.current=V},[...Etg],h,{containerSize:s.current,containerParentSize:A.current},e.urlToFetchOptions)}},[e.spec,h]);U.useEffect(()=>{var Z;if(!((Z=e.spec)!=null&&Z.responsiveSize))return;const B=document.getElementById(m);if(!B)return;const G=new jse.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 jse.ResizeSensor(v,V=>{(!A.current||A.current.height!==V.height||A.current.width!==V.width)&&(A.current=V,b())});return()=>{G.detach(),w.detach()}}),U.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 U.useMemo(()=>{var Z,B,G;return N.createElement(L2e,{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])});U2e.displayName="GoslingComponent";function Cce(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 rce=jI;rce.createRoot,rce.hydrateRoot;const Dng=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function Fng(e){return typeof e=="object"&&e!==null}function Eng(e){return"alignment"in e&&e.alignment==="overlay"}function Mng(e){return"_overlay"in e}function zng(e){return e!==null&&typeof e=="object"&&"value"in e}function Png(e){return Fng(e)&&!("value"in e)}function oce(e,g){return g in e}function Ec(e){return e.length===1?e[0]:e.slice(0,-1).join(", ")+" and "+e.slice(-1)}function bG(e){return e[0].toUpperCase()+e.slice(1)}const _n=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"]]),LA=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function Jng(e){return e.includes("chr")&&(e=e.replace("chr","")),e}function Q2e(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 Ong(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",j2e(e,g,i,I),$ng(I);const n={description:"",nTracks:I.nTracks,parentValues:i,counter:I};return g.composition=n,g.alt="",g.longDescription="",g}function j2e(e,g,I,i){if("tracks"in e){const n=ace(e,I);if(e.tracks.length>1)if(Eng(e)){const C=e;g.tracks[i.nTracks]=Ung(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]=l_(r,n,i),i.nTracks>0&&(i.allPositions=[...i.allPositions,[i.rowViews,i.colViews]]),i.nTracks++}else{if(Mng(e.tracks[0])){const C=e.tracks[0];g.tracks[i.nTracks]=Lng(C,I,i)}else{const C=e.tracks[0];g.tracks[i.nTracks]=l_(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=ace(r,I);j2e(r,g,a,i)}),I.arrangement==="vertical"||I.arrangement==="parallel"?i.rowViews=n:i.colViews=C}}function ace(e,g){const I=JSON.parse(JSON.stringify(g));return oce(e,"arrangement")&&(I.arrangement=e.arrangement),oce(e,"layout")&&(I.layout=e.layout),I}function l_(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=q2e(e);const o=$2e(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=Q2e(i),i.description="",i}function _ng(e,g,I){let i={...e,...e._overlay[0]};return delete i._overlay,delete i.overlayOnPreviousTrack,i=i,l_(i,g,I)}function Lng(e,g,I){return _ng(e,g,I)}function Ung(e,g,I){let i=Qbe(e);return i=mbe(i),Qng(e,i,g,I)}function Qng(e,g,I,i){const n={};n.alttype="ov-data";const C={trackNumber:i.nTracks,rowNumber:i.rowViews,colNumber:i.colViews},r=[],o=[];for(const s of g){const A=s;let l;A.id!=="unknown"?l=A.id:l="",r.push(l),o.push(jng(A,I))}const a={description:"",details:C};return n.position=a,n.title=e.title,n.appearance={details:{layout:"linear"}},n.tracks=o,n.uids=r,n.description="",n}function jng(e,g,I){const i={},n={};n.assembly=e.assembly,n.layout=g.layout,n.overlaid=!1,n.mark=e.mark,n.encodings=q2e(e);const C=$2e(e.data,n.encodings),r={data:e.data,fields:C},o={description:"",details:n},a={description:"",details:r};return i.appearance=o,i.data=a,i.charttype=Q2e(i),i.description="",i}function $2e(e,g){const I={};return g.encodingDeepGenomic.length>0&&(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 q2e(e){const g=[],I=[],i=[],n=[];return Dng.forEach(r=>{const o=e[r];Png(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}):zng(o)&&n.push({name:r,description:"",details:o})}),{encodingDeepGenomic:g,encodingDeepQuantitative:I,encodingDeepNominal:i,encodingValue:n}}function $ng(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 qng(e){eCg(e),ICg(e)}function eCg(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?tCg(e):gCg(e)}function tCg(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=g,e.tracks[1].position.description=I,e.composition.description=i}function gCg(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) "+Ec(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 ICg(e){for(const g in e.tracks){const I=e.tracks[g];if(I.alttype==="single"){let i="";I.charttype?i=i.concat(bG(I.charttype)+"."):i=i.concat("Chart with "+_n.get(I.appearance.details.mark)+".");const n=iCg(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 iCg(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 "+_n.get(g)+" on the "+Ec(a)+"-axes.");for(const l of a)r.push([l,"The "+l+" of the "+_n.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 "+_n.get(g)+"."),r.push(["y","The y-axis shows the expression with"+_n.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 "+_n.get(g)+" shows the expression values."])):(i=i.concat("The height of the expression values is shown with the "+a[0]+"-axis."),r.push([LA.get(a[0]),"The "+LA.get(a[0])+" of the "+_n.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=>LA.get(c));n=n.concat(" The categories are also shown with the "+Ec(l)+" of the "+_n.get(g)+"."),r.push(["row","The chart is stratified by rows for the categories."]);for(const c of l)r.push([LA.get(c),"The "+c+" of the "+_n.get(g)+" show the different categories."])}else{const l=s.map(c=>LA.get(c));n=n.concat("The categories are shown with the "+Ec(l)+" of the "+_n.get(g)+".");for(const c of s)r.push([LA.get(c),"The "+c+" of the "+_n.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 "+LA.get(s[0])+" of the "+_n.get(g)+" indicates the different categories."),r.push([LA.get(s[0]),"The "+LA.get(s[0])+" of the "+_n.get(g)+" show the different categories."])));for(let l=0;lNv(n,I)))}.`):i=i.concat(` The ${g} value is shown at ${e.length} different genomic positions, the first being ${Nv(e[0],I)}.`),i}function c_(e,g){const I=Uu(e,g);return[Jng(I.chromosome),I.position]}function Nv(e,g){const I=c_(e,g);return I[0]==="unknown"?`absolute position ${I[1]} (on the unmapped part of the genome)`:`chromosome ${I[0]} position ${I[1]}`}function eHe(e,g,I){const i=c_(e,I),n=c_(g,I);return i[0]==="unknown"&&n[0]=="unknown"?` The genomic range is shown from from absolute position ${i[1]} to ${n[1]} on an unmapped part of the genome.`:n[0]==="unknown"?(i[0]==="chr1"||i[0]===1)&&i[1]===0?" The full genome is shown.":i[0]==="chrX"||i[0]==="X"?` The genomic range shown is chromomosome X (from position ${i[1]}), Y and an unmapped part of the genome at the end.`:i[0]==="chrY"||i[0]==="Y"?` The genomic range shown is chromomosome Y (from position ${i[1]}) and an unmapped part of the genome at the end.`:` The genomic range is shown from chromosome ${i[0]} to chromosome 22 and the X and Y chromosomes, as well as an unmapped part of the genome at the end.`:i===n?` The genomic range is shown from position ${i[1]} to position ${n[1]} on chromosome ${i[0]}.`:` The genomic range is shown from chromosome ${i[0]} position ${i[1]} to chromosome ${n[0]} position ${n[1]}.`}function tHe(e){var g,I,i,n,C,r,o,a,s,A,l,c,u,d,h,m,f,b;if((e.alttype==="single"||e.alttype==="ov-mark")&&e.data.details.dataStatistics){let p="";const y=e.appearance.details.assembly;if(((g=e.data.details.dataStatistics)==null?void 0:g.genomicMin)!==void 0&&((I=e.data.details.dataStatistics)==null?void 0:I.genomicMax)!==void 0){const Z=eHe(e.data.details.dataStatistics.genomicMin,e.data.details.dataStatistics.genomicMax,y),B=Nv((i=e.data.details.dataStatistics)==null?void 0:i.genomicMin,y),G=Nv((n=e.data.details.dataStatistics)==null?void 0:n.genomicMax,y);e.data.details.dataStatistics.genomicDescList=[["Minimum",B],["Maximum",G]],p=p.concat(Z)}if(((C=e.data.details.dataStatistics)==null?void 0:C.valueMin)!==void 0&&((r=e.data.details.dataStatistics)==null?void 0:r.valueMax)!==void 0){const Z=(o=e.data.details.dataStatistics)==null?void 0:o.valueMin,B=(a=e.data.details.dataStatistics)==null?void 0:a.valueMax;if(p=p.concat(` The expression values range from ${Z} to ${B}.`),(s=e.data.details.dataStatistics)!=null&&s.valueMaxGenomic&&((A=e.data.details.dataStatistics)!=null&&A.valueMinGenomic)){const G=Ace((l=e.data.details.dataStatistics)==null?void 0:l.valueMinGenomic,"minimum",y),v=Ace((c=e.data.details.dataStatistics)==null?void 0:c.valueMaxGenomic,"maximum",y);p=p.concat(v,G),e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}. ${G}`],["Maximum",`${B}. ${v}`]]}else e.data.details.dataStatistics.valueDescList=[["Minimum",`${Z}`],["Maximum",`${B}`]]}(u=e.data.details.dataStatistics)!=null&&u.categories&&(p=p.concat(` There are ${(d=e.data.details.dataStatistics)==null?void 0:d.categories.length} categories.`),(h=e.data.details.dataStatistics)!=null&&h.highestCategory&&(((m=e.data.details.dataStatistics)==null?void 0:m.highestCategory.length)===1?p=p.concat(` The highest value is observed in sample ${(f=e.data.details.dataStatistics)==null?void 0:f.highestCategory[0]}.`):p=p.concat(` The highest value is observed in samples ${Ec((b=e.data.details.dataStatistics)==null?void 0:b.highestCategory)}.`))),e.data.description=p}}function q$(e,g){if(g!==!1&&CCg(e),e.alt="Gosling visualization.",e.composition.nTracks===1)e.longDescription=e.tracks[0].description,e.alt=e.longDescription.split(".")[0];else if(e.composition.nTracks===2){let I="",i="";i=i.concat("Figure with two charts.");const n=e.tracks[0].description.split("."),C=n[0],r=n.slice(1).join("."),o=e.tracks[0].description.split("."),a=o[0],s=o.slice(1).join(".");i=i.concat(` ${bG(e.tracks[0].position.description)} track is a ${C.toLowerCase()}. ${r}`),i=i.concat(` ${bG(e.tracks[1].position.description)} track is a ${a.toLowerCase()}. ${s}`),I=I.concat(` Figure with ${C.toLowerCase()} on ${bG(e.tracks[0].position.description)} and ${a.toLowerCase()} on ${bG(e.tracks[1].position.description)}`),e.alt=I,e.longDescription=i}else{let I="";const i=[];for(const n in Object.keys(e.tracks)){const C=e.tracks[n].description.split(".")[0];i.push(C)}I=I.concat(`Figure with ${e.composition.nTracks} individual charts. Briefly, these are a ${Ec(i).toLowerCase()}.`),e.alt=`Gosling visualization with ${e.composition.nTracks} individual charts.`,e.longDescription=I}}function CCg(e){if(Object.keys(e.tracks).length===1)u_(e.tracks[0],!1);else for(const g in Object.keys(e.tracks))u_(e.tracks[g],!0)}function u_(e,g){let I="",i="";e.alttype==="single"||e.alttype==="ov-mark"?(g&&(i=i.concat(e.position.description)),I=i.concat(` ${e.appearance.description} ${e.data.description}`)):(g&&i.concat(e.position.description),I=i.concat(" Overlaid track with different data sources. See individual tracks for details.")),e.description=I}function rCg(e){qng(e),q$(e)}function oCg(e){nCg(e),q$(e)}function aCg(e,g,I){const i={id:e,flatTileData:g};if(I){if(I.genomicField!==void 0){const n=I.genomicField;try{const C=g.map(r=>r[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 ACg(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=U.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 WH={prefix:String(Math.round(Math.random()*1e10)),current:0},IHe=N.createContext(WH),uCg=N.createContext(!1);let dCg=!!(typeof window<"u"&&window.document&&window.document.createElement),YF=new WeakMap;function hCg(e=!1){let g=U.useContext(IHe),I=U.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=YF.get(C);r==null?YF.set(C,{id:g.current,state:C.memoizedState}):C.memoizedState!==r.state&&(g.current=r.id,YF.delete(C))}I.current=++g.current}return I.current}function mCg(e){let g=U.useContext(IHe);g===WH&&!dCg&&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=hCg(!!e),i=`react-aria${g.prefix}`;return e||`${i}-${I}`}function fCg(e){let g=N.useId(),[I]=U.useState(kw()),i=I?"react-aria":`react-aria${WH.prefix}`;return e||`${i}-${g}`}const pCg=typeof N.useId=="function"?fCg:mCg;function bCg(){return!1}function yCg(){return!0}function ZCg(e){return()=>{}}function kw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(ZCg,bCg,yCg):U.useContext(uCg)}function iHe(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 ar(e){const g=U.useRef(null);return bi(()=>{g.current=e},[e]),U.useCallback((...I)=>{const i=g.current;return i(...I)},[])}function vCg(e){let[g,I]=U.useState(e),i=U.useRef(null),n=ar(()=>{let r=i.current.next();if(r.done){i.current=null;return}g===r.value?n():I(r.value)});bi(()=>{i.current&&n()});let C=ar(r=>{i.current=r(g),n()});return[g,C]}let BCg=!!(typeof window<"u"&&window.document&&window.document.createElement),XH=new Map;function Fh(e){let[g,I]=U.useState(e),i=U.useRef(null),n=pCg(g),C=U.useCallback(r=>{i.current=r},[]);return BCg&&XH.set(n,C),bi(()=>{let r=n;return()=>{XH.delete(r)}},[n]),U.useEffect(()=>{let r=i.current;r&&(i.current=null,I(r))}),n}function SCg(e,g){if(e===g)return e;let I=XH.get(e);if(I)return I(g),g;let i=XH.get(g);return i?(i(e),e):g}function sce(e=[]){let g=Fh(),[I,i]=vCg(g),n=U.useCallback(()=>{i(function*(){yield g,yield document.getElementById(g)?g:void 0})},[g,i]);return bi(n,[g,n,...e]),I}function wCg(...e){return(...g)=>{for(let I of e)typeof I=="function"&&I(...g)}}const Cc=e=>{var g;return(g=e==null?void 0:e.ownerDocument)!==null&&g!==void 0?g:document},HH=e=>e&&"window"in e&&e.window===e?e:Cc(e).defaultView||window;function Gi(...e){let g={...e[0]};for(let I=1;I=65&&n.charCodeAt(2)<=90?g[n]=wCg(C,r):(n==="className"||n==="UNSAFE_className")&&typeof C=="string"&&typeof r=="string"?g[n]=GCg(C,r):n==="id"&&C&&r?g.id=SCg(C,r):g[n]=r!==void 0?r:C}}return g}function VCg(...e){return e.length===1?e[0]:g=>{for(let I of e)typeof I=="function"?I(g):I!=null&&(I.current=g)}}const RCg=new Set(["id"]),WCg=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),XCg=new Set(["href","target","rel","download","ping","referrerPolicy"]),HCg=/^(data-.*)$/;function YA(e,g={}){let{labelable:I,isLink:i,propNames:n}=g,C={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(RCg.has(r)||I&&WCg.has(r)||i&&XCg.has(r)||n!=null&&n.has(r)||HCg.test(r))&&(C[r]=e[r]);return C}function vs(e){if(TCg())e.focus({preventScroll:!0});else{let g=NCg(e);e.focus(),kCg(g)}}let r1=null;function TCg(){if(r1==null){r1=!1;try{var e=document.createElement("div");e.focus({get preventScroll(){return r1=!0,!0}})}catch{}}return r1}function NCg(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 t8(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 Eh(){return t8(/^Mac/i)}function YCg(){return t8(/^iPhone/i)}function nHe(){return t8(/^iPad/i)||Eh()&&navigator.maxTouchPoints>1}function g8(){return YCg()||nHe()}function KCg(){return Eh()||g8()}function xCg(){return $k(/AppleWebKit/i)&&!DCg()}function DCg(){return $k(/Chrome/i)}function TH(){return $k(/Android/i)}function FCg(){return $k(/Firefox/i)}const ECg=U.createContext({isNative:!0,open:zCg});function CHe(){return U.useContext(ECg)}function Mh(e,g,I=!0){var i,n;let{metaKey:C,ctrlKey:r,altKey:o,shiftKey:a}=g;FCg()&&(!((n=window.event)===null||n===void 0||(i=n.type)===null||i===void 0)&&i.startsWith("key"))&&e.target==="_blank"&&(Eh()?C=!0:r=!0);let s=xCg()&&Eh()&&!nHe()?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});Mh.isOpening=I,vs(e),e.dispatchEvent(s),Mh.isOpening=!1}Mh.isOpening=!1;function MCg(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 zCg(e,g){MCg(e,I=>Mh(I,g))}function PCg(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 Ff=new Map,d_=new Set;function lce(){if(typeof window>"u")return;let e=I=>{let i=Ff.get(I.target);i||(i=new Set,Ff.set(I.target,i),I.target.addEventListener("transitioncancel",g)),i.add(I.propertyName)},g=I=>{let i=Ff.get(I.target);if(i&&(i.delete(I.propertyName),i.size===0&&(I.target.removeEventListener("transitioncancel",g),Ff.delete(I.target)),Ff.size===0)){for(let n of d_)n();d_.clear()}};document.body.addEventListener("transitionrun",e),document.body.addEventListener("transitionend",g)}typeof document<"u"&&(document.readyState!=="loading"?lce():document.addEventListener("DOMContentLoaded",lce));function rHe(e){requestAnimationFrame(()=>{Ff.size===0?e():d_.add(e)})}function oHe(){let e=U.useRef(new Map),g=U.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=U.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=U.useCallback(()=>{e.current.forEach((n,C)=>{I(n.eventTarget,n.type,C,n.options)})},[I]);return U.useEffect(()=>i,[i]),{addGlobalListener:g,removeGlobalListener:I,removeAllGlobalListeners:i}}function JCg(e,g){let{id:I,"aria-label":i,"aria-labelledby":n}=e;return I=Fh(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 Yw(e){const g=U.useRef();return U.useMemo(()=>({get current(){return g.current},set current(I){g.current=I,typeof e=="function"?e(I):e&&(e.current=I)}}),[e])}function aHe(e,g){const I=U.useRef(!0),i=U.useRef(null);U.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]),U.useEffect(()=>{I.current?I.current=!1:(!i.current||g.some((n,C)=>!Object.is(n,i[C])))&&e(),i.current=g},g)}function AHe(e,g){bi(()=>{if(e&&e.ref&&g)return e.ref.current=g.current,()=>{e.ref.current=null}})}function _l(e){for(NH(e)&&(e=e.parentElement);e&&!NH(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}function NH(e){let g=window.getComputedStyle(e);return/(auto|scroll)/.test(g.overflow+g.overflowX+g.overflowY)}let OCg=0;const KF=new Map;function qk(e){let[g,I]=U.useState(void 0);return bi(()=>{if(!e)return;let i=KF.get(e);if(i)I(i.element.id);else{let n=`react-aria-description-${OCg++}`;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},KF.set(e,i)}return i.refCount++,()=>{--i.refCount===0&&(i.element.remove(),KF.delete(e))}},[e]),{"aria-describedby":e?g:void 0}}function _Cg(e,g,I,i){let n=ar(I),C=I==null;U.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 sHe(e,g){let I=cce(e,g,"left"),i=cce(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 cce(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 Ll(e,g){if(document.contains(e)){let r=document.scrollingElement||document.documentElement;if(window.getComputedStyle(r).overflow==="hidden"){let a=_l(e);for(;e&&a&&e!==r&&a!==r;)sHe(a,e),e=a,a=_l(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 h_(e){return e.mozInputSource===0&&e.isTrusted?!0:TH()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function LCg(e){return!TH()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function UCg(e,g,I){let i=U.useRef(g),n=ar(()=>{I&&I(i.current)});U.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 QCg(e,g){return g.get?g.get.call(e):g.value}function lHe(e,g,I){if(!g.has(e))throw new TypeError("attempted to "+I+" private field on non-instance");return g.get(e)}function jCg(e,g){var I=lHe(e,g,"get");return QCg(e,I)}function $Cg(e,g){if(g.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function qCg(e,g,I){$Cg(e,g),g.set(e,I)}function erg(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 uce(e,g,I){var i=lHe(e,g,"set");return erg(e,i,I),I}let cp="default",m_="",KW=new WeakMap;function dce(e){if(g8()){if(cp==="default"){const g=Cc(e);m_=g.documentElement.style.webkitUserSelect,g.documentElement.style.webkitUserSelect="none"}cp="disabled"}else(e instanceof HTMLElement||e instanceof SVGElement)&&(KW.set(e,e.style.userSelect),e.style.userSelect="none")}function o1(e){if(g8()){if(cp!=="disabled")return;cp="restoring",setTimeout(()=>{rHe(()=>{if(cp==="restoring"){const g=Cc(e);g.documentElement.style.webkitUserSelect==="none"&&(g.documentElement.style.webkitUserSelect=m_||""),m_="",cp="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&KW.has(e)){let g=KW.get(e);e.style.userSelect==="none"&&g&&(e.style.userSelect=g),e.getAttribute("style")===""&&e.removeAttribute("style"),KW.delete(e)}}const cHe=N.createContext({register:()=>{}});cHe.displayName="PressResponderContext";function trg(e){let g=U.useContext(cHe);if(g){let{register:I,...i}=g;e=Gi(i,e),I()}return AHe(g,e.ref),e}var a1=new WeakMap;class A1{continuePropagation(){uce(this,a1,!1)}get shouldStopPropagation(){return jCg(this,a1)}constructor(g,I,i){qCg(this,a1,{writable:!0,value:void 0}),uce(this,a1,!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 hce=Symbol("linkClicked");function I8(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}=trg(e),[u,d]=U.useState(!1),h=U.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=oHe(),b=ar((v,w)=>{let V=h.current;if(r||V.didFirePressStart)return!1;let S=!0;if(V.isTriggeringEvent=!0,i){let X=new A1("pressstart",w,v);i(X),S=X.shouldStopPropagation}return I&&I(!0),V.isTriggeringEvent=!1,V.didFirePressStart=!0,d(!0),S}),p=ar((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 A1("pressend",w,v);n(W),X=W.shouldStopPropagation}if(I&&I(!1),d(!1),g&&V&&!r){let W=new A1("press",w,v);g(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=ar((v,w)=>{let V=h.current;if(r)return!1;if(C){V.isTriggeringEvent=!0;let S=new A1("pressup",w,v);return C(S),V.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=ar(v=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p(UA(w.target,v),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),A||o1(w.target))}),B=ar(v=>{s&&Z(v)}),G=U.useMemo(()=>{let v=h.current,w={onKeyDown(S){if(xF(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;fce(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(Cc(S.currentTarget),"keyup",V,!1)),W&&S.stopPropagation(),S.metaKey&&Eh()&&((X=v.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(v.metaKeyEvents=new Map)},onKeyUp(S){xF(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&v.target&&y(UA(v.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!v.isTriggeringEvent&&!Mh.isOpening){let X=!0;if(r&&S.preventDefault(),!v.ignoreClickAfterPress&&!v.ignoreEmulatedMouseEvents&&!v.isPressed&&(v.pointerType==="virtual"||h_(S.nativeEvent))){!r&&!a&&vs(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&&xF(S,v.target)){var W;fce(S.target,S.key)&&S.preventDefault();let H=S.target,Y=p(UA(v.target,S),"keyboard",v.target.contains(H));f(),Y&&S.stopPropagation(),S.key!=="Enter"&&i8(v.target)&&v.target.contains(H)&&!S[hce]&&(S[hce]=!0,Mh(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(LCg(R.nativeEvent)){v.pointerType="virtual";return}DF(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&&vs(R.currentTarget),A||dce(v.target),H=b(R,v.pointerType),m(Cc(R.currentTarget),"pointermove",S,!1),m(Cc(R.currentTarget),"pointerup",X,!1),m(Cc(R.currentTarget),"pointercancel",W,!1)),H&&R.stopPropagation()},w.onMouseDown=R=>{R.currentTarget.contains(R.target)&&R.button===0&&(DF(R.currentTarget)&&R.preventDefault(),R.stopPropagation())},w.onPointerUp=R=>{!R.currentTarget.contains(R.target)||v.pointerType==="virtual"||R.button===0&&af(R,R.currentTarget)&&y(R,v.pointerType||R.pointerType)};let S=R=>{R.pointerId===v.activePointerId&&(v.target&&af(R,v.target)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,b(UA(v.target,R),v.pointerType)):v.target&&v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,p(UA(v.target,R),v.pointerType,!1),B(R)))},X=R=>{R.pointerId===v.activePointerId&&v.isPressed&&R.button===0&&v.target&&(af(R,v.target)&&v.pointerType!=null?p(UA(v.target,R),v.pointerType):v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,R),v.pointerType,!1),v.isPressed=!1,v.isOverTarget=!1,v.activePointerId=null,v.pointerType=null,f(),A||o1(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(DF(W.currentTarget)&&W.preventDefault(),v.ignoreEmulatedMouseEvents){W.stopPropagation();return}v.isPressed=!0,v.isOverTarget=!0,v.target=W.currentTarget,v.pointerType=h_(W.nativeEvent)?"virtual":"mouse",!r&&!a&&vs(W.currentTarget),b(W,v.pointerType)&&W.stopPropagation(),m(Cc(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&&af(W,v.target)&&v.pointerType!=null?p(UA(v.target,W),v.pointerType):v.target&&v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,W),v.pointerType,!1),v.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let R=grg(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&&vs(W.currentTarget),A||dce(v.target),b(W,v.pointerType)&&W.stopPropagation(),m(HH(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let R=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(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=mce(W.nativeEvent,v.activePointerId),H=!0;R&&af(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&&o1(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 U.useEffect(()=>()=>{var v;A||o1((v=h.current.target)!==null&&v!==void 0?v:void 0)},[A]),{isPressed:o||u,pressProps:Gi(c,G)}}function i8(e){return e.tagName==="A"&&e.hasAttribute("href")}function xF(e,g){const{key:I,code:i}=e,n=g,C=n.getAttribute("role");return(I==="Enter"||I===" "||I==="Spacebar"||i==="Space")&&!(n instanceof HH(n).HTMLInputElement&&!uHe(n,I)||n instanceof HH(n).HTMLTextAreaElement||n.isContentEditable)&&!((C==="link"||!C&&i8(n))&&I!=="Enter")}function grg(e){const{targetTouches:g}=e;return g.length>0?g[0]:null}function mce(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 af(e,g){let I=g.getBoundingClientRect(),i=Irg(e);return irg(I,i)}function DF(e){return!(e instanceof HTMLElement)||!e.hasAttribute("draggable")}function fce(e,g){return e instanceof HTMLInputElement?!uHe(e,g):e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!i8(e)}const nrg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function uHe(e,g){return e.type==="checkbox"||e.type==="radio"?g===" ":nrg.has(e.type)}class Crg{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 dHe(e){let g=U.useRef({isFocused:!1,observer:null});bi(()=>{const i=g.current;return()=>{i.observer&&(i.observer.disconnect(),i.observer=null)}},[]);let I=ar(i=>{e==null||e(i)});return U.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 Crg("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 hHe(e){let{isDisabled:g,onFocus:I,onBlur:i,onFocusChange:n}=e;const C=U.useCallback(a=>{if(a.target===a.currentTarget)return i&&i(a),n&&n(!1),!0},[i,n]),r=dHe(C),o=U.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 _s=null,AS=new Set,pce=!1,zh=!1,f_=!1;const rrg={Tab:!0,Escape:!0};function eY(e,g){for(let I of AS)I(e,g)}function org(e){return!(e.metaKey||!Eh()&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function bce(e){zh=!0,org(e)&&(_s="keyboard",eY("keyboard",e))}function Af(e){_s="pointer",(e.type==="mousedown"||e.type==="pointerdown")&&(zh=!0,eY("pointer",e))}function arg(e){h_(e)&&(zh=!0,_s="virtual")}function Arg(e){e.target===window||e.target===document||(!zh&&!f_&&(_s="virtual",eY("virtual",e)),zh=!1,f_=!1)}function srg(){zh=!1,f_=!0}function kH(){if(typeof window>"u"||pce)return;let e=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){zh=!0,e.apply(this,arguments)},document.addEventListener("keydown",bce,!0),document.addEventListener("keyup",bce,!0),document.addEventListener("click",arg,!0),window.addEventListener("focus",Arg,!0),window.addEventListener("blur",srg,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",Af,!0),document.addEventListener("pointermove",Af,!0),document.addEventListener("pointerup",Af,!0)):(document.addEventListener("mousedown",Af,!0),document.addEventListener("mousemove",Af,!0),document.addEventListener("mouseup",Af,!0)),pce=!0}typeof document<"u"&&(document.readyState!=="loading"?kH():document.addEventListener("DOMContentLoaded",kH));function n8(){return _s!=="pointer"}function p_(){return _s}function lrg(e){_s=e,eY(e,null)}function crg(){kH();let[e,g]=U.useState(_s);return U.useEffect(()=>{let I=()=>{g(_s)};return AS.add(I),()=>{AS.delete(I)}},[]),kw()?null:e}const urg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function drg(e,g,I){var i;return e=e||(I==null?void 0:I.target)instanceof HTMLInputElement&&!urg.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&&!rrg[I.key])}function hrg(e,g,I){kH(),U.useEffect(()=>{let i=(n,C)=>{drg(!!(I!=null&&I.isTextInput),n,C)&&e(n8())};return AS.add(i),()=>{AS.delete(i)}},g)}function mHe(e){let{isDisabled:g,onBlurWithin:I,onFocusWithin:i,onFocusWithinChange:n}=e,C=U.useRef({isFocusWithin:!1}),r=U.useCallback(s=>{C.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(C.current.isFocusWithin=!1,I&&I(s),n&&n(!1))},[I,n,C]),o=dHe(r),a=U.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 YH=!1,FF=0;function b_(){YH=!0,setTimeout(()=>{YH=!1},50)}function yce(e){e.pointerType==="touch"&&b_()}function mrg(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",yce):document.addEventListener("touchend",b_),FF++,()=>{FF--,!(FF>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",yce):document.removeEventListener("touchend",b_))}}function C8(e){let{onHoverStart:g,onHoverChange:I,onHoverEnd:i,isDisabled:n}=e,[C,r]=U.useState(!1),o=U.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;U.useEffect(mrg,[]);let{hoverProps:a,triggerHoverEnd:s}=U.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=>{YH&&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&&!YH&&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 U.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:a,isHovered:C}}function Zce(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 frg(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:Zce(e.onKeyDown),onKeyUp:Zce(e.onKeyUp)}}}const prg=500;function brg(e){let{isDisabled:g,onLongPressStart:I,onLongPressEnd:i,onLongPress:n,threshold:C=prg,accessibilityDescription:r}=e;const o=U.useRef();let{addGlobalListener:a,removeGlobalListener:s}=oHe(),{pressProps:A}=I8({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=qk(n&&!g?r:void 0);return{longPressProps:Gi(A,l)}}function gr(e){if(p_()==="virtual"){let g=document.activeElement;rHe(()=>{document.activeElement===g&&document.contains(e)&&vs(e)})}else vs(e)}function yrg(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 Zrg(e,g){return!e.hasAttribute("hidden")&&(e.nodeName==="DETAILS"&&g&&g.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function fHe(e,g){return e.nodeName!=="#comment"&&yrg(e)&&Zrg(e,g)&&(!e.parentElement||fHe(e.parentElement,e))}const Gce=N.createContext(null);let mI=null;function Grg(e){let{children:g,contain:I,restoreFocus:i,autoFocus:n}=e,C=U.useRef(null),r=U.useRef(null),o=U.useRef([]),{parentNode:a}=U.useContext(Gce)||{},s=U.useMemo(()=>new Z_({scopeRef:o}),[o]);bi(()=>{let c=a||di.root;if(di.getTreeNode(c.scopeRef)&&mI&&!KH(mI,c.scopeRef)){let u=di.getTreeNode(mI);u&&(c=u)}c.addChild(s),di.addNode(s)},[s,a]),bi(()=>{let c=di.getTreeNode(o);c&&(c.contain=!!I)},[I]),bi(()=>{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]),Rrg(o,i,I),wrg(o,I),Xrg(o,i,I),Vrg(o,n),U.useEffect(()=>{let c=document.activeElement,u=null;if(Yn(c,o.current)){for(let d of di.traverse())d.scopeRef&&Yn(c,d.scopeRef.current)&&(u=d);u===di.getTreeNode(o)&&(mI=u.scopeRef)}},[o]),bi(()=>()=>{var c,u,d;let h=(d=(u=di.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===mI||KH(o,mI))&&(!h||di.getTreeNode(h))&&(mI=h),di.removeTreeNode(o)},[o]);let A=U.useMemo(()=>vrg(o),[]),l=U.useMemo(()=>({focusManager:A,parentNode:s}),[s,A]);return N.createElement(Gce.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 vrg(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=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.nextNode();return!l&&C&&(A.currentNode=a,l=A.nextNode()),l&&Bs(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=yd(I),A=jr(s,{tabbable:n,accept:r},I);A.currentNode=Yn(o,I)?o:a;let l=A.previousNode();return!l&&C&&(A.currentNode=a,l=A.previousNode()),l&&Bs(l,!0),l},focusFirst(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[0].previousElementSibling;let o=r.nextNode();return o&&Bs(o,!0),o},focusLast(g={}){let I=e.current,{tabbable:i,accept:n}=g,C=yd(I),r=jr(C,{tabbable:i,accept:n},I);r.currentNode=I[I.length-1].nextElementSibling;let o=r.previousNode();return o&&Bs(o,!0),o}}}const r8=["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]"],Brg=r8.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";r8.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const Srg=r8.join(':not([hidden]):not([tabindex="-1"]),');function yd(e){return e[0].parentElement}function yG(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.contain)return!1;g=g.parent}return!0}function wrg(e,g){let I=U.useRef(),i=U.useRef();bi(()=>{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||!yG(e))return;let s=document.activeElement,A=e.current;if(!A||!Yn(s,A))return;let l=yd(A),c=jr(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&&Bs(u,!0)},r=a=>{(!mI||KH(mI,e))&&Yn(a.target,e.current)?(mI=e,I.current=a.target):yG(e)&&!y_(a.target,e)?I.current?I.current.focus():mI&&mI.current&&xH(mI.current):yG(e)&&(I.current=a.target)},o=a=>{i.current&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(()=>{if(document.activeElement&&yG(e)&&!y_(document.activeElement,e))if(mI=e,document.body.contains(a.target)){var s;I.current=a.target,(s=I.current)===null||s===void 0||s.focus()}else mI.current&&xH(mI.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]),bi(()=>()=>{i.current&&cancelAnimationFrame(i.current)},[i])}function pHe(e){return y_(e)}function Yn(e,g){return!e||!g?!1:g.some(I=>I.contains(e))}function y_(e,g=null){if(e instanceof Element&&e.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:I}of di.traverse(di.getTreeNode(g)))if(I&&Yn(e,I.current))return!0;return!1}function KH(e,g){var I;let i=(I=di.getTreeNode(g))===null||I===void 0?void 0:I.parent;for(;i;){if(i.scopeRef===e)return!0;i=i.parent}return!1}function Bs(e,g=!1){if(e!=null&&!g)try{gr(e)}catch{}else if(e!=null)try{e.focus()}catch{}}function xH(e,g=!0){let I=e[0].previousElementSibling,i=yd(e),n=jr(i,{tabbable:g},e);n.currentNode=I;let C=n.nextNode();g&&!C&&(i=yd(e),n=jr(i,{tabbable:!1},e),n.currentNode=I,C=n.nextNode()),Bs(C)}function Vrg(e,g){const I=N.useRef(g);U.useEffect(()=>{I.current&&(mI=e,!Yn(document.activeElement,mI.current)&&e.current&&xH(e.current)),I.current=!1},[e])}function Rrg(e,g,I){bi(()=>{if(g||I)return;let i=e.current,n=C=>{let r=C.target;Yn(r,e.current)?mI=e:pHe(r)||(mI=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 Wrg(e){let g=di.getTreeNode(mI);for(;g&&g.scopeRef!==e;){if(g.nodeToRestore)return!1;g=g.parent}return(g==null?void 0:g.scopeRef)===e}function Xrg(e,g,I){const i=U.useRef(typeof document<"u"?document.activeElement:null);bi(()=>{let n=e.current;if(!g||I)return;let C=()=>{(!mI||KH(mI,e))&&Yn(document.activeElement,e.current)&&(mI=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]),bi(()=>{if(!g)return;let n=C=>{if(C.key!=="Tab"||C.altKey||C.ctrlKey||C.metaKey||!yG(e))return;let r=document.activeElement;if(!Yn(r,e.current))return;let o=di.getTreeNode(e);if(!o)return;let a=o.nodeToRestore,s=jr(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||!Yn(A,e.current))&&a){s.currentNode=a;do A=C.shiftKey?s.previousNode():s.nextNode();while(Yn(A,e.current));C.preventDefault(),C.stopPropagation(),A?Bs(A,!0):pHe(a)?Bs(a,!0):r.blur()}};return I||document.addEventListener("keydown",n,!0),()=>{I||document.removeEventListener("keydown",n,!0)}},[e,g,I]),bi(()=>{if(!g)return;let n=di.getTreeNode(e);if(n){var C;return n.nodeToRestore=(C=i.current)!==null&&C!==void 0?C:void 0,()=>{let r=di.getTreeNode(e);if(!r)return;let o=r.nodeToRestore;if(g&&o&&(Yn(document.activeElement,e.current)||document.activeElement===document.body&&Wrg(e))){let a=di.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=a.getTreeNode(e);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){Bs(s.nodeToRestore);return}s=s.parent}for(s=a.getTreeNode(e);s;){if(s.scopeRef&&s.scopeRef.current&&di.getTreeNode(s.scopeRef)){xH(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[e,g])}function jr(e,g,I){let i=g!=null&&g.tabbable?Srg:Brg,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)&&fHe(C)&&(!I||Yn(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 o8{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 Z_({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&&Yn(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 o8;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 Z_({scopeRef:null}),this.fastMap.set(null,this.root)}}class Z_{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 di=new o8;function tY(e={}){let{autoFocus:g=!1,isTextInput:I,within:i}=e,n=U.useRef({isFocused:!1,isFocusVisible:g||n8()}),[C,r]=U.useState(!1),[o,a]=U.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=U.useCallback(()=>a(n.current.isFocused&&n.current.isFocusVisible),[]),A=U.useCallback(u=>{n.current.isFocused=u,r(u),s()},[s]);hrg(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:I});let{focusProps:l}=hHe({isDisabled:i,onFocusChange:A}),{focusWithinProps:c}=mHe({isDisabled:!i,onFocusWithinChange:A});return{isFocused:C,isFocusVisible:o,focusProps:i?c:l}}let Hrg=N.createContext(null);function Trg(e){let g=U.useContext(Hrg)||{};AHe(g,e);let{ref:I,...i}=g;return i}function bHe(e,g){let{focusProps:I}=hHe(e),{keyboardProps:i}=frg(e),n=Gi(I,i),C=Trg(g),r=e.isDisabled?{}:C,o=U.useRef(e.autoFocus);return U.useEffect(()=>{o.current&&g.current&&gr(g.current),o.current=!1},[g]),{focusableProps:Gi({...n,tabIndex:e.excludeFromTabOrder&&!e.isDisabled?-1:void 0},r)}}function Nrg(e,g){let I=g==null?void 0:g.isDisabled,[i,n]=U.useState(!1);return bi(()=>{if(e!=null&&e.current&&!I){let C=()=>{if(e.current){let o=jr(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 krg{getStringForLocale(g,I){let i=this.strings[I];i||(i=Yrg(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 Yrg(e,g,I="en-US"){if(g[e])return g[e];let i=Krg(e);if(g[i])return g[i];for(let n in g)if(n.startsWith(i+"-"))return g[n];return g[I]}function Krg(e){return Intl.Locale?new Intl.Locale(e).language:e.split("-")[0]}const vce=new Map,Bce=new Map;class xrg{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=vce.get(C);r||(r=new Intl.PluralRules(this.locale,{type:i}),vce.set(C,r));let o=r.select(g);return n=I[o]||I.other,typeof n=="function"?n():n}number(g){let I=Bce.get(this.locale);return I||(I=new Intl.NumberFormat(this.locale),Bce.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 Drg=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),Frg=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function Erg(e){if(Intl.Locale){let I=new Intl.Locale(e).maximize().script;return I?Drg.has(I):!1}let g=e.split("-")[0];return Frg.has(g)}function yHe(){let e=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e="en-US"}return{locale:e,direction:Erg(e)?"rtl":"ltr"}}let G_=yHe(),ZG=new Set;function Sce(){G_=yHe();for(let e of ZG)e(G_)}function Mrg(){let e=kw(),[g,I]=U.useState(G_);return U.useEffect(()=>(ZG.size===0&&window.addEventListener("languagechange",Sce),ZG.add(I),()=>{ZG.delete(I),ZG.size===0&&window.removeEventListener("languagechange",Sce)}),[]),e?{locale:"en-US",direction:"ltr"}:g}const zrg=N.createContext(null);function vm(){let e=Mrg();return U.useContext(zrg)||e}const wce=new WeakMap;function Prg(e){let g=wce.get(e);return g||(g=new krg(e),wce.set(e,g)),g}function hy(e){let{locale:g}=vm(),I=U.useMemo(()=>Prg(e),[e]);return U.useMemo(()=>new xrg(g,I),[g,I])}let EF=new Map;function ZHe(e){let{locale:g}=vm(),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 Org(e,g,I){let{validationBehavior:i,focus:n}=e;bi(()=>{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(Lrg(I.current))}});let C=ar(()=>{g.resetValidation()}),r=ar(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&&Urg(A)===I.current){var l;n?n():(l=I.current)===null||l===void 0||l.focus(),lrg("keyboard")}a.preventDefault()}),o=ar(()=>{g.commitValidation()});U.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 _rg(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 Lrg(e){return{isInvalid:!e.validity.valid,validationDetails:_rg(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function Urg(e){for(let g=0;gRce(qrg(r,n)),[r,n]);C!=null&&C.validationDetails.valid&&(C=null);let A=U.useContext(Qrg),l=U.useMemo(()=>i?Array.isArray(i)?i.flatMap(V=>v_(A[V])):v_(A[i]):[],[A,i]),[c,u]=U.useState(A),[d,h]=U.useState(!1);A!==c&&(u(A),h(!1));let m=U.useMemo(()=>Rce(d?[]:l),[d,l]),f=U.useRef(GZ),[b,p]=U.useState(GZ),y=U.useRef(GZ),Z=()=>{if(!B)return;G(!1);let V=s||C||f.current;zF(V,y.current)||(y.current=V,p(V))},[B,G]=U.useState(!1);return U.useEffect(Z),{realtimeValidation:a||m||s||C||GZ,displayValidation:o==="native"?a||m||b:a||m||s||C||b,updateValidation(V){o==="aria"&&!zF(b,V)?p(V):f.current=V},resetValidation(){let V=GZ;zF(V,y.current)||(y.current=V,p(V)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function v_(e){return e?Array.isArray(e)?e:[e]:[]}function qrg(e,g){if(typeof e=="function"){let I=e(g);if(I&&typeof I!="boolean")return v_(I)}return[]}function Rce(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:SHe}:null}function zF(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 eog(e){let{id:g,label:I,"aria-labelledby":i,"aria-label":n,labelElementType:C="label"}=e;g=Fh(g);let r=Fh(),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=JCg({id:g,"aria-label":n,"aria-labelledby":i});return{labelProps:o,fieldProps:a}}function tog(e){let{description:g,errorMessage:I,isInvalid:i,validationState:n}=e,{labelProps:C,fieldProps:r}=eog(e),o=sce([!!g,!!I,i,n]),a=sce([!!g,!!I,i,n]);return r=Gi(r,{"aria-describedby":[o,a,e["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:C,fieldProps:r,descriptionProps:{id:o},errorMessageProps:{id:a}}}const Wce={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 a8(e={}){let{style:g,isFocusable:I}=e,[i,n]=U.useState(!1),{focusWithinProps:C}=mHe({isDisabled:!I,onFocusWithinChange:o=>n(o)}),r=U.useMemo(()=>i?g:g?{...Wce,...g}:Wce,[i]);return{visuallyHiddenProps:{...C,style:r}}}function B_(e){return KCg()?e.altKey:e.ctrlKey}function Ef(e){return Eh()?e.metaKey:e.ctrlKey}const gog=1e3;function Iog(e){let{keyboardDelegate:g,selectionManager:I,onTypeSelect:i}=e,n=U.useRef({search:"",timeout:null}).current,C=r=>{let o=iog(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=""},gog)};return{typeSelectProps:{onKeyDownCapture:g.getKeyForSearch?C:null}}}function iog(e){return e.length===1||!/^[A-Z]/i.test(e)?e:""}function nog(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}=vm(),m=CHe(),f=V=>{if(V.altKey&&V.key==="Tab"&&V.preventDefault(),!i.current.contains(V.target))return;const S=(P,ge)=>{if(P!=null){if(g.isLink(P)&&d==="selection"&&a&&!B_(V)){Aa.flushSync(()=>{g.setFocusedKey(P,ge)});let q=u.current.querySelector(`[data-key="${P}"]`);m.open(q,V);return}if(g.setFocusedKey(P,ge),g.isLink(P)&&d==="override")return;V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&!B_(V)&&g.replaceSelection(P)}};switch(V.key){case"ArrowDown":if(I.getKeyBelow){var X,W;V.preventDefault();let P=g.focusedKey!=null?I.getKeyBelow(g.focusedKey):(X=I.getFirstKey)===null||X===void 0?void 0:X.call(I);P==null&&C&&(P=(W=I.getFirstKey)===null||W===void 0?void 0:W.call(I,g.focusedKey)),S(P)}break;case"ArrowUp":if(I.getKeyAbove){var R,H;V.preventDefault();let P=g.focusedKey!=null?I.getKeyAbove(g.focusedKey):(R=I.getLastKey)===null||R===void 0?void 0:R.call(I);P==null&&C&&(P=(H=I.getLastKey)===null||H===void 0?void 0:H.call(I,g.focusedKey)),S(P)}break;case"ArrowLeft":if(I.getKeyLeftOf){var Y,K;V.preventDefault();let P=I.getKeyLeftOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(Y=I.getFirstKey)===null||Y===void 0?void 0:Y.call(I,g.focusedKey):(K=I.getLastKey)===null||K===void 0?void 0:K.call(I,g.focusedKey)),S(P,h==="rtl"?"first":"last")}break;case"ArrowRight":if(I.getKeyRightOf){var F,J;V.preventDefault();let P=I.getKeyRightOf(g.focusedKey);P==null&&C&&(P=h==="rtl"?(F=I.getLastKey)===null||F===void 0?void 0:F.call(I,g.focusedKey):(J=I.getFirstKey)===null||J===void 0?void 0:J.call(I,g.focusedKey)),S(P,h==="rtl"?"last":"first")}break;case"Home":if(I.getFirstKey){V.preventDefault();let P=I.getFirstKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"End":if(I.getLastKey){V.preventDefault();let P=I.getLastKey(g.focusedKey,Ef(V));g.setFocusedKey(P),Ef(V)&&V.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"PageDown":if(I.getKeyPageBelow){V.preventDefault();let P=I.getKeyPageBelow(g.focusedKey);S(P)}break;case"PageUp":if(I.getKeyPageAbove){V.preventDefault();let P=I.getKeyPageAbove(g.focusedKey);S(P)}break;case"a":Ef(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 P=jr(i.current,{tabbable:!0}),ge,q;do q=P.lastChild(),q&&(ge=q);while(q);ge&&!ge.contains(document.activeElement)&&vs(ge)}break}}},b=U.useRef({top:0,left:0});_Cg(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)||vs(W),p_()==="keyboard"&&Ll(W,{containingElement:i.current}))}}},y=V=>{V.currentTarget.contains(V.relatedTarget)||g.setFocused(!1)};const Z=U.useRef(n);U.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&&gr(i.current)}Z.current=!1},[]);let B=U.useRef(g.focusedKey);U.useEffect(()=>{let V=p_();if(g.isFocused&&g.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${g.focusedKey}"]`);S&&V==="keyboard"&&(c||sHe(u.current,S),Ll(S,{containingElement:i.current}))}g.isFocused&&g.focusedKey==null&&B.current!=null&&gr(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}=Iog({keyboardDelegate:I,selectionManager:g});s||(G=Gi(v,G));let w;return A||(w=g.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function wHe(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=CHe(),c=K=>{if(K.pointerType==="keyboard"&&B_(K))g.toggleSelection(I);else{if(g.selectionMode==="none")return;if(g.isLink(I)){if(A==="selection"){l.open(i.current,K),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):K&&K.shiftKey?g.extendSelection(I):g.selectionBehavior==="toggle"||K&&(Ef(K)||K.pointerType==="touch"||K.pointerType==="virtual")?g.toggleSelection(I):g.replaceSelection(I)}};U.useEffect(()=>{I===g.focusedKey&&g.isFocused&&!C&&(r?r():document.activeElement!==i.current&&gr(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(K){K.target===i.current&&g.setFocusedKey(I)}}:o&&(u.onMouseDown=K=>{K.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=U.useRef(null),B=y&&m,G=U.useRef(!1),v=U.useRef(!1),w=K=>{a&&a(),h&&l.open(i.current,K)},V={};n?(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,K.pointerType==="keyboard"&&(!y||Hce())&&c(K)},s?(V.onPressUp=b?null:K=>{K.pointerType!=="keyboard"&&m&&c(K)},V.onPress=b?w:null):V.onPress=K=>{if(b||p&&K.pointerType!=="mouse"){if(K.pointerType==="keyboard"&&!Xce())return;w(K)}else K.pointerType!=="keyboard"&&m&&c(K)}):(V.onPressStart=K=>{Z.current=K.pointerType,G.current=B,v.current=b,m&&(K.pointerType==="mouse"&&!b||K.pointerType==="keyboard"&&(!f||Hce()))&&c(K)},V.onPress=K=>{(K.pointerType==="touch"||K.pointerType==="pen"||K.pointerType==="virtual"||K.pointerType==="keyboard"&&y&&Xce()||K.pointerType==="mouse"&&v.current)&&(y?w(K):m&&c(K))}),u["data-key"]=I,V.preventFocusOnPress=C;let{pressProps:S,isPressed:X}=I8(V),W=p?K=>{Z.current==="mouse"&&(K.stopPropagation(),K.preventDefault(),w(K))}:void 0,{longPressProps:R}=brg({isDisabled:!B,onLongPress(K){K.pointerType==="touch"&&(c(K),g.setSelectionBehavior("toggle"))}}),H=K=>{Z.current==="touch"&&G.current&&K.preventDefault()},Y=g.isLink(I)?K=>{Mh.isOpening||K.preventDefault()}:void 0;return{itemProps:Gi(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 Xce(){let e=window.event;return(e==null?void 0:e.key)==="Enter"}function Hce(){let e=window.event;return(e==null?void 0:e.key)===" "||(e==null?void 0:e.code)==="Space"}class Cog{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(!NH(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(!NH(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:oog(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 <${PF(m.type)}> in <${PF(n.type)}>. Only <${PF(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:Tce(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 Tce(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 oog(e,g){if(e&&g)return I=>e(g(I));if(e)return e;if(g)return g}function PF(e){return e[0].toUpperCase()+e.slice(1)}function aog(e,g,I){let i=U.useMemo(()=>new rog,[]),{children:n,items:C,collection:r}=e;return U.useMemo(()=>{if(r)return r;let a=i.build({children:n,items:C},I);return g(a)},[i,n,C,r,I,g])}function wi(e,g){return typeof g.getChildren=="function"?g.getChildren(e.key):e.childNodes}function As(e){return Ul(e,0)}function Ul(e,g){if(g<0)return;let I=0;for(let i of e){if(I===g)return i;I++}}function yc(e){let g;for(let I of e)g=I;return g}function JF(e,g,I){if(g.parentKey===I.parentKey)return g.index-I.index;let i=[...Nce(e,g),g],n=[...Nce(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 Nce(e,g){let I=[];for(;(g==null?void 0:g.parentKey)!=null;)g=e.getItem(g.parentKey),I.unshift(g);return I}function Aog(e,g){let{inputElementType:I="input",isDisabled:i=!1,isRequired:n=!1,isReadOnly:C=!1,type:r="text",validationBehavior:o="aria"}=e,[a,s]=gHe(e.value,e.defaultValue||"",e.onChange),{focusableProps:A}=bHe(e,g),l=jrg({...e,value:a}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=tog({...e,isInvalid:c,errorMessage:e.errorMessage||u}),p=YA(e,{labelable:!0});const y={type:r,pattern:e.pattern};return UCg(g,a,s),Org(e,l,g),U.useEffect(()=>{if(g.current instanceof HH(g.current).HTMLTextAreaElement){let Z=g.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[g]),{labelProps:h,inputProps:Gi(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 up{copy(){return new up(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 dp{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 up(this.x,this.y)}get topRight(){return new up(this.maxX,this.y)}get bottomLeft(){return new up(this.x,this.maxY)}get bottomRight(){return new up(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 dp(I,i,n,C)}intersection(g){if(!this.intersects(g))return new dp(0,0,0,0);let I=Math.max(this.x,g.x),i=Math.max(this.y,g.y);return new dp(I,i,Math.min(this.maxX,g.maxX)-I,Math.min(this.maxY,g.maxY)-i)}copy(){return new dp(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 Mf=typeof window<"u"?window.performance:null,kce=Mf&&(Mf.now||Mf.webkitNow||Mf.msNow||Mf.mozNow);kce&&kce.bind(Mf);function A8(e){return e&&e.__esModule?e.default:e}class VHe{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 Ul(wi(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 Ul(wi(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=wi(I,this.collection);return this.direction==="rtl"?yc(i).key:As(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index-1):Ul(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=wi(I,this.collection);return this.direction==="rtl"?As(i).key:yc(i).key}if(this.isCell(I)){let i=this.collection.getItem(I.parentKey),n=wi(i,this.collection),C=this.direction==="rtl"?Ul(n,I.index+1):Ul(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 As(wi(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=As(wi(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=wi(n,this.collection);return yc(C).key}}if(g=this.findPreviousKey(),g!=null&&i&&this.isCell(i)&&I||this.focusMode==="cell"){let n=this.collection.getItem(g),C=wi(n,this.collection);g=yc(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 dp(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 WHe={};WHe={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 XHe={};XHe={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 HHe={};HHe={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 THe={};THe={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 NHe={};NHe={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 kHe={};kHe={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 YHe={};YHe={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 KHe={};KHe={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 xHe={};xHe={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 DHe={};DHe={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 FHe={};FHe={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 EHe={};EHe={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 MHe={};MHe={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 zHe={};zHe={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 PHe={};PHe={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 JHe={};JHe={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 OHe={};OHe={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 _He={};_He={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 LHe={};LHe={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 UHe={};UHe={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 QHe={};QHe={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 jHe={};jHe={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 $He={};$He={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 qHe={};qHe={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 eTe={};eTe={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 tTe={};tTe={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 gTe={};gTe={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 ITe={};ITe={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 iTe={};iTe={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 nTe={};nTe={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 CTe={};CTe={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 rTe={};rTe={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 oTe={};oTe={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}」。`};gY={"ar-AE":RHe,"bg-BG":WHe,"cs-CZ":XHe,"da-DK":HHe,"de-DE":THe,"el-GR":NHe,"en-US":kHe,"es-ES":YHe,"et-EE":KHe,"fi-FI":xHe,"fr-FR":DHe,"he-IL":FHe,"hr-HR":EHe,"hu-HU":MHe,"it-IT":zHe,"ja-JP":PHe,"ko-KR":JHe,"lt-LT":OHe,"lv-LV":_He,"nb-NO":LHe,"nl-NL":UHe,"pl-PL":QHe,"pt-BR":jHe,"pt-PT":$He,"ro-RO":qHe,"ru-RU":eTe,"sk-SK":tTe,"sl-SI":gTe,"sr-SP":ITe,"sv-SE":iTe,"tr-TR":nTe,"uk-UA":CTe,"zh-CN":rTe,"zh-TW":oTe};function sog(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=hy(A8(gY)),n=g.selectionManager.rawSelection,C=U.useRef(n);aHe(()=>{var r;if(!g.selectionManager.isFocused){C.current=n;return}let o=Yce(n,C.current),a=Yce(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&&vHe(A.join(" ")),C.current=n},[n])}function Yce(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 log(e){let g=hy(A8(gY)),I=crg(),i=(I==="pointer"||I==="virtual"||I==null)&&typeof window<"u"&&"ontouchstart"in window,n=U.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 qk(n)}function cog(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=ZHe({usage:"search",sensitivity:"base"}),{direction:c}=vm(),u=g.selectionManager.disabledBehavior,d=U.useMemo(()=>n||new VHe({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}=nog({ref:I,selectionManager:A,keyboardDelegate:d,isVirtualized:i,scrollRef:r}),m=Fh(e.id);s8.set(g,{keyboardDelegate:d,actions:{onRowAction:a,onCellAction:s}});let f=log({selectionManager:A,hasItemActions:!!(a||s)}),b=YA(e,{labelable:!0}),p=U.useCallback(G=>{if(A.isFocused){G.currentTarget.contains(G.target)||A.setFocused(!1);return}G.currentTarget.contains(G.target)&&A.setFocused(!0)},[A]),y=U.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=Nrg(I,{isDisabled:g.collection.size!==0}),B=Gi(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),sog({getRowText:o},g),{gridProps:B}}function uog(){return{rowGroupProps:{role:"rowgroup"}}}function dog(e,g,I){let{node:i,isVirtualized:n,shouldSelectOnPressUp:C,onAction:r}=e,{actions:{onRowAction:o}}=s8.get(g),{itemProps:a,...s}=wHe({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 aTe(e,g,I){let{node:i,isVirtualized:n,focusMode:C="child",shouldSelectOnPressUp:r,onAction:o}=e,{direction:a}=vm(),{keyboardDelegate:s,actions:{onCellAction:A}}=s8.get(g),l=U.useRef(null),c=()=>{let p=jr(I.current);if(C==="child"){if(I.current.contains(document.activeElement)&&I.current!==document.activeElement)return;let y=g.selectionManager.childFocusStrategy==="last"?OF(p):p.firstChild();if(y){gr(y);return}}(l.current!=null&&i.key!==l.current||!I.current.contains(document.activeElement))&&gr(I.current)},{itemProps:u,isPressed:d}=wHe({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=Gi(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||g.isKeyboardNavigationDisabled)return;let y=jr(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(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyLeftOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="rtl"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?y.firstChild():OF(y),Z&&(gr(Z),Ll(Z,{containingElement:_l(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(),gr(Z),Ll(Z,{containingElement:_l(I.current)});else{if(s.getKeyRightOf(i.key)!==i.key)break;p.preventDefault(),p.stopPropagation(),C==="cell"&&a==="ltr"?(gr(I.current),Ll(I.current,{containingElement:_l(I.current)})):(y.currentNode=I.current,Z=a==="rtl"?OF(y):y.firstChild(),Z&&(gr(Z),Ll(Z,{containingElement:_l(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){n8()||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 OF(e){let g,I;do I=e.lastChild(),I&&(g=I);while(I);return g}function hog(e,g){let{key:I}=e,i=g.selectionManager,n=Fh(),C=!g.selectionManager.canSelectItem(I),r=g.selectionManager.isSelected(I),o=()=>i.select(I);const a=hy(A8(gY));return{checkboxProps:{id:n,"aria-label":a.format("select"),isSelected:r,isDisabled:C,onChange:o}}}let mog=!1;function DH(){return mog}function l8(e){return e&&e.__esModule?e.default:e}const c8=new WeakMap;function S_(e){return typeof e=="string"?e.replace(/\s*/g,""):""+e}function fog(e,g){let I=c8.get(e);if(!I)throw new Error("Unknown grid");return`${I}-${S_(g)}`}function ATe(e,g,I){let i=c8.get(e);if(!i)throw new Error("Unknown grid");return`${i}-${S_(g)}-${S_(I)}`}function sTe(e,g){return[...e.collection.rowHeaderColumnKeys].map(I=>ATe(e,g,I)).join(" ")}var IY={},lTe={};lTe={ascending:"تصاعدي",ascendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تصاعدي`,columnSize:e=>`${e.value} بالبكسل`,descending:"تنازلي",descendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var cTe={};cTe={ascending:"възходящ",ascendingSort:e=>`сортирано по колона ${e.columnName} във възходящ ред`,columnSize:e=>`${e.value} пиксела`,descending:"низходящ",descendingSort:e=>`сортирано по колона ${e.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var uTe={};uTe={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 dTe={};dTe={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 hTe={};hTe={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 mTe={};mTe={ascending:"αύξουσα",ascendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε αύξουσα σειρά`,columnSize:e=>`${e.value} pixel`,descending:"φθίνουσα",descendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var fTe={};fTe={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 pTe={};pTe={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 bTe={};bTe={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 yTe={};yTe={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 ZTe={};ZTe={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 GTe={};GTe={ascending:"עולה",ascendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר עולה`,columnSize:e=>`${e.value} פיקסלים`,descending:"יורד",descendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var vTe={};vTe={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 BTe={};BTe={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 STe={};STe={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 wTe={};wTe={ascending:"昇順",ascendingSort:e=>`列 ${e.columnName} を昇順で並べ替え`,columnSize:e=>`${e.value} ピクセル`,descending:"降順",descendingSort:e=>`列 ${e.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var VTe={};VTe={ascending:"오름차순",ascendingSort:e=>`${e.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:e=>`${e.value} 픽셀`,descending:"내림차순",descendingSort:e=>`${e.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var RTe={};RTe={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 WTe={};WTe={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 XTe={};XTe={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 HTe={};HTe={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 TTe={};TTe={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 NTe={};NTe={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 kTe={};kTe={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 YTe={};YTe={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 KTe={};KTe={ascending:"возрастание",ascendingSort:e=>`сортировать столбец ${e.columnName} в порядке возрастания`,columnSize:e=>`${e.value} пикс.`,descending:"убывание",descendingSort:e=>`сортировать столбец ${e.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var xTe={};xTe={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 DTe={};DTe={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 FTe={};FTe={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 ETe={};ETe={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 MTe={};MTe={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 zTe={};zTe={ascending:"висхідний",ascendingSort:e=>`відсортовано за стовпцем ${e.columnName} у висхідному порядку`,columnSize:e=>`${e.value} пікс.`,descending:"низхідний",descendingSort:e=>`відсортовано за стовпцем ${e.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var PTe={};PTe={ascending:"升序",ascendingSort:e=>`按列 ${e.columnName} 升序排序`,columnSize:e=>`${e.value} 像素`,descending:"降序",descendingSort:e=>`按列 ${e.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var JTe={};JTe={ascending:"遞增",ascendingSort:e=>`已依據「${e.columnName}」欄遞增排序`,columnSize:e=>`${e.value} 像素`,descending:"遞減",descendingSort:e=>`已依據「${e.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};IY={"ar-AE":lTe,"bg-BG":cTe,"cs-CZ":uTe,"da-DK":dTe,"de-DE":hTe,"el-GR":mTe,"en-US":fTe,"es-ES":pTe,"et-EE":bTe,"fi-FI":yTe,"fr-FR":ZTe,"he-IL":GTe,"hr-HR":vTe,"hu-HU":BTe,"it-IT":STe,"ja-JP":wTe,"ko-KR":VTe,"lt-LT":RTe,"lv-LV":WTe,"nb-NO":XTe,"nl-NL":HTe,"pl-PL":TTe,"pt-BR":NTe,"pt-PT":kTe,"ro-RO":YTe,"ru-RU":KTe,"sk-SK":xTe,"sl-SI":DTe,"sr-SP":FTe,"sv-SE":ETe,"tr-TR":MTe,"uk-UA":zTe,"zh-CN":PTe,"zh-TW":JTe};class pog extends VHe{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=As(wi(I,this.collection));if(i)return i.key;let n=this.getFirstKey();if(n==null)return;let C=this.collection.getItem(n);return Ul(wi(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 wi(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=[...wi(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 wi(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 bog(e,g,I){let{keyboardDelegate:i,isVirtualized:n,layout:C}=e,r=ZHe({usage:"search",sensitivity:"base"}),{direction:o}=vm(),a=g.selectionManager.disabledBehavior,s=U.useMemo(()=>i||new pog({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=Fh(e.id);c8.set(g,A);let{gridProps:l}=cog({...e,id:A,keyboardDelegate:s},g,I);n&&(l["aria-rowcount"]=g.collection.size+g.collection.headerRows.length),DH()&&"expandedKeys"in g&&(l.role="treegrid");let{column:c,direction:u}=g.sortDescriptor||{},d=hy(l8(IY)),h=U.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=qk(h);return aHe(()=>{vHe(h,"assertive",500)},[h]),{gridProps:Gi(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function yog(e,g,I){var i,n;let{node:C}=e,r=C.props.allowsSorting,{gridCellProps:o}=aTe({...e,focusMode:"child"},g,I),a=C.props.isSelectionCell&&g.selectionManager.selectionMode==="single",{pressProps:s}=I8({isDisabled:!r||a,onPress(){g.sort(C.key)},ref:I}),{focusableProps:A}=bHe({},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&&!TH()&&(l=c?u:"none");let d=hy(l8(IY)),h;r&&(h=`${d.format("sortable")}`,c&&u&&TH()&&(h=`${h}, ${d.format(u)}`));let m=qk(h),f=g.collection.size===0;return U.useEffect(()=>{f&&g.selectionManager.focusedKey===C.key&&g.selectionManager.setFocusedKey(null)},[f,g.selectionManager,C.key]),{columnHeaderProps:{...Gi(o,s,A,m,f&&{tabIndex:-1}),role:"columnheader",id:fog(g,C.key),"aria-colspan":C.colspan&&C.colspan>1?C.colspan:null,"aria-sort":l}}}const Kce={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function Zog(e,g,I){let{node:i,isVirtualized:n}=e,{rowProps:C,...r}=dog(e,g,I),{direction:o}=vm();n&&!(DH()&&"expandedKeys"in g)?C["aria-rowindex"]=i.index+1+g.collection.headerRows.length:delete C["aria-rowindex"];let a={};if(DH()&&"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===Kce.expand[o]&&g.selectionManager.focusedKey===u.key&&d&&g.expandedKeys!=="all"&&!g.expandedKeys.has(u.key)||h.key===Kce.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?yc(g.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:yc(g.keyMap.get(g.collection.body.key).childNodes).indexOfType+1}}}let c=r.hasAction?PCg(i.props):{};return{rowProps:{...Gi(C,a,c),"aria-labelledby":sTe(g,i.key)},...r}}function Gog(e,g,I){let{node:i,isVirtualized:n}=e,C={role:"row"};return n&&!(DH()&&"expandedKeys"in g)&&(C["aria-rowindex"]=i.index+1),{rowProps:C}}function vog(e,g,I){let{gridCellProps:i,isPressed:n}=aTe(e,g,I),C=e.node.column.key;return g.collection.rowHeaderColumnKeys.has(C)&&(i.role="rowheader",i.id=ATe(g,e.node.parentKey,C)),{gridCellProps:i,isPressed:n}}function Bog(e,g){let{key:I}=e;const{checkboxProps:i}=hog(e,g);return{checkboxProps:{...i,"aria-labelledby":`${i.id} ${sTe(g,I)}`}}}function Sog(e){let{isEmpty:g,isSelectAll:I,selectionMode:i}=e.selectionManager;return{checkboxProps:{"aria-label":hy(l8(IY)).format(i==="single"?"select":"selectAll"),isSelected:I,isDisabled:i!=="multiple"||e.collection.size===0,isIndeterminate:!g&&!I,onChange:()=>e.selectionManager.toggleSelectAll()}}}function OTe(){return uog()}var _Te={exports:{}},LTe={};/** +- 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"}},Otg={$ref:ztg,$schema:Ptg,definitions:Jtg};function _tg(e){return c2e(Otg,e)}function c2e(e,g,i=!1){const I=new C6e({extendRefs:!0}).compile(e),n=I(g);let r="",C="";return I.errors&&(C=JSON.stringify(I.errors,null,2),i||console.warn(C),r="⚠️ Some properties are incorrectly used."),{state:n?"success":"warn",message:r,details:C}}function u2e(e){let g=!0;const i=[];return N0(e).forEach(n=>{!J$(n)&&n.mark!=="brush"&&n.mark!=="rule"&&(i.push("genomic type is not encoded to either a x- or y- axis"),g=!1);const r=n.color;n.mark==="line"&&ut(r)&&r.type==="quantitative"&&(i.push("`line` mark cannot be used with `quantitative` value"),g=!1)}),{valid:g,errorMessages:i}}function J$(e){let g;return["x","y","xe","ye","x1","y1","x1e","y1e"].reverse().forEach(i=>{const I=e[i];ut(I)&&I.type==="genomic"&&(g=I)}),g}function d2e(e){let g;return["x","xe","y","ye","x1","y1","x1e","y1e"].reverse().forEach(i=>{const I=e[i];ut(I)&&I.type==="genomic"&&(g=i)}),g}const Ltg=[{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 Utg(e,g){P9(e,(i,I,n)=>{var r,C;if(!wje(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:(r=i.width)!=null?r:100,height:(C=i.height)!=null?C: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 Ile=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],Zo={color:Ile[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Ile,quantitativeSizeRange:[2,6]},Qtg={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:{...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:"normal"},brush:{...Zo,color:"gray",opacity:.3,stroke:"black",strokeWidth:1}},nle=["#E79F00","#029F73","#0072B2","#CB7AA7","#D45E00","#57B4E9","#EFE441"],jtg={color:nle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:nle,quantitativeSizeRange:[2,6]},Go={...jtg,stroke:"white"},$tg={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:{...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:"lightgray",opacity:.3,stroke:"white",strokeWidth:1}},rle=["#D19000","#008F67","#005F96","#B86E97","#B55100","#4793BF","#C9C03"],vo={color:rle[0],size:1,stroke:"#3C3C3C",strokeWidth:0,opacity:1,nominalColorRange:rle,quantitativeSizeRange:[2,6]},qtg={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:{...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:"#3C3C3C",strokeWidth:1}},Cle=["#F66A62","#05B230","#5692FF","#D764D6","#86E9D4","#6E6AD7","#FFFB00"],Bo={color:Cle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Cle,quantitativeSizeRange:[2,6]},egg={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:{...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:"bold"},brush:{...Bo,color:"black",opacity:.3,stroke:"black",strokeWidth:1}},ole=["#37E649","#ED2D44","#AEAFEA","#EBAEAE","#CE7B3D","#8743E0","#5233F0"],So={color:ole[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ole,quantitativeSizeRange:[2,6]},tgg={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:{...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:"bold"},brush:{...So,color:"white",opacity:.3,stroke:"black",strokeWidth:1}},ale=["#CD9B1D","#8A668B","#40E0D0","#FF6969","#666666","#FAC902","#FE0000","#CC96CD","#D9D9D9"],wo={color:ale[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:ale,quantitativeSizeRange:[2,6]},ggg={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:{...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:"gray",opacity:.3,stroke:"black",strokeWidth:1}},Ale=["#3A62FE","#F85353","#3A62FE","#F85353","#DCA326","#03BF06","#BABABA"],Ro={color:Ale[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:Ale,quantitativeSizeRange:[2,6]},igg={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:{...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:"#c5d5d9",opacity:.3,stroke:"black",strokeWidth:1}},sle=["#3A5FCD","#FFA54E","#8FBC8F","#B6709B","#EE6A50","#CCB79E","#DADA8F","#00CDCC","#EED5D2","#CD8EDD","#9ACD31","#D1BEA8","#FFB6C0"],Vo={color:sle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:sle,quantitativeSizeRange:[2,6]},Igg={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:{...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:"gray",opacity:.3,stroke:"black",strokeWidth:1}},lle=["#6E12AC","#15C250","#E70FB1","#FF8E55","#A3B8F3","#DE5E59","#77AAAA","#F5CCCA"],Wo={color:lle[0],size:1,stroke:"black",strokeWidth:0,opacity:1,nominalColorRange:lle,quantitativeSizeRange:[2,6]},ngg={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:{...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:"gray",opacity:.3,stroke:"gray",strokeWidth:1}},cle=["#ED7D31","#4472C4","#FFC207","#76AE4F","#9E480E","#A5A5A5","#4472C4","#264378","#76AE4F","#5B9CD5"],Xo={color:cle[0],size:1,stroke:"#5A5A5A",strokeWidth:0,opacity:1,nominalColorRange:cle,quantitativeSizeRange:[2,6]},rgg={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:{...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:"#5A5A5A",opacity:.3,stroke:"#5A5A5A",strokeWidth:1}},ule=["#4185f4","#DB4437","#F4B400","#0D9D58","#AA30C3","#FF6E02","#CBC74C"],Ho={color:ule[0],size:2,stroke:"black",strokeWidth:.3,opacity:1,nominalColorRange:ule,quantitativeSizeRange:[2,6]},Cgg={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:{...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:"#999999",opacity:.3,stroke:"black",strokeWidth:.7}},i_={light:Qtg,dark:$tg,warm:qtg,ggplot:egg,igv:tgg,ensembl:ggg,jbrowse:igg,ucsc:Igg,washu:ngg,excel:rgg,google:Cgg};function I_(e){return Object.keys(i_).indexOf(e)!==-1}function fG(e){return I_(e)?i_[e]:i_.light}function O$(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 ogg=200,agg=6,Agg=2,h2e=7829367,sgg=' ',lgg={type:"axis-track",datatype:["multivec","epilogos"],local:!1,orientation:"1d-horizontal",thumbnail:new DOMParser().parseFromString(sgg,"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:h2e}},cgg=(e,g,i)=>{const{absToChr:I,colorToHex:n,pixiTextToSvg:r,svgLine:C,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=Fs({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=ogg,this.tickHeight=agg,this.tickTextSeparation=Agg,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={...bi(m).size},p=[];Object.keys(bi(m).size).forEach(y=>{f[y]={chr:y,pos:bi(m).size[y]}}),Object.keys(bi(m).interval).forEach(y=>{p.push({chr:y,pos:bi(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):h2e,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=eqe(l,u),h=c0e(","),m=u0e(`,.${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=qd().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 V=R-u;R=u,w-=V}const S=[],X=b+G.height/2+3;for(let V=R;V>=w;V-=v/10){const H=Mt(V,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 x6e;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=r(d.text);u.appendChild(h)}),Object.values(this.tickTexts).forEach(d=>{d.filter(h=>h.visible).forEach(h=>{if(!h.tickLine)return;let m=r(h);u.appendChild(m),m=C(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},dle=O$(lgg,cgg);function n_(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 r,C;super(...n),Ct(this,"circularBrushData"),Ct(this,"prevExtent");const[o,a]=n,{registerViewportChanged:s,removeViewportChanged:A,setDomainsCallback:l}=o;this.uid=ln(),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=sqe().innerRadius((r=this.options.innerRadius)!=null?r:100).outerRadius((C=this.options.outerRadius)!=null?C: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[r,C]=n,o=0;for(;(r>Math.PI*2||C>Math.PI*2||r<0||C<0)&&!(o++>10);)r>Math.PI*2||C>Math.PI*2?(r-=Math.PI*2,C-=Math.PI*2):(r<0||C<0)&&(r+=Math.PI*2,C+=Math.PI*2);return[r,C].sort((a,s)=>a-s)}updateBrush(n){let[r,C]=n;if(r<=gn&&C<=gn||r>=Math.PI*2-gn&&C>=Math.PI*2-gn){this.gBrush.attr("visibility","hidden");return}rMath.PI*2-gn&&(r=Math.PI*2-gn),CMath.PI*2-gn&&(C=Math.PI*2-gn),this.circularBrushData=this.getBrushData(n),this.gBrush.data(this.circularBrushData).attr("d",this.brush).attr("visibility","visible")}dragged(){const n=C=>{this.startEvent=C.sourceEvent,this.prevExtent=[this.circularBrushData[0].startAngle,this.circularBrushData[0].endAngle]},r=(C,o)=>{const[a,s]=this.position,[A,l]=this.dimensions,c=C.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,bR?(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,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",r)}draw(){if(!this._xScale||!this.yScale||!this.viewportXDomain||!this.viewportYDomain)return;const n=this._xScale(this.viewportXDomain[0]),r=this._xScale(this.viewportXDomain[1]),[C]=this.dimensions;let o=jg(n,C,this.options.startAngle,this.options.endAngle)+Math.PI/2,a=jg(r,C,this.options.startAngle,this.options.endAngle)+Math.PI/2;[a,o]=this.cropExtent([a,o]),this.updateBrush([a,o])}viewportChanged(n,r){const C=n.domain(),o=r.domain();this.viewportXDomain=C,this.viewportYDomain=o,this.draw()}remove(){this.removeViewportChanged(this.uid),super.remove()}rerender(){}zoomed(n,r){this.xScale(n),this.yScale(r),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 ugg=' ';n_.config={type:"brush-track",datatype:["projection"],local:!1,projection:!0,orientation:"2d",thumbnail:new DOMParser().parseFromString(ugg,"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 hle=3,dgg={color:"#777",stroke:"#777",strokeWidth:1,strokeOpacity:.7,opacity:.3};class hgg{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=lqe(),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({},dgg,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,r=C=>Math.abs(C.end-C.start);return this.brushSelection.data(this.data).attr("transform",C=>`translate(${i+C.start}, ${I+1})`).attr("width",C=>`${r(C)}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",C=>C.type==="body"?this.style.opacity:0).attr("stroke-opacity",C=>C.type==="body"?this.style.strokeOpacity:0).attr("cursor",C=>C.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-hle,end:g},{type:"end",cursor:"ew-resize",start:i,end:i+hle}]}onDrag(){const g=I=>{this.startEvent=I.sourceEvent,this.prevExtent=this.range},i=(I,n)=>{var r;const C=I.sourceEvent.layerX-this.startEvent.layerX;let[o,a]=(r=this.prevExtent)!=null?r:[0,0];n.type==="body"?(o+=C,a+=C):n.type==="start"?o+=C:n.type==="end"&&(a+=C),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 mgg=([e,g],[i,I],[n,r],[C,o])=>{const a=Math.sqrt((e-i)**2+(g-I)**2);if(aMath.sqrt((e-i)**2+(g-I)**2)e<=i&&i<=g,pgg=(e,g,i=5)=>r_(e,g-i)&&r_(e,g+i),bgg=(e,g)=>g.filter((i,I)=>I%2===0).every(i=>r_(e,i)),ygg=([e,g],i,I=5)=>{let n,r,C,o,a=!1;for(let s=0;s0?h=Math.sqrt((g-o)**2+(e-C)**2):d<0?h=Math.sqrt((g-r)**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,r,C,o=!1;for(let a=0,s=i.length-2;ag!=C>g&&e<(r-I)*(g-n)/(C-n)+I&&(o=!o),s=a;return o};class Ggg{constructor(){Ct(this,"data"),this.data=[]}size(){return this.data.length}addPolygonBasedEvent(g,i){this.data.push({uid:ln(),type:"polygon",value:g,polygon:i})}addPointBasedEvent(g,i){this.data.push({uid:ln(),type:"point",value:g,polygon:i})}addLineBasedEvent(g,i){this.data.push({uid:ln(),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(r=>this.isMouseWithin(r,g,i))}findAll(g,i,I=!1){const n=Array.from(this.data);return I&&n.reverse(),n.filter(r=>this.isMouseWithin(r,g,i))}getSiblings(g,i){const I=[],n=Array.from(new Set(g.map(r=>r.uid)));return g.forEach(r=>{const C=r.value[i];C&&I.push(...this.data.filter(o=>o.value[i]===C&&n.indexOf(o.uid)===-1))}),I}isMouseWithin(g,i,I){switch(g.type){case"point":return fgg([i,I],g.polygon);case"line":return ygg([i,I],g.polygon);case"polygon":default:return Zgg([i,I],g.polygon)}}findAllWithinRange(g,i,I=!1){const n=Array.from(this.data);return I&&n.reverse(),n.filter(r=>this.isWithinRange(r,g,i))}isWithinRange(g,i,I){switch(g.type){case"point":return pgg([i,I],g.polygon[0],g.polygon[2]);case"line":case"polygon":default:return bgg([i,I],g.polygon)}}}const m2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29tbW9uSlMgPSAoY2IsIG1vZCkgPT4gZnVuY3Rpb24gX19yZXF1aXJlKCkgewogICAgcmV0dXJuIG1vZCB8fCAoMCw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ckNvZGVBdChpMiArIDEpXSA8PCA0IHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMildID4+IDI7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCA+PiA4ICYgMjU1OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgJiAyNTU7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhcnI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJpcGxldFRvQmFzZTY0KG51bSkgewogICAgICAgIHJldHVybiBsb29rdXBbbnVtID4+IDE4ICYgNjNdICsgbG9va3VwW251bSA+PiAxMiAmIDYzXSArIGxvb2t1cFtudW0gPj4gNiAmIDYzXSArIGxvb2t1cFtudW0gJiA2M107CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZW5jb2RlQ2h1bmsodWludDgsIHN0YXJ0LCBlbmQpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBvdXRwdXQgPSBbXTsKICAgICAgICBmb3IgKHZhciBpMiA9IHN0YXJ0OyBpMiA8IGVuZDsgaTIgKz0gMykgewogICAgICAgICAgdG1wID0gKHVpbnQ4W2kyXSA8PCAxNiAmIDE2NzExNjgwKSArICh1aW50OFtpMiArIDFdIDw8IDggJiA2NTI4MCkgKyAodWludDhbaTIgKyAyXSAmIDI1NSk7CiAgICAgICAgICBvdXRwdXQucHVzaCh0cmlwbGV0VG9CYXNlNjQodG1wKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBvdXRwdXQuam9pbigiIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUJ5dGVBcnJheSh1aW50OCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIGxlbjIgPSB1aW50OC5sZW5ndGg7CiAgICAgICAgdmFyIGV4dHJhQnl0ZXMgPSBsZW4yICUgMzsKICAgICAgICB2YXIgcGFydHMgPSBbXTsKICAgICAgICB2YXIgbWF4Q2h1bmtMZW5ndGggPSAxN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5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMud3JpdGUgPSBmdW5jdGlvbihidWZmZXIsIHZhbHVlLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtLCBjOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgcnQgPSBtTGVuID09PSAyMyA/IE1hdGgucG93KDIsIC0yNCkgLSBNYXRoLnBvdygyLCAtNzcpIDogMDsKICAgICAgICB2YXIgaSA9IGlzTEUgPyAwIDogbkJ5dGVzIC0gMTsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAxIDogLTE7CiAgICAgICAgdmFyIHMgPSB2YWx1ZSA8IDAgfHwgdmFsdWUgPT09IDAgJiYgMSAvIHZhbHVlIDwgMCA/IDEgOiAwOwogICAgICAgIHZhbHVlID0gTWF0aC5hYnModmFsdWUpOwogICAgICAgIGlmIChpc05hTih2YWx1ZSkgfHwgdmFsdWUgPT09IEluZmluaXR5KSB7CiAgICAgICAgICBtID0gaXNOYU4odmFsdWUpID8gMSA6IDA7CiAgICAgICAgICBlID0gZU1heDsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZSA9IE1hdGguZmxvb3IoTWF0aC5sb2codmFsdWUpIC8gTWF0aC5MTjIpOwogICAgICAgICAgaWYgKHZhbHVlICogKGMgPSBNYXRoLnBvdygyLCAtZSkpIDwgMSkgewogICAgICAgICAgICBlLS07CiAgICAgICAgICAgIGMgKj0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICB2YWx1ZSArPSBydCAvIGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YWx1ZSArPSBydCAqIE1hdGgucG93KDIsIDEgLSBlQmlhcyk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodmFsdWUgKiBjID49IDIpIHsKICAgICAgICAgICAgZSsrOwogICAgICAgICAgICBjIC89IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IGVNYXgpIHsKICAgICAgICAgICAgbSA9IDA7CiAgICAgICAgICAgIGUgPSBlTWF4OwogICAgICAgICAgfSBlbHNlIGlmIChlICsgZUJpYXMgPj0gMSkgewogICAgICAgICAgICBtID0gKHZhbHVlICogYyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSBlICsgZUJpYXM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtID0gdmFsdWUgKiBNYXRoLnBvdygyLCBlQmlhcyAtIDEpICogTWF0aC5wb3coMiwgbUxlbik7CiAgICAgICAgICAgIGUgPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKDsgbUxlbiA+PSA4OyBidWZmZXJbb2Zmc2V0ICsgaV0gPSBtICYgMjU1LCBpICs9IGQsIG0gLz0gMjU2LCBtTGVuIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgZSA9IGUgPDwgbUxlbiB8IG07CiAgICAgICAgZUxlbiArPSBtTGVuOwogICAgICAgIGZvciAoOyBlTGVuID4gMDsgYnVmZmVyW29mZnNldCArIGldID0gZSAmIDI1NSwgaSArPSBkLCBlIC89IDI1NiwgZUxlbiAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGJ1ZmZlcltvZmZzZXQgKyBpIC0gZF0gfD0gcyAqIDEyODsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL2J1ZmZlckA2LjAuMy9ub2RlX21vZHVsZXMvYn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VpbnQ4QXJyYXkpIHN1cHBvcnQgd2hpY2ggaXMgcmVxdWlyZWQgYnkgYGJ1ZmZlcmAgdjUueC4gVXNlIGBidWZmZXJgIHY0LnggaWYgeW91IHJlcXVpcmUgb2xkIGJyb3dzZXIgc3VwcG9ydC4iKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB0eXBlZEFycmF5U3VwcG9ydCgpIHsKICAgICAgICB0cnkgewogICAgICAgICAgY29uc3QgYXJyID0gbmV3IFVpbnQ4QXJyYXkoMSk7CiAgICAgICAgICBjb25zdCBwcm90byA9IHsgZm9vOiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgcmV0dXJuIDQyOwogICAgICAgICAgfSB9OwogICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKHByb3RvLCBVaW50OEFycmF5LnByb3RvdHlwZSk7CiAgICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXI4LnByb3RvdHlwZSwgInBhcmVudCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjgucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ5dGVPZmZzZXQ7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgZnVuY3Rpb24gY3JlYXRlQnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPiBLX01BWF9MRU5HVEgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCdUaGUgdmFsdWUgIicgKyBsZW5ndGggKyAnIiBpcyBpbnZhbGlkIGZvciBvcHRpb24gInNpemUiJyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGJ1ZiA9IG5ldyBVaW50OEFycmF5KGxlbmd0aCk7CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1ZiwgQnVmZmVyOC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gQnVmZmVyOChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIHN0cmluZy4gUmVjZWl2ZWQgdHlwZSBudW1iZXInKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShhcmcpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbShhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCk7CiAgICAgIH0KICAgICAgQnVmZmVyOC5wb29sU2l6ZSA9IDgxOTI7CiAgICAgIGZ1bmN0aW9uIGZyb20odmFsdWUsIGVuY29kaW5nT3JPZmZz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mV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja2VkKGxlbmd0aCkgewogICAgICAgIGlmIChsZW5ndGggPj0gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQXR0ZW1wdCB0byBhbGxvY2F0ZSBCdWZmZXIgbGFyZ2VyIHRoYW4gbWF4aW11bSBzaXplOiAweCIgKyBLX01BWF9MRU5HVEgudG9TdHJpbmcoMTYpICsgIiBieXRlcyIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuZ3RoIHwgMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBTbG93QnVmZmVyKGxlbmd0aCkgewogICAgICAgIGlmICgrbGVuZ3RoICE9IGxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJ1ZmZlcjguYWxsb2MoK2xlbmd0aCk7CiAgICAgIH0KICAgICAgQnVmZmVyOC5pc0J1ZmZlciA9IGZ1bmN0aW9uIGlzQnVmZmVyKGIpIHsKICAgICAgICByZXR1cm4gYiAhPSBudWxsICYmIGIuX2lzQnVmZmVyID09PSB0cnVlICYmIGIgIT09IEJ1ZmZlcjgucHJvdG90eXBlOwogICAgICB9OwogICAgICBCdWZmZXI4LmNvbXBhcmUgPSBmdW5jdGlvbiBjb21wYXJlKGEsIGIpIHsKICAgICAgICBpZiAoaXNJbnN0YW5jZShhLCBVaW50OEFycmF5KSkKICAgICAgICAgIGEgPSBCdWZmZXI4LmZyb20oYSwgYS5vZmZzZXQsIGEuYnl0ZUxlbmd0aCk7CiAgICAgICAgaWYgKGlzSW5zdGFuY2UoYiwgVWludDhBcnJheSkpCiAgICAgICAgICBiID0gQnVmZmVyOC5mcm9tKGIsIGIub2Zmc2V0LCBiLmJ5dGVMZW5ndGgpOwogICAgICAgIGlmICghQnVmZmVyOC5pc0J1ZmZlcihhKSB8fCAhQnVmZmVyOC5pc0J1ZmZlcihiKSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlICJidWYxIiwgImJ1ZjIiIGFyZ3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjguaXNFbmNvZGluZyA9IGZ1bmN0aW9uIGlzRW5jb2RpbmcoZW5jb2RpbmcpIHsKICAgICAgICBzd2l0Y2ggKFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKSkgewogICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9OwogICAgICBCdWZmZXI4LmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyOC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXI4LmFsbG9jVW5zYWZlKGxlbmd0aCk7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGxldCBidWYgPSBsaXN0W2ldOwogICAgICAgICAgaWYgKGlzSW5zdGFuY2UoYnVmLCBVaW50OEFycmF5KSkgewogICAgICAgICAgICBpZiAocG9zICsgYnVmLmxlbmd0aCA+IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgICAgICBpZiAoIUJ1ZmZlcjguaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjguZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyOC5pc0J1ZmZlcihidWYpKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgIH0KICAgICAgICAgIHBvcyArPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmZmVyOwogICAgICB9OwogICAgICBmdW5jdGlvbiBieXRlTGVuZ3RoKHN0cmluZywgZW5jb2RpbmcpIHsKICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcihzdHJpbmcpKSB7CiAgICAgICAgICByZXR1cm4gc3RyaW5nLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKEFycmF5QnVmZmVyLmlzVmlldyhzdHJpbmcpIHx8IGlzSW5zdGFuY2Uoc3RyaW5nLCBBcnJheUJ1ZmZlcikpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcuYnl0ZUxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiBzdHJpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvbmUgb2YgdHlwZSBzdHJpbmcsIEJ1ZmZlciwgb3IgQXJyYXlCdWZmZXIuIFJlY2VpdmVkIHR5cGUgJyArIHR5cGVvZiBzdHJpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW4gPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGNvbnN0IG11c3RNYXRjaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjguYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5faXNCdWZmZXIgPSB0cnVlOwogICAgICBmdW5jdGlvbiBzd2FwKGIsIG4sIG0pIHsKICAgICAgICBjb25zdCBpID0gYltuXTsKICAgICAgICBiW25dID0gYlttXTsKICAgICAgICBiW21dID0gaTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDIgIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgMTYtYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSAyKSB7CiAgICAgICAgICBzd2FwKHRoaXMsIGksIGkgKyAxKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjgucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUuc3dhcDY0ID0gZnVuY3Rpb24gc3dhcDY0KCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gJSA4ICE9PSAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiQnVmZmVyIHNpemUgbXVzdCBiZSBhIG11bHRpcGxlIG9mIDY0LWJpdHMiKTsKICAgICAgICB9CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW47IGkgKz0gOCkgewogICAgICAgICAgc3dhcCh0aGlzLCBpLCBpICsgNyk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAxLCBpICsgNik7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAyLCBpICsgNSk7CiAgICAgICAgICBzd2FwKHRoaXMsIGkgKyAzLCBpICsgNCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICBCdWZmZXI4LnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgIC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0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb3B5ID0gdGhpcy5zbGljZSh0aGlzU3RhcnQsIHRoaXNFbmQpOwogICAgICAgIGNvbnN0IHRhcmdldENvcHkgPSB0YXJnZXQuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKHRoaXNDb3B5W2ldICE9PSB0YXJnZXRDb3B5W2ldKSB7CiAgICAgICAgICAgIHggPSB0aGlzQ29weVtpXTsKICAgICAgICAgICAgeSA9IHRhcmdldENvcHlbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJpZGlyZWN0aW9uYWxJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgaWYgKGJ1ZmZlci5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHR5cGVvZiBieXRlT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBieXRlT2Zmc2V0OwogICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0ID4gMjE0NzQ4MzY0NykgewogICAgICAgICAgYnl0ZU9mZnNldCA9IDIxNDc0ODM2NDc7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgLTIxNDc0ODM2NDgpIHsKICAgICAgICAgIGJ5dGVPZmZzZXQgPSAtMjE0NzQ4MzY0ODsKICAgICAgICB9CiAgICAgICAgYnl0ZU9mZnNldCA9ICtieXRlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgdmFsID0gQnVmZmVyOC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyOC5pc0J1ZmZlcih2YWwpKSB7CiAgICAgICAgICBpZiAodmFsLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gYXJyYXlJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgICBpZiAodHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmluZGV4T2YgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mLmNhbGwoYnVmZmVyLCB2YWwsIGJ5dGVPZmZzZXQpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJldHVybiBVaW50OEFycmF5LnByb3RvdHlwZS5sYXN0SW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIFt2YWxdLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKTsKICAgICAgICB9CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigidmFsIG11c3QgYmUgc3RyaW5nLCBudW1iZXIgb3IgQnVmZmVyIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXJyYXlJbmRleE9mKGFyciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgbGV0IGluZGV4U2l6ZSA9IDE7CiAgICAgICAgbGV0IGFyckxlbmd0aCA9IGFyci5sZW5ndGg7CiAgICAgICAgbGV0IHZhbExlbmd0aCA9IHZhbC5sZW5ndGg7CiAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDApIHsKICAgICAgICAgIGVuY29kaW5nID0gU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidWNzMiIgfHwgZW5jb2RpbmcgPT09ICJ1Y3MtMiIgfHwgZW5jb2RpbmcgPT09ICJ1dGYxNmxlIiB8fCBlbmNvZGluZyA9PT0gInV0Zi0xNmxlIikgewogICAgICAgICAgICBpZiAoYXJyLmxlbmd0aCA8IDIgfHwgdmFsLmxlbmd0aCA8IDIpIHsKICAgICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW5kZXhTaXplID0gMjsKICAgICAgICAgICAgYXJyTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIHZhbExlbmd0aCAvPSAyOwogICAgICAgICAgICBieXRlT2Zmc2V0IC89IDI7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHJlYWQoYnVmLCBpMikgewogICAgICAgICAgaWYgKGluZGV4U2l6ZSA9PT0gMSkgewogICAgICAgICAgICByZXR1cm4gYnVmW2kyXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBidWYucmVhZFVJbnQxNkJFKGkyICogaW5kZXhTaXplKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGRpcikgewogICAgICAgICAgbGV0IGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPCBhcnJMZW5ndGg7IGkrKykgewogICAgICAgICAgICBpZiAocmVhZChhcnIsIGkpID09PSByZWFkKHZhbCwgZm91bmRJbmRleCA9PT0gLTEgPyAwIDogaSAtIGZvdW5kSW5kZXgpKSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggPT09IC0xKQogICAgICAgICAgICAgICAgZm91bmRJbmRleCA9IGk7CiAgICAgICAgICAgICAgaWYgKGkgLSBmb3VuZEluZGV4ICsgMSA9PT0gdmFsTGVuZ3RoKQogICAgICAgICAgICAgICAgcmV0dXJuIGZvdW5kSW5kZXggKiBpbmRleFNpemU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgaWYgKGZvdW5kSW5kZXggIT09IC0xKQogICAgICAgICAgICAgICAgaSAtPSBpIC0gZm91bmRJbmRleDsKICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGJ5dGVPZmZzZXQgKyB2YWxMZW5ndGggPiBhcnJMZW5ndGgpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSBhcnJMZW5ndGggLSB2YWxMZW5ndGg7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpID49IDA7IGktLSkgewogICAgICAgICAgICBsZXQgZm91bmQgPSB0cnVlOwogICAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IHZhbExlbmd0aDsgaisrKSB7CiAgICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpICsgaikgIT09IHJlYWQodmFsLCBqKSkgewogICAgICAgICAgICAgICAgZm91bmQgPSBmYWxzZTsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZm91bmQpCiAgICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBCdWZmZXI4LnByb3RvdHlwZS5pbmNsdWRlcyA9I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BzdXBwb3J0ZWQiKTsKICAgICAgICB9CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gdGhpcy5sZW5ndGggLSBvZmZzZXQ7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwIHx8IGxlbmd0aCA+IHJlbWFpbmluZykKICAgICAgICAgIGxlbmd0aCA9IHJlbWFpbmluZzsKICAgICAgICBpZiAoc3RyaW5nLmxlbmd0aCA+IDAgJiYgKGxlbmd0aCA8IDAgfHwgb2Zmc2V0IDwgMCkgfHwgb2Zmc2V0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJBdHRlbXB0IHRvIHdyaXRlIG91dHNpZGUgYnVmZmVyIGJvdW5kcyIpOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgbGV0IGxvd2VyZWRDYXNlID0gZmFsc2U7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyOC5wcm90b3R5cGUudG9KU09OID0gZnVuY3Rpb24gdG9KU09OKCkgewogICAgICAgIHJldHVybiB7CiAgICAgICAgICB0eXBlOiAiQnVmZmVyIiwKICAgICAgICAgIGRhdGE6IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKHRoaXMuX2FyciB8fCB0aGlzLCAwKQogICAgICAgIH07CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFNsaWNlKGJ1Ziwgc3RhcnQsIGVuZCkgewogICAgICAgIGlmIChzdGFydCA9PT0gMCAmJiBlbmQgPT09IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiBiYXNlNjQuZnJvbUJ5dGVBcnJheShidWYpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZXR1cm4gYmFzZTY0LmZyb21CeXRlQXJyYXkoYnVmLnNsaWNlKHN0YXJ0LC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gICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyOC5wcm90b3R5cGUuc2xpY2UgPSBmdW5jdGlvbiBzbGljZShzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgc3RhcnQgPSB+fnN0YXJ0OwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gbGVuIDogfn5lbmQ7CiAgICAgICAgaWYgKHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgKz0gbGVuOwogICAgICAgICAgaWYgKHN0YXJ0IDwgMCkKICAgICAgICAgICA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DsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwICYmIHR5cGVvZiBlbmNvZGluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiZW5jb2RpbmcgbXVzdCBiZSBhIHN0cmluZyIpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZyA9PT0gInN0cmluZyIgJiYgIUJ1ZmZlcjguaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjguaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjguZnJvbSh2YWwsIGVuY29kaW5nKTsKICAgICAgICAgIGNvbnN0IGxlbiA9IGJ5dGVzLmxlbmd0aDsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlIHZhbHVlICInICsgdmFsICsgJyIgaXMgaW52YWxpZCBmb3IgYXJndW1lbnQgInZhbHVlIicpOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGVuZCAtIHN0YXJ0OyArK2kpIHsKICAgICAgICAgICAgdGhpc1tpICsgc3RhcnRdID0gYnl0ZXNbaSAlIGxlbl07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9OwogICAgICB2YXIgZXJyb3JzID0ge307CiAgICAgIGZ1bmN0aW9uIEUoc3ltLCBnZXRNZXNzYWdlLCBCYXNlKSB7CiAgICAgICAgZXJyb3JzW3N5bV0gPSBjbGFzcyBOb2RlRXJyb3IgZXh0ZW5kcyBCYXNlIHsKICAgICAgICAgIGNvbnN0cnVjdG9yKCkgewogICAgICAgICAgICBzdXBlcigpOwogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIm1lc3NhZ2UiLCB7CiAgICAgICAgICAgICAgdmFsdWU6IGdldE1lc3NhZ2UuYXBwbHkodGhpcywgYXJndW1lbnRzKSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHRoaXMubmFtZSA9IGAke3RoaXMubmFtZX0gWyR7c3ltfV1gOwogICAgICAgICAgICB0aGlzLnN0YWNrOwogICAgICAgICAgICBkZWxldGUgdGhpcy5uYW1lOwogICAgICAgICAgfQogICAgICAgICAgZ2V0IGNvZGUoKSB7CiAgICAgICAgICAgIHJldHVybiBzeW07CiAgICAgICAgICB9CiAgICAgICAgICBzZXQgY29kZSh2YWx1ZSkgewogICAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImNvZGUiLCB7CiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgICAgICAgdmFsdWUsCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgICB0b1N0cmluZygpIHsKICAgICAgICAgICAgcmV0dXJuIGAke3RoaXMubmFtZX0gWyR7c3ltfV06ICR7dGhpcy5tZXNzYWdlfWA7CiAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgfQogICAgICBFKCJFUlJfQlVGRkVSX09VVF9PRl9CT1VORFMiLCBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgaWYgKG5hbWUpIHsKICAgICAgICAgIHJldHVybiBgJHtuYW1lfSBpcyBvdXRzaWRlIG9mIGJ1ZmZlciBib3VuZHNgOwogICAgICAgIH0KICAgICAgICByZXR1cm4gIkF0dGVtcHQgdG8gYWNjZXNzIG1lbW9yeSBvdXRzaWRlIGJ1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Q29kZUF0KGkpOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU1Mjk1ICYmIGNvZGVQb2ludCA8IDU3MzQ0KSB7CiAgICAgICAgICAgIGlmICghbGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NjMxOSkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChpICsgMSA9PT0gbGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY29kZVBvaW50IDwgNTYzMjApIHsKICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY29kZVBvaW50ID0gKGxlYWRTdXJyb2dhdGUgLSA1NTI5NiA8PCAxMCB8IGNvZGVQb2ludCAtIDU2MzIwKSArIDY1NTM2OwogICAgICAgICAgfSBlbHNlIGlmIChsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgfQogICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgICBpZiAoY29kZVBvaW50IDwgMTI4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMSkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDIwNDgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDYgfCAxOTIsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgNjU1MzYpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDEyIHwgMjI0LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSA0KSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50ID4+IDE4IHwgMjQwLCBjb2RlUG9pbnQgPj4gMTIgJiA2MyB8IDEyOCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJJbnZhbGlkIGNvZGUgcG9pbnQiKTsKICAgICAgICAgIH0KICAgIC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sgb2Zmc2V0ID49IGRzdC5sZW5ndGggfHwgaSA+PSBzcmMubGVuZ3RoKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGRzdFtpICsgb2Zmc2V0XSA9IHNyY1tpXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaXNJbnN0YW5jZShvYmosIHR5cGUpIHsKICAgICAgICByZXR1cm4gb2JqIGluc3RhbmNlb2YgdHlwZSB8fCBvYmogIT0gbnVsbCAmJiBvYmouY29uc3RydWN0b3IgIT0gbnVsbCAmJiBvYmouY29uc3RydWN0b3IubmFtZSAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lID09PSB0eXBlLm5hbWU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gbnVtYmVySXNOYU4ob2JqKSB7CiAgICAgICAgcmV0dXJuIG9iaiAhPT0gb2JqOwogICAgICB9CiAgICAgIHZhciBoZXhTbGljZUxvb2t1cFRhYmxlID0gZnVuY3Rpb24oKSB7CiAgICAgICAgY29uc3QgYWxwaGFiZXQgPSAiMDEyMzQ1Njc4OWFiY2RlZiI7CiAgICAgICAgY29uc3QgdGFibGUgPSBuZXcgQXJyYXkoMjU2KTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IDE2OyArK2kpIHsKICAgICAgICAgIGNvbnN0IGkxNiA9IGkgKiAxNjsKICAgICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgMTY7ICsraikgewogICAgICAgICAgICB0YWJsZVtpMTYgKyBqXSA9IGFscGhhYmV0W2ldICsgYWxwaGFiZXRbal07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfSgpOwogICAgICBmdW5jdGlvbiBkZWZpbmVCaWdJbnRNZXRob2QoZm4pIHsKICAgICAgICByZXR1cm4gdHlwZW9mIEJpZ0ludCA9PT0gInVuZGVmaW5lZCIgPyBCdWZmZXJCaWdJbnRO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pIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLmRlc2VyaWFsaXplKG1lc3NhZ2UsIGZhbGxiYWNrRGVzZXJpYWxpemVyKTsKICAgICAgICAgIH0sCiAgICAgICAgICBzZXJpYWxpemUoaW5wdXQpIHsKICAgICAgICAgICAgcmV0dXJuIGltcGxlbWVudGF0aW9uLnNlcmlhbGl6ZShpbnB1dCwgZmFsbGJhY2tTZXJpYWxpemVyKTsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMuZXh0ZW5kU2VyaWFsaXplciA9IGV4dGVuZFNlcmlhbGl6ZXI7CiAgICAgIHZhciBEZWZhdWx0RXJyb3JTZXJpYWxpemVyID0gewogICAgICAgIGRlc2VyaWFsaXplKG1lc3NhZ2UpIHsKICAgICAgICAgIHJldHVybiBPYmplY3QuYXNzaWduKEVycm9yKG1lc3NhZ2UubWVzc2FnZSksIHsKICAgICAgICAgICAgbmFtZTogbWVzc2FnZS5uYW1lLAogICAgICAgICAgICBzdGFjazogbWVzc2FnZS5zdGFjawogICAgICAgICAgfSk7CiAgICAgICAgfSwKICAgICAgICBzZXJpYWxpemUoZXJyb3IpIHsKICAgICAgICAgIHJldHVybiB7CiAgICAgICAgICAgIF9fZXJyb3JfbWFya2VyOiAiJCRlcnJvciIsCiAgICAgICAgICAgIG1lc3NhZ2U6IGVycm9yLm1lc3NhZ2UsCiAgICAgICAgICAgIG5hbWU6IGVycm9yLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBlcnJvci5zdGFjawogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBpc1NlcmlhbGl6ZWRFcnJvciA9ICh0aGluZykgPT4gdGhpbmcgJiYgdHlwZW9mIHRoaW5nID09PSAib2JqZWN0IiAmJiAiX19lcnJvcl9tYXJrZXIiIGluIHRoaW5nICYmIHRoaW5nLl9fZXJyb3JfbWFya2VyID09PSAiJCRlcnJvciI7CiAgICA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bGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgICAgcG9zdEpvYlJlc3VsdE1lc3NhZ2Uoam9iVUlELCB0cnVlKTsKICAgICAgICAgICAgICBhY3RpdmVTdWJzY3JpcHRpb25zLmRlbGV0ZShqb2JVSUQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5zZXQoam9iVUlELCBzdWJzY3JpcHRpb24pOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBjb25zdCByZXN1bHQgPSB5aWVsZCBzeW5jUmVzdWx0OwogICAgICAgICAgICAgIHBvc3RKb2JSZXN1bHRNZXNzYWdlKGpvYlVJRCwgdHJ1ZSwgY29tbW9uXzEuc2VyaWFsaXplKHJlc3VsdCkpOwogICAgICAgICAgICB9IGNhdGNoIChlcnJvcikgewogICAgICAgICAgICAgIHBvc3RKb2JFcnJvck1lc3NhZ2Uoam9iVUlELCBjb21tb25fMS5zZXJpYWxpemUoZXJyb3IpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGV4cG9zZTIoZXhwb3NlZCkgewogICAgICAgIGlmICghaW1wbGVtZW50YXRpb25fMS5kZWZhdWx0LmlzV29ya2VyUnVudGltZSgpKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIGluIHRoZSBtYXN0ZXIgdGhyZWFkLiIpOwogICAgICAgIH0KICAgICAgICBpZiAoZXhwb3NlQ2FsbGVkKSB7CiAgICAgICAgICB0aHJvdyBFcnJvcigiZXhwb3NlKCkgY2FsbGVkIG1vcmUgdGhhbiBvbmNlLiBUaGlzIGlzIG5vdCBwb3NzaWJsZS4gUGFzcyBhbiBvYmplY3QgdG8gZXhwb3NlKCkgaWYgeW91IHdhbnQgdG8gZXhwb3NlIG11bHRp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gICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcwogIHZhciByZXF1aXJlX2xvbmcgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vbG9uZ0A0LjAuMC9ub2RlX21vZHVsZXMvbG9uZy9zcmMvbG9uZy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExv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iAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHV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ICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1plcm8oKSkKICAgICAgICAgICAgcmV0dXJuIGRpZ2l0cyArIHJlc3VsdDsKICAgICAgICAgIGVsc2UgewogICAgICAgICAgICB3aGlsZSAoZGlnaXRzLmxlbmd0aCA8IDYpCiAgICAgICAgICAgICAgZGlnaXRzID0gIjAiICsgZGlnaXRzOwogICAgICAgICAgICByZXN1bHQgPSAiIiArIG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ogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzWmVybyA9IGZ1bmN0aW9uIGlzWmVybygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSAwICYmIHRoaXMubG93ID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxeiA9IExvbmdQcm90b3R5cGUuaXNaZXJvOwogICAgICBMb25nUHJvdG90eXBlLmlzTmVnYXRpdmUgPSBmdW5jdGlvbiBpc05lZ2F0aXZlKCkgewogICAgICAgIHJldHVybiAhdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPCAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkICE9PSBvdGhlci51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPj4+IDMxID09PSAxICYmIG90aGVyLmhpZ2ggPj4+IDMxID09PSAxKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIHJldHVybiB0aGlzLmhpZ2ggPT09IG90aGVyL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gICAgYzE2ICY9IDY1NTM1OwogICAgICAgIGMzMiArPSBhMzIgKyBiMzI7CiAgICAgICAgYzQ4ICs9IGMzMiA+Pj4gMTY7CiAgICAgICAgYzMyICY9IDY1NTM1OwogICAgICAgIGM0OCArPSBhNDggKyBiNDg7CiAgICAgICAgYzQ4ICY9IDY1NTM1OwogICAgICAgIHJldHVybiBmcm9tQml0cyhjMTYgPDwgMTYgfCBjMDAsIGM0OCA8PCAxNiB8IGMzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc3VidHJhY3QgPSBmdW5jdGlvbiBzdWJ0cmFjdChzdWJ0cmFoZW5kKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoc3VidHJhaGVuZCkpCiAgICAgICAgICBzdWJ0cmFoZW5kID0gZnJvbVZhbHVlKHN1YnRyYWhlbmQpOwogICAgICAgIHJldHVybiB0aGlzLmFkZChzdWJ0cmFoZW5kLm5lZygpKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zdWIgPSBMb25nUHJvdG90eXBlLnN1YnRyYWN0OwogICAgICBMb25nUHJvdG90eXBlLm11bHRpcGx5ID0gZnVuY3Rpb24gbXVsdGlwbHkobXVsdGlwbGllcikgewogICAgICAgIGlmICh0aGlzLmlzWmVybygpKQogICAgICAgICAgcmV0dXJuIFpFUk87CiAgICAgICAgaWYgKCFpc0xvbmcobXVsdGlwbGllcikpCiAgICAgICAgICBtdWx0aXBsaWVyID0gZnJvbVZhbHVlKG11bHRpcGxpZXIpOwogICAgICAgIGlmICh3YXNtKSB7CiAgICAgICAgICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICB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cGx5OwogICAgICBMb25nUHJvdG90eXBlLmRpdmlkZSA9IGZ1bmN0aW9uIGRpdmlkZShkaXZpc29yKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbnVtQml0cywgdGhpcy5oaWdoIDw8IG51bUJpdHMgfCB0aGlzLmxvdyA+Pj4gMzIgLSBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoMCwgdGhpcy5sb3cgPDwgbnVtQml0cyAtIDMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGwgPSBMb25nUHJvdG90eXBlLnNoaWZ0TGVmdDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0ID0gZnVuY3Rpb24gc2hpZnRSaWdodChudW1CaXRzKSB7CiAgICAgICAgaWYgKGlzTG9uZyhudW1CaXRzKSkKICAgICAgICAgIG51bUJpdHMgPSBudW1CaXRzLnRvSW50KCk7CiAgICAgICAgaWYgKChudW1CaXRzICY9IDYzKSA9PT0gMCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIGVsc2UgaWYgKG51bUJpdHMgPCAzMikKICAgICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyA+Pj4gbnVtQml0cyB8IHRoaXMuaGlnaCA8PCAzMiAtIG51bUJpdHMsIHRoaXMuaGlnaCA+PiBudW1CaXRzLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICBlbHNlCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5oaWdoID4+IG51bUJpdHMgLSAzMiwgdGhpcy5oaWdoID49IDAgPyAwIDogLTEsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnNociA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodDsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQgPSBmdW5jdGlvbiBzaGlmdFJpZ2h0VW5zaWduZWQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJp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ZXMobGUpIHsKICAgICAgICByZXR1cm4gbGUgPyB0aGlzLnRvQnl0ZXNMRSgpIDogdGhpcy50b0J5dGVzQkUoKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gJiAyNTUKICAgICAgICBdOwogICAgICB9OwogICAgICBMb25nNC5mcm9tQnl0ZXMgPSBmdW5jdGlvbiBmcm9tQnl0ZXMyKGJ5dGVzLCB1bnNpZ25lZCwgbGUpIHsKICAgICAgICByZXR1cm4gbGUgPyBMb25nNC5mcm9tQnl0ZXNMRShieXRlcywgdW5zaWduZWQpIDogTG9uZzQuZnJvbUJ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AgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0cy5zaHJpbmtCdWYgPSBmdW5jdGlvbihidWYsIHNpemUpIHsKICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gc2l6ZSkgewogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSkgewogICAgICAgICAgcmV0dXJuIGJ1Zi5zdWJhcnJheSgwLCBzaXplKTsKICAgICAgICB9CiAgICAgICAgYnVmLmxlbmd0aCA9IHNpemU7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgdmFyIGZuVHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBpZiAoc3JjLnN1YmFycmF5ICYmIGRlc3Quc3ViYXJyYXkpIHsKICAgICAgICAgICAgZGVzdC5zZXQoc3JjLnN1YmFycmF5KHNyY19vZmZzLCBzcmNfb2ZmcyArIGxlbiksIGRlc3Rfb2Zmcyk7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICB2YXIgaSwgbCwgbGVuLCBwb3MsIGNodW5rLCByZXN1bHQ7CiAgICAgICAgICBsZW4gPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgbGVuICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXN1bHQgPSBuZXcgVWludDhBcnJheShsZW4pOwogICAgICAgICAgcG9zID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGNodW5rID0gY2h1bmtzW2ldOwogICAgICAgICAgICByZXN1bHQuc2V0KGNodW5rLCBwb3MpOwogICAgICAgICAgICBwb3MgKz0gY2h1bmsubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICB9CiAgICAgIH07CiAgICAgIHZhciBmblVudHlwZWQgPSB7CiAgICAgICAgYXJyYXlTZXQ6IGZ1bmN0aW9uKGRlc3QsIHNyYywgc3JjX29mZnMsIGxlbiwgZGVzdF9vZmZzKSB7CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgcmV0dXJuIFtdLmNvbmNhdC5hcHBseShbXSwgY2h1bmtzKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0cy5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMTYgPSBVaW50MTZBcnJheTsKICAgICAgICAgIGV4cG9ydHMuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5UeXBlZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGV4cG9ydHMuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5CdWYzMiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0cy5hc3NpZ24oZXhwb3J0cywgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMuc2V0VHlwZWQoVFlQRURfT0spOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMKICB2YXIgcmVxdWlyZV90cmVlcyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcyIoZXhwb3J0cykgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBaX0ZJWEVEID0gNDsKICAgICAgdmFyIFpfQklOQVJZID0gMDsKICAgICAgdmFyIFpfVEVYVCA9IDE7CiAgICAgIHZhciBaX1VOS05PV04gPSAyOwogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIHZhciBTVE9SRURfQkxPQ0sgPSAwOwogICAgICB2YXIgU1RBVElDX1RSRUVTID0gMTsKIC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IHw9IHZhbHVlIDw8IHMuYmlfdmFsaWQgJiA2NTUzNTsKICAgICAgICAgIHMuYmlfdmFsaWQgKz0gbGVuZ3RoOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2NvZGUocywgYywgdHJlZSkgewogICAgICAgIHNlbmRfYml0cyhzLCB0cmVlW2MgKiAyXSwgdHJlZVtjICogMiArIDFdKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV9yZXZlcnNlKGNvZGUsIGxlbikgewogICAgICAgIHZhciByZXMgPSAwOwogICAgICAgIGRvIHsKICAgICAgICAgIHJlcyB8PSBjb2RlICYgMTsKICAgICAgICAgIGNvZGUgPj4+PSAxOwogICAgICAgICAgcmVzIDw8PSAxOwogICAgICAgIH0gd2hpbGUgKC0tbGVuID4gMCk7CiAgICAgICAgcmV0dXJuIHJlcyA+Pj4gMTsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV9mbHVzaChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPT09IDE2KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID49IDgpIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWYgJiAyNTU7CiAgICAgICAgICBzLmJpX2J1ZiA+Pj0gODsKICAgICAgICAgIHMuYmlfdmFsaWQgLT0gODsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2JpdGxlbihzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBtYXhfY29kZSA9IGRlc2MubWF4X2NvZGU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZXh0cmEgPSBkZXNjLnN0YXRfZGVzYy5leHRyYV9iaXRzOwogICAgICAgIHZhciBiYXNlID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYmFzZTsKICAgICAgICB2YXIgbWF4X2xlbmd0aCA9IGRlc2Muc3RhdF9kZXNjLm1heF9sZW5ndGg7CiAgICAgICAgdmFyIGg7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIHhiaXRzOwogICAgICAgIHZhciBmOwogICAgICAgIHZhciBvdmVyZmxvdyA9IDA7CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgdHJlZVtzLmhlYXBbcy5oZWFwX21heF0gKiAyICsgMV0gPSAwOwogICAgICAgIGZvciAoaCA9IHMuaGVhcF9tYXggKyAxOyBoIDwgSEVBUF9TSVpFOyBoKyspIHsKICAgICAgICAgIG4gPSBzLmhlYXBbaF07CiAgICAgICAgICBiaXRzID0gdHJlZVt0cmVlW24gKiAyICsgMV0gKiAyICsgMV0gKyAxOwogICAgICAgICAgaWYgKGJpdHMgPiBtYXhfbGVuZ3RoKSB7CiAgICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoOwogICAgICAgICAgICBvdmVyZmxvdysrOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gYml0czsKICAgICAgICAgIGlmIChuID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdKys7CiAgICAgICAgICB4Yml0cyA9IDA7CiAgICAgICAgICBpZiAobiA+PSBiYXNlKSB7CiAgICAgICAgICAgIHhiaXRzID0gZXh0cmFbbiAtIGJhc2VdOwogICAgICAgICAgfQogICAgICAgICAgZiA9IHRyZWVbbiAqIDJdOwogICAgICAgICAgcy5vcHRfbGVuICs9IGYgKiAoYml0cyArIHhiaXRzKTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuICs9IGYgKiAoc3RyZWVbbiAqIDIgKyAxXSArIHhiaXRzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG92ZXJmbG93ID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIGRvIHsKICAgICAgICAgIGJpdHMgPSBtYXhfbGVuZ3RoIC0gMTsKICAgICAgICAgIHdoaWxlIChzLmJsX2NvdW50W2JpdHNdID09PSAwKSB7CiAgICAgICAgICAgIGJpdHMtLTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10tLTsKICAgICAgICAgIHMuYmxfY291bnRbYml0cyArIDFdICs9IDI7CiAgICAgICAgICBzLmJsX2NvdW50W21heF9sZW5ndGhdLS07CiAgICAgICAgICBvdmVyZmxvdyAtPSAyOwogICAgICAgIH0gd2hpbGUgKG92ZXJmbG93ID4gMCk7CiAgICAgICAgZm9yIChiaXRzID0gbWF4X2xlbmd0aDsgYml0cyAhPT0gMDsgYml0cy0tKSB7CiAgICAgICAgICBuID0gcy5ibF9jb3VudFtiaXRzXTsKICAgICAgICAgIHdoaWxlIChuICE9PSAwKSB7CiAgICAgICAgICAgIG0gPSBzLmhlYXBbLS1oXTsKICAgICAgICAgICAgaWYgKG0gPiBtYXhfY29kZSkgewogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh0cmVlW20gKiAyICsgMV0gIT09IGJpdHMpIHsKICAgICAgICAgICAgICBzLm9wdF9sZW4gKz0gKGJpdHMgLSB0cmVlW20gKiAyICsgMV0pICogdHJlZVttICogMl07CiAgICAgICAgICAgICAgdHJlZVttICogMiArIDFdID0gYml0czsKICAgICAgICAgICAgfQogICAgICAgICAgICBuLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgYmxfY291bnQpIHsKICAgICAgICB2YXIgbmV4dF9jb2RlID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgdmFyIGNvZGUgPSAwOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAoYml0cyA9IDE7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgbmV4dF9jb2RlW2JpdHNdID0gY29kZSA9IGNvZGUgKyBibF9jb3VudFtiaXRzIC0gMV0gPDwgMTsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICB2YXIgbGVuID0gdHJlZVtuICogMiArIDFdOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDJdID0gYmlfcmV2ZXJzZShuZXh0X2NvZGVbbGVuXSsrLCBsZW4pOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiB0cl9zdGF0aWNfaW5pdCgpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGVuZ3RoOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBibF9jb3VudCA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIGxlbmd0aCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IExFTkdUSF9DT0RFUyAtIDE7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9sZW5ndGhbY29kZV0gPSBsZW5ndGg7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9sYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGgrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoIC0gMV0gPSBjb2RlOwogICAgICAgIGRpc3QgPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCAxNjsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlW2Rpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkaXN0ID4+PSA3OwogICAgICAgIGZvciAoOyBjb2RlIDwgRF9DT0RFUzsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2Rpc3RbY29kZV0gPSBkaXN0IDw8IDc7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXSAtIDc7IG4rKykgewogICAgICAgICAgICBfZGlzdF9jb2RlWzI1NiArIGRpc3QrK10gPSBjb2RlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIGJsX2NvdW50W2JpdHNdID0gMDsKICAgICAgICB9CiAgICAgICAgbiA9IDA7CiAgICAgICAgd2hpbGUgKG4gPD0gMTQzKSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNTUpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gOTsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzldKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI3OSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA3OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbN10rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjg3KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDg7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs4XSsrOwogICAgICAgIH0KICAgICAgICBnZW5fY29kZXMoc3RhdGljX2x0cmVlLCBMX0NPREVTICsgMSwgYmxfY291bnQpOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMiArIDFdID0gNTsKICAgICAgICAgIHN0YXRpY19kdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG4sIDUpOwogICAgICAgIH0KICAgICAgICBzdGF0aWNfbF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKHN0YXRpY19sdHJlZSwgZXh0cmFfbGJpdHMsIExJVEVSQUxTICsgMSwgTF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19kX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2R0cmVlLCBleHRyYV9kYml0cywgMCwgRF9DT0RFUywgTUFYX0JJVFMpOwogICAgICAgIHN0YXRpY19ibF9kZXNjID0gbmV3IFN0YXRpY1RyZWVEZXNjKG5ldyBBcnJheSgwKSwgZXh0cmFfYmxiaXRzLCAwLCBCTF9DT0RFUywgTUFYX0JMX0JJVFMpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluaXRfYmxvY2socykgewogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2x0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBEX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuZHluX2R0cmVlW24gKiAyXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPCBCTF9DT0RFUzsgbisrKSB7CiAgICAgICAgICBzLmJsX3RyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgcy5keW5fbHRyZWVbRU5EX0JMT0NLICogMl0gPSAxOwogICAgICAgIHMub3B0X2xlbiA9IHMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgcy5sYXN0X2xpdCA9IHMubWF0Y2hlcyA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmlfd2luZHVwKHMpIHsKICAgICAgICBpZiAocy5iaV92YWxpZCA+IDgpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBzLmJpX2J1Zik7CiAgICAgICAgfSBlbHNlIGlmIChzLmJpX3ZhbGlkID4gMCkgewogICAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBzLmJpX2J1ZjsKICAgICAgICB9CiAgICAgICAgcy5iaV9idWYgPSAwOwogICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvcHlfYmxvY2socywgYnVmLCBsZW4sIGhlYWRlcikgewogICAgICAgIGJpX3dpbmR1cChzKTsKICAgICAgICBpZiAoaGVhZGVyKSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgbGVuKTsKICAgICAgICAgIHB1dF9zaG9ydChzLCB+bGVuKTsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQocy5wZW5kaW5nX2J1Ziwgcy53aW5kb3csIGJ1ZiwgbGVuLCBzLnBlbmRpbmcpOwogICAgICAgIHMucGVuZGluZyArPSBsZW47CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc21hbGxlcih0cmVlLCBuLCBtLCBkZXB0aCkgewogICAgICAgIHZhciBfbjIgPSBuICogMjsKICAgICAgICB2YXIgX20yID0gbSAqIDI7CiAgICAgICAgcmV0dXJuIHRyZWVbX24yXSA8IHRyZWVbX20yXSB8fCB0cmVlW19uMl0gPT09IHRyZWVbX20yXSAmJiBkZXB0aFtuXSA8PSBkZXB0aFttXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBwcWRvd25oZWFwKHMsIHRyZWUsIGspIHsKICAgICAgICB2YXIgdiA9IHMuaGVhcFtrXTsKICAgICAgICB2YXIgaiA9IGsgPDwgMTsKICAgICAgICB3aGlsZSAoaiA8PSBzLmhlYXBfbGVuKSB7CiAgICAgICAgICBpZiAoaiA8IHMuaGVhcF9sZW4gJiYgc21hbGxlcih0cmVlLCBzLmhlYXBbaiArIDFdLCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGorKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzbWFsbGVyKHRyZWUsIHYsIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBzLmhlYXBba10gPSBzLmhlYXBbal07CiAgICAgICAgICBrID0gajsKICAgICAgICAgIGogPDw9IDE7CiAgICAgICAgfQogICAgICAgIHMuaGVhcFtrXSA9IHY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29tcHJlc3NfYmxvY2socywgbHRyZWUsIGR0cmVlKSB7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGxjOwogICAgICAgIHZhciBseCA9IDA7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGV4dHJhOwogICAgICAgIGlmIChzLmxhc3RfbGl0ICE9PSAwKSB7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGRpc3QgPSBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDJdIDw8IDggfCBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBseCAqIDIgKyAxXTsKICAgICAgICAgICAgbGMgPSBzLnBlbmRpbmdfYnVmW3MubF9idWYgKyBseF07CiAgICAgICAgICAgIGx4Kys7CiAgICAgICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGxjLCBsdHJlZSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29kZSA9IF9sZW5ndGhfY29kZVtsY107CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUgKyBMSVRFUkFMUyArIDEsIGx0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2xiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgbGMgLT0gYmFzZV9sZW5ndGhbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgbGMsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZGlzdC0tOwogICAgICAgICAgICAgIGNvZGUgPSBkX2NvZGUoZGlzdCk7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGNvZGUsIGR0cmVlKTsKICAgICAgICAgICAgICBleHRyYSA9IGV4dHJhX2RiaXRzW2NvZGVdOwogICAgICAgICAgICAgIGlmIChleHRyYSAhPT0gMCkgewogICAgICAgICAgICAgICAgZGlzdCAtPSBiYXNlX2Rpc3RbY29kZV07CiAgICAgICAgICAgICAgICBzZW5kX2JpdHMocywgZGlzdCwgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAobHggPCBzLmxhc3RfbGl0KTsKICAgICAgICB9CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgbHRyZWUpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX3RyZWUocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5zdGF0aWNfdHJlZTsKICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBlbGVtcyA9IGRlc2Muc3RhdF9kZXNjLmVsZW1zOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBtYXhfY29kZSA9IC0xOwogICAgICAgIHZhciBub2RlOwogICAgICAgIHMuaGVhcF9sZW4gPSAwOwogICAgICAgIHMuaGVhcF9tYXggPSBIRUFQX1NJWkU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IGVsZW1zOyBuKyspIHsKICAgICAgICAgIGlmICh0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlID0gbjsKICAgICAgICAgICAgcy5kZXB0aFtuXSA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSAwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB3aGlsZSAocy5oZWFwX2xlbiA8IDIpIHsKICAgICAgICAgIG5vZGUgPSBzLmhlYXBbKytzLmhlYXBfbGVuXSA9IG1heF9jb2RlIDwgMiA/ICsrbWF4X2NvZGUgOiAwOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSAxOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IDA7CiAgICAgICAgICBzLm9wdF9sZW4tLTsKICAgICAgICAgIGlmIChoYXNfc3RyZWUpIHsKICAgICAgICAgICAgcy5zdGF0aWNfbGVuIC09IHN0cmVlW25vZGUgKiAyICsgMV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlc2MubWF4X2NvZGUgPSBtYXhfY29kZTsKICAgICAgICBmb3IgKG4gPSBzLmhlYXBfbGVuID4+IDE7IG4gPj0gMTsgbi0tKSB7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIG4pOwogICAgICAgIH0KICAgICAgICBub2RlID0gZWxlbXM7CiAgICAgICAgZG8gewogICAgICAgICAgbiA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFsxXSA9IHMuaGVhcFtzLmhlYXBfbGVuLS1dOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICAgIG0gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG47CiAgICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IG07CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IHRyZWVbbiAqIDJdICsgdHJlZVttICogMl07CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gKHMuZGVwdGhbbl0gPj0gcy5kZXB0aFttXSA/IHMuZGVwdGhbbl0gOiBzLmRlcHRoW21dKSArIDE7CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSB0cmVlW20gKiAyICsgMV0gPSBub2RlOwogICAgICAgICAgcy5oZWFwWzFdID0gbm9kZSsrOwogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCAxKTsKICAgICAgICB9IHdoaWxlIChzLmhlYXBfbGVuID49IDIpOwogICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gcy5oZWFwWzFdOwogICAgICAgIGdlbl9iaXRsZW4ocywgZGVzYyk7CiAgICAgICAgZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBzLmJsX2NvdW50KTsKICAgICAgfQogICAgICBmdW5jdGlvbiBzY2FuX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgdHJlZVsobWF4X2NvZGUgKyAxKSAqIDIgKyAxXSA9IDY1NTM1OwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSArPSBjb3VudDsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0rKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLmJsX3RyZWVbUkVQXzNfNiAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzNfMTAgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfMTFfMTM4ICogMl0rKzsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgY3VybGVuID0gbmV4dGxlbjsKICAgICAgICAgIG5leHRsZW4gPSB0cmVlWyhuICsgMSkgKiAyICsgMV07CiAgICAgICAgICBpZiAoKytjb3VudCA8IG1heF9jb3VudCAmJiBjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDwgbWluX2NvdW50KSB7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICB9IHdoaWxlICgtLWNvdW50ICE9PSAwKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuICE9PSAwKSB7CiAgICAgICAgICAgIGlmIChjdXJsZW4gIT09IHByZXZsZW4pIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY3VybGVuLCBzLmJsX3RyZWUpOwogICAgICAgICAgICAgIGNvdW50LS07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUF8zXzYsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDIpOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8zXzEwLCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAzKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzExXzEzOCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMTEsIDcpOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF9ibF90cmVlKHMpIHsKICAgICAgICB2YXIgbWF4X2JsaW5kZXg7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2x0cmVlLCBzLmxfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgc2Nhbl90cmVlKHMsIHMuZHluX2R0cmVlLCBzLmRfZGVzYy5tYXhfY29kZSk7CiAgICAgICAgYnVpbGRfdHJlZShzLCBzLmJsX2Rlc2MpOwogICAgICAgIGZvciAobWF4X2JsaW5kZXggPSBCTF9DT0RFUyAtIDE7IG1heF9ibGluZGV4ID49IDM7IG1heF9ibGluZGV4LS0pIHsKICAgICAgICAgIGlmIChzLmJsX3RyZWVbYmxfb3JkZXJbbWF4X2JsaW5kZXhdICogMiArIDFdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLm9wdF9sZW4gKz0gMyAqIChtYXhfYmxpbmRleCArIDEpICsgNSArIDUgKyA0OwogICAgICAgIHJldHVybiBtYXhfYmxpbmRleDsKICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX2FsbF90cmVlcyhzLCBsY29kZXMsIGRjb2RlcywgYmxjb2RlcykgewogICAgICAgIHZhciByYW5rOwogICAgICAgIHNlbmRfYml0cyhzLCBsY29kZXMgLSAyNTcsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBkY29kZXMgLSAxLCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgYmxjb2RlcyAtIDQsIDQpOwogICAgICAgIGZvciAocmFuayA9IDA7IHJhbmsgPCBibGNvZGVzOyByYW5rKyspIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCBzLmJsX3RyZWVbYmxfb3JkZXJbcmFua10gKiAyICsgMV0sIDMpOwogICAgICAgIH0KICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fbHRyZWUsIGxjb2RlcyAtIDEpOwogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9kdHJlZSwgZGNvZGVzIC0gMSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGV0ZWN0X2RhdGFfdHlwZShzKSB7CiAgICAgICAgdmFyIGJsYWNrX21hc2sgPSA0MDkzNjI0NDQ3OwogICAgICAgIHZhciBuOwogICAgICAgIGZvciAobiA9IDA7IG4gPD0gMzE7IG4rKywgYmxhY2tfbWFzayA+Pj49IDEpIHsKICAgICAgICAgIGlmIChibGFja19tYXNrICYgMSAmJiBzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5keW5fbHRyZWVbOSAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEwICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTMgKiAyXSAhPT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMzI7IG4gPCBMSVRFUkFMUzsgbisrKSB7CiAgICAgICAgICBpZiAocy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgfQogICAgICB2YXIgc3RhdGljX2luaXRfZG9uZSA9IGZhbHNlOwogICAgICBmdW5jdGlvbiBfdHJfaW5pdChzKSB7CiAgICAgICAgaWYgKCFzdGF0aWNfaW5pdF9kb25lKSB7CiAgICAgICAgICB0cl9zdGF0aWNfaW5pdCgpOwogICAgICAgICAgc3RhdGljX2luaXRfZG9uZSA9IHRydWU7CiAgICAgICAgfQogICAgICAgIHMubF9kZXNjID0gbmV3IFRyZWVEZXNjKHMuZHluX2x0cmVlLCBzdGF0aWNfbF9kZXNjKTsKICAgICAgICBzLmRf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RyX2FsaWduID0gX3RyX2FsaWduOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcwogIHZhciByZXF1aXJlX2FkbGVyMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvYWRsZXIzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBhZGxlcjMyKGFkbGVyLCBidWYsIGxlbiwgcG9zKSB7CiAgICAgICAgdmFyIHMxID0gYWRsZXIgJiA2NTUzNSB8IDAsIHMyID0gYWRsZXIgPj4+IDE2ICYgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIyKGNyYywgYnVmLCBsZW4sIHBvcykgewogICAgICAgIHZhciB0ID0gY3JjVGFibGUsIGVuZCA9IHBvcyArIGxlbjsKICAgICAgICBjcmMgXj0gLTE7CiAgICAgICAgZm9yICh2YXIgaSA9IHBvczsgaSA8IGVuZDsgaSsrKSB7CiAgICAgICAgICBjcmMgPSBjcmMgPj4+IDggXiB0WyhjcmMgXiBidWZbaV0pICYgMjU1XTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGNyYyBeIC0xOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gY3JjMzIyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMKICB2YXIgcmVxdWlyZV9tZXNzYWdlczIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdGlibGUgdmVyc2lvbiIKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2RlZmxhdGUuanMiKGV4cG9ydHMpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uMigpOwogICAgICB2YXIgdHJlZXMgPSByZXF1aXJlX3RyZWVzKCk7CiAgICAgIHZhciBhZGxlcjMyID0gcmVxdWlyZV9hZGxlcjMyKCk7CiAgICAgIHZhciBjcmMzMjIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBtc2cgPSByZXF1aXJlX21lc3NhZ2VzMigpOwogICAgICB2YXIgWl9OT19GTFVTSCA9IDA7CiAgICAgIHZhciBaX1BBUlRJQUxfRkxVU0ggPSAxOwogICAgICB2YXIgWl9GVUxMX0ZMVVNIID0gMzsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9PSyA9IDA7CiAgICAgIHZhciBaX1NUUkVBTV9FTkQgPSAxOwogICAgICB2YXIgWl9TVFJFQU1fRVJST1IgPSAtMjsKICAgICAgdmFyIFpfREFUQV9FUlJPUiA9IC0zOwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xOwogICAgICB2YXIgWl9GSUxURVJFRCA9IDE7CiAgICAgIHZhciBaX0hVRkZNQU5fT05MWSA9IDI7CiAgICAgIHZhciBaX1JMRSA9IDM7CiAgICAgIHZhciBaX0ZJWEVEID0gNDsKICAgICAgdmFyIFpfREVGQVVMVF9TVFJBVEVHWSA9IDA7CiAgICAgIHZhciBaX1VOS05PV04gPSAyOwogICAgICB2YXIgWl9ERUZMQVRFRCA9IDg7CiAgICAgIHZhciBNQVhfTUVNX0xFVkVMID0gOTsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX01FTV9MRVZFTCA9IDg7CiAgICAgIHZhciBMRU5HVEhfQ09ERVMgPSAyOTsKICAgICAgdmFyIExJVEVSQUxTID0gMjU2OwogICAgICB2YXIgTF9DT0RFUyA9IExJVEVSQUxTICsgMSArIExFTkdUSF9DT0RFUzsKICAgICAgdmFyIERfQ09ERVMgPSAzMDsKICAgICAgdmFyIEJMX0NPREVTID0gMTk7CiAgICAgIHZhciBIRUFQX1NJWkUgPSAyICogTF9DT0RFUyArIDE7CiAgICAgIHZhciBNQVhfQklUUyA9IDE1OwogICAgICB2YXIgTUlOX01BVENIID0gMzsKICAgICAgdmFyIE1BWF9NQVRDSCA9IDI1ODsKICAgICAgdmFyIE1JTl9MT09LQUhFQUQgPSBNQVhfTUFUQ0ggKyBNSU5fTUFUQ0ggKyAxOwogICAgICB2YXIgUFJFU0VUX0RJQ1QgPSAzMjsKICAgICAgdmFyIElOSVRfU1RBVEUgPSA0MjsKICAgICAgdmFyIEVYVFJBX1NUQVRFID0gNjk7CiAgICAgIHZhciBOQU1FX1NUQVRFID0gNzM7CiAgICAgIHZhciBDT01NRU5UX1NUQVRFID0gOTE7CiAgICAgIHZhciBIQ1JDX1NUQVRFID0gMTAzOwogICAgICB2YXIgQlVTWV9TVEFURSA9IDExMzsKICAgICAgdmFyIEZJTklTSF9TVEFURSA9IDY2NjsKICAgICAgdmFyIEJTX05FRURfTU9SRSA9IDE7CiAgICAgIHZhciBCU19CTE9DS19ET05FID0gMjsKICAgICAgdmFyIEJTX0ZJTklTSF9TVEFSVEVEID0gMzsKICAgICAgdmFyIEJTX0ZJTklTSF9ET05FID0gNDsKICAgICAgdmFyIE9TX0NPREUgPSAzOwogICAgICBmdW5jdGlvbiBlcnIoc3RybSwgZXJyb3JDb2RlKSB7CiAgICAgICAgc3RybS5tc2cgPSBtc2dbZXJyb3JDb2RlXTsKICAgICAgICByZXR1cm4gZXJyb3JDb2RlOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHJhbmsoZikgewogICAgICAgIHJldHVybiAoZiA8PCAxKSAtIChmID4gNCA/IDkgOiAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiB6ZXJvKGJ1ZikgewogICAgICAgIHZhciBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIHdoaWxlICgtLWxlbiA+PSAwKSB7CiAgICAgICAgICBidWZbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX3BlbmRpbmcoc3RybSkgewogICAgICAgIHZhciBzID0gc3RybS5zdGF0ZTsKICAgICAgICB2YXIgbGVuID0gcy5wZW5kaW5nOwogICAgICAgIGlmIChsZW4gPiBzdHJtLmF2YWlsX291dCkgewogICAgICAgICAgbGVuID0gc3RybS5hdmFpbF9vdXQ7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHMucGVuZGluZ19idWYsIHMucGVuZGluZ19vdXQsIGxlbiwgc3RybS5uZXh0X291dCk7CiAgICAgICAgc3RybS5uZXh0X291dCArPSBsZW47CiAgICAgICAgcy5wZW5kaW5nX291dCArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9vdXQgKz0gbGVuOwogICAgICAgIHN0cm0uYXZhaWxfb3V0IC09IGxlbjsKICAgICAgICBzLnBlbmRpbmcgLT0gbGVuOwogICAgICAgIGlmIChzLnBlbmRpbmcgPT09IDApIHsKICAgICAgICAgIHMucGVuZGluZ19vdXQgPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9ibG9ja19vbmx5KHMsIGxhc3QpIHsKICAgICAgICB0cmVlcy5fdHJfZmx1c2hfYmxvY2socywgcy5ibG9ja19zdGFydCA+PSAwID8gcy5ibG9ja19zdGFydCA6IC0xLCBzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCwgbGFzdCk7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgZmx1c2hfcGVuZGluZyhzLnN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHB1dF9ieXRlKHMsIGIpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0U2hvcnRNU0IocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiA+Pj4gOCAmIDI1NTsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IGIgJiAyNTU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcmVhZF9idWYoc3RybSwgYnVmLCBzdGFydCwgc2l6ZSkgewogICAgICAgIHZhciBsZW4gPSBzdHJtLmF2YWlsX2luOwogICAgICAgIGlmIChsZW4gPiBzaXplKSB7CiAgICAgICAgICBsZW4gPSBzaXplOwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgc3RybS5hdmFpbF9pbiAtPSBsZW47CiAgICAgICAgdXRpbHMuYXJyYXlTZXQoYnVmLCBzdHJtLmlucHV0LCBzdHJtLm5leHRfaW4sIGxlbiwgc3RhcnQpOwogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGJ1ZiwgbGVuLCBzdGFydCk7CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLnN0YXRlLndyYXAgPT09IDIpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgYnVmLCBsZW4sIHN0YXJ0KTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX2luICs9IGxlbjsKICAgICAgICByZXR1cm4gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxvbmdlc3RfbWF0Y2gocywgY3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAg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ICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMucHJldl9sZW5ndGggPj0gTUlOX01BVENIICYmIHMubWF0Y2hfbGVuZ3RoIDw9IHMucHJldl9sZW5ndGgpIHsKICAgICAgICAgICAgbWF4X2luc2VydCA9IHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCAtIE1JTl9NQVRDSDsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIHMuc3Ryc3RhcnQgLSAxIC0gcy5wcmV2X21hdGNoLCBzLnByZXZfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5wcmV2X2xlbmd0aCAtIDE7CiAgICAgICAgICAgIHMucHJldl9sZW5ndGggLT0gMjsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICA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gICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdGhpcy5pbnNfaCA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NpemUgPSAwOwogICAgICAgIHRoaXMuaGFzaF9iaXRzID0gMDsKICAgICAgICB0aGlzLmhhc2hfbWFzayA9IDA7CiAgICAgICAgdGhpcy5oYXNoX3NoaWZ0ID0gMDsKICAgICAgICB0aGlzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5wcmV2X21hdGNoID0gMDsKICAgICAgICB0aGlzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgdGhpcy5zdHJzdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9zdGFydCA9IDA7CiAgICAgICAgdGhpcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHRoaXMucHJldl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2NoYWluX2xlbmd0aCA9IDA7CiAgICAgICAgdGhpcy5tYXhfbGF6eV9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5sZXZlbCA9IDA7CiAgICAgICAgdGhpcy5zdHJhdGVneSA9IDA7CiAgICAgICAgdGhpcy5nb29kX21hdGNoID0gMDsKICAgICAgICB0aGlzLm5pY2VfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMuZHluX2x0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KEhFQVBfU0laRSAqIDIpOwogICAgICAgIHRoaXMuZHluX2R0cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogRF9DT0RFUyArIDEpICogMik7CiAgICAgICAgdGhpcy5ibF90cmVlID0gbmV3IHV0aWxzLkJ1ZjE2KCgyICogQkxfQ09ERVMgKyAxKSAqIDIpOwogICAgICAgIHplcm8odGhpcy5keW5fbHRyZWUpOwogICAgICAgIHplcm8odGhpcy5keW5fZHRyZWUpOwogICAgICAgIHplcm8odGhpcy5ibF90cmVlKTsKICAgICAgICB0aGlzLmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZG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MCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0cyA9IG1lbUxldmVsICsgNzsKICAgICAgICBzLmhhc2hfc2l6ZSA9IDEgPDwgcy5oYXNoX2JpdHM7CiAgICAgICAgcy5oYXNoX21hc2sgPSBzLmhhc2hfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX3NoaWZ0ID0gfn4oKHMuaGFzaF9iaXRzICsgTUlOX01BVENIIC0gMSkgLyBNSU5fTUFUQ0gpOwogICAgICAgIHMud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgocy53X3NpemUgKiAyKTsKICAgICAgICBzLmhlYWQgPSBuZXcgdXRpbHMuQnVmMTYocy5oYXNoX3NpemUpOwogICAgICAgIHMucHJldiA9IG5ldyB1dGlscy5CdWYxNihzLndfc2l6ZSk7CiAgICAgICAgcy5saXRfYnVmc2l6ZSA9IDEgPDwgbWVtTGV2ZWwgKyA2OwogICAgICAgIHMucGVuZGluZ19idWZfc2l6ZSA9IHMubGl0X2J1ZnNpemUgKiA0OwogICAgICAgIHMucGVuZGluZ19idWYgPSBuZXcgdXRpbHMuQnVmOChzLnBlbmRpbmdfYnVmX3NpemUpOwogIC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gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhW3MuZ3ppbmRleF0gJiAyNTUpOwogICAgICAgICAgICAgIHMuZ3ppbmRleCsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IENPTU1FTlRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5jb21tZW50KSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMjIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2U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FKSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gRklOSVNIX1NUQVRFOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGJzdGF0ZSA9PT0gQlNfTkVFRF9NT1JFIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX1NUQVJURUQpIHsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19CTE9DS19ET05FKSB7CiAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9QQVJUSUFMX0ZMVVNIKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX2FsaWduKHMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiA4ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gPj4gMTYgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAyNCAmIDI1NSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgJiA2NTUzNSk7CiAgICAgICAgfQogICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgaWYgKHMud3JhcCA+IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzLnBlbmRpbmcgIT09IDAgPyBaX09LIDogWl9TVFJFQU1fRU5EOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVFbmQoc3RybSkgewogICAgICAgIHZhciBzdGF0dXM7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXR1cyA9IHN0cm0uc3RhdGUuc3RhdHVzOwogICAgICAgIGlmIChzdGF0dXMgIT09IElOSVRfU1RBVEUgJiYgc3RhdHVzICE9PSBFWFRSQV9TVEFURSAmJiBzdGF0dXMgIT09IE5BTUVfU1RBVEUgJiYgc3RhdHVzICE9PSBDT01NRU5UX1NUQVRFICYmIHN0YXR1cyAhPT0gSENSQ19TVEFURSAmJiBzdGF0dXMgIT09IEJVU1lfU1RBVEUgJiYgc3RhdHVzICE9PSBGSU5JU0hfU1RBVEUpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgICAgICAgIHMubG9va2FoZWFkID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIH0KICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSBzLnN0cnN0YXJ0OwogICAgICAgIHMuaW5zZXJ0ID0gcy5sb29rYWhlYWQ7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5wcmV2X2xlbmd0aCA9IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgc3RybS5pbnB1dCA9IGlucHV0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBhdmFpbDsKICAgICAgICBzLndyYXAgPSB3cmFwOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMuZGVmbGF0ZUluaXQgPSBk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NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgYnVmX2xlbiArPSBjIDwgMTI4ID8gMSA6IGMgPCAyMDQ4ID8gMiA6IGMgPCA2NTUzNiA/IDMgOiA0OwogICAgICAgIH0KICAgICAgICBidWYgPSBuZXcgdXRpbHMuQnVmOChidWZfbGVuKTsKICAgICAgICBmb3IgKGkgPSAwLCBtX3BvcyA9IDA7IGkgPCBidWZfbGVuOyBtX3BvcysrKSB7CiAgICAgICAgICBjID0gc3RyLmNoYXJDb2RlQXQobV9wb3MpOwogICAgICAgICAgaWYgKChjICYgNjQ1MTIpID09PSA1NTI5NiAmJiBtX3BvcyArIDEgPCBzdHJfbGVuKSB7CiAgICAgICAgICAgIGMyID0gc3RyLmNoYXJDb2RlQXQobV9wb3MgKyAxKTsKICAgICAgICAgICAgaWYgKChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBid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kgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0cy51dGY4Ym9yZGVyID0gZnVuY3Rpb24oYnVmLCBtYXgpIHsKICAgICAgICB2YXIgcG9zOwogICAgICAgIG1heCA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIGlmIChtYXggPiBidWYubGVuZ3RoKSB7CiAgICAgICAgICBtYXggPSBidWYubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBwb3MgPSBtYXggLSAxOwogICAgICAgIHdoaWxlIChwb3MgPj0gMCAmJiAoYnVmW3Bvc10gJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgIHBvcy0tOwogICAgICAgIH0KICAgICAgICBpZiAocG9zIDwgMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIG1heDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBvcyArIF91dGY4bGVuW2J1Zltwb3NdXSA+IG1heCA/IHBvcyA6IG1heDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3pzdHJlYW0uanMKICB2YXIgcmVxdWlyZV96c3RyZWFtID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kd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V9zdHJpbmdzKCk7CiAgICAgIHZhciBtc2cgPSByZXF1aXJlX21lc3NhZ2VzMigpOwogICAgICB2YXIgWlN0cmVhbSA9IHJlcXVpcmVfenN0cmVhbSgpOwogICAgICB2YXIgdG9TdHJpbmcgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nOwogICAgICB2YXIgWl9OT19GTFVTSCA9IDA7CiAgICAgIHZhciBaX0ZJTklTSCA9IDQ7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX1NZTkNfRkxVU0gyID0gMjsKICAgICAgdmFyIFpfREVGQVVMVF9DT01QUkVTU0lPTiA9IC0xOwogICAgICB2YXIgWl9ERUZBVUxUX1NUUkFURUdZID0gMDsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICBmdW5jdGlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0Lnd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XSIpIHsKICAgICAgICAgICAgZGljdCA9IG5ldyBVaW50OEFycmF5KG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGRpY3QgPSBvcHQuZGljdGlvbmFyeTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlU2V0RGljdGlvbmFyeSh0aGlzLnN0cm0sIGRpY3QpOwogICAgICAgICAgaWYgKHN0YXR1cyAhPT0gWl9PSykgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5fZGljdF9zZXQgPSB0cnVlOwogICAgICAgIH0KICAgICAgfQogICAgICBEZWZsYXRlLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFt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anMKICB2YXIgcmVxdWlyZV9pbmZmYXN0ID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmZhc3QuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICBtb2R1bGUuZXhwb3J0cyA9IGZ1bmN0aW9uIGluZmxhdGVfZmFzdChzdHJtLCBzdGFydCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgX2luOwogICAgICAgIHZhciBsYXN0OwogICAgICAgIHZhciBfb3V0OwogICAgICAgIHZhciBiZWc7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgZG1heDsKICAgICAgICB2YXIgd3NpemU7CiAgICAgICAgdmFyIHdoYXZlOwogICAgICAgIHZhciB3bmV4dDsKICAgICAgICB2YXIgc193aW5kb3c7CiAgICAgICAgdmFyIGhvbGQ7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxjb2RlOwogICAgICAgIHZhciBkY29kZTsKICAgICAgICB2YXIgbG1hc2s7CiAgICAgICAgdmFyIGRtYXNrOwogICAgICAgIHZhciBoZXJlOwogICAgICAgIHZhciBvcDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgICAgICB2YXIgaW5wdXQsIG91dHB1dDsKICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgX2luID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBsYXN0ID0gX2luICsgKHN0cm0uYXZhaWxfaW4gLSA1KTsKICAgICAgICBfb3V0ID0gc3RybS5uZXh0X291dDsKICAgICAgICBvdXRwdXQgPSBzdHJtLm91dHB1dDsKICAgICAgICBiZWcgPSBfb3V0IC0gKHN0YXJ0IC0gc3RybS5hdmFpbF9vdXQpOwogICAgICAgIGVuZCA9IF9vdXQgKyAoc3RybS5hdmFpbF9vdXQgLSAyNTcpOwogICAgICAgIGRtYXggPSBzdGF0ZS5kbWF4OwogICAgICAgIHdzaXplID0gc3RhdGUud3NpemU7CiAgICAgICAgd2hhdmUgPSBzdGF0ZS53aGF2ZTsKICAgICAgICB3bmV4dCA9IHN0YXRlLnduZXh0OwogICAgICAgIHNfd2luZG93ID0gc3RhdGUud2luZG93OwogICAgICAgIGhvbGQgPSBzdGF0ZS5ob2xkOwogICAgICAgIGJpdHMgPSBzdGF0ZS5iaXRzOwogICAgICAgIGxjb2RlID0gc3RhdGUubGVuY29kZTsKICAgICAgICBkY29kZSA9IHN0YXRlLmRpc3Rjb2RlOwogICAgICAgIGxtYXNrID0gKDEgPDwgc3RhdGUubGVuYml0cykgLSAxOwogICAgICAgIGRtYXNrID0gKDEgPDwgc3RhdGUuZGlzdGJpdHMpIC0gMTsKICAgICAgICB0b3A6CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZXJlID0gbGNvZGVbaG9sZCAmIGxtYXNrXTsKICAgICAgICAgICAgZG9sZW46CiAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICBpZiAob3AgPT09IDApIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgbGVuID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgaWYgKG9wKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgbGVuICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgMTUpIHsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbaG9sZCAmIGRtYXNrXTsKICAgICAgICAgICAgICAgICAgZG9kaXN0OgogICAgICAgICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgICAgICAgaWYgKG9wICYgMTYpIHsKICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ICs9IGhvbGQgJiAoMSA8PCBvcCkgLSAxOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IGRtYXgpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICBvcCA9IF9vdXQgLSBiZWc7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IGRpc3QgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPiB3aGF2ZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHN0YXRlLnNhbmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gc193aW5kb3c7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0ID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplIC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHduZXh0IDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgKyB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgLT0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gd25leHQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3bmV4dCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIHdoaWxlIChsZW4gPiAyKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAobGVuID4gMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICBoZXJlID0gZGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgICAgICAgY29udGludWUgZG9kaXN0OwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSBjb2RlIjsKICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgaGVyZSA9IGxjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvbGVuOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDMyKSB7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBUWVBFOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGxpdGVyYWwvbGVuZ3RoIGNvZGUiOwogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChfaW4gPCBsYXN0ICYmIF9vdXQgPCBlbmQpOwogICAgICAgIGxlbiA9IGJpdHMgPj4gMzsKICAgICAgICBfaW4gLT0gbGVuOwogICAgICAgIGJpdHMgLT0gbGVuIDw8IDM7CiAgICAgICAgaG9sZCAmPSAoMSA8PCBiaXRzKSAtIDE7CiAgICAgICAgc3RybS5uZXh0X2luID0gX2luOwogICAgICAgIHN0cm0ubmV4dF9vdXQgPSBfb3V0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBfaW4gPCBsYXN0ID8gNSArIChsYXN0IC0gX2luKSA6IDUgLSAoX2luIC0gbGFzdCk7CiAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBfb3V0IDwgZW5kID8gMjU3ICsgKGVuZCAtIF9vdXQpIDogMjU3IC0gKF9vdXQgLSBlbmQpOwogICAgICAgIHN0YXRlLmhvbGQgPSBob2xkOwogICAgICAgIHN0YXRlLmJpdHMgPSBiaXRzOwogICAgICAgIHJldHVybjsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzCiAgdmFyIHJlcXVpcmVfaW5mdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mdHJlZXMuanMiKGV4cG9ydHMsIG1vZHVsZSkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24yKCk7CiAgICAgIHZhciBNQVhCSVRTID0gMTU7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgbGJhc2UgPSBbCiAgICAgICAgMywKICAgICAgICA0LAogICAgICAgIDUsCiAgICAgICAgNiwKICAgICAgICA3LAogICAgICAgIDgsCiAgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdCA9IDA7CiAgICAgICAgdmFyIGN1cnIgPSAwOwogICAgICAgIHZhciBkcm9wID0gMDsKICAgICAgICB2YXIgbGVmdCA9IDA7CiAgICAgICAgdmFyIHVzZWQgPSAwOwogICAgICAgIHZhciBodWZmID0gMDsKICAgICAgICB2YXIgaW5jcjsKICAgICAgICB2YXIgZmlsbDsKICAgICAgICB2YXIgbG93OwogICAgICAgIHZhciBtYXNrOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBiYXNlID0gbnVsbDsKICAgICAgICB2YXIgYmFzZV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGVuZDsKICAgICAgICB2YXIgY291bnQgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBvZmZzID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgZXh0cmEgPSBudWxsOwogICAgICAgIHZhciBleHRyYV9pbmRleCA9IDA7CiAgICAgICAgdmFyIGhlcmVfYml0cywgaGVyZV9vcCwgaGVyZV92YWw7CiAgICAgICAgZm9yIChsZW4gPSAwOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGNvdW50W2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgY291bnRbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rKzsKICAgICAgICB9CiAgICAgICAgcm9vdCA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA+IG1heCkgewogICAgICAgICAgcm9vdCA9IG1heDsKICAgICAgICB9CiAgICAgICAgaWYgKG1heCA9PT0gMCkgewogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgdGFibGVbdGFibGVfaW5kZXgrK10gPSAxIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgICAgb3B0cy5iaXRzID0gMTsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBmb3IgKG1pbiA9IDE7IG1pbiA8IG1heDsgbWluKyspIHsKICAgICAgICAgIGlmIChjb3VudFttaW5dICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdCA8IG1pbikgewogICAgICAgICAgcm9vdCA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3Q7CiAgICAgICAgZHJvcCA9IDA7CiAgICAgICAgbG93ID0gLTE7CiAgICAgICAgdXNlZCA9IDEgPDwgcm9vdDsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbmV4dCArPSBtaW47CiAgICAgICAgICAgIGN1cnIgPSBsZW4gLSBkcm9wOwogICAgICAgICAgICBsZWZ0ID0gMSA8PCBjdXJyOwogICAgICAgICAgICB3aGlsZSAoY3VyciArIGRyb3AgPCBtYXgpIHsKICAgICAgICAgICAgICBsZWZ0IC09IGNvdW50W2N1cnIgKyBkcm9wXTsKICAgICAgICAgICAgICBpZiAobGVmdCA8PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgY3VycisrOwogICAgICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdXNlZCArPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIGlmICh0eXBlID09PSBMRU5TICYmIHVzZWQgPiBFTk9VR0hfTEVOUyB8fCB0eXBlID09PSBESVNUUyAmJiB1c2VkID4gRU5PVUdIX0RJU1RTKSB7CiAgICAgICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbG93ID0gaHVmZiAmIG1hc2s7CiAgICAgICAgICAgIHRhYmxlW2xvd10gPSByb290IDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290OwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhd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AgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3RkeW4gPSBudWxsOwogICAgICAgIHRoaXMuc2FuZSA9IDA7CiAgICAgICAgdGhpcy5iYWNrID0gMDsKICAgICAgICB0a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B7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdGF0ZS53c2l6ZSA9IDA7CiAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpIHsKICAgICAgICB2YXIgd3JhcDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+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/IGNyYzMyMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICBpZiAoc3RhdGUud3NpemUgfHwgX291dCAhPT0gc3RybS5hdmFpbF9vdXQgJiYgc3RhdGUubW9kZSA8IEJBRCAmJiAoc3RhdGUubW9kZSA8IENIRUNLIHx8IGZsdXNoICE9PSBaX0ZJTklTSCkpIHsKICAgICAgICAgIGlmICh1cGRhdGV3aW5kb3coc3RybSwgc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQsIF9vdXQgLSBzdHJtLmF2YWlsX291dCkpIHsKICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfaW4gLT0gc3RybS5hdmFpbF9pbjsKICAgICAgICBfb3V0IC09IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIHN0cm0udG90YWxfaW4gKz0gX2luOwogICAgICAgIHN0cm0udG90YWxfb3V0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F0ZUdldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKChzdGF0ZS53cmFwICYgMikgPT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUuaGVhZCA9IGhlYWQ7CiAgICAgICAgaGVhZC5kb25lID0gZmFsc2U7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBkaWN0aWQ7CiAgICAgICAgdmFyIHJldDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53cmFwICE9PSAwICYmIHN0YXRlLm1vZGUgIT09IERJQ1QpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXRlLm1vZGUgPT09IERJQ1QpIHsKICAgICAgICAgIGRpY3RpZCA9IDE7CiAgICAgICAgICBkaWN0aWQgPSBhZGxlcjMyKGRpY3RpZCwgZGljdGlvbmFyeSwgZGljdExlbmd0aCwgMCk7CiAgICAgICAgICBpZiAoZGljdGlkICE9PSBzdGF0ZS5jaGVjaykgewogICAgICAgICAgICByZXR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vbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY29uc3RhbnRzLmpzIihleHBvcnRzLCBtb2R1bGUpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIG1vZHVsZS5leHBvcnRzID0gewogICAgICAgIFpfTk9fRkxVU0g6IDAsCiAgICAgICAgWl9QQVJUSUFMX0ZMVVNIOiAxLAogICAgICAgIFpfU1lOQ19GTFVTSDogMiwKICAgICAgICBaX0ZVTExfRkxVU0g6IDMsCiAgICAgICAgWl9GSU5JU0g6IDQsCiAgICAgICAgWl9CTE9DSzogNSwKICAgICAgICBaX1RSRUVTOiA2LAogICAgICAgIFpfT0s6IDAsCiAgICAgICAgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2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V9pbmZsYXRlKCk7CiAgICAgIHZhciB1dGlscyA9IHJlcXVpcmVfY29tbW9uMigpOwogICAgICB2YXIgc3RyaW5ncyA9IHJlcXVpcmVfc3RyaW5ncygpOwogICAgICB2YXIgYyA9IHJlcXVpcmVfY29uc3RhbnRzKCk7CiAgICAgIHZhciBtc2cgPSByZXF1aXJlX21lc3NhZ2VzMigpOwogICAgICB2YXIgWlN0cmVhbSA9IHJlcXVpcmVfenN0cmVhbSgpOwogICAgICB2YXIgR1poZWFkZXIgPSByZXF1aXJlX2d6aGVhZGVyKCk7CiAgICAgIHZhciB0b1N0cmluZyA9IE9iamVjdC5wcm90b3R5cGUudG9TdHJpbmc7CiAgICAgIGZ1bmN0aW9uIEluZmxhdGUyKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgSW5mbGF0ZTIpKQogICAgICAgICAgcmV0dXJuIG5ldyBJbmZsYXRlMihvcHRpb25zKTsKICAgICAgICB0aGlzLm9wdGlvbnMgPSB1dGlscy5hc3NpZ24oewogICAgICAgICAgY2h1bmtTaXplOiAxNjM4NCwKICAgICAgICAgIHdpbmRvd0JpdHM6IDAsCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYgJiYgIShvcHRpb25zICYmIG9wdGlvbnMud2luZG93Qml0cykpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzICs9IDMyOwogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPiAxNSAmJiBvcHQud2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICBpZiAoKG9wdC53aW5kb3dCaXRzICYgMTUpID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzIHw9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmVyciA9IDA7CiAgICAgICAgdGhpcy5tc2cgPSAiIjsKICAgICAgICB0aGlzLmVuZGVkID0gZmFsc2U7CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLnN0cm0gPSBuZXcgWlN0cmVhbSgpOwogICAgICAgIHRoaXMuc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgIHZhciBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUluaXQyKHRoaXMuc3RybSwgb3B0LndpbmRvd0JpdHMpOwogICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKG1zZ1tzdGF0dXNdKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5oZWFkZXIgPSBuZXcgR1poZWFkZXIoKTsKICAgICAgICB6bGliX2luZmxhdGUuaW5mbGF0ZUdldEhlYWRlcih0aGlzLnN0cm0sIHRoaXMuaGVhZGVyKTsKICAgICAgICBpZiAob3B0LmRpY3Rpb25hcnkpIHsKICAgICAgICAgIGlmICh0eXBlb2Ygb3B0LmRpY3Rpb25hcnkgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIG9wdC5kaWN0aW9uYXJ5ID0gc3RyaW5ncy5zdHJpbmcyYnVmKG9wdC5kaWN0aW9uYXJ5KTsKICAgICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChvcHQuZGljdGlvbmFyeSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBuZXcgVWludDhBcnJheShvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAob3B0LnJhdykgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBvcHQuZGljdGlvbmFyeSk7CiAgICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcihtc2dbc3RhdHVzXSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLnB1c2ggPSBmdW5jdGlvbihkYXRhLCBtb2RlKSB7CiAgICAgICAgdmFyIHN0cm0gPSB0aGlzLnN0cm07CiAgICAgICAgdmFyIGNodW5rU2l6ZSA9IHRoaXMub3B0aW9ucy5jaHVua1NpemU7CiAgICAgICAgdmFyIGRpY3Rpb25hcnkgPSB0aGlzLm9wdGlvbnMuZGljdGlvbmFyeTsKICAgICAgICB2YXIgc3RhdHVzLCBfbW9kZTsKICAgICAgICB2YXIgbmV4dF9vdXRfdXRmOCwgdGFpbCwgdXRmOHN0cjsKICAgICAgICB2YXIgYWxsb3dCdWZFcnJvciA9IGZhbHNlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBjLlpfRklOSVNIIDogYy5aX05PX0ZMVVNIOwogICAgICAgIGlmICh0eXBlb2YgZGF0YSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBzdHJpbmdzLmJpbnN0cmluZzJidWYoZ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T0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0ubmV4dF9vdXQpIHsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQgfHwgc3RybS5hdmFpbF9pbiA9PT0gMCAmJiAoX21vZGUgPT09IGMuWl9GSU5JU0ggfHwgX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSkgewogICAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgICBuZXh0X291dF91dGY4ID0gc3RyaW5ncy51dGY4Ym9yZGVyKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KTsKICAgICAgICAgICAgICAgIHRhaWwgPSBzdHJtLm5leHRfb3V0IC0gbmV4dF9vdXRfdXRmODsKICAgICAgICAgICAgICAgIHV0ZjhzdHIgPSBzdHJpbmdzLmJ1ZjJzdHJpbmcoc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgpOwogICAgICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IHRhaWw7CiAgICAgICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZSAtIHRhaWw7CiAgICAgICAgICAgICAgICBpZiAodGFpbCkgewogICAgICAgICAgICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgc3RybS5vdXRwdXQsIG5leHRfb3V0X3V0ZjgsIHRhaWwsIDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRmOHN0cik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgYWxsb3dCdWZFcnJvciA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EKTsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCkgewogICAgICAgICAgX21vZGUgPSBjLlpfRklOSVNIOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IGMuWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkgewogICAgICAgICAgdGhpcy5vbkVuZChjLlpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRW5kID0gZnVuY3Rpb24oc3RhdHVzKSB7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5jaHVua3MgPSBbXTsKICAgICAgICB0aGlzLmVyciA9IHN0YXR1czsKICAgICAgICB0aGlzLm1zZyA9IHRoaXMuc3RybS5tc2c7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICB2YXIgaW5mbGF0b3IgPSBuZXcgSW5mbGF0ZTIob3B0aW9ucyk7CiAgICAgICAgaW5mbGF0b3IucHVzaChpbnB1dCwgdHJ1ZSk7CiAgICAgICAgaWYgKGluZmxhdG9yLmVycikgewogICAgICAgICAgdGhyb3cgaW5mbGF0b3IubXNnIHx8IG1zZ1tpbmZsYXRvci5lcnJdOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaW5mbGF0b3IucmVzdWx0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSYXcoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICBvcHRpb25zID0gb3B0aW9ucyB8fCB7fTsKICAgICAgICBvcHRpb25zLnJhdyA9IHRydWU7CiAgICAgICAgcmV0dXJuIGluZmxhdGUoaW5wdXQsIG9wdGlvbnMpOwogICAgICB9CiAgICAgIGV4cG9ydHMuSW5mbGF0ZSA9IEluZmxhdGUyOwogICAgICBleHBvcnRzLmluZmxhdGUgPSBpbmZsYXRlOwogICAgICBleHBvcnRzLmluZmxhdGVSYXcgPSBpbmZsYXRlUmF3OwogICAgICBleHBvcnRz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I7CiAgICAgIHZhciBDUkNfVEFCTEUgPSBbCiAgICAgICAgMCwKICAgICAgICAxOTk2OTU5ODk0LAogICAgICAgIDM5OTM5MTk3ODgsCiAgICAgICAgMjU2NzUyNDc5NCwKICAgICAgICAxMjQ2MzQxMzcsCiAgICAgICAgMTg4NjA1NzYxNSwKICAgICAgICAzOTE1NjIxNjg1LAogICAgICAgIDI2NTczOTIwMzUsCiAgICAgICAgMjQ5MjY4Mjc0LAogICAgICAgIDIwNDQ1MDgzMjQsCiAgICAgICAgMzc3MjExNTIzMCwKICAgICAgICAyNTQ3MTc3ODY0LAogICAgICAgIDE2Mjk0MTk5NSwKICAgICAgICAyMTI1NTYxMDIxLAogICAgICAgIDM4ODc2MDcwNDcsCiAgICAgICAgMjQyODQ0NDA0OSwKICAgICAgICA0OTg1MzY1NDgsCiAgICAgICAgMTc4OTkyNzY2NiwKICAgICAgICA0MDg5MDE2NjQ4LAogICAgICAgIDIyMjcwNjEyMTQsCiAgICAgICAgNDUwNTQ4ODYxLAogICAgICAgIDE4NDMyNTg2MDMsCiAgICAgICAgNDEwNzU4MDc1MywKICAgICAgICAyMjExNjc3NjM5LAogICAgICAgIDMyNTg4Mzk5MCwKICAgICAgICAxNjg0Nzc3MTUyLAogICAgICAgIDQyNTExMjIwNDIsCiAgICAgICAgMjMyMTkyNjYzNiwKICAgICAgICAzMzU2MzM0ODcsCiAgICAgICAgMTY2MTM2NTQ2NSwKICAgICAgICA0MTk1MzAyNzU1LAogICAgICAgIDIzNjYxMTUzMTcsCiAgICAgICAgOTk3MDczMDk2LAogICAgICAgIDEyODE5NTM4ODYsCiAgICAgICAgMzU3OTg1NTMzMiwKICAgICAgICAyNzI0Njg4MjQyLAogICAgICAgIDEwMDY4ODgxNDUsCiAgICAgICAgMTI1ODYwNzY4NywKICAgICAgICAzNTI0MTAxNjI5LAogICAgICAgIDI3Njg5NDI0NDMsCiAgICAgICAgOTAxMDk3NzIyLAogICAgICAgIDExMTkwMDA2ODQsCiAgICAgICAgMzY4NjUxNzIwNiwKICAgICAgICAyODk4MDY1NzI4LAogICAgICAgIDg1MzA0NDQ1MSwKICAgICAgICAxMTcyMjY2MTAxLAogICAgICAgIDM3MDUwMTU3NTksCiAgICAgICAgMjg4MjYxNjY2NSwKICAgICAgICA2NTE3Njc5ODAsCiAgICAgICAgMTM3MzUwMzU0NiwKICAgICAgICAzMzY5NTU0MzA0LAogICAgICAgIDMyMTgxMDQ1OTgsCiAgICAgICAgNTY1NTA3MjUzLAogICAgICAgIDE0NTQ2MjE3MzEsCiAgICAgICAgMzQ4NTExMTcwNSwKICAgICAgICAzMDk5NDM2MzAzLAogICAgICAgIDY3MTI2Njk3NCwKICAgICAgICAxNTk0MTk4MDI0LAogICAgICAgIDMzMjI3MzA5MzAsCiAgICAgICAgMjk3MDM0NzgxMiwKICAgICAgICA3OTU4MzU1MjcsCiAgICAgICAgMTQ4MzIzMDIyNSwKICAgICAgICAzMjQ0MzY3Mjc1LAogICAgICAgIDMwNjAxNDk1NjUsCiAgICAgICAgMTk5NDE0NjE5MiwKICAgICAgICAzMTE1ODUzNCwKICAgICAgICAyNTYzOTA3NzcyLAogICAgICAgIDQwMjM3MTc5MzAsCiAgICAgICAgMTkwNzQ1OTQ2NSwKICAgICAgICAxMTI2MzcyMTUsCiAgICAgICAgMjY4MDE1MzI1MywKICAgICAgICAzOTA0NDI3MDU5LAogICAgICAgIDIwMTM3NzYyOTAsCiAgICAgICAgMjUxNzIyMDM2LAogICAgICAgIDI1MTcyMTUzNzQsCiAgICAgICAgMzc3NTgzMDA0MCwKICAgICAgICAyMTM3NjU2NzYzLAogICAgICAgIDE0MTM3NjgxMywKICAgICAgICAyNDM5Mjc3NzE5LAogICAgICAgIDM4NjUyNzEyOTcsCiAgICAgICAgMTgwMjE5NTQ0NCwKICAgICAgICA0NzY4NjQ4NjYsCiAgICAgICAgMjIzODAwMTM2OCwKICAgICAgICA0MDY2NTA4ODc4LAogICAgICAgIDE4MTIzNzA5MjUsCiAgICAgICAgNDUzMDkyNzMxLAogICAgICAgIDIxODE2MjUwMjUsCiAgICAgICAgNDExMTQ1MTIyMywKICAgICAgICAxNzA2MDg4OTAyLAogICAgICAgIDMxNDA0MjcwNCwKICAgICAgICAyMzQ0NTMyMjAyLAogICAgICAgIDQyNDAwMTc1MzIsCiAgICAgICAgMTY1ODY1ODI3MSwKICAgICAgICAzNjY2MTk5NzcsCiAgICAgICAgMjM2MjY3MDMyMywKICAgICAgICA0MjI0OTk0NDA1LAogICAgICAgIDEzMDM1MzU5NjAsCiAgICAgICAgOTg0OTYxNDg2LAogICAgICAgIDI3NDcwMDcwOTIsCiAgICAgICAgMzU2OTAzNzUzOCwKICAgICAgICAxMjU2MTcwODE3LAogICAgICAgIDEwMzc2MDQzMTEsCiAgICAgICAgMjc2NTIxMDczMywKICAgICAgICAzNTU0MDc5OTk1LAogICAgICAgIDExMzEwMTQ1MDYsCiAgICAgICAgODc5Njc5OTk2LAogICAgICAgIDI5MDkyNDM0NjIsCiAgICAgICAgMzY2Mzc3MTg1NiwKICAgICAgICAxMTQxMTI0NDY3LAogICAgICAgIDg1NTg0MjI3NywKICAgICAgICAyODUyODAxNjMxLAogICAgICAgIDM3MDg2NDg2NDksCiAgICAgICAgMTM0MjUzMzk0OCwKICAgICAgICA2NTQ0NTkzMDYsCiAgICAgICAgMzE4ODM5NjA0OCwKICAgICAgICAzMzczMDE1MTc0LAogICAgICAgIDE0NjY0Nzk5MDksCiAgICAgICAgNTQ0MTc5NjM1LAogICAgICAgIDMxMTA1MjM5MTMsCiAgICAgICAgMzQ2MjUyMjAxNSwKICAgICAgICAxNTkxNjcxMDU0LAogICAgICAgIDcwMjEzODc3NiwKICAgICAgICAyOTY2NDYwNDUwLAogICAgICAgIDMzNTI3OTk0MTIsCiAgICAgICAgMTUwNDkxODgwNywKICAgICAgICA3ODM1NTE4NzMsCiAgICAgICAgMzA4MjY0MDQ0MywKICAgICAgICAzMjMzNDQyOTg5LAogICAgICAgIDM5ODgyOTIzODQsCiAgICAgICAgMjU5NjI1NDY0NiwKICAgICAgICA2MjMxNzA2OCwKICAgICAgICAxOTU3ODEwODQyLAogICAgICAgIDM5Mzk4NDU5NDUsCiAgICAgICAgMjY0NzgxNjExMSwKICAgICAgICA4MTQ3MDk5NywKICAgICAgICAxOTQzODAzNTIzLAogICAgICAgIDM4MTQ5MTg5MzAsCiAgICAgICAgMjQ4OTU5NjgwNCwKICAgICAgICAyMjUyNzQ0MzAsCiAgICAgICAgMjA1Mzc5MDM3NiwKICAgICAgICAzODI2MTc1NzU1LAogICAgICAgIDI0NjY5MDYwMTMsCiAgICAgICAgMTY3ODE2NzQzLAogICAgICAgIDIwOTc2NTEzNzcsCiAgICAgICAgNDAyNzU1MjU4MCwKICAgICAgICAyMjY1NDkwMzg2LAogICAgICAgIDUwMzQ0NDA3MiwKICAgICAgICAxNzYyMDUwODE0LAogICAgICAgIDQxNTA0MTcyNDUsCiAgICAgICAgMjE1NDEyOTM1NSwKICAgICAgICA0MjY1MjIyMjUsCiAgICAgICAgMTg1MjUwNzg3OSwKICAgICAgICA0Mjc1MzEzNTI2LAogICAgICAgIDIzMTIzMTc5MjAsCiAgICAgICAgMjgyNzUzNjI2LAogICAgICAgIDE3NDI1NTU4NTIsCiAgICAgICAgNDE4OTcwODE0MywKICAgICAgICAyMzk0ODc3OTQ1LAogICAgICAgIDM5NzkxNzc2MywKICAgICAgICAxNjIyMTgzNjM3LAogICAgICAgIDM2MDQzOTA4ODgsCiAgICAgICAgMjcxNDg2NjU1OCwKICAgICAgICA5NTM3Mjk3MzIsCiAgICAgICAgMTM0MDA3NjYyNiwKICAgICAgICAzNTE4NzE5OTg1LAogICAgICAgIDI3OTczNjA5OTksCiAgICAgICAgMTA2ODgyODM4MSwKICAgICAgICAxMjE5NjM4ODU5LAogICAgICAgIDM2MjQ3NDE4NTAsCiAgICAgICAgMjkzNjY3NTE0OCwKICAgICAgICA5MDYxODU0NjIsCiAgICAgICAgMTA5MDgxMjUxMiwKICAgICAgICAzNzQ3NjcyMDAzLAogICAgICAgIDI4MjUzNzk2NjksCiAgICAgICAgODI5MzI5MTM1LAogICAgICAgIDExODEzMzUxNjEsCiAgICAgICAgMzQxMjE3NzgwNCwKICAgICAgICAzMTYwODM0ODQyLAogICAgICAgIDYyODA4NTQwOCwKICAgICAgICAxMzgyNjA1MzY2LAogICAgICAgIDM0MjMzNjkxMDksCiAgICAgICAgMzEzODA3ODQ2NywKICAgICAgICA1NzA1NjIyMzMsCiAgICAgICAgMTQyNjQwMDgxNSwKICAgICAgICAzMzE3MzE2NTQyLAogICAgICAgIDI5OTg3MzM2MDgsCiAgICAgICAgNzMzMjM5OTU0LAogICAgICAgIDE1NTUyNjE5NTYsCiAgICAgICAgMzI2ODkzNTU5MSwKICAgICAgICAzMDUwMzYwNjI1LAogICAgICAgIDc1MjQ1OTQwMywKICAgICAgICAxNTQxMzIwMjIxLAogICAgICAgIDI2MDcwNzE5MjAsCiAgICAgICAgMzk2NTk3MzAzMCwKICAgICAgICAxOTY5OTIyOTcyLAogICAgICAgIDQwNzM1NDk4LAogICAgICAgIDI2MTc4MzcyMjUsCiAgICAgICAgMzk0MzU3NzE1MSwKICAgICAgICAxOTEzMDg3ODc3LAogICAgICAgIDgzOTA4MzcxLAogICAgICAgIDI1MTIzNDE2MzQsCiAgICAgICAgMzgwMzc0MDY5MiwKICAgICAgICAyMDc1MjA4NjIyLAogICAgICAgIDIxMzI2MTExMiwKICAgICAgICAyNDYzMjcyNjAzLAogICAgICAgIDM4NTU5OTAyODUsCiAgICAgICAgMjA5NDg1NDA3MSwKICAgICAgICAxOTg5NTg4ODEsCiAgICAgICAgMjI2MjAyOTAxMiwKICAgICAgICA0MDU3MjYwNjEwLAogICAgICAgIDE3NTkzNTk5OTIsCiAgICAgICAgNTM0NDE0MTkwLAogICAgICAgIDIxNzY3MTg1NDEsCiAgICAgICAgNDEzOTMyOTExNSwKICAgICAgICAxODczODM2MDAxLAogICAgICAgIDQxNDY2NDU2NywKICAgICAgICAyMjgyMjQ4OTM0LAogICAgICAgIDQyNzkyMDAzNjgsCiAgICAgICAgMTcxMTY4NDU1NCwKICAgICAgICAyODUyODExMTYsCiAgICAgICAgMjQwNTgwMTcyNywKICAgICAgICA0MTY3MjE2NzQ1LAogICAgICAgIDE2MzQ0Njc3OTUsCiAgICAgICAgMzc2MjI5NzAxLAogICAgICAgIDI2ODUwNjc4OTYsCiAgICAgICAgMzYwODAwNzQwNiwKICAgICAgICAxMzA4OTE4NjEyLAogICAgICAgIDk1NjU0MzkzOCwKICAgICAgICAyODA4NTU1MTA1LAogICAgICAgIDM0OTU5NTgyNjMsCiAgICAgICAgMTIzMTYzNjMwMSwKICAgICAgICAxMDQ3NDI3MDM1LAogICAgICAgIDI5MzI5NTk4MTgsCiAgICAgICAgMzY1NDcwMzgzNiwKICAgICAgICAxMDg4MzU5MjcwLAogICAgICAgIDkzNjkxOGUzLAogICAgICAgIDI4NDc3MTQ4OTksCiAgICAgICAgMzczNjgzNzgyOSwKICAgICAgICAxMjAyOTAwODYzLAogICAgICAgIDgxNzIzMzg5NywKICAgICAgICAzMTgzMzQyMTA4LAogICAgICAgIDM0MDEyMzcxMzAsCiAgICAgICAgMTQwNDI3NzU1MiwKICAgICAgICA2MTU4MTgxNTAsCiAgICAgICAgMzEzNDIwNzQ5MywKICAgICAgICAzNDUzNDIxMjAzLAogICAgICAgIDE0MjM4NTc0NDksCiAgICAgICAgNjAxNDUwNDMxLAogICAgICAgIDMwMDk4Mzc2MTQsCiAgICAgICAgMzI5NDcxMDQ1NiwKICAgICAgICAxNTY3MTAzNzQ2LAogICAgICAgIDcxMTkyODcyNCwKICAgICAgICAzMDIwNjY4NDcxLAogICAgICAgIDMyNzIzODAwNjUsCiAgICAgICAgMTUxMDMzNDIzNSwKICAgICAgICA3NTUxNjcxMTcKICAgICAgXTsKICAgICAgaWYgKHR5cGVvZiBJbnQzMkFycmF5ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgIENSQ19UQUJMRSA9IG5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W50cmllcy5qcyIoZXhwb3J0cywgbW9kdWxlKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgaGFzID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICB2YXIgaXNFbnVtZXJhYmxlID0gZnVuY3Rpb24ob2JqLCBwcm9wKSB7CiAgICAgICAgcmV0dXJuIE9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChvYmosIHByb3ApOwogICAgICB9OwogICAgICBmdW5jdGlvbiBlbnRyaWVzMihvYmopIHsKICAgICAgICBpZiAob2JqID09IG51bGwpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkNhbm5vdCBjb252ZXJ0IHVuZGVmaW5lZCBvciBudWxsIHRvIG9iamVjdCIpOwogICAgICAgIH0KICAgICAgICB2YXIgcGFpcnMgPSBbXTsKICAgICAgICBmb3IgKHZhciBrZXkgaW4gb2JqKSB7CiAgICAgICAgICBpZiAoaGFzKG9iaiwga2V5KSAmJiBpc0VudW1lcmFibGUob2JqLCBrZXkpKSB7CiAgICAgICAgICAgIHBhaXJzLnB1c2goW2tleSwgb2JqW2tleV1dKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHBhaXJzOwogICAgICB9CiAgICAgIG1vZHVsZS5leHBvcnRzID0gZW50cmllczI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9vYmplY3QuZW50cmllcy1wb255ZmlsbEAxLjAuMS9ub2RlX21vZHVsZXMvb2JqZWN0LmVudHJpZXMtcG9ueWZpbGwvaW5kZXguanMKICB2YXIgcmVxdWlyZV9vYmplY3QgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21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3MpIHsKICAgICAgICBpZiAodHlwZW9mIHN1cGVyQ2xhc3MgIT09ICJmdW5jdGlvbiIgJiYgc3VwZXJDbGFzcyAhPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiU3VwZXIgZXhwcmVzc2lvbiBtdXN0IGVpdGhlciBiZSBudWxsIG9yIGEgZnVuY3Rpb24iKTsKICAgICAgICB9CiAgICAgICAgc3ViQ2xhc3MucHJvdG90eXBlID0gT2JqZWN0LmNyZWF0ZShzdXBlckNsYXNzICYmIHN1cGVyQ2xhc3MucHJvdG90eXBlLCB7CiAgICAgICAgICBjb25zdHJ1Y3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyID09PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBSZWZlcmVuY2VFcnJvcigidGhpcyBoYXNuJ3QgYmVlbiBpbml0aWFsaXNlZCAtIHN1c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mVzdWx0ID0gU3VwZXIuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybih0aGlzLCByZXN1bHQpOwogICAgICAgIH07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3N1cGVyUHJvcEJhc2Uob2JqZWN0LCBwcm9wZXJ0eSkgewogICAgICAgIHdoaWxlICghT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iamVjdCwgcHJvcGVydHkpKSB7CiAgICAgICAgICBvYmplY3QgPSBfZ2V0UHJvdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRDb250cm9sbGVyXSI7CiAgICAgICAgICB9CiAgICAgICAgfV0pOwogICAgICAgIHJldHVybiBBYm9ydENvbnRyb2xsZXIyOwogICAgICB9KCk7CiAgICAgIGlmICh0eXBlb2YgU3ltYm9sICE9PSAidW5kZWZpbmVkIiAmJiBTeW1ib2wudG9TdHJpbmdUYWcpIHsKICAgICAgICBBYm9ydENvbnRyb2xsZXIucHJvdG90eXBlW1N5bWJvbC50b1N0cmluZ1RhZ10gPSAiQWJvcnRDb250cm9sbGVyIjsKICAgICAgICBBYm9ydFNpZ25hbC5wcm90b3R5cGVbU3ltYm9sLnRvU3RyaW5nVGFnXSA9ICJBYm9ydFNpZ25hbCI7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcG9seWZpbGxOZWVkZWQoc2VsZjIpIHsKICAgICAgICBpZiAoc2VsZjIuX19GT1JDRV9JTlNUQUxMX0FCT1JUQ09OVFJPTExFUl9QT0xZRklMTCkgewogICAgICAgICAgY29uc29sZS5sb2coIl9fRk9SQ0VfSU5TVEFMTF9BQk9SVENPTlRST0xMRVJfUE9MWUZJTEw9dHJ1ZSBp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ICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2gyOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWxGZXRjaChpbnB1dCwgaW5pdDIpXSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVhbEZldGNoKGlucHV0LCBpbml0Mik7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgZmV0Y2g6IGFib3J0YWJsZUZldGNoLAogICAgICAgICAgUmVxdWVzdAogICAgICAgIH07CiAgICAgIH0KICAgICAgZXhwb3J0cy5BYm9ydENvbnRyb2xsZXIgPSBBYm9ydENvbnRyb2xsZXI7CiAgICAgIGV4cG9ydHMuQWJvcnRTaWduYWwgPSBBYm9ydFNpZ25hbDsKICAgICAgZXhwb3J0cy5hYm9ydGFibGVGZXRjaCA9IGFib3J0YWJsZUZldGNoRGVjb3JhdG9yOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlL2VzbS9hYm9ydGNvbnRyb2xsZXItcG9ueWZpbGwuanMKICB2YXIg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yB7CiAgICAgIH07CiAgICAgIHZhciBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXIgPSBjbGFzcyB7CiAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICB0aGlzLnNpZ25hbHMgPSBuZXcgU2V0KCk7CiAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlciA9IG5ldyBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMS5BYm9ydENvbnRyb2xsZXIoKTsKICAgICAgICB9CiAgICAgICAgYWRkU2lnbmFsKHNpZ25hbCA9IG5ldyBOdWxsU2lnbmFsKCkpIHsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiY2Fubm90IGFkZCBhIHNpZ25hbCwgYWxyZWFkeSBhYm9ydGVkISIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5zaWduYWxzLmFkZChzaWduYWwpOwogICAgICAgICAgaWYgKHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2Ygc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIgPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgKCkgPT4gewogICAgICAgICAgICAgIHRoaXMuaGFuZGxlQWJvcnRlZChzaWduYWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaGFuZGxlQWJvcnRlZChzaWduYWwpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscy5kZWxldGUoc2lnbmFsKTsKICAgICAgICAgIGlmICh0aGlzLnNpZ25hbHMuc2l6ZSA9PT0gMCkgewogICAgICAgICAgICB0aGlzLmFib3J0Q29udHJvbGxlci5hYm9ydCgpOwogICAgICAgICA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CwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICB0aHJvdyBlcnJvcjsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgaWYgKCFzaWduYWwgJiYgZGF0YSBpbnN0YW5jZW9mIGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0U2lnbmFsKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInNlY29uZCBnZXQgYXJndW1lbnQgYXBwZWFycyB0byBiZSBhbiBBYm9ydFNpZ25hbCwgcGVyaGFwcyB5b3UgbWVhbnQgdG8gcGFzcyBgbnVsbGAgZm9yIHRoZSBmaWxsIGRhdGE/Iik7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBjYWNoZUVudHJ5ID0gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIGlmIChjYWNoZUVudHJ5KSB7CiAgICAgICAgICAgIGlmIChjYWNoZUVudHJ5LmFib3J0ZWQgJiYgIWNhY2hlRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBjYWNoZUVudHJ5KTsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy5nZXQoa2V5LCBkYXRhLCBzaWduYWwsIHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoY2FjaGVFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlRW50cnkucHJvbWlzZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjYWNoZUVudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICAgIGNhY2hlRW50cnkuc3RhdHVzUmVwb3J0ZXIuYWRkQ2FsbGJhY2soc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UoY2FjaGVFbnRyeS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5maWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZ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UgPSAwOwogICAgICAgIH0KICAgICAgICBfc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgdGhpcy5fc2l6ZSsrOwogICAgICAgICAgaWYgKHRoaXMuX3NpemUgPj0gdGhpcy5tYXhTaXplKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlID0gdGhpcy5jYWNoZTsKICAgICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0KGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICBjb25zdCB2YWx1ZSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSkgfHwgdGhpcy5vbGRDYWNoZS5oYXMoa2V5KTsKICAgICAgICB9CiAgICAgICAgcGVlayhrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRlbGV0ZShrZXkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgaWYgKGRlbGV0ZWQpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZS0tOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMub2xkQ2FjaGUuZGVsZXRlKGtleSkgfHwgZGVsZXRlZDsKICAgICAgICB9CiAgICAgICAgY2xlYXIoKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlLmNsZWFyKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgKmtleXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFtrZXldIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQga2V5OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqdmFsdWVzKCkgewogICAgICAgICAgZm9yIChjb25zdCBbLCB2YWx1ZV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKltTeW1ib2wuaXRlcmF0b3JdKCkgewogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICAgICAgeWllbGQgaXRlbTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB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HNlYXJjaFBhcmFtczogIlVSTFNlYXJjaFBhcmFtcyIgaW4gc2VsZjIsCiAgICAgICAgICAgIGl0ZXJhYmxlOiAiU3ltYm9sIiBpbiBzZWxmMiAmJiAiaXRlcmF0b3IiIGluIFN5bWJvbCwKICAgICAgICAgICAgYmxvYjogIkZpbGVSZWFkZXIiIGluIHNlbGYyICYmICJCbG9iIiBpbiBzZWxmMiAmJiBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbmV3IEJsb2IoKTsKICAgICAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0oKSwKICAgICAgICAgICAgZm9ybURhdGE6ICJGb3JtRGF0YSIgaW4gc2VsZjIsCiAgICAgICAgICAgIGFycmF5QnVmZmVyOiAiQXJyYXlCdWZmZXIiIGluIHNlbGYyCiAgICAgICAgICB9OwogICAgICAgICAgZnVuY3Rpb24gaXNEYXRhVmlldyhvYmopIHsKICAgICAgICAgICAgcmV0dXJuIG9iaiAmJiBEYXRhVmlldy5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihvYmopOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN1cHBvcnQuYXJyYXlCdWZmZXIpIHsKICAgICAgICAgICAgdmFyIHZpZXdDbGFzc2VzID0gWwogICAgICAgICAgICAgICJbb2JqZWN0IEludDhBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IFVpbnQ4QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50OENsYW1wZWRBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDE2QXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MTZBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEludDMyQXJyYXldIiwKICAgICAgICAgICAgICAiW29iamVjdCBVaW50MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0MzJBcnJheV0iLAogICAgICAgICAgICAgICJbb2JqZWN0IEZsb2F0NjRBcnJheV0iCiAgICAgICAgICAgIF07CiAgICAgICAgICAgIHZhciBpc0FycmF5QnVmZmVyVmlldyA9IEFycmF5QnVmZmVyLmlzVmlldyB8fCBmdW5jdGlvbihvYmopIHsKICAgICAgICAgICAgICByZXR1cm4gb2JqICYmIHZpZXdDbGFzc2VzLmluZGV4T2YoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKG9iaikpID4gLTE7CiAgICAgICAgICAgIH07CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBub3JtYWxpemVOYW1lKG5hbWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiBuYW1lICE9PSAic3RyaW5nIikgewogICAgICAgICAgICAgIG5hbWUgPSBTdHJpbmcobmFtZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKC9bXmEtejAtOVwtIyQlJicqKy5eX2B8fl0vaS50ZXN0KG5hbWUpKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiSW52YWxpZCBjaGFyYWN0ZXIgaW4gaGVhZGVyIGZpZWxkIG5hbWUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmFtZS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gbm9ybWFsaXplVmFsdWUodmFsdWUpIHsKICAgICAgICAgICAgaWYgKHR5cGVvZiB2YWx1ZSAhPT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB2YWx1ZSA9IFN0cmluZyh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHZhbHVlOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gaXRlcmF0b3JGb3IoaXRlbXMpIHsKICAgICAgICAgICAgdmFyIGl0ZXJhdG9yID0gewogICAgICAgICAgICAgIG5leHQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gaXRlbXMuc2hpZnQoKTsKICAgICAgICAgICAgICAgIHJldHVybiB7IGRvbmU6IHZhbHVlID09PSB2b2lkIDAsIHZhbHVlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5pdGVyYWJsZSkgewogICAgICAgICAgICAgIGl0ZXJhdG9yW1N5bWJvbC5pdGVyYXRvcl0gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBpdGVyYXRvcjsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEhlYWRlcnMoaGVhZGVycykgewogICAgICAgICAgICB0aGlzLm1hcCA9IHt9OwogICAgICAgICAgICBpZiAoaGVhZGVycyBpbnN0YW5jZW9mIEhlYWRlcnMpIHsKICAgICAgICAgICAgICBoZWFkZXJzLmZvckVhY2goZnVuY3Rpb24odmFsdWUsIG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIHZhbHVlKTsKICAgICAgICAgICAgICB9LCB0aGlzKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChBcnJheS5pc0FycmF5KGhlYWRlcnMpKSB7CiAgICAgICAgICAgICAgaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKGhlYWRlcikgewogICAgICAgICAgICAgICAgdGhpcy5hcHBlbmQoaGVhZGVyWzBdLCBoZWFkZXJbMV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGhlYWRlcnMpIHsKICAgICAgICAgICAgICBPYmplY3QuZ2V0T3duUHJvcGVydHlOYW1lcyhoZWFkZXJzKS5mb3JFYWNoKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgICAgICAgIHRoaXMuYXBwZW5kKG5hbWUsIGhlYWRlcnNbbmFtZV0pOwogICAgICAgICAgICAgIH0sIHRoaXMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5hcHBlbmQgPSBmdW5jdGlvbihuYW1lLCB2YWx1ZSkgewogICAgICAgICAgICBuYW1lID0gbm9ybWFsaXplTmFtZShuYW1lKTsKICAgICAgICAgICAgdmFsdWUgPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICAgIHZhciBvbGRWYWx1ZSA9IHRoaXMubWFwW25hbWVdOwogICAgICAgICAgICB0aGlzLm1hcFtuYW1lXSA9IG9sZFZhbHVlID8gb2xkVmFsdWUgKyAiLCAiICsgdmFsdWUgOiB2YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZVsiZGVsZXRlIl0gPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm1hcFtub3JtYWxpemVOYW1lKG5hbWUpXTsKICAgICAgICAgIH07CiAgICAgICAgICBIZWFkZXJzLnByb3RvdHlwZS5nZXQgPSBmdW5jdGlvbihuYW1lKSB7CiAgICAgICAgICAgIG5hbWUgPSBub3JtYWxpemVOYW1lKG5hbWUpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5oYXMobmFtZSkgPyB0aGlzLm1hcFtuYW1lXSA6IG51bGw7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuaGFzID0gZnVuY3Rpb24obmFtZSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5tYXAuaGFzT3duUHJvcGVydHkobm9ybWFsaXplTmFtZShuYW1lKSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuc2V0ID0gZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAgICAgICAgdGhpcy5tYXBbbm9ybWFsaXplTmFtZShuYW1lKV0gPSBub3JtYWxpemVWYWx1ZSh2YWx1ZSk7CiAgICAgICAgICB9OwogICAgICAgICAgSGVhZGVycy5wcm90b3R5cGUuZm9yRWFjaCA9IGZ1bmN0aW9uKGNhbGxiYWNrLCB0aGlzQXJnKSB7CiAgICAgICAgICAgIGZvciAodmFyIG5hbWUgaW4gdGhpcy5tYXApIHsKICAgICAgICAgICAgICBpZiAodGhpcy5tYXAuaGFzT3duUHJvcGVydHkobmFtZSkpIHsKICAgICAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwodGhpc0FyZywgdGhpcy5tYXBbbmFtZV0sIG5hbWUsIHRoaXMpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmtleXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2gobmFtZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLnZhbHVlcyA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICB2YXIgaXRlbXMgPSBbXTsKICAgICAgICAgICAgdGhpcy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgICAgaXRlbXMucHVzaCh2YWx1ZSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlLmVudHJpZXMgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgdmFyIGl0ZW1zID0gW107CiAgICAgICAgICAgIHRoaXMuZm9yRWFjaChmdW5jdGlvbih2YWx1ZSwgbmFtZSkgewogICAgICAgICAgICAgIGl0ZW1zLnB1c2goW25hbWUsIHZhbHVlXSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaXRlcmF0b3JGb3IoaXRlbXMpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChzdXBwb3J0Lml0ZXJhYmxlKSB7CiAgICAgICAgICAgIEhlYWRlcnMucHJvdG90eXBlW1N5bWJvbC5pdGVyYXRvcl0gPSBIZWFkZXJzLnByb3RvdHlwZS5lbnRyaWVzOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gY29uc3VtZWQoYm9keSkgewogICAgICAgICAgICBpZiAoYm9keS5ib2R5VXNlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYm9keS5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmaWxlUmVhZGVyUmVhZHkocmVhZGVyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICByZWFkZXIub25sb2FkID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXNvbHZlKHJlYWRlci5yZXN1bHQpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgcmVhZGVyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChyZWFkZXIuZXJyb3IpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcmVhZEJsb2JBc0FycmF5QnVmZmVyKGJsb2IpIHsKICAgICAgICAgICAgdmFyIHJlYWRlciA9IG5ldyBGaWxlUmVhZGVyKCk7CiAgICAgICAgICAgIHZhciBwcm9taXNlID0gZmlsZVJlYWRlclJlYWR5KHJlYWRlcik7CiAgICAgICAgICAgIHJlYWRlci5yZWFkQXNBcnJheUJ1ZmZlcihibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQmxvYkFzVGV4dChibG9iKSB7CiAgICAgICAgICAgIHZhciByZWFkZXIgPSBuZXcgRmlsZVJlYWRlcigpOwogICAgICAgICAgICB2YXIgcHJvbWlzZSA9IGZpbGVSZWFkZXJSZWFkeShyZWFkZXIpOwogICAgICAgICAgICByZWFkZXIucmVhZEFzVGV4dChibG9iKTsKICAgICAgICAgICAgcmV0dXJuIHByb21pc2U7CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWFkQXJyYXlCdWZmZXJBc1RleHQoYnVmKSB7CiAgICAgICAgICAgIHZhciB2aWV3ID0gbmV3IFVpbnQ4QXJyYXkoYnVmKTsKICAgICAgICAgICAgdmFyIGNoYXJzID0gbmV3IEFycmF5KHZpZXcubGVuZ3RoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCB2aWV3Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgICAgY2hhcnNbaV0gPSBTdHJpbmcuZnJvbUNoYXJDb2RlKHZpZXdbaV0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBjaGFycy5qb2luKCIiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIGJ1ZmZlckNsb25lKGJ1ZikgewogICAgICAgICAgICBpZiAoYnVmLnNsaWNlKSB7CiAgICAgICAgICAgICAgcmV0dXJuIGJ1Zi5zbGljZSgwKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YXIgdmlldyA9IG5ldyBVaW50OEFycmF5KGJ1Zi5ieXRlTGVuZ3RoKTsKICAgICAgICAgICAgICB2aWV3LnNldChuZXcgVWludDhBcnJheShidWYpKTsKICAgICAgICAgICAgICByZXR1cm4gdmlldy5idWZmZXI7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIEJvZHkoKSB7CiAgICAgICAgICAgIHRoaXMuYm9keVVzZWQgPSBmYWxzZTsKICAgICAgICAgICAgdGhpcy5faW5pdEJvZHkgPSBmdW5jdGlvbihib2R5KSB7CiAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBib2R5OwogICAgICAgICAgICAgIGlmICghYm9keSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSAiIjsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBib2R5ID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keVRleHQgPSBib2R5OwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5ibG9iICYmIEJsb2IucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlCbG9iID0gYm9keTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHN1cHBvcnQuZm9ybURhdGEgJiYgRm9ybURhdGEucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlGb3JtRGF0YSA9IGJvZHk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlUZXh0ID0gYm9keS50b1N0cmluZygpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoc3VwcG9ydC5hcnJheUJ1ZmZlciAmJiBzdXBwb3J0LmJsb2IgJiYgaXNEYXRhVmlldyhib2R5KSkgewogICAgICAgICAgICAgICAgdGhpcy5fYm9keUFycmF5QnVmZmVyID0gYnVmZmVyQ2xvbmUoYm9keS5idWZmZXIpOwogICAgICAgICAgICAgICAgdGhpcy5fYm9keUluaXQgPSBuZXcgQmxvYihbdGhpcy5fYm9keUFycmF5QnVmZmVyXSk7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LmFycmF5QnVmZmVyICYmIChBcnJheUJ1ZmZlci5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihib2R5KSB8fCBpc0FycmF5QnVmZmVyVmlldyhib2R5KSkpIHsKICAgICAgICAgICAgICAgIHRoaXMuX2JvZHlBcnJheUJ1ZmZlciA9IGJ1ZmZlckNsb25lKGJvZHkpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLl9ib2R5VGV4dCA9IGJvZHkgPSBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwoYm9keSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmICghdGhpcy5oZWFkZXJzLmdldCgiY29udGVudC10eXBlIikpIHsKICAgICAgICAgICAgICAgIGlmICh0eXBlb2YgYm9keSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgInRleHQvcGxhaW47Y2hhcnNldD1VVEYtOCIpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmICh0aGlzLl9ib2R5QmxvYiAmJiB0aGlzLl9ib2R5QmxvYi50eXBlKSB7CiAgICAgICAgICAgICAgICAgIHRoaXMuaGVhZGVycy5zZXQoImNvbnRlbnQtdHlwZSIsIHRoaXMuX2JvZHlCbG9iLnR5cGUpOwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChzdXBwb3J0LnNlYXJjaFBhcmFtcyAmJiBVUkxTZWFyY2hQYXJhbXMucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoYm9keSkpIHsKICAgICAgICAgICAgICAgICAgdGhpcy5oZWFkZXJzLnNldCgiY29udGVudC10eXBlIiwgImFwcGxpY2F0aW9uL3gtd3d3LWZvcm0tdXJsZW5jb2RlZDtjaGFyc2V0PVVURi04Iik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5ibG9iKSB7CiAgICAgICAgICAgICAgdGhpcy5ibG9iID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICAgIGlmIChyZWplY3RlZCkgewogICAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0ZWQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUJsb2IpIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5QmxvYik7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlBcnJheUJ1ZmZlcikgewogICAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKG5ldyBCbG9iKFt0aGlzLl9ib2R5QXJyYXlCdWZmZXJdKSk7CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImNvdWxkIG5vdCByZWFkIEZvcm1EYXRhIGJvZHkgYXMgYmxvYiIpOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZShuZXcgQmxvYihbdGhpcy5fYm9keVRleHRdKSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB0aGlzLmFycmF5QnVmZmVyID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiBjb25zdW1lZCh0aGlzKSB8fCBQcm9taXNlLnJlc29sdmUodGhpcy5fYm9keUFycmF5QnVmZmVyKTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLmJsb2IoKS50aGVuKHJlYWRCbG9iQXNBcnJheUJ1ZmZlcik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnRleHQgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICB2YXIgcmVqZWN0ZWQgPSBjb25zdW1lZCh0aGlzKTsKICAgICAgICAgICAgICBpZiAocmVqZWN0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3RlZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHRoaXMuX2JvZHlCbG9iKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVhZEJsb2JBc1RleHQodGhpcy5fYm9keUJsb2IpOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAodGhpcy5fYm9keUFycmF5QnVmZmVyKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZXNvbHZlKHJlYWRBcnJheUJ1ZmZlckFzVGV4dCh0aGlzLl9ib2R5QXJyYXlCdWZmZXIpKTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKHRoaXMuX2JvZHlGb3JtRGF0YSkgewogICAgICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjb3VsZCBub3QgcmVhZCBGb3JtRGF0YSBib2R5IGFzIHRleHQiKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmV0dXJuIFByb21pc2UucmVzb2x2ZSh0aGlzLl9ib2R5VGV4dCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwogICAgICAgICAgICBpZiAoc3VwcG9ydC5mb3JtRGF0YSkgewogICAgICAgICAgICAgIHRoaXMuZm9ybURhdGEgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJldHVybiB0aGlzLnRleHQoKS50aGVuKGRlY29kZSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmpzb24gPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICByZXR1cm4gdGhpcy50ZXh0KCkudGhlbihKU09OLnBhcnNlKTsKICAgICAgICAgICAgfTsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbWV0aG9kcyA9IFsiREVMRVRFIiwgIkdFVCIsICJIRUFEIiwgIk9QVElPTlMiLCAiUE9TVCIsICJQVVQiXTsKICAgICAgICAgIGZ1bmN0aW9uIG5vcm1hbGl6ZU1ldGhvZChtZXRob2QpIHsKICAgICAgICAgICAgdmFyIHVwY2FzZWQgPSBtZXRob2QudG9VcHBlckNhc2UoKTsKICAgICAgICAgICAgcmV0dXJuIG1ldGhvZHMuaW5kZXhPZih1cGNhc2VkKSA+IC0xID8gdXBjYXNlZCA6IG1ldGhvZDsKICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIFJlcXVlc3QoaW5wdXQsIG9wdGlvbnMpIHsKICAgICAgICAgICAgb3B0aW9ucyA9IG9wdGlvbnMgfHwge307CiAgICAgICAgICAgIHZhciBib2R5ID0gb3B0aW9ucy5ib2R5OwogICAgICAgICAgICBpZiAoaW5wdXQgaW5zdGFuY2VvZiBSZXF1ZXN0KSB7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmJvZHlVc2VkKSB7CiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJBbHJlYWR5IHJlYWQiKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy51cmwgPSBpbnB1dC51cmw7CiAgICAgICAgICAgICAgdGhpcy5jcmVkZW50aWFscyA9IGlucHV0LmNyZWRlbnRpYWxzOwogICAgICAgICAgICAgIGlmICghb3B0aW9ucy5oZWFkZXJzKSB7CiAgICAgICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhpbnB1dC5oZWFkZXJzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBpbnB1dC5tZXRob2Q7CiAgICAgICAgICAgICAgdGhpcy5tb2RlID0gaW5wdXQubW9kZTsKICAgICAgICAgICAgICB0aGlzLnNpZ25hbCA9IGlucHV0LnNpZ25hbDsKICAgICAgICAgICAgICBpZiAoIWJvZHkgJiYgaW5wdXQuX2JvZHlJbml0ICE9IG51bGwpIHsKICAgICAgICAgICAgICAgIGJvZHkgPSBpbnB1dC5fYm9keUluaXQ7CiAgICAgICAgICAgICAgICBpbnB1dC5ib2R5VXNlZCA9IHRydWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMudXJsID0gU3RyaW5nKGlucHV0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNyZWRlbnRpYWxzID0gb3B0aW9ucy5jcmVkZW50aWFscyB8fCB0aGlzLmNyZWRlbnRpYWxzIHx8ICJzYW1lLW9yaWdpbiI7CiAgICAgICAgICAgIGlmIChvcHRpb25zLmhlYWRlcnMgfHwgIXRoaXMuaGVhZGVycykgewogICAgICAgICAgICAgIHRoaXMuaGVhZGVycyA9IG5ldyBIZWFkZXJzKG9wdGlvbnMuaGVhZGVycyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5tZXRob2QgPSBub3JtYWxpemVNZXRob2Qob3B0aW9ucy5tZXRob2QgfHwgdGhpcy5tZXRob2QgfHwgIkdFVCIpOwogICAgICAgICAgICB0aGlzLm1vZGUgPSBvcHRpb25zLm1vZGUgfHwgdGhpcy5tb2RlIHx8IG51bGw7CiAgICAgICAgICAgIHRoaXMuc2lnbmFsID0gb3B0aW9ucy5zaWduYWwgfHwgdGhpcy5zaWduYWw7CiAgICAgICAgICAgIHRoaXMucmVmZXJyZXIgPSBudWxsOwogICAgICAgICAgICBpZiAoKHRoaXMubWV0aG9kID09PSAiR0VUIiB8fCB0aGlzLm1ldGhvZCA9PT0gIkhFQUQiKSAmJiBib2R5KSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiQm9keSBub3QgYWxsb3dlZCBmb3IgR0VUIG9yIEhFQUQgcmVxdWVzdHMiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5KTsKICAgICAgICAgIH0KICAgICAgICAgIFJlcXVlc3QucHJvdG90eXBlLmNsb25lID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUmVxdWVzdCh0aGlzLCB7IGJvZHk6IHRoaXMuX2JvZHlJbml0IH0pOwogICAgICAgICAgfTsKICAgICAgICAgIGZ1bmN0aW9uIGRlY29kZShib2R5KSB7CiAgICAgICAgICAgIHZhciBmb3JtID0gbmV3IEZvcm1EYXRhKCk7CiAgICAgICAgICAgIGJvZHkudHJpbSgpLnNwbGl0KCImIikuZm9yRWFjaChmdW5jdGlvbihieXRlcykgewogICAgICAgICAgICAgIGlmIChieXRlcykgewogICAgICAgICAgICAgICAgdmFyIHNwbGl0ID0gYnl0ZXMuc3BsaXQoIj0iKTsKICAgICAgICAgICAgICAgIHZhciBuYW1lID0gc3BsaXQuc2hpZnQoKS5yZXBsYWNlKC9cKy9nLCAiICIpOwogICAgICAgICAgICAgICAgdmFyIHZhbHVlID0gc3BsaXQuam9pbigiPSIpLnJlcGxhY2UoL1wrL2csICIgIik7CiAgICAgICAgICAgICAgICBmb3JtLmFwcGVuZChkZWNvZGVVUklDb21wb25lbnQobmFtZSksIGRlY29kZVVSSUNvbXBvbmVudCh2YWx1ZSkpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIHJldHVybiBmb3JtOwogICAgICAgICAgfQogICAgICAgICAgZnVuY3Rpb24gcGFyc2VIZWFkZXJzKHJhd0hlYWRlcnMpIHsKICAgICAgICAgICAgdmFyIGhlYWRlcnMgPSBuZXcgSGVhZGVycygpOwogICAgICAgICAgICB2YXIgcHJlUHJvY2Vzc2VkSGVhZGVycyA9IHJhd0hlYWRlcnMucmVwbGFjZSgvXHI/XG5bXHQgXSsvZywgIiAiKTsKICAgICAgICAgICAgcHJlUHJvY2Vzc2VkSGVhZGVycy5zcGxpdCgvXHI/XG4vKS5mb3JFYWNoKGZ1bmN0aW9uKGxpbmUpIHsKICAgICAgICAgICAgICB2YXIgcGFydHMgPSBsaW5lLnNwbGl0KCI6Iik7CiAgICAgICAgICAgICAgdmFyIGtleSA9IHBhcnRzLnNoaWZ0KCkudHJpbSgpOwogICAgICAgICAgICAgIGlmIChrZXkpIHsKICAgICAgICAgICAgICAgIHZhciB2YWx1ZSA9IHBhcnRzLmpvaW4oIjoiKS50cmltKCk7CiAgICAgICAgICAgICAgICBoZWFkZXJzLmFwcGVuZChrZXksIHZhbHVlKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICByZXR1cm4gaGVhZGVyczsKICAgICAgICAgIH0KICAgICAgICAgIEJvZHkuY2FsbChSZXF1ZXN0LnByb3RvdHlwZSk7CiAgICAgICAgICBmdW5jdGlvbiBSZXNwb25zZShib2R5SW5pdCwgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoIW9wdGlvbnMpIHsKICAgICAgICAgICAgICBvcHRpb25zID0ge307CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy50eXBlID0gImRlZmF1bHQiOwogICAgICAgICAgICB0aGlzLnN0YXR1cyA9IG9wdGlvbnMuc3RhdHVzID09PSB2b2lkIDAgPyAyMDAgOiBvcHRpb25zLnN0YXR1czsKICAgICAgICAgICAgdGhpcy5vayA9IHRoaXMuc3RhdHVzID49IDIwMCAmJiB0aGlzLnN0YXR1cyA8IDMwMDsKICAgICAgICAgICAgdGhpcy5zdGF0dXNUZXh0ID0gInN0YXR1c1RleHQiIGluIG9wdGlvbnMgPyBvcHRpb25zLnN0YXR1c1RleHQgOiAiT0siOwogICAgICAgICAgICB0aGlzLmhlYWRlcnMgPSBuZXcgSGVhZGVycyhvcHRpb25zLmhlYWRlcnMpOwogICAgICAgICAgICB0aGlzLnVybCA9IG9wdGlvbnMudXJsIHx8ICIiOwogICAgICAgICAgICB0aGlzLl9pbml0Qm9keShib2R5SW5pdCk7CiAgICAgICAgICB9CiAgICAgICAgICBCb2R5LmNhbGwoUmVzcG9uc2UucHJvdG90eXBlKTsKICAgICAgICAgIFJlc3BvbnNlLnByb3RvdHlwZS5jbG9uZSA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKHRoaXMuX2JvZHlJbml0LCB7CiAgICAgICAgICAgICAgc3RhdHVzOiB0aGlzLnN0YXR1cywKICAgICAgICAgICAgICBzdGF0dXNUZXh0OiB0aGlzLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgaGVhZGVyczogbmV3IEhlYWRlcnModGhpcy5oZWFkZXJzKSwKICAgICAgICAgICAgICB1cmw6IHRoaXMudXJsCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfTsKICAgICAgICAgIFJlc3BvbnNlLmVycm9yID0gZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHZhciByZXNwb25zZSA9IG5ldyBSZXNwb25zZShudWxsLCB7IHN0YXR1czogMCwgc3RhdHVzVGV4dDogIiIgfSk7CiAgICAgICAgICAgIHJlc3BvbnNlLnR5cGUgPSAiZXJyb3IiOwogICAgICAgICAgICByZXR1cm4gcmVzcG9uc2U7CiAgICAgICAgICB9OwogICAgICAgICAgdmFyIHJlZGlyZWN0U3RhdHVzZXMgPSBbMzAxLCAzMDIsIDMwMywgMzA3LCAzMDhdOwogICAgICAgICAgUmVzcG9uc2UucmVkaXJlY3QgPSBmdW5jdGlvbih1cmwsIHN0YXR1cykgewogICAgICAgICAgICBpZiAocmVkaXJlY3RTdGF0dXNlcy5pbmRleE9mKHN0YXR1cykgPT09IC0xKSB7CiAgICAgICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkludmFsaWQgc3RhdHVzIGNvZGUiKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gbmV3IFJlc3BvbnNlKG51bGwsIHsgc3RhdHVzLCBoZWFkZXJzOiB7IGxvY2F0aW9uOiB1cmwgfSB9KTsKICAgICAgICAgIH07CiAgICAgICAgICBleHBvcnRzMi5ET01FeGNlcHRpb24gPSBzZWxmMi5ET01FeGNlcHRpb247CiAgICAgICAgICB0cnkgewogICAgICAgICAgICBuZXcgZXhwb3J0czIuRE9NRXhjZXB0aW9uKCk7CiAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgZXhwb3J0czIuRE9NRXhjZXB0aW9uID0gZnVuY3Rpb24obWVzc2FnZSwgbmFtZSkgewogICAgICAgICAgICAgIHRoaXMubWVzc2FnZSA9IG1lc3NhZ2U7CiAgICAgICAgICAgICAgdGhpcy5uYW1lID0gbmFtZTsKICAgICAgICAgICAgICB2YXIgZXJyb3IgPSBFcnJvcihtZXNzYWdlKTsKICAgICAgICAgICAgICB0aGlzLnN0YWNrID0gZXJyb3Iuc3RhY2s7CiAgICAgICAgICAgIH07CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUgPSBPYmplY3QuY3JlYXRlKEVycm9yLnByb3RvdHlwZSk7CiAgICAgICAgICAgIGV4cG9ydHMyLkRPTUV4Y2VwdGlvbi5wcm90b3R5cGUuY29uc3RydWN0b3IgPSBleHBvcnRzMi5ET01FeGNlcHRpb247CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiBmZXRjaDIoaW5wdXQsIGluaXQyKSB7CiAgICAgICAgICAgIHJldHVybiBuZXcgUHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpIHsKICAgICAgICAgICAgICB2YXIgcmVxdWVzdCA9IG5ldyBSZXF1ZXN0KGlucHV0LCBpbml0Mik7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsICYmIHJlcXVlc3Quc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICAgIHJldHVybiByZWplY3QobmV3IGV4cG9ydHMyLkRPTUV4Y2VwdGlvbigiQWJvcnRlZCIsICJBYm9ydEVycm9yIikpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB2YXIgeGhyID0gbmV3IFhNTEh0dHBSZXF1ZXN0KCk7CiAgICAgICAgICAgICAgZnVuY3Rpb24gYWJvcnRYaHIoKSB7CiAgICAgICAgICAgICAgICB4aHIuYWJvcnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgeGhyLm9ubG9hZCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgdmFyIG9wdGlvbnMgPSB7CiAgICAgICAgICAgICAgICAgIHN0YXR1czogeGhyLnN0YXR1cywKICAgICAgICAgICAgICAgICAgc3RhdHVzVGV4dDogeGhyLnN0YXR1c1RleHQsCiAgICAgICAgICAgICAgICAgIGhlYWRlcnM6IHBhcnNlSGVhZGVycyh4aHIuZ2V0QWxsUmVzcG9uc2VIZWFkZXJzKCkgfHwgIiIpCiAgICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgICAgb3B0aW9ucy51cmwgPSAicmVzcG9uc2VVUkwiIGluIHhociA/IHhoci5yZXNwb25zZVVSTCA6IG9wdGlvbnMuaGVhZGVycy5nZXQoIlgtUmVxdWVzdC1VUkwiKTsKICAgICAgICAgICAgICAgIHZhciBib2R5ID0gInJlc3BvbnNlIiBpbiB4aHIgPyB4aHIucmVzcG9uc2UgOiB4aHIucmVzcG9uc2VUZXh0OwogICAgICAgICAgICAgICAgcmVzb2x2ZShuZXcgUmVzcG9uc2UoYm9keSwgb3B0aW9ucykpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9uZXJyb3IgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgIHJlamVjdChuZXcgVHlwZUVycm9yKCJOZXR3b3JrIHJlcXVlc3QgZmFpbGVkIikpOwogICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgeGhyLm9udGltZW91dCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBUeXBlRXJyb3IoIk5ldHdvcmsgcmVxdWVzdCBmYWlsZWQiKSk7CiAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB4aHIub25hYm9ydCA9IGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBleHBvcnRzMi5ET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpKTsKICAgICAgICAgICAgICB9OwogICAgICAgICAgICAgIHhoci5vcGVuKHJlcXVlc3QubWV0aG9kLCByZXF1ZXN0LnVybCwgdHJ1ZSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3QuY3JlZGVudGlhbHMgPT09ICJpbmNsdWRlIikgewogICAgICAgICAgICAgICAgeGhyLndpdGhDcmVkZW50aWFscyA9IHRydWU7CiAgICAgICAgICAgICAgfSBlbHNlIGlmIChyZXF1ZXN0LmNyZWRlbnRpYWxzID09PSAib21pdCIpIHsKICAgICAgICAgICAgICAgIHhoci53aXRoQ3JlZGVudGlhbHMgPSBmYWxzZTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKCJyZXNwb25zZVR5cGUiIGluIHhociAmJiBzdXBwb3J0LmJsb2IpIHsKICAgICAgICAgICAgICAgIHhoci5yZXNwb25zZVR5cGUgPSAiYmxvYiI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHJlcXVlc3QuaGVhZGVycy5mb3JFYWNoKGZ1bmN0aW9uKHZhbHVlLCBuYW1lKSB7CiAgICAgICAgICAgICAgICB4aHIuc2V0UmVxdWVzdEhlYWRlcihuYW1lLCB2YWx1ZSk7CiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgaWYgKHJlcXVlc3Quc2lnbmFsKSB7CiAgICAgICAgICAgICAgICByZXF1ZXN0LnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGFib3J0WGhyKTsKICAgICAgICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2UgPSBmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgaWYgKHhoci5yZWFkeVN0YXRlID09PSA0KSB7CiAgICAgICAgICAgICAgICAgICAgcmVxdWVzdC5zaWduYWwucmVtb3ZlRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCBhYm9ydFhocik7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHhoci5zZW5kKHR5cGVvZiByZXF1ZXN0Ll9ib2R5SW5pdCA9PT0gInVuZGVmaW5lZCIgPyBudWxsIDogcmVxdWVzdC5fYm9keUluaXQpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIGZldGNoMi5wb2x5ZmlsbCA9IHRydWU7CiAgICAgICAgICBpZiAoIXNlbGYyLmZldGNoKSB7CiAgICAgICAgICAgIHNlbGYyLmZldGNoID0gZmV0Y2gyOwogICAgICAgICAgICBzZWxmMi5IZWFkZXJzID0gSGVhZGVyczsKICAgICAgICAgICAgc2VsZjIuUmVxdWVzdCA9IFJlcXVlc3Q7CiAgICAgICAgICAgIHNlbGYyLlJlc3BvbnNlID0gUmVzcG9uc2U7CiAgICAgICAgICB9CiAgICAgICAgICBleHBvcnRzMi5IZWFkZXJzID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0Q2h1bmsgPSBudWxsOwogICAgaWYgKGNodW5rcy5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIGNodW5rczsKICAgIH0KICAgIGNodW5rcy5zb3J0KChjMCwgYzEpID0+IHsKICAgICAgY29uc3QgZGlmID0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChjaHVuay5tYXh2LmNvbXBhcmVUbyhsYXN0Q2h1bmsubWF4dikgPiAwKSB7CiAgICAgICAgICAgICAgbGFzdENodW5rLm1heHYgPSBjaHVuay5tYXh2OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICByZXR1cm4gbWVyZ2VkQ2h1bmtzOwogIH0KCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL0BnbW9kK2JhbUAxLjEuM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AgICAgICAgIGlmIChiaW4gPT09IGJpbkxpbWl0ICsgMSkgewogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMzI7CiAgICAgICAgICB9IGVsc2UgaWYgKGJpbiA+IGJpbkxpbWl0ICsgMSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImJhaSBpbmRleCBjb250YWlucyB0b28gbWFueSBiaW5zLCBwbGVhc2UgdXNlIENTSSIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIHRoaXMuX2ZpbmRGaXJzdERhdGEoZGF0YSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICBkYXRhLmluZGljZXNbaV0gPSB7IGJpbkluZGV4LCBsaW5lYXJJbmRleCwgc3RhdHMgfTsKICAgICAgfQogICAgICByZXR1cm4gZGF0YTsKICAgIH0KICAgIGFzeW5jIGluZGV4Q292KHNlcUlkLCBzdGFydCwgZW5kLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgdiA9IDE2Mzg0OwogICAgICBjb25zdCByYW5nZSA9IHN0YXJ0ICE9PSB2b2lkIDA7CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGNvbnN0IHNlcUlkeCA9IGluZGV4RGF0YS5pbmRpY2VzW3NlcUlkXTsKICAgICAgaWYgKCFzZXFJZHgpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgeyBsaW5lYXJJbmRleCA9IFtdLCBzdGF0cyB9ID0gc2VxSWR4OwogICAgICBpZiAoIWxpbmVhckluZGV4Lmxlbmd0aCkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBlID0gZW5kICE9PSB2b2lkIDAgPyByb3VuZFVwKGVuZCwgdikgOiAobGluZWFySW5kZXgubGVuZ3RoIC0gMSkgKiB2OwogICAgICBjb25zdCBzID0gc3RhcnQgIT09IHZvaWQ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CkgewogICAgICBlbmQgLT0gMTsKICAgICAgcmV0dXJuIFsKICAgICAgICBbMCwgMF0sCiAgICAgICAgWzEgKyAoYmVnID4+IDI2KSwgMSArIChlbmQgPj4gMjYpXSwKICAgICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICAgIFs3MyArIChiZWcgPj4gMjApLCA3MyArIChlbmQgPj4gMjApXSwKICAgICAgICBbNTg1ICsgKGJlZyA+PiAxNyksIDU4NSArIChlbmQgPj4gMTcpXSwKICAgICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICAgIF07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZJZCwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIG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sKICAgICAgICAgIGNvbnNvbGUud2FybihgZ2VuZXJpYy1maWxlaGFuZGxlOiByZWZldGNoaW5nICR7aW5wdXR9IHRvIGF0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3NpdGlvbn0tJHtwb3NpdGlvbiArIGxlbmd0aH1gOwogICAgICB9IGVsc2UgaWYgKGxlbmd0aCA9PT0gSW5maW5pdHkgJiYgcG9zaXRpb24gIT09IDApIHsKICAgICAgICBoZWFkZXJzLnJhbmdlID0gYGJ5dGVzPSR7cG9zaXRpb259LWA7CiAgICAgIH0KICAgICAgY29uc3QgYXJncyA9IHsKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzLAogICAgICAgIGhlYWRlcnM6IHsKICAgICAgICAgIC4uLmhlYWRlcnMsCiAgICAgICAgICAuLi5vdmVycmlkZXMuaGVhZGVycywKICAgICAgICAgIC4uLnRoaXMuYmFzZU92ZXJyaWR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gICAgIH0KICAgICAgaWYgKHJlc3BvbnNlLnN0YXR1cyA9PT0gMjAwKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCIke3RoaXMudXJsfSBmZXRjaCByZXR1cm5lZCBzdGF0dXMgMjAwLCBleHBlY3RlZCAyMDYiKTsKICAgICAgfQogICAgICB0aHJvdyBuZXcgRXJyb3IoYEhUVFAgJHtyZXNwb25zZS5zdGF0dXN9IGZldGNoaW5nICR7dGhpcy51cmx9YCk7CiAgICB9CiAgICBhc3luYyByZWFkRmlsZShvcHRpb25zID0ge30pIHsKICAgICAgbGV0IGVuY29kaW5nOwogICAgICBsZXQgb3B0czsKICAgICAgaWYgKHR5cGVvZiBvcHRpb25zID09PSAic3RyaW5nIikgewogICAgICAgIGVuY29kaW5nID0gb3B0aW9uczsKICAgICAgICBvcHRzID0ge307CiAgICAgIH0gZWxzZSB7CiAgICAgICAgZW5jb2RpbmcgPSBvcHRpb25zLmVuY29kaW5nOwogICAgICAgIG9wdHMgPSBvcHRpb25zOwogICAgICAgIGRlbGV0ZSBvcHRzLmVuY29kaW5nOwogICAgICB9CiAgICAgIGNvbnN0IHsgaGVhZGVycyA9IHt9LCBzaWduYWwsIG92ZXJyaWRlcyA9IHt9IH0gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZS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gPSBtaW52LmRhdGFQb3NpdGlvbjsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGNvbnN0IGNwb3NpdGlvbnMgPSBbXTsKICAgICAgY29uc3QgZHBvc2l0aW9ucyA9IFtdOwogICAgICBsZXQgdG90YWxTaXplID0gMDsKICAgICAgbGV0IGkgPSAwOwogICAgICBkbyB7CiAgICAgICAgY29uc3QgcmVtYWluaW5nSW5wdXQgPSBpbnB1dERhdGEuc3ViYXJyYXkoY3BvcyAtIG1pbnYuYmxvY2tQb3NpdGlvbik7CiAgICAgICAgY29uc3QgaW5mbGF0b3IgPSBuZXcgaW1wb3J0X3Bha28uSW5mbGF0ZSgpOwogICAgICAgICh7IHN0cm0gfSA9IGluZmxhdG9yKTsKICAgICAgICBpbmZsYXRvci5wdXNoKHJlbWFpbmluZ0lucHV0LCBpbXBvcnRfcGFrby5aX1NZTkNfRkxVU0gpOwogICAgICAgIGlmIChpbmZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihpbmZsYXRvci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X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gICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICB0aGlzLl9maW5kRmlyc3REYXRhKGRhdGEsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRhdGEuaW5kaWNlc1tpXSA9IHsgYmluSW5kZXgsIHN0YXRzIH07CiAgICAgIH0KICAgICAgcmV0dXJuIGRhdGE7CiAgICB9CiAgICBwYXJzZVBzZXVkb0JpbihieXRlcywgb2Zmc2V0KSB7CiAgICAgIGNvbnN0IGxpbmVDb3VudCA9IGxvbmdUb051bWJlcihpbXBvcnRfbG9uZzMuZGVmYXVsdC5mcm9tQnl0ZXNMRShBcnJheS5wcm90b3R5cGUuc2xpY2UuY2FsbChieXRlcywgb2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZklkLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YSA9PT0gbnVsbCB8fCBpbmRleERhdGEgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICA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E7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQyI6CiAgICAgICAgICAgIHZhbHVlID0gYnl0ZUFycmF5LnJlYWRVSW50OChwKTsKICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgInMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgcCArPSAyOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGNhc2UgIlMiOgogICAgICAgICAgICB2YWx1ZSA9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJmIjoKICAgICAgICAgICAgdmFsdWUgPSBieXRlQXJyYXkucmVhZEZsb2F0TEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBjYXNlICJaIjoKICAgICAgICAgIGNhc2UgIkgiOgogICAgICAgICAgICB2YWx1ZSA9ICIiOwogICAgICAgICAgICB3aGlsZSAocCA8PSBibG9ja0VuZCkgewogICAgICAgICAgICAgIGNvbnN0IGNjID0gYnl0ZUFycmF5W3ArK107CiAgICAgICAgICAgICAgaWYgKGNjID09PSAwKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShjYyk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgY2FzZSAiQiI6IHsKICAgICAgICAgICAgdmFsdWUgPSAiIjsKICAgICAgICAgICAgY29uc3QgY2MgPSBieXRlQXJyYXlbcCsrXTsKICAgICAgICAgICAgY29uc3QgQnR5cGUgPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGNjKTsKICAgICAgICAgICAgY29uc3QgbGltaXQgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiaSIpIHsKICAgICAgICAgICAgICBpZiAodGFnID09PSAiQ0ciKSB7CiAgICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgICAgY29uc3QgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MzJMRShwKTsKICAgICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJJIikgewogICAgICAgICAgICAgIGlmICh0YWcgPT09ICJDRyIpIHsKICAgICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgICBjb25zdCBjaWdvcCA9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGNvbnN0IGxvcCA9IGNpZ29wID4+IDQ7CiAgICAgICAgICAgICAgICAgIGNvbnN0IG9wID0gQ0lHQVJfREVDT0RFUltjaWdvcCAmIDE1XTsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gbG9wICsgb3A7CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDMyTEUocCk7CiAgICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIHAgKz0gNDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAicyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkSW50MTZMRShwKTsKICAgICAgICAgICAgICAgIGlmIChrICsgMSA8IGxpbWl0KSB7CiAgICAgICAgICAgICAgICAgIHZhbHVlICs9ICIsIjsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHAgKz0gMjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKEJ0eXBlID09PSAiUyIpIHsKICAgICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbWl0OyBrKyspIHsKICAgICAgICAgICAgICAgIHZhbHVlICs9IGJ5dGVBcnJheS5yZWFkVUludDE2TEUocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDI7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gImMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZEludDgocCk7CiAgICAgICAgICAgICAgICBpZiAoayArIDEgPCBsaW1pdCkgewogICAgICAgICAgICAgICAgICB2YWx1ZSArPSAiLCI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBwICs9IDE7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChCdHlwZSA9PT0gIkMiKSB7CiAgICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBsaW1pdDsgaysrKSB7CiAgICAgICAgICAgICAgICB2YWx1ZSArPSBieXRlQXJyYXkucmVhZFVJbnQ4KHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSAxOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoQnR5cGUgPT09ICJmIikgewogICAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGltaXQ7IGsrKykgewogICAgICAgICAgICAgICAgdmFsdWUgKz0gYnl0ZUFycmF5LnJlYWRGbG9hdExFKHApOwogICAgICAgICAgICAgICAgaWYgKGsgKyAxIDwgbGltaXQpIHsKICAgICAgICAgICAgICAgICAgdmFsdWUgKz0gIiwiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgcCArPSA0OwogICAgICAgICAgICAgI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GV0IGMgPSAwOyBjIDwgbnVtQ2lnYXJPcHM7ICsrYykgewogICAgICAgICAgY2lnb3AgPSBieXRlQXJyYXkucmVhZEludDMyTEUocCk7CiAgICAgICAgICBsb3AgPSBjaWdvcCA+PiA0OwogICAgICAgICAgb3AgPSBDSUdBUl9ERUNPREVSW2NpZ29wICYgMTVdOwogICAgICAgICAgY2lnYXIgKz0gbG9wICsgb3A7CiAgICAgICAgICBpZiAob3AgIT09ICJIIiAmJiBvcCAhPT0gIlMiICYmIG9wICE9PSAiSSIpIHsKICAgICAgICAgICAgbHJlZiArPSBsb3A7CiAgICAgICAgICB9CiAgICAgICAgICBwICs9IDQ7CiAgICAgICAgfQogICAgICAgIHRoaXMuZGF0YS5sZW5ndGhfb25fcmVmID0gbHJlZjsKICAgICAgICByZXR1cm4gY2lnYXI7CiAgICAgIH0KICAgIH0KICAgIF9mbGFncygpIHsKICAgIH0KICAgIGxlbmd0aF9vbl9yZWYoKSB7CiAgICAgIGlmICh0aGlzLmRhdGEubGVuZ3RoX29uX3JlZikgewogICAgICAgIHJldHVybiB0aGlzLmRhdGEubGVuZ3RoX29uX3JlZjsKICAgICAgfSBlbHNlIHsKICAgICAgICB0aGlzLmdldCgiY2lnYXIiKTsKICAgICAgICByZXR1cm4gdGhpcy5kYXRhLmxlbmd0aF9vbl9yZWY7CiAgICAgIH0KICAgIH0KICAgIF9uX2NpZ2FyX29wKCkgewogICAgICByZXR1cm4gdGhpcy5nZXQoIl9mbGFnX25jIikgJiA2NTUzNTsKICAgIH0KICAgIF9sX3JlYWRfbmFtZSgpIHsKICAgICAgcmV0dXJuIHRoaXMuZ2V0KCJfYmluX21xX25sIikgJiAyNTU7CiAgICB9CiAgICBfc2VxX2J5dGVzKCkgewogICAgICByZXR1cm4gdGhpcy5nZXQoInNlcV9sZW5ndGgiKSArIDEgPj4gMTsKICAgIH0KICAgIGdldFJlYWRCYXNlcygpIHsKICAgICAgcmV0dXJuIHRoaXMuc2VxKCk7CiAgICB9CiA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QgZG9uZSA9IGZhbHNlOwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGNodW5rcy5sZW5ndGg7IGkrKykgewogICAgICAgIGNvbnN0IGMgPSBjaHVua3NbaV07CiAgICAgICAgY29uc3QgcmVjb3JkcyA9IGF3YWl0IHRoaXMuZmVhdHVyZUNhY2hlLmdldChjLnRvU3RyaW5nKCksIHsKICAgICAgICAgIGNodW5rOiBjLAogICAgICAgICAgb3B0cwogICAgICAgIH0sIG9wdHMuc2lnbmFsKTsKICAgICAgICBjb25zdCByZWNzID0gW107CiAgICAgICAgZm9yIChsZXQgaTIgPSAwOyBpMiA8IHJlY29yZHMubGVuZ3RoOyBpMiArPSAxKSB7CiAgICAgICAgICBjb25zdCBmZWF0dXJlID0gcmVjb3Jkc1tpMl07CiAgICAgICAgICBpZiAoZmVhdHVyZS5zZXFfaWQoKSA9PT0gY2hySWQpIHsKICAgICAgICAgICAgaWYgKGZlYXR1cmUuZ2V0KCJzdGFydCIpID49IG1heCkgewogICAgICAgICAgICAgIGRvbmUgPSB0cnVlOwogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZlYXR1cmUuZ2V0KCJlbmQiKSA+PSBtaW4pIHsKICAgICAgICAgICAgICByZWNzLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZmVhdHMucHVzaChyZWNzKTsKICAgICAgICB5aWVsZCByZWNzOwogICAgICAgIGlmIChkb25lKSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY2hlY2tBYm9ydFNpZ25hbChvcHRzLnNpZ25hbCk7CiAgICAgIGlmICh2aWV3QXNQYWlycykgewogICAgICAgIHlpZWxkIHRoaXMuZmV0Y2hQYWlycyhjaHJJZCwgZmVhdHMsIG9wdHMpOwogICAgICB9CiAgICB9CiAgICBhc3luYyBmZXRjaFBhaXJzKGNocklkLCBmZWF0cywgb3B0cykgewogICAgICBjb25zdCB7IHBhaXJBY3Jvc3NDaHIgPSBmYWxzZSwgbWF4SW5zZXJ0U2l6ZSA9IDJlNSB9ID0gb3B0czsKICAgICAgY29uc3QgdW5tYXRlZFBhaXJzID0ge307CiAgICAgIGNvbnN0IHJlYWRJZHMgPSB7fTsKICAgICAgZmVhdHMubWFwKChyZXQpID0+IHsKICAgICAgICBjb25zdCByZWFkTmFtZXMgPSB7fTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHJldC5sZW5ndGg7IGkrKykgewogICAgICAgICAgY29uc3QgbmFtZSA9IHJldFtpXS5uYW1lKCk7CiAgICAgICAgICBjb25zdCBpZCA9IHJldFtpXS5pZCgpOwogICAgICAgICAgaWYgKCFyZWFkTmFtZXNbbmFtZV0pIHsKICAgICAgICAgICAgcmVhZE5hbWVzW25hbWVdID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHJlYWROYW1lc1tuYW1lXSsrOwogICAgICAgICAgcmVhZElkc1tpZF0gPSAxOwogICAgICAgIH0KICAgICAgICAoMCwgaW1wb3J0X29iamVjdC5kZWZhdWx0KShyZWFkTmFtZXMpLmZvckVhY2goKFtrLCB2XSkgPT4gewogICAgICAgICAgaWYgKHYgPT09IDEpIHsKICAgICAgICAgICAgdW5tYXRlZFBhaXJzW2tdID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgfSk7CiAgICAgIGNvbnN0IG1hdGVQcm9taXNlcyA9IFtdOwogICAgICBmZWF0cy5tYXAoKHJldCkgPT4gewogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgcmV0Lmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICBjb25zdCBmID0gcmV0W2ldOwogICAgICAgICAgY29uc3QgbmFtZSA9IGYubmFtZSgpOwogICAgICAgICAgY29uc3Qgc3RhcnQgPSBmLmdldCgic3RhcnQiKTsKICAgICAgICAgIGNvbnN0IHBuZXh0ID0gZi5fbmV4dF9wb3MoKTs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PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGNodW5rLm1pbnYuZGF0YVBvc2l0aW9uICsgMSA6IGltcG9ydF9idWZmZXJfY3JjMzIuZGVmYXVsdC5zaWduZWQoYmEuc2xpY2UoYmxvY2tTdGFydCwgYmxvY2tFbmQpKQogICAgICAgICAgfSk7CiAgICAgICAgICBzaW5rLnB1c2goZmVhdHVyZSk7CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRocmVhZFRpbWUgJiYgK0RhdGUubm93KCkgLSBsYXN0ID4gdGhpcy55aWVsZFRocmVhZFRpbWUpIHsKICAgICAgICAgICAgYXdhaXQgdGltZW91dCgxKTsKICAgICAgICAgICAgbGFzdCA9ICtEYXRlLm5vdygpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBibG9ja1N0YXJ0ID0gYmxvY2tFbmQgKyAxOwogICAgICB9CiAgICAgIHJldHVybiBzaW5rOwogICAgfQogICAgYXN5bmMgaGFzUmVmU2VxKHNlcU5hbWUpIHsKICAgICAgY29uc3QgcmVmSWQgPSB0aGlzLmNoclRvSW5kZXggJiYgdGhpcy5jaHJUb0luZGV4W3NlcU5hbWVdOwogICAgICByZXR1cm4gdGhpcy5pbmRleC5oYXNSZWZTZXEocmVmSWQpOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHNlcU5hbWUpIHsKICAgICAgY29uc3QgcmVmSWQgPSB0aGlzLmNoclRvSW5kZXggJiYgdGhpcy5jaHJUb0luZGV4W3NlcU5hbWVdOwogICAgICByZXR1cm4gdGhpcy5pbmRleC5saW5lQ291bnQocmVmSWQpOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3Yoc2VxTmFtZSwgc3RhcnQsIGVuZCkgewogICAgICBhd2FpdCB0aGlzLmluZGV4LnBhcnNlKCk7CiAgICAgIGNvbnN0IHNlcUlkID0gdGhpcy5jaHJUb0luZGV4ICYmIHRoaXMuY2hyVG9JbmRleFtzZXFOYW1lXTsKICAg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pdGVtOwogICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICAgIGlmIChkZWxldGVkID09PSBmYWxzZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgIGNvbnN0IFtrZXksIHZhbHVlXSA9IGl0ZW07CiAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIHZhbHVlKTsKICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgICBnZXQoa2V5KSB7CiAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgcmV0dXJuIHRoaXMuX2dldEl0ZW1WYWx1ZShrZXksIGl0ZW0pOwogICAgICB9CiAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgY29uc3QgaXRlbSA9IHRoaXMub2xkQ2FjaGUuZ2V0KGtleSk7CiAgICAgICAgaWYgKHRoaXMuX2RlbGV0ZUlmRXhwaXJlZChrZXksIGl0ZW0pID09PSBmYWxzZSkgewogICAgICAgICAgdGhpcy5fbW92ZVRvUmVjZW50KGtleSwgaXRlbSk7CiAgICAgICAgICByZXR1cm4gaXRlbS52YWx1ZTsKICAgICAgICB9CiAgICAgIH0KICAgIH0KICAgIHNldChrZXksIHZhbHVlLCB7IG1heEFnZSA9IHRoaXMubWF4QWdlIH0gPSB7fSkgewogICAgICBjb25zdCBle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kgewogICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgfQogICAgY2xlYXIoKSB7CiAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICB0aGlzLl9zaXplID0gMDsKICAgIH0KICAgIHJlc2l6ZShuZXdTaXplKSB7CiAgICAgIGlmICghKG5ld1NpemUgJiYgbmV3U2l6ZSA+IDApKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiYG1heFNpemVgIG11c3QgYmUgYSBudW1iZXIgZ3JlYXRlciB0aGFuIDAiKTsKICAgICAgfQogICAgICBjb25zdCBpdGVtcyA9IFsuLi50aGlzLl9lbnRyaWVzQXNjZW5kaW5nKCldOwogICAgICBjb25zdCByZW1vdmVDb3VudCA9IGl0ZW1zLmxlbmd0aCAtIG5ld1NpemU7CiAgICAgIGlmIChyZW1vdmVDb3VudCA8IDApIHsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcChpdGVtcyk7CiAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICB0aGlzLl9zaXplID0gaXRlbXMubGVuZ3RoOwogICAgICB9IGVsc2UgewogICAgICAgIGlmIChyZW1vdmVDb3VudCA+IDApIHsKICAgICAgICAgIHRoaXMuX2VtaXRFdmljdGlvbnMoaXRlbXMuc2xpY2UoMCwgcmVtb3ZlQ291bnQpKTsKICAgICAgICB9CiAgICAgICAgdGhpcy5vbGRDYWNoZSA9IG5ldyBNYXAoaXRlbXMuc2xpY2UocmVtb3ZlQ291bnQpKTsKICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICB9CiAgICAgIHRoaXMubWF4U2l6ZSA9IG5ld1NpemU7CiAgICB9CiAgICAqa2V5cygpIHsKICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgeWllbGQga2V5OwogICAgICB9CiAgICB9CiAgICAqdmFsdWVzKCkgewogICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgIH0KICAgIH0KICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMuY2FjaGUpIHsKICAgICAgICBjb25zdCBba2V5LCB2YWx1ZV0gPSBpdGVtOwogICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB2YWx1ZSk7CiAgICAgICAgaWYgKGRlbGV0ZWQgPT09IGZhbHNlKSB7CiAgICAgICAgICB5aWVsZCBba2V5LCB2YWx1ZS52YWx1ZV07CiAgICAgICAgfQogICAgICB9CiAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLm9sZENhY2hlKSB7CiAgICAgICAgY29uc3QgW2tleSwgdmFsdWVdID0gaXRlbTsKICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgIGNvbnN0IGRlbGV0ZWQgPSB0aGlzLl9kZWxldGVJZkV4cGlyZWQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCA9PT0gZmFsc2UpIHsKICAgICAgICAgICAgeWllbGQgW2tleSwgdmFsdWUudmFsdWVdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgfQogICAgKmVudHJpZXNEZXNjZW5kaW5nKCkgewogICAgICBsZXQgaXRlbXMgPSBbLi4udGhpcy5jYWNoZV07CiAgICAgIGZvciAobGV0IGkgPSBpdGVtcy5sZW5ndGggLSAxOyBpID49IDA7IC0taSkgewogICAgICAgIGNvbnN0IGl0ZW0gPSBpdGVtc1tpXTsKICAgICAg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GEgPj0gYiA/IDAgOiBOYU47CiAgfQoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vZDMtYXJyYXlAMi4xMi4xL25vZGVfbW9kdWxlcy9kMy1hcnJheS9zcmMvYmlzZWN0b3IuanMKICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgZnVuY3Rpb24gYmlzZWN0b3JfZGVmYXVsdChmKSB7CiAgICBsZXQgZGVsdGEgPSBmOwogICAgbGV0IGNvbXBhcmUgPSBmOwogICAgaWYgKGYubGVuZ3RoID09PSAxKSB7CiAgICAgIGRlbHRhID0gKGQsIHgpID0+IGYoZCkgLSB4OwogICAgICBjb21wYXJlID0gYXNjZW5kaW5nQ29tcGFyYXRvcihmKTsKICAgIH0KICAgIGZ1bmN0aW9uIGxlZnQoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBmaWxlOwogICAgICB0aGlzLm9wdGlvbnMgPSBvcHRpb25zOwogICAgICB0aGlzLmNocm9tSW5mbyA9IHNpemVzVG9DaHJvbUluZm8oY2hyb21TaXplcyk7CiAgICAgIHRoaXMudGlsZXNldEluZm8gPSB0aWxlc2V0SW5mb0Zyb21DaHJvbUluZm8odGhpcy5jaHJvbUluZm8pOwogICAgfQogICAgY2hyb21JbmZvOwogICAgdGlsZXNldEluZm87CiAgfTsKICB2YXIgY2hyb21JbmZvQmlzZWN0b3IgPSBiaXNlY3Rvcl9kZWZhdWx0KChkKSA9PiBkLnBvcykubGVmdDsKICB2YXIgY2hyVG9BYnMgPSAoY2hyb20sIGNocm9tUG9zLCBjaHJvbUluZm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VzcG9uc2Uuc3RhdHVzfSBmZXRjaGluZyAke3RoaXMudXJsfWApOwogICAgfTsKICB9OwoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy9iYW0vYmFtLXdvcmtlci50cz93b3JrZXImaW5saW5lP3dvcmtlcl9maWxlCiAgZnVuY3Rpb24gcGFyc2VNRChtZFN0cmluZywgdXNlQ291bnRzKSB7CiAgICBsZXQgY3VyclBvcyA9IDA7CiAgICBsZXQgY3Vyck51bSA9IDA7CiAgICBsZXQgZGVsZXRpb25FbmNvdW50ZXJlZCA9IGZhbHNlOwogICAgbGV0IGJhbVNlcVNoaWZ0ID0gMDsKICAgIGNvbnN0IHN1YnN0aXR1dGlvbnMgPSBbXTsKICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbWRTdHJpbmcubGVuZ3RoOyBpKyspIHsKICAgICAgaWYgKG1kU3RyaW5nW2ldLm1hdGNoKC9bMC05XS9nKSkgewogICAgICAgIGN1cnJOdW0gPSBjdXJyTnVtICogMTAgKyArbWRTdHJpbmdbaV07CiAgICAgICAgZGVsZXRpb25FbmNvdW50ZXJlZCA9IGZhbHNlOwogICAgICB9IGVsc2UgaWYgKG1kU3RyaW5nW2ldID09PSAiXiIpIHsKICAgICAgICBkZWxldGlvbkVuY291bnRlcmVkID0gdHJ1ZTsKICAgICAgfSBlbHNlIHsKICAgICAgICBjdXJyUG9zICs9IGN1cnJOdW07CiAgICAgICAgaWYgKHVzZUNvdW50cykgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgbGVuZ3RoOiBjdXJyTnVtLAogICAgICAgICAgICB0eXBlOiBtZFN0cmluZ1tpXQogICAgICAgICAgfSk7CiAgICAgICAgfSBlbHNlIGlmIChkZWxldGlvbkVuY291bnRlcmVkKSB7CiAgICAgICAgICBiYW1TZXFTaGlmdCAtPSAxOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGJhc2U6IG1kU3RyaW5nW2ldLAogICAgICAgICAgICBsZW5ndGg6IDEsCiAgICAgICAgICAgIGJhbVNlcVNoaWZ0CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgY3Vyck51bSA9IDA7CiAgICAgICAgY3VyclBvcyArPSAxOwogICAgICB9CiAgICB9CiAgICByZXR1cm4gc3Vic3RpdHV0aW9uczsKICB9CiAgZnVuY3Rpb24gZ2V0U3Vic3RpdHV0aW9ucyhzZWdtZW50LCBzZXEpIHsKICAgIGxldCBzdWJzdGl0dXRpb25zID0gW107CiAgICBsZXQgc29mdENsaXBwaW5nQXRSZWFkU3RhcnQgPSBudWxsOwogICAgaWYgKHNlZ21lbnQuY2lnYXIpIHsKICAgICAgY29uc3QgY2lnYXJTdWJzID0gcGFyc2VNRChzZWdtZW50LmNpZ2FyLCB0cnVlKTsKICAgICAgbGV0IGN1cnJQb3MgPSAwOwogICAgICBmb3IgKGNvbnN0IHN1YiBvZiBjaWdhclN1YnMpIHsKICAgICAgICBpZiAoc3ViLnR5cGUgPT09ICJYIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJYIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIkkiKSB7CiAgICAgICAgICBzdWJzdGl0dXRpb25zLnB1c2goewogICAgICAgICAgICBwb3M6IGN1cnJQb3MsCiAgICAgICAgICAgIGxlbmd0aDogc3ViLmxlbmd0aCwKICAgICAgICAgICAgdHlwZTogIkkiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgaWYgKHN1Yi50eXBlID09PSAiRCIpIHsKICAgICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICAgIHBvczogY3VyclBvcywKICAgICAgICAgICAgbGVuZ3RoOiBzdWIubGVuZ3RoLAogICAgICAgICAgICB0eXBlOiAiRCIKICAgICAgICAgIH0pOwogICAgICAgICAgY3VyclBvcyArPSBzdWIubGVuZ3RoOwogICAgICAgIH0gZWxzZSBpZiAoc3ViLnR5cGUgPT09ICJOIikgewogICAgICAgICAgc3Vic3RpdHV0aW9ucy5wdXNoKHsKICAgICAgICAgICAgcG9zOiBjdXJyUG9zLAogICAgICAgICAgICBsZW5ndGg6IHN1Yi5sZW5ndGgsCiAgICAgICAgICAgIHR5cGU6ICJOIgogICAgICAgICAgfSk7CiAgICAgICAgICBjdXJyUG9zICs9IHN1Yi5sZW5ndGg7CiAgICAgICAgfSBlbHNlIGlmIChzdWIudHlwZSA9PT0gIj0iIHx8IHN1Yi50eXBlID09PSAiTSIpIHsKICAgICAgICAgIGN1cnJQb3MgKz0gc3ViLmxlbmd0aDsKICAgICAgICB9IGVsc2UgewogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBmaXJzdFN1YiA9IGNpZ2FyU3Vic1swXTsKICAgICAgY29uc3QgbGFzdFN1YiA9IGNpZ2FyU3Vic1tjaWdhclN1YnMubGVuZ3RoIC0gMV07CiAgICAgIGlmIChmaXJzdFN1Yi50eXBlID09PSAiUyIpIHsKICAgICAgICBzb2Z0Q2xpcHBpbmdBdFJlYWRTdGFydCA9IGZpcnN0U3ViOwogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBwb3M6IC1maXJzdFN1Yi5sZW5ndGgsCiAgICAgICAgICB0eXBlOiAiUyIsCiAgICAgICAgICBsZW5ndGg6IGZpcnN0U3ViLmxlbmd0aAogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChsYXN0U3ViLnR5cGUgPT09ICJTIikgewogICAgICAgIHN1YnN0aXR1dGlvbnMucHVzaCh7CiAgICAgICAgICBw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+IHsKICAgIGNvbnN0IHNlZ21lbnRzQnlSZWFkTmFtZSA9IGdyb3VwQnkoc2VnbWVudHMsICJuYW1lIik7CiAgICBPYmplY3QudmFsdWVzKHNlZ21lbnRzQnlSZWFkTmFtZSkuZm9yRWFjaCgoc2VnbWVudEdyb3VwKSA9PiB7CiAgICAgIGlmIChzZWdtZW50R3JvdXAubGVuZ3RoID09PSAyKSB7CiAgICAgICAgY29uc3QgcmVhZCA9IHNlZ21lbnRHcm91cFswXTsKICAgICAgICBjb25zdCBtYXRlID0gc2VnbWVudEdyb3VwWzFdOwogICAgICAgIHJlYWQubWF0ZUlkcyA9IFttYXRlLmlkXTsKICAgICAgICBtYXRlLm1hdGVJZHMgPSBbcmVhZC5pZF07CiAgICAgICAgY29uc3QgW2wsIHJdID0gW3JlYWQsIG1hdGVdLnNvcnQoKGEsIGIpID0+ICthLnN0YXJ0IC0gK2Iuc3RhcnQpOwogICAgICAgIGNvbnN0IGluc2VydFNpemUgPSBNYXRoLm1heCgwLCArci5zdGFydCAtICtsLmVuZCk7CiAgICAgICAgY29uc3QgbGFyZ2VJbnNlcnRTaXplID0gaW5zZXJ0U2l6ZSA+PSBtYXhJbnNlcnRTaXplOwogICAgICAgIGxldCBzdlR5cGU7CiAgICAgICAgaWYgKCFsYXJnZUluc2VydFNpemUpIHsKICAgICAgICAgIHN2VHlwZSA9ICJub3JtYWwgcmVhZCI7CiAgICAgICAgfSBlbHNlIGlmIChsLnN0cmFuZCA9PT0gIisiICYmIHIuc3RyYW5kID09PSAiLSIpIHsKICAgICAgICAgIHN2VHlwZSA9ICJkZWxldGlvbiAoKy0pIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiKyIgJiYgci5zdHJhbmQgPT09ICIrIikgewogICAgICAgICAgc3ZUeXBlID0gImludmVyc2lvbiAoKyspIjsKICAgICAgICB9IGVsc2UgaWYgKGwuc3RyYW5kID09PSAiLSIgJiYgci5zdHJhbmQgPT09ICItIikgewogICAgICA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0YQogIH07CiAgZXhwb3NlKHRpbGVGdW5jdGlvbnMpOwp9KSgpOwovKiEKICogVGhlIGJ1ZmZlciBtb2R1bGUgZnJvbSBub2RlLmpzLCBmb3IgdGhlIGJyb3dzZXIuCiAqCiAqIEBhdXRob3IgICBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmc+CiAqIEBsaWNlbnNlICBNSVQKICovCi8qISBpZWVlNzU0LiBCU0QtMy1DbGF1c2UgTGljZW5zZS4gRmVyb3NzIEFib3VraGFkaWplaCA8aHR0cHM6Ly9mZXJvc3Mub3JnL29wZW5zb3VyY2U+ICovCg==",mle=typeof window<"u"&&window.Blob&&new Blob([atob(m2e)],{type:"text/javascript;charset=utf-8"});function vgg(){const e=mle&&(window.URL||window.webkitURL).createObjectURL(mle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+m2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const Bgg=200;class RH{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:r,...C}=i;this.worker=LT(new vgg).then(async o=>{const a=Object.entries(bi(r).size);return await o.init(this.uid,{url:I,indexUrl:n},a,C),o})}async tilesetInfo(g){(await this.worker).tilesetInfo(this.uid).then(g)}fetchTilesDebounced(g,i){var I;const{toFetch:n}=this,r=i[0].split(".")[0],C=n.size?[...n][0].split(".")[0]:null;if(r!==C){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()},Bgg)}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(RH,"config",{type:"bam"});const f2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHk7CiAgdmFyIF9fbWFya0FzTW9kdWxlID0gKHRhcmdldCkgPT4gX19kZWZQcm9wKHRhcmdldCwgIl9fZXNNb2R1bGUiLCB7IHZhbHVlOiB0cnVlIH0pOwogIHZhciBfX2VzbSA9IChmbiwgcmVzKSA9PiBmdW5jdGlvbiBfX2luaXQoKSB7CiAgICByZXR1cm4gZm4gJiYgKHJlcyA9ICgwLCBmbltPYmplY3Qua2V5cyhmbilbMF1dKShmbiA9IDApKSwgcmVzOwogIH07CiAgdmFyIF9fY29tbW9uSlMgPSAoY2IsIG1vZCkgPT4gZnVuY3Rpb24gX19yZXF1aXJlKCkgewogICAgcmV0dXJuIG1vZCB8fCAoMCwgY2JbT2JqZWN0LmtleXMoY2IpWzBdXSkoKG1vZCA9IHsgZXhwb3J0czoge30gfSkuZXhwb3J0cywgbW9kKSwgbW9kLmV4cG9ydHM7CiAgfTsKICB2YXIgX19yZUV4cG9ydCA9ICh0YXJnZXQsIG1vZHVsZTIsIGRlc2MpID0+IHsKICAgIGlmIChtb2R1bGUyICYmIHR5cGVvZiBtb2R1bGUyID09PSAib2Jq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sKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGFycjsKICAgICAgfQogICAgICBmdW5jdGlvbiB0cmlwbGV0VG9CYXNlNjQobnVtKSB7CiAgICAgICAgcmV0dXJuIGxvb2t1cFtudW0gPj4gMTggJiA2M10gKyBsb29rdXBbbnVtID4+IDEyICYgNjNdICsgbG9va3VwW251bSA+PiA2ICYgNjNdICsgbG9va3VwW251bSAmIDYzXTsKICAgICAgfQogICAgICBmdW5jdGlvbiBlbmNvZGVDaHVuayh1aW50OCwgc3RhcnQsIGVuZCkgewogICAgICAgIHZhciB0bXA7CiAgICAgICAgdmFyIG91dHB1dCA9IFtdOwogICAgICAgIGZvciAodmFyIGkyID0gc3RhcnQ7IGkyIDwgZW5kOyBpMiArPSAzKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbaTJdIDw8IDE2ICYgMTY3MTE2ODApICsgKHVpbnQ4W2kyICsgMV0gPDwgOCAmIDY1MjgwKSArICh1aW50OFtpMiArIDJdICYgMjU1KTsKICAgICAgICAgIG91dHB1dC5wdXNoKHRyaXBsZXRUb0Jhc2U2NCh0bXApKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dHB1dC5qb2luKCIiKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBmcm9tQnl0ZUFycmF5KHVpbnQ4KSB7CiAgICAgICAgdmFyIHRtcDsKICAgICAgICB2YXIgbGVuMiA9IHVpbnQ4Lmxlbmd0aDsKICAgICAgICB2YXIgZXh0cmFCeXRlcyA9IGxlbjIgJSAzOwogICAgICAgIHZhciBwYXJ0cyA9IFtdOwogICAgICAgIHZhciBtYXhDaHVua0xlbmd0aCA9IDE2MzgzOwogICAgICAgIGZvciAodmFyIGkyID0gMCwgbGVuMjIgPSBsZW4yIC0gZXh0cmFCeXRlczsgaTIgPCBsZW4yMjsgaTIgKz0gbWF4Q2h1bmtMZW5ndGgpIHsKICAgICAgICAgIHBhcnRzLnB1c2goZW5jb2RlQ2h1bmsodWludDgsIGkyLCBpM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ZW4pIC0gMTsKICAgICAgICB2YXIgZUJpYXMgPSBlTWF4ID4+IDE7CiAgICAgICAgdmFyIG5CaXRzID0gLTc7CiAgICAgICAgdmFyIGkgPSBpc0xFID8gbkJ5dGVzIC0gMSA6IDA7CiAgICAgICAgdmFyIGQgPSBpc0xFID8gLTEgOiAxOwogICAgICAgIHZhciBzID0gYnVmZmVyW29mZnNldCArIGldOwogICAgICAgIGkgKz0gZDsKICAgICAgICBlID0gcyAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIHMgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBlTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IGUgPSBlICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgbSA9IGUgJiAoMSA8PCAtbkJpdHMpIC0gMTsKICAgICAgICBlID4+PSAtbkJpdHM7CiAgICAgICAgbkJpdHMgKz0gbUxlbjsKICAgICAgICBmb3IgKDsgbkJpdHMgPiAwOyBtID0gbSAqIDI1NiArIGJ1ZmZlcltvZmZzZXQgKyBpXSwgaSArPSBkLCBuQml0cyAtPSA4KSB7CiAgICAgICAgfQogICAgICAgIGlmIChlID09PSAwKSB7CiAgICAgICAgICBlID0gMSAtIGVCaWFzOwogICAgICAgIH0gZWxzZSBpZiAoZSA9PT0gZU1heCkgewogICAgICAgICAgcmV0dXJuIG0gPyBOYU4gOiAocyA/IC0xIDogMSkgKiBJbmZpbml0eTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbSA9IG0gKyBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgIGUgPSBlIC0gZUJpYXM7CiAgICAgICAgfQogICAgICAgIHJldHVybiAocyA/IC0xIDogMSkgKiBtICogTWF0aC5wb3coMiwgZSAtIG1MZW4pOwogICAgICB9OwogICAgICBleHBvcnRzMi53cml0ZSA9IGZ1bmN0aW9uKGJ1ZmZlciwgdmFsd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h2YWx1ZSAqIGMgPj0gMikgewogICAgICAgICAgICBlKys7CiAgICAgICAgICAgIGMgLz0gMjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChlICsgZUJpYXMgPj0gZU1heCkgewogICAgICAgICAgICBtID0gMDsKICAgICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgICB9IGVsc2UgaWYgKGUgKyBlQmlhcyA+PSAxKSB7CiAgICAgICAgICAgIG0gPSAodmFsdWUgKiBjIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IGUgKyBlQmlhczsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG0gPSB2YWx1ZSAqIE1hdGgucG93KDIsIGVCaWFzIC0gMSkgKiBNYXRoLnBvdygyLCBtTGVuKTsKICAgICAgICAgICAgZSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoOyBtTGVuID49IDg7IGJ1ZmZlcltvZmZzZXQgKyBpXSA9IG0gJiAyNTUsIGkgKz0gZCwgbSAvPSAyNTYsIG1MZW4gLT0gOCkgewogICAgICAgIH0KICAgICAgICBlID0gZSA8PCBtTGVuIHwgbTsKICAgICAgICBlTGVuICs9IG1MZW47CiAgICAgICAgZm9yICg7IGVMZW4gPiAwOyBidWZmZXJbb2Zmc2V0ICsgaV0gPSBlICYgMjU1LCBpICs9IGQsIGUgLz0gMjU2LCBlTGVuIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgYnVmZmVyW29mZnNldCArIGkgLSBkXSB8PSBzICogMTI4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYnVmZmVyQDYuMC4zL25vZGVfbW9kdWxlcy9idWZmZXIvaW5kZXguanMKICB2YXIgcmVxdWlyZV9idWZmZXIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vYnVmZmVyQDYuMC4zL25vZGVfbW9kdWxlcy9idWZmZXI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icm93c2VyIHN1cHBvcnQuIik7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHlwZWRBcnJheVN1cHBvcnQoKSB7CiAgICAgICAgdHJ5IHsKICAgICAgICAgIGNvbnN0IGFyciA9IG5ldyBVaW50OEFycmF5KDEpOwogICAgICAgICAgY29uc3QgcHJvdG8gPSB7IGZvbzogZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIHJldHVybiA0MjsKICAgICAgICAgIH0gfTsKICAgICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihwcm90bywgVWludDhBcnJheS5wcm90b3R5cGUpOwogICAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGFyciwgcHJvdG8pOwogICAgICAgICAgcmV0dXJuIGFyci5mb28oKSA9PT0gNDI7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAicGFyZW50IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5idWZmZXI7CiAgICAgICAgfQogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KEJ1ZmZlcjEwLnByb3RvdHlwZSwgIm9mZnNldCIsIHsKICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgIGdldDogZnVuY3Rpb24oKSB7CiAgICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKHRoaXMpKQogICAgICAgICAgICByZXR1cm4gdm9pZCAwOwogICAgICAgICAgcmV0dXJuIHRoaXMuYnl0ZU9mZnNldDsKICAgICAgICB9CiAgICAgIH0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XQsIGxlbmd0aCk7CiAgICAgIH07CiAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihCdWZmZXIxMC5wcm90b3R5cGUsIFVpbnQ4QXJyYXkucHJvdG90eXBlKTsKICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKEJ1ZmZlcjEwLCBVaW50OEFycmF5KTsKICAgICAgZnVuY3Rpb24gYXNzZXJ0U2l6ZShzaXplKSB7CiAgICAgICAgaWYgKHR5cGVvZiBzaXplICE9PSAibnVtYmVyIikgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignInNpemUiIGFyZ3VtZW50IG11c3QgYmUgb2YgdHlwZSBudW1iZXInKTsKICAgICAgICB9IGVsc2UgaWYgKHNpemUgPCAwKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgc2l6ZSArICciIGlzIGludmFsaWQgZm9yIG9wdGlvbiAic2l6ZSInKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYWxsb2Moc2l6ZSwgZmlsbCwgZW5jb2RpbmcpIHsKICAgICAgICBhc3NlcnRTaXplKHNpemUpOwogICAgICAgIGlmIChzaXplIDw9IDApIHsKICAgICAgICAgIHJldHVybiBjcmVhdGVCdWZmZXIoc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGlmIChmaWxsICE9PSB2b2lkIDApIHsKICAgICAgICAgIHJldHVybiB0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciID8gY3JlYXRlQnVmZmVyKHNpemUpLmZpbGwoZmlsbCwgZW5jb2RpbmcpIDogY3JlYXRlQnVmZmVyKHNpemUpLmZpbGwoZmlsbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmVhdGVCdWZmZXIoc2l6ZSk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYWxsb2MgPSBmdW5jdGlvbihzaXplLCBmaWxsLCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB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SBmdW5jdGlvbiBjb21wYXJlKGEsIGIpIHsKICAgICAgICBpZiAoaXNJbnN0YW5jZShhLCBVaW50OEFycmF5KSkKICAgICAgICAgIGEgPSBCdWZmZXIxMC5mcm9tKGEsIGEub2Zmc2V0LCBhLmJ5dGVMZW5ndGgpOwogICAgICAgIGlmIChpc0luc3RhbmNlKGIsIFVpbnQ4QXJyYXkpKQogICAgICAgICAgYiA9IEJ1ZmZlcjEwLmZyb20oYiwgYi5vZmZzZXQsIGIuYnl0ZUxlbmd0aCk7CiAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihhKSB8fCAhQnVmZmVyMTAuaXNCdWZmZXIoYikpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAiYnVmMSIsICJidWYyIiBhcmd1bWVudHMgbXVzdCBiZSBvbmUgb2YgdHlwZSBCdWZmZXIgb3IgVWludDhBcnJheScpOwogICAgICAgIH0KICAgICAgICBpZiAoYSA9PT0gYikKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gYS5sZW5ndGg7CiAgICAgICAgbGV0IHkgPSBiLmxlbmd0aDsKICAgICAgICBmb3IgKGxldCBpID0gMCwgbGVuID0gTWF0aC5taW4oeCwgeSk7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKGFbaV0gIT09IGJbaV0pIHsKICAgICAgICAgICAgeCA9IGFbaV07CiAgICAgICAgICAgIHkgPSBiW2ldOwogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHggPCB5KQogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIGlmICh5IDwgeCkKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIHJldHVybiAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5pc0VuY29kaW5nID0gZnVuY3Rpb24gaXNFbmNvZGluZyhlbmNvZGluZykgewogICAgICAgIHN3aXRjaCAoU3RyaW5nKGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpKSB7CiAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmNvbmNhdCA9IGZ1bmN0aW9uIGNvbmNhdChsaXN0LCBsZW5ndGgpIHsKICAgICAgICBpZiAoIUFycmF5LmlzQXJyYXkobGlzdCkpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJyJsaXN0IiBhcmd1bWVudCBtdXN0IGJlIGFuIEFycmF5IG9mIEJ1ZmZlcnMnKTsKICAgICAgICB9CiAgICAgICAgaWYgKGxpc3QubGVuZ3RoID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gQnVmZmVyMTAuYWxsb2MoMCk7CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChsZW5ndGggPT09IHZvaWQgMCkgewogICAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICAgIGxlbmd0aCArPSBsaXN0W2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgYnVmZmVyID0gQnVmZmVyMTAuYWxsb2NVbnNhZmUobGVuZ3RoKTsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGlzdC5sZW5ndGg7ICsraSkgewogICAgICAgICAgbGV0IGJ1ZiA9IGxpc3RbaV07CiAgICAgICAgICBpZiAoaXNJbnN0YW5jZShidWYsIFVpbnQ4QXJyYXkpKSB7CiAgICAgICAgICAgIGlmIChwb3MgKyBidWYubGVuZ3RoID4gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkKICAgICAgICAgICAgICAgIGJ1ZiA9IEJ1ZmZlcjEwLmZyb20oYnVmKTsKICAgICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwoYnVmZmVyLCBidWYsIHBvcyk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoIUJ1ZmZlcjEwLmlzQnVmZmVyKGJ1ZikpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmLmNvcHkoYnVmZmVyLCBwb3MpOwogICAgICAgICAgfQogICAgICAgICAgcG9zICs9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWZmZXI7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ5dGVMZW5ndGgoc3RyaW5nLCBlbmNvZGluZykgewogICAgICAgIGlmIChCdWZmZXIxMC5pc0J1ZmZlcihzdHJpbmcpKSB7CiAgICAgICAgICByZXR1cm4gc3RyaW5nLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKEFycmF5QnVmZmVyLmlzVmlldyhzdHJpbmcpIHx8IGlzSW5zdGFuY2Uoc3RyaW5nLCBBcnJheUJ1ZmZlcikpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcuYnl0ZUxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiBzdHJpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvbmUgb2YgdHlwZSBzdHJpbmcsIEJ1ZmZlciwgb3IgQXJyYXlCdWZmZXIuIFJlY2VpdmVkIHR5cGUgJyArIHR5cGVvZiBzdHJpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW4gPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGNvbnN0IG11c3RNYXRjaCA9IGFyZ3VtZW50cy5sZW5ndGggPiAyICYmIGFyZ3VtZW50c1syXSA9PT0gdHJ1ZTsKICAgICAgICBpZiAoIW11c3RNYXRjaCAmJiBsZW4gPT09IDApCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsZW47CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gKiAyOwogICAgICAgICAgICBjYXNlICJoZXgiOgogICAgICAgICAgICAgIHJldHVybiBsZW4gPj4+IDE7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbXVzdE1hdGNoID8gLTEgOiB1dGY4VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgICAgICBsb3dlcmVkQ2FzZSA9IHRydWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEJ1ZmZlcjEwLmJ5dGVMZW5ndGggPSBieXRlTGVuZ3RoOwogICAgICBmdW5jdGlvbiBzbG93VG9TdHJpbmcoZW5jb2RpbmcsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCB8fCBzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA9PT0gdm9pZCAwIHx8IGVuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgfQogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgaWYgKCFlbmNvZGluZykKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICBzd2l0Y2ggKGVuY29kaW5nKSB7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGhleFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgICAgY2FzZSAidXRmLTgiOgogICAgICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgICAgICByZXR1cm4gYXNjaWlTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAibGF0aW4xIjoKICAgICAgICAgICAgY2FzZSAiYmluYXJ5IjoKICAgICAgICAgICAgICByZXR1cm4gbGF0aW4xU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgImJhc2U2NCI6CiAgICAgICAgICAgICAgcmV0dXJuIGJhc2U2NFNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJ1Y3MyIjoKICAgICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgICBjYXNlICJ1dGYxNmxlIjoKICAgICAgICAgICAgY2FzZSAidXRmLTE2bGUiOgogICAgICAgICAgICAgIHJldHVybiB1dGYxNmxlU2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgaWYgKGxvd2VyZWRDYXNlKQogICAgICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgICAgICBlbmNvZGluZyA9IChlbmNvZGluZyArICIiKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLl9pc0J1ZmZlciA9IHRydWU7CiAgICAgIGZ1bmN0aW9uIHN3YXAoYiwgbiwgbSkgewogICAgICAgIGNvbnN0IGkgPSBiW25dOwogICAgICAgIGJbbl0gPSBiW21dOwogICAgICAgIGJbbV0gPSBpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMTYgPSBmdW5jdGlvbiBzd2FwMTYoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDIgIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgMTYtYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSAyKSB7CiAgICAgICAgICBzd2FwKHRoaXMsIGksIGkgKyAxKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwMzIgPSBmdW5jdGlvbiBzd2FwMzIoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDQgIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgMzItYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSA0KSB7CiAgICAgICAgICBzd2FwKHRoaXMsIGksIGkgKyAzKTsKICAgICAgICAgIHN3YXAodGhpcywgaSArIDEsIGkgKyAyKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5zd2FwNjQgPSBmdW5jdGlvbiBzd2FwNjQoKSB7CiAgICAgICAgY29uc3QgbGVuID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbiAlIDggIT09IDApIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJCdWZmZXIgc2l6ZSBtdXN0IGJlIGEgbXVsdGlwbGUgb2YgNjQtYml0cyIpOwogICAgICAgIH0KICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbjsgaSArPSA4KSB7CiAgICAgICAgICBzd2FwKHRoaXMsIGksIGkgKyA3KTsKICAgICAgICAgIHN3YXAodGhpcywgaSArIDEsIGkgKyA2KTsKICAgICAgICAgIHN3YXAodGhpcywgaSArIDIsIGkgKyA1KTsKICAgICAgICAgIHN3YXAodGhpcywgaSArIDMsIGkgKyA0KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS50b1N0cmluZyA9IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gIiI7CiAgICAgICAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gdXRmOFNsaWNlKHRoaXMsIDAsIGxlbmd0aCk7CiAgICAgICAgcmV0dXJuIHNsb3dUb1N0cmluZy5hcHBseSh0aGlzLCBhcmd1bWVudHMpOwogICAgICB9OwogICAgICBCdWZmZ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uZCkgewogICAgICAgIGlmIChpc0luc3RhbmNlKHRhcmdldCwgVWludDhBcnJheSkpIHsKICAgICAgICAgIHRhcmdldCA9IEJ1ZmZlcjEwLmZyb20odGFyZ2V0LCB0YXJnZXQub2Zmc2V0LCB0YXJnZXQuYnl0ZUxlbmd0aCk7CiAgICAgICAgfQogICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGFyZ2V0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlICJ0YXJnZXQiIGFyZ3VtZW50IG11c3QgYmUgb25lIG9mIHR5cGUgQnVmZmVyIG9yIFVpbnQ4QXJyYXkuIFJlY2VpdmVkIHR5cGUgJyArIHR5cGVvZiB0YXJnZXQpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPT09IHZvaWQgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIGVuZCA9IHRhcmdldCA/IHRhcmdldC5sZW5ndGggOiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNTdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzRW5kID09PSB2b2lkIDApIHsKICAgICAgICAgIHRoaXNFbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCBlbmQgPiB0YXJnZXQubGVuZ3RoIHx8IHRoaXNTdGFydCA8IDAgfHwgdGhpc0VuZCA+IHRoaXMubGVuZ3RoKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigib3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCAmJiBzdGFydCA+PSBlbmQpIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBpZiAodGhpc1N0YXJ0ID49IHRoaXNFbmQpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID4+Pj0gMDsKICAgICAgICBlbmQgPj4+PSAwOwogICAgICAgIHRoaXNTdGFydCA+Pj49IDA7CiAgICAgICAgdGhpc0VuZCA+Pj49IDA7CiAgICAgICAgaWYgKHRoaXMgPT09IHRhcmdldCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCB4ID0gdGhpc0VuZCAtIHRoaXNTdGFydDsKICAgICAgICBsZXQgeSA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGNvbnN0IGxlbiA9IE1hdGgubWluKHgsIHkpOwogICAgICAgIGNvbnN0IHRoaXNDb3B5ID0gdGhpcy5zbGljZSh0aGlzU3RhcnQsIHRoaXNFbmQpOwogICAgICAgIGNvbnN0IHRhcmdldENvcHkgPSB0YXJnZXQuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW47ICsraSkgewogICAgICAgICAgaWYgKHRoaXNDb3B5W2ldICE9PSB0YXJnZXRDb3B5W2ldKSB7CiAgICAgICAgICAgIHggPSB0aGlzQ29weVtpXTsKICAgICAgICAgICAgeSA9IHRhcmdldENvcHlbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJpZGlyZWN0aW9uYWxJbmRleE9mKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZywgZGlyKSB7CiAgICAgICAgaWYgKGJ1ZmZlci5sZW5ndGggPT09IDApCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHR5cGVvZiBieXRlT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgZW5jb2RpbmcgPSBieXRlT2Zmc2V0OwogICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0ID4gMjE0NzQ4MzY0NykgewogICAgICAgICAgYnl0ZU9mZnNldCA9IDIxNDc0ODM2NDc7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgLTIxNDc0ODM2NDgpIHsKICAgICAgICAgIGJ5dGVPZmZzZXQgPSAtMjE0NzQ4MzY0ODsKICAgICAgICB9CiAgICAgICAgYnl0ZU9mZnNldCA9ICtieXRlT2Zmc2V0OwogICAgICAgIGlmIChudW1iZXJJc05hTihieXRlT2Zmc2V0KSkgewogICAgICAgICAgYnl0ZU9mZnNldCA9IGRpciA/IDAgOiBidWZmZXIubGVuZ3RoIC0gMTsKICAgICAgICB9CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPCAwKQogICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggKyBieXRlT2Zmc2V0OwogICAgICAgIGlmIChieXRlT2Zmc2V0ID49IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0gZWxzZSBpZiAoYnl0ZU9mZnNldCA8IDApIHsKICAgICAgICAgIGlmIChkaXIpCiAgICAgICAgICAgIGJ5dGVPZmZzZXQgPSAwOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlb2YgdmFsID09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LCBkaXIpIHsKICAgICAgICBsZXQgaW5kZXhTaXplID0gMTsKICAgICAgICBsZXQgYXJyTGVuZ3RoID0gYXJyLmxlbmd0aDsKICAgICAgICBsZXQgdmFsTGVuZ3RoID0gdmFsLmxlbmd0aDsKICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCkgewogICAgICAgICAgZW5jb2RpbmcgPSBTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1Y3MyIiB8fCBlbmNvZGluZyA9PT0gInVjcy0yIiB8fCBlbmNvZGluZyA9PT0gInV0ZjE2bGUiIHx8IGVuY29kaW5nID09PSAidXRmLTE2bGUiKSB7CiAgICAgICAgICAgIGlmIChhcnIubGVuZ3RoIDwgMiB8fCB2YWwubGVuZ3RoIDwgMikgewogICAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbmRleFNpemUgPSAyOwogICAgICAgICAgICBhcnJMZW5ndGggLz0gMjsKICAgICAgICAgICAgdmFsTGVuZ3RoIC89IDI7CiAgICAgICAgICAgIGJ5dGVPZmZzZXQgLz0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcmVhZChidWYsIGkyKSB7CiAgICAgICAgICBpZiAoaW5kZXhTaXplID09PSAxKSB7CiAgICAgICAgICAgIHJldHVybiBidWZbaTJdOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmV0dXJuIGJ1Zi5yZWFkVUludDE2QkUoaTIgKiBpbmRleFNpemUpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBpZiAoZGlyKSB7CiAgICAgICAgICBsZXQgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA8IGFyckxlbmd0aDsgaSsrKSB7CiAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSkgPT09IHJlYWQodmFsLCBmb3VuZEluZGV4ID09PSAtMSA/IDAgOiBpIC0gZm91bmRJbmRleCkpIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCA9PT0gLTEpCiAgICAgICAgICAgICAgICBmb3VuZEluZGV4ID0gaTsKICAgICAgICAgICAgICBpZiAoaSAtIGZvdW5kSW5kZXggKyAxID09PSB2YWxMZW5ndGgpCiAgICAgICAgICAgICAgICByZXR1cm4gZm91bmRJbmRleCAqIGluZGV4U2l6ZTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBpZiAoZm91bmRJbmRleCAhPT0gLTEpCiAgICAgICAgICAgICAgICBpIC09IGkgLSBmb3VuZEluZGV4OwogICAgICAgICAgICAgIGZvdW5kSW5kZXggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoYnl0ZU9mZnNldCArIHZhbExlbmd0aCA+IGFyckxlbmd0aCkKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IGFyckxlbmd0aCAtIHZhbExlbmd0aDsKICAgICAgICAgIGZvciAoaSA9IGJ5dGVPZmZzZXQ7IGkgPj0gMDsgaS0tKSB7CiAgICAgICAgICAgIGxldCBmb3VuZCA9IHRydWU7CiAgICAgICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgdmFsTGVuZ3RoOyBqKyspIHsKICAgICAgICAgICAgICBpZiAocmVhZChhcnIsIGkgKyBqKSAhPT0gcmVhZCh2YWwsIGopKSB7CiAgICAgICAgICAgICAgICBmb3VuZCA9IGZhbHNlOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChmb3VuZCkKICAgICAgICAgICAgICByZXR1cm4gaTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIC0xOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLn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SAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHVjczJXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKCIiICsgZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvSlNPTiA9IGZ1bmN0aW9uIHRvSlNPTigpIHsKICAgICAgICByZXR1cm4gewogICAgICAgICAgdHlwZTogIkJ1ZmZlciIsCiAgICAgICAgICBkYXRhOiBBcnJheS5wcm90b3R5cGUuc2xpY2UuY2FsbCh0aGlzLl9hcnIgfHwgdGhpcywgMCkKICAgICAgICB9OwogICAgICB9OwogICAgICBmdW5jdGlvbiBiYXNlNjRTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBpZiAoc3RhcnQgPT09IDAgJiYgZW5kID09PSBidWYubGVuZ3RoKSB7CiAgICAgICAgICByZXR1cm4gYmFzZTY0LmZyb21CeXRlQXJyYXkoYnVmKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcmV0dXJuIGJhc2U2NC5mcm9tQnl0ZUF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BzZWNvbmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMTI3KSB7CiAgICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gdGVtcENvZGVQb2ludDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAzOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICB0aGlyZEJ5dGUgPSBidWZbaSArIDJdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTIgfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCA2IHwgdGhpcmRCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gMjA0NyAmJiAodGVtcENvZGVQb2ludCA8IDU1Mjk2IHx8IHRlbXBDb2RlUG9pbnQgPiA1NzM0MykpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDQ6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBmb3VydGhCeXRlID0gYnVmW2kgKyAzXTsKICAgICAgICAgICAgICAgIGlmICgoc2Vjb25kQnl0ZSAmIDE5MikgPT09IDEyOCAmJiAodGhpcmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmIChmb3VydGhCeXRlICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICAgICAgICAgIHRlbXBDb2RlUG9pbnQgPSAoZmlyc3RCeXRlICYgMTUpIDw8IDE4IHwgKHNlY29uZEJ5dGUgJiA2MykgPDwgMTIgfCAodGhpcmRCeXRlICYgNjMpIDw8IDYgfCBmb3VydGhCeXRlICYgNjM7CiAgICAgICAgICAgICAgICAgIGlmICh0ZW1wQ29kZVBvaW50ID4gNjU1MzUgJiYgdGVtcENvZGVQb2ludCA8IDExMTQxMTIpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChjb2RlUG9pbnQgPT09IG51bGwpIHsKICAgICAgICAgICAgY29kZVBvaW50ID0gNjU1MzM7CiAgICAgICAgICAgIGJ5dGVzUGVyU2VxdWVuY2UgPSAxOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPiA2NTUzNSkgewogICAgICAgICAgICBjb2RlUG9pbnQgLT0gNjU1MzY7CiAgICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCA+Pj4gMTAgJiAxMDIzIHwgNTUyOTYpOwogICAgICAgICAgICBjb2RlUG9pbnQgPSA1NjMyMCB8IGNvZGVQb2ludCAmIDEwMjM7CiAgICAgICAgICB9CiAgICAgICAgICByZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgaSArPSBieXRlc1BlclNlcXVlbmNlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZGVjb2RlQ29kZVBvaW50c0FycmF5KHJlcyk7CiAgICAgIH0KICAgICAgdmFyIE1BWF9BUkdVTUVOVFNfTEVOR1RIID0gNDA5NjsKICAgICAgZnVuY3Rpb24gZGVjb2RlQ29kZVBvaW50c0FycmF5KGNvZGVQb2lud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BsZW47CiAgICAgICAgICBpZiAoc3RhcnQgPCAwKQogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChzdGFydCA+IGxlbikgewogICAgICAgICAgc3RhcnQgPSBsZW47CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPCAwKSB7CiAgICAgICAgICBlbmQgKz0gbGVuOwogICAgICAgICAgaWYgKGVuZCA8IDApCiAgICAgICAgICAgIGVuZCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChlbmQgPiBsZW4pIHsKICAgICAgICAgIGVuZCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IHN0YXJ0KQogICAgICAgICAgZW5kID0gc3RhcnQ7CiAgICAgICAgY29uc3QgbmV3QnVmID0gdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKTsKICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YobmV3QnVmLCBCdWZmZXIxMC5wcm90b3R5cGUpOwogICAgICAgIHJldHVybiBuZXdCdWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGNoZWNrT2Zmc2V0KG9mZnNldCwgZXh0LCBsZW5ndGgpIHsKICAgICAgICBpZiAob2Zmc2V0ICUgMSAhPT0gMCB8fCBvZmZzZXQgPCAwKQogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIm9mZnNldCBpcyBub3QgdWludCIpOwogICAgICAgIGlmIChvZmZzZXQgKyBleHQgPiBsZW5ndGgpCiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiVHJ5aW5nIHRvIGFjY2VzcyBiZXlvbmQgYnVmZmVyIGxlbmd0aCIpOwogICAgICB9CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5yZWFkVWludExFID0gQnVmZmVyMTAucHJvdG90eXBlLnJlYWRVSW50TEUgPSBmdW5jdGlvbiByZWFkVUludExFKG9mZnNldCwgYnl0ZUxlbmd0aDIsIG5vQXNzZXJ0KS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pID4+IDg7CiAgICAgICAgYnVmW29mZnNldCsrXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0KytdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQrK10gPSBoaTsKICAgICAgICByZXR1cm4gb2Zmc2V0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHdydEJpZ1VJbnQ2NEJFKGJ1ZiwgdmFsdWUsIG9mZnNldCwgbWluLCBtYXgpIHsKICAgICAgICBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIDcpOwogICAgICAgIGxldCBsbyA9IE51bWJlcih2YWx1ZSAmIEJpZ0ludCg0Mjk0OTY3Mjk1KSk7CiAgICAgICAgYnVmW29mZnNldCArIDddID0gbG87CiAgICAgICAgbG8gPSBsbyA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXQgKyA2XSA9IGxvOwogICAgICAgIGxvID0gbG8gPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgNV0gPSBsbzsKICAgICAgICBsbyA9IGxvID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDRdID0gbG87CiAgICAgICAgbGV0IGhpID0gTnVtYmVyKHZhbHVlID4+IEJpZ0ludCgzMikgJiBCaWdJbnQoNDI5NDk2NzI5NSkpOwogICAgICAgIGJ1ZltvZmZzZXQgKyAzXSA9IGhpOwogICAgICAgIGhpID0gaGkgPj4gODsKICAgICAgICBidWZbb2Zmc2V0ICsgMl0gPSBoaTsKICAgICAgICBoaSA9IGhpID4+IDg7CiAgICAgICAgYnVmW29mZnNldCArIDFdID0gaGk7CiAgICAgICAgaGkgPSBoaSA+PiA4OwogICAgICAgIGJ1ZltvZmZzZXRdID0gaGk7CiAgICAgICAgcmV0dXJuIG9mZnNldCArIDg7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLndyaXRlQmlnVUludDY0TEUgPS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DwgMCkKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJzb3VyY2VFbmQgb3V0IG9mIGJvdW5kcyIpOwogICAgICAgIGlmIChlbmQgPiB0aGlzLmxlbmd0aCkKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIGlmICh0YXJnZXQubGVuZ3RoIC0gdGFyZ2V0U3RhcnQgPCBlbmQgLSBzdGFydCkgewogICAgICAgICAgZW5kID0gdGFyZ2V0Lmxlbmd0aCAtIHRhcmdldFN0YXJ0ICsgc3RhcnQ7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IGVuZCAtIHN0YXJ0OwogICAgICAgIGlmICh0aGlzID09PSB0YXJnZXQgJiYgdHlwZW9mIFVpbnQ4QXJyYXkucHJvdG90eXBlLmNvcHlXaXRoaW4gPT09ICJmdW5jdGlvbiIpIHsKICAgICAgICAgIHRoaXMuY29weVdpdGhpbih0YXJnZXRTdGFydCwgc3RhcnQsIGVuZCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIFVpbnQ4QXJyYXkucHJvdG90eXBlLnNldC5jYWxsKHRhcmdldCwgdGhpcy5zdWJhcnJheShzdGFydCwgZW5kKSwgdGFyZ2V0U3RhcnQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbGVuOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuZmlsbCA9IGZ1bmN0aW9uIGZpbGwodmFsLCBzdGFydCwgZW5kLCBlbmNvZGluZykgewogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAic3RyaW5nIikgewogICAgICAgICAgaWYgKHR5cGVvZiBzdGFydCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBzdGFydDsKICAgICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgICAgICBlbmQgPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIGVuZCA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBlbmQ7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGVuY29kaW5nICE9PSB2b2lkIDAgJiYgdHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJlbmNvZGluZyBtdXN0IGJlIGEgc3RyaW5nIik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nID09PSAic3RyaW5nIiAmJiAhQnVmZmVyMTAuaXNFbmNvZGluZyhlbmNvZGluZykpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVW5rbm93biBlbmNvZGluZzogIiArIGVuY29kaW5nKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh2YWwubGVuZ3RoID09PSAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNvZGUgPSB2YWwuY2hhckNvZGVBdCgwKTsKICAgICAgICAgICAgaWYgKGVuY29kaW5nID09PSAidXRmOCIgJiYgY29kZSA8IDEyOCB8fCBlbmNvZGluZyA9PT0gImxhdGluMSIpIHsKICAgICAgICAgICAgICB2YWwgPSBjb2RlOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHZhbCA9PT0gImJvb2xlYW4iKSB7CiAgICAgICAgICB2YWwgPSBOdW1iZXIodmFsKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0YXJ0IDwgMCB8fCB0aGlzLmxlbmd0aCA8IHN0YXJ0IHx8IHRoaXMubGVuZ3RoIDwgZW5kKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcigiT3V0IG9mIHJhbmdlIGluZGV4Iik7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPD0gc3RhcnQpIHsKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBzdGFydCA9IHN0YXJ0ID4+PiAwOwogICAgICAgIGVuZCA9IGVuZCA9PT0gdm9pZCAwID8gdGhpcy5sZW5ndGggOiBlbmQgPj4+IDA7CiAgICAgICAgaWYgKCF2YWwpCiAgICAgICAgICB2YWwgPSAwOwogICAgICAgIGxldCBpOwogICAgICAgIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgZm9yIChpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2ldID0gdmFsOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjb25zdCBieXRlcyA9IEJ1ZmZlcjEwLmlzQnVmZmVyKHZhbCkgPyB2YWwgOiBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgICAgY29uc3QgbGVuID0gYnl0ZXMubGVuZ3RoOwogICAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgdmFsdWUgIicgKyB2YWwgKyAnIiBpcyBpbnZhbGlkIGZvciBhcmd1bWVudCAidmFsdWUiJyk7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGkgPSAwOyBpIDwgZW5kIC0gc3RhcnQ7ICsraSkgewogICAgICAgICAgICB0aGlzW2kgKyBzdGFydF0gPSBieXRlc1tpICUgbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgIH07CiAgICAgIHZhciBlcnJvcnMgPSB7fTsKICAgICAgZnVuY3Rpb24gRShzeW0sIGdldE1lc3NhZ2UsIEJhc2UpIHsKICAgICAgICBlcnJvcnNbc3ltXSA9IGNsYXNzIE5vZGVFcnJvciBleHRlbmRzIEJhc2UgewogICAgICAgICAgY29uc3RydWN0b3IoKSB7CiAgICAgICAgICAgIHN1cGVyKCk7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAibWVzc2FnZSIsIHsKICAgICAgICAgICAgICB2YWx1ZTogZ2V0TWVzc2FnZS5hcHBseSh0aGlzLCBhcmd1bWVudHMpLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgICAgdGhpcy5uYW1lID0gYCR7dGhpcy5uYW1lfSBbJHtzeW19XWA7CiAgICAgICAgICAgIHRoaXMuc3RhY2s7CiAgICAgICAgICAgIGRlbGV0ZSB0aGlzLm5hbWU7CiAgICAgICAgICB9CiAgICAgICAgICBnZXQgY29kZSgpIHsKICAgICAgICAgICAgcmV0dXJuIHN5bTsKICAgICAgICAgIH0KICAgICAgICAgIHNldCBjb2RlKHZhbHVlKSB7CiAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eSh0aGlzLCAiY29kZSIsIHsKICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICB2YWx1ZSwKICAgICAgICAgICAgICB3cml0YWJsZTogdHJ1ZQogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICAgIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gYCR7dGhpcy5uYW1lfSBbJHtzeW19XTogJHt0aGlzLm1lc3NhZ2V9YDsKICAgICAgICAgIH0KICAgICAgICB9OwogICAgICB9CiAgICAgIEUoIkVSUl9CVUZGRVJfT1VUX09GX0JPVU5EUyIsIGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICBpZiAobmFtZSkgewogICAgICAgICAgcmV0dXJuIGAke25hbWV9IGlzIG91dHNp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5dGVzID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgY29kZVBvaW50ID0gc3RyaW5nLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTUyOTUgJiYgY29kZVBvaW50IDwgNTczNDQpIHsKICAgICAgICAgICAgaWYgKCFsZWFkU3Vycm9nYXRlKSB7CiAgICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA+IDU2MzE5KSB7CiAgICAgICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgICB9IGVsc2UgaWYgKGkgKyAxID09PSBsZW5ndGgpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCA1NjMyMCkgewogICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICAgICAgbGVhZFN1cnJvZ2F0ZSA9IGNvZGVQb2ludDsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjb2RlUG9pbnQgPSAobGVhZFN1cnJvZ2F0ZSAtIDU1Mjk2IDw8IDEwIHwgY29kZVBvaW50IC0gNTYzMjApICsgNjU1MzY7CiAgICAgICAgICB9IGVsc2UgaWYgKGxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgIGJ5dGVzLnB1c2goMjM5LCAxOTEsIDE4OSk7CiAgICAgICAgICB9CiAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gbnVsbDsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPCAxMjgpIHsKICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAxKSA8IDApCiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIGJ5dGVzLnB1c2goY29kZVBvaW50KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMjA0OCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDIpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gNiB8IDE5MiwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCA2NTUzNikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTIgfCAyMjQsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSBpZiAoY29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDQpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQgPj4gMTggfCAyNDAsIGNvZGVQb2ludCA+PiAxMiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgPj4gNiAmIDYzIHwgMTI4LCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoIkludmFsaWQgY29kZSBwb2ludCIpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlUb0J5dGVzKHN0cikgewogICAgICAgIGNvbnN0IGJ5dGVBcnJheSA9IFtdOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChzdHIuY2hhckNvZGVBdChpKSAmIDI1NSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdXRmMTZsZVRvQnl0ZXMoc3RyLCB1bml0cykgewogICAgICAgIGxldCBjLCBoaSwgbG87CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICBicmVhazsKICAgICAgICAgIGMgPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGhpID0gYyA+PiA4OwogICAgICAgICAgbG8gPSBjICUgMjU2OwogICAgICAgICAgYnl0ZUFycmF5LnB1c2gobG8pOwogICAgICAgICAgYnl0ZUFycmF5LnB1c2goaGkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gYnl0ZUFycmF5OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJhc2U2NFRvQnl0ZXMoc3RyKSB7CiAgICAgICAgcmV0dXJuIGJhc2U2NC50b0J5dGVBcnJheShiYXNlNjRjbGVhbihzdHIpKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBibGl0QnVmZmVyKHNyYywgZHN0LCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGxldCBpOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKGkgKyBvZmZzZXQgPj0gZHN0Lmxlbmd0aCB8fCBpID49IHNyYy5sZW5ndGgpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgZHN0W2kgKyBvZmZzZXRdID0gc3JjW2ldOwogICAgICAgIH0KICAgICAgICByZXR1cm4gaTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc0luc3RhbmNlKG9iaiwgdHlwZSkgewogICAgICAgIHJldHVybiBvYmogaW5zdGFuY2VvZiB0eXBlIHx8IG9iaiAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3RvciAhPSBudWxsICYmIG9iai5jb25zdHJ1Y3Rvci5uYW1lICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgPT09IHR5cGUubmFtZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBudW1iZXJJc05hTihvYmopIHsKICAgICAgICByZXR1cm4gb2JqICE9PSBvYmo7CiAgICAgIH0KICAgICAgdmFyIGhleFNsaWNlTG9va3VwVGFibGUgPSBmdW5jdGlvbigpIHsKICAgICAgICBjb25zdCBhbHBoYWJldCA9ICIwMTIzNDU2Nzg5YWJjZGVmIjsKICAgICAgICBjb25zdCB0YWJsZSA9IG5ldyBBcnJheSgyNTYpOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgMTY7ICsraSkgewogICAgICAgICAgY29uc3QgaTE2ID0gaSAqIDE2OwogICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCAxNjsgKytqKSB7CiAgICAgICAgICAgIHRhYmxlW2kxNiArIGpdID0gYWxwaGFiZXRbaV0gKyBhbHBoYWJldFtqXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9KCk7CiAgICAgIGZ1bmN0aW9uIGRlZmluZUJpZ0ludE1ldGhvZChmbikgewogICAgICAgIHJldHVybiB0e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iAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICByZXR1cm4gQ29uc3RydWN0b3I7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2luaGVyaXRzKHN1YkNsYXNzLCBzdXBlckNsYXNzKSB7CiAgICAgICAgaWYgKHR5cGVvZiBzdXBlckNsYXNzICE9PSAiZnVuY3Rpb24iICYmIHN1cGVyQ2xhc3MgIT09IG51bGwpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlN1cGVyIGV4cHJlc3Npb24gbXVzdCBlaXRoZXIgYmUgbnVsbCBvciBhIGZ1bmN0aW9uIik7CiAgICAgICAgfQogICAgICAgIHN1YkNsYXNzLnByb3RvdHlwZSA9IE9iamVjdC5jcmVhdGUoc3VwZXJDbGFzcyAmJiBzdXBlckNsYXNzLnByb3RvdHlwZSwgewogICAgICAgICAgY29uc3RydWN0b3I6IHsKICAgICAgICAgICAgdmFsdWU6IHN1YkNsYXNzLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHN1YkNsYXNzLCAicHJvdG90eXBlIiwgewogICAgICAgICAgd3JpdGFibGU6IGZhbHNlCiAgICAgICAgfSk7CiAgICAgICAgaWYgKHN1cGVyQ2xhc3MpCiAgICAgICAgICBfc2V0UHJvdG90eXBlT2Yoc3ViQ2xhc3MsIHN1cGVyQ2xhc3MpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZihvKSB7CiAgICAgICAgX2dldFByb3RvdHlwZU9mID0gT2JqZWN0LnNldFByb3RvdHlwZU9mID8gT2JqZWN0LmdldFByb3RvdHlwZU9mLmJpbmQoKSA6IGZ1bmN0aW9uIF9nZXRQcm90b3R5cGVPZjIobzIpIHsKICAgICAgICAgIHJldHVybiBvMi5fX3Byb3RvX18gfHwgT2JqZWN0LmdldFByb3RvdHlwZU9mKG8yKTsKICAgICAgICB9OwogICAgICAgIHJldHVybiBfZ2V0UHJvdG90eXBlT2Yobyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mKG8sIHApIHsKICAgICAgICBfc2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3Quc2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX3NldFByb3RvdHlwZU9mMihvMiwgcDIpIHsKICAgICAgICAgIG8yLl9fcHJvdG9fXyA9IHAyOwogICAgICAgICAgcmV0dXJuIG8yOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9zZXRQcm90b3R5cGVPZihvLCBwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfaXNOYXRpdmVSZWZsZWN0Q29uc3RydWN0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCA9PT0gInVuZGVmaW5lZCIgfHwgIVJlZmxlY3QuY29uc3RydWN0KQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmIChSZWZsZWN0LmNvbnN0cnVjdC5zaGFtKQogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIGlmICh0eXBlb2YgUHJveHkgPT09ICJmdW5jdGlvbiIpCiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB0cnkgewogICAgICAgICAgQm9vbGVhbi5wcm90b3R5cGUudmFsdWVPZi5jYWxsKFJlZmxlY3QuY29uc3RydWN0KEJvb2xlYW4sIFtdLCBmdW5jdGlvbigpIHsKICAgICAgICAgIH0pKTsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2Fzc2VydFRoaXNJbml0aWF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zKS5jb25zdHJ1Y3RvcjsKICAgICAgICAgICAgcmVzdWx0ID0gUmVmbGVjdC5jb25zdHJ1Y3QoU3VwZXIsIGFyZ3VtZW50cywgTmV3VGFyZ2V0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJlc3VsdCA9IFN1cGVyLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gX3Bvc3NpYmxlQ29uc3RydWN0b3JSZXR1cm4odGhpcywgcmVzdWx0KTsKICAgICAgICB9OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9zdXBlclByb3BCYXNlKG9iamVjdCwgcHJvcGVydHkpIHsKICAgICAgICB3aGlsZSAoIU9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydHkuY2FsbChvYmplY3QsIHByb3BlcnR5KSkgewogICAgICAgICAgb2JqZWN0ID0gX2dldFByb3RvdHlwZU9mKG9iamVjdCk7CiAgICAgICAgICBpZiAob2JqZWN0ID09PSBudWxsKQogICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iamVjdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBfZ2V0KCkgewogICAgICAgIGlmICh0eXBlb2YgUmVmbGVjdCAhPT0gInVuZGVmaW5lZCIgJiYgUmVmbGVjdC5nZXQpIHsKICAgICAgICAgIF9nZXQgPSBSZWZsZWN0LmdldC5iaW5kKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIF9nZXQgPSBmdW5jdGlvbiBfZ2V0Mih0YXJnZXQsIHByb3BlcnR5LCByZWNlaXZlcikgewogICAgICAgICAgICB2YXIgYmFzZSA9IF9zdXBlclByb3BCYXNlKHRhcmdldCwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoIWJhc2UpCiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB2YXIgZGVzYyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eURlc2NyaXB0b3IoYmFzZSwgcHJvcGVydHkpOwogICAgICAgICAgICBpZiAoZGVzYy5nZXQpIHsKICAgICAgICAgICAgICByZXR1cm4gZGVzYy5nZXQuY2FsbChhcmd1bWVudHMubGVuZ3RoIDwgMyA/IHRhcmdldCA6IHJlY2VpdmVyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gZGVzYy52YWx1ZTsKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICAgIHJldHVybiBfZ2V0LmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH0KICAgICAgdmFyIEVtaXR0ZXIgPSAvKiBAX19QVVJFX18gKi8gZnVuY3Rpb24oKSB7CiAgICAgICAgZnVuY3Rpb24gRW1pdHRlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgRW1pdHRlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJsaXN0ZW5lcnMiLCB7CiAgICAgICAgICAgIHZhbHVlOiB7fSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhFbWl0dGVyMiwgW3sKICAgICAgICAgIGtleTogImFkZEV2ZW50TGlzdGVuZXIiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFkZEV2ZW50TGlzdGVuZXIodHlwZSwgY2FsbGJhY2ssIG9wdGlvbnMpIHsKICAgICAgICAgICAgaWYgKCEodHlwZSBpbiB0aGlzLmxpc3RlbmVycykpIHsKICAgICAgICAgICAgICB0aGlzLmxpc3RlbmVyc1t0eXBlXSA9IFtdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdLnB1c2goewogICAgICAgICAgICAgIGNhbGxiYWNrLAogICAgICAgICAgICAgIG9wdGlvbnMKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAicmVtb3ZlRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gcmVtb3ZlRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1t0eXBlXTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFjay5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICBpZiAoc3RhY2tbaV0uY2FsbGJhY2sgPT09IGNhbGxiYWNrKSB7CiAgICAgICAgICAgICAgICBzdGFjay5zcGxpY2UoaSwgMSk7CiAgICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSwgewogICAgICAgICAga2V5OiAiZGlzcGF0Y2hFdmVudCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gZGlzcGF0Y2hFdmVudChldmVudCkgewogICAgICAgICAgICBpZiAoIShldmVudC50eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgc3RhY2sgPSB0aGlzLmxpc3RlbmVyc1tldmVudC50eXBlXTsKICAgICAgICAgICAgdmFyIHN0YWNrVG9DYWxsID0gc3RhY2suc2xpY2UoKTsKICAgICAgICAgICAgZm9yICh2YXIgaSA9IDAsIGwgPSBzdGFja1RvQ2FsbC5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICB2YXIgbGlzdGVuZXIgPSBzdGFja1RvQ2FsbFtpXTsKICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgbGlzdGVuZXIuY2FsbGJhY2suY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgICAgUHJvbWlzZS5yZXNvbHZlKCkudGhlbihmdW5jdGlvbigpIHsKICAgICAgICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgICAgICAgIH0pOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAobGlzdGVuZXIub3B0aW9ucyAmJiBsaXN0ZW5lci5vcHRpb25zLm9uY2UpIHsKICAgICAgICAgICAgICAgIHRoaXMucmVtb3ZlRXZlbnRMaXN0ZW5lcihldmVudC50eXBlLCBsaXN0ZW5lci5jYWxsYmFjayk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiAhZXZlbnQuZGVmYXVsdFByZXZlbnRlZDsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEVtaXR0ZXIyOwogICAgICB9KCk7CiAgICAgIHZhciBBYm9ydFNpZ25hbCA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbihfRW1pdHRlcikgewogICAgICAgIF9pbmhlcml0cyhBYm9ydFNpZ25hbDIsIF9FbWl0dGVyKTsKICAgICAgICB2YXIgX3N1cGVyID0gX2NyZWF0ZVN1cGVyKEFib3J0U2lnbmFsMik7CiAgICAgICAgZnVuY3Rpb24gQWJvcnRTaWduYWwyKCkgewogICAgICAgICAgdmFyIF90aGlzOwogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0U2lnbmFsMik7CiAgICAgICAgICBfdGhpcyA9IF9zdXBlci5jYWxsKHRoaXMpOwogICAgICAgICAgaWYgKCFfdGhpcy5saXN0ZW5lcnMpIHsKICAgICAgICAgICAgRW1pdHRlci5jYWxsKF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpKTsKICAgICAgICAgIH0KICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgImFib3J0ZWQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBmYWxzZSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJvbmFib3J0IiwgewogICAgICAgICAgICB2YWx1ZTogbnVsbCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcyksICJyZWFzb24iLCB7CiAgICAgICAgICAgIHZhbHVlOiB2b2lkIDAsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0pOwogICAgICAgICAgcmV0dXJuIF90aGlzOwogICAgICAgIH0KICAgICAgICBfY3JlYXRlQ2xhc3MoQWJvcnRTaWduYWwyLCBbewogICAgICAgICAga2V5OiAidG9TdHJpbmciLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIHRvU3RyaW5nKCkgewogICAgICAgICAgICByZXR1cm4gIltvYmplY3QgQWJvcnRTaWduYWxdIjsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmIChldmVudC50eXBlID09PSAiYWJvcnQiKSB7CiAgICAgICAgICAgICAgdGhpcy5hYm9ydGVkID0gdHJ1ZTsKICAgICAgICAgICAgICBpZiAodHlwZW9mIHRoaXMub25hYm9ydCA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICAgICAgdGhpcy5vbmFib3J0LmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBfZ2V0KF9nZXRQcm90b3R5cGVPZihBYm9ydFNpZ25hbDIucHJvdG90eXBlKSwgImRpc3BhdGNoRXZlbnQiLCB0aGlzKS5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgIH0KICAgICAgICB9XSk7CiAgICAgICAgcmV0dXJuIEFib3J0U2lnbmFsMjsKICAgICAgfShFbWl0dGVyKTsKICAgICAgdmFyIEFib3J0Q29udHJvbGxlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBBYm9ydENvbnRyb2xsZXIyKCkgewogICAgICAgICAgX2NsYXNzQ2FsbENoZWNrKHRoaXMsIEFib3J0Q29udHJvbGxlcjIpOwogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJzaWduYWwiLCB7CiAgICAgICAgICAgIHZhbHVlOiBuZXcgQWJvcnRTaWduYWwoKSwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydENvbnRyb2xsZXIyLCBbewogICAgICAgICAga2V5OiAiYWJvcnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGFib3J0KHJlYXNvbikgewogICAgICAgICAgICB2YXIgZXZlbnQ7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgZXZlbnQgPSBuZXcgRXZlbnQoImFib3J0Iik7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICBpZiAodHlwZW9mIGRvY3VtZW50ICE9PSAidW5kZWZpbmVkIikgewogICAgICAgICAgICAgICAgaWYgKCFkb2N1bWVudC5jcmVhdGVFdmVudCkgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50T2JqZWN0KCk7CiAgICAgICAgICAgICAgICAgIGV2ZW50LnR5cGUgPSAiYWJvcnQiOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgZXZlbnQgPSBkb2N1bWVudC5jcmVhdGVFdmVudCgiRXZlbnQiKTsKICAgICAgICAgICAgICAgICAgZXZlbnQuaW5pdEV2ZW50KCJhYm9ydCIsIGZhbHNlLCBmYWxzZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGV2ZW50ID0gewogICAgICAgICAgICAgICAgICB0eXBlOiAiYWJvcnQiLAogICAgICAgICAgICAgICAgICBidWJibGVzOiBmYWxzZSwKICAgICAgICAgICAgICAgICAgY2FuY2VsYWJsZTogZmFsc2UKICAgICAgICAgICAgICAgIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzaWduYWxSZWFzb24gPSByZWFzb247CiAgICAgICAgICAgIGlmIChzaWduYWxSZWFzb24gPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgPT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24ubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uID0gbmV3IERPTUV4Y2VwdGlvbigic2lnbmFsIGlzIGFib3J0ZWQgd2l0aG91dCByZWFzb24iKTsKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKGVycikgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRXJyb3IoIlRoaXMgb3BlcmF0aW9uIHdhcyBhYm9ydGVkIik7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLnNpZ25hbC5yZWFzb24gPSBzaWduYWxSZWFzb247CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLmRpc3BhdGNoRXZlbnQoZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogInRvU3RyaW5nIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiB0b1N0cmluZygpIHsKICAgICAgICAgICAgcmV0dXJuICJbb2JqZWN0IEFib3J0Q29udHJvbGxlcl0iOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRDb250cm9sbGVyMjsKICAgICAgfSgpOwogICAgICBpZiAodHlwZW9mIFN5bWJvbCAhPT0gInVuZGVmaW5lZCIgJiYgU3ltYm9sLnRvU3RyaW5nVGFnKSB7CiAgICAgICAgQWJvcnRDb250cm9sbGVyLnByb3RvdHlwZVtTeW1ib2wudG9TdHJpbmdUYWddID0gIkFib3J0Q29udHJvbGxlciI7CiAgICAgICAgQWJvcnRTaWduYWwucHJvdG90eXBlW1N5bWJvbC50b1N0cmluZ1RhZ10gPSAiQWJvcnRTaWduYWwiOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBvbHlmaWxsTmVlZGVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyLl9fRk9SQ0VfSU5TVE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pZ25hbCkgewogICAgICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShyZXF1ZXN0LCAic2lnbmFsIiwgewogICAgICAgICAgICAgICAgd3JpdGFibGU6IGZhbHNlLAogICAgICAgICAgICAgICAgZW51bWVyYWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUsCiAgICAgICAgICAgICAgICB2YWx1ZTogc2lnbmFsCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIHJlcXVlc3Q7CiAgICAgICAgICB9OwogICAgICAgICAgUmVxdWVzdC5wcm90b3R5cGUgPSBOYXRpdmVSZXF1ZXN0LnByb3RvdHlwZTsKICAgICAgICB9CiAgICAgICAgdmFyIHJlYWxGZXRjaCA9IGZldGNoOwogICAgICAgIHZhciBhYm9ydGFibGVGZXRjaCA9IGZ1bmN0aW9uIGFib3J0YWJsZUZldGNoMihpbnB1dCwgaW5pdDIpIHsKICAgICAgICAgIHZhciBzaWduYWwgPSBSZXF1ZXN0ICYmIFJlcXVlc3QucHJvdG90eXBlLmlzUHJvdG90eXBlT2YoaW5wdXQpID8gaW5wdXQuc2lnbmFsIDogaW5pdDIgPyBpbml0Mi5zaWduYWwgOiB2b2lkIDA7CiAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgIHZhciBhYm9ydEVycm9yOwogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIGFib3J0RXJyb3IgPSBuZXcgRE9NRXhjZXB0aW9uKCJBYm9ydGVkIiwgIkFib3J0RXJyb3IiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBFcnJvcigiQWJvcnRlZCIpOwogICAgICAgICAgICAgIGFib3J0RXJyb3IubmFtZSA9ICJBYm9ydEVycm9yIjsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yZWplY3QoYWJvcnRFcnJvcik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIGNhbmNlbGxhdGlvbiA9IG5ldyBQcm9taXNlKGZ1bmN0aW9uKF8sIHJlamVjdCkgewogICAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsIGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgICB9LCB7CiAgICAgICAgICAgICAgICBvbmNlOiB0cnVlCiAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgZGVsZXRlIGluaXQyLnNpZ25hbDsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gUHJvbWlzZS5yYWNlKFtjYW5jZWxsYXRpb24sIHJlYWxGZXRjaChpbnB1dCwgaW5pdDIpXSk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVhbEZldGNoKGlucHV0LCBpbml0Mik7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gewogICAgICAgICAgZmV0Y2g6IGFib3J0YWJsZUZldGNoLAogICAgICAgICAgUmVxdWVzdAogICAgICAgIH07CiAgICAgIH0KICAgICAgZXhwb3J0czIuQWJvcnRDb250cm9sbGVyID0gQWJvcnRDb250cm9sbGVyOwogICAgICBleHBvcnRzMi5BYm9ydFNpZ25hbCA9IEFib3J0U2lnbmFsOwogICAgICBleHBvcnRzMi5hYm9ydGFibGVGZXRjaCA9IGFib3J0YWJsZUZldGNoRGVjb3JhdG9yOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vYWJvcnRhYmxlLXByb21pc2UtY2FjaGVAMS41LjAvbm9kZV9tb2R1bGVzL2Fib3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aWxsXzEgPSByZXF1aXJlX2Fib3J0Y29udHJvbGxlcl9wb255ZmlsbCgpOwogICAgICB2YXIgTnVsbFNpZ25hbCA9IGNsYXNzIHsKICAgICAgfTsKICAgICAgdmFyIEFnZ3JlZ2F0ZUFib3J0Q29udHJvbGxlciA9IGNsYXNzIHsKICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgIHRoaXMuc2lnbmFscyA9IG5ldyBTZXQoKTsKICAgICAgICAgIHRoaXMuYWJvcnRDb250cm9sbGVyID0gbmV3IGFib3J0Y29udHJvbGxlcl9wb255ZmlsbF8xLkFib3J0Q29udHJvbGxlcigpOwogICAgICAgIH0KICAgICAgICBhZGRTaWduYWwoc2lnbmFsID0gbmV3IE51bGxTaWduYWwoKSkgewogICAgICAgICAgaWYgKHRoaXMuc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJjYW5ub3QgYWRkIGEgc2lnbmFsLCBhbHJlYWR5IGFib3J0ZWQhIik7CiAgICAgICAgICB9CiAgICAgICAgICB0aGlzLnNpZ25hbHMuYWRkKHNpZ25hbCk7CiAgICAgICAgICBpZiAoc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIikgewogICAgICAgICAgICBzaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgICAgdGhpcy5oYW5kbGVBYm9ydGVkKHNpZ25hbCk7CiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBoYW5kbGVBYm9ydGVkKHNpZ25hbCkgewogICAgICAgICAgdGhpcy5zaWduYWxzLmRlbGV0ZShzaWduYWwpOwogICAgICAgICAgaWYgKHR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IHsKICAgICAgICAgICAgYWJvcnRlciwKICAgICAgICAgICAgcHJvbWlzZTogdGhpcy5maWxsQ2FsbGJhY2soZGF0YSwgYWJvcnRlci5zaWduYWwsIChtZXNzYWdlKSA9PiB7CiAgICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIuY2FsbGJhY2sobWVzc2FnZSk7CiAgICAgICAgICAgIH0pLAogICAgICAgICAgICBzZXR0bGVkOiBmYWxzZSwKICAgICAgICAgICAgc3RhdHVzUmVwb3J0ZXIsCiAgICAgICAgICAgIGdldCBhYm9ydGVkKCkgewogICAgICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0ZXIuc2lnbmFsLmFib3J0ZWQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgbmV3RW50cnkuYWJvcnRlci5zaWduYWwuYWRkRXZlbnRMaXN0ZW5lcigiYWJvcnQiLCAoKSA9PiB7CiAgICAgICAgICAgIGlmICghbmV3RW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0pOwogICAgICAgICAgbmV3RW50cnkucHJvbWlzZS50aGVuKCgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICB9LCAoKSA9PiB7CiAgICAgICAgICAgIG5ld0VudHJ5LnNldHRsZWQgPSB0cnVlOwogICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgbmV3RW50cnkpOwogICAgICAgICAgfSkuY2F0Y2goKGUpID0+IHsKICAgICAgICAgICAgY29uc29sZS5lcnJvcihlKTsKICAgICAgICAgICAgdGhyb3cgZTsKICAgICAgICAgIH0pOwogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpYyBjaGVja1NpbmdsZVByb21pc2UocHJvbWlzZSwgc2lnbmFsKSB7CiAgICAgICAgICBmdW5jdGlvbiBjaGVja0ZvclNpbmdsZUFib3J0KCkgewogICAgICAgICAgICBpZiAoc2lnbmFsICYmIHNpZ25hbC5hYm9ydGVkKSB7CiAgICAgICAgICAgICAgdGhyb3cgT2JqZWN0LmFzc2lnbihuZXcgRXJyb3IoImFib3J0ZWQiKSwgeyBjb2RlOiAiRVJSX0FCT1JURUQiIH0pOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcHJvbWlzZS50aGVuKChyZXN1bHQpID0+IHsKICAgICAgICAgICAgY2hlY2tGb3JTaW5nbGVBYm9ydCgpOwogICAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgICAgfSwgKGVycm9yKSA9PiB7CiAgICAgICAgICAgIGNoZWNrRm9yU2luZ2xlQWJvcnQoKTsKICAgICAgICAgICAgdGhyb3cgZXJyb3I7CiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgaGFzKGtleSkgewogICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIGdldChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spIHsKICAgICAgICAgIGlmICghc2lnbmFsICYmIGRhdGEgaW5zdGFuY2VvZiBhYm9ydGNvbnRyb2xsZXJfcG9ueWZpbGxfMS5BYm9ydFNpZ25hbCkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJzZWNvbmQgZ2V0IGFyZ3VtZW50IGFwcGVhcnMgdG8gYmUgYW4gQWJvcnRTaWduYWwsIHBlcmhhcHMgeW91IG1lYW50IHRvIHBhc3MgYG51bGxgIGZvciB0aGUgZmlsbCBkYXRhPyIpOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgY2FjaGVFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVFbnRyeSkgewogICAgICAgICAgICBpZiAoY2FjaGVFbnRyeS5hYm9ydGVkICYmICFjYWNoZUVudHJ5LnNldHRsZWQpIHsKICAgICAgICAgICAgICB0aGlzLmV2aWN0KGtleSwgY2FjaGVFbnRyeSk7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuZ2V0KGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNhY2hlRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIHJldHVybiBjYWNoZUVudHJ5LnByb21pc2U7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY2FjaGVFbnRyeS5hYm9ydGVyLmFkZFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBjYWNoZUVudHJ5LnN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKGNhY2hlRW50cnkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuZmlsbChrZXksIGRhdGEsIHNpZ25hbCwgc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgcmV0dXJuIEFib3J0YWJsZVByb21pc2VDYWNoZTIuY2hlY2tTaW5nbGVQcm9taXNlKHRoaXMuY2FjaGUuZ2V0KGtleSkucHJvbWlzZSwgc2lnbmFsKTsKICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgY2FjaGVkRW50cnkgPSB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgaWYgKGNhY2hlZEVudHJ5KSB7CiAgICAgICAgICAgIGlmICghY2FjaGVkRW50cnkuc2V0dGxlZCkgewogICAgICAgICAgICAgIGNhY2hlZEVudHJ5LmFib3J0ZXIuYWJvcnQoKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIGNvbnN0IGtleUl0ZXIgPSB0aGlzLmNhY2hlLmtleXMoKTsKICAgICAgICAgIGxldCBkZWxldGVDb3VudCA9IDA7CiAgICAgICAgICBmb3IgKGxldCByZXN1bHQgPSBrZXlJdGVyLm5leHQoKTsgIXJlc3VsdC5kb25lOyByZXN1bHQgPSBrZXlJdGVyLm5leHQoKSkgewogICAgICAgICAgICB0aGlzLmRlbGV0ZShyZXN1bHQudmFsdWUpOwogICAgICAgICAgICBkZWxldGVDb3VudCArPSAxOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGRlbGV0ZUNvdW50OwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuZGVmYXVsdCA9IEFib3J0YWJsZVByb21pc2VDYWNoZTI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZUAxLjUuMC9ub2RlX21vZHVsZXMvYWJvcnRhYmxlLXByb21pc2UtY2FjaGUvZXNtL2luZGV4LmpzCiAgdmFyIHJlcXVpcmVfZXNtID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL2Fib3J0YWJsZS1wcm9taXNlLWNhY2hlQDEuNS4wL25vZGVfbW9kdWxlcy9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZS9lc20vaW5kZXguanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgX19pbXBvcnREZWZhdWx0ID0gZXhwb3J0czIgJiYgZXhwb3J0czIuX19pbXBvcnREZWZhdWx0IHx8IGZ1bmN0aW9u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aGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLm9sZENhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgIF9zZXQoa2V5LCB2YWx1ZSkgewogICAgICAgICAgdGhpcy5jYWNoZS5zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICB0aGlzLl9zaXplKys7CiAgICAgICAgICBpZiAodGhpcy5fc2l6ZSA+PSB0aGlzLm1heFNpemUpIHsKICAgICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSB0aGlzLmNhY2hlOwogICAgICAgICAgICB0aGlzLmNhY2hlID0gbmV3IE1hcCgpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBnZXQoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIGNvbnN0IHZhbHVlID0gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgICByZXR1cm4gdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHNldChrZXksIHZhbHVlKSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMuX3NldChrZXksIHZhbHVlKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIH0KICAgICAgICBoYXMoa2V5KSB7CiAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5oYXMoa2V5KSB8fCB0aGlzLm9sZENhY2hlLmhhcyhrZXkpOwogICAgICAgIH0KICAgICAgICBwZWVrKGtleSkgewogICAgICAgICAgaWYgKHRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy5vbGRDYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVsZXRlKGtleSkgewogICAgICAgICAgY29uc3QgZGVsZXRlZCA9IHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICBpZiAoZGVsZXRlZCkgewogICAgICAgICAgICB0aGlzLl9zaXplLS07CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gdGhpcy5vbGRDYWNoZS5kZWxldGUoa2V5KSB8fCBkZWxldGVkOwogICAgICAgIH0KICAgICAgICBjbGVhcigpIHsKICAgICAgICAgIHRoaXMuY2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUuY2xlYXIoKTsKICAgICAgICAgIHRoaXMuX3NpemUgPSAwOwogICAgICAgIH0KICAgICAgICAqa2V5cygpIHsKICAgICAgICAgIGZvciAoY29uc3QgW2tleV0gb2YgdGhpcykgewogICAgICAgICAgICB5aWVsZCBrZXk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICp2YWx1ZXMoKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IFssIHZhbHVlXSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIHZhbHVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAqW1N5bWJvbC5pdGVyYXRvcl0oKSB7CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5jYWNoZSkgewogICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgfQogICAgICAgICAgZm9yIChjb25zdCBpdGVtIG9mIHRoaXMub2xkQ2FjaGUpIHsKICAgICAgICAgICAgY29uc3QgW2tleV0gPSBpdGVtOwogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICB5aWVsZCBpdGVtOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldCBzaXplKCkgewogICAgICAgICAgbGV0IG9sZENhY2hlU2l6ZSA9IDA7CiAgICAgICAgICBmb3IgKGNvbnN0IGtleSBvZiB0aGlzLm9sZENhY2hlLmtleXMoKSkgewogICAgICAgICAgICBpZiAoIXRoaXMuY2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgICBvbGRDYWNoZVNpemUrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXMuX3NpemUgKyBvbGRDYWNoZVNpemU7CiAgICAgICAgfQogICAgICB9OwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBRdWlja0xSVTsKICAgIH0KICB9KTsKCiAgLy8gKGRpc2FibGVkKTpub2RlX21vZHVsZXMvLnBucG0vZ2VuZXJpYy1maWxlaGFuZGxlQDMuMS4xL25vZGVfbW9kdWxlcy9nZW5lcmljLWZpbGVoYW5kbGUvZXNtL2xvY2FsRmlsZQogIHZhciByZXF1aXJlX2xvY2FsRmlsZSA9IF9fY29tbW9uSlMoewogICAgIihkaXNhYmxlZCk6bm9kZV9tb2R1bGVzLy5wbnBtL2dlbmVyaWMtZmlsZWhhbmRsZUAzLjEuMS9ub2RlX21vZHVsZXMvZ2VuZXJpYy1maWxlaGFuZGxlL2VzbS9sb2NhbEZpbGUiKCkgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvdXRpbHMvY29tbW9uLmpzCiAgdmFyIHJlcXVpcmVfY29tbW9uID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi91dGlscy9jb21tb24uanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgVFlQRURfT0sgPSB0eXBlb2YgVWludDhBcnJheSAhPT0gInVuZGVmaW5lZCIgJiYgdHlwZW9mIFVpbnQxNkFycmF5ICE9PSAidW5kZWZpbmVkIiAmJiB0eXBlb2YgSW50MzJBcnJheSAhPT0gInVuZGVmaW5lZCI7CiAgICAgIGZ1bmN0aW9uIF9oYXMob2JqLCBrZXkpIHsKICAgICAgICByZXR1cm4gT2JqZWN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eS5jYWxsKG9iaiwga2V5KTsKICAgICAgfQogICAgICBleHBvcnRzMi5hc3NpZ24gPSBmdW5jdGlvbihvYmopIHsKICAgICAgICB2YXIgc291cmNlcyA9IEFycmF5LnByb3RvdHlwZS5zbGljZS5jYWxsKGFyZ3VtZW50cywgMSk7CiAgICAgICAgd2hpbGUgKHNvdXJjZXMubGVuZ3RoKSB7CiAgICAgICAgICB2YXIgc291cmNlID0gc291cmNlcy5zaGlmdCgpOwogICAgICAgICAgaWYgKCFzb3VyY2UpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodHlwZW9mIHNvdXJjZSAhPT0gIm9iamVjdCIpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcihzb3VyY2UgKyAibXVzdCBiZSBub24tb2JqZWN0Iik7CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBwIGluIHNvdXJjZSkgewogICAgICAgICAgICBpZiAoX2hhcyhzb3VyY2UsIHApKSB7CiAgICAgICAgICAgICAgb2JqW3BdID0gc291cmNlW3BdOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBvYmo7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNocmlua0J1ZiA9IGZ1bmN0aW9uKGJ1Ziwgc2l6ZSkgewogICAgICAgIGlmIChidWYubGVuZ3RoID09PSBzaXplKSB7CiAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgIH0KICAgICAgICBpZiAoYnVmLnN1YmFycmF5KSB7CiAgICAgICAgICByZXR1cm4gYnVmLnN1YmFycmF5KDAsIHNpemUpOwogICAgICAgIH0KICAgICAgICBidWYubGVuZ3RoID0gc2l6ZTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9OwogICAgICB2YXIgZm5UeXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGlmIChzcmMuc3ViYXJyYXkgJiYgZGVzdC5zdWJhcnJheSkgewogICAgICAgICAgICBkZXN0LnNldChzcmMuc3ViYXJyYXkoc3JjX29mZnMsIHNyY19vZmZzICsgbGVuKSwgZGVzdF9vZmZzKTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfQogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHZhciBpLCBsLCBsZW4sIHBvcywgY2h1bmssIHJlc3VsdDsKICAgICAgICAgIGxlbiA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBsZW4gKz0gY2h1bmtzW2ldLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJlc3VsdCA9IG5ldyBVaW50OEFycmF5KGxlbik7CiAgICAgICAgICBwb3MgPSAwOwogICAgICAgICAgZm9yIChpID0gMCwgbCA9IGNodW5rcy5sZW5ndGg7IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgY2h1bmsgPSBjaHVua3NbaV07CiAgICAgICAgICAgIHJlc3VsdC5zZXQoY2h1bmssIHBvcyk7CiAgICAgICAgICAgIHBvcyArPSBjaHVuay5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gcmVzdWx0OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGZuVW50eXBlZCA9IHsKICAgICAgICBhcnJheVNldDogZnVuY3Rpb24oZGVzdCwgc3JjLCBzcmNfb2ZmcywgbGVuLCBkZXN0X29mZnMpIHsKICAgICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgICAgZGVzdFtkZXN0X29mZnMgKyBpXSA9IHNyY1tzcmNfb2ZmcyArIGldOwogICAgICAgICAgfQogICAgICAgIH0sCiAgICAgICAgZmxhdHRlbkNodW5rczogZnVuY3Rpb24oY2h1bmtzKSB7CiAgICAgICAgICByZXR1cm4gW10uY29uY2F0LmFwcGx5KFtdLCBjaHVua3MpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgZXhwb3J0czIuc2V0VHlwZWQgPSBmdW5jdGlvbihvbikgewogICAgICAgIGlmIChvbikgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IFVpbnQ4QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IFVpbnQxNkFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBJbnQzMkFycmF5OwogICAgICAgICAgZXhwb3J0czIuYXNzaWduKGV4cG9ydHMyLCBmblR5cGVkKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgZXhwb3J0czIuQnVmOCA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMTYgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjMyID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVW50eXBlZCk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZChUWVBFRF9PSyk7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi90cmVlcy5qcwogIHZhciByZXF1aXJlX3RyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3RyZWVzLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIFpfRklYRUQgPSA0OwogICAgICB2YXIgWl9CSU5BUlkgPSAwOwogICAgICB2YXIgWl9URVhUID0gMTsKICAgICAgdmFyIFpfVU5LTk9XTiA9IDI7CiAgICAgIGZ1bmN0aW9uIHplcm8oYnVmKSB7CiAgICAgICAgdmFyIGxlbiA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgd2hpbGUgKC0tbGVuID49IDApIHsKICAgICAgICAgIGJ1ZltsZW5dID0gMDsKICAgICAgICB9CiAgICAgIH0KICAgICAgdmFyIFNUT1JFRF9CTE9DSyA9IDA7CiAgICAgIHZhciBTVEFUSUNfVFJFRVMgPSAxOwogICAgICB2YXIgRFlOX1RSRUV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KICAgICAgICB2YXIgaGFzX3N0cmVlID0gZGVzYy5zdGF0X2Rlc2MuaGFzX3N0cmVlOwogICAgICAgIHZhciBleHRyYSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2JpdHM7CiAgICAgICAgdmFyIGJhc2UgPSBkZXNjLnN0YXRfZGVzYy5leHRyYV9iYXNlOwogICAgICAgIHZhciBtYXhfbGVuZ3RoID0gZGVzYy5zdGF0X2Rlc2MubWF4X2xlbmd0aDsKICAgICAgICB2YXIgaDsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgeGJpdHM7CiAgICAgICAgdmFyIGY7CiAgICAgICAgdmFyIG92ZXJmbG93ID0gMDsKICAgICAgICBmb3IgKGJpdHMgPSAwOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIHMuYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICB0cmVlW3MuaGVhcFtzLmhlYXBfbWF4XSAqIDIgKyAxXSA9IDA7CiAgICAgICAgZm9yIChoID0gcy5oZWFwX21heCArIDE7IGggPCBIRUFQX1NJWkU7IGgrKykgewogICAgICAgICAgbiA9IHMuaGVhcFtoXTsKICAgICAgICAgIGJpdHMgPSB0cmVlW3RyZWVbbiAqIDIgKyAxXSAqIDIgKyAxXSArIDE7CiAgICAgICAgICBpZiAoYml0cyA+IG1heF9sZW5ndGgpIHsKICAgICAgICAgICAgYml0cyA9IG1heF9sZW5ndGg7CiAgICAgICAgICAgIG92ZXJmbG93Kys7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgaWYgKG4gPiBtYXhfY29kZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHMuYmxfY291bnRbYml0c10rKzsKICAgICAgICAgIHhiaXRzID0gMDsKICAgICAgICAgIGlmIChuID49IGJhc2UpIHsKICAgICAgICAgICAgeGJpdHMgPSBleHRyYVtuIC0gYmFzZV07CiAgICAgICAgICB9CiAgICAgICAgICBmID0gdHJlZVtuICogMl07CiAgICAgICAgICBzLm9wdF9sZW4gKz0gZiAqIChiaXRzICsgeGJpdHMpOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gKz0gZiAqIChzdHJlZVtuICogMiArIDFdICsgeGJpdHMpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3ZlcmZsb3cgPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgYml0cyA9IG1heF9sZW5ndGggLSAxOwogICAgICAgICAgd2hpbGUgKHMuYmxfY291bnRbYml0c10gPT09IDApIHsKICAgICAgICAgICAgYml0cy0tOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXS0tOwogICAgICAgICAgcy5ibF9jb3VudFtiaXRzICsgMV0gKz0gMjsKICAgICAgICAgIHMuYmxfY291bnRbbWF4X2xlbmd0aF0tLTsKICAgICAgICAgIG92ZXJmbG93IC09IDI7CiAgICAgICAgfSB3aGlsZSAob3ZlcmZsb3cgPiAwKTsKICAgICAgICBmb3IgKGJpdHMgPSBtYXhfbGVuZ3RoOyBiaXRzICE9PSAwOyBiaXRzLS0pIHsKICAgICAgICAgIG4gPSBzLmJsX2NvdW50W2JpdHNdOwogICAgICAgICAgd2hpbGUgKG4gIT09IDApIHsKICAgICAgICAgICAgbSA9IHMuaGVhcFstLWhdOwogICAgICAgICAgICBpZiAobSA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHRyZWVbbSAqIDIgKyAxXSAhPT0gYml0cykgewogICAgICAgICAgICAgIHMub3B0X2xlbiArPSAoYml0cyAtIHRyZWVbbSAqIDIgKyAxXSkgKiB0cmVlW20gKiAyXTsKICAgICAgICAgICAgICB0cmVlW20gKiAyICsgMV0gPSBiaXRzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG4tLTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZ2VuX2NvZGVzKHRyZWUsIG1heF9jb2RlLCBibF9jb3VudCkgewogICAgICAgIHZhciBuZXh0X2NvZGUgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICB2YXIgY29kZSA9IDA7CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChiaXRzID0gMTsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBuZXh0X2NvZGVbYml0c10gPSBjb2RlID0gY29kZSArIGJsX2NvdW50W2JpdHMgLSAxXSA8PCAxOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIHZhciBsZW4gPSB0cmVlW24gKiAyICsgMV07CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgdHJlZVtuICogMl0gPSBiaV9yZXZlcnNlKG5leHRfY29kZVtsZW5dKyssIGxlbik7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyX3N0YXRpY19pbml0KCkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsZW5ndGg7CiAgICAgICAgdmFyIGNvZGU7CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGJsX2NvdW50ID0gbmV3IEFycmF5KE1BWF9CSVRTICsgMSk7CiAgICAgICAgbGVuZ3RoID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgTEVOR1RIX0NPREVTIC0gMTsgY29kZSsrKSB7CiAgICAgICAgICBiYXNlX2xlbmd0aFtjb2RlXSA9IGxlbmd0aDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2xiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIF9sZW5ndGhfY29kZVtsZW5ndGggLSAxXSA9IGNvZGU7CiAgICAgICAgZGlzdCA9IDA7CiAgICAgICAgZm9yIChjb2RlID0gMDsgY29kZSA8IDE2OyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3Q7CiAgICAgICAgICBmb3IgKG4gPSAwOyBuIDwgMSA8PCBleHRyYV9kYml0c1tjb2RlXTsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGRpc3QgPj49IDc7CiAgICAgICAgZm9yICg7IGNvZGUgPCBEX0NPREVTOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfZGlzdFtjb2RlXSA9IGRpc3QgPDwgNzsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdIC0gNzsgbisrKSB7CiAgICAgICAgICAgIF9kaXN0X2NvZGVbMjU2ICsgZGlzdCsrXSA9IGNvZGU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgYmxfY291bnRbYml0c10gPSAwOwogICAgICAgIH0KICAgICAgICBuID0gMDsKICAgICAgICB3aGlsZSAobiA8PSAxNDMpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI1NSkgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA5OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOV0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjc5KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDc7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs3XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyODcpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gODsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzhdKys7CiAgICAgICAgfQogICAgICAgIGdlbl9jb2RlcyhzdGF0aWNfbHRyZWUsIExfQ09ERVMgKyAxLCBibF9jb3VudCk7CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyICsgMV0gPSA1OwogICAgICAgICAgc3RhdGljX2R0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobiwgNSk7CiAgICAgICAgfQogICAgICAgIHN0YXRpY19sX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2Moc3RhdGljX2x0cmVlLCBleHRyYV9sYml0cywgTElURVJBTFMgKyAxLCBMX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2RfZGVzYyA9IG5ldyBTdGF0aWNUcmVlRGVzYyhzdGF0aWNfZHRyZWUsIGV4dHJhX2RiaXRzLCAwLCBEX0NPREVTLCBNQVhfQklUUyk7CiAgICAgICAgc3RhdGljX2JsX2Rlc2MgPSBuZXcgU3RhdGljVHJlZURlc2MobmV3IEFycmF5KDApLCBleHRyYV9ibGJpdHMsIDAsIEJMX0NPREVTLCBNQVhfQkxfQklUUyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5pdF9ibG9jayhzKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8IExfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fbHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IERfQ09ERVM7IG4rKykgewogICAgICAgICAgcy5keW5fZHRyZWVbbiAqIDJdID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8IEJMX0NPREVTOyBuKyspIHsKICAgICAgICAgIHMuYmxfdHJlZVtuICogMl0gPSAwOwogICAgICAgIH0KICAgICAgICBzLmR5bl9sdHJlZVtFTkRfQkxPQ0sgKiAyXSA9IDE7CiAgICAgICAgcy5vcHRfbGVuID0gcy5zdGF0aWNfbGVuID0gMDsKICAgICAgICBzLmxhc3RfbGl0ID0gcy5tYXRjaGVzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBiaV93aW5kdXAocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID4gOCkgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICB9IGVsc2UgaWYgKHMuYmlfdmFsaWQgPiAwKSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmOwogICAgICAgIH0KICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gY29weV9ibG9jayhzLCBidWYsIGxlbiwgaGVhZGVyKSB7CiAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIGlmIChoZWFkZXIpIHsKICAgICAgICAgIHB1dF9zaG9ydChzLCBsZW4pOwogICAgICAgICAgcHV0X3Nob3J0KHMsIH5sZW4pOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzLnBlbmRpbmdfYnVmLCBzLndpbmRvdywgYnVmLCBsZW4sIHMucGVuZGluZyk7CiAgICAgICAgcy5wZW5kaW5nICs9IGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBzbWFsbGVyKHRyZWUsIG4sIG0sIGRlcHRoKSB7CiAgICAgICAgdmFyIF9uMiA9IG4gKiAyOwogICAgICAgIHZhciBfbTIgPSBtICogMjsKICAgICAgICByZXR1cm4gdHJlZVtfbjJdIDwgdHJlZVtfbTJdIHx8IHRyZWVbX24yXSA9PT0gdHJlZVtfbTJdICYmIGRlcHRoW25dIDw9IGRlcHRoW21dOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHBxZG93bmhlYXAocywgdHJlZSwgaykgewogICAgICAgIHZhciB2ID0gcy5oZWFwW2tdOwogICAgICAgIHZhciBqID0gayA8PCAxOwogICAgICAgIHdoaWxlIChqIDw9IHMuaGVhcF9sZW4pIHsKICAgICAgICAgIGlmIChqIDwgcy5oZWFwX2xlbiAmJiBzbWFsbGVyKHRyZWUsIHMuaGVhcFtqICsgMV0sIHMuaGVhcFtqXSwgcy5kZXB0aCkpIHsKICAgICAgICAgICAgaisrOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHNtYWxsZXIodHJlZSwgdiwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIHMuaGVhcFtrXSA9IHMuaGVhcFtqXTsKICAgICAgICAgIGsgPSBqOwogICAgICAgICAgaiA8PD0gMTsKICAgICAgICB9CiAgICAgICAgcy5oZWFwW2tdID0gdjsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb21wcmVzc19ibG9jayhzLCBsdHJlZSwgZHRyZWUpIHsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgbGM7CiAgICAgICAgdmFyIGx4ID0gMDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZXh0cmE7CiAgICAgICAgaWYgKHMubGFzdF9saXQgIT09IDApIHsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZGlzdCA9IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMl0gPDwgOCB8IHMucGVuZGluZ19idWZbcy5kX2J1ZiArIGx4ICogMiArIDFdOwogICAgICAgICAgICBsYyA9IHMucGVuZGluZ19idWZbcy5sX2J1ZiArIGx4XTsKICAgICAgICAgICAgbHgrKzsKICAgICAgICAgICAgaWYgKGRpc3QgPT09IDApIHsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgbGMsIGx0cmVlKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBjb2RlID0gX2xlbmd0aF9jb2RlW2xjXTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSArIExJVEVSQUxTICsgMSwgbHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfbGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBsYyAtPSBiYXNlX2xlbmd0aFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBsYywgZXh0cmEpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBkaXN0LS07CiAgICAgICAgICAgICAgY29kZSA9IGRfY29kZShkaXN0KTsKICAgICAgICAgICAgICBzZW5kX2NvZGUocywgY29kZSwgZHRyZWUpOwogICAgICAgICAgICAgIGV4dHJhID0gZXh0cmFfZGJpdHNbY29kZV07CiAgICAgICAgICAgICAgaWYgKGV4dHJhICE9PSAwKSB7CiAgICAgICAgICAgICAgICBkaXN0IC09IGJhc2VfZGlzdFtjb2RlXTsKICAgICAgICAgICAgICAgIHNlbmRfYml0cyhzLCBkaXN0LCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IHdoaWxlIChseCA8IHMubGFzdF9saXQpOwogICAgICAgIH0KICAgICAgICBzZW5kX2NvZGUocywgRU5EX0JMT0NLLCBsdHJlZSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfdHJlZShzLCBkZXNjKSB7CiAgICAgICAgdmFyIHRyZWUgPSBkZXNjLmR5bl90cmVlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGVsZW1zID0gZGVzYy5zdGF0X2Rlc2MuZWxlbXM7CiAgICAgICAgdmFyIG4sIG07CiAgICAgICAgdmFyIG1heF9jb2RlID0gLTE7CiAgICAgICAgdmFyIG5vZGU7CiAgICAgICAgcy5oZWFwX2xlbiA9IDA7CiAgICAgICAgcy5oZWFwX21heCA9IEhFQVBfU0laRTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgZWxlbXM7IG4rKykgewogICAgICAgICAgaWYgKHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPSBuOwogICAgICAgICAgICBzLmRlcHRoW25dID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHdoaWxlIChzLmhlYXBfbGVuIDwgMikgewogICAgICAgICAgbm9kZSA9IHMuaGVhcFsrK3MuaGVhcF9sZW5dID0gbWF4X2NvZGUgPCAyID8gKyttYXhfY29kZSA6IDA7CiAgICAgICAgICB0cmVlW25vZGUgKiAyXSA9IDE7CiAgICAgICAgICBzLmRlcHRoW25vZGVdID0gMDsKICAgICAgICAgIHMub3B0X2xlbi0tOwogICAgICAgICAgaWYgKGhhc19zdHJlZSkgewogICAgICAgICAgICBzLnN0YXRpY19sZW4gLT0gc3RyZWVbbm9kZSAqIDIgKyAxXTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGVzYy5tYXhfY29kZSA9IG1heF9jb2RlOwogICAgICAgIGZvciAobiA9IHMuaGVhcF9sZW4gPj4gMTsgbiA+PSAxOyBuLS0pIHsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgbik7CiAgICAgICAgfQogICAgICAgIG5vZGUgPSBlbGVtczsKICAgICAgICBkbyB7CiAgICAgICAgICBuID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWzFdID0gcy5oZWFwW3MuaGVhcF9sZW4tLV07CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgICAgbSA9IHMuaGVhcFsxXTsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbjsKICAgICAgICAgIHMuaGVhcFstLXMuaGVhcF9tYXhdID0gbTsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gdHJlZVtuICogMl0gKyB0cmVlW20gKiAyXTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAocy5kZXB0aFtuXSA+PSBzLmRlcHRoW21dID8gcy5kZXB0aFtuXSA6IHMuZGVwdGhbbV0pICsgMTsKICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IHRyZWVbbSAqIDIgKyAxXSA9IG5vZGU7CiAgICAgICAgICBzLmhlYXBbMV0gPSBub2RlKys7CiAgICAgICAgICBwcWRvd25oZWFwKHMsIHRyZWUsIDEpOwogICAgICAgIH0gd2hpbGUgKHMuaGVhcF9sZW4gPj0gMik7CiAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBzLmhlYXBbMV07CiAgICAgICAgZ2VuX2JpdGxlbihzLCBkZXNjKTsKICAgICAgICBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIHMuYmxfY291bnQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNjYW5fdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICB0cmVlWyhtYXhfY29kZSArIDEpICogMiArIDFdID0gNjU1MzU7CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdICs9IGNvdW50OwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHMuYmxfdHJlZVtjdXJsZW4gKiAyXSsrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBfM182ICogMl0rKzsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgcy5ibF90cmVlW1JFUFpfM18xMCAqIDJdKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8xMV8xMzggKiAyXSsrOwogICAgICAgICAgfQogICAgICAgICAgY291bnQgPSAwOwogICAgICAgICAgcHJldmxlbiA9IGN1cmxlbjsKICAgICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDY7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtYXhfY291bnQgPSA3OwogICAgICAgICAgICBtaW5fY291bnQgPSA0OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBzZW5kX3RyZWUocywgdHJlZSwgbWF4X2NvZGUpIHsKICAgICAgICB2YXIgbjsKICAgICAgICB2YXIgcHJldmxlbiA9IC0xOwogICAgICAgIHZhciBjdXJsZW47CiAgICAgICAgdmFyIG5leHRsZW4gPSB0cmVlWzAgKiAyICsgMV07CiAgICAgICAgdmFyIGNvdW50ID0gMDsKICAgICAgICB2YXIgbWF4X2NvdW50ID0gNzsKICAgICAgICB2YXIgbWluX2NvdW50ID0gNDsKICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICB9CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSBtYXhfY29kZTsgbisrKSB7CiAgICAgICAgICBjdXJsZW4gPSBuZXh0bGVuOwogICAgICAgICAgbmV4dGxlbiA9IHRyZWVbKG4gKyAxKSAqIDIgKyAxXTsKICAgICAgICAgIGlmICgrK2NvdW50IDwgbWF4X2NvdW50ICYmIGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPCBtaW5fY291bnQpIHsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIH0gd2hpbGUgKC0tY291bnQgIT09IDApOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gIT09IDApIHsKICAgICAgICAgICAgaWYgKGN1cmxlbiAhPT0gcHJldmxlbikgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjdXJsZW4sIHMuYmxfdHJlZSk7CiAgICAgICAgICAgICAgY291bnQtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQXzNfNiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMik7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvdW50IDw9IDEwKSB7CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBaXzNfMTAsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDMsIDMpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfMTFfMTM4LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAxMSwgNyk7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJ1aWxkX2JsX3RyZWUocykgewogICAgICAgIHZhciBtYXhfYmxpbmRleDsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fbHRyZWUsIHMubF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBzY2FuX3RyZWUocywgcy5keW5fZHRyZWUsIHMuZF9kZXNjLm1heF9jb2RlKTsKICAgICAgICBidWlsZF90cmVlKHMsIHMuYmxfZGVzYyk7CiAgICAgICAgZm9yIChtYXhfYmxpbmRleCA9IEJMX0NPREVTIC0gMTsgbWF4X2JsaW5kZXggPj0gMzsgbWF4X2JsaW5kZXgtLSkgewogICAgICAgICAgaWYgKHMuYmxfdHJlZVtibF9vcmRlclttYXhfYmxpbmRleF0gKiAyICsgMV0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMub3B0X2xlbiArPSAzICogKG1heF9ibGluZGV4ICsgMSkgKyA1ICsgNSArIDQ7CiAgICAgICAgcmV0dXJuIG1heF9ibGluZGV4OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfYWxsX3RyZWVzKHMsIGxjb2RlcywgZGNvZGVzLCBibGNvZGVzKSB7CiAgICAgICAgdmFyIHJhbms7CiAgICAgICAgc2VuZF9iaXRzKHMsIGxjb2RlcyAtIDI1NywgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGRjb2RlcyAtIDEsIDUpOwogICAgICAgIHNlbmRfYml0cyhzLCBibGNvZGVzIC0gNCwgNCk7CiAgICAgICAgZm9yIChyYW5rID0gMDsgcmFuayA8IGJsY29kZXM7IHJhbmsrKykgewogICAgICAgICAgc2VuZF9iaXRzKHMsIHMuYmxfdHJlZVtibF9vcmRlcltyYW5rXSAqIDIgKyAxXSwgMyk7CiAgICAgICAgfQogICAgICAgIHNlbmRfdHJlZShzLCBzLmR5bl9sdHJlZSwgbGNvZGVzIC0gMSk7CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2R0cmVlLCBkY29kZXMgLSAxKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZXRlY3RfZGF0YV90eXBlKHMpIHsKICAgICAgICB2YXIgYmxhY2tfbWFzayA9IDQwOTM2MjQ0NDc7CiAgICAgICAgdmFyIG47CiAgICAgICAgZm9yIChuID0gMDsgbiA8PSAzMTsgbisrLCBibGFja19tYXNrID4+Pj0gMSkgewogICAgICAgICAgaWYgKGJsYWNrX21hc2sgJiAxICYmIHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLmR5bl9sdHJlZVs5ICogMl0gIT09IDAgfHwgcy5keW5fbHRyZWVbMTAgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMyAqIDJdICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAzMjsgbiA8IExJVEVSQUxTOyBuKyspIHsKICAgICAgICAgIGlmIChzLmR5bl9sdHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIFpfVEVYVDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIFpfQklOQVJZOwogICAgICB9CiAgICAgIHZhciBzdGF0aWNfaW5pdF9kb25lID0gZmFsc2U7CiAgICAgIGZ1bmN0aW9uIF90cl9pbml0KHMpIHsKICAgICAgICBpZiAoIXN0YXRpY19pbml0X2RvbmUpIHsKICAgICAgICAgIHRyX3N0YXRpY19pbml0KCk7CiAgICAgICAgICBzdGF0aWNfaW5pdF9kb25lID0gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcy5sX2Rlc2MgPSBuZXcgVHJlZURlc2Mocy5keW5fbHRyZWUsIHN0YXRpY19sX2Rlc2MpOwogICAgICAgIHMuZF9kZX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kX2Rlc2MpOwogICAgICAgICAgbWF4X2JsaW5kZXggPSBidWlsZF9ibF90cmVlKHMpOwogICAgICAgICAgb3B0X2xlbmIgPSBzLm9wdF9sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIHN0YXRpY19sZW5iID0gcy5zdGF0aWNfbGVuICsgMyArIDcgPj4+IDM7CiAgICAgICAgICBpZiAoc3RhdGljX2xlbmIgPD0gb3B0X2xlbmIpIHsKICAgICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgb3B0X2xlbmIgPSBzdGF0aWNfbGVuYiA9IHN0b3JlZF9sZW4gKyA1OwogICAgICAgIH0KICAgICAgICBpZiAoc3RvcmVkX2xlbiArIDQgPD0gb3B0X2xlbmIgJiYgYnVmICE9PSAtMSkgewogICAgICAgICAgX3RyX3N0b3JlZF9ibG9jayhzLCBidWYsIHN0b3JlZF9sZW4sIGxhc3QpOwogICAgICAgIH0gZWxzZSBpZiAocy5zdHJhdGVneSA9PT0gWl9GSVhFRCB8fCBzdGF0aWNfbGVuYiA9PT0gb3B0X2xlbmIpIHsKICAgICAgICAgIHNlbmRfYml0cyhzLCAoU1RBVElDX1RSRUVTIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgc3RhdGljX2x0cmVlLCBzdGF0aWNfZHRyZWUpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgKERZTl9UUkVFUyA8PCAxKSArIChsYXN0ID8gMSA6IDApLCAzKTsKICAgICAgICAgIHNlbmRfYWxsX3RyZWVzKHMsIHMubF9kZXNjLm1heF9jb2RlICsgMSwgcy5kX2Rlc2MubWF4X2NvZGUgKyAxLCBtYXhfYmxpbmRleCArIDEpOwogICAgICAgICAgY29tcHJlc3NfYmxvY2socywgcy5keW5fbHRyZWUsIHMuZHluX2R0cmVlKTsKICAgICAgICB9CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgICBpZiAobGFzdCkgewogICAgICAgICAgYmlfd2luZHVwKHMpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfdGFsbHkocywgZGlzdCwgbGMpIHsKICAgICAgICBzLnBlbmRpbmdfYnVmW3MuZF9idWYgKyBzLmxhc3RfbGl0ICogMl0gPSBkaXN0ID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5kX2J1ZiArIHMubGFzdF9saXQgKiAyICsgMV0gPSBkaXN0ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5sX2J1ZiArIHMubGFzdF9saXRdID0gbGMgJiAyNTU7CiAgICAgICAgcy5sYXN0X2xpdCsrOwogICAgICAgIGlmIChkaXN0ID09PSAwKSB7CiAgICAgICAgICBzLmR5bl9sdHJlZVtsYyAqIDJdKys7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHMubWF0Y2hlcysrOwogICAgICAgICAgZGlzdC0tOwogICAgICAgICAgcy5keW5fbHRyZWVbKF9sZW5ndGhfY29kZVtsY10gKyBMSVRFUkFMUyArIDEpICogMl0rKzsKICAgICAgICAgIHMuZHluX2R0cmVlW2RfY29kZShkaXN0KSAqIDJdKys7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzLmxhc3RfbGl0ID09PSBzLmxpdF9idWZzaXplIC0gMTsKICAgICAgfQogICAgICBleHBvcnRzMi5fdHJfaW5pdCA9IF90cl9pbml0OwogICAgICBleHBvcnRzMi5fdHJfc3RvcmVkX2Jsb2NrID0gX3RyX3N0b3JlZF9ibG9jazsKICAgICAgZXhwb3J0czIuX3RyX2ZsdXNoX2Jsb2NrID0gX3RyX2ZsdXNoX2Jsb2NrOwogICAgICBleHBvcnRzMi5fdHJfdGFsbHkgPSBfdHJfdGFsbHk7CiAgICAgIGV4cG9ydHMyLl90cl9hbGlnbiA9IF90cl9hbGlnbjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2FkbGVyMzIuanMKICB2YXIgcmVxdWlyZV9hZGxlcjMyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2FkbGVyMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBhZGxlcjMyKGFkbGVyLCBidWYsIGxlbiwgcG9zKSB7CiAgICAgICAgdmFyIHMxID0gYWRsZXIgJiA2NTUzNSB8IDAsIHMyID0gYWRsZXIgPj4+IDE2ICYgNjU1MzUgfCAwLCBuID0gMDsKICAgICAgICB3aGlsZSAobGVuICE9PSAwKSB7CiAgICAgICAgICBuID0gbGVuID4gMmUzID8gMmUzIDogbGVuOwogICAgICAgICAgbGVuIC09IG47CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMxID0gczEgKyBidWZbcG9zKytdIHwgMDsKICAgICAgICAgICAgczIgPSBzMiArIHMxIHwgMDsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzMSAlPSA2NTUyMTsKICAgICAgICAgIHMyICU9IDY1NTIxOwogICAgICAgIH0KICAgICAgICByZXR1cm4gczEgfCBzMiA8PCAxNiB8IDA7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gYWRsZXIzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2NyYzMyLmpzCiAgdmFyIHJlcXVpcmVfY3JjMzIgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBmdW5jdGlvbiBtYWtlVGFibGUoKSB7CiAgICAgICAgdmFyIGMsIHRhYmxlID0gW107CiAgICAgICAgZm9yICh2YXIgbiA9IDA7IG4gPCAyNTY7IG4rKykgewogICAgICAgICAgYyA9IG47CiAgICAgICAgICBmb3IgKHZhciBrID0gMDsgayA8IDg7IGsrKykgewogICAgICAgICAgICBjID0gYyAmIDEgPyAzOTg4MjkyMzg0IF4gYyA+Pj4gMSA6IGMgPj4+IDE7CiAgICAgICAgICB9CiAgICAgICAgICB0YWJsZVtuXSA9IGM7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0YWJsZTsKICAgICAgfQogICAgICB2YXIgY3JjVGFibGUgPSBtYWtlVGFibGUoKTsKICAgICAgZnVuY3Rpb24gY3JjMzIoY3JjLCBidWYsIGxlbiwgcG9zKSB7CiAgICAgICAgdmFyIHQgPSBjcmNUYWJsZSwgZW5kID0gcG9zICsgbGVuOwogICAgICAgIGNyYyBePSAtMTsKICAgICAgICBmb3IgKHZhciBpID0gcG9zOyBpIDwgZW5kOyBpKyspIHsKICAgICAgICAgIGNyYyA9IGNyYyA+Pj4gOCBeIHRbKGNyYyBeIGJ1ZltpXSkgJiAyNTVdOwogICAgICAgIH0KICAgICAgICByZXR1cm4gY3JjIF4gLTE7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gY3JjMzI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9tZXNzYWdlcy5qcwogIHZhciByZXF1aXJlX21lc3NhZ2VzID0gX19jb21tb25KUyh7CiAgICAibm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W4gPSBzLnBlbmRpbmc7CiAgICAgICAgaWYgKGxlbiA+IHN0cm0uYXZhaWxfb3V0KSB7CiAgICAgICAgICBsZW4gPSBzdHJtLmF2YWlsX291dDsKICAgICAgICB9CiAgICAgICAgaWYgKGxlbiA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICB1dGlscy5hcnJheVNldChzdHJtLm91dHB1dCwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nX291dCwgbGVuLCBzdHJtLm5leHRfb3V0KTsKICAgICAgICBzdHJtLm5leHRfb3V0ICs9IGxlbjsKICAgICAgICBzLnBlbmRpbmdfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX291dCArPSBsZW47CiAgICAgICAgc3RybS5hdmFpbF9vdXQgLT0gbGVuOwogICAgICAgIHMucGVuZGluZyAtPSBsZW47CiAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gMCkgewogICAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZsdXNoX2Jsb2NrX29ubHkocywgbGFzdCkgewogICAgICAgIHRyZWVzLl90cl9mbHVzaF9ibG9jayhzLCBzLmJsb2NrX3N0YXJ0ID49IDAgPyBzLmJsb2NrX3N0YXJ0IDogLTEsIHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0LCBsYXN0KTsKICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gcy5zdHJzdGFydDsKICAgICAgICBmbHVzaF9wZW5kaW5nKHMuc3RybSk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHV0X2J5dGUocywgYikgewogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYjsKICAgICAgfQogICAgICBmdW5jdGlvbiBwdXRTaG9ydE1TQihzLCBiKSB7CiAgICAgICAgcy5wZW5kaW5nX2J1ZltzLnBlbmRpbmcrK10gPSBiID4+PiA4ICYgMjU1OwogICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gYiAmIDI1NTsKICAgICAgfQogICAgICBmdW5jdGlvbiByZWFkX2J1ZihzdHJtLCBidWYsIHN0YXJ0LCBzaXplKSB7CiAgICAgICAgdmFyIGxlbiA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgaWYgKGxlbiA+IHNpemUpIHsKICAgICAgICAgIGxlbiA9IHNpemU7CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIH0KICAgICAgICBzdHJtLmF2YWlsX2luIC09IGxlbjsKICAgICAgICB1dGlscy5hcnJheVNldChidWYsIHN0cm0uaW5wdXQsIHN0cm0ubmV4dF9pbiwgbGVuLCBzdGFydCk7CiAgICAgICAgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMSkgewogICAgICAgICAgc3RybS5hZGxlciA9IGFkbGVyMzIoc3RybS5hZGxlciwgYnVmLCBsZW4sIHN0YXJ0KTsKICAgICAgICB9IGVsc2UgaWYgKHN0cm0uc3RhdGUud3JhcCA9PT0gMikgewogICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIGJ1ZiwgbGVuLCBzdGFydCk7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiArPSBsZW47CiAgICAgICAgc3RybS50b3RhbF9pbiArPSBsZW47CiAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgfQogICAgICBmdW5jdGlvbiBsb25nZXN0X21hdGNoKHMsIGN1cl9tYXRjaCkgewogICAgICAgIHZhciBjaGFpbl9sZW5ndGggPSBzLm1heF9jaGFpbl9sZW5ndGg7CiAgICAgICAgdmFyIHNjYW4gPSBzLnN0cnN0YXJ0OwogICAgICAgIHZhciBtYXRjaDsKICAgICAgICB2YXIgbGVuOwogICAgICAgIHZhciBiZXN0X2xlbiA9IHMucHJldl9sZW5ndGg7CiAgICAgICAgdmFyIG5pY2VfbWF0Y2ggPSBzLm5pY2VfbWF0Y2g7CiAgICAgICAgdmFyIGxpbWl0ID0gcy5zdHJzdGFydCA+IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCA/IHMuc3Ryc3RhcnQgLSAocy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSA6IDA7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICB2YXIgd21hc2sgPSBzLndfbWFzazsKICAgICAgICB2YXIgcHJldiA9IHMucHJldjsKICAgICAgICB2YXIgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICB2YXIgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICB2YXIgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgaWYgKHMucHJldl9sZW5ndGggPj0gcy5nb29kX21hdGNoKSB7CiAgICAgICAgICBjaGFpbl9sZW5ndGggPj49IDI7CiAgICAgICAgfQogICAgICAgIGlmIChuaWNlX21hdGNoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIG5pY2VfbWF0Y2ggPSBzLmxvb2thaGVhZDsKICAgICAgICB9CiAgICAgICAgZG8gewogICAgICAgICAgbWF0Y2ggPSBjdXJfbWF0Y2g7CiAgICAgICAgICBpZiAoX3dpblttYXRjaCArIGJlc3RfbGVuXSAhPT0gc2Nhbl9lbmQgfHwgX3dpblttYXRjaCArIGJlc3RfbGVuIC0gMV0gIT09IHNjYW5fZW5kMSB8fCBfd2luW21hdGNoXSAhPT0gX3dpbltzY2FuXSB8fCBfd2luWysrbWF0Y2hdICE9PSBfd2luW3NjYW4gKyAxXSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIHNjYW4gKz0gMjsKICAgICAgICAgIG1hdGNoKys7CiAgICAgICAgICBkbyB7CiAgICAgICAgICB9IHdoaWxlIChfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIHNjYW4gPCBzdHJlbmQpOwogICAgICAgICAgbGVuID0gTUFYX01BVENIIC0gKHN0cmVuZCAtIHNjYW4pOwogICAgICAgICAgc2NhbiA9IHN0cmVuZCAtIE1BWF9NQVRDSDsKICAgICAgICAgIGlmIChsZW4gPiBiZXN0X2xlbikgewogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0ID0gY3VyX21hdGNoOwogICAgICAgICAgICBiZXN0X2xlbiA9IGxlbjsKICAgICAgICAgICAgaWYgKGxlbiA+PSBuaWNlX21hdGNoKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgc2Nhbl9lbmQxID0gX3dpbltzY2FuICsgYmVzdF9sZW4gLSAxXTsKICAgICAgICAgICAgc2Nhbl9lbmQgPSBfd2luW3NjYW4gKyBiZXN0X2xlbl07CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKGN1cl9tYXRjaCA9IHByZXZbY3VyX21hdGNoICYgd21hc2tdKSA+IGxpbWl0ICYmIC0tY2hhaW5fbGVuZ3RoICE9PSAwKTsKICAgICAgICBpZiAoYmVzdF9sZW4gPD0gcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBiZXN0X2xlbjsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMubG9va2FoZWFkOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZpbGxfd2luZG93KHMpIHsKICAgICAgICB2YXIgX3dfc2l6ZSA9IHMud19zaXplOwogICAgICAgIHZhciBwLCBuLCBtLCBtb3JlLCBzdHI7CiAgICAgICAgZG8gewogICAgICAgICAgbW9yZSA9IHMud2luZG93X3NpemUgLSBzLmxvb2thaGVhZCAtIHMuc3Ryc3RhcnQ7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA+PSBfd19zaXplICsgKF93X3NpemUgLSBNSU5fTE9PS0FIRUFEKSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzLndpbmRvdywgcy53aW5kb3csIF93X3NpemUsIF93X3NpemUsIDApOwogICAgICAgICAgICBzLm1hdGNoX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBuID0gcy5oYXNoX3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMuaGVhZFstLXBdOwogICAgICAgICAgICAgIHMuaGVhZFtwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbiA9IF93X3NpemU7CiAgICAgICAgICAgIHAgPSBuOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgbSA9IHMucHJldlstLXBdOwogICAgICAgICAgICAgIHMucHJldltwXSA9IG0gPj0gX3dfc2l6ZSA/IG0gLSBfd19zaXplIDogMDsKICAgICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgICAgbW9yZSArPSBfd19zaXplOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9pbiA9PT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIG4gPSByZWFkX2J1ZihzLnN0cm0sIHMud2luZG93LCBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQsIG1vcmUpOwogICAgICAgICAgcy5sb29rYWhlYWQgKz0gbjsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0ID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0IC0gcy5pbnNlcnQ7CiAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzdHJdOwogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHdoaWxlIChzLmluc2VydCkgewogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICBzLnByZXZbc3RyICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgICBzdHIrKzsKICAgICAgICAgICAgICBzLmluc2VydC0tOwogICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCArIHMuaW5zZXJ0IDwgTUlOX01BVENIKSB7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgcy5zdHJtLmF2YWlsX2luICE9PSAwKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3N0b3JlZChzLCBmbHVzaCkgewogICAgICAgIHZhciBtYXhfYmxvY2tfc2l6ZSA9IDY1NTM1OwogICAgICAgIGlmIChtYXhfYmxvY2tfc2l6ZSA+IHMucGVuZGluZ19idWZfc2l6ZSAtIDUpIHsKICAgICAgICAgIG1heF9ibG9ja19zaXplID0gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNTsKICAgICAgICB9CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPD0gMSkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5zdHJzdGFydCArPSBzLmxvb2thaGVhZDsKICAgICAgICAgIHMubG9va2FoZWFkID0gMDsKICAgICAgICAgIHZhciBtYXhfc3RhcnQgPSBzLmJsb2NrX3N0YXJ0ICsgbWF4X2Jsb2NrX3NpemU7CiAgICAgICAgICBpZiAocy5zdHJzdGFydCA9PT0gMCB8fCBzLnN0cnN0YXJ0ID49IG1heF9zdGFydCkgewogICAgICAgICAgICBzLmxvb2thaGVhZCA9IHMuc3Ryc3RhcnQgLSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSBtYXhfc3RhcnQ7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnN0cnN0YXJ0IC0gcy5ibG9ja19zdGFydCA+PSBzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMuc3Ryc3RhcnQgPiBzLmJsb2NrX3N0YXJ0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9mYXN0KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAg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xlbmd0aC0tOwogICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfSB3aGlsZSAoLS1zLm1hdGNoX2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgICAgIHMuaW5zX2ggPSBzLndpbmRvd1tzLnN0cnN0YXJ0XTsKICAgICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSBzLnN0cnN0YXJ0IDwgTUlOX01BVENIIC0gMSA/IHMuc3Ryc3RhcnQgOiBNSU5fTUFUQ0ggLSAxOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc2xvdyhzLCBmbHVzaCkgewogICAgICAgIHZhciBoYXNoX2hlYWQ7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICB2YXIgbWF4X2luc2VydDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8IE1JTl9MT09LQUhFQUQgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBoYXNoX2hlYWQgPSAwOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbcy5zdHJzdGFydCArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgIH0KICAgICAgICAgIHMucHJldl9sZW5ndGggPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgIHMucHJldl9tYXRjaCA9IHMubWF0Y2hfc3RhcnQ7CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMucHJldl9sZW5ndGggPCBzLm1heF9sYXp5X21hdGNoICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPD0gNSAmJiAocy5zdHJhdGVneSA9PT0gWl9GSUxURVJFRCB8fCBzLm1hdGNoX2xlbmd0aCA9PT0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgLSBzLm1hdGNoX3N0YXJ0ID4gNDA5NikpIHsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLnByZXZfbGVuZ3RoID49IE1JTl9NQVRDSCAmJiBzLm1hdGNoX2xlbmd0aCA8PSBzLnByZXZfbGVuZ3RoKSB7CiAgICAgICAgICAgIG1heF9pbnNlcnQgPSBzLnN0cnN0YXJ0ICsgcy5sb29rYWhlYWQgLSBNSU5fTUFUQ0g7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCBzLnN0cnN0YXJ0IC0gMSAtIHMucHJldl9tYXRjaCwgcy5wcmV2X2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMucHJldl9sZW5ndGggLSAxOwogICAgICAgICAgICBzLnByZXZfbGVuZ3RoIC09IDI7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAoKytzLnN0cnN0YXJ0IDw9IG1heF9pbnNlcnQpIHsKICAgICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgICAgICBoYXNoX2hlYWQgPSBzLnByZXZbcy5zdHJzdGFydCAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IHdoaWxlICgtLXMucHJldl9sZW5ndGggIT09IDApOwogICAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKHMubWF0Y2hfYXZhaWxhYmxlKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMTsKICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0IC0gMV0pOwogICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9ybGUocywgZmx1c2gpIHsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBwcmV2OwogICAgICAgIHZhciBzY2FuLCBzdHJlbmQ7CiAgICAgICAgdmFyIF93aW4gPSBzLndpbmRvdzsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0gpIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSBNQVhfTUFUQ0ggJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIICYmIHMuc3Ryc3RhcnQgPiAwKSB7CiAgICAgICAgICAgIHNjYW4gPSBzLnN0cnN0YXJ0IC0gMTsKICAgICAgICAgICAgcHJldiA9IF93aW5bc2Nhbl07CiAgICAgICAgICAgIGlmIChwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSkgewogICAgICAgICAgICAgIHN0cmVuZCA9IHMuc3Ryc3RhcnQgKyBNQVhfTUFUQ0g7CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIH0gd2hpbGUgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID4gcy5sb29rYWhlYWQpIHsKICAgICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5sb29rYWhlYWQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAxLCBzLm1hdGNoX2xlbmd0aCAtIE1JTl9NQVRDSCk7CiAgICAgICAgICAgIHMubG9va2FoZWFkIC09IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubWF0Y2hfbGVuZ3RoOwogICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgMCwgcy53aW5kb3dbcy5zdHJzdGFydF0pOwogICAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfaHVmZihzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgZmlsbF93aW5kb3cocyk7CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICBzLmxvb2thaGVhZC0tOwogICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgaWYgKGJmbHVzaCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiA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IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nID0gMDsKICAgICAgICB0aGlzLndyYXAgPSAwOwogICAgICAgIHRoaXMuZ3poZWFkID0gbnVsbDsKICAgICAgICB0aGlzLmd6aW5kZXggPSAwOwogICAgICAgIHRoaXMubWV0aG9kID0gWl9ERUZMQVRFRDsKICAgICAgICB0aGlzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICB0aGlzLndfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy53X2JpdHMgPSAwOwogICAgICAgIHRoaXMud19tYXNrID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy53aW5kb3dfc2l6ZSA9IDA7CiAgICAgICAgdGhpcy5wcmV2ID0gbnVsbDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuaW5zX2ggPSAwOwogICAgICAgIHRoaXMuaGFzaF9zaXplID0gMDsKICAgICAgICB0aGlzLmhhc2hfYml0cyA9IDA7CiAgICAgICAgdGhpcy5oYXNoX21hc2sgPSAwOwogICAgICAgIHRoaXMuaGFzaF9zaGlmdCA9IDA7CiAgICAgICAgdGhpcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgIHRoaXMucHJldl9tYXRjaCA9IDA7CiAgICAgICAgdGhpcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIHRoaXMuc3Ryc3RhcnQgPSAwOwogICAgICAgIHRoaXMubWF0Y2hfc3RhcnQgPSAwOwogICAgICAgIHRoaXMubG9va2FoZWFkID0gMDsKICAgICAgICB0aGlzLnByZXZfbGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm1heF9jaGFpbl9sZW5ndGggPSAwOwogICAgICAgIHRoaXMubWF4X2xhenlfbWF0Y2ggPSAwOwogICAgICAgIHRoaXMubGV2ZWwgPSAw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Ghpcy5vcHRfbGVuID0gMDsKICAgICAgICB0aGlzLnN0YXRpY19sZW4gPSAwOwogICAgICAgIHRoaXMubWF0Y2hlcyA9IDA7CiAgICAgICAgdGhpcy5pbnNlcnQgPSAwOwogICAgICAgIHRoaXMuYmlfYnVmID0gMDsKICAgICAgICB0aGlzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgczsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSAwOwogICAgICAgIHN0cm0uZGF0YV90eXBlID0gWl9VTktOT1dOOwogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIHMucGVuZGluZyA9IDA7CiAgICAgICAgcy5wZW5kaW5nX291dCA9IDA7CiAgICAgICAgaWYgKHMud3JhcCA8IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHMuc3RhdHVzID0gcy53cmFwID8gSU5JVF9TVEFURSA6IEJVU1lfU1RBVEU7CiAgICAgICAgc3RybS5hZGxlciA9IHMud3JhcCA9PT0gMiA/IDAgOiAxOwogICAgICAgIHMubGFzdF9mbHVzaCA9IFpfTk9fRkxVU0g7CiAgICAgICAgdHJlZXMuX3RyX2luaXQocyk7CiAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgcmV0ID0gZGVmbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgICBpZiAocmV0ID09PSBaX09LKSB7CiAgICAgICAgICBsbV9pbml0KHN0cm0uc3RhdGUpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RybS5zdGF0ZS53cmFwICE9PSAyKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUuZ3poZWFkID0gaGVhZDsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlSW5pdDIoc3RybSwgbGV2ZWwsIG1ldGhvZCwgd2luZG93Qml0cywgbWVtTGV2ZWwsIHN0cmF0ZWd5KSB7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHZhciB3cmFwID0gMTsKICAgICAgICBpZiAobGV2ZWwgPT09IFpfREVGQVVMVF9DT01QUkVTU0lPTikgewogICAgICAgICAgbGV2ZWwgPSA2OwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSBpZiAod2luZG93Qml0cyA+IDE1KSB7CiAgICAgICAgICB3cmFwID0gMjsKICAgICAgICAgIHdpbmRvd0JpdHMgLT0gMTY7CiAgICAgICAgfQogICAgICAgIGlmIChtZW1MZXZlbCA8IDEgfHwgbWVtTGV2ZWwgPiBNQVhfTUVNX0xFVkVMIHx8IG1ldGhvZCAhPT0gWl9ERUZMQVRFRCB8fCB3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUgfHwgbGV2ZWwgPCAwIHx8IGxldmVsID4gOSB8fCBzdHJhdGVneSA8IDAgfHwgc3RyYXRlZ3kgPiBaX0ZJWEVEKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfU1RSRUFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHdpbmRvd0JpdHMgPT09IDgpIHsKICAgICAgICAgIHdpbmRvd0JpdHMgPSA5OwogICAgICAgIH0KICAgICAgICB2YXIgcyA9IG5ldyBEZWZsYXRlU3RhdGUoKTsKICAgICAgICBzdHJtLnN0YXRlID0gczsKICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIHMud3JhcCA9IHdyYXA7CiAgICAgICAgcy5nemhlYWQgPSBudWxsOwogICAgICAgIHMud19iaXRzID0gd2luZG93Qml0czsKICAgICAgICBzLndfc2l6ZSA9IDEgPDwgcy53X2JpdHM7CiAgICAgICAgcy53X21hc2sgPSBzLndfc2l6ZSAtIDE7CiAgICAgICAgcy5oYXNoX2JpdHMgPSBtZW1MZXZlbCArIDc7CiAgICAgICAgcy5oYXNoX3NpemUgPSAxIDw8IHMuaGFzaF9iaXRzOwogICAgICAgIHMuaGFzaF9tYXNrID0gcy5oYXNoX3NpemUgLSAxOwogICAgICAgIHMuaGFzaF9zaGlmdCA9IH5+KChzLmhhc2hfYml0cyArIE1JTl9NQVRDSCAtIDEpIC8gTUlOX01BVENIKTsKICAgICAgICBzLndpbmRvdyA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplICogMik7CiAgICAgICAgcy5oZWFkID0gbmV3IHV0aWxzLkJ1ZjE2KHMuaGFzaF9zaXplKTsKICAgICAgICBzLnByZXYgPSBuZXcgdXRpbHMuQnVmMTYocy53X3NpemUpOwogICAgICAgIHMubGl0X2J1ZnNpemUgPSAxIDw8IG1lbUxldmVsICsgNjsKICAgICAgICBzLnBlbmRpbmdfYnVmX3NpemUgPSBzLmxpdF9idWZzaXplICogNDsKICAgICAgICBzLnBlbmRpbmdfYnVmID0gbmV3IH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UFNX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgcy5zdHJtID0gc3RybTsKICAgICAgICBvbGRfZmx1c2ggPSBzLmxhc3RfZmx1c2g7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gZmx1c2g7CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBJTklUX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAwOwogICAgICAgICAgICBwdXRfYnl0ZShzLCAzMSk7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDEzOSk7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDgpOwogICAgICAgICAgICBpZiAoIXMuZ3poZWFkKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIE9TX0NPREUpOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAocy5nemhlYWQudGV4dCA/IDEgOiAwKSArIChzLmd6aGVhZC5oY3JjID8gMiA6IDApICsgKCFzLmd6aGVhZC5leHRyYSA/IDAgOiA0KSArICghcy5nemhlYWQubmFtZSA/IDAgOiA4KSArICghcy5nemhlYWQuY29tbWVudCA/IDAgOiAxNikpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLnRpbWUgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAxNiAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiAyNCAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5sZXZlbCA9PT0gOSA/IDIgOiBzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyID8gNCA6IDApOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLm9zICYgMjU1KTsKICAgICAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEgJiYgcy5nemhlYWQuZXh0cmEubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggJiAyNTUpOwogICAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmEubGVuZ3RoID4+IDggJiAyNTUpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZywgMCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBFWFRSQV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFyIGhlYWRlciA9IFpfREVGTEFURUQgKyAocy53X2JpdHMgLSA4IDw8IDQpIDw8IDg7CiAgICAgICAgICAgIHZhciBsZXZlbF9mbGFncyA9IC0xOwogICAgICAgICAgICBpZiAocy5zdHJhdGVneSA+PSBaX0hVRkZNQU5fT05MWSB8fCBzLmxldmVsIDwgMikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMDsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsIDwgNikgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzLmxldmVsID09PSA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGxldmVsX2ZsYWdzID0gMzsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgfD0gbGV2ZWxfZmxhZ3MgPDwgNjsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBoZWFkZXIgfD0gUFJFU0VUX0RJQ1Q7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVhZGVyICs9IDMxIC0gaGVhZGVyICUgMzE7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgICAgcHV0U2hvcnRNU0IocywgaGVhZGVyKTsKICAgICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgIT09IDApIHsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyID4+PiAxNik7CiAgICAgICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzdHJtLmFkbGVyID0gMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBFWFRSQV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmV4dHJhKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgd2hpbGUgKHMuZ3ppbmRleCA8IChzLmd6aGVhZC5leHRyYS5sZW5ndGggJiA2NTUzNSkpIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQuZXh0cmFbcy5nemluZGV4XSAmIDI1NSk7CiAgICAgICAgICAgICAgcy5nemluZGV4Kys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemluZGV4ID09PSBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICBzLmd6aW5kZXggPSAwOwogICAgICAgICAgICAgIHMuc3RhdHVzID0gTkFNRV9TVEFURTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IE5BTUVfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLmd6aGVhZC5uYW1lKSB7CiAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIHZhbCA9IDE7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAocy5nemluZGV4IDwgcy5nemhlYWQubmFtZS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHZhbCA9IHMuZ3poZWFkLm5hbWUuY2hhckNvZGVBdChzLmd6aW5kZXgrKykgJiAyNTU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHZhbCk7CiAgICAgICAgICAgIH0gd2hpbGUgKHZhbCAhPT0gMCk7CiAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHZhbCA9PT0gMCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBDT01NRU5UX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gQ09NTUVOVF9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmNvbW1lbnQpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5jb21tZW50Lmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQuY29tbWVudC5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBIQ1JDX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gSENSQ19TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMpIHsKICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPiBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgKyAyIDw9IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgJiAyNTUpOwogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9CiAgIC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TX0ZJTklTSF9ET05FKSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gRklOSVNIX1NUQVRFOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGJzdGF0ZSA9PT0gQlNfTkVFRF9NT1JFIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX1NUQVJURUQpIHsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19CTE9DS19ET05FKSB7CiAgICAgICAgICAgIGlmIChmbHVzaCA9PT0gWl9QQVJUSUFMX0ZMVVNIKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX2FsaWduKHMpOwogICAgICAgICAgICB9IGVsc2UgaWYgKGZsdXNoICE9PSBaX0JMT0NLKSB7CiAgICAgICAgICAgICAgdHJlZXMuX3RyX3N0b3JlZF9ibG9jayhzLCAwLCAwLCBmYWxzZSk7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZVTExfRkxVU0gpIHsKICAgICAgICAgICAgICAgIHplcm8ocy5oZWFkKTsKICAgICAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcy5sYXN0X2ZsdXNoID0gLTE7CiAgICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChzLndyYXAgPD0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VORDsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA9PT0gMikgewogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDI0ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiA4ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0udG90YWxfaW4gPj4gMTYgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAyNCAmIDI1NSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgJiA2NTUzNSk7CiAgICAgICAgfQogICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgaWYgKHMud3JhcCA+IDApIHsKICAgICAgICAgIHMud3JhcCA9IC1zLndyYXA7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzLnBlbmRpbmcgIT09IDAgPyBaX09LIDogWl9TVFJFQU1fRU5EOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVFbmQoc3RybSkgewogICAgICAgIHZhciBzdGF0dXM7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXR1cyA9IHN0cm0uc3RhdGUuc3RhdHVzOwogICAgICAgIGlmIChzdGF0dXMgIT09IElOSVRfU1RBVEUgJiYgc3RhdHVzICE9PSBFWFRSQV9TVEFURSAmJiBzdGF0dXMgIT09IE5BTUVfU1RBVEUgJiYgc3RhdHVzICE9PSBDT01NRU5UX1NUQVRFICYmIHN0YXR1cyAhPT0gSENSQ19TVEFURSAmJiBzdGF0dXMgIT09IEJVU1lfU1RBVEUgJiYgc3RhdHVzICE9PSBGSU5JU0hfU1RBVEUpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzdHJtLnN0YXRlID0gbnVsbDsKICAgICAgICByZXR1cm4gc3RhdHVzID09PSBCVVNZX1NUQVRFID8gZXJyKHN0cm0sIFpfREFUQV9FUlJPUikgOiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzOwogICAgICAgIHZhciBzdHIsIG47CiAgICAgICAgdmFyIHdyYXA7CiAgICAgICAgdmFyIGF2YWlsOwogICAgICAgIHZhciBuZXh0OwogICAgICAgIHZhciBpbnB1dDsKICAgICAgICB2YXIgdG1wRGljdDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgd3JhcCA9IHMud3JhcDsKICAgICAgICBpZiAod3JhcCA9PT0gMiB8fCB3cmFwID09PSAxICYmIHMuc3RhdHVzICE9PSBJTklUX1NUQVRFIHx8IHMubG9va2FoZWFkKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmICh3cmFwID09PSAxKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICB9CiAgICAgICAgcy53cmFwID0gMDsKICAgICAgICBpZiAoZGljdExlbmd0aCA+PSBzLndfc2l6ZSkgewogICAgICAgICAgaWYgKHdyYXAgPT09IDApIHsKICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICBzLnN0cnN0YXJ0ID0gMDsKICAgICAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHRtcERpY3QgPSBuZXcgdXRpbHMuQnVmOChzLndfc2l6ZSk7CiAgICAgICAgICB1dGlscy5hcnJheVNldCh0bXBEaWN0LCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoIC0gcy53X3NpemUsIHMud19zaXplLCAwKTsKICAgICAgICAgIGRpY3Rpb25hcnkgPSB0bXBEaWN0OwogICAgICAgICAgZGljdExlbmd0aCA9IHMud19zaXplOwogICAgICAgIH0KICAgICAgICBhdmFpbCA9IHN0cm0uYXZhaWxfaW47CiAgICAgICAgbmV4dCA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IGRpY3RMZW5ndGg7CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmlucHV0ID0gZGljdGlvbmFyeTsKICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICB3aGlsZSAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICBzdHIgPSBzLnN0cnN0YXJ0OwogICAgICAgICAgbiA9IHMubG9va2FoZWFkIC0gKE1JTl9NQVRDSCAtIDEpOwogICAgICAgICAgZG8gewogICAgICAgICAgICBzLmluc19oID0gKHMuaW5zX2ggPDwgcy5oYXNoX3NoaWZ0IF4gcy53aW5kb3dbc3RyICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHN0cjsKICAgICAgICAgICAgc3RyKys7CiAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgcy5zdHJzdGFydCA9IHN0cjsKICAgICAgICAgIHMubG9va2FoZWFkID0gTUlOX01BVENIIC0gMTsKICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIH0KICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgIHMuYmxvY2tfc3RhcnQgPSBzLnN0cnN0YXJ0OwogICAgICAgIHMuaW5zZXJ0ID0gcy5sb29rYWhlYWQ7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gcy5wcmV2X2xlbmd0aCA9IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAwOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IG5leHQ7CiAgICAgICAgc3RybS5pbnB1dCA9IGlucHV0OwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBhdmFpbDsKICAgICAgICBzLndyYXAgPSB3cmFwOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmRlZ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gPDwgMTApICsgKGMyIC0gNTYzMjApOwogICAgICAgICAgICAgIG1fcG9zKys7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGJ1Zl9sZW4gKz0gYyA8IDEyOCA/IDEgOiBjIDwgMjA0OCA/IDIgOiBjIDwgNjU1MzYgPyAzIDogNDsKICAgICAgICB9CiAgICAgICAgYnVmID0gbmV3IHV0aWxzLkJ1ZjgoYnVmX2xlbik7CiAgICAgICAgZm9yIChpID0gMCwgbV9wb3MgPSAwOyBpIDwgYnVmX2xlbjsgbV9wb3MrKykgewogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zKTsKICAgICAgICAgIGlmICgoYyAmIDY0NTEyKSA9PT0gNTUyOTYgJiYgbV9wb3MgKyAxIDwgc3RyX2xlbikgewogICAgICAgICAgICBjMiA9IHN0ci5jaGFyQ29kZUF0KG1fcG9zICsgMSk7CiAgICAgICAgICAgIGlmICgoYzIgJiA2NDUxMikgPT09IDU2MzIwKSB7CiAgICAgICAgICAgICAgYyA9IDY1NTM2ICsgKGMgLSA1NTI5NiA8PCAxMCkgKyAoYzIgLSA1NjMyMCk7CiAgICAgICAgICAgICAgbV9wb3MrKzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCAxMjgpIHsKICAgICAgICAgICAgYnVmW2krK10gPSBjOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgMjA0OCkgewogICAgICAgICAgICBidWZbaSsrXSA9IDE5MiB8IGMgPj4+IDY7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIGlmIChjIDwgNjU1MzYpIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyMjQgfCBjID4+PiAxMjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiA2ICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyAmIDYzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYnVmW2krK10gPSAyNDAgfCBjID4+PiAxODsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjID4+PiAxMiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGJ1ZjJiaW5zdHJpbmcoYnVmLCBsZW4pIHsKICAgICAgICBpZiAobGVuIDwgNjU1MzQpIHsKICAgICAgICAgIGlmIChidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX1VJQV9PSyB8fCAhYnVmLnN1YmFycmF5ICYmIFNUUl9BUFBMWV9PSykgewogICAgICAgICAgICByZXR1cm4gU3RyaW5nLmZyb21DaGFyQ29kZS5hcHBseShudWxsLCB1dGlscy5zaHJpbmtCdWYoYnVmLCBsZW4pKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdmFyIHJlc3VsdCA9ICIiOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIHJlc3VsdCArPSBTdHJpbmcuZnJvbUNoYXJDb2RlKGJ1ZltpXSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgIH0KICAgICAgZXhwb3J0czIuYnVmMmJpbnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZikgewogICAgICAgIHJldHVybiBidWYyYmluc3RyaW5nKGJ1ZiwgYnVmLmxlbmd0aCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJpbnN0cmluZzJidWYgPSBmdW5jdGlvbihzdHIpIHsKICAgICAgICB2YXIgYnVmID0gbmV3IHV0aWxzLkJ1Zjgoc3RyLmxlbmd0aCk7CiAgICAgICAgZm9yICh2YXIgaSA9IDAsIGxlbiA9IGJ1Zi5sZW5ndGg7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgYnVmW2ldID0gc3RyLmNoYXJDb2RlQXQoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmJ1ZjJzdHJpbmcgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBpLCBvdXQsIGMsIGNfbGVuOwogICAgICAgIHZhciBsZW4gPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICB2YXIgdXRmMTZidWYgPSBuZXcgQXJyYXkobGVuICogMik7CiAgICAgICAgZm9yIChvdXQgPSAwLCBpID0gMDsgaSA8IGxlbjsgKSB7CiAgICAgICAgICBjID0gYnVmW2krK107CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGNfbGVuID0gX3V0ZjhsZW5bY107CiAgICAgICAgICBpZiAoY19sZW4gPiA0KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IDY1NTMzOwogICAgICAgICAgICBpICs9IGNfbGVuIC0gMTsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBjICY9IGNfbGVuID09PSAyID8gMzEgOiBjX2xlbiA9PT0gMyA/IDE1IDogNzsKICAgICAgICAgIHdoaWxlIChjX2xlbiA+IDEgJiYgaSA8IGxlbikgewogICAgICAgICAgICBjID0gYyA8PCA2IHwgYnVmW2krK10gJiA2MzsKICAgICAgICAgICAgY19sZW4tLTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChjX2xlbiA+IDEpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgYyAtPSA2NTUzNjsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTUyOTYgfCBjID4+IDEwICYgMTAyMzsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNTYzMjAgfCBjICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcodXRmMTZidWYsIG91dCk7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnV0Zjhib3JkZXIgPSBmdW5jdGlvbihidWYsIG1heCkgewogICAgICAgIHZhciBwb3M7CiAgICAgICAgbWF4ID0gbWF4IHx8IGJ1Zi5sZW5ndGg7CiAgICAgICAgaWYgKG1heCA+IGJ1Zi5sZW5ndGgpIHsKICAgICAgICAgIG1heCA9IGJ1Zi5sZW5ndGg7CiAgICAgICAgfQogICAgICAgIHBvcyA9IG1heCAtIDE7CiAgICAgICAgd2hpbGUgKHBvcyA+PSAwICYmIChidWZbcG9zXSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgcG9zLS07CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPCAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAocG9zID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gbWF4OwogICAgICAgIH0KICAgICAgICByZXR1cm4gcG9zICsgX3V0ZjhsZW5bYnVmW3Bvc11dID4gbWF4ID8gcG9zIDogbWF4OwogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcwogIHZhciByZXF1aXJlX3pzdHJlYW0gPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvenN0cmVhbS5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIFpTdHJlYW0oKSB7CiAgICAgICAgdGhpcy5pbnB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X2luID0gMDsKICAgICAgICB0aGlzLmF2YWlsX2luID0gMDsKICAgICAgICB0aGlzLnRvdGFsX2luID0gMDsKICAgICAgICB0aGlzLm91dHB1dCA9IG51bGw7CiAgICAgICAgdGhpcy5uZXh0X291dCA9IDA7CiAgICAgICAgdGhpcy5hdmFpbF9vdXQgPSAwOwogICAgICAgIHRoaXMudG90YWxfb3V0ID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuc3RhdGUgPSBudWxsOwogICAgICAgIHRoaXMuZGF0YV90eXBlID0gMjsKICAgICAgICB0aGlzLmFkbGVyID0gMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBaU3RyZWFtOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL2RlZmxhdGUuanMKICB2YXIgcmVxdWlyZV9kZWZsYXRlMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvZGVmbGF0ZS5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciB6bGliX2RlZmxhdGUgPSByZXF1aXJlX2RlZmxhdGUoKTsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIHN0cmluZ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F0YSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBkYXRhOwogICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uYXZhaWxfaW4gPSBzdHJtLmlucHV0Lmxlbmd0aDsKICAgICAgICBkbyB7CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgc3RybS5vdXRwdXQgPSBuZXcgdXRpbHMuQnVmOChjaHVua1NpemUpOwogICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gMDsKICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2RlZmxhdGUuZGVmbGF0ZShzdHJtLCBfbW9kZSk7CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQgJiYgc3RhdHVzICE9PSBaX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gWl9GSU5JU0ggfHwgX21vZGUgPT09IFpfU1lOQ19GTFVTSDIpKSB7CiAgICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgICAgdGhpcy5vbkRhdGEoc3RyaW5ncy5idWYyYmluc3RyaW5nKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBaX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChfbW9kZSA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlRW5kKHRoaXMuc3RybSk7CiAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgIHJldHVybiBzdGF0dXMgPT09IFpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikgewogICAgICAgICAgdGhpcy5vbkVuZChaX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25EYXRhID0gZnVuY3Rpb24oY2h1bmspIHsKICAgICAgICB0aGlzLmNodW5rcy5wdXNoKGNodW5rKTsKICAgICAgfTsKICAgICAgRGVmbGF0ZS5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBaX09LKSB7CiAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHRoaXMuY2h1bmtzLmpvaW4oIiIpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB1dGlscy5mbGF0dGVuQ2h1bmtzKHRoaXMuY2h1bmtzKTsKICAgICAgICAgIH0KICA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xLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mZmFzdC5qcwogIHZhciByZXF1aXJlX2luZmZhc3QgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvaW5mZmFzdC5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIFRZUEUgPSAxMjsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV9mYXN0KHN0cm0sIHN0YXJ0KSB7CiAgICAgICAgdmFyIHN0YXRlOwogICAgICAgIHZhciBfaW47CiAgICAgICAgdmFyIGxhc3Q7CiAgICAgICAgdmFyIF9vdXQ7CiAgICAgICAgdmFyIGJlZzsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBkbWF4OwogICAgICAgIHZhciB3c2l6ZTsKICAgICAgICB2YXIgd2hhdmU7CiAgICAgICAgdmFyIHduZXh0OwogICAgICAgIHZhciBzX3dpbmRvdzsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbGNvZGU7CiAgICAgICAgdmFyIGRjb2RlOwogICAgICAgIHZhciBsbWFzazsKICAgICAgICB2YXIgZG1hc2s7CiAgICAgICAgdmFyIGhlcmU7CiAgICAgICAgdmFyIG9wOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGRpc3Q7CiAgICAgICAgdmFyIGZyb207CiAgICAgICAgdmFyIGZyb21fc291cmNlOwogICAgICAgIHZhciBpbnB1dCwgb3V0cHV0OwogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBfaW4gPSBzdHJtLm5leHRfaW47CiAgICAgICAgaW5wdXQgPSBzdHJtLmlucHV0OwogICAgICAgIGxhc3QgPSBfaW4gKyAoc3RybS5hdmFpbF9pbiAtIDUpOwogICAgICAgIF9vdXQgPSBzdHJtLm5leHRfb3V0OwogICAgICAgIG91dHB1dCA9IHN0cm0ub3V0cHV0OwogICAgICAgIGJlZyA9IF9vdXQgLSAoc3RhcnQgLSBzdHJtLmF2YWlsX291dCk7CiAgICAgICAgZW5kID0gX291dCArIChzdHJtLmF2YWlsX291dCAtIDI1Nyk7CiAgICAgICAgZG1heCA9IHN0YXRlLmRtYXg7CiAgICAgICAgd3NpemUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICB3aGF2ZSA9IHN0YXRlLndoYXZlOwogICAgICAgIHduZXh0ID0gc3RhdGUud25leHQ7CiAgICAgICAgc193aW5kb3cgPSBzdGF0ZS53aW5kb3c7CiAgICAgICAgaG9sZCA9IHN0YXRlLmhvbGQ7CiAgICAgICAgYml0cyA9IHN0YXRlLmJpdHM7CiAgICAgICAgbGNvZGUgPSBzdGF0ZS5sZW5jb2RlOwogICAgICAgIGRjb2RlID0gc3RhdGUuZGlzdGNvZGU7CiAgICAgICAgbG1hc2sgPSAoMSA8PCBzdGF0ZS5sZW5iaXRzKSAtIDE7CiAgICAgICAgZG1hc2sgPSAoMSA8PCBzdGF0ZS5kaXN0Yml0cykgLSAxOwogICAgICAgIHRvcDoKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlcmUgPSBsY29kZVtob2xkICYgbG1hc2tdOwogICAgICAgICAgICBkb2xlbjoKICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgIGlmIChvcCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICBsZW4gPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICBpZiAob3ApIHsKICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W19pbisrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBsZW4gKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCAxNSkgewogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVtob2xkICYgZG1hc2tdOwogICAgICAgICAgICAgICAgICBkb2Rpc3Q6CiAgICAgICAgICAgICAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDI0OwogICAgICAgICAgICAgICAgICAgICAgaG9sZCA+Pj49IG9wOwogICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMTYgJiAyNTU7CiAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgJiAxNikgewogICAgICAgICAgICAgICAgICAgICAgICBkaXN0ID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgICAgICAgICBvcCAmPSAxNTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgKz0gaG9sZCAmICgxIDw8IG9wKSAtIDE7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChkaXN0ID4gZG1heCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gX291dCAtIGJlZzsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIG9wID0gZGlzdCAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA+IHdoYXZlKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoc3RhdGUuc2FuZSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIHRvbyBmYXIgYmFjayI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBzX3dpbmRvdzsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd3NpemUgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAod25leHQgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSArIHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCAtPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHduZXh0IDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSB3bmV4dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHduZXh0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAob3AgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBzX3dpbmRvd1tmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlICgtLW9wKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IG91dHB1dDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUgKGxlbiA+IDIpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICB9IHdoaWxlIChsZW4gPiAyKTsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGxlbiA+IDEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGhlcmUgPSBkY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2Rpc3Q7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbnZhbGlkIGRpc3RhbmNlIGNvZGUiOwogICAgICAgICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gQkFEOwogICAgICAgICAgICAgICAgICAgICAgICBicmVhayB0b3A7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKChvcCAmIDY0KSA9PT0gMCkgewogICAgICAgICAgICAgICAgICBoZXJlID0gbGNvZGVbKGhlcmUgJiA2NTUzNSkgKyAoaG9sZCAmICgxIDw8IG9wKSAtIDEpXTsKICAgICAgICAgICAgICAgICAgY29udGludWUgZG9sZW47CiAgICAgICAgICAgICAgICB9IGVsc2UgaWYgKG9wICYgMzIpIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEU7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgbGl0ZXJhbC9sZW5ndGggY29kZSI7CiAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKF9pbiA8IGxhc3QgJiYgX291dCA8IGVuZCk7CiAgICAgICAgbGVuID0gYml0cyA+PiAzOwogICAgICAgIF9pbiAtPSBsZW47CiAgICAgICAgYml0cyAtPSBsZW4gPDwgMzsKICAgICAgICBob2xkICY9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AgICAgICAgOSwKICAgICAgICAxMCwKICAgICAgICAxMSwKICAgICAgICAxMywKICAgICAgICAxNSwKICAgICAgICAxNywKICAgICAgICAxOSwKICAgICAgICAyMywKICAgICAgICAyNywKICAgICAgICAzMSwKICAgICAgICAzNSwKICAgICAgICA0MywKICAgICAgICA1MSwKICAgICAgICA1OSwKICAgICAgICA2NywKICAgICAgICA4MywKICAgICAgICA5OSwKICAgICAgICAxMTUsCiAgICAgICAgMTMxLAogICAgICAgIDE2MywKICAgICAgICAxOTUsCiAgICAgICAgMjI3LAogICAgICAgIDI1OCwKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGxleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMTYsCiAgICAgICAgNzIsCiAgICAgICAgNzgKICAgICAgXTsKICAgICAgdmFyIGRiYXNlID0gWwogICAgICAgIDEsCiAgICAgICAgMiwKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA3LAogICAgICAgIDksCiAgICAgICAgMTMsCiAgICAgICAgMTcsCiAgICAgICAgMjUsCiAgICAgICAgMzMsCiAgICAgICAgNDksCiAgICAgICAgNjUsCiAgICAgICAgOTcsCiAgICAgICAgMTI5LAogICAgICAgIDE5MywKICAgICAgICAyNTcsCiAgICAgICAgMzg1LAogICAgICAgIDUxMywKICAgICAgICA3NjksCiAgICAgICAgMTAyNSwKICAgICAgICAxNTM3LAogICAgICAgIDIwNDksCiAgICAgICAgMzA3MywKICAgICAgICA0MDk3LAogICAgICAgIDYxNDUsCiAgICAgICAgODE5MywKICAgICAgICAxMjI4OSwKICAgICAgICAxNjM4NSwKICAgICAgICAyNDU3NywKICAgICAgICAwLAogICAgICAgIDAKICAgICAgXTsKICAgICAgdmFyIGRleHQgPSBbCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTYsCiAgICAgICAgMTcsCiAgICAgICAgMTcsCiAgICAgICAgMTgsCiAgICAgICAgMTgsCiAgICAgICAgMTksCiAgICAgICAgMTksCiAgICAgICAgMjAsCiAgICAgICAgMjAsCiAgICAgICAgMjEsCiAgICAgICAgMjEsCiAgICAgICAgMjIsCiAgICAgICAgMjIsCiAgICAgICAgMjMsCiAgICAgICAgMjMsCiAgICAgICAgMjQsCiAgICAgICAgMjQsCiAgICAgICAgMjUsCiAgICAgICAgMjUsCiAgICAgICAgMjYsCiAgICAgICAgMjYsCiAgICAgICAgMjcsCiAgICAgICAgMjcsCiAgICAgICAgMjgsCiAgICAgICAgMjgsCiAgICAgICAgMjksCiAgICAgICAgMjksCiAgICAgICAgNjQsCiAgICAgICAgNjQKICAgICAgXTsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gZnVuY3Rpb24gaW5mbGF0ZV90YWJsZSh0eXBlLCBsZW5zLCBsZW5zX2luZGV4LCBjb2RlcywgdGFibGUsIHRhYmxlX2luZGV4LCB3b3JrLCBvcHRzKSB7CiAgICAgICAgdmFyIGJpdHMgPSBvcHRzLmJpdHM7CiAgICAgICAgdmFyIGxlbiA9IDA7CiAgICAgICAgdmFyIHN5bSA9IDA7CiAgICAgICAgdmFyIG1pbiA9IDAsIG1heCA9IDA7CiAgICAgICAgdmFyIHJvb3QyID0gMDsKICAgICAgICB2YXIgY3VyciA9IDA7CiAgICAgICAgdmFyIGRyb3AgPSAwOwogICAgICAgIHZhciBsZWZ0ID0gMDsKICAgICAgICB2YXIgdXNlZCA9IDA7CiAgICAgICAgdmFyIGh1ZmYgPSAwOwogICAgICAgIHZhciBpbmNyOwogICAgICAgIHZhciBmaWxsOwogICAgICAgIHZhciBsb3c7CiAgICAgICAgdmFyIG1hc2s7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGJhc2UgPSBudWxsOwogICAgICAgIHZhciBiYXNlX2luZGV4ID0gMDsKICAgICAgICB2YXIgZW5kOwogICAgICAgIHZhciBjb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIG9mZnMgPSBuZXcgdXRpbHMuQnVmMTYoTUFYQklUUyArIDEpOwogICAgICAgIHZhciBleHRyYSA9IG51bGw7CiAgICAgICAgdmFyIGV4dHJhX2luZGV4ID0gMDsKICAgICAgICB2YXIgaGVyZV9iaXRzLCBoZXJlX29wLCBoZXJlX3ZhbDsKICAgICAgICBmb3IgKGxlbiA9IDA7IGxlbiA8PSBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgY291bnRbbGVuXSA9IDA7CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBjb3VudFtsZW5zW2xlbnNfaW5kZXggKyBzeW1dXSsrOwogICAgICAgIH0KICAgICAgICByb290MiA9IGJpdHM7CiAgICAgICAgZm9yIChtYXggPSBNQVhCSVRTOyBtYXggPj0gMTsgbWF4LS0pIHsKICAgICAgICAgIGlmIChjb3VudFttYXhdICE9PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocm9vdDIgPiBtYXgpIHsKICAgICAgICAgIHJvb3QyID0gbWF4OwogICAgICAgIH0KICAgICAgICBpZiAobWF4ID09PSAwKSB7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICB0YWJsZVt0YWJsZV9pbmRleCsrXSA9IDEgPDwgMjQgfCA2NCA8PCAxNiB8IDA7CiAgICAgICAgICBvcHRzLmJpdHMgPSAxOwogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvciAobWluID0gMTsgbWluIDwgbWF4OyBtaW4rKykgewogICAgICAgICAgaWYgKGNvdW50W21pbl0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA8IG1pbikgewogICAgICAgICAgcm9vdDIgPSBtaW47CiAgICAgICAgfQogICAgICAgIGxlZnQgPSAxOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgbGVmdCAtPSBjb3VudFtsZW5dOwogICAgICAgICAgaWYgKGxlZnQgPCAwKSB7CiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGxlZnQgPiAwICYmICh0eXBlID09PSBDT0RFUyB8fCBtYXggIT09IDEpKSB7CiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgfQogICAgICAgIG9mZnNbMV0gPSAwOwogICAgICAgIGZvciAobGVuID0gMTsgbGVuIDwgTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIG9mZnNbbGVuICsgMV0gPSBvZmZzW2xlbl0gKyBjb3VudFtsZW5dOwogICAgICAgIH0KICAgICAgICBmb3IgKHN5bSA9IDA7IHN5bSA8IGNvZGVzOyBzeW0rKykgewogICAgICAgICAgaWYgKGxlbnNbbGVuc19pbmRleCArIHN5bV0gIT09IDApIHsKICAgICAgICAgICAgd29ya1tvZmZzW2xlbnNbbGVuc19pbmRleCArIHN5bV1dKytdID0gc3ltOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAodHlwZSA9PT0gQ09ERVMpIHsKICAgICAgICAgIGJhc2UgPSBleHRyYSA9IHdvcms7CiAgICAgICAgICBlbmQgPSAxOTsKICAgICAgICB9IGVsc2UgaWYgKHR5cGUgPT09IExFTlMpIHsKICAgICAgICAgIGJhc2UgPSBsYmFzZTsKICAgICAgICAgIGJhc2VfaW5kZXggLT0gMjU3OwogICAgICAgICAgZXh0cmEgPSBsZXh0OwogICAgICAgICAgZXh0cmFfaW5kZXggLT0gMjU3OwogICAgICAgICAgZW5kID0gMjU2OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBiYXNlID0gZGJhc2U7CiAgICAgICAgICBleHRyYSA9IGRleHQ7CiAgICAgICAgICBlbmQgPSAtMTsKICAgICAgICB9CiAgICAgICAgaHVmZiA9IDA7CiAgICAgICAgc3ltID0gMDsKICAgICAgICBsZW4gPSBtaW47CiAgICAgICAgbmV4dCA9IHRhYmxlX2luZGV4OwogICAgICAgIGN1cnIgPSByb290MjsKICAgICAgICBkcm9wID0gMDsKICAgICAgICBsb3cgPSAtMTsKICAgICAgICB1c2VkID0gMSA8PCByb290MjsKICAgICAgICBtYXNrID0gdXNlZCAtIDE7CiAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgIHJldHVybiAxOwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGhlcmVfYml0cyA9IGxlbiAtIGRyb3A7CiAgICAgICAgICBpZiAod29ya1tzeW1dIDwgZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAwOwogICAgICAgICAgICBoZXJlX3ZhbCA9IHdvcmtbc3ltXTsKICAgICAgICAgIH0gZWxzZSBpZiAod29ya1tzeW1dID4gZW5kKSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSBleHRyYVtleHRyYV9pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICAgIGhlcmVfdmFsID0gYmFzZVtiYXNlX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGhlcmVfb3AgPSAzMiArIDY0OwogICAgICAgICAgICBoZXJlX3ZhbCA9IDA7CiAgICAgICAgICB9CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSBkcm9wOwogICAgICAgICAgZmlsbCA9IDEgPDwgY3VycjsKICAgICAgICAgIG1pbiA9IGZpbGw7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIGZpbGwgLT0gaW5jcjsKICAgICAgICAgICAgdGFibGVbbmV4dCArIChodWZmID4+IGRyb3ApICsgZmlsbF0gPSBoZXJlX2JpdHMgPDwgMjQgfCBoZXJlX29wIDw8IDE2IHwgaGVyZV92YWwgfCAwOwogICAgICAgICAgfSB3aGlsZSAoZmlsbCAhPT0gMCk7CiAgICAgICAgICBpbmNyID0gMSA8PCBsZW4gLSAxOwogICAgICAgICAgd2hpbGUgKGh1ZmYgJiBpbmNyKSB7CiAgICAgICAgICAgIGluY3IgPj49IDE7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaW5jciAhPT0gMCkgewogICAgICAgICAgICBodWZmICY9IGluY3IgLSAxOwogICAgICAgICAgICBodWZmICs9IGluY3I7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBodWZmID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIHN5bSsrOwogICAgICAgICAgaWYgKC0tY291bnRbbGVuXSA9PT0gMCkgewogICAgICAgICAgICBpZiAobGVuID09PSBtYXgpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBsZW4gPSBsZW5zW2xlbnNfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGxlbiA+IHJvb3QyICYmIChodWZmICYgbWFzaykgIT09IGxvdykgewogICAgICAgICAgICBpZiAoZHJvcCA9PT0gMCkgewogICAgICAgICAgICAgIGRyb3AgPSByb290MjsKICAgICAgICAgICAgfQogICAgICAgICAgICBuZXh0ICs9IG1pbjsKICAgICAgICAgICAgY3VyciA9IGxlbiAtIGRyb3A7CiAgICAgICAgICAgIGxlZnQgPSAxIDw8IGN1cnI7CiAgICAgICAgICAgIHdoaWxlIChjdXJyICsgZHJvcCA8IG1heCkgewogICAgICAgICAgICAgIGxlZnQgLT0gY291bnRbY3VyciArIGRyb3BdOwogICAgICAgICAgICAgIGlmIChsZWZ0IDw9IDApIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBjdXJyKys7CiAgICAgICAgICAgICAgbGVmdCA8PD0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICB1c2VkICs9IDEgPDwgY3VycjsKICAgICAgICAgICAgaWYgKHR5cGUgPT09IExFTlMgJiYgdXNlZCA+IEVOT1VHSF9MRU5TIHx8IHR5cGUgPT09IERJU1RTICYmIHVzZWQgPiBFTk9VR0hfRElTVFMpIHsKICAgICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBsb3cgPSBodWZmICYgbWFzazsKICAgICAgICAgICAgdGFibGVbbG93XSA9IHJvb3QyIDw8IDI0IHwgY3VyciA8PCAxNiB8IG5leHQgLSB0YWJsZV9pbmRleCB8IDA7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChodWZmICE9PSAwKSB7CiAgICAgICAgICB0YWJsZVtuZXh0ICsgaHVmZl0gPSBsZW4gLSBkcm9wIDw8IDI0IHwgNjQgPDwgMTYgfCAwOwogICAgICAgIH0KICAgICAgICBvcHRzLmJpdHMgPSByb290MjsKICAgICAgICByZXR1cm4gMDsKICAgICAgfTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMKICB2YXIgcmVxdWlyZV9pbmZsYXRlID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZmxhdGUuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgYWRsZXIzMiA9IHJlcXVpcmVfYWRsZXIzMigpOwogICAgICB2YXIgY3JjMzIgPSByZXF1aXJlX2NyYzMyKCk7CiAgICAgIHZhciBpbmZsYXRlX2Zhc3QgPSByZXF1aXJlX2luZmZhc3QoKTsKICAgICAgdmFyIGluZmxhdGVfdGFibGUgPSByZXF1aXJlX2luZnRyZWVzKCk7CiAgICAgIHZhciBDT0RFUyA9IDA7CiAgICAgIHZhciBMRU5TID0gMTsKICAgICAgdmFyIERJU1RTID0gMjsKICAgICAgdmFyIFpfRklOSVNIID0gNDsKICAgICAgdmFyIFpfQkxPQ0sgPSA1OwogICAgICB2YXIgWl9UUkVFUyA9IDY7CiAgICAgIHZhciBaX09LID0gMDsKICAgICAgdmFyIFpfU1RSRUFNX0VORCA9IDE7CiAgICAgIHZhciBaX05FRURfRElDVCA9IDI7CiAgICAgIHZhciBaX1NUUkVBTV9FUlJPUiA9IC0yOwogICAgICB2YXIgWl9EQVRBX0VSUk9SID0gLTM7CiAgICAgIHZhciBaX01FTV9FUlJPUiA9IC00OwogICAgICB2YXIgWl9CVUZfRVJST1IgPSAtNTsKICAgICAgdmFyIFpfREVGTEFURUQgPSA4OwogICAgICB2YXIgSEVBRCA9IDE7CiAgICAgIHZhciBGTEFHUyA9IDI7CiAgICAgIHZhciBUSU1FID0gMzsKICAgICAgdmFyIE9TID0gNDsKICAgICAgdmFyIEVYTEVOID0gNTsKICAgICAgdmFyIEVYVFJBID0gNjsKICAgICAgdmFyIE5BTUUgPSA3OwogICAgICB2YXIgQ09NTUVOVCA9IDg7CiAgICAgIHZhciBIQ1JDID0gOTsKICAgICAgdmFyIERJQ1RJRCA9IDEwOwogICAgICB2YXIgRElDVCA9IDExOwogICAgICB2YXIgVFlQRSA9IDEyOwogICAgICB2YXIgVFlQRURPID0gMTM7CiAgICAgIHZhciBTVE9SRUQgPSAxNDsKICAgICAgdmFyIENPUFlfID0gMTU7CiAgICAgIHZhciBDT1BZID0gMTY7CiAgICAgIHZhciBUQUJMRSA9IDE3OwogICAgICB2YXIgTEVOTEVOUyA9IDE4OwogICAgICB2YXIgQ09ERUxFTlMgPSAxOTsKICAgICAgdmFyIExFTl8gPSAyMDsKICAgICAgdmFyIExFTiA9IDIxOwogICAgICB2YXIgTEVORVhUID0gMjI7CiAgICAgIHZhciBESVNUID0gMjM7CiAgICAgIHZhciBESVNURVhUID0gMjQ7CiAgICAgIHZhciBNQVRDSCA9IDI1OwogICAgICB2YXIgTElUID0gMjY7CiAgICAgIHZhciBDSEVDSyA9IDI3OwogICAgICB2YXIgTEVOR1RIID0gMjg7CiAgICAgIHZhciBET05FID0gMjk7CiAgICAgIHZhciBCQUQgPSAzMDsKICAgICAgdmFyIE1FTSA9IDMxOwogICAgICB2YXIgU1lOQyA9IDMyOwogICAgICB2YXIgRU5PVUdIX0xFTlMgPSA4NTI7CiAgICAgIHZhciBFTk9VR0hfRElTVFMgPSA1OTI7CiAgICAgIHZhciBNQVhfV0JJVFMgPSAxNTsKICAgICAgdmFyIERFRl9XQklUUyA9IE1BWF9XQklUUzsKICAgICAgZnVuY3Rpb24genN3YXAzMihxKSB7CiAgICAgICAgcmV0dXJuIChxID4+PiAyNCAmIDI1NSkgKyAocSA+Pj4gOCAmIDY1MjgwKSArICgocSAmIDY1MjgwKSA8PCA4KSArICgocSAmIDI1NSkgPDwgMjQpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEluZmxhdGVTdGF0ZSgpIHsKICAgICAgICB0aGlzLm1vZGUgPSAwOwogICAgICAgIHRoaXMubGFzdCA9IGZhbHNlOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5oYXZlZGljdCA9IGZhbHNlOwogICAgICAgIHRoaXMuZmxhZ3MgPSAwOwogICAgICAgIHRoaXMuZG1heCA9IDA7CiAgICAgICAgdGhpcy5jaGVjayA9IDA7CiAgICAgICAgdGhpcy50b3RhbCA9IDA7CiAgICAgICAgdGhpcy5oZWFkID0gbnVsbDsKICAgICAgICB0aGlzLndiaXRzID0gMDsKICAgICAgICB0aGlzLndzaXplID0gMDsKICAgICAgICB0aGlzLndoYXZlID0gMDsKICAgICAgICB0aGlzLnduZXh0ID0gMDsKICAgICAgICB0aGlzLndpbmRvdyA9IG51bGw7CiAgICAgICAgdGhpcy5ob2xkID0gMDsKICAgICAgICB0aGlzLmJpdHMgPSAwOwogICAgICAgIHRoaXMubGVuZ3RoID0gMDsKICAgICAgICB0aGlzLm9mZnNldCA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IDA7CiAgICAgICAgdGhpcy5sZW5jb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmRpc3Rjb2RlID0gbnVsbDsKICAgICAgICB0aGlzLmxlbmJpdHMgPSAwOwogICAgICAgIHRoaXMuZGlzdGJpdHMgPSAwOwogICAgICAgIHRoaXMubmNvZGUgPSAwOwogICAgICAgIHRoaXMubmxlbiA9IDA7CiAgICAgICAgdGhpcy5uZGlzdCA9IDA7CiAgICAgICAgdGhpcy5oYXZlID0gMDsKICAgICAgICB0aGlzLm5leHQgPSBudWxsOwogICAgICAgIHRoaXMubGVucyA9IG5ldyB1dGlscy5CdWYxNigzMjApOwogICAgICAgIHRoaXMud29yayA9IG5ldyB1dGlscy5CdWYxNigyODgpOwogICAgICAgIHRoaXMubGVuZHluID0gbnVsbDsKICAgICAgICB0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mbGF0ZVJlc2V0KHN0cm0pIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdGF0ZS53c2l6ZSA9IDA7CiAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgIHN0YXRlLnduZXh0ID0gMDsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0S2VlcChzdHJtKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQyKHN0cm0sIHdpbmRvd0JpdHMpIHsKICAgICAgICB2YXIgd3JhcDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAod2luZG93Qml0cyA8IDApIHsKICAgICAgICAgIHdyYXAgPSAwOwogICAgICAgICAgd2luZG93Qml0cyA9IC13aW5kb3dCaXRzOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB3cmFwID0gKHdpbmRvd0JpdHMgPj4gNCkgKyAxOwogICAgICAgICAgaWYgKHdpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgICB3aW5kb3dCaXRzICY9IDE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyAmJiAod2luZG93Qml0cyA8IDggfHwgd2luZG93Qml0cyA+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+IGxlZnQpIHsKICAgICAgICAgICAgICAgICAgY29weSA9IGxlZnQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBsZWZ0IC09IGNvcHk7CiAgICAgICAgICAgICAgICBzdGF0ZS5sZW5ndGggLT0gY29weTsKICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgb3V0cHV0W3B1dCsrXSA9IGZyb21fc291cmNlW2Zyb20rK107CiAgICAgICAgICAgICAgICB9IHdoaWxlICgtLWNvcHkpOwogICAgICAgICAgICAgICAgaWYgKHN0YXRlLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSBMSVQ6CiAgICAgICAgICAgICAgICBpZiAobGVmdCA9PT0gMCkgewogICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBvdXRwdXRbcHV0KytdID0gc3RhdGUubGVuZ3RoOwogICAgICAgICAgICAgICAgbGVmdC0tOwogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTjsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgQ0hFQ0s6CiAgICAgICAgICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDMyKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGhhdmUgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIGluZl9sZWF2ZTsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgaGF2ZS0tOwogICAgICAgICAgICAgICAgICAgIGhvbGQgfD0gaW5wdXRbbmV4dCsrXSA8PCBiaXRzOwogICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBfb3V0IC09IGxlZnQ7CiAgICAgICAgICAgICAgICAgIHN0cm0udG90YWxfb3V0ICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIHN0YXRlLnRvdGFsICs9IF9vdXQ7CiAgICAgICAgICAgICAgICAgIGlmIChfb3V0KSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLmNoZWNrID0gc3RhdGUuZmxhZ3MgPyBjcmMzMihzdGF0ZS5jaGVjaywgb3V0cHV0LCBfb3V0LCBwdXQgLSBfb3V0KSA6IGFkbGVyMzIoc3RhdGUuY2hlY2ssIG91dHB1dCwgX291dCwgcHV0IC0gX291dCk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgX291dCA9IGxlZnQ7CiAgICAgICAgICAgICAgICAgIGlmICgoc3RhdGUuZmxhZ3MgPyBob2xkIDogenN3YXAzMihob2xkKSkgIT09IHN0YXRlLmNoZWNrKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGRhdGEgY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IExFTkdUSDsKICAgICAgICAgICAgICBjYXNlIExFTkdUSDoKICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYmIHN0YXRlLmZsYWdzKSB7CiAgICAgICAgICAgICAgICAgIHdoaWxlIChiaXRzIDwgMzIpIHsKICAgICAgICAgICAgICAgICAgICBpZiAoaGF2ZSA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBoYXZlLS07CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgYml0cyArPSA4OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChob2xkICE9PSAoc3RhdGUudG90YWwgJiA0Mjk0OTY3Mjk1KSkgewogICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImluY29ycmVjdCBsZW5ndGggY2hlY2siOwogICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaG9sZCA9IDA7CiAgICAgICAgICAgICAgICAgIGJpdHMgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IERPTkU7CiAgICAgICAgICAgICAgY2FzZSBET05FOgogICAgICAgICAgICAgICAgcmV0ID0gWl9TVFJFQU1fRU5EOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgQkFEOgogICAgICAgICAgICAgICAgcmV0ID0gWl9EQVRBX0VSUk9SOwogICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgIGNhc2UgTUVNOgogICAgICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgICAgIGNhc2UgU1lOQzoKICAgICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X291dCA9IHB1dDsKICAgICAgICBzdHJtLmF2YWlsX291dCA9IGxlZnQ7CiAgICAgICAgc3RybS5uZXh0X2luID0gbmV4dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gaGF2ZTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICBpZiAoc3RhdGUud3NpemUgfHwgX291dCAhPT0gc3RybS5hdmFpbF9vdXQgJiYgc3RhdGUubW9kZSA8IEJBRCAmJiAoc3RhdGUubW9kZSA8IENIRUNLIHx8IGZsdXNoICE9PSBaX0ZJTklTSCkpIHsKICAgICAgICAgIGlmICh1cGRhdGV3aW5kb3coc3RybSwgc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQsIF9vdXQgLSBzdHJtLmF2YWlsX291dCkpIHsKICAgICAgICAgICAgc3RhdGUubW9kZSA9IE1FTTsKICAgICAgICAgICAgcmV0dXJuIFpfTUVNX0VSUk9SOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBfaW4gLT0gc3RybS5hdmFpbF9pbjsKICAgICAgICBfb3V0IC09IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIHN0cm0udG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Wl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlR2V0SGVhZGVyKHN0cm0sIGhlYWQpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoKHN0YXRlLndyYXAgJiAyKSA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5oZWFkID0gaGVhZDsKICAgICAgICBoZWFkLmRvbmUgPSBmYWxzZTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlU2V0RGljdGlvbmFyeShzdHJtLCBkaWN0aW9uYXJ5KSB7CiAgICAgICAgdmFyIGRpY3RMZW5ndGggPSBkaWN0aW9uYXJ5Lmxlbmd0aDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGRpY3RpZDsKICAgICAgICB2YXIgcmV0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndyYXAgIT09IDAgJiYgc3RhdGUubW9kZSAhPT0gRElDVCkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhdGUubW9kZSA9PT0gRElDVCkgewogICAgICAgICAgZGljdGlkID0gMTsKICAgICAgICAgIGRpY3RpZCA9IGFkbGVyMzIoZGljdGlkLCBkaWN0aW9uYXJ5LCBkaWN0TGVuZ3RoLCAwKTsKICAgICAgICAgIGlmIChkaW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MS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jb25zdGFudHMuanMKICB2YXIgcmVxdWlyZV9jb25zdGFudHMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY29uc3RhbnRzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgbW9kdWxlMi5leHBvcnRzID0gewogICAgICAgIFpfTk9fRkxVU0g6IDAsCiAgICAgICAgWl9QQVJUSUFMX0ZMVVNIOiAxLAogICAgICAgIFpfU1lOQ19GTFVTSDogMiwKICAgICAgICBaX0ZVTExfRkxVU0g6IDMsCiAgICAgICAgWl9GSU5JU0g6IDQsCiAgICAgICAgWl9CTE9DSzogNSwKICAgICAgICBaX1RSRUVTOiA2LAogICAgICAgIFpfT0s6IDAsCiAgICAgICAgWl9TVFJFQU1fRU5EOiAxLAogICAgICAgIFpfTkVFRF9ESUNUOiAyLAogICAgICAgIFpfRVJSTk86IC0xLAogICAgICAgIFpfU1RSRUFNX0VSUk9SOiAtMiwKICAgICAgICBaX0RBVEFfRVJST1I6IC0zLAogICAgICAgIFpfQlVGX0VSUk9SOiAtNSwKICAgICAgICBaX05PX0NPTVBSRVNTSU9OOiAwLAogICAgICAgIFpfQkVTVF9TUEVFRDogMSwKICAgICAgICBaX0JFU1RfQ09NUFJFU1NJT046IDksCiAgICAgICAgWl9ERUZBVUxUX0NPTVBSRVNTSU9OOiAtMSwKICAgICAgICBaX0ZJTFRFUkVEOiAxLAogICAgICAgIFpfSFVGRk1BTl9PTkxZOiAyLAogICAgICAgIFpfUkxFOiAzLAogICAgICAgIFpfRklYRUQ6IDQsCiAgICAgICAgWl9ERUZBVUxUX1NUUkFURUdZOiAwLAogICAgICAgIFpfQklOQVJZOiAwLAogICAgICAgIFpfVEVYVDogMSwKICAgICAgICBaX1VOS05PV046IDIsCiAgICAgICAgWl9ERUZMQVRFRDogOAogICAgICB9OwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvZ3poZWFkZXIuanMKICB2YXIgcmVxdWlyZV9nemhlYWRlciA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIEdaaGVhZGVyKCkgewogICAgICAgIHRoaXMudGV4dCA9IDA7CiAgICAgICAgdGhpcy50aW1lID0gMDsKICAgICAgICB0aGlzLnhmbGFncyA9IDA7CiAgICAgICAgdGhpcy5vcyA9IDA7CiAgICAgICAgdGhpcy5leHRyYSA9IG51bGw7CiAgICAgICAgdGhpcy5leHRyYV9sZW4gPSAwOwogICAgICAgIHRoaXMubmFtZSA9ICIiOwogICAgICAgIHRoaXMuY29tbWVudCA9ICIiOwogICAgICAgIHRoaXMuaGNyYyA9IDA7CiAgICAgICAgdGhpcy5kb25lID0gZmFsc2U7CiAgICAgIH0KICAgICAgbW9kdWxlMi5leHBvcnRzID0gR1poZWFkZXI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvaW5mbGF0ZS5qcwogIHZhciByZXF1aXJlX2luZmxhdGUyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi9pbmZsYXRlLmpzIihleHBvcnRzMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHpsaWJfaW5mbGF0ZSA9IHJlcXVpcmVfaW5mbGF0ZSgpOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgc3RyaW5ncyA9IHJlcXVpcmVfc3RyaW5ncygpOwogICAgICB2YXIgYyA9IHJlcXVpcmVfY29uc3RhbnRzKCk7CiAgICAgIHZhciBtc2cgPSByZXF1aXJlX21lc3NhZ2VzKCk7CiAgICAgIHZhciBaU3RyZWFtID0gcmVxdWlyZV96c3RyZWFtKCk7CiAgICAgIHZhciBHWmhlYWRlciA9IHJlcXVpcmVfZ3poZWFkZXIoKTsKICAgICAgdmFyIHRvU3RyaW5nID0gT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZzsKICAgICAgZnVuY3Rpb24gSW5mbGF0ZTIob3B0aW9ucykgewogICAgICAgIGlmICghKHRoaXMgaW5zdGFuY2VvZiBJbmZsYXRlMikpCiAgICAgICAgICByZXR1cm4gbmV3IEluZmxhdGUyKG9wdGlvbnMpOwogICAgICAgIHRoaXMub3B0aW9ucyA9IHV0aWxzLmFzc2lnbih7CiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMCwKICAgICAgICAgIHRvOiAiIgogICAgICAgIH0sIG9wdGlvbnMgfHwge30pOwogICAgICAgIHZhciBvcHQgPSB0aGlzLm9wdGlvbnM7CiAgICAgICAgaWYgKG9wdC5yYXcgJiYgb3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2KSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC1vcHQud2luZG93Qml0czsKICAgICAgICAgIGlmIChvcHQud2luZG93Qml0cyA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyA9IC0xNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID49IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNiAmJiAhKG9wdGlvbnMgJiYgb3B0aW9ucy53aW5kb3dCaXRzKSkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMzI7CiAgICAgICAgfQogICAgICAgIGlmIChvcHQud2luZG93Qml0cyA+IDE1ICYmIG9wdC53aW5kb3dCaXRzIDwgNDgpIHsKICAgICAgICAgIGlmICgob3B0LndpbmRvd0JpdHMgJiAxNSkgPT09IDApIHsKICAgICAgICAgICAgb3B0LndpbmRvd0JpdHMgfD0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQud2luZG93Qml0cyk7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IobXNnW3N0YXR1c10pOwogICAgICAgIH0KICAgICAgICB0aGlzLmhlYWRlciA9IG5ldyBHWmhlYWRlcigpOwogICAgICAgIHpsaWJfaW5mbGF0ZS5pbmZsYXRlR2V0SGVhZGVyKHRoaXMuc3RybSwgdGhpcy5oZWFkZXIpOwogICAgICAgIGlmIChvcHQuZGljdGlvbmFyeSkgewogICAgICAgICAgaWYgKHR5cGVvZiBvcHQuZGljdGlvbmFyeSA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgb3B0LmRpY3Rpb25hcnkgPSBzdHJpbmdzLnN0cmluZzJidW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AgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3MuYmluc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfaW5mbGF0ZS5pbmZsYXRlKHN0cm0sIGMuWl9OT19GTFVTSCk7CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfTkVFRF9ESUNUICYmIGRpY3Rpb25hcnkpIHsKICAgICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVTZXREaWN0aW9uYXJ5KHRoaXMuc3RybSwgZGljdGlvbmFyeSk7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfQlVGX0VSUk9SICYmIGFsbG93QnVmRXJyb3IgPT09IHRydWUpIHsKICAgICAgICAgICAgc3RhdHVzID0gYy5aX09LOwogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IGMuWl9PSykgewogICAgICAgICAgICB0aGlzLm9uRW5kKHN0YXR1cyk7CiAgICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5uZXh0X291dCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDAgfHwgc3RhdHVzID09PSBjLlpfU1RSRUFNX0VORCB8fCBzdHJtLmF2YWlsX2luID09PSAwICYmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCB8fCBfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpKSB7CiAgICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICAgIG5leHRfb3V0X3V0ZjggPSBzdHJpbmdzLnV0Zjhib3JkZXIoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpOwogICAgICAgICAgICAgICAgdGFpbCA9IHN0cm0ubmV4dF9vdXQgLSBuZXh0X291dF91dGY4OwogICAgICAgICAgICAgICAgdXRmOHN0ciA9IHN0cmluZ3MuYnVmMnN0cmluZyhzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCk7CiAgICAgICAgICAgICAgICBzdHJtLm5leHRfb3V0ID0gdGFpbDsKICAgICAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplIC0gdGFpbDsKICAgICAgICAgICAgICAgIGlmICh0YWlsKSB7CiAgICAgICAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzdHJtLm91dHB1dCwgbmV4dF9vdXRfdXRmOCwgdGFpbCwgMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGY4c3RyKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdGhpcy5vbkRhdGEodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc3RybS5hdmFpbF9pbiA9PT0gMCAmJiBzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBhbGxvd0J1ZkVycm9yID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoc3RybS5hdmFpbF9pbiA+IDAgfHwgc3RybS5hdmFpbF9vdXQgPT09IDApICYmIHN0YXR1cyAhPT0gYy5aX1NUUkVBTV9FTkQpOwogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EKSB7CiAgICAgICAgICBfbW9kZSA9IGMuWl9GSU5JU0g7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gYy5aX09LOwogICAgICAgIH0KICAgICAgICBpZiAoX21vZGUgPT09IGMuWl9TWU5DX0ZMVVNIKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKGMuWl9PSyk7CiAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBJbmZsYXRlMi5wcm90b3R5cGUub25FbmQgPSBmdW5jdGlvbihzdGF0dXMpIHsKICAgICAgICBpZiAoc3RhdHVzID09PSBjLlpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gaW5mbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBpbmZsYXRvciA9IG5ldyBJbmZsYXRlMihvcHRpb25zKTsKICAgICAgICBpbmZsYXRvci5wdXNoKGlucHV0LCB0cnVlKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBpbmZsYXRvci5tc2cgfHwgbXNnW2luZmxhdG9yLmVycl07CiAgICAgICAgfQogICAgICAgIHJldHVybiBpbmZsYXRvci5yZXN1bHQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZVJhdyhpbnB1dCwgb3B0aW9ucykgewogICAgICAgIG9wdGlvbnMgPSBvcHRpb25zIHx8IHt9OwogICAgICAgIG9wdGlvbnMucmF3ID0gdHJ1ZTsKICAgICAgICByZXR1cm4gaW5mbGF0ZShpbnB1dCwgb3B0aW9ucyk7CiAgICAgIH0KICAgICAgZXhwb3J0czIuSW5mbGF0ZSA9IEluZmxhdGUyOwogICAgICBleHBvcnRzMi5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wogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBMb25nNDsKICAgICAgdmFyIHdhc20gPSBudWxsOwogICAgICB0cnkgewogICAgICAgIHdhc20gPSBuZXcgV2ViQXNzZW1ibHkuSW5zdGFuY2UobmV3IFdlYkFzc2VtYmx5Lk1vZHVsZShuZXcgVWludDhBcnJheShbCiAgICAgICAgICAwLAogICAgICAgICAgOTcsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEzLAogICAgICAgICAgMiwKICAgICAgICAgIDk2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICA5NiwKICAgICAgICAgIDQsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMywKICAgICAgICAgIDcsCiAgICAgICAgICA2LAogICAgICAgICAgMCwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgNiwKICAgICAgICAgIDYsCiAgICAgICAgICAxLAogICAgICAgICAgMTI3LAogICAgICAgICAgMSwKICAgICAgICAgIDY1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgNywKICAgICAgICAgIDUwLAogICAgICAgICAgNiwKICAgICAgICAgIDMsCiAgICAgICAgICAxMDksCiAgICAgICAgICAxMTcsCiAgICAgICAgICAxMDgsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDUsCiAgICAgICAgICAxMDAsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMTgsCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICAyLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDMsCiAgICAgICAgICA1LAogICAgICAgICAgMTE0LAogICAgICAgICAgMTAxLAogICAgICAgICAgMTA5LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTUsCiAgICAgICAgICAwLAogICAgICAgICAgNCwKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNywKICAgICAgICAgIDAsCiAgICAgICAgICA1LAogICAgICAgICAgOCwKICAgICAgICAgIDEwMywKICAgICAgICAgIDEwMSwKICAgICAgICAgIDExNiwKICAgICAgICAgIDk1LAogICAgICAgICAgMTA0LAogICAgICAgICAgMTA1LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTA0LAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxMCwKICAgICAgICAgIDE5MSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNCwKICAgICAgICAgIDAsCiAgICAgICAgICAzNSwKICAgICAgICAgIDAsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyNywKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEyOSwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMSwKICAgICAgICAgIDM2LAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDAsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMzIsCiAgICAgICAgICAyLAogICAgICAgICAgMTczLAogICAgICAgICAgMzIsCiAgICAgICAgICAzLAogICAgICAgICAgMTczLAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNCwKICAgICAgICAgIDEzMiwKICAgICAgICAgIDEzMCwKICAgICAgICAgIDM0LAogICAgICAgICAgNCwKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzUsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAzNiwKICAgICAgICAgIDAsCiAgICAgICAgICAzMiwKICAgICAgICAgIDQsCiAgICAgICAgICAxNjcsCiAgICAgICAgICAxMQogICAgICAgIF0pKSwge30pLmV4cG9ydHM7CiAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgfQogICAgICBmdW5jdGlvbiBMb25nNChsb3csIGhpZ2gsIHVuc2lnbmVkKSB7CiAgICAgICAgdGhpcy5sb3cgPSBsb3cgfCAwOwogICAgICAgIHRoaXMuaGlnaCA9IGhpZ2ggfCAwOwogICAgICAgIHRoaXMudW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICB9CiAgICAgIExvbmc0LnByb3RvdHlwZS5fX2lzTG9uZ19fOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoTG9uZzQucHJvdG90eXBlLCAiX19pc0xvbmdfXyIsIHsgdmFsdWU6IHRydWUgfSk7CiAgICAgIGZ1bmN0aW9uIGlzTG9uZyhvYmopIHsKICAgICAgICByZXR1cm4gKG9iaiAmJiBvYmpbIl9faXNMb25nX18iXSkgPT09IHRydWU7CiAgICAgIH0KICAgICAgTG9uZzQuaXNMb25nID0gaXNMb25nOwogICAgICB2YXIgSU5UX0NBQ0hFID0ge307CiAgICAgIHZhciBVSU5UX0NBQ0hFID0ge307CiAgICAgIGZ1bmN0aW9uIGZyb21JbnQodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgdmFyIG9iaiwgY2FjaGVkT2JqLCBjYWNoZTsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIHZhbHVlID4+Pj0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IDAgPD0gdmFsdWUgJiYgdmFsdWUgPCAyNTYpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gVUlOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCAodmFsdWUgfCAwKSA8IDAgPyAtMSA6IDAsIHRydWUpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBVSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHZhbHVlIHw9IDA7CiAgICAgICAgICBpZiAoY2FjaGUgPSAtMTI4IDw9IHZhbHVlICYmIHZhbHVlIDwgMTI4KSB7CiAgICAgICAgICAgIGNhY2hlZE9iaiA9IElOVF9DQUNIRVt2YWx1ZV07CiAgICAgICAgICAgIGlmIChjYWNoZWRPYmopCiAgICAgICAgICAgICAgcmV0dXJuIGNhY2hlZE9iajsKICAgICAgICAgIH0KICAgICAgICAgIG9iaiA9IGZyb21CaXRzKHZhbHVlLCB2YWx1ZSA8IDAgPyAtMSA6IDAsIGZhbHNlKTsKICAgICAgICAgIGlmIChjYWNoZSkKICAgICAgICAgICAgSU5UX0NBQ0hFW3ZhbHVlXSA9IG9iajsKICAgICAgICAgIHJldHVybiBvYmo7CiAgICAgICAgfQogICAgICB9CiAgICAgIExvbmc0LmZyb21JbnQgPSBmcm9tSW50OwogICAgICBmdW5jdGlvbiBmcm9tTnVtYmVyKHZhbHVlLCB1bnNpZ25lZCkgewogICAgICAgIGlmIChpc05hTih2YWx1ZSkpCiAgICAgICAgICByZXR1cm4gdW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgaWYgKHVuc2lnbmVkKSB7CiAgICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAodmFsdWUgPj0gVFdPX1BXUl82NF9EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVU5TSUdORURfVkFMVUU7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmICh2YWx1ZSA8PSAtVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICBpZiAodmFsdWUgKyAxID49IFRXT19QV1JfNjNfREJMKQogICAgICAgICAgICByZXR1cm4gTUFYX1ZBTFVFOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPCAwKQogICAgICAgICAgcmV0dXJuIGZyb21OdW1iZXIoLXZhbHVlLCB1bnNpZ25lZCkubmVnKCk7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHZhbHVlICUgVFdPX1BXUl8zMl9EQkwgfCAwLCB2YWx1ZSAvIFRXT19QV1JfMzJfREJMIHwgMCwgdW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21OdW1iZXIgPSBmcm9tTnVtYmVyOwogICAgICBmdW5jdGlvbiBmcm9tQml0cyhsb3dCaXRzLCBoaWdoQml0cywgdW5zaWduZWQpIHsKICAgICAgICByZXR1cm4gbmV3IExvbmc0KGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUJpdHMgPSBmcm9tQml0czsKICAgICAgdmFyIHBvd19kYmwgPSBNYXRoLnBvdzsKICAgICAgZnVuY3Rpb24gZnJvbVN0cmluZyhzdHIsIHVuc2lnbmVkLCByYWRpeCkgewogICAgICAgIGlmIChzdHIubGVuZ3RoID09PSAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImVtcHR5IHN0cmluZyIpOwogICAgICAgIGlmIChzdHIgPT09ICJOYU4iIHx8IHN0ciA9PT0gIkluZmluaXR5IiB8fCBzdHIgPT09ICIrSW5maW5pdHkiIHx8IHN0ciA9PT0gIi1JbmZpbml0eSIpCiAgICAgICAgICByZXR1cm4gWkVSTzsKICAgICAgICBpZiAodHlwZW9mIHVuc2lnbmVkID09PSAibnVtYmVyIikgewogICAgICAgICAgcmFkaXggPSB1bnNpZ25lZCwgdW5zaWduZWQgPSBmYWxzZTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdW5zaWduZWQgPSAhIXVuc2lnbmVkOwogICAgICAgIH0KICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgdmFyIHA7CiAgICAgICAgaWYgKChwID0gc3RyLmluZGV4T2YoIi0iKSkgPiAwKQogICAgICAgICAgdGhyb3cgRXJyb3IoImludGVyaW9yIGh5cGhlbiIpOwogICAgICAgIGVsc2UgaWYgKHAgPT09IDApIHsKICAgICAgICAgIHJldHVybiBmcm9tU3RyaW5nKHN0ci5zdWJzdHJpbmcoMSksIHVuc2lnbmVkLCByYWRpeCkubmVnKCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDgpKTsKICAgICAgICB2YXIgcmVzdWx0ID0gWkVSTzsKICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IHN0ci5sZW5ndGg7IGkgKz0gOCkgewogICAgICAgICAgdmFyIHNpemUgPSBNYXRoLm1pbig4LCBzdHIubGVuZ3RoIC0gaSksIHZhbH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NlKTsKICAgICAgTG9uZzQuTUlOX1ZBTFVFID0gTUlOX1ZBTFVFOwogICAgICB2YXIgTG9uZ1Byb3RvdHlwZSA9IExvbmc0LnByb3RvdHlwZTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0ludCA9IGZ1bmN0aW9uIHRvSW50KCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gdGhpcy5sb3cgPj4+IDAgOiB0aGlzLmxvdzsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b051bWJlciA9IGZ1bmN0aW9uIHRvTnVtYmVyMigpIHsKICAgICAgICBpZiAodGhpcy51bnNpZ25lZCkKICAgICAgICAgIHJldHVybiAodGhpcy5oaWdoID4+PiAwKSAqIFRXT19QV1JfMzJfREJMICsgKHRoaXMubG93ID4+PiAwKTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoICogVFdPX1BXUl8zMl9EQkwgKyAodGhpcy5sb3cgPj4+IDApOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcocmFkaXgpIHsKICAgICAgICByYWRpeCA9IHJhZGl4IHx8IDEwOwogICAgICAgIGlmIChyYWRpeCA8IDIgfHwgMzYgPCByYWRpeCkKICAgICAgICAgIHRocm93IFJhbmdlRXJyb3IoInJhZGl4Iik7CiAgICAgICAgaWYgKHRoaXMuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gIjAiOwogICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICB2YXIgcmFkaXhMb25nID0gZnJvbU51bWJlcihyYWRpeCksIGRpdiA9IHRoaXMuZGl2KHJhZGl4TG9uZyksIHJlbTEgPSBkaXYubXVsKHJhZGl4TG9uZykuc3ViKHRoaXMpOwogICAgICAgICAgICByZXR1cm4gZGl2LnRvU3RyaW5nKHJhZGl4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gdGhpcy5oaWdoIDwgMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5pc1Bvc2l0aXZlID0gZnVuY3Rpb24gaXNQb3NpdGl2ZSgpIHsKICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCB8fCB0aGlzLmhpZ2ggPj0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5pc09kZCA9IGZ1bmN0aW9uIGlzT2RkKCkgewogICAgICAgIHJldHVybiAodGhpcy5sb3cgJiAxKSA9PT0gMTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5pc0V2ZW4gPSBmdW5jdGlvbiBpc0V2ZW4oKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxdWFscyA9IGZ1bmN0aW9uIGVxdWFscyhvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICBpZiAodGhpcy51bnNpZ25lZCAhPT0gb3RoZXIudW5zaWduZWQgJiYgdGhpcy5oaWdoID4+PiAzMSA9PT0gMSAmJiBvdGhlci5oaWdoID4+PiAzMSA9PT0gMSkKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSBvdGhlci5oaWdoICYmIHRoaXMubG93ID09PSBvdGhlci5sb3c7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXEgPSBMb25nUHJvdG90eXBlLmVxdWFsczsKICAgICAgTG9uZ1Byb3RvdHlwZS5ub3RFcXVhbHMgPSBmdW5jdGlvbiBub3RFcXVhbHMob3RoZXIpIHsKICAgICAgICByZXR1cm4gIXRoaXMuZXEob3RoZXIpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lcSA9IExvbmdQcm90b3R5cGUubm90RXF1YWxzOwogIC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T3JFcXVhbDsKICAgICAgTG9uZ1Byb3RvdHlwZS5jb21wYXJlID0gZnVuY3Rpb24gY29tcGFyZShvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICBpZiAodGhpcy5lcShvdGhlcikpCiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB2YXIgdGhpc05lZyA9IHRoaXMuaXNOZWdhdGl2ZSgpLCBvdGhlck5lZyA9IG90aGVyLmlzTmVnYXRpdmUoKTsKICAgICAgICBpZiAodGhpc05lZyAmJiAhb3RoZXJOZWcpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKCF0aGlzTmVnICYmIG90aGVyTmVnKQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXMuc3ViKG90aGVyKS5pc05lZ2F0aXZlKCkgPyAtMSA6IDE7CiAgICAgICAgcmV0dXJuIG90aGVyLmhpZ2ggPj4+IDAgPiB0aGlzLmhpZ2ggPj4+IDAgfHwgb3RoZXIuaGlnaCA9PT0gdGhpcy5oaWdoICYmIG90aGVyLmxvdyA+Pj4gMCA+IHRoaXMubG93ID4+PiAwID8gLTEgOiAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmNvbXAgPSBMb25nUHJvdG90eXBlLmNvbXBhcmU7CiAgICAgIExvbmdQcm90b3R5cGUubmVnYXRlID0gZnVuY3Rpb24gbmVnYXRlKCkgewogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCAmJiB0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gTUlOX1ZBTFVFOwogICAgICAgIHJldHVybiB0aGlzLm5vdCgpLmFkZChPTkUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm5lZyA9IExvbmdQcm90b3R5cGUubmVnYXRlOwogICAg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dGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPT09IC0yMTQ3NDgzNjQ4ICYmIGRpdmlzb3IubG93ID09PSAtMSAmJiBkaXZpc29yLmhpZ2ggPT09IC0xKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgICAgfQogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5kaXZfdSA6IHdhc20uZGl2X3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXMuaXNaZXJvKCkpCiAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICB2YXIgYXBwcm94LCByZW0sIHJlczsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpIHsKICAgICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuZXEoT05FKSB8fCBkaXZpc29yLmVxKE5FR19PTkUpKQogICAgICAgICAgICAgIHJldHVybiBNSU5fVkFMVUU7CiAgICAgICAgICAgIGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgICByZXR1cm4gT05FOwogICAgICAgICAgICBlbHNlIHsKICAgICAgICAgICAgICB2YXIgaGFsZlRoaXMgPSB0aGlzLnNocigxKTsKICAgICAgICAgICAgICBhcHByb3ggPSBoYWxmVGhpcy5kaXYoZGl2aXNvcikuc2hsKDEpOwogICAgICAgICAgICAgIGlmIChhcHByb3guZXEoWkVSTykpIHsKICAgICAgICAgICAgICAgIHJldHVybiBkaXZpc29yLmlzTmVnYXRpdmUoKSA/IE9ORSA6IE5FR19PTkU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlbSA9IHRoaXMuc3ViKGRpdmlzb3IubXVsKGFwcHJveCkpOwogICAgICAgICAgICAgICAgcmVzID0gYXBwcm94LmFkZChyZW0uZGl2KGRpdmlzb3IpKTsKICAgICAgICAgICAgICAgIHJldHVybiByZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuZXEoTUlOX1ZBTFVFKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMudW5zaWduZWQgPyBVWkVSTyA6IFpFUk87CiAgICAgICAgICBpZiAodGhpcy5pc05lZ2F0aXZlKCkpIHsKICAgICAgICAgICAgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLmRpdihkaXZpc29yLm5lZygpKTsKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IpLm5lZygpOwogICAgICAgICAgfSBlbHNlIGlmIChkaXZpc29yLmlzTmVnYXRpdmUoKSkKICAgICAgICAgICAgcmV0dXJuIHRoaXMuZGl2KGRpdmlzb3IubmVnKCkpLm5lZygpOwogICAgICAgICAgcmVzID0gWkVSTzsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKCFkaXZpc29yLnVuc2lnbmVkKQogICAgICAgICAgICBkaXZpc29yID0gZGl2aXNvci50b1Vuc2lnbmVkKCk7CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIFVaRVJPOwogICAgICAgICAgaWYgKGRpdmlzb3IuZ3QodGhpcy5zaHJ1KDEpKSkKICAgICAgICAgICAgcmV0dXJuIFVPTkU7CiAgICAgICAgICByZXMgPSBVWkVSTzsKICAgICAgICB9CiAgICAgICAgcmVtID0gdGhpczsKICAgICAgICB3aGlsZSAocmVtLmd0ZShkaXZpc29yKSkgewogICAgICAgICAgYXBwcm94ID0gTWF0aC5tYXgoMSwgTWF0aC5mbG9vcihyZW0udG9OdW1iZXIoKSAvIGRpdmlzb3IudG9OdW1iZXIoKSkpOwogICAgICAgICAgdmFyIGxvZzIgPSBNYXRoLmNlaWwoTWF0aC5sb2coYXBwcm94KSAvIE1hdGguTE4yKSwgZGVsdGEgPSBsb2cyIDw9IDQ4ID8gMSA6IHBvd19kYmwoMiwgbG9nMiAtIDQ4KSwgYXBwcm94UmVzID0gZnJvbU51bWJlcihhcHByb3gpLCBhcHByb3hSZW0gPSBhcHByb3hSZXMubXVsKGRpdmlzb3IpOwogICAgICAgICAgd2hpbGUgKGFwcHJveFJlbS5pc05lZ2F0aXZlKCkgfHwgYXBwcm94UmVtLmd0KHJlbSkpIHsKICAgICAgICAgICAgYXBwcm94IC09IGRlbHRhOwogICAgICAgICAgICBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICAgIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYXBwcm94UmVzLmlzWmVybygpKQogICAgICAgICAgICBhcHByb3hSZXMgPSBPTkU7CiAgICAgICAgICByZXMgPSByZXMuYWRkKGFwcHJveFJlcyk7CiAgICAgICAgICByZW0gPSByZW0uc3ViKGFwcHJveFJlbSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZGl2ID0gTG9uZ1Byb3RvdHlwZS5kaXZpZGU7CiAgICAgIExvbmdQcm90b3R5cGUubW9kdWxvID0gZnVuY3Rpb24gbW9kdWxvKGRpdmlzb3IpIHsKICAgICAgICBpZiAoIWlzTG9uZyhkaXZpc29yKSkKICAgICAgICAgIGRpdmlzb3IgPSBmcm9tVmFsdWUoZGl2aXNvcik7CiAgICAgICAgaWYgKHdhc20pIHsKICAgIC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aCwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUueG9yID0gZnVuY3Rpb24geG9yKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdyBeIG90aGVyLmxvdywgdGhpcy5oaWdoIF4gb3RoZXIuaGlnaCwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hpZnRMZWZ0ID0gZnVuY3Rpb24gc2hpZnRMZWZ0KG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBpZiAoKG51bUJpdHMgJj0gNjMpID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSBpZiAobnVtQml0cyA8IDMyKQogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IDw8IG51bUJpdHMsIHRoaXMuaGlnaCA8PCBudW1CaXRzIHwgdGhpcy5sb3cgPj4+IDMyIC0gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgZWxzZQogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKDAsIHRoaXMubG93IDw8IG51bUJpdHMgLSAzMiwgdGhpcy51bnNpZ25lZCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hsID0gTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hpZnRSaWdodCA9IGZ1bmN0aW9uIHNoaWZ0UmlnaHQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPj4+IG51bUJpdHMgfCB0aGlzLmhpZ2ggPDwgMzIgLSBudW1CaXRzLCB0aGlzLmhpZ2ggPj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgZWxzZQogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMuaGlnaCA+PiBudW1CaXRzIC0gMzIsIHRoaXMuaGlnaCA+PSAwID8gMCA6IC0xLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHIgPSBMb25nUHJvdG90eXBlLnNoaWZ0UmlnaHQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkID0gZnVuY3Rpb24gc2hpZnRSaWdodFVuc2lnbmVkKG51bUJpdHMpIHsKICAgICAgICBpZiAoaXNMb25nKG51bUJpdHMpKQogICAgICAgICAgbnVtQml0cyA9IG51bUJpdHMudG9JbnQoKTsKICAgICAgICBudW1CaXRzICY9IDYzOwogICAgICAgIGlmIChudW1CaXRzID09PSAwKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgZWxzZSB7CiAgICAgICAgICB2YXIgaGlnaCA9IHRoaXMuaGlnaDsKICAgICAgICAgIGlmIChudW1CaXRzIDwgMzIpIHsKICAgICAgICAgICAgdmFyIGxvdyA9IHRoaXMubG93OwogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93ID4+PiBudW1CaXRzIHwgaGlnaCA8PCAzMiAtIG51bUJpdHMsIGhpZ2ggPj4+IG51bUJpdHMsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgfSBlbHNlIGlmIChudW1CaXRzID09PSAzMikKICAgICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGhpZ2gsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCA+Pj4gbnVtQml0cyAtIDMyLCAwLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuc2hydSA9IExvbmdQcm90b3R5cGUuc2hpZnRSaWdodFVuc2lnbmVkOwogICAgICBMb25nUHJvdG90eXBlLnNocl91ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUudG9TaWduZWQgPSBmdW5jdGlvbiB0b1NpZ25lZCgpIHsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgZmFsc2UpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvVW5zaWduZWQgPSBmdW5jdGlvbiB0b1Vuc2lnbmVkKCkgewogICAgICAgIGlmICh0aGlzLnVuc2lnbmVkKQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93LCB0aGlzLmhpZ2gsIHRydWUpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLnRvQnl0ZXMgPSBmdW5jdGlvbiB0b0J5dGVzKGxlKSB7CiAgICAgICAgcmV0dXJuIGxlID8gdGhpcy50b0J5dGVzTEUoKSA6IHRoaXMudG9CeXRlc0JFKCk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0xFID0gZnVuY3Rpb24gdG9CeXRlc0xFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgbG8gJiAyNTUsCiAgICAg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l6ZShtZXNzYWdlKSB7CiAgICAgICAgICAgIHJldHVybiBpbXBsZW1lbnRhdGlvbi5kZXNlcmlhbGl6ZShtZXNzYWdlLCBmYWxsYmFja0Rlc2VyaWFsaXplcik7CiAgICAgICAgICB9LAogICAgICAgICAgc2VyaWFsaXplKGlucHV0KSB7CiAgICAgICAgICAgIHJldHVybiBpbXBsZW1lbnRhdGlvbi5zZXJpYWxpemUoaW5wdXQsIGZhbGxiYWNrU2VyaWFsaXplcik7CiAgICAgICAgICB9CiAgICAgICAgfTsKICAgICAgfQogICAgICBleHBvcnRzMi5leHRlbmRTZXJpYWxpemVyID0gZXh0ZW5kU2VyaWFsaXplcjsKICAgICAgdmFyIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIgPSB7CiAgICAgICAgZGVzZXJpYWxpemUobWVzc2FnZSkgewogICAgICAgICAgcmV0dXJuIE9iamVjdC5hc3NpZ24oRXJyb3IobWVzc2FnZS5tZXNzYWdlKSwgewogICAgICAgICAgICBuYW1lOiBtZXNzYWdlLm5hbWUsCiAgICAgICAgICAgIHN0YWNrOiBtZXNzYWdlLnN0YWNrCiAgICAgICAgICB9KTsKICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShlcnJvcikgewogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgX19lcnJvcl9tYXJrZXI6ICIkJGVycm9yIiwKICAgICAgICAgICAgbWVzc2FnZTogZXJyb3IubWVzc2FnZSwKICAgICAgICAgICAgbmFtZTogZXJyb3IubmFtZSwKICAgICAgICAgICAgc3RhY2s6IGVycm9yLnN0YWNrCiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgfTsKICAgICAgdmFyIGlzU2VyaWFsaXplZEVycm9yID0gKHRoaW5nKSA9PiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmICJfX2Vycm9yX21hcmtlciIgaW4gdGhpbmcgJiYgdGhpbmcuX19lcnJvcl9tYXJrZXIgPT09ICIkJGVycm9y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uZGVmaW5lUHJvcGVydHkoZXhwb3J0czIsICJfX2VzTW9kdWxlIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZXhwb3J0czIuVHJhbnNmZXIgPSBleHBvcnRzMi5pc1RyYW5zZmVyRGVzY3JpcHRvciA9IHZvaWQgMDsKICAgICAgdmFyIHN5bWJvbHNfMSA9IHJlcXVpcmVfc3ltYm9scygpOwogICAgICBmdW5jdGlvbiBpc1RyYW5zZmVyYWJsZSh0aGluZykgewogICAgICAgIGlmICghdGhpbmcgfHwgdHlwZW9mIHRoaW5nICE9PSAib2JqZWN0IikKICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfQogICAgICBmdW5jdGlvbiBpc1RyYW5zZmVyRGVzY3JpcHRvcih0aGluZykgewogICAgICAgIHJldHVybiB0aGluZyAmJiB0eXBlb2YgdGhpbmcgPT09ICJvYmplY3QiICYmIHRoaW5nW3N5bWJvbHNfMS4kdHJhbnNmZXJhYmxlXTsKICAgICAgfQogICAgICBleHBvcnRzMi5pc1RyYW5zZmVyRGVzY3JpcHRvciA9IGlzVHJhbnNmZXJEZXNjcmlwdG9yOwogICAgICBmdW5jdGlvbiBUcmFuc2ZlcjIocGF5bG9hZCwgdHJhbnNmZXJhYmxlcykgewogICAgICAgIGlmICghdHJhbnNmZXJhYmxlcykgewogICAgICAgICAgaWYgKCFpc1RyYW5zZmVyYWJsZShwYXlsb2FkKSkKICAgICAgICAgICAgdGhyb3cgRXJyb3IoKTsKICAgICAgICAgIHRyYW5zZmVyYWJsZXMgPSBbcGF5bG9hZF07CiAgICAgICAgfQogICAgICAgIHJldHVybiB7CiAgICAgICAgICBbc3ltYm9sc18xLiR0cmFuc2ZlcmFibGVdOiB0cnVlLAogICAgICAgICAgc2VuZDogcGF5bG9hZCwKICAgICAgICAgIHRyYW5zZmVyYWJsZXMKICAgICAgICB9OwogICAgICB9CiAgICAgIGV4cG9ydHMyLlRyYW5zZm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cHRzLm92ZXJyaWRlcykgewogICAgICAgIHRoaXMuYmFzZU92ZXJyaWRlcyA9IG9wdHMub3ZlcnJpZGVzOwogICAgICB9CiAgICAgIHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbiA9IGZldGNoOwogICAgfQogICAgYXN5bmMgZmV0Y2goaW5wdXQsIGluaXQyKSB7CiAgICAgIGxldCByZXNwb25zZTsKICAgICAgdHJ5IHsKICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgaW5pdDIpOwogICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgaWYgKGAke2V9YC5pbmNsdWRlcygiRmFpbGVkIHRvIGZldGNoIikpIHsKICAgICAgICAgIGNvbnNvbGUud2FybihgZ2VuZXJpYy1maWxlaGFuZGxlOiByZWZldGNoaW5nICR7aW5wdXR9IHRvIGF0dGVtcHQgdG8gd29yayBhcm91bmQgY2hyb21lIENPUlMgaGVhZGVyIGNhY2hpbmcgYnVnYCk7CiAgICAgICAgICByZXNwb25zZSA9IGF3YWl0IHRoaXMuZmV0Y2hJbXBsZW1lbnRhdGlvbihpbnB1dCwgewogICAgICAgICAgICAuLi5pbml0MiwKICAgICAgICAgICAgY2FjaGU6ICJyZWxvYWQiCiAgICAgICAgICB9KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHJlc3BvbnNlOwogICAgfQogICAgYXN5bmMgcmVhZChidWZmZXIsIG9mZnNldCA9IDAsIGxlbmd0aCwgcG9zaXRpb24gPSAwLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgeyBoZWFkZXJzID0ge30sIHNpZ25hbCwgb3ZlcnJpZGVzID0ge30gfSA9IG9wdHM7CiAgICAgIGlmIChsZW5ndGggPCBJbmZpbml0eSkgewogICAgICAgIGhlYWRlcnMucmFuZ2UgPSBgYnl0ZXM9JHtwb3Np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gPSBvcHRzOwogICAgICBjb25zdCBhcmdzID0gewogICAgICAgIGhlYWRlcnMsCiAgICAgICAgbWV0aG9kOiAiR0VUIiwKICAgICAgICByZWRpcmVjdDogImZvbGxvdyIsCiAgICAgICAgbW9kZTogImNvcnMiLAogICAgICAgIHNpZ25hbCwKICAgICAgICAuLi50aGlzLmJhc2VPdmVycmlkZXMsCiAgICAgICAgLi4ub3ZlcnJpZGVzCiAgICAgIH07CiAgICAgIGNvbnN0IHJlc3BvbnNlID0gYXdhaXQgdGhpcy5mZXRjaCh0aGlzLnVybCwgYXJncyk7CiAgICAgIGlmICghcmVzcG9uc2UpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoImdlbmVyaWMtZmlsZWhhbmRsZSBmYWlsZWQgdG8gZmV0Y2giKTsKICAgICAgfQogICAgICBpZiAocmVzcG9uc2Uuc3RhdHVzICE9PSAyMDApIHsKICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcihgSFRUUCAke3Jlc3BvbnNlLnN0YXR1c30gZmV0Y2hpbmcgJHt0aGlzLnVybH1gKSwgewogICAgICAgICAgc3RhdHVzOiByZXNwb25zZS5zdGF0dXMKICAgICAgICB9KTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IikgewogICAgICAgIHJldHVybiByZXNwb25zZS50ZXh0KCk7CiAgICAgIH0KICAgICAgaWYgKGVuY29kaW5nKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKGB1bnN1cHBvcnRlZCBlbmNvZGluZzogJHtlbmNvZGluZ31gKTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5nZXRCdWZmZXJGcm9tUmVzcG9uc2UocmVzcG9uc2UpOwogICAgfQogICAgYXN5bmMgc3RhdCgpIHsKICAgICAgaWYgKCF0aGlzLl9zdGF0KSB7CiAgICAgICAgY29uc3QgYnVmID0gaW1wb3J0X2J1ZmZlcjIuQnVmZmVyLmFsbG9jVW5zYWZlKD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CiAgfQogIGZ1bmN0aW9uIGNhbk1lcmdlQmxvY2tzKGNodW5rMSwgY2h1bmsyKSB7CiAgICByZXR1cm4gY2h1bmsyLm1pbnYuYmxvY2tQb3NpdGlvbiAtIGNodW5rMS5tYXh2LmJsb2NrUG9zaXRpb24gPCA2NWUzICYmIGNodW5rMi5tYXh2LmJsb2NrUG9zaXRpb24gLSBjaHVuazEubWludi5ibG9ja1Bvc2l0aW9uIDwgNWU2OwogIH0KICBmdW5jdGlvbiBvcHRpbWl6ZUNodW5rcyhjaHVua3MsIGxvd2VzdCkgewogICAgY29uc3QgbWVyZ2VkQ2h1bmtzID0gW107CiAgICBsZXQgbGFzdENodW5rID0gbnVsbDsKICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAwKSB7CiAgICAgIHJldHVybiBjaHVua3M7CiAgICB9CiAgICBjaHVua3Muc29ydChmdW5jdGlvbihjMCwgYzEpIHsKICAgICAgY29uc3QgZGlmID0gYzAubWludi5ibG9ja1Bvc2l0aW9uIC0gYzEubWludi5ibG9ja1Bvc2l0aW9uOwogICAgICBpZiAoZGlmICE9PSAwKSB7CiAgICAgICAgcmV0dXJuIGRpZjsKICAgICAgfSBlbHNlIHsKICAgICAgICByZXR1cm4gYzAubWludi5kYXRhUG9zaXRpb24gLSBjMS5taW52LmRhdGFQb3NpdGlvbjsKICAgICAgfQogICAgfSk7CiAgICBjaHVua3MuZm9yRWFjaCgoY2h1bmspID0+IHsKICAgICAgaWYgKCFsb3dlc3QgfHwgY2h1bmsubWF4di5jb21wYXJlVG8obG93ZXN0KSA+IDApIHsKICAgICAgICBpZiAobGFzdENodW5rID09PSBudWxsKSB7CiAgICAgICAgICBtZXJnZWRDaHVua3MucHVzaChjaHVuayk7CiAgICAgICAgICBsYXN0Q2h1bmsgPSBjaHVuazsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKGNhbk1lcmdlQmxvY2tzKGxhc3RDaHVuaywgY2h1bmspKSB7CiAgICAgICAgICAgIGlmIChj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SB7CiAgICAgICAgICBjb25zdCBiaW4gPSBieXRlcy5yZWFkVUludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICBpZiAoYmluID4gbWF4QmluTnVtYmVyICsgMSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoInRhYml4IGluZGV4IGNvbnRhaW5zIHRvbyBtYW55IGJpbnMsIHBsZWFzZSB1c2UgYSBDU0kgaW5kZXgiKTsKICAgICAgICAgIH0gZWxzZSBpZiAoYmluID09PSBtYXhCaW5OdW1iZXIgKyAxKSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBpZiAoY2h1bmtDb3VudCA9PT0gMikgewogICAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNiAqIGNodW5rQ291bnQ7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIHUpOwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxpbmVhckNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGxpbmVhckluZGV4ID0gbmV3IEFycmF5KGxpbmVhckNvdW50KTsKICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGxpbmVhckNvdW50OyBrICs9IDEpIHsKICAgICAgICAgIGxpbmVhckluZGV4W2tdID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgIGN1cnJPZmZzZXQgKz0gODsKICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxpbmVhckluZGV4W2tdKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHsgYmluSW5kZXgsIGxpbmVhckluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICBpbmRpY2VzLAogICAgICAgIG1ldGFDaGFyLAogICAgICAgIG1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgsCiAgICAgICAgc2tpcExpbmVzLAogICAgICAgIGZpcnN0RGF0YUxpbmUsCiAgICAgICAgY29sdW1uTnVtYmVycywKICAgICAgICBjb29yZGluYXRlVHlwZSwKICAgICAgICBmb3JtYXQsCiAgICAgICAgcmVmSWRUb05hbWUsCiAgICAgICAgcmVmTmFtZVRvSWQsCiAgIC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FRvTmFtZSB9OwogICAgfQogICAgYXN5bmMgYmxvY2tzRm9yUmFuZ2UocmVmTmFtZSwgbWluLCBtYXgsIG9wdHMgPSB7fSkgewogICAgICBpZiAobWluIDwgMCkgewogICAgICAgIG1pbiA9IDA7CiAgICAgIH0KICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGJhID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWJhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IG1pbk9mZnNldCA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4W21pbiA+PiBUQURfTElEWF9TSElGVCA+PSBiYS5saW5lYXJJbmRleC5sZW5ndGggPyBiYS5saW5lYXJJbmRleC5sZW5ndGggLSAxIDogbWluID4+IFRBRF9MSURYX1NISUZUXSA6IG5ldyBWaXJ0dWFsT2Zmc2V0KDAsIDApOwogICAgICBpZiAoIW1pbk9mZnNldCkgewogICAgICAgIGNvbnNvbGUud2FybigicXVlcnlpbmcgb3V0c2lkZSBvZiBwb3NzaWJsZSB0YWJpeCByYW5nZSIpOwogICAgICB9CiAgICAgIGNvbnN0IG92ZXJsYXBwaW5nQmlucyA9IHJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBjb25zdCBuaW50diA9IGJhLmxpbmVhckluZGV4Lmxlbmd0aDsKICAgICAgbGV0IGxvd2VzdCA9IG51bGw7CiAgICAgIGNvbnN0IG1pbkxpbiA9IE1hdGgubWluKG1pbiA+PiAxNCwgbmludHYgLSAxKTsKICAgICAgY29uc3QgbWF4TGluID0gTWF0aC5taW4obWF4ID4+IDE0LCBuaW50diAtIDEpOwogICAgICBmb3IgKGxldCBpID0gbWluTGluOyBpIDw9IG1heExpbjsgKytpKSB7CiAgICAgICAgY29uc3QgdnAgPSBiYS5saW5lYXJJbmRleFtpXTsKICAgICAgICBpZiAodnApIHsKICAgICAgICAgIGlmICghbG93ZXN0IHx8IHZwLmNvbXBhcmVUbyhsb3dlc3QpIDwgMCkgewogICAgICAgICAgICBsb3dlc3QgPSB2cDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIG9wdGltaXplQ2h1bmtzKGNodW5rcywgbG93ZXN0KTsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vY3NpLmpzCiAgaW5pdF9idWZmZXJfc2hpbSgpOwogIHZhciBpbXBvcnRfbG9uZzMgPSBfX3RvTW9kdWxlKHJlcXVpcmVfbG9uZygpKTsKICB2YXIgQ1NJMV9NQUdJQyA9IDIxNTgyNjU5OwogIHZhciBDU0kyX01BR0lDID0gMzgzNTk4NzU7CiAgZnVuY3Rpb24gbHNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIG51bSAqIDIgKiogYml0czsKICB9CiAgZnVuY3Rpb24gcnNoaWZ0KG51bSwgYml0cykgewogICAgcmV0dXJuIE1hdGguZmxvb3IobnVtIC8gMiAqKiBiaXRzKTsKICB9CiAgdmFyIENTSSA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGNvbnN0cnVjdG9yKGFyZ3MpIHsKICAgICAgc3VwZXIoYXJncyk7CiAgICAgIHRoaXMubWF4QmluTnVtYmVyID0gMDsKICAgICAgdGhpcy5kZXB0aCA9IDA7CiAgICAgIHRoaXMubWluU2hpZnQgPSAwOwogICAgfQogICAgYXN5bmMgbGluZUNvdW50KHJlZk5hbWUsIG9wdHMgPSB7fSkgewogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgaWR4ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoIWlkeCkgewogICAgICAgIHJldHVybiAtMTsKICAgICAgfQogICAgICBjb25zdCB7IHN0YXRzIH0gPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmIChzdGF0cykgewogICAgICAgIHJldHVybiBzdGF0cy5saW5lQ291bnQ7CiAgICAgIH0KICAgICAgcmV0dXJuIC0xOwogICAgfQogICAgYXN5bmMgaW5kZXhDb3YoKSB7CiAgICAgIHRocm93IG5ldyBFcnJvcigiQ1NJIGluZGV4ZXMgZG8gbm90IHN1cHBvcnQgaW5kZXhjb3YiKTsKICAgIH0KICAgIHBhcnNlQXV4RGF0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U5hbWVCeXRlcyhieXRlcy5zbGljZShvZmZzZXQgKyAyOCwgb2Zmc2V0ICsgMjggKyBuYW1lU2VjdGlvbkxlbmd0aCkpOwogICAgICByZXR1cm4gewogICAgICAgIHJlZklkVG9OYW1lLAogICAgICAgIHJlZk5hbWVUb0lkLAogICAgICAgIHNraXBMaW5lcywKICAgICAgICBtZXRhQ2hhciwKICAgICAgICBjb2x1bW5OdW1iZXJzLAogICAgICAgIGZvcm1hdCwKICAgICAgICBjb29yZGluYXRlVHlwZQogICAgICB9OwogICAgfQogICAgX3BhcnNlTmFtZUJ5dGVzKG5hbWVzQnl0ZXMpIHsKICAgICAgbGV0IGN1cnJSZWZJZCA9IDA7CiAgICAgIGxldCBjdXJyTmFtZVN0YXJ0ID0gMDsKICAgICAgY29uc3QgcmVmSWRUb05hbWUgPSBbXTsKICAgICAgY29uc3QgcmVmTmFtZVRvSWQgPSB7fTsKICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBuYW1lc0J5dGVzLmxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgaWYgKCFuYW1lc0J5dGVzW2ldKSB7CiAgICAgICAgICBpZiAoY3Vyck5hbWVTdGFydCA8IGkpIHsKICAgICAgICAgICAgbGV0IHJlZk5hbWUgPSBuYW1lc0J5dGVzLnRvU3RyaW5nKCJ1dGY4IiwgY3Vyck5hbWVTdGFydCwgaSk7CiAgICAgICAgICAgIHJlZk5hbWUgPSB0aGlzLnJlbmFtZVJlZlNlcShyZWZOYW1lKTsKICAgICAgICAgICAgcmVmSWRUb05hbWVbY3VyclJlZklkXSA9IHJlZk5hbWU7CiAgICAgICAgICAgIHJlZk5hbWVUb0lkW3JlZk5hbWVdID0gY3VyclJlZklkOwogICAgICAgICAgfQogICAgICAgICAgY3Vyck5hbWVTdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VyclJlZklkICs9IDE7CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHJlZk5hbWVUb0lkLCByZWZJZF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B9LAogICAgICAgIGNvb3JkaW5hdGVUeXBlOiAiemVyby1iYXNlZC1oYWxmLW9wZW4iLAogICAgICAgIGZvcm1hdDogImdlbmVyaWMiCiAgICAgIH07CiAgICAgIGNvbnN0IHJlZkNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoMTYgKyBhdXhMZW5ndGgpOwogICAgICBsZXQgZmlyc3REYXRhTGluZTsKICAgICAgbGV0IGN1cnJPZmZzZXQgPSAxNiArIGF1eExlbmd0aCArIDQ7CiAgICAgIGNvbnN0IGluZGljZXMgPSBuZXcgQXJyYXkocmVmQ291bnQpLmZpbGwoMCkubWFwKCgpID0+IHsKICAgICAgICBjb25zdCBiaW5Db3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgIGN1cnJPZmZzZXQgKz0gNDsKICAgICAgICBjb25zdCBiaW5JbmRleCA9IHt9OwogICAgICAgIGxldCBzdGF0czsKICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IGJpbkNvdW50OyBqICs9IDEpIHsKICAgICAgICAgIGNvbnN0IGJpbiA9IGJ5dGVzLnJlYWRVSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgIGlmIChiaW4gPiB0aGlzLm1heEJpbk51bWJlcikgewogICAgICAgICAgICBzdGF0cyA9IHRoaXMucGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIGN1cnJPZmZzZXQgKyA0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0ICsgOCArIDQgKyAxNiArIDE2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY29uc3QgbG9mZnNldCA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBmaXJzdERhdGFMaW5lID0gdGhpcy5fZmluZEZpcnN0RGF0YShmaXJzdERhdGFMaW5lLCBsb2Zmc2V0KTsKICAgICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQgKyAxMik7CiAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgIGNvbnN0IGNodW5rcyA9IG5ldyBBcnJheShjaHVua0NvdW50KTsKICAgICAgICAgICAgZm9yIChsZXQgayA9IDA7IGsgPCBjaHVua0NvdW50OyBrICs9IDEpIHsKICAgICAgICAgICAgICBjb25zdCB1ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgICBjb25zdCB2ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgOCk7CiAgICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgICBjaHVua3Nba10gPSBuZXcgQ2h1bmsodSwgdiwgYmluKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBiaW5JbmRleFtiaW5dID0gY2h1bmtzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgc3RhdHMgfTsKICAgICAgfSk7CiAgICAgIHJldHVybiB7CiAgICAgICAgLi4uYXV4LAogICAgICAgIGNzaTogdHJ1ZSwKICAgICAgICByZWZDb3VudCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjc2lWZXJzaW9uLAogICAgICAgIGluZGljZXMsCiAgICAgICAgZGVwdGg6IHRoaXMuZGVwdGgsCiAgICAgICAgbWF4QmluTnVtYmVyOiB0aGlzLm1heEJpbk51bWJlciwKICAgICAgICBtYXhSZWZMZW5ndGgKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMy5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDI4LCBvZmZzZXQgKyAzNiksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gdGhpcy5yZWcyYmlucyhtaW4sIG1heCk7CiAgICAgIGNvbnN0IGNodW5rcyA9IFtdOwogICAgICBmb3IgKGNvbnN0IFtzdGFydCwgZW5kXSBvZiBvdmVybGFwcGluZ0JpbnMpIHsKICAgICAgICBmb3IgKGxldCBiaW4gPSBzdGFydDsgYmluIDw9IGVuZDsgYmluKyspIHsKICAgICAgICAgIGlmIChiYS5iaW5JbmRleFtiaW5dKSB7CiAgICAgICAgICAgIGNvbnN0IGJpbkNodW5rcyA9IGJhLmJpbkluZGV4W2Jpbl07CiAgICAgICAgICAgIGZvciAobGV0IGMgPSAwOyBjIDwgYmluQ2h1bmtzLmxlbmd0aDsgKytjKSB7CiAgICAgICAgICAgICAgY2h1bmtzLnB1c2gobmV3IENodW5rKGJpbkNodW5rc1tjXS5taW52LCBiaW5DaHVua3NbY10ubWF4diwgYmluKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICA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oaXMueWllbGRUaW1lID0geWllbGRUaW1lOwogICAgICB0aGlzLmNodW5rQ2FjaGUgPSBuZXcgaW1wb3J0X2Fib3J0YWJsZV9wcm9taXNlX2NhY2hlLmRlZmF1bHQoewogICAgICAgIGNhY2hlOiBuZXcgaW1wb3J0X3F1aWNrX2xydS5kZWZhdWx0KHsgbWF4U2l6ZTogTWF0aC5mbG9vcihjaHVua0NhY2hlU2l6ZSAvICgxIDw8IDE2KSkgfSksCiAgICAgICAgZmlsbDogKGFyZ3MsIHNpZ25hbCkgPT4gdGhpcy5yZWFkQ2h1bmsoYXJncywgeyBzaWduYWwgfSkKICAgICAgfSk7CiAgICB9CiAgICBhc3luYyBnZXRMaW5lcyhyZWZOYW1lLCBzdGFydCwgZW5kLCBvcHRzKSB7CiAgICAgIGxldCBzaWduYWw7CiAgICAgIGxldCBvcHRpb25zID0ge307CiAgICAgIGxldCBjYWxsYmFjazsKICAgICAgaWYgKHR5cGVvZiBvcHRzID09PSAidW5kZWZpbmVkIikgewogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImxpbmUgY2FsbGJhY2sgbXVzdCBiZSBwcm92aWRlZCIpOwogICAgICB9CiAgICAgIGlmICh0eXBlb2Ygb3B0cyA9PT0gImZ1bmN0aW9uIikgewogICAgICAgIGNhbGxiYWNrID0gb3B0czsKICAgICAgfSBlbHNlIHsKICAgICAgICBvcHRpb25zID0gb3B0czsKICAgICAgICBjYWxsYmFjayA9IG9wdHMubGluZUNhbGxiYWNrOwogICAgICB9CiAgICAgIGlmIChyZWZOYW1lID09PSB2b2lkIDApIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJtdXN0IHByb3ZpZGUgYSByZWZlcmVuY2Ugc2VxdWVuY2UgbmFtZSIpOwogICAgICB9CiAgICAgIGlmICghY2FsbGJhY2spIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJsaW5lIGNhbGxiYWNrIG11c3QgYmUgcHJvdmlkZWQiKTsKIC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xhc3QgPSBEYXRlLm5vdygpOwogICAgICBmb3IgKGxldCBjaHVua051bSA9IDA7IGNodW5rTnVtIDwgY2h1bmtzLmxlbmd0aDsgY2h1bmtOdW0gKz0gMSkgewogICAgICAgIGxldCBwcmV2aW91c1N0YXJ0Q29vcmRpbmF0ZTsKICAgICAgICBjb25zdCBjID0gY2h1bmtzW2NodW5rTnVtXTsKICAgICAgICBjb25zdCB7IGJ1ZmZlciwgY3Bvc2l0aW9ucywgZHBvc2l0aW9ucyB9ID0gYXdhaXQgdGhpcy5jaHVua0NhY2hlLmdldChjLnRvU3RyaW5nKCksIGMpOwogICAgICAgIGNoZWNrQWJvcnRTaWduYWwoc2lnbmFsKTsKICAgICAgICBsZXQgYmxvY2tTdGFydCA9IDA7CiAgICAgICAgbGV0IHBvcyA9IDA7CiAgICAgICAgd2hpbGUgKGJsb2NrU3RhcnQgPCBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICBjb25zdCBuID0gYnVmZmVyLmluZGV4T2YoIlxuIiwgYmxvY2tTdGFydCk7CiAgICAgICAgICBpZiAobiA9PT0gLTEpIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBjb25zdCBiID0gYnVmZmVyLnNsaWNlKGJsb2NrU3RhcnQsIG4pOwogICAgICAgICAgY29uc3QgbGluZSA9IChkZWNvZGVyID09PSBudWxsIHx8IGRlY29kZXIgPT09IHZvaWQgMCA/IHZvaWQgMCA6IGRlY29kZXIuZGVjb2RlKGIpKSB8fCBiLnRvU3RyaW5nKCk7CiAgICAgICAgICBpZiAoZHBvc2l0aW9ucykgewogICAgICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCArIGMubWludi5kYXRhUG9zaXRpb24gPj0gZHBvc2l0aW9uc1twb3MrK10pIHsKICAgICAgICAgICAgfQogICAgICAgICAgICBwb3MtLTsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwcyB9ID0gdGhpcy5jaGVja0xpbmUobWV0YWRhdGEsIHJlZk5hbWUsIHN0YXJ0LCBlbmQsIGxpbmUpOwogICAgICAgICAgaWYgKHByZXZpb3VzU3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgcHJldmlvdXNTdGFydENvb3JkaW5hdGUgPiBzdGFydENvb3JkaW5hdGUpIHsKICAgICAgICAgICAgdGhyb3cgbmV3IEVycm9yKGBMaW5lcyBub3Qgc29ydGVkIGJ5IHN0YXJ0IGNvb3JkaW5hdGUgKCR7cHJldmlvdXNTdGFydENvb3JkaW5hdGV9ID4gJHtzdGFydENvb3JkaW5hdGV9KSwgdGhpcyBmaWxlIGlzIG5vdCB1c2FibGUgd2l0aCBUYWJpeC5gKTsKICAgICAgICAgIH0KICAgICAgICAgIHByZXZpb3VzU3RhcnRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlOwogICAgICAgICAgaWYgKG92ZXJsYXBzKSB7CiAgICAgICAgICAgIGNhbGxiYWNrKGxpbmUudHJpbSgpLCBjcG9zaXRpb25zW3Bvc10gKiAoMSA8PCA4KSArIChibG9ja1N0YXJ0IC0gZHBvc2l0aW9uc1twb3NdKSArIGMubWludi5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RhcnRDb29yZGluYXRlICE9PSB2b2lkIDAgJiYgc3RhcnRDb29yZGluYXRlID49IGVuZCkgewogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBpZiAodGhpcy55aWVsZFRpbWUgJiYgbGFzdCAtIERhdGUubm93KCkgPiB0aGlzLnlpZWxkVGltZSkgewogICAgICAgICAgICBsYXN0ID0gRGF0ZS5ub3coKTsKICAgICAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgICAgICBhd2FpdCB0aW1lb3V0KDEpOwogICAgICAgICAgfQogICAgICAgICAg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ICByZXR1cm4geyBvdmVybGFwczogZmFsc2UgfTsKICAgICAgfQogICAgICBsZXQgeyByZWYsIHN0YXJ0LCBlbmQgfSA9IGNvbHVtbk51bWJlcnM7CiAgICAgIGlmICghcmVmKSB7CiAgICAgICAgcmVmID0gMDsKICAgICAgfQogICAgICBpZiAoIXN0YXJ0KSB7CiAgICAgICAgc3RhcnQgPSAwOwogICAgICB9CiAgICAgIGlmICghZW5kKSB7CiAgICAgICAgZW5kID0gMDsKICAgICAgfQogICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgIGVuZCA9IDg7CiAgICAgIH0KICAgICAgY29uc3QgbWF4Q29sdW1uID0gTWF0aC5tYXgocmVmLCBzdGFydCwgZW5kKTsKICAgICAgbGV0IGN1cnJlbnRDb2x1bW5OdW1iZXIgPSAxOwogICAgICBsZXQgY3VycmVudENvbHVtblN0YXJ0ID0gMDsKICAgICAgbGV0IHJlZlNlcSA9ICIiOwogICAgICBsZXQgc3RhcnRDb29yZGluYXRlID0gLUluZmluaXR5OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxpbmUubGVuZ3RoICsgMTsgaSArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbaV0gPT09ICIJIiB8fCBpID09PSBsaW5lLmxlbmd0aCkgewogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHJlZikgewogICAgICAgICAgICBpZiAodGhpcy5yZW5hbWVSZWZTZXEobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpKSAhPT0gcmVnaW9uUmVmTmFtZSkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICBpZiAoY29vcmRpbmF0ZVR5cGUgPT09ICIxLWJhc2VkLWNsb3NlZCIpIHsKICAgICAgICAgICAgICBzdGFydENvb3JkaW5hdGUgLT0gMTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlID49IHJlZ2lvbkVuZCkgewogICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGVuZCA9PT0gMCB8fCBlbmQgPT09IHN0YXJ0KSB7CiAgICAgICAgICAgICAgaWYgKHN0YXJ0Q29vcmRpbmF0ZSArIDEgPD0gcmVnaW9uU3RhcnQpIHsKICAgICAgICAgICAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgaWYgKGZvcm1hdCA9PT0gIlZDRiIgJiYgY3VycmVudENvbHVtbk51bWJlciA9PT0gNCkgewogICAgICAgICAgICByZWZTZXEgPSBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPT09IGVuZCkgewogICAgICAgICAgICBsZXQgZW5kQ29vcmRpbmF0ZTsKICAgICAgICAgICAgaWYgKGZvcm1hdCA9PT0gIlZDRiIpIHsKICAgICAgICAgICAgICBlbmRDb29yZGluYXRlID0gdGhpcy5fZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSBwYXJzZUludChsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSksIDEwKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kQ29vcmRpbmF0ZSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgIHJldHVybiB7IG92ZXJsYXBzOiBmYWxzZSB9OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyZW50Q29sdW1uU3RhcnQgPSBpICsgMTsKICAgICAgICAgIGN1cnJlbnRDb2x1bW5OdW1iZXIgKz0gMTsKICAgICAgICAgIGlmIChjdXJyZW50Q29sdW1uTnVtYmVyID4gbWF4Q29sdW1uKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4geyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzOiB0cnVlIH07CiAgICB9CiAgICBfZ2V0VmNmRW5kKHN0YXJ0Q29vcmRpbmF0ZSwgcmVmU2VxLCBpbmZvKSB7CiAgICAgIGxldCBlbmRDb29yZGluYXRlID0gc3RhcnRDb29yZGluYXRlICsgcmVmU2VxLmxlbmd0aDsKICAgICAgY29uc3QgaXNUUkEgPSBpbmZvLmluZGV4T2YoIlNWVFlQRT1UUkEiKSAhPT0gLTE7CiAgICAgIGlmIChpbmZvWzBdICE9PSAiLiIgJiYgIWlzVFJBKSB7CiAgICAgICAgbGV0IHByZXZDaGFyID0gIjsiOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgaW5mby5sZW5ndGg7IGogKz0gMSkgewogICAgICAgICAgaWYgKHByZXZDaGFyID09PSAiOyIgJiYgaW5mby5zbGljZShqLCBqICsgNCkgPT09ICJFTkQ9IikgewogICAgICAgICAgICBsZXQgdmFsdWVFbmQgPSBpbmZvLmluZGV4T2YoIjsiLCBqKTsKICAgICAgICAgICAgaWYgKHZhbHVlRW5kID09PSAtMSkgewogICAgICAgICAgICAgIHZhbHVl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gICAgfSwKICAgICAgREI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiZGJTTlAgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiY29tYmluZWQgZGVwdGggYWNyb3NzIHNhbXBsZXMiCiAgICAgIH0sCiAgICAgIEVORDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFbmQgcG9zaXRpb24gKGZvciB1c2Ugd2l0aCBzeW1ib2xpYyBhbGxlbGVzKSIKICAgICAgfSwKICAgICAgSDI6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSGFwTWFwMiBtZW1iZXJzaGlwIgogICAgICB9LAogICAgICBIMzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBNYXAzIG1lbWJlcnNoaXAiCiAgICAgIH0sCiAgICAgIE1ROiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6IG51bGwsCiAgICAgICAgRGVzY3JpcHRpb246ICJSTVMgbWFwcGluZyBxdWFsaXR5IgogICAgICB9LAogICAgICBNUTA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIE1BUFEgPT0gMCByZWFkcyIKICAgICAgfSwKICAgICAgTlM6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTnVtYmVyIG9mIHNhbXBsZXMgd2l0aCBkYXRhIgogICAgICB9LAogICAgICBTQjogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTdHJhbmQgYmlhcyIKICAgICAgfSwKICAgICAgU09NQVRJQzogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJTb21hdGljIG11dGF0aW9uIChmb3IgY2FuY2VyIGdlbm9taWNzKSIKICAgICAgfSwKICAgICAgVkFMSURBVEVEOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlZhbGlkYXRlZCBieSBmb2xsb3ctdXAgZXhwZXJpbWVudCIKICAgICAgfSwKICAgICAgIjEwMDBHIjogewogICAgICAgIE51bWJlcjogMCwKICAgICAgICBUeXBlOiAiRmxhZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICIxMDAwIEdlbm9tZXMgbWVtYmVyc2hpcCIKICAgICAgfSwKICAgICAgSU1QUkVDSVNFOiB7CiAgICAgICAgTnVtYmVyOiAwLAogICAgICAgIFR5cGU6ICJGbGFnIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkltcHJlY2lzZSBzdHJ1Y3R1cmFsIHZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgTk9WRUw6IHsKICAgICAgICBOdW1iZXI6IDAsCiAgICAgICAgVHlwZTogIkZsYWciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSW5kaWNhdGVzIGEgbm92ZWwgc3RydWN0dXJhbCB2YXJpYXRpb24iCiAgICAgIH0sCiAgICAgIFNWVFlQRTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlR5cGUgb2Ygc3RydWN0dXJhbCB2YXJpYW50IgogICAgICB9LAogICAgICBTVkxFTjogewogICAgICAgIE51bWJlcjogbnVsbCwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJEaWZmZXJlbmNlIGluIGxlbmd0aCBiZXR3ZWVuIFJFRiBhbmQgQUxUIGFsbGVsZXMiCiAgICAgIH0sCiAgICAgIENJUE9TOiB7CiAgICAgICAgTnVtYmVyOiAyLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvbmZpZGVuY2UgaW50ZXJ2YWwgYXJvdW5kIFBPUyBmb3IgaW1wcmVjaXNlIHZhcmlhbnRzIgogICAgICB9LAogICAgICBDSUVORDogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBFTkQgZm9yIGltcHJlY2lzZSB2YXJpYW50cyIKICAgICAgfSwKICAgICAgSE9NTEVOOiB7CiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiTGVuZ3RoIG9mIGJhc2UgcGFpciBpZGVudGljYWwgbWljcm8taG9tb2xvZ3kgYXQgZXZlbnQgYnJlYWtwb2ludHMiCiAgICAgIH0sCiAgICAgIEhPTVNFUTogewogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiU2VxdWVuY2Ugb2YgYmFzZSBwYWlyIGlkZW50aWNhbCBtaWNyby1ob21vbG9neSBhdCBldmVudCBicmVha3BvaW50cyIKICAgICAgfSwKICAgICAgQktQVElEOiB7CiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiB0aGUgYXNzZW1ibGVkIGFsdGVybmF0ZSBhbGxlbGUgaW4gdGhlIGFzc2VtYmx5IGZpbGUiCiAgICAgIH0sCiAgICAgIE1FSU5GTzogewogICAgICAgIE51bWJlcjogNCwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIk1vYmlsZSBlbGVtZW50IGluZm8gb2YgdGhlIGZvcm0gTkFNRSxTVEFSVCxFTkQsUE9MQVJJVFkiCiAgICAgIH0sCiAgICAgIE1FVFJBTlM6IHsKICAgICAgICBOdW1iZXI6IDQsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJNb2JpbGUgZWxlbWVudCB0cmFuc2R1Y3Rpb24gaW5mbyBvZiB0aGUgZm9ybSBDSFIsU1RBUlQsRU5ELFBPTEFSSVRZIgogICAgICB9LAogICAgICBER1ZJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEYXRhYmFzZSBvZiBHZW5vbWljIFZhcmlhdGlvbiIKICAgICAgfSwKICAgICAgREJWQVJJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlZBUiIKICAgICAgfSwKICAgICAgREJSSVBJRDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIklEIG9mIHRoaXMgZWxlbWVudCBpbiBEQlJJUCIKICAgICAgfSwKICAgICAgTUFURUlEOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgbWF0ZSBicmVha2VuZHMiCiAgICAgIH0sCiAgICAgIFBBUklEOiB7CiAgICAgICAgTnVtYmVyOiAxLAogICAgICAgIFR5cGU6ICJTdHJpbmciLAogICAgICAgIERlc2NyaXB0aW9uOiAiSUQgb2YgcGFydG5lciBicmVha2VuZCIKICAgICAgfSwKICAgICAgRVZFTlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICJJRCBvZiBldmVudCBhc3NvY2lhdGVkIHRvIGJyZWFrZW5kIgogICAgICB9LAogICAgICBDSUxFTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCB0aGUgaW5zZXJ0ZWQgbWF0ZXJpYWwgYmV0d2VlbiBicmVha2VuZCIKICAgICAgfSwKICAgICAgRFBBREo6IHsgVHlwZTogIkludGVnZXIiLCBEZXNjcmlwdGlvbjogIlJlYWQgRGVwdGggb2YgYWRqYWNlbmN5IiB9LAogICAgICBDTjogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb3B5IG51bWJlciBvZiBzZWdtZW50IGNvbnRhaW5pbmcgYnJlYWtlbmQiCiAgICAgIH0sCiAgICAgIENOQURKOiB7CiAgICAgICAgTnVtYmVyOiBudWxsLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkNvcHkgbnVtYmVyIG9mIGFkamFjZW5jeSIKICAgICAgfSwKICAgICAgQ0lDTjogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25maWRlbmNlIGludGVydmFsIGFyb3VuZCBjb3B5IG51bWJlciBmb3IgdGhlIHNlZ21lbnQiCiAgICAgIH0sCiAgICAgIENJQ05BREo6IHsKICAgICAgICBOdW1iZXI6IG51bGwsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiQ29uZmlkZW5jZSBpbnRlcnZhbCBhcm91bmQgY29weSBudW1iZXIgZm9yIHRoZSBhZGphY2VuY3kiCiAgICAgIH0KICAgIH0sCiAgICBHZW5vdHlwZUZpZWxkczogewogICAgICBBRDogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIgogICAgICB9LAogICAgICBBREY6IHsKICAgICAgICBOdW1iZXI6ICJSIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJSZWFkIGRlcHRoIGZvciBlYWNoIGFsbGVsZSBvbiB0aGUgZm9yd2FyZCBzdHJhbmQiCiAgICAgIH0sCiAgICAgIEFEUjogewogICAgICAgIE51bWJlcjogIlIiLAogICAgICAgIFR5cGU6ICJJbnRlZ2VyIiwKICAgICAgICBEZXNjcmlwdGlvbjogIlJlYWQgZGVwdGggZm9yIGVhY2ggYWxsZWxlIG9uIHRoZSByZXZlcnNlIHN0cmFuZCIKICAgICAgfSwKICAgICAgRFA6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUmVhZCBkZXB0aCIKICAgICAgfSwKICAgICAgRUM6IHsKICAgICAgICBOdW1iZXI6ICJBIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJFeHBlY3RlZCBhbHRlcm5hdGUgYWxsZWxlIGNvdW50cyIKICAgICAgfSwKICAgICAgRlQ6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIlN0cmluZyIsCiAgICAgICAgRGVzY3JpcHRpb246ICdGaWx0ZXIgaW5kaWNhdGluZyBpZiB0aGlzIGdlbm90eXBlIHdhcyAiY2FsbGVkIicKICAgICAgfSwKICAgICAgR0w6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiRmxvYXQiLAogICAgICAgIERlc2NyaXB0aW9uOiAiR2Vub3R5cGUgbGlrZWxpaG9vZHMiCiAgICAgIH0sCiAgICAgIEdQOiB7CiAgICAgICAgTnVtYmVyOiAiRyIsCiAgICAgICAgVHlwZTogIkZsb2F0IiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIHBvc3RlcmlvciBwcm9iYWJpbGl0aWVzIgogICAgICB9LAogICAgICBHUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJDb25kaXRpb25hbCBnZW5vdHlwZSBxdWFsaXR5IgogICAgICB9LAogICAgICBHVDogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBUeXBlOiAiU3RyaW5nIiwKICAgICAgICBEZXNjcmlwdGlvbjogIkdlbm90eXBlIgogICAgICB9LAogICAgICBIUTogewogICAgICAgIE51bWJlcjogMiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJIYXBsb3R5cGUgcXVhbGl0eSIKICAgICAgfSwKICAgICAgTVE6IHsKICAgICAgICBOdW1iZXI6IDEsCiAgICAgICAgVHlwZTogIkludGVnZXIiLAogICAgICAgIERlc2NyaXB0aW9uOiAiUk1TIG1hcHBpbmcgcXVhbGl0eSIKICAgICAgfSwKICAgICAgUEw6IHsKICAgICAgICBOdW1iZXI6ICJHIiwKICAgICAgICBUeXBlOiAiSW50ZWdlciIsCiAgICAgICAgRGVzY3JpcHRpb246ICJQaHJlZC1zY2FsZWQgZ2Vub3R5cGUgbGlrZWxpaG9vZHMgcm91bmRlZCB0byB0aGUgY2xvc2VzdCBpbnRlZ2VyIgogICAgICB9LAogICAgICBQUTogewogICAgICAgIE51bWJlcjogMSwKICAgICAgICBU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GxpdCgiOiIpOwogICAgICBpZiAoZm9ybWF0S2V5cykgewogICAgICAgIHRoaXMuc2FtcGxlcy5mb3JFYWNoKChzYW1wbGUsIGluZGV4KSA9PiB7CiAgICAgICAgICBnZW5vdHlwZXNbc2FtcGxlXSA9IHt9OwogICAgICAgICAgZm9ybWF0S2V5cy5mb3JFYWNoKChrZXkpID0+IHsKICAgICAgICAgICAgZ2Vub3R5cGVzW3NhbXBsZV1ba2V5XSA9IG51bGw7CiAgICAgICAgICB9KTsKICAgICAgICAgIHJlc3RbaW5kZXhdLnNwbGl0KCI6IikuZmlsdGVyKChmKSA9PiBmKS5mb3JFYWNoKCh2YWwsIGluZGV4MikgPT4gewogICAgICAgICAgICBsZXQgdGhpc1ZhbHVlOwogICAgICAgICAgICBpZiAodmFsID09PSAiIiB8fCB2YWwgPT09ICIuIiB8fCB2YWwgPT09IHZvaWQgMCkgewogICAgICAgICAgICAgIHRoaXNWYWx1ZSA9IG51bGw7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgY29uc3QgZW50cmllcyA9IHZhbC5zcGxpdCgiLCIpLm1hcCgoZW50KSA9PiBlbnQgPT09ICIuIiA/IG51bGwgOiBlbnQpOwogICAgICAgICAgICAgIGNvbnN0IHZhbHVlVHlwZSA9IHRoaXMuZ2V0TWV0YWRhdGEoIkZPUk1BVCIsIGZvcm1hdEtleXNbaW5kZXgyXSwgIlR5cGUiKTsKICAgICAgICAgICAgICBpZiAodmFsdWVUeXBlID09PSAiSW50ZWdlciIgfHwgdmFsdWVUeXBlID09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgICAgICB0aGlzVmFsdWUgPSBlbnRyaWVzLm1hcCgodmFsMikgPT4gdmFsMiA/ICt2YWwyIDogdmFsMik7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHRoaXNWYWx1ZSA9IGVudHJpZXM7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIG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3VycktleSArPSBzdHJbaV07CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cnJWYWx1ZSA9PT0gIiIpIHsKICAgICAgICAgICAgZGF0YVtjdXJyS2V5XSA9IG51bGw7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAyKSB7CiAgICAgICAgICBpZiAoc3RyW2ldID09PSBwYWlyU2VwYXJhdG9yKSB7CiAgICAgICAgICAgIGRhdGFbY3VycktleV0gPSBjdXJyVmFsdWU7CiAgICAgICAgICAgIGN1cnJLZXkgPSAiIjsKICAgICAgICAgICAgY3VyclZhbHVlID0gIiI7CiAgICAgICAgICAgIHN0YXRlID0gMTsKICAgICAgICAgIH0gZWxzZSBpZiAoc3RyW2ldID09PSAnIicpIHsKICAgICAgICAgICAgc3RhdGUgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHN0YXRlID09PSAzKSB7CiAgICAgICAgICBpZiAoc3RyW2ldICE9PSAnIicpIHsKICAgICAgICAgICAgY3VyclZhbHVlICs9IHN0cltpXTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlID0gMjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgaWYgKHN0YXRlID09PSAyIHx8IHN0YXRlID09PSAzKSB7CiAgICAgICAgZGF0YVtjdXJyS2V5XSA9IGN1cnJWYWx1ZTsKICAgICAgfSBlbHNlIGlmIChzdGF0ZSA9PT0gMSkgewogICAgICAgIGRhdGFbY3VycktleV0gPSBudWxsOwogICAgICB9CiAgICAgIHJldHVybiBkYXRhOwogICAgfQogICAgcGFyc2VMaW5lKGxpbmUpIHsKICAgICAgbGluZSA9IGxpbmUudHJpbSgpOwogICAgICBpZiAoIWxpbmUubGVuZ3RoKSB7CiAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgfQogICAgICBjb25zdCBwYXJzZXIgPSB0aGlzOwogICAgICBsZXQgY3VyckNoYXIgPSAwOwogICAgICBmb3IgKGxldCBjdXJyRmllbGQgPSAwOyBjdXJyQ2hhciA8IGxpbmUubGVuZ3RoOyBjdXJyQ2hhciArPSAxKSB7CiAgICAgICAgaWYgKGxpbmVbY3VyckNoYXJdID09PSAiCSIpIHsKICAgICAgICAgIGN1cnJGaWVsZCArPSAxOwogICAgICAgIH0KICAgICAgICBpZiAoY3VyckZpZWxkID09PSA5KSB7CiAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KICAgICAgY29uc3QgZmllbGRzID0gbGluZS5zdWJzdHIoMCwgY3VyckNoYXIpLnNwbGl0KCIJIik7CiAgICAgIGNvbnN0IHJlc3QgPSBsaW5lLnN1YnN0cihjdXJyQ2hhciArIDEpOwogICAgICBjb25zdCBbQ0hST00sIFBPUywgSUQsIFJFRiwgQUxULCBRVUFMLCBGSUxURVJdID0gZmllbGRzOwogICAgICBjb25zdCBjaHJvbSA9IENIUk9NOwogICAgICBjb25zdCBwb3MgPSArUE9TOwogICAgICBjb25zdCBpZCA9IElEID09PSAiLiIgPyBudWxsIDogSUQuc3BsaXQoIjsiKTsKICAgICAgY29uc3QgcmVmID0gUkVGOwogICAgICBjb25zdCBhbHQgPSBBTFQgPT09ICIuIiA/IG51bGwgOiBBTFQuc3BsaXQoIiwiKTsKICAgICAgY29uc3QgcXVhbCA9IFFVQUwgPT09ICIuIiA/IG51bGwgOiArUVVBTDsKICAgICAgY29uc3QgZmlsdGVyID0gRklMVEVSID09PSAiLiIgPyBudWxsIDogRklMVEVSLnNwbGl0KCI7Iik7CiAgICAgIGlmICh0aGlzLnN0cmljdCAmJiBmaWVsZHNbN10gPT09IHZvaWQgMCkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigibm8gSU5GTyBmaWVsZCBzcGVjaWZpZWQsIG11c3QgY29udGFpbiBhdCBsZWFzdCBhICcuJyAodHVybiBvZmYgc3RyaWN0IG1vZGUgdG8gYWxsb3cpIik7CiAgICAgIH0KICAgICAgY29uc3QgaW5mbyA9IGZpZWxkc1s3XSA9PT0gdm9pZCAwIHx8IGZpZWxkc1s3XSA9PT0gIi4iID8ge30gOiB0aGlzLl9wYXJzZUtleVZhbHVlKGZpZWxkc1s3XSk7CiAgICAgIE9iamVjdC5rZXlzKGluZm8pLmZvckVhY2goKGtleSkgPT4gewogICAgICAgIGxldCBpdGVtczsKICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICBpdGVtcyA9IGluZm9ba2V5XS5zcGxpdCgiLCIpLm1hcCgodmFsKSA9PiB2YWwgPT09ICIuIiA/IG51bGwgOiB2YWwpLm1hcCgoZikgPT4gZiA/IGRlY29kZVVSSUNvbXBvbmVudE5vVGhyb3coZikgOiBmKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaXRlbXMgPSBpbmZvW2tleV07CiAgICAgICAgfQogICAgICAgIGNvbnN0IGl0ZW1UeXBlID0gdGhpcy5nZXRNZXRhZGF0YSgiSU5GTyIsIGtleSwgIlR5cGUiKTsKICAgICAgICBpZiAoaXRlbVR5cGUpIHsKICAgICAgICAgIGlmIChpdGVtVHlwZSA9PT0gIkludGVnZXIiIHx8IGl0ZW1UeXBlID09PSAiRmxvYXQiKSB7CiAgICAgICAgICAgIGl0ZW1zID0gaXRlbXMubWFwKCh2YWwpID0+IHsKICAgICAgICAgICAgICBpZiAodmFsID09PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gbnVsbDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcmV0dXJuIE51bWJlcih2YWwpOwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gZWxzZSBpZiAoaXRlbVR5cGUgPT09ICJGbGFnIikgewogICAgICAgICAgICBpZiAoaW5mb1trZXldKSB7CiAgICAgICAgICAgICAgY29uc29sZS53YXJuKGBJbmZvIGZpZWxkICR7a2V5fSBpcyBhIEZsYWcgYW5kIHNob3VsZCBub3QgaGF2ZSBhIHZhbHVlIChnb3QgdmFsdWUgJHtpbmZvW2tleV19KWApOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGl0ZW1zID0gdHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbmZvW2tleV0gPSBpdGVtczsKICAgICAgfSk7CiAgICAgIGNvbnN0IHZhcmlhbnQgPSBuZXcgVmFyaWFudCh7CiAgICAgICAgQ0hST006IGNocm9tLAogICAgICAgIFBPUzogcG9zLAogICAgICAgIEFMVDogYWx0LAogICAgICAgIElORk86IGluZm8sCiAgICAgICAgUkVGOiByZWYsCiAgICAgICAgRklMVEVSOiBmaWx0ZXIgJiYgZmlsdGVyLmxlbmd0aCA9PT0gMSAmJiBmaWx0ZXJbMF0gPT09ICJQQVNTIiA/ICJQQVNTIiA6IGZpbHRlciwKICAgICAgICBJRDogaWQsCiAgICAgICAgUVVBTDogcXVhbAogICAgICB9KTsKICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHZhcmlhbnQsICJTQU1QTEVTIiwgewogICAgICAgIGdldCgpIHsKICAgICAgICAgIGNvbnN0IHNhbXBsZXMgPSBwYXJzZXIuX3BhcnNlR2Vub3R5cGVzKGZpZWxkc1s4XSwgcmVzdCk7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgIlNBTVBMRVMiLCB7CiAgICAgICAgICAgIHZhbHVlOiBzYW1wbGVzLAogICAgICAgICAgICBjb25maWd1cmFibGU6IGZhbHNlCiAgICAgICAgICB9KTsKICAgICAgICAgIHJldHVybiBzYW1wbGVzOwogICAgICAgIH0sCiAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgIH0pOwogICAgICByZXR1cm4gdmFyaWFudDsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdmNmQDUuMC4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KICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4gLWRlbHRhKGFbaV0sIHgpID8gaSAtIDEgOiBpOwogICAgfQogICAgcmV0dXJuIHsgbGVmdCwgY2VudGVyLCByaWdodCB9OwogIH0KICBmdW5jdGlvbiBhc2NlbmRpbmdDb21wYXJhdG9yKGYpIHsKICAgIHJldHVybiAoZCwgeCkgPT4gYXNjZW5kaW5nX2RlZmF1bHQoZihkKSwgeCk7CiAgfQoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy91dGlscy50cwogIHZhciBEYXRhU291cmNlID0gY2xhc3MgewogICAgY29uc3RydWN0b3IoZmlsZSwgY2hyb21TaXplcywgb3B0aW9ucykgewogICAgICB0aGlzLmZpbGUgPSBmaWxlOwogICAgICB0aGlzLm9wdGlvbnMgPSBvcHRpb25zOwogICAgICB0aGlzLmNocm9tSW5mbyA9IHNpemVzVG9DaHJvbUluZm8oY2hyb21TaXplcyk7CiAgICAgIHRoaXMudGlsZXNldEluZm8gPSB0aWxlc2V0SW5mb0Zyb21DaHJvbUluZm8odGhpcy5jaHJvbUluZm8pOwogICAgfQogICAgY2hyb21JbmZvOwogICAgdGlsZXNldEluZm87CiAgfTsKICB2YXIgY2hyb21JbmZvQmlzZWN0b3IgPSBiaXNlY3Rvcl9kZWZhdWx0KChkKSA9PiBkLnBvcykubGVmdDsKICB2YXIgY2hyVG9BYn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AgICAgdGhyb3cgbmV3IEVycm9yKGBIVFRQICR7cmVzcG9uc2Uuc3RhdHVzfSBmZXRjaGluZyAke3RoaXMudXJsfWApOwogICAgfTsKICB9OwoKICAvLyBzcmMvZGF0YS1mZXRjaGVycy92Y2YvdXRpbHMudHMKICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgdmFyIGdldE11dGF0aW9uVHlwZSA9IChyZWYsIGFsdCkgPT4gewogICAgaWYgKCFhbHQpCiAgICAgIHJldHVybiAidW5rbm93biI7CiAgICBpZiAocmVmLmxlbmd0aCA9PT0gYWx0Lmxlbmd0aCkKICAgICAgcmV0dXJuICJzdWJzdGl0dXRpb24iOwogICAgaWYgKHJlZi5sZW5ndGggPiBhbHQubGVuZ3RoKQogICAgICByZXR1cm4gImRlbGV0aW9uIjsKICAgIGlmIChyZWYubGVuZ3RoIDwgYWx0Lmxlbmd0aCkKICAgICAgcmV0dXJuICJpbnNlcnRpb24iOwogICAgcmV0dXJuICJ1bmtub3duIjsKICB9OwogIHZhciBnZXRTdWJzdGl0dXRpb25UeXBlID0gKHJlZiwgYWx0KSA9PiB7CiAgICBzd2l0Y2ggKHJlZiArIGFsdCkgewogICAgICBjYXNlICJDQSI6CiAgICAgIGNhc2UgIkdUIjoKICAgICAgICByZXR1cm4gIkM+QSI7CiAgICAgIGNhc2UgIkNHIjoKICAgICAgY2FzZSAiR0MiOgogICAgICAgIHJldHVybiAiQz5HIjsKICAgICAgY2FzZSAiQ1QiOgogICAgICBjYXNlICJHQSI6CiAgICAgICAgcmV0dXJuICJDPlQiOwogICAgICBjYXNlICJUQSI6CiAgICAgIGNhc2UgIkFUIjoKICAgICAgICByZXR1cm4gIlQ+QSI7CiAgICAgIGNhc2UgIlRDIjoKICAgICAgY2FzZSAiQUciOgogICAgICAgIHJldHVybiAiVD5DIjsKICAgICAgY2FzZSAiVEciOgogICAgICBjYXNlICJBQyI6CiAgICAgICAgcmV0dXJuICJUPkciOwogICAgICBkZWZhdWx0OgogICAgICAg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BhcnNlci5wYXJzZUxpbmUobGluZSk7CiAgICAgICAgICAgIGNvbnN0IHZjZlRpbGUgPSByZWNvcmRUb1RpbGUodmNmUmVjb3JkLCBjaHJvbVN0YXJ0LCBwcmV2UE9TKTsKICAgICAgICAgICAgcHJldlBPUyA9IHZjZlRpbGUuUE9TOwogICAgICAgICAgICB0aWxlcy5wdXNoKHZjZlRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAgICAgICAgZW5kUG9zID0gY2hyb21FbmQgLSBjaHJvbVN0YXJ0OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBNYXRoLmZsb29yKGN1ck1pblggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgICAgZW5kUG9zID0gTWF0aC5jZWlsKG1heFggLSBjaHJvbVN0YXJ0KTsKICAgICAgICAgIH0KICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIHN0YXJ0UG9zLCBlbmRQb3MsIGxpbmVDYWxsYmFjaykudGhlbigoKSA9PiB7CiAgICAgICAgICAgIHJlc29sdmUodGlsZXMpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgcmVjb3JkUHJvbWlzZXMucHVzaCh0aWxlc1Byb21pc2UpOwogICAgICAgIGlmIChtYXhYIDw9IGNocm9tRW5kKSB7CiAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgY3VyTWluWCA9IGNocm9tRW5kOwogICAgICB9CiAgICAgIGNvbnN0IHRpbGVBcnJheXMgPSBhd2FpdCBQcm9taXNlLmFsbChyZWNvcmRQcm9taXNlcyk7CiAgICAgIHJldHVybiB0aWxlQXJyYXlzLmZsYXQoKTsKICAgIH0KICB9OwogIHZhciB0aWxlVmFsdWVzID0ge307CiA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DovL3VuZGVyc2NvcmVqcy5vcmcvTElDRU5TRT4KICogQ29weXJpZ2h0IEplcmVteSBBc2hrZW5hcywgRG9jdW1lbnRDbG91ZCBhbmQgSW52ZXN0aWdhdGl2ZSBSZXBvcnRlcnMgJiBFZGl0b3JzCiAqLwo=",fle=typeof window<"u"&&window.Blob&&new Blob([atob(f2e)],{type:"text/javascript;charset=utf-8"});function Sgg(){const e=fle&&(window.URL||window.webkitURL).createObjectURL(fle);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+f2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const wgg=200;class p2e{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:r,...C}=i;this.worker=LT(new Sgg).then(async o=>{const a=Object.entries(bi(r).size);return await o.init(this.uid,{url:I,indexUrl:n},a,C),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()},wgg)}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(p2e,"config",{type:"vcf"});const qk=BigInt(32);function Rgg(e,g,i){const I=+!!i,n=+!i;return BigInt(e.getInt32(g,i)*n+e.getInt32(g+4,i)*I)<>qk),r=Number(i&BigInt(4294967295));I?(e.setInt32(g+4,n,I),e.setUint32(g,r,I)):(e.setInt32(g,n,I),e.setUint32(g+4,r,I))}function Xgg(e,g,i,I){const n=Number(i>>qk),r=Number(i&BigInt(4294967295));I?(e.setUint32(g+4,n,I),e.setUint32(g,r,I)):(e.setUint32(g,n,I),e.setUint32(g+4,r,I))}"getBigInt64"in DataView||(DataView.prototype.getBigInt64=function(e,g){return Rgg(this,e,g)});"getBigUint64"in DataView||(DataView.prototype.getBigUint64=function(e,g){return Vgg(this,e,g)});"setBigInt64"in DataView||(DataView.prototype.setBigInt64=function(e,g,i){Wgg(this,e,g,i)});"setBigUint64"in DataView||(DataView.prototype.setBigUint64=function(e,g,i){Xgg(this,e,g,i)});class Hgg{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 To=new Map,Du="___parser_",No={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},t1={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"},g1={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(g,i){const I=t1[g],n=g1[g];i.pushCode(`${i.generateVariable(this.varName)} = dataView.get${I}(offset, ${n});`),i.pushCode(`offset += ${No[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 To.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"&&!To.has(i.type)&&!(i.type in No))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),r=i.choices[n];if(isNaN(n))throw new Error(`Choice key "${I}" is not a number.`);if(typeof r=="string"&&!To.has(r)&&!(r in No))throw new Error(`Choice type "${r}" 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 kg)&&!To.has(i.type))throw new Error("type must be a known parser name or a Parser object.");if(!(i.type instanceof kg)&&!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 No)&&!To.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 Hgg(g,this.useContextVariables);return i.pushCode("var dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.alias?(this.addAliasedCode(i),i.pushCode(`return ${Du+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 ${Du+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=To.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(No).indexOf(this.type)>=0)g=No[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=No[this.options.type]:this.options.type instanceof kg&&(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 kg;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},r=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 C=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}C=0,s=a=r(n(l)-s)}const u=o?a-C-c:C,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),C+=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,r=n.toLowerCase()==="hex",C='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(r?`${i} = Array.from(buffer.subarray(${I}, ${a}), ${C}).join('');`:`${i} = new TextDecoder('${n}').decode(buffer.subarray(${I}, ${a}));`)}else if(this.options.length){const o=g.generateOption(this.options.length);g.pushCode(r?`${i} = Array.from(buffer.subarray(offset, offset + ${o}), ${C}).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(r?`${i} = Array.from(buffer.subarray(${I}, offset - 1), ${C}).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(r?`${i} = Array.from(buffer.subarray(${I}, offset), ${C}).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(),r=g.generateTmpVariable();g.pushCode(`var ${n} = offset;`),g.pushCode(`var ${r} = 0;`),g.pushCode("while (offset < buffer.length) {"),g.pushCode(`${r} = dataView.getUint8(offset);`);const C=g.addImport(I);g.pushCode(`if (${C}.call(${g.generateVariable()}, ${r}, 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,r=g.generateTmpVariable(),C=g.generateVariable(this.varName),o=g.generateTmpVariable(),a=this.options.key,s=typeof a=="string";if(s?g.pushCode(`${C} = {};`):g.pushCode(`${C} = [];`),typeof this.options.readUntil=="function"?g.pushCode("do {"):this.options.readUntil==="eof"?g.pushCode(`for (var ${r} = 0; offset < buffer.length; ${r}++) {`):I!==void 0?g.pushCode(`for (var ${r} = offset + ${I}; offset < ${r}; ) {`):g.pushCode(`for (var ${r} = ${i}; ${r} > 0; ${r}--) {`),typeof n=="string")if(To.get(n)){const A=g.generateTmpVariable();if(g.pushCode(`var ${A} = ${Du+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} - ${r},`)}g.pushCode("});"),g.pushCode(`var ${o} = ${A}.result; offset = ${A}.offset;`),n!==this.alias&&g.addReference(n)}else{const A=t1[n],l=g1[n];g.pushCode(`var ${o} = dataView.get${A}(offset, ${l});`),g.pushCode(`offset += ${No[n]};`)}else if(n instanceof kg){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} - ${r};`)),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(`${C}[${o}.${a}] = ${o};`):g.pushCode(`${C}.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(To.has(I)){const r=g.generateTmpVariable();g.pushCode(`var ${r} = ${Du+I}(offset, {`),g.useContextVariables&&(g.pushCode(`$parent: ${n}.$parent,`),g.pushCode(`$root: ${n}.$root,`)),g.pushCode("});"),g.pushCode(`${n} = ${r}.result; offset = ${r}.offset;`),I!==this.alias&&g.addReference(I)}else{const r=t1[I],C=g1[I];g.pushCode(`${n} = dataView.get${r}(offset, ${C});`),g.pushCode(`offset += ${No[I]}`)}}else I instanceof kg&&(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 r=parseInt(n,10),C=this.options.choices[r];g.pushCode(`case ${r}:`),this.generateChoiceCase(g,this.varName,C),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 kg){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(To.has(this.options.type)){const I=g.generateTmpVariable();if(g.pushCode(`var ${I} = ${Du+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(),r=g.generateTmpVariable(),C=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 ${r} = offset;`),g.pushCode(`var ${C} = dataView;`),g.pushCode(`buffer = ${I};`),g.pushCode("offset = 0;"),g.pushCode("dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.length);"),this.options.type instanceof kg)this.varName&&g.pushCode(`${i} = {};`),g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName);else if(To.has(this.options.type)){const a=g.generateTmpVariable();g.pushCode(`var ${a} = ${Du+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 = ${C};`),g.pushCode(`offset = ${r};`)}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(),r=g.generateVariable(this.varName);if(g.pushCode(`var ${n} = offset;`),g.pushCode(`offset = ${I};`),this.options.type instanceof kg){if(g.pushCode(`${r} = {};`),g.useContextVariables){const C=g.generateVariable();g.pushCode(`${r}.$parent = ${C};`),g.pushCode(`${r}.$root = ${C}.$root;`)}g.pushPath(this.varName),this.options.type.generate(g),g.popPath(this.varName),g.useContextVariables&&(g.pushCode(`delete ${r}.$parent;`),g.pushCode(`delete ${r}.$root;`))}else if(To.has(this.options.type)){const C=g.generateTmpVariable();if(g.pushCode(`var ${C} = ${Du+this.options.type}(offset, {`),g.useContextVariables){const o=g.generateVariable();g.pushCode(`$parent: ${o},`),g.pushCode(`$root: ${o}.$root,`)}g.pushCode("});"),g.pushCode(`${r} = ${C}.result; offset = ${C}.offset;`),this.options.type!==this.alias&&g.addReference(this.options.type)}else if(Object.keys(No).indexOf(this.options.type)>=0){const C=t1[i],o=g1[i];g.pushCode(`${r} = dataView.get${C}(offset, ${o});`),g.pushCode(`offset += ${No[i]};`)}g.pushCode(`offset = ${n};`)}generateSaveOffset(g){const i=g.generateVariable(this.varName);g.pushCode(`${i} = offset`)}}var b2e={},_$={},Kh={},Yw={};Object.defineProperty(Yw,"__esModule",{value:!0});function L$(e,g){if(!(e instanceof g))throw new TypeError("Cannot call a class as a function")}function ple(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 pG(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function kgg(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 pG(e)}function Ygg(e){var g=Ngg();return function(){var I=h0(e),n;if(g){var r=h0(this).constructor;n=Reflect.construct(I,arguments,r)}else n=I.apply(this,arguments);return kgg(this,n)}}function Kgg(e,g){for(;!Object.prototype.hasOwnProperty.call(e,g)&&(e=h0(e),e!==null););return e}function DW(){return typeof Reflect<"u"&&Reflect.get?DW=Reflect.get.bind():DW=function(g,i,I){var n=Kgg(g,i);if(n){var r=Object.getOwnPropertyDescriptor(n,i);return r.get?r.get.call(arguments.length<3?g:I):r.value}},DW.apply(this,arguments)}var ble=function(){function e(){L$(this,e),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return U$(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],r=0,C=n.length;r"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&&(y2e.prototype[Symbol.toStringTag]="AbortController",Q$.prototype[Symbol.toStringTag]="AbortSignal");function Fgg(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 Dgg(e){typeof e=="function"&&(e={fetch:e});var g=e,i=g.fetch,I=g.Request,n=I===void 0?i.Request:I,r=g.AbortController,C=g.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL,o=C===void 0?!1:C;if(!Fgg({fetch:i,Request:n,AbortController:r,__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}}Yw.AbortController=y2e;Yw.AbortSignal=Q$;Yw.abortableFetch=Dgg;Object.defineProperty(Kh,"__esModule",{value:!0});Kh.AbortSignal=Kh.AbortController=void 0;const Z2e=Yw;var VH=function(){if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof gh<"u")return gh;throw new Error("unable to locate global object")};let xgg=typeof VH().AbortController>"u"?Z2e.AbortController:VH().AbortController;Kh.AbortController=xgg;let Egg=typeof VH().AbortController>"u"?Z2e.AbortSignal:VH().AbortSignal;Kh.AbortSignal=Egg;var j$={};Object.defineProperty(j$,"__esModule",{value:!0});const Mgg=Kh;class zgg{}class Pgg{constructor(){this.signals=new Set,this.abortController=new Mgg.AbortController}addSignal(g=new zgg){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()}}j$.default=Pgg;var q$={};Object.defineProperty(q$,"__esModule",{value:!0});class Jgg{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)})}}q$.default=Jgg;var G2e=gh&&gh.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_$,"__esModule",{value:!0});const Ogg=Kh,_gg=G2e(j$),Lgg=G2e(q$);class WH{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 r=new _gg.default,C=new Lgg.default;C.addCallback(n);const o={aborter:r,promise:this.fillCallback(i,r.signal,a=>{C.callback(a)}),settled:!1,statusReporter:C,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 Ogg.AbortSignal)throw new TypeError("second get argument appears to be an AbortSignal, perhaps you meant to pass `null` for the fill data?");const r=this.cache.get(g);return r?r.aborted&&!r.settled?(this.evict(g,r),this.get(g,i,I,n)):r.settled?r.promise:(r.aborter.addSignal(I),r.statusReporter.addCallback(n),WH.checkSinglePromise(r.promise,I)):(this.fill(g,i,I,n),WH.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}}_$.default=WH;var Ugg=gh&&gh.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(b2e,"__esModule",{value:!0});const Qgg=Ugg(_$);var jgg=b2e.default=Qgg.default;class nc{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 nc(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 r=1;rn.max()+1?(I.push(n),n=C):C.max()>n.max()&&(n=new nc(n.min(),C.max()))}return I.push(n),I.length===1?I[0]:new nc(I)}intersection(g){let i=this,I=g;const n=this.ranges(),r=I.ranges(),C=n.length,o=r.length;let a=0,s=0;const A=[];for(;a=l&&A.push(new nc(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 nc(A)}coverage(){let g=0;const i=this.ranges();for(let I=0;In.min()?1:I.max()I.max()?1:0}}function hy(e){let g=e.length;for(;--g>=0;)e[g]=0}const $gg=3,qgg=258,v2e=29,eig=256,tig=eig+1+v2e,B2e=30,gig=512,iig=new Array((tig+2)*2);hy(iig);const Iig=new Array(B2e*2);hy(Iig);const nig=new Array(gig);hy(nig);const rig=new Array(qgg-$gg+1);hy(rig);const Cig=new Array(v2e);hy(Cig);const oig=new Array(B2e);hy(oig);const aig=(e,g,i,I)=>{let n=e&65535|0,r=e>>>16&65535|0,C=0;for(;i!==0;){C=i>2e3?2e3:i,i-=C;do n=n+g[I++]|0,r=r+n|0;while(--C);n%=65521,r%=65521}return n|r<<16|0};var o_=aig;const Aig=()=>{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},sig=new Uint32Array(Aig()),lig=(e,g,i,I)=>{const n=sig,r=I+i;e^=-1;for(let C=I;C>>8^n[(e^g[C])&255];return e^-1};var Na=lig,a_={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"},e8={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 cig=(e,g)=>Object.prototype.hasOwnProperty.call(e,g);var uig=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)cig(i,I)&&(e[I]=i[I])}}return e},dig=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;sS[254]=sS[254]=1;var hig=e=>{if(typeof TextEncoder=="function"&&TextEncoder.prototype.encode)return new TextEncoder().encode(e);let g,i,I,n,r,C=e.length,o=0;for(n=0;n>>6,g[r++]=128|i&63):i<65536?(g[r++]=224|i>>>12,g[r++]=128|i>>>6&63,g[r++]=128|i&63):(g[r++]=240|i>>>18,g[r++]=128|i>>>12&63,g[r++]=128|i>>>6&63,g[r++]=128|i&63);return g};const mig=(e,g)=>{if(g<65534&&e.subarray&&w2e)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 r=new Array(i*2);for(n=0,I=0;I4){r[n++]=65533,I+=o-1;continue}for(C&=o===2?31:o===3?15:7;o>1&&I1){r[n++]=65533;continue}C<65536?r[n++]=C:(C-=65536,r[n++]=55296|C>>10&1023,r[n++]=56320|C&1023)}return mig(r,n)},pig=(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+sS[e[i]]>g?i:g},A_={string2buf:hig,buf2string:fig,utf8border:pig};function big(){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 yig=big;const i1=16209,Zig=16191;var Gig=function(g,i){let I,n,r,C,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,R;const S=g.state;I=g.next_in,w=g.input,n=I+(g.avail_in-5),r=g.next_out,R=g.output,C=r-(i-g.avail_out),o=r+(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)R[r++]=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=i1;break e}if(u>>>=y,d-=y,y=r-C,B>y){if(y=B-y,y>A&&S.sane){g.msg="invalid distance too far back",S.mode=i1;break e}if(G=0,v=c,l===0){if(G+=s-y,y2;)R[r++]=v[G++],R[r++]=v[G++],R[r++]=v[G++],Z-=3;Z&&(R[r++]=v[G++],Z>1&&(R[r++]=v[G++]))}else{G=r-B;do R[r++]=R[G++],R[r++]=R[G++],R[r++]=R[G++],Z-=3;while(Z>2);Z&&(R[r++]=R[G++],Z>1&&(R[r++]=R[G++]))}}else if(y&64){g.msg="invalid distance code",S.mode=i1;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 R=new Uint16Array(Cf+1),S=new Uint16Array(Cf+1);let X=null,W,V,H;for(s=0;s<=Cf;s++)R[s]=0;for(A=0;A=1&&R[c]===0;c--);if(u>c&&(u=c),c===0)return n[r++]=1<<24|64<<16|0,n[r++]=1<<24|64<<16|0,o.bits=1,0;for(l=1;l0&&(e===Gle||c!==1))return-1;for(S[1]=0,s=1;syle||e===vle&&f>Zle)return 1;for(;;){W=s-h,C[A]+1=w?(V=X[C[A]-w],H=v[C[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=g[i+C[A]]}if(s>u&&(b&B)!==Z){for(h===0&&(h=u),G+=l,d=s-h,m=1<yle||e===vle&&f>Zle)return 1;Z=b&B,n[Z]=u<<24|d<<16|G-r|0}}return b!==0&&(n[G+b]=s-h<<24|64<<16|0),o.bits=u,0};var Tv=Rig;const Vig=0,R2e=1,V2e=2,{Z_FINISH:Ble,Z_BLOCK:Wig,Z_TREES:I1,Z_OK:Fh,Z_STREAM_END:Xig,Z_NEED_DICT:Hig,Z_STREAM_ERROR:oo,Z_DATA_ERROR:W2e,Z_MEM_ERROR:X2e,Z_BUF_ERROR:Tig,Z_DEFLATED:Sle}=e8,eY=16180,wle=16181,Rle=16182,Vle=16183,Wle=16184,Xle=16185,Hle=16186,Tle=16187,Nle=16188,kle=16189,XH=16190,_A=16191,Rx=16192,Yle=16193,Vx=16194,Kle=16195,Fle=16196,Dle=16197,xle=16198,n1=16199,r1=16200,Ele=16201,Mle=16202,zle=16203,Ple=16204,Jle=16205,Wx=16206,Ole=16207,_le=16208,vi=16209,H2e=16210,T2e=16211,Nig=852,kig=592,Yig=15,Kig=Yig,Lle=e=>(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24);function Fig(){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 Zm=e=>{if(!e)return 1;const g=e.state;return!g||g.strm!==e||g.modeT2e?1:0},N2e=e=>{if(Zm(e))return oo;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=eY,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(Nig),g.distcode=g.distdyn=new Int32Array(kig),g.sane=1,g.back=-1,Fh},k2e=e=>{if(Zm(e))return oo;const g=e.state;return g.wsize=0,g.whave=0,g.wnext=0,N2e(e)},Y2e=(e,g)=>{let i;if(Zm(e))return oo;const I=e.state;return g<0?(i=0,g=-g):(i=(g>>4)+5,g<48&&(g&=15)),g&&(g<8||g>15)?oo:(I.window!==null&&I.wbits!==g&&(I.window=null),I.wrap=i,I.wbits=g,k2e(e))},K2e=(e,g)=>{if(!e)return oo;const i=new Fig;e.state=i,i.strm=e,i.window=null,i.mode=eY;const I=Y2e(e,g);return I!==Fh&&(e.state=null),I},Dig=e=>K2e(e,Kig);let Ule=!0,Xx,Hx;const xig=e=>{if(Ule){Xx=new Int32Array(512),Hx=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(Tv(R2e,e.lens,0,288,Xx,0,e.work,{bits:9}),g=0;g<32;)e.lens[g++]=5;Tv(V2e,e.lens,0,32,Hx,0,e.work,{bits:5}),Ule=!1}e.lencode=Xx,e.lenbits=9,e.distcode=Hx,e.distbits=5},F2e=(e,g,i,I)=>{let n;const r=e.state;return r.window===null&&(r.wsize=1<=r.wsize?(r.window.set(g.subarray(i-r.wsize,i),0),r.wnext=0,r.whave=r.wsize):(n=r.wsize-r.wnext,n>I&&(n=I),r.window.set(g.subarray(i-I,i-I+n),r.wnext),I-=n,I?(r.window.set(g.subarray(i-I,i),0),r.wnext=I,r.whave=r.wsize):(r.wnext+=n,r.wnext===r.wsize&&(r.wnext=0),r.whave{let i,I,n,r,C,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 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(Zm(e)||!e.output||!e.input&&e.avail_in!==0)return oo;i=e.state,i.mode===_A&&(i.mode=Rx),C=e.next_out,n=e.output,a=e.avail_out,r=e.next_in,I=e.input,o=e.avail_in,s=i.hold,A=i.bits,l=o,c=a,v=Fh;e:for(;;)switch(i.mode){case eY:if(i.wrap===0){i.mode=Rx;break}for(;A<16;){if(o===0)break e;o--,s+=I[r++]<>>8&255,i.check=Na(i.check,w,2,0),s=0,A=0,i.mode=wle;break}if(i.head&&(i.head.done=!1),!(i.wrap&1)||(((s&255)<<8)+(s>>8))%31){e.msg="incorrect header check",i.mode=vi;break}if((s&15)!==Sle){e.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){e.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=Na(i.check,w,2,0)),s=0,A=0,i.mode=Rle;case Rle:for(;A<32;){if(o===0)break e;o--,s+=I[r++]<>>8&255,w[2]=s>>>16&255,w[3]=s>>>24&255,i.check=Na(i.check,w,4,0)),s=0,A=0,i.mode=Vle;case Vle:for(;A<16;){if(o===0)break e;o--,s+=I[r++]<>8),i.flags&512&&i.wrap&4&&(w[0]=s&255,w[1]=s>>>8&255,i.check=Na(i.check,w,2,0)),s=0,A=0,i.mode=Wle;case Wle:if(i.flags&1024){for(;A<16;){if(o===0)break e;o--,s+=I[r++]<>>8&255,i.check=Na(i.check,w,2,0)),s=0,A=0}else i.head&&(i.head.extra=null);i.mode=Xle;case Xle: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(r,r+u),G)),i.flags&512&&i.wrap&4&&(i.check=Na(i.check,I,u,r)),o-=u,r+=u,i.length-=u),i.length))break e;i.length=0,i.mode=Hle;case Hle:if(i.flags&2048){if(o===0)break e;u=0;do G=I[r+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=_A;break;case kle:for(;A<32;){if(o===0)break e;o--,s+=I[r++]<>>=A&7,A-=A&7,i.mode=Wx;break}for(;A<3;){if(o===0)break e;o--,s+=I[r++]<>>=1,A-=1,s&3){case 0:i.mode=Yle;break;case 1:if(xig(i),i.mode=n1,g===I1){s>>>=2,A-=2;break e}break;case 2:i.mode=Fle;break;case 3:e.msg="invalid block type",i.mode=vi}s>>>=2,A-=2;break;case Yle:for(s>>>=A&7,A-=A&7;A<32;){if(o===0)break e;o--,s+=I[r++]<>>16^65535)){e.msg="invalid stored block lengths",i.mode=vi;break}if(i.length=s&65535,s=0,A=0,i.mode=Vx,g===I1)break e;case Vx:i.mode=Kle;case Kle:if(u=i.length,u){if(u>o&&(u=o),u>a&&(u=a),u===0)break e;n.set(I.subarray(r,r+u),C),o-=u,r+=u,a-=u,C+=u,i.length-=u;break}i.mode=_A;break;case Fle:for(;A<14;){if(o===0)break e;o--,s+=I[r++]<>>=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=vi;break}i.have=0,i.mode=Dle;case Dle: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},v=Tv(Vig,i.lens,0,19,i.lencode,0,i.work,R),i.lenbits=R.bits,v){e.msg="invalid code lengths set",i.mode=vi;break}i.have=0,i.mode=xle;case xle:for(;i.have>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=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=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){e.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){e.msg="invalid code -- missing end-of-block",i.mode=vi;break}if(i.lenbits=9,R={bits:i.lenbits},v=Tv(R2e,i.lens,0,i.nlen,i.lencode,0,i.work,R),i.lenbits=R.bits,v){e.msg="invalid literal/lengths set",i.mode=vi;break}if(i.distbits=6,i.distcode=i.distdyn,R={bits:i.distbits},v=Tv(V2e,i.lens,i.nlen,i.ndist,i.distcode,0,i.work,R),i.distbits=R.bits,v){e.msg="invalid distances set",i.mode=vi;break}if(i.mode=n1,g===I1)break e;case n1:i.mode=r1;case r1:if(o>=6&&a>=258){e.next_out=C,e.avail_out=a,e.next_in=r,e.avail_in=o,i.hold=s,i.bits=A,Gig(e,c),C=e.next_out,n=e.output,a=e.avail_out,r=e.next_in,I=e.input,o=e.avail_in,s=i.hold,A=i.bits,i.mode===_A&&(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[r++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=y,A-=y,i.back+=y}if(s>>>=f,A-=f,i.back+=f,i.length=p,b===0){i.mode=Jle;break}if(b&32){i.back=-1,i.mode=_A;break}if(b&64){e.msg="invalid literal/length code",i.mode=vi;break}i.extra=b&15,i.mode=Ele;case Ele:if(i.extra){for(S=i.extra;A>>=i.extra,A-=i.extra,i.back+=i.extra}i.was=i.length,i.mode=Mle;case Mle:for(;m=i.distcode[s&(1<>>24,b=m>>>16&255,p=m&65535,!(f<=A);){if(o===0)break e;o--,s+=I[r++]<>y)],f=m>>>24,b=m>>>16&255,p=m&65535,!(y+f<=A);){if(o===0)break e;o--,s+=I[r++]<>>=y,A-=y,i.back+=y}if(s>>>=f,A-=f,i.back+=f,b&64){e.msg="invalid distance code",i.mode=vi;break}i.offset=p,i.extra=b&15,i.mode=zle;case zle: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=vi;break}i.mode=Ple;case Ple: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=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=C-i.offset,u=i.length;u>a&&(u=a),a-=u,i.length-=u;do n[C++]=h[d++];while(--u);i.length===0&&(i.mode=r1);break;case Jle:if(a===0)break e;n[C++]=i.length,a--,i.mode=r1;break;case Wx:if(i.wrap){for(;A<32;){if(o===0)break e;o--,s|=I[r++]<{if(Zm(e))return oo;let g=e.state;return g.window&&(g.window=null),e.state=null,Fh},zig=(e,g)=>{if(Zm(e))return oo;const i=e.state;return i.wrap&2?(i.head=g,g.done=!1,Fh):oo},Pig=(e,g)=>{const i=g.length;let I,n,r;return Zm(e)||(I=e.state,I.wrap!==0&&I.mode!==XH)?oo:I.mode===XH&&(n=1,n=o_(n,g,i,0),n!==I.check)?W2e:(r=F2e(e,g,i,i),r?(I.mode=H2e,X2e):(I.havedict=1,Fh))};var Jig=k2e,Oig=Y2e,_ig=N2e,Lig=Dig,Uig=K2e,Qig=Eig,jig=Mig,$ig=zig,qig=Pig,eIg="pako inflate (from Nodeca project)",os={inflateReset:Jig,inflateReset2:Oig,inflateResetKeep:_ig,inflateInit:Lig,inflateInit2:Uig,inflate:Qig,inflateEnd:jig,inflateGetHeader:$ig,inflateSetDictionary:qig,inflateInfo:eIg};function tIg(){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 gIg=tIg;const D2e=Object.prototype.toString,{Z_NO_FLUSH:iIg,Z_FINISH:IIg,Z_OK:lS,Z_STREAM_END:Tx,Z_NEED_DICT:Nx,Z_STREAM_ERROR:nIg,Z_DATA_ERROR:Qle,Z_MEM_ERROR:rIg}=e8;function Kw(e){this.options=S2e.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 yig,this.strm.avail_out=0;let i=os.inflateInit2(this.strm,g.windowBits);if(i!==lS)throw new Error(a_[i]);if(this.header=new gIg,os.inflateGetHeader(this.strm,this.header),g.dictionary&&(typeof g.dictionary=="string"?g.dictionary=A_.string2buf(g.dictionary):D2e.call(g.dictionary)==="[object ArrayBuffer]"&&(g.dictionary=new Uint8Array(g.dictionary)),g.raw&&(i=os.inflateSetDictionary(this.strm,g.dictionary),i!==lS)))throw new Error(a_[i])}Kw.prototype.push=function(e,g){const i=this.strm,I=this.options.chunkSize,n=this.options.dictionary;let r,C,o;if(this.ended)return!1;for(g===~~g?C=g:C=g===!0?IIg:iIg,D2e.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),r=os.inflate(i,C),r===Nx&&n&&(r=os.inflateSetDictionary(i,n),r===lS?r=os.inflate(i,C):r===Qle&&(r=Nx));i.avail_in>0&&r===Tx&&i.state.wrap>0&&e[i.next_in]!==0;)os.inflateReset(i),r=os.inflate(i,C);switch(r){case nIg:case Qle:case Nx:case rIg:return this.onEnd(r),this.ended=!0,!1}if(o=i.avail_out,i.next_out&&(i.avail_out===0||r===Tx))if(this.options.to==="string"){let a=A_.utf8border(i.output,i.next_out),s=i.next_out-a,A=A_.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(!(r===lS&&o===0)){if(r===Tx)return r=os.inflateEnd(this.strm),this.onEnd(r),this.ended=!0,!0;if(i.avail_in===0)break}}return!0};Kw.prototype.onData=function(e){this.chunks.push(e)};Kw.prototype.onEnd=function(e){e===lS&&(this.options.to==="string"?this.result=this.chunks.join(""):this.result=S2e.flattenChunks(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};function t8(e,g){const i=new Kw(g);if(i.push(e),i.err)throw i.msg||a_[i.err];return i.result}function CIg(e,g){return g=g||{},g.raw=!0,t8(e,g)}var oIg=Kw,aIg=t8,AIg=CIg,sIg=t8,lIg=e8,cIg={Inflate:oIg,inflate:aIg,inflateRaw:AIg,ungzip:sIg,constants:lIg};const{Inflate:hpg,inflate:mpg,inflateRaw:uIg,ungzip:fpg}=cIg;var dIg=uIg;function hIg(e){return dIg(e.subarray(2))}class mIg extends Error{constructor(g){super(g),this.code="ERR_ABORTED"}}function fIg(e){e.sort((n,r)=>Number(n.offset)-Number(r.offset));const g=[];let i,I;for(let n=0;n=i}function ZIg(e){const g=e?"big":"little",i=new kg().endianess(g).uint32("chromId").uint32("start").uint32("end").uint32("validCnt").floatle("minScore").floatle("maxScore").floatle("sumData").floatle("sumSqData").saveOffset("offset"),I=new kg().endianess(g).uint8("isLeaf").skip(1).uint16("cnt").choice({tag:"isLeaf",choices:{1:new kg().endianess(g).array("blocksToFetch",{length:"cnt",type:new kg().endianess(g).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(g).uint32("startChrom").uint32("startBase").uint32("endChrom").uint32("endBase").uint64("blockOffset").saveOffset("offset")})}}),n=new kg().endianess(g).uint32("chromId").int32("start").int32("end").string("rest",{zeroTerminated:!0}).saveOffset("offset");return{bigWigParser:new kg().endianess(g).skip(4).int32("blockStart").skip(4).uint32("itemStep").uint32("itemSpan").uint8("blockType").skip(1).uint16("itemCount").choice({tag:"blockType",choices:{[yIg]:new kg().array("items",{length:"itemCount",type:new kg().floatle("score")}),[bIg]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").floatle("score")}),[pIg]:new kg().array("items",{length:"itemCount",type:new kg().endianess(g).int32("start").int32("end").floatle("score")})}}),bigBedParser:n,summaryParser:i,leafParser:I}}class x2e{constructor(g,i,I,n,r,C){if(this.bbi=g,this.refsByName=i,this.cirTreeOffset=I,this.isBigEndian=n,this.isCompressed=r,this.blockType=C,this.featureCache=new jgg({cache:new Yet({maxSize:1e3}),fill:async(a,s)=>{const A=Number(a.length),l=Number(a.offset),{buffer:c}=await this.bbi.read(th.Buffer.alloc(A),0,A,l,{signal:s});return c}}),!(I>=0))throw new Error("invalid cirTreeOffset!");const o=ZIg(n);this.leafParser=o.leafParser,this.bigBedParser=o.bigBedParser}async readWigData(g,i,I,n,r){try{const{refsByName:C,bbi:o,cirTreeOffset:a,isBigEndian:s}=this,A=C[g];A===void 0&&n.complete();const l={chrId:A,start:i,end:I};this.cirTreePromise||(this.cirTreePromise=o.read(th.Buffer.alloc(48),0,48,Number(a),r));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(R=>Number(R.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},r.signal);for(let R=0;R{try{h+=y.length;const B=4+Number(u)*32;let G=new nc(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(C){n.error(C)}}parseSummaryBlock(g,i,I){const n=[];let r=i;const C=new DataView(g.buffer,g.byteOffset,g.length);for(;rkx(o.start,o.end,n.start,n.end)):r}parseBigWigBlock(g,i,I){const n=g.subarray(i),r=new DataView(n.buffer,n.byteOffset,n.length);let C=0;C+=4;const o=r.getInt32(C,!0);C+=8;const a=r.getUint32(C,!0);C+=4;const s=r.getUint32(C,!0);C+=4;const A=r.getUint8(C);C+=2;const l=r.getUint16(C,!0);C+=2;const c=new Array(l);switch(A){case 1:for(let u=0;ukx(u.start,u.end,I.start,I.end)):c}async readFeatures(g,i,I={}){try{const{blockType:n,isCompressed:r}=this,{signal:C,request:o}=I,a=fIg(i);C1(C),await Promise.all(a.map(async s=>{C1(C);const{length:A,offset:l}=s,c=await this.featureCache.get(`${A}_${l}`,s,C);s.blocks.forEach(u=>{C1(C);let d=Number(u.offset)-Number(s.offset),h=c;switch(r&&(h=hIg(c.subarray(d)),d=0),C1(C),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 s_=function(e,g){return s_=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])},s_(e,g)};function g8(e,g){if(typeof g!="function"&&g!==null)throw new TypeError("Class extends value "+String(g)+" is not a constructor or null");s_(e,g);function i(){this.constructor=e}e.prototype=g===null?Object.create(g):(i.prototype=g.prototype,new i)}function jle(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 l_(e,g){var i=typeof Symbol=="function"&&e[Symbol.iterator];if(!i)return e;var I=i.call(e),n,r=[],C;try{for(;(g===void 0||g-- >0)&&!(n=I.next()).done;)r.push(n.value)}catch(o){C={error:o}}finally{try{n&&!n.done&&(i=I.return)&&i.call(I)}finally{if(C)throw C.error}}return r}function c_(e,g,i){if(i||arguments.length===2)for(var I=0,n=g.length,r;I=2,!1,!0))}var zIg=function(e,g){return e.push(g),e};function PIg(){return P2e(function(e,g){MIg(zIg,[])(e).subscribe(g)})}const gce=-2003829722,Fx=-2021002517;function JIg(e){return new TextDecoder().decode(e)}function ice(e){const g=e?"big":"little",i=new kg().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 kg().endianess(g).uint32("reductionLevel").uint32("reserved").uint64("dataOffset").uint64("indexOffset")}),I=new kg().endianess(g).uint64("basesCovered").doublele("scoreMin").doublele("scoreMax").doublele("scoreSum").doublele("scoreSumSquares"),n=new kg().endianess(g).uint32("magic").uint32("blockSize").uint32("keySize").uint32("valSize").uint64("itemCount"),r=new kg().endianess(g).uint8("isLeafNode").skip(1).uint16("cnt").saveOffset("offset");return{chromTreeParser:n,totalSummaryParser:I,headerParser:i,isLeafNode:r}}class OIg{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=C=>C,path:n,url:r}=g;if(this.renameRefSeqs=I,i)this.bbi=i;else if(r)this.bbi=new ybe(r);else if(n)this.bbi=new Bme(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(th.Buffer.alloc(i),0,i,0,g),n=this._isBigEndian(I),r=ice(n),C=r.headerParser.parse(I),{magic:o,asOffset:a,totalSummaryOffset:s}=C;if(C.fileType=o===Fx?"bigbed":"bigwig",a>i||s>i)return this._getMainHeader(g,i*2);if(a){const A=Number(C.asOffset);C.autoSql=JIg(I.subarray(A,I.indexOf(0,A)))}if(C.totalSummaryOffset>i)return this._getMainHeader(g,i*2);if(C.totalSummaryOffset){const A=I.subarray(Number(C.totalSummaryOffset)),l=r.totalSummaryParser.parse(A);C.totalSummary={...l,basesCovered:Number(l.basesCovered)}}return{...C,isBigEndian:n}}_isBigEndian(g){let i=g.readInt32LE(0);if(i===gce||i===Fx)return!1;if(i=g.readInt32BE(0),i===gce||i===Fx)return!0;throw new Error("not a BigWig/BigBed file")}async _readChromTree(g,i){const I=g.isBigEndian,n=I?"big":"little",r=[],C={};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(th.Buffer.alloc(s),0,s,Number(a),i),l=ice(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 B=0;B0,C)}async getFeatureStream(g,i,I,n={scale:1}){await this.getHeader(n);const r=this.renameRefSeqs(g);let C;if(n.basesPerSpan?C=await this.getView(1/n.basesPerSpan,n):n.scale?C=await this.getView(n.scale,n):C=await this.getView(1,n),!C)throw new Error("unable to get block view for data");return new TIg(o=>{C.readWigData(r,i,I,o,n)})}async getFeatures(g,i,I,n={scale:1}){const r=await this.getFeatureStream(g,i,I,n);return(await xIg(r.pipe(PIg()))).flat()}}class _Ig extends OIg{async getView(g,i){const{zoomLevels:I,refsByName:n,fileSize:r,isBigEndian:C,uncompressBufSize:o}=await this.getHeader(i),a=1/g;let s=I.length;r||(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 x2e(this.bbi,n,c,C,o>0,"summary")}}return this.getUnzoomedView(i)}}function J2e(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=bi(this.assembly).size,r=[],C={};let o=0;Object.keys(bi(this.assembly).size).forEach((a,s)=>{const A={id:s,chr:a,pos:o};r.push(A),C[a]=A,o+=bi(this.assembly).size[a]}),this.chromSizes={chrToAbs:(a,s)=>this.chromSizes.chrPositions[a].pos+s,cumPositions:r,chrPositions:C,totalLength:o,chromLengths:n},this.dataPromises.push(this.loadBBI(g))}async loadBBI(n){return n.url?(this.bwFile=new _Ig({filehandle:new r0e(n.url,{overrides:n.urlFetchOptions})}),this.bwFile.getHeader().then(r=>{this.bwFileHeader=r})):(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 r=this.chromSizes.totalLength,C={tile_size:this.TILE_SIZE,max_zoom:Math.ceil(Math.log(r/this.TILE_SIZE)/Math.log(2)),max_width:2**Math.ceil(Math.log(r)/Math.log(2)),min_pos:[0],max_pos:[r]};return n&&n(C),C}).catch(r=>(this.tilesetInfoLoading=!1,console.error(r),n&&n({error:`Error parsing bigwig: ${r}`}),null))}fetchTilesDebounced(n,r){const C={},o=[],a=[];for(const s of r){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,r){const C=[1],o=r-n;if(!this.bwFileHeader)throw Error("no bigwig header");this.bwFileHeader.zoomLevels.forEach(s=>{C.push(s.reductionLevel)});let a;return C.forEach(s=>{if(a)return;o/s<=this.TILE_SIZE*20&&(a=s)}),a||C.slice(-1)[0]}};return new i}J2e.config={type:"bigwig"};function O2e(e,g){const{field:i,not:I}=e;let n=Array.from(g);if(Wje(e)){const{oneOf:r}=e;n=n.filter(C=>I?r.indexOf(C[i])===-1:r.indexOf(C[i])!==-1)}else if(Xje(e)){const{inRange:r}=e;n=n.filter(C=>{const o=+C[i];return I?!(r[0]<=o&&o<=r[1]):r[0]<=o&&o<=r[1]})}else if(Hje(e)){const{include:r}=e;n=n.filter(C=>I?`${C[i]}`.includes(r):!`${C[i]}`.includes(r))}return n}function LIg(e,g){const{fields:i,separator:I,newField:n}=e;let r=Array.from(g);return r=r.map(C=>{const o=i.map(a=>C[a]);return C[n]=o.join(I),C}),r}function UIg(e,g){const{field:i,replace:I,newField:n}=e;let r=Array.from(g);return r=r.map(C=>(C[n]=C[i],I.forEach(o=>{const{from:a,to:s}=o;C[n]=C[n].toString().replaceAll(a,s)}),C)),r}function QIg(e,g){const{field:i,base:I,newField:n}=e;let r=Array.from(g);return r=r.map(C=>(+C[i]&&(I==="e"?C[n??i]=Math.log(+C[i]):C[n??i]=Math.log(+C[i])/Math.log(I??10)),C)),r}function jIg(e,g){const{startField:i,endField:I,newField:n}=e,r=Array.from(g);return r.forEach(C=>{const o=C[i],a=C[I];!o||!a||(C[n]=Math.abs(+a-+o))}),r}function $Ig(e,g){const{firstBp:i,secondBp:I,newField:n}=e,r=Array.from(g),[C,o,a,s,A]=["DUP","TRA","DEL","t2tINV","h2hINV"];return r.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]=C;break;default:l[n]="unknown"}}),r}function qIg(e,g,i){const{startField:I,endField:n,newField:r,groupField:C}=e,o={},a=1;return g.forEach(A=>{const l=i(A[I]),c=i(A[n]),u=C?A[C]:"__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),[r??"coverage"]:h,[C??"group"]:l}})})}function eng(e,g,i){const{boundingBox:I,method:n,newField:r}=e,{startField:C,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===C)||!Object.keys(A[0]).find(l=>l===o)))return A;if(n==="pile"){const{maxRows:l}=e,c={};A.sort((d,h)=>d[C]-h[C]).forEach(d=>{const h=+d[C]-s,m=+d[o]+s,f=a?d[a]:"__NO_GROUP__";c[f]||(c[f]=[]);let b=c[f].findIndex(p=>mc[C]-u[C]).forEach(c=>{let u=c[C]-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[`${r}Start`]=`${u+s}`,c[`${r}Etart`]=`${d-s}`,l.push({start:u,end:d})})}return A}function tng(e,g,i="hg38"){const{separator:I,fields:n,flag:r}=e;let C=Array.from(g);return C=C.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=bi(i).interval[o[u]][0]+ +h),a[m]?a[m][c]=f:a[m]=Object.assign(JSON.parse(JSON.stringify(o)),{[c]:f,[r.field]:r.value})})}),[o,...a]}).reduce((o,a)=>o.concat(a),[]),C}function gng(e,g){const{field:i,genomicField:I,baseGenomicField:n,genomicLengthField:r}=e;let C=Array.from(g);return C=C.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[r]),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),[]),C}function ing(e,g){if(kje(e).length===0)return g;const i=u5(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(!ut(I))return g;const n=I.field;if(!n)return g;const r=[...u5(e,"quantitative"),...u5(e,"genomic")],C=[],o=Array.from(new Set(g.map(s=>s[n])));let a=!1;return o.forEach(s=>{const A={};A[n]=s,r.forEach(l=>{const c=e[l];if(!ut(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]))}),C.push(A)}),a?g:C}class Ing{constructor(g){fg(this,$O),fg(this,P$),fg(this,wH),fg(this,e_),fg(this,t_),fg(this,g_),Ct(this,"dataConfig"),Ct(this,"tilesetInfoLoading"),fg(this,mG,void 0),fg(this,aS,void 0),fg(this,AS,void 0),fg(this,Ed,void 0),fg(this,BH,void 0),fg(this,SH,void 0),this.dataConfig=g,this.tilesetInfoLoading=!1,Vr(this,Ed,this.dataConfig.assembly),Vr(this,BH,this.dataConfig.filter),g.url||console.error("Please provide the `url` of the data");const{urlFetchOptions:i,url:I}=g;Vr(this,SH,new r0e(I,{overrides:i})),Vr(this,aS,Si(this,g_,l2e).call(this)),Vr(this,mG,Si(this,$O,o2e).call(this))}tilesetInfo(g){if(Dt(this,mG))return this.tilesetInfoLoading=!0,Dt(this,mG).then(()=>Si(this,e_,A2e).call(this,g)).catch(i=>{this.tilesetInfoLoading=!1,console.error("[Gosling Data Fetcher] Error parsing data:",i)})}fetchTilesDebounced(g,i){const I={},n=[],r=[];for(const C of i){const o=C.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(C),r.push(Si(this,t_,s2e).call(this,a,s,A))}Promise.all(r).then(C=>{C.forEach((o,a)=>{if(o){const s=n[a];I[s]=o,I[s].tilePositionId=s}}),g(I)})}}mG=new WeakMap;aS=new WeakMap;AS=new WeakMap;Ed=new WeakMap;BH=new WeakMap;SH=new WeakMap;$O=new WeakSet;o2e=async function(){var e,g;const{chromosomeField:i,genomicFields:I,headerNames:n,longToWideId:r,genomicFieldsToConvert:C}=this.dataConfig,o=(e=this.dataConfig.separator)!=null?e:",";try{const s=(await Dt(this,SH).readFile()).toString(),A=n?`${n.join(o)} +${s}`:s,l=xet(o).parse(A,c=>Si(this,P$,a2e).call(this,c,C,i,I));if(r&&((g=l[0])!=null&&g[r])){const c=Object.keys(l[0]),u={};l.forEach(d=>{u[d[r]]?c.forEach(h=>{u[d[r]][`${h}_2`]=d[h]}):u[d[r]]=JSON.parse(JSON.stringify(d))}),Vr(this,AS,Object.keys(u).map(d=>u[d]))}else Vr(this,AS,l)}catch(a){console.error("[Gosling Data Fetcher] Error fetching data",a)}};P$=new WeakSet;a2e=function(e,g,i,I){try{return g?g.forEach(n=>{const r=n.genomicFields,C=e[n.chromosomeField];r.forEach(o=>{const a=e[o];e[o]=String(Si(this,wH,qO).call(this,C,a))})}):i&&I&&I.forEach(n=>{const r=e[n],C=e[i];e[n]=String(Si(this,wH,qO).call(this,C,r))}),e}catch{return}};wH=new WeakSet;qO=function(e,g){if(Dt(this,Ed)!=="unknown"){const i=Z3(e,Dt(this,Ed),this.dataConfig.chromosomePrefix);return bi(Dt(this,Ed)).interval[i][0]+ +g}else return g};e_=new WeakSet;A2e=function(e){this.tilesetInfoLoading=!1;const g=1024,i=Dt(this,aS).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};t_=new WeakSet;s2e=async function(e,g,i){var I,n;const r=await this.tilesetInfo();if(!r)return;const C=+r.max_width/2**+e,o=r.min_pos[0]+g*C,a=r.min_pos[0]+(g+1)*C;let s=n0e(Dt(this,AS),[o,a],this.dataConfig);(I=Dt(this,BH))==null||I.forEach(l=>{s=O2e(l,s)});const A=(n=this.dataConfig.sampleLength)!=null?n:1e3;return{tabularData:s.length>A?r7(s,A):s,server:null,tilePos:[g,i],zoomLevel:e}};g_=new WeakSet;l2e=function(){const e=bi(Dt(this,Ed)).size,g=[],i={};let I=0;return Object.keys(e).forEach((n,r)=>{const C={id:r,chr:n,pos:I};g.push(C),i[n]=C,I+=e[n]}),{chrToAbs:(n,r)=>Dt(this,aS).chrPositions[n].pos+r,cumPositions:g,chrPositions:i,totalLength:I,chromLengths:e}};function _2e(e,g,i){if(!new.target)throw new Error('Uncaught TypeError: Class constructor cannot be invoked without "new"');return new Ing(g)}_2e.config={type:"csv"};function L2e(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[r]=n;if(this.dataConfig=r,this.tilesetInfoLoading=!1,this.assembly=this.dataConfig.assembly,!r.values){console.error("Please provide `values` of the JSON data");return}const C=bi(this.assembly).size,o=[],a={};let s=0;Object.keys(bi(this.assembly).size).forEach((u,d)=>{const h={id:d,chr:u,pos:s};o.push(h),a[u]=h,s+=bi(this.assembly).size[u]}),this.chromSizes={chrToAbs:(u,d)=>this.chromSizes.chrPositions[u].pos+d,cumPositions:o,chrPositions:a,totalLength:s,chromLengths:C};const{chromosomeField:A,genomicFields:l,genomicFieldsToConvert:c}=this.dataConfig;this.values=r.values.map(u=>{try{return c?c.forEach(d=>{const h=d.genomicFields,m=Z3(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=Z3(u[A],this.assembly);u[d]=String(this.chromSizes.chrToAbs(m,h))}),u}catch{return}})}tilesetInfo(n){this.tilesetInfoLoading=!1;const r=1024,C=this.chromSizes.totalLength,o={tile_size:r,max_zoom:Math.ceil(Math.log(C/r)/Math.log(2)),max_width:C,min_pos:[0,0],max_pos:[C,C]};return n&&n(o),o}fetchTilesDebounced(n,r){const C={},o=[],a=[];for(const s of r){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];C[c]=A,C[c].tilePositionId=c}),n(C)}),C}tile(n,r,C){var o;const a=this.tilesetInfo(),s=+a.max_width/2**+n,A=a.min_pos[0]+r*s,l=a.min_pos[0]+(r+1)*s;let c=n0e(this.values,[A,l],this.dataConfig);const u=(o=this.dataConfig.sampleLength)!=null?o:1e3;return u{const a=Object.entries(bi(r).size);return await o.init(this.uid,{url:I,indexUrl:n},a,C),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()},rng)}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(Q2e,"config",{type:"gff"});const j2e="KCgpID0+IHsKICB2YXIgX19jcmVhdGUgPSBPYmplY3QuY3JlYXRlOwogIHZhciBfX2RlZlByb3AgPSBPYmplY3QuZGVmaW5lUHJvcGVydHk7CiAgdmFyIF9fZ2V0T3duUHJvcERlc2MgPSBPYmplY3QuZ2V0T3duUHJvcGVydHlEZXNjcmlwdG9yOwogIHZhciBfX2dldE93blByb3BOYW1lcyA9IE9iamVjdC5nZXRPd25Qcm9wZXJ0eU5hbWVzOwogIHZhciBfX2dldFByb3RvT2YgPSBPYmplY3QuZ2V0UHJvdG90eXBlT2Y7CiAgdmFyIF9faGFzT3duUHJvcCA9IE9iamVjdC5wcm90b3R5cGUuaGFzT3duUHJvcGVydH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YjY0LmNoYXJDb2RlQXQoaTIgKyAyKV0gPDwgNiB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDMpXTsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wID4+IDE2ICYgMjU1OwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgPj4gOCAmIDI1NTsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICBpZiAocGxhY2VIb2xkZXJzTGVuID09PSAyKSB7CiAgICAgICAgICB0bXAgPSByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIpXSA8PCAyIHwgcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyICsgMSldID4+IDQ7CiAgICAgICAgICBhcnJbY3VyQnl0ZSsrXSA9IHRtcCAmIDI1NTsKICAgICAgICB9CiAgICAgICAgaWYgKHBsYWNlSG9sZGVyc0xlbiA9PT0gMSkgewogICAgICAgICAgdG1wID0gcmV2TG9va3VwW2I2NC5jaGFyQ29kZUF0KGkyKV0gPDwgMTAgfCByZXZMb29rdXBbYjY0LmNoYXJDb2RlQXQoaTIgKyAxKV0gPDwgNCB8IHJldkxvb2t1cFtiNjQuY2hhckNvZGVBdChpMiArIDIpXSA+PiAyOwogICAgICAgICAgYXJyW2N1ckJ5dGUrK10gPSB0bXAgPj4gOCAmIDI1NTsKICAgICAgICAgIGFycltjdXJCeXRlKytdID0gdG1wICYgMjU1OwogICAgICAgIH0KICAgICAgICByZXR1cm4gYXJyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHRyaXBsZXRUb0Jhc2U2NChudW0pIHsKICAgICAgICByZXR1cm4gbG9va3VwW251bSA+PiAxOCAmIDYzXSArIGxvb2t1cFtudW0gPj4gMTIgJiA2M10gKyBsb29rdXBbbnVtID4+IDYgJiA2M10gKyBsb29rdXBbbnVtICYgNjNdOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGVuY29kZUNodW5rKHVpbnQ4LCBzdGFydCwgZW5kKSB7CiAgICAgICAgdmFyIHRtcDsKICAgICAgICB2YXIgb3V0cHV0ID0gW107CiAgICAgICAgZm9yICh2YXIgaTIgPSBzdGFydDsgaTIgPCBlbmQ7IGkyICs9IDMpIHsKICAgICAgICAgIHRtcCA9ICh1aW50OFtpMl0gPDwgMTYgJiAxNjcxMTY4MCkgKyAodWludDhbaTIgKyAxXSA8PCA4ICYgNjUyODApICsgKHVpbnQ4W2kyICsgMl0gJiAyNTUpOwogICAgICAgICAgb3V0cHV0LnB1c2godHJpcGxldFRvQmFzZTY0KHRtcCkpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb3V0cHV0LmpvaW4oIiIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21CeXRlQXJyYXkodWludDgpIHsKICAgICAgICB2YXIgdG1wOwogICAgICAgIHZhciBsZW4yID0gdWludDgubGVuZ3RoOwogICAgICAgIHZhciBleHRyYUJ5dGVzID0gbGVuMiAlIDM7CiAgICAgICAgdmFyIHBhcnRzID0gW107CiAgICAgICAgdmFyIG1heENodW5rTGVuZ3RoID0gMTYzODM7CiAgICAgICAgZm9yICh2YXIgaTIgPSAwLCBsZW4yMiA9IGxlbjIgLSBleHRyYUJ5dGVzOyBpMiA8IGxlbjIyOyBpMiArPSBtYXhDaHVua0xlbmd0aCkgewogICAgICAgICAgcGFydHMucHVzaChlbmNvZGVDaHVuayh1aW50OCwgaTIsIGkyICsgbWF4Q2h1bmtMZW5ndGggPiBsZW4yMiA/IGxlbjIyIDogaTIgKyBtYXhDaHVua0xlbmd0aCkpOwogICAgICAgIH0KICAgICAgICBpZiAoZXh0cmFCeXRlcyA9PT0gMSkgewogICAgICAgICAgdG1wID0gdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDJdICsgbG9va3VwW3RtcCA8PCA0ICYgNjNdICsgIj09Iik7CiAgICAgICAgfSBlbHNlIGlmIChleHRyYUJ5dGVzID09PSAyKSB7CiAgICAgICAgICB0bXAgPSAodWludDhbbGVuMiAtIDJdIDw8IDgpICsgdWludDhbbGVuMiAtIDFdOwogICAgICAgICAgcGFydHMucHVzaChsb29rdXBbdG1wID4+IDEwXSArIGxvb2t1cFt0bXAgPj4gNCAmIDYzXSArIGxvb2t1cFt0bXAgPDwgMiAmIDYzXSArICI9Iik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwYXJ0cy5qb2luKCIiKTsKICAgICAgfQogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcwogIHZhciByZXF1aXJlX2llZWU3NTQgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vaWVlZTc1NEAxLjIuMS9ub2RlX21vZHVsZXMvaWVlZTc1NC9pbmRleC5qcyIoZXhwb3J0czIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICBleHBvcnRzMi5yZWFkID0gZnVuY3Rpb24oYnVmZmVyLCBvZmZzZXQsIGlzTEUsIG1MZW4sIG5CeXRlcykgewogICAgICAgIHZhciBlLCBtOwogICAgICAgIHZhciBlTGVuID0gbkJ5dGVzICogOCAtIG1MZW4gLSAxOwogICAgICAgIHZhciBlTWF4ID0gKDEgPDwgZUxlbikgLSAxOwogICAgICAgIHZhciBlQmlhcyA9IGVNYXggPj4gMTsKICAgICAgICB2YXIgbkJpdHMgPSAtNzsKICAgICAgICB2YXIgaSA9IGlzTEUgPyBuQnl0ZXMgLSAxIDogMDsKICAgICAgICB2YXIgZCA9IGlzTEUgPyAtMSA6IDE7CiAgICAgICAgdmFyIHMgPSBidWZmZXJbb2Zmc2V0ICsgaV07CiAgICAgICAgaSArPSBkOwogICAgICAgIGUgPSBzICYgKDEgPDwgLW5CaXRzKSAtIDE7CiAgICAgICAgcyA+Pj0gLW5CaXRzOwogICAgICAgIG5CaXRzICs9IGVMZW47CiAgICAgICAgZm9yICg7IG5CaXRzID4gMDsgZSA9IGUgKiAyNTYgKyBidWZmZXJbb2Zmc2V0ICsgaV0sIGkgKz0gZCwgbkJpdHMgLT0gOCkgewogICAgICAgIH0KICAgICAgICBtID0gZSAmICgxIDw8IC1uQml0cykgLSAxOwogICAgICAgIGUgPj49IC1uQml0czsKICAgICAgICBuQml0cyArPSBtTGVuOwogICAgICAgIGZvciAoOyBuQml0cyA+IDA7IG0gPSBtICogMjU2ICsgYnVmZmVyW29mZnNldCArIGldLCBpICs9IGQsIG5CaXRzIC09IDgpIHsKICAgICAgICB9CiAgICAgICAgaWYgKGUgPT09IDApIHsKICAgICAgICAgIGUgPSAxIC0gZUJpYXM7CiAgICAgICAgfSBlbHNlIGlmIChlID09PSBlTWF4KSB7CiAgICAgICAgICByZXR1cm4gbSA/IE5hTiA6IChzID8gLTEgOiAxKSAqIEluZmluaXR5OwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBtID0gbSArIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgZSA9IGUgLSBlQmlhczsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIChzID8gLTEgOiAxKSAqIG0gKiBNYXRoLnBvdygyLCBlIC0gbUxlbik7CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLndyaXRlID0gZnVuY3Rpb24oYnVmZmVyLCB2YWx1ZSwgb2Zmc2V0LCBpc0xFLCBtTGVuLCBuQnl0ZXMpIHsKICAgICAgICB2YXIgZSwgbSwgYzsKICAgICAgICB2YXIgZUxlbiA9IG5CeXRlcyAqIDggLSBtTGVuIC0gMTsKICAgICAgICB2YXIgZU1heCA9ICgxIDw8IGVMZW4pIC0gMTsKICAgICAgICB2YXIgZUJpYXMgPSBlTWF4ID4+IDE7CiAgICAgICAgdmFyIHJ0ID0gbUxlbiA9PT0gMjMgPyBNYXRoLnBvdygyLCAtMjQpIC0gTWF0aC5wb3coMiwgLTc3KSA6IDA7CiAgICAgICAgdmFyIGkgPSBpc0xFID8gMCA6IG5CeXRlcyAtIDE7CiAgICAgICAgdmFyIGQgPSBpc0xFID8gMSA6IC0xOwogICAgICAgIHZhciBzID0gdmFsdWUgPCAwIHx8IHZhbHVlID09PSAwICYmIDEgLyB2YWx1ZSA8IDAgPyAxIDogMDsKICAgICAgICB2YWx1ZSA9IE1hdGguYWJzKHZhbHVlKTsKICAgICAgICBpZiAoaXNOYU4odmFsdWUpIHx8IHZhbHVlID09PSBJbmZpbml0eSkgewogICAgICAgICAgbSA9IGlzTmFOKHZhbHVlKSA/IDEgOiAwOwogICAgICAgICAgZSA9IGVNYXg7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGUgPSBNYXRoLmZsb29yKE1hdGgubG9nKHZhbHVlKSAvIE1hdGguTE4yKTsKICAgICAgICAgIGlmICh2YWx1ZSAqIChjID0gTWF0aC5wb3coMiwgLWUpKSA8IDEpIHsKICAgICAgICAgICAgZS0tOwogICAgICAgICAgICBjICo9IDI7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgLyBjOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdmFsdWUgKz0gcnQgKiBNYXRoLnBvdygyLCAxIC0gZUJpYXMpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbHVlICogYyA+PSAyKSB7CiAgICAgICAgICAgIGUrKzsKICAgICAgICAgICAgYyAvPSAyOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGUgKyBlQmlhcyA+PSBlTWF4KSB7CiAgICAgICAgICAgIG0gPSAwOwogICAgICAgICAgICBlID0gZU1heDsKICAgICAgICAgIH0gZWxzZSBpZiAoZSArIGVCaWFzID49IDEpIHsKICAgICAgICAgICAgbSA9ICh2YWx1ZSAqIGMgLSAxKSAqIE1hdGgucG93KDIsIG1MZW4pOwogICAgICAgICAgICBlID0gZSArIGVCaWFzOw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lwZSk7CiAgICAgICAgICBPYmplY3Quc2V0UHJvdG90eXBlT2YoYXJyLCBwcm90byk7CiAgICAgICAgICByZXR1cm4gYXJyLmZvbygpID09PSA0MjsKICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICB9CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShCdWZmZXIxMC5wcm90b3R5cGUsICJwYXJlbnQiLCB7CiAgICAgICAgZW51bWVyYWJsZTogdHJ1ZSwKICAgICAgICBnZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcih0aGlzKSkKICAgICAgICAgICAgcmV0dXJuIHZvaWQgMDsKICAgICAgICAgIHJldHVybiB0aGlzLmJ1ZmZlcjsKICAgICAgICB9CiAgICAgIH0pOwogICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoQnVmZmVyMTAucHJvdG90eXBlLCAib2Zmc2V0IiwgewogICAgICAgIGVudW1lcmFibGU6IHRydWUsCiAgICAgICAgZ2V0OiBmdW5jdGlvbigpIHsKICAgICAgICAgIGlmICghQnVmZmVyMTAuaXNCdWZmZXIodGhpcykpCiAgICAgICAgICAgIHJldHVybiB2b2lkIDA7CiAgICAgICAgICByZXR1cm4gdGhpcy5ieXRlT2Zmc2V0OwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGZ1bmN0aW9uIGNyZWF0ZUJ1ZmZlcihsZW5ndGgpIHsKICAgICAgICBpZiAobGVuZ3RoID4gS19NQVhfTEVOR1RIKSB7CiAgICAgICAgICB0aHJvdyBuZXcgUmFuZ2VFcnJvcignVGhlIHZhbHVlICInICsgbGVuZ3RoICsgJyIgaXMgaW52YWxpZCBmb3Igb3B0aW9uICJzaXplIicpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWYgPSBuZXcgVWludDhBcnJheShsZW5ndGgpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihidWYsIEJ1ZmZlcjEwLnByb3RvdHlwZSk7CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfQogICAgICBmdW5jdGlvbiBCdWZmZXIxMChhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCkgewogICAgICAgIGlmICh0eXBlb2YgYXJnID09PSAibnVtYmVyIikgewogICAgICAgICAgaWYgKHR5cGVvZiBlbmNvZGluZ09yT2Zmc2V0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdUaGUgInN0cmluZyIgYXJndW1lbnQgbXVzdCBiZSBvZiB0eXBlIHN0cmluZy4gUmVjZWl2ZWQgdHlwZSBudW1iZXInKTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhbGxvY1Vuc2FmZShhcmcpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZnJvbShhcmcsIGVuY29kaW5nT3JPZmZzZXQsIGxlbmd0aCk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucG9vbFNpemUgPSA4MTkyOwogICAgICBmdW5jdGlvbiBmcm9tKHZhbHVlLCBlbmNvZGluZ09yT2Zmc2V0LCBsZW5ndGgpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbHVlID09PSAic3RyaW5nIikgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcodmFsdWUsIGVuY29kaW5nT3JPZmZzZXQpOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHZhbHVlKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheVZpZXcodmFsdWUpOwogICAgICAgIH0KICAgICAgICBpZiAodmFsdWUgPT0gbnVsbCkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcigiVGhlIGZpcnN0IGFyZ3VtZW50IG11c3QgYmUgb25lIG9mIHR5cGUgc3RyaW5nLCBCdWZmZXIsIEFycmF5QnVmZmVyLCBBcnJheSwgb3Ig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lKHNpemUpOwogICAgICB9OwogICAgICBCdWZmZXIxMC5hbGxvY1Vuc2FmZVNsb3cgPSBmdW5jdGlvbihzaXplKSB7CiAgICAgICAgcmV0dXJuIGFsbG9jVW5zYWZlKHNpemUpOwogICAgICB9OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0cmluZywgZW5jb2RpbmcpIHsKICAgICAgICBpZiAodHlwZW9mIGVuY29kaW5nICE9PSAic3RyaW5nIiB8fCBlbmNvZGluZyA9PT0gIiIpIHsKICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgIH0KICAgICAgICBpZiAoIUJ1ZmZlcjEwLmlzRW5jb2RpbmcoZW5jb2RpbmcpKSB7CiAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBjb25zdCBsZW5ndGggPSBieXRlTGVuZ3RoKHN0cmluZywgZW5jb2RpbmcpIHwgMDsKICAgICAgICBsZXQgYnVmID0gY3JlYXRlQnVmZmVyKGxlbmd0aCk7CiAgICAgICAgY29uc3QgYWN0dWFsID0gYnVmLndyaXRlKHN0cmluZywgZW5jb2RpbmcpOwogICAgICAgIGlmIChhY3R1YWwgIT09IGxlbmd0aCkgewogICAgICAgICAgYnVmID0gYnVmLnNsaWNlKDAsIGFjdHVhbCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBidWY7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZnJvbUFycmF5TGlrZShhcnJheSkgewogICAgICAgIGNvbnN0IGxlbmd0aCA9IGFycmF5Lmxlbmd0aCA8IDAgPyAwIDogY2hlY2tlZChhcnJheS5sZW5ndGgpIHwgMDsKICAgICAgICBjb25zdCBidWYgPSBjcmVhdGVCdWZmZXIobGVuZ3RoKTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgaSArPSAxKSB7CiAgICAgICAgICBidWZbaV0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ICAgICAgICAgYnVmID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXksIGJ5dGVPZmZzZXQpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBidWYgPSBuZXcgVWludDhBcnJheShhcnJheSwgYnl0ZU9mZnNldCwgbGVuZ3RoKTsKICAgICAgICB9CiAgICAgICAgT2JqZWN0LnNldFByb3RvdHlwZU9mKGJ1ZiwgQnVmZmVyMTAucHJvdG90eXBlKTsKICAgICAgICByZXR1cm4gYnVmOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGZyb21PYmplY3Qob2JqKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKG9iaikpIHsKICAgICAgICAgIGNvbnN0IGxlbiA9IGNoZWNrZWQob2JqLmxlbmd0aCkgfCAwOwogICAgICAgICAgY29uc3QgYnVmID0gY3JlYXRlQnVmZmVyKGxlbik7CiAgICAgICAgICBpZiAoYnVmLmxlbmd0aCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gYnVmOwogICAgICAgICAgfQogICAgICAgICAgb2JqLmNvcHkoYnVmLCAwLCAwLCBsZW4pOwogICAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai5sZW5ndGggIT09IHZvaWQgMCkgewogICAgICAgICAgaWYgKHR5cGVvZiBvYmoubGVuZ3RoICE9PSAibnVtYmVyIiB8fCBudW1iZXJJc05hTihvYmoubGVuZ3RoKSkgewogICAgICAgICAgICByZXR1cm4gY3JlYXRlQnVmZmVyKDApOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqKTsKICAgICAgICB9CiAgICAgICAgaWYgKG9iai50eXBlID09PSAiQnVmZmVyIiAmJiBBcnJheS5pc0FycmF5KG9iai5kYXRhKSkgewogICAgICAgICAgcmV0dXJuIGZyb21BcnJheUxpa2Uob2JqLmRhdGEpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvb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AgdGhyb3cgbmV3IFR5cGVFcnJvcignVGhlICJidWYxIiwgImJ1ZjIiIGFyZ3VtZW50cyBtdXN0IGJlIG9uZSBvZiB0eXBlIEJ1ZmZlciBvciBVaW50OEFycmF5Jyk7CiAgICAgICAgfQogICAgICAgIGlmIChhID09PSBiKQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSBhLmxlbmd0aDsKICAgICAgICBsZXQgeSA9IGIubGVuZ3RoOwogICAgICAgIGZvciAobGV0IGkgPSAwLCBsZW4gPSBNYXRoLm1pbih4LCB5KTsgaSA8IGxlbjsgKytpKSB7CiAgICAgICAgICBpZiAoYVtpXSAhPT0gYltpXSkgewogICAgICAgICAgICB4ID0gYVtpXTsKICAgICAgICAgICAgeSA9IGJbaV07CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoeCA8IHkpCiAgICAgICAgICByZXR1cm4gLTE7CiAgICAgICAgaWYgKHkgPCB4KQogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgcmV0dXJuIDA7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLmlzRW5jb2RpbmcgPSBmdW5jdGlvbiBpc0VuY29kaW5nKGVuY29kaW5nKSB7CiAgICAgICAgc3dpdGNoIChTdHJpbmcoZW5jb2RpbmcpLnRvTG93ZXJDYXNlKCkpIHsKICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICBjYXNlICJ1dGY4IjoKICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgIGNhc2UgImFzY2lpIjoKICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgY2FzZSAidWNzLTIiOgogICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfTsKICAgICAgQnVmZmVyMTAuY29uY2F0ID0gZnVuY3Rpb24gY29uY2F0KGxpc3QsIGxlbmd0aCkgewogICAgICAgIGlmICghQXJyYXkuaXNBcnJheShsaXN0KSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignImxpc3QiIGFyZ3VtZW50IG11c3QgYmUgYW4gQXJyYXkgb2YgQnVmZmVycycpOwogICAgICAgIH0KICAgICAgICBpZiAobGlzdC5sZW5ndGggPT09IDApIHsKICAgICAgICAgIHJldHVybiBCdWZmZXIxMC5hbGxvYygwKTsKICAgICAgICB9CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gdm9pZCAwKSB7CiAgICAgICAgICBsZW5ndGggPSAwOwogICAgICAgICAgZm9yIChpID0gMDsgaSA8IGxpc3QubGVuZ3RoOyArK2kpIHsKICAgICAgICAgICAgbGVuZ3RoICs9IGxpc3RbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIgPSBCdWZmZXIxMC5hbGxvY1Vuc2FmZShsZW5ndGgpOwogICAgICAgIGxldCBwb3MgPSAwOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsaXN0Lmxlbmd0aDsgKytpKSB7CiAgICAgICAgICBsZXQgYnVmID0gbGlzdFtpXTsKICAgICAgICAgIGlmIChpc0luc3RhbmNlKGJ1ZiwgVWludDhBcnJheSkpIHsKICAgICAgICAgICAgaWYgKHBvcyArIGJ1Zi5sZW5ndGggPiBidWZmZXIubGVuZ3RoKSB7CiAgICAgICAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihidWYpKQogICAgICAgICAgICAgICAgYnVmID0gQnVmZmVyMTAuZnJvbShidWYpOwogICAgICAgICAgICAgIGJ1Zi5jb3B5KGJ1ZmZlciwgcG9zKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBVaW50OEFycmF5LnByb3RvdHlwZS5zZXQuY2FsbChidWZmZXIsIGJ1ZiwgcG9zKTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIGlmICghQnVmZmVyMTAuaXNCdWZmZXIoYnVmKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCcibGlzdCIgYXJndW1lbnQgbXVzdCBiZSBhbiBBcnJheSBvZiBCdWZmZXJzJyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWYuY29weShidWZmZXIsIHBvcyk7CiAgICAgICAgICB9CiAgICAgICAgICBwb3MgKz0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZmZlcjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnl0ZUxlbmd0aChzdHJpbmcsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKEJ1ZmZlcjEwLmlzQnVmZmVyKHN0cmluZykpIHsKICAgICAgICAgIHJldHVybiBzdHJpbmcubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoQXJyYXlCdWZmZXIuaXNWaWV3KHN0cmluZykgfHwgaXNJbnN0YW5jZShzdHJpbmcsIEFycmF5QnVmZmVyKSkgewogICAgICAgICAgcmV0dXJuIHN0cmluZy5ieXRlTGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAodHlwZW9mIHN0cmluZyAhPT0gInN0cmluZyIpIHsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSAic3RyaW5nIiBhcmd1bWVudCBtdXN0IGJlIG9uZSBvZiB0eXBlIHN0cmluZywgQnVmZmVyLCBvciBBcnJheUJ1ZmZlci4gUmVjZWl2ZWQgdHlwZSAnICsgdHlwZW9mIHN0cmluZyk7CiAgICAgICAgfQogICAgICAgIGNvbnN0IGxlbiA9IHN0cmluZy5sZW5ndGg7CiAgICAgICAgY29uc3QgbXVzdE1hdGNoID0gYXJndW1lbnRzLmxlbmd0aCA+IDIgJiYgYXJndW1lbnRzWzJdID09PSB0cnVlOwogICAgICAgIGlmICghbXVzdE1hdGNoICYmIGxlbiA9PT0gMCkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgc3dpdGNoIChlbmNvZGluZykgewogICAgICAgICAgICBjYXNlICJhc2NpaSI6CiAgICAgICAgICAgIGNhc2UgImxhdGluMSI6CiAgICAgICAgICAgIGNhc2UgImJpbmFyeSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbjsKICAgICAgICAgICAgY2FzZSAidXRmOCI6CiAgICAgICAgICAgIGNhc2UgInV0Zi04IjoKICAgICAgICAgICAgICByZXR1cm4gdXRmOFRvQnl0ZXMoc3RyaW5nKS5sZW5ndGg7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiAqIDI7CiAgICAgICAgICAgIGNhc2UgImhleCI6CiAgICAgICAgICAgICAgcmV0dXJuIGxlbiA+Pj4gMTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0VG9CeXRlcyhzdHJpbmcpLmxlbmd0aDsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpIHsKICAgICAgICAgICAgICAgIHJldHVybiBtdXN0TWF0Y2ggPyAtMSA6IHV0ZjhUb0J5dGVzKHN0cmluZykubGVuZ3RoOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBlbmNvZGluZyA9ICgiIiArIGVuY29kaW5nKS50b0xvd2VyQ2FzZSgpOwogICAgICAgICAgICAgIGxvd2VyZWRDYXNlID0gdHJ1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgQnVmZmVyMTAuYnl0ZUxlbmd0aCA9IGJ5dGVMZW5ndGg7CiAgICAgIGZ1bmN0aW9uIHNsb3dUb1N0cmluZyhlbmNvZGluZywgc3RhcnQsIGVuZCkgewogICAgICAgIGxldCBsb3dlcmVkQ2FzZSA9IGZhbHNlOwogICAgICAgIGlmIChzdGFydCA9PT0gdm9pZCAwIHx8IHN0YXJ0IDwgMCkgewogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kID09PSB2b2lkIDAgfHwgZW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDw9IDApIHsKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICB9CiAgICAgICAgZW5kID4+Pj0gMDsKICAgICAgICBzdGFydCA+Pj49IDA7CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIH0KICAgICAgICBpZiAoIWVuY29kaW5nKQogICAgICAgICAgZW5jb2RpbmcgPSAidXRmOCI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVNsaWNlKHRoaXMsIHN0YXJ0LCBlbmQpOwogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBsYXRpbjFTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgY2FzZSAiYmFzZTY0IjoKICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0U2xpY2UodGhpcywgc3RhcnQsIGVuZCk7CiAgICAgICAgICAgIGNhc2UgInVjczIiOgogICAgICAgICAgICBjYXNlICJ1Y3MtMiI6CiAgICAgICAgICAgIGNhc2UgInV0ZjE2bGUiOgogICAgICAgICAgICBjYXNlICJ1dGYtMTZsZSI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjE2bGVTbGljZSh0aGlzLCBzdGFydCwgZW5kKTsKICAgICAgICAgICAgZGVmYXVsdDoKICAgICAgICAgICAgICBpZiAobG93ZXJlZENhc2UpCiAgICAgICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgICAgIGVuY29kaW5nID0gKGVuY29kaW5nICsgIiIpLnRvTG93ZXJDYXNlKCk7CiAgICAgICAgICAgICAgbG93ZXJlZENhc2UgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuX2lzQnVmZmVyID0gdHJ1ZTsKICAgICAgZnVuY3Rpb24gc3dhcChiLCBuLCBtKSB7CiAgICAgICAgY29uc3QgaSA9IGJbbl07CiAgICAgICAgYltuXSA9IGJbbV07CiAgICAgICAgYlttXSA9IGk7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAxNiA9IGZ1bmN0aW9uIHN3YXAxNigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgMiAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAxNi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDIpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDEpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXAzMiA9IGZ1bmN0aW9uIHN3YXAzMigpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgNCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiAzMi1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDQpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDMpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDIpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnN3YXA2NCA9IGZ1bmN0aW9uIHN3YXA2NCgpIHsKICAgICAgICBjb25zdCBsZW4gPSB0aGlzLmxlbmd0aDsKICAgICAgICBpZiAobGVuICUgOCAhPT0gMCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkJ1ZmZlciBzaXplIG11c3QgYmUgYSBtdWx0aXBsZSBvZiA2NC1iaXRzIik7CiAgICAgICAgfQogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGVuOyBpICs9IDgpIHsKICAgICAgICAgIHN3YXAodGhpcywgaSwgaSArIDcpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMSwgaSArIDYpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMiwgaSArIDUpOwogICAgICAgICAgc3dhcCh0aGlzLCBpICsgMywgaSArIDQpOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnRvU3RyaW5nID0gZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gdGhpcy5sZW5ndGg7CiAgICAgICAgaWYgKGxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiAiIjsKICAgICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMCkKICAgICAgICAgIHJldHVybiB1dGY4U2xpY2UodGhpcywgMCwgbGVuZ3RoKTsKICAgICAgICByZXR1cm4gc2xvd1RvU3RyaW5nLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyk7CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS50b0xvY2FsZVN0cmluZyA9IEJ1ZmZlcjEwLnByb3RvdHlwZS50b1N0cmluZzsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmVxdWFscyA9IGZ1bmN0aW9uIGVxdWFscyhiKSB7CiAgICAgICAgaWYgKCFCdWZmZXIxMC5pc0J1ZmZlcihiKSkKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIkFyZ3VtZW50IG11c3QgYmUgYSBCdWZmZXIiKTsKICAgICAgICBpZiAodGhpcyA9PT0gYikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHJldHVybiBCdWZmZXIxMC5jb21wYXJlKHRoaXMsIGIpID09PSAwOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW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dm9pZCAwKSB7CiAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgfQogICAgICAgIGlmIChlbmQgPT09IHZvaWQgMCkgewogICAgICAgICAgZW5kID0gdGFyZ2V0ID8gdGFyZ2V0Lmxlbmd0aCA6IDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPT09IHZvaWQgMCkgewogICAgICAgICAgdGhpc1N0YXJ0ID0gMDsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXNFbmQgPT09IHZvaWQgMCkgewogICAgICAgICAgdGhpc0VuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IGVuZCA+IHRhcmdldC5sZW5ndGggfHwgdGhpc1N0YXJ0IDwgMCB8fCB0aGlzRW5kID4gdGhpcy5sZW5ndGgpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJvdXQgb2YgcmFuZ2UgaW5kZXgiKTsKICAgICAgICB9CiAgICAgICAgaWYgKHRoaXNTdGFydCA+PSB0aGlzRW5kICYmIHN0YXJ0ID49IGVuZCkgewogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGlmICh0aGlzU3RhcnQgPj0gdGhpc0VuZCkgewogICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPj0gZW5kKSB7CiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgc3RhcnQgPj4+PSAwOwogICAgICAgIGVuZCA+Pj49IDA7CiAgICAgICAgdGhpc1N0YXJ0ID4+Pj0gMDsKICAgICAgICB0aGlzRW5kID4+Pj0gMDsKICAgICAgICBpZiAodGhpcyA9PT0gdGFyZ2V0KQogICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgbGV0IHggPSB0aGlzRW5kIC0gdGhpc1N0YXJ0OwogICAgICAgIGxldCB5ID0gZW5kIC0gc3RhcnQ7CiAgICAgICA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IH0KICAgICAgICBieXRlT2Zmc2V0ID0gK2J5dGVPZmZzZXQ7CiAgICAgICAgaWYgKG51bWJlcklzTmFOKGJ5dGVPZmZzZXQpKSB7CiAgICAgICAgICBieXRlT2Zmc2V0ID0gZGlyID8gMCA6IGJ1ZmZlci5sZW5ndGggLSAxOwogICAgICAgIH0KICAgICAgICBpZiAoYnl0ZU9mZnNldCA8IDApCiAgICAgICAgICBieXRlT2Zmc2V0ID0gYnVmZmVyLmxlbmd0aCArIGJ5dGVPZmZzZXQ7CiAgICAgICAgaWYgKGJ5dGVPZmZzZXQgPj0gYnVmZmVyLmxlbmd0aCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgZWxzZQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYnVmZmVyLmxlbmd0aCAtIDE7CiAgICAgICAgfSBlbHNlIGlmIChieXRlT2Zmc2V0IDwgMCkgewogICAgICAgICAgaWYgKGRpcikKICAgICAgICAgICAgYnl0ZU9mZnNldCA9IDA7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB2YWwgPSBCdWZmZXIxMC5mcm9tKHZhbCwgZW5jb2RpbmcpOwogICAgICAgIH0KICAgICAgICBpZiAoQnVmZmVyMTAuaXNCdWZmZXIodmFsKSkgewogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIGFycmF5SW5kZXhPZihidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAibnVtYmVyIikgewogICAgICAgICAgdmFsID0gdmFsICYgMjU1OwogICAgICAgICAgaWYgKHR5cGVvZiBVaW50OEFycmF5LnByb3RvdHlwZS5pbmRleE9mID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUuaW5kZXhPZi5jYWxsKGJ1ZmZlciwgdmFsLCBieXRlT2Zmc2V0KTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICByZXR1cm4gVWludDhBcnJheS5wcm90b3R5cGUubGFzdEluZGV4T2YuY2FsbChidWZmZXIsIHZhbCwgYnl0ZU9mZnNldCk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBhcnJheUluZGV4T2YoYnVmZmVyLCBbdmFsXSwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcik7CiAgICAgICAgfQogICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoInZhbCBtdXN0IGJlIHN0cmluZywgbnVtYmVyIG9yIEJ1ZmZlciIpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGFycmF5SW5kZXhPZihhcnIsIHZhbCwgYnl0ZU9mZnNldCwgZW5jb2RpbmcsIGRpcikgewogICAgICAgIGxldCBpbmRleFNpemUgPSAxOwogICAgICAgIGxldCBhcnJMZW5ndGggPSBhcnIubGVuZ3RoOwogICAgICAgIGxldCB2YWxMZW5ndGggPSB2YWwubGVuZ3RoOwogICAgICAgIGlmIChlbmNvZGluZyAhPT0gdm9pZCAwKSB7CiAgICAgICAgICBlbmNvZGluZyA9IFN0cmluZyhlbmNvZGluZykudG9Mb3dlckNhc2UoKTsKICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gInVjczIiIHx8IGVuY29kaW5nID09PSAidWNzLTIiIHx8IGVuY29kaW5nID09PSAidXRmMTZsZSIgfHwgZW5jb2RpbmcgPT09ICJ1dGYtMTZsZSIpIHsKICAgICAgICAgICAgaWYgKGFyci5sZW5ndGggPCAyIHx8IHZhbC5sZW5ndGggPCAyKSB7CiAgICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGluZGV4U2l6ZSA9IDI7CiAgICAgICAgICAgIGFyckxlbmd0aCAvPSAyOwogICAgICAgICAgICB2YWxMZW5ndGggLz0gMjsKICAgICAgICAgICAgYnl0ZU9mZnNldCAvPSAyOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiByZWFkKGJ1ZiwgaTIpIHsKICAgICAgICAgIGlmIChpbmRleFNpemUgPT09IDEpIHsKICAgICAgICAgICAgcmV0dXJuIGJ1ZltpMl07CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gYnVmLnJlYWRVSW50MTZCRShpMiAqIGluZGV4U2l6ZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGxldCBpOwogICAgICAgIGlmIChkaXIpIHsKICAgICAgICAgIGxldCBmb3VuZEluZGV4ID0gLTE7CiAgICAgICAgICBmb3IgKGkgPSBieXRlT2Zmc2V0OyBpIDwgYXJyTGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgaWYgKHJlYWQoYXJyLCBpKSA9PT0gcmVhZCh2YWwsIGZvdW5kSW5kZXggPT09IC0xID8gMCA6IGkgLSBmb3VuZEluZGV4KSkgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ID09PSAtMSkKICAgICAgICAgICAgICAgIGZvdW5kSW5kZXggPSBpOwogICAgICAgICAgICAgIGlmIChpIC0gZm91bmRJbmRleCArIDEgPT09IHZhbExlbmd0aCkKICAgICAgICAgICAgICAgIHJldHVybiBmb3VuZEluZGV4ICogaW5kZXhTaXplOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGlmIChmb3VuZEluZGV4ICE9PSAtMSkKICAgICAgICAgICAgICAgIGkgLT0gaSAtIGZvdW5kSW5kZXg7CiAgICAgICAgICAgICAgZm91bmRJbmRleCA9IC0xOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGlmIChieXRlT2Zmc2V0ICsgdmFsTGVuZ3RoID4gYXJyTGVuZ3RoKQogICAgICAgICAgICBieXRlT2Zmc2V0ID0gYXJyTGVuZ3RoIC0gdmFsTGVuZ3RoOwogICAgICAgICAgZm9yIChpID0gYnl0ZU9mZnNldDsgaSA+PSAwOyBpLS0pIHsKICAgICAgICAgICAgbGV0IGZvdW5kID0gdHJ1ZTsKICAgICAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCB2YWxMZW5ndGg7IGorKykgewogICAgICAgICAgICAgIGlmIChyZWFkKGFyciwgaSArIGopICE9PSByZWFkKHZhbCwgaikpIHsKICAgICAgICAgICAgICAgIGZvdW5kID0gZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGZvdW5kKQogICAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmluY2x1ZGVzID0gZnVuY3Rpb24gaW5jbHVkZXModmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiB0aGlzLmluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgIT09IC0xOwogICAgICB9OwogICAgICBCdWZmZXIxMC5wcm90b3R5cGUuaW5kZXhPZiA9IGZ1bmN0aW9uIGluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCB0cnVlKTsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLmxhc3RJbmRleE9mID0gZnVuY3Rpb24gbGFzdEluZGV4T2YodmFsLCBieXRlT2Zmc2V0LCBlbmNvZGluZykgewogICAgICAgIHJldHVybiBiaWRpcmVjdGlvbmFsSW5kZXhPZih0aGlzLCB2YWwsIGJ5dGVPZmZzZXQsIGVuY29kaW5nLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIGZ1bmN0aW9uIGhleFdyaXRlKGJ1Ziwgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCkgewogICAgICAgIG9mZnNldCA9IE51bWJlcihvZmZzZXQpIHx8IDA7CiAgICAgICAgY29uc3QgcmVtYWluaW5nID0gYnVmLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAoIWxlbmd0aCkgewogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBsZW5ndGggPSBOdW1iZXIobGVuZ3RoKTsKICAgICAgICAgIGlmIChsZW5ndGggPiByZW1haW5pbmcpIHsKICAgICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb25zdCBzdHJMZW4gPSBzdHJpbmcubGVuZ3RoOwogICAgICAgIGlmIChsZW5ndGggPiBzdHJMZW4gLyAyKSB7CiAgICAgICAgICBsZW5ndGggPSBzdHJMZW4gLyAyOwogICAgICAgIH0KICAgICAgICBsZXQgaTsKICAgICAgICBmb3IgKGkgPSAwOyBpIDwgbGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGNvbnN0IHBhcnNlZCA9IHBhcnNlSW50KHN0cmluZy5zdWJzdHIoaSAqIDIsIDIpLCAxNik7CiAgICAgICAgICBpZiAobnVtYmVySXNOYU4ocGFyc2VkKSkKICAgICAgICAgICAgcmV0dXJuIGk7CiAgICAgICAgICBidWZbb2Zmc2V0ICsgaV0gPSBwYXJzZWQ7CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhXcml0ZShidWYsIHN0cmluZ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gICAgZW5jb2RpbmcgPSBvZmZzZXQ7CiAgICAgICAgICBsZW5ndGggPSB0aGlzLmxlbmd0aDsKICAgICAgICAgIG9mZnNldCA9IDA7CiAgICAgICAgfSBlbHNlIGlmIChpc0Zpbml0ZShvZmZzZXQpKSB7CiAgICAgICAgICBvZmZzZXQgPSBvZmZzZXQgPj4+IDA7CiAgICAgICAgICBpZiAoaXNGaW5pdGUobGVuZ3RoKSkgewogICAgICAgICAgICBsZW5ndGggPSBsZW5ndGggPj4+IDA7CiAgICAgICAgICAgIGlmIChlbmNvZGluZyA9PT0gdm9pZCAwKQogICAgICAgICAgICAgIGVuY29kaW5nID0gInV0ZjgiOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgZW5jb2RpbmcgPSBsZW5ndGg7CiAgICAgICAgICAgIGxlbmd0aCA9IHZvaWQgMDsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCdWZmZXIud3JpdGUoc3RyaW5nLCBlbmNvZGluZywgb2Zmc2V0WywgbGVuZ3RoXSkgaXMgbm8gbG9uZ2VyIHN1cHBvcnRlZCIpOwogICAgICAgIH0KICAgICAgICBjb25zdCByZW1haW5pbmcgPSB0aGlzLmxlbmd0aCAtIG9mZnNldDsKICAgICAgICBpZiAobGVuZ3RoID09PSB2b2lkIDAgfHwgbGVuZ3RoID4gcmVtYWluaW5nKQogICAgICAgICAgbGVuZ3RoID0gcmVtYWluaW5nOwogICAgICAgIGlmIChzdHJpbmcubGVuZ3RoID4gMCAmJiAobGVuZ3RoIDwgMCB8fCBvZmZzZXQgPCAwKSB8fCBvZmZzZXQgPiB0aGlzLmxlbmd0aCkgewogICAgICAgICAgdGhyb3cgbmV3IFJhbmdlRXJyb3IoIkF0dGVtcHQgdG8gd3JpdGUgb3V0c2lkZSBidWZmZXIgYm91bmRzIik7CiAgICAgICAgfQogICAgICAgIGlmICghZW5jb2RpbmcpCiAgICAgICAgICBlbmNvZGluZyA9ICJ1dGY4IjsKICAgICAgICBsZXQgbG93ZXJlZENhc2UgPSBmYWxzZTsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIHN3aXRjaCAoZW5jb2RpbmcpIHsKICAgICAgICAgICAgY2FzZSAiaGV4IjoKICAgICAgICAgICAgICByZXR1cm4gaGV4V3JpdGUodGhpcywgc3RyaW5nLCBvZmZzZXQsIGxlbmd0aCk7CiAgICAgICAgICAgIGNhc2UgInV0ZjgiOgogICAgICAgICAgICBjYXNlICJ1dGYtOCI6CiAgICAgICAgICAgICAgcmV0dXJuIHV0ZjhXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAiYXNjaWkiOgogICAgICAgICAgICBjYXNlICJsYXRpbjEiOgogICAgICAgICAgICBjYXNlICJiaW5hcnkiOgogICAgICAgICAgICAgIHJldHVybiBhc2NpaVdyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBjYXNlICJiYXNlNjQiOgogICAgICAgICAgICAgIHJldHVybiBiYXNlNjRXcml0ZSh0aGlzLCBzdHJpbmcsIG9mZnNldCwgbGVuZ3RoKTsKICAgICAgICAgICAgY2FzZSAidWNzMiI6CiAgICAgICAgICAgIGNhc2UgInVjcy0yIjoKICAgICAgICAgICAgY2FzZSAidXRmMTZsZSI6CiAgICAgICAgICAgIGNhc2UgInV0Zi0xNmxlIjoKICAgICAgICAgICAgICByZXR1cm4gdWNzMldyaXRlKHRoaXMsIHN0cmluZywgb2Zmc2V0LCBsZW5ndGgpOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIGlmIChsb3dlcmVkQ2FzZSkKICAgICAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIlVua25vd24gZW5jb2Rpbmc6ICIgKyBlbmNvZGluZyk7CiAgICAgICAgICAgICAgZW5jb2RpbmcgPSAoIiIgKyBlbmNv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ZiAoaSArIGJ5dGVzUGVyU2VxdWVuY2UgPD0gZW5kKSB7CiAgICAgICAgICAgIGxldCBzZWNvbmRCeXRlLCB0aGlyZEJ5dGUsIGZvdXJ0aEJ5dGUsIHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgIHN3aXRjaCAoYnl0ZXNQZXJTZXF1ZW5jZSkgewogICAgICAgICAgICAgIGNhc2UgMToKICAgICAgICAgICAgICAgIGlmIChmaXJzdEJ5dGUgPCAxMjgpIHsKICAgICAgICAgICAgICAgICAgY29kZVBvaW50ID0gZmlyc3RCeXRlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgY2FzZSAyOgogICAgICAgICAgICAgICAgc2Vjb25kQnl0ZSA9IGJ1ZltpICsgMV07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAzMSkgPDwgNiB8IHNlY29uZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAxMjcpIHsKICAgICAgICAgICAgICAgICAgICBjb2RlUG9pbnQgPSB0ZW1wQ29kZVBvaW50OwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICBjYXNlIDM6CiAgICAgICAgICAgICAgICBzZWNvbmRCeXRlID0gYnVmW2kgKyAxXTsKICAgICAgICAgICAgICAgIHRoaXJkQnl0ZSA9IGJ1ZltpICsgMl07CiAgICAgICAgICAgICAgICBpZiAoKHNlY29uZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKHRoaXJkQnl0ZSAmIDE5MikgPT09IDEyOCkgewogICAgICAgICAgICAgICAgICB0ZW1wQ29kZVBvaW50ID0gKGZpcnN0Qnl0ZSAmIDE1KSA8PCAxMiB8IChzZWNvbmRCeXRlICYgNjMpIDw8IDYgfCB0aGlyZEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiAyMDQ3ICYmICh0ZW1wQ29kZVBvaW50IDwgNTUyOTYgfHwgdGVtcENvZGVQb2ludCA+IDU3MzQzKSkgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIGNhc2UgNDoKICAgICAgICAgICAgICAgIHNlY29uZEJ5dGUgPSBidWZbaSArIDFdOwogICAgICAgICAgICAgICAgdGhpcmRCeXRlID0gYnVmW2kgKyAyXTsKICAgICAgICAgICAgICAgIGZvdXJ0aEJ5dGUgPSBidWZbaSArIDNdOwogICAgICAgICAgICAgICAgaWYgKChzZWNvbmRCeXRlICYgMTkyKSA9PT0gMTI4ICYmICh0aGlyZEJ5dGUgJiAxOTIpID09PSAxMjggJiYgKGZvdXJ0aEJ5dGUgJiAxOTIpID09PSAxMjgpIHsKICAgICAgICAgICAgICAgICAgdGVtcENvZGVQb2ludCA9IChmaXJzdEJ5dGUgJiAxNSkgPDwgMTggfCAoc2Vjb25kQnl0ZSAmIDYzKSA8PCAxMiB8ICh0aGlyZEJ5dGUgJiA2MykgPDwgNiB8IGZvdXJ0aEJ5dGUgJiA2MzsKICAgICAgICAgICAgICAgICAgaWYgKHRlbXBDb2RlUG9pbnQgPiA2NTUzNSAmJiB0ZW1wQ29kZVBvaW50IDwgMTExNDExMikgewogICAgICAgICAgICAgICAgICAgIGNvZGVQb2ludCA9IHRlbXBDb2RlUG9pbnQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKGNvZGVQb2ludCA9PT0gbnVsbCkgewogICAgICAgICAgICBjb2RlUG9pbnQgPSA2NTUzMzsKICAgICAgICAgICAgYnl0ZXNQZXJTZXF1ZW5jZSA9IDE7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA+IDY1NTM1KSB7CiAgICAgICAgICAgIGNvZGVQb2ludCAtPSA2NTUzNjsKICAgICAgICAgICAgcmVzLnB1c2goY29kZVBvaW50ID4+PiAxMCAmIDEwMjMgfCA1NTI5Nik7CiAgICAgICAgICAgIGNvZGVQb2ludCA9IDU2MzIwIHwgY29kZVBvaW50ICYgMTAyMzsKICAgICAgICAgIH0KICAgICAgICAgIHJlcy5wdXNoKGNvZGVQb2ludCk7CiAgICAgICAgICBpICs9IGJ5dGVzUGVyU2VxdWVuY2U7CiAgICAgICAgfQogICAgICAgIHJldHVybiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkocmVzKTsKICAgICAgfQogICAgICB2YXIgTUFYX0FSR1VNRU5UU19MRU5HVEggPSA0MDk2OwogICAgICBmdW5jdGlvbiBkZWNvZGVDb2RlUG9pbnRzQXJyYXkoY29kZVBvaW50cykgewogICAgICAgIGNvbnN0IGxlbiA9IGNvZGVQb2ludHMubGVuZ3RoOwogICAgICAgIGlmIChsZW4gPD0gTUFYX0FSR1VNRU5UU19MRU5HVEgpIHsKICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cyk7CiAgICAgICAgfQogICAgICAgIGxldCByZXMgPSAiIjsKICAgICAgICBsZXQgaSA9IDA7CiAgICAgICAgd2hpbGUgKGkgPCBsZW4pIHsKICAgICAgICAgIHJlcyArPSBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KFN0cmluZywgY29kZVBvaW50cy5zbGljZShpLCBpICs9IE1BWF9BUkdVTUVOVFNfTEVOR1RIKSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYXNjaWlTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldICYgMTI3KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBsYXRpbjFTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBsZXQgcmV0ID0gIiI7CiAgICAgICAgZW5kID0gTWF0aC5taW4oYnVmLmxlbmd0aCwgZW5kKTsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgcmV0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJldDsKICAgICAgfQogICAgICBmdW5jdGlvbiBoZXhTbGljZShidWYsIHN0YXJ0LCBlbmQpIHsKICAgICAgICBjb25zdCBsZW4gPSBidWYubGVuZ3RoOwogICAgICAgIGlmICghc3RhcnQgfHwgc3RhcnQgPCAwKQogICAgICAgICAgc3RhcnQgPSAwOwogICAgICAgIGlmICghZW5kIHx8IGVuZCA8IDAgfHwgZW5kID4gbGVuKQogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIGxldCBvdXQgPSAiIjsKICAgICAgICBmb3IgKGxldCBpID0gc3RhcnQ7IGkgPCBlbmQ7ICsraSkgewogICAgICAgICAgb3V0ICs9IGhleFNsaWNlTG9va3VwVGFibGVbYnVmW2ldXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIG91dDsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlU2xpY2UoYnVmLCBzdGFydCwgZW5kKSB7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBidWYuc2xpY2Uoc3RhcnQsIGVuZCk7CiAgICAgICAgbGV0IHJlcyA9ICIiOwogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYnl0ZXMubGVuZ3RoIC0gMTsgaSArPSAyKSB7CiAgICAgICAgICByZXMgKz0gU3RyaW5nLmZyb21DaGFyQ29kZShieXRlc1tpXSArIGJ5dGVzW2kgKyAxXSAqIDI1Nik7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXM7CiAgICAgIH0KICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnNsaWNlID0gZnVuY3Rpb24gc2xpY2Uoc3RhcnQsIGVuZCkgewogICAgICAgIGNvbnN0IGxlbiA9IHRoaXMubGVuZ3RoOwogICAgICAgIHN0YXJ0ID0gfn5zdGFydDsKICAgICAgICBlbmQgPSBlbmQgPT09IHZvaWQgMCA/IGxlbiA6IH5+ZW5kOwogICAgICAgIGlmIChzdGFydCA8IDApIHsKICAgICAgICAgIHN0YXJ0ICs9IGxlbjsKICAgICAgICAgIGlmIChzdGFydCA8IDApCiAgICAgICAgICAgIHN0YXJ0ID0gMDsKICAgICAgICB9IGVsc2UgaWYgKHN0YXJ0ID4gbGVuKSB7CiAgICAgICAgICBzdGFydCA9IGxlbjsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8IDApIHsKICAgICAgICAgIGVuZCArPSBsZW47CiAgICAgICAgICBpZiAoZW5kIDwgMCkKICAgICAgICAgICAgZW5kID0gMDsKICAgICAgICB9IGVsc2UgaWYgKGVuZCA+IGxlbikgewogICAgICAgICAgZW5kID0gbGVuOwogICAgICAgIH0KICAgICAgICBpZiAoZW5kIDwgc3RhcnQpCiAgICAgICAgICBlbmQgPSBzdGFydDsKICAgICAgICBjb25zdCBuZXdCdWYgPSB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpOwogICAgICAgIE9iamVjdC5zZXRQcm90b3R5cGVPZihuZXdCdWYsIEJ1ZmZlcjEwLnBy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Uxlbmd0aDIgPSBieXRlTGVuZ3RoMiA+Pj4gMDsKICAgICAgICBpZiAoIW5vQXNzZXJ0KQogICAgICAgICAgY2hlY2tPZmZzZXQob2Zmc2V0LCBieXRlTGVuZ3RoMiwgdGhpcy5sZW5ndGgpOwogICAgICAgIGxldCB2YWwgPSB0aGlzW29mZnNldF07CiAgICAgICAgbGV0IG11bCA9IDE7CiAgICAgICAgbGV0IGkgPSAwOwogICAgICAgIHdoaWxlICgrK2kgPCBieXRlTGVuZ3RoMiAmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIGldICogbXVsOwogICAgICAgIH0KICAgICAgICBtdWwgKj0gMTI4OwogICAgICAgIGlmICh2YWwgPj0gbXVsKQogICAgICAgICAgdmFsIC09IE1hdGgucG93KDIsIDggKiBieXRlTGVuZ3RoMik7CiAgICAgICAgcmV0dXJuIHZhbDsKICAgICAgfTsKICAgICAgQnVmZmVyMTAucHJvdG90eXBlLnJlYWRJbnRCRSA9IGZ1bmN0aW9uIHJlYWRJbnRCRShvZmZzZXQsIGJ5dGVMZW5ndGgyLCBub0Fzc2VydCkgewogICAgICAgIG9mZnNldCA9IG9mZnNldCA+Pj4gMDsKICAgICAgICBieXRlTGVuZ3RoMiA9IGJ5dGVMZW5ndGgyID4+PiAwOwogICAgICAgIGlmICghbm9Bc3NlcnQpCiAgICAgICAgICBjaGVja09mZnNldChvZmZzZXQsIGJ5dGVMZW5ndGgyLCB0aGlzLmxlbmd0aCk7CiAgICAgICAgbGV0IGkgPSBieXRlTGVuZ3RoMjsKICAgICAgICBsZXQgbXVsID0gMTsKICAgICAgICBsZXQgdmFsID0gdGhpc1tvZmZzZXQgKyAtLWldOwogICAgICAgIHdoaWxlIChpID4gMCAmJiAobXVsICo9IDI1NikpIHsKICAgICAgICAgIHZhbCArPSB0aGlzW29mZnNldCArIC0taV0gKiBtdWw7CiAgICAgICAgfQogICAgICAgIG11bCAqPSAxMjg7CiAgICAgICA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3B5V2l0aGluKHRhcmdldFN0YXJ0LCBzdGFydCwgZW5kKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgVWludDhBcnJheS5wcm90b3R5cGUuc2V0LmNhbGwodGFyZ2V0LCB0aGlzLnN1YmFycmF5KHN0YXJ0LCBlbmQpLCB0YXJnZXRTdGFydCk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBsZW47CiAgICAgIH07CiAgICAgIEJ1ZmZlcjEwLnByb3RvdHlwZS5maWxsID0gZnVuY3Rpb24gZmlsbCh2YWwsIHN0YXJ0LCBlbmQsIGVuY29kaW5nKSB7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBpZiAodHlwZW9mIHN0YXJ0ID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IHN0YXJ0OwogICAgICAgICAgICBzdGFydCA9IDA7CiAgICAgICAgICAgIGVuZCA9IHRoaXMubGVuZ3RoOwogICAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgZW5kID09PSAic3RyaW5nIikgewogICAgICAgICAgICBlbmNvZGluZyA9IGVuZDsKICAgICAgICAgICAgZW5kID0gdGhpcy5sZW5ndGg7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoZW5jb2RpbmcgIT09IHZvaWQgMCAmJiB0eXBlb2YgZW5jb2RpbmcgIT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoImVuY29kaW5nIG11c3QgYmUgYSBzdHJpbmciKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2YgZW5jb2RpbmcgPT09ICJzdHJpbmciICYmICFCdWZmZXIxMC5pc0VuY29kaW5nKGVuY29kaW5nKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJVbmtub3duIGVuY29kaW5nOiAiICsgZW5jb2RpbmcpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHZhbC5sZW5ndGggPT09IDEpIHsKICAgICAgICAgICAgY29uc3QgY29kZSA9IHZhbC5jaGFyQ29kZUF0KDApOwogICAgICAgICAgICBpZiAoZW5jb2RpbmcgPT09ICJ1dGY4IiAmJiBjb2RlIDwgMTI4IHx8IGVuY29kaW5nID09PSAibGF0aW4xIikgewogICAgICAgICAgICAgIHZhbCA9IGNvZGU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICB2YWwgPSB2YWwgJiAyNTU7CiAgICAgICAgfSBlbHNlIGlmICh0eXBlb2YgdmFsID09PSAiYm9vbGVhbiIpIHsKICAgICAgICAgIHZhbCA9IE51bWJlcih2YWwpOwogICAgICAgIH0KICAgICAgICBpZiAoc3RhcnQgPCAwIHx8IHRoaXMubGVuZ3RoIDwgc3RhcnQgfHwgdGhpcy5sZW5ndGggPCBlbmQpIHsKICAgICAgICAgIHRocm93IG5ldyBSYW5nZUVycm9yKCJPdXQgb2YgcmFuZ2UgaW5kZXgiKTsKICAgICAgICB9CiAgICAgICAgaWYgKGVuZCA8PSBzdGFydCkgewogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIHN0YXJ0ID0gc3RhcnQgPj4+IDA7CiAgICAgICAgZW5kID0gZW5kID09PSB2b2lkIDAgPyB0aGlzLmxlbmd0aCA6IGVuZCA+Pj4gMDsKICAgICAgICBpZiAoIXZhbCkKICAgICAgICAgIHZhbCA9IDA7CiAgICAgICAgbGV0IGk7CiAgICAgICAgaWYgKHR5cGVvZiB2YWwgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICBmb3IgKGkgPSBzdGFydDsgaSA8IGVuZDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaV0gPSB2YWw7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGNvbnN0IGJ5dGVzID0gQnVmZmVyMTAuaXNCdWZmZXIodmFsKSA/IHZhbCA6IEJ1ZmZlcjEwLmZyb20odmFsLCBlbmNvZGluZyk7CiAgICAgICAgICBjb25zdCBsZW4gPSBieXRlcy5sZW5ndGg7CiAgICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1RoZSB2YWx1ZSAiJyArIHZhbCArICciIGlzIGludmFsaWQgZm9yIGFyZ3VtZW50ICJ2YWx1ZSInKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBlbmQgLSBzdGFydDsgKytpKSB7CiAgICAgICAgICAgIHRoaXNbaSArIHN0YXJ0XSA9IGJ5dGVzW2kgJSBsZW5dOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGhpczsKICAgICAgfTsKICAgICAgdmFyIGVycm9ycyA9IHt9OwogICAgICBmdW5jdGlvbiBFKHN5bSwgZ2V0TWVzc2FnZSwgQmFzZSkgewogICAgICAgIGVycm9yc1tzeW1dID0gY2xhc3MgTm9kZUVycm9yIGV4dGVuZHMgQmFzZSB7CiAgICAgICAgICBjb25zdHJ1Y3RvcigpIHsKICAgICAgICAgICAgc3VwZXIoKTsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJtZXNzYWdlIiwgewogICAgICAgICAgICAgIHZhbHVlOiBnZXRNZXNzYWdlLmFwcGx5KHRoaXMsIGFyZ3VtZW50cyksCiAgICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgICB0aGlzLm5hbWUgPSBgJHt0aGlzLm5hbWV9IFske3N5bX1dYDsKICAgICAgICAgICAgdGhpcy5zdGFjazsKICAgICAgICAgICAgZGVsZXRlIHRoaXMubmFtZTsKICAgICAgICAgIH0KICAgICAgICAgIGdldCBjb2RlKCkgewogICAgICAgICAgICByZXR1cm4gc3ltOwogICAgICAgICAgfQogICAgICAgICAgc2V0IGNvZGUodmFsdWUpIHsKICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHRoaXMsICJjb2RlIiwgewogICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICBlbnVtZXJhYmxlOiB0cnVlLAogICAgICAgICAgICAgIHZhbHVlLAogICAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlCiAgICAgICAgICAgIH0pOwogICAgICAgICAgfQogICAgICAgICAgdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiBgJHt0aGlzLm5hbWV9IFske3N5bX1dOiAke3RoaXMubWVzc2FnZX1gOwogICAgICAgICAgfQogICAgICAgIH07CiAgICAgIH0KICAgICAgRSgiRVJSX0JVRkZFUl9PVVRfT0ZfQk9VTkRTIiwgZnVuY3Rpb24obmFtZSkgewogICAgICAgIGlmIChuYW1lKSB7CiAgICAgICAgICByZXR1cm4gYCR7bmFtZX0gaXMgb3V0c2lkZSBvZiBidWZmZXIgYm91bmRzYDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICJBdHRlbXB0IHRvIGFjY2VzcyBtZW1vcnkgb3V0c2lkZSBidWZmZXIgYm91bmRzIjsKICAgICAgfSwgUmFuZ2VFcnJvcik7CiAgICAgIEUoIkVSUl9JTlZBTElEX0FSR19UWVBFIiwgZnVuY3Rpb24obmFtZSwgYWN0dWFsKSB7CiAgICAgICAgcmV0dXJuIGBUaGUgIiR7bmFtZX0iIGFyZ3VtZW50IG11c3QgYmUgb2YgdHlwZSBudW1iZXIuIFJlY2VpdmVkIHR5cGUgJHt0eXBlb2YgYWN0dWFsfWA7CiAgICAgIH0sIFR5cGVFcnJvcik7CiAgICAgIEUoIkVSUl9PVVRfT0ZfUkFOR0UiLCBmdW5jdGlvbihzdHIsIHJhbmdlLCBpbnB1dCkgewogICAgICAgIGxldCBtc2cgPSBgVGhl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ljZSgwLCBpKX0ke3Jlc31gOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNoZWNrQm91bmRzKGJ1Ziwgb2Zmc2V0LCBieXRlTGVuZ3RoMikgewogICAgICAgIHZhbGlkYXRlTnVtYmVyKG9mZnNldCwgIm9mZnNldCIpOwogICAgICAgIGlmIChidWZbb2Zmc2V0XSA9PT0gdm9pZCAwIHx8IGJ1ZltvZmZzZXQgKyBieXRlTGVuZ3RoMl0gPT09IHZvaWQgMCkgewogICAgICAgICAgYm91bmRzRXJyb3Iob2Zmc2V0LCBidWYubGVuZ3RoIC0gKGJ5dGVMZW5ndGgyICsgMSkpOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBjaGVja0ludEJJKHZhbHVlLCBtaW4sIG1heCwgYnVmLCBvZmZzZXQsIGJ5dGVMZW5ndGgyKSB7CiAgICAgICAgaWYgKHZhbHVlID4gbWF4IHx8IHZhbHVlIDwgbWluKSB7CiAgICAgICAgICBjb25zdCBuID0gdHlwZW9mIG1pbiA9PT0gImJpZ2ludCIgPyAibiIgOiAiIjsKICAgICAgICAgIGxldCByYW5nZTsKICAgICAgICAgIGlmIChieXRlTGVuZ3RoMiA+IDMpIHsKICAgICAgICAgICAgaWYgKG1pbiA9PT0gMCB8fCBtaW4gPT09IEJpZ0ludCgwKSkgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IDAke259IGFuZCA8IDIke259ICoqICR7KGJ5dGVMZW5ndGgyICsgMSkgKiA4fSR7bn1gOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHJhbmdlID0gYD49IC0oMiR7bn0gKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn0pIGFuZCA8IDIgKiogJHsoYnl0ZUxlbmd0aDIgKyAxKSAqIDggLSAxfSR7bn1gOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByYW5nZSA9IGA+PSAke21pbn0ke259IGFuZCA8P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0Y2xlYW4oc3RyKSB7CiAgICAgICAgc3RyID0gc3RyLnNwbGl0KCI9IilbMF07CiAgICAgICAgc3RyID0gc3RyLnRyaW0oKS5yZXBsYWNlKElOVkFMSURfQkFTRTY0X1JFLCAiIik7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPCAyKQogICAgICAgICAgcmV0dXJuICIiOwogICAgICAgIHdoaWxlIChzdHIubGVuZ3RoICUgNCAhPT0gMCkgewogICAgICAgICAgc3RyID0gc3RyICsgIj0iOwogICAgICAgIH0KICAgICAgICByZXR1cm4gc3RyOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHV0ZjhUb0J5dGVzKHN0cmluZywgdW5pdHMpIHsKICAgICAgICB1bml0cyA9IHVuaXRzIHx8IEluZmluaXR5OwogICAgICAgIGxldCBjb2RlUG9pbnQ7CiAgICAgICAgY29uc3QgbGVuZ3RoID0gc3RyaW5nLmxlbmd0aDsKICAgICAgICBsZXQgbGVhZFN1cnJvZ2F0ZSA9IG51bGw7CiAgICAgICAgY29uc3QgYnl0ZXMgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBjb2RlUG9pbnQgPSBzdHJpbmcuY2hhckNvZGVBdChpKTsKICAgICAgICAgIGlmIChjb2RlUG9pbnQgPiA1NTI5NSAmJiBjb2RlUG9pbnQgPCA1NzM0NCkgewogICAgICAgICAgICBpZiAoIWxlYWRTdXJyb2dhdGUpIHsKICAgICAgICAgICAgICBpZiAoY29kZVBvaW50ID4gNTYzMTkpIHsKICAgICAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPiAtMSkKICAgICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgIH0gZWxzZSBpZiAoaSArIDEgPT09IGxlbmd0aCkgewogICAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgICBieXRlcy5wdXNoKDIzOSwgMTkxLCAxODkpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBjb2RlUG9pbnQ7CiAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDU2MzIwKSB7CiAgICAgICAgICAgICAgaWYgKCh1bml0cyAtPSAzKSA+IC0xKQogICAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgICAgICBsZWFkU3Vycm9nYXRlID0gY29kZVBvaW50OwogICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGNvZGVQb2ludCA9IChsZWFkU3Vycm9nYXRlIC0gNTUyOTYgPDwgMTAgfCBjb2RlUG9pbnQgLSA1NjMyMCkgKyA2NTUzNjsKICAgICAgICAgIH0gZWxzZSBpZiAobGVhZFN1cnJvZ2F0ZSkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDMpID4gLTEpCiAgICAgICAgICAgICAgYnl0ZXMucHVzaCgyMzksIDE5MSwgMTg5KTsKICAgICAgICAgIH0KICAgICAgICAgIGxlYWRTdXJyb2dhdGUgPSBudWxsOwogICAgICAgICAgaWYgKGNvZGVQb2ludCA8IDEyOCkgewogICAgICAgICAgICBpZiAoKHVuaXRzIC09IDEpIDwgMCkKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgYnl0ZXMucHVzaChjb2RlUG9pbnQpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAyMDQ4KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMikgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiA2IHwgMTkyLCBjb2RlUG9pbnQgJiA2MyB8IDEyOCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGNvZGVQb2ludCA8IDY1NTM2KSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gMykgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxMiB8IDIyNCwgY29kZVBvaW50ID4+IDYgJiA2MyB8IDEyOCwgY29kZVBvaW50ICYgNjMgfCAxMjgpOwogICAgICAgICAgfSBlbHNlIGlmIChjb2RlUG9pbnQgPCAxMTE0MTEyKSB7CiAgICAgICAgICAgIGlmICgodW5pdHMgLT0gNCkgPCAwKQogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICBieXRlcy5wdXNoKGNvZGVQb2ludCA+PiAxOCB8IDI0MCwgY29kZVBvaW50ID4+IDEyICYgNjMgfCAxMjgsIGNvZGVQb2ludCA+PiA2ICYgNjMgfCAxMjgsIGNvZGVQb2ludCAmIDYzIHwgMTI4KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRocm93IG5ldyBFcnJvcigiSW52YWxpZCBjb2RlIHBvaW50Iik7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlczsKICAgICAgfQogICAgICBmdW5jdGlvbiBhc2NpaVRvQnl0ZXMoc3RyKSB7CiAgICAgICAgY29uc3QgYnl0ZUFycmF5ID0gW107CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyArK2kpIHsKICAgICAgICAgIGJ5dGVBcnJheS5wdXNoKHN0ci5jaGFyQ29kZUF0KGkpICYgMjU1KTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ5dGVBcnJheTsKICAgICAgfQogICAgICBmdW5jdGlvbiB1dGYxNmxlVG9CeXRlcyhzdHIsIHVuaXRzKSB7CiAgICAgICAgbGV0IGMsIGhpLCBsbzsKICAgICAgICBjb25zdCBieXRlQXJyYXkgPSBbXTsKICAgICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHN0ci5sZW5ndGg7ICsraSkgewogICAgICAgICAgaWYgKCh1bml0cyAtPSAyKSA8IDApCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgYyA9IHN0ci5jaGFyQ29kZUF0KGkpOwogICAgICAgICAgaGkgPSBjID4+IDg7CiAgICAgICAgICBsbyA9IGMgJSAyNTY7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChsbyk7CiAgICAgICAgICBieXRlQXJyYXkucHVzaChoaSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiBieXRlQXJyYXk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYmFzZTY0VG9CeXRlcyhzdHIpIHsKICAgICAgICByZXR1cm4gYmFzZTY0LnRvQnl0ZUFycmF5KGJhc2U2NGNsZWFuKHN0cikpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGJsaXRCdWZmZXIoc3JjLCBkc3QsIG9mZnNldCwgbGVuZ3RoKSB7CiAgICAgICAgbGV0IGk7CiAgICAgICAgZm9yIChpID0gMDsgaSA8IGxlbmd0aDsgKytpKSB7CiAgICAgICAgICBpZiAoaSArIG9mZnNldCA+PSBkc3QubGVuZ3RoIHx8IGkgPj0gc3JjLmxlbmd0aCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICBkc3RbaSArIG9mZnNldF0gPSBzcmNbaV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGlzSW5zdGFuY2Uob2JqLCB0eXBlKSB7CiAgICAgICAgcmV0dXJuIG9iaiBpbnN0YW5jZW9mIHR5cGUgfHwgb2JqICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yICE9IG51bGwgJiYgb2JqLmNvbnN0cnVjdG9yLm5hbWUgIT0gbnVsbCAmJiBvYmouY29uc3RydWN0b3IubmFtZSA9PT0gdHlwZS5uYW1lOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIG51bWJlcklzTmFOKG9iaikgewogICAgICAgIHJldHVybiBvYmogIT09IG9iajsKICAgICAgfQogICAgICB2YXIgaGV4U2xpY2VMb29rdXBUYWJsZSA9IGZ1bmN0aW9uKCkgewogICAgICAgIGNvbnN0IGFscGhhYmV0ID0gIjAxMjM0NTY3ODlhYmNkZWYiOwogICAgICAgIGNvbnN0IHRhYmxlID0gbmV3IEFycmF5KDI1Nik7CiAgICAgICAgZm9yIChsZXQgaSA9IDA7IGkgPCAxNjsgKytpKSB7CiAgICAgICAgICBjb25zdCBpMTYgPSBpICogMTY7CiAgICAgICAgICBmb3IgKGxldCBqID0gMDsgaiA8IDE2OyArK2opIHsKICAgICAgICAgICAgdGFibGVbaTE2ICsgal0gPSBhbHBoYWJldFtpXSArIGFscGhhYmV0W2pdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gdGFibGU7CiAgICAgIH0oKTsKICAgICAgZnVuY3Rpb24gZGVmaW5lQmlnSW50TWV0aG9kKGZuKSB7CiAgICAgICAgcmV0dXJuIHR5cGVvZiBCaWdJbnQgPT09ICJ1bmRlZmluZWQiID8gQnVmZmVyQmlnSW50Tm90RGVmaW5lZCA6IGZuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIEJ1ZmZlckJpZ0ludE5vdERlZmluZWQoKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJCaWdJbnQgbm90IHN1cHBvcnRlZCIpOwogICAgICB9CiAgICB9CiAgfSk7CgogIC8vIHNyYy9hbGlhcy9idWZmZXItc2hpbS5qcwogIHZhciBpbXBvcnRfYnVmZmVyOwogIHZhciBpbml0X2J1ZmZlcl9zaGltID0gX19lc20oewogICAgInNyYy9hbGlhcy9idWZmZXItc2hpbS5qcyIoKSB7CiAgICAgIGltcG9ydF9idWZmZXIgPSBfX3RvTW9kdWxlKHJlcXVpcmVfYnVmZmVyKCkpOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHV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3RvcjogewogICAgICAgICAgICB2YWx1ZTogc3ViQ2xhc3MsCiAgICAgICAgICAgIHdyaXRhYmxlOiB0cnVlLAogICAgICAgICAgICBjb25maWd1cmFibGU6IHRydWUKICAgICAgICAgIH0KICAgICAgICB9KTsKICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkoc3ViQ2xhc3MsICJwcm90b3R5cGUiLCB7CiAgICAgICAgICB3cml0YWJsZTogZmFsc2UKICAgICAgICB9KTsKICAgICAgICBpZiAoc3VwZXJDbGFzcykKICAgICAgICAgIF9zZXRQcm90b3R5cGVPZihzdWJDbGFzcywgc3VwZXJDbGFzcyk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mKG8pIHsKICAgICAgICBfZ2V0UHJvdG90eXBlT2YgPSBPYmplY3Quc2V0UHJvdG90eXBlT2YgPyBPYmplY3QuZ2V0UHJvdG90eXBlT2YuYmluZCgpIDogZnVuY3Rpb24gX2dldFByb3RvdHlwZU9mMihvMikgewogICAgICAgICAgcmV0dXJuIG8yLl9fcHJvdG9fXyB8fCBPYmplY3QuZ2V0UHJvdG90eXBlT2YobzIpOwogICAgICAgIH07CiAgICAgICAgcmV0dXJuIF9nZXRQcm90b3R5cGVPZihvKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YobywgcCkgewogICAgICAgIF9zZXRQcm90b3R5cGVPZiA9IE9iamVjdC5zZXRQcm90b3R5cGVPZiA/IE9iamVjdC5zZXRQcm90b3R5cGVPZi5iaW5kKCkgOiBmdW5jdGlvbiBfc2V0UHJvdG90eXBlT2YyKG8yLCBwMikgewogICAgICAgICAgbzIuX19wcm90b19fID0gcDI7CiAgICAgICAgICByZXR1cm4gbzI7CiAgICAgICAgfTsKICAgICAgICByZXR1cm4gX3NldFByb3RvdHlwZU9mKG8sIHApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9pc05hdGl2ZVJlZmxlY3RDb25zdHJ1Y3QoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ID09PSAidW5kZWZpbmVkIiB8fCAhUmVmbGVjdC5jb25zdHJ1Y3QpCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKFJlZmxlY3QuY29uc3RydWN0LnNoYW0pCiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgaWYgKHR5cGVvZiBQcm94eSA9PT0gImZ1bmN0aW9uIikKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIHRyeSB7CiAgICAgICAgICBCb29sZWFuLnByb3RvdHlwZS52YWx1ZU9mLmNhbGwoUmVmbGVjdC5jb25zdHJ1Y3QoQm9vbGVhbiwgW10sIGZ1bmN0aW9uKCkgewogICAgICAgICAgfSkpOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBfYXNzZXJ0VGhpc0luaXRpYWxpemVkKHNlbGYyKSB7CiAgICAgICAgaWYgKHNlbGYyID09PSB2b2lkIDApIHsKICAgICAgICAgIHRocm93IG5ldyBSZWZlcmVuY2VFcnJvcigidGhpcyBoYXNuJ3QgYmVlbiBpbml0aWFsaXNlZCAtIHN1cGVyKCkgaGFzbid0IGJlZW4gY2FsbGVkIik7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzZWxmMjsKICAgICAgfQogICAgICBmdW5jdGlvbiBfcG9zc2libGVDb25zdHJ1Y3RvclJldHVybihzZWxmMiwgY2FsbCkgewogICAgICAgIGlmIChjYWxsICYmICh0eXBlb2YgY2FsbCA9PT0gIm9iamVjdCIgfHwgdHlwZW9mIGNhbGwgPT09ICJmdW5jdGlvbiIpKSB7CiAgICAgICAgICByZXR1cm4gY2FsbDsKICAgICAgICB9IGVsc2UgaWYgKGNhbGwgIT09IHZvaWQgMCkgewogICAgICAgICAgdGhyb3cgbm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vdG90eXBlT2Yob2JqZWN0KTsKICAgICAgICAgIGlmIChvYmplY3QgPT09IG51bGwpCiAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICAgICByZXR1cm4gb2JqZWN0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIF9nZXQoKSB7CiAgICAgICAgaWYgKHR5cGVvZiBSZWZsZWN0ICE9PSAidW5kZWZpbmVkIiAmJiBSZWZsZWN0LmdldCkgewogICAgICAgICAgX2dldCA9IFJlZmxlY3QuZ2V0LmJpbmQoKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgX2dldCA9IGZ1bmN0aW9uIF9nZXQyKHRhcmdldCwgcHJvcGVydHksIHJlY2VpdmVyKSB7CiAgICAgICAgICAgIHZhciBiYXNlID0gX3N1cGVyUHJvcEJhc2UodGFyZ2V0LCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmICghYmFzZSkKICAgICAgICAgICAgICByZXR1cm47CiAgICAgICAgICAgIHZhciBkZXNjID0gT2JqZWN0LmdldE93blByb3BlcnR5RGVzY3JpcHRvcihiYXNlLCBwcm9wZXJ0eSk7CiAgICAgICAgICAgIGlmIChkZXNjLmdldCkgewogICAgICAgICAgICAgIHJldHVybiBkZXNjLmdldC5jYWxsKGFyZ3VtZW50cy5sZW5ndGggPCAzID8gdGFyZ2V0IDogcmVjZWl2ZXIpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHJldHVybiBkZXNjLnZhbHVlOwogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIF9nZXQuYXBwbHkodGhpcywgYXJndW1lbnRzKTsKICAgICAgfQogICAgICB2YXIgRW1pdHRlciA9IC8qIEBfX1BVUkVfXyAqLyBmdW5jdGlvbigpIHsKICAgICAgICBmdW5jdGlvbiBFbWl0dGVyMigpIHsKICAgICAgICAgIF9jbGFzc0NhbGxDaGVjayh0aGlzLCBFbWl0dGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgImxpc3RlbmVycyIsIHsKICAgICAgICAgICAgdmFsdWU6IHt9LAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEVtaXR0ZXIyLCBbewogICAgICAgICAga2V5OiAiYWRkRXZlbnRMaXN0ZW5lciIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWRkRXZlbnRMaXN0ZW5lcih0eXBlLCBjYWxsYmFjaywgb3B0aW9ucykgewogICAgICAgICAgICBpZiAoISh0eXBlIGluIHRoaXMubGlzdGVuZXJzKSkgewogICAgICAgICAgICAgIHRoaXMubGlzdGVuZXJzW3R5cGVdID0gW107CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5saXN0ZW5lcnNbdHlwZV0ucHVzaCh7CiAgICAgICAgICAgICAgY2FsbGJhY2ssCiAgICAgICAgICAgICAgb3B0aW9ucwogICAgICAgICAgICB9KTsKICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJyZW1vdmVFdmVudExpc3RlbmVyIiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiByZW1vdmVFdmVudExpc3RlbmVyKHR5cGUsIGNhbGxiYWNrKSB7CiAgICAgICAgICAgIGlmICghKHR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW3R5cGVdOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIGlmIChzdGFja1tpXS5jYWxsYmFjayA9PT0gY2FsbGJhY2spIHsKICAgICAgICAgICAgICAgIHN0YWNrLnNwbGljZShpLCAxKTsKICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9LCB7CiAgICAgICAgICBrZXk6ICJkaXNwYXRjaEV2ZW50IiwKICAgICAgICAgIHZhbHVlOiBmdW5jdGlvbiBkaXNwYXRjaEV2ZW50KGV2ZW50KSB7CiAgICAgICAgICAgIGlmICghKGV2ZW50LnR5cGUgaW4gdGhpcy5saXN0ZW5lcnMpKSB7CiAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHZhciBzdGFjayA9IHRoaXMubGlzdGVuZXJzW2V2ZW50LnR5cGVdOwogICAgICAgICAgICB2YXIgc3RhY2tUb0NhbGwgPSBzdGFjay5zbGljZSgpOwogICAgICAgICAgICBmb3IgKHZhciBpID0gMCwgbCA9IHN0YWNrVG9DYWxsLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICAgIHZhciBsaXN0ZW5lciA9IHN0YWNrVG9DYWxsW2ldOwogICAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBsaXN0ZW5lci5jYWxsYmFjay5jYWxsKHRoaXMsIGV2ZW50KTsKICAgICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgICBQcm9taXNlLnJlc29sdmUoKS50aGVuKGZ1bmN0aW9uKCkgewogICAgICAgICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChsaXN0ZW5lci5vcHRpb25zICYmIGxpc3RlbmVyLm9wdGlvbnMub25jZSkgewogICAgICAgICAgICAgICAgdGhpcy5yZW1vdmVFdmVudExpc3RlbmVyKGV2ZW50LnR5cGUsIGxpc3RlbmVyLmNhbGxiYWNrKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcmV0dXJuICFldmVudC5kZWZhdWx0UHJldmVudGVkOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gRW1pdHRlcjI7CiAgICAgIH0oKTsKICAgICAgdmFyIEFib3J0U2lnbmFsID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKF9FbWl0dGVyKSB7CiAgICAgICAgX2luaGVyaXRzKEFib3J0U2lnbmFsMiwgX0VtaXR0ZXIpOwogICAgICAgIHZhciBfc3VwZXIgPSBfY3JlYXRlU3VwZXIoQWJvcnRTaWduYWwyKTsKICAgICAgICBmdW5jdGlvbiBBYm9ydFNpZ25hbDIoKSB7CiAgICAgICAgICB2YXIgX3RoaXM7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRTaWduYWwyKTsKICAgICAgICAgIF90aGlzID0gX3N1cGVyLmNhbGwodGhpcyk7CiAgICAgICAgICBpZiAoIV90aGlzLmxpc3RlbmVycykgewogICAgICAgICAgICBFbWl0dGVyLmNhbGwoX2Fzc2VydFRoaXNJbml0aWFsaXplZChfdGhpcykpOwogICAgICAgICAgfQogICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KF9hc3NlcnRUaGlzSW5pdGlhbGl6ZWQoX3RoaXMpLCAiYWJvcnRlZCIsIHsKICAgICAgICAgICAgdmFsdWU6IGZhbHNlLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgIm9uYWJvcnQiLCB7CiAgICAgICAgICAgIHZhbHVlOiBudWxsLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShfYXNzZXJ0VGhpc0luaXRpYWxpemVkKF90aGlzKSwgInJlYXNvbiIsIHsKICAgICAgICAgICAgdmFsdWU6IHZvaWQgMCwKICAgICAgICAgICAgd3JpdGFibGU6IHRydWUsCiAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZQogICAgICAgICAgfSk7CiAgICAgICAgICByZXR1cm4gX3RoaXM7CiAgICAgICAgfQogICAgICAgIF9jcmVhdGVDbGFzcyhBYm9ydFNpZ25hbDIsIFt7CiAgICAgICAgICBrZXk6ICJ0b1N0cmluZyIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gdG9TdHJpbmcoKSB7CiAgICAgICAgICAgIHJldHVybiAiW29iamVjdCBBYm9ydFNpZ25hbF0iOwogICAgICAgICAgfQogICAgICAgIH0sIHsKICAgICAgICAgIGtleTogImRpc3BhdGNoRXZlbnQiLAogICAgICAgICAgdmFsdWU6IGZ1bmN0aW9uIGRpc3BhdGNoRXZlbnQoZXZlbnQpIHsKICAgICAgICAgICAgaWYgKGV2ZW50LnR5cGUgPT09ICJhYm9ydCIpIHsKICAgICAgICAgICAgICB0aGlzLmFib3J0ZWQgPSB0cnVlOwogICAgICAgICAgICAgIGlmICh0eXBlb2YgdGhpcy5vbmFib3J0ID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uYWJvcnQuY2FsbCh0aGlzLCBldmVudCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIF9nZXQoX2dldFByb3RvdHlwZU9mKEFib3J0U2lnbmFsMi5wcm90b3R5cGUpLCAiZGlzcGF0Y2hFdmVudCIsIHRoaXMpLmNhbGwodGhpcywgZXZlbnQpOwogICAgICAgICAgfQogICAgICAgIH1dKTsKICAgICAgICByZXR1cm4gQWJvcnRTaWduYWwyOwogICAgICB9KEVtaXR0ZXIpOwogICAgICB2YXIgQWJvcnRDb250cm9sbGVyID0gLyogQF9fUFVSRV9fICovIGZ1bmN0aW9uKCkgewogICAgICAgIGZ1bmN0aW9uIEFib3J0Q29udHJvbGxlcjIoKSB7CiAgICAgICAgICBfY2xhc3NDYWxsQ2hlY2sodGhpcywgQWJvcnRDb250cm9sbGVyMik7CiAgICAgICAgICBPYmplY3QuZGVmaW5lUHJvcGVydHkodGhpcywgInNpZ25hbCIsIHsKICAgICAgICAgICAgdmFsdWU6IG5ldyBBYm9ydFNpZ25hbCgpLAogICAgICAgICAgICB3cml0YWJsZTogdHJ1ZSwKICAgICAgICAgICAgY29uZmlndXJhYmxlOiB0cnVlCiAgICAgICAgICB9KTsKICAgICAgICB9CiAgICAgICAgX2NyZWF0ZUNsYXNzKEFib3J0Q29udHJvbGxlcjIsIFt7CiAgICAgICAgICBrZXk6ICJhYm9ydCIsCiAgICAgICAgICB2YWx1ZTogZnVuY3Rpb24gYWJvcnQocmVhc29uKSB7CiAgICAgICAgICAgIHZhciBldmVudDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICBldmVudCA9IG5ldyBFdmVudCgiYWJvcnQiKTsKICAgICAgICAgICAgfSBjYXRjaCAoZSkgewogICAgICAgICAgICAgIGlmICh0eXBlb2YgZG9jdW1lbnQgIT09ICJ1bmRlZmluZWQiKSB7CiAgICAgICAgICAgICAgICBpZiAoIWRvY3VtZW50LmNyZWF0ZUV2ZW50KSB7CiAgICAgICAgICAgICAgICAgIGV2ZW50ID0gZG9jdW1lbnQuY3JlYXRlRXZlbnRPYmplY3QoKTsKICAgICAgICAgICAgICAgICAgZXZlbnQudHlwZSA9ICJhYm9ydCI7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBldmVudCA9IGRvY3VtZW50LmNyZWF0ZUV2ZW50KCJFdmVudCIpOwogICAgICAgICAgICAgICAgICBldmVudC5pbml0RXZlbnQoImFib3J0IiwgZmFsc2UsIGZhbHNlKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgZXZlbnQgPSB7CiAgICAgICAgICAgICAgICAgIHR5cGU6ICJhYm9ydCIsCiAgICAgICAgICAgICAgICAgIGJ1YmJsZXM6IGZhbHNlLAogICAgICAgICAgICAgICAgICBjYW5jZWxhYmxlOiBmYWxzZQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHNpZ25hbFJlYXNvbiA9IHJlYXNvbjsKICAgICAgICAgICAgaWYgKHNpZ25hbFJlYXNvbiA9PT0gdm9pZCAwKSB7CiAgICAgICAgICAgICAgaWYgKHR5cGVvZiBkb2N1bWVudCA9PT0gInVuZGVmaW5lZCIpIHsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbi5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgICAgICBzaWduYWxSZWFzb24gPSBuZXcgRE9NRXhjZXB0aW9uKCJzaWduYWwgaXMgYWJvcnRlZCB3aXRob3V0IHJlYXNvbiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoZXJyKSB7CiAgICAgICAgICAgICAgICAgIHNpZ25hbFJlYXNvbiA9IG5ldyBFcnJvcigiVGhpcyBvcGVyYXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAgICAgICAgICAgICAgc2lnbmFsUmVhc29uLm5hbWUgPSAiQWJvcnRFcnJvciI7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuc2lnbmFsLnJlYXNvbiA9IHNpZ25hbFJlYXNvbjsKICAgICAgICAgICAgdGhpcy5zaWduYWwuZGlzcGF0Y2hFdmVudChldmVudCk7CiAgICAgICAgICB9CiAgICAgICAgfSwgew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mZXRjaCwKICAgICAgICAgICAgUmVxdWVzdAogICAgICAgICAgfTsKICAgICAgICB9CiAgICAgICAgdmFyIFJlcXVlc3QgPSBOYXRpdmVSZXF1ZXN0OwogICAgICAgIGlmIChSZXF1ZXN0ICYmICFSZXF1ZXN0LnByb3RvdHlwZS5oYXNPd25Qcm9wZXJ0eSgic2lnbmFsIikgfHwgX19GT1JDRV9JTlNUQUxMX0FCT1JUQ09OVFJPTExFUl9QT0xZRklMTCkgewogICAgICAgICAgUmVxdWVzdCA9IGZ1bmN0aW9uIFJlcXVlc3QyKGlucHV0LCBpbml0MikgewogICAgICAgICAgICB2YXIgc2lnbmFsOwogICAgICAgICAgICBpZiAoaW5pdDIgJiYgaW5pdDIuc2lnbmFsKSB7CiAgICAgICAgICAgICAgc2lnbmFsID0gaW5pdDIuc2lnbmFsOwogICAgICAgICAgICAgIGRlbGV0ZSBpbml0Mi5zaWduYWw7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdmFyIHJlcXVlc3QgPSBuZXcgTmF0aXZlUmVxdWVzdChpbnB1dCwgaW5pdDIpOwogICAgICAgICAgICBpZiAoc2lnbmFsKSB7CiAgICAgICAgICAgICAgT2JqZWN0LmRlZmluZVByb3BlcnR5KHJlcXVlc3QsICJzaWduYWwiLCB7CiAgICAgICAgICAgICAgICB3cml0YWJsZTogZmFsc2UsCiAgICAgICAgICAgICAgICBlbnVtZXJhYmxlOiBmYWxzZSwKICAgICAgICAgICAgICAgIGNvbmZpZ3VyYWJsZTogdHJ1ZSwKICAgICAgICAgICAgICAgIHZhbHVlOiBzaWduYWwKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gcmVxdWVzdDsKICAgICAgICAgIH07CiAgICAgICAgICBSZXF1ZXN0LnByb3RvdHlwZSA9IE5hdGl2ZVJlcXVlc3QucHJvdG90eXBlOwogICAgICAgIH0KICAgICAgICB2YXIgcmVhbEZldGNoID0gZmV0Y2g7CiAgICAgICAgdmFyIGFib3J0YWJsZUZldGNoID0gZnVuY3Rpb24gYWJvcnRhYmxlRmV0Y2gyKGlucHV0LCBpbml0MikgewogICAgICAgICAgdmFyIHNpZ25hbCA9IFJlcXVlc3QgJiYgUmVxdWVzdC5wcm90b3R5cGUuaXNQcm90b3R5cGVPZihpbnB1dCkgPyBpbnB1dC5zaWduYWwgOiBpbml0MiA/IGluaXQyLnNpZ25hbCA6IHZvaWQgMDsKICAgICAgICAgIGlmIChzaWduYWwpIHsKICAgICAgICAgICAgdmFyIGFib3J0RXJyb3I7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgYWJvcnRFcnJvciA9IG5ldyBET01FeGNlcHRpb24oIkFib3J0ZWQiLCAiQWJvcnRFcnJvciIpOwogICAgICAgICAgICB9IGNhdGNoIChlcnIpIHsKICAgICAgICAgICAgICBhYm9ydEVycm9yID0gbmV3IEVycm9yKCJBYm9ydGVkIik7CiAgICAgICAgICAgICAgYWJvcnRFcnJvci5uYW1lID0gIkFib3J0RXJyb3IiOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICAgIHJldHVybiBQcm9taXNlLnJlamVjdChhYm9ydEVycm9yKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB2YXIgY2FuY2VsbGF0aW9uID0gbmV3IFByb21pc2UoZnVuY3Rpb24oXywgcmVqZWN0KSB7CiAgICAgICAgICAgICAgc2lnbmFsLmFkZEV2ZW50TGlzdGVuZXIoImFib3J0IiwgZnVuY3Rpb24oKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gcmVqZWN0KGFib3J0RXJyb3IpOwogICAgICAgICAgICAgIH0sIHsKICAgICAgICAgICAgICAgIG9uY2U6IHRydWUKICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIGlmIChpbml0MiAmJiBpbml0Mi5zaWduYWwpIHsKICAgICAgICAgICAgICBkZWxldGUgaW5pdDIuc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dyBuZXcgRXJyb3IoImNhbm5vdCBhZGQgYSBzaWduYWwsIGFscmVhZHkgYWJvcnRlZCEiKTsKICAgICAgICAgIH0KICAgICAgICAgIHRoaXMuc2lnbmFscy5hZGQoc2lnbmFsKTsKICAgICAgICAgIGlmIChzaWduYWwuYWJvcnRlZCkgewogICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgIH0gZWxzZSBpZiAodHlwZW9mIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyID09PSAiZnVuY3Rpb24iKSB7CiAgICAgICAgICAgIHNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgICB0aGlzLmhhbmRsZUFib3J0ZWQoc2lnbmFsKTsKICAgICAgICAgICAgfSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGhhbmRsZUFib3J0ZWQoc2lnbmFsKSB7CiAgICAgICAgICB0aGlzLnNpZ25hbHMuZGVsZXRlKHNpZ25hbCk7CiAgICAgICAgICBpZiAodGhpcy5zaWduYWxzLnNpemUgPT09IDApIHsKICAgICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIuYWJvcnQoKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpZ25hbCgpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmFib3J0Q29udHJvbGxlci5zaWduYWw7CiAgICAgICAgfQogICAgICAgIGFib3J0KCkgewogICAgICAgICAgdGhpcy5hYm9ydENvbnRyb2xsZXIuYWJvcnQoKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLmRlZmF1bHQgPSBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXI7CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9hYm9ydGFibGUtcHJvbWlzZS1jYWNoZUAxLjUuMC9ub2RlX21vZHVsZXMvYWJvcnRhYmx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nJvcjogYWJvcnRlZCIgfHwgZXhjZXB0aW9uLm1lc3NhZ2UgPT09ICJFcnJvcjogYWJvcnRlZCI7CiAgICAgICAgfQogICAgICAgIGV2aWN0KGtleSwgZW50cnkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmdldChrZXkpID09PSBlbnRyeSkgewogICAgICAgICAgICB0aGlzLmNhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmaWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjaykgewogICAgICAgICAgY29uc3QgYWJvcnRlciA9IG5ldyBBZ2dyZWdhdGVBYm9ydENvbnRyb2xsZXJfMS5kZWZhdWx0KCk7CiAgICAgICAgICBjb25zdCBzdGF0dXNSZXBvcnRlciA9IG5ldyBBZ2dyZWdhdGVTdGF0dXNSZXBvcnRlcl8xLmRlZmF1bHQoKTsKICAgICAgICAgIHN0YXR1c1JlcG9ydGVyLmFkZENhbGxiYWNrKHN0YXR1c0NhbGxiYWNrKTsKICAgICAgICAgIGNvbnN0IG5ld0VudHJ5ID0gewogICAgICAgICAgICBhYm9ydGVyLAogICAgICAgICAgICBwcm9taXNlOiB0aGlzLmZpbGxDYWxsYmFjayhkYXRhLCBhYm9ydGVyLnNpZ25hbCwgKG1lc3NhZ2UpID0+IHsKICAgICAgICAgICAgICBzdGF0dXNSZXBvcnRlci5jYWxsYmFjayhtZXNzYWdlKTsKICAgICAgICAgICAgfSksCiAgICAgICAgICAgIHNldHRsZWQ6IGZhbHNlLAogICAgICAgICAgICBzdGF0dXNSZXBvcnRlciwKICAgICAgICAgICAgZ2V0IGFib3J0ZWQoKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMuYWJvcnRlci5zaWduYWwuYWJvcnRlZDsKICAgICAgICAgICAgfQogICAgICAgICAgfTsKICAgICAgICAgIG5ld0VudHJ5LmFib3J0ZXIuYWRkU2lnbmFsKHNpZ25hbCk7CiAgICAgICAgICBuZXdFbnRyeS5hYm9ydGVyLnNpZ25hbC5hZGRFdmVudExpc3RlbmVyKCJhYm9ydCIsICgpID0+IHsKICAgICAgICAgICAgaWYgKCFuZXdFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgdGhpcy5ldmljdChrZXksIG5ld0VudHJ5KTsKICAgICAgICAgICAgfQogICAgICAgICAgfSk7CiAgICAgICAgICBuZXdFbnRyeS5wcm9taXNlLnRoZW4oKCkgPT4gewogICAgICAgICAgICBuZXdFbnRyeS5zZXR0bGVkID0gdHJ1ZTsKICAgICAgICAgIH0sICgpID0+IHsKICAgICAgICAgICAgbmV3RW50cnkuc2V0dGxlZCA9IHRydWU7CiAgICAgICAgICAgIHRoaXMuZXZpY3Qoa2V5LCBuZXdFbnRyeSk7CiAgICAgICAgICB9KS5jYXRjaCgoZSkgPT4gewogICAgICAgICAgICBjb25zb2xlLmVycm9yKGUpOwogICAgICAgICAgICB0aHJvdyBlOwogICAgICAgICAgfSk7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIG5ld0VudHJ5KTsKICAgICAgICB9CiAgICAgICAgc3RhdGljIGNoZWNrU2luZ2xlUHJvbWlzZShwcm9taXNlLCBzaWduYWwpIHsKICAgICAgICAgIGZ1bmN0aW9uIGNoZWNrRm9yU2luZ2xlQWJvcnQoKSB7CiAgICAgICAgICAgIGlmIChzaWduYWwgJiYgc2lnbmFsLmFib3J0ZWQpIHsKICAgICAgICAgICAgICB0aHJvdyBPYmplY3QuYXNzaWduKG5ldyBFcnJvcigiYWJvcnRlZCIpLCB7IGNvZGU6ICJFUlJfQUJPUlRFRCIgfSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBwcm9taXNlLnRoZW4oKHJlc3VsdCkgPT4gewogICAgICAgICAgICBjaGVja0ZvclNpbmdsZUFib3J0KCk7CiAgICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgICB9LCAoZXJyb3IpID0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gICAgICAgICAgIGNhY2hlRW50cnkuc3RhdHVzUmVwb3J0ZXIuYWRkQ2FsbGJhY2soc3RhdHVzQ2FsbGJhY2spOwogICAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UoY2FjaGVFbnRyeS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5maWxsKGtleSwgZGF0YSwgc2lnbmFsLCBzdGF0dXNDYWxsYmFjayk7CiAgICAgICAgICByZXR1cm4gQWJvcnRhYmxlUHJvbWlzZUNhY2hlMi5jaGVja1NpbmdsZVByb21pc2UodGhpcy5jYWNoZS5nZXQoa2V5KS5wcm9taXNlLCBzaWduYWwpOwogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBjYWNoZWRFbnRyeSA9IHRoaXMuY2FjaGUuZ2V0KGtleSk7CiAgICAgICAgICBpZiAoY2FjaGVkRW50cnkpIHsKICAgICAgICAgICAgaWYgKCFjYWNoZWRFbnRyeS5zZXR0bGVkKSB7CiAgICAgICAgICAgICAgY2FjaGVkRW50cnkuYWJvcnRlci5hYm9ydCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRoaXMuY2FjaGUuZGVsZXRlKGtleSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgY29uc3Qga2V5SXRlciA9IHRoaXMuY2FjaGUua2V5cygpOwogICAgICAgICAgbGV0IGRlbGV0ZUNvdW50ID0gMDsKICAgICAgICAgIGZvciAobGV0IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpOyAhcmVzdWx0LmRvbmU7IHJlc3VsdCA9IGtleUl0ZXIubmV4dCgpKSB7CiAgICAgICAgICAgIHRoaXMuZGVsZXRlKHJlc3VsdC52YWx1ZSk7CiAgICAgICAgICAgIGRlbGV0ZUNvdW50ICs9IDE7CiAgICAgICAgICB9C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nVANC4wLjEvbm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcwogIHZhciByZXF1aXJlX3F1aWNrX2xydSA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9xdWljay1scnVANC4wLjEvbm9kZV9tb2R1bGVzL3F1aWNrLWxydS9pbmRleC5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIHZhciBRdWlja0xSVSA9IGNsYXNzIHsKICAgICAgICBjb25zdHJ1Y3RvcihvcHRpb25zID0ge30pIHsKICAgICAgICAgIGlmICghKG9wdGlvbnMubWF4U2l6ZSAmJiBvcHRpb25zLm1heFNpemUgPiAwKSkgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJgbWF4U2l6ZWAgbXVzdCBiZSBhIG51bWJlciBncmVhdGVyIHRoYW4gMCIpOwogICAgICAgICAgfQogICAgICAgICAgdGhpcy5tYXhTaXplID0gb3B0aW9ucy5tYXhTaXplOwogICAgICAgICAgdGhpcy5jYWNoZSA9IG5ldyBNYXAoKTsKICAgICAgICAgIHRoaXMub2xkQ2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICB9CiAgICAgICAgX3NldChrZXksIHZhbHVlKSB7CiAgICAgICAgICB0aGlzLmNhY2hlLnNldChrZXksIHZhbHVlKTsKICAgICAgICAgIHRoaXMuX3NpemUrKzsKICAgICAgICAgIGlmICh0aGlzLl9zaXplID49IHRoaXMubWF4U2l6ZSkgewogICAgICAgICAgICB0aGlzLl9zaXplID0gMDsKICAgICAgICAgICAgdGhpcy5vbGRDYWNoZSA9IHRoaXMuY2FjaGU7CiAgICAgICAgICAgIHRoaXMuY2FjaGUgPSBuZXcgTWFwKCk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGdldChrZXkpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHRoaXMub2xkQ2FjaGUuaGFzKGtleSkpIHsKICAgICAgICAgICAgY29uc3QgdmFsdWUgPSB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgICB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpOwogICAgICAgICAgICB0aGlzLl9zZXQoa2V5LCB2YWx1ZSk7CiAgICAgICAgICAgIHJldHVybiB2YWx1ZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgc2V0KGtleSwgdmFsdWUpIHsKICAgICAgICAgIGlmICh0aGlzLmNhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHRoaXMuY2FjaGUuc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdGhpcy5fc2V0KGtleSwgdmFsdWUpOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgfQogICAgICAgIGhhcyhrZXkpIHsKICAgICAgICAgIHJldHVybiB0aGlzLmNhY2hlLmhhcyhrZXkpIHx8IHRoaXMub2xkQ2FjaGUuaGFzKGtleSk7CiAgICAgICAgfQogICAgICAgIHBlZWsoa2V5KSB7CiAgICAgICAgICBpZiAodGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICByZXR1cm4gdGhpcy5jYWNoZS5nZXQoa2V5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0aGlzLm9sZENhY2hlLmhhcyhrZXkpKSB7CiAgICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmdldChrZXkpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZWxldGUoa2V5KSB7CiAgICAgICAgICBjb25zdCBkZWxldGVkID0gdGhpcy5jYWNoZS5kZWxldGUoa2V5KTsKICAgICAgICAgIGlmIChkZWxldGVkKSB7CiAgICAgICAgICAgIHRoaXMuX3NpemUtLTsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiB0aGlzLm9sZENhY2hlLmRlbGV0ZShrZXkpIHx8IGRlbGV0ZWQ7CiAgICAgICAgfQogICAgICAgIGNsZWFyKCkgewogICAgICAgICAgdGhpcy5jYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5vbGRDYWNoZS5jbGVhcigpOwogICAgICAgICAgdGhpcy5fc2l6ZSA9IDA7CiAgICAgICAgfQogICAgICAgICprZXlzKCkgewogICAgICAgICAgZm9yIChjb25zdCBba2V5XSBvZiB0aGlzKSB7CiAgICAgICAgICAgIHlpZWxkIGtleTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgKnZhbHVlcygpIHsKICAgICAgICAgIGZvciAoY29uc3QgWywgdmFsdWVdIG9mIHRoaXMpIHsKICAgICAgICAgICAgeWllbGQgdmFsdWU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgICpbU3ltYm9sLml0ZXJhdG9yXSgpIHsKICAgICAgICAgIGZvciAoY29uc3QgaXRlbSBvZiB0aGlzLmNhY2hlKSB7CiAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKGNvbnN0IGl0ZW0gb2YgdGhpcy5vbGRDYWNoZSkgewogICAgICAgICAgICBjb25zdCBba2V5XSA9IGl0ZW07CiAgICAgICAgICAgIGlmICghdGhpcy5jYWNoZS5oYXMoa2V5KSkgewogICAgICAgICAgICAgIHlpZWxkIGl0ZW07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZ2V0IHNpemUoKSB7CiAgICAgICAgICBsZXQgb2xkQ2FjaGVTaXplID0gMDsKICAgICAgICAgIGZvciAoY29uc3Qga2V5IG9mIHRoaXMub2xkQ2FjaGUua2V5cygpKSB7CiAgICAgICAgICAgIGl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VvZiBJbnQzMkFycmF5ICE9PSAidW5kZWZpbmVkIjsKICAgICAgZnVuY3Rpb24gX2hhcyhvYmosIGtleSkgewogICAgICAgIHJldHVybiBPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwob2JqLCBrZXkpOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmFzc2lnbiA9IGZ1bmN0aW9uKG9iaikgewogICAgICAgIHZhciBzb3VyY2VzID0gQXJyYXkucHJvdG90eXBlLnNsaWNlLmNhbGwoYXJndW1lbnRzLCAxKTsKICAgICAgICB3aGlsZSAoc291cmNlcy5sZW5ndGgpIHsKICAgICAgICAgIHZhciBzb3VyY2UgPSBzb3VyY2VzLnNoaWZ0KCk7CiAgICAgICAgICBpZiAoIXNvdXJjZSkgewogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmICh0eXBlb2Ygc291cmNlICE9PSAib2JqZWN0IikgewogICAgICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKHNvdXJjZSArICJtdXN0IGJlIG5vbi1vYmplY3QiKTsKICAgICAgICAgIH0KICAgICAgICAgIGZvciAodmFyIHAgaW4gc291cmNlKSB7CiAgICAgICAgICAgIGlmIChfaGFzKHNvdXJjZSwgcCkpIHsKICAgICAgICAgICAgICBvYmpbcF0gPSBzb3VyY2VbcF07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIG9iajsKICAgICAgfTsKICAgICAgZXhwb3J0czIuc2hyaW5rQnVmID0gZnVuY3Rpb24oYnVmLCBzaXplKSB7CiAgICAgICAgaWYgKGJ1Zi5sZW5ndGggPT09IHNpemUpIHsKICAgICAgICAgIHJldHVybiBidWY7CiAgICAgICAgfQogICAgICAgIGlmIChidWYuc3ViYXJyYXkpIHsKICAgICAgICAgIHJldHVybiBidWYuc3ViYXJyYXkoMCwgc2l6ZSk7CiAgICAgICAgfQogICAgICAgIGJ1Zi5sZW5ndGggPSBzaXplOwogICAgICAgIHJldHVybiBidWY7CiAgICAgIH07CiAgICAgIHZhciBmblR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgaWYgKHNyYy5zdWJhcnJheSAmJiBkZXN0LnN1YmFycmF5KSB7CiAgICAgICAgICAgIGRlc3Quc2V0KHNyYy5zdWJhcnJheShzcmNfb2Zmcywgc3JjX29mZnMgKyBsZW4pLCBkZXN0X29mZnMpOwogICAgICAgICAgICByZXR1cm47CiAgICAgICAgICB9CiAgICAgICAgICBmb3IgKHZhciBpID0gMDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICAgIGRlc3RbZGVzdF9vZmZzICsgaV0gPSBzcmNbc3JjX29mZnMgKyBpXTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIGZsYXR0ZW5DaHVua3M6IGZ1bmN0aW9uKGNodW5rcykgewogICAgICAgICAgdmFyIGksIGwsIGxlbiwgcG9zLCBjaHVuaywgcmVzdWx0OwogICAgICAgICAgbGVuID0gMDsKICAgICAgICAgIGZvciAoaSA9IDAsIGwgPSBjaHVua3MubGVuZ3RoOyBpIDwgbDsgaSsrKSB7CiAgICAgICAgICAgIGxlbiArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgfQogICAgICAgICAgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkobGVuKTsKICAgICAgICAgIHBvcyA9IDA7CiAgICAgICAgICBmb3IgKGkgPSAwLCBsID0gY2h1bmtzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBjaHVuayA9IGNodW5rc1tpXTsKICAgICAgICAgICAgcmVzdWx0LnNldChjaHVuaywgcG9zKTsKICAgICAgICAgICAgcG9zICs9IGNodW5rLmxlbmd0aDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgZm5VbnR5cGVkID0gewogICAgICAgIGFycmF5U2V0OiBmdW5jdGlvbihkZXN0LCBzcmMsIHNyY19vZmZzLCBsZW4sIGRlc3Rfb2ZmcykgewogICAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgICBkZXN0W2Rlc3Rfb2ZmcyArIGldID0gc3JjW3NyY19vZmZzICsgaV07CiAgICAgICAgICB9CiAgICAgICAgfSwKICAgICAgICBmbGF0dGVuQ2h1bmtzOiBmdW5jdGlvbihjaHVua3MpIHsKICAgICAgICAgIHJldHVybiBbXS5jb25jYXQuYXBwbHkoW10sIGNodW5rcyk7CiAgICAgICAgfQogICAgICB9OwogICAgICBleHBvcnRzMi5zZXRUeXBlZCA9IGZ1bmN0aW9uKG9uKSB7CiAgICAgICAgaWYgKG9uKSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gVWludDhBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLkJ1ZjE2ID0gVWludDE2QXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYzMiA9IEludDMyQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5hc3NpZ24oZXhwb3J0czIsIGZuVHlwZWQpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBleHBvcnRzMi5CdWY4ID0gQXJyYXk7CiAgICAgICAgICBleHBvcnRzMi5CdWYxNiA9IEFycmF5OwogICAgICAgICAgZXhwb3J0czIuQnVmMzIgPSBBcnJheTsKICAgICAgICAgIGV4cG9ydHMyLmFzc2lnbihleHBvcnRzMiwgZm5VbnR5cGVkKTsKICAgICAgICB9CiAgICAgIH07CiAgICAgIGV4cG9ydHMyLnNldFR5cGVkKFRZUEVEX09LKTsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL3RyZWVzLmpzCiAgdmFyIHJlcXVpcmVfdHJlZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvdHJlZXMuanMiKGV4cG9ydHMyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICB2YXIgdXRpbHMgPSByZXF1aXJlX2NvbW1vbigpOwogICAgICB2YXIgWl9GSVhFRCA9IDQ7CiAgICAgIHZhciBaX0JJTkFSWSA9IDA7CiAgICAgIHZhciBaX1RFWFQgPSAxOwogICAgICB2YXIgWl9VTktOT1dOID0gMjsKICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICB2YXIgU1RPUkVEX0JMT0NLID0gMDsKICAgICAgdmFyIFNUQVRJQ19UUkVFUyA9IDE7CiAgICAgIHZhciBEWU5fVFJFRVMgPSAyOwogICAgICB2YXIgTUlOX01BVENIID0gMzsKICAgICAgdmFyIE1BWF9NQVRDSCA9IDI1ODsKICAgICAgdmFyIExFTkdUSF9DT0RFUyA9IDI5OwogICAgICB2YXIgTElURVJBTFMgPSAyNTY7CiAgICAgIHZhciBMX0NPREVTID0gTElURVJBTFMgKyAxICsgTEVOR1RIX0NPREVTOwogICAgICB2YXIgRF9DT0RFUyA9IDMwOwogICAgICB2YXIgQkxfQ09ERVMgPSAxOTsKICAgICAgdmFyIEhFQVBfU0laRSA9IDIgKiBMX0NPREVTICsgMTsKICAgICAgdmFyIE1BWF9CSVRTID0gMTU7CiAgICAgIHZhciBCdWZfc2l6ZSA9IDE2OwogICAgICB2YXIgTUFYX0JMX0JJVFMgPSA3OwogICAgICB2YXIgRU5EX0JMT0NLID0gMjU2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ICAgZnVuY3Rpb24gYmlfZmx1c2gocykgewogICAgICAgIGlmIChzLmJpX3ZhbGlkID09PSAxNikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIHMuYmlfYnVmKTsKICAgICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICAgIHMuYmlfdmFsaWQgPSAwOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+PSA4KSB7CiAgICAgICAgICBzLnBlbmRpbmdfYnVmW3MucGVuZGluZysrXSA9IHMuYmlfYnVmICYgMjU1OwogICAgICAgICAgcy5iaV9idWYgPj49IDg7CiAgICAgICAgICBzLmJpX3ZhbGlkIC09IDg7CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIGdlbl9iaXRsZW4ocywgZGVzYykgewogICAgICAgIHZhciB0cmVlID0gZGVzYy5keW5fdHJlZTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSBkZXNjLm1heF9jb2RlOwogICAgICAgIHZhciBzdHJlZSA9IGRlc2Muc3RhdF9kZXNjLnN0YXRpY190cmVlOwogICAgICAgIHZhciBoYXNfc3RyZWUgPSBkZXNjLnN0YXRfZGVzYy5oYXNfc3RyZWU7CiAgICAgICAgdmFyIGV4dHJhID0gZGVzYy5zdGF0X2Rlc2MuZXh0cmFfYml0czsKICAgICAgICB2YXIgYmFzZSA9IGRlc2Muc3RhdF9kZXNjLmV4dHJhX2Jhc2U7CiAgICAgICAgdmFyIG1heF9sZW5ndGggPSBkZXNjLnN0YXRfZGVzYy5tYXhfbGVuZ3RoOwogICAgICAgIHZhciBoOwogICAgICAgIHZhciBuLCBtOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciB4Yml0czsKICAgICAgICB2YXIgZjsKICAgICAgICB2YXIgb3ZlcmZsb3cgPSAwOwogICAgICAgIGZvciAoYml0cyA9IDA7IGJpdHMgPD0gTUFYX0JJVFM7IGJpdHMrKykgewogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIHRyZWVbcy5oZWFwW3MuaGVhcF9tYXhdICogMiArIDFdID0gMDsKICAgICAgICBmb3IgKGggPSBzLmhlYXBfbWF4ICsgMTsgaCA8IEhFQVBfU0laRTsgaCsrKSB7CiAgICAgICAgICBuID0gcy5oZWFwW2hdOwogICAgICAgICAgYml0cyA9IHRyZWVbdHJlZVtuICogMiArIDFdICogMiArIDFdICsgMTsKICAgICAgICAgIGlmIChiaXRzID4gbWF4X2xlbmd0aCkgewogICAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aDsKICAgICAgICAgICAgb3ZlcmZsb3crKzsKICAgICAgICAgIH0KICAgICAgICAgIHRyZWVbbiAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICBpZiAobiA+IG1heF9jb2RlKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgcy5ibF9jb3VudFtiaXRzXSsrOwogICAgICAgICAgeGJpdHMgPSAwOwogICAgICAgICAgaWYgKG4gPj0gYmFzZSkgewogICAgICAgICAgICB4Yml0cyA9IGV4dHJhW24gLSBiYXNlXTsKICAgICAgICAgIH0KICAgICAgICAgIGYgPSB0cmVlW24gKiAyXTsKICAgICAgICAgIHMub3B0X2xlbiArPSBmICogKGJpdHMgKyB4Yml0cyk7CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiArPSBmICogKHN0cmVlW24gKiAyICsgMV0gKyB4Yml0cyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChvdmVyZmxvdyA9PT0gMCkgewogICAgICAgICAgcmV0dXJuOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBiaXRzID0gbWF4X2xlbmd0aCAtIDE7CiAgICAgICAgICB3aGlsZSAocy5ibF9jb3VudFtiaXRzXSA9PT0gMCkgewogICAgICAgICAgICBiaXRzLS07CiAgICAgICAgICB9CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHNdLS07CiAgICAgICAgICBzLmJsX2NvdW50W2JpdHMgKyAxXSArPSAyOwogICAgICAgICAgcy5ibF9jb3VudFttYXhfbGVuZ3RoXS0tOwogICAgICAgICAgb3ZlcmZsb3cgLT0gMjsKICAgICAgICB9IHdoaWxlIChvdmVyZmxvdyA+IDApOwogICAgICAgIGZvciAoYml0cyA9IG1heF9sZW5ndGg7IGJpdHMgIT09IDA7IGJpdHMtLSkgewogICAgICAgICAgbiA9IHMuYmxfY291bnRbYml0c107CiAgICAgICAgICB3aGlsZSAobiAhPT0gMCkgewogICAgICAgICAgICBtID0gcy5oZWFwWy0taF07CiAgICAgICAgICAgIGlmIChtID4gbWF4X2NvZGUpIHsKICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodHJlZVttICogMiArIDFdICE9PSBiaXRzKSB7CiAgICAgICAgICAgICAgcy5vcHRfbGVuICs9IChiaXRzIC0gdHJlZVttICogMiArIDFdKSAqIHRyZWVbbSAqIDJdOwogICAgICAgICAgICAgIHRyZWVbbSAqIDIgKyAxXSA9IGJpdHM7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgbi0tOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBnZW5fY29kZXModHJlZSwgbWF4X2NvZGUsIGJsX2NvdW50KSB7CiAgICAgICAgdmFyIG5leHRfY29kZSA9IG5ldyBBcnJheShNQVhfQklUUyArIDEpOwogICAgICAgIHZhciBjb2RlID0gMDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKGJpdHMgPSAxOyBiaXRzIDw9IE1BWF9CSVRTOyBiaXRzKyspIHsKICAgICAgICAgIG5leHRfY29kZVtiaXRzXSA9IGNvZGUgPSBjb2RlICsgYmxfY291bnRbYml0cyAtIDFdIDw8IDE7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDA7IG4gPD0gbWF4X2NvZGU7IG4rKykgewogICAgICAgICAgdmFyIGxlbiA9IHRyZWVbbiAqIDIgKyAxXTsKICAgICAgICAgIGlmIChsZW4gPT09IDApIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICB0cmVlW24gKiAyXSA9IGJpX3JldmVyc2UobmV4dF9jb2RlW2xlbl0rKywgbGVuKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gdHJfc3RhdGljX2luaXQoKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIGJpdHM7CiAgICAgICAgdmFyIGxlbmd0aDsKICAgICAgICB2YXIgY29kZTsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgYmxfY291bnQgPSBuZXcgQXJyYXkoTUFYX0JJVFMgKyAxKTsKICAgICAgICBsZW5ndGggPSAwOwogICAgICAgIGZvciAoY29kZSA9IDA7IGNvZGUgPCBMRU5HVEhfQ09ERVMgLSAxOyBjb2RlKyspIHsKICAgICAgICAgIGJhc2VfbGVuZ3RoW2NvZGVdID0gbGVuZ3RoOwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfbGJpdHNbY29kZV07IG4rKykgewogICAgICAgICAgICBfbGVuZ3RoX2NvZGVbbGVuZ3RoKytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgX2xlbmd0aF9jb2RlW2xlbmd0aCAtIDFdID0gY29kZTsKICAgICAgICBkaXN0ID0gMDsKICAgICAgICBmb3IgKGNvZGUgPSAwOyBjb2RlIDwgMTY7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdDsKICAgICAgICAgIGZvciAobiA9IDA7IG4gPCAxIDw8IGV4dHJhX2RiaXRzW2NvZGVdOyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVtkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZGlzdCA+Pj0gNzsKICAgICAgICBmb3IgKDsgY29kZSA8IERfQ09ERVM7IGNvZGUrKykgewogICAgICAgICAgYmFzZV9kaXN0W2NvZGVdID0gZGlzdCA8PCA3OwogICAgICAgICAgZm9yIChuID0gMDsgbiA8IDEgPDwgZXh0cmFfZGJpdHNbY29kZV0gLSA3OyBuKyspIHsKICAgICAgICAgICAgX2Rpc3RfY29kZVsyNTYgKyBkaXN0KytdID0gY29kZTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZm9yIChiaXRzID0gMDsgYml0cyA8PSBNQVhfQklUUzsgYml0cysrKSB7CiAgICAgICAgICBibF9jb3VudFtiaXRzXSA9IDA7CiAgICAgICAgfQogICAgICAgIG4gPSAwOwogICAgICAgIHdoaWxlIChuIDw9IDE0MykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgd2hpbGUgKG4gPD0gMjU1KSB7CiAgICAgICAgICBzdGF0aWNfbHRyZWVbbiAqIDIgKyAxXSA9IDk7CiAgICAgICAgICBuKys7CiAgICAgICAgICBibF9jb3VudFs5XSsrOwogICAgICAgIH0KICAgICAgICB3aGlsZSAobiA8PSAyNzkpIHsKICAgICAgICAgIHN0YXRpY19sdHJlZVtuICogMiArIDFdID0gNzsKICAgICAgICAgIG4rKzsKICAgICAgICAgIGJsX2NvdW50WzddKys7CiAgICAgICAgfQogICAgICAgIHdoaWxlIChuIDw9IDI4NykgewogICAgICAgICAgc3RhdGljX2x0cmVlW24gKiAyICsgMV0gPSA4OwogICAgICAgICAgbisrOwogICAgICAgICAgYmxfY291bnRbOF0rKzsKICAgICAgICB9CiAgICAgICAgZ2VuX2NvZGVzKHN0YXRpY19sdHJlZSwgTF9DT0RFUyArIDEsIGJsX2NvdW50KTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDwgRF9DT0RFUzsgbisrKSB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W9uIGJpX3dpbmR1cChzKSB7CiAgICAgICAgaWYgKHMuYmlfdmFsaWQgPiA4KSB7CiAgICAgICAgICBwdXRfc2hvcnQocywgcy5iaV9idWYpOwogICAgICAgIH0gZWxzZSBpZiAocy5iaV92YWxpZCA+IDApIHsKICAgICAgICAgIHMucGVuZGluZ19idWZbcy5wZW5kaW5nKytdID0gcy5iaV9idWY7CiAgICAgICAgfQogICAgICAgIHMuYmlfYnVmID0gMDsKICAgICAgICBzLmJpX3ZhbGlkID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBjb3B5X2Jsb2NrKHMsIGJ1ZiwgbGVuLCBoZWFkZXIpIHsKICAgICAgICBiaV93aW5kdXAocyk7CiAgICAgICAgaWYgKGhlYWRlcikgewogICAgICAgICAgcHV0X3Nob3J0KHMsIGxlbik7CiAgICAgICAgICBwdXRfc2hvcnQocywgfmxlbik7CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHMucGVuZGluZ19idWYsIHMud2luZG93LCBidWYsIGxlbiwgcy5wZW5kaW5nKTsKICAgICAgICBzLnBlbmRpbmcgKz0gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNtYWxsZXIodHJlZSwgbiwgbSwgZGVwdGgpIHsKICAgICAgICB2YXIgX24yID0gbiAqIDI7CiAgICAgICAgdmFyIF9tMiA9IG0gKiAyOwogICAgICAgIHJldHVybiB0cmVlW19uMl0gPCB0cmVlW19tMl0gfHwgdHJlZVtfbjJdID09PSB0cmVlW19tMl0gJiYgZGVwdGhbbl0gPD0gZGVwdGhbbV07CiAgICAgIH0KICAgICAgZnVuY3Rpb24gcHFkb3duaGVhcChzLCB0cmVlLCBrKSB7CiAgICAgICAgdmFyIHYgPSBzLmhlYXBba107CiAgICAgICAgdmFyIGogPSBrIDw8IDE7CiAgICAgICAgd2hpbGUgKGogPD0gcy5oZWFwX2xlbikgewogICAgICAgICAgaWYgKGogPCBzLmhlYXBfbGVuICYmIHNtYWxsZXIodHJlZSwgcy5oZWFwW2ogKyAxXSwgcy5oZWFwW2pdLCBzLmRlcHRoKSkgewogICAgICAgICAgICBqKys7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoc21hbGxlcih0cmVlLCB2LCBzLmhlYXBbal0sIHMuZGVwdGgpKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcy5oZWFwW2tdID0gcy5oZWFwW2pdOwogICAgICAgICAgayA9IGo7CiAgICAgICAgICBqIDw8PSAxOwogICAgICAgIH0KICAgICAgICBzLmhlYXBba10gPSB2OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGNvbXByZXNzX2Jsb2NrKHMsIGx0cmVlLCBkdHJlZSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBsYzsKICAgICAgICB2YXIgbHggPSAwOwogICAgICAgIHZhciBjb2RlOwogICAgICAgIHZhciBleHRyYTsKICAgICAgICBpZiAocy5sYXN0X2xpdCAhPT0gMCkgewogICAgICAgICAgZG8gewogICAgICAgICAgICBkaXN0ID0gcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyXSA8PCA4IHwgcy5wZW5kaW5nX2J1ZltzLmRfYnVmICsgbHggKiAyICsgMV07CiAgICAgICAgICAgIGxjID0gcy5wZW5kaW5nX2J1ZltzLmxfYnVmICsgbHhdOwogICAgICAgICAgICBseCsrOwogICAgICAgICAgICBpZiAoZGlzdCA9PT0gMCkgewogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBsYywgbHRyZWUpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIGNvZGUgPSBfbGVuZ3RoX2NvZGVbbGNdOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlICsgTElURVJBTFMgKyAxLCBsdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9sYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGxjIC09IGJhc2VfbGVuZ3RoW2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGxjLCBleHRyYSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGRpc3QtLTsKICAgICAgICAgICAgICBjb2RlID0gZF9jb2RlKGRpc3QpOwogICAgICAgICAgICAgIHNlbmRfY29kZShzLCBjb2RlLCBkdHJlZSk7CiAgICAgICAgICAgICAgZXh0cmEgPSBleHRyYV9kYml0c1tjb2RlXTsKICAgICAgICAgICAgICBpZiAoZXh0cmEgIT09IDApIHsKICAgICAgICAgICAgICAgIGRpc3QgLT0gYmFzZV9kaXN0W2NvZGVdOwogICAgICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGRpc3QsIGV4dHJhKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gd2hpbGUgKGx4IDwgcy5sYXN0X2xpdCk7CiAgICAgICAgfQogICAgICAgIHNlbmRfY29kZShzLCBFTkRfQkxPQ0ssIGx0cmVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBidWlsZF90cmVlKHMsIGRlc2MpIHsKICAgICAgICB2YXIgdHJlZSA9IGRlc2MuZHluX3RyZWU7CiAgICAgICAgdmFyIHN0cmVlID0gZGVzYy5zdGF0X2Rlc2Muc3RhdGljX3RyZWU7CiAgICAgICAgdmFyIGhhc19zdHJlZSA9IGRlc2Muc3RhdF9kZXNjLmhhc19zdHJlZTsKICAgICAgICB2YXIgZWxlbXMgPSBkZXNjLnN0YXRfZGVzYy5lbGVtczsKICAgICAgICB2YXIgbiwgbTsKICAgICAgICB2YXIgbWF4X2NvZGUgPSAtMTsKICAgICAgICB2YXIgbm9kZTsKICAgICAgICBzLmhlYXBfbGVuID0gMDsKICAgICAgICBzLmhlYXBfbWF4ID0gSEVBUF9TSVpFOwogICAgICAgIGZvciAobiA9IDA7IG4gPCBlbGVtczsgbisrKSB7CiAgICAgICAgICBpZiAodHJlZVtuICogMl0gIT09IDApIHsKICAgICAgICAgICAgcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA9IG47CiAgICAgICAgICAgIHMuZGVwdGhbbl0gPSAwOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgdHJlZVtuICogMiArIDFdID0gMDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgd2hpbGUgKHMuaGVhcF9sZW4gPCAyKSB7CiAgICAgICAgICBub2RlID0gcy5oZWFwWysrcy5oZWFwX2xlbl0gPSBtYXhfY29kZSA8IDIgPyArK21heF9jb2RlIDogMDsKICAgICAgICAgIHRyZWVbbm9kZSAqIDJdID0gMTsKICAgICAgICAgIHMuZGVwdGhbbm9kZV0gPSAwOwogICAgICAgICAgcy5vcHRfbGVuLS07CiAgICAgICAgICBpZiAoaGFzX3N0cmVlKSB7CiAgICAgICAgICAgIHMuc3RhdGljX2xlbiAtPSBzdHJlZVtub2RlICogMiArIDFdOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBkZXNjLm1heF9jb2RlID0gbWF4X2NvZGU7CiAgICAgICAgZm9yIChuID0gcy5oZWFwX2xlbiA+PiAxOyBuID49IDE7IG4tLSkgewogICAgICAgICAgcHFkb3duaGVhcChzLCB0cmVlLCBuKTsKICAgICAgICB9CiAgICAgICAgbm9kZSA9IGVsZW1zOwogICAgICAgIGRvIHsKICAgICAgICAgIG4gPSBzLmhlYXBbMV07CiAgICAgICAgICBzLmhlYXBbMV0gPSBzLmhlYXBbcy5oZWFwX2xlbi0tXTsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgICBtID0gcy5oZWFwWzFdOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBuOwogICAgICAgICAgcy5oZWFwWy0tcy5oZWFwX21heF0gPSBtOwogICAgICAgICAgdHJlZVtub2RlICogMl0gPSB0cmVlW24gKiAyXSArIHRyZWVbbSAqIDJdOwogICAgICAgICAgcy5kZXB0aFtub2RlXSA9IChzLmRlcHRoW25dID49IHMuZGVwdGhbbV0gPyBzLmRlcHRoW25dIDogcy5kZXB0aFttXSkgKyAxOwogICAgICAgICAgdHJlZVtuICogMiArIDFdID0gdHJlZVttICogMiArIDFdID0gbm9kZTsKICAgICAgICAgIHMuaGVhcFsxXSA9IG5vZGUrKzsKICAgICAgICAgIHBxZG93bmhlYXAocywgdHJlZSwgMSk7CiAgICAgICAgfSB3aGlsZSAocy5oZWFwX2xlbiA+PSAyKTsKICAgICAgICBzLmhlYXBbLS1zLmhlYXBfbWF4XSA9IHMuaGVhcFsxXTsKICAgICAgICBnZW5fYml0bGVuKHMsIGRlc2MpOwogICAgICAgIGdlbl9jb2Rlcyh0cmVlLCBtYXhfY29kZSwgcy5ibF9jb3VudCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2Nhbl90cmVlKHMsIHRyZWUsIG1heF9jb2RlKSB7CiAgICAgICAgdmFyIG47CiAgICAgICAgdmFyIHByZXZsZW4gPSAtMTsKICAgICAgICB2YXIgY3VybGVuOwogICAgICAgIHZhciBuZXh0bGVuID0gdHJlZVswICogMiArIDFdOwogICAgICAgIHZhciBjb3VudCA9IDA7CiAgICAgICAgdmFyIG1heF9jb3VudCA9IDc7CiAgICAgICAgdmFyIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgIG1heF9jb3VudCA9IDEzODsKICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgfQogICAgICAgIHRyZWVbKG1heF9jb2RlICsgMSkgKiAyICsgMV0gPSA2NTUzNTsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBzLmJsX3RyZWVbY3VybGVuICogMl0gKz0gY291bnQ7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgcy5ibF90cmVlW2N1cmxlbiAqIDJdKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcy5ibF90cmVlW1JFUF8zXzYgKiAyXSsrOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8PSAxMCkgewogICAgICAgICAgICBzLmJsX3RyZWVbUkVQWl8zXzEwICogMl0rKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuYmxfdHJlZVtSRVBaXzExXzEzOCAqIDJdKys7CiAgICAgICAgICB9CiAgICAgICAgICBjb3VudCA9IDA7CiAgICAgICAgICBwcmV2bGVuID0gY3VybGVuOwogICAgICAgICAgaWYgKG5leHRsZW4gPT09IDApIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gMTM4OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIGlmIChjdXJsZW4gPT09IG5leHRsZW4pIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNjsKICAgICAgICAgICAgbWluX2NvdW50ID0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1heF9jb3VudCA9IDc7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDQ7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGZ1bmN0aW9uIHNlbmRfdHJlZShzLCB0cmVlLCBtYXhfY29kZSkgewogICAgICAgIHZhciBuOwogICAgICAgIHZhciBwcmV2bGVuID0gLTE7CiAgICAgICAgdmFyIGN1cmxlbjsKICAgICAgICB2YXIgbmV4dGxlbiA9IHRyZWVbMCAqIDIgKyAxXTsKICAgICAgICB2YXIgY291bnQgPSAwOwogICAgICAgIHZhciBtYXhfY291bnQgPSA3OwogICAgICAgIHZhciBtaW5fY291bnQgPSA0OwogICAgICAgIGlmIChuZXh0bGVuID09PSAwKSB7CiAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgIH0KICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IG1heF9jb2RlOyBuKyspIHsKICAgICAgICAgIGN1cmxlbiA9IG5leHRsZW47CiAgICAgICAgICBuZXh0bGVuID0gdHJlZVsobiArIDEpICogMiArIDFdOwogICAgICAgICAgaWYgKCsrY291bnQgPCBtYXhfY291bnQgJiYgY3VybGVuID09PSBuZXh0bGVuKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfSBlbHNlIGlmIChjb3VudCA8IG1pbl9jb3VudCkgewogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgfSB3aGlsZSAoLS1jb3VudCAhPT0gMCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiAhPT0gMCkgewogICAgICAgICAgICBpZiAoY3VybGVuICE9PSBwcmV2bGVuKSB7CiAgICAgICAgICAgICAgc2VuZF9jb2RlKHMsIGN1cmxlbiwgcy5ibF90cmVlKTsKICAgICAgICAgICAgICBjb3VudC0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHNlbmRfY29kZShzLCBSRVBfM182LCBzLmJsX3RyZWUpOwogICAgICAgICAgICBzZW5kX2JpdHMocywgY291bnQgLSAzLCAyKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY291bnQgPD0gMTApIHsKICAgICAgICAgICAgc2VuZF9jb2RlKHMsIFJFUFpfM18xMCwgcy5ibF90cmVlKTsKICAgICAgICAgICAgc2VuZF9iaXRzKHMsIGNvdW50IC0gMywgMyk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzZW5kX2NvZGUocywgUkVQWl8xMV8xMzgsIHMuYmxfdHJlZSk7CiAgICAgICAgICAgIHNlbmRfYml0cyhzLCBjb3VudCAtIDExLCA3KTsKICAgICAgICAgIH0KICAgICAgICAgIGNvdW50ID0gMDsKICAgICAgICAgIHByZXZsZW4gPSBjdXJsZW47CiAgICAgICAgICBpZiAobmV4dGxlbiA9PT0gMCkgewogICAgICAgICAgICBtYXhfY291bnQgPSAxMzg7CiAgICAgICAgICAgIG1pbl9jb3VudCA9IDM7CiAgICAgICAgICB9IGVsc2UgaWYgKGN1cmxlbiA9PT0gbmV4dGxlbikgewogICAgICAgICAgICBtYXhfY291bnQgPSA2OwogICAgICAgICAgICBtaW5fY291bnQgPSAzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWF4X2NvdW50ID0gNzsKICAgICAgICAgICAgbWluX2NvdW50ID0gNDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0KICAgICAgZnVuY3Rpb24gYnVpbGRfYmxfdHJlZShzKSB7CiAgICAgICAgdmFyIG1heF9ibGluZGV4OwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9sdHJlZSwgcy5sX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIHNjYW5fdHJlZShzLCBzLmR5bl9kdHJlZSwgcy5kX2Rlc2MubWF4X2NvZGUpOwogICAgICAgIGJ1aWxkX3RyZWUocywgcy5ibF9kZXNjKTsKICAgICAgICBmb3IgKG1heF9ibGluZGV4ID0gQkxfQ09ERVMgLSAxOyBtYXhfYmxpbmRleCA+PSAzOyBtYXhfYmxpbmRleC0tKSB7CiAgICAgICAgICBpZiAocy5ibF90cmVlW2JsX29yZGVyW21heF9ibGluZGV4XSAqIDIgKyAxXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5vcHRfbGVuICs9IDMgKiAobWF4X2JsaW5kZXggKyAxKSArIDUgKyA1ICsgNDsKICAgICAgICByZXR1cm4gbWF4X2JsaW5kZXg7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gc2VuZF9hbGxfdHJlZXMocywgbGNvZGVzLCBkY29kZXMsIGJsY29kZXMpIHsKICAgICAgICB2YXIgcmFuazsKICAgICAgICBzZW5kX2JpdHMocywgbGNvZGVzIC0gMjU3LCA1KTsKICAgICAgICBzZW5kX2JpdHMocywgZGNvZGVzIC0gMSwgNSk7CiAgICAgICAgc2VuZF9iaXRzKHMsIGJsY29kZXMgLSA0LCA0KTsKICAgICAgICBmb3IgKHJhbmsgPSAwOyByYW5rIDwgYmxjb2RlczsgcmFuaysrKSB7CiAgICAgICAgICBzZW5kX2JpdHMocywgcy5ibF90cmVlW2JsX29yZGVyW3JhbmtdICogMiArIDFdLCAzKTsKICAgICAgICB9CiAgICAgICAgc2VuZF90cmVlKHMsIHMuZHluX2x0cmVlLCBsY29kZXMgLSAxKTsKICAgICAgICBzZW5kX3RyZWUocywgcy5keW5fZHRyZWUsIGRjb2RlcyAtIDEpOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRldGVjdF9kYXRhX3R5cGUocykgewogICAgICAgIHZhciBibGFja19tYXNrID0gNDA5MzYyNDQ0NzsKICAgICAgICB2YXIgbjsKICAgICAgICBmb3IgKG4gPSAwOyBuIDw9IDMxOyBuKyssIGJsYWNrX21hc2sgPj4+PSAxKSB7CiAgICAgICAgICBpZiAoYmxhY2tfbWFzayAmIDEgJiYgcy5keW5fbHRyZWVbbiAqIDJdICE9PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBaX0JJTkFSWTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuZHluX2x0cmVlWzkgKiAyXSAhPT0gMCB8fCBzLmR5bl9sdHJlZVsxMCAqIDJdICE9PSAwIHx8IHMuZHluX2x0cmVlWzEzICogMl0gIT09IDApIHsKICAgICAgICAgIHJldHVybiBaX1RFWFQ7CiAgICAgICAgfQogICAgICAgIGZvciAobiA9IDMyOyBuIDwgTElURVJBTFM7IG4rKykgewogICAgICAgICAgaWYgKHMuZHluX2x0cmVlW24gKiAyXSAhPT0gMCkgewogICAgICAgICAgICByZXR1cm4gWl9URVhUOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gWl9CSU5BUlk7CiAgICAgIH0KICAgICAgdmFyIHN0YXRpY19pbml0X2RvbmUgPSBmYWxzZTsKICAgICAgZnVuY3Rpb24gX3RyX2luaXQocykgewogICAgICAgIGlmICghc3RhdGljX2luaXRfZG9uZSkgewogICAgICAgICAgdHJfc3RhdGljX2luaXQoKTsKICAgICAgICAgIHN0YXRpY19pbml0X2RvbmUgPSB0cnVlOwogICAgICAgIH0KICAgICAgICBzLmxfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmR5bl9sdHJlZSwgc3RhdGljX2xfZGVzYyk7CiAgICAgICAgcy5kX2Rlc2MgPSBuZXcgVHJlZURlc2Mocy5keW5fZHRyZWUsIHN0YXRpY19kX2Rlc2MpOwogICAgICAgIHMuYmxfZGVzYyA9IG5ldyBUcmVlRGVzYyhzLmJsX3RyZWUsIHN0YXRpY19ibF9kZXNjKTsKICAgICAgICBzLmJpX2J1ZiA9IDA7CiAgICAgICAgcy5iaV92YWxpZCA9IDA7CiAgICAgICAgaW5pdF9ibG9jayhzKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfc3RvcmVkX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX2xlbiwgbGFzdCkgewogICAgICAgIHNlbmRfYml0cyhzLCAoU1RPUkVEX0JMT0NLIDw8IDEpICsgKGxhc3QgPyAxIDogMCksIDMpOwogICAgICAgIGNvcHlfYmxvY2socywgYnVmLCBzdG9yZWRfbGVuLCB0cnVlKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfYWxpZ24ocykgewogICAgICAgIHNlbmRfYml0cyhzLCBTVEFUSUNfVFJFRVMgPDwgMSwgMyk7CiAgICAgICAgc2VuZF9jb2RlKHMsIEVORF9CTE9DSywgc3RhdGljX2x0cmVlKTsKICAgICAgICBiaV9mbHVzaChzKTsKICAgICAgfQogICAgICBmdW5jdGlvbiBfdHJfZmx1c2hfYmxvY2socywgYnVmLCBzdG9yZWRfbGVuLCBsYXN0KSB7CiAgICAgICAgdmFyIG9wdF9sZW5iLCBzdGF0aWNfbGVuYjsKICAgICAgICB2YXIgbWF4X2JsaW5kZXggPSAwOwogICAgICAgIGlmIChzLmxldmVsID4gMCkgewogICAgICAgICAgaWYgKHMuc3RybS5kYXRhX3R5cGUgPT09IFpfVU5LTk9XTikgewogICAgICAgICAgICBzLnN0cm0uZGF0YV90eXBlID0gZGV0ZWN0X2RhdGFfdHlwZShzKTsKICAgICAgICAgIH0KICAgICAgICAgIGJ1aWxkX3RyZWUocywgcy5sX2Rlc2MpOwogICAgICAgICAgYnVpbGRfdHJlZShzLCBzLmRfZGVzYyk7CiAgICAgICAgICBtYXhfYmxpbmRleCA9IGJ1aWxkX2JsX3RyZWUocyk7CiAgICAgICAgICBvcHRfbGVuYiA9IHMub3B0X2xlbiArIDMgKyA3ID4+PiAzOwogICAgICAgICAgc3RhdGljX2xlbmIgPSBzLnN0YXRpY19sZW4gKyAzICsgNyA+Pj4gMzsKICAgICAgICAgIGlmIChzdGF0aWNfbGVuYiA8PSBvcHRfbGVuYikgewogICAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iOwogICAgICAgICAgfQogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBvcHRfbGVuYiA9IHN0YXRpY19sZW5iID0gc3RvcmVkX2xlbiArIDU7CiAgICAgICAgfQogICAgICAgIGlmIChzdG9yZWRfbGVuICsgNCA8PSBvcHRfbGVuYiAmJiBidWYgIT09IC0xKSB7CiAgICAgICAgICBfdHJfc3RvcmVkX2Jsb2NrKHMsIGJ1Ziwgc3RvcmVkX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WxlIChsZW4gIT09IDApIHsKICAgICAgICAgIG4gPSBsZW4gPiAyZTMgPyAyZTMgOiBsZW47CiAgICAgICAgICBsZW4gLT0gbjsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgczEgPSBzMSArIGJ1Zltwb3MrK10gfCAwOwogICAgICAgICAgICBzMiA9IHMyICsgczEgfCAwOwogICAgICAgICAgfSB3aGlsZSAoLS1uKTsKICAgICAgICAgIHMxICU9IDY1NTIxOwogICAgICAgICAgczIgJT0gNjU1MjE7CiAgICAgICAgfQogICAgICAgIHJldHVybiBzMSB8IHMyIDw8IDE2IHwgMDsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBhZGxlcjMyOwogICAgfQogIH0pOwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvY3JjMzIuanMKICB2YXIgcmVxdWlyZV9jcmMzMiA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9jcmMzMi5qcyIoZXhwb3J0czIsIG1vZHVsZTIpIHsKICAgICAgaW5pdF9idWZmZXJfc2hpbSgpOwogICAgICAidXNlIHN0cmljdCI7CiAgICAgIGZ1bmN0aW9uIG1ha2VUYWJsZSgpIHsKICAgICAgICB2YXIgYywgdGFibGUgPSBbXTsKICAgICAgICBmb3IgKHZhciBuID0gMDsgbiA8IDI1NjsgbisrKSB7CiAgICAgICAgICBjID0gbjsKICAgICAgICAgIGZvciAodmFyIGsgPSAwOyBrIDwgODsgaysrKSB7CiAgICAgICAgICAgIGMgPSBjICYgMSA/IDM5ODgyOTIzODQgXiBjID4+PiAxIDogYyA+Pj4gMTsKICAgICAgICAgIH0KICAgICAgICAgIHRhYmxlW25dID0gYzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRhYmxlOwogICAgICB9CiAgICAgIHZhciBjcmNUYWJsZSA9IG1ha2VUYWJsZSgpOwogICAgICBmdW5jdGlvbiBjcmMzMihjcmMsIGJ1ZiwgbGVuLCBwb3MpIHsKICAgICAgICB2YXIgdCA9IGNyY1RhYmxlLCBlbmQgPSBwb3MgKyBsZW47CiAgICAgICAgY3JjIF49IC0xOwogICAgICAgIGZvciAodmFyIGkgPSBwb3M7IGkgPCBlbmQ7IGkrKykgewogICAgICAgICAgY3JjID0gY3JjID4+PiA4IF4gdFsoY3JjIF4gYnVmW2ldKSAmIDI1NV07CiAgICAgICAgfQogICAgICAgIHJldHVybiBjcmMgXiAtMTsKICAgICAgfQogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBjcmMzMjsKICAgIH0KICB9KTsKCiAgLy8gbm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL21lc3NhZ2VzLmpzCiAgdmFyIHJlcXVpcmVfbWVzc2FnZXMgPSBfX2NvbW1vbkpTKHsKICAgICJub2RlX21vZHVsZXMvLnBucG0vcGFrb0AxLjAuMTEvbm9kZV9tb2R1bGVzL3Bha28vbGliL3psaWIvbWVzc2FnZXMuanMiKGV4cG9ydHMyLCBtb2R1bGUyKSB7CiAgICAgIGluaXRfYnVmZmVyX3NoaW0oKTsKICAgICAgInVzZSBzdHJpY3QiOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSB7CiAgICAgICAgMjogIm5lZWQgZGljdGlvbmFyeSIsCiAgICAgICAgMTogInN0cmVhbSBlbmQiLAogICAgICAgIDA6ICIiLAogICAgICAgICItMSI6ICJmaWxlIGVycm9yIiwKICAgICAgICAiLTIiOiAic3RyZWFtIGVycm9yIiwKICAgICAgICAiLTMiOiAiZGF0YSBlcnJvciIsCiAgICAgICAgIi00IjogImluc3VmZmljaWVudCBtZW1vcnkiLAogICAgICAgICItNSI6ICJidWZmZXIgZXJyb3IiLAogICAgICAgICItNiI6ICJpbmNvbXBhdG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7CiAgICAgIHZhciBCU19GSU5JU0hfRE9ORSA9IDQ7CiAgICAgIHZhciBPU19DT0RFID0gMzsKICAgICAgZnVuY3Rpb24gZXJyKHN0cm0sIGVycm9yQ29kZSkgewogICAgICAgIHN0cm0ubXNnID0gbXNnW2Vycm9yQ29kZV07CiAgICAgICAgcmV0dXJuIGVycm9yQ29kZTsKICAgICAgfQogICAgICBmdW5jdGlvbiByYW5rKGYpIHsKICAgICAgICByZXR1cm4gKGYgPDwgMSkgLSAoZiA+IDQgPyA5IDogMCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gemVybyhidWYpIHsKICAgICAgICB2YXIgbGVuID0gYnVmLmxlbmd0aDsKICAgICAgICB3aGlsZSAoLS1sZW4gPj0gMCkgewogICAgICAgICAgYnVmW2xlbl0gPSAwOwogICAgICAgIH0KICAgICAgfQogICAgICBmdW5jdGlvbiBmbHVzaF9wZW5kaW5nKHN0cm0pIHsKICAgICAgICB2YXIgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgdmFyIGxlbiA9IHMucGVuZGluZzsKICAgICAgICBpZiAobGVuID4gc3RybS5hdmFpbF9vdXQpIHsKICAgICAgICAgIGxlbiA9IHN0cm0uYXZhaWxfb3V0OwogICAgICAgIH0KICAgICAgICBpZiAobGVuID09PSAwKSB7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQogICAgICAgIHV0aWxzLmFycmF5U2V0KHN0cm0ub3V0cHV0LCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmdfb3V0LCBsZW4sIHN0cm0ubmV4dF9vdXQpOwogICAgICAgIHN0cm0ubmV4dF9vdXQgKz0gbGVuOwogICAgICAgIHMucGVuZGluZ19vdXQgKz0gbGVuOwogICAgICAgIHN0cm0udG90YWxfb3V0ICs9IGxlbjsKICAgICAgICBzdHJtLmF2YWlsX291dCAtPSBsZW47CiAgICAgICAgcy5wZW5kaW5nIC09IGxlbjsKICAgICAgICBpZiAocy5wZW5kaW5nID09PSAwKSB7Ci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gICBzdHJtLmFkbGVyID0gYWRsZXIzMihzdHJtLmFkbGVyLCBidWYsIGxlbiwgc3RhcnQpOwogICAgICAgIH0gZWxzZSBpZiAoc3RybS5zdGF0ZS53cmFwID09PSAyKSB7CiAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgYnVmLCBsZW4sIHN0YXJ0KTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luICs9IGxlbjsKICAgICAgICBzdHJtLnRvdGFsX2luICs9IGxlbjsKICAgICAgICByZXR1cm4gbGVuOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGxvbmdlc3RfbWF0Y2gocywgY3VyX21hdGNoKSB7CiAgICAgICAgdmFyIGNoYWluX2xlbmd0aCA9IHMubWF4X2NoYWluX2xlbmd0aDsKICAgICAgICB2YXIgc2NhbiA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgdmFyIG1hdGNoOwogICAgICAgIHZhciBsZW47CiAgICAgICAgdmFyIGJlc3RfbGVuID0gcy5wcmV2X2xlbmd0aDsKICAgICAgICB2YXIgbmljZV9tYXRjaCA9IHMubmljZV9tYXRjaDsKICAgICAgICB2YXIgbGltaXQgPSBzLnN0cnN0YXJ0ID4gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEID8gcy5zdHJzdGFydCAtIChzLndfc2l6ZSAtIE1JTl9MT09LQUhFQUQpIDogMDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIHZhciB3bWFzayA9IHMud19tYXNrOwogICAgICAgIHZhciBwcmV2ID0gcy5wcmV2OwogICAgICAgIHZhciBzdHJlbmQgPSBzLnN0cnN0YXJ0ICsgTUFYX01BVENIOwogICAgICAgIHZhciBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgIHZhciBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICBpZiAocy5wcmV2X2xlbmd0aCA+PSBzLmdvb2RfbWF0Y2gpIHsKICAgICAgICAgIGNoYWluX2xlbmd0aCA+Pj0gMjsKICAgICAgICB9CiAgICAgICAgaWYgKG5pY2VfbWF0Y2ggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgbmljZV9tYXRjaCA9IHMubG9va2FoZWFkOwogICAgICAgIH0KICAgICAgICBkbyB7CiAgICAgICAgICBtYXRjaCA9IGN1cl9tYXRjaDsKICAgICAgICAgIGlmIChfd2luW21hdGNoICsgYmVzdF9sZW5dICE9PSBzY2FuX2VuZCB8fCBfd2luW21hdGNoICsgYmVzdF9sZW4gLSAxXSAhPT0gc2Nhbl9lbmQxIHx8IF93aW5bbWF0Y2hdICE9PSBfd2luW3NjYW5dIHx8IF93aW5bKyttYXRjaF0gIT09IF93aW5bc2NhbiArIDFdKSB7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgc2NhbiArPSAyOwogICAgICAgICAgbWF0Y2grKzsKICAgICAgICAgIGRvIHsKICAgICAgICAgIH0gd2hpbGUgKF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgX3dpblsrK3NjYW5dID09PSBfd2luWysrbWF0Y2hdICYmIF93aW5bKytzY2FuXSA9PT0gX3dpblsrK21hdGNoXSAmJiBfd2luWysrc2Nhbl0gPT09IF93aW5bKyttYXRjaF0gJiYgc2NhbiA8IHN0cmVuZCk7CiAgICAgICAgICBsZW4gPSBNQVhfTUFUQ0ggLSAoc3RyZW5kIC0gc2Nhbik7CiAgICAgICAgICBzY2FuID0gc3RyZW5kIC0gTUFYX01BVENIOwogICAgICAgICAgaWYgKGxlbiA+IGJlc3RfbGVuKSB7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgPSBjdXJfbWF0Y2g7CiAgICAgICAgICAgIGJlc3RfbGVuID0gbGVuOwogICAgICAgICAgICBpZiAobGVuID49IG5pY2VfbWF0Y2gpIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBzY2FuX2VuZDEgPSBfd2luW3NjYW4gKyBiZXN0X2xlbiAtIDFdOwogICAgICAgICAgICBzY2FuX2VuZCA9IF93aW5bc2NhbiArIGJlc3RfbGVuXTsKICAgICAgICAgIH0KICAgICAgICB9IHdoaWxlICgoY3VyX21hdGNoID0gcHJldltjdXJfbWF0Y2ggJiB3bWFza10pID4gbGltaXQgJiYgLS1jaGFpbl9sZW5ndGggIT09IDApOwogICAgICAgIGlmIChiZXN0X2xlbiA8PSBzLmxvb2thaGVhZCkgewogICAgICAgICAgcmV0dXJuIGJlc3RfbGVuOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcy5sb29rYWhlYWQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZmlsbF93aW5kb3cocykgewogICAgICAgIHZhciBfd19zaXplID0gcy53X3NpemU7CiAgICAgICAgdmFyIHAsIG4sIG0sIG1vcmUsIHN0cjsKICAgICAgICBkbyB7CiAgICAgICAgICBtb3JlID0gcy53aW5kb3dfc2l6ZSAtIHMubG9va2FoZWFkIC0gcy5zdHJzdGFydDsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID49IF93X3NpemUgKyAoX3dfc2l6ZSAtIE1JTl9MT09LQUhFQUQpKSB7CiAgICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHMud2luZG93LCBzLndpbmRvdywgX3dfc2l6ZSwgX3dfc2l6ZSwgMCk7CiAgICAgICAgICAgIHMubWF0Y2hfc3RhcnQgLT0gX3dfc2l6ZTsKICAgICAgICAgICAgcy5zdHJzdGFydCAtPSBfd19zaXplOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0IC09IF93X3NpemU7CiAgICAgICAgICAgIG4gPSBzLmhhc2hfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5oZWFkWy0tcF07CiAgICAgICAgICAgICAgcy5oZWFkW3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBuID0gX3dfc2l6ZTsKICAgICAgICAgICAgcCA9IG47CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBtID0gcy5wcmV2Wy0tcF07CiAgICAgICAgICAgICAgcy5wcmV2W3BdID0gbSA+PSBfd19zaXplID8gbSAtIF93X3NpemUgOiAwOwogICAgICAgICAgICB9IHdoaWxlICgtLW4pOwogICAgICAgICAgICBtb3JlICs9IF93X3NpemU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX2luID09PSAwKSB7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgbiA9IHJlYWRfYnVmKHMuc3RybSwgcy53aW5kb3csIHMuc3Ryc3RhcnQgKyBzLmxvb2thaGVhZCwgbW9yZSk7CiAgICAgICAgICBzLmxvb2thaGVhZCArPSBuOwogICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQgLSBzLmluc2VydDsKICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3N0cl07CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgd2hpbGUgKHMuaW5zZXJ0KSB7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3N0ciArIE1JTl9NQVRDSCAtIDFdKSAmIHMuaGFzaF9tYXNrOwogICAgICAgICAgICAgIHMucHJldltzdHIgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICAgIHN0cisrOwogICAgICAgICAgICAgIHMuaW5zZXJ0LS07CiAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkICsgcy5pbnNlcnQgPCBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBzLnN0cm0uYXZhaWxfaW4gIT09IDApOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVfc3RvcmVkKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIG1heF9ibG9ja19zaXplID0gNjU1MzU7CiAgICAgICAgaWYgKG1heF9ibG9ja19zaXplID4gcy5wZW5kaW5nX2J1Zl9zaXplIC0gNSkgewogICAgICAgICAgbWF4X2Jsb2NrX3NpemUgPSBzLnBlbmRpbmdfYnVmX3NpemUgLSA1OwogICAgICAgIH0KICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA8PSAxKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDAgJiYgZmx1c2ggPT09IFpfTk9fRkxVU0gpIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBzLnN0cnN0YXJ0ICs9IHMubG9va2FoZWFkOwogICAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgICAgdmFyIG1heF9zdGFydCA9IHMuYmxvY2tfc3RhcnQgKyBtYXhfYmxvY2tfc2l6ZTsKICAgICAgICAgIGlmIChzLnN0cnN0YXJ0ID09PSAwIHx8IHMuc3Ryc3RhcnQgPj0gbWF4X3N0YXJ0KSB7CiAgICAgICAgICAgIHMubG9va2FoZWFkID0gcy5zdHJzdGFydCAtIG1heF9zdGFydDsKICAgICAgICAgICAgcy5zdHJzdGFydCA9IG1heF9zdGFydDsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMuc3Ryc3RhcnQgLSBzLmJsb2NrX3N0YXJ0ID49IHMud19zaXplIC0gTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdHJzdGFydCA+IHMuYmxvY2tfc3RhcnQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX2Zhc3QocywgZmx1c2gpIHsKICAgICAgICB2YXIgaGFzaF9oZWFkOwogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgZm9yICg7IDsgKSB7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPCBNSU5fTE9PS0FIRUFEICYmIGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPT09IDApIHsKICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaGFzaF9oZWFkID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgaGFzaF9oZWFkID0gcy5wcmV2W3Muc3Ryc3RhcnQgJiBzLndfbWFza10gPSBzLmhlYWRbcy5pbnNfaF07CiAgICAgICAgICAgIHMuaGVhZFtzLmluc19oXSA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoaGFzaF9oZWFkICE9PSAwICYmIHMuc3Ryc3RhcnQgLSBoYXNoX2hlYWQgPD0gcy53X3NpemUgLSBNSU5fTE9PS0FIRUFEKSB7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gbG9uZ2VzdF9tYXRjaChzLCBoYXNoX2hlYWQpOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHMubWF0Y2hfbGVuZ3RoID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICBiZmx1c2ggPSB0cmVlcy5fdHJfdGFsbHkocywgcy5zdHJzdGFydCAtIHMubWF0Y2hfc3RhcnQsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA8PSBzLm1heF9sYXp5X21hdGNoICYmIHMubG9va2FoZWFkID49IE1JTl9NQVRDSCkgewogICAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoLS07CiAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgcy5zdHJzdGFydCsrOwogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9IHdoaWxlICgtLXMubWF0Y2hfbGVuZ3RoICE9PSAwKTsKICAgICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcy5zdHJzdGFydCArPSBzLm1hdGNoX2xlbmd0aDsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IDA7CiAgICAgICAgICAgICAgcy5pbnNfaCA9IHMud2luZG93W3Muc3Ryc3RhcnRdOwogICAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IHMuc3Ryc3RhcnQgPCBNSU5fTUFUQ0ggLSAxID8gcy5zdHJzdGFydCA6IE1JTl9NQVRDSCAtIDE7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9zbG93KHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGhhc2hfaGVhZDsKICAgICAgICB2YXIgYmZsdXNoOwogICAgICAgIHZhciBtYXhfaW5zZXJ0OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDwgTUlOX0xPT0tBSEVBRCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGhhc2hfaGVhZCA9IDA7CiAgICAgICAgICBpZiAocy5sb29rYWhlYWQgPj0gTUlOX01BVENIKSB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzLnN0cnN0YXJ0ICsgTUlOX01BVENIIC0gMV0pICYgcy5oYXNoX21hc2s7CiAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICBzLmhlYWRbcy5pbnNfaF0gPSBzLnN0cnN0YXJ0OwogICAgICAgICAg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0gMjsKICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgIGlmICgrK3Muc3Ryc3RhcnQgPD0gbWF4X2luc2VydCkgewogICAgICAgICAgICAgICAgcy5pbnNfaCA9IChzLmluc19oIDw8IHMuaGFzaF9zaGlmdCBeIHMud2luZG93W3Muc3Ryc3RhcnQgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgICAgIGhhc2hfaGVhZCA9IHMucHJldltzLnN0cnN0YXJ0ICYgcy53X21hc2tdID0gcy5oZWFkW3MuaW5zX2hdOwogICAgICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gcy5zdHJzdGFydDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gd2hpbGUgKC0tcy5wcmV2X2xlbmd0aCAhPT0gMCk7CiAgICAgICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAocy5tYXRjaF9hdmFpbGFibGUpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcy5tYXRjaF9hdmFpbGFibGUgPSAxOwogICAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLm1hdGNoX2F2YWlsYWJsZSkgewogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnQgLSAxXSk7CiAgICAgICAgICBzLm1hdGNoX2F2YWlsYWJsZSA9IDA7CiAgICAgICAgfQogICAgICAgIHMuaW5zZXJ0ID0gcy5zdHJzdGFydCA8IE1JTl9NQVRDSCAtIDEgPyBzLnN0cnN0YXJ0IDogTUlOX01BVENIIC0gMTsKICAgICAgICBpZiAoZmx1c2ggPT09IFpfRklOSVNIKSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIHRydWUpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9TVEFSVEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIEJTX0ZJTklTSF9ET05FOwogICAgICAgIH0KICAgICAgICBpZiAocy5sYXN0X2xpdCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gQlNfQkxPQ0tfRE9ORTsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlX3JsZShzLCBmbHVzaCkgewogICAgICAgIHZhciBiZmx1c2g7CiAgICAgICAgdmFyIHByZXY7CiAgICAgICAgdmFyIHNjYW4sIHN0cmVuZDsKICAgICAgICB2YXIgX3dpbiA9IHMud2luZG93OwogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkIDw9IE1BWF9NQVRDSCAmJiBmbHVzaCA9PT0gWl9OT19GTFVTSCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0ggJiYgcy5zdHJzdGFydCA+IDApIHsKICAgICAgICAgICAgc2NhbiA9IHMuc3Ryc3RhcnQgLSAxOwogICAgICAgICAgICBwcmV2ID0gX3dpbltzY2FuXTsKICAgICAgICAgICAgaWYgKHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dKSB7CiAgICAgICAgICAgICAgc3RyZW5kID0gcy5zdHJzdGFydCArIE1BWF9NQVRDSDsKICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgfSB3aGlsZSAocHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBwcmV2ID09PSBfd2luWysrc2Nhbl0gJiYgcHJldiA9PT0gX3dpblsrK3NjYW5dICYmIHByZXYgPT09IF93aW5bKytzY2FuXSAmJiBzY2FuIDwgc3RyZW5kKTsKICAgICAgICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IE1BWF9NQVRDSCAtIChzdHJlbmQgLSBzY2FuKTsKICAgICAgICAgICAgICBpZiAocy5tYXRjaF9sZW5ndGggPiBzLmxvb2thaGVhZCkgewogICAgICAgICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSBzLmxvb2thaGVhZDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzLm1hdGNoX2xlbmd0aCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDEsIHMubWF0Y2hfbGVuZ3RoIC0gTUlOX01BVENIKTsKICAgICAgICAgICAgcy5sb29rYWhlYWQgLT0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgKz0gcy5tYXRjaF9sZW5ndGg7CiAgICAgICAgICAgIHMubWF0Y2hfbGVuZ3RoID0gMDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGJmbHVzaCA9IHRyZWVzLl90cl90YWxseShzLCAwLCBzLndpbmRvd1tzLnN0cnN0YXJ0XSk7CiAgICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICAgIHMuc3Ryc3RhcnQrKzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChiZmx1c2gpIHsKICAgICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCBmYWxzZSk7CiAgICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBzLmluc2VydCA9IDA7CiAgICAgICAgaWYgKGZsdXNoID09PSBaX0ZJTklTSCkgewogICAgICAgICAgZmx1c2hfYmxvY2tfb25seShzLCB0cnVlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfU1RBUlRFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBCU19GSU5JU0hfRE9ORTsKICAgICAgICB9CiAgICAgICAgaWYgKHMubGFzdF9saXQpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgaWYgKHMuc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgcmV0dXJuIEJTX05FRURfTU9SRTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIEJTX0JMT0NLX0RPTkU7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSB7CiAgICAgICAgdmFyIGJmbHVzaDsKICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgIGlmIChzLmxvb2thaGVhZCA9PT0gMCkgewogICAgICAgICAgICBmaWxsX3dpbmRvdyhzKTsKICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX05PX0ZMVVNIKSB7CiAgICAgICAgICAgICAgICByZXR1cm4gQlNfTkVFRF9NT1JFOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcy5tYXRjaF9sZW5ndGggPSAwOwogICAgICAgICAgYmZsdXNoID0gdHJlZXMuX3RyX3RhbGx5KHMsIDAsIHMud2luZG93W3Muc3Ryc3RhcnRdKTsKICAgICAgICAgIHMubG9va2FoZWFkLS07CiAgICAgICAgICBzLnN0cnN0YXJ0Kys7CiAgICAgICAgICBpZiAoYmZsdXNoKSB7CiAgICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgZmFsc2UpOwogICAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgIGlmIChmbHVzaCA9PT0gWl9GSU5JU0gpIHsKICAgICAgICAgIGZsdXNoX2Jsb2NrX29ubHkocywgdHJ1ZSk7CiAgICAgICAgICBpZiAocy5zdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX1NUQVJURUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gQlNfRklOSVNIX0RPTkU7CiAgICAgICAgfQogICAgICAgIGlmIChzLmxhc3RfbGl0KSB7CiAgICAgICAgICBmbHVzaF9ibG9ja19vbmx5KHMsIGZhbHNlKTsKICAgICAgICAgIGlmIChzLnN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHJldHVybiBCU19ORUVEX01PUkU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiBCU19CTE9DS19ET05FOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIENvbmZpZyhnb29kX2xlbmd0aCwgbWF4X2xhenksIG5pY2VfbGVuZ3RoLCBtYXhfY2hhaW4sIGZ1bmMpIHsKICAgICAgICB0aGlzLmdvb2RfbGVuZ3RoID0gZ29vZF9sZW5ndGg7CiAgICAgICAgdGhpcy5tYXhfbGF6eSA9IG1heF9sYXp5OwogICAgICAgIHRoaXMubmljZV9sZW5ndGggPSBuaWNlX2xlbmd0aDsKICAgICAgICB0aGlzLm1heF9jaGFpbiA9IG1heF9jaGFpbjsKICAgICAgICB0aGlzLmZ1bmMgPSB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25fdGFibGVbcy5sZXZlbF0ubmljZV9sZW5ndGg7CiAgICAgICAgcy5tYXhfY2hhaW5fbGVuZ3RoID0gY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5tYXhfY2hhaW47CiAgICAgICAgcy5zdHJzdGFydCA9IDA7CiAgICAgICAgcy5ibG9ja19zdGFydCA9IDA7CiAgICAgICAgcy5sb29rYWhlYWQgPSAwOwogICAgICAgIHMuaW5zZXJ0ID0gMDsKICAgICAgICBzLm1hdGNoX2xlbmd0aCA9IHMucHJldl9sZW5ndGggPSBNSU5fTUFUQ0ggLSAxOwogICAgICAgIHMubWF0Y2hfYXZhaWxhYmxlID0gMDsKICAgICAgICBzLmluc19oID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBEZWZsYXRlU3RhdGUoKSB7CiAgICAgICAgdGhpcy5zdHJtID0gbnVsbDsKICAgICAgICB0aGlzLnN0YXR1cyA9IDA7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1ZiA9IG51bGw7CiAgICAgICAgdGhpcy5wZW5kaW5nX2J1Zl9zaXplID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICB0aGlzLnBlbmRpbmcgPSAwOwogICAgICAgIHRoaXMud3JhcCA9IDA7CiAgICAgICAgdGhpcy5nemhlYWQgPSBudWxsOwogICAgICAgIHRoaXMuZ3ppbmRleCA9IDA7CiAgICAgICAgdGhpcy5tZXRob2QgPSBaX0RFRkxBVEVEOwogICAgICAgIHRoaXMubGFzdF9mbHVzaCA9IC0xOwogICAgICAgIHRoaXMud19zaXplID0gMDsKICAgICAgICB0aGlzLndfYml0cyA9IDA7CiAgICAgICAgdGhpcy53X21hc2sgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLndpbmRvd19zaXplID0gMDsKICAgICAgICB0aGlzLnByZXYgPSBudWxsOwogICAgICAgIHRoaXMuaGVhZCA9IG51bGw7CiAgICAgICAgdG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51bGw7CiAgICAgICAgdGhpcy5kX2Rlc2MgPSBudWxsOwogICAgICAgIHRoaXMuYmxfZGVzYyA9IG51bGw7CiAgICAgICAgdGhpcy5ibF9jb3VudCA9IG5ldyB1dGlscy5CdWYxNihNQVhfQklUUyArIDEpOwogICAgICAgIHRoaXMuaGVhcCA9IG5ldyB1dGlscy5CdWYxNigyICogTF9DT0RFUyArIDEpOwogICAgICAgIHplcm8odGhpcy5oZWFwKTsKICAgICAgICB0aGlzLmhlYXBfbGVuID0gMDsKICAgICAgICB0aGlzLmhlYXBfbWF4ID0gMDsKICAgICAgICB0aGlzLmRlcHRoID0gbmV3IHV0aWxzLkJ1ZjE2KDIgKiBMX0NPREVTICsgMSk7CiAgICAgICAgemVybyh0aGlzLmRlcHRoKTsKICAgICAgICB0aGlzLmxfYnVmID0gMDsKICAgICAgICB0aGlzLmxpdF9idWZzaXplID0gMDsKICAgICAgICB0aGlzLmxhc3RfbGl0ID0gMDsKICAgICAgICB0aGlzLmRfYnVmID0gMDsKICAgICAgICB0aGlzLm9wdF9sZW4gPSAwOwogICAgICAgIHRoaXMuc3RhdGljX2xlbiA9IDA7CiAgICAgICAgdGhpcy5tYXRjaGVzID0gMDsKICAgICAgICB0aGlzLmluc2VydCA9IDA7CiAgICAgICAgdGhpcy5iaV9idWYgPSAwOwogICAgICAgIHRoaXMuYmlfdmFsaWQgPSAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVSZXNldEtlZXAoc3RybSkgewogICAgICAgIHZhciBzOwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0udG90YWxfaW4gPSBzdHJtLnRvdGFsX291dCA9IDA7CiAgICAgICAgc3RybS5kYXRhX3R5cGUgPSBaX1VOS05PV047CiAgICAgICAgcyA9IHN0cm0uc3RhdGU7CiAgICAgICAgcy5wZW5kaW5nID0gMDsKICAgICAgICBzLnBlbmRpbmdfb3V0ID0gMDsKICAgICAgICBpZiAocy53cmFwIDwgMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcy5zdGF0dXMgPSBzLndyYXAgPyBJTklUX1NUQVRFIDogQlVTWV9TVEFURTsKICAgICAgICBzdHJtLmFkbGVyID0gcy53cmFwID09PSAyID8gMCA6IDE7CiAgICAgICAgcy5sYXN0X2ZsdXNoID0gWl9OT19GTFVTSDsKICAgICAgICB0cmVlcy5fdHJfaW5pdChzKTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciByZXQgPSBkZWZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICAgIGlmIChyZXQgPT09IFpfT0spIHsKICAgICAgICAgIGxtX2luaXQoc3RybS5zdGF0ZSk7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldEhlYWRlcihzdHJtLCBoZWFkKSB7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdHJtLnN0YXRlLndyYXAgIT09IDIpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RybS5zdGF0ZS5nemhlYWQgPSBoZWFkOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGRlZmxhdGVJbml0MihzdHJtLCBsZXZlbCwgbWV0aG9kLCB3aW5kb3dCaXRzLCBtZW1MZXZlbCwgc3RyYXRlZ3kpIHsKICAgICAgICBpZiAoIXN0cm0pIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgdmFyIHdyYXAgPSAxOwogICAgICAgIGlmIChsZXZlbCA9PT0gWl9ERUZBVUxUX0NPTVBSRVNTSU9OKSB7CiAgICAgICAgICBsZXZlbCA9IDY7CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmICh3aW5kb3dCaXRzID4gMTUpIHsKICAgICAgICAgIHdyYXAgPSAyOwogICAgICAgICAgd2luZG93Qml0cyAtPSAxNjsKICAgICAgICB9CiAgICAgICAgaWYgKG1lbUxldmVsIDwgMSB8fCBtZW1MZXZlbCA+IE1BWF9NRU1fTEVWRUwgfHwgbWV0aG9kICE9PSBaX0RFRkxBVEVEIHx8IHdpbmRvd0JpdHMgPCA4IHx8IHdpbmRvd0JpdHMgPiAxNSB8fCBsZXZlbCA8IDAgfHwgbGV2ZWwgPiA5IHx8IHN0cmF0ZWd5IDwgMCB8fCBzdHJhdGVneSA+IFpfRklYRUQpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAod2luZG93Qml0cyA9PT0gOCkgewogICAgICAgICAgd2luZG93Qml0cyA9IDk7CiAgICAgICAgfQogICAgICAgIHZhciBzID0gbmV3IERlZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzOwogICAgICAgIHMuc3RybSA9IHN0cm07CiAgICAgICAgcy53cmFwID0gd3JhcDsKICAgICAgICBzLmd6aGVhZCA9IG51bGw7CiAgICAgICAgcy53X2JpdHMgPSB3aW5kb3dCaXRzOwogICAgICAgIHMud19zaXplID0gMSA8PCBzLndfYml0czsKICAgICAgICBzLndfbWFzayA9IHMud19zaXplIC0gMTsKICAgICAgICBzLmhhc2hfYml0c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IGRlZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgb2xkX2ZsdXNoLCBzOwogICAgICAgIHZhciBiZWcsIHZhbDsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUgfHwgZmx1c2ggPiBaX0JMT0NLIHx8IGZsdXNoIDwgMCkgewogICAgICAgICAgcmV0dXJuIHN0cm0gPyBlcnIoc3RybSwgWl9TVFJFQU1fRVJST1IpIDogWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHMgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICghc3RybS5vdXRwdXQgfHwgIXN0cm0uaW5wdXQgJiYgc3RybS5hdmFpbF9pbiAhPT0gMCB8fCBzLnN0YXR1cyA9PT0gRklOSVNIX1NUQVRFICYmIGZsdXNoICE9PSBaX0ZJTklTSCkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBzdHJtLmF2YWlsX291dCA9PT0gMCA/IFpfQlVGX0VSUk9SIDogWl9TVFJFQU1fRVJST1IpOwogICAgICAgIH0KICAgICAgICBzLnN0cm0gPSBzdHJtOwogICAgICAgIG9sZF9mbHVzaCA9IHMubGFzdF9mbHVzaDsKICAgICAgICBzLmxhc3RfZmx1c2ggPSBmbHVzaDsKICAgICAgICBpZiAocy5zdGF0dXMgPT09IElOSVRfU1RBVEUpIHsKICAgICAgICAgIGlmIChzLndyYXAgPT09IDIpIHsKICAgICAgICAgICAgc3RybS5hZGxlciA9IDA7CiAgICAgICAgICAgIHB1dF9ieXRlKHMsIDMxKTsKICAgICAgICAgICAgcHV0X2J5dGUocywgMTM5KTsKICAgICAgICAgICAgcHV0X2J5dGUocywgOCk7CiAgICAgICAgICAgIGlmICghcy5nemhlYWQpIHsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCAwKTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgT1NfQ09ERSk7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHB1dF9ieXRlKHMsIChzLmd6aGVhZC50ZXh0ID8gMSA6IDApICsgKHMuZ3poZWFkLmhjcmMgPyAyIDogMCkgKyAoIXMuZ3poZWFkLmV4dHJhID8gMCA6IDQpICsgKCFzLmd6aGVhZC5uYW1lID8gMCA6IDgpICsgKCFzLmd6aGVhZC5jb21tZW50ID8gMCA6IDE2KSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQudGltZSA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDE2ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC50aW1lID4+IDI0ICYgMjU1KTsKICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmxldmVsID09PSA5ID8gMiA6IHMuc3RyYXRlZ3kgPj0gWl9IVUZGTUFOX09OTFkgfHwgcy5sZXZlbCA8IDIgPyA0IDogMCk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgcy5nemhlYWQub3MgJiAyNTUpOwogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5leHRyYSAmJiBzLmd6aGVhZC5leHRyYS5sZW5ndGgpIHsKICAgICAgICAgICAgICAgIHB1dF9ieXRlKHMsIHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDI1NSk7CiAgICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYS5sZW5ndGggPj4gOCAmIDI1NSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjKSB7CiAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nLCAwKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEVYVFJBX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB2YXIgaGVhZGVyID0gWl9ERUZMQVRFRCArIChzLndfYml0cyAtIDggPDwgNCkgPDwgODsKICAgICAgICAgICAgdmFyIGxldmVsX2ZsYWdzID0gLTE7CiAgICAgICAgICAgIGlmIChzLnN0cmF0ZWd5ID49IFpfSFVGRk1BTl9PTkxZIHx8IHMubGV2ZWwgPCAyKSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAwOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPCA2KSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAxOwogICAgICAgICAgICB9IGVsc2UgaWYgKHMubGV2ZWwgPT09IDYpIHsKICAgICAgICAgICAgICBsZXZlbF9mbGFncyA9IDI7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgbGV2ZWxfZmxhZ3MgPSAzOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGhlYWRlciB8PSBsZXZlbF9mbGFncyA8PCA2OwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIGhlYWRlciB8PSBQUkVTRVRfRElDVDsKICAgICAgICAgICAgfQogICAgICAgICAgICBoZWFkZXIgKz0gMzEgLSBoZWFkZXIgJSAzMTsKICAgICAgICAgICAgcy5zdGF0dXMgPSBCVVNZX1NUQVRFOwogICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBoZWFkZXIpOwogICAgICAgICAgICBpZiAocy5zdHJzdGFydCAhPT0gMCkgewogICAgICAgICAgICAgIHB1dFNob3J0TVNCKHMsIHN0cm0uYWRsZXIgPj4+IDE2KTsKICAgICAgICAgICAgICBwdXRTaG9ydE1TQihzLCBzdHJtLmFkbGVyICYgNjU1MzUpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHN0cm0uYWRsZXIgPSAxOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEVYVFJBX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuZXh0cmEpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICB3aGlsZSAocy5nemluZGV4IDwgKHMuZ3poZWFkLmV4dHJhLmxlbmd0aCAmIDY1NTM1KSkgewogICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgICAgIHN0cm0uYWRsZXIgPSBjcmMzMihzdHJtLmFkbGVyLCBzLnBlbmRpbmdfYnVmLCBzLnBlbmRpbmcgLSBiZWcsIGJlZyk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCBzLmd6aGVhZC5leHRyYVtzLmd6aW5kZXhdICYgMjU1KTsKICAgICAgICAgICAgICBzLmd6aW5kZXgrKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPT09IHMuZ3poZWFkLmV4dHJhLmxlbmd0aCkgewogICAgICAgICAgICAgIHMuZ3ppbmRleCA9IDA7CiAgICAgICAgICAgICAgcy5zdGF0dXMgPSBOQU1FX1NUQVRFOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzLnN0YXR1cyA9IE5BTUVfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChzLnN0YXR1cyA9PT0gTkFNRV9TVEFURSkgewogICAgICAgICAgaWYgKHMuZ3poZWFkLm5hbWUpIHsKICAgICAgICAgICAgYmVnID0gcy5wZW5kaW5nOwogICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgaWYgKHMucGVuZGluZyA9PT0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgICAgdmFsID0gMTsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzLmd6aW5kZXggPCBzLmd6aGVhZC5uYW1lLmxlbmd0aCkgewogICAgICAgICAgICAgICAgdmFsID0gcy5nemhlYWQubmFtZS5jaGFyQ29kZUF0KHMuZ3ppbmRleCsrKSAmIDI1NTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdmFsID0gMDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgdmFsKTsKICAgICAgICAgICAgfSB3aGlsZSAodmFsICE9PSAwKTsKICAgICAgICAgICAgaWYgKHMuZ3poZWFkLmhjcmMgJiYgcy5wZW5kaW5nID4gYmVnKSB7CiAgICAgICAgICAgICAgc3RybS5hZGxlciA9IGNyYzMyKHN0cm0uYWRsZXIsIHMucGVuZGluZ19idWYsIHMucGVuZGluZyAtIGJlZywgYmVnKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAodmFsID09PSAwKSB7CiAgICAgICAgICAgICAgcy5nemluZGV4ID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IENPTU1FTlRfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQ09NTUVOVF9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBDT01NRU5UX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuY29tbWVudCkgewogICAgICAgICAgICBiZWcgPSBzLnBlbmRpbmc7CiAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICBpZiAocy5wZW5kaW5nID09PSBzLnBlbmRpbmdfYnVmX3NpemUpIHsKICAgICAgICAgICAgICAgIGlmIChzLmd6aGVhZC5oY3JjICYmIHMucGVuZGluZyA+IGJlZykgewogICAgICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgICAgICAgIGJlZyA9IHMucGVuZGluZzsKICAgICAgICAgICAgICAgIGlmIChzLnBlbmRpbmcgPT09IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgICAgICB2YWwgPSAxOwogICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMuZ3ppbmRleCA8IHMuZ3poZWFkLmNvbW1lbnQubGVuZ3RoKSB7CiAgICAgICAgICAgICAgICB2YWwgPSBzLmd6aGVhZC5jb21tZW50LmNoYXJDb2RlQXQocy5nemluZGV4KyspICYgMjU1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB2YWwgPSAwOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBwdXRfYnl0ZShzLCB2YWwpOwogICAgICAgICAgICB9IHdoaWxlICh2YWwgIT09IDApOwogICAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYyAmJiBzLnBlbmRpbmcgPiBiZWcpIHsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gY3JjMzIoc3RybS5hZGxlciwgcy5wZW5kaW5nX2J1Ziwgcy5wZW5kaW5nIC0gYmVnLCBiZWcpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmICh2YWwgPT09IDApIHsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEhDUkNfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gSENSQ19TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMuc3RhdHVzID09PSBIQ1JDX1NUQVRFKSB7CiAgICAgICAgICBpZiAocy5nemhlYWQuaGNyYykgewogICAgICAgICAgICBpZiAocy5wZW5kaW5nICsgMiA+IHMucGVuZGluZ19idWZfc2l6ZSkgewogICAgICAgICAgICAgIGZsdXNoX3BlbmRpbmcoc3RybSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMucGVuZGluZyArIDIgPD0gcy5wZW5kaW5nX2J1Zl9zaXplKSB7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciAmIDI1NSk7CiAgICAgICAgICAgICAgcHV0X2J5dGUocywgc3RybS5hZGxlciA+PiA4ICYgMjU1KTsKICAgICAgICAgICAgICBzdHJtLmFkbGVyID0gMDsKICAgICAgICAgICAgICBzLnN0YXR1cyA9IEJVU1lfU1RBVEU7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMuc3RhdHVzID0gQlVTWV9TVEFURTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHMucGVuZGluZyAhPT0gMCkgewogICAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgcmV0dXJuIFpfT0s7CiAgICAgICAgICB9CiAgICAgICAgfSBlbHNlIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHJhbmsoZmx1c2gpIDw9IHJhbmsob2xkX2ZsdXNoKSAmJiBmbHVzaCAhPT0gWl9GSU5JU0gpIHsKICAgICAgICAgIHJldHVybiBlcnIoc3RybSwgWl9CVUZfRVJST1IpOwogICAgICAgIH0KICAgICAgICBpZiAocy5zdGF0dXMgPT09IEZJTklTSF9TVEFURSAmJiBzdHJtLmF2YWlsX2luICE9PSAwKSB7CiAgICAgICAgICByZXR1cm4gZXJyKHN0cm0sIFpfQlVGX0VSUk9SKTsKICAgICAgICB9CiAgICAgICAgaWYgKHN0cm0uYXZhaWxfaW4gIT09IDAgfHwgcy5sb29rYWhlYWQgIT09IDAgfHwgZmx1c2ggIT09IFpfTk9fRkxVU0ggJiYgcy5zdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgdmFyIGJzdGF0ZSA9IHMuc3RyYXRlZ3kgPT09IFpfSFVGRk1BTl9PTkxZID8gZGVmbGF0ZV9odWZmKHMsIGZsdXNoKSA6IHMuc3RyYXRlZ3kgPT09IFpfUkxFID8gZGVmbGF0ZV9ybGUocywgZmx1c2gpIDogY29uZmlndXJhdGlvbl90YWJsZVtzLmxldmVsXS5mdW5jKHMsIGZsdXNoKTsKICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0ZJTklTSF9TVEFSVEVEIHx8IGJzdGF0ZSA9PT0gQlNfRklOSVNIX0RPTkUpIHsKICAgICAgICAgICAgcy5zdGF0dXMgPSBGSU5JU0hfU1RBVEU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYnN0YXRlID09PSBCU19ORUVEX01PUkUgfHwgYnN0YXRlID09PSBCU19GSU5JU0hfU1RBUlRFRCkgewogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgfQogICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChic3RhdGUgPT09IEJTX0JMT0NLX0RPTkUpIHsKICAgICAgICAgICAgaWYgKGZsdXNoID09PSBaX1BBUlRJQUxfRkxVU0gpIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfYWxpZ24ocyk7CiAgICAgICAgICAgIH0gZWxzZSBpZiAoZmx1c2ggIT09IFpfQkxPQ0spIHsKICAgICAgICAgICAgICB0cmVlcy5fdHJfc3RvcmVkX2Jsb2NrKHMsIDAsIDAsIGZhbHNlKTsKICAgICAgICAgICAgICBpZiAoZmx1c2ggPT09IFpfRlVMTF9GTFVTSCkgewogICAgICAgICAgICAgICAgemVybyhzLmhlYWQpOwogICAgICAgICAgICAgICAgaWYgKHMubG9va2FoZWFkID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBmbHVzaF9wZW5kaW5nKHN0cm0pOwogICAgICAgICAgICBpZiAoc3RybS5hdmFpbF9vdXQgPT09IDApIHsKICAgICAgICAgICAgICBzLmxhc3RfZmx1c2ggPSAtMTsKICAgICAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAoZmx1c2ggIT09IFpfRklOSVNIKSB7CiAgICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKHMud3JhcCA8PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRU5EOwogICAgICAgIH0KICAgICAgICBpZiAocy53cmFwID09PSAyKSB7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gOCAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLmFkbGVyID4+IDE2ICYgMjU1KTsKICAgICAgICAgIHB1dF9ieXRlKHMsIHN0cm0uYWRsZXIgPj4gMjQgJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDggJiAyNTUpOwogICAgICAgICAgcHV0X2J5dGUocywgc3RybS50b3RhbF9pbiA+PiAxNiAmIDI1NSk7CiAgICAgICAgICBwdXRfYnl0ZShzLCBzdHJtLnRvdGFsX2luID4+IDI0ICYgMjU1KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciA+Pj4gMTYpOwogICAgICAgICAgcHV0U2hvcnRNU0Iocywgc3RybS5hZGxlciAmIDY1NTM1KTsKICAgICAgICB9CiAgICAgICAgZmx1c2hfcGVuZGluZyhzdHJtKTsKICAgICAgICBpZiAocy53cmFwID4gMCkgewogICAgICAgICAgcy53cmFwID0gLXMud3JhcDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHMucGVuZGluZyAhPT0gMCA/IFpfT0sgOiBaX1NUUkVBTV9FTkQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZUVuZChzdHJtKSB7CiAgICAgICAgdmFyIHN0YXR1czsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdHVzID0gc3RybS5zdGF0ZS5zdGF0dXM7CiAgICAgICAgaWYgKHN0YXR1cyAhPT0gSU5JVF9TVEFURSAmJiBzdGF0dXMgIT09IEVYVFJBX1NUQVRFICYmIHN0YXR1cyAhPT0gTkFNRV9TVEFURSAmJiBzdGF0dXMgIT09IENPTU1FTlRfU1RBVEUgJiYgc3RhdHVzICE9PSBIQ1JDX1NUQVRFICYmIHN0YXR1cyAhPT0gQlVTWV9TVEFURSAmJiBzdGF0dXMgIT09IEZJTklTSF9TVEFURSkgewogICAgICAgICAgcmV0dXJuIGVycihzdHJtLCBaX1NUUkVBTV9FUlJPUik7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBzdGF0dXMgPT09IEJVU1lfU1RBVEUgPyBlcnIoc3RybSwgWl9EQVRBX0VSUk9SKSA6IFpfT0s7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gZGVmbGF0ZVNldERpY3Rpb25hcnkoc3RybSwgZGljdGlvbmFyeSkgewogICAgICAgIHZhciBkaWN0TGVuZ3RoID0gZGljdGlvbmFyeS5sZW5ndGg7CiAgICAgICAgdmFyIHM7CiAgICAgICAgdmFyIHN0ciwgbjsKICAgICAgICB2YXIgd3JhcDsKICAgICAgICB2YXIgYXZhaWw7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIGlucHV0OwogICAgICAgIHZhciB0bXBEaWN0OwogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICBzID0gc3RybS5zdGF0ZTsKICAgICAgICB3cmFwID0gcy53cmFwOwogICAgICAgIGlmICh3cmFwID09PSAyIHx8IHdyYXAgPT09IDEgJiYgcy5zdGF0dXMgIT09IElOSVRfU1RBVEUgfHwgcy5sb29rYWhlYWQpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgaWYgKHdyYXAgPT09IDEpIHsKICAgICAgICAgIHN0cm0uYWRsZXIgPSBhZGxlcjMyKHN0cm0uYWRsZXIsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgIH0KICAgICAgICBzLndyYXAgPSAwOwogICAgICAgIGlmIChkaWN0TGVuZ3RoID49IHMud19zaXplKSB7CiAgICAgICAgICBpZiAod3JhcCA9PT0gMCkgewogICAgICAgICAgICB6ZXJvKHMuaGVhZCk7CiAgICAgICAgICAgIHMuc3Ryc3RhcnQgPSAwOwogICAgICAgICAgICBzLmJsb2NrX3N0YXJ0ID0gMDsKICAgICAgICAgICAgcy5pbnNlcnQgPSAwOwogICAgICAgICAgfQogICAgICAgICAgdG1wRGljdCA9IG5ldyB1dGlscy5CdWY4KHMud19zaXplKTsKICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHRtcERpY3QsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGggLSBzLndfc2l6ZSwgcy53X3NpemUsIDApOwogICAgICAgICAgZGljdGlvbmFyeSA9IHRtcERpY3Q7CiAgICAgICAgICBkaWN0TGVuZ3RoID0gcy53X3NpemU7CiAgICAgICAgfQogICAgICAgIGF2YWlsID0gc3RybS5hdmFpbF9pbjsKICAgICAgICBuZXh0ID0gc3RybS5uZXh0X2luOwogICAgICAgIGlucHV0ID0gc3RybS5pbnB1dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gZGljdExlbmd0aDsKICAgICAgICBzdHJtLm5leHRfaW4gPSAwOwogICAgICAgIHN0cm0uaW5wdXQgPSBkaWN0aW9uYXJ5OwogICAgICAgIGZpbGxfd2luZG93KHMpOwogICAgICAgIHdoaWxlIChzLmxvb2thaGVhZCA+PSBNSU5fTUFUQ0gpIHsKICAgICAgICAgIHN0ciA9IHMuc3Ryc3RhcnQ7CiAgICAgICAgICBuID0gcy5sb29rYWhlYWQgLSAoTUlOX01BVENIIC0gMSk7CiAgICAgICAgICBkbyB7CiAgICAgICAgICAgIHMuaW5zX2ggPSAocy5pbnNfaCA8PCBzLmhhc2hfc2hpZnQgXiBzLndpbmRvd1tzdHIgKyBNSU5fTUFUQ0ggLSAxXSkgJiBzLmhhc2hfbWFzazsKICAgICAgICAgICAgcy5wcmV2W3N0ciAmIHMud19tYXNrXSA9IHMuaGVhZFtzLmluc19oXTsKICAgICAgICAgICAgcy5oZWFkW3MuaW5zX2hdID0gc3RyOwogICAgICAgICAgICBzdHIrKzsKICAgICAgICAgIH0gd2hpbGUgKC0tbik7CiAgICAgICAgICBzLnN0cnN0YXJ0ID0gc3RyOwogICA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ChjMiAmIDY0NTEyKSA9PT0gNTYzMjApIHsKICAgICAgICAgICAgICBjID0gNjU1MzYgKyAoYyAtIDU1Mjk2IDw8IDEwKSArIChjMiAtIDU2MzIwKTsKICAgICAgICAgICAgICBtX3BvcysrOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDEyOCkgewogICAgICAgICAgICBidWZbaSsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCAyMDQ4KSB7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTkyIHwgYyA+Pj4gNjsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgaWYgKGMgPCA2NTUzNikgewogICAgICAgICAgICBidWZbaSsrXSA9IDIyNCB8IGMgPj4+IDEyOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDYgJiA2MzsKICAgICAgICAgICAgYnVmW2krK10gPSAxMjggfCBjICYgNjM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBidWZbaSsrXSA9IDI0MCB8IGMgPj4+IDE4OwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgPj4+IDEyICYgNjM7CiAgICAgICAgICAgIGJ1ZltpKytdID0gMTI4IHwgYyA+Pj4gNiAmIDYzOwogICAgICAgICAgICBidWZbaSsrXSA9IDEyOCB8IGMgJiA2MzsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gYnVmMmJpbnN0cmluZyhidWYsIGxlbikgewogICAgICAgIGlmIChsZW4gPCA2NTUzNCkgewogICAgICAgICAgaWYgKGJ1Zi5zdWJhcnJheSAmJiBTVFJfQVBQTFlfVUlBX09LIHx8ICFidWYuc3ViYXJyYXkgJiYgU1RSX0FQUExZX09LKSB7CiAgICAgICAgICAgIHJldHVybiBTdHJpbmcuZnJvbUNoYXJDb2RlLmFwcGx5KG51bGwsIHV0aWxzLnNocmlua0J1ZihidWYsIGxlbikpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBsZW47IGkrKykgewogICAgICAgICAgcmVzdWx0ICs9IFN0cmluZy5mcm9tQ2hhckNvZGUoYnVmW2ldKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBleHBvcnRzMi5idWYyYmluc3RyaW5nID0gZnVuY3Rpb24oYnVmKSB7CiAgICAgICAgcmV0dXJuIGJ1ZjJiaW5zdHJpbmcoYnVmLCBidWYubGVuZ3RoKTsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYmluc3RyaW5nMmJ1ZiA9IGZ1bmN0aW9uKHN0cikgewogICAgICAgIHZhciBidWYgPSBuZXcgdXRpbHMuQnVmOChzdHIubGVuZ3RoKTsKICAgICAgICBmb3IgKHZhciBpID0gMCwgbGVuID0gYnVmLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAgICAgICBidWZbaV0gPSBzdHIuY2hhckNvZGVBdChpKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJ1ZjsKICAgICAgfTsKICAgICAgZXhwb3J0czIuYnVmMnN0cmluZyA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIGksIG91dCwgYywgY19sZW47CiAgICAgICAgdmFyIGxlbiA9IG1heCB8fCBidWYubGVuZ3RoOwogICAgICAgIHZhciB1dGYxNmJ1ZiA9IG5ldyBBcnJheShsZW4gKiAyKTsKICAgICAgICBmb3IgKG91dCA9IDAsIGkgPSAwOyBpIDwgbGVuOyApIHsKICAgICAgICAgIGMgPSBidWZbaSsrXTsKICAgICAgICAgIGlmIChjIDwgMTI4KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgfQogICAgICAgICAgY19sZW4gPSBfdXRmOGxlbltjXTsKICAgICAgICAgIGlmIChjX2xlbiA+IDQpIHsKICAgICAgICAgICAgdXRmMTZidWZbb3V0KytdID0gNjU1MzM7CiAgICAgICAgICAgIGkgKz0gY19sZW4gLSAxOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgIH0KICAgICAgICAgIGMgJj0gY19sZW4gPT09IDIgPyAzMSA6IGNfbGVuID09PSAzID8gMTUgOiA3OwogICAgICAgICAgd2hpbGUgKGNfbGVuID4gMSAmJiBpIDwgbGVuKSB7CiAgICAgICAgICAgIGMgPSBjIDw8IDYgfCBidWZbaSsrXSAmIDYzOwogICAgICAgICAgICBjX2xlbi0tOwogICAgICAgICAgfQogICAgICAgICAgaWYgKGNfbGVuID4gMSkgewogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA2NTUzMzsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoYyA8IDY1NTM2KSB7CiAgICAgICAgICAgIHV0ZjE2YnVmW291dCsrXSA9IGM7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjIC09IDY1NTM2OwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NTI5NiB8IGMgPj4gMTAgJiAxMDIzOwogICAgICAgICAgICB1dGYxNmJ1ZltvdXQrK10gPSA1NjMyMCB8IGMgJiAxMDIzOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICByZXR1cm4gYnVmMmJpbnN0cmluZyh1dGYxNmJ1Ziwgb3V0KTsKICAgICAgfTsKICAgICAgZXhwb3J0czIudXRmOGJvcmRlciA9IGZ1bmN0aW9uKGJ1ZiwgbWF4KSB7CiAgICAgICAgdmFyIHBvczsKICAgICAgICBtYXggPSBtYXggfHwgYnVmLmxlbmd0aDsKICAgICAgICBpZiAobWF4ID4gYnVmLmxlbmd0aCkgewogICAgICAgICAgbWF4ID0gYnVmLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgcG9zID0gbWF4IC0gMTsKICAgICAgICB3aGlsZSAocG9zID49IDAgJiYgKGJ1Zltwb3NdICYgMTkyKSA9PT0gMTI4KSB7CiAgICAgICAgICBwb3MtLTsKICAgICAgICB9CiAgICAgICAgaWYgKHBvcyA8IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChwb3MgPT09IDApIHsKICAgICAgICAgIHJldHVybiBtYXg7CiAgICAgICAgfQogICAgICAgIHJldHVybiBwb3MgKyBfdXRmOGxlbltidWZbcG9zXV0gPiBtYXggPyBwb3MgOiBtYXg7CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi96c3RyZWFtLmpzCiAgdmFyIHJlcXVpcmVfenN0cmVhbSA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi96c3RyZWFtLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gWlN0cmVhbSgpIHsKICAgICAgICB0aGlzLmlucHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfaW4gPSAwOwogICAgICAgIHRoaXMuYXZhaWxfaW4gPSAwOwogICAgICAgIHRoaXMudG90YWxfaW4gPSAwOwogICAgICAgIHRoaXMub3V0cHV0ID0gbnVsbDsKICAgICAgICB0aGlzLm5leHRfb3V0ID0gMDsKICAgICAgICB0aGlzLmF2YWlsX291dCA9IDA7CiAgICAgICAgdGhpcy50b3RhbF9vdXQgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhp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GlvbiBEZWZsYXRlKG9wdGlvbnMpIHsKICAgICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgRGVmbGF0ZSkpCiAgICAgICAgICByZXR1cm4gbmV3IERlZmxhdGUob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGxldmVsOiBaX0RFRkFVTFRfQ09NUFJFU1NJT04sCiAgICAgICAgICBtZXRob2Q6IFpfREVGTEFURUQsCiAgICAgICAgICBjaHVua1NpemU6IDE2Mzg0LAogICAgICAgICAgd2luZG93Qml0czogMTUsCiAgICAgICAgICBtZW1MZXZlbDogOCwKICAgICAgICAgIHN0cmF0ZWd5OiBaX0RFRkFVTFRfU1RSQVRFR1ksCiAgICAgICAgICB0bzogIiIKICAgICAgICB9LCBvcHRpb25zIHx8IHt9KTsKICAgICAgICB2YXIgb3B0ID0gdGhpcy5vcHRpb25zOwogICAgICAgIGlmIChvcHQucmF3ICYmIG9wdC53aW5kb3dCaXRzID4gMCkgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgPSAtb3B0LndpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIGlmIChvcHQuZ3ppcCAmJiBvcHQud2luZG93Qml0cyA+IDAgJiYgb3B0LndpbmRvd0JpdHMgPCAxNikgewogICAgICAgICAgb3B0LndpbmRvd0JpdHMgKz0gMTY7CiAgICAgICAgfQogICAgICAgIHRoaXMuZXJyID0gMDsKICAgICAgICB0aGlzLm1zZyA9ICIiOwogICAgICAgIHRoaXMuZW5kZWQgPSBmYWxzZTsKICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuc3RybSA9IG5ldyBaU3RyZWFtKCk7CiAgICAgICAgdGhpcy5zdHJtLmF2YWlsX291dCA9IDA7CiAgICAgICAgdmFyIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlSW5pdDIodGhpcy5zdHJtLCBvcHQubGV2ZWwsIG9wd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wgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBzdGF0dXMsIF9tb2RlOwogICAgICAgIGlmICh0aGlzLmVuZGVkKSB7CiAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgfQogICAgICAgIF9tb2RlID0gbW9kZSA9PT0gfn5tb2RlID8gbW9kZSA6IG1vZGUgPT09IHRydWUgPyBaX0ZJTklTSCA6IFpfTk9fRkxVU0g7CiAgICAgICAgaWYgKHR5cGVvZiBkYXRhID09PSAic3RyaW5nIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IHN0cmluZ3Muc3RyaW5nMmJ1ZihkYXRhKTsKICAgICAgICB9IGVsc2UgaWYgKHRvU3RyaW5nLmNhbGwoZGF0YSkgPT09ICJbb2JqZWN0IEFycmF5QnVmZmVyXSIpIHsKICAgICAgICAgIHN0cm0uaW5wdXQgPSBuZXcgVWludDhBcnJheShkYXRhKTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgc3RybS5pbnB1dCA9IGRhdGE7CiAgICAgICAgfQogICAgICAgIHN0cm0ubmV4dF9pbiA9IDA7CiAgICAgICAgc3RybS5hdmFpbF9pbiA9IHN0cm0uaW5wdXQubGVuZ3RoOwogICAgICAgIGRvIHsKICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCkgewogICAgICAgICAgICBzdHJtLm91dHB1dCA9IG5ldyB1dGlscy5CdWY4KGNodW5rU2l6ZSk7CiAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSAwOwogICAgICAgICAgICBzdHJtLmF2YWlsX291dCA9IGNodW5rU2l6ZTsKICAgICAgICAgIH0KICAgICAgICAgIHN0YXR1cyA9IHpsaWJfZGVmbGF0ZS5kZWZsYXRlKHN0cm0sIF9tb2RlKTsKICAgICAgICAgIGlmIChzdGF0dXMgIT09IFpfU1RSRUFNX0VORCAmJiBzdGF0dXMgIT09IFpfT0spIHsKICAgICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgICB0aGlzLmVuZGVkID0gdHJ1ZTsKICAgICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgICAgfQogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBaX0ZJTklTSCB8fCBfbW9kZSA9PT0gWl9TWU5DX0ZMVVNIMikpIHsKICAgICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgICB0aGlzLm9uRGF0YShzdHJpbmdzLmJ1ZjJiaW5zdHJpbmcodXRpbHMuc2hyaW5rQnVmKHN0cm0ub3V0cHV0LCBzdHJtLm5leHRfb3V0KSkpOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0aWxzLnNocmlua0J1ZihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCkpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfSB3aGlsZSAoKHN0cm0uYXZhaWxfaW4gPiAwIHx8IHN0cm0uYXZhaWxfb3V0ID09PSAwKSAmJiBzdGF0dXMgIT09IFpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKF9tb2RlID09PSBaX0ZJTklTSCkgewogICAgICAgICAgc3RhdHVzID0gemxpYl9kZWZsYXRlLmRlZmxhdGVFbmQodGhpcy5zdHJtKTsKICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgIHRoaXMuZW5kZWQgPSB0cnVlOwogICAgICAgICAgcmV0dXJuIHN0YXR1cyA9PT0gWl9PSzsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBaX1NZTkNfRkxVU0gyKSB7CiAgICAgICAgICB0aGlzLm9uRW5kKFpfT0spOwogICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSAwOwogICAgICAgICAgcmV0dXJuIHRydWU7CiAgICAgICAgfQogICAgICAgIHJldHVybiB0cnVlOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkRhdGEgPSBmdW5jdGlvbihjaHVuaykgewogICAgICAgIHRoaXMuY2h1bmtzLnB1c2goY2h1bmspOwogICAgICB9OwogICAgICBEZWZsYXRlLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IFpfT0spIHsKICAgICAgICAgIGlmICh0aGlzLm9wdGlvbnMudG8gPT09ICJzdHJpbmciKSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdGhpcy5jaHVua3Muam9pbigiIik7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICB0aGlzLnJlc3VsdCA9IHV0aWxzLmZsYXR0ZW5DaHVua3ModGhpcy5jaHVua3MpOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICB0aGlzLmNodW5rcyA9IFtdOwogICAgICAgIHRoaXMuZXJyID0gc3RhdHVzOwogICAgICAgIHRoaXMubXNnID0gdGhpcy5zdHJtLm1zZzsKICAgICAgfTsKICAgICAgZnVuY3Rpb24gZGVmbGF0ZShpbnB1dCwgb3B0aW9ucykgewogICAgICAgIHZhciBkZWZsYXRvciA9IG5ldyBEZWZsYXRlKG9wdGlvbnMpOwogICAgICAgIGRlZmxhdG9yLnB1c2goaW5wdXQsIHRydWUpOwogICAgICAgIGlmIChkZWZsYXRvci5lcnIpIHsKICAgICAgICAgIHRocm93IGRlZmxhdG9yLm1zZyB8fCBtc2dbZGVmbGF0b3IuZXJyXTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRlZmxhdG9yLnJlc3VsdDsKICAgICAgfQogICAgICBmdW5jdGlvbiBkZWZsYXRlUmF3KGlucHV0LCBvcHRpb25zKSB7CiAgICAgICA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ICB2YXIgYmVnOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGRtYXg7CiAgICAgICAgdmFyIHdzaXplOwogICAgICAgIHZhciB3aGF2ZTsKICAgICAgICB2YXIgd25leHQ7CiAgICAgICAgdmFyIHNfd2luZG93OwogICAgICAgIHZhciBob2xkOwogICAgICAgIHZhciBiaXRzOwogICAgICAgIHZhciBsY29kZTsKICAgICAgICB2YXIgZGNvZGU7CiAgICAgICAgdmFyIGxtYXNrOwogICAgICAgIHZhciBkbWFzazsKICAgICAgICB2YXIgaGVyZTsKICAgICAgICB2YXIgb3A7CiAgICAgICAgdmFyIGxlbjsKICAgICAgICB2YXIgZGlzdDsKICAgICAgICB2YXIgZnJvbTsKICAgICAgICB2YXIgZnJvbV9zb3VyY2U7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIF9pbiA9IHN0cm0ubmV4dF9pbjsKICAgICAgICBpbnB1dCA9IHN0cm0uaW5wdXQ7CiAgICAgICAgbGFzdCA9IF9pbiArIChzdHJtLmF2YWlsX2luIC0gNSk7CiAgICAgICAgX291dCA9IHN0cm0ubmV4dF9vdXQ7CiAgICAgICAgb3V0cHV0ID0gc3RybS5vdXRwdXQ7CiAgICAgICAgYmVnID0gX291dCAtIChzdGFydCAtIHN0cm0uYXZhaWxfb3V0KTsKICAgICAgICBlbmQgPSBfb3V0ICsgKHN0cm0uYXZhaWxfb3V0IC0gMjU3KTsKICAgICAgICBkbWF4ID0gc3RhdGUuZG1heDsKICAgICAgICB3c2l6ZSA9IHN0YXRlLndzaXplOwogICAgICAgIHdoYXZlID0gc3RhdGUud2hhdmU7CiAgICAgICAgd25leHQgPSBzdGF0ZS53bmV4dDsKICAgICAgICBzX3dpbmRvdyA9IHN0YXRlLndpbmRvdzsKICAgICAgICBob2xkID0gc3RhdGUuaG9sZDsKICAgICAgICBiaXRzID0gc3RhdGUuYml0czsKICAgICAgICBsY29kZSA9IHN0YXRlLmxlbmNvZGU7CiAgICAgICAgZGNvZGUgPSBzdGF0ZS5kaXN0Y29kZTsKICAgICAgICBsbWFzayA9ICgxIDw8IHN0YXRlLmxlbmJpdHMpIC0gMTsKICAgICAgICBkbWFzayA9ICgxIDw8IHN0YXRlLmRpc3RiaXRzKSAtIDE7CiAgICAgICAgdG9wOgogICAgICAgICAgZG8gewogICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaGVyZSA9IGxjb2RlW2hvbGQgJiBsbWFza107CiAgICAgICAgICAgIGRvbGVuOgogICAgICAgICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAyNDsKICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgIGJpdHMgLT0gb3A7CiAgICAgICAgICAgICAgICBvcCA9IGhlcmUgPj4+IDE2ICYgMjU1OwogICAgICAgICAgICAgICAgaWYgKG9wID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gaGVyZSAmIDY1NTM1OwogICAgICAgICAgICAgICAgfSBlbHNlIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgIGxlbiA9IGhlcmUgJiA2NTUzNTsKICAgICAgICAgICAgICAgICAgb3AgJj0gMTU7CiAgICAgICAgICAgICAgICAgIGlmIChvcCkgewogICAgICAgICAgICAgICAgICAgIGlmIChiaXRzIDwgb3ApIHsKICAgICAgICAgICAgICAgICAgICAgIGhvbGQgKz0gaW5wdXRbX2luKytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGxlbiArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IDE1KSB7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlW2hvbGQgJiBkbWFza107CiAgICAgICAgICAgICAgICAgIGRvZGlzdDoKICAgICAgICAgICAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgICAgICAgICAgIG9wID0gaGVyZSA+Pj4gMjQ7CiAgICAgICAgICAgICAgICAgICAgICBob2xkID4+Pj0gb3A7CiAgICAgICAgICAgICAgICAgICAgICBiaXRzIC09IG9wOwogICAgICAgICAgICAgICAgICAgICAgb3AgPSBoZXJlID4+PiAxNiAmIDI1NTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCAmIDE2KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGRpc3QgPSBoZXJlICYgNjU1MzU7CiAgICAgICAgICAgICAgICAgICAgICAgIG9wICY9IDE1OwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoYml0cyA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGJpdHMgPCBvcCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtfaW4rK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgZGlzdCArPSBob2xkICYgKDEgPDwgb3ApIC0gMTsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGRpc3QgPiBkbWF4KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBkaXN0YW5jZSB0b28gZmFyIGJhY2siOwogICAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGhvbGQgPj4+PSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgYml0cyAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBfb3V0IC0gYmVnOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoZGlzdCA+IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgb3AgPSBkaXN0IC0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wID4gd2hhdmUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdGF0ZS5zYW5lKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgdG9vIGZhciBiYWNrIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tX3NvdXJjZSA9IHNfd2luZG93OwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh3bmV4dCA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSArPSB3c2l6ZSAtIG9wOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSBfb3V0IC0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbV9zb3VyY2UgPSBvdXRwdXQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICh3bmV4dCA8IG9wKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tICs9IHdzaXplICsgd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG9wIC09IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKG9wIDwgbGVuKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZG8gewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gc193aW5kb3dbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gPSAwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAod25leHQgPCBsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvcCA9IHduZXh0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBkbyB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSB3aGlsZSAoLS1vcCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb20gKz0gd25leHQgLSBvcDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChvcCA8IGxlbikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZW4gLT0gb3A7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IHNfd2luZG93W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKC0tb3ApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBmcm9tID0gX291dCAtIGRpc3Q7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZyb21fc291cmNlID0gb3V0cHV0OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB3aGlsZSAobGVuID4gMikgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBmcm9tX3NvdXJjZVtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVuIC09IDM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4gPiAxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gZnJvbV9zb3VyY2VbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZnJvbSA9IF9vdXQgLSBkaXN0OwogICAgICAgICAgICAgICAgICAgICAgICAgIGRvIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgb3V0cHV0W19vdXQrK10gPSBvdXRwdXRbZnJvbSsrXTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlbiAtPSAzOwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gd2hpbGUgKGxlbiA+IDIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChsZW4pIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIG91dHB1dFtfb3V0KytdID0gb3V0cHV0W2Zyb20rK107CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAobGVuID4gMSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBvdXRwdXRbX291dCsrXSA9IG91dHB1dFtmcm9tKytdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmICgob3AgJiA2NCkgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgaGVyZSA9IGRjb2RlWyhoZXJlICYgNjU1MzUpICsgKGhvbGQgJiAoMSA8PCBvcCkgLSAxKV07CiAgICAgICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlIGRvZGlzdDsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0cm0ubXNnID0gImludmFsaWQgZGlzdGFuY2UgY29kZSI7CiAgICAgICAgICAgICAgICAgICAgICAgIHN0YXRlLm1vZGUgPSBCQUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrIHRvcDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAoKG9wICYgNjQpID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIGhlcmUgPSBsY29kZVsoaGVyZSAmIDY1NTM1KSArIChob2xkICYgKDEgPDwgb3ApIC0gMSldOwogICAgICAgICAgICAgICAgICBjb250aW51ZSBkb2xlbjsKICAgICAgICAgICAgICAgIH0gZWxzZSBpZiAob3AgJiAzMikgewogICAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gVFlQRTsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW52YWxpZCBsaXRlcmFsL2xlbmd0aCBjb2RlIjsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgYnJlYWsgdG9wOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgfSB3aGlsZSAoX2luIDwgbGFzdCAmJiBfb3V0IDwgZW5kKTsKICAgICAgICBsZW4gPSBiaXRzID4+IDM7CiAgICAgICAgX2luIC09IGxlbjsKICAgICAgICBiaXRzIC09IGxlbiA8PCAzOwogICAgICAgIGhvbGQgJj0gKDEgPDwgYml0cykgLSAxOwogICAgICAgIHN0cm0ubmV4dF9pbiA9IF9pbjsKICAgICAgICBzdHJtLm5leHRfb3V0ID0gX291dDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gX2luIDwgbGFzdCA/IDUgKyAobGFzdCAtIF9pbikgOiA1IC0gKF9pbiAtIGxhc3QpOwogICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gX291dCA8IGVuZCA/IDI1NyArIChlbmQgLSBfb3V0KSA6IDI1NyAtIChfb3V0IC0gZW5kKTsKICAgICAgICBzdGF0ZS5ob2xkID0gaG9sZDsKICAgICAgICBzdGF0ZS5iaXRzID0gYml0czsKICAgICAgICByZXR1cm47CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9pbmZ0cmVlcy5qcwogIHZhciByZXF1aXJlX2luZnRyZWVzID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2luZnRyZWVzLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgdmFyIHV0aWxzID0gcmVxdWlyZV9jb21tb24oKTsKICAgICAgdmFyIE1BWEJJVFMgPSAxNTsKICAgICAgdmFyIEVOT1VHSF9MRU5TID0gODUyOwogICAgICB2YXIgRU5PVUdIX0RJU1RTID0gNTkyOwogICAgICB2YXIgQ09ERVMgPSAwOwogICAgICB2YXIgTEVOUyA9IDE7CiAgICAgIHZhciBESVNUUyA9IDI7CiAgICAgIHZhciBsYmFzZSA9IFsKICAgICAgICAzLAogICAgICAgIDQsCiAgICAgICAgNSwKICAgICAgICA2LAogICAgICAgIDcsCiAgICAgICAgOCwKICAgICAgICA5LAogICAgICAgIDEwLAogICAgICAgIDExLAogICAgICAgIDEzLAogICAgICAgIDE1LAogICAgICAgIDE3LAogICAgICAgIDE5LAogICAgICAgIDIzLAogICAgICAgIDI3LAogICAgICAgIDMxLAogICAgICAgIDM1LAogICAgICAgIDQzLAogICAgICAgIDUxLAogICAgICAgIDU5LAogICAgICAgIDY3LAogICAgICAgIDgzLAogICAgICAgIDk5LAogICAgICAgIDExNSwKICAgICAgICAxMzEsCiAgICAgICAgMTYzLAogICAgICAgIDE5NSwKICAgICAgICAyMjcsCiAgICAgICAgMjU4LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgbGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAxNiwKICAgICAgICA3MiwKICAgICAgICA3OAogICAgICBdOwogICAgICB2YXIgZGJhc2UgPSBbCiAgICAgICAgMSwKICAgICAgICAyLAogICAgICAgIDMsCiAgICAgICAgNCwKICAgICAgICA1LAogICAgICAgIDcsCiAgICAgICAgOSwKICAgICAgICAxMywKICAgICAgICAxNywKICAgICAgICAyNSwKICAgICAgICAzMywKICAgICAgICA0OSwKICAgICAgICA2NSwKICAgICAgICA5NywKICAgICAgICAxMjksCiAgICAgICAgMTkzLAogICAgICAgIDI1NywKICAgICAgICAzODUsCiAgICAgICAgNTEzLAogICAgICAgIDc2OSwKICAgICAgICAxMDI1LAogICAgICAgIDE1MzcsCiAgICAgICAgMjA0OSwKICAgICAgICAzMDczLAogICAgICAgIDQwOTcsCiAgICAgICAgNjE0NSwKICAgICAgICA4MTkzLAogICAgICAgIDEyMjg5LAogICAgICAgIDE2Mzg1LAogICAgICAgIDI0NTc3LAogICAgICAgIDAsCiAgICAgICAgMAogICAgICBdOwogICAgICB2YXIgZGV4dCA9IFsKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNiwKICAgICAgICAxNywKICAgICAgICAxNywKICAgICAgICAxOCwKICAgICAgICAxOCwKICAgICAgICAxOSwKICAgICAgICAxOSwKICAgICAgICAyMCwKICAgICAgICAyMCwKICAgICAgICAyMSwKICAgICAgICAyMSwKICAgICAgICAyMiwKICAgICAgICAyMiwKICAgICAgICAyMywKICAgICAgICAyMywKICAgICAgICAyNCwKICAgICAgICAyNCwKICAgICAgICAyNSwKICAgICAgICAyNSwKICAgICAgICAyNiwKICAgICAgICAyNiwKICAgICAgICAyNywKICAgICAgICAyNywKICAgICAgICAyOCwKICAgICAgICAyOCwKICAgICAgICAyOSwKICAgICAgICAyOSwKICAgICAgICA2NCwKICAgICAgICA2NAogICAgICBdOwogICAgICBtb2R1bGUyLmV4cG9ydHMgPSBmdW5jdGlvbiBpbmZsYXRlX3RhYmxlKHR5cGUsIGxlbnMsIGxlbnNfaW5kZXgsIGNvZGVzLCB0YWJsZSwgdGFibGVfaW5kZXgsIHdvcmssIG9wdHMpIHsKICAgICAgICB2YXIgYml0cyA9IG9wdHMuYml0czsKICAgICAgICB2YXIgbGVuID0gMDsKICAgICAgICB2YXIgc3ltID0gMDsKICAgICAgICB2YXIgbWluID0gMCwgbWF4ID0gMDsKICAgICAgICB2YXIgcm9vdDIgPSAwOwogICAgICAgIHZhciBjdXJyID0gMDsKICAgICAgICB2YXIgZHJvcCA9IDA7CiAgICAgICAgdmFyIGxlZnQgPSAwOwogICAgICAgIHZhciB1c2VkID0gMDsKICAgICAgICB2YXIgaHVmZiA9IDA7CiAgICAgICAgdmFyIGluY3I7CiAgICAgICAgdmFyIGZpbGw7CiAgICAgICAgdmFyIGxvdzsKICAgICAgICB2YXIgbWFzazsKICAgICAgICB2YXIgbmV4dDsKICAgICAgICB2YXIgYmFzZSA9IG51bGw7CiAgICAgICAgdmFyIGJhc2VfaW5kZXggPSAwOwogICAgICAgIHZhciBlbmQ7CiAgICAgICAgdmFyIGNvdW50ID0gbmV3IHV0aWxzLkJ1ZjE2KE1BWEJJVFMgKyAxKTsKICAgICAgICB2YXIgb2ZmcyA9IG5ldyB1dGlscy5CdWYxNihNQVhCSVRTICsgMSk7CiAgICAgICAgdmFyIGV4dHJhID0gbnVsbDsKICAgICAgICB2YXIgZXh0cmFfaW5kZXggPSAwOwogICAgICAgIHZhciBoZXJlX2JpdHMsIGhlcmVfb3AsIGhlcmVfdmFsOwogICAgICAgIGZvciAobGVuID0gMDsgbGVuIDw9IE1BWEJJVFM7IGxlbisrKSB7CiAgICAgICAgICBjb3VudFtsZW5dID0gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChzeW0gPSAwOyBzeW0gPCBjb2Rlczsgc3ltKyspIHsKICAgICAgICAgIGNvdW50W2xlbnNbbGVuc19pbmRleCArIHN5bV1dKys7CiAgICAgICAgfQogICAgICAgIHJvb3QyID0gYml0czsKICAgICAgICBmb3IgKG1heCA9IE1BWEJJVFM7IG1heCA+PSAxOyBtYXgtLSkgewogICAgICAgICAgaWYgKGNvdW50W21heF0gIT09IDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChyb290MiA+IG1heCkgewogICAgICAgICAgcm9vdDIgPSBtYXg7CiAgICAgICAgfQogICAgICAgIGlmIChtYXggPT09IDApIHsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIHRhYmxlW3RhYmxlX2luZGV4KytdID0gMSA8PCAyNCB8IDY0IDw8IDE2IHwgMDsKICAgICAgICAgIG9wdHMuYml0cyA9IDE7CiAgICAgICAgICByZXR1cm4gMDsKICAgICAgICB9CiAgICAgICAgZm9yIChtaW4gPSAxOyBtaW4gPCBtYXg7IG1pbisrKSB7CiAgICAgICAgICBpZiAoY291bnRbbWluXSAhPT0gMCkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKHJvb3QyIDwgbWluKSB7CiAgICAgICAgICByb290MiA9IG1pbjsKICAgICAgICB9CiAgICAgICAgbGVmdCA9IDE7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPD0gTUFYQklUUzsgbGVuKyspIHsKICAgICAgICAgIGxlZnQgPDw9IDE7CiAgICAgICAgICBsZWZ0IC09IGNvdW50W2xlbl07CiAgICAgICAgICBpZiAobGVmdCA8IDApIHsKICAgICAgICAgICAgcmV0dXJuIC0xOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAobGVmdCA+IDAgJiYgKHR5cGUgPT09IENPREVTIHx8IG1heCAhPT0gMSkpIHsKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICB9CiAgICAgICAgb2Zmc1sxXSA9IDA7CiAgICAgICAgZm9yIChsZW4gPSAxOyBsZW4gPCBNQVhCSVRTOyBsZW4rKykgewogICAgICAgICAgb2Zmc1tsZW4gKyAxXSA9IG9mZnNbbGVuXSArIGNvdW50W2xlbl07CiAgICAgICAgfQogICAgICAgIGZvciAoc3ltID0gMDsgc3ltIDwgY29kZXM7IHN5bSsrKSB7CiAgICAgICAgICBpZiAobGVuc1tsZW5zX2luZGV4ICsgc3ltXSAhPT0gMCkgewogICAgICAgICAgICB3b3JrW29mZnNbbGVuc1tsZW5zX2luZGV4ICsgc3ltXV0rK10gPSBzeW07CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh0eXBlID09PSBDT0RFUykgewogICAgICAgICAgYmFzZSA9IGV4dHJhID0gd29yazsKICAgICAgICAgIGVuZCA9IDE5OwogICAgICAgIH0gZWxzZSBpZiAodHlwZSA9PT0gTEVOUykgewogICAgICAgICAgYmFzZSA9IGxiYXNlOwogICAgICAgICAgYmFzZV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBleHRyYSA9IGxleHQ7CiAgICAgICAgICBleHRyYV9pbmRleCAtPSAyNTc7CiAgICAgICAgICBlbmQgPSAyNTY7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIGJhc2UgPSBkYmFzZTsKICAgICAgICAgIGV4dHJhID0gZGV4dDsKICAgICAgICAgIGVuZCA9IC0xOwogICAgICAgIH0KICAgICAgICBodWZmID0gMDsKICAgICAgICBzeW0gPSAwOwogICAgICAgIGxlbiA9IG1pbjsKICAgICAgICBuZXh0ID0gdGFibGVfaW5kZXg7CiAgICAgICAgY3VyciA9IHJvb3QyOwogICAgICAgIGRyb3AgPSAwOwogICAgICAgIGxvdyA9IC0xOwogICAgICAgIHVzZWQgPSAxIDw8IHJvb3QyOwogICAgICAgIG1hc2sgPSB1c2VkIC0gMTsKICAgICAgICBpZiAodHlwZSA9PT0gTEVOUyAmJiB1c2VkID4gRU5PVUdIX0xFTlMgfHwgdHlwZSA9PT0gRElTVFMgJiYgdXNlZCA+IEVOT1VHSF9ESVNUUykgewogICAgICAgICAgcmV0dXJuIDE7CiAgICAgICAgfQogICAgICAgIGZvciAoOyA7ICkgewogICAgICAgICAgaGVyZV9iaXRzID0gbGVuIC0gZHJvcDsKICAgICAgICAgIGlmICh3b3JrW3N5bV0gPCBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDA7CiAgICAgICAgICAgIGhlcmVfdmFsID0gd29ya1tzeW1dOwogICAgICAgICAgfSBlbHNlIGlmICh3b3JrW3N5bV0gPiBlbmQpIHsKICAgICAgICAgICAgaGVyZV9vcCA9IGV4dHJhW2V4dHJhX2luZGV4ICsgd29ya1tzeW1dXTsKICAgICAgICAgICAgaGVyZV92YWwgPSBiYXNlW2Jhc2VfaW5kZXggKyB3b3JrW3N5bV1dOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaGVyZV9vcCA9IDMyICsgNjQ7CiAgICAgICAgICAgIGhlcmVfdmFsID0gMDsKICAgICAgICAgIH0KICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIGRyb3A7CiAgICAgICAgICBmaWxsID0gMSA8PCBjdXJyOwogICAgICAgICAgbWluID0gZmlsbDsKICAgICAgICAgIGRvIHsKICAgICAgICAgICAgZmlsbCAtPSBpbmNyOwogICAgICAgICAgICB0YWJsZVtuZXh0ICsgKGh1ZmYgPj4gZHJvcCkgKyBmaWxsXSA9IGhlcmVfYml0cyA8PCAyNCB8IGhlcmVfb3AgPDwgMTYgfCBoZXJlX3ZhbCB8IDA7CiAgICAgICAgICB9IHdoaWxlIChmaWxsICE9PSAwKTsKICAgICAgICAgIGluY3IgPSAxIDw8IGxlbiAtIDE7CiAgICAgICAgICB3aGlsZSAoaHVmZiAmIGluY3IpIHsKICAgICAgICAgICAgaW5jciA+Pj0gMTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChpbmNyICE9PSAwKSB7CiAgICAgICAgICAgIGh1ZmYgJj0gaW5jciAtIDE7CiAgICAgICAgICAgIGh1ZmYgKz0gaW5jcjsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGh1ZmYgPSAwOwogICAgICAgICAgfQogICAgICAgICAgc3ltKys7CiAgICAgICAgICBpZiAoLS1jb3VudFtsZW5dID09PSAwKSB7CiAgICAgICAgICAgIGlmIChsZW4gPT09IG1heCkgewogICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGxlbiA9IGxlbnNbbGVuc19pbmRleCArIHdvcmtbc3ltXV07CiAgICAgICAgICB9CiAgICAgICAgICBpZiAobGVuID4gcm9vdDIgJiYgKGh1ZmYgJiBtYXNrKSAhPT0gbG93KSB7CiAgICAgICAgICAgIGlmIChkcm9wID09PSAwKSB7CiAgICAgICAgICAgICAgZHJvcCA9IHJvb3QyOwogICAgICAgICAgICB9CiAgICAgICAgICAgIG5leHQgKz0gbWluOwogICAgICAgICAgICBjdXJyID0gbGVuIC0gZHJvcDsKICAgICAgICAgICAgbGVmdCA9IDEgPDwgY3VycjsKICAgICAgICAgICAgd2hpbGUgKGN1cnIgKyBkcm9wIDwgbWF4KSB7CiAgICAgICAgICAgICAgbGVmdCAtPSBjb3VudFtjdXJyICsgZHJvcF07CiAgICAgICAgICAgICAgaWYgKGxlZnQgPD0gMCkgewogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGN1cnIrKzsKICAgICAgICAgICAgICBsZWZ0IDw8PSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHVzZWQgKz0gMSA8PCBjdXJyOwogICAgICAgICAgICBpZiAodHlwZSA9PT0gTEVO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MoKTsKICAgICAgdmFyIENPREVTID0gMDsKICAgICAgdmFyIExFTlMgPSAxOwogICAgICB2YXIgRElTVFMgPSAyOwogICAgICB2YXIgWl9GSU5JU0ggPSA0OwogICAgICB2YXIgWl9CTE9DSyA9IDU7CiAgICAgIHZhciBaX1RSRUVTID0gNjsKICAgICAgdmFyIFpfT0sgPSAwOwogICAgICB2YXIgWl9TVFJFQU1fRU5EID0gMTsKICAgICAgdmFyIFpfTkVFRF9ESUNUID0gMjsKICAgICAgdmFyIFpfU1RSRUFNX0VSUk9SID0gLTI7CiAgICAgIHZhciBaX0RBVEFfRVJST1IgPSAtMzsKICAgICAgdmFyIFpfTUVNX0VSUk9SID0gLTQ7CiAgICAgIHZhciBaX0JVRl9FUlJPUiA9IC01OwogICAgICB2YXIgWl9ERUZMQVRFRCA9IDg7CiAgICAgIHZhciBIRUFEID0gMTsKICAgICAgdmFyIEZMQUdTID0gMjsKICAgICAgdmFyIFRJTUUgPSAzOwogICAgICB2YXIgT1MgPSA0OwogICAgICB2YXIgRVhMRU4gPSA1OwogICAgICB2YXIgRVhUUkEgPSA2OwogICAgICB2YXIgTkFNRSA9IDc7CiAgICAgIHZhciBDT01NRU5UID0gODsKICAgICAgdmFyIEhDUkMgPSA5OwogICAgICB2YXIgRElDVElEID0gMTA7CiAgICAgIHZhciBESUNUID0gMTE7CiAgICAgIHZhciBUWVBFID0gMTI7CiAgICAgIHZhciBUWVBFRE8gPSAxMzsKICAgICAgdmFyIFNUT1JFRCA9IDE0OwogICAgICB2YXIgQ09QWV8gPSAxNTsKICAgICAgdmFyIENPUFkgPSAxNjsKICAgICAgdmFyIFRBQkxFID0gMTc7CiAgICAgIHZhciBMRU5MRU5TID0gMTg7CiAgICAgIHZhciBDT0RFTEVOUyA9IDE5OwogICAgICB2YXIgTEVOXyA9IDIwOwogICAgICB2YXIgTEVOID0gMjE7CiAgICAgIHZhciBMRU5FWFQgPSAyMjsKICAgICAgdmFyIERJU1QgPSAyMzsKICAgICAgdmFyIERJU1RFWFQgPSAyNDsKICAgICAgdmFyIE1BVENIID0gMjU7CiAgICAgIHZhciBMSVQgPSAyNjsKICAgICAgdmFyIENIRUNLID0gMjc7CiAgICAgIHZhciBMRU5HVEggPSAyODsKICAgICAgdmFyIERPTkUgPSAyOTsKICAgICAgdmFyIEJBRCA9IDMwOwogICAgICB2YXIgTUVNID0gMzE7CiAgICAgIHZhciBTWU5DID0gMzI7CiAgICAgIHZhciBFTk9VR0hfTEVOUyA9IDg1MjsKICAgICAgdmFyIEVOT1VHSF9ESVNUUyA9IDU5MjsKICAgICAgdmFyIE1BWF9XQklUUyA9IDE1OwogICAgICB2YXIgREVGX1dCSVRTID0gTUFYX1dCSVRTOwogICAgICBmdW5jdGlvbiB6c3dhcDMyKHEpIHsKICAgICAgICByZXR1cm4gKHEgPj4+IDI0ICYgMjU1KSArIChxID4+PiA4ICYgNjUyODApICsgKChxICYgNjUyODApIDw8IDgpICsgKChxICYgMjU1KSA8PCAyNCk7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gSW5mbGF0ZVN0YXRlKCkgewogICAgICAgIHRoaXMubW9kZSA9IDA7CiAgICAgICAgdGhpcy5sYXN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy53cmFwID0gMDsKICAgICAgICB0aGlzLmhhdmVkaWN0ID0gZmFsc2U7CiAgICAgICAgdGhpcy5mbGFncyA9IDA7CiAgICAgICAgdGhpcy5kbWF4ID0gMDsKICAgICAgICB0aGlzLmNoZWNrID0gMDsKICAgICAgICB0aGlzLnRvdGFsID0gMDsKICAgICAgICB0aGlzLmhlYWQgPSBudWxsOwogICAgICAgIHRoaXMud2JpdHMgPSAwOwogICAgICAgIHRoaXMud3NpemUgPSAwOwogICAgICAgIHRoaXMud2hhdmUgPSAwOwogICAgICAgIHRoaXMud25leHQgPSAwOwogICAgICAgIHRoaXMud2luZG93ID0gbnVsbDsKICAgICAgICB0aGlzLmhvbGQgPSAwOwogICAgICAgIHRoaXMuYml0cyA9IDA7CiAgICAgICAgdGhpcy5sZW5ndGggPSAwOwogICAgICAgIHRoaXMub2Zmc2V0ID0gMDsKICAgICAgICB0aGlzLmV4dHJhID0gMDsKICAgICAgICB0aGlzLmxlbmNvZGUgPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGNvZGUgPSBudWxsOwogICAgICAgIHRoaXMubGVuYml0cyA9IDA7CiAgICAgICAgdGhpcy5kaXN0Yml0cyA9IDA7CiAgICAgICAgdGhpcy5uY29kZSA9IDA7CiAgICAgICAgdGhpcy5ubGVuID0gMDsKICAgICAgICB0aGlzLm5kaXN0ID0gMDsKICAgICAgICB0aGlzLmhhdmUgPSAwOwogICAgICAgIHRoaXMubmV4dCA9IG51bGw7CiAgICAgICAgdGhpcy5sZW5zID0gbmV3IHV0aWxzLkJ1ZjE2KDMyMCk7CiAgICAgICAgdGhpcy53b3JrID0gbmV3IHV0aWxzLkJ1ZjE2KDI4OCk7CiAgICAgICAgdGhpcy5sZW5keW4gPSBudWxsOwogICAgICAgIHRoaXMuZGlzdGR5biA9IG51bGw7CiAgICAgICAgdGhpcy5zYW5lID0gMDsKICAgICAgICB0aGlzLmJhY2sgPSAwOwogICAgICAgIHRoaXMud2FzID0gMDsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBzdHJtLnRvdGFsX2luID0gc3RybS50b3RhbF9vdXQgPSBzdGF0ZS50b3RhbCA9IDA7CiAgICAgICAgc3RybS5tc2cgPSAiIjsKICAgICAgICBpZiAoc3RhdGUud3JhcCkgewogICAgICAgICAgc3RybS5hZGxlciA9IHN0YXRlLndyYXAgJiAxOwogICAgICAgIH0KICAgICAgICBzdGF0ZS5tb2RlID0gSEVBRDsKICAgICAgICBzdGF0ZS5sYXN0ID0gMDsKICAgICAgICBzdGF0ZS5oYXZlZGljdCA9IDA7CiAgICAgICAgc3RhdGUuZG1heCA9IDMyNzY4OwogICAgICAgIHN0YXRlLmhlYWQgPSBudWxsOwogICAgICAgIHN0YXRlLmhvbGQgPSAwOwogICAgICAgIHN0YXRlLmJpdHMgPSAwOwogICAgICAgIHN0YXRlLmxlbmNvZGUgPSBzdGF0ZS5sZW5keW4gPSBuZXcgdXRpbHMuQnVmMzIoRU5PVUdIX0xFTlMpOwogICAgICAgIHN0YXRlLmRpc3Rjb2RlID0gc3RhdGUuZGlzdGR5biA9IG5ldyB1dGlscy5CdWYzMihFTk9VR0hfRElTVFMpOwogICAgICAgIHN0YXRlLnNhbmUgPSAxOwogICAgICAgIHN0YXRlLmJhY2sgPSAtMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBmdW5jdGlvbiBpbmZsYXRlUmVzZXQoc3RybSkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIHN0YXRlLndzaXplID0gMDsKICAgICAgICBzdGF0ZS53aGF2ZSA9IDA7CiAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgIHJldHVybiBpbmZsYXRlUmVzZXRLZWVwKHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cykgewogICAgICAgIHZhciB3cmFwOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICh3aW5kb3dCaXRzIDwgMCkgewogICAgICAgICAgd3JhcCA9IDA7CiAgICAgICAgICB3aW5kb3dCaXRzID0gLXdpbmRvd0JpdHM7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHdyYXAgPSAod2luZG93Qml0cyA+PiA0KSArIDE7CiAgICAgICAgICBpZiAod2luZG93Qml0cyA8IDQ4KSB7CiAgICAgICAgICAgIHdpbmRvd0JpdHMgJj0gMTU7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmICh3aW5kb3dCaXRzICYmICh3aW5kb3dCaXRzIDwgOCB8fCB3aW5kb3dCaXRzID4gMTUpKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS53aW5kb3cgIT09IG51bGwgJiYgc3RhdGUud2JpdHMgIT09IHdpbmRvd0JpdHMpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0YXRlLndyYXAgPSB3cmFwOwogICAgICAgIHN0YXRlLndiaXRzID0gd2luZG93Qml0czsKICAgICAgICByZXR1cm4gaW5mbGF0ZVJlc2V0KHN0cm0pOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVJbml0MihzdHJtLCB3aW5kb3dCaXRzKSB7CiAgICAgICAgdmFyIHJldDsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgaWYgKCFzdHJtKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gbmV3IEluZmxhdGVTdGF0ZSgpOwogICAgICAgIHN0cm0uc3RhdGUgPSBzdGF0ZTsKICAgICAgICBzdGF0ZS53aW5kb3cgPSBudWxsOwogICAgICAgIHJldCA9IGluZmxhdGVSZXNldDIoc3RybSwgd2luZG93Qml0cyk7CiAgICAgICAgaWYgKHJldCAhPT0gWl9PSykgewogICAgICAgICAgc3RybS5zdGF0ZSA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHJldHVybiByZXQ7CiAgICAgIH0KICAgICAgZnVuY3Rpb24gaW5mbGF0ZUluaXQoc3RybSkgewogICAgICAgIHJldHVybiBpbmZsYXRlSW5pdDIoc3RybSwgREVGX1dCSVRTKTsKICAgICAgfQogICAgICB2YXIgdmlyZ2luID0gdHJ1ZTsKICAgICAgdmFyIGxlbmZpeDsKICAgICAgdmFyIGRpc3RmaXg7CiAgICAgIGZ1bmN0aW9uIGZpeGVkdGFibGVzKHN0YXRlKSB7CiAgICAgICAgaWYgKHZpcmdpbikgewogICAgICAgICAgdmFyIHN5bTsKICAgICAgICAgIGxlbmZpeCA9IG5ldyB1dGlscy5CdWYzMig1MTIpOwogICAgICAgICAgZGlzdGZpeCA9IG5ldyB1dGlscy5CdWYzMigzMik7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDE0NCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICB3aGlsZSAoc3ltIDwgMjU2KSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gOTsKICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzeW0gPCAyODApIHsKICAgICAgICAgICAgc3RhdGUubGVuc1tzeW0rK10gPSA3OwogICAgICAgICAgfQogICAgICAgICAgd2hpbGUgKHN5bSA8IDI4OCkgewogICAgICAgICAgICBzdGF0ZS5sZW5zW3N5bSsrXSA9IDg7CiAgICAgICAgICB9CiAgICAgICAgICBpbmZsYXRlX3RhYmxlKExFTlMsIHN0YXRlLmxlbnMsIDAsIDI4OCwgbGVuZml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDkgfSk7CiAgICAgICAgICBzeW0gPSAwOwogICAgICAgICAgd2hpbGUgKHN5bSA8IDMyKSB7CiAgICAgICAgICAgIHN0YXRlLmxlbnNbc3ltKytdID0gNTsKICAgICAgICAgIH0KICAgICAgICAgIGluZmxhdGVfdGFibGUoRElTVFMsIHN0YXRlLmxlbnMsIDAsIDMyLCBkaXN0Zml4LCAwLCBzdGF0ZS53b3JrLCB7IGJpdHM6IDUgfSk7CiAgICAgICAgICB2aXJnaW4gPSBmYWxzZTsKICAgICAgICB9CiAgICAgICAgc3RhdGUubGVuY29kZSA9IGxlbmZpeDsKICAgICAgICBzdGF0ZS5sZW5iaXRzID0gOTsKICAgICAgICBzdGF0ZS5kaXN0Y29kZSA9IGRpc3RmaXg7CiAgICAgICAgc3RhdGUuZGlzdGJpdHMgPSA1OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIHVwZGF0ZXdpbmRvdyhzdHJtLCBzcmMsIGVuZCwgY29weSkgewogICAgICAgIHZhciBkaXN0OwogICAgICAgIHZhciBzdGF0ZSA9IHN0cm0uc3RhdGU7CiAgICAgICAgaWYgKHN0YXRlLndpbmRvdyA9PT0gbnVsbCkgewogICAgICAgICAgc3RhdGUud3NpemUgPSAxIDw8IHN0YXRlLndiaXRzOwogICAgICAgICAgc3RhdGUud25leHQgPSAwOwogICAgICAgICAgc3RhdGUud2hhdmUgPSAwOwogICAgICAgICAgc3RhdGUud2luZG93ID0gbmV3IHV0aWxzLkJ1Zjgoc3RhdGUud3NpemUpOwogICAgICAgIH0KICAgICAgICBpZiAoY29weSA+PSBzdGF0ZS53c2l6ZSkgewogICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RhdGUud2luZG93LCBzcmMsIGVuZCAtIHN0YXRlLndzaXplLCBzdGF0ZS53c2l6ZSwgMCk7CiAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICBzdGF0ZS53aGF2ZSA9IHN0YXRlLndzaXplOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBkaXN0ID0gc3RhdGUud3NpemUgLSBzdGF0ZS53bmV4dDsKICAgICAgICAgIGlmIChkaXN0ID4gY29weSkgewogICAgICAgICAgICBkaXN0ID0gY29weTsKICAgICAgICAgIH0KICAgICAgICAgIHV0aWxzLmFycmF5U2V0KHN0YXRlLndpbmRvdywgc3JjLCBlbmQgLSBjb3B5LCBkaXN0LCBzdGF0ZS53bmV4dCk7CiAgICAgICAgICBjb3B5IC09IGRpc3Q7CiAgICAgICAgICBpZiAoY29weSkgewogICAgICAgICAgICB1dGlscy5hcnJheVNldChzdGF0ZS53aW5kb3csIHNyYywgZW5kIC0gY29weSwgY29weSwgMCk7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ID0gY29weTsKICAgICAgICAgICAgc3RhdGUud2hhdmUgPSBzdGF0ZS53c2l6ZTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHN0YXRlLnduZXh0ICs9IGRpc3Q7CiAgICAgICAgICAgIGlmIChzdGF0ZS53bmV4dCA9PT0gc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53bmV4dCA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHN0YXRlLndoYXZlIDwgc3RhdGUud3NpemUpIHsKICAgICAgICAgICAgICBzdGF0ZS53aGF2ZSArPSBkaXN0OwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiAwOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGUoc3RybSwgZmx1c2gpIHsKICAgICAgICB2YXIgc3RhdGU7CiAgICAgICAgdmFyIGlucHV0LCBvdXRwdXQ7CiAgICAgICAgdmFyIG5leHQ7CiAgICAgICAgdmFyIHB1dDsKICAgICAgICB2YXIgaGF2ZSwgbGVmdDsKICAgICAgICB2YXIgaG9sZDsKICAgICAgICB2YXIgYml0czsKICAgICAgICB2YXIgX2luLCBfb3V0OwogICAgICAgIHZhciBjb3B5OwogICAgICAgIHZhciBmcm9tOwogICAgICAgIHZhciBmcm9tX3NvdXJjZTsKICAgIC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bGVhdmU6CiAgICAgICAgICBmb3IgKDsgOyApIHsKICAgICAgICAgICAgc3dpdGNoIChzdGF0ZS5tb2RlKSB7CiAgICAgICAgICAgICAgY2FzZSBIRUFEOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgPT09IDApIHsKICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IFRZUEVETzsKICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB3aGlsZSAoYml0cyA8IDE2KSB7CiAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgYnJlYWsgaW5mX2xlYXZlOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgaG9sZCArPSBpbnB1dFtuZXh0KytdIDw8IGJpdHM7CiAgICAgICAgICAgICAgICAgIGJpdHMgKz0gODsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzdGF0ZS53cmFwICYgMiAmJiBob2xkID09PSAzNTYxNSkgewogICAgICAgICAgICAgICAgICBzdGF0ZS5jaGVjayA9IDA7CiAgICAgICAgICAgICAgICAgIGhidWZbMF0gPSBob2xkICYgMjU1OwogICAgICAgICAgICAgICAgICBoYnVmWzFdID0gaG9sZCA+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/IGhvbGQgOiB6c3dhcDMyKGhvbGQpKSAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgICAgICAgICBzdHJtLm1zZyA9ICJpbmNvcnJlY3QgZGF0YSBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gTEVOR1RIOwogICAgICAgICAgICAgIGNhc2UgTEVOR1RIOgogICAgICAgICAgICAgICAgaWYgKHN0YXRlLndyYXAgJiYgc3RhdGUuZmxhZ3MpIHsKICAgICAgICAgICAgICAgICAgd2hpbGUgKGJpdHMgPCAzMikgewogICAgICAgICAgICAgICAgICAgIGlmIChoYXZlID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGhhdmUtLTsKICAgICAgICAgICAgICAgICAgICBob2xkICs9IGlucHV0W25leHQrK10gPDwgYml0czsKICAgICAgICAgICAgICAgICAgICBiaXRzICs9IDg7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgaWYgKGhvbGQgIT09IChzdGF0ZS50b3RhbCAmIDQyOTQ5NjcyOTUpKSB7CiAgICAgICAgICAgICAgICAgICAgc3RybS5tc2cgPSAiaW5jb3JyZWN0IGxlbmd0aCBjaGVjayI7CiAgICAgICAgICAgICAgICAgICAgc3RhdGUubW9kZSA9IEJBRDsKICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICBob2xkID0gMDsKICAgICAgICAgICAgICAgICAgYml0cyA9IDA7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBzdGF0ZS5tb2RlID0gRE9ORTsKICAgICAgICAgICAgICBjYXNlIERPTkU6CiAgICAgICAgICAgICAgICByZXQgPSBaX1NUUkVBTV9FTkQ7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBCQUQ6CiAgICAgICAgICAgICAgICByZXQgPSBaX0RBVEFfRVJST1I7CiAgICAgICAgICAgICAgICBicmVhayBpbmZfbGVhdmU7CiAgICAgICAgICAgICAgY2FzZSBNRU06CiAgICAgICAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgICAgICAgY2FzZSBTWU5DOgogICAgICAgICAgICAgIGRlZmF1bHQ6CiAgICAgICAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICBzdHJtLm5leHRfb3V0ID0gcHV0OwogICAgICAgIHN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QgOiAwKSArIChzdGF0ZS5tb2RlID09PSBUWVBFID8gMTI4IDogMCkgKyAoc3RhdGUubW9kZSA9PT0gTEVOXyB8fCBzdGF0ZS5tb2RlID09PSBDT1BZXyA/IDI1NiA6IDApOwogICAgICAgIGlmICgoX2luID09PSAwICYmIF9vdXQgPT09IDAgfHwgZmx1c2ggPT09IFpfRklOSVNIKSAmJiByZXQgPT09IFpfT0spIHsKICAgICAgICAgIHJldCA9IFpfQlVGX0VSUk9SOwogICAgICAgIH0KICAgICAgICByZXR1cm4gcmV0OwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVFbmQoc3RybSkgewogICAgICAgIGlmICghc3RybSB8fCAhc3RybS5zdGF0ZSkgewogICAgICAgICAgcmV0dXJuIFpfU1RSRUFNX0VSUk9SOwogICAgICAgIH0KICAgICAgICB2YXIgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmIChzdGF0ZS53aW5kb3cpIHsKICAgICAgICAgIHN0YXRlLndpbmRvdyA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHN0cm0uc3RhdGUgPSBudWxsOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVHZXRIZWFkZXIoc3RybSwgaGVhZCkgewogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICBpZiAoIXN0cm0gfHwgIXN0cm0uc3RhdGUpIHsKICAgICAgICAgIHJldHVybiBaX1NUUkVBTV9FUlJPUjsKICAgICAgICB9CiAgICAgICAgc3RhdGUgPSBzdHJtLnN0YXRlOwogICAgICAgIGlmICgoc3RhdGUud3JhcCAmIDIpID09PSAwKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhlYWQgPSBoZWFkOwogICAgICAgIGhlYWQuZG9uZSA9IGZhbHNlOwogICAgICAgIHJldHVybiBaX09LOwogICAgICB9CiAgICAgIGZ1bmN0aW9uIGluZmxhdGVTZXREaWN0aW9uYXJ5KHN0cm0sIGRpY3Rpb25hcnkpIHsKICAgICAgICB2YXIgZGljdExlbmd0aCA9IGRpY3Rpb25hcnkubGVuZ3RoOwogICAgICAgIHZhciBzdGF0ZTsKICAgICAgICB2YXIgZGljdGlkOwogICAgICAgIHZhciByZXQ7CiAgICAgICAgaWYgKCFzdHJtIHx8ICFzdHJtLnN0YXRlKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlID0gc3RybS5zdGF0ZTsKICAgICAgICBpZiAoc3RhdGUud3JhcCAhPT0gMCAmJiBzdGF0ZS5tb2RlICE9PSBESUNUKSB7CiAgICAgICAgICByZXR1cm4gWl9TVFJFQU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIGlmIChzdGF0ZS5tb2RlID09PSBESUNUKSB7CiAgICAgICAgICBkaWN0aWQgPSAxOwogICAgICAgICAgZGljdGlkID0gYWRsZXIzMihkaWN0aWQsIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIDApOwogICAgICAgICAgaWYgKGRpY3RpZCAhPT0gc3RhdGUuY2hlY2spIHsKICAgICAgICAgICAgcmV0dXJuIFpfREFUQV9FUlJPUjsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmV0ID0gdXBkYXRld2luZG93KHN0cm0sIGRpY3Rpb25hcnksIGRpY3RMZW5ndGgsIGRpY3RMZW5ndGgpOwogICAgICAgIGlmIChyZXQpIHsKICAgICAgICAgIHN0YXRlLm1vZGUgPSBNRU07CiAgICAgICAgICByZXR1cm4gWl9NRU1fRVJST1I7CiAgICAgICAgfQogICAgICAgIHN0YXRlLmhhdmVkaWN0ID0gMTsKICAgICAgICByZXR1cm4gWl9PSzsKICAgICAgfQogICAgICBleHBvcnRzMi5pbmZsYXRlUmVzZXQgPSBpbmZsYXRlUmVzZXQ7CiAgICAgIGV4cG9ydHMyLmluZmxhdGVSZXNldDIgPS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ICAgICBaX0JMT0NLOiA1LAogICAgICAgIFpfVFJFRVM6IDYsCiAgICAgICAgWl9PSzogMCwKICAgICAgICBaX1NUUkVBTV9FTkQ6IDEsCiAgICAgICAgWl9ORUVEX0RJQ1Q6IDIsCiAgICAgICAgWl9FUlJOTzogLTEsCiAgICAgICAgWl9TVFJFQU1fRVJST1I6IC0yLAogICAgICAgIFpfREFUQV9FUlJPUjogLTMsCiAgICAgICAgWl9CVUZfRVJST1I6IC01LAogICAgICAgIFpfTk9fQ09NUFJFU1NJT046IDAsCiAgICAgICAgWl9CRVNUX1NQRUVEOiAxLAogICAgICAgIFpfQkVTVF9DT01QUkVTU0lPTjogOSwKICAgICAgICBaX0RFRkFVTFRfQ09NUFJFU1NJT046IC0xLAogICAgICAgIFpfRklMVEVSRUQ6IDEsCiAgICAgICAgWl9IVUZGTUFOX09OTFk6IDIsCiAgICAgICAgWl9STEU6IDMsCiAgICAgICAgWl9GSVhFRDogNCwKICAgICAgICBaX0RFRkFVTFRfU1RSQVRFR1k6IDAsCiAgICAgICAgWl9CSU5BUlk6IDAsCiAgICAgICAgWl9URVhUOiAxLAogICAgICAgIFpfVU5LTk9XTjogMiwKICAgICAgICBaX0RFRkxBVEVEOiA4CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9wYWtvQDEuMC4xMS9ub2RlX21vZHVsZXMvcGFrby9saWIvemxpYi9nemhlYWRlci5qcwogIHZhciByZXF1aXJlX2d6aGVhZGVyID0gX19jb21tb25KUyh7CiAgICAibm9kZV9tb2R1bGVzLy5wbnBtL3Bha29AMS4wLjExL25vZGVfbW9kdWxlcy9wYWtvL2xpYi96bGliL2d6aGVhZGVyLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgICJ1c2Ugc3RyaWN0IjsKICAgICAgZnVuY3Rpb24gR1poZWFkZXIoKSB7CiAgICAgICAgdGhpcy50ZX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RyaW5nOwogICAgICBmdW5jdGlvbiBJbmZsYXRlMihvcHRpb25zKSB7CiAgICAgICAgaWYgKCEodGhpcyBpbnN0YW5jZW9mIEluZmxhdGUyKSkKICAgICAgICAgIHJldHVybiBuZXcgSW5mbGF0ZTIob3B0aW9ucyk7CiAgICAgICAgdGhpcy5vcHRpb25zID0gdXRpbHMuYXNzaWduKHsKICAgICAgICAgIGNodW5rU2l6ZTogMTYzODQsCiAgICAgICAgICB3aW5kb3dCaXRzOiAwLAogICAgICAgICAgdG86ICIiCiAgICAgICAgfSwgb3B0aW9ucyB8fCB7fSk7CiAgICAgICAgdmFyIG9wdCA9IHRoaXMub3B0aW9uczsKICAgICAgICBpZiAob3B0LnJhdyAmJiBvcHQud2luZG93Qml0cyA+PSAwICYmIG9wdC53aW5kb3dCaXRzIDwgMTYpIHsKICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLW9wdC53aW5kb3dCaXRzOwogICAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID09PSAwKSB7CiAgICAgICAgICAgIG9wdC53aW5kb3dCaXRzID0gLTE1OwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZiAob3B0LndpbmRvd0JpdHMgPj0gMCAmJiBvcHQud2luZG93Qml0cyA8IDE2ICYmICEob3B0aW9ucyAmJiBvcHRpb25zLndpbmRvd0JpdHMpKSB7CiAgICAgICAgICBvcHQud2luZG93Qml0cyArPSAzMjsKICAgICAgICB9CiAgICAgICAgaWYgKG9wdC53aW5kb3dCaXRzID4gMTUgJiYgb3B0LndpbmRvd0JpdHMgPCA0OCkgewogICAgICAgICAgaWYgKChvcHQud2luZG93Qml0cyAmIDE1KSA9PT0gMCkgewogICAgICAgICAgICBvcHQud2luZG93Qml0cyB8PSAxNTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgdGhpcy5lcnIgPSAwOwogICAgICAgIHRoaXMubXNnID0gIiI7CiAgICAgICAgdGhpcy5lbmRlZCA9IGZhbHNlOwogICAg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ogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5wdXNoID0gZnVuY3Rpb24oZGF0YSwgbW9kZSkgewogICAgICAgIHZhciBzdHJtID0gdGhpcy5zdHJtOwogICAgICAgIHZhciBjaHVua1NpemUgPSB0aGlzLm9wdGlvbnMuY2h1bmtTaXplOwogICAgICAgIHZhciBkaWN0aW9uYXJ5ID0gdGhpcy5vcHRpb25zLmRpY3Rpb25hcnk7CiAgICAgICAgdmFyIHN0YXR1cywgX21vZGU7CiAgICAgICAgdmFyIG5leHRfb3V0X3V0ZjgsIHRhaWwsIHV0ZjhzdHI7CiAgICAgICAgdmFyIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICBpZiAodGhpcy5lbmRlZCkgewogICAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICAgIH0KICAgICAgICBfbW9kZSA9IG1vZGUgPT09IH5+bW9kZSA/IG1vZGUgOiBtb2RlID09PSB0cnVlID8gYy5aX0ZJTklTSCA6IGMuWl9OT19GTFVTSDsKICAgICAgICBpZiAodHlwZW9mIGRhdGEgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gc3RyaW5ncy5iaW5zdHJpbmcyYnVmKGRhdGEpOwogICAgICAgIH0gZWxzZSBpZiAodG9TdHJpbmcuY2FsbChkYXRhKSA9PT0gIltvYmplY3QgQXJyYXlCdWZmZXJdIikgewogICAgICAgICAgc3RybS5pbnB1dCA9IG5ldyBVaW50OEFycmF5KGRhdGEpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBzdHJtLmlucHV0ID0gZGF0YTsKICAgICAgICB9CiAgICAgICAgc3RybS5uZXh0X2luID0gMDsKICAgICAgICBzdHJtLmF2YWlsX2luID0gc3RybS5pbnB1dC5sZW5ndGg7CiAgICAgICAgZG8gewogICAgICAgICAgaWYgKHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIHN0cm0ub3V0cHV0ID0gbmV3IHV0aWxzLkJ1ZjgoY2h1bmtTaXplKTsKICAgICAgICAgICAgc3RybS5uZXh0X291dCA9IDA7CiAgICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gY2h1bmtTaXplOwogICAgICAgICAgfQogICAgICAgICAgc3RhdHVzID0gemxpYl9pbmZsYXRlLmluZmxhdGUoc3RybSwgYy5aX05PX0ZMVVNIKTsKICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9ORUVEX0RJQ1QgJiYgZGljdGlvbmFyeSkgewogICAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZVNldERpY3Rpb25hcnkodGhpcy5zdHJtLCBkaWN0aW9uYXJ5KTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9CVUZfRVJST1IgJiYgYWxsb3dCdWZFcnJvciA9PT0gdHJ1ZSkgewogICAgICAgICAgICBzdGF0dXMgPSBjLlpfT0s7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdGF0dXMgIT09IGMuWl9TVFJFQU1fRU5EICYmIHN0YXR1cyAhPT0gYy5aX09LKSB7CiAgICAgICAgICAgIHRoaXMub25FbmQoc3RhdHVzKTsKICAgICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLm5leHRfb3V0KSB7CiAgICAgICAgICAgIGlmIChzdHJtLmF2YWlsX291dCA9PT0gMCB8fCBzdGF0dXMgPT09IGMuWl9TVFJFQU1fRU5EIHx8IHN0cm0uYXZhaWxfaW4gPT09IDAgJiYgKF9tb2RlID09PSBjLlpfRklOSVNIIHx8IF9tb2RlID09PSBjLlpfU1lOQ19GTFVTSCkpIHsKICAgICAgICAgICAgICBpZiAodGhpcy5vcHRpb25zLnRvID09PSAic3RyaW5nIikgewogICAgICAgICAgICAgICAgbmV4dF9vdXRfdXRmOCA9IHN0cmluZ3MudXRmOGJvcmRlcihzdHJtLm91dHB1dCwgc3RybS5uZXh0X291dCk7CiAgICAgICAgICAgICAgICB0YWlsID0gc3RybS5uZXh0X291dCAtIG5leHRfb3V0X3V0Zjg7CiAgICAgICAgICAgICAgICB1dGY4c3RyID0gc3RyaW5ncy5idWYyc3RyaW5nKHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4KTsKICAgICAgICAgICAgICAgIHN0cm0ubmV4dF9vdXQgPSB0YWlsOwogICAgICAgICAgICAgICAgc3RybS5hdmFpbF9vdXQgPSBjaHVua1NpemUgLSB0YWlsOwogICAgICAgICAgICAgICAgaWYgKHRhaWwpIHsKICAgICAgICAgICAgICAgICAgdXRpbHMuYXJyYXlTZXQoc3RybS5vdXRwdXQsIHN0cm0ub3V0cHV0LCBuZXh0X291dF91dGY4LCB0YWlsLCAwKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHRoaXMub25EYXRhKHV0ZjhzdHIpOwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICB0aGlzLm9uRGF0YSh1dGlscy5zaHJpbmtCdWYoc3RybS5vdXRwdXQsIHN0cm0ubmV4dF9vdXQpKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzdHJtLmF2YWlsX2luID09PSAwICYmIHN0cm0uYXZhaWxfb3V0ID09PSAwKSB7CiAgICAgICAgICAgIGFsbG93QnVmRXJyb3IgPSB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0gd2hpbGUgKChzdHJtLmF2YWlsX2luID4gMCB8fCBzdHJtLmF2YWlsX291dCA9PT0gMCkgJiYgc3RhdHVzICE9PSBjLlpfU1RSRUFNX0VORCk7CiAgICAgICAgaWYgKHN0YXR1cyA9PT0gYy5aX1NUUkVBTV9FTkQpIHsKICAgICAgICAgIF9tb2RlID0gYy5aX0ZJTklTSDsKICAgICAgICB9CiAgICAgICAgaWYgKF9tb2RlID09PSBjLlpfRklOSVNIKSB7CiAgICAgICAgICBzdGF0dXMgPSB6bGliX2luZmxhdGUuaW5mbGF0ZUVuZCh0aGlzLnN0cm0pOwogICAgICAgICAgdGhpcy5vbkVuZChzdGF0dXMpOwogICAgICAgICAgdGhpcy5lbmRlZCA9IHRydWU7CiAgICAgICAgICByZXR1cm4gc3RhdHVzID09PSBjLlpfT0s7CiAgICAgICAgfQogICAgICAgIGlmIChfbW9kZSA9PT0gYy5aX1NZTkNfRkxVU0gpIHsKICAgICAgICAgIHRoaXMub25FbmQoYy5aX09LKTsKICAgICAgICAgIHN0cm0uYXZhaWxfb3V0ID0gMDsKICAgICAgICAgIHJldHVybiB0cnVlOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdHJ1ZTsKICAgICAgfTsKICAgICAgSW5mbGF0ZTIucHJvdG90eXBlLm9uRGF0YSA9IGZ1bmN0aW9uKGNodW5rKSB7CiAgICAgICAgdGhpcy5jaHVua3MucHVzaChjaHVuayk7CiAgICAgIH07CiAgICAgIEluZmxhdGUyLnByb3RvdHlwZS5vbkVuZCA9IGZ1bmN0aW9uKHN0YXR1cykgewogICAgICAgIGlmIChzdGF0dXMgPT09IGMuWl9PSykgewogICAgICAgICAgaWYgKHRoaXMub3B0aW9ucy50byA9PT0gInN0cmluZyIpIHsKICAgICAgICAgICAgdGhpcy5yZXN1bHQgPSB0aGlzLmNodW5rcy5qb2luKCIiKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRoaXMucmVzdWx0ID0gdXRpbHMuZmxhdHRlbkNodW5rcyh0aGlzLmNodW5rcyk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHRoaXMuY2h1bmtzID0gW107CiAgICAgICAgdGhpcy5lcnIgPSBzdGF0dXM7CiAgICAgICAgdGhpcy5tc2cgPSB0aG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bigpLmFzc2lnbjsKICAgICAgdmFyIGRlZmxhdGUgPSByZXF1aXJlX2RlZmxhdGUyKCk7CiAgICAgIHZhciBpbmZsYXRlID0gcmVxdWlyZV9pbmZsYXRlMigpOwogICAgICB2YXIgY29uc3RhbnRzID0gcmVxdWlyZV9jb25zdGFudHMoKTsKICAgICAgdmFyIHBha28gPSB7fTsKICAgICAgYXNzaWduKHBha28sIGRlZmxhdGUsIGluZmxhdGUsIGNvbnN0YW50cyk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IHBha287CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzCiAgdmFyIHJlcXVpcmVfbG9uZyA9IF9fY29tbW9uSlMoewogICAgIm5vZGVfbW9kdWxlcy8ucG5wbS9sb25nQDQuMC4wL25vZGVfbW9kdWxlcy9sb25nL3NyYy9sb25nLmpzIihleHBvcnRzMiwgbW9kdWxlMikgewogICAgICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgICAgIG1vZHVsZTIuZXhwb3J0cyA9IExvbmc0OwogICAgICB2YXIgd2FzbSA9IG51bGw7CiAgICAgIHRyeSB7CiAgICAgICAgd2FzbSA9IG5ldyBXZWJBc3NlbWJseS5JbnN0YW5jZShuZXcgV2ViQXNzZW1ibHkuTW9kdWxlKG5ldyBVaW50OEFycmF5KFsKICAgICAgICAgIDAsCiAgICAgICAgICA5NywKICAgICAgICAgIDExNSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDEsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgMTMsCiAgICAgICAgICAyLAogICAgICAgICAgOTYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNywKICAgICAgICAgIDk2LAogICAgICAgICAgNCwKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEyNywKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAzLAogICAgICAgICAgNywKICAgICAgICAgIDYsCiAgICAgICAgICAwLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEsCiAgICAgICAgICA2LAogICAgICAgICAgNiwKICAgICAgICAgIDEsCiAgICAgICAgICAxMjcsCiAgICAgICAgICAxLAogICAgICAgICAgNjUsCiAgICAgICAgICAwLAogICAgICAgICAgMTEsCiAgICAgICAgICA3LAogICAgICAgICAgNTAsCiAgICAgICAgICA2LAogICAgICAgICAgMywKICAgICAgICAgIDEwOSwKICAgICAgICAgIDExNywKICAgICAgICAgIDEwOCwKICAgICAgICAgIDAsCiAgICAgICAgICAxLAogICAgICAgICAgNSwKICAgICAgICAgIDEwMCwKICAgICAgICAgIDEwNSwKICAgICAgICAgIDExOCwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE1LAogICAgICAgICAgMCwKICAgICAgICAgIDIsCiAgICAgICAgICA1LAogICAgICAgICAgMTAwLAogICAgICAgICAgMTA1LAogICAgICAgICAgMTE4LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMTcsCiAgICAgICAgICAwLAogICAgICAgICAgMywKICAgICAgICAgIDUsCiAgICAgICAgICAxMTQsCiAgICAgICAgICAxMDEsCiAgICAgICAgICAxMDksCiAgICAgICAgICA5NSwKICAgICAgICAgIDExNSwKICAgICAgICAgIDAsCiAgICAgICAgICA0LAogICAgICAgICAgNSwKICAgICAgICAgIDExNCwKICAgICAgICAgIDEwMSwKICAgICAgICAgIDEwOSwKICAgICAgICAgIDk1LAogICAgICAgICAgMTE3LAogICAgICAgICAgMCwKICAgICAgICAgIDUsCiAgICAgICAgICA4LAogICAgICAgICAgMTAzLAogICAgICAgICAgMTAxLAogICAgICAgICAgMTE2LAogICAgICAgICAgOTUsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAxMDUsCiAgICAgICAgICAxMDMsCiAgICAgICAgICAxMDQsCiAgICAgICAgICAwLAogICAgICAgICAgMCwKICAgICAgICAgIDEwLAogICAgICAgICAgMTkxLAogICAgICAgICAgMSwKICAgICAgICAgIDYsCiAgICAgICAgICA0LAogICAgICAgICAgMCwKICAgICAgICAgIDM1LAogICAgICAgICAgMCwKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI2LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI3LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI4LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTI5LAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExLAogICAgICAgICAgMzYsCiAgICAgICAgICAxLAogICAgICAgICAgMSwKICAgICAgICAgIDEyNiwKICAgICAgICAgIDMyLAogICAgICAgICAgMCwKICAgICAgICAgIDE3MywKICAgICAgICAgIDMyLAogICAgICAgICAgMSwKICAgICAgICAgIDE3MywKICAgICAgICAgIDY2LAogICAgICAgICAgMzIsCiAgICAgICAgICAxMzQsCiAgICAgICAgICAxMzIsCiAgICAgICAgICAzMiwKICAgICAgICAgIDIsCiAgICAgICAgICAxNzMsCiAgICAgICAgICAzMiwKICAgICAgICAgIDMsCiAgICAgICAgICAxNzMsCiAgICAgICAgICA2NiwKICAgICAgICAgIDMyLAogICAgICAgICAgMTM0LAogICAgICAgICAgMTMyLAogICAgICAgICAgMTMwLAogICAgICAgICAgMzQsCiAgICAgICAgICA0LAogICAgICAgICAgNjYsCiAgICAgICAgICAzMiwKICAgICAgICAgIDEzNSwKICAgICAgICAgIDE2NywKICAgICAgICAgIDM2LAogICAgICAgICAgMCwKICAgICAgICAgIDMyLAogICAgICAgICAgNCwKICAgICAgICAgIDE2NywKICAgICAgICAgIDExCiAgICAgICAgXSkpLCB7fSkuZXhwb3J0czsKICAgICAgfSBjYXRjaCAoZSkgewogICAgICB9CiAgICAgIGZ1bmN0aW9uIExvbmc0KGxvdywgaGlnaCwgdW5zaWduZWQpIHsKICAgICAgICB0aGlzLmxvdyA9IGxvdyB8IDA7CiAgICAgICAgdGhpcy5oaWdoID0gaGlnaCB8IDA7CiAgICAgICAgdGhpcy51bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgIH0KICAgICAgTG9uZzQucHJvdG90eXBlLl9faXNMb25nX187CiAgICAgIE9iamVjdC5kZWZpbmVQcm9wZXJ0eShMb25nNC5wcm90b3R5cGUsICJfX2lzTG9uZ19fIiwgeyB2YWx1ZTogdHJ1ZSB9KTsKICAgICAgZnVuY3Rpb24gaXNMb25nKG9iaikgewogICAgICAgIHJldHVybiAob2JqICYmIG9ialsiX19pc0xvbmdfXyJdKSA9PT0gdHJ1ZTsKICAgICAgfQogICAgICBMb25nNC5pc0xvbmcgPSBpc0xvbmc7CiAgICAgIHZhciBJTlRfQ0FDSEUgPSB7fTsKICAgICAgdmFyIFVJTlRfQ0FDSEUgPSB7fTsKICAgICAgZnVuY3Rpb24gZnJvbUludCh2YWx1ZSwgdW5zaWduZWQpIHsKICAgICAgICB2YXIgb2JqLCBjYWNoZWRPYmosIGNhY2hlOwogICAgICAgIGlmICh1bnNpZ25lZCkgewogICAgICAgICAgdmFsdWUgPj4+PSAwOwogICAgICAgICAgaWYgKGNhY2hlID0gMCA8PSB2YWx1ZSAmJiB2YWx1ZSA8IDI1NikgewogICAgICAgICAgICBjYWNoZWRPYmogPSBVSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsICh2YWx1ZSB8IDApIDwgMCA/IC0xIDogMCwgdHJ1ZSk7CiAgICAgICAgICBpZiAoY2FjaGUpCiAgICAgICAgICAgIFVJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFsdWUgfD0gMDsKICAgICAgICAgIGlmIChjYWNoZSA9IC0xMjggPD0gdmFsdWUgJiYgdmFsdWUgPCAxMjgpIHsKICAgICAgICAgICAgY2FjaGVkT2JqID0gSU5UX0NBQ0hFW3ZhbHVlXTsKICAgICAgICAgICAgaWYgKGNhY2hlZE9iaikKICAgICAgICAgICAgICByZXR1cm4gY2FjaGVkT2JqOwogICAgICAgICAgfQogICAgICAgICAgb2JqID0gZnJvbUJpdHModmFsdWUsIHZhbHVlIDwgMCA/IC0xIDogMCwgZmFsc2UpOwogICAgICAgICAgaWYgKGNhY2hlKQogICAgICAgICAgICBJTlRfQ0FDSEVbdmFsdWVdID0gb2JqOwogICAgICAgICAgcmV0dXJuIG9iajsKICAgICAgICB9CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbUludCA9IGZyb21JbnQ7CiAgICAgIGZ1bmN0aW9uIGZyb21OdW1iZXIodmFsdWUsIHVuc2lnbmVkKSB7CiAgICAgICAgaWYgKGlzTmFOKHZhbHVlKSkKICAgICAgICAgIHJldHVybiB1bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICBpZiAodW5zaWduZWQpIHsKICAgICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICAgIHJldHVybiBVWkVSTzsKICAgICAgICAgIGlmICh2YWx1ZSA+PSBUV09fUFdSXzY0X0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1BWF9VTlNJR05FRF9WQUxVRTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgaWYgKHZhbHVlIDw9IC1UV09fUFdSXzYzX0RCTCkKICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgIGlmICh2YWx1ZSArIDEgPj0gVFdPX1BXUl82M19EQkwpCiAgICAgICAgICAgIHJldHVybiBNQVhfVkFMVUU7CiAgICAgICAgfQogICAgICAgIGlmICh2YWx1ZSA8IDApCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcigtdmFsdWUsIHVuc2lnbmVkKS5uZWcoKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsdWUgJSBUV09fUFdSXzMyX0RCTCB8IDAsIHZhbHVlIC8gVFdPX1BXUl8zMl9EQkwgfCAwLCB1bnNpZ25lZCk7CiAgICAgIH0KICAgICAgTG9uZzQuZnJvbU51bWJlciA9IGZyb21OdW1iZXI7CiAgICAgIGZ1bmN0aW9uIGZyb21CaXRzKGxvd0JpdHMsIGhpZ2hCaXRzLCB1bnNpZ25lZCkgewogICAgICAgIHJldHVybiBuZXcgTG9uZzQobG93Qml0cywgaGlnaEJpdHMsIHVuc2lnbmVkKTsKICAgICAgfQogICAgICBMb25nNC5mcm9tQml0cyA9IGZyb21CaXRzOwogICAgICB2YXIgcG93X2RibCA9IE1hdGgucG93OwogICAgICBmdW5jdGlvbiBmcm9tU3RyaW5nKHN0ciwgdW5zaWduZWQsIHJhZGl4KSB7CiAgICAgICAgaWYgKHN0ci5sZW5ndGggPT09IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiZW1wdHkgc3RyaW5nIik7CiAgICAgICAgaWYgKHN0ciA9PT0gIk5hTiIgfHwgc3RyID09PSAiSW5maW5pdHkiIHx8IHN0ciA9PT0gIitJbmZpbml0eSIgfHwgc3RyID09PSAiLUluZmluaXR5IikKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0eXBlb2YgdW5zaWduZWQgPT09ICJudW1iZXIiKSB7CiAgICAgICAgICByYWRpeCA9IHVuc2lnbmVkLCB1bnNpZ25lZCA9IGZhbHNlOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICB1bnNpZ25lZCA9ICEhdW5zaWduZWQ7CiAgICAgICAgfQogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICB2YXIgcDsKICAgICAgICBpZiAoKHAgPSBzdHIuaW5kZXhPZigiLSIpKSA+IDApCiAgICAgICAgICB0aHJvdyBFcnJvcigiaW50ZXJpb3IgaHlwaGVuIik7CiAgICAgICAgZWxzZSBpZiAocCA9PT0gMCkgewogICAgICAgICAgcmV0dXJuIGZyb21TdHJpbmcoc3RyLnN1YnN0cmluZygxKSwgdW5zaWduZWQsIHJhZGl4KS5uZWcoKTsKICAgICAgICB9CiAgICAgICAgdmFyIHJhZGl4VG9Qb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgOCkpOwogICAgICAgIHZhciByZXN1bHQgPSBaRVJPOwogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwgc3RyLmxlbmd0aDsgaSArPSA4KSB7CiAgICAgICAgICB2YXIgc2l6ZSA9IE1hdGgubWluKDgsIHN0ci5sZW5ndGggLSBpKSwgdmFsdWUgPSBwYXJzZUludChzdHIuc3Vic3RyaW5nKGksIGkgKyBzaXplKSwgcmFkaXgpOwogICAgICAgICAgaWYgKHNpemUgPCA4KSB7CiAgICAgICAgICAgIHZhciBwb3dlciA9IGZyb21OdW1iZXIocG93X2RibChyYWRpeCwgc2l6ZSkpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQubXVsKHBvd2VyKS5hZGQoZnJvbU51bWJlcih2YWx1ZSkpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcmVzdWx0ID0gcmVzdWx0Lm11bChyYWRpeFRvUG93ZXIpOwogICAgICAgICAgICByZXN1bHQgPSByZXN1bHQuYWRkKGZyb21OdW1iZXIodmFsdWUpKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgcmVzdWx0LnVuc2lnbmVkID0gdW5zaWduZWQ7CiAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgfQogICAgICBMb25nNC5mcm9tU3RyaW5nID0gZnJvbVN0cmluZzsKICAgICAgZnVuY3Rpb24gZnJvbVZhbHVlKHZhbCwgdW5zaWduZWQpIHsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gIm51bWJlciIpCiAgICAgICAgICByZXR1cm4gZnJvbU51bWJlcih2YWwsIHVuc2lnbmVkKTsKICAgICAgICBpZiAodHlwZW9mIHZhbCA9PT0gInN0cmluZyIpCiAgICAgICAgICByZXR1cm4gZnJvbVN0cmluZyh2YWwsIHVuc2lnbmVkKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModmFsLmxvdywgdmFsLmhpZ2gsIHR5cGVvZiB1bnNpZ25lZCA9PT0gImJvb2xlYW4iID8gdW5zaWduZWQgOiB2YWwudW5zaWduZWQpOwogICAgICB9CiAgICAgIExvbmc0LmZyb21WYWx1ZSA9IGZyb21WYWx1ZTsKICAgICAgdmFyIFRXT19QV1JfMTZfREJMID0gMSA8PCAxNjsKICAgICAgdmFyIFRXT19QV1JfMjRfREJMID0gMSA8PCAyNDsKICAgICAgdmFyIFRXT19QV1JfMzJfREJMID0gVFdPX1BXUl8xNl9EQkwgKiBUV09fUFdSXzE2X0RCTDsKICAgICAgdmFyIFRXT19QV1JfNjRfREJMID0gVFdPX1BXUl8zMl9EQkwgKiBUV09fUFdSXzMyX0RCTDsKICAgICAgdmFyIFRXT19QV1JfNjNfREJMID0gVFdPX1BXUl82NF9EQkwgLyAyOwogICAgICB2YXIgVFdPX1BXUl8yNCA9IGZyb21JbnQoVFdPX1BXUl8yNF9EQkwpOwogICAgICB2YXIgWkVSTyA9IGZyb21JbnQoMCk7CiAgICAgIExvbmc0LlpFUk8gPSBaRVJPOwogICAgICB2YXIgVVpFUk8gPSBmcm9tSW50KDAsIHRydWUpOwogICAgICBMb25nNC5VWkVSTyA9IFVaRVJPOwogICAgICB2YXIgT05FID0gZnJvbUludCgxKTsKICAgICAgTG9uZzQuT05FID0gT05FOwogICAgICB2YXIgVU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mdQcm90b3R5cGUudG9TdHJpbmcgPSBmdW5jdGlvbiB0b1N0cmluZyhyYWRpeCkgewogICAgICAgIHJhZGl4ID0gcmFkaXggfHwgMTA7CiAgICAgICAgaWYgKHJhZGl4IDwgMiB8fCAzNiA8IHJhZGl4KQogICAgICAgICAgdGhyb3cgUmFuZ2VFcnJvcigicmFkaXgiKTsKICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiAiMCI7CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAodGhpcy5lcShNSU5fVkFMVUUpKSB7CiAgICAgICAgICAgIHZhciByYWRpeExvbmcgPSBmcm9tTnVtYmVyKHJhZGl4KSwgZGl2ID0gdGhpcy5kaXYocmFkaXhMb25nKSwgcmVtMSA9IGRpdi5tdWwocmFkaXhMb25nKS5zdWIodGhpcyk7CiAgICAgICAgICAgIHJldHVybiBkaXYudG9TdHJpbmcocmFkaXgpICsgcmVtMS50b0ludCgpLnRvU3RyaW5nKHJhZGl4KTsKICAgICAgICAgIH0gZWxzZQogICAgICAgICAgICByZXR1cm4gIi0iICsgdGhpcy5uZWcoKS50b1N0cmluZyhyYWRpeCk7CiAgICAgICAgfQogICAgICAgIHZhciByYWRpeFRvUG93ZXIgPSBmcm9tTnVtYmVyKHBvd19kYmwocmFkaXgsIDYpLCB0aGlzLnVuc2lnbmVkKSwgcmVtID0gdGhpczsKICAgICAgICB2YXIgcmVzdWx0ID0gIiI7CiAgICAgICAgd2hpbGUgKHRydWUpIHsKICAgICAgICAgIHZhciByZW1EaXYgPSByZW0uZGl2KHJhZGl4VG9Qb3dlciksIGludHZhbCA9IHJlbS5zdWIocmVtRGl2Lm11bChyYWRpeFRvUG93ZXIpKS50b0ludCgpID4+PiAwLCBkaWdpdHMgPSBpbnR2YWwudG9TdHJpbmcocmFkaXgpOwogICAgICAgICAgcmVtID0gcmVtRGl2OwogICAgICAgICAgaWYgKHJlbS5pc1pl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c7CiAgICAgICAgZm9yICh2YXIgYml0ID0gMzE7IGJpdCA+IDA7IGJpdC0tKQogICAgICAgICAgaWYgKCh2YWwgJiAxIDw8IGJpdCkgIT0gMCkKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgcmV0dXJuIHRoaXMuaGlnaCAhPSAwID8gYml0ICsgMzMgOiBiaXQgKyAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzWmVybyA9IGZ1bmN0aW9uIGlzWmVybygpIHsKICAgICAgICByZXR1cm4gdGhpcy5oaWdoID09PSAwICYmIHRoaXMubG93ID09PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmVxeiA9IExvbmdQcm90b3R5cGUuaXNaZXJvOwogICAgICBMb25nUHJvdG90eXBlLmlzTmVnYXRpdmUgPSBmdW5jdGlvbiBpc05lZ2F0aXZlKCkgewogICAgICAgIHJldHVybiAhdGhpcy51bnNpZ25lZCAmJiB0aGlzLmhpZ2ggPCAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzUG9zaXRpdmUgPSBmdW5jdGlvbiBpc1Bvc2l0aXZlKCkgewogICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkIHx8IHRoaXMuaGlnaCA+PSAwOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzT2RkID0gZnVuY3Rpb24gaXNPZGQoKSB7CiAgICAgICAgcmV0dXJuICh0aGlzLmxvdyAmIDEpID09PSAxOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmlzRXZlbiA9IGZ1bmN0aW9uIGlzRXZlbigpIHsKICAgICAgICByZXR1cm4gKHRoaXMubG93ICYgMSkgPT09IDA7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUuZXF1YWxzID0gZnVuY3Rpb24gZXF1YWxzKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogIC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ExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW4gPSBmdW5jdGlvbiBncmVhdGVyVGhhbihvdGhlcikgewogICAgICAgIHJldHVybiB0aGlzLmNvbXAob3RoZXIpID4gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5ndCA9IExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW47CiAgICAgIExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW5PckVxdWFsID0gZnVuY3Rpb24gZ3JlYXRlclRoYW5PckVxdWFsKG90aGVyKSB7CiAgICAgICAgcmV0dXJuIHRoaXMuY29tcChvdGhlcikgPj0gMDsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5ndGUgPSBMb25nUHJvdG90eXBlLmdyZWF0ZXJUaGFuT3JFcXVhbDsKICAgICAgTG9uZ1Byb3RvdHlwZS5nZSA9IExvbmdQcm90b3R5cGUuZ3JlYXRlclRoYW5PckVxdWFsOwogICAgICBMb25nUHJvdG90eXBlLmNvbXBhcmUgPSBmdW5jdGlvbiBjb21wYXJlKG90aGVyKSB7CiAgICAgICAgaWYgKCFpc0xvbmcob3RoZXIpKQogICAgICAgICAgb3RoZXIgPSBmcm9tVmFsdWUob3RoZXIpOwogICAgICAgIGlmICh0aGlzLmVxKG90aGVyKSkKICAgICAgICAgIHJldHVybiAwOwogICAgICAgIHZhciB0aGlzTmVnID0gdGhpcy5pc05lZ2F0aXZlKCksIG90aGVyTmVnID0gb3RoZXIuaXNOZWdhdGl2ZSgpOwogICAgICAgIGlmICh0aGlzTmVnICYmICFvdGhlck5lZykKICAgICAgICAgIHJldHVybiAtMTsKICAgICAgICBpZiAoIXRoaXNOZWcgJiYgb3RoZXJOZWcpCiAgICAgICAgICByZXR1cm4gMTsKICAgICAgICBpZiAoIXRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpcy5zdWIob3RoZXIpLmlzTmVnYXRpdmUoKSA/IC0xIDogMTsKICAgICAgICByZXR1cm4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gICB2YXIgbG93ID0gd2FzbS5tdWwodGhpcy5sb3csIHRoaXMuaGlnaCwgbXVsdGlwbGllci5sb3csIG11bHRpcGxpZXIuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAobXVsdGlwbGllci5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiBaRVJPOwogICAgICAgIGlmICh0aGlzLmVxKE1JTl9WQUxVRSkpCiAgICAgICAgICByZXR1cm4gbXVsdGlwbGllci5pc09kZCgpID8gTUlOX1ZBTFVFIDogWkVSTzsKICAgICAgICBpZiAobXVsdGlwbGllci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgcmV0dXJuIHRoaXMuaXNPZGQoKSA/IE1JTl9WQUxVRSA6IFpFUk87CiAgICAgICAgaWYgKHRoaXMuaXNOZWdhdGl2ZSgpKSB7CiAgICAgICAgICBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgIHJldHVybiB0aGlzLm5lZygpLm11bChtdWx0aXBsaWVyLm5lZygpKTsKICAgICAgICAgIGVsc2UKICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkubXVsKG11bHRpcGxpZXIpLm5lZygpOwogICAgICAgIH0gZWxzZSBpZiAobXVsdGlwbGllci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICByZXR1cm4gdGhpcy5tdWwobXVsdGlwbGllci5uZWcoKSkubmVnKCk7CiAgICAgICAgaWYgKHRoaXMubHQoVFdPX1BXUl8yNCkgJiYgbXVsdGlwbGllci5sdChUV09fUFdSXzI0KSkKICAgICAgICAgIHJldHVybiBmcm9tTnVtYmVyKHRoaXMudG9OdW1iZXIoKSAqIG11bHRpcGxpZXIudG9OdW1iZXIoKSwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgdmFyIGE0OCA9IHRoaXMuaGlnaCA+Pj4gMTY7Ci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ICAgICAgICBjNDggJj0gNjU1MzU7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKGMxNiA8PCAxNiB8IGMwMCwgYzQ4IDw8IDE2IHwgYzMyLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tdWwgPSBMb25nUHJvdG90eXBlLm11bHRpcGx5OwogICAgICBMb25nUHJvdG90eXBlLmRpdmlkZSA9IGZ1bmN0aW9uIGRpdmlkZShkaXZpc29yKSB7CiAgICAgICAgaWYgKCFpc0xvbmcoZGl2aXNvcikpCiAgICAgICAgICBkaXZpc29yID0gZnJvbVZhbHVlKGRpdmlzb3IpOwogICAgICAgIGlmIChkaXZpc29yLmlzWmVybygpKQogICAgICAgICAgdGhyb3cgRXJyb3IoImRpdmlzaW9uIGJ5IHplcm8iKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgaWYgKCF0aGlzLnVuc2lnbmVkICYmIHRoaXMuaGlnaCA9PT0gLTIxNDc0ODM2NDggJiYgZGl2aXNvci5sb3cgPT09IC0xICYmIGRpdmlzb3IuaGlnaCA9PT0gLTEpIHsKICAgICAgICAgICAgcmV0dXJuIHRoaXM7CiAgICAgICAgICB9CiAgICAgICAgICB2YXIgbG93ID0gKHRoaXMudW5zaWduZWQgPyB3YXNtLmRpdl91IDogd2FzbS5kaXZfcykodGhpcy5sb3csIHRoaXMuaGlnaCwgZGl2aXNvci5sb3csIGRpdmlzb3IuaGlnaCk7CiAgICAgICAgICByZXR1cm4gZnJvbUJpdHMobG93LCB3YXNtLmdldF9oaWdoKCksIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgICBpZiAodGhpcy5pc1plcm8oKSkKICAgICAgICAgIHJldHVybiB0aGlzLnVuc2lnbmVkID8gVVpFUk8gOiBaRVJPOwogICAgICAgIHZhciBhcHByb3gsIHJlbSwgcmVzOwogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkgewogICAgICAgICAgaWYgKHRoaXMuZXEoTUlOX1ZBTFVFKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5lcShPTkUpIHx8IGRpdmlzb3IuZXEoTkVHX09ORSkpCiAgICAgICAgICAgICAgcmV0dXJuIE1JTl9WQUxVRTsKICAgICAgICAgICAgZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICAgIHJldHVybiBPTkU7CiAgICAgICAgICAgIGVsc2UgewogICAgICAgICAgICAgIHZhciBoYWxmVGhpcyA9IHRoaXMuc2hyKDEpOwogICAgICAgICAgICAgIGFwcHJveCA9IGhhbGZUaGlzLmRpdihkaXZpc29yKS5zaGwoMSk7CiAgICAgICAgICAgICAgaWYgKGFwcHJveC5lcShaRVJPKSkgewogICAgICAgICAgICAgICAgcmV0dXJuIGRpdmlzb3IuaXNOZWdhdGl2ZSgpID8gT05FIDogTkVHX09ORTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcmVtID0gdGhpcy5zdWIoZGl2aXNvci5tdWwoYXBwcm94KSk7CiAgICAgICAgICAgICAgICByZXMgPSBhcHByb3guYWRkKHJlbS5kaXYoZGl2aXNvcikpOwogICAgICAgICAgICAgICAgcmV0dXJuIHJlczsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZGl2aXNvci5lcShNSU5fVkFMVUUpKQogICAgICAgICAgICByZXR1cm4gdGhpcy51bnNpZ25lZCA/IFVaRVJPIDogWkVSTzsKICAgICAgICAgIGlmICh0aGlzLmlzTmVnYXRpdmUoKSkgewogICAgICAgICAgICBpZiAoZGl2aXNvci5pc05lZ2F0aXZlKCkpCiAgICAgICAgICAgICAgcmV0dXJuIHRoaXMubmVnKCkuZGl2KGRpdmlzb3IubmVnKCkpOwogICAgICAgICAgICByZXR1cm4gdGhpcy5uZWcoKS5kaXYoZGl2aXNvcikubmVnKCk7CiAgICAgICAgICB9IGVsc2UgaWYgKGRpdmlzb3IuaXNOZWdhdGl2ZSgpKQogICAgICAgICAgICByZXR1cm4gdGhpcy5kaXYoZGl2aXNvci5uZWcoKSkubmVnKCk7CiAgICAgICAgICByZXMgPSBaRVJPOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoIWRpdmlzb3IudW5zaWduZWQpCiAgICAgICAgICAgIGRpdmlzb3IgPSBkaXZpc29yLnRvVW5zaWduZWQoKTsKICAgICAgICAgIGlmIChkaXZpc29yLmd0KHRoaXMpKQogICAgICAgICAgICByZXR1cm4gVVpFUk87CiAgICAgICAgICBpZiAoZGl2aXNvci5ndCh0aGlzLnNocnUoMSkpKQogICAgICAgICAgICByZXR1cm4gVU9ORTsKICAgICAgICAgIHJlcyA9IFVaRVJPOwogICAgICAgIH0KICAgICAgICByZW0gPSB0aGlzOwogICAgICAgIHdoaWxlIChyZW0uZ3RlKGRpdmlzb3IpKSB7CiAgICAgICAgICBhcHByb3ggPSBNYXRoLm1heCgxLCBNYXRoLmZsb29yKHJlbS50b051bWJlcigpIC8gZGl2aXNvci50b051bWJlcigpKSk7CiAgICAgICAgICB2YXIgbG9nMiA9IE1hdGguY2VpbChNYXRoLmxvZyhhcHByb3gpIC8gTWF0aC5MTjIpLCBkZWx0YSA9IGxvZzIgPD0gNDggPyAxIDogcG93X2RibCgyLCBsb2cyIC0gNDgpLCBhcHByb3hSZXMgPSBmcm9tTnVtYmVyKGFwcHJveCksIGFwcHJveFJlbSA9IGFwcHJveFJlcy5tdWwoZGl2aXNvcik7CiAgICAgICAgICB3aGlsZSAoYXBwcm94UmVtLmlzTmVnYXRpdmUoKSB8fCBhcHByb3hSZW0uZ3QocmVtKSkgewogICAgICAgICAgICBhcHByb3ggLT0gZGVsdGE7CiAgICAgICAgICAgIGFwcHJveFJlcyA9IGZyb21OdW1iZXIoYXBwcm94LCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICAgICAgYXBwcm94UmVtID0gYXBwcm94UmVzLm11bChkaXZpc29yKTsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChhcHByb3hSZXMuaXNaZXJvKCkpCiAgICAgICAgICAgIGFwcHJveFJlcyA9IE9ORTsKICAgICAgICAgIHJlcyA9IHJlcy5hZGQoYXBwcm94UmVzKTsKICAgICAgICAgIHJlbSA9IHJlbS5zdWIoYXBwcm94UmVtKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHJlczsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5kaXYgPSBMb25nUHJvdG90eXBlLmRpdmlkZTsKICAgICAgTG9uZ1Byb3RvdHlwZS5tb2R1bG8gPSBmdW5jdGlvbiBtb2R1bG8oZGl2aXNvcikgewogICAgICAgIGlmICghaXNMb25nKGRpdmlzb3IpKQogICAgICAgICAgZGl2aXNvciA9IGZyb21WYWx1ZShkaXZpc29yKTsKICAgICAgICBpZiAod2FzbSkgewogICAgICAgICAgdmFyIGxvdyA9ICh0aGlzLnVuc2lnbmVkID8gd2FzbS5yZW1fdSA6IHdhc20ucmVtX3MpKHRoaXMubG93LCB0aGlzLmhpZ2gsIGRpdmlzb3IubG93LCBkaXZpc29yLmhpZ2gpOwogICAgICAgICAgcmV0dXJuIGZyb21CaXRzKGxvdywgd2FzbS5nZXRfaGlnaCgpLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIHRoaXMuc3ViKHRoaXMuZGl2KGRpdmlzb3IpLm11bChkaXZpc29yKSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUubW9kID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUucmVtID0gTG9uZ1Byb3RvdHlwZS5tb2R1bG87CiAgICAgIExvbmdQcm90b3R5cGUubm90ID0gZnVuY3Rpb24gbm90KCkgewogICAgICAgIHJldHVybiBmcm9tQml0cyh+dGhpcy5sb3csIH50aGlzLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLmFuZCA9IGZ1bmN0aW9uIGFuZChvdGhlcikgewogICAgICAgIGlmICghaXNMb25nKG90aGVyKSkKICAgICAgICAgIG90aGVyID0gZnJvbVZhbHVlKG90aGVyKTsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgJiBvdGhlci5sb3csIHRoaXMuaGlnaCAmIG90aGVyLmhpZ2gsIHRoaXMudW5zaWduZWQpOwogICAgICB9OwogICAgICBMb25nUHJvdG90eXBlLm9yID0gZnVuY3Rpb24gb3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IHwgb3RoZXIubG93LCB0aGlzLmhpZ2ggfCBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS54b3IgPSBmdW5jdGlvbiB4b3Iob3RoZXIpIHsKICAgICAgICBpZiAoIWlzTG9uZyhvdGhlcikpCiAgICAgICAgICBvdGhlciA9IGZyb21WYWx1ZShvdGhlcik7CiAgICAgICAgcmV0dXJuIGZyb21CaXRzKHRoaXMubG93IF4gb3RoZXIubG93LCB0aGlzLmhpZ2ggXiBvdGhlci5oaWdoLCB0aGlzLnVuc2lnbmVkKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaGlmdExlZnQgPSBmdW5jdGlvbiBzaGlmdExlZnQobnVtQml0cykgewogICAgICAgIGlmIChpc0xvbmcobnVtQml0cykpCiAgICAgICAgICBudW1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIGlmICgobnVtQml0cyAmPSA2MykgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIGlmIChudW1CaXRzIDwgMzIpCiAgICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3cgPDwgbn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W1CaXRzID0gbnVtQml0cy50b0ludCgpOwogICAgICAgIG51bUJpdHMgJj0gNjM7CiAgICAgICAgaWYgKG51bUJpdHMgPT09IDApCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICBlbHNlIHsKICAgICAgICAgIHZhciBoaWdoID0gdGhpcy5oaWdoOwogICAgICAgICAgaWYgKG51bUJpdHMgPCAzMikgewogICAgICAgICAgICB2YXIgbG93ID0gdGhpcy5sb3c7CiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhsb3cgPj4+IG51bUJpdHMgfCBoaWdoIDw8IDMyIC0gbnVtQml0cywgaGlnaCA+Pj4gbnVtQml0cywgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICB9IGVsc2UgaWYgKG51bUJpdHMgPT09IDMyKQogICAgICAgICAgICByZXR1cm4gZnJvbUJpdHMoaGlnaCwgMCwgdGhpcy51bnNpZ25lZCk7CiAgICAgICAgICBlbHNlCiAgICAgICAgICAgIHJldHVybiBmcm9tQml0cyhoaWdoID4+PiBudW1CaXRzIC0gMzIsIDAsIHRoaXMudW5zaWduZWQpOwogICAgICAgIH0KICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS5zaHJ1ID0gTG9uZ1Byb3RvdHlwZS5zaGlmdFJpZ2h0VW5zaWduZWQ7CiAgICAgIExvbmdQcm90b3R5cGUuc2hyX3UgPSBMb25nUHJvdG90eXBlLnNoaWZ0UmlnaHRVbnNpZ25lZDsKICAgICAgTG9uZ1Byb3RvdHlwZS50b1NpZ25lZCA9IGZ1bmN0aW9uIHRvU2lnbmVkKCkgewogICAgICAgIGlmICghdGhpcy51bnNpZ25lZCkKICAgICAgICAgIHJldHVybiB0aGlzOwogICAgICAgIHJldHVybiBmcm9tQml0cyh0aGlzLmxvdywgdGhpcy5oaWdoLCBmYWxzZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9VbnNpZ25lZCA9IGZ1bmN0aW9uIHRvVW5zaWduZWQoKSB7CiAgICAgICAgaWYgKHRoaXMudW5zaWduZWQpCiAgICAgICAgICByZXR1cm4gdGhpczsKICAgICAgICByZXR1cm4gZnJvbUJpdHModGhpcy5sb3csIHRoaXMuaGlnaCwgdHJ1ZSk7CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlcyA9IGZ1bmN0aW9uIHRvQnl0ZXMobGUpIHsKICAgICAgICByZXR1cm4gbGUgPyB0aGlzLnRvQnl0ZXNMRSgpIDogdGhpcy50b0J5dGVzQkUoKTsKICAgICAgfTsKICAgICAgTG9uZ1Byb3RvdHlwZS50b0J5dGVzTEUgPSBmdW5jdGlvbiB0b0J5dGVzTEUoKSB7CiAgICAgICAgdmFyIGhpID0gdGhpcy5oaWdoLCBsbyA9IHRoaXMubG93OwogICAgICAgIHJldHVybiBbCiAgICAgICAgICBsbyAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDE2ICYgMjU1LAogICAgICAgICAgbG8gPj4+IDI0LAogICAgICAgICAgaGkgJiAyNTUsCiAgICAgICAgICBoaSA+Pj4gOCAmIDI1NSwKICAgICAgICAgIGhpID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGhpID4+PiAyNAogICAgICAgIF07CiAgICAgIH07CiAgICAgIExvbmdQcm90b3R5cGUudG9CeXRlc0JFID0gZnVuY3Rpb24gdG9CeXRlc0JFKCkgewogICAgICAgIHZhciBoaSA9IHRoaXMuaGlnaCwgbG8gPSB0aGlzLmxvdzsKICAgICAgICByZXR1cm4gWwogICAgICAgICAgaGkgPj4+IDI0LAogICAgICAgICAgaGkgPj4+IDE2ICYgMjU1LAogICAgICAgICAgaGkgPj4+IDggJiAyNTUsCiAgICAgICAgICBoaSAmIDI1NSwKICAgICAgICAgIGxvID4+PiAyNCwKICAgICAgICAgIGxvID4+PiAxNiAmIDI1NSwKICAgICAgICAgIGxvID4+PiA4ICYgMjU1LAogICAgICAgICAgbG8gJiAyNTUKICAgIC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hY2sKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAgICAgICAgc2VyaWFsaXplKGVycm9yKSB7CiAgICAgICAgICByZXR1cm4gewogICAgICAgICAgICBfX2Vycm9yX21hcmtlcjogIiQkZXJyb3IiLAogICAgICAgICAgICBtZXNzYWdlOiBlcnJvci5tZXNzYWdlLAogICAgICAgICAgICBuYW1lOiBlcnJvci5uYW1lLAogICAgICAgICAgICBzdGFjazogZXJyb3Iuc3RhY2sKICAgICAgICAgIH07CiAgICAgICAgfQogICAgICB9OwogICAgICB2YXIgaXNTZXJpYWxpemVkRXJyb3IgPSAodGhpbmcpID0+IHRoaW5nICYmIHR5cGVvZiB0aGluZyA9PT0gIm9iamVjdCIgJiYgIl9fZXJyb3JfbWFya2VyIiBpbiB0aGluZyAmJiB0aGluZy5fX2Vycm9yX21hcmtlciA9PT0gIiQkZXJyb3IiOwogICAgICBleHBvcnRzMi5EZWZhdWx0U2VyaWFsaXplciA9IHsKICAgICAgICBkZXNlcmlhbGl6ZShtZXNzYWdlKSB7CiAgICAgICAgICBpZiAoaXNTZXJpYWxpemVkRXJyb3IobWVzc2FnZSkpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuZGVzZXJpYWxpemUobWVzc2FnZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICByZXR1cm4gbWVzc2FnZTsKICAgICAgICAgIH0KICAgICAgICB9LAogICAgICAgIHNlcmlhbGl6ZShpbnB1dCkgewogICAgICAgICAgaWYgKGlucHV0IGluc3RhbmNlb2YgRXJyb3IpIHsKICAgICAgICAgICAgcmV0dXJuIERlZmF1bHRFcnJvclNlcmlhbGl6ZXIuc2VyaWFsaXplKGlucHV0KTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybiBpbnB1dDsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH07CiAgICB9CiAgfSk7CgogIC8vIG5vZGVfbW9kdWxlcy8ucG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ewogICAgICAgICAgICByZXNvbHZlKHZhbHVlKTsKICAgICAgICAgIH0pOwogICAgICAgIH0KICAgICAgICByZXR1cm4gbmV3IChQIHx8IChQID0gUHJvbWlzZSkpKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkgewogICAgICAgICAgZnVuY3Rpb24gZnVsZmlsbGVkKHZhbHVlKSB7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOwogICAgICAgICAgICB9IGNhdGNoIChlKSB7CiAgICAgICAgICAgICAgcmVqZWN0KGUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgewogICAgICAgICAgICB0cnkgewogICAgICAgICAgICAgIHN0ZXAoZ2VuZXJhdG9yWyJ0aHJvdyJdKHZhbHVlKSk7CiAgICAgICAgICAgIH0gY2F0Y2ggKGUpIHsKICAgICAgICAgICAgICByZWplY3QoZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGZ1bmN0aW9uIHN0ZXAocmVzdWx0KSB7CiAgICAgICAgICAgIHJlc3VsdC5kb25lID8gcmVzb2x2ZShyZXN1bHQudmFsdWUpIDogYWRvcHQocmVzdWx0LnZhbHVlKS50aGVuKGZ1bGZpbGxlZCwgcmVqZWN0ZWQpOwogICAgICAgICAgfQogICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOwogICAgICAgIH0pOwogICAgICB9OwogICAgICB2YXIgX19pbXBvcnREZWZhdWx0ID0gZXhwb3J0czIgJiYgZXhwb3J0czIuX19pbXBvcnREZWZhdWx0IHx8IGZ1bmN0aW9uKG1vZCkgewogICAgICAgIHJldHVybiBtb2QgJiYgbW9kLl9fZXNNb2R1bGUgPyBtb2QgOiB7ICJkZW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URhdGEudWlkOwogICAgICAgICAgICBjb25zdCBzdWJzY3JpcHRpb24gPSBhY3RpdmVTdWJzY3JpcHRpb25zLmdldChqb2JVSUQpOwogICAgICAgICAgICBpZiAoc3Vic2NyaXB0aW9uKSB7CiAgICAgICAgICAgICAgc3Vic2NyaXB0aW9uLnVuc3Vic2NyaWJlKCk7CiAgICAgICAgICAgICAgYWN0aXZlU3Vic2NyaXB0aW9ucy5kZWxldGUoam9iVUlEKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0pOwogICAgICB9CiAgICAgIGV4cG9ydHMyLmV4cG9zZSA9IGV4cG9zZTI7CiAgICAgIGlmICh0eXBlb2Ygc2VsZiAhPT0gInVuZGVmaW5lZCIgJiYgdHlwZW9mIHNlbGYuYWRkRXZlbnRMaXN0ZW5lciA9PT0gImZ1bmN0aW9uIiAmJiBpbXBsZW1lbnRhdGlvbl8xLmRlZmF1bHQuaXNXb3JrZXJSdW50aW1lKCkpIHsKICAgICAgICBzZWxmLmFkZEV2ZW50TGlzdGVuZXIoImVycm9yIiwgKGV2ZW50KSA9PiB7CiAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShldmVudC5lcnJvciB8fCBldmVudCksIDI1MCk7CiAgICAgICAgfSk7CiAgICAgICAgc2VsZi5hZGRFdmVudExpc3RlbmVyKCJ1bmhhbmRsZWRyZWplY3Rpb24iLCAoZXZlbnQpID0+IHsKICAgICAgICAgIGNvbnN0IGVycm9yID0gZXZlbnQucmVhc29uOwogICAgICAgICAgaWYgKGVycm9yICYmIHR5cGVvZiBlcnJvci5tZXNzYWdlID09PSAic3RyaW5nIikgewogICAgICAgICAgICBzZXRUaW1lb3V0KCgpID0+IHBvc3RVbmNhdWdodEVycm9yTWVzc2FnZShlcnJvciksIDI1MCk7CiAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICAgIH0KICAgICAgaWYgKHR5cGVvZiBwcm9jZXNzICE9PS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liZUV4cGVjdGVkKGV4cGVjdGVkMikgewogICAgICAgICAgdmFyIGRlc2NyaXB0aW9ucyA9IG5ldyBBcnJheShleHBlY3RlZDIubGVuZ3RoKSwgaSwgajsKICAgICAgICAgIGZvciAoaSA9IDA7IGkgPCBleHBlY3RlZDIubGVuZ3RoOyBpKyspIHsKICAgICAgICAgICAgZGVzY3JpcHRpb25zW2ldID0gZGVzY3JpYmVFeHBlY3RhdGlvbihleHBlY3RlZDJbaV0pOwogICAgICAgICAgfQogICAgICAgICAgZGVzY3JpcHRpb25zLnNvcnQoKTsKICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnMubGVuZ3RoID4gMCkgewogICAgICAgICAgICBmb3IgKGkgPSAxLCBqID0gMTsgaSA8IGRlc2NyaXB0aW9ucy5sZW5ndGg7IGkrKykgewogICAgICAgICAgICAgIGlmIChkZXNjcmlwdGlvbnNbaSAtIDFdICE9PSBkZXNjcmlwdGlvbnNbaV0pIHsKICAgICAgICAgICAgICAgIGRlc2NyaXB0aW9uc1tqXSA9IGRlc2NyaXB0aW9uc1tpXTsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGVzY3JpcHRpb25zLmxlbmd0aCA9IGo7CiAgICAgICAgICB9CiAgICAgICAgICBzd2l0Y2ggKGRlc2NyaXB0aW9ucy5sZW5ndGgpIHsKICAgICAgICAgICAgY2FzZSAxOgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnNbMF07CiAgICAgICAgICAgIGNhc2UgMjoKICAgICAgICAgICAgICByZXR1cm4gZGVzY3JpcHRpb25zWzBdICsgIiBvciAiICsgZGVzY3JpcHRpb25zWzFdOwogICAgICAgICAgICBkZWZhdWx0OgogICAgICAgICAgICAgIHJldHVybiBkZXNjcmlwdGlvbnMuc2xpY2UoMCwgLTEpLmpvaW4oIiwgIikgKyAiLCBvciAiICsgZGVzY3JpcHRpb25zW2Rlc2NyaXB0aW9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gICAgIHJldHVybiB7IHR5cGU6ICJlbmQiIH07CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRvdGhlckV4cGVjdGF0aW9uKGRlc2NyaXB0aW9uKSB7CiAgICAgICAgICByZXR1cm4geyB0eXBlOiAib3RoZXIiLCBkZXNjcmlwdGlvbiB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckY29tcHV0ZVBvc0RldGFpbHMocG9zKSB7CiAgICAgICAgICB2YXIgZGV0YWlscyA9IHBlZyRwb3NEZXRhaWxzQ2FjaGVbcG9zXSwgcDsKICAgICAgICAgIGlmIChkZXRhaWxzKSB7CiAgICAgICAgICAgIHJldHVybiBkZXRhaWxzOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcCA9IHBvcyAtIDE7CiAgICAgICAgICAgIHdoaWxlICghcGVnJHBvc0RldGFpbHNDYWNoZVtwXSkgewogICAgICAgICAgICAgIHAtLTsKICAgICAgICAgICAgfQogICAgICAgICAgICBkZXRhaWxzID0gcGVnJHBvc0RldGFpbHNDYWNoZVtwXTsKICAgICAgICAgICAgZGV0YWlscyA9IHsKICAgICAgICAgICAgICBsaW5lOiBkZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBkZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9OwogICAgICAgICAgICB3aGlsZSAocCA8IHBvcykgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHApID09PSAxMCkgewogICAgICAgICAgICAgICAgZGV0YWlscy5saW5lKys7CiAgICAgICAgICAgICAgICBkZXRhaWxzLmNvbHVtbiA9IDE7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIGRldGFpbHMuY29sdW1uKys7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHArKzsKICAgICAgICAgICAgfQogICAgICAgICAgICBwZWckcG9zRGV0YWlsc0NhY2hlW3Bvc10gPSBkZXRhaWxzOwogICAgICAgICAgICByZXR1cm4gZGV0YWlsczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJGNvbXB1dGVMb2NhdGlvbihzdGFydFBvcywgZW5kUG9zKSB7CiAgICAgICAgICB2YXIgc3RhcnRQb3NEZXRhaWxzID0gcGVnJGNvbXB1dGVQb3NEZXRhaWxzKHN0YXJ0UG9zKSwgZW5kUG9zRGV0YWlscyA9IHBlZyRjb21wdXRlUG9zRGV0YWlscyhlbmRQb3MpOwogICAgICAgICAgcmV0dXJuIHsKICAgICAgICAgICAgc3RhcnQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IHN0YXJ0UG9zLAogICAgICAgICAgICAgIGxpbmU6IHN0YXJ0UG9zRGV0YWlscy5saW5lLAogICAgICAgICAgICAgIGNvbHVtbjogc3RhcnRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9LAogICAgICAgICAgICBlbmQ6IHsKICAgICAgICAgICAgICBvZmZzZXQ6IGVuZFBvcywKICAgICAgICAgICAgICBsaW5lOiBlbmRQb3NEZXRhaWxzLmxpbmUsCiAgICAgICAgICAgICAgY29sdW1uOiBlbmRQb3NEZXRhaWxzLmNvbHVtbgogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckZmFpbChleHBlY3RlZDIpIHsKICAgICAgICAgIGlmIChwZWckY3VyclBvcyA8IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChwZWckY3VyclBvcyA+IHBlZyRtYXhGYWlsUG9zKSB7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsUG9zID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQgPSBbXTsKICAgICAgICAgIH0KICAgICAgICAgIHBlZyRtYXhGYWlsRXhwZWN0ZWQucHVzaChleHBlY3RlZDIpOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckYnVpbGRTaW1wbGVFcnJvcihtZXNzYWdlLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKG1lc3NhZ2UsIG51bGwsIG51bGwsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRidWlsZFN0cnVjdHVyZWRFcnJvcihleHBlY3RlZDIsIGZvdW5kLCBsb2NhdGlvbjIpIHsKICAgICAgICAgIHJldHVybiBuZXcgcGVnJFN5bnRheEVycm9yKHBlZyRTeW50YXhFcnJvci5idWlsZE1lc3NhZ2UoZXhwZWN0ZWQyLCBmb3VuZCksIGV4cGVjdGVkMiwgZm91bmQsIGxvY2F0aW9uMik7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmF0aW9uKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzLCBzNCwgczUsIHM2LCBzNywgczgsIHM5LCBzMTAsIHMxMSwgczEyLCBzMTM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlZGVjbGFyZU5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczggPSBwZWckYzA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM4ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTAgPSBwZWckcGFyc2VmaWVsZExpc3QoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJGMyOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEzID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckYzQoczIsIHM0LCBzNiwgczEwKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZGVjbGFyZVR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGM1OwogICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjNzsKICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA1KSA9PT0gcGVnJGM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjOTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWRlY2xhcmVOYW1lKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczIsIHMzOwogICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlaW5kZXhUeXBlKCk7CiAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMSA9IFtzMSwgczJdOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDQpID09PSBwZWckYzExKSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyXTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VpbmRleFR5cGUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMTEpIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMxMTsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDQ7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMxMik7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczEgPSBbczEsIHMyLCBzM107CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VpbmRleFR5cGUoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA3KSA9PT0gcGVnJGMxMykgewogICAgICAgICAgICBzMCA9IHBlZyRjMTM7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDc7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE0KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzE1KSB7CiAgICAgICAgICAgICAgczAgPSBwZWckYzE1OwogICAgICAgICAgICAgIHBlZyRjdXJyUG9zICs9IDU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMTYpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBpZiAoaW5wdXQuc3Vic3RyKHBlZyRjdXJyUG9zLCA2KSA9PT0gcGVnJGMxNykgewogICAgICAgICAgICAgICAgczAgPSBwZWckYzE3OwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzE4KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlY29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkTGlzdCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQsIHM1LCBzNjsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMzID0gW107CiAgICAgICAgICAgICAgczQgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlZmllbGQoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgczUgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHM0ID0gczU7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIHdoaWxlIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgICBzNCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgczYgPSBwZWckcGFyc2VmaWVsZCgpOwogICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzNDsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMTkoczEsIHM2KTsKICAgICAgICAgICAgICAgICAgICBzNCA9IHM1OwogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczQ7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHM0OwogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczQgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyMChzMSwgczMpOwogICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2Vjb21tZW50U3RhcnQoKSB7CiAgICAgICAgICB2YXIgczA7CiAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMyMTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjIpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWludGVybmFsQ29tbWVudCgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMywgczQ7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBwZWckcGFyc2Vjb21tZW50U3RhcnQoKTsKICAgICAgICAgICAgaWYgKHMyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2Vub25RdW90ZWRTdHJpbmcoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIHMxID0gW3MxLCBzMiwgczMsIHM0XTsKICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGQoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczYsIHM3LCBzOCwgczksIHMxMCwgczExLCBzMTIsIHMxMzsKICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRjMjM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzNSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczcgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczcgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMyNShzMSwgczMsIHM3KTsKICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBzMiA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTEpIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckYzI2OwogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyNyk7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFNpemUoKTsKICAgICAgICAgICAgICAgICAgICBpZiAoczUgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gOTMpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjg7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMyOSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzNyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHM4ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgczkgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczkgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEwICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA1OSkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMjQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczExICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczEyICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMyA9IHBlZyRwYXJzZWNvbW1lbnQoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRzYXZlZFBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxID0gcGVnJGMzMChzMSwgczUsIHM5LCBzMTMpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgICBzMSA9IHBlZyRwYXJzZWZpZWxkVHlwZSgpOwogICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0MCkgewogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJGMwOwogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMSk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIHM0ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgIGlmIChzNCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VmaWVsZFZhbHVlcygpOwogICAgICAgICAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHM2ID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICBpZiAoczYgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoaW5wdXQuY2hhckNvZGVBdChwZWckY3VyclBvcykgPT09IDQxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzNyA9IHBlZyRjMjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHM3ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM3ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOCA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzOCAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzOSA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHM5ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEwID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTAgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gNTkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczExID0gcGVnJGMyMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMxMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzI0KTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMTIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMTMgPSBwZWckcGFyc2Vjb21tZW50KCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHMxMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjMzEoczEsIHM1LCBzOSwgczEzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczAgPSBwZWckcGFyc2VpbnRlcm5hbENvbW1lbnQoKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlZmllbGRWYWx1ZXMoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0LCBzNSwgczY7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczIgPSBbXTsKICAgICAgICAgICAgczMgPSBwZWckY3VyclBvczsKICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgIHM0ID0gcGVnJGMzMjsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczUgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgaWYgKHM1ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgIGlmIChzNiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgIHMzID0gczQ7CiAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczM7CiAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIHMzID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSA0NCkgewogICAgICAgICAgICAgICAgczQgPSBwZWckYzMyOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzMzKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgaWYgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICBzNSA9IHBlZyRwYXJzZV8oKTsKICAgICAgICAgICAgICAgIGlmIChzNSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICBzNiA9IHBlZyRwYXJzZW5hbWUoKTsKICAgICAgICAgICAgICAgICAgaWYgKHM2ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczM7CiAgICAgICAgICAgICAgICAgICAgczQgPSBwZWckYzE5KHMxLCBzNik7CiAgICAgICAgICAgICAgICAgICAgczMgPSBzNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMzsKICAgICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMzOwogICAgICAgICAgICAgICAgczMgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjMzQoczEsIHMyKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkVHlwZSgpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDMpID09PSBwZWckYzM1KSB7CiAgICAgICAgICAgIHMwID0gcGVnJGMzNTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjMzYpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjMzcpIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRjMzc7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGMzOCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzM5KSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRjMzk7CiAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDApOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIH0KICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzQxKSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0MTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDIpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDMpIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDM7CiAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM0NCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ1KSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDU7CiAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA1OwogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDYpOwogICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDUpID09PSBwZWckYzQ3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM0NzsKICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNTsKICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNDgpOwogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNDkpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNDk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1MCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzUxKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTIpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDcpID09PSBwZWckYzUzKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1MzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTQpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgNCkgPT09IHBlZyRjNTUpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM1Nik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU3KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNTc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyArPSA2OwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNTgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChpbnB1dC5zdWJzdHIocGVnJGN1cnJQb3MsIDYpID09PSBwZWckYzU5KSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGM1OTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gNjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjApOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGlucHV0LnN1YnN0cihwZWckY3VyclBvcywgMykgPT09IHBlZyRjNjEpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRjNjE7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgKz0gMzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM2Mik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHMwID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczEgPSBwZWckcGFyc2VkZWNsYXJlVHlwZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczIgPSBwZWckcGFyc2VfKCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczMgPSBwZWckcGFyc2VkZWNsYXJlTmFtZSgpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoczMgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNjMoczEsIHMzKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZWZpZWxkU2l6ZSgpIHsKICAgICAgICAgIHZhciBzMDsKICAgICAgICAgIHMwID0gcGVnJHBhcnNlbnVtYmVyKCk7CiAgICAgICAgICBpZiAoczAgPT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczAgPSBwZWckcGFyc2VuYW1lKCk7CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW5hbWUoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczMsIHM0OwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJGN1cnJQb3M7CiAgICAgICAgICBpZiAocGVnJGM2NC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNjUpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgczMgPSBbXTsKICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHM0ID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHM0ID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgd2hpbGUgKHM0ICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczMucHVzaChzNCk7CiAgICAgICAgICAgICAgaWYgKHBlZyRjNjYudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgICAgczQgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgczQgPSBwZWckRkFJTEVEOwogICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzY3KTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYgKHMzICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgICAgczIgPSBbczIsIHMzXTsKICAgICAgICAgICAgICBzMSA9IHMyOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczE7CiAgICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMxOwogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoczEgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgIHMxID0gcGVnJGM2OChzMSk7CiAgICAgICAgICB9CiAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VxdW90ZWRTdHJpbmcoKSB7CiAgICAgICAgICB2YXIgczAsIHMxLCBzMiwgczM7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgaWYgKGlucHV0LmNoYXJDb2RlQXQocGVnJGN1cnJQb3MpID09PSAzNCkgewogICAgICAgICAgICBzMSA9IHBlZyRjNjk7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzcwKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHMyLnB1c2goczMpOwogICAgICAgICAgICAgIGlmIChwZWckYzcxLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3Mik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIGlmIChpbnB1dC5jaGFyQ29kZUF0KHBlZyRjdXJyUG9zKSA9PT0gMzQpIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJGM2OTsKICAgICAgICAgICAgICAgIHBlZyRjdXJyUG9zKys7CiAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3MCk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgcGVnJHNhdmVkUG9zID0gczA7CiAgICAgICAgICAgICAgICBzMSA9IHBlZyRjNzMoczIpOwogICAgICAgICAgICAgICAgczAgPSBzMTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MgPSBzMDsKICAgICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgIHMwID0gcGVnJEZBSUxFRDsKICAgICAgICAgIH0KICAgICAgICAgIHJldHVybiBzMDsKICAgICAgICB9CiAgICAgICAgZnVuY3Rpb24gcGVnJHBhcnNlbm9uUXVvdGVkU3RyaW5nKCkgewogICAgICAgICAgdmFyIHMwLCBzMSwgczI7CiAgICAgICAgICBzMCA9IHBlZyRjdXJyUG9zOwogICAgICAgICAgczEgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzc0LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczIgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczIgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3NSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMiAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMS5wdXNoKHMyKTsKICAgICAgICAgICAgaWYgKHBlZyRjNzQudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMyID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc1KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGlmIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgczEgPSBwZWckYzc2KHMxKTsKICAgICAgICAgIH0KICAgICAgICAgIHMwID0gczE7CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIGZ1bmN0aW9uIHBlZyRwYXJzZW51bWJlcigpIHsKICAgICAgICAgIHZhciBzMCwgczEsIHMyLCBzMzsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBwZWckY3VyclBvczsKICAgICAgICAgIHMxID0gcGVnJHBhcnNlXygpOwogICAgICAgICAgaWYgKHMxICE9PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMyID0gW107CiAgICAgICAgICAgIGlmIChwZWckYzc4LnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgICBzMyA9IGlucHV0LmNoYXJBdChwZWckY3VyclBvcyk7CiAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICBzMyA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM3OSk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgIHdoaWxlIChzMyAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICAgICAgczIucHVzaChzMyk7CiAgICAgICAgICAgICAgICBpZiAocGVnJGM3OC50ZXN0KGlucHV0LmNoYXJBdChwZWckY3VyclBvcykpKSB7CiAgICAgICAgICAgICAgICAgIHMzID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICAgICAgcGVnJGN1cnJQb3MrKzsKICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgIHMzID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjNzkpOwogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgfQogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMyID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoczIgIT09IHBlZyRGQUlMRUQpIHsKICAgICAgICAgICAgICBwZWckc2F2ZWRQb3MgPSBzMDsKICAgICAgICAgICAgICBzMSA9IHBlZyRjODAoKTsKICAgICAgICAgICAgICBzMCA9IHMxOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHBlZyRjdXJyUG9zID0gczA7CiAgICAgICAgICAgICAgczAgPSBwZWckRkFJTEVEOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBwZWckY3VyclBvcyA9IHMwOwogICAgICAgICAgICBzMCA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICB9CiAgICAgICAgICBwZWckc2lsZW50RmFpbHMtLTsKICAgICAgICAgIGlmIChzMCA9PT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMSA9IHBlZyRGQUlMRUQ7CiAgICAgICAgICAgIGlmIChwZWckc2lsZW50RmFpbHMgPT09IDApIHsKICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzc3KTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgcmV0dXJuIHMwOwogICAgICAgIH0KICAgICAgICBmdW5jdGlvbiBwZWckcGFyc2VfKCkgewogICAgICAgICAgdmFyIHMwLCBzMTsKICAgICAgICAgIHBlZyRzaWxlbnRGYWlscysrOwogICAgICAgICAgczAgPSBbXTsKICAgICAgICAgIGlmIChwZWckYzgyLnRlc3QoaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKSkpIHsKICAgICAgICAgICAgczEgPSBpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpOwogICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgczEgPSBwZWckRkFJTEVEOwogICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgcGVnJGZhaWwocGVnJGM4Myk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHdoaWxlIChzMSAhPT0gcGVnJEZBSUxFRCkgewogICAgICAgICAgICBzMC5wdXNoKHMxKTsKICAgICAgICAgICAgaWYgKHBlZyRjODIudGVzdChpbnB1dC5jaGFyQXQocGVnJGN1cnJQb3MpKSkgewogICAgICAgICAgICAgIHMxID0gaW5wdXQuY2hhckF0KHBlZyRjdXJyUG9zKTsKICAgICAgICAgICAgICBwZWckY3VyclBvcysrOwogICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgICBpZiAocGVnJHNpbGVudEZhaWxzID09PSAwKSB7CiAgICAgICAgICAgICAgICBwZWckZmFpbChwZWckYzgzKTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIHBlZyRzaWxlbnRGYWlscy0tOwogICAgICAgICAgaWYgKHMwID09PSBwZWckRkFJTEVEKSB7CiAgICAgICAgICAgIHMxID0gcGVnJEZBSUxFRDsKICAgICAgICAgICAgaWYgKHBlZyRzaWxlbnRGYWlscyA9PT0gMCkgewogICAgICAgICAgICAgIHBlZyRmYWlsKHBlZyRjODEpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgICByZXR1cm4gczA7CiAgICAgICAgfQogICAgICAgIHBlZyRyZXN1bHQgPSBwZWckc3RhcnRSdWxlRnVuY3Rpb24oKTsKICAgICAgICBpZiAocGVnJHJlc3VsdCAhPT0gcG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B0aGlzLmZldGNoKHRoaXMudXJsLCBhcmdzKTsKICAgICAgaWYgKCFyZXNwb25zZSkgewogICAgICAgIHRocm93IG5ldyBFcnJvcigiZ2VuZXJpYy1maWxlaGFuZGxlIGZhaWxlZCB0byBmZXRjaCIpOwogICAgICB9CiAgICAgIGlmIChyZXNwb25zZS5zdGF0dXMgIT09IDIwMCkgewogICAgICAgIHRocm93IE9iamVjdC5hc3NpZ24obmV3IEVycm9yKGBIVFRQICR7cmVzcG9uc2Uuc3RhdHVzfSBmZXRjaGluZyAke3RoaXMudXJsfWApLCB7CiAgICAgICAgICBzdGF0dXM6IHJlc3BvbnNlLnN0YXR1cwogICAgICAgIH0pOwogICAgICB9CiAgICAgIGlmIChlbmNvZGluZyA9PT0gInV0ZjgiKSB7CiAgICAgICAgcmV0dXJuIHJlc3BvbnNlLnRleHQoKTsKICAgICAgfQogICAgICBpZiAoZW5jb2RpbmcpIHsKICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYHVuc3VwcG9ydGVkIGVuY29kaW5nOiAke2VuY29kaW5nfWApOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLmdldEJ1ZmZlckZyb21SZXNwb25zZShyZXNwb25zZSk7CiAgICB9CiAgICBhc3luYyBzdGF0KCkgewogICAgICBpZiAoIXRoaXMuX3N0YXQpIHsKICAgICAgICBjb25zdCBidWYgPSBpbXBvcnRfYnVmZmVyMi5CdWZmZXIuYWxsb2NVbnNhZmUoMTApOwogICAgICAgIGF3YWl0IHRoaXMucmVhZChidWYsIDAsIDEwLCAwKTsKICAgICAgICBpZiAoIXRoaXMuX3N0YXQpIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcihgdW5hYmxlIHRvIGRldGVybWluZSBzaXplIG9mIGZpbGUgYXQgJHt0aGlzLnVybH1gKTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHRoaXMuX3N0YXQ7CiAgICB9CiAgICBhc3luYyBjbG9zZSgpIHsKICAgICAgcmV0dXJ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9ydF9wYWtvID0gX190b01vZHVsZShyZXF1aXJlX3Bha28oKSk7CiAgYXN5bmMgZnVuY3Rpb24gdW56aXAoaW5wdXREYXRhKSB7CiAgICB0cnkgewogICAgICBsZXQgc3RybTsKICAgICAgbGV0IHBvcyA9IDA7CiAgICAgIGxldCBpID0gMDsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGxldCB0b3RhbFNpemUgPSAwOwogICAgICBsZXQgaW5mbGF0b3I7CiAgICAgIGRvIHsKICAgICAgICBjb25zdCByZW1haW5pbmdJbnB1dCA9IGlucHV0RGF0YS5zdWJhcnJheShwb3MpOwogICAgICAgIGluZmxhdG9yID0gbmV3IGltcG9ydF9wYWtvLkluZmxhdGUoKTsKICAgICAgICAoeyBzdHJtIH0gPSBpbmZsYXRvcik7CiAgICAgICAgaW5mbGF0b3IucHVzaChyZW1haW5pbmdJbnB1dCwgaW1wb3J0X3Bha28uWl9TWU5DX0ZMVVNIKTsKICAgICAgICBpZiAoaW5mbGF0b3IuZXJyKSB7CiAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoaW5mbGF0b3IubXNnKTsKICAgICAgICB9CiAgICAgICAgcG9zICs9IHN0cm0ubmV4dF9pbjsKICAgICAgICBjaHVua3NbaV0gPSBpbmZsYXRvci5yZXN1bHQ7CiAgICAgICAgdG90YWxTaXplICs9IGNodW5rc1tpXS5sZW5ndGg7CiAgICAgICAgaSArPSAxOwogICAgICB9IHdoaWxlIChzdHJtLmF2YWlsX2luKTsKICAgICAgY29uc3QgcmVzdWx0ID0gbmV3IFVpbnQ4QXJyYXkodG90YWxTaXplKTsKICAgICAgZm9yIChsZXQgaTIgPSAwLCBvZmZzZXQgPSAwOyBpMiA8IGNodW5rcy5sZW5ndGg7IGkyKyspIHsKICAgICAgICByZXN1bHQuc2V0KGNodW5rc1tpMl0sIG9mZnNldCk7CiAgICAgICAgb2Zmc2V0ICs9IGNodW5rc1tpMl0ubGVuZ3RoOwogICAgICB9CiAgICAgIHJ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vci5tc2cpOwogICAgICAgIH0KICAgICAgICBjb25zdCBidWZmZXIyID0gaW5mbGF0b3IucmVzdWx0OwogICAgICAgIGNodW5rcy5wdXNoKGJ1ZmZlcjIpOwogICAgICAgIGxldCBsZW4gPSBidWZmZXIyLmxlbmd0aDsKICAgICAgICBjcG9zaXRpb25zLnB1c2goY3Bvcyk7CiAgICAgICAgZHBvc2l0aW9ucy5wdXNoKGRwb3MpOwogICAgICAgIGlmIChjaHVua3MubGVuZ3RoID09PSAxICYmIG1pbnYuZGF0YVBvc2l0aW9uKSB7CiAgICAgICAgICBjaHVua3NbMF0gPSBjaHVua3NbMF0uc3ViYXJyYXkobWludi5kYXRhUG9zaXRpb24pOwogICAgICAgICAgbGVuID0gY2h1bmtzWzBdLmxlbmd0aDsKICAgICAgICB9CiAgICAgICAgY29uc3Qgb3JpZ0Nwb3MgPSBjcG9zOwogICAgICAgIGNwb3MgKz0gc3RybS5uZXh0X2luOwogICAgICAgIGRwb3MgKz0gbGVuOwogICAgICAgIGlmIChvcmlnQ3BvcyA+PSBtYXh2LmJsb2NrUG9zaXRpb24pIHsKICAgICAgICAgIGNodW5rc1tpXSA9IGNodW5rc1tpXS5zdWJhcnJheSgwLCBtYXh2LmJsb2NrUG9zaXRpb24gPT09IG1pbnYuYmxvY2tQb3NpdGlvbiA/IG1heHYuZGF0YVBvc2l0aW9uIC0gbWludi5kYXRhUG9zaXRpb24gKyAxIDogbWF4di5kYXRhUG9zaXRpb24gKyAxKTsKICAgICAgICAgIGNwb3NpdGlvbnMucHVzaChjcG9zKTsKICAgICAgICAgIGRwb3NpdGlvbnMucHVzaChkcG9zKTsKICAgICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgICAgYnJlYWs7CiAgICAgICAgfQogICAgICAgIHRvdGFsU2l6ZSArPSBjaHVua3NbaV0ubGVuZ3RoOwogICAgICAgIGkrKzsKICAgICAgfSB3aGlsZSAoc3RybS5hdmFpbF9pbik7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ZWRDaHVua3MgPSBbXTsKICAgIGxldCBsYXN0Q2h1bmsgPSBudWxsOwogICAgaWYgKGNodW5rcy5sZW5ndGggPT09IDApIHsKICAgICAgcmV0dXJuIGNodW5rczsKICAgIH0KICAgIGNodW5rcy5zb3J0KGZ1bmN0aW9uKGMwLCBjMSkgewogICAgICBjb25zdCBkaWYgPSBjMC5taW52LmJsb2NrUG9zaXRpb24gLSBjMS5taW52LmJsb2NrUG9zaXRpb247CiAgICAgIGlmIChkaWYgIT09IDApIHsKICAgICAgICByZXR1cm4gZGlmOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiBjMC5taW52LmRhdGFQb3NpdGlvbiAtIGMxLm1pbnYuZGF0YVBvc2l0aW9uOwogICAgICB9CiAgICB9KTsKICAgIGNodW5rcy5mb3JFYWNoKChjaHVuaykgPT4gewogICAgICBpZiAoIWxvd2VzdCB8fCBjaHVuay5tYXh2LmNvbXBhcmVUbyhsb3dlc3QpID4gMCkgewogICAgICAgIGlmIChsYXN0Q2h1bmsgPT09IG51bGwpIHsKICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgIGxhc3RDaHVuayA9IGNodW5rOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBpZiAoY2FuTWVyZ2VCbG9ja3MobGFzdENodW5rLCBjaHVuaykpIHsKICAgICAgICAgICAgaWYgKGNodW5rLm1heHYuY29tcGFyZVRvKGxhc3RDaHVuay5tYXh2KSA+IDApIHsKICAgICAgICAgICAgICBsYXN0Q2h1bmsubWF4diA9IGNodW5rLm1heHY7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIG1lcmdlZENodW5rcy5wdXNoKGNodW5rKTsKICAgICAgICAgICAgbGFzdENodW5rID0gY2h1bms7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9KTsKICAgIHJldHVybiBtZXJnZWRDaHVua3M7CiAgfQoKICAvLyBub2RlX21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HJlc3Q7CiAgICB9CiAgICBfZmluZEZpcnN0RGF0YShjdXJyZW50RmRsLCB2aXJ0dWFsT2Zmc2V0KSB7CiAgICAgIGlmIChjdXJyZW50RmRsKSB7CiAgICAgICAgcmV0dXJuIGN1cnJlbnRGZGwuY29tcGFyZVRvKHZpcnR1YWxPZmZzZXQpID4gMCA/IHZpcnR1YWxPZmZzZXQgOiBjdXJyZW50RmRsOwogICAgICB9IGVsc2UgewogICAgICAgIHJldHVybiB2aXJ0dWFsT2Zmc2V0OwogICAgICB9CiAgICB9CiAgICBhc3luYyBwYXJzZShvcHRzID0ge30pIHsKICAgICAgaWYgKCF0aGlzLnBhcnNlUCkgewogICAgICAgIHRoaXMucGFyc2VQID0gdGhpcy5fcGFyc2Uob3B0cykuY2F0Y2goKGUpID0+IHsKICAgICAgICAgIHRoaXMucGFyc2VQID0gdm9pZCAwOwogICAgICAgICAgdGhyb3cgZTsKICAgICAgICB9KTsKICAgICAgfQogICAgICByZXR1cm4gdGhpcy5wYXJzZVA7CiAgICB9CiAgICBhc3luYyBoYXNSZWZTZXEoc2VxSWQsIG9wdHMgPSB7fSkgewogICAgICByZXR1cm4gISEoKGF3YWl0IHRoaXMucGFyc2Uob3B0cykpLmluZGljZXNbc2VxSWRdIHx8IHt9KS5iaW5JbmRleDsKICAgIH0KICB9OwoKICAvLyBub2RlX21vZHVsZXMvLnBucG0vQGdtb2QrdGFiaXhAMS41LjExL25vZGVfbW9kdWxlcy9AZ21vZC90YWJpeC9lc20vdGJpLmpzCiAgdmFyIFRCSV9NQUdJQyA9IDIxNTc4MzI0OwogIHZhciBUQURfTElEWF9TSElGVCA9IDE0OwogIGZ1bmN0aW9uIHJlZzJiaW5zKGJlZywgZW5kKSB7CiAgICBiZWcgKz0gMTsKICAgIGVuZCAtPSAxOwogICAgcmV0dXJuIFsKICAgICAgWzAsIDBdLAogICAgICBbMSArIChiZWcgPj4gMjYpLCAxICsgKGVuZCA+PiAyNildLAogICAgICBbOSArIChiZWcgPj4gMjMpLCA5ICsgKGVuZCA+PiAyMyldLAogICAgICBbNzMgKyAoYmVnID4+IDIwKSwgNzMgKyAoZW5kID4+IDIwKV0sCiAgICAgIFs1ODUgKyAoYmVnID4+IDE3KSwgNTg1ICsgKGVuZCA+PiAxNyldLAogICAgICBbNDY4MSArIChiZWcgPj4gMTQpLCA0NjgxICsgKGVuZCA+PiAxNCldCiAgICBdOwogIH0KICB2YXIgVGFiaXhJbmRleCA9IGNsYXNzIGV4dGVuZHMgSW5kZXhGaWxlIHsKICAgIGFzeW5jIGxpbmVDb3VudChyZWZOYW1lLCBvcHRzID0ge30pIHsKICAgICAgY29uc3QgaW5kZXhEYXRhID0gYXdhaXQgdGhpcy5wYXJzZShvcHRzKTsKICAgICAgaWYgKCFpbmRleERhdGEpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgcmVmSWQgPSBpbmRleERhdGEucmVmTmFtZVRvSWRbcmVmTmFtZV07CiAgICAgIGNvbnN0IGlkeCA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFpZHgpIHsKICAgICAgICByZXR1cm4gLTE7CiAgICAgIH0KICAgICAgY29uc3QgeyBzdGF0cyB9ID0gaW5kZXhEYXRhLmluZGljZXNbcmVmSWRdOwogICAgICBpZiAoc3RhdHMpIHsKICAgICAgICByZXR1cm4gc3RhdHMubGluZUNvdW50OwogICAgICB9CiAgICAgIHJldHVybiAtMTsKICAgIH0KICAgIGFzeW5jIF9wYXJzZShvcHRzID0ge30pIHsKICAgICAgY29uc3QgYnVmID0gYXdhaXQgdGhpcy5maWxlaGFuZGxlLnJlYWRGaWxlKG9wdHMpOwogICAgICBjb25zdCBieXRlcyA9IGF3YWl0IHVuemlwKGJ1Zik7CiAgICAgIGNoZWNrQWJvcnRTaWduYWwob3B0cy5zaWduYWwpOwogICAgICBpZiAoYnl0ZXMucmVhZFVJbnQzMkxFKDApICE9PSBUQklfTUFHSUMpIHsKICAg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ICAgICAgICAgY29uc3QgY2h1bmtDb3VudCA9IGJ5dGVzLnJlYWRJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgICAgIGlmIChjaHVua0NvdW50ID09PSAyKSB7CiAgICAgICAgICAgICAgc3RhdHMgPSB0aGlzLnBhcnNlUHNldWRvQmluKGJ5dGVzLCBjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgfQogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2ICogY2h1bmtDb3VudDsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIGNvbnN0IGNodW5rQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgICAgICBjb25zdCBjaHVua3MgPSBuZXcgQXJyYXkoY2h1bmtDb3VudCk7CiAgICAgICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgY2h1bmtDb3VudDsgayArPSAxKSB7CiAgICAgICAgICAgICAgY29uc3QgdSA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCk7CiAgICAgICAgICAgICAgY29uc3QgdiA9IGZyb21CeXRlcyhieXRlcywgY3Vyck9mZnNldCArIDgpOwogICAgICAgICAgICAgIGN1cnJPZmZzZXQgKz0gMTY7CiAgICAgICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgdSk7CiAgICAgICAgICAgICAgY2h1bmtzW2tdID0gbmV3IENodW5rKHUsIHYsIGJpbik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYmluSW5kZXhbYmluXSA9IGNodW5rczsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgY29uc3QgbGluZWFyQ291bnQgPSBieXRlcy5yZWFkSW50MzJMRShjdXJyT2Zmc2V0KTsKICAgICAgICBjdXJyT2Zmc2V0ICs9IDQ7CiAgICAgICAgY29uc3QgbGluZWFySW5kZXggPSBuZXcgQXJyYXkobGluZWFyQ291bnQpOwogICAgICAgIGZvciAobGV0IGsgPSAwOyBrIDwgbGluZWFyQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgbGluZWFySW5kZXhba10gPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgY3Vyck9mZnNldCArPSA4OwogICAgICAgICAgZmlyc3REYXRhTGluZSA9IHRoaXMuX2ZpbmRGaXJzdERhdGEoZmlyc3REYXRhTGluZSwgbGluZWFySW5kZXhba10pOwogICAgICAgIH0KICAgICAgICByZXR1cm4geyBiaW5JbmRleCwgbGluZWFySW5kZXgsIHN0YXRzIH07CiAgICAgIH0pOwogICAgICByZXR1cm4gewogICAgICAgIGluZGljZXMsCiAgICAgICAgbWV0YUNoYXIsCiAgICAgICAgbWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aCwKICAgICAgICBza2lwTGluZXMsCiAgICAgICAgZmlyc3REYXRhTGluZSwKICAgICAgICBjb2x1bW5OdW1iZXJzLAogICAgICAgIGNvb3JkaW5hdGVUeXBlLAogICAgICAgIGZvcm1hdCwKICAgICAgICByZWZJZFRvTmFtZSwKICAgICAgICByZWZOYW1lVG9JZCwKICAgICAgICBtYXhCbG9ja1NpemU6IDEgPDwgMTYKICAgICAgfTsKICAgIH0KICAgIHBhcnNlUHNldWRvQmluKGJ5dGVzLCBvZmZzZXQpIHsKICAgICAgY29uc3QgbGluZUNvdW50ID0gbG9uZ1RvTnVtYmVyKGltcG9ydF9sb25nMi5kZWZhdWx0LmZyb21CeXRlc0xFKGJ5dGVzLnNsaWNlKG9mZnNldCArIDE2LCBvZmZzZXQgKyAyNCksIHRydWUpKTsKICAgICAgcmV0dXJuIHsgbGluZUNvdW50IH07CiAgICB9CiAgICBfcGFyc2VOYW1lQnl0ZXMobmFtZXNCeXRlcykgewogICAgICBsZXQgY3VyclJlZklkID0gMDsKICAgICAgbGV0IGN1cnJOYW1lU3RhcnQgPSAwOwogICAgICBjb25zdCByZWZJZFRvTmFtZSA9IFtdOwogICAgICBjb25zdCByZWZOYW1lVG9JZCA9IHt9OwogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IG5hbWVzQnl0ZXMubGVuZ3RoOyBpICs9IDEpIHsKICAgICAgICBpZiAoIW5hbWVzQnl0ZXNbaV0pIHsKICAgICAgICAgIGlmIChjdXJyTmFtZVN0YXJ0IDwgaSkgewogICAgICAgICAgICBsZXQgcmVmTmFtZSA9IG5hbWVzQnl0ZXMudG9TdHJpbmcoInV0ZjgiLCBjdXJyTmFtZVN0YXJ0LCBpKTsKICAgICAgICAgICAgcmVmTmFtZSA9IHRoaXMucmVuYW1lUmVmU2VxKHJlZk5hbWUpOwogICAgICAgICAgICByZWZJZFRvTmFtZVtjdXJyUmVmSWRdID0gcmVmTmFtZTsKICAgICAgICAgICAgcmVmTmFtZVRvSWRbcmVmTmFtZV0gPSBjdXJyUmVmSWQ7CiAgICAgICAgICB9CiAgICAgICAgICBjdXJyTmFtZVN0YXJ0ID0gaSArIDE7CiAgICAgICAgICBjdXJyUmVmSWQgKz0gMTsKICAgICAgICB9CiAgICAgIH0KICAgICAgcmV0dXJuIHsgcmVmTmFtZVRvSWQsIHJlZklkVG9OYW1lIH07CiAgICB9CiAgICBhc3luYyBibG9ja3NGb3JSYW5nZShyZWZOYW1lLCBtaW4sIG1heCwgb3B0cyA9IHt9KSB7CiAgICAgIGlmIChtaW4gPCAwKSB7CiAgICAgICAgbWluID0gMDsKICAgICAgfQogICAgICBjb25zdCBpbmRleERhdGEgPSBhd2FpdCB0aGlzLnBhcnNlKG9wdHMpOwogICAgICBpZiAoIWluZGV4RGF0YSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCByZWZJZCA9IGluZGV4RGF0YS5yZWZOYW1lVG9JZFtyZWZOYW1lXTsKICAgICAgY29uc3QgYmEgPSBpbmRleERhdGEuaW5kaWNlc1tyZWZJZF07CiAgICAgIGlmICghYmEpIHsKICAgICAgICByZXR1cm4gW107CiAgICAgIH0KICAgICAgY29uc3QgbWluT2Zmc2V0ID0gYmEubGluZWFySW5kZXgubGVuZ3RoID8gYmEubGluZWFySW5kZXhbbWluID4+IFRBRF9MSURYX1NISUZUID49IGJhLmxpbmVhckluZGV4Lmxlbmd0aCA/IGJhLmxpbmVhckluZGV4Lmxlbmd0aCAtIDEgOiBtaW4gPj4gVEFEX0xJRFhfU0hJRlRdIDogbmV3IFZpcnR1YWxPZmZzZXQoMCwgMCk7CiAgICAgIGlmICghbWluT2Zmc2V0KSB7CiAgICAgICAgY29uc29sZS53YXJuKCJxdWVyeWluZyBvdXRzaWRlIG9mIHBvc3NpYmxlIHRhYml4IHJhbmdlIik7CiAgICAgIH0KICAgICAgY29uc3Qgb3ZlcmxhcHBpbmdCaW5zID0gcmVnMmJpbnMobWluLCBtYXgpOwogICAgICBjb25zdCBjaHVua3MgPSBbXTsKICAgICAgZm9yIChjb25zdCBbc3RhcnQsIGVuZF0gb2Ygb3ZlcmxhcHBpbmdCaW5zKSB7CiAgICAgICAgZm9yIChsZXQgYmluID0gc3RhcnQ7IGJpbiA8PSBlbmQ7IGJpbisrKSB7CiAgICAgICAgICBpZiAoYmEuYmluSW5kZXhbYmluXSkgewogICAgICAgICAgICBjb25zdCBiaW5DaHVua3MgPSBiYS5iaW5JbmRleFtiaW5dOwogICAgICAgICAgICBmb3IgKGxldCBjID0gMDsgYyA8IGJpbkNodW5rcy5sZW5ndGg7ICsrYykgewogICAgICAgICAgICAgIGNodW5rcy5wdXNoKG5ldyBDaHVuayhiaW5DaHVua3NbY10ubWludiwgYmluQ2h1bmtzW2NdLm1heHYsIGJpbikpOwogICAgICAgICAgICB9CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIGNvbnN0IG5pbnR2ID0gYmEubGluZWFySW5kZXgubGVuZ3RoOwogICAgICBsZXQgbG93ZXN0ID0gbnVsbDsKICAgICAgY29uc3QgbWluTGluID0gTWF0aC5taW4obWluID4+IDE0LCBuaW50diAtIDEpOwogICAgICBjb25zdCBtYXhMaW4gPSBNYXRoLm1pbihtYXggPj4gMTQsIG5pbnR2IC0gMSk7CiAgICAgIGZvciAobGV0IGkgPSBtaW5MaW47IGkgPD0gbWF4TGluOyArK2kpIHsKICAgICAgICBjb25zdCB2cCA9IGJhLmxpbmVhckluZGV4W2ldOwogICAgICAgIGlmICh2cCkgewogICAgICAgICAgaWYgKCFsb3dlc3QgfHwgdnAuY29tcGFyZVRvKGxvd2VzdCkgPCAwKSB7CiAgICAgICAgICAgIGxvd2VzdCA9IHZwOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBsb3dlc3QpOwogICAgfQogIH07CgogIC8vIG5vZGVfbW9kdWxlcy8ucG5wbS9AZ21vZCt0YWJpeEAxLjUuMTEvbm9kZV9tb2R1bGVzL0BnbW9kL3RhYml4L2VzbS9jc2kuanMKICBpbml0X2J1ZmZlcl9zaGltKCk7CiAgdmFyIGltcG9ydF9sb25nMyA9IF9fdG9Nb2R1bGUocmVxdWlyZV9sb25nKCkpOwogIHZhciBDU0kxX01BR0lDID0gMjE1ODI2NTk7CiAgdmFyIENTSTJfTUFHSUMgPSAzODM1OTg3NTsKICBmdW5jdGlvbiBsc2hpZnQobnVtLCBiaXRzKSB7CiAgICByZXR1cm4gbnVtICogMiAqKiBiaXRzOwogIH0KICBmdW5jdGlvbiByc2hpZnQobnVtLCBiaXRzKSB7CiAgICByZXR1cm4gTWF0aC5mbG9vcihudW0gLyAyICoqIGJpdHMpOwogIH0KICB2YXIgQ1NJID0gY2xhc3MgZXh0ZW5kcyBJbmRleEZpbGUgewogICAgY29uc3RydWN0b3IoYXJncykgewogICAgICBzdXBlcihhcmdzKTsKICAgICAgdGhpcy5tYXhCaW5OdW1iZXIgPSAwOwogICAgICB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4gewogICAgICAgIGNvbnN0IGJpbkNvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCk7CiAgICAgICAgY3Vyck9mZnNldCArPSA0OwogICAgICAgIGNvbnN0IGJpbkluZGV4ID0ge307CiAgICAgICAgbGV0IHN0YXRzOwogICAgICAgIGZvciAobGV0IGogPSAwOyBqIDwgYmluQ291bnQ7IGogKz0gMSkgewogICAgICAgICAgY29uc3QgYmluID0gYnl0ZXMucmVhZFVJbnQzMkxFKGN1cnJPZmZzZXQpOwogICAgICAgICAgaWYgKGJpbiA+IHRoaXMubWF4QmluTnVtYmVyKSB7CiAgICAgICAgICAgIHN0YXRzID0gdGhpcy5wYXJzZVBzZXVkb0JpbihieXRlcywgY3Vyck9mZnNldCArIDQpOwogICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDQgKyA4ICsgNCArIDE2ICsgMTY7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBjb25zdCBsb2Zmc2V0ID0gZnJvbUJ5dGVzKGJ5dGVzLCBjdXJyT2Zmc2V0ICsgNCk7CiAgICAgICAgICAgIGZpcnN0RGF0YUxpbmUgPSB0aGlzLl9maW5kRmlyc3REYXRhKGZpcnN0RGF0YUxpbmUsIGxvZmZzZXQpOwogICAgICAgICAgICBjb25zdCBjaHVua0NvdW50ID0gYnl0ZXMucmVhZEludDMyTEUoY3Vyck9mZnNldCArIDEyKTsKICAgICAgICAgICAgY3Vyck9mZnNldCArPSAxNjsKICAgICAgICAgICAgY29uc3QgY2h1bmtzID0gbmV3IEFycmF5KGNodW5rQ291bnQpOwogICAgICAgICAgICBmb3IgKGxldCBrID0gMDsgayA8IGNodW5rQ291bnQ7IGsgKz0gMSkgewogICAgICAgICAgICAgIGNvbnN0IHUgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQpOwogICAgICAgICAgICAgIGNvbnN0IHYgPSBmcm9tQnl0ZXMoYnl0ZXMsIGN1cnJPZmZzZXQgKyA4KTsKICAgICAgICAgICAgICBjdXJyT2Zmc2V0ICs9IDE2OwogICAgICAgICAgICAgIGNodW5rc1trXSA9IG5ldyBDaHVuayh1LCB2LCBiaW4pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJpbkluZGV4W2Jpbl0gPSBjaHVua3M7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHJldHVybiB7IGJpbkluZGV4LCBzdGF0cyB9OwogICAgICB9KTsKICAgICAgcmV0dXJuIHsKICAgICAgICAuLi5hdXgsCiAgICAgICAgY3NpOiB0cnVlLAogICAgICAgIHJlZkNvdW50LAogICAgICAgIG1heEJsb2NrU2l6ZTogMSA8PCAxNiwKICAgICAgICBmaXJzdERhdGFMaW5lLAogICAgICAgIGNzaVZlcnNpb24sCiAgICAgICAgaW5kaWNlcywKICAgICAgICBkZXB0aDogdGhpcy5kZXB0aCwKICAgICAgICBtYXhCaW5OdW1iZXI6IHRoaXMubWF4QmluTnVtYmVyLAogICAgICAgIG1heFJlZkxlbmd0aAogICAgICB9OwogICAgfQogICAgcGFyc2VQc2V1ZG9CaW4oYnl0ZXMsIG9mZnNldCkgewogICAgICBjb25zdCBsaW5lQ291bnQgPSBsb25nVG9OdW1iZXIoaW1wb3J0X2xvbmczLmRlZmF1bHQuZnJvbUJ5dGVzTEUoYnl0ZXMuc2xpY2Uob2Zmc2V0ICsgMjgsIG9mZnNldCArIDM2KSwgdHJ1ZSkpOwogICAgICByZXR1cm4geyBsaW5lQ291bnQgfTsKICAgIH0KICAgIGFzeW5jIGJsb2Nrc0ZvclJhbmdlKHJlZk5hbWUsIG1pbiwgbWF4LCBvcHRzID0ge30pIHsKICAgICAgaWYgKG1pbiA8IDApIHsKICAgICAgICBtaW4gPSAwOwogICAgICB9CiAgICAgIGNvbnN0IGluZGV4RGF0YSA9IGF3YWl0IHRoaXMucGFyc2Uob3B0cyk7CiAgICAgIGlmICghaW5kZXhEYXRhKSB7CiAgICAgICAgcmV0dXJuIFtdOwogICAgICB9CiAgICAgIGNvbnN0IHJlZklkID0gaW5kZXhEYXRhLnJlZk5hbWVUb0lkW3JlZk5hbWVdOwogICAgICBjb25zdCBiYSA9IGluZGV4RGF0YS5pbmRpY2VzW3JlZklkXTsKICAgICAgaWYgKCFiYSkgewogICAgICAgIHJldHVybiBbXTsKICAgICAgfQogICAgICBjb25zdCBvdmVybGFwcGluZ0JpbnMgPSB0aGlzLnJlZzJiaW5zKG1pbiwgbWF4KTsKICAgICAgY29uc3QgY2h1bmtzID0gW107CiAgICAgIGZvciAoY29uc3QgW3N0YXJ0LCBlbmRdIG9mIG92ZXJsYXBwaW5nQmlucykgewogICAgICAgIGZvciAobGV0IGJpbiA9IHN0YXJ0OyBiaW4gPD0gZW5kOyBiaW4rKykgewogICAgICAgICAgaWYgKGJhLmJpbkluZGV4W2Jpbl0pIHsKICAgICAgICAgICAgY29uc3QgYmluQ2h1bmtzID0gYmEuYmluSW5kZXhbYmluXTsKICAgICAgICAgICAgZm9yIChsZXQgYyA9IDA7IGMgPCBiaW5DaHVua3MubGVuZ3RoOyArK2MpIHsKICAgICAgICAgICAgICBjaHVua3MucHVzaChuZXcgQ2h1bmsoYmluQ2h1bmtzW2NdLm1pbnYsIGJpbkNodW5rc1tjXS5tYXh2LCBiaW4pKTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgfQogICAgICByZXR1cm4gb3B0aW1pemVDaHVua3MoY2h1bmtzLCBuZXcgVmlydHVhbE9mZnNldCgwLCAwKSk7CiAgICB9CiAgICByZWcyYmlucyhiZWcsIGVuZCkgewogICAgICBiZWcgLT0gMTsKICAgICAgaWYgKGJlZyA8IDEpIHsKICAgICAgICBiZWcgPSAxOwogICAgICB9CiAgICAgIGlmIChlbmQgPiAyICoqIDUwKSB7CiAgICAgICAgZW5kID0gMiAqKiAzNDsKICAgICAgfQogICAgICBlbmQgLT0gMTsKICAgICAgbGV0IGwgPSAwOwogICAgICBsZXQgdCA9IDA7CiAgICAgIGxldCBzID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pdCB0aGlzLmNodW5rQ2FjaGUuZ2V0KGMudG9TdHJpbmcoKSwgYyk7CiAgICAgICAgY2hlY2tBYm9ydFNpZ25hbChzaWduYWwpOwogICAgICAgIGxldCBibG9ja1N0YXJ0ID0gMDsKICAgICAgICBsZXQgcG9zID0gMDsKICAgICAgICB3aGlsZSAoYmxvY2tTdGFydCA8IGJ1ZmZlci5sZW5ndGgpIHsKICAgICAgICAgIGNvbnN0IG4gPSBidWZmZXIuaW5kZXhPZigiXG4iLCBibG9ja1N0YXJ0KTsKICAgICAgICAgIGlmIChuID09PSAtMSkgewogICAgICAgICAgICBicmVhazsKICAgICAgICAgIH0KICAgICAgICAgIGNvbnN0IGIgPSBidWZmZXIuc2xpY2UoYmxvY2tTdGFydCwgbik7CiAgICAgICAgICBjb25zdCBsaW5lID0gKGRlY29kZXIgPT09IG51bGwgfHwgZGVjb2RlciA9PT0gdm9pZCAwID8gdm9pZCAwIDogZGVjb2Rlci5kZWNvZGUoYikpIHx8IGIudG9TdHJpbmcoKTsKICAgICAgICAgIGlmIChkcG9zaXRpb25zKSB7CiAgICAgICAgICAgIHdoaWxlIChibG9ja1N0YXJ0ICsgYy5taW52LmRhdGFQb3NpdGlvbiA+PSBkcG9zaXRpb25zW3BvcysrXSkgewogICAgICAgICAgICB9CiAgICAgICAgICAgIHBvcy0tOwogICAgICAgICAgfQogICAgICAgICAgY29uc3QgeyBzdGFydENvb3JkaW5hdGUsIG92ZXJsYXBzIH0gPSB0aGlzLmNoZWNrTGluZShtZXRhZGF0YSwgcmVmTmFtZSwgc3RhcnQsIGVuZCwgbGluZSk7CiAgICAgICAgICBpZiAocHJldmlvdXNTdGFydENvb3JkaW5hdGUgIT09IHZvaWQgMCAmJiBzdGFydENvb3JkaW5hdGUgIT09IHZvaWQgMCAmJiBwcmV2aW91c1N0YXJ0Q29vcmRpbmF0ZSA+IHN0YXJ0Q29vcmRpbmF0ZSkgewogICAgICAgICAgICB0aHJvdyBuZXcgRXJyb3IoYExpbm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ogICAgICB9CiAgICAgIGlmIChmb3JtYXQgPT09ICJWQ0YiKSB7CiAgICAgICAgZW5kID0gODsKICAgICAgfQogICAgICBjb25zdCBtYXhDb2x1bW4gPSBNYXRoLm1heChyZWYsIHN0YXJ0LCBlbmQpOwogICAgICBsZXQgY3VycmVudENvbHVtbk51bWJlciA9IDE7CiAgICAgIGxldCBjdXJyZW50Q29sdW1uU3RhcnQgPSAwOwogICAgICBsZXQgcmVmU2VxID0gIiI7CiAgICAgIGxldCBzdGFydENvb3JkaW5hdGUgPSAtSW5maW5pdHk7CiAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgbGluZS5sZW5ndGggKyAxOyBpICs9IDEpIHsKICAgICAgICBpZiAobGluZVtpXSA9PT0gIgkiIHx8IGkgPT09IGxpbmUubGVuZ3RoKSB7CiAgICAgICAgICBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gcmVmKSB7CiAgICAgICAgICAgIGlmICh0aGlzLnJlbmFtZVJlZlNlcShsaW5lLnNsaWNlKGN1cnJlbnRDb2x1bW5TdGFydCwgaSkpICE9PSByZWdpb25SZWZOYW1lKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgc3RhcnRDb29yZGluYXRlID0gcGFyc2VJbnQobGluZS5zbGljZShjdXJyZW50Q29sdW1uU3RhcnQsIGkpLCAxMCk7CiAgICAgICAgICAgIGlmIChjb29yZGluYXRlVHlwZSA9PT0gIjEtYmFzZWQtY2xvc2VkIikgewogICAgICAgICAgICAgIHN0YXJ0Q29vcmRpbmF0ZSAtPSAxOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChzdGFydENvb3JkaW5hdGUgPj0gcmVnaW9uRW5kKSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpZiAoZW5kID09PSAwIHx8IGVuZCA9PT0gc3RhcnQpIHsKICAgICAgICAgICAgICBpZiAoc3RhcnRDb29yZGluYXRlICsgMSA8PSByZWdpb25TdGFydCkgewogICAgICAgICAgICAgICAgcmV0dXJuIHsgc3RhcnRDb29yZGluYXRlLCBvdmVybGFwczogZmFsc2UgfTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgIH0gZWxzZSBpZiAoZm9ybWF0ID09PSAiVkNGIiAmJiBjdXJyZW50Q29sdW1uTnVtYmVyID09PSA0KSB7CiAgICAgICAgICAgIHJlZlNlcSA9IGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKTsKICAgICAgICAgIH0gZWxzZSBpZiAoY3VycmVudENvbHVtbk51bWJlciA9PT0gZW5kKSB7CiAgICAgICAgICAgIGxldCBlbmRDb29yZGluYXRlOwogICAgICAgICAgICBpZiAoZm9ybWF0ID09PSAiVkNGIikgewogICAgICAgICAgICAgIGVuZENvb3JkaW5hdGUgPSB0aGlzLl9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSk7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgZW5kQ29vcmRpbmF0ZSA9IHBhcnNlSW50KGxpbmUuc2xpY2UoY3VycmVudENvbHVtblN0YXJ0LCBpKSwgMTApOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGlmIChlbmRDb29yZGluYXRlIDw9IHJlZ2lvblN0YXJ0KSB7CiAgICAgICAgICAgICAgcmV0dXJuIHsgb3ZlcmxhcHM6IGZhbHNlIH07CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAgICAgIGN1cnJlbnRDb2x1bW5TdGFydCA9IGkgKyAxOwogICAgICAgICAgY3VycmVudENvbHVtbk51bWJlciArPSAxOwogICAgICAgICAgaWYgKGN1cnJlbnRDb2x1bW5OdW1iZXIgPiBtYXhDb2x1bW4pIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICAgIHJldHVybiB7IHN0YXJ0Q29vcmRpbmF0ZSwgb3ZlcmxhcHM6IHRydWUgfTsKICAgIH0KICAgIF9nZXRWY2ZFbmQoc3RhcnRDb29yZGluYXRlLCByZWZTZXEsIGluZm8pIHsKICAgICAgbGV0IGVuZENvb3JkaW5hdGUgPSBzdGFydENvb3JkaW5hdGUgKyByZWZTZXEubGVuZ3RoOwogICAgICBjb25zdCBpc1RSQSA9IGluZm8uaW5kZXhPZigiU1ZUWVBFPVRSQSIpICE9PSAtMTsKICAgICAgaWYgKGluZm9bMF0gIT09ICIuIiAmJiAhaXNUUkEpIHsKICAgICAgICBsZXQgcHJldkNoYXIgPSAiOyI7CiAgICAgICAgZm9yIChsZXQgaiA9IDA7IGogPCBpbmZvLmxlbmd0aDsgaiArPSAxKSB7CiAgICAgICAgICBpZiAocHJldkNoYXIgPT09ICI7IiAmJiBpbmZvLnNsaWNlKGosIGogKyA0KSA9PT0gIkVORD0iKSB7CiAgICAgICAgICAgIGxldCB2YWx1ZUVuZCA9IGluZm8uaW5kZXhPZigiOyIsIGopOwogICAgICAgICAgICBpZiAodmFsdWVFbmQgPT09IC0xKSB7CiAgICAgICAgICAgICAgdmFsdWVFbmQgPSBpbmZvLmxlbmd0aDsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbmRDb29yZGluYXRlID0gcGFyc2VJbnQoaW5mby5zbGljZShqICsgNCwgdmFsdWVFbmQpLCAxMCk7CiAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgfQogICAgICAgICAgcHJldkNoYXIgPSBpbmZvW2pdOwogICAgICAgIH0KICAgICAgfSBlbHNlIGlmIChpc1RSQSkgewogICAgICAgIHJldHVybiBzdGFydENvb3Jka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oZCkgLSB4OwogICAgICBjb21wYXJlID0gYXNjZW5kaW5nQ29tcGFyYXRvcihmKTsKICAgIH0KICAgIGZ1bmN0aW9uIGxlZnQoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgd2hpbGUgKGxvIDwgaGkpIHsKICAgICAgICBjb25zdCBtaWQgPSBsbyArIGhpID4+PiAxOwogICAgICAgIGlmIChjb21wYXJlKGFbbWlkXSwgeCkgPCAwKQogICAgICAgICAgbG8gPSBtaWQgKyAxOwogICAgICAgIGVsc2UKICAgICAgICAgIGhpID0gbWlkOwogICAgICB9CiAgICAgIHJldHVybiBsbzsKICAgIH0KICAgIGZ1bmN0aW9uIHJpZ2h0KGEsIHgsIGxvLCBoaSkgewogICAgICBpZiAobG8gPT0gbnVsbCkKICAgICAgICBsbyA9IDA7CiAgICAgIGlmIChoaSA9PSBudWxsKQogICAgICAgIGhpID0gYS5sZW5ndGg7CiAgICAgIHdoaWxlIChsbyA8IGhpKSB7CiAgICAgICAgY29uc3QgbWlkID0gbG8gKyBoaSA+Pj4gMTsKICAgICAgICBpZiAoY29tcGFyZShhW21pZF0sIHgpID4gMCkKICAgICAgICAgIGhpID0gbWlkOwogICAgICAgIGVsc2UKICAgICAgICAgIGxvID0gbWlkICsgMTsKICAgICAgfQogICAgICByZXR1cm4gbG87CiAgICB9CiAgICBmdW5jdGlvbiBjZW50ZXIoYSwgeCwgbG8sIGhpKSB7CiAgICAgIGlmIChsbyA9PSBudWxsKQogICAgICAgIGxvID0gMDsKICAgICAgaWYgKGhpID09IG51bGwpCiAgICAgICAgaGkgPSBhLmxlbmd0aDsKICAgICAgY29uc3QgaSA9IGxlZnQoYSwgeCwgbG8sIGhpIC0gMSk7CiAgICAgIHJldHVybiBpID4gbG8gJiYgZGVsdGEoYVtpIC0gMV0sIHgpID4g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heS5pc0FycmF5KGxpbmUpID8gbGluZSA6IGxpbmUuc3BsaXQoIgkiKTsKICAgICAgbGV0IGZlYXR1cmUgPSB7fTsKICAgICAgaWYgKCF0aGlzLmF0dGVtcHREZWZhdWx0QmVkIHx8IHRoaXMuYXR0ZW1wdERlZmF1bHRCZWQgJiYgaXNCZWQxMkxpa2UoZmllbGRzKSkgewogICAgICAgIGZvciAobGV0IGkgPSAwOyBpIDwgYXV0b1NxbC5maWVsZHMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgIGNvbnN0IGF1dG9GaWVsZCA9IGF1dG9TcWwuZmllbGRzW2ldOwogICAgICAgICAgbGV0IGNvbHVtblZhbCA9IGZpZWxkc1tpXTsKICAgICAgICAgIGNvbnN0IHsgaXNOdW1lcmljLCBpc0FycmF5OiBpc0FycmF5MiwgYXJyYXlJc051bWVyaWMsIG5hbWUgfSA9IGF1dG9GaWVsZDsKICAgICAgICAgIGlmIChjb2x1bW5WYWwgPT09IG51bGwgfHwgY29sdW1uVmFsID09PSB2b2lkIDApIHsKICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICB9CiAgICAgICAgICBpZiAoY29sdW1uVmFsICE9PSAiLiIpIHsKICAgICAgICAgICAgaWYgKGlzTnVtZXJpYykgewogICAgICAgICAgICAgIGNvbnN0IG51bSA9IE51bWJlcihjb2x1bW5WYWwpOwogICAgICAgICAgICAgIGNvbHVtblZhbCA9IE51bWJlci5pc05hTihudW0pID8gY29sdW1uVmFsIDogbnVtOwogICAgICAgICAgICB9IGVsc2UgaWYgKGlzQXJyYXkyKSB7CiAgICAgICAgICAgICAgY29sdW1uVmFsID0gY29sdW1uVmFsLnNwbGl0KCIsIik7CiAgICAgICAgICAgICAgaWYgKGNvbHVtblZhbFtjb2x1bW5WYWwubGVuZ3RoIC0gMV0gPT09ICIiKSB7CiAgICAgICAgICAgICAgICBjb2x1bW5WYWwucG9wKCk7CiAgICAgICAgICAgICAgfQogICAgICAgICAgICAgIGlmIChhcnJheUlz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idWludCIsICJjaHJvbVN0YXJ0Il0sCiAgICAgICAgWyJ1aW50IiwgImNocm9tRW5kIl0sCiAgICAgICAgWyJzdHJpbmciLCAibmFtZSJdLAogICAgICAgIFsiZmxvYXQiLCAic2NvcmUiXSwKICAgICAgICBbImNoYXIiLCAic3RyYW5kIl0sCiAgICAgICAgWyJ1aW50IiwgInRoaWNrU3RhcnQiXSwKICAgICAgICBbInVpbnQiLCAidGhpY2tFbmQiXSwKICAgICAgICBbInN0cmluZyIsICJpdGVtUmdiIl0sCiAgICAgICAgWyJ1aW50IiwgImJsb2NrQ291bnQiXSwKICAgICAgICBbInVpbnRbYmxvY2tDb3VudF0iLCAiYmxvY2tTaXplcyJdLAogICAgICAgIFsidWludFtibG9ja0NvdW50XSIsICJibG9ja1N0YXJ0cyJdCiAgICAgIF07CiAgICAgIGlmICghdGhpcy4jbl9jb2x1bW5zKQogICAgICAgIHRocm93IG5ldyBFcnJvcigiTnVtYmVyIG9mIGNvbHVtbnMgd2FzIG5vdCBhYmxlIHRvIGJlIGRldGVybWluZWQiKTsKICAgICAgaWYgKCF0aGlzLiNjdXN0b21GaWVsZHMpCiAgICAgICAgcmV0dXJuICIiOwogICAgICBjb25zdCBjdXN0b21GaWVsZFR5cGUgPSAic3RyaW5nIjsKICAgICAgY29uc3QgY3VzdG9tRmllbGRzV2l0aFR5cGVzID0gdGhpcy4jY3VzdG9tRmllbGRzLm1hcCgoY29sdW1uKSA9PiBbY3VzdG9tRmllbGRUeXBlLCBjb2x1bW5dKTsKICAgICAgbGV0IGFsbEZpZWxkczsKICAgICAgY29uc3QgUkVRVUlSRURfQ09MUyA9IDM7CiAgICAgIGlmICh0aGlzLiNuX2NvbHVtbnMgPiBCRUQxMkZpZWxkcy5sZW5ndGgpIHsKICAgICAgICBpZiAodGhpcy4jbl9jb2x1bW5zICE9PSBCRUQxMkZpZWxkcy5sZW5ndGggKyB0aGlzLiNjdXN0b21GaWVsZHMubGVuZ3RoKSB7CiAgICAgICAgICB0a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CBvcHQgPSB0aGlzLiNjdXN0b21GaWVsZHMgPyB7IGN1c3RvbUZpZWxkczogdGhpcy4jY3VzdG9tRmllbGRzLCBuX2NvbHVtbnM6IGF3YWl0IHRoaXMuI2NhbGNOQ29sdW1ucygpIH0gOiB2b2lkIDA7CiAgICAgICAgdGhpcy4jcGFyc2VyID0gbmV3IGJlZF9wYXJzZXJfZGVmYXVsdChvcHQpOwogICAgICB9CiAgICAgIHJldHVybiB0aGlzLiNwYXJzZXI7CiAgICB9CiAgICBhc3luYyAjY2FsY05Db2x1bW5zKCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgbGV0IG5fY29scyA9IDA7CiAgICAgIGZvciAoY29uc3QgY3VtUG9zIG9mIGN1bVBvc2l0aW9ucykgewogICAgICAgIGNvbnN0IGNocm9tTmFtZSA9IGN1bVBvcy5jaHI7CiAgICAgICAgY29uc3QgY2hyb21TdGFydCA9IGN1bVBvcy5wb3M7CiAgICAgICAgY29uc3QgY2hyb21FbmQgPSBjdW1Qb3MucG9zICsgY2hyb21MZW5ndGhzW2Nocm9tTmFtZV07CiAgICAgICAgbl9jb2xzID0gYXdhaXQgbmV3IFByb21pc2UoKHJlc29sdmUpID0+IHsKICAgICAgICAgIHNvdXJjZS5maWxlLnRiaS5nZXRMaW5lcyhjaHJvbU5hbWUsIGNocm9tU3RhcnQsIGNocm9tRW5kLCAobGluZSkgPT4gewogICAgICAgICAgICByZXNvbHZlKGxpbmUuc3BsaXQoIgkiKS5sZW5ndGgpOwogICAgICAgICAgfSk7CiAgICAgICAgfSk7CiAgICAgICAgaWYgKG5fY29scyA+IDApCiAgICAgICAgICBicmVhazsKICAgICAgfQogICAgICByZXR1cm4gbl9jb2xzOwogICAgfQogICAgYXN5bmMgZ2V0VGlsZURhdGEobWluWCwgbWF4WCkgewogICAgICBjb25zdCBzb3VyY2UgPSBkYXRhU291cmNlcy5nZXQodGhpcy4jdWlkKTsKICAgICAgY29uc3QgcGFyc2VyMiA9IGF3YWl0IHRoaXMuZ2V0UGFyc2VyKCk7CiAgICAgIGxldCBjdXJNaW5YID0gbWluWDsKICAgICAgY29uc3QgeyBjaHJvbUxlbmd0aHMsIGN1bVBvc2l0aW9ucyB9ID0gc291cmNlLmNocm9tSW5mbzsKICAgICAgY29uc3QgYWxsVGlsZXMgPSBbXTsKICAgICAgZm9yIChjb25zdCBjdW1Qb3Mgb2YgY3VtUG9zaXRpb25zKSB7CiAgICAgICAgY29uc3QgY2hyb21OYW1lID0gY3VtUG9zLmNocjsKICAgICAgICBjb25zdCBjaHJvbVN0YXJ0ID0gY3VtUG9zLnBvczsKICAgICAgICBjb25zdCBjaHJvbUVuZCA9IGN1bVBvcy5wb3MgKyBjaHJvbUxlbmd0aHNbY2hyb21OYW1lXTsKICAgICAgICBsZXQgc3RhcnRQb3MsIGVuZFBvczsKICAgICAgICBpZiAoY2hyb21TdGFydCA+IGN1ck1pblggfHwgY3VyTWluWCA+PSBjaHJvbUVuZCkgewogICAgICAgICAgY29udGludWU7CiAgICAgICAgfQogICAgICAgIGNvbnN0IHRpbGVzUHJvbWlzZSA9IG5ldyBQcm9taXNlKChyZXNvbHZlKSA9PiB7CiAgICAgICAgICBjb25zdCB0aWxlcyA9IFtdOwogICAgICAgICAgY29uc3QgbGluZUNhbGxiYWNrID0gKGxpbmUpID0+IHsKICAgICAgICAgICAgY29uc3QgYmVkVGlsZSA9IHBhcnNlcjIucGFyc2VMaW5lKGxpbmUsIGNocm9tU3RhcnQpOwogICAgICAgICAgICB0aWxlcy5wdXNoKGJlZFRpbGUpOwogICAgICAgICAgfTsKICAgICAgICAgIGlmIChtYXhYID4gY2hyb21FbmQpIHsKICAgICAgICAgICAgc3RhcnRQb3MgPSBjdXJNaW5YIC0gY2hyb21TdGFydDsKICAgICAg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m91bmNlZCA9IGFzeW5jICh1aWQsIHRpbGVJZHMpID0+IHsKICAgIGNvbnN0IHRpbGVzID0ge307CiAgICBjb25zdCB2YWxpZFRpbGVJZHMgPSBbXTsKICAgIGNvbnN0IHRpbGVQcm9taXNlcyA9IFtdOwogICAgZm9yIChjb25zdCB0aWxlSWQgb2YgdGlsZUlkcykgewogICAgICBjb25zdCBwYXJ0cyA9IHRpbGVJZC5zcGxpdCgiLiIpOwogICAgICBjb25zdCB6ID0gcGFyc2VJbnQocGFydHNbMF0sIDEwKTsKICAgICAgY29uc3QgeCA9IHBhcnNlSW50KHBhcnRzWzFdLCAxMCk7CiAgICAgIGlmIChOdW1iZXIuaXNOYU4oeCkgfHwgTnVtYmVyLmlzTmFOKHopKSB7CiAgICAgICAgY29uc29sZS53YXJuKCJJbnZhbGlkIHRpbGUgem9vbSBvciBwb3NpdGlvbjoiLCB6LCB4KTsKICAgICAgICBjb250aW51ZTsKICAgICAgfQogICAgICB2YWxpZFRpbGVJZHMucHVzaCh0aWxlSWQpOwogICAgICB0aWxlUHJvbWlzZXMucHVzaCh0aWxlKHVpZCwgeiwgeCkpOwogICAgfQogICAgcmV0dXJuIFByb21pc2UuYWxsKHRpbGVQcm9taXNlcykudGhlbigodmFsdWVzMikgPT4gewogICAgICBmb3IgKGxldCBpID0gMDsgaSA8IHZhbHVlczIubGVuZ3RoOyBpKyspIHsKICAgICAgICBjb25zdCB2YWxpZFRpbGVJZCA9IHZhbGlkVGlsZUlkc1tpXTsKICAgICAgICB0aWxlc1t2YWxpZFRpbGVJZF0gPSB7IHRpbGVQb3NpdGlvbklkOiB2YWxpZFRpbGVJZCB9OwogICAgICB9CiAgICAgIHJldHVybiB0aWxlczsKICAgIH0pOwogIH07CiAgdmFyIGdldFRhYnVsYXJEYXRhID0gKHVpZCwgdGlsZUlkcykgPT4gewogICAgY29uc3QgZGF0YSA9IFtdOwogICAgdGlsZUlkcy5mb3JFYWNoKCh0aWxlSWQpID0+IHsKICAgICAgY29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sIGZvciB0aGUgYnJvd3Nlci4KICoKICogQGF1dGhvciAgIEZlcm9zcyBBYm91a2hhZGlqZWggPGh0dHBzOi8vZmVyb3NzLm9yZz4KICogQGxpY2Vuc2UgIE1JVAogKi8KLyohIGllZWU3NTQuIEJTRC0zLUNsYXVzZSBMaWNlbnNlLiBGZXJvc3MgQWJvdWtoYWRpamVoIDxodHRwczovL2Zlcm9zcy5vcmcvb3BlbnNvdXJjZT4gKi8KLyoqCiAqIEBsaWNlbnNlCiAqIExvZGFzaCAoQ3VzdG9tIEJ1aWxkKSA8aHR0cHM6Ly9sb2Rhc2guY29tLz4KICogQnVpbGQ6IGBsb2Rhc2ggbW9kdWxhcml6ZSBleHBvcnRzPSJlcyIgLW8gLi9gCiAqIENvcHlyaWdodCBPcGVuSlMgRm91bmRhdGlvbiBhbmQgb3RoZXIgY29udHJpYnV0b3JzIDxodHRwczovL29wZW5qc2Yub3JnLz4KICogUmVsZWFzZWQgdW5kZXIgTUlUIGxpY2Vuc2UgPGh0dHBzOi8vbG9kYXNoLmNvbS9saWNlbnNlPgogKiBCYXNlZCBvbiBVbmRlcnNjb3JlLmpzIDEuOC4zIDxodHRwOi8vdW5kZXJzY29yZWpzLm9yZy9MSUNFTlNFPgogKiBDb3B5cmlnaHQgSmVyZW15IEFzaGtlbmFzLCBEb2N1bWVudENsb3VkIGFuZCBJbnZlc3RpZ2F0aXZlIFJlcG9ydGVycyAmIEVkaXRvcnMKICovCg==",nce=typeof window<"u"&&window.Blob&&new Blob([atob(j2e)],{type:"text/javascript;charset=utf-8"});function Cng(){const e=nce&&(window.URL||window.webkitURL).createObjectURL(nce);try{return e?new Worker(e):new Worker("data:application/javascript;base64,"+j2e,{type:"module"})}finally{e&&(window.URL||window.webkitURL).revokeObjectURL(e)}}const ong=200;class $2e{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:r,...C}=i;this.worker=LT(new Cng).then(async o=>{const a=Object.entries(bi(r).size);return await o.init(this.uid,{url:I,indexUrl:n},a,C),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()},ong)}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($2e,"config",{type:"bed"});const ang=Object.freeze(Object.defineProperty({__proto__:null,BamDataFetcher:RH,BedDataFetcher:$2e,BigWigDataFetcher:J2e,CsvDataFetcher:_2e,GffDataFetcher:Q2e,JsonDataFetcher:L2e,VcfDataFetcher:p2e},Symbol.toStringTag,{value:"Module"})),Ang="gosling-data-row-uid";function sng(e,g){var i,I,n,r,C,o,a,s,A,l,c,u,d,h,m,f;const b=[];if(!A7(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=(r=e.data.start)!=null?r:"start",R=(C=e.data.end)!=null?C:"end",S=`${G}_min`,X=`${G}_max`,W=(o=e.data.aggregation)!=null?o:"mean";let V=0,H=Number.MAX_SAFE_INTEGER,Y=Number.MIN_SAFE_INTEGER,K=Number.MIN_SAFE_INTEGER,x=Number.MAX_SAFE_INTEGER;Array.from(Array(Z).keys()).forEach((J,P)=>{if(p===1){const ge=y[P]/(W==="mean"?B:1);b.push({[G]:ge,[v]:g.tileX+(P+.5)*B,[w]:g.tileX+P*B,[R]:g.tileX+(P+1)*B,[S]:ge,[X]:ge})}else if(P%p===0)V=H=Y=y[P],K=P,x=P+p;else if(P%p===p-1)b.push({[G]:V/p/(W==="mean"?B:1),[v]:g.tileX+(K+p/2)*B,[w]:g.tileX+K*B,[R]:g.tileX+x*B,[S]:H,[X]:Y});else if(P===Z-1){const ge=Z%p,q=K+ge;b.push({[G]:V/ge/(W==="mean"?B:1),[v]:g.tileX+(K+ge/2)*B,[w]:g.tileX+K*B,[R]:g.tileX+q*B,[S]:H,[X]:Y})}else V+=y[P],H>y[P]&&(H=y[P]),Y{let J=0,P=Number.MIN_SAFE_INTEGER,ge=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 Q=B[G*x+te]/(Y==="mean"?v:1);b.push({[w]:K,[R]:Q,[S]:g.tileX+(te+.5)*v,[X]:g.tileX+te*v,[W]:g.tileX+(te+1)*v,[V]:Q,[H]:Q})}else if(te%p===0)J=q=$=B[G*x+te],P=te,ge=te+p;else if(te%p===p-1)b.push({[w]:K,[R]:Y==="mean"?J/p/v:J,[S]:g.tileX+(P+p/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+ge*v,[V]:q,[H]:$});else if(te===G-1){const Q=G%p,Ie=P+Q;b.push({[w]:K,[R]:Y==="mean"?J/Q/v:J,[S]:g.tileX+(P+Q/2)*v,[X]:g.tileX+P*v,[W]:g.tileX+Ie*v,[V]:q,[H]:$})}else{const Q=B[G*x+te];J+=Q,q>Q&&(q=Q),$"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,R=G/p,S=(m=e.data.column)!=null?m:"x",X=(f=e.data.row)!=null?f:"y",W=16;for(let V=0;V{const{chrOffset:v,fields:w}=B,R={};if(R[Ang]=`${G}`,p.forEach(S=>{R[S.name]=+w[S.index]+v}),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,Y)=>{const K=V[Y];if(b.push({...R,[S.name]:+H+v,[X.name]:+K+v,type:"exon"}),Y+1n===e.chromosome))){if(vje(e))return[i[e.chromosome][0]+1,i[e.chromosome][1]];if(Bje(e))return e.interval;if(Sje(e)){const I=i[e.chromosome][0],[n,r]=e.interval;return[I+n,I+r]}}}function hng(e,g){const i={},I=Xd;e.forEach(n=>{I.forEach(r=>{const C=n.spec()[r];if(!ut(C)||C.domain===void 0)return;const{domain:o,type:a}=C;if(a==="quantitative"){const s=Array.from(o);if(!i[r])i[r]=s;else{const A=i[r];A[0]>s[0]&&(A[0]=s[0]),A[1]{I.forEach(r=>{const C=n.spec()[r];ut(C)&&C.type==="genomic"||(n.setChannelDomain(r,i[r],g),n.generateScales())}),n.updateChannelValue()})}const mng={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"},UC=30,fng=e=>({genomePositionSearchBoxVisible:!1,genomePositionSearchBox:{autocompleteServer:"https://higlass.io/api/v1",autocompleteId:c6e(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,bi(e).total],initialYDomain:[0,bi(e).total],zoomFixed:!1});class png{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({...fng(i),uid:g}))),this}setAssembly(g){return this.assembly=g,this.setChromInfoPath(bi(this.assembly).path),this}getAssembly(){return this.assembly}setTextTrack(g,i,I,n="black",r=14,C="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:r,fontWeight:C,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,r){var C,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:ln(),fromViewUid:n,options:{projectionFillColor:(C=r==null?void 0:r.color)!=null?C:I.brush.color,projectionStrokeColor:(o=r==null?void 0:r.stroke)!=null?o:I.brush.stroke,projectionFillOpacity:(a=r==null?void 0:r.opacity)!=null?a:I.brush.opacity,projectionStrokeOpacity:(s=r==null?void 0:r.opacity)!=null?s:I.brush.opacity,strokeWidth:(A=r==null?void 0:r.strokeWidth)!=null?A:I.brush.strokeWidth,startAngle:r==null?void 0:r.startAngle,endAngle:r==null?void 0:r.endAngle,innerRadius:r==null?void 0:r.innerRadius,outerRadius:r==null?void 0:r.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 c2e(dng,this.spec(),g).state==="success"}setDomain(g,i){return g&&(this.getLastView().initialXDomain=u_(g,this.getAssembly())),i&&(this.getLastView().initialYDomain=u_(i,this.getAssembly())),this}adjustDomain(g="horizontal",i,I){if(g!=="vertical")return this;const n=this.getLastView().initialXDomain;if(!n)return this;const[r,C]=n,o=C-r,a=(r+C)/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:ln()}-${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",r={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({...r,options:{...r.options,layout:"circular"}});else{const C={...r,[n]:UC};if(g==="left"){if(this.getLastView().tracks.left.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.left=tje(this.getLastView().tracks.left,0,C)}else if(g==="right"){if(this.getLastView().tracks.right.filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks.right.push(C)}else{if(this.getLastView().tracks[g].filter(o=>o.type==="axis-track").length!==0)return this;this.getLastView().tracks[g].push(C)}}return this}setExampleHiglassViewConfig(){this.hg=mng}}function bG(e,g,i,I){const n=I&&I!==0?I:void 0;let r=0;switch(g){case"less-than":case"LT":case"lt":r=i>e?n?(i-e)/n:1:0;break;case"less-than-or-equal-to":case"LTET":case"ltet":r=i>=e?n?(i-e)/n:1:0;break;case"greater-than":case"GT":case"gt":r=i{e[i]&&i!=="base"&&(g[i]=Object.assign(JSON.parse(JSON.stringify(g[i])),JSON.parse(JSON.stringify(e[i]))))}),g}}class yng{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=ln(),this.theme=I??q2e(),this.dataAggregated=i,this.specOriginal=g,this.specComplete=structuredClone(g),this.channelScales={},this.mouseEventModel=new Ggg;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=ing(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=ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"),i==="y"&&(I=ut(g.y)&&g.y.axis!==void 0&&g.y.axis!=="none"),g.layout!=="circular"?ut(g.x)&&g.x.axis!==void 0&&g.x.axis!=="none"&&(g.height-=UC):i==="x"&&I&&ut(g.x)&&g.x.axis==="top"?g.outerRadius=g.outerRadius-UC:i==="x"&&I&&ut(g.x)&&g.x.axis==="bottom"&&(g.innerRadius=g.innerRadius+UC),Xd.forEach(n=>{const r=g[n];ut(r)&&!("zeroBaseline"in r)&&r.type==="quantitative"&&(r.zeroBaseline=!0)}),this.addScaleMaterials(g)}flipRanges(g){ut(g.y)&&g.y.flip&&Array.isArray(g.y.range)&&(g.y.range=g.y.range.reverse())}getGenomicChannelKey(){return d2e(this.spec())}getGenomicChannel(){return J$(this.spec())}setChannelDomain(g,i,I){const n=this.originalSpec()[g];if(!I&&ut(n)&&n.domain!==void 0)return;const r=this.specComplete[g];ut(r)&&(r.domain=i)}updateChannelValue(){if(this.originalSpec().y===void 0){const g=this.spec().y,i=this.getChannelDomainArray("row");g&&K1(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],r=ut(n)?n.type:K1(n)?"constant":void 0;if(r){if(r==="constant")return this.channelScales[g]();if(i!==void 0&&(i===null&&(r==="quantitative"?i=0:r==="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(r==="quantitative"||r==="genomic")return this.channelScales[g](i);if(r==="nominal")return this.channelScales[g](i);break;case"stroke":case"color":if(r==="quantitative"){const C=this.channelScales[g].copy(),o=C.domain(),a=o[1]-o[0],s=Array.from((I=n.scaleOffset)!=null?I:[0,1]);return C.domain([o[0]+a*s.sort()[0],o[0]+a*s.sort()[1]])(i)}if(r==="nominal")return this.channelScales[g](i);break;case"size":if(r==="quantitative")return this.channelScales[g](i);if(r==="nominal")return this.channelScales[g](i);break;case"row":if(r==="nominal")return this.channelScales[g](i);break;case"strokeWidth":case"opacity":if(r==="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:r,measure:C,threshold:o}=n;let a;C==="zoomLevel"?a=g[C]:a=i[C],a!==void 0&&(I=I&&bG(a,r,o)===1)}),I}markVisibility(g,i){const I=this.spec();if(!I.visibility||I.visibility.length===0||I.visibility.filter(r=>r.target==="mark").length===0)return 1;let n=1;return I.visibility.filter(r=>r.target==="mark").forEach(r=>{const{operation:C,threshold:o,conditionPadding:a,transitionPadding:s,measure:A}=r,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=bG(i.width+l,C,Math.abs(d-h),s))}else A==="width"&&typeof o=="number"&&(i!=null&&i.width)?u=bG(i.width+l,C,o,s):A==="zoomLevel"&&typeof o=="number"&&(i!=null&&i.zoomLevel)&&(u=bG(i.zoomLevel,C,o,s));n>u&&(n=u)}),n}visualPropertyByChannel(g,i){const I=i!==void 0?pi(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 _4e(this,g,i,I);case"point":case"text":return P4e(this,g,i);case"rect":return Q4e(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}Xd.forEach(n=>{var r,C,o,a;const s=g[n];if(Nje(g,n)&&ut(s)){const A=vT(i,c=>c[I.field]),l=[...A.keys()];if(!s.domain){const c="zeroBaseline"in s&&s.zeroBaseline?0:N1(l.map(d=>$ee(A.get(d).map(h=>s.field?h[s.field]:void 0)))),u=xG(l.map(d=>$ee(A.get(d).map(h=>s.field?h[s.field]:void 0))));s.domain=[c,u]}if(!s.range){const c=g.row,u=ut(c)?c.field:void 0,d=(r=this.getChannelDomainArray("row"))!=null?r: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=ut(A)?A.field:void 0,c=(C=this.getChannelDomainArray("row"))!=null?C:l?Array.from(new Set(i.map(d=>d[l]))):[1],u=g.height/c.length;if(s){if(ut(s)&&(s.type==="quantitative"||s.type==="genomic")){if(s.domain===void 0){const d="zeroBaseline"in s&&s.zeroBaseline?0:(o=N1(i.map(m=>+m[s.field])))!=null?o:0,h=(a=xG(i.map(m=>+m[s.field])))!=null?a:0;s.domain=[d,h]}else s.type==="genomic"&&!zte(s.domain)&&(s.domain=u_(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=bng.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(ut(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"&&ut(g.x)&&ut(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[r,C]=n,o=g[r],a=g[C];if(ut(o)&&ut(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=N1([o.domain[0],a.domain[0]]),A=xG([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();Xd.forEach(i=>{const I=g[i];if(K1(I))this.channelScales[i]=()=>I.value;else if(ut(I)){if(i==="text")return;const n=I.domain,r=I.range;if(n===void 0||r===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]=qd().domain(n).range(r);break;case"color":case"stroke":let C=pbe;Object.keys(K9).includes(r)&&(C=K9[r]),this.channelScales[i]=Dpe(C).domain(n);break}else if(I.type==="nominal")switch(i){case"x":case"xe":case"y":case"ye":case"row":this.channelScales[i]=Wpe().domain(n).range(r);break;case"size":this.channelScales[i]=W9().domain(n).range(r);break;case"color":case"stroke":this.channelScales[i]=W9(r).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 ut(g.y)&&g.y.axis!=="none"&&g.y.type==="quantitative"&&!!i&&!!I}getChannelDomainArray(g){const i=this.spec()[g];return ut(i)&&zte(i.domain)?i.domain:void 0}getChannelRangeArray(g){const i=this.spec()[g];return ut(i)&&Tje(i.range)?i.range:void 0}validateSpec(){return u2e(this.originalSpec())}}function XC(e,g){V7.publish(e,g)}function Zng(e,g){V7.subscribe(e,g)}function Gng(e){V7.unsubscribe(e)}const rce={stroke:"black",strokeWidth:1,strokeOpacity:1,color:"none",opacity:1,arrange:"front"};function vng(){return{goslingModels:[],tabularData:[],skipRendering:!1}}const Bng={type:"gosling-track",datatype:["multivec","epilogos"],orientation:"1d-horizontal",defaultOptions:{theme:fG("light")}},Sng=(e,g,i)=>{var I,n,r,C,o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z,B,G,v,w,R,S,X,W,V,H,Y,K,x,J;const{tileProxy:P}=e.services,{BarTrack:ge}=e.tracks,q=Fs({color:"black",size:12}),$=class d_ extends ge{constructor(){var Q,Ie,he,ne,be,pe;super(g,i),fg(this,d),fg(this,m),fg(this,b),fg(this,y),fg(this,B),fg(this,v),fg(this,R),fg(this,X),fg(this,V),fg(this,Y),fg(this,x),Ct(this,"tileSize"),Ct(this,"mRangeBrush"),fg(this,I,void 0),fg(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),fg(this,r,0),fg(this,C,0),fg(this,o,!1),fg(this,a,e.libraries.d3Selection.select(g.svgElement).append("g")),fg(this,s,new e.libraries.PIXI.TextStyle(q)),fg(this,A,new e.libraries.PIXI.Graphics),fg(this,l,new e.libraries.PIXI.Text("",q)),Ct(this,"prevVisibleAndFetchedTiles"),Ct(this,"resolvedTracks"),Ct(this,"hideMousePosition"),g.dataFetcher.track=this,Vr(this,n,{}),Vr(this,I,this.options.spec.assembly),"overlay"in this.options.spec?this.options.spec.overlay=this.options.spec._overlay.map(Be=>({...Be,_renderingId:ln()})):this.options.spec._renderingId=ln(),this.fetchedTiles={},this.tileSize=(Ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?Ie:1024;const{valid:ve,errorMessages:We}=u2e(this.options.spec);ve||console.warn("The specification of the following track is invalid",We,this.options.spec),this.pMain.addChild(this.pMouseHover),this.pMain.addChild(this.pMouseSelection),this.pMask.interactive=!0,this.mRangeBrush=new hgg(Dt(this,a),e.libraries,(he=this.options.spec.style)==null?void 0:he.brush),this.mRangeBrush.on("brush",Si(this,V,H).bind(this)),this.pMask.on("mousedown",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);Si(this,b,p).call(this,Je,Pe,Be.data.originalEvent.altKey)}),this.pMask.on("mouseup",Be=>{const{x:Je,y:Pe}=Be.data.getLocalPosition(this.pMain);Si(this,B,G).call(this,Je,Pe)}),this.pMask.on("mousemove",Be=>{const{x:Je}=Be.data.getLocalPosition(this.pMain);Si(this,y,Z).call(this,Je)}),this.pMask.on("mouseout",Si(this,v,w).bind(this)),this.flipText=this.options.spec.orientation==="vertical",this.hideMousePosition&&(this.hideMousePosition(),this.hideMousePosition=void 0),(ne=this.options)!=null&&ne.showMousePosition&&!this.hideMousePosition&&(this.hideMousePosition=e.utils.showMousePosition(this,Ir(this.getResolvedTracks()[0]),this.isShowGlobalMousePosition())),this.pLabel.removeChild(this.trackNotFoundText),Dt(this,l).anchor.x=1,Dt(this,l).anchor.y=1,this.pLabel.addChild(Dt(this,A)),this.pLabel.addChild(Dt(this,l)),e.libraries.PIXI.GRAPHICS_CURVES.adaptive=(pe=(be=this.options.spec.style)==null?void 0:be.enableSmoothPath)!=null?pe:!1,e.libraries.PIXI.GRAPHICS_CURVES.adaptive&&(e.libraries.PIXI.GRAPHICS_CURVES.maxLength=1,e.libraries.PIXI.GRAPHICS_CURVES.maxSegments=2048*10)}draw(){var Q,Ie;this.clearMouseEventData(),this.textsBeingUsed=0,(Q=this.pMouseHover)==null||Q.clear();const he=()=>{const ne=this.dataFetcher instanceof RH;this.processAllTiles(ne),super.draw(),this.prevVisibleAndFetchedTiles=this.visibleAndFetchedTiles()};_R(this.dataFetcher)&&!mbe(this.visibleAndFetchedTiles(),this.prevVisibleAndFetchedTiles)?this.updateTileAsync(this.dataFetcher,he):he(),(Ie=this.mRangeBrush)==null||Ie.drawBrush(!0),this.firstDraw&&(Si(this,x,J).call(this),this.firstDraw=!1)}initTile(Q){this.drawTile(Q)}updateTile(){}renderTile(){}drawTile(Q){var Ie,he;Q.drawnAtScale=this._xScale.copy();const ne=Dt(this,n)[Q.tileId];ne&&((Ie=Q.graphics)==null||Ie.clear(),(he=Q.graphics)==null||he.removeChildren(),this.pBackground.clear(),this.pBackground.removeChildren(),this.pBorder.clear(),this.pBorder.removeChildren(),this.displayedLegends=[],ne.goslingModels.forEach(be=>{const pe=this.dimensions[0],ve=this._xScale.invert(pe)-this._xScale.invert(0);be.trackVisibility({zoomLevel:ve})&&(mje(e,this,Q,be,this.options.theme),hje(e,this,Q,be),fje(e,this,Q,be,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 Ie,he;return(he=(Ie=Dt(this,n)[Q.tileId])==null?void 0:Ie.goslingModels)!=null?he:[]})}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,Ie){const he=this.mRangeBrush.getRange();this.mRangeBrush.updateRange(he?[Q(this._xScale.invert(he[0])),Q(this._xScale.invert(he[1]))]:null),this.xScale(Q),this.yScale(Ie),this.refreshTiles(),this.draw(),this.forceDraw();const ne=Q.domain().map(be=>Lu(be,Dt(this,I),!0));XC("location",{id:g.viewUid,genomicRange:ne})}setMask(Q,Ie){if(this.pMask.clear(),this.pMask.beginFill(),this.options.spec.layout==="circular"){const[he,ne]=this.position,[be,pe]=this.dimensions,ve=he+be/2,We=ne+pe/2,Be=this.options.spec.outerRadius;this.pMask.drawCircle(ve,We,Be)}else this.pMask.drawRect(Q[0],Q[1],Ie[0],Ie[1]);this.pMask.endFill()}processAllTiles(Q=!1){var Ie,he;this.tileSize=(he=(Ie=this.tilesetInfo)==null?void 0:Ie.tile_size)!=null?he:1024;const ne=this.visibleAndFetchedTiles();ne.forEach(ve=>Si(this,m,f).call(this,ve,Q)),this.combineAllTilesIfNeeded();const be=ne.flatMap(ve=>this.transformDataAndCreateModels(ve));hng(be);const pe=[].concat(...be.map(ve=>ve.data()));pe.length!==0&&this.options.siblingIds.forEach(ve=>XC("rawData",{id:ve,data:pe}))}async updateTileAsync(Q,Ie){if(!this.tilesetInfo)return;const he=this.visibleAndFetchedTiles(),ne=await Q.getTabularData(Object.values(he).map(pe=>pe.remoteId)),be=this.tilesetInfo;he.forEach((pe,ve)=>{if(ve===0){const[We]=e.utils.trackUtils.calculate1DVisibleTiles(be,this._xScale);pe.tileData.zoomLevel=We[0],pe.tileData.tilePos=[We[1],We[1]],pe.tileData.tabularData=ne}else pe.tileData.tabularData=[]}),Ie()}calculateVisibleTiles(){var Q,Ie,he,ne,be;if(this.tilesetInfo)if(_R(this.dataFetcher)){const pe=e.utils.trackUtils.calculate1DVisibleTiles(this.tilesetInfo,this._xScale),ve=(Ie=(Q=this.tilesetInfo.max_tile_width)!=null?Q:this.dataFetcher.MAX_TILE_WIDTH)!=null?Ie:Number.MAX_SAFE_INTEGER;for(const We of pe){const{tileWidth:Be}=this.getTilePosAndDimensions(We[0],[We[1],We[1]]);if(this.forceDraw(),Be>ve)return}this.setVisibleTiles(pe)}else{if(!this.tilesetInfo)return;const pe=this.calculateZoomLevel();if("resolutions"in this.tilesetInfo){const ve=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe),We=P.calculateTilesFromResolution(ve[pe],this._xScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]);let Be;Ir(this.getResolvedTracks()[0])&&(Be=P.calculateTilesFromResolution(ve[pe],this._yScale,this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0]));const Je=Si(he=d_,c,u).call(he,We,Be,pe);this.setVisibleTiles(Je)}else{const ve=P.calculateTiles(pe,this.relevantScale(),this.tilesetInfo.min_pos[0],this.tilesetInfo.max_pos[0],this.tilesetInfo.max_zoom,this.tilesetInfo.max_width);let We;Ir(this.getResolvedTracks()[0])&&(We=P.calculateTiles(pe,this._yScale,this.tilesetInfo.min_pos[1],this.tilesetInfo.max_pos[1],this.tilesetInfo.max_zoom,(ne=this.tilesetInfo.max_width1)!=null?ne:this.tilesetInfo.max_width));const Be=Si(be=d_,c,u).call(be,ve,We,pe);this.setVisibleTiles(Be)}}}getTilePosAndDimensions(Q,Ie){if(!this.tilesetInfo)throw Error("tilesetInfo not parsed");if("resolutions"in this.tilesetInfo){const ne=this.tilesetInfo.resolutions.map(Pe=>+Pe).sort((Pe,De)=>De-Pe)[Q],[be,pe]=Ie,ve=ne*Dt(this,d,h),We=ve,Be=ve*be,Je=We*pe;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}else{const[he,ne]=Ie,be=this.tilesetInfo.min_pos[0],pe=this.tilesetInfo.min_pos[1],ve=this.tilesetInfo.max_width/2**Q,We=this.tilesetInfo.max_width/2**Q,Be=be+he*ve,Je=pe+ne*We;return{tileX:Be,tileY:Je,tileWidth:ve,tileHeight:We}}}getIndicesOfVisibleDataInTile(Q){const Ie=this._xScale.range();if(!this.tilesetInfo||!Q.tileData.tilePos||!("dense"in Q.tileData))return[0,0];const{tileX:he,tileWidth:ne}=this.getTilePosAndDimensions(Q.tileData.zoomLevel,Q.tileData.tilePos),be=e.libraries.d3Scale.scaleLinear().domain([0,Dt(this,d,h)]).range([he,he+ne]),pe=Math.max(0,Math.round(be.invert(this._xScale.invert(Ie[0])))),ve=Math.min(Q.tileData.dense.length,Math.round(be.invert(this._xScale.invert(Ie[1]))));return[pe,ve]}receivedTiles(Q){super.receivedTiles(Q),_R(this.dataFetcher)&&this.drawLoadingCue()}removeOldTiles(){super.removeOldTiles(),_R(this.dataFetcher)&&this.drawLoadingCue()}combineAllTilesIfNeeded(){var Q,Ie,he;if(!this.shouldCombineTiles())return;const ne=this.visibleAndFetchedTiles();if(!ne||ne.length<=1)return;this.tileSize=((Ie=(Q=this.tilesetInfo)==null?void 0:Q.tile_size)!=null?Ie:1024)*ne.length;let be=[];ne.forEach((ve,We)=>{const Be=Dt(this,n)[ve.tileId];Be&&(be=[...be,...Be.tabularData],Be.skipRendering=We!==0)});const pe=Dt(this,n)[ne[0].tileId];pe.tabularData=be,(he=pe.tabularData[0])!=null&&he.uid&&(pe.tabularData=l4e(pe.tabularData,"uid"))}shouldCombineTiles(){const Q=pje(this.options.spec,"displace"),Ie=()=>{const ne=this.visibleAndFetchedTiles();return ne.length>=1&&"dense"in ne[0].tileData},he=this.dataFetcher instanceof RH;return Q&&!Ie()&&!he}getResolvedTracks(Q=!1){if(Q||!this.resolvedTracks){const Ie=structuredClone(this.options.spec),he=N0(Ie).filter(ne=>ne.mark!=="brush");he.forEach(ne=>{"values"in ne.data&&(ne.data.values=[])}),this.resolvedTracks=he}return this.resolvedTracks}transformDataAndCreateModels(Q){const Ie=Dt(this,n)[Q.tileId];return!Ie||Ie.skipRendering?[]:(Ie.goslingModels=[],this.getResolvedTracks().forEach(ne=>{var be;let pe=Array.from(Ie.tabularData);(be=ne.dataTransform)==null||be.forEach(_e=>{switch(_e.type){case"filter":pe=O2e(_e,pe);break;case"concat":pe=LIg(_e,pe);break;case"replace":pe=UIg(_e,pe);break;case"log":pe=QIg(_e,pe);break;case"exonSplit":pe=tng(_e,pe,ne.assembly);break;case"genomicLength":pe=jIg(_e,pe);break;case"svType":pe=$Ig(_e,pe);break;case"coverage":pe=qIg(_e,pe,this._xScale.copy());break;case"subjson":pe=gng(_e,pe);break;case"displace":pe=eng(_e,pe,this._xScale.copy());break}});try{if(PubSub){const gt=pe.length;PubSub.publish("data-preview",{id:g.viewUid,dataConfig:JSON.stringify({data:ne.data}),data:100>gt?pe:r7(pe,100)})}}catch{}const[ve,We]=this.dimensions,Be=F9(ne)?UC:0,[Je,Pe]=[ve,We+Be],De=Math.min(Je,Pe)/Math.min(ne.width,ne.height);ne.innerRadius&&(ne.innerRadius=ne.innerRadius*De),ne.outerRadius&&(ne.outerRadius=ne.outerRadius*De),ne.width=Je,ne.height=Pe;const Qe=new yng(ne,pe,this.options.theme);Ie.goslingModels.push(Qe)}),Ie.goslingModels)}getMouseOverHtml(Q,Ie){var he,ne,be,pe,ve;if(Si(this,X,W).call(this,"trackMouseOver",Q,Ie),Dt(this,o)||!this.tilesetInfo)return"";this.pMouseHover.clear();const We=Lu(Math.floor(this._xScale.invert(Q)),Dt(this,I)),Be=Si(this,R,S).call(this,Q,Ie);if(Be.length!==0?document.body.style.cursor="pointer":document.body.style.cursor="default",Be.length!==0){const Je=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents;if(!!Je||km(Je)&&!!Je.mouseOver){const _e=this.pMouseHover;((be=(ne=this.options.spec.style)==null?void 0:ne.mouseOver)==null?void 0:be.arrange)!=="behind"&&(this.pMain.removeChild(_e),this.pMain.addChild(_e)),Si(this,Y,K).call(this,_e,Be,Object.assign({},rce,(pe=this.options.spec.style)==null?void 0:pe.mouseOver)),XC("mouseOver",{id:g.viewUid,genomicPosition:We,data:Be.map(gt=>gt.value)})}const Qe=(ve=this.visibleAndFetchedGoslingModels().find(_e=>{var gt;return _e.spec().tooltip&&((gt=_e.spec().tooltip)==null?void 0:gt.length)!==0}))==null?void 0:ve.spec().tooltip;if(Qe){let _e=Qe.map(gt=>{var lt;const tt=Be[0].value[gt.field];let Xe=tt;if(gt.type==="quantitative"&>.format)Xe=e.libraries.d3Format.format(gt.format)(+tt);else if(gt.type==="genomic"){const{chromosome:ae,position:ye}=Lu(+tt,Dt(this,I));Xe=`${ae}:${e.libraries.d3Format.format(",")(ye)}`}return`${(lt=gt.alt)!=null?lt:gt.field}${Xe}`}).join("");return _e=`${_e}
`,Be.length>1&&(_e+=`
${Be.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(" ")}`;Dt(this,l).text=Ie,Dt(this,l).x=this.position[0]+this.dimensions[0]-6/2,Dt(this,l).y=this.position[1]+this.dimensions[1]-6/2;const he=e.libraries.PIXI.TextMetrics.measureText(Ie,Dt(this,s)),{width:ne,height:be}=he;Dt(this,A).clear(),Dt(this,A).lineStyle(1,pt("grey"),1,.5),Dt(this,A).beginFill(pt("white"),.8),Dt(this,A).drawRect(this.position[0]+this.dimensions[0]-ne-6-1,this.position[1]+this.dimensions[1]-be-6-1,ne+6,be+6),Dt(this,l).visible=!0,Dt(this,A).visible=!0}else Dt(this,l).visible=!1,Dt(this,A).visible=!1}updateScaleOffsetFromOriginalSpec(Q,Ie,he){this.getResolvedTracks().map(ne=>{if(ne._renderingId===Q){const be=ne[he];ut(be)&&(be.scaleOffset=Ie)}})}shareScaleOffsetAcrossTracksAndTiles(Q,Ie){this.visibleAndFetchedGoslingModels().forEach(ne=>{const be=ne.spec()[Ie];ut(be)&&(be.scaleOffset=Q);const pe=ne.originalSpec()[Ie];ut(pe)&&(pe.scaleOffset=Q)})}};I=new WeakMap,n=new WeakMap,r=new WeakMap,C=new WeakMap,o=new WeakMap,a=new WeakMap,s=new WeakMap,A=new WeakMap,l=new WeakMap,c=new WeakSet,u=function(te,Q,Ie){if(!Q)return te.map(ne=>[Ie,ne]);const he=[];return te.forEach(ne=>Q.forEach(be=>he.push([Ie,ne,be]))),he},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,Q=!1){if(Dt(this,n)[te.tileId]&&!Q||!te.tileData.tilePos)return;const Ie=vng(),he=this.getResolvedTracks();if(he.length===0)return[];const ne=he[0];if("tabularData"in te.tileData)Ie.tabularData=te.tileData.tabularData;else{const{tileX:be,tileY:pe,tileWidth:ve,tileHeight:We}=this.getTilePosAndDimensions(te.tileData.zoomLevel,te.tileData.tilePos),Be="length"in te.tileData?Array.from(te.tileData):[],Je=Object.assign({},te.tileData,{sparse:Be,tileX:be,tileY:pe,tileWidth:ve,tileHeight:We,tileSize:this.tileSize}),Pe=sng(ne,Je);Pe&&(Ie.tabularData=Pe)}Dt(this,n)[te.tileId]=Ie},b=new WeakSet,p=function(te,Q,Ie){var he;Vr(this,r,te),Vr(this,C,Q);const ne=(he=this.options.spec.experimental)==null?void 0:he.mouseEvents,be=!!ne||km(ne)&&!!ne.rangeSelect;Vr(this,o,be&&Ie),this.pMouseHover.clear()},y=new WeakSet,Z=function(te){this.options.spec.layout!=="circular"&&Dt(this,o)&&this.mRangeBrush.updateRange([te,Dt(this,r)]).drawBrush().visible().disable()},B=new WeakSet,G=function(te,Q){var Ie;Si(this,X,W).call(this,"trackClick",te,Q);const he=(Ie=this.options.spec.experimental)==null?void 0:Ie.mouseEvents,ne=!!he||km(he)&&!!he.click,be=Math.sqrt((Dt(this,r)-te)**2+(Dt(this,C)-Q)**2)>1;if(!Dt(this,o)&&!be?(this.mRangeBrush.clear(),this.pMouseSelection.clear()):this.mRangeBrush.enable(),Vr(this,o,!1),!!this.tilesetInfo&&!be&&ne){const pe=Lu(Math.floor(this._xScale.invert(te)),Dt(this,I)),ve=Si(this,R,S).call(this,te,Q);ve.length!==0&&this.options.siblingIds.forEach(We=>XC("click",{id:We,genomicPosition:pe,data:ve.map(Be=>Be.value)}))}},v=new WeakSet,w=function(){Vr(this,o,!1),document.body.style.cursor="default",this.pMouseHover.clear()},R=new WeakSet,S=function(te,Q){var Ie;const he=this.visibleAndFetchedGoslingModels(),ne=(Ie=this.options.spec.experimental)==null?void 0:Ie.mouseEvents,be=km(ne)&&ne.enableMouseOverOnMultipleMarks,pe=km(ne)&&ne.groupMarksByField,ve=he.map(We=>We.getMouseEventModel().findAll(te,Q,!0)).flat();if(be||ve.splice(1,ve.length-1),ve.length!==0&&pe){const We=Array.from(ve);he.forEach(Be=>{const Je=Be.getMouseEventModel().getSiblings(We,pe);ve.push(...Je)})}return ve},X=new WeakSet,W=function(te,Q,Ie){const[he,ne]=this.position,[be,pe]=this.dimensions;if(this.options.spec.layout==="circular"){const ve=he+be/2,We=ne+pe/2,Be=this.options.spec.innerRadius,Je=this.options.spec.outerRadius,Pe=this.options.spec.startAngle,De=this.options.spec.endAngle;mgg([Q,Ie],[be/2,pe/2],[Be,Je],[Pe,De])&&XC(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe,cx:ve,cy:We,innerRadius:Be,outerRadius:Je,startAngle:Pe,endAngle:De}})}else XC(te,{id:g.viewUid,spec:structuredClone(this.options.spec),shape:{x:he,y:ne,width:be,height:pe}})},V=new WeakSet,H=function(te,Q=!1){var Ie,he,ne,be;if(this.pMouseSelection.clear(),te===null){Q||XC("rangeSelect",{id:g.viewUid,genomicRange:null,data:[]});return}const pe=this.visibleAndFetchedGoslingModels(),[ve,We]=te;let Be=pe.map(De=>De.getMouseEventModel().findAllWithinRange(ve,We,!0)).flat();const Je=(Ie=this.options.spec.experimental)==null?void 0:Ie.mouseEvents,Pe=km(Je)&&Je.groupMarksByField;if(Be.length!==0&&Pe&&pe.forEach(De=>{const Qe=De.getMouseEventModel().getSiblings(Be,Pe),_e=Array.from(new Set(Qe.map(gt=>gt.value[Pe])));Be=Be.filter(gt=>_e.indexOf(gt.value[Pe])===-1)}),Be.length!==0){const De=this.pMouseSelection;((ne=(he=this.options.spec.style)==null?void 0:he.select)==null?void 0:ne.arrange)!=="behind"&&(this.pMain.removeChild(De),this.pMain.addChild(De)),Si(this,Y,K).call(this,De,Be,Object.assign({},rce,(be=this.options.spec.style)==null?void 0:be.select))}if(!Q){const De=[Lu(Math.floor(this._xScale.invert(ve)),Dt(this,I)),Lu(Math.floor(this._xScale.invert(We)),Dt(this,I))];XC("rangeSelect",{id:g.viewUid,genomicRange:De,data:Be.map(Qe=>Qe.value)})}this.forceDraw()},Y=new WeakSet,K=function(te,Q,Ie){te.lineStyle(Ie.strokeWidth,pt(Ie.stroke),Ie.strokeOpacity,.5),te.beginFill(pt(Ie.color),Ie.color==="none"?0:Ie.opacity),Q.forEach(he=>{if(he.type==="point"){const[ne,be,pe=3]=he.polygon;te.drawCircle(ne,be,pe)}else he.type==="line"?(te.moveTo(he.polygon[0],he.polygon[1]),gje(he.polygon).map(ne=>te.lineTo(ne[0],ne[1]))):te.drawPolygon(he.polygon)})},x=new WeakSet,J=function(){XC("onNewTrack",{id:g.viewUid})},fg($,c);let j=$;return new j},a1=O$(Bng,Sng),wng={type:"dummy-track",defaultOptions:{height:0,width:0,title:"",background:"#fff",textFontSize:12,textFontWeight:"normal",textStroke:"#000",textStrokeWidth:.1,outline:"#fff"}},Rng=(e,g,i)=>{var I,n,r,C;const{SVGTrack:o}=e.tracks;class a extends o{constructor(){super(g,i),fg(this,I),fg(this,r),Si(this,I,n).call(this),Si(this,r,C).call(this),XC("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)},r=new WeakSet,C=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},Cce=O$(wng,Rng);let oce=!1;function Vng(){if(!oce){wu({name:"GoslingTrack",track:a1,config:a1.config}),wu({name:"Gosling2DTrack",track:a1,config:{...a1.config,type:"gosling-2d-track",orientation:"2d"}}),wu({name:"AxisTrack",track:dle,config:dle.config}),wu({name:"TextTrack",track:B3,config:B3.config}),wu({name:"BrushTrack",track:n_,config:n_.config}),wu({name:"DummyTrack",track:Cce,config:Cce.config});for(const e of Object.values(ang)){const{config:g}=e;wu({dataFetcher:e,config:g},{pluginType:"dataFetcher"})}oce=!0}}function eHe(e){let g=0,i=0;return e.forEach(I=>{const n=I.boundingBox.x+I.boundingBox.width,r=I.boundingBox.y+I.boundingBox.height;i{s.boundingBox.y+=o+a}),n=[{track:Xng({width:r.width,height:o},e.title,e.subtitle),boundingBox:{x:0,y:0,width:r.width,height:o},layout:{x:0,y:0,w:12,h:o/r.height*12}},...n]}else r.height=r.height+(8-r.height%8);const C=!(typeof e.responsiveSize!="object"?e.responsiveSize:e.responsiveSize.height);return n.forEach(o=>{o.layout.x=o.boundingBox.x/r.width*12,o.layout.w=o.boundingBox.width/r.width*12,o.layout.y=C?o.boundingBox.y:o.boundingBox.y/r.height*12,o.layout.h=C?o.boundingBox.height:o.boundingBox.height/r.height*12}),{trackInfos:n,size:r}}function h_(e,g,i=0,I=0,n=!0){let r=0,C=0,o=!0,a=!1;bb(e,c=>{a=!0,c.layout!=="circular"&&(o=!1)});let s=!0;i0e(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"?(C=Math.max(...c.map(u=>u.height)),c.forEach((u,d,h)=>{Ace([u])===1&&(u.width+=UC),u.height=C,g.push({track:u,boundingBox:{x:i+r,y:I,width:u.width,height:C},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(r+=u.width,d!==h.length-1&&(r+=e.spacing!==void 0?e.spacing:0))})):(r=Math.max(...c.map(u=>u.width)),c.forEach((u,d,h)=>{Ace([u])===1&&(u.height+=UC);const m=N0(u);m.length>0&&Ir(m[0])&&Wng([u])===1&&(r+=UC),u.width=r,g.push({track:u,boundingBox:{x:i,y:I+C,width:r,height:u.height},layout:{x:0,y:0,w:0,h:0}}),h[d+1]&&h[d+1].overlayOnPreviousTrack||(C+=u.height,d!==h.length-1&&(C+=e.spacing!==void 0?e.spacing:0))}))}else if(e.arrangement==="parallel"||e.arrangement==="vertical"){const c=e.spacing!==void 0?e.spacing:Y1;e.views.forEach((u,d,h)=>{var m,f,b,p,y;const Z=h_(u,g,i+((m=u.xOffset)!=null?m:0),I+((f=u.yOffset)!=null?f:0)+C,!A&&n);r<((b=u.xOffset)!=null?b:0)+Z.width&&(r=((p=u.xOffset)!=null?p:0)+Z.width),d!==h.length-1&&(C+=c),C+=((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:Y1,Z=h_(c,g,i+((h=c.xOffset)!=null?h:0)+r,I+((m=c.yOffset)!=null?m:0),!A&&n);C<((f=c.xOffset)!=null?f:0)+Z.height&&(C=((b=c.xOffset)!=null?b:0)+Z.height),u!==d.length-1&&(r+=y),r+=((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:Y1,h=x4e,m=e.centerRadius!==void 0?e.centerRadius:Zbe,f=r/2+h,b=f*(1-m);c.forEach((p,y)=>{var Z,B;if(XS(p.track))return;p.track.layout="circular",p.track.outerRadius=f-h-(p.boundingBox.y-I)/C*b,p.track.innerRadius=f-h-(p.boundingBox.y+p.boundingBox.height-I)/C*b;const G=d/r*360;p.track.startAngle=G+(p.boundingBox.x-i)/r*(r-d)/r*360,p.track.endAngle=(p.boundingBox.x+p.boundingBox.width-i)/r*(r-d)/r*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&&uI(p.track)&&(p.track._overlay=p.track._overlay.filter(v=>v.mark!=="brush"))}),C=f*2}return e._assignedWidth=r,e._assignedHeight=C,{x:i,y:I,width:r,height:C}}function Ace(e){return e.filter(g=>F9(g)).length}function Wng(e){return e.filter(g=>Yje(g)).length}const Xng=(e,g,i)=>JSON.parse(JSON.stringify({mark:"header",width:e.width,height:e.height,title:g,subtitle:i}));function Hng(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 Tng(e,g,i,I,n,r,C){var o,a,s,A,l,c,u,d,h,m,f,b,p,y,Z;if(XS(g))return e.addDefaultView(g.id).setDummyTrack(g).setLayout(I),e;const B=N0(g),G=B[0],v=(o=G.id)!=null?o:ln();G.id||(G.id=v),B.forEach(R=>{R.id&&r.addMapping(R.id,v)});const w=G.assembly;if(Mte(G.data)){let R,S;if(A7(G.data)){const ge=Hng(G.data.url);R=ge.server,S=ge.tilesetUid}const X=J$(G),W=d2e(G),H=(W==="x"||W==="xe")&&ut(X)?X.domain:void 0,Y=Ir(G)&&ut(G.y)?G.y.domain:void 0,K=i.width-(G.layout!=="circular"&&G.orientation==="vertical"&&F9(G)?UC:0),x=i.height-(G.layout!=="circular"&&G.orientation==="horizontal"&&F9(G)?UC:0),J={uid:`${v}-track`,type:Ir(G)?"gosling-2d-track":"gosling-track",server:R,tilesetUid:S,width:K,height:x,options:{id:v,siblingIds:r.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&&Mte(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 ge=te=>{const Q=G[te];return Q&&ut(Q)?Q.field:void 0},q={x:ge("x"),xe:ge("xe"),x1:ge("x1"),x1e:ge("x1e")},$="url"in G.data&&(C==null?void 0:C[G.data.url])||{},j="indexUrl"in G.data&&(C==null?void 0:C[G.data.indexUrl])||{};J.data={...G.data,...q,urlFetchOptions:$,indexUrlFetchOptions:j,assembly:w}}if(Vje(G)){J.type="heatmap";const ge=ut(G.color)&&typeof G.color.range=="string"?G.color.range:"viridis";J.options.colorRange=bje(ge),J.options.trackBorderWidth=(s=(a=G.style)==null?void 0:a.outlineWidth)!=null?s:n.track.outlineWidth,J.options.trackBorderColor=(l=(A=G.style)==null?void 0:A.outline)!=null?l:n.track.outline,J.options.extent=(u=(c=G.style)==null?void 0:c.matrixExtent)!=null?u:"full",J.options.colorbarPosition=(d=G.color)!=null&&d.legend?J.options.extent==="lower-left"?"bottomLeft":"topRight":"hidden"}G.overlayOnPreviousTrack?e.setViewOrientation(G.orientation).addTrackToCombined(J):e.setViewOrientation(G.orientation).setAssembly(w).addDefaultView(v,w).setDomain(H,Y??H).adjustDomain(G.orientation,K,x).setMainTrack(J).addTrackSourceServers(R).setZoomFixed(G.static===!0).setZoomLimits((h=G.zoomLimits)!=null?h:[1,null]).setLayout(I);const P=(ge,q="horizontal",$,j)=>q==="horizontal"?ge==="x"&&$<=200||ge==="y"&&j<=200?"narrower":ge==="x"&&$<=400||ge==="y"&&j<=400?"narrow":"regular":ge==="x"&&j<=200||ge==="y"&&$<=200?"narrower":ge==="x"&&j<=400||ge==="y"&&$<=400?"narrow":"regular";["x","y"].forEach(ge=>{const q=G[ge];if(ut(q)&&"axis"in q&&q.axis&&q.axis!=="none"&&q.type==="genomic"){const $=P(ge,g.orientation,i.width,i.height);e.setAxisTrack(q.axis,$,{id:`${v}-${q.axis}-axis`,layout:G.layout,innerRadius:q.axis==="top"?G.outerRadius-UC:G.innerRadius,outerRadius:q.axis==="top"?G.outerRadius:G.innerRadius+UC,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)+Y9,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:s3.fontFamily),typeof G.subtitle=="string"&&e.setTextTrack(i.width,((p=n.root.subtitleFontSize)!=null?p:14)+Y9,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:s3.fontFamily));return e}function Nng(e){const g=[];return e.spec().views.forEach(i=>{var I,n,r,C,o,a,s,A,l,c,u,d,h,m,f;const b=i.uid;let p=(o=(C=(r=(n=(I=i.tracks.center)==null?void 0:I[0])==null?void 0:n.contents)==null?void 0:r[0])==null?void 0:C.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;N0(p).forEach(Z=>{Xd.forEach(B=>{var G,v,w,R;const S=Z[B];if(ut(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:(R=Z.opacity)==null?void 0:R.value,startAngle:Z.startAngle,endAngle:Z.endAngle,innerRadius:Z.innerRadius,outerRadius:Z.outerRadius}});return}})})}),g}class kng{constructor(){fg(this,jA,{})}addMapping(g,i){Dt(this,jA)[g]&&Dt(this,jA)[g]!==i&&console.warn(`The track ID ${g} already exists but overwriting with a different ID.`),Dt(this,jA)[g]=i}getTable(){return Dt(this,jA)}getGoslingIds(){return Object.keys(Dt(this,jA))}getHiGlassId(g){return Dt(this,jA)[g]}getSiblingGoslingIds(g){return Object.entries(Dt(this,jA)).filter(([,i])=>i===g).map(([i])=>i)}}jA=new WeakMap;function Yng(e){const g=new Set;return e.id&&g.add(e.id),bb(e,i=>{("views"in i||"tracks"in i)&&i.id&&g.add(i.id)}),Array.from(g)}function Kng(e){const g=new Set;return bb(e,i=>{!("views"in i)&&!("tracks"in i)&&i.id&&g.add(i.id)}),Array.from(g)}function Fng(e,g){let i;return e.id===g&&(i=e),bb(e,I=>{I.id===g&&(i=I)}),i}function Dng(e,g){return Yng(e).map(i=>{const I=Fng(e,i),n=Kng(I),r={x:Number.MAX_SAFE_INTEGER,y:Number.MAX_SAFE_INTEGER,xe:-Number.MAX_SAFE_INTEGER,ye:-Number.MAX_SAFE_INTEGER};return n.map(C=>g.find(o=>o.id===C)).forEach(C=>{if(!C)return;const{shape:o}=C;r.x>o.x&&(r.x=o.x),r.y>o.y&&(r.y=o.y),r.xe{const{track:u,boundingBox:d,layout:h}=c;Tng(r,u,d,h,I,C,n)});const o=Nng(r);o.filter(c=>c.isBrush).forEach(c=>{var u;r.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=>{r.spec().zoomLocks.locksByViewUid[c.hgViewId]=c.linkId,r.spec().locationLocks.locksByViewUid[c.hgViewId]=c.linkId}),Array.from(new Set(o.map(c=>c.linkId))).forEach(c=>{r.spec().zoomLocks.locksDict[c]={uid:c},r.spec().locationLocks.locksDict[c]={uid:c},o.filter(u=>!u.isBrush).filter(u=>u.linkId===c).forEach(u=>{r.spec().zoomLocks.locksDict[c][u.hgViewId]=[1246253105e-1,1246253105e-1,249250.621],r.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"||XS(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=Dng(e,s),l=[...s.map(c=>({...c,type:"track"})),...A.map(c=>({...c,type:"view"}))];i(r.spec(),eHe(g),e,l,C.getTable())}function tHe(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 r=!1;const{responsiveSpec:C}=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 C&&C.forEach(l=>{const{spec:c,selectivity:u}=l;if(Eng(u,s,A)&&!r){Object.keys(c).forEach(d=>{e[d]=c[d]}),delete e.responsiveSpec,r=!0;return}}),"views"in e&&e.views.forEach(l=>{r=tHe(l,g,i,I,n)||r}),r}function Eng(e,g,i){if(e.length===0)return!1;let I=!0;return e.forEach(n=>{const{measure:r,operation:C,threshold:o,target:a}=n;I=I&&bG((a==="container"?i:g)[r],C,o)===1}),I}function Mng(e,g,i,I,n,r){var C,o;const a=JSON.parse(JSON.stringify(e));s6e(a),Utg(a,i),y3(a);const s=ace(a,I);let{trackInfos:A}=s;const{size:l}=s,c=typeof e.responsiveSize=="object"&&((C=e.responsiveSize)==null?void 0:C.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;tHe(a,d,h,m,f)&&(y3(a),A=ace(a,I).trackInfos),XC("specProcessed",{id:a.id,spec:a}),xng(a,A,g,I,r)}Vng();const gHe=U.forwardRef((e,g)=>{var i;const[I,n]=U.useState((i=e.id)!=null?i:ln());U.useEffect(()=>{var u;n((u=e.id)!=null?u:ln())},[e.id]);const r=e.viewConfig||{},C=!1,o=U.useMemo(()=>N.createElement(dy,{ref:g,options:{pixelPreciseMarginPadding:C,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:r}),[r,C]),{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(r),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)))});gHe.displayName="HiGlassComponentWrapper";function zng(e,g,i,I,n){const r=structuredClone(n),C=d=>{const h=r[d];return h||console.warn(`Unable to find the track ID, named ${d}.`),h??d},o=()=>Object.keys(r),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=Ys.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:Zng,unsubscribe:Gng,zoomTo:(d,h,m=0,f=1e3)=>{var b;const p=(b=A(d))==null?void 0:b.spec.assembly,Z=b7.fromString(h).toAbsoluteCoordinates(p,m),B=C(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,bi(f).total],y=C(d);e.api.zoomTo(y,b,p,b,p,h)},zoomToGene:(d,h,m=0,f=1e3)=>{const b=C(d);e.api.zoomToGene(b,h,m,f)},suggestGene:(d,h,m)=>{const f=C(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 f5e(()=>import("./jspdf.es.min-c088be8f.js").then(p=>p.j),[]),{canvas:m}=u({resolution:4,transparentBackground:d}),f=m.toDataURL("image/jpeg",1),b=new h({orientation:m.width{a7(i)&&g.forEach(I=>{delete i[I]})})}const Png=(e,g)=>{e.views.forEach(i=>{var I,n,r;const C=i.uid;if(!g.views.find(a=>a.uid===C)){const{locksByViewUid:a}=e.zoomLocks,s=a[C],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=(r=g.views.find(c=>c.uid===A))==null?void 0:r.initialYDomain)}})},Jng=300,iHe=U.forwardRef((e,g)=>{var i,I,n;const[r,C]=U.useState(),[o,a]=U.useState({width:200,height:200}),s=U.useRef(),A=U.useRef(),l=U.useRef(),c=U.useRef([]),u=U.useRef({}),d=U.useRef(null),h=q2e(e.theme||"light"),m=(i=e.id)!=null?i:ln(),f=Z=>{const B=c.current.filter(R=>R.type=="view"),G=Z.filter(R=>R.type=="view"),v=new Set(B.map(R=>R.id));G.filter(R=>!v.has(R.id)).forEach(R=>{XC("onNewView",{id:R.id})})};U.useImperativeHandle(g,()=>{const Z=lce(d),B=lce(c);return{api:zng(Z,r,B,h,u.current),hgApi:Z}},[r,h]);const b=U.useCallback(()=>{if(e.spec){if(_tg(e.spec).state==="error"){console.warn("Gosling spec is not valid. Please refer to the console message.");return}Mng(e.spec,(B,G,v,w,R)=>{var S,X;if(l.current&&mbe(sce(l.current,["linkingId"]),sce(v,["linkingId"])))return;(S=e.compiled)==null||S.call(e,e.spec,B,{_processedSpec:v}),a(G);const W=typeof r<"u";(X=e.experimental)!=null&&X.reactive&&W?setTimeout(()=>{var V,H;Png(B,(V=d.current)==null?void 0:V.api.getViewConfig()),(H=d.current)==null||H.api.setViewConfig(B)},Jng):C(B),f(w),l.current=v,c.current=w,u.current=R},[...Ltg],h,{containerSize:s.current,containerParentSize:A.current},e.urlToFetchOptions)}},[e.spec,h]);U.useEffect(()=>{var Z;if(!((Z=e.spec)!=null&&Z.responsiveSize))return;const B=document.getElementById(m);if(!B)return;const G=new ile.ResizeSensor(B,R=>{(!s.current||s.current.height!==R.height||s.current.width!==R.width)&&(s.current=R,b())}),v=B.parentElement;if(!v)return;const w=new ile.ResizeSensor(v,R=>{(!A.current||A.current.height!==R.height||A.current.width!==R.width)&&(A.current=R,b())});return()=>{G.detach(),w.detach()}}),U.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 U.useMemo(()=>{var Z,B,G;return N.createElement(gHe,{ref:d,viewConfig:r,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}})},[r,o,h,p])});iHe.displayName="GoslingComponent";function lce(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 cce=ji;cce.createRoot,cce.hydrateRoot;const Nv=["x","xe","x1","x1e","y","ye","y1","y1e","color","size","row","stroke","strokeWidth","opacity","text"];function Ong(e){return typeof e=="object"&&e!==null}function _ng(e){return"alignment"in e&&e.alignment==="overlay"}function Lng(e){return"_overlay"in e}function Ung(e){return e!==null&&typeof e=="object"&&"value"in e}function Qng(e){return Ong(e)&&!("value"in e)}function m_(e,g){return g in e}function uce(e,g){return e[g]}function to(e){return e=e.filter(g=>g!==void 0),e.length===0?"":e.length===1?e[0]:e.slice(0,-1).join(", ")+" and "+e.slice(-1)}function lp(e){return e[0].toUpperCase()+e.slice(1)}const kv=new Map([["point","points"],["line","lines"],["bar","bars"],["rect","rectangles"],["area","area displayed"],["withinLink","connections"],["betweenLink","connections"],["triangleLeft","triangles"],["triangleRight","triangles"],["triangleBottom","triangles"],["text","text"],["rule","lines"]]),LA=new Map([["y","height"],["color","color"],["strokeWidth","stroke width"],["opacity","opacity"],["text","text"]]);function jng(e){return e.includes("chr")&&(e=e.replace("chr","")),e}function $ng(e,g){return e.filter(i=>i===g).length}function IHe(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(a=>a.name),n=e.appearance.details.encodings.encodingDeepQuantitative.map(a=>a.name),r=e.appearance.details.encodings.encodingDeepNominal.map(a=>a.name),C=e.appearance.details.encodings.encodingValue.map(a=>a.name),o=[...I,...n,...r,...C];return i==="point"&&n.includes("x")&&n.includes("y")?"scatter plot":i==="line"&&I.includes("x")&&n.includes("y")||i==="line"&&n.includes("x")&&I.includes("y")?"line chart":i==="bar"&&I.includes("x")&&n.includes("y")?"bar chart":i==="rect"&&I.includes("x")&&I.includes("xe")&&n.includes("color")?"heat map":i==="rect"&&I.includes("x")&&I.includes("xe")&&r.includes("color")?"ideogram":i==="rule"&&o.includes("x")&&o.includes("y")?"lines":i==="rule"&&o.includes("x")?"vertical lines":i==="rule"&&o.includes("y")?"horizontal lines":kv.get(i)?`chart with ${kv.get(i)}.`:"unknown chart"}function qng(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={};m_(e,"arrangement")&&uce(e,"arrangement")?I.arrangement=uce(e,"arrangement"):I.arrangement="vertical",e.layout?I.layout=e.layout:I.layout="linear",nHe(e,g,I,i),rrg(i);const n={description:"",nTracks:i.nTracks,parentValues:I,counter:i};return g.composition=n,g.alt="",g.longDescription="",g}function nHe(e,g,i,I){if("tracks"in e){const n=dce(e,i);if(e.tracks.length>1)if(console.log("multiple tracks"),_ng(e)){const r=e;g.tracks[I.nTracks]=irg(r,n,I),I.nTracks>0&&(I.allPositions=[...I.allPositions,[I.rowViews,I.colViews]]),I.nTracks++}else for(const r in e.tracks){const C=e.tracks[r];g.tracks[I.nTracks]=f_(C,n,I),I.nTracks>0&&(I.allPositions=[...I.allPositions,[I.rowViews,I.colViews]]),I.nTracks++}else{if(console.log("only 1 track"),Lng(e.tracks[0])){console.log("is overlaid track");const r=e.tracks[0];g.tracks[I.nTracks]=grg(r,i,I)}else{const r=e.tracks[0];g.tracks[I.nTracks]=f_(r,i,I)}I.nTracks>0&&(I.allPositions=[...I.allPositions,[I.rowViews,I.colViews]]),I.nTracks++}}else if("views"in e){const n=I.rowViews,r=I.colViews;e.views.forEach((C,o)=>{o!==0&&(i.arrangement==="vertical"||i.arrangement==="parallel"?I.rowViews++:I.colViews++);const a=dce(C,i);nHe(C,g,a,I)}),i.arrangement==="vertical"||i.arrangement==="parallel"?I.rowViews=n:I.colViews=r}}function dce(e,g){const i=JSON.parse(JSON.stringify(g));return m_(e,"arrangement")&&(i.arrangement=e.arrangement),m_(e,"layout")&&(i.layout=e.layout),i}function f_(e,g,i){const I={};I.alttype="single";let n;e.id!=="unknown"?n=e.id:(n="",console.warn("ID not found?"));const r={trackNumber:i.nTracks,rowNumber:i.rowViews,colNumber:i.colViews},C={};C.assembly=e.assembly,C.layout=g.layout,C.overlaid=!1,C.mark=e.mark,C.encodings=Yv(e);const o=rHe(e.data,C.encodings),a={data:e.data,fields:o};e.dataTransform&&(a.transforms=e.dataTransform);const s={description:"",details:r},A={description:"",details:C},l={description:"",details:a};return I.uid=n,I.position=s,I.appearance=A,I.title=e.title,I.data=l,I.charttype=IHe(I),I.description="",I}function erg(e,g,i,I){let n={...e,...g};return delete n._overlay,delete n.overlayOnPreviousTrack,n=n,f_(n,i,I)}function trg(e,g,i){let I=[];for(let o=0;o{a!=="text"&&(e._overlay[o][a]?I[o][a]=e._overlay[o][a]:e[a]&&(I[o][a]=e[a]))}),e._overlay[o].dataTransform?I[o].dataTransform=e._overlay[o].dataTransform:e.dataTransform&&(I[o].dataTransform=e.dataTransform);let n={},r={};I.filter(o=>o.mark===void 0).length===0&&[...new Set(I.map(o=>o.mark))].length===1?(n.mark=I[0].mark,I.map(o=>delete o.mark)):r.mark=!0,Nv.forEach(o=>{o!=="text"&&(I.filter(a=>a[o]===void 0).length===0&&[...new Set(I.map(a=>a[o]))].length===1?(n[o]=I[0][o],I.map(a=>delete a[o])):r[o]=!0)}),I.filter(o=>o.dataTransform===void 0).length===0&&[...new Set(I.map(o=>o.dataTransform))].length===1?(n.dataTransform=I[0].dataTransform,I.map(o=>delete o.dataTransform)):r.dataTransform=!0,r.mark&&delete e.mark,n.mark&&(e.mark=n.mark),r.dataTransform&&delete e.dataTransform,n.dataTransform&&(e.dataTransform=n.dataTransform),Nv.forEach(o=>{o!=="text"&&(r[o]&&delete e[o],n[o]&&(e[o]=n[o]))}),console.log(e),console.log(I);const C=[];for(let o=0;o{m!=="text"&&(d[m]||C[h][m]&&(d[m]=C[h][m]))});a.encodings=Yv(d)}else a.markByTrack=o.map(d=>d.appearance.details.mark),a.encodings=Yv(r),a.encodingsByTrack=C.map(d=>Yv(d));const s={};s.alttype="ov-mark";const A=o[0].data.details,l={description:"",details:n},c={description:"",details:a},u={description:"",details:A};return s.uid=I,s.position=l,s.appearance=c,s.title=e.title,s.data=u,s.charttype=o.map(d=>d.charttype),s.description="",s}function irg(e,g,i){let I=I0e(e);return I=Bbe(I),Irg(e,I,g,i)}function Irg(e,g,i,I){const n={};n.alttype="ov-data",console.log("overlaid by data",e),console.log("tracks",g);const r={trackNumber:I.nTracks,rowNumber:I.rowViews,colNumber:I.colViews},C=[],o=[];for(const s of g){const A=s;let l;A.id!=="unknown"?l=A.id:l="",C.push(l),o.push(nrg(A,i))}const a={description:"",details:r};return n.position=a,n.title=e.title,n.appearance={description:"",details:{layout:"linear"}},n.tracks=o,n.uids=C,n.description="",console.log("alttrackoverlaid",n),n}function nrg(e,g,i){const I={};I.alttype="ov-data-ind";let n;e.id!=="unknown"?n=e.id:n="",I.uid=n;const r={};r.assembly=e.assembly,r.layout=g.layout,r.overlaid=!1,r.mark=e.mark,r.encodings=Yv(e);const C=rHe(e.data,r.encodings),o={data:e.data,fields:C},a={description:"",details:r},s={description:"",details:o};return I.appearance=a,I.data=s,I.charttype=IHe(I),I.description="",I}function rHe(e,g){const i={};return g.encodingDeepGenomic.length>0&&(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 Yv(e){const g=[],i=[],I=[],n=[];return Nv.forEach(C=>{const o=e[C];Qng(o)?o.type==="genomic"?g.push({name:C,description:"",details:o}):o.type==="quantitative"?i.push({name:C,description:"",details:o}):I.push({name:C,description:"",details:o}):Ung(o)&&n.push({name:C,description:"",details:o})}),{encodingDeepGenomic:g,encodingDeepQuantitative:i,encodingDeepNominal:I,encodingValue:n}}function rrg(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;ir[0]===i).map(r=>r[1]),n={};for(const r of I)n[r]?n[r]=n[r]+1:n[r]=1;g[i]=n}e.matrix=g}var n8={};Object.defineProperty(n8,"__esModule",{value:!0});var CHe=n8.GetColorName=void 0;CHe=n8.GetColorName=function(e){var g=new Crg,i=g.name(e);i[0];var I=i[1];return I};var Crg=function(){function e(){this.names=[["000000","Black"],["000080","Navy Blue"],["0000C8","Dark Blue"],["0000FF","Blue"],["000741","Stratos"],["001B1C","Swamp"],["002387","Resolution Blue"],["002900","Deep Fir"],["002E20","Burnham"],["002FA7","International Klein Blue"],["003153","Prussian Blue"],["003366","Midnight Blue"],["003399","Smalt"],["003532","Deep Teal"],["003E40","Cyprus"],["004620","Kaitoke Green"],["0047AB","Cobalt"],["004816","Crusoe"],["004950","Sherpa Blue"],["0056A7","Endeavour"],["00581A","Camarone"],["0066CC","Science Blue"],["0066FF","Blue Ribbon"],["00755E","Tropical Rain Forest"],["0076A3","Allports"],["007BA7","Deep Cerulean"],["007EC7","Lochmara"],["007FFF","Azure Radiance"],["008080","Teal"],["0095B6","Bondi Blue"],["009DC4","Pacific Blue"],["00A693","Persian Green"],["00A86B","Jade"],["00CC99","Caribbean Green"],["00CCCC","Robin's Egg Blue"],["00FF00","Green"],["00FF7F","Spring Green"],["00FFFF","Cyan / Aqua"],["010D1A","Blue Charcoal"],["011635","Midnight"],["011D13","Holly"],["012731","Daintree"],["01361C","Cardin Green"],["01371A","County Green"],["013E62","Astronaut Blue"],["013F6A","Regal Blue"],["014B43","Aqua Deep"],["015E85","Orient"],["016162","Blue Stone"],["016D39","Fun Green"],["01796F","Pine Green"],["017987","Blue Lagoon"],["01826B","Deep Sea"],["01A368","Green Haze"],["022D15","English Holly"],["02402C","Sherwood Green"],["02478E","Congress Blue"],["024E46","Evening Sea"],["026395","Bahama Blue"],["02866F","Observatory"],["02A4D3","Cerulean"],["03163C","Tangaroa"],["032B52","Green Vogue"],["036A6E","Mosque"],["041004","Midnight Moss"],["041322","Black Pearl"],["042E4C","Blue Whale"],["044022","Zuccini"],["044259","Teal Blue"],["051040","Deep Cove"],["051657","Gulf Blue"],["055989","Venice Blue"],["056F57","Watercourse"],["062A78","Catalina Blue"],["063537","Tiber"],["069B81","Gossamer"],["06A189","Niagara"],["073A50","Tarawera"],["080110","Jaguar"],["081910","Black Bean"],["082567","Deep Sapphire"],["088370","Elf Green"],["08E8DE","Bright Turquoise"],["092256","Downriver"],["09230F","Palm Green"],["09255D","Madison"],["093624","Bottle Green"],["095859","Deep Sea Green"],["097F4B","Salem"],["0A001C","Black Russian"],["0A480D","Dark Fern"],["0A6906","Japanese Laurel"],["0A6F75","Atoll"],["0B0B0B","Cod Gray"],["0B0F08","Marshland"],["0B1107","Gordons Green"],["0B1304","Black Forest"],["0B6207","San Felix"],["0BDA51","Malachite"],["0C0B1D","Ebony"],["0C0D0F","Woodsmoke"],["0C1911","Racing Green"],["0C7A79","Surfie Green"],["0C8990","Blue Chill"],["0D0332","Black Rock"],["0D1117","Bunker"],["0D1C19","Aztec"],["0D2E1C","Bush"],["0E0E18","Cinder"],["0E2A30","Firefly"],["0F2D9E","Torea Bay"],["10121D","Vulcan"],["101405","Green Waterloo"],["105852","Eden"],["110C6C","Arapawa"],["120A8F","Ultramarine"],["123447","Elephant"],["126B40","Jewel"],["130000","Diesel"],["130A06","Asphalt"],["13264D","Blue Zodiac"],["134F19","Parsley"],["140600","Nero"],["1450AA","Tory Blue"],["151F4C","Bunting"],["1560BD","Denim"],["15736B","Genoa"],["161928","Mirage"],["161D10","Hunter Green"],["162A40","Big Stone"],["163222","Celtic"],["16322C","Timber Green"],["163531","Gable Green"],["171F04","Pine Tree"],["175579","Chathams Blue"],["182D09","Deep Forest Green"],["18587A","Blumine"],["19330E","Palm Leaf"],["193751","Nile Blue"],["1959A8","Fun Blue"],["1A1A68","Lucky Point"],["1AB385","Mountain Meadow"],["1B0245","Tolopea"],["1B1035","Haiti"],["1B127B","Deep Koamaru"],["1B1404","Acadia"],["1B2F11","Seaweed"],["1B3162","Biscay"],["1B659D","Matisse"],["1C1208","Crowshead"],["1C1E13","Rangoon Green"],["1C39BB","Persian Blue"],["1C402E","Everglade"],["1C7C7D","Elm"],["1D6142","Green Pea"],["1E0F04","Creole"],["1E1609","Karaka"],["1E1708","El Paso"],["1E385B","Cello"],["1E433C","Te Papa Green"],["1E90FF","Dodger Blue"],["1E9AB0","Eastern Blue"],["1F120F","Night Rider"],["1FC2C2","Java"],["20208D","Jacksons Purple"],["202E54","Cloud Burst"],["204852","Blue Dianne"],["211A0E","Eternity"],["220878","Deep Blue"],["228B22","Forest Green"],["233418","Mallard"],["240A40","Violet"],["240C02","Kilamanjaro"],["242A1D","Log Cabin"],["242E16","Black Olive"],["24500F","Green House"],["251607","Graphite"],["251706","Cannon Black"],["251F4F","Port Gore"],["25272C","Shark"],["25311C","Green Kelp"],["2596D1","Curious Blue"],["260368","Paua"],["26056A","Paris M"],["261105","Wood Bark"],["261414","Gondola"],["262335","Steel Gray"],["26283B","Ebony Clay"],["273A81","Bay of Many"],["27504B","Plantation"],["278A5B","Eucalyptus"],["281E15","Oil"],["283A77","Astronaut"],["286ACD","Mariner"],["290C5E","Violent Violet"],["292130","Bastille"],["292319","Zeus"],["292937","Charade"],["297B9A","Jelly Bean"],["29AB87","Jungle Green"],["2A0359","Cherry Pie"],["2A140E","Coffee Bean"],["2A2630","Baltic Sea"],["2A380B","Turtle Green"],["2A52BE","Cerulean Blue"],["2B0202","Sepia Black"],["2B194F","Valhalla"],["2B3228","Heavy Metal"],["2C0E8C","Blue Gem"],["2C1632","Revolver"],["2C2133","Bleached Cedar"],["2C8C84","Lochinvar"],["2D2510","Mikado"],["2D383A","Outer Space"],["2D569B","St Tropaz"],["2E0329","Jacaranda"],["2E1905","Jacko Bean"],["2E3222","Rangitoto"],["2E3F62","Rhino"],["2E8B57","Sea Green"],["2EBFD4","Scooter"],["2F270E","Onion"],["2F3CB3","Governor Bay"],["2F519E","Sapphire"],["2F5A57","Spectra"],["2F6168","Casal"],["300529","Melanzane"],["301F1E","Cocoa Brown"],["302A0F","Woodrush"],["304B6A","San Juan"],["30D5C8","Turquoise"],["311C17","Eclipse"],["314459","Pickled Bluewood"],["315BA1","Azure"],["31728D","Calypso"],["317D82","Paradiso"],["32127A","Persian Indigo"],["32293A","Blackcurrant"],["323232","Mine Shaft"],["325D52","Stromboli"],["327C14","Bilbao"],["327DA0","Astral"],["33036B","Christalle"],["33292F","Thunder"],["33CC99","Shamrock"],["341515","Tamarind"],["350036","Mardi Gras"],["350E42","Valentino"],["350E57","Jagger"],["353542","Tuna"],["354E8C","Chambray"],["363050","Martinique"],["363534","Tuatara"],["363C0D","Waiouru"],["36747D","Ming"],["368716","La Palma"],["370202","Chocolate"],["371D09","Clinker"],["37290E","Brown Tumbleweed"],["373021","Birch"],["377475","Oracle"],["380474","Blue Diamond"],["381A51","Grape"],["383533","Dune"],["384555","Oxford Blue"],["384910","Clover"],["394851","Limed Spruce"],["396413","Dell"],["3A0020","Toledo"],["3A2010","Sambuca"],["3A2A6A","Jacarta"],["3A686C","William"],["3A6A47","Killarney"],["3AB09E","Keppel"],["3B000B","Temptress"],["3B0910","Aubergine"],["3B1F1F","Jon"],["3B2820","Treehouse"],["3B7A57","Amazon"],["3B91B4","Boston Blue"],["3C0878","Windsor"],["3C1206","Rebel"],["3C1F76","Meteorite"],["3C2005","Dark Ebony"],["3C3910","Camouflage"],["3C4151","Bright Gray"],["3C4443","Cape Cod"],["3C493A","Lunar Green"],["3D0C02","Bean "],["3D2B1F","Bistre"],["3D7D52","Goblin"],["3E0480","Kingfisher Daisy"],["3E1C14","Cedar"],["3E2B23","English Walnut"],["3E2C1C","Black Marlin"],["3E3A44","Ship Gray"],["3EABBF","Pelorous"],["3F2109","Bronze"],["3F2500","Cola"],["3F3002","Madras"],["3F307F","Minsk"],["3F4C3A","Cabbage Pont"],["3F583B","Tom Thumb"],["3F5D53","Mineral Green"],["3FC1AA","Puerto Rico"],["3FFF00","Harlequin"],["401801","Brown Pod"],["40291D","Cork"],["403B38","Masala"],["403D19","Thatch Green"],["405169","Fiord"],["40826D","Viridian"],["40A860","Chateau Green"],["410056","Ripe Plum"],["411F10","Paco"],["412010","Deep Oak"],["413C37","Merlin"],["414257","Gun Powder"],["414C7D","East Bay"],["4169E1","Royal Blue"],["41AA78","Ocean Green"],["420303","Burnt Maroon"],["423921","Lisbon Brown"],["427977","Faded Jade"],["431560","Scarlet Gum"],["433120","Iroko"],["433E37","Armadillo"],["434C59","River Bed"],["436A0D","Green Leaf"],["44012D","Barossa"],["441D00","Morocco Brown"],["444954","Mako"],["454936","Kelp"],["456CAC","San Marino"],["45B1E8","Picton Blue"],["460B41","Loulou"],["462425","Crater Brown"],["465945","Gray Asparagus"],["4682B4","Steel Blue"],["480404","Rustic Red"],["480607","Bulgarian Rose"],["480656","Clairvoyant"],["481C1C","Cocoa Bean"],["483131","Woody Brown"],["483C32","Taupe"],["49170C","Van Cleef"],["492615","Brown Derby"],["49371B","Metallic Bronze"],["495400","Verdun Green"],["496679","Blue Bayoux"],["497183","Bismark"],["4A2A04","Bracken"],["4A3004","Deep Bronze"],["4A3C30","Mondo"],["4A4244","Tundora"],["4A444B","Gravel"],["4A4E5A","Trout"],["4B0082","Pigment Indigo"],["4B5D52","Nandor"],["4C3024","Saddle"],["4C4F56","Abbey"],["4D0135","Blackberry"],["4D0A18","Cab Sav"],["4D1E01","Indian Tan"],["4D282D","Cowboy"],["4D282E","Livid Brown"],["4D3833","Rock"],["4D3D14","Punga"],["4D400F","Bronzetone"],["4D5328","Woodland"],["4E0606","Mahogany"],["4E2A5A","Bossanova"],["4E3B41","Matterhorn"],["4E420C","Bronze Olive"],["4E4562","Mulled Wine"],["4E6649","Axolotl"],["4E7F9E","Wedgewood"],["4EABD1","Shakespeare"],["4F1C70","Honey Flower"],["4F2398","Daisy Bush"],["4F69C6","Indigo"],["4F7942","Fern Green"],["4F9D5D","Fruit Salad"],["4FA83D","Apple"],["504351","Mortar"],["507096","Kashmir Blue"],["507672","Cutty Sark"],["50C878","Emerald"],["514649","Emperor"],["516E3D","Chalet Green"],["517C66","Como"],["51808F","Smalt Blue"],["52001F","Castro"],["520C17","Maroon Oak"],["523C94","Gigas"],["533455","Voodoo"],["534491","Victoria"],["53824B","Hippie Green"],["541012","Heath"],["544333","Judge Gray"],["54534D","Fuscous Gray"],["549019","Vida Loca"],["55280C","Cioccolato"],["555B10","Saratoga"],["556D56","Finlandia"],["5590D9","Havelock Blue"],["56B4BE","Fountain Blue"],["578363","Spring Leaves"],["583401","Saddle Brown"],["585562","Scarpa Flow"],["587156","Cactus"],["589AAF","Hippie Blue"],["591D35","Wine Berry"],["592804","Brown Bramble"],["593737","Congo Brown"],["594433","Millbrook"],["5A6E9C","Waikawa Gray"],["5A87A0","Horizon"],["5B3013","Jambalaya"],["5C0120","Bordeaux"],["5C0536","Mulberry Wood"],["5C2E01","Carnaby Tan"],["5C5D75","Comet"],["5D1E0F","Redwood"],["5D4C51","Don Juan"],["5D5C58","Chicago"],["5D5E37","Verdigris"],["5D7747","Dingley"],["5DA19F","Breaker Bay"],["5E483E","Kabul"],["5E5D3B","Hemlock"],["5F3D26","Irish Coffee"],["5F5F6E","Mid Gray"],["5F6672","Shuttle Gray"],["5FA777","Aqua Forest"],["5FB3AC","Tradewind"],["604913","Horses Neck"],["605B73","Smoky"],["606E68","Corduroy"],["6093D1","Danube"],["612718","Espresso"],["614051","Eggplant"],["615D30","Costa Del Sol"],["61845F","Glade Green"],["622F30","Buccaneer"],["623F2D","Quincy"],["624E9A","Butterfly Bush"],["625119","West Coast"],["626649","Finch"],["639A8F","Patina"],["63B76C","Fern"],["6456B7","Blue Violet"],["646077","Dolphin"],["646463","Storm Dust"],["646A54","Siam"],["646E75","Nevada"],["6495ED","Cornflower Blue"],["64CCDB","Viking"],["65000B","Rosewood"],["651A14","Cherrywood"],["652DC1","Purple Heart"],["657220","Fern Frond"],["65745D","Willow Grove"],["65869F","Hoki"],["660045","Pompadour"],["660099","Purple"],["66023C","Tyrian Purple"],["661010","Dark Tan"],["66B58F","Silver Tree"],["66FF00","Bright Green"],["66FF66","Screamin' Green"],["67032D","Black Rose"],["675FA6","Scampi"],["676662","Ironside Gray"],["678975","Viridian Green"],["67A712","Christi"],["683600","Nutmeg Wood Finish"],["685558","Zambezi"],["685E6E","Salt Box"],["692545","Tawny Port"],["692D54","Finn"],["695F62","Scorpion"],["697E9A","Lynch"],["6A442E","Spice"],["6A5D1B","Himalaya"],["6A6051","Soya Bean"],["6B2A14","Hairy Heath"],["6B3FA0","Royal Purple"],["6B4E31","Shingle Fawn"],["6B5755","Dorado"],["6B8BA2","Bermuda Gray"],["6B8E23","Olive Drab"],["6C3082","Eminence"],["6CDAE7","Turquoise Blue"],["6D0101","Lonestar"],["6D5E54","Pine Cone"],["6D6C6C","Dove Gray"],["6D9292","Juniper"],["6D92A1","Gothic"],["6E0902","Red Oxide"],["6E1D14","Moccaccino"],["6E4826","Pickled Bean"],["6E4B26","Dallas"],["6E6D57","Kokoda"],["6E7783","Pale Sky"],["6F440C","Cafe Royale"],["6F6A61","Flint"],["6F8E63","Highland"],["6F9D02","Limeade"],["6FD0C5","Downy"],["701C1C","Persian Plum"],["704214","Sepia"],["704A07","Antique Bronze"],["704F50","Ferra"],["706555","Coffee"],["708090","Slate Gray"],["711A00","Cedar Wood Finish"],["71291D","Metallic Copper"],["714693","Affair"],["714AB2","Studio"],["715D47","Tobacco Brown"],["716338","Yellow Metal"],["716B56","Peat"],["716E10","Olivetone"],["717486","Storm Gray"],["718080","Sirocco"],["71D9E2","Aquamarine Blue"],["72010F","Venetian Red"],["724A2F","Old Copper"],["726D4E","Go Ben"],["727B89","Raven"],["731E8F","Seance"],["734A12","Raw Umber"],["736C9F","Kimberly"],["736D58","Crocodile"],["737829","Crete"],["738678","Xanadu"],["74640D","Spicy Mustard"],["747D63","Limed Ash"],["747D83","Rolling Stone"],["748881","Blue Smoke"],["749378","Laurel"],["74C365","Mantis"],["755A57","Russett"],["7563A8","Deluge"],["76395D","Cosmic"],["7666C6","Blue Marguerite"],["76BD17","Lima"],["76D7EA","Sky Blue"],["770F05","Dark Burgundy"],["771F1F","Crown of Thorns"],["773F1A","Walnut"],["776F61","Pablo"],["778120","Pacifika"],["779E86","Oxley"],["77DD77","Pastel Green"],["780109","Japanese Maple"],["782D19","Mocha"],["782F16","Peanut"],["78866B","Camouflage Green"],["788A25","Wasabi"],["788BBA","Ship Cove"],["78A39C","Sea Nymph"],["795D4C","Roman Coffee"],["796878","Old Lavender"],["796989","Rum"],["796A78","Fedora"],["796D62","Sandstone"],["79DEEC","Spray"],["7A013A","Siren"],["7A58C1","Fuchsia Blue"],["7A7A7A","Boulder"],["7A89B8","Wild Blue Yonder"],["7AC488","De York"],["7B3801","Red Beech"],["7B3F00","Cinnamon"],["7B6608","Yukon Gold"],["7B7874","Tapa"],["7B7C94","Waterloo "],["7B8265","Flax Smoke"],["7B9F80","Amulet"],["7BA05B","Asparagus"],["7C1C05","Kenyan Copper"],["7C7631","Pesto"],["7C778A","Topaz"],["7C7B7A","Concord"],["7C7B82","Jumbo"],["7C881A","Trendy Green"],["7CA1A6","Gumbo"],["7CB0A1","Acapulco"],["7CB7BB","Neptune"],["7D2C14","Pueblo"],["7DA98D","Bay Leaf"],["7DC8F7","Malibu"],["7DD8C6","Bermuda"],["7E3A15","Copper Canyon"],["7F1734","Claret"],["7F3A02","Peru Tan"],["7F626D","Falcon"],["7F7589","Mobster"],["7F76D3","Moody Blue"],["7FFF00","Chartreuse"],["7FFFD4","Aquamarine"],["800000","Maroon"],["800B47","Rose Bud Cherry"],["801818","Falu Red"],["80341F","Red Robin"],["803790","Vivid Violet"],["80461B","Russet"],["807E79","Friar Gray"],["808000","Olive"],["808080","Gray"],["80B3AE","Gulf Stream"],["80B3C4","Glacier"],["80CCEA","Seagull"],["81422C","Nutmeg"],["816E71","Spicy Pink"],["817377","Empress"],["819885","Spanish Green"],["826F65","Sand Dune"],["828685","Gunsmoke"],["828F72","Battleship Gray"],["831923","Merlot"],["837050","Shadow"],["83AA5D","Chelsea Cucumber"],["83D0C6","Monte Carlo"],["843179","Plum"],["84A0A0","Granny Smith"],["8581D9","Chetwode Blue"],["858470","Bandicoot"],["859FAF","Bali Hai"],["85C4CC","Half Baked"],["860111","Red Devil"],["863C3C","Lotus"],["86483C","Ironstone"],["864D1E","Bull Shot"],["86560A","Rusty Nail"],["868974","Bitter"],["86949F","Regent Gray"],["871550","Disco"],["87756E","Americano"],["877C7B","Hurricane"],["878D91","Oslo Gray"],["87AB39","Sushi"],["885342","Spicy Mix"],["886221","Kumera"],["888387","Suva Gray"],["888D65","Avocado"],["893456","Camelot"],["893843","Solid Pink"],["894367","Cannon Pink"],["897D6D","Makara"],["8A3324","Burnt Umber"],["8A73D6","True V"],["8A8360","Clay Creek"],["8A8389","Monsoon"],["8A8F8A","Stack"],["8AB9F1","Jordy Blue"],["8B00FF","Electric Violet"],["8B0723","Monarch"],["8B6B0B","Corn Harvest"],["8B8470","Olive Haze"],["8B847E","Schooner"],["8B8680","Natural Gray"],["8B9C90","Mantle"],["8B9FEE","Portage"],["8BA690","Envy"],["8BA9A5","Cascade"],["8BE6D8","Riptide"],["8C055E","Cardinal Pink"],["8C472F","Mule Fawn"],["8C5738","Potters Clay"],["8C6495","Trendy Pink"],["8D0226","Paprika"],["8D3D38","Sanguine Brown"],["8D3F3F","Tosca"],["8D7662","Cement"],["8D8974","Granite Green"],["8D90A1","Manatee"],["8DA8CC","Polo Blue"],["8E0000","Red Berry"],["8E4D1E","Rope"],["8E6F70","Opium"],["8E775E","Domino"],["8E8190","Mamba"],["8EABC1","Nepal"],["8F021C","Pohutukawa"],["8F3E33","El Salva"],["8F4B0E","Korma"],["8F8176","Squirrel"],["8FD6B4","Vista Blue"],["900020","Burgundy"],["901E1E","Old Brick"],["907874","Hemp"],["907B71","Almond Frost"],["908D39","Sycamore"],["92000A","Sangria"],["924321","Cumin"],["926F5B","Beaver"],["928573","Stonewall"],["928590","Venus"],["9370DB","Medium Purple"],["93CCEA","Cornflower"],["93DFB8","Algae Green"],["944747","Copper Rust"],["948771","Arrowtown"],["950015","Scarlett"],["956387","Strikemaster"],["959396","Mountain Mist"],["960018","Carmine"],["964B00","Brown"],["967059","Leather"],["9678B6","Purple Mountain's Majesty"],["967BB6","Lavender Purple"],["96A8A1","Pewter"],["96BBAB","Summer Green"],["97605D","Au Chico"],["9771B5","Wisteria"],["97CD2D","Atlantis"],["983D61","Vin Rouge"],["9874D3","Lilac Bush"],["98777B","Bazaar"],["98811B","Hacienda"],["988D77","Pale Oyster"],["98FF98","Mint Green"],["990066","Fresh Eggplant"],["991199","Violet Eggplant"],["991613","Tamarillo"],["991B07","Totem Pole"],["996666","Copper Rose"],["9966CC","Amethyst"],["997A8D","Mountbatten Pink"],["9999CC","Blue Bell"],["9A3820","Prairie Sand"],["9A6E61","Toast"],["9A9577","Gurkha"],["9AB973","Olivine"],["9AC2B8","Shadow Green"],["9B4703","Oregon"],["9B9E8F","Lemon Grass"],["9C3336","Stiletto"],["9D5616","Hawaiian Tan"],["9DACB7","Gull Gray"],["9DC209","Pistachio"],["9DE093","Granny Smith Apple"],["9DE5FF","Anakiwa"],["9E5302","Chelsea Gem"],["9E5B40","Sepia Skin"],["9EA587","Sage"],["9EA91F","Citron"],["9EB1CD","Rock Blue"],["9EDEE0","Morning Glory"],["9F381D","Cognac"],["9F821C","Reef Gold"],["9F9F9C","Star Dust"],["9FA0B1","Santas Gray"],["9FD7D3","Sinbad"],["9FDD8C","Feijoa"],["A02712","Tabasco"],["A1750D","Buttered Rum"],["A1ADB5","Hit Gray"],["A1C50A","Citrus"],["A1DAD7","Aqua Island"],["A1E9DE","Water Leaf"],["A2006D","Flirt"],["A23B6C","Rouge"],["A26645","Cape Palliser"],["A2AAB3","Gray Chateau"],["A2AEAB","Edward"],["A3807B","Pharlap"],["A397B4","Amethyst Smoke"],["A3E3ED","Blizzard Blue"],["A4A49D","Delta"],["A4A6D3","Wistful"],["A4AF6E","Green Smoke"],["A50B5E","Jazzberry Jam"],["A59B91","Zorba"],["A5CB0C","Bahia"],["A62F20","Roof Terracotta"],["A65529","Paarl"],["A68B5B","Barley Corn"],["A69279","Donkey Brown"],["A6A29A","Dawn"],["A72525","Mexican Red"],["A7882C","Luxor Gold"],["A85307","Rich Gold"],["A86515","Reno Sand"],["A86B6B","Coral Tree"],["A8989B","Dusty Gray"],["A899E6","Dull Lavender"],["A8A589","Tallow"],["A8AE9C","Bud"],["A8AF8E","Locust"],["A8BD9F","Norway"],["A8E3BD","Chinook"],["A9A491","Gray Olive"],["A9ACB6","Aluminium"],["A9B2C3","Cadet Blue"],["A9B497","Schist"],["A9BDBF","Tower Gray"],["A9BEF2","Perano"],["A9C6C2","Opal"],["AA375A","Night Shadz"],["AA4203","Fire"],["AA8B5B","Muesli"],["AA8D6F","Sandal"],["AAA5A9","Shady Lady"],["AAA9CD","Logan"],["AAABB7","Spun Pearl"],["AAD6E6","Regent St Blue"],["AAF0D1","Magic Mint"],["AB0563","Lipstick"],["AB3472","Royal Heath"],["AB917A","Sandrift"],["ABA0D9","Cold Purple"],["ABA196","Bronco"],["AC8A56","Limed Oak"],["AC91CE","East Side"],["AC9E22","Lemon Ginger"],["ACA494","Napa"],["ACA586","Hillary"],["ACA59F","Cloudy"],["ACACAC","Silver Chalice"],["ACB78E","Swamp Green"],["ACCBB1","Spring Rain"],["ACDD4D","Conifer"],["ACE1AF","Celadon"],["AD781B","Mandalay"],["ADBED1","Casper"],["ADDFAD","Moss Green"],["ADE6C4","Padua"],["ADFF2F","Green Yellow"],["AE4560","Hippie Pink"],["AE6020","Desert"],["AE809E","Bouquet"],["AF4035","Medium Carmine"],["AF4D43","Apple Blossom"],["AF593E","Brown Rust"],["AF8751","Driftwood"],["AF8F2C","Alpine"],["AF9F1C","Lucky"],["AFA09E","Martini"],["AFB1B8","Bombay"],["AFBDD9","Pigeon Post"],["B04C6A","Cadillac"],["B05D54","Matrix"],["B05E81","Tapestry"],["B06608","Mai Tai"],["B09A95","Del Rio"],["B0E0E6","Powder Blue"],["B0E313","Inch Worm"],["B10000","Bright Red"],["B14A0B","Vesuvius"],["B1610B","Pumpkin Skin"],["B16D52","Santa Fe"],["B19461","Teak"],["B1E2C1","Fringy Flower"],["B1F4E7","Ice Cold"],["B20931","Shiraz"],["B2A1EA","Biloba Flower"],["B32D29","Tall Poppy"],["B35213","Fiery Orange"],["B38007","Hot Toddy"],["B3AF95","Taupe Gray"],["B3C110","La Rioja"],["B43332","Well Read"],["B44668","Blush"],["B4CFD3","Jungle Mist"],["B57281","Turkish Rose"],["B57EDC","Lavender"],["B5A27F","Mongoose"],["B5B35C","Olive Green"],["B5D2CE","Jet Stream"],["B5ECDF","Cruise"],["B6316C","Hibiscus"],["B69D98","Thatch"],["B6B095","Heathered Gray"],["B6BAA4","Eagle"],["B6D1EA","Spindle"],["B6D3BF","Gum Leaf"],["B7410E","Rust"],["B78E5C","Muddy Waters"],["B7A214","Sahara"],["B7A458","Husk"],["B7B1B1","Nobel"],["B7C3D0","Heather"],["B7F0BE","Madang"],["B81104","Milano Red"],["B87333","Copper"],["B8B56A","Gimblet"],["B8C1B1","Green Spring"],["B8C25D","Celery"],["B8E0F9","Sail"],["B94E48","Chestnut"],["B95140","Crail"],["B98D28","Marigold"],["B9C46A","Wild Willow"],["B9C8AC","Rainee"],["BA0101","Guardsman Red"],["BA450C","Rock Spray"],["BA6F1E","Bourbon"],["BA7F03","Pirate Gold"],["BAB1A2","Nomad"],["BAC7C9","Submarine"],["BAEEF9","Charlotte"],["BB3385","Medium Red Violet"],["BB8983","Brandy Rose"],["BBD009","Rio Grande"],["BBD7C1","Surf"],["BCC9C2","Powder Ash"],["BD5E2E","Tuscany"],["BD978E","Quicksand"],["BDB1A8","Silk"],["BDB2A1","Malta"],["BDB3C7","Chatelle"],["BDBBD7","Lavender Gray"],["BDBDC6","French Gray"],["BDC8B3","Clay Ash"],["BDC9CE","Loblolly"],["BDEDFD","French Pass"],["BEA6C3","London Hue"],["BEB5B7","Pink Swan"],["BEDE0D","Fuego"],["BF5500","Rose of Sharon"],["BFB8B0","Tide"],["BFBED8","Blue Haze"],["BFC1C2","Silver Sand"],["BFC921","Key Lime Pie"],["BFDBE2","Ziggurat"],["BFFF00","Lime"],["C02B18","Thunderbird"],["C04737","Mojo"],["C08081","Old Rose"],["C0C0C0","Silver"],["C0D3B9","Pale Leaf"],["C0D8B6","Pixie Green"],["C1440E","Tia Maria"],["C154C1","Fuchsia Pink"],["C1A004","Buddha Gold"],["C1B7A4","Bison Hide"],["C1BAB0","Tea"],["C1BECD","Gray Suit"],["C1D7B0","Sprout"],["C1F07C","Sulu"],["C26B03","Indochine"],["C2955D","Twine"],["C2BDB6","Cotton Seed"],["C2CAC4","Pumice"],["C2E8E5","Jagged Ice"],["C32148","Maroon Flush"],["C3B091","Indian Khaki"],["C3BFC1","Pale Slate"],["C3C3BD","Gray Nickel"],["C3CDE6","Periwinkle Gray"],["C3D1D1","Tiara"],["C3DDF9","Tropical Blue"],["C41E3A","Cardinal"],["C45655","Fuzzy Wuzzy Brown"],["C45719","Orange Roughy"],["C4C4BC","Mist Gray"],["C4D0B0","Coriander"],["C4F4EB","Mint Tulip"],["C54B8C","Mulberry"],["C59922","Nugget"],["C5994B","Tussock"],["C5DBCA","Sea Mist"],["C5E17A","Yellow Green"],["C62D42","Brick Red"],["C6726B","Contessa"],["C69191","Oriental Pink"],["C6A84B","Roti"],["C6C3B5","Ash"],["C6C8BD","Kangaroo"],["C6E610","Las Palmas"],["C7031E","Monza"],["C71585","Red Violet"],["C7BCA2","Coral Reef"],["C7C1FF","Melrose"],["C7C4BF","Cloud"],["C7C9D5","Ghost"],["C7CD90","Pine Glade"],["C7DDE5","Botticelli"],["C88A65","Antique Brass"],["C8A2C8","Lilac"],["C8A528","Hokey Pokey"],["C8AABF","Lily"],["C8B568","Laser"],["C8E3D7","Edgewater"],["C96323","Piper"],["C99415","Pizza"],["C9A0DC","Light Wisteria"],["C9B29B","Rodeo Dust"],["C9B35B","Sundance"],["C9B93B","Earls Green"],["C9C0BB","Silver Rust"],["C9D9D2","Conch"],["C9FFA2","Reef"],["C9FFE5","Aero Blue"],["CA3435","Flush Mahogany"],["CABB48","Turmeric"],["CADCD4","Paris White"],["CAE00D","Bitter Lemon"],["CAE6DA","Skeptic"],["CB8FA9","Viola"],["CBCAB6","Foggy Gray"],["CBD3B0","Green Mist"],["CBDBD6","Nebula"],["CC3333","Persian Red"],["CC5500","Burnt Orange"],["CC7722","Ochre"],["CC8899","Puce"],["CCCAA8","Thistle Green"],["CCCCFF","Periwinkle"],["CCFF00","Electric Lime"],["CD5700","Tenn"],["CD5C5C","Chestnut Rose"],["CD8429","Brandy Punch"],["CDF4FF","Onahau"],["CEB98F","Sorrell Brown"],["CEBABA","Cold Turkey"],["CEC291","Yuma"],["CEC7A7","Chino"],["CFA39D","Eunry"],["CFB53B","Old Gold"],["CFDCCF","Tasman"],["CFE5D2","Surf Crest"],["CFF9F3","Humming Bird"],["CFFAF4","Scandal"],["D05F04","Red Stage"],["D06DA1","Hopbush"],["D07D12","Meteor"],["D0BEF8","Perfume"],["D0C0E5","Prelude"],["D0F0C0","Tea Green"],["D18F1B","Geebung"],["D1BEA8","Vanilla"],["D1C6B4","Soft Amber"],["D1D2CA","Celeste"],["D1D2DD","Mischka"],["D1E231","Pear"],["D2691E","Hot Cinnamon"],["D27D46","Raw Sienna"],["D29EAA","Careys Pink"],["D2B48C","Tan"],["D2DA97","Deco"],["D2F6DE","Blue Romance"],["D2F8B0","Gossip"],["D3CBBA","Sisal"],["D3CDC5","Swirl"],["D47494","Charm"],["D4B6AF","Clam Shell"],["D4BF8D","Straw"],["D4C4A8","Akaroa"],["D4CD16","Bird Flower"],["D4D7D9","Iron"],["D4DFE2","Geyser"],["D4E2FC","Hawkes Blue"],["D54600","Grenadier"],["D591A4","Can Can"],["D59A6F","Whiskey"],["D5D195","Winter Hazel"],["D5F6E3","Granny Apple"],["D69188","My Pink"],["D6C562","Tacha"],["D6CEF6","Moon Raker"],["D6D6D1","Quill Gray"],["D6FFDB","Snowy Mint"],["D7837F","New York Pink"],["D7C498","Pavlova"],["D7D0FF","Fog"],["D84437","Valencia"],["D87C63","Japonica"],["D8BFD8","Thistle"],["D8C2D5","Maverick"],["D8FCFA","Foam"],["D94972","Cabaret"],["D99376","Burning Sand"],["D9B99B","Cameo"],["D9D6CF","Timberwolf"],["D9DCC1","Tana"],["D9E4F5","Link Water"],["D9F7FF","Mabel"],["DA3287","Cerise"],["DA5B38","Flame Pea"],["DA6304","Bamboo"],["DA6A41","Red Damask"],["DA70D6","Orchid"],["DA8A67","Copperfield"],["DAA520","Golden Grass"],["DAECD6","Zanah"],["DAF4F0","Iceberg"],["DAFAFF","Oyster Bay"],["DB5079","Cranberry"],["DB9690","Petite Orchid"],["DB995E","Di Serria"],["DBDBDB","Alto"],["DBFFF8","Frosted Mint"],["DC143C","Crimson"],["DC4333","Punch"],["DCB20C","Galliano"],["DCB4BC","Blossom"],["DCD747","Wattle"],["DCD9D2","Westar"],["DCDDCC","Moon Mist"],["DCEDB4","Caper"],["DCF0EA","Swans Down"],["DDD6D5","Swiss Coffee"],["DDF9F1","White Ice"],["DE3163","Cerise Red"],["DE6360","Roman"],["DEA681","Tumbleweed"],["DEBA13","Gold Tips"],["DEC196","Brandy"],["DECBC6","Wafer"],["DED4A4","Sapling"],["DED717","Barberry"],["DEE5C0","Beryl Green"],["DEF5FF","Pattens Blue"],["DF73FF","Heliotrope"],["DFBE6F","Apache"],["DFCD6F","Chenin"],["DFCFDB","Lola"],["DFECDA","Willow Brook"],["DFFF00","Chartreuse Yellow"],["E0B0FF","Mauve"],["E0B646","Anzac"],["E0B974","Harvest Gold"],["E0C095","Calico"],["E0FFFF","Baby Blue"],["E16865","Sunglo"],["E1BC64","Equator"],["E1C0C8","Pink Flare"],["E1E6D6","Periglacial Blue"],["E1EAD4","Kidnapper"],["E1F6E8","Tara"],["E25465","Mandy"],["E2725B","Terracotta"],["E28913","Golden Bell"],["E292C0","Shocking"],["E29418","Dixie"],["E29CD2","Light Orchid"],["E2D8ED","Snuff"],["E2EBED","Mystic"],["E2F3EC","Apple Green"],["E30B5C","Razzmatazz"],["E32636","Alizarin Crimson"],["E34234","Cinnabar"],["E3BEBE","Cavern Pink"],["E3F5E1","Peppermint"],["E3F988","Mindaro"],["E47698","Deep Blush"],["E49B0F","Gamboge"],["E4C2D5","Melanie"],["E4CFDE","Twilight"],["E4D1C0","Bone"],["E4D422","Sunflower"],["E4D5B7","Grain Brown"],["E4D69B","Zombie"],["E4F6E7","Frostee"],["E4FFD1","Snow Flurry"],["E52B50","Amaranth"],["E5841B","Zest"],["E5CCC9","Dust Storm"],["E5D7BD","Stark White"],["E5D8AF","Hampton"],["E5E0E1","Bon Jour"],["E5E5E5","Mercury"],["E5F9F6","Polar"],["E64E03","Trinidad"],["E6BE8A","Gold Sand"],["E6BEA5","Cashmere"],["E6D7B9","Double Spanish White"],["E6E4D4","Satin Linen"],["E6F2EA","Harp"],["E6F8F3","Off Green"],["E6FFE9","Hint of Green"],["E6FFFF","Tranquil"],["E77200","Mango Tango"],["E7730A","Christine"],["E79F8C","Tonys Pink"],["E79FC4","Kobi"],["E7BCB4","Rose Fog"],["E7BF05","Corn"],["E7CD8C","Putty"],["E7ECE6","Gray Nurse"],["E7F8FF","Lily White"],["E7FEFF","Bubbles"],["E89928","Fire Bush"],["E8B9B3","Shilo"],["E8E0D5","Pearl Bush"],["E8EBE0","Green White"],["E8F1D4","Chrome White"],["E8F2EB","Gin"],["E8F5F2","Aqua Squeeze"],["E96E00","Clementine"],["E97451","Burnt Sienna"],["E97C07","Tahiti Gold"],["E9CECD","Oyster Pink"],["E9D75A","Confetti"],["E9E3E3","Ebb"],["E9F8ED","Ottoman"],["E9FFFD","Clear Day"],["EA88A8","Carissma"],["EAAE69","Porsche"],["EAB33B","Tulip Tree"],["EAC674","Rob Roy"],["EADAB8","Raffia"],["EAE8D4","White Rock"],["EAF6EE","Panache"],["EAF6FF","Solitude"],["EAF9F5","Aqua Spring"],["EAFFFE","Dew"],["EB9373","Apricot"],["EBC2AF","Zinnwaldite"],["ECA927","Fuel Yellow"],["ECC54E","Ronchi"],["ECC7EE","French Lilac"],["ECCDB9","Just Right"],["ECE090","Wild Rice"],["ECEBBD","Fall Green"],["ECEBCE","Aths Special"],["ECF245","Starship"],["ED0A3F","Red Ribbon"],["ED7A1C","Tango"],["ED9121","Carrot Orange"],["ED989E","Sea Pink"],["EDB381","Tacao"],["EDC9AF","Desert Sand"],["EDCDAB","Pancho"],["EDDCB1","Chamois"],["EDEA99","Primrose"],["EDF5DD","Frost"],["EDF5F5","Aqua Haze"],["EDF6FF","Zumthor"],["EDF9F1","Narvik"],["EDFC84","Honeysuckle"],["EE82EE","Lavender Magenta"],["EEC1BE","Beauty Bush"],["EED794","Chalky"],["EED9C4","Almond"],["EEDC82","Flax"],["EEDEDA","Bizarre"],["EEE3AD","Double Colonial White"],["EEEEE8","Cararra"],["EEEF78","Manz"],["EEF0C8","Tahuna Sands"],["EEF0F3","Athens Gray"],["EEF3C3","Tusk"],["EEF4DE","Loafer"],["EEF6F7","Catskill White"],["EEFDFF","Twilight Blue"],["EEFF9A","Jonquil"],["EEFFE2","Rice Flower"],["EF863F","Jaffa"],["EFEFEF","Gallery"],["EFF2F3","Porcelain"],["F091A9","Mauvelous"],["F0D52D","Golden Dream"],["F0DB7D","Golden Sand"],["F0DC82","Buff"],["F0E2EC","Prim"],["F0E68C","Khaki"],["F0EEFD","Selago"],["F0EEFF","Titan White"],["F0F8FF","Alice Blue"],["F0FCEA","Feta"],["F18200","Gold Drop"],["F19BAB","Wewak"],["F1E788","Sahara Sand"],["F1E9D2","Parchment"],["F1E9FF","Blue Chalk"],["F1EEC1","Mint Julep"],["F1F1F1","Seashell"],["F1F7F2","Saltpan"],["F1FFAD","Tidal"],["F1FFC8","Chiffon"],["F2552A","Flamingo"],["F28500","Tangerine"],["F2C3B2","Mandys Pink"],["F2F2F2","Concrete"],["F2FAFA","Black Squeeze"],["F34723","Pomegranate"],["F3AD16","Buttercup"],["F3D69D","New Orleans"],["F3D9DF","Vanilla Ice"],["F3E7BB","Sidecar"],["F3E9E5","Dawn Pink"],["F3EDCF","Wheatfield"],["F3FB62","Canary"],["F3FBD4","Orinoco"],["F3FFD8","Carla"],["F400A1","Hollywood Cerise"],["F4A460","Sandy brown"],["F4C430","Saffron"],["F4D81C","Ripe Lemon"],["F4EBD3","Janna"],["F4F2EE","Pampas"],["F4F4F4","Wild Sand"],["F4F8FF","Zircon"],["F57584","Froly"],["F5C85C","Cream Can"],["F5C999","Manhattan"],["F5D5A0","Maize"],["F5DEB3","Wheat"],["F5E7A2","Sandwisp"],["F5E7E2","Pot Pourri"],["F5E9D3","Albescent White"],["F5EDEF","Soft Peach"],["F5F3E5","Ecru White"],["F5F5DC","Beige"],["F5FB3D","Golden Fizz"],["F5FFBE","Australian Mint"],["F64A8A","French Rose"],["F653A6","Brilliant Rose"],["F6A4C9","Illusion"],["F6F0E6","Merino"],["F6F7F7","Black Haze"],["F6FFDC","Spring Sun"],["F7468A","Violet Red"],["F77703","Chilean Fire"],["F77FBE","Persian Pink"],["F7B668","Rajah"],["F7C8DA","Azalea"],["F7DBE6","We Peep"],["F7F2E1","Quarter Spanish White"],["F7F5FA","Whisper"],["F7FAF7","Snow Drift"],["F8B853","Casablanca"],["F8C3DF","Chantilly"],["F8D9E9","Cherub"],["F8DB9D","Marzipan"],["F8DD5C","Energy Yellow"],["F8E4BF","Givry"],["F8F0E8","White Linen"],["F8F4FF","Magnolia"],["F8F6F1","Spring Wood"],["F8F7DC","Coconut Cream"],["F8F7FC","White Lilac"],["F8F8F7","Desert Storm"],["F8F99C","Texas"],["F8FACD","Corn Field"],["F8FDD3","Mimosa"],["F95A61","Carnation"],["F9BF58","Saffron Mango"],["F9E0ED","Carousel Pink"],["F9E4BC","Dairy Cream"],["F9E663","Portica"],["F9EAF3","Amour"],["F9F8E4","Rum Swizzle"],["F9FF8B","Dolly"],["F9FFF6","Sugar Cane"],["FA7814","Ecstasy"],["FA9D5A","Tan Hide"],["FAD3A2","Corvette"],["FADFAD","Peach Yellow"],["FAE600","Turbo"],["FAEAB9","Astra"],["FAECCC","Champagne"],["FAF0E6","Linen"],["FAF3F0","Fantasy"],["FAF7D6","Citrine White"],["FAFAFA","Alabaster"],["FAFDE4","Hint of Yellow"],["FAFFA4","Milan"],["FB607F","Brink Pink"],["FB8989","Geraldine"],["FBA0E3","Lavender Rose"],["FBA129","Sea Buckthorn"],["FBAC13","Sun"],["FBAED2","Lavender Pink"],["FBB2A3","Rose Bud"],["FBBEDA","Cupid"],["FBCCE7","Classic Rose"],["FBCEB1","Apricot Peach"],["FBE7B2","Banana Mania"],["FBE870","Marigold Yellow"],["FBE96C","Festival"],["FBEA8C","Sweet Corn"],["FBEC5D","Candy Corn"],["FBF9F9","Hint of Red"],["FBFFBA","Shalimar"],["FC0FC0","Shocking Pink"],["FC80A5","Tickle Me Pink"],["FC9C1D","Tree Poppy"],["FCC01E","Lightning Yellow"],["FCD667","Goldenrod"],["FCD917","Candlelight"],["FCDA98","Cherokee"],["FCF4D0","Double Pearl Lusta"],["FCF4DC","Pearl Lusta"],["FCF8F7","Vista White"],["FCFBF3","Bianca"],["FCFEDA","Moon Glow"],["FCFFE7","China Ivory"],["FCFFF9","Ceramic"],["FD0E35","Torch Red"],["FD5B78","Wild Watermelon"],["FD7B33","Crusta"],["FD7C07","Sorbus"],["FD9FA2","Sweet Pink"],["FDD5B1","Light Apricot"],["FDD7E4","Pig Pink"],["FDE1DC","Cinderella"],["FDE295","Golden Glow"],["FDE910","Lemon"],["FDF5E6","Old Lace"],["FDF6D3","Half Colonial White"],["FDF7AD","Drover"],["FDFEB8","Pale Prim"],["FDFFD5","Cumulus"],["FE28A2","Persian Rose"],["FE4C40","Sunset Orange"],["FE6F5E","Bittersweet"],["FE9D04","California"],["FEA904","Yellow Sea"],["FEBAAD","Melon"],["FED33C","Bright Sun"],["FED85D","Dandelion"],["FEDB8D","Salomie"],["FEE5AC","Cape Honey"],["FEEBF3","Remy"],["FEEFCE","Oasis"],["FEF0EC","Bridesmaid"],["FEF2C7","Beeswax"],["FEF3D8","Bleach White"],["FEF4CC","Pipi"],["FEF4DB","Half Spanish White"],["FEF4F8","Wisp Pink"],["FEF5F1","Provincial Pink"],["FEF7DE","Half Dutch White"],["FEF8E2","Solitaire"],["FEF8FF","White Pointer"],["FEF9E3","Off Yellow"],["FEFCED","Orange White"],["FF0000","Red"],["FF007F","Rose"],["FF00CC","Purple Pizzazz"],["FF00FF","Magenta / Fuchsia"],["FF2400","Scarlet"],["FF3399","Wild Strawberry"],["FF33CC","Razzle Dazzle Rose"],["FF355E","Radical Red"],["FF3F34","Red Orange"],["FF4040","Coral Red"],["FF4D00","Vermilion"],["FF4F00","International Orange"],["FF6037","Outrageous Orange"],["FF6600","Blaze Orange"],["FF66FF","Pink Flamingo"],["FF681F","Orange"],["FF69B4","Hot Pink"],["FF6B53","Persimmon"],["FF6FFF","Blush Pink"],["FF7034","Burning Orange"],["FF7518","Pumpkin"],["FF7D07","Flamenco"],["FF7F00","Flush Orange"],["FF7F50","Coral"],["FF8C69","Salmon"],["FF9000","Pizazz"],["FF910F","West Side"],["FF91A4","Pink Salmon"],["FF9933","Neon Carrot"],["FF9966","Atomic Tangerine"],["FF9980","Vivid Tangerine"],["FF9E2C","Sunshade"],["FFA000","Orange Peel"],["FFA194","Mona Lisa"],["FFA500","Web Orange"],["FFA6C9","Carnation Pink"],["FFAB81","Hit Pink"],["FFAE42","Yellow Orange"],["FFB0AC","Cornflower Lilac"],["FFB1B3","Sundown"],["FFB31F","My Sin"],["FFB555","Texas Rose"],["FFB7D5","Cotton Candy"],["FFB97B","Macaroni and Cheese"],["FFBA00","Selective Yellow"],["FFBD5F","Koromiko"],["FFBF00","Amber"],["FFC0A8","Wax Flower"],["FFC0CB","Pink"],["FFC3C0","Your Pink"],["FFC901","Supernova"],["FFCBA4","Flesh"],["FFCC33","Sunglow"],["FFCC5C","Golden Tainoi"],["FFCC99","Peach Orange"],["FFCD8C","Chardonnay"],["FFD1DC","Pastel Pink"],["FFD2B7","Romantic"],["FFD38C","Grandis"],["FFD700","Gold"],["FFD800","School bus Yellow"],["FFD8D9","Cosmos"],["FFDB58","Mustard"],["FFDCD6","Peach Schnapps"],["FFDDAF","Caramel"],["FFDDCD","Tuft Bush"],["FFDDCF","Watusi"],["FFDDF4","Pink Lace"],["FFDEAD","Navajo White"],["FFDEB3","Frangipani"],["FFE1DF","Pippin"],["FFE1F2","Pale Rose"],["FFE2C5","Negroni"],["FFE5A0","Cream Brulee"],["FFE5B4","Peach"],["FFE6C7","Tequila"],["FFE772","Kournikova"],["FFEAC8","Sandy Beach"],["FFEAD4","Karry"],["FFEC13","Broom"],["FFEDBC","Colonial White"],["FFEED8","Derby"],["FFEFA1","Vis Vis"],["FFEFC1","Egg White"],["FFEFD5","Papaya Whip"],["FFEFEC","Fair Pink"],["FFF0DB","Peach Cream"],["FFF0F5","Lavender blush"],["FFF14F","Gorse"],["FFF1B5","Buttermilk"],["FFF1D8","Pink Lady"],["FFF1EE","Forget Me Not"],["FFF1F9","Tutu"],["FFF39D","Picasso"],["FFF3F1","Chardon"],["FFF46E","Paris Daisy"],["FFF4CE","Barley White"],["FFF4DD","Egg Sour"],["FFF4E0","Sazerac"],["FFF4E8","Serenade"],["FFF4F3","Chablis"],["FFF5EE","Seashell Peach"],["FFF5F3","Sauvignon"],["FFF6D4","Milk Punch"],["FFF6DF","Varden"],["FFF6F5","Rose White"],["FFF8D1","Baja White"],["FFF9E2","Gin Fizz"],["FFF9E6","Early Dawn"],["FFFACD","Lemon Chiffon"],["FFFAF4","Bridal Heath"],["FFFBDC","Scotch Mist"],["FFFBF9","Soapstone"],["FFFC99","Witch Haze"],["FFFCEA","Buttery White"],["FFFCEE","Island Spice"],["FFFDD0","Cream"],["FFFDE6","Chilean Heath"],["FFFDE8","Travertine"],["FFFDF3","Orchid White"],["FFFDF4","Quarter Pearl Lusta"],["FFFEE1","Half and Half"],["FFFEEC","Apricot White"],["FFFEF0","Rice Cake"],["FFFEF6","Black White"],["FFFEFD","Romance"],["FFFF00","Yellow"],["FFFF66","Laser Lemon"],["FFFF99","Pale Canary"],["FFFFB4","Portafino"],["FFFFF0","Ivory"],["FFFFFF","White"]],this.rgb=function(l){return[parseInt("0x"+l.substring(1,3)),parseInt("0x"+l.substring(3,5)),parseInt("0x"+l.substring(5,7))]};for(var g=0;g7)return["#000000","Invalid Color: "+g,!1];g=g.toUpperCase(),g.length%3==0&&(g="#"+g),g.length==4&&(g="#"+g.substr(1,1)+g.substr(1,1)+g.substr(2,1)+g.substr(2,1)+g.substr(3,1)+g.substr(3,1));for(var i=this.rgb(g),I=i[0],n=i[1],r=i[2],C=this.hsl(g),o=C[0],a=C[1],s=C[2],A=0,l=0,c=0,u=-1,d=-1,h=0;hc)&&(d=c,u=h)}return u<0?["#000000","Invalid Color: "+g,!1]:["#"+this.names[u][0],this.names[u][1],!1]},e.prototype.hsl=function(g){var i=[parseInt("0x"+g.substring(1,3))/255,parseInt("0x"+g.substring(3,5))/255,parseInt("0x"+g.substring(5,7))/255],I=i[0],n=i[1],r=i[2],C=Math.min(I,Math.min(n,r)),o=Math.max(I,Math.max(n,r)),a=o-C,s=(C+o)/2,A=0;s>0&&s<1&&(A=a/(s<.5?2*s:2-2*s));var l=0;return a>0&&(o==I&&o!=n&&(l+=(n-r)/a),o==n&&o!=r&&(l+=2+(r-I)/a),o==r&&o!=I&&(l+=4+(I-n)/a),l/=6),[l*255,A*255,s*255]},e}();function org(e){arg(e),lrg(e)}function arg(e){e.composition.nTracks==1?(e.tracks[0].position.description="There is only one view.",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?Arg(e):srg(e)}function Arg(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=g,e.tracks[1].position.description=i,e.composition.description=I}function srg(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(r=>Object.keys(e.composition.counter.matrix[r]).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 r=[],C=[];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) "+to(C.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 r=0;r9?i=i.concat(" Row number "+r+" has "+e.composition.counter.matrix[r].length+" track(s) next to each other."):i=i.concat(" The "+g[r]+" row has "+e.composition.counter.matrix[r].length+" track(s) next to each other.")}e.composition.description=i;for(const I in e.tracks){let n="";const r=e.tracks[I].position.details,C=e.composition.counter;e.composition.counter.totalRows>1&&(r.rowNumber===0?n=n.concat("top row"):r.rowNumber===C.totalRows-1?n=n.concat("bottom row"):r.rowNumber<10?n=n.concat(g[r.rowNumber]+" row"):n=n.concat("row "+r.rowNumber+1)),e.composition.counter.totalCols>1&&Object.keys(C.matrix[r.colNumber]).length>1&&(n.length>1&&(n=n.concat(", ")),r.colNumber===0?n=n.concat("left"):r.colNumber===Object.keys(C.matrix[r.rowNumber]).length-1?n=n.concat("right"):r.colNumber===2&&Object.keys(C.matrix[r.rowNumber]).length===2?n=n.concat("middle"):n=n.concat(g[r.colNumber]+" from left")),e.tracks[I].position.description=n}}function lrg(e){for(const g in e.tracks){const i=e.tracks[g];if(i.alttype==="single"){let I="";I=I.concat(lp(i.charttype)),i.title&&(I=I.concat(` Chart is titled '${i.title}'.`));const n=Dx(i);I=I.concat(" "+n.desc),i.appearance.description=I,i.appearance.details.encodingsDescList=n.descList}else if(i.alttype==="ov-mark"){let I="";I=I.concat(lp(to(i.charttype))),i.title&&(I=I.concat(` Chart is titled '${i.title}'.`));const n=Dx(i);I=I.concat(" "+n.desc),i.appearance.description=I,i.appearance.details.encodingsDescList=n.descList}else if(i.alttype==="ov-data"){let I="";const n=i.tracks.map(r=>r.charttype);I=I.concat(lp(to(n))),i.title&&(I=I.concat(` Chart is titled '${i.title}'.`)),I=I.concat(" This is an overlaid track with multiple data sources. See individual tracks for more information."),i.appearance.description=I;for(let r=0;rd!==void 0).map(d=>kv.get(d)).filter(d=>d!==void 0)),n.push(xx(I,e.appearance.details.encodings));for(let d=0;dd.descGenomic).filter(d=>d!=="").join(" "),C=n.map(d=>d.descQuantitative).filter(d=>d!=="").join(" "),o=n.map(d=>d.descNominal).filter(d=>d!=="").join(" "),a=n.map(d=>d.descValue).filter(d=>d!=="").join(" ");let s=[r,C,o,a].join(" "),A=n.map(d=>d.descList),l=A[0].concat(...A.slice(1)),c=l.map(d=>d[0]);const u=c.filter((d,h)=>c.indexOf(d)!==h);for(const d of u){let h=l.filter(m=>m[0]===d).map(m=>m[1]).join(" ");l=l.filter(m=>m[0]!==d),l.push([d,h])}return{desc:s,descList:l}}}function xx(e,g){let i="",I="",n="",r="";const C=[],o=g.encodingDeepGenomic.map(A=>A.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."),C.push(["x","The x-axis show genomic intervals."]),C.push(["y","The y-axis show genomic intervals."])):o.includes("xe")?(i=i.concat(" The genome on the x-axis displays genomic intervals."),C.push(["x","The x-axis show genomic intervals."]),C.push(["y","The y-axis shows the genome."])):o.includes("ye")?(i=i.concat(" The genome on the y-axis displays genomic intervals."),C.push(["x","The x-axis shows the genome."]),C.push(["y","The y-axis show genomic intervals."])):(C.push(["x","The x-axis shows the genome."]),C.push(["y","The y-axis shows the genome."]));else{if(o.includes("x")){let A="";o.includes("xe")?(A="in intervals ",C.push(["x","The x-axis show genomic intervals."])):C.push(["x","The x-axis shows the genome."]),i=i.concat(`The genome is shown ${A}on the x-axis.`)}if(o.includes("y")){let A="";o.includes("ye")?(A="in intervals ",C.push(["y","The y-axis show genomic intervals."])):C.push(["y","The y-axis shows the genome."]),i=i.concat(`The genome is shown ${A}on the y-axis.`)}}const a=g.encodingDeepQuantitative.map(A=>A.name);if(a.length>1){I=I.concat(`The expression values are shown with ${e} on the ${to(a)} + '-axes.`);for(const A of a)C.push([A,`The ${A} of the ${e} shows the expression values.`])}else a.length===1&&(a.includes("y")?(I=I.concat(`The expression is shown on the y-axis with ${e}.`),C.push(["y",`The y-axis shows the expression with ${e}.`])):a.includes("color")?(I=I.concat("The height of the expression values is shown with color."),C.push(["color",`The color of the ${e} shows the expression values.`])):(I=I.concat(`The height of the expression values is shown with the ${a[0]} + '-axis.`),C.push([LA.get(a[0]),`The ${LA.get(a[0])} of the ${e} shows the expression values.`])));let s=g.encodingDeepNominal.map(A=>A.name);if(s=s.filter(A=>A!=="text"),s.length>1)if(s.includes("row")){n=n.concat("The chart is stratified by rows for the categories.");const A=s.filter(l=>l!=="row").map(l=>LA.get(l));n=n.concat(` The categories are also shown with the ${to(A)} of the ${e}.`),C.push(["row","The chart is stratified by rows for the categories."]);for(const l of A)C.push([LA.get(l),`The ${l} of the ${e} show the different categories.`])}else{const A=s.map(l=>LA.get(l));n=n.concat(`The categories are shown with the ${to(A)} of the ${e}.`);for(const l of s)C.push([LA.get(l),`The ${l} of the ${e} show the different categories.`])}else s.length==1&&(s.includes("row")?(n=n.concat("The chart is stratified by rows for the categories."),C.push(["row","The chart is stratified by rows for the categories."])):(n=n.concat(`The ${LA.get(s[0])} of the ${e} indicates the different categories.`),C.push([LA.get(s[0]),`The ${LA.get(s[0])} of the ${e} show the different categories.`])));for(let A=0;AKv(n,i)))}.`):I=I.concat(` The ${g} value is shown at ${e.length} different genomic positions, the first being ${Kv(e[0],i)}.`),I}function p_(e,g){const i=Lu(e,g);return[jng(i.chromosome),i.position]}function Kv(e,g){const i=p_(e,g);return i[0]==="unknown"?`absolute position ${i[1]} (on the unmapped part of the genome)`:`chromosome ${i[0]} position ${i[1]}`}function oHe(e,g,i){const I=p_(e,i),n=p_(g,i);return I[0]==="unknown"&&n[0]=="unknown"?` The genomic range is shown from from absolute position ${I[1]} to ${n[1]} on an unmapped part of the genome.`:n[0]==="unknown"?(I[0]==="chr1"||I[0]===1)&&I[1]===0?" The full genome is shown.":I[0]==="chrX"||I[0]==="X"?` The genomic range shown is chromomosome X (from position ${I[1]}), Y and an unmapped part of the genome at the end.`:I[0]==="chrY"||I[0]==="Y"?` The genomic range shown is chromomosome Y (from position ${I[1]}) and an unmapped part of the genome at the end.`:` The genomic range is shown from chromosome ${I[0]} to chromosome 22 and the X and Y chromosomes, as well as an unmapped part of the genome at the end.`:I===n?` The genomic range is shown from position ${I[1]} to position ${n[1]} on chromosome ${I[0]}.`:` The genomic range is shown from chromosome ${I[0]} position ${I[1]} to chromosome ${n[0]} position ${n[1]}.`}function b_(e){if((e.alttype==="single"||e.alttype==="ov-mark")&&mce(e),e.alttype==="ov-data")for(let g=0;g[C,$ng(I,C)]).map(C=>{const o=C[1];let a=C[0];return a=a.toLowerCase(),o==1?`a ${a}`:(a.includes("chart")?a=a.replace("chart","charts"):a=`${a}s`,`${o} different ${a}`)});i=i.concat(`Figure with ${e.composition.nTracks} individual charts. Briefly, these are ${to(r).toLowerCase()}.`),e.alt=`Gosling visualization with ${e.composition.nTracks} individual charts.`,e.longDescription=i}}function urg(e){if(Object.keys(e.tracks).length===1&&cp(e.tracks[0]),Object.keys(e.tracks).length===2)cp(e.tracks[0]),cp(e.tracks[1]);else for(const g in Object.keys(e.tracks))cp(e.tracks[g])}function cp(e,g){let i="",I="";e.alttype==="single"||e.alttype==="ov-mark"?i=I.concat(` ${e.appearance.description} ${e.data.description}`):i=I.concat(" Overlaid track with different data sources. See individual tracks for details."),e.description=i}function drg(e){org(e),r8(e)}function hrg(e){crg(e),r8(e)}function fce(e,g,i){const I={id:e,flatTileData:g};if(i){if(i.genomicField!==void 0){const n=i.genomicField;try{const r=g.map(C=>C[n]).filter(C=>!isNaN(C));I.genomicMin=Math.min(...r),I.genomicMax=Math.max(...r)}catch(r){console.log(r)}}if(i.valueField!==void 0){const n=i.valueField;try{const r=g.map(C=>C[n]).filter(C=>!isNaN(C));I.valueMin=Math.min(...r),I.valueMax=Math.max(...r)}catch(r){console.log(r)}}if(i.genomicField!==void 0&&i.valueField!==void 0){const n=i.genomicField,r=i.valueField;try{I.valueMinGenomic=g.filter(C=>C[r]==I.valueMin).map(C=>C[n]),I.valueMaxGenomic=g.filter(C=>C[r]==I.valueMax).map(C=>C[n])}catch(C){console.log(C)}}if(i.categoryField!==void 0){const n=i.categoryField,r=g.map(s=>s[n]),C=[...new Set(r)];I.categories=C;const o=i.genomicField,a=i.valueField;if(o&&a)try{const s=g.map(u=>u[n]),A=[...new Set(s)],l={},c=[];for(const u of A){const d=g.filter(y=>y[n]===u),h=d.map(y=>y[a]).filter(y=>!isNaN(y)),m=Math.min(...h),f=Math.max(...h),b=d.filter(y=>y[a]==m).map(y=>y[o]),p=d.filter(y=>y[a]==f).map(y=>y[o]);l[u]=[m,b,f,p],f===I.valueMax&&c.push(u)}I.categoryMinMaxWG=l,c.length>0&&(I.highestCategory=c)}catch(s){console.log(s)}}return I}else return I}function mrg(e,g,i){e.tracks.length>1;for(let I=0;I{let s=r.current;s!==C&&console.warn(`WARN: A component changed from ${s?"controlled":"uncontrolled"} to ${C?"controlled":"uncontrolled"}.`),r.current=C},[C]);let o=C?e:I,a=U.useCallback((s,...A)=>{let l=(c,...u)=>{i&&(Object.is(o,c)||i(c,...u)),C||(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(C?o:u,...d);return l(h,...A),C?u:h})):(C||n(s),l(s,...A))},[C,o,i]);return[o,a]}const TH={prefix:String(Math.round(Math.random()*1e10)),current:0},AHe=N.createContext(TH),yrg=N.createContext(!1);let Zrg=!!(typeof window<"u"&&window.document&&window.document.createElement),Ex=new WeakMap;function Grg(e=!1){let g=U.useContext(AHe),i=U.useRef(null);if(i.current===null&&!e){var I,n;let r=(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(r){let C=Ex.get(r);C==null?Ex.set(r,{id:g.current,state:r.memoizedState}):r.memoizedState!==C.state&&(g.current=C.id,Ex.delete(r))}i.current=++g.current}return i.current}function vrg(e){let g=U.useContext(AHe);g===TH&&!Zrg&&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=Grg(!!e),I=`react-aria${g.prefix}`;return e||`${I}-${i}`}function Brg(e){let g=N.useId(),[i]=U.useState(Fw()),I=i?"react-aria":`react-aria${TH.prefix}`;return e||`${I}-${g}`}const Srg=typeof N.useId=="function"?Brg:vrg;function wrg(){return!1}function Rrg(){return!0}function Vrg(e){return()=>{}}function Fw(){return typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore(Vrg,wrg,Rrg):U.useContext(yrg)}function sHe(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 oC(e){const g=U.useRef(null);return bI(()=>{g.current=e},[e]),U.useCallback((...i)=>{const I=g.current;return I(...i)},[])}function Xrg(e){let[g,i]=U.useState(e),I=U.useRef(null),n=oC(()=>{let C=I.current.next();if(C.done){I.current=null;return}g===C.value?n():i(C.value)});bI(()=>{I.current&&n()});let r=oC(C=>{I.current=C(g),n()});return[g,r]}let Hrg=!!(typeof window<"u"&&window.document&&window.document.createElement),NH=new Map;function Dh(e){let[g,i]=U.useState(e),I=U.useRef(null),n=Srg(g),r=U.useCallback(C=>{I.current=C},[]);return Hrg&&NH.set(n,r),bI(()=>{let C=n;return()=>{NH.delete(C)}},[n]),U.useEffect(()=>{let C=I.current;C&&(I.current=null,i(C))}),n}function Trg(e,g){if(e===g)return e;let i=NH.get(e);if(i)return i(g),g;let I=NH.get(g);return I?(I(e),e):g}function pce(e=[]){let g=Dh(),[i,I]=Xrg(g),n=U.useCallback(()=>{I(function*(){yield g,yield document.getElementById(g)?g:void 0})},[g,I]);return bI(n,[g,n,...e]),i}function Nrg(...e){return(...g)=>{for(let i of e)typeof i=="function"&&i(...g)}}const rc=e=>{var g;return(g=e==null?void 0:e.ownerDocument)!==null&&g!==void 0?g:document},kH=e=>e&&"window"in e&&e.window===e?e:rc(e).defaultView||window;function GI(...e){let g={...e[0]};for(let i=1;i=65&&n.charCodeAt(2)<=90?g[n]=Nrg(r,C):(n==="className"||n==="UNSAFE_className")&&typeof r=="string"&&typeof C=="string"?g[n]=Wrg(r,C):n==="id"&&r&&C?g.id=Trg(r,C):g[n]=C!==void 0?C:r}}return g}function krg(...e){return e.length===1?e[0]:g=>{for(let i of e)typeof i=="function"?i(g):i!=null&&(i.current=g)}}const Yrg=new Set(["id"]),Krg=new Set(["aria-label","aria-labelledby","aria-describedby","aria-details"]),Frg=new Set(["href","target","rel","download","ping","referrerPolicy"]),Drg=/^(data-.*)$/;function YA(e,g={}){let{labelable:i,isLink:I,propNames:n}=g,r={};for(const C in e)Object.prototype.hasOwnProperty.call(e,C)&&(Yrg.has(C)||i&&Krg.has(C)||I&&Frg.has(C)||n!=null&&n.has(C)||Drg.test(C))&&(r[C]=e[C]);return r}function vs(e){if(xrg())e.focus({preventScroll:!0});else{let g=Erg(e);e.focus(),Mrg(g)}}let A1=null;function xrg(){if(A1==null){A1=!1;try{var e=document.createElement("div");e.focus({get preventScroll(){return A1=!0,!0}})}catch{}}return A1}function Erg(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 C8(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 xh(){return C8(/^Mac/i)}function zrg(){return C8(/^iPhone/i)}function lHe(){return C8(/^iPad/i)||xh()&&navigator.maxTouchPoints>1}function o8(){return zrg()||lHe()}function Prg(){return xh()||o8()}function Jrg(){return tY(/AppleWebKit/i)&&!Org()}function Org(){return tY(/Chrome/i)}function YH(){return tY(/Android/i)}function _rg(){return tY(/Firefox/i)}const Lrg=U.createContext({isNative:!0,open:Qrg});function cHe(){return U.useContext(Lrg)}function Eh(e,g,i=!0){var I,n;let{metaKey:r,ctrlKey:C,altKey:o,shiftKey:a}=g;_rg()&&(!((n=window.event)===null||n===void 0||(I=n.type)===null||I===void 0)&&I.startsWith("key"))&&e.target==="_blank"&&(xh()?r=!0:C=!0);let s=Jrg()&&xh()&&!lHe()?new KeyboardEvent("keydown",{keyIdentifier:"Enter",metaKey:r,ctrlKey:C,altKey:o,shiftKey:a}):new MouseEvent("click",{metaKey:r,ctrlKey:C,altKey:o,shiftKey:a,bubbles:!0,cancelable:!0});Eh.isOpening=i,vs(e),e.dispatchEvent(s),Eh.isOpening=!1}Eh.isOpening=!1;function Urg(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 Qrg(e,g){Urg(e,i=>Eh(i,g))}function jrg(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 Df=new Map,y_=new Set;function bce(){if(typeof window>"u")return;let e=i=>{let I=Df.get(i.target);I||(I=new Set,Df.set(i.target,I),i.target.addEventListener("transitioncancel",g)),I.add(i.propertyName)},g=i=>{let I=Df.get(i.target);if(I&&(I.delete(i.propertyName),I.size===0&&(i.target.removeEventListener("transitioncancel",g),Df.delete(i.target)),Df.size===0)){for(let n of y_)n();y_.clear()}};document.body.addEventListener("transitionrun",e),document.body.addEventListener("transitionend",g)}typeof document<"u"&&(document.readyState!=="loading"?bce():document.addEventListener("DOMContentLoaded",bce));function uHe(e){requestAnimationFrame(()=>{Df.size===0?e():y_.add(e)})}function dHe(){let e=U.useRef(new Map),g=U.useCallback((n,r,C,o)=>{let a=o!=null&&o.once?(...s)=>{e.current.delete(C),C(...s)}:C;e.current.set(C,{type:r,eventTarget:n,fn:a,options:o}),n.addEventListener(r,C,o)},[]),i=U.useCallback((n,r,C,o)=>{var a;let s=((a=e.current.get(C))===null||a===void 0?void 0:a.fn)||C;n.removeEventListener(r,s,o),e.current.delete(C)},[]),I=U.useCallback(()=>{e.current.forEach((n,r)=>{i(n.eventTarget,n.type,r,n.options)})},[i]);return U.useEffect(()=>I,[I]),{addGlobalListener:g,removeGlobalListener:i,removeAllGlobalListeners:I}}function $rg(e,g){let{id:i,"aria-label":I,"aria-labelledby":n}=e;return i=Dh(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 Dw(e){const g=U.useRef();return U.useMemo(()=>({get current(){return g.current},set current(i){g.current=i,typeof e=="function"?e(i):e&&(e.current=i)}}),[e])}function hHe(e,g){const i=U.useRef(!0),I=U.useRef(null);U.useEffect(()=>(i.current=!0,()=>{i.current=!1}),[]),U.useEffect(()=>{i.current?i.current=!1:(!I.current||g.some((n,r)=>!Object.is(n,I[r])))&&e(),I.current=g},g)}function mHe(e,g){bI(()=>{if(e&&e.ref&&g)return e.ref.current=g.current,()=>{e.ref.current=null}})}function _l(e){for(KH(e)&&(e=e.parentElement);e&&!KH(e);)e=e.parentElement;return e||document.scrollingElement||document.documentElement}function KH(e){let g=window.getComputedStyle(e);return/(auto|scroll)/.test(g.overflow+g.overflowX+g.overflowY)}let qrg=0;const Mx=new Map;function gY(e){let[g,i]=U.useState(void 0);return bI(()=>{if(!e)return;let I=Mx.get(e);if(I)i(I.element.id);else{let n=`react-aria-description-${qrg++}`;i(n);let r=document.createElement("div");r.id=n,r.style.display="none",r.textContent=e,document.body.appendChild(r),I={refCount:0,element:r},Mx.set(e,I)}return I.refCount++,()=>{--I.refCount===0&&(I.element.remove(),Mx.delete(e))}},[e]),{"aria-describedby":e?g:void 0}}function eCg(e,g,i,I){let n=oC(i),r=i==null;U.useEffect(()=>{if(r)return;let C=e.current;return C.addEventListener(g,n,I),()=>{C.removeEventListener(g,n,I)}},[e,g,I,r,n])}function fHe(e,g){let i=yce(e,g,"left"),I=yce(e,g,"top"),n=g.offsetWidth,r=g.offsetHeight,C=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<=C?C=i-parseInt(s,10):i+n>c&&(C+=i+n-c),I<=l?o=I-parseInt(a,10):I+r>u&&(o+=I+r-u),e.scrollLeft=C,e.scrollTop=o}function yce(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 Ll(e,g){if(document.contains(e)){let C=document.scrollingElement||document.documentElement;if(window.getComputedStyle(C).overflow==="hidden"){let a=_l(e);for(;e&&a&&e!==C&&a!==C;)fHe(a,e),e=a,a=_l(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,r;g==null||(n=g.containingElement)===null||n===void 0||(I=n.scrollIntoView)===null||I===void 0||I.call(n,{block:"center",inline:"center"}),(r=e.scrollIntoView)===null||r===void 0||r.call(e,{block:"nearest"})}}}}function Z_(e){return e.mozInputSource===0&&e.isTrusted?!0:YH()&&e.pointerType?e.type==="click"&&e.buttons===1:e.detail===0&&!e.pointerType}function tCg(e){return!YH()&&e.width===0&&e.height===0||e.width===1&&e.height===1&&e.pressure===0&&e.detail===0&&e.pointerType==="mouse"}function gCg(e,g,i){let I=U.useRef(g),n=oC(()=>{i&&i(I.current)});U.useEffect(()=>{var r;let C=e==null||(r=e.current)===null||r===void 0?void 0:r.form;return C==null||C.addEventListener("reset",n),()=>{C==null||C.removeEventListener("reset",n)}},[e,n])}function iCg(e,g){return g.get?g.get.call(e):g.value}function pHe(e,g,i){if(!g.has(e))throw new TypeError("attempted to "+i+" private field on non-instance");return g.get(e)}function ICg(e,g){var i=pHe(e,g,"get");return iCg(e,i)}function nCg(e,g){if(g.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")}function rCg(e,g,i){nCg(e,g),g.set(e,i)}function CCg(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 Zce(e,g,i){var I=pHe(e,g,"set");return CCg(e,I,i),i}let up="default",G_="",xW=new WeakMap;function Gce(e){if(o8()){if(up==="default"){const g=rc(e);G_=g.documentElement.style.webkitUserSelect,g.documentElement.style.webkitUserSelect="none"}up="disabled"}else(e instanceof HTMLElement||e instanceof SVGElement)&&(xW.set(e,e.style.userSelect),e.style.userSelect="none")}function s1(e){if(o8()){if(up!=="disabled")return;up="restoring",setTimeout(()=>{uHe(()=>{if(up==="restoring"){const g=rc(e);g.documentElement.style.webkitUserSelect==="none"&&(g.documentElement.style.webkitUserSelect=G_||""),G_="",up="default"}})},300)}else if((e instanceof HTMLElement||e instanceof SVGElement)&&e&&xW.has(e)){let g=xW.get(e);e.style.userSelect==="none"&&g&&(e.style.userSelect=g),e.getAttribute("style")===""&&e.removeAttribute("style"),xW.delete(e)}}const bHe=N.createContext({register:()=>{}});bHe.displayName="PressResponderContext";function oCg(e){let g=U.useContext(bHe);if(g){let{register:i,...I}=g;e=GI(I,e),i()}return mHe(g,e.ref),e}var l1=new WeakMap;class c1{continuePropagation(){Zce(this,l1,!1)}get shouldStopPropagation(){return ICg(this,l1)}constructor(g,i,I){rCg(this,l1,{writable:!0,value:void 0}),Zce(this,l1,!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 vce=Symbol("linkClicked");function a8(e){let{onPress:g,onPressChange:i,onPressStart:I,onPressEnd:n,onPressUp:r,isDisabled:C,isPressed:o,preventFocusOnPress:a,shouldCancelOnPointerExit:s,allowTextSelectionOnPress:A,ref:l,...c}=oCg(e),[u,d]=U.useState(!1),h=U.useRef({isPressed:!1,ignoreEmulatedMouseEvents:!1,ignoreClickAfterPress:!1,didFirePressStart:!1,isTriggeringEvent:!1,activePointerId:null,target:null,isOverTarget:!1,pointerType:null}),{addGlobalListener:m,removeAllGlobalListeners:f}=dHe(),b=oC((v,w)=>{let R=h.current;if(C||R.didFirePressStart)return!1;let S=!0;if(R.isTriggeringEvent=!0,I){let X=new c1("pressstart",w,v);I(X),S=X.shouldStopPropagation}return i&&i(!0),R.isTriggeringEvent=!1,R.didFirePressStart=!0,d(!0),S}),p=oC((v,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 c1("pressend",w,v);n(W),X=W.shouldStopPropagation}if(i&&i(!1),d(!1),g&&R&&!C){let W=new c1("press",w,v);g(W),X&&(X=W.shouldStopPropagation)}return S.isTriggeringEvent=!1,X}),y=oC((v,w)=>{let R=h.current;if(C)return!1;if(r){R.isTriggeringEvent=!0;let S=new c1("pressup",w,v);return r(S),R.isTriggeringEvent=!1,S.shouldStopPropagation}return!0}),Z=oC(v=>{let w=h.current;w.isPressed&&w.target&&(w.isOverTarget&&w.pointerType!=null&&p(UA(w.target,v),w.pointerType,!1),w.isPressed=!1,w.isOverTarget=!1,w.activePointerId=null,w.pointerType=null,f(),A||s1(w.target))}),B=oC(v=>{s&&Z(v)}),G=U.useMemo(()=>{let v=h.current,w={onKeyDown(S){if(zx(S.nativeEvent,S.currentTarget)&&S.currentTarget.contains(S.target)){var X;Sce(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(rc(S.currentTarget),"keyup",R,!1)),W&&S.stopPropagation(),S.metaKey&&xh()&&((X=v.metaKeyEvents)===null||X===void 0||X.set(S.key,S.nativeEvent))}else S.key==="Meta"&&(v.metaKeyEvents=new Map)},onKeyUp(S){zx(S.nativeEvent,S.currentTarget)&&!S.repeat&&S.currentTarget.contains(S.target)&&v.target&&y(UA(v.target,S),"keyboard")},onClick(S){if(!(S&&!S.currentTarget.contains(S.target))&&S&&S.button===0&&!v.isTriggeringEvent&&!Eh.isOpening){let X=!0;if(C&&S.preventDefault(),!v.ignoreClickAfterPress&&!v.ignoreEmulatedMouseEvents&&!v.isPressed&&(v.pointerType==="virtual"||Z_(S.nativeEvent))){!C&&!a&&vs(S.currentTarget);let W=b(S,"virtual"),V=y(S,"virtual"),H=p(S,"virtual");X=W&&V&&H}v.ignoreEmulatedMouseEvents=!1,v.ignoreClickAfterPress=!1,X&&S.stopPropagation()}}},R=S=>{var X;if(v.isPressed&&v.target&&zx(S,v.target)){var W;Sce(S.target,S.key)&&S.preventDefault();let H=S.target,Y=p(UA(v.target,S),"keyboard",v.target.contains(H));f(),Y&&S.stopPropagation(),S.key!=="Enter"&&A8(v.target)&&v.target.contains(H)&&!S[vce]&&(S[vce]=!0,Eh(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 V;let H=v.metaKeyEvents;v.metaKeyEvents=void 0;for(let Y of H.values())(V=v.target)===null||V===void 0||V.dispatchEvent(new KeyboardEvent("keyup",Y))}};if(typeof PointerEvent<"u"){w.onPointerDown=V=>{if(V.button!==0||!V.currentTarget.contains(V.target))return;if(tCg(V.nativeEvent)){v.pointerType="virtual";return}Px(V.currentTarget)&&V.preventDefault(),v.pointerType=V.pointerType;let H=!0;v.isPressed||(v.isPressed=!0,v.isOverTarget=!0,v.activePointerId=V.pointerId,v.target=V.currentTarget,!C&&!a&&vs(V.currentTarget),A||Gce(v.target),H=b(V,v.pointerType),m(rc(V.currentTarget),"pointermove",S,!1),m(rc(V.currentTarget),"pointerup",X,!1),m(rc(V.currentTarget),"pointercancel",W,!1)),H&&V.stopPropagation()},w.onMouseDown=V=>{V.currentTarget.contains(V.target)&&V.button===0&&(Px(V.currentTarget)&&V.preventDefault(),V.stopPropagation())},w.onPointerUp=V=>{!V.currentTarget.contains(V.target)||v.pointerType==="virtual"||V.button===0&&of(V,V.currentTarget)&&y(V,v.pointerType||V.pointerType)};let S=V=>{V.pointerId===v.activePointerId&&(v.target&&of(V,v.target)?!v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!0,b(UA(v.target,V),v.pointerType)):v.target&&v.isOverTarget&&v.pointerType!=null&&(v.isOverTarget=!1,p(UA(v.target,V),v.pointerType,!1),B(V)))},X=V=>{V.pointerId===v.activePointerId&&v.isPressed&&V.button===0&&v.target&&(of(V,v.target)&&v.pointerType!=null?p(UA(v.target,V),v.pointerType):v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,V),v.pointerType,!1),v.isPressed=!1,v.isOverTarget=!1,v.activePointerId=null,v.pointerType=null,f(),A||s1(v.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(Px(W.currentTarget)&&W.preventDefault(),v.ignoreEmulatedMouseEvents){W.stopPropagation();return}v.isPressed=!0,v.isOverTarget=!0,v.target=W.currentTarget,v.pointerType=Z_(W.nativeEvent)?"virtual":"mouse",!C&&!a&&vs(W.currentTarget),b(W,v.pointerType)&&W.stopPropagation(),m(rc(W.currentTarget),"mouseup",S,!1)},w.onMouseEnter=W=>{if(!W.currentTarget.contains(W.target))return;let V=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!0,V=b(W,v.pointerType)),V&&W.stopPropagation()},w.onMouseLeave=W=>{if(!W.currentTarget.contains(W.target))return;let V=!0;v.isPressed&&!v.ignoreEmulatedMouseEvents&&v.pointerType!=null&&(v.isOverTarget=!1,V=p(W,v.pointerType,!1),B(W)),V&&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&&of(W,v.target)&&v.pointerType!=null?p(UA(v.target,W),v.pointerType):v.target&&v.isOverTarget&&v.pointerType!=null&&p(UA(v.target,W),v.pointerType,!1),v.isOverTarget=!1}};w.onTouchStart=W=>{if(!W.currentTarget.contains(W.target))return;let V=aCg(W.nativeEvent);if(!V)return;v.activePointerId=V.identifier,v.ignoreEmulatedMouseEvents=!0,v.isOverTarget=!0,v.isPressed=!0,v.target=W.currentTarget,v.pointerType="touch",!C&&!a&&vs(W.currentTarget),A||Gce(v.target),b(W,v.pointerType)&&W.stopPropagation(),m(kH(W.currentTarget),"scroll",X,!0)},w.onTouchMove=W=>{if(!W.currentTarget.contains(W.target))return;if(!v.isPressed){W.stopPropagation();return}let V=Bce(W.nativeEvent,v.activePointerId),H=!0;V&&of(V,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 V=Bce(W.nativeEvent,v.activePointerId),H=!0;V&&of(V,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&&s1(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,C,a,f,A,Z,B,p,b,y]);return U.useEffect(()=>()=>{var v;A||s1((v=h.current.target)!==null&&v!==void 0?v:void 0)},[A]),{isPressed:o||u,pressProps:GI(c,G)}}function A8(e){return e.tagName==="A"&&e.hasAttribute("href")}function zx(e,g){const{key:i,code:I}=e,n=g,r=n.getAttribute("role");return(i==="Enter"||i===" "||i==="Spacebar"||I==="Space")&&!(n instanceof kH(n).HTMLInputElement&&!yHe(n,i)||n instanceof kH(n).HTMLTextAreaElement||n.isContentEditable)&&!((r==="link"||!r&&A8(n))&&i!=="Enter")}function aCg(e){const{targetTouches:g}=e;return g.length>0?g[0]:null}function Bce(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 of(e,g){let i=g.getBoundingClientRect(),I=ACg(e);return sCg(i,I)}function Px(e){return!(e instanceof HTMLElement)||!e.hasAttribute("draggable")}function Sce(e,g){return e instanceof HTMLInputElement?!yHe(e,g):e instanceof HTMLButtonElement?e.type!=="submit"&&e.type!=="reset":!A8(e)}const lCg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function yHe(e,g){return e.type==="checkbox"||e.type==="radio"?g===" ":lCg.has(e.type)}class cCg{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 ZHe(e){let g=U.useRef({isFocused:!1,observer:null});bI(()=>{const I=g.current;return()=>{I.observer&&(I.observer.disconnect(),I.observer=null)}},[]);let i=oC(I=>{e==null||e(I)});return U.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,r=C=>{g.current.isFocused=!1,n.disabled&&i(new cCg("blur",C)),g.current.observer&&(g.current.observer.disconnect(),g.current.observer=null)};n.addEventListener("focusout",r,{once:!0}),g.current.observer=new MutationObserver(()=>{if(g.current.isFocused&&n.disabled){var C;(C=g.current.observer)===null||C===void 0||C.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 GHe(e){let{isDisabled:g,onFocus:i,onBlur:I,onFocusChange:n}=e;const r=U.useCallback(a=>{if(a.target===a.currentTarget)return I&&I(a),n&&n(!1),!0},[I,n]),C=ZHe(r),o=U.useCallback(a=>{a.target===a.currentTarget&&document.activeElement===a.target&&(i&&i(a),n&&n(!0),C(a))},[n,i,C]);return{focusProps:{onFocus:!g&&(i||n||I)?o:void 0,onBlur:!g&&(I||n)?r:void 0}}}let _s=null,cS=new Set,wce=!1,Mh=!1,v_=!1;const uCg={Tab:!0,Escape:!0};function iY(e,g){for(let i of cS)i(e,g)}function dCg(e){return!(e.metaKey||!xh()&&e.altKey||e.ctrlKey||e.key==="Control"||e.key==="Shift"||e.key==="Meta")}function Rce(e){Mh=!0,dCg(e)&&(_s="keyboard",iY("keyboard",e))}function af(e){_s="pointer",(e.type==="mousedown"||e.type==="pointerdown")&&(Mh=!0,iY("pointer",e))}function hCg(e){Z_(e)&&(Mh=!0,_s="virtual")}function mCg(e){e.target===window||e.target===document||(!Mh&&!v_&&(_s="virtual",iY("virtual",e)),Mh=!1,v_=!1)}function fCg(){Mh=!1,v_=!0}function FH(){if(typeof window>"u"||wce)return;let e=HTMLElement.prototype.focus;HTMLElement.prototype.focus=function(){Mh=!0,e.apply(this,arguments)},document.addEventListener("keydown",Rce,!0),document.addEventListener("keyup",Rce,!0),document.addEventListener("click",hCg,!0),window.addEventListener("focus",mCg,!0),window.addEventListener("blur",fCg,!1),typeof PointerEvent<"u"?(document.addEventListener("pointerdown",af,!0),document.addEventListener("pointermove",af,!0),document.addEventListener("pointerup",af,!0)):(document.addEventListener("mousedown",af,!0),document.addEventListener("mousemove",af,!0),document.addEventListener("mouseup",af,!0)),wce=!0}typeof document<"u"&&(document.readyState!=="loading"?FH():document.addEventListener("DOMContentLoaded",FH));function s8(){return _s!=="pointer"}function B_(){return _s}function pCg(e){_s=e,iY(e,null)}function bCg(){FH();let[e,g]=U.useState(_s);return U.useEffect(()=>{let i=()=>{g(_s)};return cS.add(i),()=>{cS.delete(i)}},[]),Fw()?null:e}const yCg=new Set(["checkbox","radio","range","color","file","image","button","submit","reset"]);function ZCg(e,g,i){var I;return e=e||(i==null?void 0:i.target)instanceof HTMLInputElement&&!yCg.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&&!uCg[i.key])}function GCg(e,g,i){FH(),U.useEffect(()=>{let I=(n,r)=>{ZCg(!!(i!=null&&i.isTextInput),n,r)&&e(s8())};return cS.add(I),()=>{cS.delete(I)}},g)}function vHe(e){let{isDisabled:g,onBlurWithin:i,onFocusWithin:I,onFocusWithinChange:n}=e,r=U.useRef({isFocusWithin:!1}),C=U.useCallback(s=>{r.current.isFocusWithin&&!s.currentTarget.contains(s.relatedTarget)&&(r.current.isFocusWithin=!1,i&&i(s),n&&n(!1))},[i,n,r]),o=ZHe(C),a=U.useCallback(s=>{!r.current.isFocusWithin&&document.activeElement===s.target&&(I&&I(s),n&&n(!0),r.current.isFocusWithin=!0,o(s))},[I,n,o]);return g?{focusWithinProps:{onFocus:void 0,onBlur:void 0}}:{focusWithinProps:{onFocus:a,onBlur:C}}}let DH=!1,Jx=0;function S_(){DH=!0,setTimeout(()=>{DH=!1},50)}function Vce(e){e.pointerType==="touch"&&S_()}function vCg(){if(!(typeof document>"u"))return typeof PointerEvent<"u"?document.addEventListener("pointerup",Vce):document.addEventListener("touchend",S_),Jx++,()=>{Jx--,!(Jx>0)&&(typeof PointerEvent<"u"?document.removeEventListener("pointerup",Vce):document.removeEventListener("touchend",S_))}}function l8(e){let{onHoverStart:g,onHoverChange:i,onHoverEnd:I,isDisabled:n}=e,[r,C]=U.useState(!1),o=U.useRef({isHovered:!1,ignoreEmulatedMouseEvents:!1,pointerType:"",target:null}).current;U.useEffect(vCg,[]);let{hoverProps:a,triggerHoverEnd:s}=U.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),C(!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),C(!1)},c={};return typeof PointerEvent<"u"?(c.onPointerEnter=u=>{DH&&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&&!DH&&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 U.useEffect(()=>{n&&s({currentTarget:o.target},o.pointerType)},[n]),{hoverProps:a,isHovered:r}}function Wce(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 BCg(e){return{keyboardProps:e.isDisabled?{}:{onKeyDown:Wce(e.onKeyDown),onKeyUp:Wce(e.onKeyUp)}}}const SCg=500;function wCg(e){let{isDisabled:g,onLongPressStart:i,onLongPressEnd:I,onLongPress:n,threshold:r=SCg,accessibilityDescription:C}=e;const o=U.useRef();let{addGlobalListener:a,removeGlobalListener:s}=dHe(),{pressProps:A}=a8({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},r),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&&!g?C:void 0);return{longPressProps:GI(A,l)}}function tC(e){if(B_()==="virtual"){let g=document.activeElement;uHe(()=>{document.activeElement===g&&document.contains(e)&&vs(e)})}else vs(e)}function RCg(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:r,visibility:C}=n(e);I=r!=="none"&&C!=="hidden"&&C!=="collapse"}return I}function VCg(e,g){return!e.hasAttribute("hidden")&&(e.nodeName==="DETAILS"&&g&&g.nodeName!=="SUMMARY"?e.hasAttribute("open"):!0)}function BHe(e,g){return e.nodeName!=="#comment"&&RCg(e)&&VCg(e,g)&&(!e.parentElement||BHe(e.parentElement,e))}const Xce=N.createContext(null);let mi=null;function WCg(e){let{children:g,contain:i,restoreFocus:I,autoFocus:n}=e,r=U.useRef(null),C=U.useRef(null),o=U.useRef([]),{parentNode:a}=U.useContext(Xce)||{},s=U.useMemo(()=>new R_({scopeRef:o}),[o]);bI(()=>{let c=a||dI.root;if(dI.getTreeNode(c.scopeRef)&&mi&&!xH(mi,c.scopeRef)){let u=dI.getTreeNode(mi);u&&(c=u)}c.addChild(s),dI.addNode(s)},[s,a]),bI(()=>{let c=dI.getTreeNode(o);c&&(c.contain=!!i)},[i]),bI(()=>{var c;let u=(c=r.current)===null||c===void 0?void 0:c.nextSibling,d=[];for(;u&&u!==C.current;)d.push(u),u=u.nextSibling;o.current=d},[g]),YCg(o,I,i),NCg(o,i),FCg(o,I,i),kCg(o,n),U.useEffect(()=>{let c=document.activeElement,u=null;if(Yn(c,o.current)){for(let d of dI.traverse())d.scopeRef&&Yn(c,d.scopeRef.current)&&(u=d);u===dI.getTreeNode(o)&&(mi=u.scopeRef)}},[o]),bI(()=>()=>{var c,u,d;let h=(d=(u=dI.getTreeNode(o))===null||u===void 0||(c=u.parent)===null||c===void 0?void 0:c.scopeRef)!==null&&d!==void 0?d:null;(o===mi||xH(o,mi))&&(!h||dI.getTreeNode(h))&&(mi=h),dI.removeTreeNode(o)},[o]);let A=U.useMemo(()=>XCg(o),[]),l=U.useMemo(()=>({focusManager:A,parentNode:s}),[s,A]);return N.createElement(Xce.Provider,{value:l},N.createElement("span",{"data-focus-scope-start":!0,hidden:!0,ref:r}),g,N.createElement("span",{"data-focus-scope-end":!0,hidden:!0,ref:C}))}function XCg(e){return{focusNext(g={}){let i=e.current,{from:I,tabbable:n,wrap:r,accept:C}=g,o=I||document.activeElement,a=i[0].previousElementSibling,s=bd(i),A=QC(s,{tabbable:n,accept:C},i);A.currentNode=Yn(o,i)?o:a;let l=A.nextNode();return!l&&r&&(A.currentNode=a,l=A.nextNode()),l&&Bs(l,!0),l},focusPrevious(g={}){let i=e.current,{from:I,tabbable:n,wrap:r,accept:C}=g,o=I||document.activeElement,a=i[i.length-1].nextElementSibling,s=bd(i),A=QC(s,{tabbable:n,accept:C},i);A.currentNode=Yn(o,i)?o:a;let l=A.previousNode();return!l&&r&&(A.currentNode=a,l=A.previousNode()),l&&Bs(l,!0),l},focusFirst(g={}){let i=e.current,{tabbable:I,accept:n}=g,r=bd(i),C=QC(r,{tabbable:I,accept:n},i);C.currentNode=i[0].previousElementSibling;let o=C.nextNode();return o&&Bs(o,!0),o},focusLast(g={}){let i=e.current,{tabbable:I,accept:n}=g,r=bd(i),C=QC(r,{tabbable:I,accept:n},i);C.currentNode=i[i.length-1].nextElementSibling;let o=C.previousNode();return o&&Bs(o,!0),o}}}const c8=["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=c8.join(":not([hidden]),")+",[tabindex]:not([disabled]):not([hidden])";c8.push('[tabindex]:not([tabindex="-1"]):not([disabled])');const TCg=c8.join(':not([hidden]):not([tabindex="-1"]),');function bd(e){return e[0].parentElement}function yG(e){let g=dI.getTreeNode(mi);for(;g&&g.scopeRef!==e;){if(g.contain)return!1;g=g.parent}return!0}function NCg(e,g){let i=U.useRef(),I=U.useRef();bI(()=>{let n=e.current;if(!g){I.current&&(cancelAnimationFrame(I.current),I.current=void 0);return}let r=a=>{if(a.key!=="Tab"||a.altKey||a.ctrlKey||a.metaKey||!yG(e))return;let s=document.activeElement,A=e.current;if(!A||!Yn(s,A))return;let l=bd(A),c=QC(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&&Bs(u,!0)},C=a=>{(!mi||xH(mi,e))&&Yn(a.target,e.current)?(mi=e,i.current=a.target):yG(e)&&!w_(a.target,e)?i.current?i.current.focus():mi&&mi.current&&EH(mi.current):yG(e)&&(i.current=a.target)},o=a=>{I.current&&cancelAnimationFrame(I.current),I.current=requestAnimationFrame(()=>{if(document.activeElement&&yG(e)&&!w_(document.activeElement,e))if(mi=e,document.body.contains(a.target)){var s;i.current=a.target,(s=i.current)===null||s===void 0||s.focus()}else mi.current&&EH(mi.current)})};return document.addEventListener("keydown",r,!1),document.addEventListener("focusin",C,!1),n==null||n.forEach(a=>a.addEventListener("focusin",C,!1)),n==null||n.forEach(a=>a.addEventListener("focusout",o,!1)),()=>{document.removeEventListener("keydown",r,!1),document.removeEventListener("focusin",C,!1),n==null||n.forEach(a=>a.removeEventListener("focusin",C,!1)),n==null||n.forEach(a=>a.removeEventListener("focusout",o,!1))}},[e,g]),bI(()=>()=>{I.current&&cancelAnimationFrame(I.current)},[I])}function SHe(e){return w_(e)}function Yn(e,g){return!e||!g?!1:g.some(i=>i.contains(e))}function w_(e,g=null){if(e instanceof Element&&e.closest("[data-react-aria-top-layer]"))return!0;for(let{scopeRef:i}of dI.traverse(dI.getTreeNode(g)))if(i&&Yn(e,i.current))return!0;return!1}function xH(e,g){var i;let I=(i=dI.getTreeNode(g))===null||i===void 0?void 0:i.parent;for(;I;){if(I.scopeRef===e)return!0;I=I.parent}return!1}function Bs(e,g=!1){if(e!=null&&!g)try{tC(e)}catch{}else if(e!=null)try{e.focus()}catch{}}function EH(e,g=!0){let i=e[0].previousElementSibling,I=bd(e),n=QC(I,{tabbable:g},e);n.currentNode=i;let r=n.nextNode();g&&!r&&(I=bd(e),n=QC(I,{tabbable:!1},e),n.currentNode=i,r=n.nextNode()),Bs(r)}function kCg(e,g){const i=N.useRef(g);U.useEffect(()=>{i.current&&(mi=e,!Yn(document.activeElement,mi.current)&&e.current&&EH(e.current)),i.current=!1},[e])}function YCg(e,g,i){bI(()=>{if(g||i)return;let I=e.current,n=r=>{let C=r.target;Yn(C,e.current)?mi=e:SHe(C)||(mi=null)};return document.addEventListener("focusin",n,!1),I==null||I.forEach(r=>r.addEventListener("focusin",n,!1)),()=>{document.removeEventListener("focusin",n,!1),I==null||I.forEach(r=>r.removeEventListener("focusin",n,!1))}},[e,g,i])}function KCg(e){let g=dI.getTreeNode(mi);for(;g&&g.scopeRef!==e;){if(g.nodeToRestore)return!1;g=g.parent}return(g==null?void 0:g.scopeRef)===e}function FCg(e,g,i){const I=U.useRef(typeof document<"u"?document.activeElement:null);bI(()=>{let n=e.current;if(!g||i)return;let r=()=>{(!mi||xH(mi,e))&&Yn(document.activeElement,e.current)&&(mi=e)};return document.addEventListener("focusin",r,!1),n==null||n.forEach(C=>C.addEventListener("focusin",r,!1)),()=>{document.removeEventListener("focusin",r,!1),n==null||n.forEach(C=>C.removeEventListener("focusin",r,!1))}},[e,i]),bI(()=>{if(!g)return;let n=r=>{if(r.key!=="Tab"||r.altKey||r.ctrlKey||r.metaKey||!yG(e))return;let C=document.activeElement;if(!Yn(C,e.current))return;let o=dI.getTreeNode(e);if(!o)return;let a=o.nodeToRestore,s=QC(document.body,{tabbable:!0});s.currentNode=C;let A=r.shiftKey?s.previousNode():s.nextNode();if((!a||!document.body.contains(a)||a===document.body)&&(a=void 0,o.nodeToRestore=void 0),(!A||!Yn(A,e.current))&&a){s.currentNode=a;do A=r.shiftKey?s.previousNode():s.nextNode();while(Yn(A,e.current));r.preventDefault(),r.stopPropagation(),A?Bs(A,!0):SHe(a)?Bs(a,!0):C.blur()}};return i||document.addEventListener("keydown",n,!0),()=>{i||document.removeEventListener("keydown",n,!0)}},[e,g,i]),bI(()=>{if(!g)return;let n=dI.getTreeNode(e);if(n){var r;return n.nodeToRestore=(r=I.current)!==null&&r!==void 0?r:void 0,()=>{let C=dI.getTreeNode(e);if(!C)return;let o=C.nodeToRestore;if(g&&o&&(Yn(document.activeElement,e.current)||document.activeElement===document.body&&KCg(e))){let a=dI.clone();requestAnimationFrame(()=>{if(document.activeElement===document.body){let s=a.getTreeNode(e);for(;s;){if(s.nodeToRestore&&document.body.contains(s.nodeToRestore)){Bs(s.nodeToRestore);return}s=s.parent}for(s=a.getTreeNode(e);s;){if(s.scopeRef&&s.scopeRef.current&&dI.getTreeNode(s.scopeRef)){EH(s.scopeRef.current,!0);return}s=s.parent}}})}}}},[e,g])}function QC(e,g,i){let I=g!=null&&g.tabbable?TCg:HCg,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode(r){var C;return!(g==null||(C=g.from)===null||C===void 0)&&C.contains(r)?NodeFilter.FILTER_REJECT:r.matches(I)&&BHe(r)&&(!i||Yn(r,i))&&(!(g!=null&&g.accept)||g.accept(r))?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});return g!=null&&g.from&&(n.currentNode=g.from),n}class u8{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 r=new R_({scopeRef:g});n.addChild(r),r.parent=n,this.fastMap.set(g,r),I&&(r.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 r of this.traverse())r!==i&&i.nodeToRestore&&r.nodeToRestore&&i.scopeRef&&i.scopeRef.current&&Yn(r.nodeToRestore,i.scopeRef.current)&&(r.nodeToRestore=i.nodeToRestore);let n=i.children;I&&(I.removeChild(i),n.size>0&&n.forEach(r=>I&&I.addChild(r))),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 u8;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 R_({scopeRef:null}),this.fastMap.set(null,this.root)}}class R_{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 dI=new u8;function IY(e={}){let{autoFocus:g=!1,isTextInput:i,within:I}=e,n=U.useRef({isFocused:!1,isFocusVisible:g||s8()}),[r,C]=U.useState(!1),[o,a]=U.useState(()=>n.current.isFocused&&n.current.isFocusVisible),s=U.useCallback(()=>a(n.current.isFocused&&n.current.isFocusVisible),[]),A=U.useCallback(u=>{n.current.isFocused=u,C(u),s()},[s]);GCg(u=>{n.current.isFocusVisible=u,s()},[],{isTextInput:i});let{focusProps:l}=GHe({isDisabled:I,onFocusChange:A}),{focusWithinProps:c}=vHe({isDisabled:!I,onFocusWithinChange:A});return{isFocused:r,isFocusVisible:o,focusProps:I?c:l}}let DCg=N.createContext(null);function xCg(e){let g=U.useContext(DCg)||{};mHe(g,e);let{ref:i,...I}=g;return I}function wHe(e,g){let{focusProps:i}=GHe(e),{keyboardProps:I}=BCg(e),n=GI(i,I),r=xCg(g),C=e.isDisabled?{}:r,o=U.useRef(e.autoFocus);return U.useEffect(()=>{o.current&&g.current&&tC(g.current),o.current=!1},[g]),{focusableProps:GI({...n,tabIndex:e.excludeFromTabOrder&&!e.isDisabled?-1:void 0},C)}}function ECg(e,g){let i=g==null?void 0:g.isDisabled,[I,n]=U.useState(!1);return bI(()=>{if(e!=null&&e.current&&!i){let r=()=>{if(e.current){let o=QC(e.current,{tabbable:!0});n(!!o.nextNode())}};r();let C=new MutationObserver(r);return C.observe(e.current,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["tabIndex","disabled"]}),()=>{C.disconnect()}}}),i?!1:I}class MCg{getStringForLocale(g,i){let I=this.strings[i];I||(I=zCg(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 zCg(e,g,i="en-US"){if(g[e])return g[e];let I=PCg(e);if(g[I])return g[I];for(let n in g)if(n.startsWith(I+"-"))return g[n];return g[i]}function PCg(e){return Intl.Locale?new Intl.Locale(e).language:e.split("-")[0]}const Hce=new Map,Tce=new Map;class JCg{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 r=this.locale+":"+I,C=Hce.get(r);C||(C=new Intl.PluralRules(this.locale,{type:I}),Hce.set(r,C));let o=C.select(g);return n=i[o]||i.other,typeof n=="function"?n():n}number(g){let i=Tce.get(this.locale);return i||(i=new Intl.NumberFormat(this.locale),Tce.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 OCg=new Set(["Arab","Syrc","Samr","Mand","Thaa","Mend","Nkoo","Adlm","Rohg","Hebr"]),_Cg=new Set(["ae","ar","arc","bcc","bqi","ckb","dv","fa","glk","he","ku","mzn","nqo","pnb","ps","sd","ug","ur","yi"]);function LCg(e){if(Intl.Locale){let i=new Intl.Locale(e).maximize().script;return i?OCg.has(i):!1}let g=e.split("-")[0];return _Cg.has(g)}function RHe(){let e=typeof navigator<"u"&&(navigator.language||navigator.userLanguage)||"en-US";try{Intl.DateTimeFormat.supportedLocalesOf([e])}catch{e="en-US"}return{locale:e,direction:LCg(e)?"rtl":"ltr"}}let V_=RHe(),ZG=new Set;function Nce(){V_=RHe();for(let e of ZG)e(V_)}function UCg(){let e=Fw(),[g,i]=U.useState(V_);return U.useEffect(()=>(ZG.size===0&&window.addEventListener("languagechange",Nce),ZG.add(i),()=>{ZG.delete(i),ZG.size===0&&window.removeEventListener("languagechange",Nce)}),[]),e?{locale:"en-US",direction:"ltr"}:g}const QCg=N.createContext(null);function Gm(){let e=UCg();return U.useContext(QCg)||e}const kce=new WeakMap;function jCg(e){let g=kce.get(e);return g||(g=new MCg(e),kce.set(e,g)),g}function my(e){let{locale:g}=Gm(),i=U.useMemo(()=>jCg(e),[e]);return U.useMemo(()=>new JCg(g,i),[g,i])}let Ox=new Map;function VHe(e){let{locale:g}=Gm(),i=g+(e?Object.entries(e).sort((n,r)=>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 qCg(e,g,i){let{validationBehavior:I,focus:n}=e;bI(()=>{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(tog(i.current))}});let r=oC(()=>{g.resetValidation()}),C=oC(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&&gog(A)===i.current){var l;n?n():(l=i.current)===null||l===void 0||l.focus(),pCg("keyboard")}a.preventDefault()}),o=oC(()=>{g.commitValidation()});U.useEffect(()=>{let a=i==null?void 0:i.current;if(!a)return;let s=a.form;return a.addEventListener("invalid",C),a.addEventListener("change",o),s==null||s.addEventListener("reset",r),()=>{a.removeEventListener("invalid",C),a.removeEventListener("change",o),s==null||s.removeEventListener("reset",r)}},[i,C,o,r,I])}function eog(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 tog(e){return{isInvalid:!e.validity.valid,validationDetails:eog(e),validationErrors:e.validationMessage?[e.validationMessage]:[]}}function gog(e){for(let g=0;gKce(rog(C,n)),[C,n]);r!=null&&r.validationDetails.valid&&(r=null);let A=U.useContext(iog),l=U.useMemo(()=>I?Array.isArray(I)?I.flatMap(R=>W_(A[R])):W_(A[I]):[],[A,I]),[c,u]=U.useState(A),[d,h]=U.useState(!1);A!==c&&(u(A),h(!1));let m=U.useMemo(()=>Kce(d?[]:l),[d,l]),f=U.useRef(vZ),[b,p]=U.useState(vZ),y=U.useRef(vZ),Z=()=>{if(!B)return;G(!1);let R=s||r||f.current;Lx(R,y.current)||(y.current=R,p(R))},[B,G]=U.useState(!1);return U.useEffect(Z),{realtimeValidation:a||m||s||r||vZ,displayValidation:o==="native"?a||m||b:a||m||s||r||b,updateValidation(R){o==="aria"&&!Lx(b,R)?p(R):f.current=R},resetValidation(){let R=vZ;Lx(R,y.current)||(y.current=R,p(R)),o==="native"&&G(!1),h(!0)},commitValidation(){o==="native"&&G(!0),h(!0)}}}function W_(e){return e?Array.isArray(e)?e:[e]:[]}function rog(e,g){if(typeof e=="function"){let i=e(g);if(i&&typeof i!="boolean")return W_(i)}return[]}function Kce(e){return e.length?{isInvalid:!0,validationErrors:e,validationDetails:THe}:null}function Lx(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 Cog(e){let{id:g,label:i,"aria-labelledby":I,"aria-label":n,labelElementType:r="label"}=e;g=Dh(g);let C=Dh(),o={};i?(I=I?`${C} ${I}`:C,o={id:C,htmlFor:r==="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=$rg({id:g,"aria-label":n,"aria-labelledby":I});return{labelProps:o,fieldProps:a}}function oog(e){let{description:g,errorMessage:i,isInvalid:I,validationState:n}=e,{labelProps:r,fieldProps:C}=Cog(e),o=pce([!!g,!!i,I,n]),a=pce([!!g,!!i,I,n]);return C=GI(C,{"aria-describedby":[o,a,e["aria-describedby"]].filter(Boolean).join(" ")||void 0}),{labelProps:r,fieldProps:C,descriptionProps:{id:o},errorMessageProps:{id:a}}}const Fce={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 d8(e={}){let{style:g,isFocusable:i}=e,[I,n]=U.useState(!1),{focusWithinProps:r}=vHe({isDisabled:!i,onFocusWithinChange:o=>n(o)}),C=U.useMemo(()=>I?g:g?{...Fce,...g}:Fce,[I]);return{visuallyHiddenProps:{...r,style:C}}}function X_(e){return Prg()?e.altKey:e.ctrlKey}function xf(e){return xh()?e.metaKey:e.ctrlKey}const aog=1e3;function Aog(e){let{keyboardDelegate:g,selectionManager:i,onTypeSelect:I}=e,n=U.useRef({search:"",timeout:null}).current,r=C=>{let o=sog(C.key);if(!o||C.ctrlKey||C.metaKey||!C.currentTarget.contains(C.target))return;o===" "&&n.search.trim().length>0&&(C.preventDefault(),"continuePropagation"in C||C.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=""},aog)};return{typeSelectProps:{onKeyDownCapture:g.getKeyForSearch?r:null}}}function sog(e){return e.length===1||!/^[A-Z]/i.test(e)?e:""}function log(e){let{selectionManager:g,keyboardDelegate:i,ref:I,autoFocus:n=!1,shouldFocusWrap:r=!1,disallowEmptySelection:C=!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}=Gm(),m=cHe(),f=R=>{if(R.altKey&&R.key==="Tab"&&R.preventDefault(),!I.current.contains(R.target))return;const S=(P,ge)=>{if(P!=null){if(g.isLink(P)&&d==="selection"&&a&&!X_(R)){Aa.flushSync(()=>{g.setFocusedKey(P,ge)});let q=u.current.querySelector(`[data-key="${P}"]`);m.open(q,R);return}if(g.setFocusedKey(P,ge),g.isLink(P)&&d==="override")return;R.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&!X_(R)&&g.replaceSelection(P)}};switch(R.key){case"ArrowDown":if(i.getKeyBelow){var X,W;R.preventDefault();let P=g.focusedKey!=null?i.getKeyBelow(g.focusedKey):(X=i.getFirstKey)===null||X===void 0?void 0:X.call(i);P==null&&r&&(P=(W=i.getFirstKey)===null||W===void 0?void 0:W.call(i,g.focusedKey)),S(P)}break;case"ArrowUp":if(i.getKeyAbove){var V,H;R.preventDefault();let P=g.focusedKey!=null?i.getKeyAbove(g.focusedKey):(V=i.getLastKey)===null||V===void 0?void 0:V.call(i);P==null&&r&&(P=(H=i.getLastKey)===null||H===void 0?void 0:H.call(i,g.focusedKey)),S(P)}break;case"ArrowLeft":if(i.getKeyLeftOf){var Y,K;R.preventDefault();let P=i.getKeyLeftOf(g.focusedKey);P==null&&r&&(P=h==="rtl"?(Y=i.getFirstKey)===null||Y===void 0?void 0:Y.call(i,g.focusedKey):(K=i.getLastKey)===null||K===void 0?void 0:K.call(i,g.focusedKey)),S(P,h==="rtl"?"first":"last")}break;case"ArrowRight":if(i.getKeyRightOf){var x,J;R.preventDefault();let P=i.getKeyRightOf(g.focusedKey);P==null&&r&&(P=h==="rtl"?(x=i.getLastKey)===null||x===void 0?void 0:x.call(i,g.focusedKey):(J=i.getFirstKey)===null||J===void 0?void 0:J.call(i,g.focusedKey)),S(P,h==="rtl"?"last":"first")}break;case"Home":if(i.getFirstKey){R.preventDefault();let P=i.getFirstKey(g.focusedKey,xf(R));g.setFocusedKey(P),xf(R)&&R.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"End":if(i.getLastKey){R.preventDefault();let P=i.getLastKey(g.focusedKey,xf(R));g.setFocusedKey(P),xf(R)&&R.shiftKey&&g.selectionMode==="multiple"?g.extendSelection(P):a&&g.replaceSelection(P)}break;case"PageDown":if(i.getKeyPageBelow){R.preventDefault();let P=i.getKeyPageBelow(g.focusedKey);S(P)}break;case"PageUp":if(i.getKeyPageAbove){R.preventDefault();let P=i.getKeyPageAbove(g.focusedKey);S(P)}break;case"a":xf(R)&&g.selectionMode==="multiple"&&o!==!0&&(R.preventDefault(),g.selectAll());break;case"Escape":R.preventDefault(),C||g.clearSelection();break;case"Tab":if(!l){if(R.shiftKey)I.current.focus();else{let P=QC(I.current,{tabbable:!0}),ge,q;do q=P.lastChild(),q&&(ge=q);while(q);ge&&!ge.contains(document.activeElement)&&vs(ge)}break}}},b=U.useRef({top:0,left:0});eCg(u,"scroll",c?null:()=>{b.current={top:u.current.scrollTop,left:u.current.scrollLeft}});let p=R=>{if(g.isFocused){R.currentTarget.contains(R.target)||g.setFocused(!1);return}if(R.currentTarget.contains(R.target)){if(g.setFocused(!0),g.focusedKey==null){let W=H=>{H!=null&&(g.setFocusedKey(H),a&&g.replaceSelection(H))},V=R.relatedTarget;var S,X;V&&R.currentTarget.compareDocumentPosition(V)&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)||vs(W),B_()==="keyboard"&&Ll(W,{containingElement:I.current}))}}},y=R=>{R.currentTarget.contains(R.relatedTarget)||g.setFocused(!1)};const Z=U.useRef(n);U.useEffect(()=>{if(Z.current){let R=null;n==="first"&&(R=i.getFirstKey()),n==="last"&&(R=i.getLastKey());let S=g.selectedKeys;S.size&&(R=S.values().next().value),g.setFocused(!0),g.setFocusedKey(R),R==null&&!A&&tC(I.current)}Z.current=!1},[]);let B=U.useRef(g.focusedKey);U.useEffect(()=>{let R=B_();if(g.isFocused&&g.focusedKey!=null&&(u!=null&&u.current)){let S=u.current.querySelector(`[data-key="${g.focusedKey}"]`);S&&R==="keyboard"&&(c||fHe(u.current,S),Ll(S,{containingElement:I.current}))}g.isFocused&&g.focusedKey==null&&B.current!=null&&tC(I.current),B.current=g.focusedKey},[c,u,g.focusedKey,g.isFocused,I]);let G={onKeyDown:f,onFocus:p,onBlur:y,onMouseDown(R){u.current===R.target&&R.preventDefault()}},{typeSelectProps:v}=Aog({keyboardDelegate:i,selectionManager:g});s||(G=GI(v,G));let w;return A||(w=g.focusedKey==null?0:-1),{collectionProps:{...G,tabIndex:w}}}function NHe(e){let{selectionManager:g,key:i,ref:I,shouldSelectOnPressUp:n,shouldUseVirtualFocus:r,focus:C,isDisabled:o,onAction:a,allowsDifferentPressOrigin:s,linkBehavior:A="action"}=e,l=cHe(),c=K=>{if(K.pointerType==="keyboard"&&X_(K))g.toggleSelection(i);else{if(g.selectionMode==="none")return;if(g.isLink(i)){if(A==="selection"){l.open(I.current,K),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):K&&K.shiftKey?g.extendSelection(i):g.selectionBehavior==="toggle"||K&&(xf(K)||K.pointerType==="touch"||K.pointerType==="virtual")?g.toggleSelection(i):g.replaceSelection(i)}};U.useEffect(()=>{i===g.focusedKey&&g.isFocused&&!r&&(C?C():document.activeElement!==I.current&&tC(I.current))},[I,i,g.focusedKey,g.childFocusStrategy,g.isFocused,r]),o=o||g.isDisabled(i);let u={};!r&&!o?u={tabIndex:i===g.focusedKey?0:-1,onFocus(K){K.target===I.current&&g.setFocusedKey(i)}}:o&&(u.onMouseDown=K=>{K.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=U.useRef(null),B=y&&m,G=U.useRef(!1),v=U.useRef(!1),w=K=>{a&&a(),h&&l.open(I.current,K)},R={};n?(R.onPressStart=K=>{Z.current=K.pointerType,G.current=B,K.pointerType==="keyboard"&&(!y||xce())&&c(K)},s?(R.onPressUp=b?null:K=>{K.pointerType!=="keyboard"&&m&&c(K)},R.onPress=b?w:null):R.onPress=K=>{if(b||p&&K.pointerType!=="mouse"){if(K.pointerType==="keyboard"&&!Dce())return;w(K)}else K.pointerType!=="keyboard"&&m&&c(K)}):(R.onPressStart=K=>{Z.current=K.pointerType,G.current=B,v.current=b,m&&(K.pointerType==="mouse"&&!b||K.pointerType==="keyboard"&&(!f||xce()))&&c(K)},R.onPress=K=>{(K.pointerType==="touch"||K.pointerType==="pen"||K.pointerType==="virtual"||K.pointerType==="keyboard"&&y&&Dce()||K.pointerType==="mouse"&&v.current)&&(y?w(K):m&&c(K))}),u["data-key"]=i,R.preventFocusOnPress=r;let{pressProps:S,isPressed:X}=a8(R),W=p?K=>{Z.current==="mouse"&&(K.stopPropagation(),K.preventDefault(),w(K))}:void 0,{longPressProps:V}=wCg({isDisabled:!B,onLongPress(K){K.pointerType==="touch"&&(c(K),g.setSelectionBehavior("toggle"))}}),H=K=>{Z.current==="touch"&&G.current&&K.preventDefault()},Y=g.isLink(i)?K=>{Eh.isOpening||K.preventDefault()}:void 0;return{itemProps:GI(u,m||b?S:{},B?V:{},{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 Dce(){let e=window.event;return(e==null?void 0:e.key)==="Enter"}function xce(){let e=window.event;return(e==null?void 0:e.key)===" "||(e==null?void 0:e.code)==="Space"}class cog{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 r=n.getBoundingClientRect();do g=i(g),n=this.getItem(g);while(n&&I(r,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(!KH(i))return this.getFirstKey();let n=i.getBoundingClientRect(),r=I.getBoundingClientRect();if(this.orientation==="horizontal"){let C=n.x-i.scrollLeft,o=Math.max(0,r.x-C+r.width-n.width);for(;I&&r.x-C>o;)g=this.getKeyAbove(g),I=g==null?null:this.getItem(g),r=I==null?void 0:I.getBoundingClientRect()}else{let C=n.y-i.scrollTop,o=Math.max(0,r.y-C+r.height-n.height);for(;I&&r.y-C>o;)g=this.getKeyAbove(g),I=g==null?null:this.getItem(g),r=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(!KH(i))return this.getLastKey();let n=i.getBoundingClientRect(),r=I.getBoundingClientRect();if(this.orientation==="horizontal"){let C=n.x-i.scrollLeft,o=Math.min(i.scrollWidth,r.x-C-r.width+n.width);for(;I&&r.x-Cthis.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,C=>{n.push(C)});let r=0;for(let C of n){let o=this.getFullNode({element:C,index:r},{});for(let a of o)r++,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 r=i.value;if(r!=null){var C;let o=(C=r.key)!==null&&C!==void 0?C:r.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 r=g.element;if(!r&&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}r=i.renderer(g.value)}if(N.isValidElement(r)){let a=r.type;if(typeof a!="function"&&typeof a.getCollectionNode!="function"){let c=typeof r.type=="function"?r.type.name:r.type;throw new Error(`Unknown element <${c}> in collection.`)}let s=a.getCollectionNode(r.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(r,g,i,I));let h=[...this.getFullNode({...c,key:u,index:A,wrapper:dog(g.wrapper,c.wrapper)},this.getChildState(i,c),I?`${I}${r.key}`:r.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 <${Ux(m.type)}> in <${Ux(n.type)}>. Only <${Ux(g.type)}> is supported.`);A++,yield m}l=s.next(h)}return}if(g.key==null)return;let C=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:Ece(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=C.getFullNode(s,C.getChildState(i,s),o.key,o);for(let l of A)a++,yield l}})};yield o}constructor(){this.cache=new WeakMap}}function Ece(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 dog(e,g){if(e&&g)return i=>e(g(i));if(e)return e;if(g)return g}function Ux(e){return e[0].toUpperCase()+e.slice(1)}function hog(e,g,i){let I=U.useMemo(()=>new uog,[]),{children:n,items:r,collection:C}=e;return U.useMemo(()=>{if(C)return C;let a=I.build({children:n,items:r},i);return g(a)},[I,n,r,C,i,g])}function wI(e,g){return typeof g.getChildren=="function"?g.getChildren(e.key):e.childNodes}function As(e){return Ul(e,0)}function Ul(e,g){if(g<0)return;let i=0;for(let I of e){if(i===g)return I;i++}}function yc(e){let g;for(let i of e)g=i;return g}function Qx(e,g,i){if(g.parentKey===i.parentKey)return g.index-i.index;let I=[...Mce(e,g),g],n=[...Mce(e,i),i],r=I.slice(0,n.length).findIndex((C,o)=>C!==n[o]);return r!==-1?(g=I[r],i=n[r],g.index-i.index):I.findIndex(C=>C===i)>=0?1:(n.findIndex(C=>C===g)>=0,-1)}function Mce(e,g){let i=[];for(;(g==null?void 0:g.parentKey)!=null;)g=e.getItem(g.parentKey),i.unshift(g);return i}function mog(e,g){let{inputElementType:i="input",isDisabled:I=!1,isRequired:n=!1,isReadOnly:r=!1,type:C="text",validationBehavior:o="aria"}=e,[a,s]=aHe(e.value,e.defaultValue||"",e.onChange),{focusableProps:A}=wHe(e,g),l=Iog({...e,value:a}),{isInvalid:c,validationErrors:u,validationDetails:d}=l.displayValidation,{labelProps:h,fieldProps:m,descriptionProps:f,errorMessageProps:b}=oog({...e,isInvalid:c,errorMessage:e.errorMessage||u}),p=YA(e,{labelable:!0});const y={type:C,pattern:e.pattern};return gCg(g,a,s),qCg(e,l,g),U.useEffect(()=>{if(g.current instanceof kH(g.current).HTMLTextAreaElement){let Z=g.current;Object.defineProperty(Z,"defaultValue",{get:()=>Z.value,set:()=>{},configurable:!0})}},[g]),{labelProps:h,inputProps:GI(p,i==="input"&&y,{disabled:I,readOnly:r,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 dp{copy(){return new dp(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 hp{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 dp(this.x,this.y)}get topRight(){return new dp(this.maxX,this.y)}get bottomLeft(){return new dp(this.x,this.maxY)}get bottomRight(){return new dp(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,r=Math.max(this.maxY,g.maxY)-I;return new hp(i,I,n,r)}intersection(g){if(!this.intersects(g))return new hp(0,0,0,0);let i=Math.max(this.x,g.x),I=Math.max(this.y,g.y);return new hp(i,I,Math.min(this.maxX,g.maxX)-i,Math.min(this.maxY,g.maxY)-I)}copy(){return new hp(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 Ef=typeof window<"u"?window.performance:null,zce=Ef&&(Ef.now||Ef.webkitNow||Ef.msNow||Ef.mozNow);zce&&zce.bind(Ef);function h8(e){return e&&e.__esModule?e.default:e}class kHe{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 Ul(wI(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 Ul(wI(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=wI(i,this.collection);return this.direction==="rtl"?yc(I).key:As(I).key}if(this.isCell(i)){let I=this.collection.getItem(i.parentKey),n=wI(I,this.collection),r=this.direction==="rtl"?Ul(n,i.index-1):Ul(n,i.index+1);return r?r.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=wI(i,this.collection);return this.direction==="rtl"?As(I).key:yc(I).key}if(this.isCell(i)){let I=this.collection.getItem(i.parentKey),n=wI(I,this.collection),r=this.direction==="rtl"?Ul(n,i.index+1):Ul(n,i.index-1);return r?r.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 As(wI(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=As(wI(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),r=wI(n,this.collection);return yc(r).key}}if(g=this.findPreviousKey(),g!=null&&I&&this.isCell(I)&&i||this.focusMode==="cell"){let n=this.collection.getItem(g),r=wI(n,this.collection);g=yc(r).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 hp(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 KHe={};KHe={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 FHe={};FHe={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 DHe={};DHe={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 xHe={};xHe={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 EHe={};EHe={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 MHe={};MHe={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 zHe={};zHe={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 PHe={};PHe={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 JHe={};JHe={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 OHe={};OHe={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 _He={};_He={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 LHe={};LHe={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 UHe={};UHe={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 QHe={};QHe={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 jHe={};jHe={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 $He={};$He={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 qHe={};qHe={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 eTe={};eTe={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 tTe={};tTe={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 gTe={};gTe={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 iTe={};iTe={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 ITe={};ITe={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 nTe={};nTe={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 rTe={};rTe={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 CTe={};CTe={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 oTe={};oTe={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 aTe={};aTe={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 ATe={};ATe={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 sTe={};sTe={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 lTe={};lTe={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 cTe={};cTe={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 uTe={};uTe={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 dTe={};dTe={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}」。`};nY={"ar-AE":YHe,"bg-BG":KHe,"cs-CZ":FHe,"da-DK":DHe,"de-DE":xHe,"el-GR":EHe,"en-US":MHe,"es-ES":zHe,"et-EE":PHe,"fi-FI":JHe,"fr-FR":OHe,"he-IL":_He,"hr-HR":LHe,"hu-HU":UHe,"it-IT":QHe,"ja-JP":jHe,"ko-KR":$He,"lt-LT":qHe,"lv-LV":eTe,"nb-NO":tTe,"nl-NL":gTe,"pl-PL":iTe,"pt-BR":ITe,"pt-PT":nTe,"ro-RO":rTe,"ru-RU":CTe,"sk-SK":oTe,"sl-SI":aTe,"sr-SP":ATe,"sv-SE":sTe,"tr-TR":lTe,"uk-UA":cTe,"zh-CN":uTe,"zh-TW":dTe};function fog(e,g){let{getRowText:i=C=>{var o,a,s,A;return(A=(o=(a=g.collection).getTextValue)===null||o===void 0?void 0:o.call(a,C))!==null&&A!==void 0?A:(s=g.collection.getItem(C))===null||s===void 0?void 0:s.textValue}}=e,I=my(h8(nY)),n=g.selectionManager.rawSelection,r=U.useRef(n);hHe(()=>{var C;if(!g.selectionManager.isFocused){r.current=n;return}let o=Pce(n,r.current),a=Pce(r.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||r.current==="all"||((C=r.current)===null||C===void 0?void 0:C.size)>1)&&A.push(n==="all"?I.format("selectedAll"):I.format("selectedCount",{count:n.size})),A.length>0&&XHe(A.join(" ")),r.current=n},[n])}function Pce(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 pog(e){let g=my(h8(nY)),i=bCg(),I=(i==="pointer"||i==="virtual"||i==null)&&typeof window<"u"&&"ontouchstart"in window,n=U.useMemo(()=>{let C=e.selectionManager.selectionMode,o=e.selectionManager.selectionBehavior,a;return I&&(a=g.format("longPressToSelect")),o==="replace"&&C!=="none"&&e.hasItemActions?a:void 0},[e.selectionManager.selectionMode,e.selectionManager.selectionBehavior,e.hasItemActions,g,I]);return gY(n)}function bog(e,g,i){let{isVirtualized:I,keyboardDelegate:n,focusMode:r,scrollRef:C,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=VHe({usage:"search",sensitivity:"base"}),{direction:c}=Gm(),u=g.selectionManager.disabledBehavior,d=U.useMemo(()=>n||new kHe({collection:g.collection,disabledKeys:u==="selection"?new Set:g.disabledKeys,ref:i,direction:c,collator:l,focusMode:r}),[n,g.collection,g.disabledKeys,u,i,c,l,r]),{collectionProps:h}=log({ref:i,selectionManager:A,keyboardDelegate:d,isVirtualized:I,scrollRef:C}),m=Dh(e.id);m8.set(g,{keyboardDelegate:d,actions:{onRowAction:a,onCellAction:s}});let f=pog({selectionManager:A,hasItemActions:!!(a||s)}),b=YA(e,{labelable:!0}),p=U.useCallback(G=>{if(A.isFocused){G.currentTarget.contains(G.target)||A.setFocused(!1);return}G.currentTarget.contains(G.target)&&A.setFocused(!0)},[A]),y=U.useMemo(()=>({onBlur:h.onBlur,onFocus:p}),[p,h.onBlur]),Z=ECg(i,{isDisabled:g.collection.size!==0}),B=GI(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),fog({getRowText:o},g),{gridProps:B}}function yog(){return{rowGroupProps:{role:"rowgroup"}}}function Zog(e,g,i){let{node:I,isVirtualized:n,shouldSelectOnPressUp:r,onAction:C}=e,{actions:{onRowAction:o}}=m8.get(g),{itemProps:a,...s}=NHe({selectionManager:g.selectionManager,key:I.key,ref:i,isVirtualized:n,shouldSelectOnPressUp:r,onAction:o?()=>o(I.key):C,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 hTe(e,g,i){let{node:I,isVirtualized:n,focusMode:r="child",shouldSelectOnPressUp:C,onAction:o}=e,{direction:a}=Gm(),{keyboardDelegate:s,actions:{onCellAction:A}}=m8.get(g),l=U.useRef(null),c=()=>{let p=QC(i.current);if(r==="child"){if(i.current.contains(document.activeElement)&&i.current!==document.activeElement)return;let y=g.selectionManager.childFocusStrategy==="last"?jx(p):p.firstChild();if(y){tC(y);return}}(l.current!=null&&I.key!==l.current||!i.current.contains(document.activeElement))&&tC(i.current)},{itemProps:u,isPressed:d}=NHe({selectionManager:g.selectionManager,key:I.key,ref:i,isVirtualized:n,focus:c,shouldSelectOnPressUp:C,onAction:A?()=>A(I.key):o,isDisabled:g.collection.size===0}),f=GI(u,{role:"gridcell",onKeyDownCapture:p=>{if(!p.currentTarget.contains(p.target)||g.isKeyboardNavigationDisabled)return;let y=QC(i.current);switch(y.currentNode=document.activeElement,p.key){case"ArrowLeft":{let Z=a==="rtl"?y.nextNode():y.previousNode();if(r==="child"&&Z===i.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),tC(Z),Ll(Z,{containingElement:_l(i.current)});else{if(s.getKeyLeftOf(I.key)!==I.key)break;p.preventDefault(),p.stopPropagation(),r==="cell"&&a==="rtl"?(tC(i.current),Ll(i.current,{containingElement:_l(i.current)})):(y.currentNode=i.current,Z=a==="rtl"?y.firstChild():jx(y),Z&&(tC(Z),Ll(Z,{containingElement:_l(i.current)})))}break}case"ArrowRight":{let Z=a==="rtl"?y.previousNode():y.nextNode();if(r==="child"&&Z===i.current&&(Z=null),Z)p.preventDefault(),p.stopPropagation(),tC(Z),Ll(Z,{containingElement:_l(i.current)});else{if(s.getKeyRightOf(I.key)!==I.key)break;p.preventDefault(),p.stopPropagation(),r==="cell"&&a==="ltr"?(tC(i.current),Ll(i.current,{containingElement:_l(i.current)})):(y.currentNode=i.current,Z=a==="rtl"?jx(y):y.firstChild(),Z&&(tC(Z),Ll(Z,{containingElement:_l(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){s8()||g.selectionManager.setFocusedKey(I.key);return}requestAnimationFrame(()=>{r==="child"&&document.activeElement===i.current&&c()})}});var b;return n&&(f["aria-colindex"]=((b=I.colIndex)!==null&&b!==void 0?b:I.index)+1),C&&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 jx(e){let g,i;do i=e.lastChild(),i&&(g=i);while(i);return g}function Gog(e,g){let{key:i}=e,I=g.selectionManager,n=Dh(),r=!g.selectionManager.canSelectItem(i),C=g.selectionManager.isSelected(i),o=()=>I.select(i);const a=my(h8(nY));return{checkboxProps:{id:n,"aria-label":a.format("select"),isSelected:C,isDisabled:r,onChange:o}}}let vog=!1;function MH(){return vog}function f8(e){return e&&e.__esModule?e.default:e}const p8=new WeakMap;function H_(e){return typeof e=="string"?e.replace(/\s*/g,""):""+e}function Bog(e,g){let i=p8.get(e);if(!i)throw new Error("Unknown grid");return`${i}-${H_(g)}`}function mTe(e,g,i){let I=p8.get(e);if(!I)throw new Error("Unknown grid");return`${I}-${H_(g)}-${H_(i)}`}function fTe(e,g){return[...e.collection.rowHeaderColumnKeys].map(i=>mTe(e,g,i)).join(" ")}var rY={},pTe={};pTe={ascending:"تصاعدي",ascendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تصاعدي`,columnSize:e=>`${e.value} بالبكسل`,descending:"تنازلي",descendingSort:e=>`ترتيب حسب العمود ${e.columnName} بترتيب تنازلي`,resizerDescription:"اضغط على مفتاح Enter لبدء تغيير الحجم",select:"تحديد",selectAll:"تحديد الكل",sortable:"عمود قابل للترتيب"};var bTe={};bTe={ascending:"възходящ",ascendingSort:e=>`сортирано по колона ${e.columnName} във възходящ ред`,columnSize:e=>`${e.value} пиксела`,descending:"низходящ",descendingSort:e=>`сортирано по колона ${e.columnName} в низходящ ред`,resizerDescription:"Натиснете „Enter“, за да започнете да преоразмерявате",select:"Изберете",selectAll:"Изберете всичко",sortable:"сортираща колона"};var yTe={};yTe={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 ZTe={};ZTe={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 GTe={};GTe={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 vTe={};vTe={ascending:"αύξουσα",ascendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε αύξουσα σειρά`,columnSize:e=>`${e.value} pixel`,descending:"φθίνουσα",descendingSort:e=>`διαλογή ανά στήλη ${e.columnName} σε φθίνουσα σειρά`,resizerDescription:"Πατήστε Enter για έναρξη της αλλαγής μεγέθους",select:"Επιλογή",selectAll:"Επιλογή όλων",sortable:"Στήλη διαλογής"};var BTe={};BTe={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 STe={};STe={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 wTe={};wTe={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 RTe={};RTe={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 VTe={};VTe={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 WTe={};WTe={ascending:"עולה",ascendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר עולה`,columnSize:e=>`${e.value} פיקסלים`,descending:"יורד",descendingSort:e=>`מוין לפי עמודה ${e.columnName} בסדר יורד`,resizerDescription:"הקש Enter כדי לשנות את הגודל",select:"בחר",selectAll:"בחר הכול",sortable:"עמודה שניתן למיין"};var XTe={};XTe={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 HTe={};HTe={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 TTe={};TTe={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 NTe={};NTe={ascending:"昇順",ascendingSort:e=>`列 ${e.columnName} を昇順で並べ替え`,columnSize:e=>`${e.value} ピクセル`,descending:"降順",descendingSort:e=>`列 ${e.columnName} を降順で並べ替え`,resizerDescription:"Enter キーを押してサイズ変更を開始",select:"選択",selectAll:"すべて選択",sortable:"並べ替え可能な列"};var kTe={};kTe={ascending:"오름차순",ascendingSort:e=>`${e.columnName} 열을 기준으로 오름차순으로 정렬됨`,columnSize:e=>`${e.value} 픽셀`,descending:"내림차순",descendingSort:e=>`${e.columnName} 열을 기준으로 내림차순으로 정렬됨`,resizerDescription:"크기 조정을 시작하려면 Enter를 누르세요.",select:"선택",selectAll:"모두 선택",sortable:"정렬 가능한 열"};var YTe={};YTe={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 KTe={};KTe={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 FTe={};FTe={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 DTe={};DTe={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 xTe={};xTe={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 ETe={};ETe={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 MTe={};MTe={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 zTe={};zTe={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 PTe={};PTe={ascending:"возрастание",ascendingSort:e=>`сортировать столбец ${e.columnName} в порядке возрастания`,columnSize:e=>`${e.value} пикс.`,descending:"убывание",descendingSort:e=>`сортировать столбец ${e.columnName} в порядке убывания`,resizerDescription:"Нажмите клавишу Enter для начала изменения размеров",select:"Выбрать",selectAll:"Выбрать все",sortable:"сортируемый столбец"};var JTe={};JTe={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 OTe={};OTe={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 _Te={};_Te={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 LTe={};LTe={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 UTe={};UTe={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 QTe={};QTe={ascending:"висхідний",ascendingSort:e=>`відсортовано за стовпцем ${e.columnName} у висхідному порядку`,columnSize:e=>`${e.value} пікс.`,descending:"низхідний",descendingSort:e=>`відсортовано за стовпцем ${e.columnName} у низхідному порядку`,resizerDescription:"Натисніть Enter, щоб почати зміну розміру",select:"Вибрати",selectAll:"Вибрати все",sortable:"сортувальний стовпець"};var jTe={};jTe={ascending:"升序",ascendingSort:e=>`按列 ${e.columnName} 升序排序`,columnSize:e=>`${e.value} 像素`,descending:"降序",descendingSort:e=>`按列 ${e.columnName} 降序排序`,resizerDescription:"按“输入”键开始调整大小。",select:"选择",selectAll:"全选",sortable:"可排序的列"};var $Te={};$Te={ascending:"遞增",ascendingSort:e=>`已依據「${e.columnName}」欄遞增排序`,columnSize:e=>`${e.value} 像素`,descending:"遞減",descendingSort:e=>`已依據「${e.columnName}」欄遞減排序`,resizerDescription:"按 Enter 鍵以開始調整大小",select:"選取",selectAll:"全選",sortable:"可排序的欄"};rY={"ar-AE":pTe,"bg-BG":bTe,"cs-CZ":yTe,"da-DK":ZTe,"de-DE":GTe,"el-GR":vTe,"en-US":BTe,"es-ES":STe,"et-EE":wTe,"fi-FI":RTe,"fr-FR":VTe,"he-IL":WTe,"hr-HR":XTe,"hu-HU":HTe,"it-IT":TTe,"ja-JP":NTe,"ko-KR":kTe,"lt-LT":YTe,"lv-LV":KTe,"nb-NO":FTe,"nl-NL":DTe,"pl-PL":xTe,"pt-BR":ETe,"pt-PT":MTe,"ro-RO":zTe,"ru-RU":PTe,"sk-SK":JTe,"sl-SI":OTe,"sr-SP":_Te,"sv-SE":LTe,"tr-TR":UTe,"uk-UA":QTe,"zh-CN":jTe,"zh-TW":$Te};class Sog extends kHe{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=As(wI(i,this.collection));if(I)return I.key;let n=this.getFirstKey();if(n==null)return;let r=this.collection.getItem(n);return Ul(wI(r,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 wI(I,this.collection))if(n.type==="column")return n.key}findPreviousColumnKey(g){let i=this.findPreviousKey(g.key,r=>r.type==="column");if(i!=null)return i;let I=this.collection.headerRows[g.level],n=[...wI(I,this.collection)];for(let r=n.length-1;r>=0;r--){let C=n[r];if(C.type==="column")return C.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 r=I.getItem(n);r.type==="cell"&&(n=r.parentKey);let C=!1;for(;n!=null;){let o=I.getItem(n);for(let a of wI(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):r).type==="cell"?a.key:o.key}}n=this.getKeyBelow(n),n==null&&!C&&(n=this.getFirstKey(),C=!0)}return null}}function wog(e,g,i){let{keyboardDelegate:I,isVirtualized:n,layout:r}=e,C=VHe({usage:"search",sensitivity:"base"}),{direction:o}=Gm(),a=g.selectionManager.disabledBehavior,s=U.useMemo(()=>I||new Sog({collection:g.collection,disabledKeys:a==="selection"?new Set:g.disabledKeys,ref:i,direction:o,collator:C,layout:r}),[I,g.collection,g.disabledKeys,a,i,o,C,r]),A=Dh(e.id);p8.set(g,A);let{gridProps:l}=bog({...e,id:A,keyboardDelegate:s},g,i);n&&(l["aria-rowcount"]=g.collection.size+g.collection.headerRows.length),MH()&&"expandedKeys"in g&&(l.role="treegrid");let{column:c,direction:u}=g.sortDescriptor||{},d=my(f8(rY)),h=U.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=gY(h);return hHe(()=>{XHe(h,"assertive",500)},[h]),{gridProps:GI(l,m,{"aria-describedby":[m["aria-describedby"],l["aria-describedby"]].filter(Boolean).join(" ")})}}function Rog(e,g,i){var I,n;let{node:r}=e,C=r.props.allowsSorting,{gridCellProps:o}=hTe({...e,focusMode:"child"},g,i),a=r.props.isSelectionCell&&g.selectionManager.selectionMode==="single",{pressProps:s}=a8({isDisabled:!C||a,onPress(){g.sort(r.key)},ref:i}),{focusableProps:A}=wHe({},i),l=null,c=((I=g.sortDescriptor)===null||I===void 0?void 0:I.column)===r.key,u=(n=g.sortDescriptor)===null||n===void 0?void 0:n.direction;r.props.allowsSorting&&!YH()&&(l=c?u:"none");let d=my(f8(rY)),h;C&&(h=`${d.format("sortable")}`,c&&u&&YH()&&(h=`${h}, ${d.format(u)}`));let m=gY(h),f=g.collection.size===0;return U.useEffect(()=>{f&&g.selectionManager.focusedKey===r.key&&g.selectionManager.setFocusedKey(null)},[f,g.selectionManager,r.key]),{columnHeaderProps:{...GI(o,s,A,m,f&&{tabIndex:-1}),role:"columnheader",id:Bog(g,r.key),"aria-colspan":r.colspan&&r.colspan>1?r.colspan:null,"aria-sort":l}}}const Jce={expand:{ltr:"ArrowRight",rtl:"ArrowLeft"},collapse:{ltr:"ArrowLeft",rtl:"ArrowRight"}};function Vog(e,g,i){let{node:I,isVirtualized:n}=e,{rowProps:r,...C}=Zog(e,g,i),{direction:o}=Gm();n&&!(MH()&&"expandedKeys"in g)?r["aria-rowindex"]=I.index+1+g.collection.headerRows.length:delete r["aria-rowindex"];let a={};if(MH()&&"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===Jce.expand[o]&&g.selectionManager.focusedKey===u.key&&d&&g.expandedKeys!=="all"&&!g.expandedKeys.has(u.key)||h.key===Jce.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?yc(g.keyMap.get(u==null?void 0:u.parentKey).childNodes).indexOfType+1:yc(g.keyMap.get(g.collection.body.key).childNodes).indexOfType+1}}}let c=C.hasAction?jrg(I.props):{};return{rowProps:{...GI(r,a,c),"aria-labelledby":fTe(g,I.key)},...C}}function Wog(e,g,i){let{node:I,isVirtualized:n}=e,r={role:"row"};return n&&!(MH()&&"expandedKeys"in g)&&(r["aria-rowindex"]=I.index+1),{rowProps:r}}function Xog(e,g,i){let{gridCellProps:I,isPressed:n}=hTe(e,g,i),r=e.node.column.key;return g.collection.rowHeaderColumnKeys.has(r)&&(I.role="rowheader",I.id=mTe(g,e.node.parentKey,r)),{gridCellProps:I,isPressed:n}}function Hog(e,g){let{key:i}=e;const{checkboxProps:I}=Gog(e,g);return{checkboxProps:{...I,"aria-labelledby":`${I.id} ${fTe(g,i)}`}}}function Tog(e){let{isEmpty:g,isSelectAll:i,selectionMode:I}=e.selectionManager;return{checkboxProps:{"aria-label":my(f8(rY)).format(I==="single"?"select":"selectAll"),isSelected:i,isDisabled:I!=="multiple"||e.collection.size===0,isIndeterminate:!g&&!i,onChange:()=>e.selectionManager.toggleSelectAll()}}}function qTe(){return yog()}var eNe={exports:{}},tNe={};/** * @license React * use-sync-external-store-shim.production.min.js * @@ -1997,7 +1997,7 @@ ${s}`:s,l=Tet(o).parse(A,c=>SI(this,x$,t2e).call(this,c,r,I,i));if(C&&((g=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 h0=U;function wog(e,g){return e===g&&(e!==0||1/e===1/g)||e!==e&&g!==g}var Vog=typeof Object.is=="function"?Object.is:wog,Rog=h0.useState,Wog=h0.useEffect,Xog=h0.useLayoutEffect,Hog=h0.useDebugValue;function Tog(e,g){var I=g(),i=Rog({inst:{value:I,getSnapshot:g}}),n=i[0].inst,C=i[1];return Xog(function(){n.value=I,n.getSnapshot=g,_F(n)&&C({inst:n})},[e,I,g]),Wog(function(){return _F(n)&&C({inst:n}),e(function(){_F(n)&&C({inst:n})})},[e]),Hog(I),I}function _F(e){var g=e.getSnapshot;e=e.value;try{var I=g();return!Vog(e,I)}catch{return!0}}function Nog(e,g){return g()}var kog=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?Nog:Tog;LTe.useSyncExternalStore=h0.useSyncExternalStore!==void 0?h0.useSyncExternalStore:kog;_Te.exports=LTe;var Yog=_Te.exports;class Mo extends Set{constructor(g,I,i){super(g),g instanceof Mo?(this.anchorKey=I||g.anchorKey,this.currentKey=i||g.currentKey):(this.anchorKey=I,this.currentKey=i)}}function Kog(e,g){if(e.size!==g.size)return!1;for(let I of e)if(!g.has(I))return!1;return!0}function xog(e){let{selectionMode:g="none",disallowEmptySelection:I,allowDuplicateSelectionEvents:i,selectionBehavior:n="toggle",disabledBehavior:C="all"}=e,r=U.useRef(!1),[,o]=U.useState(!1),a=U.useRef(null),s=U.useRef(null),[,A]=U.useState(null),l=U.useMemo(()=>xce(e.selectedKeys),[e.selectedKeys]),c=U.useMemo(()=>xce(e.defaultSelectedKeys,new Mo),[e.defaultSelectedKeys]),[u,d]=gHe(l,c,e.onSelectionChange),h=U.useMemo(()=>e.disabledKeys?new Set(e.disabledKeys):new Set,[e.disabledKeys]),[m,f]=U.useState(n);n==="replace"&&m==="toggle"&&typeof u=="object"&&u.size===0&&f("replace");let b=U.useRef(n);return U.useEffect(()=>{n!==b.current&&(f(n),b.current=n)},[n]),{selectionMode:g,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||!Kog(p,u))&&d(p)},disabledKeys:h,disabledBehavior:C}}function xce(e,g){return e?e==="all"?"all":new Mo(e):g}class Dog{get selectionMode(){return this.state.selectionMode}get disallowEmptySelection(){return this.state.disallowEmptySelection}get selectionBehavior(){return this.state.selectionBehavior}setSelectionBehavior(g){this.state.setSelectionBehavior(g)}get isFocused(){return this.state.isFocused}setFocused(g){this.state.setFocused(g)}get focusedKey(){return this.state.focusedKey}get childFocusStrategy(){return this.state.childFocusStrategy}setFocusedKey(g,I){(g==null||this.collection.getItem(g))&&this.state.setFocusedKey(g,I)}get selectedKeys(){return this.state.selectedKeys==="all"?new Set(this.getSelectAllKeys()):this.state.selectedKeys}get rawSelection(){return this.state.selectedKeys}isSelected(g){return this.state.selectionMode==="none"?!1:(g=this.getKey(g),this.state.selectedKeys==="all"?this.canSelectItem(g):this.state.selectedKeys.has(g))}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 g=this.getSelectAllKeys(),I=this.state.selectedKeys;return this._isSelectAll=g.every(i=>I.has(i)),this._isSelectAll}get firstSelectedKey(){let g=null;for(let I of this.state.selectedKeys){let i=this.collection.getItem(I);(!g||i&&JF(this.collection,i,g)<0)&&(g=i)}return g==null?void 0:g.key}get lastSelectedKey(){let g=null;for(let I of this.state.selectedKeys){let i=this.collection.getItem(I);(!g||i&&JF(this.collection,i,g)>0)&&(g=i)}return g==null?void 0:g.key}get disabledKeys(){return this.state.disabledKeys}get disabledBehavior(){return this.state.disabledBehavior}extendSelection(g){if(this.selectionMode==="none")return;if(this.selectionMode==="single"){this.replaceSelection(g);return}g=this.getKey(g);let I;if(this.state.selectedKeys==="all")I=new Mo([g],g,g);else{let i=this.state.selectedKeys,n=i.anchorKey||g;I=new Mo(i,n,g);for(let C of this.getKeyRange(n,i.currentKey||g))I.delete(C);for(let C of this.getKeyRange(g,n))this.canSelectItem(C)&&I.add(C)}this.state.setSelectedKeys(I)}getKeyRange(g,I){let i=this.collection.getItem(g),n=this.collection.getItem(I);return i&&n?JF(this.collection,i,n)<=0?this.getKeyRangeInternal(g,I):this.getKeyRangeInternal(I,g):[]}getKeyRangeInternal(g,I){let i=[],n=g;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(g){let I=this.collection.getItem(g);if(!I||I.type==="cell"&&this.allowsCellSelection)return g;for(;I.type!=="item"&&I.parentKey!=null;)I=this.collection.getItem(I.parentKey);return!I||I.type!=="item"?null:I.key}toggleSelection(g){if(this.selectionMode==="none")return;if(this.selectionMode==="single"&&!this.isSelected(g)){this.replaceSelection(g);return}if(g=this.getKey(g),g==null)return;let I=new Mo(this.state.selectedKeys==="all"?this.getSelectAllKeys():this.state.selectedKeys);I.has(g)?I.delete(g):this.canSelectItem(g)&&(I.add(g),I.anchorKey=g,I.currentKey=g),!(this.disallowEmptySelection&&I.size===0)&&this.state.setSelectedKeys(I)}replaceSelection(g){if(this.selectionMode==="none"||(g=this.getKey(g),g==null))return;let I=this.canSelectItem(g)?new Mo([g],g,g):new Mo;this.state.setSelectedKeys(I)}setSelectedKeys(g){if(this.selectionMode==="none")return;let I=new Mo;for(let i of g)if(i=this.getKey(i),i!=null&&(I.add(i),this.selectionMode==="single"))break;this.state.setSelectedKeys(I)}getSelectAllKeys(){let g=[],I=i=>{for(;i;){if(this.canSelectItem(i)){let n=this.collection.getItem(i);n.type==="item"&&g.push(i),n.hasChildNodes&&(this.allowsCellSelection||n.type!=="item")&&I(As(wi(n,this.collection)).key)}i=this.collection.getKeyAfter(i)}};return I(this.collection.getFirstKey()),g}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 Mo)}toggleSelectAll(){this.isSelectAll?this.clearSelection():this.selectAll()}select(g,I){this.selectionMode!=="none"&&(this.selectionMode==="single"?this.isSelected(g)&&!this.disallowEmptySelection?this.toggleSelection(g):this.replaceSelection(g):this.selectionBehavior==="toggle"||I&&(I.pointerType==="touch"||I.pointerType==="virtual")?this.toggleSelection(g):this.replaceSelection(g))}isSelectionEqual(g){if(g===this.state.selectedKeys)return!0;let I=this.selectedKeys;if(g.size!==I.size)return!1;for(let i of g)if(!I.has(i))return!1;for(let i of I)if(!g.has(i))return!1;return!0}canSelectItem(g){if(this.state.selectionMode==="none"||this.state.disabledKeys.has(g))return!1;let I=this.collection.getItem(g);return!(!I||I.type==="cell"&&!this.allowsCellSelection)}isDisabled(g){return this.state.disabledKeys.has(g)&&this.state.disabledBehavior==="all"}isLink(g){var I,i;return!!(!((i=this.collection.getItem(g))===null||i===void 0||(I=i.props)===null||I===void 0)&&I.href)}constructor(g,I,i){this.collection=g,this.state=I;var n;this.allowsCellSelection=(n=i==null?void 0:i.allowsCellSelection)!==null&&n!==void 0?n:!1,this._isSelectAll=null}}function Fog(e){let{collection:g,focusMode:I}=e,i=xog(e),n=U.useMemo(()=>e.disabledKeys?new Set(e.disabledKeys):new Set,[e.disabledKeys]),C=i.setFocusedKey;i.setFocusedKey=(a,s)=>{if(I==="cell"&&a!=null){let c=g.getItem(a);if((c==null?void 0:c.type)==="item"){var A,l;let u=wi(c,g);s==="last"?a=(A=yc(u))===null||A===void 0?void 0:A.key:a=(l=As(u))===null||l===void 0?void 0:l.key}}C(a,s)};let r=U.useMemo(()=>new Dog(g,i),[g,i]);const o=U.useRef(null);return U.useEffect(()=>{if(i.focusedKey!=null&&!g.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=g.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?[...wi(d,g)]:[],m=d.hasChildNodes&&s!==a&&a.index{let r=this.keyMap.get(C.key);g.visitNode&&(C=g.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;g.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 UTe="row-header-column-"+Math.random().toString(36).slice(2);let w_="row-header-column-"+Math.random().toString(36).slice(2);for(;UTe===w_;)w_="row-header-column-"+Math.random().toString(36).slice(2);function QTe(e,g){if(g.length===0)return[];let I=[],i=new Map;for(let a of g){let s=a.parentKey,A=[a];for(;s;){let l=e.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 Mog extends Eog{*[Symbol.iterator](){yield*this.body.childNodes}get size(){return this._size}getKeys(){return this.keyMap.keys()}getKeyBefore(g){let I=this.keyMap.get(g);return I?I.prevKey:null}getKeyAfter(g){let I=this.keyMap.get(g);return I?I.nextKey:null}getFirstKey(){var g;return(g=As(this.body.childNodes))===null||g===void 0?void 0:g.key}getLastKey(){var g;return(g=yc(this.body.childNodes))===null||g===void 0?void 0:g.key}getItem(g){return this.keyMap.get(g)}at(g){const I=[...this.getKeys()];return this.getItem(I[g])}getTextValue(g){let I=this.getItem(g);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(g,I,i){let n=new Set,C,r=[];if(i!=null&&i.showSelectionCheckboxes){let l={type:"column",key:UTe,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:w_,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 g)s(l);let A=QTe(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 zog={ascending:"descending",descending:"ascending"};function Pog(e){let[g,I]=U.useState(!1),{selectionMode:i="none",showSelectionCheckboxes:n,showDragButtons:C}=e,r=U.useMemo(()=>({showSelectionCheckboxes:n&&i!=="none",showDragButtons:C,selectionMode:i,columns:[]}),[e.children,n,i,C]),o=aog(e,U.useCallback(A=>new Mog(A,null,r),[r]),r),{disabledKeys:a,selectionManager:s}=Fog({...e,collection:o,disabledBehavior:e.disabledBehavior||"selection"});return{collection:o,disabledKeys:a,selectionManager:s,showSelectionCheckboxes:e.showSelectionCheckboxes||!1,sortDescriptor:e.sortDescriptor,isKeyboardNavigationDisabled:o.size===0||g,setKeyboardNavigationDisabled:I,sort(A,l){var c;e.onSortChange({column:A,direction:l??(((c=e.sortDescriptor)===null||c===void 0?void 0:c.column)===A?zog[e.sortDescriptor.direction]:"ascending")})}}}class sS{get childNodes(){throw new Error("childNodes is not supported")}clone(){let g=new sS(this.type,this.key);return g.value=this.value,g.level=this.level,g.hasChildNodes=this.hasChildNodes,g.rendered=this.rendered,g.textValue=this.textValue,g["aria-label"]=this["aria-label"],g.index=this.index,g.parentKey=this.parentKey,g.prevKey=this.prevKey,g.nextKey=this.nextKey,g.firstChildKey=this.firstChildKey,g.lastChildKey=this.lastChildKey,g.props=this.props,g}constructor(g,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=g,this.key=I}}class jTe{*[Symbol.iterator](){let g=this.firstChild;for(;g;)yield g,g=g.nextSibling}get firstChild(){return this._firstChild}set firstChild(g){this._firstChild=g,this.ownerDocument.markDirty(this)}get lastChild(){return this._lastChild}set lastChild(g){this._lastChild=g,this.ownerDocument.markDirty(this)}get previousSibling(){return this._previousSibling}set previousSibling(g){this._previousSibling=g,this.ownerDocument.markDirty(this)}get nextSibling(){return this._nextSibling}set nextSibling(g){this._nextSibling=g,this.ownerDocument.markDirty(this)}get parentNode(){return this._parentNode}set parentNode(g){this._parentNode=g,this.ownerDocument.markDirty(this)}appendChild(g){this.ownerDocument.startTransaction(),g.parentNode&&g.parentNode.removeChild(g),this.firstChild==null&&(this.firstChild=g),this.lastChild?(this.lastChild.nextSibling=g,g.index=this.lastChild.index+1,g.previousSibling=this.lastChild):(g.previousSibling=null,g.index=0),g.parentNode=this,g.nextSibling=null,this.lastChild=g,this.ownerDocument.markDirty(this),g.hasSetProps&&this.ownerDocument.addNode(g),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}insertBefore(g,I){if(I==null)return this.appendChild(g);this.ownerDocument.startTransaction(),g.parentNode&&g.parentNode.removeChild(g),g.nextSibling=I,g.previousSibling=I.previousSibling,g.index=I.index,this.firstChild===I?this.firstChild=g:I.previousSibling&&(I.previousSibling.nextSibling=g),I.previousSibling=g,g.parentNode=I.parentNode;let i=I;for(;i;)i.index++,i=i.nextSibling;g.hasSetProps&&this.ownerDocument.addNode(g),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}removeChild(g){if(g.parentNode!==this)return;this.ownerDocument.startTransaction();let I=g.nextSibling;for(;I;)I.index--,I=I.nextSibling;g.nextSibling&&(g.nextSibling.previousSibling=g.previousSibling),g.previousSibling&&(g.previousSibling.nextSibling=g.nextSibling),this.firstChild===g&&(this.firstChild=g.nextSibling),this.lastChild===g&&(this.lastChild=g.previousSibling),g.parentNode=null,g.nextSibling=null,g.previousSibling=null,g.index=0,this.ownerDocument.removeNode(g),this.ownerDocument.endTransaction(),this.ownerDocument.queueUpdate()}addEventListener(){}removeEventListener(){}constructor(g){this._firstChild=null,this._lastChild=null,this._previousSibling=null,this._nextSibling=null,this._parentNode=null,this.ownerDocument=g}}class lS extends jTe{get index(){return this._index}set index(g){this._index=g,this.ownerDocument.markDirty(this)}get level(){return this.parentNode instanceof lS?this.parentNode.level+(this.node.type==="item"?1:0):0}updateNode(){var g,I,i,n;let C=this.ownerDocument.getMutableNode(this);C.index=this.index,C.level=this.level,C.parentKey=this.parentNode instanceof lS?this.parentNode.node.key:null;var r;C.prevKey=(r=(g=this.previousSibling)===null||g===void 0?void 0:g.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(g,I,i){let n=this.ownerDocument.getMutableNode(this),{value:C,textValue:r,id:o,...a}=g;if(a.ref=I,n.props=a,n.rendered=i,n.value=C,n.textValue=r||(typeof i=="string"?i:"")||g["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(g,I){super(I),this.nodeType=8,this._index=0,this.hasSetProps=!1,this.node=new sS(g,`react-aria-${++I.nodeId}`),this.ownerDocument.startTransaction()}}class $Te{get size(){return this.keyMap.size}getKeys(){return this.keyMap.keys()}*[Symbol.iterator](){let g=this.firstKey!=null?this.keyMap.get(this.firstKey):void 0;for(;g;)yield g,g=g.nextKey!=null?this.keyMap.get(g.nextKey):void 0}getChildren(g){let I=this.keyMap;return{*[Symbol.iterator](){let i=I.get(g),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(g){let I=this.keyMap.get(g);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(g){let I=this.keyMap.get(g);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 g=this.lastKey!=null?this.keyMap.get(this.lastKey):null;for(;(g==null?void 0:g.lastChildKey)!=null;)g=this.keyMap.get(g.lastChildKey);var I;return(I=g==null?void 0:g.key)!==null&&I!==void 0?I:null}getItem(g){var I;return(I=this.keyMap.get(g))!==null&&I!==void 0?I:null}at(){throw new Error("Not implemented")}clone(){let g=this.constructor,I=new g;return I.keyMap=new Map(this.keyMap),I.firstKey=this.firstKey,I.lastKey=this.lastKey,I}addNode(g){if(this.frozen)throw new Error("Cannot add a node to a frozen collection");this.keyMap.set(g.key,g)}removeNode(g){if(this.frozen)throw new Error("Cannot remove a node to a frozen collection");this.keyMap.delete(g)}commit(g,I,i=!1){if(this.frozen)throw new Error("Cannot commit a frozen collection");this.firstKey=g,this.lastKey=I,this.frozen=!i}constructor(){this.keyMap=new Map,this.firstKey=null,this.lastKey=null,this.frozen=!1}}class Jog extends jTe{createElement(g){return new lS(g,this)}getMutableNode(g){let I=g.node;return this.mutatedNodes.has(g)||(I=g.node.clone(),this.mutatedNodes.add(g),g.node=I),this.markDirty(g),I}getMutableCollection(){return!this.isSSR&&!this.collectionMutated&&(this.collection=this.collection.clone(),this.collectionMutated=!0),this.collection}markDirty(g){this.dirtyNodes.add(g)}startTransaction(){this.transactionCount++}endTransaction(){this.transactionCount--}addNode(g){let I=this.getMutableCollection();if(!I.getItem(g.node.key)){I.addNode(g.node);for(let i of g)this.addNode(i)}this.markDirty(g)}removeNode(g){for(let i of g)i.parentNode=null,this.removeNode(i);this.getMutableCollection().removeNode(g.node.key),this.markDirty(g)}getCollection(){return this.transactionCount>0?this.collection:(this.updateCollection(),this.collection)}updateCollection(){for(let C of this.dirtyNodes)C instanceof lS&&C.parentNode&&C.updateNode();if(this.dirtyNodes.clear(),this.mutatedNodes.size){var g,I;let C=this.getMutableCollection();for(let r of this.mutatedNodes)r.parentNode&&C.addNode(r.node);var i,n;C.commit((i=(g=this.firstChild)===null||g===void 0?void 0:g.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 g of this.subscriptions)g()}subscribe(g){return this.subscriptions.add(g),()=>this.subscriptions.delete(g)}resetAfterSSR(){this.isSSR&&(this.isSSR=!1,this.firstChild=null,this.lastChild=null,this.nodeId=0)}constructor(g){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=g,this.collectionMutated=!0}}function Kw(e){let{children:g,items:I,idScope:i,addIdAndValue:n}=e,C=U.useMemo(()=>new WeakMap,[]);return U.useMemo(()=>{if(I&&typeof g=="function"){let a=[];for(let s of I){let A=C.get(s);if(!A){if(A=g(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=U.cloneElement(A,n?{key:l,id:l,value:s}:{key:l})}C.set(s,A)}a.push(A)}return a}else if(typeof g!="function")return g},[g,I,C,i,n])}function xw(e){return Kw({...e,addIdAndValue:!0})}const Oog=U.createContext(!1);function _og(e,g){let{collection:I,document:i}=Qog(g);return{portal:$og(e,i),collection:I}}function Log(e,g,I){let i=kw(),n=U.useRef(i);n.current=i;let C=U.useCallback(()=>n.current?I():g(),[g,I]);return Yog.useSyncExternalStore(e,C)}const Uog=typeof N.useSyncExternalStore=="function"?N.useSyncExternalStore:Log;function Qog(e){let g=U.useMemo(()=>new Jog(e||new $Te),[e]),I=U.useCallback(r=>g.subscribe(r),[g]),i=U.useCallback(()=>{let r=g.getCollection();return g.isSSR&&g.resetAfterSSR(),r},[g]),n=U.useCallback(()=>(g.isSSR=!0,g.getCollection()),[g]);return{collection:Uog(I,i,n),document:g}}const V_=U.createContext(null),jog=U.createContext(null);function $og(e,g){let I=U.useContext(jog),i=g??I,n=xw(e),C=U.useMemo(()=>N.createElement(Oog.Provider,{value:!0},n),[n]);return kw()?N.createElement(V_.Provider,{value:i},C):Aa.createPortal(C,i)}function qog(e,g,I){return U.useCallback(i=>{i==null||i.setProps(e,g,I)},[e,g,I])}function Dw(e,g,I,i,n){let C=qog(g,I,i),r=U.useContext(V_);if(r){let o=r.ownerDocument.nodesByProps.get(g);return o||(o=r.ownerDocument.createElement(e),o.setProps(g,I,i),r.appendChild(o),r.ownerDocument.updateCollection(),r.ownerDocument.nodesByProps.set(g,o)),n?N.createElement(V_.Provider,{value:o},n):null}return N.createElement(e,{ref:C},n)}const eag=U.createContext(null),qTe=U.createContext(null),tag=Symbol("callback"),R_=Symbol("default");function iY({values:e,children:g}){for(let[I,i]of e)g=N.createElement(I.Provider,{value:i},g);return g}function Bm(e){let{className:g,style:I,children:i,defaultClassName:n,defaultChildren:C,values:r}=e;return U.useMemo(()=>{let o,a,s;return typeof g=="function"?o=g(r):o=g,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":""}},[g,I,i,n,C,r])}function gag(e,g){let I=U.useContext(e);if(g===null)return null;if(I&&typeof I=="object"&&"slots"in I&&I.slots){if(!g&&!I.slots[R_])throw new Error("A slot prop is required");let i=g||R_;if(!I.slots[i])throw new Error(`Invalid slot "${g}". Valid slot names are `+new Intl.ListFormat().format(Object.keys(I.slots).map(n=>`"${n}"`))+".");return I.slots[i]}return I}function eNe(e,g,I){let i=gag(I,e.slot)||{},{ref:n,[tag]:C,...r}=i,o=Yw(U.useMemo(()=>VCg(g,n),[g,n])),a=Gi(r,e);return U.useEffect(()=>{C&&C(e)},[C,e]),[a,o]}function Iag(){let[e,g]=U.useState(!0),I=U.useRef(!1),i=U.useCallback(n=>{I.current=!0,g(!!n)},[]);return bi(()=>{I.current||g(!1)},[]),[i,e]}if(typeof HTMLTemplateElement<"u"){const e=Object.getOwnPropertyDescriptor(Node.prototype,"firstChild").get;Object.defineProperty(HTMLTemplateElement.prototype,"firstChild",{configurable:!0,enumerable:!0,get:function(){return this.dataset.reactAriaHidden?this.content.firstChild:e.call(this)}})}typeof DocumentFragment<"u"&&new DocumentFragment;function iag(e){const g=/^(data-.*)$/;let I={};for(const i in e)g.test(i)||(I[i]=e[i]);return I}const nag=U.createContext({}),Cag=U.createContext({}),rag=U.createContext({}),tNe=U.createContext(null),oag=U.createContext({}),gNe=U.createContext(null);function aag(e,g){let{render:I}=U.useContext(gNe);return N.createElement(N.Fragment,null,I(e,g))}const Aag=U.forwardRef(aag),Fw=U.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 sag extends $Te{addNode(g){super.addNode(g),this.columnsDirty||(this.columnsDirty=g.type==="column"),g.type==="tableheader"&&(this.head=g),g.type==="tablebody"&&(this.body=g)}commit(g,I,i=!1){this.updateColumns(i),super.commit(g,I,i)}updateColumns(g){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=QTe(I,this.columns),this.columnsDirty=!1,this.rowHeaderColumnKeys.size===0&&this.columns.length>0&&!g)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 g;return(g=[...this.getChildren(this.body.key)][0])===null||g===void 0?void 0:g.key}getLastKey(){var g;let I=[...this.getChildren(this.body.key)];return(g=I[I.length-1])===null||g===void 0?void 0:g.key}getKeyAfter(g){let I=this.getItem(g);var i;return(I==null?void 0:I.type)==="column"?(i=I.nextKey)!==null&&i!==void 0?i:null:super.getKeyAfter(g)}getKeyBefore(g){var I;let i=this.getItem(g);var n;if((i==null?void 0:i.type)==="column")return(n=i.prevKey)!==null&&n!==void 0?n:null;let C=super.getKeyBefore(g);return C!=null&&((I=this.getItem(C))===null||I===void 0?void 0:I.type)==="tablebody"?null:C}getChildren(g){if(!this.getItem(g)){for(let I of this.headerRows)if(I.key===g)return I.childNodes}return super.getChildren(g)}clone(){let g=super.clone();return g.headerRows=this.headerRows,g.columns=this.columns,g.rowHeaderColumnKeys=this.rowHeaderColumnKeys,g.head=this.head,g.body=this.body,g}getTextValue(g){let I=this.getItem(g);if(!I)return"";if(I.textValue)return I.textValue;let i=this.rowHeaderColumnKeys,n=[];for(let C of this.getChildren(g)){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(...g){super(...g),this.headerRows=[],this.columns=[],this.rowHeaderColumnKeys=new Set,this.head=new sS("tableheader",-1),this.body=new sS("tablebody",-2),this.columnsDirty=!0}}const lag=U.createContext(null),cag=U.createContext(null),Sm=U.createContext(null),INe=U.createContext(null);function uag(e,g){[e,g]=eNe(e,g,cag);let I=U.useMemo(()=>new sag,[]),{portal:i,collection:n}=_og(e,I),C=Pog({...e,collection:n,children:void 0}),{gridProps:r}=bog(e,C,g),{dragAndDropHooks:o}=e,a=C.selectionManager,s=!!(o!=null&&o.useDraggableCollectionState),A=!!(o!=null&&o.useDroppableCollectionState),l=U.useRef(s),c=U.useRef(A);U.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=U.useRef(null);if(s&&o){u=o.useDraggableCollectionState({collection:n,selectionManager:a,preview:o.renderDragPreview?b:void 0}),o.useDraggableCollection({},u,g);let R=o.DragPreview;f=o.renderDragPreview?N.createElement(R,{ref:b},o.renderDragPreview):null}if(A&&o){d=o.useDroppableCollectionState({collection:n,selectionManager:a});let R=new Cog(n,a.disabledBehavior==="selection"?new Set:a.disabledKeys,g),H=o.dropTargetDelegate||new o.ListDropTargetDelegate(n,g);h=o.useDroppableCollection({keyboardDelegate:R,dropTargetDelegate:H},d,g),m=d.isDropTarget({type:"root"})}let{focusProps:p,isFocused:y,isFocusVisible:Z}=tY(),B=Bm({className:e.className,style:e.style,defaultClassName:"react-aria-Table",values:{isDropTarget:m,isFocused:y,isFocusVisible:Z,state:C}}),{selectionBehavior:G,selectionMode:v,disallowEmptySelection:w}=C.selectionManager,V=U.useMemo(()=>({selectionBehavior:v==="none"?null:G,selectionMode:v,disallowEmptySelection:w,allowsDragging:s}),[G,v,w,s]),S=B.style,X=U.useContext(lag),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(hag.Provider,{value:V},i),N.createElement(iY,{values:[[Sm,C],[INe,W],[Fw,{dragAndDropHooks:o,dragState:u,dropState:d}],[gNe,{render:Nag}]]},N.createElement(Grg,null,N.createElement("table",{...YA(e),...B,...Gi(r,p,h==null?void 0:h.collectionProps),style:S,ref:g,slot:e.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(wag,{collection:n}),N.createElement(Vag,{collection:n,isDroppable:A}))),f))}const dag=U.forwardRef(uag),hag=U.createContext(null);function mag(e,g){let I=xw({children:e.children,items:e.columns}),i=typeof e.children=="function"?e.children:null;return N.createElement(qTe.Provider,{value:i},Dw("tableheader",e,g,null,I))}const fag=U.forwardRef(mag);function pag(e,g){let I=U.useContext(qTe),i;typeof I=="function"?i=I:typeof e.children!="function"&&(i=e.children);let n=xw({children:e.title||e.childColumns?i:null,items:e.childColumns});var C;return Dw("column",e,g,(C=e.title)!==null&&C!==void 0?C:e.children,n)}const bag=U.forwardRef(pag);function yag(e,g){let I=xw(e);return Dw("tablebody",e,g,null,I)}const Zag=U.forwardRef(yag);function Gag(e,g){let I=xw({children:e.children,items:e.columns,idScope:e.id}),i=U.useMemo(()=>({idScope:e.id}),[e.id]);return Dw("item",e,g,null,N.createElement(eag.Provider,{value:i},I))}const vag=U.forwardRef(Gag);function Bag(e,g){return Dw("cell",e,g,e.children)}const Sag=U.forwardRef(Bag);function wag({collection:e}){let g=Kw({items:e.headerRows,children:U.useCallback(n=>{switch(n.type){case"headerrow":return N.createElement(Rag,{item:n});default:throw new Error("Unsupported node type in TableHeader: "+n.type)}},[])}),{rowGroupProps:I}=OTe();var i;return N.createElement("thead",{...YA(e.head.props),...I,ref:e.head.props.ref,className:(i=e.head.props.className)!==null&&i!==void 0?i:"react-aria-TableHeader",style:e.head.props.style},g)}function Vag({collection:e,isDroppable:g}){let I=Kw({items:e.rows,children:U.useCallback(o=>{switch(o.type){case"item":return N.createElement(Hag,{item:o});default:throw new Error("Unsupported node type in TableBody: "+o.type)}},[])}),i=e.body.props,n=Bm({...i,id:void 0,children:void 0,defaultClassName:"react-aria-TableBody",values:{isEmpty:e.size===0}}),C;e.size===0&&i.renderEmptyState&&(C=N.createElement("tr",{role:"row"},N.createElement("td",{role:"gridcell",colSpan:e.columnCount},i.renderEmptyState())));let{rowGroupProps:r}=OTe();return N.createElement("tbody",{...Gi(YA(i),r),...n,ref:e.body.props.ref,"data-empty":e.size===0||void 0},g&&N.createElement(Kag,null),I,C)}function Rag({item:e}){let g=U.useRef(null),I=U.useContext(Sm),{rowProps:i}=Gog({node:e},I,g),{checkboxProps:n}=Sog(I),C=Kw({items:I.collection.getChildren(e.key),children:r=>{switch(r.type){case"column":return N.createElement(Xag,{column:r});default:throw new Error("Unsupported node type in Row: "+r.type)}}});return N.createElement("tr",{...i,ref:g},N.createElement(iY,{values:[[tNe,{slots:{selection:n}}]]},C))}const Wag=U.createContext(null);function Xag({column:e}){var g,I;let i=Yw(e.props.ref),n=U.useContext(Sm),{columnHeaderProps:C}=yog({node:e},n,i),{isFocused:r,isFocusVisible:o,focusProps:a}=tY(),{hoverProps:s,isHovered:A}=C8({}),l=U.useContext(INe),c=!1;if(l)c=l.resizingColumn===e.key;else for(let m in["width","defaultWidth","minWidth","maxWidth"])m in e.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=e.props,d=Bm({...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",{...Gi(YA(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(Wag.Provider,{value:{column:e,triggerRef:i}},d.children))}function Hag({item:e}){let g=Yw(e.props.ref),I=U.useContext(Sm),{dragAndDropHooks:i,dragState:n,dropState:C}=U.useContext(Fw),{rowProps:r,...o}=Zog({node:e,shouldSelectOnPressUp:!!n},I,g),{isFocused:a,isFocusVisible:s,focusProps:A}=tY(),{hoverProps:l,isHovered:c}=C8({isDisabled:!o.allowsSelection&&!o.hasAction}),{checkboxProps:u}=Bog({key:e.key},I),d;n&&i&&(d=i.useDraggableItem({key:e.key,hasDragButton:!0},n));let h,m=U.useRef(null),{visuallyHiddenProps:f}=a8();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(Aag,{target:v})),p=U.useRef(null);U.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=vm({...u,id:void 0,children:e.rendered,defaultClassName:"react-aria-Column",values:{isHovered:A,isFocused:C,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",{...GI(YA(u),r,a,s),...d,style:h,colSpan:e.colspan,ref:I,"data-focused":C||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(Kag.Provider,{value:{column:e,triggerRef:I}},d.children))}function Dag({item:e}){let g=Dw(e.props.ref),i=U.useContext(Bm),{dragAndDropHooks:I,dragState:n,dropState:r}=U.useContext(zw),{rowProps:C,...o}=Vog({node:e,shouldSelectOnPressUp:!!n},i,g),{isFocused:a,isFocusVisible:s,focusProps:A}=IY(),{hoverProps:l,isHovered:c}=l8({isDisabled:!o.allowsSelection&&!o.hasAction}),{checkboxProps:u}=Hog({key:e.key},i),d;n&&I&&(d=I.useDraggableItem({key:e.key,hasDragButton:!0},n));let h,m=U.useRef(null),{visuallyHiddenProps:f}=d8();r&&I&&(h=I.useDropIndicator({target:{type:"item",key:e.key,dropPosition:"on"}},r,m));let b=(I==null?void 0:I.renderDropIndicator)||(v=>N.createElement(mag,{target:v})),p=U.useRef(null);U.useEffect(()=>{n&&!p.current&&console.warn('Draggable items in a Table must contain a