board-game-engine 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/board-game-engine.cjs +5 -5
- package/dist/board-game-engine.js +5 -5
- package/dist/board-game-engine.min.js +2 -2
- package/dist/board-game-engine.mjs +5 -5
- package/examples/checkers.json +2 -2
- package/examples/connect-four.json +1 -1
- package/examples/eights.json +15 -15
- package/package.json +1 -1
- package/src/client/client.js +1 -1
- package/src/game-factory/condition/condition.js +1 -1
- package/src/utils/resolve-properties.js +9 -9
|
@@ -4,7 +4,7 @@ This likely means game code is triggering an infinite loop.`,e.PhaseEventInOnEnd
|
|
|
4
4
|
${s}`),[e,r]},p0=({G:e,ctx:t,plugins:n={}},{game:r,playerID:i})=>([...br,...r.plugins].forEach(({name:s,playerView:o})=>{if(!o)return;let{data:a}=n[s]||{data:{}},u=o({G:e,ctx:t,game:r,data:a,playerID:i});n={...n,[s]:{data:u}}}),n);function sa(e,t=!1){e.moveLimit&&(t&&(e.minMoves=e.moveLimit),e.maxMoves=e.moveLimit,delete e.moveLimit)}function oa(e,t){let n={},r=[],i=null,s={},o={};if(Array.isArray(t)){let u={};t.forEach(c=>u[c]=nn.NULL),n=u}else{if(sa(t),t.next&&(i=t.next),t.revert&&(r=[...e._prevActivePlayers,{activePlayers:e.activePlayers,_activePlayersMinMoves:e._activePlayersMinMoves,_activePlayersMaxMoves:e._activePlayersMaxMoves,_activePlayersNumMoves:e._activePlayersNumMoves}]),t.currentPlayer!==void 0&&gs(n,s,o,e.currentPlayer,t.currentPlayer),t.others!==void 0)for(let u=0;u<e.playOrder.length;u++){let c=e.playOrder[u];c!==e.currentPlayer&&gs(n,s,o,c,t.others)}if(t.all!==void 0)for(let u=0;u<e.playOrder.length;u++){let c=e.playOrder[u];gs(n,s,o,c,t.all)}if(t.value)for(let u in t.value)gs(n,s,o,u,t.value[u]);if(t.minMoves)for(let u in n)s[u]===void 0&&(s[u]=t.minMoves);if(t.maxMoves)for(let u in n)o[u]===void 0&&(o[u]=t.maxMoves)}Object.keys(n).length===0&&(n=null),Object.keys(s).length===0&&(s=null),Object.keys(o).length===0&&(o=null);let a={};for(let u in n)a[u]=0;return{...e,activePlayers:n,_activePlayersMinMoves:s,_activePlayersMaxMoves:o,_activePlayersNumMoves:a,_prevActivePlayers:r,_nextActivePlayers:i}}function h0(e){let{activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s,_nextActivePlayers:o}=e;if(t&&Object.keys(t).length===0)if(o)e=oa(e,o),{activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s}=e;else if(s.length>0){let a=s.length-1;({activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i}=s[a]),s=s.slice(0,a)}else t=null,n=null,r=null;return{...e,activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s}}function gs(e,t,n,r,i){(typeof i!="object"||i===nn.NULL)&&(i={stage:i}),i.stage!==void 0&&(sa(i),e[r]=i.stage,i.minMoves&&(t[r]=i.minMoves),i.maxMoves&&(n[r]=i.maxMoves))}function ea(e,t){return e[t]+""}function d0(e,t){let{G:n,ctx:r}=e,{numPlayers:i}=r,o={...ia(e),G:n,ctx:r},a=t.order,u=[...Array.from({length:i})].map((p,h)=>h+"");a.playOrder!==void 0&&(u=a.playOrder(o));let c=a.first(o),l=typeof c;l!=="number"&&Sn(`invalid value returned by turn.order.first \u2014 expected number got ${l} \u201C${c}\u201D.`);let f=ea(u,c);return r={...r,currentPlayer:f,playOrderPos:c,playOrder:u},r=oa(r,t.activePlayers||{}),r}function m0(e,t,n,r){let i=n.order,{G:s,ctx:o}=e,a=o.playOrderPos,u=!1;if(r&&r!==!0)typeof r!="object"&&Sn(`invalid argument to endTurn: ${r}`),Object.keys(r).forEach(c=>{switch(c){case"remove":t=ea(o.playOrder,a);break;case"next":a=o.playOrder.indexOf(r.next),t=r.next;break;default:Sn(`invalid argument to endTurn: ${c}`)}});else{let l={...ia(e),G:s,ctx:o},f=i.next(l),p=typeof f;f!==void 0&&p!=="number"&&Sn(`invalid value returned by turn.order.next \u2014 expected number or undefined got ${p} \u201C${f}\u201D.`),f===void 0?u=!0:(a=f,t=ea(o.playOrder,a))}return o={...o,playOrderPos:a,currentPlayer:t},{endPhase:u,ctx:o}}var g0={DEFAULT:{first:({ctx:e})=>e.turn===0?e.playOrderPos:(e.playOrderPos+1)%e.playOrder.length,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},RESET:{first:()=>0,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},CONTINUE:{first:({ctx:e})=>e.playOrderPos,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},ONCE:{first:()=>0,next:({ctx:e})=>{if(e.playOrderPos<e.playOrder.length-1)return e.playOrderPos+1}},CUSTOM:e=>({playOrder:()=>e,first:()=>0,next:({ctx:t})=>(t.playOrderPos+1)%t.playOrder.length}),CUSTOM_FROM:e=>({playOrder:({G:t})=>t[e],first:()=>0,next:({ctx:t})=>(t.playOrderPos+1)%t.playOrder.length})},nn={NULL:null},y0={ALL:{all:nn.NULL},ALL_ONCE:{all:nn.NULL,minMoves:1,maxMoves:1},OTHERS:{others:nn.NULL},OTHERS_ONCE:{others:nn.NULL,minMoves:1,maxMoves:1}};K.ActionCreators=$_;K.ActivePlayers=y0;K.Enhance=a0;K.FlushAndValidate=f0;K.FnWrap=s0;K.GAME_EVENT=ta;K.GetAPIs=ia;K.INVALID_MOVE=Qo;K.InitTurnOrderState=d0;K.MAKE_MOVE=ql;K.NoClient=c0;K.PATCH=Gl;K.PLUGIN=Fl;K.PlayerView=p0;K.ProcessAction=i0;K.REDO=jl;K.RESET=Dl;K.STRIP_TRANSIENTS=Ul;K.SYNC=Rl;K.SetActivePlayers=oa;K.Setup=o0;K.Stage=nn;K.TurnOrder=g0;K.UNDO=Bl;K.UPDATE=Ll;K.UpdateActivePlayersOnceEmpty=h0;K.UpdateTurnOrderState=m0;K.error=Sn;K.gameEvent=zl;K.info=r0;K.makeMove=Vl;K.patch=Wl;K.redo=Xl;K.reset=Yl;K.stripTransients=Ql;K.supportDeprecatedMoveLimit=sa;K.sync=Hl;K.undo=$l;K.update=Jl});var aa=v(zt=>{"use strict";Object.defineProperty(zt,"__esModule",{value:!0});var _r=Zl();Jo();Xo();tn();var v0={STRIP_SECRETS:({G:e,playerID:t})=>{let n={...e};return n.secret!==void 0&&delete n.secret,n.players&&(n.players=t?{[t]:n.players[t]}:{}),n}};zt.ActivePlayers=_r.ActivePlayers;Object.defineProperty(zt,"GameMethod",{enumerable:!0,get:function(){return _r.GameMethod}});zt.INVALID_MOVE=_r.INVALID_MOVE;zt.Stage=_r.Stage;zt.TurnOrder=_r.TurnOrder;zt.PlayerView=v0});var tf=v((fD,ef)=>{function b0(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),n=n>i?i:n,n<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var s=Array(i);++r<i;)s[r]=e[r+t];return s}ef.exports=b0});var Or=v((pD,nf)=>{function _0(e,t){return e===t||e!==e&&t!==t}nf.exports=_0});var ua=v((hD,rf)=>{var w0=typeof global=="object"&&global&&global.Object===Object&&global;rf.exports=w0});var rt=v((dD,sf)=>{var O0=ua(),P0=typeof self=="object"&&self&&self.Object===Object&&self,E0=O0||P0||Function("return this")();sf.exports=E0});var on=v((mD,of)=>{var k0=rt(),A0=k0.Symbol;of.exports=A0});var lf=v((gD,cf)=>{var af=on(),uf=Object.prototype,x0=uf.hasOwnProperty,S0=uf.toString,Pr=af?af.toStringTag:void 0;function T0(e){var t=x0.call(e,Pr),n=e[Pr];try{e[Pr]=void 0;var r=!0}catch{}var i=S0.call(e);return r&&(t?e[Pr]=n:delete e[Pr]),i}cf.exports=T0});var pf=v((yD,ff)=>{var M0=Object.prototype,I0=M0.toString;function N0(e){return I0.call(e)}ff.exports=N0});var an=v((vD,mf)=>{var hf=on(),C0=lf(),q0=pf(),j0="[object Null]",D0="[object Undefined]",df=hf?hf.toStringTag:void 0;function R0(e){return e==null?e===void 0?D0:j0:df&&df in Object(e)?C0(e):q0(e)}mf.exports=R0});var pt=v((bD,gf)=>{function B0(e){var t=typeof e;return e!=null&&(t=="object"||t=="function")}gf.exports=B0});var ca=v((_D,yf)=>{var L0=an(),G0=pt(),F0="[object AsyncFunction]",U0="[object Function]",V0="[object GeneratorFunction]",z0="[object Proxy]";function K0(e){if(!G0(e))return!1;var t=L0(e);return t==U0||t==V0||t==F0||t==z0}yf.exports=K0});var ys=v((wD,vf)=>{var H0=9007199254740991;function W0(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=H0}vf.exports=W0});var Tn=v((OD,bf)=>{var J0=ca(),Y0=ys();function $0(e){return e!=null&&Y0(e.length)&&!J0(e)}bf.exports=$0});var Er=v((PD,_f)=>{var X0=9007199254740991,Q0=/^(?:0|[1-9]\d*)$/;function Z0(e,t){var n=typeof e;return t=t??X0,!!t&&(n=="number"||n!="symbol"&&Q0.test(e))&&e>-1&&e%1==0&&e<t}_f.exports=Z0});var Of=v((ED,wf)=>{var ew=Or(),tw=Tn(),nw=Er(),rw=pt();function iw(e,t,n){if(!rw(n))return!1;var r=typeof t;return(r=="number"?tw(n)&&nw(t,n.length):r=="string"&&t in n)?ew(n[t],e):!1}wf.exports=iw});var Ef=v((kD,Pf)=>{var sw=/\s/;function ow(e){for(var t=e.length;t--&&sw.test(e.charAt(t)););return t}Pf.exports=ow});var Af=v((AD,kf)=>{var aw=Ef(),uw=/^\s+/;function cw(e){return e&&e.slice(0,aw(e)+1).replace(uw,"")}kf.exports=cw});var kt=v((xD,xf)=>{function lw(e){return e!=null&&typeof e=="object"}xf.exports=lw});var kr=v((SD,Sf)=>{var fw=an(),pw=kt(),hw="[object Symbol]";function dw(e){return typeof e=="symbol"||pw(e)&&fw(e)==hw}Sf.exports=dw});var Nf=v((TD,If)=>{var mw=Af(),Tf=pt(),gw=kr(),Mf=NaN,yw=/^[-+]0x[0-9a-f]+$/i,vw=/^0b[01]+$/i,bw=/^0o[0-7]+$/i,_w=parseInt;function ww(e){if(typeof e=="number")return e;if(gw(e))return Mf;if(Tf(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Tf(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=mw(e);var n=vw.test(e);return n||bw.test(e)?_w(e.slice(2),n?2:8):yw.test(e)?Mf:+e}If.exports=ww});var jf=v((MD,qf)=>{var Ow=Nf(),Cf=1/0,Pw=17976931348623157e292;function Ew(e){if(!e)return e===0?e:0;if(e=Ow(e),e===Cf||e===-Cf){var t=e<0?-1:1;return t*Pw}return e===e?e:0}qf.exports=Ew});var la=v((ID,Df)=>{var kw=jf();function Aw(e){var t=kw(e),n=t%1;return t===t?n?t-n:t:0}Df.exports=Aw});var Bf=v((ND,Rf)=>{var xw=tf(),Sw=Of(),Tw=la(),Mw=Math.ceil,Iw=Math.max;function Nw(e,t,n){(n?Sw(e,t,n):t===void 0)?t=1:t=Iw(Tw(t),0);var r=e==null?0:e.length;if(!r||t<1)return[];for(var i=0,s=0,o=Array(Mw(r/t));i<r;)o[s++]=xw(e,i,i+=t);return o}Rf.exports=Nw});var Ff=v((jD,Gf)=>{function Cw(){this.__data__=[],this.size=0}Gf.exports=Cw});var xr=v((DD,Uf)=>{var qw=Or();function jw(e,t){for(var n=e.length;n--;)if(qw(e[n][0],t))return n;return-1}Uf.exports=jw});var zf=v((RD,Vf)=>{var Dw=xr(),Rw=Array.prototype,Bw=Rw.splice;function Lw(e){var t=this.__data__,n=Dw(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():Bw.call(t,n,1),--this.size,!0}Vf.exports=Lw});var Hf=v((BD,Kf)=>{var Gw=xr();function Fw(e){var t=this.__data__,n=Gw(t,e);return n<0?void 0:t[n][1]}Kf.exports=Fw});var Jf=v((LD,Wf)=>{var Uw=xr();function Vw(e){return Uw(this.__data__,e)>-1}Wf.exports=Vw});var $f=v((GD,Yf)=>{var zw=xr();function Kw(e,t){var n=this.__data__,r=zw(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}Yf.exports=Kw});var Sr=v((FD,Xf)=>{var Hw=Ff(),Ww=zf(),Jw=Hf(),Yw=Jf(),$w=$f();function Mn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Mn.prototype.clear=Hw;Mn.prototype.delete=Ww;Mn.prototype.get=Jw;Mn.prototype.has=Yw;Mn.prototype.set=$w;Xf.exports=Mn});var Zf=v((UD,Qf)=>{var Xw=Sr();function Qw(){this.__data__=new Xw,this.size=0}Qf.exports=Qw});var tp=v((VD,ep)=>{function Zw(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}ep.exports=Zw});var rp=v((zD,np)=>{function eO(e){return this.__data__.get(e)}np.exports=eO});var sp=v((KD,ip)=>{function tO(e){return this.__data__.has(e)}ip.exports=tO});var ap=v((HD,op)=>{var nO=rt(),rO=nO["__core-js_shared__"];op.exports=rO});var lp=v((WD,cp)=>{var fa=ap(),up=function(){var e=/[^.]+$/.exec(fa&&fa.keys&&fa.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function iO(e){return!!up&&up in e}cp.exports=iO});var pa=v((JD,fp)=>{var sO=Function.prototype,oO=sO.toString;function aO(e){if(e!=null){try{return oO.call(e)}catch{}try{return e+""}catch{}}return""}fp.exports=aO});var hp=v((YD,pp)=>{var uO=ca(),cO=lp(),lO=pt(),fO=pa(),pO=/[\\^$.*+?()[\]{}|]/g,hO=/^\[object .+?Constructor\]$/,dO=Function.prototype,mO=Object.prototype,gO=dO.toString,yO=mO.hasOwnProperty,vO=RegExp("^"+gO.call(yO).replace(pO,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function bO(e){if(!lO(e)||cO(e))return!1;var t=uO(e)?vO:hO;return t.test(fO(e))}pp.exports=bO});var mp=v(($D,dp)=>{function _O(e,t){return e?.[t]}dp.exports=_O});var Kt=v((XD,gp)=>{var wO=hp(),OO=mp();function PO(e,t){var n=OO(e,t);return wO(n)?n:void 0}gp.exports=PO});var vs=v((QD,yp)=>{var EO=Kt(),kO=rt(),AO=EO(kO,"Map");yp.exports=AO});var Tr=v((ZD,vp)=>{var xO=Kt(),SO=xO(Object,"create");vp.exports=SO});var wp=v((eR,_p)=>{var bp=Tr();function TO(){this.__data__=bp?bp(null):{},this.size=0}_p.exports=TO});var Pp=v((tR,Op)=>{function MO(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}Op.exports=MO});var kp=v((nR,Ep)=>{var IO=Tr(),NO="__lodash_hash_undefined__",CO=Object.prototype,qO=CO.hasOwnProperty;function jO(e){var t=this.__data__;if(IO){var n=t[e];return n===NO?void 0:n}return qO.call(t,e)?t[e]:void 0}Ep.exports=jO});var xp=v((rR,Ap)=>{var DO=Tr(),RO=Object.prototype,BO=RO.hasOwnProperty;function LO(e){var t=this.__data__;return DO?t[e]!==void 0:BO.call(t,e)}Ap.exports=LO});var Tp=v((iR,Sp)=>{var GO=Tr(),FO="__lodash_hash_undefined__";function UO(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=GO&&t===void 0?FO:t,this}Sp.exports=UO});var Ip=v((sR,Mp)=>{var VO=wp(),zO=Pp(),KO=kp(),HO=xp(),WO=Tp();function In(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}In.prototype.clear=VO;In.prototype.delete=zO;In.prototype.get=KO;In.prototype.has=HO;In.prototype.set=WO;Mp.exports=In});var qp=v((oR,Cp)=>{var Np=Ip(),JO=Sr(),YO=vs();function $O(){this.size=0,this.__data__={hash:new Np,map:new(YO||JO),string:new Np}}Cp.exports=$O});var Dp=v((aR,jp)=>{function XO(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}jp.exports=XO});var Mr=v((uR,Rp)=>{var QO=Dp();function ZO(e,t){var n=e.__data__;return QO(t)?n[typeof t=="string"?"string":"hash"]:n.map}Rp.exports=ZO});var Lp=v((cR,Bp)=>{var eP=Mr();function tP(e){var t=eP(this,e).delete(e);return this.size-=t?1:0,t}Bp.exports=tP});var Fp=v((lR,Gp)=>{var nP=Mr();function rP(e){return nP(this,e).get(e)}Gp.exports=rP});var Vp=v((fR,Up)=>{var iP=Mr();function sP(e){return iP(this,e).has(e)}Up.exports=sP});var Kp=v((pR,zp)=>{var oP=Mr();function aP(e,t){var n=oP(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}zp.exports=aP});var bs=v((hR,Hp)=>{var uP=qp(),cP=Lp(),lP=Fp(),fP=Vp(),pP=Kp();function Nn(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Nn.prototype.clear=uP;Nn.prototype.delete=cP;Nn.prototype.get=lP;Nn.prototype.has=fP;Nn.prototype.set=pP;Hp.exports=Nn});var Jp=v((dR,Wp)=>{var hP=Sr(),dP=vs(),mP=bs(),gP=200;function yP(e,t){var n=this.__data__;if(n instanceof hP){var r=n.__data__;if(!dP||r.length<gP-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new mP(r)}return n.set(e,t),this.size=n.size,this}Wp.exports=yP});var _s=v((mR,Yp)=>{var vP=Sr(),bP=Zf(),_P=tp(),wP=rp(),OP=sp(),PP=Jp();function Cn(e){var t=this.__data__=new vP(e);this.size=t.size}Cn.prototype.clear=bP;Cn.prototype.delete=_P;Cn.prototype.get=wP;Cn.prototype.has=OP;Cn.prototype.set=PP;Yp.exports=Cn});var Xp=v((gR,$p)=>{var EP="__lodash_hash_undefined__";function kP(e){return this.__data__.set(e,EP),this}$p.exports=kP});var Zp=v((yR,Qp)=>{function AP(e){return this.__data__.has(e)}Qp.exports=AP});var th=v((vR,eh)=>{var xP=bs(),SP=Xp(),TP=Zp();function ws(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new xP;++t<n;)this.add(e[t])}ws.prototype.add=ws.prototype.push=SP;ws.prototype.has=TP;eh.exports=ws});var rh=v((bR,nh)=>{function MP(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}nh.exports=MP});var sh=v((_R,ih)=>{function IP(e,t){return e.has(t)}ih.exports=IP});var ha=v((wR,oh)=>{var NP=th(),CP=rh(),qP=sh(),jP=1,DP=2;function RP(e,t,n,r,i,s){var o=n&jP,a=e.length,u=t.length;if(a!=u&&!(o&&u>a))return!1;var c=s.get(e),l=s.get(t);if(c&&l)return c==t&&l==e;var f=-1,p=!0,h=n&DP?new NP:void 0;for(s.set(e,t),s.set(t,e);++f<a;){var d=e[f],y=t[f];if(r)var m=o?r(y,d,f,t,e,s):r(d,y,f,e,t,s);if(m!==void 0){if(m)continue;p=!1;break}if(h){if(!CP(t,function(b,g){if(!qP(h,g)&&(d===b||i(d,b,n,r,s)))return h.push(g)})){p=!1;break}}else if(!(d===y||i(d,y,n,r,s))){p=!1;break}}return s.delete(e),s.delete(t),p}oh.exports=RP});var da=v((OR,ah)=>{var BP=rt(),LP=BP.Uint8Array;ah.exports=LP});var ch=v((PR,uh)=>{function GP(e){var t=-1,n=Array(e.size);return e.forEach(function(r,i){n[++t]=[i,r]}),n}uh.exports=GP});var fh=v((ER,lh)=>{function FP(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}lh.exports=FP});var gh=v((kR,mh)=>{var ph=on(),hh=da(),UP=Or(),VP=ha(),zP=ch(),KP=fh(),HP=1,WP=2,JP="[object Boolean]",YP="[object Date]",$P="[object Error]",XP="[object Map]",QP="[object Number]",ZP="[object RegExp]",eE="[object Set]",tE="[object String]",nE="[object Symbol]",rE="[object ArrayBuffer]",iE="[object DataView]",dh=ph?ph.prototype:void 0,ma=dh?dh.valueOf:void 0;function sE(e,t,n,r,i,s,o){switch(n){case iE:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case rE:return!(e.byteLength!=t.byteLength||!s(new hh(e),new hh(t)));case JP:case YP:case QP:return UP(+e,+t);case $P:return e.name==t.name&&e.message==t.message;case ZP:case tE:return e==t+"";case XP:var a=zP;case eE:var u=r&HP;if(a||(a=KP),e.size!=t.size&&!u)return!1;var c=o.get(e);if(c)return c==t;r|=WP,o.set(e,t);var l=VP(a(e),a(t),r,i,s,o);return o.delete(e),l;case nE:if(ma)return ma.call(e)==ma.call(t)}return!1}mh.exports=sE});var Os=v((AR,yh)=>{function oE(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}yh.exports=oE});var et=v((xR,vh)=>{var aE=Array.isArray;vh.exports=aE});var ga=v((SR,bh)=>{var uE=Os(),cE=et();function lE(e,t,n){var r=t(e);return cE(e)?r:uE(r,n(e))}bh.exports=lE});var ya=v((TR,_h)=>{function fE(e,t){for(var n=-1,r=e==null?0:e.length,i=0,s=[];++n<r;){var o=e[n];t(o,n,e)&&(s[i++]=o)}return s}_h.exports=fE});var va=v((MR,wh)=>{function pE(){return[]}wh.exports=pE});var Ps=v((IR,Ph)=>{var hE=ya(),dE=va(),mE=Object.prototype,gE=mE.propertyIsEnumerable,Oh=Object.getOwnPropertySymbols,yE=Oh?function(e){return e==null?[]:(e=Object(e),hE(Oh(e),function(t){return gE.call(e,t)}))}:dE;Ph.exports=yE});var kh=v((NR,Eh)=>{function vE(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}Eh.exports=vE});var xh=v((CR,Ah)=>{var bE=an(),_E=kt(),wE="[object Arguments]";function OE(e){return _E(e)&&bE(e)==wE}Ah.exports=OE});var Es=v((qR,Mh)=>{var Sh=xh(),PE=kt(),Th=Object.prototype,EE=Th.hasOwnProperty,kE=Th.propertyIsEnumerable,AE=Sh(function(){return arguments}())?Sh:function(e){return PE(e)&&EE.call(e,"callee")&&!kE.call(e,"callee")};Mh.exports=AE});var Nh=v((jR,Ih)=>{function xE(){return!1}Ih.exports=xE});var ks=v((Ir,qn)=>{var SE=rt(),TE=Nh(),jh=typeof Ir=="object"&&Ir&&!Ir.nodeType&&Ir,Ch=jh&&typeof qn=="object"&&qn&&!qn.nodeType&&qn,ME=Ch&&Ch.exports===jh,qh=ME?SE.Buffer:void 0,IE=qh?qh.isBuffer:void 0,NE=IE||TE;qn.exports=NE});var Rh=v((DR,Dh)=>{var CE=an(),qE=ys(),jE=kt(),DE="[object Arguments]",RE="[object Array]",BE="[object Boolean]",LE="[object Date]",GE="[object Error]",FE="[object Function]",UE="[object Map]",VE="[object Number]",zE="[object Object]",KE="[object RegExp]",HE="[object Set]",WE="[object String]",JE="[object WeakMap]",YE="[object ArrayBuffer]",$E="[object DataView]",XE="[object Float32Array]",QE="[object Float64Array]",ZE="[object Int8Array]",ek="[object Int16Array]",tk="[object Int32Array]",nk="[object Uint8Array]",rk="[object Uint8ClampedArray]",ik="[object Uint16Array]",sk="[object Uint32Array]",be={};be[XE]=be[QE]=be[ZE]=be[ek]=be[tk]=be[nk]=be[rk]=be[ik]=be[sk]=!0;be[DE]=be[RE]=be[YE]=be[BE]=be[$E]=be[LE]=be[GE]=be[FE]=be[UE]=be[VE]=be[zE]=be[KE]=be[HE]=be[WE]=be[JE]=!1;function ok(e){return jE(e)&&qE(e.length)&&!!be[CE(e)]}Dh.exports=ok});var As=v((RR,Bh)=>{function ak(e){return function(t){return e(t)}}Bh.exports=ak});var xs=v((Nr,jn)=>{var uk=ua(),Lh=typeof Nr=="object"&&Nr&&!Nr.nodeType&&Nr,Cr=Lh&&typeof jn=="object"&&jn&&!jn.nodeType&&jn,ck=Cr&&Cr.exports===Lh,ba=ck&&uk.process,lk=function(){try{var e=Cr&&Cr.require&&Cr.require("util").types;return e||ba&&ba.binding&&ba.binding("util")}catch{}}();jn.exports=lk});var _a=v((BR,Uh)=>{var fk=Rh(),pk=As(),Gh=xs(),Fh=Gh&&Gh.isTypedArray,hk=Fh?pk(Fh):fk;Uh.exports=hk});var wa=v((LR,Vh)=>{var dk=kh(),mk=Es(),gk=et(),yk=ks(),vk=Er(),bk=_a(),_k=Object.prototype,wk=_k.hasOwnProperty;function Ok(e,t){var n=gk(e),r=!n&&mk(e),i=!n&&!r&&yk(e),s=!n&&!r&&!i&&bk(e),o=n||r||i||s,a=o?dk(e.length,String):[],u=a.length;for(var c in e)(t||wk.call(e,c))&&!(o&&(c=="length"||i&&(c=="offset"||c=="parent")||s&&(c=="buffer"||c=="byteLength"||c=="byteOffset")||vk(c,u)))&&a.push(c);return a}Vh.exports=Ok});var Ss=v((GR,zh)=>{var Pk=Object.prototype;function Ek(e){var t=e&&e.constructor,n=typeof t=="function"&&t.prototype||Pk;return e===n}zh.exports=Ek});var Oa=v((FR,Kh)=>{function kk(e,t){return function(n){return e(t(n))}}Kh.exports=kk});var Wh=v((UR,Hh)=>{var Ak=Oa(),xk=Ak(Object.keys,Object);Hh.exports=xk});var Yh=v((VR,Jh)=>{var Sk=Ss(),Tk=Wh(),Mk=Object.prototype,Ik=Mk.hasOwnProperty;function Nk(e){if(!Sk(e))return Tk(e);var t=[];for(var n in Object(e))Ik.call(e,n)&&n!="constructor"&&t.push(n);return t}Jh.exports=Nk});var un=v((zR,$h)=>{var Ck=wa(),qk=Yh(),jk=Tn();function Dk(e){return jk(e)?Ck(e):qk(e)}$h.exports=Dk});var Pa=v((KR,Xh)=>{var Rk=ga(),Bk=Ps(),Lk=un();function Gk(e){return Rk(e,Lk,Bk)}Xh.exports=Gk});var ed=v((HR,Zh)=>{var Qh=Pa(),Fk=1,Uk=Object.prototype,Vk=Uk.hasOwnProperty;function zk(e,t,n,r,i,s){var o=n&Fk,a=Qh(e),u=a.length,c=Qh(t),l=c.length;if(u!=l&&!o)return!1;for(var f=u;f--;){var p=a[f];if(!(o?p in t:Vk.call(t,p)))return!1}var h=s.get(e),d=s.get(t);if(h&&d)return h==t&&d==e;var y=!0;s.set(e,t),s.set(t,e);for(var m=o;++f<u;){p=a[f];var b=e[p],g=t[p];if(r)var O=o?r(g,b,p,t,e,s):r(b,g,p,e,t,s);if(!(O===void 0?b===g||i(b,g,n,r,s):O)){y=!1;break}m||(m=p=="constructor")}if(y&&!m){var I=e.constructor,j=t.constructor;I!=j&&"constructor"in e&&"constructor"in t&&!(typeof I=="function"&&I instanceof I&&typeof j=="function"&&j instanceof j)&&(y=!1)}return s.delete(e),s.delete(t),y}Zh.exports=zk});var nd=v((WR,td)=>{var Kk=Kt(),Hk=rt(),Wk=Kk(Hk,"DataView");td.exports=Wk});var id=v((JR,rd)=>{var Jk=Kt(),Yk=rt(),$k=Jk(Yk,"Promise");rd.exports=$k});var od=v((YR,sd)=>{var Xk=Kt(),Qk=rt(),Zk=Xk(Qk,"Set");sd.exports=Zk});var ud=v(($R,ad)=>{var eA=Kt(),tA=rt(),nA=eA(tA,"WeakMap");ad.exports=nA});var qr=v((XR,md)=>{var Ea=nd(),ka=vs(),Aa=id(),xa=od(),Sa=ud(),dd=an(),Dn=pa(),cd="[object Map]",rA="[object Object]",ld="[object Promise]",fd="[object Set]",pd="[object WeakMap]",hd="[object DataView]",iA=Dn(Ea),sA=Dn(ka),oA=Dn(Aa),aA=Dn(xa),uA=Dn(Sa),cn=dd;(Ea&&cn(new Ea(new ArrayBuffer(1)))!=hd||ka&&cn(new ka)!=cd||Aa&&cn(Aa.resolve())!=ld||xa&&cn(new xa)!=fd||Sa&&cn(new Sa)!=pd)&&(cn=function(e){var t=dd(e),n=t==rA?e.constructor:void 0,r=n?Dn(n):"";if(r)switch(r){case iA:return hd;case sA:return cd;case oA:return ld;case aA:return fd;case uA:return pd}return t});md.exports=cn});var Pd=v((QR,Od)=>{var Ta=_s(),cA=ha(),lA=gh(),fA=ed(),gd=qr(),yd=et(),vd=ks(),pA=_a(),hA=1,bd="[object Arguments]",_d="[object Array]",Ts="[object Object]",dA=Object.prototype,wd=dA.hasOwnProperty;function mA(e,t,n,r,i,s){var o=yd(e),a=yd(t),u=o?_d:gd(e),c=a?_d:gd(t);u=u==bd?Ts:u,c=c==bd?Ts:c;var l=u==Ts,f=c==Ts,p=u==c;if(p&&vd(e)){if(!vd(t))return!1;o=!0,l=!1}if(p&&!l)return s||(s=new Ta),o||pA(e)?cA(e,t,n,r,i,s):lA(e,t,u,n,r,i,s);if(!(n&hA)){var h=l&&wd.call(e,"__wrapped__"),d=f&&wd.call(t,"__wrapped__");if(h||d){var y=h?e.value():e,m=d?t.value():t;return s||(s=new Ta),i(y,m,n,r,s)}}return p?(s||(s=new Ta),fA(e,t,n,r,i,s)):!1}Od.exports=mA});var Ma=v((ZR,Ad)=>{var gA=Pd(),Ed=kt();function kd(e,t,n,r,i){return e===t?!0:e==null||t==null||!Ed(e)&&!Ed(t)?e!==e&&t!==t:gA(e,t,n,r,kd,i)}Ad.exports=kd});var Sd=v((e4,xd)=>{var yA=_s(),vA=Ma(),bA=1,_A=2;function wA(e,t,n,r){var i=n.length,s=i,o=!r;if(e==null)return!s;for(e=Object(e);i--;){var a=n[i];if(o&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++i<s;){a=n[i];var u=a[0],c=e[u],l=a[1];if(o&&a[2]){if(c===void 0&&!(u in e))return!1}else{var f=new yA;if(r)var p=r(c,l,u,e,t,f);if(!(p===void 0?vA(l,c,bA|_A,r,f):p))return!1}}return!0}xd.exports=wA});var Ia=v((t4,Td)=>{var OA=pt();function PA(e){return e===e&&!OA(e)}Td.exports=PA});var Id=v((n4,Md)=>{var EA=Ia(),kA=un();function AA(e){for(var t=kA(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,EA(i)]}return t}Md.exports=AA});var Na=v((r4,Nd)=>{function xA(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}Nd.exports=xA});var Ca=v((i4,Cd)=>{var SA=Sd(),TA=Id(),MA=Na();function IA(e){var t=TA(e);return t.length==1&&t[0][2]?MA(t[0][0],t[0][1]):function(n){return n===e||SA(n,e,t)}}Cd.exports=IA});var Ms=v((s4,qd)=>{var NA=et(),CA=kr(),qA=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,jA=/^\w*$/;function DA(e,t){if(NA(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||CA(e)?!0:jA.test(e)||!qA.test(e)||t!=null&&e in Object(t)}qd.exports=DA});var Rd=v((o4,Dd)=>{var jd=bs(),RA="Expected a function";function qa(e,t){if(typeof e!="function"||t!=null&&typeof t!="function")throw new TypeError(RA);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],s=n.cache;if(s.has(i))return s.get(i);var o=e.apply(this,r);return n.cache=s.set(i,o)||s,o};return n.cache=new(qa.Cache||jd),n}qa.Cache=jd;Dd.exports=qa});var Ld=v((a4,Bd)=>{var BA=Rd(),LA=500;function GA(e){var t=BA(e,function(r){return n.size===LA&&n.clear(),r}),n=t.cache;return t}Bd.exports=GA});var Fd=v((u4,Gd)=>{var FA=Ld(),UA=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,VA=/\\(\\)?/g,zA=FA(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(""),e.replace(UA,function(n,r,i,s){t.push(i?s.replace(VA,"$1"):r||n)}),t});Gd.exports=zA});var Vd=v((c4,Ud)=>{function KA(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}Ud.exports=KA});var Yd=v((l4,Jd)=>{var zd=on(),HA=Vd(),WA=et(),JA=kr(),YA=1/0,Kd=zd?zd.prototype:void 0,Hd=Kd?Kd.toString:void 0;function Wd(e){if(typeof e=="string")return e;if(WA(e))return HA(e,Wd)+"";if(JA(e))return Hd?Hd.call(e):"";var t=e+"";return t=="0"&&1/e==-YA?"-0":t}Jd.exports=Wd});var Xd=v((f4,$d)=>{var $A=Yd();function XA(e){return e==null?"":$A(e)}$d.exports=XA});var jr=v((p4,Qd)=>{var QA=et(),ZA=Ms(),ex=Fd(),tx=Xd();function nx(e,t){return QA(e)?e:ZA(e,t)?[e]:ex(tx(e))}Qd.exports=nx});var Rn=v((h4,Zd)=>{var rx=kr(),ix=1/0;function sx(e){if(typeof e=="string"||rx(e))return e;var t=e+"";return t=="0"&&1/e==-ix?"-0":t}Zd.exports=sx});var Is=v((d4,em)=>{var ox=jr(),ax=Rn();function ux(e,t){t=ox(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[ax(t[n++])];return n&&n==r?e:void 0}em.exports=ux});var nm=v((m4,tm)=>{var cx=Is();function lx(e,t,n){var r=e==null?void 0:cx(e,t);return r===void 0?n:r}tm.exports=lx});var im=v((g4,rm)=>{function fx(e,t){return e!=null&&t in Object(e)}rm.exports=fx});var om=v((y4,sm)=>{var px=jr(),hx=Es(),dx=et(),mx=Er(),gx=ys(),yx=Rn();function vx(e,t,n){t=px(t,e);for(var r=-1,i=t.length,s=!1;++r<i;){var o=yx(t[r]);if(!(s=e!=null&&n(e,o)))break;e=e[o]}return s||++r!=i?s:(i=e==null?0:e.length,!!i&&gx(i)&&mx(o,i)&&(dx(e)||hx(e)))}sm.exports=vx});var ja=v((v4,am)=>{var bx=im(),_x=om();function wx(e,t){return e!=null&&_x(e,t,bx)}am.exports=wx});var cm=v((b4,um)=>{var Ox=Ma(),Px=nm(),Ex=ja(),kx=Ms(),Ax=Ia(),xx=Na(),Sx=Rn(),Tx=1,Mx=2;function Ix(e,t){return kx(e)&&Ax(t)?xx(Sx(e),t):function(n){var r=Px(n,e);return r===void 0&&r===t?Ex(n,e):Ox(t,r,Tx|Mx)}}um.exports=Ix});var Da=v((_4,lm)=>{function Nx(e){return e}lm.exports=Nx});var pm=v((w4,fm)=>{function Cx(e){return function(t){return t?.[e]}}fm.exports=Cx});var dm=v((O4,hm)=>{var qx=Is();function jx(e){return function(t){return qx(t,e)}}hm.exports=jx});var gm=v((P4,mm)=>{var Dx=pm(),Rx=dm(),Bx=Ms(),Lx=Rn();function Gx(e){return Bx(e)?Dx(Lx(e)):Rx(e)}mm.exports=Gx});var Ns=v((E4,ym)=>{var Fx=Ca(),Ux=cm(),Vx=Da(),zx=et(),Kx=gm();function Hx(e){return typeof e=="function"?e:e==null?Vx:typeof e=="object"?zx(e)?Ux(e[0],e[1]):Fx(e):Kx(e)}ym.exports=Hx});var bm=v((k4,vm)=>{var Wx=Ns(),Jx=Tn(),Yx=un();function $x(e){return function(t,n,r){var i=Object(t);if(!Jx(t)){var s=Wx(n,3);t=Yx(t),n=function(a){return s(i[a],a,i)}}var o=e(t,n,r);return o>-1?i[s?t[o]:o]:void 0}}vm.exports=$x});var wm=v((A4,_m)=>{function Xx(e,t,n,r){for(var i=e.length,s=n+(r?1:-1);r?s--:++s<i;)if(t(e[s],s,e))return s;return-1}_m.exports=Xx});var Pm=v((x4,Om)=>{var Qx=wm(),Zx=Ns(),eS=la(),tS=Math.max;function nS(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=n==null?0:eS(n);return i<0&&(i=tS(r+i,0)),Qx(e,Zx(t,3),i)}Om.exports=nS});var Ra=v((S4,Em)=>{var rS=bm(),iS=Pm(),sS=rS(iS);Em.exports=sS});var Am=v((T4,km)=>{function oS(e){return function(t,n,r){for(var i=-1,s=Object(t),o=r(t),a=o.length;a--;){var u=o[e?a:++i];if(n(s[u],u,s)===!1)break}return t}}km.exports=oS});var Sm=v((M4,xm)=>{var aS=Am(),uS=aS();xm.exports=uS});var Mm=v((I4,Tm)=>{var cS=Sm(),lS=un();function fS(e,t){return e&&cS(e,t,lS)}Tm.exports=fS});var Nm=v((N4,Im)=>{var pS=Tn();function hS(e,t){return function(n,r){if(n==null)return n;if(!pS(n))return e(n,r);for(var i=n.length,s=t?i:-1,o=Object(n);(t?s--:++s<i)&&r(o[s],s,o)!==!1;);return n}}Im.exports=hS});var qm=v((C4,Cm)=>{var dS=Mm(),mS=Nm(),gS=mS(dS);Cm.exports=gS});var Dm=v((q4,jm)=>{var yS=qm();function vS(e,t){var n=[];return yS(e,function(r,i,s){t(r,i,s)&&n.push(r)}),n}jm.exports=vS});var Bm=v((j4,Rm)=>{var bS=ya(),_S=Dm(),wS=Ns(),OS=et();function PS(e,t){var n=OS(e)?bS:_S;return n(e,wS(t,3))}Rm.exports=PS});var Cs=v((D4,Lm)=>{var ES=Oa(),kS=ES(Object.getPrototypeOf,Object);Lm.exports=kS});var qs=v((R4,Fm)=>{var AS=an(),xS=Cs(),SS=kt(),TS="[object Object]",MS=Function.prototype,IS=Object.prototype,Gm=MS.toString,NS=IS.hasOwnProperty,CS=Gm.call(Object);function qS(e){if(!SS(e)||AS(e)!=TS)return!1;var t=xS(e);if(t===null)return!0;var n=NS.call(t,"constructor")&&t.constructor;return typeof n=="function"&&n instanceof n&&Gm.call(n)==CS}Fm.exports=qS});var Ba=v((B4,Um)=>{var jS=Kt(),DS=function(){try{var e=jS(Object,"defineProperty");return e({},"",{}),e}catch{}}();Um.exports=DS});var La=v((L4,zm)=>{var Vm=Ba();function RS(e,t,n){t=="__proto__"&&Vm?Vm(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}zm.exports=RS});var js=v((G4,Km)=>{var BS=La(),LS=Or(),GS=Object.prototype,FS=GS.hasOwnProperty;function US(e,t,n){var r=e[t];(!(FS.call(e,t)&&LS(r,n))||n===void 0&&!(t in e))&&BS(e,t,n)}Km.exports=US});var Jm=v((F4,Wm)=>{var VS=js(),zS=jr(),KS=Er(),Hm=pt(),HS=Rn();function WS(e,t,n,r){if(!Hm(e))return e;t=zS(t,e);for(var i=-1,s=t.length,o=s-1,a=e;a!=null&&++i<s;){var u=HS(t[i]),c=n;if(u==="__proto__"||u==="constructor"||u==="prototype")return e;if(i!=o){var l=a[u];c=r?r(l,u,a):void 0,c===void 0&&(c=Hm(l)?l:KS(t[i+1])?[]:{})}VS(a,u,c),a=a[u]}return e}Wm.exports=WS});var $m=v((U4,Ym)=>{var JS=Is(),YS=Jm(),$S=jr();function XS(e,t,n){for(var r=-1,i=t.length,s={};++r<i;){var o=t[r],a=JS(e,o);n(a,o)&&YS(s,$S(o,e),a)}return s}Ym.exports=XS});var Qm=v((V4,Xm)=>{var QS=$m(),ZS=ja();function eT(e,t){return QS(e,t,function(n,r){return ZS(e,r)})}Xm.exports=eT});var ng=v((z4,tg)=>{var Zm=on(),tT=Es(),nT=et(),eg=Zm?Zm.isConcatSpreadable:void 0;function rT(e){return nT(e)||tT(e)||!!(eg&&e&&e[eg])}tg.exports=rT});var sg=v((K4,ig)=>{var iT=Os(),sT=ng();function rg(e,t,n,r,i){var s=-1,o=e.length;for(n||(n=sT),i||(i=[]);++s<o;){var a=e[s];t>0&&n(a)?t>1?rg(a,t-1,n,r,i):iT(i,a):r||(i[i.length]=a)}return i}ig.exports=rg});var ag=v((H4,og)=>{var oT=sg();function aT(e){var t=e==null?0:e.length;return t?oT(e,1):[]}og.exports=aT});var cg=v((W4,ug)=>{function uT(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}ug.exports=uT});var pg=v((J4,fg)=>{var cT=cg(),lg=Math.max;function lT(e,t,n){return t=lg(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,s=lg(r.length-t,0),o=Array(s);++i<s;)o[i]=r[t+i];i=-1;for(var a=Array(t+1);++i<t;)a[i]=r[i];return a[t]=n(o),cT(e,this,a)}}fg.exports=lT});var dg=v((Y4,hg)=>{function fT(e){return function(){return e}}hg.exports=fT});var yg=v(($4,gg)=>{var pT=dg(),mg=Ba(),hT=Da(),dT=mg?function(e,t){return mg(e,"toString",{configurable:!0,enumerable:!1,value:pT(t),writable:!0})}:hT;gg.exports=dT});var bg=v((X4,vg)=>{var mT=800,gT=16,yT=Date.now;function vT(e){var t=0,n=0;return function(){var r=yT(),i=gT-(r-n);if(n=r,i>0){if(++t>=mT)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}vg.exports=vT});var wg=v((Q4,_g)=>{var bT=yg(),_T=bg(),wT=_T(bT);_g.exports=wT});var Pg=v((Z4,Og)=>{var OT=ag(),PT=pg(),ET=wg();function kT(e){return ET(PT(e,void 0,OT),e+"")}Og.exports=kT});var Ga=v((e5,Eg)=>{var AT=Qm(),xT=Pg(),ST=xT(function(e,t){return e==null?{}:AT(e,t)});Eg.exports=ST});var Vg=v((h5,Ug)=>{function xM(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}Ug.exports=xM});var Lr=v((d5,zg)=>{var SM=js(),TM=La();function MM(e,t,n,r){var i=!n;n||(n={});for(var s=-1,o=t.length;++s<o;){var a=t[s],u=r?r(n[a],e[a],a,n,e):void 0;u===void 0&&(u=e[a]),i?TM(n,a,u):SM(n,a,u)}return n}zg.exports=MM});var Hg=v((m5,Kg)=>{var IM=Lr(),NM=un();function CM(e,t){return e&&IM(t,NM(t),e)}Kg.exports=CM});var Jg=v((g5,Wg)=>{function qM(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}Wg.exports=qM});var $g=v((y5,Yg)=>{var jM=pt(),DM=Ss(),RM=Jg(),BM=Object.prototype,LM=BM.hasOwnProperty;function GM(e){if(!jM(e))return RM(e);var t=DM(e),n=[];for(var r in e)r=="constructor"&&(t||!LM.call(e,r))||n.push(r);return n}Yg.exports=GM});var Fs=v((v5,Xg)=>{var FM=wa(),UM=$g(),VM=Tn();function zM(e){return VM(e)?FM(e,!0):UM(e)}Xg.exports=zM});var Zg=v((b5,Qg)=>{var KM=Lr(),HM=Fs();function WM(e,t){return e&&KM(t,HM(t),e)}Qg.exports=WM});var iy=v((Gr,Kn)=>{var JM=rt(),ry=typeof Gr=="object"&&Gr&&!Gr.nodeType&&Gr,ey=ry&&typeof Kn=="object"&&Kn&&!Kn.nodeType&&Kn,YM=ey&&ey.exports===ry,ty=YM?JM.Buffer:void 0,ny=ty?ty.allocUnsafe:void 0;function $M(e,t){if(t)return e.slice();var n=e.length,r=ny?ny(n):new e.constructor(n);return e.copy(r),r}Kn.exports=$M});var oy=v((_5,sy)=>{function XM(e,t){var n=-1,r=e.length;for(t||(t=Array(r));++n<r;)t[n]=e[n];return t}sy.exports=XM});var uy=v((w5,ay)=>{var QM=Lr(),ZM=Ps();function eI(e,t){return QM(e,ZM(e),t)}ay.exports=eI});var $a=v((O5,cy)=>{var tI=Os(),nI=Cs(),rI=Ps(),iI=va(),sI=Object.getOwnPropertySymbols,oI=sI?function(e){for(var t=[];e;)tI(t,rI(e)),e=nI(e);return t}:iI;cy.exports=oI});var fy=v((P5,ly)=>{var aI=Lr(),uI=$a();function cI(e,t){return aI(e,uI(e),t)}ly.exports=cI});var hy=v((E5,py)=>{var lI=ga(),fI=$a(),pI=Fs();function hI(e){return lI(e,pI,fI)}py.exports=hI});var my=v((k5,dy)=>{var dI=Object.prototype,mI=dI.hasOwnProperty;function gI(e){var t=e.length,n=new e.constructor(t);return t&&typeof e[0]=="string"&&mI.call(e,"index")&&(n.index=e.index,n.input=e.input),n}dy.exports=gI});var Us=v((A5,yy)=>{var gy=da();function yI(e){var t=new e.constructor(e.byteLength);return new gy(t).set(new gy(e)),t}yy.exports=yI});var by=v((x5,vy)=>{var vI=Us();function bI(e,t){var n=t?vI(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}vy.exports=bI});var wy=v((S5,_y)=>{var _I=/\w*$/;function wI(e){var t=new e.constructor(e.source,_I.exec(e));return t.lastIndex=e.lastIndex,t}_y.exports=wI});var Ay=v((T5,ky)=>{var Oy=on(),Py=Oy?Oy.prototype:void 0,Ey=Py?Py.valueOf:void 0;function OI(e){return Ey?Object(Ey.call(e)):{}}ky.exports=OI});var Sy=v((M5,xy)=>{var PI=Us();function EI(e,t){var n=t?PI(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}xy.exports=EI});var My=v((I5,Ty)=>{var kI=Us(),AI=by(),xI=wy(),SI=Ay(),TI=Sy(),MI="[object Boolean]",II="[object Date]",NI="[object Map]",CI="[object Number]",qI="[object RegExp]",jI="[object Set]",DI="[object String]",RI="[object Symbol]",BI="[object ArrayBuffer]",LI="[object DataView]",GI="[object Float32Array]",FI="[object Float64Array]",UI="[object Int8Array]",VI="[object Int16Array]",zI="[object Int32Array]",KI="[object Uint8Array]",HI="[object Uint8ClampedArray]",WI="[object Uint16Array]",JI="[object Uint32Array]";function YI(e,t,n){var r=e.constructor;switch(t){case BI:return kI(e);case MI:case II:return new r(+e);case LI:return AI(e,n);case GI:case FI:case UI:case VI:case zI:case KI:case HI:case WI:case JI:return TI(e,n);case NI:return new r;case CI:case DI:return new r(e);case qI:return xI(e);case jI:return new r;case RI:return SI(e)}}Ty.exports=YI});var Cy=v((N5,Ny)=>{var $I=pt(),Iy=Object.create,XI=function(){function e(){}return function(t){if(!$I(t))return{};if(Iy)return Iy(t);e.prototype=t;var n=new e;return e.prototype=void 0,n}}();Ny.exports=XI});var jy=v((C5,qy)=>{var QI=Cy(),ZI=Cs(),eN=Ss();function tN(e){return typeof e.constructor=="function"&&!eN(e)?QI(ZI(e)):{}}qy.exports=tN});var Ry=v((q5,Dy)=>{var nN=qr(),rN=kt(),iN="[object Map]";function sN(e){return rN(e)&&nN(e)==iN}Dy.exports=sN});var Fy=v((j5,Gy)=>{var oN=Ry(),aN=As(),By=xs(),Ly=By&&By.isMap,uN=Ly?aN(Ly):oN;Gy.exports=uN});var Vy=v((D5,Uy)=>{var cN=qr(),lN=kt(),fN="[object Set]";function pN(e){return lN(e)&&cN(e)==fN}Uy.exports=pN});var Wy=v((R5,Hy)=>{var hN=Vy(),dN=As(),zy=xs(),Ky=zy&&zy.isSet,mN=Ky?dN(Ky):hN;Hy.exports=mN});var Xa=v((B5,Xy)=>{var gN=_s(),yN=Vg(),vN=js(),bN=Hg(),_N=Zg(),wN=iy(),ON=oy(),PN=uy(),EN=fy(),kN=Pa(),AN=hy(),xN=qr(),SN=my(),TN=My(),MN=jy(),IN=et(),NN=ks(),CN=Fy(),qN=pt(),jN=Wy(),DN=un(),RN=Fs(),BN=1,LN=2,GN=4,Jy="[object Arguments]",FN="[object Array]",UN="[object Boolean]",VN="[object Date]",zN="[object Error]",Yy="[object Function]",KN="[object GeneratorFunction]",HN="[object Map]",WN="[object Number]",$y="[object Object]",JN="[object RegExp]",YN="[object Set]",$N="[object String]",XN="[object Symbol]",QN="[object WeakMap]",ZN="[object ArrayBuffer]",e2="[object DataView]",t2="[object Float32Array]",n2="[object Float64Array]",r2="[object Int8Array]",i2="[object Int16Array]",s2="[object Int32Array]",o2="[object Uint8Array]",a2="[object Uint8ClampedArray]",u2="[object Uint16Array]",c2="[object Uint32Array]",ge={};ge[Jy]=ge[FN]=ge[ZN]=ge[e2]=ge[UN]=ge[VN]=ge[t2]=ge[n2]=ge[r2]=ge[i2]=ge[s2]=ge[HN]=ge[WN]=ge[$y]=ge[JN]=ge[YN]=ge[$N]=ge[XN]=ge[o2]=ge[a2]=ge[u2]=ge[c2]=!0;ge[zN]=ge[Yy]=ge[QN]=!1;function Vs(e,t,n,r,i,s){var o,a=t&BN,u=t&LN,c=t&GN;if(n&&(o=i?n(e,r,i,s):n(e)),o!==void 0)return o;if(!qN(e))return e;var l=IN(e);if(l){if(o=SN(e),!a)return ON(e,o)}else{var f=xN(e),p=f==Yy||f==KN;if(NN(e))return wN(e,a);if(f==$y||f==Jy||p&&!i){if(o=u||p?{}:MN(e),!a)return u?EN(e,_N(o,e)):PN(e,bN(o,e))}else{if(!ge[f])return i?e:{};o=TN(e,f,a)}}s||(s=new gN);var h=s.get(e);if(h)return h;s.set(e,o),jN(e)?e.forEach(function(m){o.add(Vs(m,t,n,m,e,s))}):CN(e)&&e.forEach(function(m,b){o.set(b,Vs(m,t,n,b,e,s))});var d=c?u?AN:kN:u?RN:DN,y=l?void 0:d(e);return yN(y||e,function(m,b){y&&(b=m,m=e[b]),vN(o,b,Vs(m,t,n,b,e,s))}),o}Xy.exports=Vs});var Fr=v((L5,Qy)=>{var l2=Xa(),f2=Ca(),p2=1;function h2(e){return f2(l2(e,p2))}Qy.exports=h2});var fv=v((y6,lv)=>{var A2=Xa(),x2=1,S2=4;function T2(e){return A2(e,x2|S2)}lv.exports=T2});var Uu=v(Jt=>{"use strict";Object.defineProperty(Jt,"__esModule",{value:!0});Jt.Pointer=Jt.escapeToken=Jt.unescapeToken=void 0;function zv(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}Jt.unescapeToken=zv;function Kv(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}Jt.escapeToken=Kv;var fC=function(){function e(t){t===void 0&&(t=[""]),this.tokens=t}return e.fromJSON=function(t){var n=t.split("/").map(zv);if(n[0]!=="")throw new Error("Invalid JSON Pointer: ".concat(t));return new e(n)},e.prototype.toString=function(){return this.tokens.map(Kv).join("/")},e.prototype.evaluate=function(t){for(var n=null,r="",i=t,s=1,o=this.tokens.length;s<o;s++)n=i,r=this.tokens[s],!(r=="__proto__"||r=="constructor"||r=="prototype")&&(i=(n||{})[r]);return{parent:n,key:r,value:i}},e.prototype.get=function(t){return this.evaluate(t).value},e.prototype.set=function(t,n){var r=this.evaluate(t);r.parent&&(r.parent[r.key]=n)},e.prototype.push=function(t){this.tokens.push(t)},e.prototype.add=function(t){var n=this.tokens.concat(String(t));return new e(n)},e}();Jt.Pointer=fC});var zu=v(Ct=>{"use strict";Object.defineProperty(Ct,"__esModule",{value:!0});Ct.clone=Ct.objectType=Ct.hasOwnProperty=void 0;Ct.hasOwnProperty=Object.prototype.hasOwnProperty;function pC(e){return e===void 0?"undefined":e===null?"null":Array.isArray(e)?"array":typeof e}Ct.objectType=pC;function hC(e){return e!=null&&typeof e=="object"}function Vu(e){if(!hC(e))return e;if(e.constructor==Array){for(var t=e.length,n=new Array(t),r=0;r<t;r++)n[r]=Vu(e[r]);return n}if(e.constructor==Date){var i=new Date(+e);return i}var s={};for(var o in e)Ct.hasOwnProperty.call(e,o)&&(s[o]=Vu(e[o]));return s}Ct.clone=Vu});var Wu=v(Ke=>{"use strict";Object.defineProperty(Ke,"__esModule",{value:!0});Ke.diffAny=Ke.diffObjects=Ke.diffArrays=Ke.intersection=Ke.subtract=Ke.isDestructive=void 0;var Ci=zu();function dC(e){var t=e.op;return t==="remove"||t==="replace"||t==="copy"||t==="move"}Ke.isDestructive=dC;function Hu(e,t){var n={};for(var r in e)Ci.hasOwnProperty.call(e,r)&&e[r]!==void 0&&(n[r]=1);for(var i in t)Ci.hasOwnProperty.call(t,i)&&t[i]!==void 0&&delete n[i];return Object.keys(n)}Ke.subtract=Hu;function Hv(e){for(var t=e.length,n={},r=0;r<t;r++){var i=e[r];for(var s in i)Ci.hasOwnProperty.call(i,s)&&i[s]!==void 0&&(n[s]=(n[s]||0)+1)}for(var s in n)n[s]<t&&delete n[s];return Object.keys(n)}Ke.intersection=Hv;function mC(e){return e.op==="add"}function gC(e){return e.op==="remove"}function Ku(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function Wv(e,t,n,r){r===void 0&&(r=no);var i={"0,0":{operations:[],cost:0}};function s(l,f){var p="".concat(l,",").concat(f),h=i[p];if(h===void 0){if(l>0&&f>0&&!r(e[l-1],t[f-1],n.add(String(l-1))).length)h=s(l-1,f-1);else{var d=[];if(l>0){var y=s(l-1,f),m={op:"remove",index:l-1};d.push(Ku(y,m))}if(f>0){var b=s(l,f-1),g={op:"add",index:l-1,value:t[f-1]};d.push(Ku(b,g))}if(l>0&&f>0){var O=s(l-1,f-1),I={op:"replace",index:l-1,original:e[l-1],value:t[f-1]};d.push(Ku(O,I))}var j=d.sort(function(N,D){return N.cost-D.cost})[0];h=j}i[p]=h}return h}var o=isNaN(e.length)||e.length<=0?0:e.length,a=isNaN(t.length)||t.length<=0?0:t.length,u=s(o,a).operations,c=u.reduce(function(l,f){var p=l[0],h=l[1];if(mC(f)){var d=f.index+1+h,y=d<o+h?String(d):"-",m={op:f.op,path:n.add(y).toString(),value:f.value};return[p.concat(m),h+1]}else if(gC(f)){var m={op:f.op,path:n.add(String(f.index+h)).toString()};return[p.concat(m),h-1]}else{var b=n.add(String(f.index+h)),g=r(f.original,f.value,b);return[p.concat.apply(p,g),h]}},[[],0])[0];return c}Ke.diffArrays=Wv;function Jv(e,t,n,r){r===void 0&&(r=no);var i=[];return Hu(e,t).forEach(function(s){i.push({op:"remove",path:n.add(s).toString()})}),Hu(t,e).forEach(function(s){i.push({op:"add",path:n.add(s).toString(),value:t[s]})}),Hv([e,t]).forEach(function(s){i.push.apply(i,r(e[s],t[s],n.add(s)))}),i}Ke.diffObjects=Jv;function no(e,t,n,r){if(r===void 0&&(r=no),e===t)return[];var i=(0,Ci.objectType)(e),s=(0,Ci.objectType)(t);return i=="array"&&s=="array"?Wv(e,t,n,r):i=="object"&&s=="object"?Jv(e,t,n,r):[{op:"replace",path:n.toString(),value:t}]}Ke.diffAny=no});var ib=v(Ae=>{"use strict";var Ju=Ae&&Ae.__extends||function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&(r[s]=i[s])},e(t,n)};return function(t,n){if(typeof n!="function"&&n!==null)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");e(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(Ae,"__esModule",{value:!0});Ae.apply=Ae.InvalidOperationError=Ae.test=Ae.copy=Ae.move=Ae.replace=Ae.remove=Ae.add=Ae.TestError=Ae.MissingError=void 0;var qt=Uu(),Yu=zu(),yC=Wu(),mt=function(e){Ju(t,e);function t(n){var r=e.call(this,"Value required at path: ".concat(n))||this;return r.path=n,r.name="MissingError",r}return t}(Error);Ae.MissingError=mt;var Yv=function(e){Ju(t,e);function t(n,r){var i=e.call(this,"Test failed: ".concat(n," != ").concat(r))||this;return i.actual=n,i.expected=r,i.name="TestError",i}return t}(Error);Ae.TestError=Yv;function $u(e,t,n){if(Array.isArray(e))if(t=="-")e.push(n);else{var r=parseInt(t,10);e.splice(r,0,n)}else e[t]=n}function $v(e,t){if(Array.isArray(e)){var n=parseInt(t,10);e.splice(n,1)}else delete e[t]}function Xv(e,t){var n=qt.Pointer.fromJSON(t.path).evaluate(e);return n.parent===void 0?new mt(t.path):($u(n.parent,n.key,(0,Yu.clone)(t.value)),null)}Ae.add=Xv;function Qv(e,t){var n=qt.Pointer.fromJSON(t.path).evaluate(e);return n.value===void 0?new mt(t.path):($v(n.parent,n.key),null)}Ae.remove=Qv;function Zv(e,t){var n=qt.Pointer.fromJSON(t.path).evaluate(e);if(n.parent===null)return new mt(t.path);if(Array.isArray(n.parent)){if(parseInt(n.key,10)>=n.parent.length)return new mt(t.path)}else if(n.value===void 0)return new mt(t.path);return n.parent[n.key]=(0,Yu.clone)(t.value),null}Ae.replace=Zv;function eb(e,t){var n=qt.Pointer.fromJSON(t.from).evaluate(e);if(n.value===void 0)return new mt(t.from);var r=qt.Pointer.fromJSON(t.path).evaluate(e);return r.parent===void 0?new mt(t.path):($v(n.parent,n.key),$u(r.parent,r.key,n.value),null)}Ae.move=eb;function tb(e,t){var n=qt.Pointer.fromJSON(t.from).evaluate(e);if(n.value===void 0)return new mt(t.from);var r=qt.Pointer.fromJSON(t.path).evaluate(e);return r.parent===void 0?new mt(t.path):($u(r.parent,r.key,(0,Yu.clone)(n.value)),null)}Ae.copy=tb;function nb(e,t){var n=qt.Pointer.fromJSON(t.path).evaluate(e);return(0,yC.diffAny)(n.value,t.value,new qt.Pointer).length?new Yv(n.value,t.value):null}Ae.test=nb;var rb=function(e){Ju(t,e);function t(n){var r=e.call(this,"Invalid operation: ".concat(n.op))||this;return r.operation=n,r.name="InvalidOperationError",r}return t}(Error);Ae.InvalidOperationError=rb;function vC(e,t){switch(t.op){case"add":return Xv(e,t);case"remove":return Qv(e,t);case"replace":return Zv(e,t);case"move":return eb(e,t);case"copy":return tb(e,t);case"test":return nb(e,t)}return new rb(t)}Ae.apply=vC});var qi=v(gt=>{"use strict";Object.defineProperty(gt,"__esModule",{value:!0});gt.createTests=gt.createPatch=gt.applyPatch=gt.Pointer=void 0;var Xu=Uu();Object.defineProperty(gt,"Pointer",{enumerable:!0,get:function(){return Xu.Pointer}});var bC=ib(),Qu=Wu();function _C(e,t){return t.map(function(n){return(0,bC.apply)(e,n)})}gt.applyPatch=_C;function wC(e){function t(n,r,i){var s=e(n,r,i);return Array.isArray(s)?s:(0,Qu.diffAny)(n,r,i,t)}return t}function OC(e,t,n){var r=new Xu.Pointer;return(n?wC(n):Qu.diffAny)(e,t,r)}gt.createPatch=OC;function sb(e,t){var n=Xu.Pointer.fromJSON(t).evaluate(e);if(n!==void 0)return{op:"test",path:t,value:n.value}}function PC(e,t){var n=new Array;return t.filter(Qu.isDestructive).forEach(function(r){var i=sb(e,r.path);if(i&&n.push(i),"from"in r){var s=sb(e,r.from);s&&n.push(s)}}),n}gt.createTests=PC});var io=v(lb=>{(function(e,t){"use strict";if(e.setImmediate)return;var n=1,r={},i=!1,s=e.document,o;function a(g){typeof g!="function"&&(g=new Function(""+g));for(var O=new Array(arguments.length-1),I=0;I<O.length;I++)O[I]=arguments[I+1];var j={callback:g,args:O};return r[n]=j,o(n),n++}function u(g){delete r[g]}function c(g){var O=g.callback,I=g.args;switch(I.length){case 0:O();break;case 1:O(I[0]);break;case 2:O(I[0],I[1]);break;case 3:O(I[0],I[1],I[2]);break;default:O.apply(t,I);break}}function l(g){if(i)setTimeout(l,0,g);else{var O=r[g];if(O){i=!0;try{c(O)}finally{u(g),i=!1}}}}function f(){o=function(g){process.nextTick(function(){l(g)})}}function p(){if(e.postMessage&&!e.importScripts){var g=!0,O=e.onmessage;return e.onmessage=function(){g=!1},e.postMessage("","*"),e.onmessage=O,g}}function h(){var g="setImmediate$"+Math.random()+"$",O=function(I){I.source===e&&typeof I.data=="string"&&I.data.indexOf(g)===0&&l(+I.data.slice(g.length))};e.addEventListener?e.addEventListener("message",O,!1):e.attachEvent("onmessage",O),o=function(I){e.postMessage(g+I,"*")}}function d(){var g=new MessageChannel;g.port1.onmessage=function(O){var I=O.data;l(I)},o=function(O){g.port2.postMessage(O)}}function y(){var g=s.documentElement;o=function(O){var I=s.createElement("script");I.onreadystatechange=function(){l(O),I.onreadystatechange=null,g.removeChild(I),I=null},g.appendChild(I)}}function m(){o=function(g){setTimeout(l,0,g)}}var b=Object.getPrototypeOf&&Object.getPrototypeOf(e);b=b&&b.setTimeout?b:e,{}.toString.call(e.process)==="[object process]"?f():p()?h():e.MessageChannel?d():s&&"onreadystatechange"in s.createElement("script")?y():m(),b.setImmediate=a,b.clearImmediate=u})(typeof self>"u"?typeof global>"u"?lb:global:self)});var Jj={};ll(Jj,{Client:()=>qo,gameFactory:()=>gi});function He(e,t){let{duplicates:n,circular:r}=hr(e),i=[...n],s=new Map(i.map(a=>[a,null])),o=t?.deduplicateInstances!==!1;return JSON.stringify(e,(a,u)=>{if(typeof u=="object"&&u!==null&&!Array.isArray(u)){let c=s.get(u),l=r.has(u);if(typeof c=="number"&&l)return{_instanceReference:c};if(o&&typeof c=="number")return{_instanceReference:c};let f={...u};if(c===null){let p=i.indexOf(u);s.set(u,p),f._instanceReferenceId=p}else!o&&typeof c=="number"&&(f._instanceReference=c);return u.constructor&&u.constructor!==Object&&u.constructor!==Array&&(f._constructorName=u.constructor.name),f}else{if(Number.isNaN(u))return"Wacksonan";if(Object.is(u,-0))return"Wacksonegativezero";switch(u){case 1/0:return"Wacksonfinity";case-1/0:return"Wacksonegativinfinity";case void 0:return"Wacksondefined";default:return u}}},t?.space)}function Ft(e,t){let n=JSON.parse(e,(i,s)=>{switch(s){case"Wacksonfinity":return 1/0;case"Wacksonegativinfinity":return-1/0;case"Wacksondefined":return;case"Wacksonan":return NaN;case"Wacksonegativezero":return-0;default:return s}}),r=new Map;return hr(n,i=>{if(i._instanceReferenceId!=null){let s=i._instanceReferenceId;delete i._instanceReferenceId,r.set(s,i)}if(t&&i._constructorName){let s=t[i._constructorName];if(!s)throw new Error(`Constructor ${i._constructorName} is not in registry`);Object.setPrototypeOf(i,s.prototype),delete i._constructorName}}),hr(n,(i,s,o)=>{if(i?._instanceReference!=null){let a=r.get(i._instanceReference);if(!a)throw new Error(`Unknown _instanceReference: ${i._instanceReference}`);s[o]=a}}),n}function hr(e,t,n=new WeakSet,r=null,i=null,s=new Set,o=new Set,a=new WeakSet){if(typeof e!="object"||e===null)return{duplicates:s,circular:o};if(n.has(e)){s.add(e),a.has(e)&&o.add(e);return}if(n.add(e),a.add(e),t?.(e,r,i),Array.isArray(e))for(let u=0;u<e.length;u++)hr(e[u],t,n,e,u,s,o,a);else for(let u of Object.keys(e))hr(e[u],t,n,e,u,s,o,a);return a.delete(e),{duplicates:s,circular:o}}var cv=he(aa());var Et=class{constructor(t,n,r){if(!t?.fromBank)throw new Error(`Do not create entities directly. Go through the Bank. rule: ${JSON.stringify(n)}`);this.rule=n,this.entityId=r,this.state={},this.rule.stateGroups&&Object.entries(this.rule.stateGroups).forEach(([i,s])=>{let o=t?.initialStateGroups?.[i]??Object.keys(s)[0];Object.assign(this.state,s[o])}),this.rule.state&&Object.assign(this.state,this.rule.state)}get attributes(){return{...this.rule,...this,...this.state}}};var rn=class extends Et{constructor(...t){super(...t),this.entities=[]}placeEntity(t,n="Last"){n==="Last"?this.entities.push(t):n==="First"&&this.entities.unshift(t)}remove(t){this.entities.splice(this.entities.indexOf(t),1)}takeOne(t="First"){if(t==="First")return this.entities.splice(0,1)[0]}isEmpty(){return this.entities.length===0}};var wr=class extends rn{};var sn=class extends Et{constructor(t,...n){super(t,...n),this.spaces=this.makeSpaces(t.bank)}makeSpaces(t){return Array(this.getSpacesCount()).fill().map((n,r)=>t.createEntity({entityType:"Space",index:r}))}getEmptySpaces(){return this.spaces.filter(t=>t.isEmpty())}getSpace(t){return this.spaces[t]}getEntities(t){return this.getSpace(t).entities}placeEntity(t,n){this.getSpace(t).placeEntity(n)}};var Lf=he(Bf());var Ar=class extends sn{getSpacesCount(){return this.rule.width*this.rule.height}getRows(){return(0,Lf.default)(this.spaces,this.rule.width)}getCoordinates(t){let{width:n}=this.rule;return[t%n,Math.floor(t/n)]}getIndex([t,n]){let{width:r}=this.rule;return n*r+t}getSpace(t){return this.spaces[this.getIndex(t)]}getRelativeCoordinates([t,n],[r,i]){let s=[t+r,n+i];return this.areCoordinatesValid(s)?s:null}areCoordinatesValid([t,n]){return t>=0&&n>=0&&t<this.rule.width&&n<this.rule.height}};var ov=he(Ra()),av=he(Bm());var Gg=he(qs()),Fg=he(Ga());function ln(e,t){let n=e;for(let r of t){if(n===void 0)return n;if(r?.flatten){if(!Array.isArray(n))return;n=n.flat(),r.map&&(n=n.map(i=>ln(i,r.map)))}else n=n[r]}return n}var tt="INUMBER",Un="IOP1",Vn="IOP2",zn="IOP3",xt="IVAR",pn="IVARNAME",Ln="IFUNCALL",Ds="IFUNDEF",ze="IEXPR",Va="IEXPREVAL",hn="IMEMBER",Rs="IENDSTATEMENT",Gn="IARRAY";function re(e,t){this.type=e,this.value=t??0}re.prototype.toString=function(){switch(this.type){case tt:case Un:case Vn:case zn:case xt:case pn:case Rs:return this.value;case Ln:return"CALL "+this.value;case Ds:return"DEF "+this.value;case Gn:return"ARRAY "+this.value;case hn:return"."+this.value;default:return"Invalid Instruction"}};function Bs(e){return new re(Un,e)}function Tt(e){return new re(Vn,e)}function Ng(e){return new re(zn,e)}function Ua(e,t,n,r,i){for(var s=[],o=[],a,u,c,l,f=0;f<e.length;f++){var p=e[f],h=p.type;if(h===tt||h===pn)Array.isArray(p.value)?s.push.apply(s,Ua(p.value.map(function(d){return new re(tt,d)}).concat(new re(Gn,p.value.length)),t,n,r,i)):s.push(p);else if(h===xt&&i.hasOwnProperty(p.value))p=new re(tt,i[p.value]),s.push(p);else if(h===Vn&&s.length>1)u=s.pop(),a=s.pop(),l=n[p.value],p=new re(tt,l(a.value,u.value)),s.push(p);else if(h===zn&&s.length>2)c=s.pop(),u=s.pop(),a=s.pop(),p.value==="?"?s.push(a.value?u.value:c.value):(l=r[p.value],p=new re(tt,l(a.value,u.value,c.value)),s.push(p));else if(h===Un&&s.length>0)a=s.pop(),l=t[p.value],p=new re(tt,l(a.value)),s.push(p);else if(h===ze){for(;s.length>0;)o.push(s.shift());o.push(new re(ze,Ua(p.value,t,n,r,i)))}else if(h===hn&&s.length>0)a=s.pop(),s.push(new re(tt,a.value[p.value]));else{for(;s.length>0;)o.push(s.shift());o.push(p)}}for(;s.length>0;)o.push(s.shift());return o}function Cg(e,t,n){for(var r=[],i=0;i<e.length;i++){var s=e[i],o=s.type;if(o===xt&&s.value===t)for(var a=0;a<n.tokens.length;a++){var u=n.tokens[a],c;u.type===Un?c=Bs(u.value):u.type===Vn?c=Tt(u.value):u.type===zn?c=Ng(u.value):c=new re(u.type,u.value),r.push(c)}else o===ze?r.push(new re(ze,Cg(s.value,t,n))):r.push(s)}return r}function fn(e,t,n){var r=[],i,s,o,a,u,c;if(za(e))return At(e,n);for(var l=e.length,f=0;f<l;f++){var p=e[f],h=p.type;if(h===tt||h===pn)r.push(p.value);else if(h===Vn)s=r.pop(),i=r.pop(),p.value==="and"?r.push(i?!!fn(s,t,n):!1):p.value==="or"?r.push(i?!0:!!fn(s,t,n)):p.value==="="?(a=t.binaryOps[p.value],r.push(a(i,fn(s,t,n),n))):(a=t.binaryOps[p.value],r.push(a(At(i,n),At(s,n))));else if(h===zn)o=r.pop(),s=r.pop(),i=r.pop(),p.value==="?"?r.push(fn(i?s:o,t,n)):(a=t.ternaryOps[p.value],r.push(a(At(i,n),At(s,n),At(o,n))));else if(h===xt)if(p.value in t.functions)r.push(t.functions[p.value]);else if(p.value in t.unaryOps&&t.parser.isOperatorEnabled(p.value))r.push(t.unaryOps[p.value]);else{var d=n[p.value];if(d!==void 0)r.push(d);else throw new Error("undefined variable: "+p.value)}else if(h===Un)i=r.pop(),a=t.unaryOps[p.value],r.push(a(At(i,n)));else if(h===Ln){for(c=p.value,u=[];c-- >0;)u.unshift(At(r.pop(),n));if(a=r.pop(),a.apply&&a.call)r.push(a.apply(void 0,u));else throw new Error(a+" is not a function")}else if(h===Ds)r.push(function(){for(var y=r.pop(),m=[],b=p.value;b-- >0;)m.unshift(r.pop());var g=r.pop(),O=function(){for(var I=Object.assign({},n),j=0,N=m.length;j<N;j++)I[m[j]]=arguments[j];return fn(y,t,I)};return Object.defineProperty(O,"name",{value:g,writable:!1}),n[g]=O,O}());else if(h===ze)r.push(TT(p,t));else if(h===Va)r.push(p);else if(h===hn)i=r.pop(),r.push(i[p.value]);else if(h===Rs)r.pop();else if(h===Gn){for(c=p.value,u=[];c-- >0;)u.unshift(r.pop());r.push(u)}else throw new Error("invalid Expression")}if(r.length>1)throw new Error("invalid Expression (parity)");return r[0]===0?0:At(r[0],n)}function TT(e,t,n){return za(e)?e:{type:Va,value:function(r){return fn(e.value,t,r)}}}function za(e){return e&&e.type===Va}function At(e,t){return za(e)?e.value(t):e}function Ka(e,t){for(var n=[],r,i,s,o,a,u,c=0;c<e.length;c++){var l=e[c],f=l.type;if(f===tt)typeof l.value=="number"&&l.value<0?n.push("("+l.value+")"):Array.isArray(l.value)?n.push("["+l.value.map(kg).join(", ")+"]"):n.push(kg(l.value));else if(f===Vn)i=n.pop(),r=n.pop(),o=l.value,t?o==="^"?n.push("Math.pow("+r+", "+i+")"):o==="and"?n.push("(!!"+r+" && !!"+i+")"):o==="or"?n.push("(!!"+r+" || !!"+i+")"):o==="||"?n.push("(function(a,b){ return Array.isArray(a) && Array.isArray(b) ? a.concat(b) : String(a) + String(b); }(("+r+"),("+i+")))"):o==="=="?n.push("("+r+" === "+i+")"):o==="!="?n.push("("+r+" !== "+i+")"):o==="["?n.push(r+"[("+i+") | 0]"):n.push("("+r+" "+o+" "+i+")"):o==="["?n.push(r+"["+i+"]"):n.push("("+r+" "+o+" "+i+")");else if(f===zn)if(s=n.pop(),i=n.pop(),r=n.pop(),o=l.value,o==="?")n.push("("+r+" ? "+i+" : "+s+")");else throw new Error("invalid Expression");else if(f===xt||f===pn)n.push(l.value);else if(f===Un)r=n.pop(),o=l.value,o==="-"||o==="+"?n.push("("+o+r+")"):t?o==="not"?n.push("(!"+r+")"):o==="!"?n.push("fac("+r+")"):n.push(o+"("+r+")"):o==="!"?n.push("("+r+"!)"):n.push("("+o+" "+r+")");else if(f===Ln){for(u=l.value,a=[];u-- >0;)a.unshift(n.pop());o=n.pop(),n.push(o+"("+a.join(", ")+")")}else if(f===Ds){for(i=n.pop(),u=l.value,a=[];u-- >0;)a.unshift(n.pop());r=n.pop(),t?n.push("("+r+" = function("+a.join(", ")+") { return "+i+" })"):n.push("("+r+"("+a.join(", ")+") = "+i+")")}else if(f===hn)r=n.pop(),n.push(r+"."+l.value);else if(f===Gn){for(u=l.value,a=[];u-- >0;)a.unshift(n.pop());n.push("["+a.join(", ")+"]")}else if(f===ze)n.push("("+Ka(l.value,t)+")");else if(f!==Rs)throw new Error("invalid Expression")}return n.length>1&&(t?n=[n.join(",")]:n=[n.join(";")]),String(n[0])}function kg(e){return typeof e=="string"?JSON.stringify(e).replace(/\u2028/g,"\\u2028").replace(/\u2029/g,"\\u2029"):e}function Bn(e,t){for(var n=0;n<e.length;n++)if(e[n]===t)return!0;return!1}function Ha(e,t,n){n=n||{};for(var r=!!n.withMembers,i=null,s=0;s<e.length;s++){var o=e[s];o.type===xt||o.type===pn?!r&&!Bn(t,o.value)?t.push(o.value):(i!==null&&(Bn(t,i)||t.push(i)),i=o.value):o.type===hn&&r&&i!==null?i+="."+o.value:o.type===ze?Ha(o.value,t,n):i!==null&&(Bn(t,i)||t.push(i),i=null)}i!==null&&!Bn(t,i)&&t.push(i)}function it(e,t){this.tokens=e,this.parser=t,this.unaryOps=t.unaryOps,this.binaryOps=t.binaryOps,this.ternaryOps=t.ternaryOps,this.functions=t.functions}it.prototype.simplify=function(e){return e=e||{},new it(Ua(this.tokens,this.unaryOps,this.binaryOps,this.ternaryOps,e),this.parser)};it.prototype.substitute=function(e,t){return t instanceof it||(t=this.parser.parse(String(t))),new it(Cg(this.tokens,e,t),this.parser)};it.prototype.evaluate=function(e){return e=e||{},fn(this.tokens,this,e)};it.prototype.toString=function(){return Ka(this.tokens,!1)};it.prototype.symbols=function(e){e=e||{};var t=[];return Ha(this.tokens,t,e),t};it.prototype.variables=function(e){e=e||{};var t=[];Ha(this.tokens,t,e);var n=this.functions;return t.filter(function(r){return!(r in n)})};it.prototype.toJSFunction=function(e,t){var n=this,r=new Function(e,"with(this.functions) with (this.ternaryOps) with (this.binaryOps) with (this.unaryOps) { return "+Ka(this.simplify(t).tokens,!0)+"; }");return function(){return r.apply(n,arguments)}};var Dr="TEOF",me="TOP",Ls="TNUMBER",qg="TSTRING",St="TPAREN",Fn="TBRACKET",Gs="TCOMMA",Wa="TNAME",Ja="TSEMICOLON";function jg(e,t,n){this.type=e,this.value=t,this.index=n}jg.prototype.toString=function(){return this.type+": "+this.value};function Te(e,t){this.pos=0,this.current=null,this.unaryOps=e.unaryOps,this.binaryOps=e.binaryOps,this.ternaryOps=e.ternaryOps,this.consts=e.consts,this.expression=t,this.savedPosition=0,this.savedCurrent=null,this.options=e.options,this.parser=e}Te.prototype.newToken=function(e,t,n){return new jg(e,t,n??this.pos)};Te.prototype.save=function(){this.savedPosition=this.pos,this.savedCurrent=this.current};Te.prototype.restore=function(){this.pos=this.savedPosition,this.current=this.savedCurrent};Te.prototype.next=function(){if(this.pos>=this.expression.length)return this.newToken(Dr,"EOF");if(this.isWhitespace()||this.isComment())return this.next();if(this.isRadixInteger()||this.isNumber()||this.isOperator()||this.isString()||this.isParen()||this.isBracket()||this.isComma()||this.isSemicolon()||this.isNamedOp()||this.isConst()||this.isName())return this.current;this.parseError('Unknown character "'+this.expression.charAt(this.pos)+'"')};Te.prototype.isString=function(){var e=!1,t=this.pos,n=this.expression.charAt(t);if(n==="'"||n==='"')for(var r=this.expression.indexOf(n,t+1);r>=0&&this.pos<this.expression.length;){if(this.pos=r+1,this.expression.charAt(r-1)!=="\\"){var i=this.expression.substring(t+1,r);this.current=this.newToken(qg,this.unescape(i),t),e=!0;break}r=this.expression.indexOf(n,r+1)}return e};Te.prototype.isParen=function(){var e=this.expression.charAt(this.pos);return e==="("||e===")"?(this.current=this.newToken(St,e),this.pos++,!0):!1};Te.prototype.isBracket=function(){var e=this.expression.charAt(this.pos);return(e==="["||e==="]")&&this.isOperatorEnabled("[")?(this.current=this.newToken(Fn,e),this.pos++,!0):!1};Te.prototype.isComma=function(){var e=this.expression.charAt(this.pos);return e===","?(this.current=this.newToken(Gs,","),this.pos++,!0):!1};Te.prototype.isSemicolon=function(){var e=this.expression.charAt(this.pos);return e===";"?(this.current=this.newToken(Ja,";"),this.pos++,!0):!1};Te.prototype.isConst=function(){for(var e=this.pos,t=e;t<this.expression.length;t++){var n=this.expression.charAt(t);if(n.toUpperCase()===n.toLowerCase()&&(t===this.pos||n!=="_"&&n!=="."&&(n<"0"||n>"9")))break}if(t>e){var r=this.expression.substring(e,t);if(r in this.consts)return this.current=this.newToken(Ls,this.consts[r]),this.pos+=r.length,!0}return!1};Te.prototype.isNamedOp=function(){for(var e=this.pos,t=e;t<this.expression.length;t++){var n=this.expression.charAt(t);if(n.toUpperCase()===n.toLowerCase()&&(t===this.pos||n!=="_"&&(n<"0"||n>"9")))break}if(t>e){var r=this.expression.substring(e,t);if(this.isOperatorEnabled(r)&&(r in this.binaryOps||r in this.unaryOps||r in this.ternaryOps))return this.current=this.newToken(me,r),this.pos+=r.length,!0}return!1};Te.prototype.isName=function(){for(var e=this.pos,t=e,n=!1;t<this.expression.length;t++){var r=this.expression.charAt(t);if(r.toUpperCase()===r.toLowerCase()){if(t===this.pos&&(r==="$"||r==="_")){r==="_"&&(n=!0);continue}else if(t===this.pos||!n||r!=="_"&&(r<"0"||r>"9"))break}else n=!0}if(n){var i=this.expression.substring(e,t);return this.current=this.newToken(Wa,i),this.pos+=i.length,!0}return!1};Te.prototype.isWhitespace=function(){for(var e=!1,t=this.expression.charAt(this.pos);(t===" "||t===" "||t===`
|
|
5
5
|
`||t==="\r")&&(e=!0,this.pos++,!(this.pos>=this.expression.length));)t=this.expression.charAt(this.pos);return e};var MT=/^[0-9a-f]{4}$/i;Te.prototype.unescape=function(e){var t=e.indexOf("\\");if(t<0)return e;for(var n=e.substring(0,t);t>=0;){var r=e.charAt(++t);switch(r){case"'":n+="'";break;case'"':n+='"';break;case"\\":n+="\\";break;case"/":n+="/";break;case"b":n+="\b";break;case"f":n+="\f";break;case"n":n+=`
|
|
6
6
|
`;break;case"r":n+="\r";break;case"t":n+=" ";break;case"u":var i=e.substring(t+1,t+5);MT.test(i)||this.parseError("Illegal escape sequence: \\u"+i),n+=String.fromCharCode(parseInt(i,16)),t+=4;break;default:throw this.parseError('Illegal escape sequence: "\\'+r+'"')}++t;var s=e.indexOf("\\",t);n+=e.substring(t,s<0?e.length:s),t=s}return n};Te.prototype.isComment=function(){var e=this.expression.charAt(this.pos);return e==="/"&&this.expression.charAt(this.pos+1)==="*"?(this.pos=this.expression.indexOf("*/",this.pos)+2,this.pos===1&&(this.pos=this.expression.length),!0):!1};Te.prototype.isRadixInteger=function(){var e=this.pos;if(e>=this.expression.length-2||this.expression.charAt(e)!=="0")return!1;++e;var t,n;if(this.expression.charAt(e)==="x")t=16,n=/^[0-9a-f]$/i,++e;else if(this.expression.charAt(e)==="b")t=2,n=/^[01]$/i,++e;else return!1;for(var r=!1,i=e;e<this.expression.length;){var s=this.expression.charAt(e);if(n.test(s))e++,r=!0;else break}return r&&(this.current=this.newToken(Ls,parseInt(this.expression.substring(i,e),t)),this.pos=e),r};Te.prototype.isNumber=function(){for(var e=!1,t=this.pos,n=t,r=t,i=!1,s=!1,o;t<this.expression.length&&(o=this.expression.charAt(t),o>="0"&&o<="9"||!i&&o===".");)o==="."?i=!0:s=!0,t++,e=s;if(e&&(r=t),o==="e"||o==="E"){t++;for(var a=!0,u=!1;t<this.expression.length;){if(o=this.expression.charAt(t),a&&(o==="+"||o==="-"))a=!1;else if(o>="0"&&o<="9")u=!0,a=!1;else break;t++}u||(t=r)}return e?(this.current=this.newToken(Ls,parseFloat(this.expression.substring(n,t))),this.pos=t):this.pos=r,e};Te.prototype.isOperator=function(){var e=this.pos,t=this.expression.charAt(this.pos);if(t==="+"||t==="-"||t==="*"||t==="/"||t==="%"||t==="^"||t==="?"||t===":"||t===".")this.current=this.newToken(me,t);else if(t==="\u2219"||t==="\u2022")this.current=this.newToken(me,"*");else if(t===">")this.expression.charAt(this.pos+1)==="="?(this.current=this.newToken(me,">="),this.pos++):this.current=this.newToken(me,">");else if(t==="<")this.expression.charAt(this.pos+1)==="="?(this.current=this.newToken(me,"<="),this.pos++):this.current=this.newToken(me,"<");else if(t==="|")if(this.expression.charAt(this.pos+1)==="|")this.current=this.newToken(me,"||"),this.pos++;else return!1;else if(t==="=")this.expression.charAt(this.pos+1)==="="?(this.current=this.newToken(me,"=="),this.pos++):this.current=this.newToken(me,t);else if(t==="!")this.expression.charAt(this.pos+1)==="="?(this.current=this.newToken(me,"!="),this.pos++):this.current=this.newToken(me,t);else return!1;return this.pos++,this.isOperatorEnabled(this.current.value)?!0:(this.pos=e,!1)};Te.prototype.isOperatorEnabled=function(e){return this.parser.isOperatorEnabled(e)};Te.prototype.getCoordinates=function(){var e=0,t,n=-1;do e++,t=this.pos-n,n=this.expression.indexOf(`
|
|
7
|
-
`,n+1);while(n>=0&&n<this.pos);return{line:e,column:t}};Te.prototype.parseError=function(e){var t=this.getCoordinates();throw new Error("parse error ["+t.line+":"+t.column+"]: "+e)};function _e(e,t,n){this.parser=e,this.tokens=t,this.current=null,this.nextToken=null,this.next(),this.savedCurrent=null,this.savedNextToken=null,this.allowMemberAccess=n.allowMemberAccess!==!1}_e.prototype.next=function(){return this.current=this.nextToken,this.nextToken=this.tokens.next()};_e.prototype.tokenMatches=function(e,t){return typeof t>"u"?!0:Array.isArray(t)?Bn(t,e.value):typeof t=="function"?t(e):e.value===t};_e.prototype.save=function(){this.savedCurrent=this.current,this.savedNextToken=this.nextToken,this.tokens.save()};_e.prototype.restore=function(){this.tokens.restore(),this.current=this.savedCurrent,this.nextToken=this.savedNextToken};_e.prototype.accept=function(e,t){return this.nextToken.type===e&&this.tokenMatches(this.nextToken,t)?(this.next(),!0):!1};_e.prototype.expect=function(e,t){if(!this.accept(e,t)){var n=this.tokens.getCoordinates();throw new Error("parse error ["+n.line+":"+n.column+"]: Expected "+(t||e))}};_e.prototype.parseAtom=function(e){var t=this.tokens.unaryOps;function n(i){return i.value in t}if(this.accept(Wa)||this.accept(me,n))e.push(new re(xt,this.current.value));else if(this.accept(Ls))e.push(new re(tt,this.current.value));else if(this.accept(qg))e.push(new re(tt,this.current.value));else if(this.accept(St,"("))this.parseExpression(e),this.expect(St,")");else if(this.accept(Fn,"["))if(this.accept(Fn,"]"))e.push(new re(Gn,0));else{var r=this.parseArrayList(e);e.push(new re(Gn,r))}else throw new Error("unexpected "+this.nextToken)};_e.prototype.parseExpression=function(e){var t=[];this.parseUntilEndStatement(e,t)||(this.parseVariableAssignmentExpression(t),!this.parseUntilEndStatement(e,t)&&this.pushExpression(e,t))};_e.prototype.pushExpression=function(e,t){for(var n=0,r=t.length;n<r;n++)e.push(t[n])};_e.prototype.parseUntilEndStatement=function(e,t){return this.accept(Ja)?(this.nextToken&&this.nextToken.type!==Dr&&!(this.nextToken.type===St&&this.nextToken.value===")")&&t.push(new re(Rs)),this.nextToken.type!==Dr&&this.parseExpression(t),e.push(new re(ze,t)),!0):!1};_e.prototype.parseArrayList=function(e){for(var t=0;!this.accept(Fn,"]");)for(this.parseExpression(e),++t;this.accept(Gs);)this.parseExpression(e),++t;return t};_e.prototype.parseVariableAssignmentExpression=function(e){for(this.parseConditionalExpression(e);this.accept(me,"=");){var t=e.pop(),n=[],r=e.length-1;if(t.type===Ln){if(!this.tokens.isOperatorEnabled("()="))throw new Error("function definition is not permitted");for(var i=0,s=t.value+1;i<s;i++){var o=r-i;e[o].type===xt&&(e[o]=new re(pn,e[o].value))}this.parseVariableAssignmentExpression(n),e.push(new re(ze,n)),e.push(new re(Ds,t.value));continue}if(t.type!==xt&&t.type!==hn)throw new Error("expected variable for assignment");this.parseVariableAssignmentExpression(n),e.push(new re(pn,t.value)),e.push(new re(ze,n)),e.push(Tt("="))}};_e.prototype.parseConditionalExpression=function(e){for(this.parseOrExpression(e);this.accept(me,"?");){var t=[],n=[];this.parseConditionalExpression(t),this.expect(me,":"),this.parseConditionalExpression(n),e.push(new re(ze,t)),e.push(new re(ze,n)),e.push(Ng("?"))}};_e.prototype.parseOrExpression=function(e){for(this.parseAndExpression(e);this.accept(me,"or");){var t=[];this.parseAndExpression(t),e.push(new re(ze,t)),e.push(Tt("or"))}};_e.prototype.parseAndExpression=function(e){for(this.parseComparison(e);this.accept(me,"and");){var t=[];this.parseComparison(t),e.push(new re(ze,t)),e.push(Tt("and"))}};var IT=["==","!=","<","<=",">=",">","in"];_e.prototype.parseComparison=function(e){for(this.parseAddSub(e);this.accept(me,IT);){var t=this.current;this.parseAddSub(e),e.push(Tt(t.value))}};var NT=["+","-","||"];_e.prototype.parseAddSub=function(e){for(this.parseTerm(e);this.accept(me,NT);){var t=this.current;this.parseTerm(e),e.push(Tt(t.value))}};var CT=["*","/","%"];_e.prototype.parseTerm=function(e){for(this.parseFactor(e);this.accept(me,CT);){var t=this.current;this.parseFactor(e),e.push(Tt(t.value))}};_e.prototype.parseFactor=function(e){var t=this.tokens.unaryOps;function n(i){return i.value in t}if(this.save(),this.accept(me,n)){if(this.current.value!=="-"&&this.current.value!=="+"){if(this.nextToken.type===St&&this.nextToken.value==="("){this.restore(),this.parseExponential(e);return}else if(this.nextToken.type===Ja||this.nextToken.type===Gs||this.nextToken.type===Dr||this.nextToken.type===St&&this.nextToken.value===")"){this.restore(),this.parseAtom(e);return}}var r=this.current;this.parseFactor(e),e.push(Bs(r.value))}else this.parseExponential(e)};_e.prototype.parseExponential=function(e){for(this.parsePostfixExpression(e);this.accept(me,"^");)this.parseFactor(e),e.push(Tt("^"))};_e.prototype.parsePostfixExpression=function(e){for(this.parseFunctionCall(e);this.accept(me,"!");)e.push(Bs("!"))};_e.prototype.parseFunctionCall=function(e){var t=this.tokens.unaryOps;function n(s){return s.value in t}if(this.accept(me,n)){var r=this.current;this.parseAtom(e),e.push(Bs(r.value))}else for(this.parseMemberExpression(e);this.accept(St,"(");)if(this.accept(St,")"))e.push(new re(Ln,0));else{var i=this.parseArgumentList(e);e.push(new re(Ln,i))}};_e.prototype.parseArgumentList=function(e){for(var t=0;!this.accept(St,")");)for(this.parseExpression(e),++t;this.accept(Gs);)this.parseExpression(e),++t;return t};_e.prototype.parseMemberExpression=function(e){for(this.parseAtom(e);this.accept(me,".")||this.accept(Fn,"[");){var t=this.current;if(t.value==="."){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect(Wa),e.push(new re(hn,this.current.value))}else if(t.value==="["){if(!this.tokens.isOperatorEnabled("["))throw new Error('unexpected "[]", arrays are disabled');this.parseExpression(e),this.expect(Fn,"]"),e.push(Tt("["))}else throw new Error("unexpected symbol: "+t.value)}};function qT(e,t){return Number(e)+Number(t)}function jT(e,t){return e-t}function DT(e,t){return e*t}function RT(e,t){return e/t}function BT(e,t){return e%t}function LT(e,t){return Array.isArray(e)&&Array.isArray(t)?e.concat(t):""+e+t}function GT(e,t){return e===t}function FT(e,t){return e!==t}function UT(e,t){return e>t}function VT(e,t){return e<t}function zT(e,t){return e>=t}function KT(e,t){return e<=t}function HT(e,t){return!!(e&&t)}function WT(e,t){return!!(e||t)}function JT(e,t){return Bn(t,e)}function YT(e){return(Math.exp(e)-Math.exp(-e))/2}function $T(e){return(Math.exp(e)+Math.exp(-e))/2}function XT(e){return e===1/0?1:e===-1/0?-1:(Math.exp(e)-Math.exp(-e))/(Math.exp(e)+Math.exp(-e))}function QT(e){return e===-1/0?e:Math.log(e+Math.sqrt(e*e+1))}function ZT(e){return Math.log(e+Math.sqrt(e*e-1))}function eM(e){return Math.log((1+e)/(1-e))/2}function Ag(e){return Math.log(e)*Math.LOG10E}function tM(e){return-e}function nM(e){return!e}function rM(e){return e<0?Math.ceil(e):Math.floor(e)}function iM(e){return Math.random()*(e||1)}function xg(e){return Ya(e+1)}function sM(e){return isFinite(e)&&e===Math.round(e)}var oM=4.7421875,Fa=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22];function Ya(e){var t,n;if(sM(e)){if(e<=0)return isFinite(e)?1/0:NaN;if(e>171)return 1/0;for(var r=e-2,i=e-1;r>1;)i*=r,r--;return i===0&&(i=1),i}if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Ya(1-e));if(e>=171.35)return 1/0;if(e>85){var s=e*e,o=s*e,a=o*e,u=a*e;return Math.sqrt(2*Math.PI/e)*Math.pow(e/Math.E,e)*(1+1/(12*e)+1/(288*s)-139/(51840*o)-571/(2488320*a)+163879/(209018880*u)+5246819/(75246796800*u*e))}--e,n=Fa[0];for(var c=1;c<Fa.length;++c)n+=Fa[c]/(e+c);return t=e+oM+.5,Math.sqrt(2*Math.PI)*Math.pow(t,e+.5)*Math.exp(-t)*n}function aM(e){return Array.isArray(e)?e.length:String(e).length}function Sg(){for(var e=0,t=0,n=0;n<arguments.length;n++){var r=Math.abs(arguments[n]),i;t<r?(i=t/r,e=e*i*i+1,t=r):r>0?(i=r/t,e+=i*i):e+=r}return t===1/0?1/0:t*Math.sqrt(e)}function Tg(e,t,n){return e?t:n}function uM(e,t){return typeof t>"u"||+t==0?Math.round(e):(e=+e,t=-+t,isNaN(e)||!(typeof t=="number"&&t%1===0)?NaN:(e=e.toString().split("e"),e=Math.round(+(e[0]+"e"+(e[1]?+e[1]-t:-t))),e=e.toString().split("e"),+(e[0]+"e"+(e[1]?+e[1]+t:t))))}function cM(e,t,n){return n&&(n[e]=t),t}function lM(e,t){return e[t|0]}function fM(e){return arguments.length===1&&Array.isArray(e)?Math.max.apply(Math,e):Math.max.apply(Math,arguments)}function pM(e){return arguments.length===1&&Array.isArray(e)?Math.min.apply(Math,e):Math.min.apply(Math,arguments)}function hM(e,t){if(typeof e!="function")throw new Error("First argument to map is not a function");if(!Array.isArray(t))throw new Error("Second argument to map is not an array");return t.map(function(n,r){return e(n,r)})}function dM(e,t,n){if(typeof e!="function")throw new Error("First argument to fold is not a function");if(!Array.isArray(n))throw new Error("Second argument to fold is not an array");return n.reduce(function(r,i,s){return e(r,i,s)},t)}function mM(e,t){if(typeof e!="function")throw new Error("First argument to filter is not a function");if(!Array.isArray(t))throw new Error("Second argument to filter is not an array");return t.filter(function(n,r){return e(n,r)})}function gM(e,t){if(!(Array.isArray(t)||typeof t=="string"))throw new Error("Second argument to indexOf is not a string or array");return t.indexOf(e)}function yM(e,t){if(!Array.isArray(t))throw new Error("Second argument to join is not an array");return t.join(e)}function vM(e){return(e>0)-(e<0)||+e}var Mg=1/3;function bM(e){return e<0?-Math.pow(-e,Mg):Math.pow(e,Mg)}function _M(e){return Math.exp(e)-1}function wM(e){return Math.log(1+e)}function OM(e){return Math.log(e)/Math.LN2}function Ht(e){this.options=e||{},this.unaryOps={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh||YT,cosh:Math.cosh||$T,tanh:Math.tanh||XT,asinh:Math.asinh||QT,acosh:Math.acosh||ZT,atanh:Math.atanh||eM,sqrt:Math.sqrt,cbrt:Math.cbrt||bM,log:Math.log,log2:Math.log2||OM,ln:Math.log,lg:Math.log10||Ag,log10:Math.log10||Ag,expm1:Math.expm1||_M,log1p:Math.log1p||wM,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||rM,"-":tM,"+":Number,exp:Math.exp,not:nM,length:aM,"!":xg,sign:Math.sign||vM},this.binaryOps={"+":qT,"-":jT,"*":DT,"/":RT,"%":BT,"^":Math.pow,"||":LT,"==":GT,"!=":FT,">":UT,"<":VT,">=":zT,"<=":KT,and:HT,or:WT,in:JT,"=":cM,"[":lM},this.ternaryOps={"?":Tg},this.functions={random:iM,fac:xg,min:pM,max:fM,hypot:Math.hypot||Sg,pyt:Math.hypot||Sg,pow:Math.pow,atan2:Math.atan2,if:Tg,gamma:Ya,roundTo:uM,map:hM,fold:dM,filter:mM,indexOf:gM,join:yM},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Ht.prototype.parse=function(e){var t=[],n=new _e(this,new Te(this,e),{allowMemberAccess:this.options.allowMemberAccess});return n.parseExpression(t),n.expect(Dr,"EOF"),new it(t,this)};Ht.prototype.evaluate=function(e,t){return this.parse(e).evaluate(t)};var Dg=new Ht;Ht.parse=function(e){return Dg.parse(e)};Ht.evaluate=function(e,t){return Dg.parse(e).evaluate(t)};var Ig={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};function PM(e){return Ig.hasOwnProperty(e)?Ig[e]:e}Ht.prototype.isOperatorEnabled=function(e){var t=PM(e),n=this.options.operators||{};return!(t in n)||!!n[t]};var Rg=new Ht;Rg.functions.sum=e=>e.reduce((t,n)=>t+n,0);function Rr(e,t,n){let r=pe(e,t.arguments,n);return Rg.evaluate(t.expression,r)}var Bg=he(qs()),EM=["state"];function Br(e,t,n,r){return!EM.includes(r)&&(0,Bg.default)(t)?e.G.bank.find(e,t,n):t}var kM=["conditions","move","then","mapping"];function pe(e,t,n,r){if(!(0,Gg.default)(t)&&!Array.isArray(t))return t;let i=Array.isArray(t)?[...t]:{...t};Object.entries(t).forEach(([a,u])=>{kM.includes(a)||(i[a]=pe(e,u,n,a))});let s=AM(e,i,n);return s?.resolveAsEntity||r==="target"||r==="targets"?Br(e,s,n,r):s}function AM(e,t,n){if(t?.type==="expression")return Rr(e,{...t,arguments:pe(e,t.arguments,n,"arguments")},n);if(t?.type==="count")return e.G.bank.findAll(e,t,n).length;if(t?.type==="contextPath")return ln(n,t.path);if(t?.type==="ctxPath")return ln(e.ctx,t.path);if(t?.type==="gamePath")return ln(e.G,t.path);if(t?.type==="RelativePath"){let r=pe(e,t.target,n,"target");return ln(r.attributes,t.path)??null}else if(t?.type==="Parent"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget;return e.G.bank.findParent(r)??null}else{if(t?.type==="map")return Lg(e,t.targets,t.mapping,n).map(r=>r.value);if(t?.type==="mapMax"){let r=Lg(e,t.targets,t.mapping,n),i,s=[];for(let o=0,a=r.length;o<a;o++){let{target:u,value:c}=r[o];i===void 0||c>i?(i=c,s.length=0,s.push(u)):c===i&&s.push(u)}return s}else if(t?.type==="Pick"){let r=pe(e,t.target,n,"target");return(0,Fg.default)(pe(e,r.attributes,n,"attributes"),t.properties)}else if(t?.type==="Coordinates"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget;return e.G.bank.findParent(r).getCoordinates(r.rule.index)}else if(t?.type==="relativeCoordinates"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget,i=e.G.bank.findParent(r),s=i.getCoordinates(r.rule.index),o=i.getRelativeCoordinates(s,pe(e,t.location,n,"location"));return(o&&i.spaces[i.getIndex(o)])??null}else return t}}function Lg(e,t,n,r){return t.resolveAsEntity=!0,pe(e,t,r)?.map(i=>({target:i,value:pe(e,n,{...r,loopTarget:i})}))??[]}var oe=class{constructor(t){this.rule=t}check(t,n,r){let i={...n},s={...r};i.target&&(s.originalTarget=i.target);let o=pe(t,this.rule,s);return o.target!==void 0&&(i.target=o.target),this.rule.target!==void 0&&!i.target?{conditionIsMet:!1}:this.checkCondition(t,o,i,s)}isMet(...t){return this.check(...t).conditionIsMet}};var Zy=he(Fr());function d2(e,t,n){let r={...t};return delete r.state,delete r.stateGroups,pe(e,r,n)}function m2(e){return{...e.rule,...e.state}}function Qa(e,t,n,r){return(0,Zy.default)(d2(e,t,r))(m2(n))}var Ur=class extends oe{checkCondition(t,n,{target:r},i){return this.rule.entity&&r!==n.entity?{target:r,conditionIsMet:!1}:{target:r,conditionIsMet:Qa(t,n.matcher,r,i)}}};var Vr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!ke(t,n,r,i).conditionsAreMet}}};function Za(e,{conditions:t=[]},n,r){let i;for(let s of t){let o=dn(s).check(e,n,r);if(o.conditionIsMet){i={...o,conditionRule:s};break}}return i}var zr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!!Za(t,n,r,i)}}};var Kr=class extends oe{checkCondition(t,n,{target:r},i){let s=r.find(o=>{let a={...i,loopTarget:o};return ke(t,n,void 0,a).conditionsAreMet});return{conditionIsMet:!!s,result:s}}};var Hr=class extends oe{checkCondition(t,n,{target:r},i){let s=r.map(o=>{let a={...i,loopTarget:o};return ke(t,n,void 0,a)});return{conditionIsMet:s.every(o=>o.conditionsAreMet),results:s}}};var s8=he(Fr());var Wr=class extends oe{checkCondition(t,n,r,i){let{target:s}=r;if(s){let a=(s.entities??s.spaces)?.filter(u=>ke(t,n,{target:u},i).conditionsAreMet)??[];return{matches:a,conditionIsMet:!!a.length}}else return{matches:[],conditionIsMet:!1}}};var ev=he(Ga());var Jr=class extends oe{checkCondition(t,n,{targets:r}){if(r.length===1&&r[0].entities?.length)return{conditionIsMet:!0};let[i,...s]=r;return{conditionIsMet:i.entities.some(a=>{let u=dn({conditionType:"Contains",conditions:[{conditionType:"Is",matcher:(0,ev.default)(a.rule,n.properties)}]});return s.every(c=>u.isMet(t,{target:c}))})}}};var h8=he(Fr());var g2=[[1,0],[0,1],[1,1],[-1,1]],tv=new WeakMap;function y2(e,t){let n={moveInstance:t.moveInstance?.id,moveArguments:t.moveArguments};return JSON.stringify({pattern:e,context:n})}function v2(e){return(e.entities||[]).map(n=>{let r=n.entities||[];return r.length===0?"empty":r.map(i=>{let s=Object.keys(i).sort(),o={};return s.forEach(a=>{o[a]=i[a]}),JSON.stringify(o)}).sort().join("|")}).join(",")}function nv(e,t,n,r,i,s=!1){let o=[],a=t.length,u=0;for(;u<=a-r;){let c=w2(e,t,u,n,i,s);c&&o.push(c),u++}return o}function b2(e,t,n){let{width:r,height:i}=e.attributes,s=[];if(t===1&&n===0)for(let o=0;o<i;o++)s.push([0,o]);else if(t===0&&n===1)for(let o=0;o<r;o++)s.push([o,0]);else if(t===1&&n===1){for(let o=0;o<r;o++)s.push([o,0]);for(let o=1;o<i;o++)s.push([0,o])}else if(t===-1&&n===1){for(let o=0;o<r;o++)s.push([o,0]);for(let o=1;o<i;o++)s.push([r-1,o])}return s}function _2(e,t,n,r,i){let s=[],[o,a]=[t,n];for(;e.areCoordinatesValid([o,a]);)s.push(e.getSpace([o,a])),o+=r,a+=i;return s}function w2(e,t,n,r,i,s=!1){let o=n,a=[],u=t.length;for(let c of r){let{count:l,minCount:f,maxCount:p,conditions:h}=c,d,y;l!==void 0?d=y=l:f!==void 0||p!==void 0?(d=f||0,y=p||1/0):d=y=1;let m=0,b=[];for(;m<y&&o<u;){let g=s?t[u-1-o]:t[o];if(O2(e,g,h,b,i))b.push(g),m++,o++;else break}if(m<d)return null;a.push(...b)}return a.length>0?a:null}function O2(e,t,n,r=[],i){return!n||n.length===0?!0:ke(e,{conditions:n},{target:t,targets:[t,...r]},i).conditionsAreMet}function Yr(e,t,n,r){let i=y2(n,r),s=tv.get(t);s||(s=new Map,tv.set(t,s));let o=v2(t),a=s.get(i);if(a&&a.stateKey===o)return a.result;let u=[],c=n.reduce((f,p)=>f+(p.minCount||p.count||1),0);for(let[f,p]of g2){let h=b2(t,f,p);for(let[d,y]of h){let m=_2(t,d,y,f,p);if(m.length<c)continue;let b=nv(e,m,n,c,r);if(u.push(...b),b.length===0||n.length>1){let g=nv(e,m,n,c,r,!0);u.push(...g)}}}let l={matches:u,conditionIsMet:!!u.length};return s.set(i,{stateKey:o,result:l}),l}var $r=class extends oe{checkCondition(t,n,r,i){let{G:s}=t,{target:o}=r,a=s.bank.findParent(r.target),{matches:u}=Yr(t,a,n.sequence,i),c=u.filter(l=>l.some(f=>f===o));return{matches:c,conditionIsMet:!!c.length}}};var Xr=class extends oe{checkCondition(t,n,r,i){let{matches:s}=Yr(t,r.target,n.sequence,i);return{matches:s,conditionIsMet:!!s.length}}};var Qr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:r.target.spaces.every(s=>s?.entities.length)}}};function Zr(e,t,n){let r=Ft(He(e.G),ht),i={...e,G:r},s={...t,arguments:{}};return Object.entries(t.arguments).forEach(([o,a])=>{s.arguments[o]=a.abstract?a:r.bank.locate(typeof a=="number"?a:a.entityId)}),n.moveInstance.doMove(i,s,n,{skipCheck:!0}),r}var P2={PlaceNew:["destination"],RemoveEntity:["entity"],MoveEntity:["entity","destination"],TakeFrom:["source","destination"],SetState:["entity","state"]},ei=class extends oe{checkCondition(t,n,{target:r,targets:i=[r]},s){let o={arguments:i.reduce((p,h,d)=>({...p,[P2[s.moveInstance.rule.moveType][d]]:h}),{})},a=Zr(t,o,s),u={};r?u={target:a.bank.locate(r.entityId)}:i&&(u={targets:i.map(p=>a.bank.locate(p.entityId))});let c=ke({...t,G:a},n,u,s),l=c.conditionsAreMet;return{results:l?eu(c.results,p=>t.G.bank.locate(p)):c.results,conditionIsMet:l}}};function eu(e,t,n=new WeakSet){if(typeof e!="object"||e===null||n.has(e))return e;if(n.add(e),e.entityId!==void 0)return t(e.entityId);if(Array.isArray(e))return e.map(r=>eu(r,t,n));{let r={};for(let i in e)e.hasOwnProperty(i)&&(r[i]=eu(e[i],t,n));return r}}var rv=he(qs());function iv(e,t=new Set){if(!e||typeof e!="object")return t;e.type==="contextPath"&&Array.isArray(e.path)&&e.path[0]==="moveArguments"&&e.path[1]&&t.add(e.path[1]);for(let n of Object.values(e))iv(n,t);return t}function E2(e){let t=Object.keys(e),n={},r={};t.forEach(o=>{n[o]=[],r[o]=0}),t.forEach(o=>{let a=e[o];iv(a).forEach(c=>{t.includes(c)&&c!==o&&(n[c].push(o),r[o]++)})});let i=t.filter(o=>r[o]===0),s=[];for(;i.length>0;){let o=i.shift();s.push(o),n[o].forEach(a=>{r[a]--,r[a]===0&&i.push(a)})}return s.length===t.length?s:t}function sv(e,t,n,r,i,s=0,o={}){if(s===r.length){let p={arguments:o};return t.isValid(e,p,i)}let a=r[s],u=n[a],c={...i,moveArguments:o},l=(0,rv.default)(u)?Br(e,{...u,matchMultiple:!0},c,a):u,f=Array.isArray(l)?l:l!==void 0?[l]:[];return f.length===0?!1:f.some(p=>sv(e,t,n,r,i,s+1,{...o,[a]:p}))}function tu(e,t){return Object.values(t).some(n=>{let{moveInstance:r}=n,i={moveInstance:r},o=pe(e,r.rule,i).arguments??{};if(Object.keys(o).length===0)return r.isValid(e,{arguments:{}},i);let a=E2(o);return sv(e,r,o,a,i)})}function ti(e,{game:t,playerID:n,stageName:r}){let i=e.ctx.phase,s=r??e.ctx.activePlayers?.[n??e.ctx.currentPlayer],o=t.phases?.[i]??t;return(o.turn?.stages?.[s]??o).moves??{}}var ni=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!tu(t,ti(t,i))}}};var G8=he(Fr());var ri=class extends oe{checkCondition(t,n,r,i){let s={...i};r?.target&&(s.target=r.target);let o=Rr(t,n,s);return{result:o,conditionIsMet:!!o}}};var ii=class extends oe{checkCondition(t,n,{target:r}){let i=t.G.bank.findParent(r),s;return n.position==="First"&&(s=i.entities.indexOf(r)===0),{conditionIsMet:s}}};function dn(e){if(e.conditionType==="Is")return new Ur(e);if(e.conditionType==="Not")return new Vr(e);if(e.conditionType==="Or")return new zr(e);if(e.conditionType==="Some")return new Kr(e);if(e.conditionType==="Contains")return new Wr(e);if(e.conditionType==="ContainsSame")return new Jr(e);if(e.conditionType==="Every")return new Hr(e);if(e.conditionType==="InLine")return new $r(e);if(e.conditionType==="HasLine")return new Xr(e);if(e.conditionType==="IsFull")return new Qr(e);if(e.conditionType==="Would")return new ei(e);if(e.conditionType==="NoPossibleMoves")return new ni(e);if(e.conditionType==="Evaluate")return new ri(e);if(e.conditionType==="Position")return new ii(e)}function ke(e,t,n,r){let{conditions:i=[]}=t,s=[],o;for(let a of i){let u=dn(a).check(e,n,r);if(u.conditionIsMet)s.push(u);else{o=a;break}}return{results:s,failedAt:o,conditionsAreMet:s.length===i.length}}var nu=class{constructor(t,n){this.bank=n,this.rule=t,this.pool=[],this.remaining=+t.count||1}getOne(t,n,r){return this.getMultiple(t,1,n,r)[0]}getMultiple(t,n=1/0,r={},i){let s=[];if(this.remaining===1/0&&n===1/0)throw new Error(`Cannot get infinite pieces from slot with infinite remaining: ${this.rule.name}`);if(n!==1/0&&n>this.remaining)throw new Error(`Requested ${n} pieces but only ${this.remaining} available in slot: ${this.rule.name}`);let o=n===1/0?this.remaining:n;this.remaining!==1/0&&(this.remaining-=o);let a=Math.min(o,this.pool.length);s.push(...this.pool.splice(0,a));let u=o-a;if(u>0&&s.push(...Array.from(new Array(u)).map(()=>this.bank.createEntity(this.rule))),r.state){let c=pe(t,r.state,i);s.forEach(l=>{l.state={...l.state,...c}})}return s}returnToBank(t){t.rule.state?t.state=t.rule.state:delete t.state,this.remaining!==void 0&&(this.remaining+=1),this.pool.push(t)}},zs=nu;var ru=class{constructor(t){this.currentEntityId=0,this.tracker={},this.slots=t.map(n=>new zs(n,this))}createEntity(t={},n){let r=new ht[t.entityType||"Entity"]({bank:this,fromBank:!0,...n},t,this.currentEntityId++);return this.track(r),r}track(t){this.tracker[t.entityId]=t}locate(t){return this.tracker[t]}findAll(t,n,r){if(!n.conditions)throw new Error(`Cannot find entity with no conditions. Rule: ${JSON.stringify(n)}`);return(0,av.default)(Object.values(this.tracker),i=>ke(t,n,{target:i},r).conditionsAreMet)}findOne(t,n,r){return this.findAll(t,n,r)[0]}find(t,n,r){return n.matchMultiple?this.findAll(t,n,r):this.findOne(t,n,r)}findParent(t){return(0,ov.default)(this.tracker,n=>n.entities?.includes(t)||n.spaces?.includes(t))}getOne(t,n,r){let i=this.getSlot(t,n,r);return i||console.error(`No matching slot for ${JSON.stringify(n)}`),i.getOne(t,{state:n.state},r)}getMultiple(t,n,r,i){let s=this.getSlots(t,n,i);return s.length||console.error(`No matching slots for ${JSON.stringify(n)}`),s.reduce((o,a)=>[...o,...a.getMultiple(t,r,{state:n.state})],[])}getSlot(t,n,r){return this.slots.find(i=>ke(t,n,{target:i},r).conditionsAreMet)}getSlots(t,n,r){return this.slots.filter(i=>ke(t,n,{target:i},r).conditionsAreMet)}returnToBank(t,n){this.findParent(n).remove(n),this.getSlot(t,n.rule).returnToBank(n),delete this.tracker[n.entityId]}},Ks=ru;var ht={Board:wr,SpaceGroup:sn,Space:rn,Grid:Ar,Bank:Ks,BankSlot:zs,Entity:Et};function Mt(e){return{...e,G:Ft(JSON.stringify(e.G),ht)}}var uv=he(aa());var we=class{constructor(t){this.rule=this.transformRule(t)}checkValidity(t,n,r){let i=Object.entries(this.rule.arguments??{});if(!i.every(([a])=>{let u=n.arguments[a];return u!==void 0&&(!Array.isArray(u)||u.length)}))return!1;let s={};for(let a=0,u=i.length;a<u;a++){let[c,l]=i[a],f=n.arguments[c],p=Array.isArray(f)?f:[f],h=[];for(let y=0,m=p.length;y<m;y++){let b=p[y],g=ke(t,l,{target:b},{...r,moveArguments:n.arguments});if(h.push(g),!g.conditionsAreMet)break}let d=h.at(-1).conditionsAreMet;if(s[c]={results:h,conditionsAreMet:d},!d)break}let o=ke(t,{conditions:this.rule.conditions},void 0,{...r,moveArguments:n.arguments});return{argumentResults:s,moveResults:o,conditionsAreMet:o.conditionsAreMet&&Object.values(s).every(a=>a.conditionsAreMet)}}isValid(t,n,r){return this.checkValidity(t,n,r).conditionsAreMet}doMove(t,n,r,{skipCheck:i=!1}={}){let s=pe(t,this.rule,r),o={...n,arguments:Object.entries(s.arguments??{}).reduce((u,[c,l])=>({...u,[c]:n?.arguments?.[c]??l}),{})};s.name&&(t.G._meta.previousPayloads[s.name]=o);let a;return i||(a=this.checkValidity(t,o,r)),!i&&!a.conditionsAreMet?uv.INVALID_MOVE:(this.do(t,s,o,r),r&&(r.previousArguments=o.arguments),{conditionResults:a})}transformRule(t){let n=t.arguments;for(let r in n){let i=n[r];i.playerChoice||(i.resolveAsEntity=!0)}return t}};var si=class extends we{do(t,n,{arguments:{entity:r,destination:i}}){Array.isArray(r)?r.forEach(s=>{t.G.bank.findParent(s)?.remove(s),i.placeEntity(s,n.position)}):(t.G.bank.findParent(r)?.remove(r),i.placeEntity(r,n.position))}};var oi=class extends we{do(t,n,{arguments:{entity:r}}){t.G.bank.returnToBank(t,r)}};var ai=class extends we{do(t,n,{arguments:{destination:r}},i){(n.matchMultiple?t.G.bank.getMultiple(t,{...n.entity,conditions:[...n.entity?.conditions||[],...n.conditions||[]]},n.count,i):[t.G.bank.getOne(t,{...n.entity,conditions:[...n.entity?.conditions||[],...n.conditions||[]]},i)]).forEach(o=>{r.placeEntity(o,n.position)})}};var ui=class extends we{do(t,n,{arguments:{source:r,destination:i}}){i.placeEntity(r.takeOne(n.arguments.source.position))}};var ci=class extends we{do(t,n,{arguments:{entity:r,state:i}}){r.state={...r.state,[i.property]:i.value}}};function mn(e,t=[],n){return t?.length&&t.forEach(r=>{Hn(r,n.game).moveInstance.doMove(e,void 0,n)}),e.G}var li=class extends we{do(t,n,r,i){t.events.setActivePlayers(n.options);let s=t.ctx.phase,o=n.options.currentPlayer?.stage,u=(i.game.phases?.[s]??i.game)?.turn?.stages?.[o];mn(t,u?.initialMoves,{...i,stageName:o})}};var fi=class extends we{do(t){t.events.endTurn()}};var pi=class extends we{do(t){t.G._meta.passedPlayers.length<t.ctx.numPlayers&&(t.G._meta.passedPlayers.push(t.ctx.currentPlayer),t.events.pass())}};var hi=class extends we{do(t,n,{arguments:{targets:r}},i){r.forEach(s=>{let o={...i,loopTarget:s};Hs(n.move).doMove(t,void 0,o)})}};var di=class extends we{do(t){t.events.endTurn()}};var mi=class extends we{do(t,n,{arguments:{target:r}}){r.entities=t.random.Shuffle(r.entities)}};function Hn(e,t){let n=Hs(e),r=function(i,s){let o=Mt(i),{G:a}=o,u=k2(s,a),c={moveInstance:n,game:t},l=n.doMove(o,u,c);if(c.moveConditionResults=[l],l!==cv.INVALID_MOVE&&e.then)for(let f of e.then){let p=Hs(f).doMove(o,{},{...c});c.moveConditionResults.push(p)}return JSON.parse(He(a))};return r.moveInstance=n,r}function k2(e,t){if(e){let n=Ft(JSON.stringify(e),ht);return n.arguments=Object.entries(n.arguments).reduce((r,[i,s])=>({...r,[i]:typeof s=="number"?t.bank.locate(s):s}),{}),n}else return e}function Hs(e){switch(e.moveType){case"MoveEntity":return new si(e);case"PlaceNew":return new ai(e);case"RemoveEntity":return new oi(e);case"TakeFrom":return new ui(e);case"SetState":return new ci(e);case"ForEach":return new hi(e);case"Pass":return new di(e);case"Shuffle":return new mi(e);case"SetActivePlayers":return new li(e);case"EndTurn":return new fi(e);case"PassTurn":return new pi(e)}}var b6=he(fv()),hv=he(Ra());function iu(e,t){return JSON.parse(JSON.stringify(e),(n,r)=>{let i=r;for(let s of t)s.test(i)&&(i=s.replace(i));return i})}var M2=[{entityType:"Space",count:"Infinity"},{entityType:"Board",name:"sharedBoard"},{name:"playerMarker",perPlayer:!0,count:"Infinity"}];function I2(e){e.entities=[...M2,...e.entities||[]]}function pv(e,t){if(e.sharedBoard){let n=e.sharedBoard.map(r=>({entity:r,destination:{name:"sharedBoard"}}));e.initialPlacements||(e.initialPlacements=[]),e.initialPlacements.unshift(...n)}if(e.personalBoard){t.push({entityType:"Board",name:"personalBoard",perPlayer:!0});let n=e.personalBoard.map(r=>({entity:r,destination:{name:"personalBoard"}}));e.initialPlacements||(e.initialPlacements=[]),e.initialPlacements.unshift(...n)}if(e.initialPlacements){let n=e.initialPlacements.map(r=>{let{state:i,...s}=r.entity,o=(0,hv.default)(t,s);return r.destination.name==="personalBoard"?{moveType:"ForEach",arguments:{targets:{type:"ctxPath",path:["playOrder"]}},move:{moveType:"PlaceNew",entity:{state:i,conditions:[{conditionType:"Is",matcher:{...s,...o.perPlayer?{player:{type:"contextPath",path:["loopTarget"]}}:{}}}]},arguments:{destination:{conditions:[{conditionType:"Is",matcher:{...r.destination,player:{type:"contextPath",path:["loopTarget"]}}}]}}}}:{moveType:"PlaceNew",entity:{state:i,conditions:[{conditionType:"Is",matcher:s}]},arguments:{destination:{conditions:[{conditionType:"Is",matcher:r.destination}]}}}});e.initialMoves||(e.initialMoves=[]),e.initialMoves.unshift(...n),delete e.initialPlacements}}var N2=[],su=[["isCurrentPlayer",{conditionType:"Is",matcher:{player:{type:"ctxPath",path:["currentPlayer"]}}}],["isEmpty",{conditionType:"Not",conditions:[{conditionType:"Contains"}]}],["ownerOfFirstResultEntity",{type:"contextPath",path:["results",0,"matches",0,0,"entities",0,"attributes","player"]}]],C2=[{test:e=>e&&typeof e=="object",replace:e=>(N2.forEach(([t,n])=>{e.hasOwnProperty(t)&&(e[n]=e[t],delete e[t])}),e)},{test:e=>typeof e=="string",replace:e=>{for(let t=0,n=su.length;t<n;t++)if(e===su[t][0])return su[t][1];return e}},{test:e=>e?.conditions,replace:e=>(Array.isArray(e.conditions)||(e.conditions=[e.conditions]),e)},{test:e=>e?.conditions,replace:e=>{for(let t=0,n=e.conditions.length;t<n;t++)e.conditions[t].conditionType||(e.conditions[t]={conditionType:"Is",matcher:e.conditions[t]});return e}},{test:e=>typeof e?.target=="string",replace:e=>({...e,target:{conditions:[{conditionType:"Is",matcher:{name:e.target}}]}})}];function ou(e){let t=iu(e,C2);return t.sharedBoard||(t.sharedBoard=t.entities),t.turn||(t.turn={minMoves:1,maxMoves:1}),I2(t),pv(t,t.entities),t.phases&&Object.entries(t.phases).forEach(n=>{pv(n,t.entities)}),e.numPlayers&&(e.minPlayers=e.maxPlayers=e.numPlayers),t}function Ws(e,t,n){let r;for(let i of t){let s=ke(e,i);if(s.conditionsAreMet){r={scenario:i,conditionResults:s};break}}return r?.scenario?.result?pe(e,r.scenario.result,{results:r.conditionResults.results}):r}function gi(e,t){let n={name:t},r=ou(e);return n.setup=i=>{let{ctx:s}=i,o={_meta:{passedPlayers:[],previousPayloads:{}}},a=q2(r.entities,s);return o.bank=new Ks(a),o.sharedBoard=o.bank.getOne(i,{conditions:[{conditionType:"Is",matcher:{name:"sharedBoard"}}]}),r.personalBoard&&(o.personalBoards=i.ctx.playOrder.map(u=>o.bank.getOne(i,{conditions:[{conditionType:"Is",matcher:{name:"personalBoard",player:u}}]}))),r.initialMoves?.forEach(u=>{Hn(u,n).moveInstance.doMove({...i,G:o})}),JSON.parse(He(o))},r.moves&&(n.moves=au(r.moves,n)),r.turn&&(n.turn=dv(r.turn,n)),r.phases&&(n.phases=Object.entries(r.phases).reduce((i,[s,o])=>({...i,[s]:j2(o,n)}),{})),r.endIf&&(n.endIf=i=>{let s=Mt(i);return Ws(s,r.endIf)}),e.DEBUG_DISABLE_SECRET_STATE||(n.playerView=i=>{let{G:s,playerID:o}=Mt(i);return Object.values(s.bank.tracker).forEach(a=>{(a.rule.contentsHiddenFrom==="All"||a.rule.contentsHiddenFrom==="Others"&&(o!==a.rule.player||o==null))&&(a.spaces&&(a.spaces=a.rule.hideLength?[]:a.spaces.map(()=>s.bank.createEntity())),a.entities&&(a.entities=a.rule.hideLength?[]:a.entities.map(()=>s.bank.createEntity())))}),JSON.parse(He(s))}),n}function q2(e,t){return e.reduce((n,r)=>{let i={...r};if(i.perPlayer&&(delete i.perPlayer,i.variants?i.variants=new Array(t.numPlayers).fill().reduce((s,o,a)=>[...s,...i.variants.map(u=>({...u,player:`${a}`}))],[]):i.variants=new Array(t.numPlayers).fill().map((s,o)=>({player:`${o}`}))),i.variants){let s=i.variants;return delete i.variants,[...n,...s.map(o=>({...i,...o}))]}else return[...n,i]},[])}function dv(e,t){let n={...e};return n.onBegin=r=>{let i=Mt(r),s=e.stages?.[i.ctx.activePlayers?.[i.ctx.currentPlayer]];return i.G._meta.passedPlayers=i.G._meta.passedPlayers.filter(o=>o!==i.ctx.currentPlayer),mn(i,e.initialMoves,{game:t}),mn(i,s?.initialMoves,{game:t}),JSON.parse(He(i.G))},e.stages&&Object.entries(e.stages).forEach(([r,i])=>{i.moves&&(n.stages[r].moves=au(i.moves,t))}),e.order?.playOrder==="RotateFirst"&&(e.order.first=()=>0,e.order.next=({ctx:r})=>(r.playOrderPos+1)%r.numPlayers,n.order.playOrder=({ctx:r,G:i})=>i._meta.isAfterFirstPhase?[...r.playOrder.slice(1),r.playOrder[0]]:r.playOrder),n}function j2(e,t){let n={...e};return e.turn&&(n.turn=dv(e.turn,t)),e.moves&&(n.moves=au(e.moves,t)),n.onBegin=r=>{let i=Mt(r);return mn(i,e.initialMoves,{game:t}),i.G._meta.currentPhaseHasBeenSetUp=!0,i.G._meta.nextPhase=e.next,JSON.parse(He(i.G))},e.endIf&&(n.endIf=r=>{let i=Mt(r);if(i.G._meta.currentPhaseHasBeenSetUp){let s=Ws(i,e.endIf);if(s)return s}}),n.onEnd=({G:r})=>{r._meta.currentPhaseHasBeenSetUp=!1,r._meta.isAfterFirstPhase=!0},n}function au(e,t){return Object.entries(e).reduce((n,[r,i])=>({...n,[r]:Hn({...i,name:r},t)}),{})}var D2="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var mv=(e=21)=>{let t="",n=e|0;for(;n--;)t+=D2[Math.random()*64|0];return t};function st(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0)var i,s;throw Error("[Immer] minified error nr: "+e+(n.length?" "+n.map(function(o){return"'"+o+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function Wn(e){return!!e&&!!e[Je]}function yn(e){var t;return!!e&&(function(n){if(!n||typeof n!="object")return!1;var r=Object.getPrototypeOf(n);if(r===null)return!0;var i=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return i===Object||typeof i=="function"&&Function.toString.call(i)===z2}(e)||Array.isArray(e)||!!e[Pv]||!!(!((t=e.constructor)===null||t===void 0)&&t[Pv])||yu(e)||vu(e))}function vi(e,t,n){n===void 0&&(n=!1),Jn(e)===0?(n?Object.keys:Pu)(e).forEach(function(r){n&&typeof r=="symbol"||t(r,e[r],e)}):e.forEach(function(r,i){return t(i,r,e)})}function Jn(e){var t=e[Je];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:yu(e)?2:vu(e)?3:0}function pu(e,t){return Jn(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function R2(e,t){return Jn(e)===2?e.get(t):e[t]}function Ev(e,t,n){var r=Jn(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function B2(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function yu(e){return U2&&e instanceof Map}function vu(e){return V2&&e instanceof Set}function gn(e){return e.o||e.t}function bu(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=K2(e);delete t[Je];for(var n=Pu(t),r=0;r<n.length;r++){var i=n[r],s=t[i];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[i]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[i]})}return Object.create(Object.getPrototypeOf(e),t)}function _u(e,t){return t===void 0&&(t=!1),wu(e)||Wn(e)||!yn(e)||(Jn(e)>1&&(e.set=e.add=e.clear=e.delete=L2),Object.freeze(e),t&&vi(e,function(n,r){return _u(r,!0)},!0)),e}function L2(){st(2)}function wu(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function dt(e){var t=H2[e];return t||st(18,e),t}function gv(){return bi}function uu(e,t){t&&(dt("Patches"),e.u=[],e.s=[],e.v=t)}function Js(e){hu(e),e.p.forEach(G2),e.p=null}function hu(e){e===bi&&(bi=e.l)}function yv(e){return bi={p:[],l:bi,h:e,m:!0,_:0}}function G2(e){var t=e[Je];t.i===0||t.i===1?t.j():t.g=!0}function cu(e,t){t._=t.p.length;var n=t.p[0],r=e!==void 0&&e!==n;return t.h.O||dt("ES5").S(t,e,r),r?(n[Je].P&&(Js(t),st(4)),yn(e)&&(e=Ys(t,e),t.l||$s(t,e)),t.u&&dt("Patches").M(n[Je].t,e,t.u,t.s)):e=Ys(t,n,[]),Js(t),t.u&&t.v(t.u,t.s),e!==kv?e:void 0}function Ys(e,t,n){if(wu(t))return t;var r=t[Je];if(!r)return vi(t,function(a,u){return vv(e,r,t,a,u,n)},!0),t;if(r.A!==e)return t;if(!r.P)return $s(e,r.t,!0),r.t;if(!r.I){r.I=!0,r.A._--;var i=r.i===4||r.i===5?r.o=bu(r.k):r.o,s=i,o=!1;r.i===3&&(s=new Set(i),i.clear(),o=!0),vi(s,function(a,u){return vv(e,r,i,a,u,n,o)}),$s(e,i,!1),n&&e.u&&dt("Patches").N(r,n,e.u,e.s)}return r.o}function vv(e,t,n,r,i,s,o){if(Wn(i)){var a=Ys(e,i,s&&t&&t.i!==3&&!pu(t.R,r)?s.concat(r):void 0);if(Ev(n,r,a),!Wn(a))return;e.m=!1}else o&&n.add(i);if(yn(i)&&!wu(i)){if(!e.h.D&&e._<1)return;Ys(e,i),t&&t.A.l||$s(e,i)}}function $s(e,t,n){n===void 0&&(n=!1),!e.l&&e.h.D&&e.m&&_u(t,n)}function lu(e,t){var n=e[Je];return(n?gn(n):e)[t]}function bv(e,t){if(t in e)for(var n=Object.getPrototypeOf(e);n;){var r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=Object.getPrototypeOf(n)}}function du(e){e.P||(e.P=!0,e.l&&du(e.l))}function fu(e){e.o||(e.o=bu(e.t))}function mu(e,t,n){var r=yu(t)?dt("MapSet").F(t,n):vu(t)?dt("MapSet").T(t,n):e.O?function(i,s){var o=Array.isArray(i),a={i:o?1:0,A:s?s.A:gv(),P:!1,I:!1,R:{},l:s,t:i,k:null,o:null,j:null,C:!1},u=a,c=gu;o&&(u=[a],c=yi);var l=Proxy.revocable(u,c),f=l.revoke,p=l.proxy;return a.k=p,a.j=f,p}(t,n):dt("ES5").J(t,n);return(n?n.A:gv()).p.push(r),r}function F2(e){return Wn(e)||st(22,e),function t(n){if(!yn(n))return n;var r,i=n[Je],s=Jn(n);if(i){if(!i.P&&(i.i<4||!dt("ES5").K(i)))return i.t;i.I=!0,r=_v(n,s),i.I=!1}else r=_v(n,s);return vi(r,function(o,a){i&&R2(i.t,o)===a||Ev(r,o,t(a))}),s===3?new Set(r):r}(e)}function _v(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return bu(e)}var wv,bi,Ou=typeof Symbol<"u"&&typeof Symbol("x")=="symbol",U2=typeof Map<"u",V2=typeof Set<"u",Ov=typeof Proxy<"u"&&Proxy.revocable!==void 0&&typeof Reflect<"u",kv=Ou?Symbol.for("immer-nothing"):((wv={})["immer-nothing"]=!0,wv),Pv=Ou?Symbol.for("immer-draftable"):"__$immer_draftable",Je=Ou?Symbol.for("immer-state"):"__$immer_state";var z2=""+Object.prototype.constructor,Pu=typeof Reflect<"u"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,K2=Object.getOwnPropertyDescriptors||function(e){var t={};return Pu(e).forEach(function(n){t[n]=Object.getOwnPropertyDescriptor(e,n)}),t},H2={},gu={get:function(e,t){if(t===Je)return e;var n=gn(e);if(!pu(n,t))return function(i,s,o){var a,u=bv(s,o);return u?"value"in u?u.value:(a=u.get)===null||a===void 0?void 0:a.call(i.k):void 0}(e,n,t);var r=n[t];return e.I||!yn(r)?r:r===lu(e.t,t)?(fu(e),e.o[t]=mu(e.A.h,r,e)):r},has:function(e,t){return t in gn(e)},ownKeys:function(e){return Reflect.ownKeys(gn(e))},set:function(e,t,n){var r=bv(gn(e),t);if(r?.set)return r.set.call(e.k,n),!0;if(!e.P){var i=lu(gn(e),t),s=i?.[Je];if(s&&s.t===n)return e.o[t]=n,e.R[t]=!1,!0;if(B2(n,i)&&(n!==void 0||pu(e.t,t)))return!0;fu(e),du(e)}return e.o[t]===n&&(n!==void 0||t in e.o)||Number.isNaN(n)&&Number.isNaN(e.o[t])||(e.o[t]=n,e.R[t]=!0),!0},deleteProperty:function(e,t){return lu(e.t,t)!==void 0||t in e.t?(e.R[t]=!1,fu(e),du(e)):delete e.R[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var n=gn(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty:function(){st(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){st(12)}},yi={};vi(gu,function(e,t){yi[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),yi.deleteProperty=function(e,t){return yi.set.call(this,e,t,void 0)},yi.set=function(e,t,n){return gu.set.call(this,e[0],t,n,e[0])};var W2=function(){function e(n){var r=this;this.O=Ov,this.D=!0,this.produce=function(i,s,o){if(typeof i=="function"&&typeof s!="function"){var a=s;s=i;var u=r;return function(y){var m=this;y===void 0&&(y=a);for(var b=arguments.length,g=Array(b>1?b-1:0),O=1;O<b;O++)g[O-1]=arguments[O];return u.produce(y,function(I){var j;return(j=s).call.apply(j,[m,I].concat(g))})}}var c;if(typeof s!="function"&&st(6),o!==void 0&&typeof o!="function"&&st(7),yn(i)){var l=yv(r),f=mu(r,i,void 0),p=!0;try{c=s(f),p=!1}finally{p?Js(l):hu(l)}return typeof Promise<"u"&&c instanceof Promise?c.then(function(y){return uu(l,o),cu(y,l)},function(y){throw Js(l),y}):(uu(l,o),cu(c,l))}if(!i||typeof i!="object"){if((c=s(i))===void 0&&(c=i),c===kv&&(c=void 0),r.D&&_u(c,!0),o){var h=[],d=[];dt("Patches").M(i,c,h,d),o(h,d)}return c}st(21,i)},this.produceWithPatches=function(i,s){if(typeof i=="function")return function(c){for(var l=arguments.length,f=Array(l>1?l-1:0),p=1;p<l;p++)f[p-1]=arguments[p];return r.produceWithPatches(c,function(h){return i.apply(void 0,[h].concat(f))})};var o,a,u=r.produce(i,s,function(c,l){o=c,a=l});return typeof Promise<"u"&&u instanceof Promise?u.then(function(c){return[c,o,a]}):[u,o,a]},typeof n?.useProxies=="boolean"&&this.setUseProxies(n.useProxies),typeof n?.autoFreeze=="boolean"&&this.setAutoFreeze(n.autoFreeze)}var t=e.prototype;return t.createDraft=function(n){yn(n)||st(8),Wn(n)&&(n=F2(n));var r=yv(this),i=mu(this,n,void 0);return i[Je].C=!0,hu(r),i},t.finishDraft=function(n,r){var i=n&&n[Je],s=i.A;return uu(s,r),cu(void 0,s)},t.setAutoFreeze=function(n){this.D=n},t.setUseProxies=function(n){n&&!Ov&&st(20),this.O=n},t.applyPatches=function(n,r){var i;for(i=r.length-1;i>=0;i--){var s=r[i];if(s.path.length===0&&s.op==="replace"){n=s.value;break}}i>-1&&(r=r.slice(i+1));var o=dt("Patches").$;return Wn(n)?o(n,r):this.produce(n,function(a){return o(a,r)})},e}(),Ye=new W2,J2=Ye.produce,j6=Ye.produceWithPatches.bind(Ye),D6=Ye.setAutoFreeze.bind(Ye),R6=Ye.setUseProxies.bind(Ye),B6=Ye.applyPatches.bind(Ye),L6=Ye.createDraft.bind(Ye),G6=Ye.finishDraft.bind(Ye),Av=J2;var Eu=class{constructor(t){let n=Y2();this.c=1,this.s0=n(" "),this.s1=n(" "),this.s2=n(" "),this.s0-=n(t),this.s0<0&&(this.s0+=1),this.s1-=n(t),this.s1<0&&(this.s1+=1),this.s2-=n(t),this.s2<0&&(this.s2+=1)}next(){let t=2091639*this.s0+this.c*23283064365386963e-26;return this.s0=this.s1,this.s1=this.s2,this.s2=t-(this.c=Math.trunc(t))}};function Y2(){let e=4022871197;return function(n){let r=n.toString();for(let i=0;i<r.length;i++){e+=r.charCodeAt(i);let s=.02519603282416938*e;e=s>>>0,s-=e,s*=e,e=s>>>0,s-=e,e+=s*4294967296}return(e>>>0)*23283064365386963e-26}}function xv(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function ku(e,t){let n=new Eu(e),r=n.next.bind(n);return t&&xv(t,n),r.state=()=>xv(n,{}),r}var Xs=class{constructor(t){this.state=t||{seed:"0"},this.used=!1}static seed(){return Date.now().toString(36).slice(-10)}isUsed(){return this.used}getState(){return this.state}_random(){this.used=!0;let t=this.state,n=t.prngstate?"":t.seed,r=ku(n,t.prngstate),i=r();return this.state={...t,prngstate:r.state()},i}api(){let t=this._random.bind(this),n={D4:4,D6:6,D8:8,D10:10,D12:12,D20:20},r={};for(let s in n){let o=n[s];r[s]=a=>a===void 0?Math.floor(t()*o)+1:Array.from({length:a}).map(()=>Math.floor(t()*o)+1)}function i(s=6,o){return o===void 0?Math.floor(t()*s)+1:Array.from({length:o}).map(()=>Math.floor(t()*s)+1)}return{...r,Die:i,Number:()=>t(),Shuffle:s=>{let o=[...s],a=s.length,u=0,c=Array.from({length:a});for(;a;){let l=Math.trunc(a*t());c[u++]=o[l],o[l]=o[--a]}return c},_private:this}}},Sv={name:"random",noClient:({api:e})=>e._private.isUsed(),flush:({api:e})=>e._private.getState(),api:({data:e})=>new Xs(e).api(),setup:({game:e})=>{let{seed:t}=e;return t===void 0&&(t=Xs.seed()),{seed:t}},playerView:()=>{}};var $2=he(tn()),_i="MAKE_MOVE",Yn="GAME_EVENT",wi="REDO",Oi="RESET",Pi="SYNC",Ei="UNDO",ki="UPDATE",Ai="PATCH",Su="PLUGIN",$n="STRIP_TRANSIENTS",Tu=(e,t,n,r)=>({type:_i,payload:{type:e,args:t,playerID:n,credentials:r}}),vn=(e,t,n,r)=>({type:Yn,payload:{type:e,args:t,playerID:n,credentials:r}}),Tv=(e,t,n,r)=>({type:Yn,payload:{type:e,args:t,playerID:n,credentials:r},automatic:!0}),xi=e=>({type:Pi,state:e.state,log:e.log,initialState:e.initialState,clientOnly:!0}),Mu=(e,t,n,r)=>({type:Ai,prevStateID:e,stateID:t,patch:n,deltalog:r,clientOnly:!0}),Iu=(e,t)=>({type:ki,state:e,deltalog:t,clientOnly:!0}),Nu=e=>({type:Oi,state:e,clientOnly:!0}),Cu=(e,t)=>({type:Ei,payload:{type:null,args:null,playerID:e,credentials:t}}),qu=(e,t)=>({type:wi,payload:{type:null,args:null,playerID:e,credentials:t}}),X2=(e,t,n,r)=>({type:Su,payload:{type:e,args:t,playerID:n,credentials:r}}),ju=()=>({type:$n}),Mv=Object.freeze({__proto__:null,makeMove:Tu,gameEvent:vn,automaticGameEvent:Tv,sync:xi,patch:Mu,update:Iu,reset:Nu,undo:Cu,redo:qu,plugin:X2,stripTransients:ju}),Zs="INVALID_MOVE",Q2={name:"plugin-immer",fnWrap:e=>(t,...n)=>{let r=!1,i=Av(t.G,s=>{let o=e({...t,G:s},...n);if(o===Zs){r=!0;return}return o});return r?Zs:i}},Re;(function(e){e.MOVE="MOVE",e.GAME_ON_END="GAME_ON_END",e.PHASE_ON_BEGIN="PHASE_ON_BEGIN",e.PHASE_ON_END="PHASE_ON_END",e.TURN_ON_BEGIN="TURN_ON_BEGIN",e.TURN_ON_MOVE="TURN_ON_MOVE",e.TURN_ON_END="TURN_ON_END"})(Re||(Re={}));var It;(function(e){e.CalledOutsideHook="Events must be called from moves or the `onBegin`, `onEnd`, and `onMove` hooks.\nThis error probably means you called an event from other game code, like an `endIf` trigger or one of the `turn.order` methods.",e.EndTurnInOnEnd="`endTurn` is disallowed in `onEnd` hooks \u2014 the turn is already ending.",e.MaxTurnEndings=`Maximum number of turn endings exceeded for this update.
|
|
7
|
+
`,n+1);while(n>=0&&n<this.pos);return{line:e,column:t}};Te.prototype.parseError=function(e){var t=this.getCoordinates();throw new Error("parse error ["+t.line+":"+t.column+"]: "+e)};function _e(e,t,n){this.parser=e,this.tokens=t,this.current=null,this.nextToken=null,this.next(),this.savedCurrent=null,this.savedNextToken=null,this.allowMemberAccess=n.allowMemberAccess!==!1}_e.prototype.next=function(){return this.current=this.nextToken,this.nextToken=this.tokens.next()};_e.prototype.tokenMatches=function(e,t){return typeof t>"u"?!0:Array.isArray(t)?Bn(t,e.value):typeof t=="function"?t(e):e.value===t};_e.prototype.save=function(){this.savedCurrent=this.current,this.savedNextToken=this.nextToken,this.tokens.save()};_e.prototype.restore=function(){this.tokens.restore(),this.current=this.savedCurrent,this.nextToken=this.savedNextToken};_e.prototype.accept=function(e,t){return this.nextToken.type===e&&this.tokenMatches(this.nextToken,t)?(this.next(),!0):!1};_e.prototype.expect=function(e,t){if(!this.accept(e,t)){var n=this.tokens.getCoordinates();throw new Error("parse error ["+n.line+":"+n.column+"]: Expected "+(t||e))}};_e.prototype.parseAtom=function(e){var t=this.tokens.unaryOps;function n(i){return i.value in t}if(this.accept(Wa)||this.accept(me,n))e.push(new re(xt,this.current.value));else if(this.accept(Ls))e.push(new re(tt,this.current.value));else if(this.accept(qg))e.push(new re(tt,this.current.value));else if(this.accept(St,"("))this.parseExpression(e),this.expect(St,")");else if(this.accept(Fn,"["))if(this.accept(Fn,"]"))e.push(new re(Gn,0));else{var r=this.parseArrayList(e);e.push(new re(Gn,r))}else throw new Error("unexpected "+this.nextToken)};_e.prototype.parseExpression=function(e){var t=[];this.parseUntilEndStatement(e,t)||(this.parseVariableAssignmentExpression(t),!this.parseUntilEndStatement(e,t)&&this.pushExpression(e,t))};_e.prototype.pushExpression=function(e,t){for(var n=0,r=t.length;n<r;n++)e.push(t[n])};_e.prototype.parseUntilEndStatement=function(e,t){return this.accept(Ja)?(this.nextToken&&this.nextToken.type!==Dr&&!(this.nextToken.type===St&&this.nextToken.value===")")&&t.push(new re(Rs)),this.nextToken.type!==Dr&&this.parseExpression(t),e.push(new re(ze,t)),!0):!1};_e.prototype.parseArrayList=function(e){for(var t=0;!this.accept(Fn,"]");)for(this.parseExpression(e),++t;this.accept(Gs);)this.parseExpression(e),++t;return t};_e.prototype.parseVariableAssignmentExpression=function(e){for(this.parseConditionalExpression(e);this.accept(me,"=");){var t=e.pop(),n=[],r=e.length-1;if(t.type===Ln){if(!this.tokens.isOperatorEnabled("()="))throw new Error("function definition is not permitted");for(var i=0,s=t.value+1;i<s;i++){var o=r-i;e[o].type===xt&&(e[o]=new re(pn,e[o].value))}this.parseVariableAssignmentExpression(n),e.push(new re(ze,n)),e.push(new re(Ds,t.value));continue}if(t.type!==xt&&t.type!==hn)throw new Error("expected variable for assignment");this.parseVariableAssignmentExpression(n),e.push(new re(pn,t.value)),e.push(new re(ze,n)),e.push(Tt("="))}};_e.prototype.parseConditionalExpression=function(e){for(this.parseOrExpression(e);this.accept(me,"?");){var t=[],n=[];this.parseConditionalExpression(t),this.expect(me,":"),this.parseConditionalExpression(n),e.push(new re(ze,t)),e.push(new re(ze,n)),e.push(Ng("?"))}};_e.prototype.parseOrExpression=function(e){for(this.parseAndExpression(e);this.accept(me,"or");){var t=[];this.parseAndExpression(t),e.push(new re(ze,t)),e.push(Tt("or"))}};_e.prototype.parseAndExpression=function(e){for(this.parseComparison(e);this.accept(me,"and");){var t=[];this.parseComparison(t),e.push(new re(ze,t)),e.push(Tt("and"))}};var IT=["==","!=","<","<=",">=",">","in"];_e.prototype.parseComparison=function(e){for(this.parseAddSub(e);this.accept(me,IT);){var t=this.current;this.parseAddSub(e),e.push(Tt(t.value))}};var NT=["+","-","||"];_e.prototype.parseAddSub=function(e){for(this.parseTerm(e);this.accept(me,NT);){var t=this.current;this.parseTerm(e),e.push(Tt(t.value))}};var CT=["*","/","%"];_e.prototype.parseTerm=function(e){for(this.parseFactor(e);this.accept(me,CT);){var t=this.current;this.parseFactor(e),e.push(Tt(t.value))}};_e.prototype.parseFactor=function(e){var t=this.tokens.unaryOps;function n(i){return i.value in t}if(this.save(),this.accept(me,n)){if(this.current.value!=="-"&&this.current.value!=="+"){if(this.nextToken.type===St&&this.nextToken.value==="("){this.restore(),this.parseExponential(e);return}else if(this.nextToken.type===Ja||this.nextToken.type===Gs||this.nextToken.type===Dr||this.nextToken.type===St&&this.nextToken.value===")"){this.restore(),this.parseAtom(e);return}}var r=this.current;this.parseFactor(e),e.push(Bs(r.value))}else this.parseExponential(e)};_e.prototype.parseExponential=function(e){for(this.parsePostfixExpression(e);this.accept(me,"^");)this.parseFactor(e),e.push(Tt("^"))};_e.prototype.parsePostfixExpression=function(e){for(this.parseFunctionCall(e);this.accept(me,"!");)e.push(Bs("!"))};_e.prototype.parseFunctionCall=function(e){var t=this.tokens.unaryOps;function n(s){return s.value in t}if(this.accept(me,n)){var r=this.current;this.parseAtom(e),e.push(Bs(r.value))}else for(this.parseMemberExpression(e);this.accept(St,"(");)if(this.accept(St,")"))e.push(new re(Ln,0));else{var i=this.parseArgumentList(e);e.push(new re(Ln,i))}};_e.prototype.parseArgumentList=function(e){for(var t=0;!this.accept(St,")");)for(this.parseExpression(e),++t;this.accept(Gs);)this.parseExpression(e),++t;return t};_e.prototype.parseMemberExpression=function(e){for(this.parseAtom(e);this.accept(me,".")||this.accept(Fn,"[");){var t=this.current;if(t.value==="."){if(!this.allowMemberAccess)throw new Error('unexpected ".", member access is not permitted');this.expect(Wa),e.push(new re(hn,this.current.value))}else if(t.value==="["){if(!this.tokens.isOperatorEnabled("["))throw new Error('unexpected "[]", arrays are disabled');this.parseExpression(e),this.expect(Fn,"]"),e.push(Tt("["))}else throw new Error("unexpected symbol: "+t.value)}};function qT(e,t){return Number(e)+Number(t)}function jT(e,t){return e-t}function DT(e,t){return e*t}function RT(e,t){return e/t}function BT(e,t){return e%t}function LT(e,t){return Array.isArray(e)&&Array.isArray(t)?e.concat(t):""+e+t}function GT(e,t){return e===t}function FT(e,t){return e!==t}function UT(e,t){return e>t}function VT(e,t){return e<t}function zT(e,t){return e>=t}function KT(e,t){return e<=t}function HT(e,t){return!!(e&&t)}function WT(e,t){return!!(e||t)}function JT(e,t){return Bn(t,e)}function YT(e){return(Math.exp(e)-Math.exp(-e))/2}function $T(e){return(Math.exp(e)+Math.exp(-e))/2}function XT(e){return e===1/0?1:e===-1/0?-1:(Math.exp(e)-Math.exp(-e))/(Math.exp(e)+Math.exp(-e))}function QT(e){return e===-1/0?e:Math.log(e+Math.sqrt(e*e+1))}function ZT(e){return Math.log(e+Math.sqrt(e*e-1))}function eM(e){return Math.log((1+e)/(1-e))/2}function Ag(e){return Math.log(e)*Math.LOG10E}function tM(e){return-e}function nM(e){return!e}function rM(e){return e<0?Math.ceil(e):Math.floor(e)}function iM(e){return Math.random()*(e||1)}function xg(e){return Ya(e+1)}function sM(e){return isFinite(e)&&e===Math.round(e)}var oM=4.7421875,Fa=[.9999999999999971,57.15623566586292,-59.59796035547549,14.136097974741746,-.4919138160976202,3399464998481189e-20,4652362892704858e-20,-9837447530487956e-20,.0001580887032249125,-.00021026444172410488,.00021743961811521265,-.0001643181065367639,8441822398385275e-20,-26190838401581408e-21,36899182659531625e-22];function Ya(e){var t,n;if(sM(e)){if(e<=0)return isFinite(e)?1/0:NaN;if(e>171)return 1/0;for(var r=e-2,i=e-1;r>1;)i*=r,r--;return i===0&&(i=1),i}if(e<.5)return Math.PI/(Math.sin(Math.PI*e)*Ya(1-e));if(e>=171.35)return 1/0;if(e>85){var s=e*e,o=s*e,a=o*e,u=a*e;return Math.sqrt(2*Math.PI/e)*Math.pow(e/Math.E,e)*(1+1/(12*e)+1/(288*s)-139/(51840*o)-571/(2488320*a)+163879/(209018880*u)+5246819/(75246796800*u*e))}--e,n=Fa[0];for(var c=1;c<Fa.length;++c)n+=Fa[c]/(e+c);return t=e+oM+.5,Math.sqrt(2*Math.PI)*Math.pow(t,e+.5)*Math.exp(-t)*n}function aM(e){return Array.isArray(e)?e.length:String(e).length}function Sg(){for(var e=0,t=0,n=0;n<arguments.length;n++){var r=Math.abs(arguments[n]),i;t<r?(i=t/r,e=e*i*i+1,t=r):r>0?(i=r/t,e+=i*i):e+=r}return t===1/0?1/0:t*Math.sqrt(e)}function Tg(e,t,n){return e?t:n}function uM(e,t){return typeof t>"u"||+t==0?Math.round(e):(e=+e,t=-+t,isNaN(e)||!(typeof t=="number"&&t%1===0)?NaN:(e=e.toString().split("e"),e=Math.round(+(e[0]+"e"+(e[1]?+e[1]-t:-t))),e=e.toString().split("e"),+(e[0]+"e"+(e[1]?+e[1]+t:t))))}function cM(e,t,n){return n&&(n[e]=t),t}function lM(e,t){return e[t|0]}function fM(e){return arguments.length===1&&Array.isArray(e)?Math.max.apply(Math,e):Math.max.apply(Math,arguments)}function pM(e){return arguments.length===1&&Array.isArray(e)?Math.min.apply(Math,e):Math.min.apply(Math,arguments)}function hM(e,t){if(typeof e!="function")throw new Error("First argument to map is not a function");if(!Array.isArray(t))throw new Error("Second argument to map is not an array");return t.map(function(n,r){return e(n,r)})}function dM(e,t,n){if(typeof e!="function")throw new Error("First argument to fold is not a function");if(!Array.isArray(n))throw new Error("Second argument to fold is not an array");return n.reduce(function(r,i,s){return e(r,i,s)},t)}function mM(e,t){if(typeof e!="function")throw new Error("First argument to filter is not a function");if(!Array.isArray(t))throw new Error("Second argument to filter is not an array");return t.filter(function(n,r){return e(n,r)})}function gM(e,t){if(!(Array.isArray(t)||typeof t=="string"))throw new Error("Second argument to indexOf is not a string or array");return t.indexOf(e)}function yM(e,t){if(!Array.isArray(t))throw new Error("Second argument to join is not an array");return t.join(e)}function vM(e){return(e>0)-(e<0)||+e}var Mg=1/3;function bM(e){return e<0?-Math.pow(-e,Mg):Math.pow(e,Mg)}function _M(e){return Math.exp(e)-1}function wM(e){return Math.log(1+e)}function OM(e){return Math.log(e)/Math.LN2}function Ht(e){this.options=e||{},this.unaryOps={sin:Math.sin,cos:Math.cos,tan:Math.tan,asin:Math.asin,acos:Math.acos,atan:Math.atan,sinh:Math.sinh||YT,cosh:Math.cosh||$T,tanh:Math.tanh||XT,asinh:Math.asinh||QT,acosh:Math.acosh||ZT,atanh:Math.atanh||eM,sqrt:Math.sqrt,cbrt:Math.cbrt||bM,log:Math.log,log2:Math.log2||OM,ln:Math.log,lg:Math.log10||Ag,log10:Math.log10||Ag,expm1:Math.expm1||_M,log1p:Math.log1p||wM,abs:Math.abs,ceil:Math.ceil,floor:Math.floor,round:Math.round,trunc:Math.trunc||rM,"-":tM,"+":Number,exp:Math.exp,not:nM,length:aM,"!":xg,sign:Math.sign||vM},this.binaryOps={"+":qT,"-":jT,"*":DT,"/":RT,"%":BT,"^":Math.pow,"||":LT,"==":GT,"!=":FT,">":UT,"<":VT,">=":zT,"<=":KT,and:HT,or:WT,in:JT,"=":cM,"[":lM},this.ternaryOps={"?":Tg},this.functions={random:iM,fac:xg,min:pM,max:fM,hypot:Math.hypot||Sg,pyt:Math.hypot||Sg,pow:Math.pow,atan2:Math.atan2,if:Tg,gamma:Ya,roundTo:uM,map:hM,fold:dM,filter:mM,indexOf:gM,join:yM},this.consts={E:Math.E,PI:Math.PI,true:!0,false:!1}}Ht.prototype.parse=function(e){var t=[],n=new _e(this,new Te(this,e),{allowMemberAccess:this.options.allowMemberAccess});return n.parseExpression(t),n.expect(Dr,"EOF"),new it(t,this)};Ht.prototype.evaluate=function(e,t){return this.parse(e).evaluate(t)};var Dg=new Ht;Ht.parse=function(e){return Dg.parse(e)};Ht.evaluate=function(e,t){return Dg.parse(e).evaluate(t)};var Ig={"+":"add","-":"subtract","*":"multiply","/":"divide","%":"remainder","^":"power","!":"factorial","<":"comparison",">":"comparison","<=":"comparison",">=":"comparison","==":"comparison","!=":"comparison","||":"concatenate",and:"logical",or:"logical",not:"logical","?":"conditional",":":"conditional","=":"assignment","[":"array","()=":"fndef"};function PM(e){return Ig.hasOwnProperty(e)?Ig[e]:e}Ht.prototype.isOperatorEnabled=function(e){var t=PM(e),n=this.options.operators||{};return!(t in n)||!!n[t]};var Rg=new Ht;Rg.functions.sum=e=>e.reduce((t,n)=>t+n,0);function Rr(e,t,n){let r=pe(e,t.arguments,n);return Rg.evaluate(t.expression,r)}var Bg=he(qs()),EM=["state"];function Br(e,t,n,r){return!EM.includes(r)&&(0,Bg.default)(t)?e.G.bank.find(e,t,n):t}var kM=["conditions","move","then","mapping"];function pe(e,t,n,r){if(!(0,Gg.default)(t)&&!Array.isArray(t))return t;let i=Array.isArray(t)?[...t]:{...t};Object.entries(t).forEach(([a,u])=>{kM.includes(a)||(i[a]=pe(e,u,n,a))});let s=AM(e,i,n);return s?.resolveAsEntity||r==="target"||r==="targets"?Br(e,s,n,r):s}function AM(e,t,n){if(t?.type==="expression")return Rr(e,{...t,arguments:pe(e,t.arguments,n,"arguments")},n);if(t?.type==="count")return e.G.bank.findAll(e,t,n).length;if(t?.type==="contextPath")return ln(n,t.path);if(t?.type==="ctxPath")return ln(e.ctx,t.path);if(t?.type==="gamePath")return ln(e.G,t.path);if(t?.type==="relativePath"||t?.type==="RelativePath"){let r=pe(e,t.target,n,"target");return ln(r.attributes,t.path)??null}else if(t?.type==="parent"||t?.type==="Parent"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget;return e.G.bank.findParent(r)??null}else{if(t?.type==="map")return Lg(e,t.targets,t.mapping,n).map(r=>r.value);if(t?.type==="mapMax"){let r=Lg(e,t.targets,t.mapping,n),i,s=[];for(let o=0,a=r.length;o<a;o++){let{target:u,value:c}=r[o];i===void 0||c>i?(i=c,s.length=0,s.push(u)):c===i&&s.push(u)}return s}else if(t?.type==="pick"||t?.type==="Pick"){let r=pe(e,t.target,n,"target");return(0,Fg.default)(pe(e,r.attributes,n,"attributes"),t.properties)}else if(t?.type==="coordinates"||t?.type==="Coordinates"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget;return e.G.bank.findParent(r).getCoordinates(r.rule.index)}else if(t?.type==="relativeCoordinates"){let r=t.target?pe(e,t.target,n,"target"):n.originalTarget,i=e.G.bank.findParent(r),s=i.getCoordinates(r.rule.index),o=i.getRelativeCoordinates(s,pe(e,t.location,n,"location"));return(o&&i.spaces[i.getIndex(o)])??null}else return t}}function Lg(e,t,n,r){return t.resolveAsEntity=!0,pe(e,t,r)?.map(i=>({target:i,value:pe(e,n,{...r,loopTarget:i})}))??[]}var oe=class{constructor(t){this.rule=t}check(t,n,r){let i={...n},s={...r};i.target&&(s.originalTarget=i.target);let o=pe(t,this.rule,s);return o.target!==void 0&&(i.target=o.target),this.rule.target!==void 0&&!i.target?{conditionIsMet:!1}:this.checkCondition(t,o,i,s)}isMet(...t){return this.check(...t).conditionIsMet}};var Zy=he(Fr());function d2(e,t,n){let r={...t};return delete r.state,delete r.stateGroups,pe(e,r,n)}function m2(e){return{...e.rule,...e.state}}function Qa(e,t,n,r){return(0,Zy.default)(d2(e,t,r))(m2(n))}var Ur=class extends oe{checkCondition(t,n,{target:r},i){return this.rule.entity&&r!==n.entity?{target:r,conditionIsMet:!1}:{target:r,conditionIsMet:Qa(t,n.matcher,r,i)}}};var Vr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!ke(t,n,r,i).conditionsAreMet}}};function Za(e,{conditions:t=[]},n,r){let i;for(let s of t){let o=dn(s).check(e,n,r);if(o.conditionIsMet){i={...o,conditionRule:s};break}}return i}var zr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!!Za(t,n,r,i)}}};var Kr=class extends oe{checkCondition(t,n,{target:r},i){let s=r.find(o=>{let a={...i,loopTarget:o};return ke(t,n,void 0,a).conditionsAreMet});return{conditionIsMet:!!s,result:s}}};var Hr=class extends oe{checkCondition(t,n,{target:r},i){let s=r.map(o=>{let a={...i,loopTarget:o};return ke(t,n,void 0,a)});return{conditionIsMet:s.every(o=>o.conditionsAreMet),results:s}}};var s8=he(Fr());var Wr=class extends oe{checkCondition(t,n,r,i){let{target:s}=r;if(s){let a=(s.entities??s.spaces)?.filter(u=>ke(t,n,{target:u},i).conditionsAreMet)??[];return{matches:a,conditionIsMet:!!a.length}}else return{matches:[],conditionIsMet:!1}}};var ev=he(Ga());var Jr=class extends oe{checkCondition(t,n,{targets:r}){if(r.length===1&&r[0].entities?.length)return{conditionIsMet:!0};let[i,...s]=r;return{conditionIsMet:i.entities.some(a=>{let u=dn({conditionType:"Contains",conditions:[{conditionType:"Is",matcher:(0,ev.default)(a.rule,n.properties)}]});return s.every(c=>u.isMet(t,{target:c}))})}}};var h8=he(Fr());var g2=[[1,0],[0,1],[1,1],[-1,1]],tv=new WeakMap;function y2(e,t){let n={moveInstance:t.moveInstance?.id,moveArguments:t.moveArguments};return JSON.stringify({pattern:e,context:n})}function v2(e){return(e.entities||[]).map(n=>{let r=n.entities||[];return r.length===0?"empty":r.map(i=>{let s=Object.keys(i).sort(),o={};return s.forEach(a=>{o[a]=i[a]}),JSON.stringify(o)}).sort().join("|")}).join(",")}function nv(e,t,n,r,i,s=!1){let o=[],a=t.length,u=0;for(;u<=a-r;){let c=w2(e,t,u,n,i,s);c&&o.push(c),u++}return o}function b2(e,t,n){let{width:r,height:i}=e.attributes,s=[];if(t===1&&n===0)for(let o=0;o<i;o++)s.push([0,o]);else if(t===0&&n===1)for(let o=0;o<r;o++)s.push([o,0]);else if(t===1&&n===1){for(let o=0;o<r;o++)s.push([o,0]);for(let o=1;o<i;o++)s.push([0,o])}else if(t===-1&&n===1){for(let o=0;o<r;o++)s.push([o,0]);for(let o=1;o<i;o++)s.push([r-1,o])}return s}function _2(e,t,n,r,i){let s=[],[o,a]=[t,n];for(;e.areCoordinatesValid([o,a]);)s.push(e.getSpace([o,a])),o+=r,a+=i;return s}function w2(e,t,n,r,i,s=!1){let o=n,a=[],u=t.length;for(let c of r){let{count:l,minCount:f,maxCount:p,conditions:h}=c,d,y;l!==void 0?d=y=l:f!==void 0||p!==void 0?(d=f||0,y=p||1/0):d=y=1;let m=0,b=[];for(;m<y&&o<u;){let g=s?t[u-1-o]:t[o];if(O2(e,g,h,b,i))b.push(g),m++,o++;else break}if(m<d)return null;a.push(...b)}return a.length>0?a:null}function O2(e,t,n,r=[],i){return!n||n.length===0?!0:ke(e,{conditions:n},{target:t,targets:[t,...r]},i).conditionsAreMet}function Yr(e,t,n,r){let i=y2(n,r),s=tv.get(t);s||(s=new Map,tv.set(t,s));let o=v2(t),a=s.get(i);if(a&&a.stateKey===o)return a.result;let u=[],c=n.reduce((f,p)=>f+(p.minCount||p.count||1),0);for(let[f,p]of g2){let h=b2(t,f,p);for(let[d,y]of h){let m=_2(t,d,y,f,p);if(m.length<c)continue;let b=nv(e,m,n,c,r);if(u.push(...b),b.length===0||n.length>1){let g=nv(e,m,n,c,r,!0);u.push(...g)}}}let l={matches:u,conditionIsMet:!!u.length};return s.set(i,{stateKey:o,result:l}),l}var $r=class extends oe{checkCondition(t,n,r,i){let{G:s}=t,{target:o}=r,a=s.bank.findParent(r.target),{matches:u}=Yr(t,a,n.sequence,i),c=u.filter(l=>l.some(f=>f===o));return{matches:c,conditionIsMet:!!c.length}}};var Xr=class extends oe{checkCondition(t,n,r,i){let{matches:s}=Yr(t,r.target,n.sequence,i);return{matches:s,conditionIsMet:!!s.length}}};var Qr=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:r.target.spaces.every(s=>s?.entities.length)}}};function Zr(e,t,n){let r=Ft(He(e.G),ht),i={...e,G:r},s={...t,arguments:{}};return Object.entries(t.arguments).forEach(([o,a])=>{s.arguments[o]=a.abstract?a:r.bank.locate(typeof a=="number"?a:a.entityId)}),n.moveInstance.doMove(i,s,n,{skipCheck:!0}),r}var P2={PlaceNew:["destination"],RemoveEntity:["entity"],MoveEntity:["entity","destination"],TakeFrom:["source","destination"],SetState:["entity","state"]},ei=class extends oe{checkCondition(t,n,{target:r,targets:i=[r]},s){let o={arguments:i.reduce((p,h,d)=>({...p,[P2[s.moveInstance.rule.moveType][d]]:h}),{})},a=Zr(t,o,s),u={};r?u={target:a.bank.locate(r.entityId)}:i&&(u={targets:i.map(p=>a.bank.locate(p.entityId))});let c=ke({...t,G:a},n,u,s),l=c.conditionsAreMet;return{results:l?eu(c.results,p=>t.G.bank.locate(p)):c.results,conditionIsMet:l}}};function eu(e,t,n=new WeakSet){if(typeof e!="object"||e===null||n.has(e))return e;if(n.add(e),e.entityId!==void 0)return t(e.entityId);if(Array.isArray(e))return e.map(r=>eu(r,t,n));{let r={};for(let i in e)e.hasOwnProperty(i)&&(r[i]=eu(e[i],t,n));return r}}var rv=he(qs());function iv(e,t=new Set){if(!e||typeof e!="object")return t;e.type==="contextPath"&&Array.isArray(e.path)&&e.path[0]==="moveArguments"&&e.path[1]&&t.add(e.path[1]);for(let n of Object.values(e))iv(n,t);return t}function E2(e){let t=Object.keys(e),n={},r={};t.forEach(o=>{n[o]=[],r[o]=0}),t.forEach(o=>{let a=e[o];iv(a).forEach(c=>{t.includes(c)&&c!==o&&(n[c].push(o),r[o]++)})});let i=t.filter(o=>r[o]===0),s=[];for(;i.length>0;){let o=i.shift();s.push(o),n[o].forEach(a=>{r[a]--,r[a]===0&&i.push(a)})}return s.length===t.length?s:t}function sv(e,t,n,r,i,s=0,o={}){if(s===r.length){let p={arguments:o};return t.isValid(e,p,i)}let a=r[s],u=n[a],c={...i,moveArguments:o},l=(0,rv.default)(u)?Br(e,{...u,matchMultiple:!0},c,a):u,f=Array.isArray(l)?l:l!==void 0?[l]:[];return f.length===0?!1:f.some(p=>sv(e,t,n,r,i,s+1,{...o,[a]:p}))}function tu(e,t){return Object.values(t).some(n=>{let{moveInstance:r}=n,i={moveInstance:r},o=pe(e,r.rule,i).arguments??{};if(Object.keys(o).length===0)return r.isValid(e,{arguments:{}},i);let a=E2(o);return sv(e,r,o,a,i)})}function ti(e,{game:t,playerID:n,stageName:r}){let i=e.ctx.phase,s=r??e.ctx.activePlayers?.[n??e.ctx.currentPlayer],o=t.phases?.[i]??t;return(o.turn?.stages?.[s]??o).moves??{}}var ni=class extends oe{checkCondition(t,n,r,i){return{conditionIsMet:!tu(t,ti(t,i))}}};var G8=he(Fr());var ri=class extends oe{checkCondition(t,n,r,i){let s={...i};r?.target&&(s.target=r.target);let o=Rr(t,n,s);return{result:o,conditionIsMet:!!o}}};var ii=class extends oe{checkCondition(t,n,{target:r}){let i=t.G.bank.findParent(r),s;return n.position==="First"&&(s=i.entities.indexOf(r)===0),{conditionIsMet:s}}};function dn(e){if(e.conditionType==="Is")return new Ur(e);if(e.conditionType==="Not")return new Vr(e);if(e.conditionType==="Or")return new zr(e);if(e.conditionType==="Some")return new Kr(e);if(e.conditionType==="Contains")return new Wr(e);if(e.conditionType==="ContainsSame")return new Jr(e);if(e.conditionType==="Every")return new Hr(e);if(e.conditionType==="InLine")return new $r(e);if(e.conditionType==="HasLine")return new Xr(e);if(e.conditionType==="IsFull")return new Qr(e);if(e.conditionType==="Would")return new ei(e);if(e.conditionType==="NoPossibleMoves")return new ni(e);if(e.conditionType==="Evaluate")return new ri(e);if(e.conditionType==="Position")return new ii(e)}function ke(e,t,n,r){let{conditions:i=[]}=t,s=[],o;for(let a of i){let u=dn(a).check(e,n,r);if(u.conditionIsMet)s.push(u);else{o=a;break}}return{results:s,failedAt:o,conditionsAreMet:s.length===i.length}}var nu=class{constructor(t,n){this.bank=n,this.rule=t,this.pool=[],this.remaining=+t.count||1}getOne(t,n,r){return this.getMultiple(t,1,n,r)[0]}getMultiple(t,n=1/0,r={},i){let s=[];if(this.remaining===1/0&&n===1/0)throw new Error(`Cannot get infinite pieces from slot with infinite remaining: ${this.rule.name}`);if(n!==1/0&&n>this.remaining)throw new Error(`Requested ${n} pieces but only ${this.remaining} available in slot: ${this.rule.name}`);let o=n===1/0?this.remaining:n;this.remaining!==1/0&&(this.remaining-=o);let a=Math.min(o,this.pool.length);s.push(...this.pool.splice(0,a));let u=o-a;if(u>0&&s.push(...Array.from(new Array(u)).map(()=>this.bank.createEntity(this.rule))),r.state){let c=pe(t,r.state,i);s.forEach(l=>{l.state={...l.state,...c}})}return s}returnToBank(t){t.rule.state?t.state=t.rule.state:delete t.state,this.remaining!==void 0&&(this.remaining+=1),this.pool.push(t)}},zs=nu;var ru=class{constructor(t){this.currentEntityId=0,this.tracker={},this.slots=t.map(n=>new zs(n,this))}createEntity(t={},n){let r=new ht[t.entityType||"Entity"]({bank:this,fromBank:!0,...n},t,this.currentEntityId++);return this.track(r),r}track(t){this.tracker[t.entityId]=t}locate(t){return this.tracker[t]}findAll(t,n,r){if(!n.conditions)throw new Error(`Cannot find entity with no conditions. Rule: ${JSON.stringify(n)}`);return(0,av.default)(Object.values(this.tracker),i=>ke(t,n,{target:i},r).conditionsAreMet)}findOne(t,n,r){return this.findAll(t,n,r)[0]}find(t,n,r){return n.matchMultiple?this.findAll(t,n,r):this.findOne(t,n,r)}findParent(t){return(0,ov.default)(this.tracker,n=>n.entities?.includes(t)||n.spaces?.includes(t))}getOne(t,n,r){let i=this.getSlot(t,n,r);return i||console.error(`No matching slot for ${JSON.stringify(n)}`),i.getOne(t,{state:n.state},r)}getMultiple(t,n,r,i){let s=this.getSlots(t,n,i);return s.length||console.error(`No matching slots for ${JSON.stringify(n)}`),s.reduce((o,a)=>[...o,...a.getMultiple(t,r,{state:n.state})],[])}getSlot(t,n,r){return this.slots.find(i=>ke(t,n,{target:i},r).conditionsAreMet)}getSlots(t,n,r){return this.slots.filter(i=>ke(t,n,{target:i},r).conditionsAreMet)}returnToBank(t,n){this.findParent(n).remove(n),this.getSlot(t,n.rule).returnToBank(n),delete this.tracker[n.entityId]}},Ks=ru;var ht={Board:wr,SpaceGroup:sn,Space:rn,Grid:Ar,Bank:Ks,BankSlot:zs,Entity:Et};function Mt(e){return{...e,G:Ft(JSON.stringify(e.G),ht)}}var uv=he(aa());var we=class{constructor(t){this.rule=this.transformRule(t)}checkValidity(t,n,r){let i=Object.entries(this.rule.arguments??{});if(!i.every(([a])=>{let u=n.arguments[a];return u!==void 0&&(!Array.isArray(u)||u.length)}))return!1;let s={};for(let a=0,u=i.length;a<u;a++){let[c,l]=i[a],f=n.arguments[c],p=Array.isArray(f)?f:[f],h=[];for(let y=0,m=p.length;y<m;y++){let b=p[y],g=ke(t,l,{target:b},{...r,moveArguments:n.arguments});if(h.push(g),!g.conditionsAreMet)break}let d=h.at(-1).conditionsAreMet;if(s[c]={results:h,conditionsAreMet:d},!d)break}let o=ke(t,{conditions:this.rule.conditions},void 0,{...r,moveArguments:n.arguments});return{argumentResults:s,moveResults:o,conditionsAreMet:o.conditionsAreMet&&Object.values(s).every(a=>a.conditionsAreMet)}}isValid(t,n,r){return this.checkValidity(t,n,r).conditionsAreMet}doMove(t,n,r,{skipCheck:i=!1}={}){let s=pe(t,this.rule,r),o={...n,arguments:Object.entries(s.arguments??{}).reduce((u,[c,l])=>({...u,[c]:n?.arguments?.[c]??l}),{})};s.name&&(t.G._meta.previousPayloads[s.name]=o);let a;return i||(a=this.checkValidity(t,o,r)),!i&&!a.conditionsAreMet?uv.INVALID_MOVE:(this.do(t,s,o,r),r&&(r.previousArguments=o.arguments),{conditionResults:a})}transformRule(t){let n=t.arguments;for(let r in n){let i=n[r];i.playerChoice||(i.resolveAsEntity=!0)}return t}};var si=class extends we{do(t,n,{arguments:{entity:r,destination:i}}){Array.isArray(r)?r.forEach(s=>{t.G.bank.findParent(s)?.remove(s),i.placeEntity(s,n.position)}):(t.G.bank.findParent(r)?.remove(r),i.placeEntity(r,n.position))}};var oi=class extends we{do(t,n,{arguments:{entity:r}}){t.G.bank.returnToBank(t,r)}};var ai=class extends we{do(t,n,{arguments:{destination:r}},i){(n.matchMultiple?t.G.bank.getMultiple(t,{...n.entity,conditions:[...n.entity?.conditions||[],...n.conditions||[]]},n.count,i):[t.G.bank.getOne(t,{...n.entity,conditions:[...n.entity?.conditions||[],...n.conditions||[]]},i)]).forEach(o=>{r.placeEntity(o,n.position)})}};var ui=class extends we{do(t,n,{arguments:{source:r,destination:i}}){i.placeEntity(r.takeOne(n.arguments.source.position))}};var ci=class extends we{do(t,n,{arguments:{entity:r,state:i}}){r.state={...r.state,[i.property]:i.value}}};function mn(e,t=[],n){return t?.length&&t.forEach(r=>{Hn(r,n.game).moveInstance.doMove(e,void 0,n)}),e.G}var li=class extends we{do(t,n,r,i){t.events.setActivePlayers(n.options);let s=t.ctx.phase,o=n.options.currentPlayer?.stage,u=(i.game.phases?.[s]??i.game)?.turn?.stages?.[o];mn(t,u?.initialMoves,{...i,stageName:o})}};var fi=class extends we{do(t){t.events.endTurn()}};var pi=class extends we{do(t){t.G._meta.passedPlayers.length<t.ctx.numPlayers&&(t.G._meta.passedPlayers.push(t.ctx.currentPlayer),t.events.pass())}};var hi=class extends we{do(t,n,{arguments:{targets:r}},i){r.forEach(s=>{let o={...i,loopTarget:s};Hs(n.move).doMove(t,void 0,o)})}};var di=class extends we{do(t){t.events.endTurn()}};var mi=class extends we{do(t,n,{arguments:{target:r}}){r.entities=t.random.Shuffle(r.entities)}};function Hn(e,t){let n=Hs(e),r=function(i,s){let o=Mt(i),{G:a}=o,u=k2(s,a),c={moveInstance:n,game:t},l=n.doMove(o,u,c);if(c.moveConditionResults=[l],l!==cv.INVALID_MOVE&&e.then)for(let f of e.then){let p=Hs(f).doMove(o,{},{...c});c.moveConditionResults.push(p)}return JSON.parse(He(a))};return r.moveInstance=n,r}function k2(e,t){if(e){let n=Ft(JSON.stringify(e),ht);return n.arguments=Object.entries(n.arguments).reduce((r,[i,s])=>({...r,[i]:typeof s=="number"?t.bank.locate(s):s}),{}),n}else return e}function Hs(e){switch(e.moveType){case"MoveEntity":return new si(e);case"PlaceNew":return new ai(e);case"RemoveEntity":return new oi(e);case"TakeFrom":return new ui(e);case"SetState":return new ci(e);case"ForEach":return new hi(e);case"Pass":return new di(e);case"Shuffle":return new mi(e);case"SetActivePlayers":return new li(e);case"EndTurn":return new fi(e);case"PassTurn":return new pi(e)}}var b6=he(fv()),hv=he(Ra());function iu(e,t){return JSON.parse(JSON.stringify(e),(n,r)=>{let i=r;for(let s of t)s.test(i)&&(i=s.replace(i));return i})}var M2=[{entityType:"Space",count:"Infinity"},{entityType:"Board",name:"sharedBoard"},{name:"playerMarker",perPlayer:!0,count:"Infinity"}];function I2(e){e.entities=[...M2,...e.entities||[]]}function pv(e,t){if(e.sharedBoard){let n=e.sharedBoard.map(r=>({entity:r,destination:{name:"sharedBoard"}}));e.initialPlacements||(e.initialPlacements=[]),e.initialPlacements.unshift(...n)}if(e.personalBoard){t.push({entityType:"Board",name:"personalBoard",perPlayer:!0});let n=e.personalBoard.map(r=>({entity:r,destination:{name:"personalBoard"}}));e.initialPlacements||(e.initialPlacements=[]),e.initialPlacements.unshift(...n)}if(e.initialPlacements){let n=e.initialPlacements.map(r=>{let{state:i,...s}=r.entity,o=(0,hv.default)(t,s);return r.destination.name==="personalBoard"?{moveType:"ForEach",arguments:{targets:{type:"ctxPath",path:["playOrder"]}},move:{moveType:"PlaceNew",entity:{state:i,conditions:[{conditionType:"Is",matcher:{...s,...o.perPlayer?{player:{type:"contextPath",path:["loopTarget"]}}:{}}}]},arguments:{destination:{conditions:[{conditionType:"Is",matcher:{...r.destination,player:{type:"contextPath",path:["loopTarget"]}}}]}}}}:{moveType:"PlaceNew",entity:{state:i,conditions:[{conditionType:"Is",matcher:s}]},arguments:{destination:{conditions:[{conditionType:"Is",matcher:r.destination}]}}}});e.initialMoves||(e.initialMoves=[]),e.initialMoves.unshift(...n),delete e.initialPlacements}}var N2=[],su=[["isCurrentPlayer",{conditionType:"Is",matcher:{player:{type:"ctxPath",path:["currentPlayer"]}}}],["isEmpty",{conditionType:"Not",conditions:[{conditionType:"Contains"}]}],["ownerOfFirstResultEntity",{type:"contextPath",path:["results",0,"matches",0,0,"entities",0,"attributes","player"]}]],C2=[{test:e=>e&&typeof e=="object",replace:e=>(N2.forEach(([t,n])=>{e.hasOwnProperty(t)&&(e[n]=e[t],delete e[t])}),e)},{test:e=>typeof e=="string",replace:e=>{for(let t=0,n=su.length;t<n;t++)if(e===su[t][0])return su[t][1];return e}},{test:e=>e?.conditions,replace:e=>(Array.isArray(e.conditions)||(e.conditions=[e.conditions]),e)},{test:e=>e?.conditions,replace:e=>{for(let t=0,n=e.conditions.length;t<n;t++)e.conditions[t].conditionType||(e.conditions[t]={conditionType:"Is",matcher:e.conditions[t]});return e}},{test:e=>typeof e?.target=="string",replace:e=>({...e,target:{conditions:[{conditionType:"Is",matcher:{name:e.target}}]}})}];function ou(e){let t=iu(e,C2);return t.sharedBoard||(t.sharedBoard=t.entities),t.turn||(t.turn={minMoves:1,maxMoves:1}),I2(t),pv(t,t.entities),t.phases&&Object.entries(t.phases).forEach(n=>{pv(n,t.entities)}),e.numPlayers&&(e.minPlayers=e.maxPlayers=e.numPlayers),t}function Ws(e,t,n){let r;for(let i of t){let s=ke(e,i);if(s.conditionsAreMet){r={scenario:i,conditionResults:s};break}}return r?.scenario?.result?pe(e,r.scenario.result,{results:r.conditionResults.results}):r}function gi(e,t){let n={name:t},r=ou(e);return n.setup=i=>{let{ctx:s}=i,o={_meta:{passedPlayers:[],previousPayloads:{}}},a=q2(r.entities,s);return o.bank=new Ks(a),o.sharedBoard=o.bank.getOne(i,{conditions:[{conditionType:"Is",matcher:{name:"sharedBoard"}}]}),r.personalBoard&&(o.personalBoards=i.ctx.playOrder.map(u=>o.bank.getOne(i,{conditions:[{conditionType:"Is",matcher:{name:"personalBoard",player:u}}]}))),r.initialMoves?.forEach(u=>{Hn(u,n).moveInstance.doMove({...i,G:o})}),JSON.parse(He(o))},r.moves&&(n.moves=au(r.moves,n)),r.turn&&(n.turn=dv(r.turn,n)),r.phases&&(n.phases=Object.entries(r.phases).reduce((i,[s,o])=>({...i,[s]:j2(o,n)}),{})),r.endIf&&(n.endIf=i=>{let s=Mt(i);return Ws(s,r.endIf)}),e.DEBUG_DISABLE_SECRET_STATE||(n.playerView=i=>{let{G:s,playerID:o}=Mt(i);return Object.values(s.bank.tracker).forEach(a=>{(a.rule.contentsHiddenFrom==="All"||a.rule.contentsHiddenFrom==="Others"&&(o!==a.rule.player||o==null))&&(a.spaces&&(a.spaces=a.rule.hideLength?[]:a.spaces.map(()=>s.bank.createEntity())),a.entities&&(a.entities=a.rule.hideLength?[]:a.entities.map(()=>s.bank.createEntity())))}),JSON.parse(He(s))}),n}function q2(e,t){return e.reduce((n,r)=>{let i={...r};if(i.perPlayer&&(delete i.perPlayer,i.variants?i.variants=new Array(t.numPlayers).fill().reduce((s,o,a)=>[...s,...i.variants.map(u=>({...u,player:`${a}`}))],[]):i.variants=new Array(t.numPlayers).fill().map((s,o)=>({player:`${o}`}))),i.variants){let s=i.variants;return delete i.variants,[...n,...s.map(o=>({...i,...o}))]}else return[...n,i]},[])}function dv(e,t){let n={...e};return n.onBegin=r=>{let i=Mt(r),s=e.stages?.[i.ctx.activePlayers?.[i.ctx.currentPlayer]];return i.G._meta.passedPlayers=i.G._meta.passedPlayers.filter(o=>o!==i.ctx.currentPlayer),mn(i,e.initialMoves,{game:t}),mn(i,s?.initialMoves,{game:t}),JSON.parse(He(i.G))},e.stages&&Object.entries(e.stages).forEach(([r,i])=>{i.moves&&(n.stages[r].moves=au(i.moves,t))}),e.order?.playOrder==="RotateFirst"&&(e.order.first=()=>0,e.order.next=({ctx:r})=>(r.playOrderPos+1)%r.numPlayers,n.order.playOrder=({ctx:r,G:i})=>i._meta.isAfterFirstPhase?[...r.playOrder.slice(1),r.playOrder[0]]:r.playOrder),n}function j2(e,t){let n={...e};return e.turn&&(n.turn=dv(e.turn,t)),e.moves&&(n.moves=au(e.moves,t)),n.onBegin=r=>{let i=Mt(r);return mn(i,e.initialMoves,{game:t}),i.G._meta.currentPhaseHasBeenSetUp=!0,i.G._meta.nextPhase=e.next,JSON.parse(He(i.G))},e.endIf&&(n.endIf=r=>{let i=Mt(r);if(i.G._meta.currentPhaseHasBeenSetUp){let s=Ws(i,e.endIf);if(s)return s}}),n.onEnd=({G:r})=>{r._meta.currentPhaseHasBeenSetUp=!1,r._meta.isAfterFirstPhase=!0},n}function au(e,t){return Object.entries(e).reduce((n,[r,i])=>({...n,[r]:Hn({...i,name:r},t)}),{})}var D2="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var mv=(e=21)=>{let t="",n=e|0;for(;n--;)t+=D2[Math.random()*64|0];return t};function st(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];if(0)var i,s;throw Error("[Immer] minified error nr: "+e+(n.length?" "+n.map(function(o){return"'"+o+"'"}).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function Wn(e){return!!e&&!!e[Je]}function yn(e){var t;return!!e&&(function(n){if(!n||typeof n!="object")return!1;var r=Object.getPrototypeOf(n);if(r===null)return!0;var i=Object.hasOwnProperty.call(r,"constructor")&&r.constructor;return i===Object||typeof i=="function"&&Function.toString.call(i)===z2}(e)||Array.isArray(e)||!!e[Pv]||!!(!((t=e.constructor)===null||t===void 0)&&t[Pv])||yu(e)||vu(e))}function vi(e,t,n){n===void 0&&(n=!1),Jn(e)===0?(n?Object.keys:Pu)(e).forEach(function(r){n&&typeof r=="symbol"||t(r,e[r],e)}):e.forEach(function(r,i){return t(i,r,e)})}function Jn(e){var t=e[Je];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:yu(e)?2:vu(e)?3:0}function pu(e,t){return Jn(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function R2(e,t){return Jn(e)===2?e.get(t):e[t]}function Ev(e,t,n){var r=Jn(e);r===2?e.set(t,n):r===3?e.add(n):e[t]=n}function B2(e,t){return e===t?e!==0||1/e==1/t:e!=e&&t!=t}function yu(e){return U2&&e instanceof Map}function vu(e){return V2&&e instanceof Set}function gn(e){return e.o||e.t}function bu(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=K2(e);delete t[Je];for(var n=Pu(t),r=0;r<n.length;r++){var i=n[r],s=t[i];s.writable===!1&&(s.writable=!0,s.configurable=!0),(s.get||s.set)&&(t[i]={configurable:!0,writable:!0,enumerable:s.enumerable,value:e[i]})}return Object.create(Object.getPrototypeOf(e),t)}function _u(e,t){return t===void 0&&(t=!1),wu(e)||Wn(e)||!yn(e)||(Jn(e)>1&&(e.set=e.add=e.clear=e.delete=L2),Object.freeze(e),t&&vi(e,function(n,r){return _u(r,!0)},!0)),e}function L2(){st(2)}function wu(e){return e==null||typeof e!="object"||Object.isFrozen(e)}function dt(e){var t=H2[e];return t||st(18,e),t}function gv(){return bi}function uu(e,t){t&&(dt("Patches"),e.u=[],e.s=[],e.v=t)}function Js(e){hu(e),e.p.forEach(G2),e.p=null}function hu(e){e===bi&&(bi=e.l)}function yv(e){return bi={p:[],l:bi,h:e,m:!0,_:0}}function G2(e){var t=e[Je];t.i===0||t.i===1?t.j():t.g=!0}function cu(e,t){t._=t.p.length;var n=t.p[0],r=e!==void 0&&e!==n;return t.h.O||dt("ES5").S(t,e,r),r?(n[Je].P&&(Js(t),st(4)),yn(e)&&(e=Ys(t,e),t.l||$s(t,e)),t.u&&dt("Patches").M(n[Je].t,e,t.u,t.s)):e=Ys(t,n,[]),Js(t),t.u&&t.v(t.u,t.s),e!==kv?e:void 0}function Ys(e,t,n){if(wu(t))return t;var r=t[Je];if(!r)return vi(t,function(a,u){return vv(e,r,t,a,u,n)},!0),t;if(r.A!==e)return t;if(!r.P)return $s(e,r.t,!0),r.t;if(!r.I){r.I=!0,r.A._--;var i=r.i===4||r.i===5?r.o=bu(r.k):r.o,s=i,o=!1;r.i===3&&(s=new Set(i),i.clear(),o=!0),vi(s,function(a,u){return vv(e,r,i,a,u,n,o)}),$s(e,i,!1),n&&e.u&&dt("Patches").N(r,n,e.u,e.s)}return r.o}function vv(e,t,n,r,i,s,o){if(Wn(i)){var a=Ys(e,i,s&&t&&t.i!==3&&!pu(t.R,r)?s.concat(r):void 0);if(Ev(n,r,a),!Wn(a))return;e.m=!1}else o&&n.add(i);if(yn(i)&&!wu(i)){if(!e.h.D&&e._<1)return;Ys(e,i),t&&t.A.l||$s(e,i)}}function $s(e,t,n){n===void 0&&(n=!1),!e.l&&e.h.D&&e.m&&_u(t,n)}function lu(e,t){var n=e[Je];return(n?gn(n):e)[t]}function bv(e,t){if(t in e)for(var n=Object.getPrototypeOf(e);n;){var r=Object.getOwnPropertyDescriptor(n,t);if(r)return r;n=Object.getPrototypeOf(n)}}function du(e){e.P||(e.P=!0,e.l&&du(e.l))}function fu(e){e.o||(e.o=bu(e.t))}function mu(e,t,n){var r=yu(t)?dt("MapSet").F(t,n):vu(t)?dt("MapSet").T(t,n):e.O?function(i,s){var o=Array.isArray(i),a={i:o?1:0,A:s?s.A:gv(),P:!1,I:!1,R:{},l:s,t:i,k:null,o:null,j:null,C:!1},u=a,c=gu;o&&(u=[a],c=yi);var l=Proxy.revocable(u,c),f=l.revoke,p=l.proxy;return a.k=p,a.j=f,p}(t,n):dt("ES5").J(t,n);return(n?n.A:gv()).p.push(r),r}function F2(e){return Wn(e)||st(22,e),function t(n){if(!yn(n))return n;var r,i=n[Je],s=Jn(n);if(i){if(!i.P&&(i.i<4||!dt("ES5").K(i)))return i.t;i.I=!0,r=_v(n,s),i.I=!1}else r=_v(n,s);return vi(r,function(o,a){i&&R2(i.t,o)===a||Ev(r,o,t(a))}),s===3?new Set(r):r}(e)}function _v(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return bu(e)}var wv,bi,Ou=typeof Symbol<"u"&&typeof Symbol("x")=="symbol",U2=typeof Map<"u",V2=typeof Set<"u",Ov=typeof Proxy<"u"&&Proxy.revocable!==void 0&&typeof Reflect<"u",kv=Ou?Symbol.for("immer-nothing"):((wv={})["immer-nothing"]=!0,wv),Pv=Ou?Symbol.for("immer-draftable"):"__$immer_draftable",Je=Ou?Symbol.for("immer-state"):"__$immer_state";var z2=""+Object.prototype.constructor,Pu=typeof Reflect<"u"&&Reflect.ownKeys?Reflect.ownKeys:Object.getOwnPropertySymbols!==void 0?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,K2=Object.getOwnPropertyDescriptors||function(e){var t={};return Pu(e).forEach(function(n){t[n]=Object.getOwnPropertyDescriptor(e,n)}),t},H2={},gu={get:function(e,t){if(t===Je)return e;var n=gn(e);if(!pu(n,t))return function(i,s,o){var a,u=bv(s,o);return u?"value"in u?u.value:(a=u.get)===null||a===void 0?void 0:a.call(i.k):void 0}(e,n,t);var r=n[t];return e.I||!yn(r)?r:r===lu(e.t,t)?(fu(e),e.o[t]=mu(e.A.h,r,e)):r},has:function(e,t){return t in gn(e)},ownKeys:function(e){return Reflect.ownKeys(gn(e))},set:function(e,t,n){var r=bv(gn(e),t);if(r?.set)return r.set.call(e.k,n),!0;if(!e.P){var i=lu(gn(e),t),s=i?.[Je];if(s&&s.t===n)return e.o[t]=n,e.R[t]=!1,!0;if(B2(n,i)&&(n!==void 0||pu(e.t,t)))return!0;fu(e),du(e)}return e.o[t]===n&&(n!==void 0||t in e.o)||Number.isNaN(n)&&Number.isNaN(e.o[t])||(e.o[t]=n,e.R[t]=!0),!0},deleteProperty:function(e,t){return lu(e.t,t)!==void 0||t in e.t?(e.R[t]=!1,fu(e),du(e)):delete e.R[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var n=gn(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r&&{writable:!0,configurable:e.i!==1||t!=="length",enumerable:r.enumerable,value:n[t]}},defineProperty:function(){st(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){st(12)}},yi={};vi(gu,function(e,t){yi[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}}),yi.deleteProperty=function(e,t){return yi.set.call(this,e,t,void 0)},yi.set=function(e,t,n){return gu.set.call(this,e[0],t,n,e[0])};var W2=function(){function e(n){var r=this;this.O=Ov,this.D=!0,this.produce=function(i,s,o){if(typeof i=="function"&&typeof s!="function"){var a=s;s=i;var u=r;return function(y){var m=this;y===void 0&&(y=a);for(var b=arguments.length,g=Array(b>1?b-1:0),O=1;O<b;O++)g[O-1]=arguments[O];return u.produce(y,function(I){var j;return(j=s).call.apply(j,[m,I].concat(g))})}}var c;if(typeof s!="function"&&st(6),o!==void 0&&typeof o!="function"&&st(7),yn(i)){var l=yv(r),f=mu(r,i,void 0),p=!0;try{c=s(f),p=!1}finally{p?Js(l):hu(l)}return typeof Promise<"u"&&c instanceof Promise?c.then(function(y){return uu(l,o),cu(y,l)},function(y){throw Js(l),y}):(uu(l,o),cu(c,l))}if(!i||typeof i!="object"){if((c=s(i))===void 0&&(c=i),c===kv&&(c=void 0),r.D&&_u(c,!0),o){var h=[],d=[];dt("Patches").M(i,c,h,d),o(h,d)}return c}st(21,i)},this.produceWithPatches=function(i,s){if(typeof i=="function")return function(c){for(var l=arguments.length,f=Array(l>1?l-1:0),p=1;p<l;p++)f[p-1]=arguments[p];return r.produceWithPatches(c,function(h){return i.apply(void 0,[h].concat(f))})};var o,a,u=r.produce(i,s,function(c,l){o=c,a=l});return typeof Promise<"u"&&u instanceof Promise?u.then(function(c){return[c,o,a]}):[u,o,a]},typeof n?.useProxies=="boolean"&&this.setUseProxies(n.useProxies),typeof n?.autoFreeze=="boolean"&&this.setAutoFreeze(n.autoFreeze)}var t=e.prototype;return t.createDraft=function(n){yn(n)||st(8),Wn(n)&&(n=F2(n));var r=yv(this),i=mu(this,n,void 0);return i[Je].C=!0,hu(r),i},t.finishDraft=function(n,r){var i=n&&n[Je],s=i.A;return uu(s,r),cu(void 0,s)},t.setAutoFreeze=function(n){this.D=n},t.setUseProxies=function(n){n&&!Ov&&st(20),this.O=n},t.applyPatches=function(n,r){var i;for(i=r.length-1;i>=0;i--){var s=r[i];if(s.path.length===0&&s.op==="replace"){n=s.value;break}}i>-1&&(r=r.slice(i+1));var o=dt("Patches").$;return Wn(n)?o(n,r):this.produce(n,function(a){return o(a,r)})},e}(),Ye=new W2,J2=Ye.produce,j6=Ye.produceWithPatches.bind(Ye),D6=Ye.setAutoFreeze.bind(Ye),R6=Ye.setUseProxies.bind(Ye),B6=Ye.applyPatches.bind(Ye),L6=Ye.createDraft.bind(Ye),G6=Ye.finishDraft.bind(Ye),Av=J2;var Eu=class{constructor(t){let n=Y2();this.c=1,this.s0=n(" "),this.s1=n(" "),this.s2=n(" "),this.s0-=n(t),this.s0<0&&(this.s0+=1),this.s1-=n(t),this.s1<0&&(this.s1+=1),this.s2-=n(t),this.s2<0&&(this.s2+=1)}next(){let t=2091639*this.s0+this.c*23283064365386963e-26;return this.s0=this.s1,this.s1=this.s2,this.s2=t-(this.c=Math.trunc(t))}};function Y2(){let e=4022871197;return function(n){let r=n.toString();for(let i=0;i<r.length;i++){e+=r.charCodeAt(i);let s=.02519603282416938*e;e=s>>>0,s-=e,s*=e,e=s>>>0,s-=e,e+=s*4294967296}return(e>>>0)*23283064365386963e-26}}function xv(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function ku(e,t){let n=new Eu(e),r=n.next.bind(n);return t&&xv(t,n),r.state=()=>xv(n,{}),r}var Xs=class{constructor(t){this.state=t||{seed:"0"},this.used=!1}static seed(){return Date.now().toString(36).slice(-10)}isUsed(){return this.used}getState(){return this.state}_random(){this.used=!0;let t=this.state,n=t.prngstate?"":t.seed,r=ku(n,t.prngstate),i=r();return this.state={...t,prngstate:r.state()},i}api(){let t=this._random.bind(this),n={D4:4,D6:6,D8:8,D10:10,D12:12,D20:20},r={};for(let s in n){let o=n[s];r[s]=a=>a===void 0?Math.floor(t()*o)+1:Array.from({length:a}).map(()=>Math.floor(t()*o)+1)}function i(s=6,o){return o===void 0?Math.floor(t()*s)+1:Array.from({length:o}).map(()=>Math.floor(t()*s)+1)}return{...r,Die:i,Number:()=>t(),Shuffle:s=>{let o=[...s],a=s.length,u=0,c=Array.from({length:a});for(;a;){let l=Math.trunc(a*t());c[u++]=o[l],o[l]=o[--a]}return c},_private:this}}},Sv={name:"random",noClient:({api:e})=>e._private.isUsed(),flush:({api:e})=>e._private.getState(),api:({data:e})=>new Xs(e).api(),setup:({game:e})=>{let{seed:t}=e;return t===void 0&&(t=Xs.seed()),{seed:t}},playerView:()=>{}};var $2=he(tn()),_i="MAKE_MOVE",Yn="GAME_EVENT",wi="REDO",Oi="RESET",Pi="SYNC",Ei="UNDO",ki="UPDATE",Ai="PATCH",Su="PLUGIN",$n="STRIP_TRANSIENTS",Tu=(e,t,n,r)=>({type:_i,payload:{type:e,args:t,playerID:n,credentials:r}}),vn=(e,t,n,r)=>({type:Yn,payload:{type:e,args:t,playerID:n,credentials:r}}),Tv=(e,t,n,r)=>({type:Yn,payload:{type:e,args:t,playerID:n,credentials:r},automatic:!0}),xi=e=>({type:Pi,state:e.state,log:e.log,initialState:e.initialState,clientOnly:!0}),Mu=(e,t,n,r)=>({type:Ai,prevStateID:e,stateID:t,patch:n,deltalog:r,clientOnly:!0}),Iu=(e,t)=>({type:ki,state:e,deltalog:t,clientOnly:!0}),Nu=e=>({type:Oi,state:e,clientOnly:!0}),Cu=(e,t)=>({type:Ei,payload:{type:null,args:null,playerID:e,credentials:t}}),qu=(e,t)=>({type:wi,payload:{type:null,args:null,playerID:e,credentials:t}}),X2=(e,t,n,r)=>({type:Su,payload:{type:e,args:t,playerID:n,credentials:r}}),ju=()=>({type:$n}),Mv=Object.freeze({__proto__:null,makeMove:Tu,gameEvent:vn,automaticGameEvent:Tv,sync:xi,patch:Mu,update:Iu,reset:Nu,undo:Cu,redo:qu,plugin:X2,stripTransients:ju}),Zs="INVALID_MOVE",Q2={name:"plugin-immer",fnWrap:e=>(t,...n)=>{let r=!1,i=Av(t.G,s=>{let o=e({...t,G:s},...n);if(o===Zs){r=!0;return}return o});return r?Zs:i}},Re;(function(e){e.MOVE="MOVE",e.GAME_ON_END="GAME_ON_END",e.PHASE_ON_BEGIN="PHASE_ON_BEGIN",e.PHASE_ON_END="PHASE_ON_END",e.TURN_ON_BEGIN="TURN_ON_BEGIN",e.TURN_ON_MOVE="TURN_ON_MOVE",e.TURN_ON_END="TURN_ON_END"})(Re||(Re={}));var It;(function(e){e.CalledOutsideHook="Events must be called from moves or the `onBegin`, `onEnd`, and `onMove` hooks.\nThis error probably means you called an event from other game code, like an `endIf` trigger or one of the `turn.order` methods.",e.EndTurnInOnEnd="`endTurn` is disallowed in `onEnd` hooks \u2014 the turn is already ending.",e.MaxTurnEndings=`Maximum number of turn endings exceeded for this update.
|
|
8
8
|
This likely means game code is triggering an infinite loop.`,e.PhaseEventInOnEnd="`setPhase` & `endPhase` are disallowed in a phase\u2019s `onEnd` hook \u2014 the phase is already ending.\nIf you\u2019re trying to dynamically choose the next phase when a phase ends, use the phase\u2019s `next` trigger.",e.StageEventInOnEnd="`setStage`, `endStage` & `setActivePlayers` are disallowed in `onEnd` hooks.",e.StageEventInPhaseBegin="`setStage`, `endStage` & `setActivePlayers` are disallowed in a phase\u2019s `onBegin` hook.\nUse `setActivePlayers` in a `turn.onBegin` hook or declare stages with `turn.activePlayers` instead.",e.StageEventInTurnBegin="`setStage` & `endStage` are disallowed in `turn.onBegin`.\nUse `setActivePlayers` or declare stages with `turn.activePlayers` instead."})(It||(It={}));var Au=class{constructor(t,n,r){this.flow=t,this.playerID=r,this.dispatch=[],this.initialTurn=n.turn,this.updateTurnContext(n,void 0),this.maxEndedTurnsPerAction=n.numPlayers*100}api(){let t={_private:this};for(let n of this.flow.eventNames)t[n]=(...r)=>{this.dispatch.push({type:n,args:r,phase:this.currentPhase,turn:this.currentTurn,calledFrom:this.currentMethod,error:new Error("Events Plugin Error")})};return t}isUsed(){return this.dispatch.length>0}updateTurnContext(t,n){this.currentPhase=t.phase,this.currentTurn=t.turn,this.currentMethod=n}unsetCurrentMethod(){this.currentMethod=void 0}update(t){let n=t,r=({stack:i},s)=>({...n,plugins:{...n.plugins,events:{...n.plugins.events,data:{error:s+`
|
|
9
9
|
`+i}}}});e:for(let i=0;i<this.dispatch.length;i++){let s=this.dispatch[i],o=s.turn!==t.ctx.turn;if(this.currentTurn-this.initialTurn>=this.maxEndedTurnsPerAction)return r(s.error,It.MaxTurnEndings);if(s.calledFrom===void 0)return r(s.error,It.CalledOutsideHook);if(t.ctx.gameover)break e;switch(s.type){case"endStage":case"setStage":case"setActivePlayers":{switch(s.calledFrom){case Re.TURN_ON_END:case Re.PHASE_ON_END:return r(s.error,It.StageEventInOnEnd);case Re.PHASE_ON_BEGIN:return r(s.error,It.StageEventInPhaseBegin);case Re.TURN_ON_BEGIN:if(s.type==="setActivePlayers")break;return r(s.error,It.StageEventInTurnBegin)}if(o)continue e;break}case"endTurn":{if(s.calledFrom===Re.TURN_ON_END||s.calledFrom===Re.PHASE_ON_END)return r(s.error,It.EndTurnInOnEnd);if(o)continue e;break}case"endPhase":case"setPhase":{if(s.calledFrom===Re.PHASE_ON_END)return r(s.error,It.PhaseEventInOnEnd);if(s.phase!==t.ctx.phase)continue e;break}}let u=Tv(s.type,s.args,this.playerID);t=this.flow.processEvent(t,u)}return t}},Du={name:"events",noClient:({api:e})=>e._private.isUsed(),isInvalid:({data:e})=>e.error||!1,fnWrap:(e,t)=>(n,...r)=>{let i=n.events;i&&i._private.updateTurnContext(n.ctx,t);let s=e(n,...r);return i&&i._private.unsetCurrentMethod(),s},dangerouslyFlushRawState:({state:e,api:t})=>t._private.update(e),api:({game:e,ctx:t,playerID:n})=>new Au(e.flow,t,n).api()},Z2={name:"log",flush:()=>({}),api:({data:e})=>({setMetadata:t=>{e.metadata=t}}),setup:()=>({})};var eC={name:"plugin-serializable",fnWrap:e=>(t,...n)=>e(t,...n)},tC=!0,nC=tC?()=>{}:(...e)=>console.log(...e),rC=(...e)=>console.error(...e);function Ru(e){nC(`INFO: ${e}`)}function Oe(e){rC("ERROR:",e)}var Bu=[Q2,Sv,Z2,eC],Si=[...Bu,Du],Iv=(e,t,n)=>(n.game.plugins.filter(r=>r.action!==void 0).filter(r=>r.name===t.payload.type).forEach(r=>{let i=r.name,s=e.plugins[i]||{data:{}},o=r.action(s.data,t.payload);e={...e,plugins:{...e.plugins,[i]:{...s,data:o}}}}),e),Wt=({plugins:e})=>Object.entries(e||{}).reduce((t,[n,{api:r}])=>(t[n]=r,t),{}),Lu=(e,t,n)=>[...Bu,...n,Du].filter(r=>r.fnWrap!==void 0).reduce((r,{fnWrap:i})=>i(r,t),e),Nv=(e,t)=>([...Si,...t.game.plugins].filter(n=>n.setup!==void 0).forEach(n=>{let r=n.name,i=n.setup({G:e.G,ctx:e.ctx,game:t.game});e={...e,plugins:{...e.plugins,[r]:{data:i}}}}),e),Ti=(e,t)=>([...Si,...t.game.plugins].filter(n=>n.api!==void 0).forEach(n=>{let r=n.name,i=e.plugins[r]||{data:{}},s=n.api({G:e.G,ctx:e.ctx,data:i.data,game:t.game,playerID:t.playerID});e={...e,plugins:{...e.plugins,[r]:{...i,api:s}}}}),e),iC=(e,t)=>([...Bu,...t.game.plugins,Du].reverse().forEach(n=>{let r=n.name,i=e.plugins[r]||{data:{}};if(n.flush){let s=n.flush({G:e.G,ctx:e.ctx,game:t.game,api:i.api,data:i.data});e={...e,plugins:{...e.plugins,[n.name]:{data:s}}}}else if(n.dangerouslyFlushRawState){e=n.dangerouslyFlushRawState({state:e,game:t.game,api:i.api,data:i.data});let s=e.plugins[r].data;e={...e,plugins:{...e.plugins,[n.name]:{data:s}}}}}),e),Cv=(e,t)=>[...Si,...t.game.plugins].filter(n=>n.noClient!==void 0).map(n=>{let r=n.name,i=e.plugins[r];return i?n.noClient({G:e.G,ctx:e.ctx,game:t.game,api:i.api,data:i.data}):!1}).includes(!0),sC=(e,t)=>[...Si,...t.game.plugins].filter(r=>r.isInvalid!==void 0).map(r=>{let{name:i}=r,s=e.plugins[i],o=r.isInvalid({G:e.G,ctx:e.ctx,game:t.game,data:s&&s.data});return o?{plugin:i,message:o}:!1}).find(r=>r)||!1,eo=(e,t)=>{let n=iC(e,t),r=sC(n,t);if(!r)return[n];let{plugin:i,message:s}=r;return Oe(`${i} plugin declared action invalid:
|
|
10
10
|
${s}`),[e,r]},qv=({G:e,ctx:t,plugins:n={}},{game:r,playerID:i})=>([...Si,...r.plugins].forEach(({name:s,playerView:o})=>{if(!o)return;let{data:a}=n[s]||{data:{}},u=o({G:e,ctx:t,game:r,data:a,playerID:i});n={...n,[s]:{data:u}}}),n);function Mi(e,t=!1){e.moveLimit&&(t&&(e.minMoves=e.moveLimit),e.maxMoves=e.moveLimit,delete e.moveLimit)}function Ii(e,t){let n={},r=[],i=null,s={},o={};if(Array.isArray(t)){let u={};t.forEach(c=>u[c]=Nt.NULL),n=u}else{if(Mi(t),t.next&&(i=t.next),t.revert&&(r=[...e._prevActivePlayers,{activePlayers:e.activePlayers,_activePlayersMinMoves:e._activePlayersMinMoves,_activePlayersMaxMoves:e._activePlayersMaxMoves,_activePlayersNumMoves:e._activePlayersNumMoves}]),t.currentPlayer!==void 0&&Qs(n,s,o,e.currentPlayer,t.currentPlayer),t.others!==void 0)for(let u=0;u<e.playOrder.length;u++){let c=e.playOrder[u];c!==e.currentPlayer&&Qs(n,s,o,c,t.others)}if(t.all!==void 0)for(let u=0;u<e.playOrder.length;u++){let c=e.playOrder[u];Qs(n,s,o,c,t.all)}if(t.value)for(let u in t.value)Qs(n,s,o,u,t.value[u]);if(t.minMoves)for(let u in n)s[u]===void 0&&(s[u]=t.minMoves);if(t.maxMoves)for(let u in n)o[u]===void 0&&(o[u]=t.maxMoves)}Object.keys(n).length===0&&(n=null),Object.keys(s).length===0&&(s=null),Object.keys(o).length===0&&(o=null);let a={};for(let u in n)a[u]=0;return{...e,activePlayers:n,_activePlayersMinMoves:s,_activePlayersMaxMoves:o,_activePlayersNumMoves:a,_prevActivePlayers:r,_nextActivePlayers:i}}function jv(e){let{activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s,_nextActivePlayers:o}=e;if(t&&Object.keys(t).length===0)if(o)e=Ii(e,o),{activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s}=e;else if(s.length>0){let a=s.length-1;({activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i}=s[a]),s=s.slice(0,a)}else t=null,n=null,r=null;return{...e,activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:i,_prevActivePlayers:s}}function Qs(e,t,n,r,i){(typeof i!="object"||i===Nt.NULL)&&(i={stage:i}),i.stage!==void 0&&(Mi(i),e[r]=i.stage,i.minMoves&&(t[r]=i.minMoves),i.maxMoves&&(n[r]=i.maxMoves))}function xu(e,t){return e[t]+""}function Dv(e,t){let{G:n,ctx:r}=e,{numPlayers:i}=r,o={...Wt(e),G:n,ctx:r},a=t.order,u=[...Array.from({length:i})].map((p,h)=>h+"");a.playOrder!==void 0&&(u=a.playOrder(o));let c=a.first(o),l=typeof c;l!=="number"&&Oe(`invalid value returned by turn.order.first \u2014 expected number got ${l} \u201C${c}\u201D.`);let f=xu(u,c);return r={...r,currentPlayer:f,playOrderPos:c,playOrder:u},r=Ii(r,t.activePlayers||{}),r}function Rv(e,t,n,r){let i=n.order,{G:s,ctx:o}=e,a=o.playOrderPos,u=!1;if(r&&r!==!0)typeof r!="object"&&Oe(`invalid argument to endTurn: ${r}`),Object.keys(r).forEach(c=>{switch(c){case"remove":t=xu(o.playOrder,a);break;case"next":a=o.playOrder.indexOf(r.next),t=r.next;break;default:Oe(`invalid argument to endTurn: ${c}`)}});else{let l={...Wt(e),G:s,ctx:o},f=i.next(l),p=typeof f;f!==void 0&&p!=="number"&&Oe(`invalid value returned by turn.order.next \u2014 expected number or undefined got ${p} \u201C${f}\u201D.`),f===void 0?u=!0:(a=f,t=xu(o.playOrder,a))}return o={...o,playOrderPos:a,currentPlayer:t},{endPhase:u,ctx:o}}var Bv={DEFAULT:{first:({ctx:e})=>e.turn===0?e.playOrderPos:(e.playOrderPos+1)%e.playOrder.length,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},RESET:{first:()=>0,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},CONTINUE:{first:({ctx:e})=>e.playOrderPos,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},ONCE:{first:()=>0,next:({ctx:e})=>{if(e.playOrderPos<e.playOrder.length-1)return e.playOrderPos+1}},CUSTOM:e=>({playOrder:()=>e,first:()=>0,next:({ctx:t})=>(t.playOrderPos+1)%t.playOrder.length}),CUSTOM_FROM:e=>({playOrder:({G:t})=>t[e],first:()=>0,next:({ctx:t})=>(t.playOrderPos+1)%t.playOrder.length})},Nt={NULL:null},K6={ALL:{all:Nt.NULL},ALL_ONCE:{all:Nt.NULL,minMoves:1,maxMoves:1},OTHERS:{others:Nt.NULL},OTHERS_ONCE:{others:Nt.NULL,minMoves:1,maxMoves:1}};var{parse:oC,stringify:aC}=JSON,{keys:uC}=Object,Ni=String,Fv="string",Lv={},to="object",Uv=(e,t)=>t,cC=e=>e instanceof Ni?Ni(e):e,lC=(e,t)=>typeof t===Fv?new Ni(t):t,Vv=(e,t,n,r)=>{let i=[];for(let s=uC(n),{length:o}=s,a=0;a<o;a++){let u=s[a],c=n[u];if(c instanceof Ni){let l=e[c];typeof l===to&&!t.has(l)?(t.add(l),n[u]=Lv,i.push({k:u,a:[e,t,l,r]})):n[u]=r.call(n,u,l)}else n[u]!==Lv&&(n[u]=r.call(n,u,c))}for(let{length:s}=i,o=0;o<s;o++){let{k:a,a:u}=i[o];n[a]=r.call(n,a,Vv.apply(null,u))}return n},Gv=(e,t,n)=>{let r=Ni(t.push(n)-1);return e.set(n,r),r},Gu=(e,t)=>{let n=oC(e,lC).map(cC),r=n[0],i=t||Uv,s=typeof r===to&&r?Vv(n,new Set,r,i):r;return i.call({"":s},"",s)},Fu=(e,t,n)=>{let r=t&&typeof t===to?(l,f)=>l===""||-1<t.indexOf(l)?f:void 0:t||Uv,i=new Map,s=[],o=[],a=+Gv(i,s,r.call({"":e},"",e)),u=!a;for(;a<s.length;)u=!0,o[a]=aC(s[a++],c,n);return"["+o.join(",")+"]";function c(l,f){if(u)return u=!u,f;let p=r.call(this,l,f);switch(typeof p){case to:if(p===null)return p;case Fv:return i.get(p)||Gv(i,s,p)}return p}};var ab=he(qi());function EC({moves:e,phases:t,endIf:n,onEnd:r,turn:i,events:s,plugins:o}){e===void 0&&(e={}),s===void 0&&(s={}),o===void 0&&(o=[]),t===void 0&&(t={}),n||(n=()=>{}),r||(r=({G:_})=>_),i||(i={});let a={...t};""in a&&Oe("cannot specify phase with empty name"),a[""]={};let u={},c=new Set,l=null;Object.keys(e).forEach(_=>c.add(_));let f=(_,E)=>{let T=Lu(_,E,o);return F=>{let z=Wt(F);return T({...z,G:F.G,ctx:F.ctx,playerID:F.playerID})}},p=_=>E=>{let T=Wt(E);return _({...T,G:E.G,ctx:E.ctx})},h={onEnd:f(r,Re.GAME_ON_END),endIf:p(n)};for(let _ in a){let E=a[_];if(E.start===!0&&(l=_),E.moves!==void 0)for(let T of Object.keys(E.moves))u[_+"."+T]=E.moves[T],c.add(T);E.endIf===void 0&&(E.endIf=()=>{}),E.onBegin===void 0&&(E.onBegin=({G:T})=>T),E.onEnd===void 0&&(E.onEnd=({G:T})=>T),E.turn===void 0&&(E.turn=i),E.turn.order===void 0&&(E.turn.order=Bv.DEFAULT),E.turn.onBegin===void 0&&(E.turn.onBegin=({G:T})=>T),E.turn.onEnd===void 0&&(E.turn.onEnd=({G:T})=>T),E.turn.endIf===void 0&&(E.turn.endIf=()=>!1),E.turn.onMove===void 0&&(E.turn.onMove=({G:T})=>T),E.turn.stages===void 0&&(E.turn.stages={}),Mi(E.turn,!0);for(let T in E.turn.stages){let z=E.turn.stages[T].moves||{};for(let H of Object.keys(z)){let Se=_+"."+T+"."+H;u[Se]=z[H],c.add(H)}}if(E.wrapped={onBegin:f(E.onBegin,Re.PHASE_ON_BEGIN),onEnd:f(E.onEnd,Re.PHASE_ON_END),endIf:p(E.endIf)},E.turn.wrapped={onMove:f(E.turn.onMove,Re.TURN_ON_MOVE),onBegin:f(E.turn.onBegin,Re.TURN_ON_BEGIN),onEnd:f(E.turn.onEnd,Re.TURN_ON_END),endIf:p(E.turn.endIf)},typeof E.next!="function"){let{next:T}=E;E.next=()=>T||null}E.wrapped.next=p(E.next)}function d(_){return _.phase?a[_.phase]:a[""]}function y(_){return _}function m(_,E){let T=new Set,F=new Set;for(let z=0;z<E.length;z++){let{fn:H,arg:Se,...ve}=E[z];if(H===ne){F.clear();let Ge=_.ctx.phase;if(T.has(Ge)){let ct={..._.ctx,phase:null};return{..._,ctx:ct}}T.add(Ge)}let Ze=[];if(_=H(_,{...ve,arg:Se,next:Ze}),H===se)break;let Ce=J(_);if(Ce){E.push({fn:se,arg:Ce,turn:_.ctx.turn,phase:_.ctx.phase,automatic:!0});continue}let De=fe(_);if(De){E.push({fn:ne,arg:De,turn:_.ctx.turn,phase:_.ctx.phase,automatic:!0});continue}if([y,N,D].includes(H)){let Ge=V(_);if(Ge){E.push({fn:G,arg:Ge,turn:_.ctx.turn,phase:_.ctx.phase,automatic:!0});continue}}E.push(...Ze)}return _}function b(_,{next:E}){return E.push({fn:g}),_}function g(_,{next:E}){let{G:T,ctx:F}=_;return T=d(F).wrapped.onBegin(_),E.push({fn:O}),{..._,G:T,ctx:F}}function O(_,{currentPlayer:E}){let{ctx:T}=_,F=d(T);E?(T={...T,currentPlayer:E},F.turn.activePlayers&&(T=Ii(T,F.turn.activePlayers))):T=Dv(_,F.turn);let z=T.turn+1;T={...T,turn:z,numMoves:0,_prevActivePlayers:[]};let H=F.turn.wrapped.onBegin({..._,ctx:T});return{..._,G:H,ctx:T,_undo:[],_redo:[]}}function I(_,{arg:E,next:T,phase:F}){let z=d({phase:F}),{ctx:H}=_;if(E&&E.next)if(E.next in a)H={...H,phase:E.next};else return Oe("invalid phase: "+E.next),_;else H={...H,phase:z.wrapped.next(_)||null};return _={..._,ctx:H},T.push({fn:g}),_}function j(_,{arg:E,currentPlayer:T,next:F}){let{G:z,ctx:H}=_,Se=d(H),{endPhase:ve,ctx:Ze}=Rv(_,T,Se.turn,E);return H=Ze,_={..._,G:z,ctx:H},ve?F.push({fn:ne,turn:H.turn,phase:H.phase}):F.push({fn:O,currentPlayer:H.currentPlayer}),_}function N(_,{arg:E,playerID:T}){if((typeof E=="string"||E===Nt.NULL)&&(E={stage:E}),typeof E!="object")return _;Mi(E);let{ctx:F}=_,{activePlayers:z,_activePlayersMinMoves:H,_activePlayersMaxMoves:Se,_activePlayersNumMoves:ve}=F;return E.stage!==void 0&&(z===null&&(z={}),z[T]=E.stage,ve[T]=0,E.minMoves&&(H===null&&(H={}),H[T]=E.minMoves),E.maxMoves&&(Se===null&&(Se={}),Se[T]=E.maxMoves)),F={...F,activePlayers:z,_activePlayersMinMoves:H,_activePlayersMaxMoves:Se,_activePlayersNumMoves:ve},{..._,ctx:F}}function D(_,{arg:E}){return{..._,ctx:Ii(_.ctx,E)}}function J(_){return h.endIf(_)}function fe(_){return d(_.ctx).wrapped.endIf(_)}function V(_){let E=d(_.ctx),T=_.ctx.numMoves||0;return E.turn.maxMoves&&T>=E.turn.maxMoves?!0:E.turn.wrapped.endIf(_)}function se(_,{arg:E,phase:T}){_=ne(_,{phase:T}),E===void 0&&(E=!0),_={..._,ctx:{..._.ctx,gameover:E}};let F=h.onEnd(_);return{..._,G:F}}function ne(_,{arg:E,next:T,turn:F,automatic:z}){_=G(_,{turn:F,force:!0,automatic:!0});let{phase:H,turn:Se}=_.ctx;if(T&&T.push({fn:I,arg:E,phase:H}),H===null)return _;let Ze=d(_.ctx).wrapped.onEnd(_),Ce={..._.ctx,phase:null},De=vn("endPhase",E),{_stateID:Ge}=_,ct={action:De,_stateID:Ge,turn:Se,phase:H};z&&(ct.automatic=!0);let Zt=[..._.deltalog||[],ct];return{..._,G:Ze,ctx:Ce,deltalog:Zt}}function G(_,{arg:E,next:T,turn:F,force:z,automatic:H,playerID:Se}){if(F!==_.ctx.turn)return _;let{currentPlayer:ve,numMoves:Ze,phase:Ce,turn:De}=_.ctx,Ge=d(_.ctx),ct=Ze||0;if(!z&&Ge.turn.minMoves&&ct<Ge.turn.minMoves)return Ru(`cannot end turn before making ${Ge.turn.minMoves} moves`),_;let Zt=Ge.turn.wrapped.onEnd(_);T&&T.push({fn:j,arg:E,currentPlayer:ve});let Gt={..._.ctx,activePlayers:null};if(E&&E.remove){Se=Se||ve;let en=Gt.playOrder.filter(m_=>m_!=Se),d_=Gt.playOrderPos>en.length-1?0:Gt.playOrderPos;if(Gt={...Gt,playOrder:en,playOrderPos:d_},en.length===0)return T.push({fn:ne,turn:De,phase:Ce}),_}let Do=vn("endTurn",E),{_stateID:cl}=_,pr={action:Do,_stateID:cl,turn:De,phase:Ce};H&&(pr.automatic=!0);let Ro=[..._.deltalog||[],pr];return{..._,G:Zt,ctx:Gt,deltalog:Ro,_undo:[],_redo:[]}}function Pe(_,{arg:E,next:T,automatic:F,playerID:z}){z=z||_.ctx.currentPlayer;let{ctx:H,_stateID:Se}=_,{activePlayers:ve,_activePlayersNumMoves:Ze,_activePlayersMinMoves:Ce,_activePlayersMaxMoves:De,phase:Ge,turn:ct}=H,Zt=ve!==null&&z in ve,Gt=d(H);if(!E&&Zt){let en=Gt.turn.stages[ve[z]];en&&en.next&&(E=en.next)}if(T&&T.push({fn:N,arg:E,playerID:z}),!Zt)return _;let Do=Ze[z]||0;if(Ce&&Ce[z]&&Do<Ce[z])return Ru(`cannot end stage before making ${Ce[z]} moves`),_;ve={...ve},delete ve[z],Ce&&(Ce={...Ce},delete Ce[z]),De&&(De={...De},delete De[z]),H=jv({...H,activePlayers:ve,_activePlayersMinMoves:Ce,_activePlayersMaxMoves:De});let pr={action:vn("endStage",E),_stateID:Se,turn:ct,phase:Ge};F&&(pr.automatic=!0);let Ro=[..._.deltalog||[],pr];return{..._,ctx:H,deltalog:Ro}}function ue(_,E,T){let F=d(_),z=F.turn.stages,{activePlayers:H}=_;if(H&&H[T]!==void 0&&H[T]!==Nt.NULL&&z[H[T]]!==void 0&&z[H[T]].moves!==void 0){let ve=z[H[T]].moves;if(E in ve)return ve[E]}else if(F.moves){if(E in F.moves)return F.moves[E]}else if(E in e)return e[E];return null}function Lt(_,E){let{playerID:T,type:F}=E,{currentPlayer:z,activePlayers:H,_activePlayersMaxMoves:Se}=_.ctx,ve=ue(_.ctx,F,T),Ze=!ve||typeof ve=="function"||ve.noLimit!==!0,{numMoves:Ce,_activePlayersNumMoves:De}=_.ctx;Ze&&(T===z&&Ce++,H&&De[T]++),_={..._,ctx:{..._.ctx,numMoves:Ce,_activePlayersNumMoves:De}},Se&&De[T]>=Se[T]&&(_=Pe(_,{playerID:T,automatic:!0}));let ct=d(_.ctx).turn.wrapped.onMove({..._,playerID:T});return _={..._,G:ct},m(_,[{fn:y}])}function bt(_,E,T){return m(_,[{fn:Pe,arg:T,playerID:E}])}function kn(_,E){return m(_,[{fn:Pe,playerID:E}])}function _t(_,E,T){return m(_,[{fn:D,arg:T}])}function xe(_,E,T){return m(_,[{fn:ne,phase:_.ctx.phase,turn:_.ctx.turn,arg:{next:T}}])}function jo(_){return m(_,[{fn:ne,phase:_.ctx.phase,turn:_.ctx.turn}])}function Me(_,E,T){return m(_,[{fn:G,turn:_.ctx.turn,phase:_.ctx.phase,arg:T}])}function Ie(_,E,T){return m(_,[{fn:G,turn:_.ctx.turn,phase:_.ctx.phase,force:!0,arg:T}])}function Ne(_,E,T){return m(_,[{fn:se,turn:_.ctx.turn,phase:_.ctx.phase,arg:T}])}let C={endStage:kn,setStage:bt,endTurn:Me,pass:Ie,endPhase:jo,setPhase:xe,endGame:Ne,setActivePlayers:_t},W=[];s.endTurn!==!1&&W.push("endTurn"),s.pass!==!1&&W.push("pass"),s.endPhase!==!1&&W.push("endPhase"),s.setPhase!==!1&&W.push("setPhase"),s.endGame!==!1&&W.push("endGame"),s.setActivePlayers!==!1&&W.push("setActivePlayers"),s.endStage!==!1&&W.push("endStage"),s.setStage!==!1&&W.push("setStage");function wt(_,E){let{type:T,playerID:F,args:z}=E.payload;return typeof C[T]!="function"?_:C[T](_,F,...Array.isArray(z)?z:[z])}function fr(_,E,T){return E.activePlayers?T in E.activePlayers:E.currentPlayer===T}return{ctx:_=>({numPlayers:_,turn:0,currentPlayer:"0",playOrder:[...Array.from({length:_})].map((E,T)=>T+""),playOrderPos:0,phase:l,activePlayers:null}),init:_=>m(_,[{fn:b}]),isPlayerActive:fr,eventHandlers:C,eventNames:Object.keys(C),enabledEventNames:W,moveMap:u,moveNames:[...c.values()],processMove:Lt,processEvent:wt,getMove:ue}}function kC(e){return e.processMove!==void 0}function ji(e){if(kC(e))return e;if(e.name===void 0&&(e.name="default"),e.deltaState===void 0&&(e.deltaState=!1),e.disableUndo===void 0&&(e.disableUndo=!1),e.setup===void 0&&(e.setup=()=>({})),e.moves===void 0&&(e.moves={}),e.playerView===void 0&&(e.playerView=({G:n})=>n),e.plugins===void 0&&(e.plugins=[]),e.plugins.forEach(n=>{if(n.name===void 0)throw new Error("Plugin missing name attribute");if(n.name.includes(" "))throw new Error(n.name+": Plugin name must not include spaces")}),e.name.includes(" "))throw new Error(e.name+": Game name must not include spaces");let t=EC(e);return{...e,flow:t,moveNames:t.moveNames,pluginNames:e.plugins.map(n=>n.name),processMove:(n,r)=>{let i=t.getMove(n.ctx,r.type,r.playerID);if(AC(i)&&(i=i.move),i instanceof Function){let s=Lu(i,Re.MOVE,e.plugins),o=[];r.args!==void 0&&(o=Array.isArray(r.args)?r.args:[r.args]);let a={...Wt(n),G:n.G,ctx:n.ctx,playerID:r.playerID};return s(a,...o)}return Oe(`invalid move object: ${r.type}`),n.G}}}function AC(e){return e instanceof Object&&e.move!==void 0}var tc;(function(e){e.UnauthorizedAction="update/unauthorized_action",e.MatchNotFound="update/match_not_found",e.PatchFailed="update/patch_failed"})(tc||(tc={}));var Be;(function(e){e.StaleStateId="action/stale_state_id",e.UnavailableMove="action/unavailable_move",e.InvalidMove="action/invalid_move",e.InactivePlayer="action/inactive_player",e.GameOver="action/gameover",e.ActionDisabled="action/action_disabled",e.ActionInvalid="action/action_invalid",e.PluginActionInvalid="action/plugin_invalid"})(Be||(Be={}));var ro=e=>e.payload.playerID!==null&&e.payload.playerID!==void 0,xC=(e,t,n)=>{function r(s){return s.undoable!==void 0}function i(s){return s instanceof Function}return r(n)?i(n.undoable)?n.undoable({G:e,ctx:t}):n.undoable:!0};function ob(e,t){if(t.game.disableUndo)return e;let n={G:e.G,ctx:e.ctx,plugins:e.plugins,playerID:t.action.payload.playerID||e.ctx.currentPlayer};return t.action.type==="MAKE_MOVE"&&(n.moveType=t.action.payload.type),{...e,_undo:[...e._undo,n],_redo:[]}}function Zu(e,t,n){let r={action:t,_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase},i=e.plugins.log.data.metadata;return i!==void 0&&(r.metadata=i),typeof n=="object"&&n.redact===!0?r.redact=!0:typeof n=="object"&&n.redact instanceof Function&&(r.redact=n.redact({G:e.G,ctx:e.ctx})),{...e,deltalog:[r]}}function ec(e,t,n){let[r,i]=eo(e,n);return i?[r,Fe(t,Be.PluginActionInvalid,i)]:[r]}function ub(e){if(!e)return[null,void 0];let{transients:t,...n}=e;return[n,t]}function Fe(e,t,n){return{...e,transients:{error:{type:t,payload:n}}}}var cb=e=>t=>n=>{let r=t(n);switch(n.type){case $n:return r;default:{let[,i]=ub(e.getState());return typeof i<"u"?(e.dispatch(ju()),{...r,transients:i}):r}}};function Xn({game:e,isClient:t}){return e=ji(e),(n=null,r)=>{let[i]=ub(n);switch(r.type){case $n:return i;case Yn:{if(i={...i,deltalog:[]},t)return i;if(i.ctx.gameover!==void 0)return Oe("cannot call event after game end"),Fe(i,Be.GameOver);if(ro(r)&&!e.flow.isPlayerActive(i.G,i.ctx,r.payload.playerID))return Oe(`disallowed event: ${r.payload.type}`),Fe(i,Be.InactivePlayer);i=Ti(i,{game:e,isClient:!1,playerID:r.payload.playerID});let s=e.flow.processEvent(i,r),o;return[s,o]=ec(s,i,{game:e,isClient:!1}),o||(s=ob(s,{game:e,action:r}),{...s,_stateID:i._stateID+1})}case _i:{let s=i={...i,deltalog:[]},o=e.flow.getMove(i.ctx,r.payload.type,r.payload.playerID||i.ctx.currentPlayer);if(o===null)return Oe(`disallowed move: ${r.payload.type}`),Fe(i,Be.UnavailableMove);if(t&&o.client===!1)return i;if(i.ctx.gameover!==void 0)return Oe("cannot make move after game end"),Fe(i,Be.GameOver);if(ro(r)&&!e.flow.isPlayerActive(i.G,i.ctx,r.payload.playerID))return Oe(`disallowed move: ${r.payload.type}`),Fe(i,Be.InactivePlayer);i=Ti(i,{game:e,isClient:t,playerID:r.payload.playerID});let a=e.processMove(i,r.payload);if(a===Zs)return Oe(`invalid move: ${r.payload.type} args: ${r.payload.args}`),Fe(i,Be.InvalidMove);let u={...i,G:a};if(t&&Cv(u,{game:e}))return i;if(i=u,t){let l;return[i,l]=ec(i,s,{game:e,isClient:!0}),l||{...i,_stateID:i._stateID+1}}i=Zu(i,r,o),i=e.flow.processMove(i,r.payload);let c;return[i,c]=ec(i,s,{game:e}),c||(i=ob(i,{game:e,action:r}),{...i,_stateID:i._stateID+1})}case Oi:case ki:case Pi:return r.state;case Ei:{if(i={...i,deltalog:[]},e.disableUndo)return Oe("Undo is not enabled"),Fe(i,Be.ActionDisabled);let{G:s,ctx:o,_undo:a,_redo:u,_stateID:c}=i;if(a.length<2)return Oe("No moves to undo"),Fe(i,Be.ActionInvalid);let l=a[a.length-1],f=a[a.length-2];if(ro(r)&&r.payload.playerID!==l.playerID)return Oe("Cannot undo other players' moves"),Fe(i,Be.ActionInvalid);if(l.moveType){let p=e.flow.getMove(f.ctx,l.moveType,l.playerID);if(!xC(s,o,p))return Oe("Move cannot be undone"),Fe(i,Be.ActionInvalid)}return i=Zu(i,r),{...i,G:f.G,ctx:f.ctx,plugins:f.plugins,_stateID:c+1,_undo:a.slice(0,-1),_redo:[l,...u]}}case wi:{if(i={...i,deltalog:[]},e.disableUndo)return Oe("Redo is not enabled"),Fe(i,Be.ActionDisabled);let{_undo:s,_redo:o,_stateID:a}=i;if(o.length===0)return Oe("No moves to redo"),Fe(i,Be.ActionInvalid);let u=o[0];return ro(r)&&r.payload.playerID!==u.playerID?(Oe("Cannot redo other players' moves"),Fe(i,Be.ActionInvalid)):(i=Zu(i,r),{...i,G:u.G,ctx:u.ctx,plugins:u.plugins,_stateID:a+1,_undo:[...s,u],_redo:o.slice(1)})}case Su:return Iv(i,r,{game:e});case Ai:{let s=i,o=JSON.parse(JSON.stringify(s)),a=(0,ab.applyPatch)(o,r.patch);return a.some(c=>c!==null)?(Oe(`Patch ${JSON.stringify(r.patch)} apply failed`),Fe(s,tc.PatchFailed,a)):o}default:return i}}}var nL=he(io());var so=class{constructor({enumerate:t,seed:n}){this.enumerateFn=t,this.seed=n,this.iterationCounter=0,this._opts={}}addOpt({key:t,range:n,initial:r}){this._opts[t]={range:n,value:r}}getOpt(t){return this._opts[t].value}setOpt(t,n){t in this._opts&&(this._opts[t].value=n)}opts(){return this._opts}enumerate(t,n,r){return this.enumerateFn(t,n,r).map(s=>{if("payload"in s)return s;if("move"in s)return Tu(s.move,s.args,r);if("event"in s)return vn(s.event,s.args,r)})}random(t){let n;if(this.seed!==void 0){let r=this.prngstate?"":this.seed,i=ku(r,this.prngstate);n=i(),this.prngstate=i.state()}else n=Math.random();if(t)if(Array.isArray(t)){let r=Math.floor(n*t.length);return t[r]}else return Math.floor(n*t);return n}},SC=25,Di=class extends so{constructor({enumerate:t,seed:n,objectives:r,game:i,iterations:s,playoutDepth:o,iterationCallback:a}){super({enumerate:t,seed:n}),r===void 0&&(r=()=>({})),this.objectives=r,this.iterationCallback=a||(()=>{}),this.reducer=Xn({game:i}),this.iterations=s,this.playoutDepth=o,this.addOpt({key:"async",initial:!1}),this.addOpt({key:"iterations",initial:typeof s=="number"?s:1e3,range:{min:1,max:2e3}}),this.addOpt({key:"playoutDepth",initial:typeof o=="number"?o:50,range:{min:1,max:100}})}createNode({state:t,parentAction:n,parent:r,playerID:i}){let{G:s,ctx:o}=t,a=[],u=[];if(i!==void 0)a=this.enumerate(s,o,i),u=this.objectives(s,o,i);else if(o.activePlayers)for(let c in o.activePlayers)a.push(...this.enumerate(s,o,c)),u.push(this.objectives(s,o,c));else a=this.enumerate(s,o,o.currentPlayer),u=this.objectives(s,o,o.currentPlayer);return{state:t,parent:r,parentAction:n,actions:a,objectives:u,children:[],visits:0,value:0}}select(t){if(t.actions.length>0||t.children.length===0)return t;let n=null,r=0;for(let i of t.children){let s=i.visits+Number.EPSILON,o=i.value/s+Math.sqrt(2*Math.log(t.visits)/s);(n==null||o>r)&&(r=o,n=i)}return this.select(n)}expand(t){let n=t.actions;if(n.length===0||t.state.ctx.gameover!==void 0)return t;let r=this.random(n.length),i=n[r];t.actions.splice(r,1);let s=this.reducer(t.state,i),o=this.createNode({state:s,parentAction:i,parent:t});return t.children.push(o),o}playout({state:t}){let n=this.getOpt("playoutDepth");typeof this.playoutDepth=="function"&&(n=this.playoutDepth(t.G,t.ctx));for(let r=0;r<n&&t.ctx.gameover===void 0;r++){let{G:i,ctx:s}=t,o=s.currentPlayer;s.activePlayers&&(o=Object.keys(s.activePlayers)[0]);let a=this.enumerate(i,s,o),u=this.objectives(i,s,o),c=Object.keys(u).reduce((p,h)=>{let d=u[h];return d.checker(i,s)?p+d.weight:p},0);if(c>0)return{score:c};if(!a||a.length===0)return;let l=this.random(a.length);t=this.reducer(t,a[l])}return t.ctx.gameover}backpropagate(t,n={}){t.visits++,n.score!==void 0&&(t.value+=n.score),n.draw===!0&&(t.value+=.5),t.parentAction&&n.winner===t.parentAction.payload.playerID&&t.value++,t.parent&&this.backpropagate(t.parent,n)}play(t,n){let r=this.createNode({state:t,playerID:n}),i=this.getOpt("iterations");typeof this.iterations=="function"&&(i=this.iterations(t.G,t.ctx));let s=()=>{let o=null;for(let c of r.children)(o==null||c.visits>o.visits)&&(o=c);return{action:o&&o.parentAction,metadata:r}};return new Promise(o=>{let a=()=>{for(let u=0;u<SC&&this.iterationCounter<i;u++){let c=this.select(r),l=this.expand(c),f=this.playout(l);this.backpropagate(l,f),this.iterationCounter++}this.iterationCallback({iterationCounter:this.iterationCounter,numIterations:i,metadata:r})};if(this.iterationCounter=0,this.getOpt("async")){let u=()=>{this.iterationCounter<i?(a(),setImmediate(u)):o(s())};u()}else{for(;this.iterationCounter<i;)a();o(s())}})}},oo=class extends so{play({G:t,ctx:n},r){let i=this.enumerate(t,n,r);return Promise.resolve({action:this.random(i)})}};async function nc(e,t){let n=e.store.getState(),r=n.ctx.currentPlayer;n.ctx.activePlayers&&(r=Object.keys(n.ctx.activePlayers)[0]);let{action:i,metadata:s}=await t.play(n,r);if(i){let o={...i,payload:{...i.payload,metadata:s}};return e.store.dispatch(o),o}}function U(){}var Sc=e=>e;function jt(e,t){for(let n in t)e[n]=t[n];return e}function m1(e){return e()}function fb(){return Object.create(null)}function Le(e){e.forEach(m1)}function Yt(e){return typeof e=="function"}function ee(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function TC(e){return Object.keys(e).length===0}function Hi(e,...t){if(e==null)return U;let n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function g1(e,t,n){e.$$.on_destroy.push(Hi(t,n))}function MC(e,t,n,r){if(e){let i=y1(e,t,n,r);return e[0](i)}}function y1(e,t,n,r){return e[1]&&r?jt(n.ctx.slice(),e[1](r(t))):n.ctx}function IC(e,t,n,r){if(e[2]&&r){let i=e[2](r(n));if(t.dirty===void 0)return i;if(typeof i=="object"){let s=[],o=Math.max(t.dirty.length,i.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|i[a];return s}return t.dirty|i}return t.dirty}function NC(e,t,n,r,i,s){if(i){let o=y1(t,n,r,s);e.p(o,i)}}function CC(e){if(e.ctx.length>32){let t=[],n=e.ctx.length/32;for(let r=0;r<n;r++)t[r]=-1;return t}return-1}function lo(e){let t={};for(let n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function pb(e){return e??""}var v1=typeof window<"u",Tc=v1?()=>window.performance.now():()=>Date.now(),Mc=v1?e=>requestAnimationFrame(e):U,Zn=new Set;function b1(e){Zn.forEach(t=>{t.c(e)||(Zn.delete(t),t.f())}),Zn.size!==0&&Mc(b1)}function Ic(e){let t;return Zn.size===0&&Mc(b1),{promise:new Promise(n=>{Zn.add(t={c:e,f:n})}),abort(){Zn.delete(t)}}}function w(e,t){e.appendChild(t)}function de(e,t,n){let r=Nc(e);if(!r.getElementById(t)){let i=A("style");i.id=t,i.textContent=n,_1(r,i)}}function Nc(e){if(!e)return document;let t=e.getRootNode?e.getRootNode():e.ownerDocument;return t&&t.host?t:e.ownerDocument}function qC(e){let t=A("style");return _1(Nc(e),t),t.sheet}function _1(e,t){w(e.head||e,t)}function M(e,t,n){e.insertBefore(t,n||null)}function S(e){e.parentNode.removeChild(e)}function $e(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function A(e){return document.createElement(e)}function Po(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function Y(e){return document.createTextNode(e)}function q(){return Y(" ")}function at(){return Y("")}function Q(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function jC(e){return function(t){return t.stopPropagation(),e.call(this,t)}}function k(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function DC(e){return e===""?null:+e}function RC(e){return Array.from(e.childNodes)}function ae(e,t){t=""+t,e.wholeText!==t&&(e.data=t)}function hb(e,t){e.value=t??""}function fo(e,t){for(let n=0;n<e.options.length;n+=1){let r=e.options[n];if(r.__value===t){r.selected=!0;return}}e.selectedIndex=-1}function w1(e){let t=e.querySelector(":checked")||e.options[0];return t&&t.__value}function ie(e,t,n){e.classList[n?"add":"remove"](t)}function O1(e,t,{bubbles:n=!1,cancelable:r=!1}={}){let i=document.createEvent("CustomEvent");return i.initCustomEvent(e,n,r,t),i}var po=new Map,ho=0;function BC(e){let t=5381,n=e.length;for(;n--;)t=(t<<5)-t^e.charCodeAt(n);return t>>>0}function LC(e,t){let n={stylesheet:qC(t),rules:{}};return po.set(e,n),n}function mo(e,t,n,r,i,s,o,a=0){let u=16.666/r,c=`{
|
|
@@ -29,7 +29,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
29
29
|
<th class="svelte-ztcwsu">Action</th>`,r=q(),i=A("tbody");for(let c=0;c<a.length;c+=1)a[c].c();k(t,"class","svelte-ztcwsu")},m(c,l){M(c,t,l),w(t,n),w(t,r),w(t,i);for(let f=0;f<a.length;f+=1)a[f].m(i,null);s=!0},p(c,[l]){if(l&15){o=c[1];let f;for(f=0;f<o.length;f+=1){let p=Wb(c,o,f);a[f]?(a[f].p(p,l),P(a[f],1)):(a[f]=Jb(p),a[f].c(),P(a[f],1),a[f].m(i,null))}for(ce(),f=o.length;f<a.length;f+=1)u(f);le()}},i(c){if(!s){for(let l=0;l<o.length;l+=1)P(a[l]);s=!0}},o(c){a=a.filter(Boolean);for(let l=0;l<a.length;l+=1)x(a[l]);s=!1},d(c){c&&S(t),$e(a,c)}}}function B3(e,t,n){let{root:r}=t,{selectedIndex:i=null}=t,s=Ji(),o=[],a=[];function u(h,d){s("select",{node:h,selectedIndex:d})}function c(h,d){i===null&&s("preview",{node:h})}let l=(h,d)=>u(h,d),f=h=>c(null),p=(h,d)=>c(h);return e.$$set=h=>{"root"in h&&n(4,r=h.root),"selectedIndex"in h&&n(0,i=h.selectedIndex)},e.$$.update=()=>{if(e.$$.dirty&48){let h=r;for(n(5,o=[]);h.parent;){let d=h.parent,{type:y,args:m}=h.parentAction.payload,b=(m||[]).join(","),g=`${y}(${b})`;o.push({parent:d,arrowText:g}),h=d}o.reverse(),n(1,a=[...r.children].sort((d,y)=>d.visits<y.visits?1:-1).slice(0,50))}},[i,a,u,c,r,o,l,f,p]}var Vi=class extends Z{constructor(t){super(),te(this,t,B3,R3,ee,{root:4,selectedIndex:0},D3)}};function L3(e){de(e,"svelte-1f0amz4",".visualizer.svelte-1f0amz4{display:flex;flex-direction:column;align-items:center;padding:50px}.preview.svelte-1f0amz4{opacity:0.5}.icon.svelte-1f0amz4{color:#777;width:32px;height:32px;margin-bottom:20px}")}function Yb(e,t,n){let r=e.slice();return r[9]=t[n].node,r[10]=t[n].selectedIndex,r[12]=n,r}function G3(e){let t,n,r;return n=new Oo({}),{c(){t=A("div"),L(n.$$.fragment),k(t,"class","icon svelte-1f0amz4")},m(i,s){M(i,t,s),R(n,t,null),r=!0},i(i){r||(P(n.$$.fragment,i),r=!0)},o(i){x(n.$$.fragment,i),r=!1},d(i){i&&S(t),B(n)}}}function F3(e){let t,n;function r(...i){return e[7](e[12],...i)}return t=new Vi({props:{root:e[9],selectedIndex:e[10]}}),t.$on("select",r),{c(){L(t.$$.fragment)},m(i,s){R(t,i,s),n=!0},p(i,s){e=i;let o={};s&1&&(o.root=e[9]),s&1&&(o.selectedIndex=e[10]),t.$set(o)},i(i){n||(P(t.$$.fragment,i),n=!0)},o(i){x(t.$$.fragment,i),n=!1},d(i){B(t,i)}}}function U3(e){let t,n;function r(...s){return e[5](e[12],...s)}function i(...s){return e[6](e[12],...s)}return t=new Vi({props:{root:e[9]}}),t.$on("select",r),t.$on("preview",i),{c(){L(t.$$.fragment)},m(s,o){R(t,s,o),n=!0},p(s,o){e=s;let a={};o&1&&(a.root=e[9]),t.$set(a)},i(s){n||(P(t.$$.fragment,s),n=!0)},o(s){x(t.$$.fragment,s),n=!1},d(s){B(t,s)}}}function $b(e){let t,n,r,i,s,o=e[12]!==0&&G3(),a=[U3,F3],u=[];function c(l,f){return l[12]===l[0].length-1?0:1}return r=c(e),i=u[r]=a[r](e),{c(){o&&o.c(),t=q(),n=A("section"),i.c()},m(l,f){o&&o.m(l,f),M(l,t,f),M(l,n,f),u[r].m(n,null),s=!0},p(l,f){let p=r;r=c(l),r===p?u[r].p(l,f):(ce(),x(u[p],1,1,()=>{u[p]=null}),le(),i=u[r],i?i.p(l,f):(i=u[r]=a[r](l),i.c()),P(i,1),i.m(n,null))},i(l){s||(P(o),P(i),s=!0)},o(l){x(o),x(i),s=!1},d(l){o&&o.d(l),l&&S(t),l&&S(n),u[r].d()}}}function Xb(e){let t,n,r,i,s,o;return n=new Oo({}),s=new Vi({props:{root:e[1]}}),{c(){t=A("div"),L(n.$$.fragment),r=q(),i=A("section"),L(s.$$.fragment),k(t,"class","icon svelte-1f0amz4"),k(i,"class","preview svelte-1f0amz4")},m(a,u){M(a,t,u),R(n,t,null),M(a,r,u),M(a,i,u),R(s,i,null),o=!0},p(a,u){let c={};u&2&&(c.root=a[1]),s.$set(c)},i(a){o||(P(n.$$.fragment,a),P(s.$$.fragment,a),o=!0)},o(a){x(n.$$.fragment,a),x(s.$$.fragment,a),o=!1},d(a){a&&S(t),B(n),a&&S(r),a&&S(i),B(s)}}}function V3(e){let t,n,r,i=e[0],s=[];for(let u=0;u<i.length;u+=1)s[u]=$b(Yb(e,i,u));let o=u=>x(s[u],1,1,()=>{s[u]=null}),a=e[1]&&Xb(e);return{c(){t=A("div");for(let u=0;u<s.length;u+=1)s[u].c();n=q(),a&&a.c(),k(t,"class","visualizer svelte-1f0amz4")},m(u,c){M(u,t,c);for(let l=0;l<s.length;l+=1)s[l].m(t,null);w(t,n),a&&a.m(t,null),r=!0},p(u,[c]){if(c&13){i=u[0];let l;for(l=0;l<i.length;l+=1){let f=Yb(u,i,l);s[l]?(s[l].p(f,c),P(s[l],1)):(s[l]=$b(f),s[l].c(),P(s[l],1),s[l].m(t,n))}for(ce(),l=i.length;l<s.length;l+=1)o(l);le()}u[1]?a?(a.p(u,c),c&2&&P(a,1)):(a=Xb(u),a.c(),P(a,1),a.m(t,null)):a&&(ce(),x(a,1,1,()=>{a=null}),le())},i(u){if(!r){for(let c=0;c<i.length;c+=1)P(s[c]);P(a),r=!0}},o(u){s=s.filter(Boolean);for(let c=0;c<s.length;c+=1)x(s[c]);x(a),r=!1},d(u){u&&S(t),$e(s,u),a&&a.d()}}}function z3(e,t,n){let{metadata:r}=t,i=[],s=null;function o({node:f,selectedIndex:p},h){n(1,s=null),n(0,i[h].selectedIndex=p,i),n(0,i=[...i.slice(0,h+1),{node:f}])}function a({node:f},p){n(1,s=f)}let u=(f,p)=>o(p.detail,f),c=(f,p)=>a(p.detail),l=(f,p)=>o(p.detail,f);return e.$$set=f=>{"metadata"in f&&n(4,r=f.metadata)},e.$$.update=()=>{e.$$.dirty&16&&n(0,i=[{node:r}])},[i,s,o,a,r,u,c,l]}var zi=class extends Z{constructor(t){super(),te(this,t,z3,V3,ee,{metadata:4},L3)}};function K3(e){de(e,"svelte-1pq5e4b",".gamelog.svelte-1pq5e4b{display:grid;grid-template-columns:30px 1fr 30px;grid-auto-rows:auto;grid-auto-flow:column}")}function Qb(e,t,n){let r=e.slice();return r[16]=t[n].phase,r[18]=n,r}function Zb(e,t,n){let r=e.slice();return r[19]=t[n].action,r[20]=t[n].metadata,r[18]=n,r}function e1(e,t,n){let r=e.slice();return r[22]=t[n].turn,r[18]=n,r}function t1(e){let t,n;return t=new _c({props:{turn:e[22],numEvents:e[3][e[18]]}}),{c(){L(t.$$.fragment)},m(r,i){R(t,r,i),n=!0},p(r,i){let s={};i&2&&(s.turn=r[22]),i&8&&(s.numEvents=r[3][r[18]]),t.$set(s)},i(r){n||(P(t.$$.fragment,r),n=!0)},o(r){x(t.$$.fragment,r),n=!1},d(r){B(t,r)}}}function n1(e){let t,n,r=e[18]in e[3]&&t1(e);return{c(){r&&r.c(),t=at()},m(i,s){r&&r.m(i,s),M(i,t,s),n=!0},p(i,s){i[18]in i[3]?r?(r.p(i,s),s&8&&P(r,1)):(r=t1(i),r.c(),P(r,1),r.m(t.parentNode,t)):r&&(ce(),x(r,1,1,()=>{r=null}),le())},i(i){n||(P(r),n=!0)},o(i){x(r),n=!1},d(i){r&&r.d(i),i&&S(t)}}}function r1(e){let t,n;return t=new Pc({props:{pinned:e[18]===e[2],logIndex:e[18],action:e[19],metadata:e[20]}}),t.$on("click",e[5]),t.$on("mouseenter",e[6]),t.$on("mouseleave",e[7]),{c(){L(t.$$.fragment)},m(r,i){R(t,r,i),n=!0},p(r,i){let s={};i&4&&(s.pinned=r[18]===r[2]),i&2&&(s.action=r[19]),i&2&&(s.metadata=r[20]),t.$set(s)},i(r){n||(P(t.$$.fragment,r),n=!0)},o(r){x(t.$$.fragment,r),n=!1},d(r){B(t,r)}}}function i1(e){let t,n;return t=new wc({props:{phase:e[16],numEvents:e[4][e[18]]}}),{c(){L(t.$$.fragment)},m(r,i){R(t,r,i),n=!0},p(r,i){let s={};i&2&&(s.phase=r[16]),i&16&&(s.numEvents=r[4][r[18]]),t.$set(s)},i(r){n||(P(t.$$.fragment,r),n=!0)},o(r){x(t.$$.fragment,r),n=!1},d(r){B(t,r)}}}function s1(e){let t,n,r=e[18]in e[4]&&i1(e);return{c(){r&&r.c(),t=at()},m(i,s){r&&r.m(i,s),M(i,t,s),n=!0},p(i,s){i[18]in i[4]?r?(r.p(i,s),s&16&&P(r,1)):(r=i1(i),r.c(),P(r,1),r.m(t.parentNode,t)):r&&(ce(),x(r,1,1,()=>{r=null}),le())},i(i){n||(P(r),n=!0)},o(i){x(r),n=!1},d(i){r&&r.d(i),i&&S(t)}}}function H3(e){let t,n,r,i,s,o,a=e[1],u=[];for(let m=0;m<a.length;m+=1)u[m]=n1(e1(e,a,m));let c=m=>x(u[m],1,1,()=>{u[m]=null}),l=e[1],f=[];for(let m=0;m<l.length;m+=1)f[m]=r1(Zb(e,l,m));let p=m=>x(f[m],1,1,()=>{f[m]=null}),h=e[1],d=[];for(let m=0;m<h.length;m+=1)d[m]=s1(Qb(e,h,m));let y=m=>x(d[m],1,1,()=>{d[m]=null});return{c(){t=A("div");for(let m=0;m<u.length;m+=1)u[m].c();n=q();for(let m=0;m<f.length;m+=1)f[m].c();r=q();for(let m=0;m<d.length;m+=1)d[m].c();k(t,"class","gamelog svelte-1pq5e4b"),ie(t,"pinned",e[2])},m(m,b){M(m,t,b);for(let g=0;g<u.length;g+=1)u[g].m(t,null);w(t,n);for(let g=0;g<f.length;g+=1)f[g].m(t,null);w(t,r);for(let g=0;g<d.length;g+=1)d[g].m(t,null);i=!0,s||(o=Q(window,"keydown",e[8]),s=!0)},p(m,[b]){if(b&10){a=m[1];let g;for(g=0;g<a.length;g+=1){let O=e1(m,a,g);u[g]?(u[g].p(O,b),P(u[g],1)):(u[g]=n1(O),u[g].c(),P(u[g],1),u[g].m(t,n))}for(ce(),g=a.length;g<u.length;g+=1)c(g);le()}if(b&230){l=m[1];let g;for(g=0;g<l.length;g+=1){let O=Zb(m,l,g);f[g]?(f[g].p(O,b),P(f[g],1)):(f[g]=r1(O),f[g].c(),P(f[g],1),f[g].m(t,r))}for(ce(),g=l.length;g<f.length;g+=1)p(g);le()}if(b&18){h=m[1];let g;for(g=0;g<h.length;g+=1){let O=Qb(m,h,g);d[g]?(d[g].p(O,b),P(d[g],1)):(d[g]=s1(O),d[g].c(),P(d[g],1),d[g].m(t,null))}for(ce(),g=h.length;g<d.length;g+=1)y(g);le()}b&4&&ie(t,"pinned",m[2])},i(m){if(!i){for(let b=0;b<a.length;b+=1)P(u[b]);for(let b=0;b<l.length;b+=1)P(f[b]);for(let b=0;b<h.length;b+=1)P(d[b]);i=!0}},o(m){u=u.filter(Boolean);for(let b=0;b<u.length;b+=1)x(u[b]);f=f.filter(Boolean);for(let b=0;b<f.length;b+=1)x(f[b]);d=d.filter(Boolean);for(let b=0;b<d.length;b+=1)x(d[b]);i=!1},d(m){m&&S(t),$e(u,m),$e(f,m),$e(d,m),s=!1,o()}}}function W3(e,t,n){let r,i=U,s=()=>(i(),i=Hi(o,j=>n(10,r=j)),o);e.$$.on_destroy.push(()=>i());let{client:o}=t;s();let{secondaryPane:a}=wn("secondaryPane"),u=Xn({game:o.game}),c=o.getInitialState(),{log:l}=r,f=null;function p(j){let N=c;for(let D=0;D<l.length;D++){let{action:J,automatic:fe}=l[D];if(!fe){if(N=u(N,J),j==0)break;j--}}return{G:N.G,ctx:N.ctx,plugins:N.plugins}}function h(j){let{logIndex:N}=j.detail,D=p(N),J=l.filter(fe=>!fe.automatic);if(o.overrideGameState(D),f==N)n(2,f=null),a.set(null);else{n(2,f=N);let{metadata:fe}=J[N].action.payload;fe&&a.set({component:zi,metadata:fe})}}function d(j){let{logIndex:N}=j.detail;if(f===null){let D=p(N);o.overrideGameState(D)}}function y(){f===null&&o.overrideGameState(null)}function m(){n(2,f=null),o.overrideGameState(null),a.set(null)}Cc(m);function b(j){j.keyCode==27&&m()}let g,O={},I={};return e.$$set=j=>{"client"in j&&s(n(0,o=j.client))},e.$$.update=()=>{if(e.$$.dirty&1538){n(9,l=r.log),n(1,g=l.filter(D=>!D.automatic));let j=0,N=0;n(3,O={}),n(4,I={});for(let D=0;D<g.length;D++){let{action:J,payload:fe,turn:V,phase:se}=g[D];N++,j++,(D==g.length-1||g[D+1].turn!=V)&&(n(3,O[D]=N,O),N=0),(D==g.length-1||g[D+1].phase!=se)&&(n(4,I[D]=j,I),j=0)}}},[o,g,f,O,I,h,d,y,b,l,r]}var kc=class extends Z{constructor(t){super(),te(this,t,W3,H3,ee,{client:0},K3)}};function J3(e){de(e,"svelte-1fu900w","label.svelte-1fu900w{color:#666}.option.svelte-1fu900w{margin-bottom:20px}.value.svelte-1fu900w{font-weight:bold;color:#000}input[type='checkbox'].svelte-1fu900w{vertical-align:middle}")}function o1(e,t,n){let r=e.slice();return r[6]=t[n][0],r[7]=t[n][1],r[8]=t,r[9]=n,r}function Y3(e){let t,n,r,i;function s(){e[5].call(t,e[6])}return{c(){t=A("input"),k(t,"id",n=e[3](e[6])),k(t,"type","checkbox"),k(t,"class","svelte-1fu900w")},m(o,a){M(o,t,a),t.checked=e[1][e[6]],r||(i=[Q(t,"change",s),Q(t,"change",e[2])],r=!0)},p(o,a){e=o,a&1&&n!==(n=e[3](e[6]))&&k(t,"id",n),a&3&&(t.checked=e[1][e[6]])},d(o){o&&S(t),r=!1,Le(i)}}}function $3(e){let t,n=e[1][e[6]]+"",r,i,s,o,a,u,c,l;function f(){e[4].call(s,e[6])}return{c(){t=A("span"),r=Y(n),i=q(),s=A("input"),k(t,"class","value svelte-1fu900w"),k(s,"id",o=e[3](e[6])),k(s,"type","range"),k(s,"min",a=e[7].range.min),k(s,"max",u=e[7].range.max)},m(p,h){M(p,t,h),w(t,r),M(p,i,h),M(p,s,h),hb(s,e[1][e[6]]),c||(l=[Q(s,"change",f),Q(s,"input",f),Q(s,"change",e[2])],c=!0)},p(p,h){e=p,h&3&&n!==(n=e[1][e[6]]+"")&&ae(r,n),h&1&&o!==(o=e[3](e[6]))&&k(s,"id",o),h&1&&a!==(a=e[7].range.min)&&k(s,"min",a),h&1&&u!==(u=e[7].range.max)&&k(s,"max",u),h&3&&hb(s,e[1][e[6]])},d(p){p&&S(t),p&&S(i),p&&S(s),c=!1,Le(l)}}}function a1(e){let t,n,r=e[6]+"",i,s,o,a;function u(f,p){if(f[7].range)return $3;if(typeof f[7].value=="boolean")return Y3}let c=u(e),l=c&&c(e);return{c(){t=A("div"),n=A("label"),i=Y(r),o=q(),l&&l.c(),a=q(),k(n,"for",s=e[3](e[6])),k(n,"class","svelte-1fu900w"),k(t,"class","option svelte-1fu900w")},m(f,p){M(f,t,p),w(t,n),w(n,i),w(t,o),l&&l.m(t,null),w(t,a)},p(f,p){p&1&&r!==(r=f[6]+"")&&ae(i,r),p&1&&s!==(s=f[3](f[6]))&&k(n,"for",s),c===(c=u(f))&&l?l.p(f,p):(l&&l.d(1),l=c&&c(f),l&&(l.c(),l.m(t,a)))},d(f){f&&S(t),l&&l.d()}}}function X3(e){let t,n=Object.entries(e[0].opts()),r=[];for(let i=0;i<n.length;i+=1)r[i]=a1(o1(e,n,i));return{c(){for(let i=0;i<r.length;i+=1)r[i].c();t=at()},m(i,s){for(let o=0;o<r.length;o+=1)r[o].m(i,s);M(i,t,s)},p(i,[s]){if(s&15){n=Object.entries(i[0].opts());let o;for(o=0;o<n.length;o+=1){let a=o1(i,n,o);r[o]?r[o].p(a,s):(r[o]=a1(a),r[o].c(),r[o].m(t.parentNode,t))}for(;o<r.length;o+=1)r[o].d(1);r.length=n.length}},i:U,o:U,d(i){$e(r,i),i&&S(t)}}}function Q3(e,t,n){let{bot:r}=t,i={};for(let[c,l]of Object.entries(r.opts()))i[c]=l.value;function s(){for(let[c,l]of Object.entries(i))r.setOpt(c,l)}let o=c=>"ai-option-"+c;function a(c){i[c]=DC(this.value),n(1,i)}function u(c){i[c]=this.checked,n(1,i)}return e.$$set=c=>{"bot"in c&&n(0,r=c.bot)},[r,i,s,o,a,u]}var Ac=class extends Z{constructor(t){super(),te(this,t,Q3,X3,ee,{bot:0},J3)}};function Z3(e){de(e,"svelte-fn09gm","ul.svelte-fn09gm{padding-left:0}li.svelte-fn09gm{list-style:none;margin:0;margin-bottom:5px}h3.svelte-fn09gm{text-transform:uppercase}label.svelte-fn09gm{color:#666}input[type='checkbox'].svelte-fn09gm{vertical-align:middle}")}function u1(e,t,n){let r=e.slice();return r[7]=t[n],r}function ej(e){let t,n,r;return{c(){t=A("p"),t.textContent="No bots available.",n=q(),r=A("p"),r.innerHTML=`Follow the instructions
|
|
30
30
|
<a href="https://boardgame.io/documentation/#/tutorial?id=bots" target="_blank">here</a>
|
|
31
31
|
to set up bots.`},m(i,s){M(i,t,s),M(i,n,s),M(i,r,s)},p:U,i:U,o:U,d(i){i&&S(t),i&&S(n),i&&S(r)}}}function tj(e){let t;return{c(){t=A("p"),t.textContent="The bot debugger is only available in singleplayer mode."},m(n,r){M(n,t,r)},p:U,i:U,o:U,d(n){n&&S(t)}}}function nj(e){let t,n,r,i,s,o,a,u,c,l,f,p,h,d,y,m,b,g,O=Object.keys(e[7].opts()).length,I,j,N,D,J;o=new vt({props:{value:"1",onPress:e[13],label:"reset"}}),c=new vt({props:{value:"2",onPress:e[11],label:"play"}}),p=new vt({props:{value:"3",onPress:e[12],label:"simulate"}});let fe=Object.keys(e[8]),V=[];for(let G=0;G<fe.length;G+=1)V[G]=c1(u1(e,fe,G));let se=O&&l1(e),ne=(e[5]||e[3])&&f1(e);return{c(){t=A("section"),n=A("h3"),n.textContent="Controls",r=q(),i=A("ul"),s=A("li"),L(o.$$.fragment),a=q(),u=A("li"),L(c.$$.fragment),l=q(),f=A("li"),L(p.$$.fragment),h=q(),d=A("section"),y=A("h3"),y.textContent="Bot",m=q(),b=A("select");for(let G=0;G<V.length;G+=1)V[G].c();g=q(),se&&se.c(),I=q(),ne&&ne.c(),j=at(),k(n,"class","svelte-fn09gm"),k(s,"class","svelte-fn09gm"),k(u,"class","svelte-fn09gm"),k(f,"class","svelte-fn09gm"),k(i,"class","svelte-fn09gm"),k(y,"class","svelte-fn09gm"),e[4]===void 0&&ot(()=>e[17].call(b))},m(G,Pe){M(G,t,Pe),w(t,n),w(t,r),w(t,i),w(i,s),R(o,s,null),w(i,a),w(i,u),R(c,u,null),w(i,l),w(i,f),R(p,f,null),M(G,h,Pe),M(G,d,Pe),w(d,y),w(d,m),w(d,b);for(let ue=0;ue<V.length;ue+=1)V[ue].m(b,null);fo(b,e[4]),M(G,g,Pe),se&&se.m(G,Pe),M(G,I,Pe),ne&&ne.m(G,Pe),M(G,j,Pe),N=!0,D||(J=[Q(b,"change",e[17]),Q(b,"change",e[10])],D=!0)},p(G,Pe){if(Pe&256){fe=Object.keys(G[8]);let ue;for(ue=0;ue<fe.length;ue+=1){let Lt=u1(G,fe,ue);V[ue]?V[ue].p(Lt,Pe):(V[ue]=c1(Lt),V[ue].c(),V[ue].m(b,null))}for(;ue<V.length;ue+=1)V[ue].d(1);V.length=fe.length}Pe&272&&fo(b,G[4]),Pe&128&&(O=Object.keys(G[7].opts()).length),O?se?(se.p(G,Pe),Pe&128&&P(se,1)):(se=l1(G),se.c(),P(se,1),se.m(I.parentNode,I)):se&&(ce(),x(se,1,1,()=>{se=null}),le()),G[5]||G[3]?ne?ne.p(G,Pe):(ne=f1(G),ne.c(),ne.m(j.parentNode,j)):ne&&(ne.d(1),ne=null)},i(G){N||(P(o.$$.fragment,G),P(c.$$.fragment,G),P(p.$$.fragment,G),P(se),N=!0)},o(G){x(o.$$.fragment,G),x(c.$$.fragment,G),x(p.$$.fragment,G),x(se),N=!1},d(G){G&&S(t),B(o),B(c),B(p),G&&S(h),G&&S(d),$e(V,G),G&&S(g),se&&se.d(G),G&&S(I),ne&&ne.d(G),G&&S(j),D=!1,Le(J)}}}function c1(e){let t,n=e[7]+"",r;return{c(){t=A("option"),r=Y(n),t.__value=e[7],t.value=t.__value},m(i,s){M(i,t,s),w(t,r)},p:U,d(i){i&&S(t)}}}function l1(e){let t,n,r,i,s,o,a,u,c,l,f;return u=new Ac({props:{bot:e[7]}}),{c(){t=A("section"),n=A("h3"),n.textContent="Options",r=q(),i=A("label"),i.textContent="debug",s=q(),o=A("input"),a=q(),L(u.$$.fragment),k(n,"class","svelte-fn09gm"),k(i,"for","ai-option-debug"),k(i,"class","svelte-fn09gm"),k(o,"id","ai-option-debug"),k(o,"type","checkbox"),k(o,"class","svelte-fn09gm")},m(p,h){M(p,t,h),w(t,n),w(t,r),w(t,i),w(t,s),w(t,o),o.checked=e[1],w(t,a),R(u,t,null),c=!0,l||(f=[Q(o,"change",e[18]),Q(o,"change",e[9])],l=!0)},p(p,h){h&2&&(o.checked=p[1]);let d={};h&128&&(d.bot=p[7]),u.$set(d)},i(p){c||(P(u.$$.fragment,p),c=!0)},o(p){x(u.$$.fragment,p),c=!1},d(p){p&&S(t),B(u),l=!1,Le(f)}}}function f1(e){let t,n,r,i,s=e[2]&&e[2]<1&&p1(e),o=e[5]&&h1(e);return{c(){t=A("section"),n=A("h3"),n.textContent="Result",r=q(),s&&s.c(),i=q(),o&&o.c(),k(n,"class","svelte-fn09gm")},m(a,u){M(a,t,u),w(t,n),w(t,r),s&&s.m(t,null),w(t,i),o&&o.m(t,null)},p(a,u){a[2]&&a[2]<1?s?s.p(a,u):(s=p1(a),s.c(),s.m(t,i)):s&&(s.d(1),s=null),a[5]?o?o.p(a,u):(o=h1(a),o.c(),o.m(t,null)):o&&(o.d(1),o=null)},d(a){a&&S(t),s&&s.d(),o&&o.d()}}}function p1(e){let t;return{c(){t=A("progress"),t.value=e[2]},m(n,r){M(n,t,r)},p(n,r){r&4&&(t.value=n[2])},d(n){n&&S(t)}}}function h1(e){let t,n,r,i,s,o,a,u=JSON.stringify(e[6])+"",c;return{c(){t=A("ul"),n=A("li"),r=Y("Action: "),i=Y(e[5]),s=q(),o=A("li"),a=Y("Args: "),c=Y(u),k(n,"class","svelte-fn09gm"),k(o,"class","svelte-fn09gm"),k(t,"class","svelte-fn09gm")},m(l,f){M(l,t,f),w(t,n),w(n,r),w(n,i),w(t,s),w(t,o),w(o,a),w(o,c)},p(l,f){f&32&&ae(i,l[5]),f&64&&u!==(u=JSON.stringify(l[6])+"")&&ae(c,u)},d(l){l&&S(t)}}}function rj(e){let t,n,r,i,s,o,a=[nj,tj,ej],u=[];function c(l,f){return l[0].game.ai&&!l[0].multiplayer?0:l[0].multiplayer?1:2}return n=c(e),r=u[n]=a[n](e),{c(){t=A("section"),r.c()},m(l,f){M(l,t,f),u[n].m(t,null),i=!0,s||(o=Q(window,"keydown",e[14]),s=!0)},p(l,[f]){let p=n;n=c(l),n===p?u[n].p(l,f):(ce(),x(u[p],1,1,()=>{u[p]=null}),le(),r=u[n],r?r.p(l,f):(r=u[n]=a[n](l),r.c()),P(r,1),r.m(t,null))},i(l){i||(P(r),i=!0)},o(l){x(r),i=!1},d(l){l&&S(t),u[n].d(),s=!1,o()}}}function ij(e,t,n){let{client:r}=t,{clientManager:i}=t,{ToggleVisibility:s}=t,{secondaryPane:o}=wn("secondaryPane"),a={MCTS:Di,Random:oo},u=!1,c=null,l=0,f=null,p=({iterationCounter:V,numIterations:se,metadata:ne})=>{n(3,l=V),n(2,c=V/se),f=ne,u&&f&&o.set({component:zi,metadata:f})};function h(){u&&f?o.set({component:zi,metadata:f}):o.set(null)}let d;r.game.ai&&(d=new Di({game:r.game,enumerate:r.game.ai.enumerate,iterationCallback:p}),d.setOpt("async",!0));let y,m,b;function g(){let V=a[y];n(7,d=new V({game:r.game,enumerate:r.game.ai.enumerate,iterationCallback:p})),d.setOpt("async",!0),n(5,m=null),f=null,o.set(null),n(3,l=0)}async function O(){n(5,m=null),f=null,n(3,l=0);let V=await nc(r,d);V&&(n(5,m=V.payload.type),n(6,b=V.payload.args))}function I(V=1e4,se=100){return n(5,m=null),f=null,n(3,l=0),(async()=>{for(let G=0;G<V&&await nc(r,d);G++)await new Promise(ue=>setTimeout(ue,se))})()}function j(){r.overrideGameState(null),o.set(null),n(1,u=!1)}function N(){r.reset(),n(5,m=null),f=null,n(3,l=0),j()}function D(V){V.keyCode==27&&j()}Cc(j);function J(){y=w1(this),n(4,y),n(8,a)}function fe(){u=this.checked,n(1,u)}return e.$$set=V=>{"client"in V&&n(0,r=V.client),"clientManager"in V&&n(15,i=V.clientManager),"ToggleVisibility"in V&&n(16,s=V.ToggleVisibility)},[r,u,c,l,y,m,b,d,a,h,g,O,I,N,D,i,s,J,fe]}var xc=class extends Z{constructor(t){super(),te(this,t,ij,rj,ee,{client:0,clientManager:15,ToggleVisibility:16},Z3)}};function sj(e){de(e,"svelte-8ymctk",`.debug-panel.svelte-8ymctk.svelte-8ymctk{position:fixed;color:#555;font-family:monospace;right:0;top:0;height:100%;font-size:14px;opacity:0.9;z-index:99999}.panel.svelte-8ymctk.svelte-8ymctk{display:flex;position:relative;flex-direction:row;height:100%}.visibility-toggle.svelte-8ymctk.svelte-8ymctk{position:absolute;box-sizing:border-box;top:7px;border:1px solid #ccc;border-radius:5px;width:48px;height:48px;padding:8px;background:white;color:#555;box-shadow:0 0 5px rgba(0, 0, 0, 0.2)}.visibility-toggle.svelte-8ymctk.svelte-8ymctk:hover,.visibility-toggle.svelte-8ymctk.svelte-8ymctk:focus{background:#eee}.opener.svelte-8ymctk.svelte-8ymctk{right:10px}.closer.svelte-8ymctk.svelte-8ymctk{left:-326px}@keyframes svelte-8ymctk-rotateFromZero{from{transform:rotateZ(0deg)}to{transform:rotateZ(180deg)}}.icon.svelte-8ymctk.svelte-8ymctk{display:flex;height:100%;animation:svelte-8ymctk-rotateFromZero 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55) 0s 1
|
|
32
|
-
normal forwards}.closer.svelte-8ymctk .icon.svelte-8ymctk{animation-direction:reverse}.pane.svelte-8ymctk.svelte-8ymctk{flex-grow:2;overflow-x:hidden;overflow-y:scroll;background:#fefefe;padding:20px;border-left:1px solid #ccc;box-shadow:-1px 0 5px rgba(0, 0, 0, 0.2);box-sizing:border-box;width:280px}.secondary-pane.svelte-8ymctk.svelte-8ymctk{background:#fefefe;overflow-y:scroll}.debug-panel.svelte-8ymctk button,.debug-panel.svelte-8ymctk select{cursor:pointer;font-size:14px;font-family:monospace}.debug-panel.svelte-8ymctk select{background:#eee;border:1px solid #bbb;color:#555;padding:3px;border-radius:3px}.debug-panel.svelte-8ymctk section{margin-bottom:20px}.debug-panel.svelte-8ymctk .screen-reader-only{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}`)}function oj(e){let t,n,r,i,s,o,a,u,c,l=e[10]&&uj(e);r=new sc({props:{panes:e[6],pane:e[2]}}),r.$on("change",e[8]);var f=e[6][e[2]].component;function p(d){return{props:{client:d[4],clientManager:d[0],ToggleVisibility:d[9]}}}f&&(o=new f(p(e)));let h=e[5]&&d1(e);return{c(){t=A("div"),l&&l.c(),n=q(),L(r.$$.fragment),i=q(),s=A("div"),o&&L(o.$$.fragment),a=q(),h&&h.c(),k(s,"class","pane svelte-8ymctk"),k(s,"role","region"),k(s,"aria-label",e[2]),k(s,"tabindex","-1"),k(t,"class","panel svelte-8ymctk")},m(d,y){M(d,t,y),l&&l.m(t,null),w(t,n),R(r,t,null),w(t,i),w(t,s),o&&R(o,s,null),e[16](s),w(t,a),h&&h.m(t,null),c=!0},p(d,y){e=d,e[10]&&l.p(e,y);let m={};y&4&&(m.pane=e[2]),r.$set(m);let b={};if(y&16&&(b.client=e[4]),y&1&&(b.clientManager=e[0]),f!==(f=e[6][e[2]].component)){if(o){ce();let g=o;x(g.$$.fragment,1,0,()=>{B(g,1)}),le()}f?(o=new f(p(e)),L(o.$$.fragment),P(o.$$.fragment,1),R(o,s,null)):o=null}else f&&o.$set(b);(!c||y&4)&&k(s,"aria-label",e[2]),e[5]?h?(h.p(e,y),y&32&&P(h,1)):(h=d1(e),h.c(),P(h,1),h.m(t,null)):h&&(ce(),x(h,1,1,()=>{h=null}),le())},i(d){c||(P(l),P(r.$$.fragment,d),o&&P(o.$$.fragment,d),P(h),ot(()=>{u||(u=mb(t,yb,{x:400,...e[12]},!0)),u.run(1)}),c=!0)},o(d){x(l),x(r.$$.fragment,d),o&&x(o.$$.fragment,d),x(h),u||(u=mb(t,yb,{x:400,...e[12]},!1)),u.run(0),c=!1},d(d){d&&S(t),l&&l.d(),B(r),o&&B(o),e[16](null),h&&h.d(),d&&u&&u.end()}}}function aj(e){let t,n,r=e[10]&&cj(e);return{c(){r&&r.c(),t=at()},m(i,s){r&&r.m(i,s),M(i,t,s),n=!0},p(i,s){i[10]&&r.p(i,s)},i(i){n||(P(r),n=!0)},o(i){x(r),n=!1},d(i){r&&r.d(i),i&&S(t)}}}function uj(e){let t,n,r,i,s,o,a,u;return r=new bo({}),{c(){t=A("button"),n=A("span"),L(r.$$.fragment),k(n,"class","icon svelte-8ymctk"),k(n,"aria-hidden","true"),k(t,"class","visibility-toggle closer svelte-8ymctk"),k(t,"title","Hide Debug Panel")},m(c,l){M(c,t,l),w(t,n),R(r,n,null),o=!0,a||(u=Q(t,"click",e[9]),a=!0)},p:U,i(c){o||(P(r.$$.fragment,c),ot(()=>{s&&s.end(1),i=k1(t,e[14],{key:"toggle"}),i.start()}),o=!0)},o(c){x(r.$$.fragment,c),i&&i.invalidate(),s=A1(t,e[13],{key:"toggle"}),o=!1},d(c){c&&S(t),B(r),c&&s&&s.end(),a=!1,u()}}}function d1(e){let t,n,r;var i=e[5].component;function s(o){return{props:{metadata:o[5].metadata}}}return i&&(n=new i(s(e))),{c(){t=A("div"),n&&L(n.$$.fragment),k(t,"class","secondary-pane svelte-8ymctk")},m(o,a){M(o,t,a),n&&R(n,t,null),r=!0},p(o,a){let u={};if(a&32&&(u.metadata=o[5].metadata),i!==(i=o[5].component)){if(n){ce();let c=n;x(c.$$.fragment,1,0,()=>{B(c,1)}),le()}i?(n=new i(s(o)),L(n.$$.fragment),P(n.$$.fragment,1),R(n,t,null)):n=null}else i&&n.$set(u)},i(o){r||(n&&P(n.$$.fragment,o),r=!0)},o(o){n&&x(n.$$.fragment,o),r=!1},d(o){o&&S(t),n&&B(n)}}}function cj(e){let t,n,r,i,s,o,a,u;return r=new bo({}),{c(){t=A("button"),n=A("span"),L(r.$$.fragment),k(n,"class","icon svelte-8ymctk"),k(n,"aria-hidden","true"),k(t,"class","visibility-toggle opener svelte-8ymctk"),k(t,"title","Show Debug Panel")},m(c,l){M(c,t,l),w(t,n),R(r,n,null),o=!0,a||(u=Q(t,"click",e[9]),a=!0)},p:U,i(c){o||(P(r.$$.fragment,c),ot(()=>{s&&s.end(1),i=k1(t,e[14],{key:"toggle"}),i.start()}),o=!0)},o(c){x(r.$$.fragment,c),i&&i.invalidate(),s=A1(t,e[13],{key:"toggle"}),o=!1},d(c){c&&S(t),B(r),c&&s&&s.end(),a=!1,u()}}}function lj(e){let t,n,r,i,s,o,a=[aj,oj],u=[];function c(l,f){return l[3]?1:0}return n=c(e),r=u[n]=a[n](e),{c(){t=A("section"),r.c(),k(t,"aria-label","boardgame.io Debug Panel"),k(t,"class","debug-panel svelte-8ymctk")},m(l,f){M(l,t,f),u[n].m(t,null),i=!0,s||(o=Q(window,"keypress",e[11]),s=!0)},p(l,[f]){let p=n;n=c(l),n===p?u[n].p(l,f):(ce(),x(u[p],1,1,()=>{u[p]=null}),le(),r=u[n],r?r.p(l,f):(r=u[n]=a[n](l),r.c()),P(r,1),r.m(t,null))},i(l){i||(P(r),i=!0)},o(l){x(r),i=!1},d(l){l&&S(t),u[n].d(),s=!1,o()}}}function fj(e,t,n){let r,i,s=U,o=()=>(s(),s=Hi(u,J=>n(15,i=J)),u),a;e.$$.on_destroy.push(()=>s());let{clientManager:u}=t;o();let c={main:{label:"Main",shortcut:"m",component:vc},log:{label:"Log",shortcut:"l",component:kc},info:{label:"Info",shortcut:"i",component:bc},ai:{label:"AI",shortcut:"a",component:xc}},l=gb(!1),f=gb(null);g1(e,f,J=>n(5,a=J)),Fi("hotkeys",{disableHotkeys:l}),Fi("secondaryPane",{secondaryPane:f});let p,h="main";function d(J){n(2,h=J.detail),p.focus()}function y(){n(3,b=!b)}let m=i.client.debugOpt,b=!m||!m.collapseOnLoad,g=!m||!m.hideToggleButton;function O(J){if(J.key=="."){y();return}b&&Object.entries(c).forEach(([fe,{shortcut:V}])=>{J.key==V&&n(2,h=fe)})}let I={duration:150,easing:Dc},[j,N]=WC(I);function D(J){yo[J?"unshift":"push"](()=>{p=J,n(1,p)})}return e.$$set=J=>{"clientManager"in J&&o(n(0,u=J.clientManager))},e.$$.update=()=>{e.$$.dirty&32768&&n(4,r=i.client)},[u,p,h,b,r,a,c,f,d,y,g,O,I,j,N,i,D]}var Ki=class extends Z{constructor(t){super(),te(this,t,fj,lj,ee,{clientManager:0},sj)}};function On(e){"@babel/helpers - typeof";return On=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},On(e)}function M1(e,t){if(On(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(On(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function I1(e){var t=M1(e,"string");return On(t)=="symbol"?t:t+""}function N1(e,t,n){return(t=I1(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function Rc(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?C1(Object(n),!0).forEach(function(r){N1(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C1(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Xe(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}var q1=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}(),Bc=function(){return Math.random().toString(36).substring(7).split("").join(".")},j1={INIT:"@@redux/INIT"+Bc(),REPLACE:"@@redux/REPLACE"+Bc(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Bc()}};function pj(e){if(typeof e!="object"||e===null)return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Lc(e,t,n){var r;if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(Xe(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(Xe(1));return n(Lc)(e,t)}if(typeof e!="function")throw new Error(Xe(2));var i=e,s=t,o=[],a=o,u=!1;function c(){a===o&&(a=o.slice())}function l(){if(u)throw new Error(Xe(3));return s}function f(y){if(typeof y!="function")throw new Error(Xe(4));if(u)throw new Error(Xe(5));var m=!0;return c(),a.push(y),function(){if(m){if(u)throw new Error(Xe(6));m=!1,c();var g=a.indexOf(y);a.splice(g,1),o=null}}}function p(y){if(!pj(y))throw new Error(Xe(7));if(typeof y.type>"u")throw new Error(Xe(8));if(u)throw new Error(Xe(9));try{u=!0,s=i(s,y)}finally{u=!1}for(var m=o=a,b=0;b<m.length;b++){var g=m[b];g()}return y}function h(y){if(typeof y!="function")throw new Error(Xe(10));i=y,p({type:j1.REPLACE})}function d(){var y,m=f;return y={subscribe:function(g){if(typeof g!="object"||g===null)throw new Error(Xe(11));function O(){g.next&&g.next(l())}O();var I=m(O);return{unsubscribe:I}}},y[q1]=function(){return this},y}return p({type:j1.INIT}),r={dispatch:p,subscribe:f,getState:l,replaceReducer:h},r[q1]=d,r}function Gc(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.length===0?function(r){return r}:t.length===1?t[0]:t.reduce(function(r,i){return function(){return r(i.apply(void 0,arguments))}})}function D1(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(r){return function(){var i=r.apply(void 0,arguments),s=function(){throw new Error(Xe(15))},o={getState:i.getState,dispatch:function(){return s.apply(void 0,arguments)}},a=t.map(function(u){return u(o)});return s=Gc.apply(void 0,a)(i.dispatch),Rc(Rc({},i),{},{dispatch:s})}}}function R1({game:e,numPlayers:t,setupData:n}){e=ji(e),t||(t=2);let r=e.flow.ctx(t),i={G:{},ctx:r,plugins:{}};i=Nv(i,{game:e}),i=Ti(i,{game:e,playerID:void 0});let s=Wt(i);i.G=e.setup({...s,ctx:i.ctx},n);let o={...i,_undo:[],_redo:[],_stateID:0};return o=e.flow.init(o),[o]=eo(o,{game:e}),e.disableUndo||(o._undo=[{G:o.G,ctx:o.ctx,plugins:o.plugins}]),o}var ir=class{constructor({transportDataCallback:t,gameName:n,playerID:r,matchID:i,credentials:s,numPlayers:o}){this.connectionStatusCallback=()=>{},this.isConnected=!1,this.transportDataCallback=t,this.gameName=n||"default",this.playerID=r||null,this.matchID=i||"default",this.credentials=s,this.numPlayers=o||2}subscribeToConnectionStatus(t){this.connectionStatusCallback=t}setConnectionStatus(t){this.isConnected=t,this.connectionStatusCallback()}notifyClient(t){this.transportDataCallback(t)}};var Fc=class extends ir{connect(){}disconnect(){}sendAction(){}sendChatMessage(){}requestSync(){}updateCredentials(){}updateMatchID(){}updatePlayerID(){}},hj=e=>new Fc(e),Uc=class{constructor(){this.debugPanel=null,this.currentClient=null,this.clients=new Map,this.subscribers=new Map}register(t){this.clients.set(t,t),this.mountDebug(t),this.notifySubscribers()}unregister(t){if(this.clients.delete(t),this.currentClient===t){this.unmountDebug();for(let[n]of this.clients){if(this.debugPanel)break;this.mountDebug(n)}}this.notifySubscribers()}subscribe(t){let n=Symbol();return this.subscribers.set(n,t),t(this.getState()),()=>{this.subscribers.delete(n)}}switchPlayerID(t){if(this.currentClient.multiplayer){for(let[n]of this.clients)if(n.playerID===t&&n.debugOpt!==!1&&n.multiplayer===this.currentClient.multiplayer){this.switchToClient(n);return}}this.currentClient.updatePlayerID(t),this.notifySubscribers()}switchToClient(t){t!==this.currentClient&&(this.unmountDebug(),this.mountDebug(t),this.notifySubscribers())}notifySubscribers(){let t=this.getState();this.subscribers.forEach(n=>{n(t)})}getState(){return{client:this.currentClient,debuggableClients:this.getDebuggableClients()}}getDebuggableClients(){return[...this.clients.values()].filter(t=>t.debugOpt!==!1)}mountDebug(t){if(t.debugOpt===!1||this.debugPanel!==null||typeof document>"u")return;let n,r=document.body;t.debugOpt&&t.debugOpt!==!0&&(n=t.debugOpt.impl||n,r=t.debugOpt.target||r),n&&(this.currentClient=t,this.debugPanel=new n({target:r,props:{clientManager:this}}))}unmountDebug(){this.debugPanel.$destroy(),this.debugPanel=null,this.currentClient=null}},dj=new Uc;function Vc(e,t,n){return!n&&e==null&&(e=t.getState().ctx.currentPlayer),e}function Kc(e,t,n,r,i,s){let o={};for(let a of t)o[a]=(...u)=>{let c=Mv[e](a,u,Vc(r,n,s),i);n.dispatch(c)};return o}var mj=Kc.bind(null,"makeMove"),gj=Kc.bind(null,"gameEvent"),yj=Kc.bind(null,"plugin"),zc=class{constructor({game:t,debug:n,numPlayers:r,multiplayer:i,matchID:s,playerID:o,credentials:a,enhancer:u}){this.game=ji(t),this.playerID=o,this.matchID=s||"default",this.credentials=a,this.multiplayer=i,this.debugOpt=n,this.manager=dj,this.gameStateOverride=null,this.subscribers={},this._running=!1,this.reducer=Xn({game:this.game,isClient:i!==void 0}),this.initialState=null,i||(this.initialState=R1({game:this.game,numPlayers:r})),this.reset=()=>{this.store.dispatch(Nu(this.initialState))},this.undo=()=>{let h=Cu(Vc(this.playerID,this.store,this.multiplayer),this.credentials);this.store.dispatch(h)},this.redo=()=>{let h=qu(Vc(this.playerID,this.store,this.multiplayer),this.credentials);this.store.dispatch(h)},this.log=[];let p=D1(cb,()=>h=>d=>{let y=h(d);return this.notifySubscribers(),y},h=>d=>y=>{let m=h.getState(),b=d(y);return!("clientOnly"in y)&&y.type!==$n&&this.transport.sendAction(m,y),b},h=>d=>y=>{let m=d(y),b=h.getState();switch(y.type){case _i:case Yn:case Ei:case wi:{let g=b.deltalog;this.log=[...this.log,...g];break}case Oi:{this.log=[];break}case Ai:case ki:{let g=-1;this.log.length>0&&(g=this.log[this.log.length-1]._stateID);let O=y.deltalog||[];O=O.filter(I=>I._stateID>g),this.log=[...this.log,...O];break}case Pi:{this.initialState=y.initialState,this.log=y.log||[];break}}return m});u=u!==void 0?Gc(p,u):p,this.store=Lc(this.reducer,this.initialState,u),i||(i=hj),this.transport=i({transportDataCallback:h=>this.receiveTransportData(h),gameKey:t,game:this.game,matchID:s,playerID:o,credentials:a,gameName:this.game.name,numPlayers:r}),this.createDispatchers(),this.chatMessages=[],this.sendChatMessage=h=>{this.transport.sendChatMessage(this.matchID,{id:mv(7),sender:this.playerID,payload:h})}}receiveMatchData(t){this.matchData=t,this.notifySubscribers()}receiveChatMessage(t){this.chatMessages=[...this.chatMessages,t],this.notifySubscribers()}receiveTransportData(t){let[n]=t.args;if(n===this.matchID)switch(t.type){case"sync":{let[,r]=t.args,i=xi(r);this.receiveMatchData(r.filteredMetadata),this.store.dispatch(i);break}case"update":{let[,r,i]=t.args,s=this.store.getState();if(r._stateID>=s._stateID){let o=Iu(r,i);this.store.dispatch(o)}break}case"patch":{let[,r,i,s,o]=t.args,a=this.store.getState()._stateID;if(r!==a)break;let u=Mu(r,i,s,o);this.store.dispatch(u),this.store.getState()._stateID===a&&this.transport.requestSync();break}case"matchData":{let[,r]=t.args;this.receiveMatchData(r);break}case"chat":{let[,r]=t.args;this.receiveChatMessage(r);break}}}notifySubscribers(){Object.values(this.subscribers).forEach(t=>t(this.getState()))}overrideGameState(t){this.gameStateOverride=t,this.notifySubscribers()}start(){this.transport.connect(),this._running=!0,this.manager.register(this)}stop(){this.transport.disconnect(),this._running=!1,this.manager.unregister(this)}subscribe(t){let n=Object.keys(this.subscribers).length;return this.subscribers[n]=t,this.transport.subscribeToConnectionStatus(()=>this.notifySubscribers()),(this._running||!this.multiplayer)&&t(this.getState()),()=>{delete this.subscribers[n]}}getInitialState(){return this.initialState}getState(){let t=this.store.getState();if(this.gameStateOverride!==null&&(t=this.gameStateOverride),t===null)return t;let n=!0,r=this.game.flow.isPlayerActive(t.G,t.ctx,this.playerID);return this.multiplayer&&!r&&(n=!1),!this.multiplayer&&this.playerID!==null&&this.playerID!==void 0&&!r&&(n=!1),t.ctx.gameover!==void 0&&(n=!1),this.multiplayer||(t={...t,G:this.game.playerView({G:t.G,ctx:t.ctx,playerID:this.playerID}),plugins:qv(t,this)}),{...t,log:this.log,isActive:n,isConnected:this.transport.isConnected}}createDispatchers(){this.moves=mj(this.game.moveNames,this.store,this.playerID,this.credentials,this.multiplayer),this.events=gj(this.game.flow.enabledEventNames,this.store,this.playerID,this.credentials,this.multiplayer),this.plugins=yj(this.game.pluginNames,this.store,this.playerID,this.credentials,this.multiplayer)}updatePlayerID(t){this.playerID=t,this.createDispatchers(),this.transport.updatePlayerID(t),this.notifySubscribers()}updateMatchID(t){this.matchID=t,this.createDispatchers(),this.transport.updateMatchID(t),this.notifySubscribers()}updateCredentials(t){this.credentials=t,this.createDispatchers(),this.transport.updateCredentials(t),this.notifySubscribers()}};function Hc(e){return new zc(e)}var DL=he(tn());var BL=he(qi());var LL=he(io());var UL=he(tn());var zL=he(qi());var KL=he(io());var ut=Object.create(null);ut.open="0";ut.close="1";ut.ping="2";ut.pong="3";ut.message="4";ut.upgrade="5";ut.noop="6";var Yi=Object.create(null);Object.keys(ut).forEach(e=>{Yi[ut[e]]=e});var $i={type:"error",data:"parser error"};var G1=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",F1=typeof ArrayBuffer=="function",U1=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,Xi=({type:e,data:t},n,r)=>G1&&t instanceof Blob?n?r(t):B1(t,r):F1&&(t instanceof ArrayBuffer||U1(t))?n?r(t):B1(new Blob([t]),r):r(ut[e]+(t||"")),B1=(e,t)=>{let n=new FileReader;return n.onload=function(){let r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function L1(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Wc;function V1(e,t){if(G1&&e.data instanceof Blob)return e.data.arrayBuffer().then(L1).then(t);if(F1&&(e.data instanceof ArrayBuffer||U1(e.data)))return t(L1(e.data));Xi(e,!1,n=>{Wc||(Wc=new TextEncoder),t(Wc.encode(n))})}var z1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Qi=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<z1.length;e++)Qi[z1.charCodeAt(e)]=e;var K1=e=>{let t=e.length*.75,n=e.length,r,i=0,s,o,a,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);let c=new ArrayBuffer(t),l=new Uint8Array(c);for(r=0;r<n;r+=4)s=Qi[e.charCodeAt(r)],o=Qi[e.charCodeAt(r+1)],a=Qi[e.charCodeAt(r+2)],u=Qi[e.charCodeAt(r+3)],l[i++]=s<<2|o>>4,l[i++]=(o&15)<<4|a>>2,l[i++]=(a&3)<<6|u&63;return c};var vj=typeof ArrayBuffer=="function",Zi=(e,t)=>{if(typeof e!="string")return{type:"message",data:H1(e,t)};let n=e.charAt(0);return n==="b"?{type:"message",data:bj(e.substring(1),t)}:Yi[n]?e.length>1?{type:Yi[n],data:e.substring(1)}:{type:Yi[n]}:$i},bj=(e,t)=>{if(vj){let n=K1(e);return H1(n,t)}else return{base64:!0,data:e}},H1=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}};var W1="",J1=(e,t)=>{let n=e.length,r=new Array(n),i=0;e.forEach((s,o)=>{Xi(s,!1,a=>{r[o]=a,++i===n&&t(r.join(W1))})})},Y1=(e,t)=>{let n=e.split(W1),r=[];for(let i=0;i<n.length;i++){let s=Zi(n[i],t);if(r.push(s),s.type==="error")break}return r};function $1(){return new TransformStream({transform(e,t){V1(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let s=new DataView(i.buffer);s.setUint8(0,126),s.setUint16(1,r)}else{i=new Uint8Array(9);let s=new DataView(i.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var Jc;function Eo(e){return e.reduce((t,n)=>t+n.length,0)}function ko(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function X1(e,t){Jc||(Jc=new TextDecoder);let n=[],r=0,i=-1,s=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(r===0){if(Eo(n)<1)break;let u=ko(n,1);s=(u[0]&128)===128,i=u[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(Eo(n)<2)break;let u=ko(n,2);i=new DataView(u.buffer,u.byteOffset,u.length).getUint16(0),r=3}else if(r===2){if(Eo(n)<8)break;let u=ko(n,8),c=new DataView(u.buffer,u.byteOffset,u.length),l=c.getUint32(0);if(l>Math.pow(2,21)-1){a.enqueue($i);break}i=l*Math.pow(2,32)+c.getUint32(4),r=3}else{if(Eo(n)<i)break;let u=ko(n,i);a.enqueue(Zi(s?u:Jc.decode(u),t)),r=0}if(i===0||i>e){a.enqueue($i);break}}}})}var Yc=4;function ye(e){if(e)return _j(e)}function _j(e){for(var t in ye.prototype)e[t]=ye.prototype[t];return e}ye.prototype.on=ye.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};ye.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};ye.prototype.off=ye.prototype.removeListener=ye.prototype.removeAllListeners=ye.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks["$"+e],this};ye.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this};ye.prototype.emitReserved=ye.prototype.emit;ye.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]};ye.prototype.hasListeners=function(e){return!!this.listeners(e).length};var Dt=typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0),Ue=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Q1="arraybuffer";function Ao(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}var wj=Ue.setTimeout,Oj=Ue.clearTimeout;function Rt(e,t){t.useNativeTimers?(e.setTimeoutFn=wj.bind(Ue),e.clearTimeoutFn=Oj.bind(Ue)):(e.setTimeoutFn=Ue.setTimeout.bind(Ue),e.clearTimeoutFn=Ue.clearTimeout.bind(Ue))}var Pj=1.33;function Z1(e){return typeof e=="string"?Ej(e):Math.ceil((e.byteLength||e.size)*Pj)}function Ej(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function xo(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function e_(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function t_(e){let t={},n=e.split("&");for(let r=0,i=n.length;r<i;r++){let s=n[r].split("=");t[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return t}var So=class extends Error{constructor(t,n,r){super(t),this.description=n,this.context=r,this.type="TransportError"}},Bt=class extends ye{constructor(t){super(),this.writable=!1,Rt(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,n,r){return super.emitReserved("error",new So(t,n,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(t){this.readyState==="open"&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){let n=Zi(t,this.socket.binaryType);this.onPacket(n)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,n={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(n)}_hostname(){let t=this.opts.hostname;return t.indexOf(":")===-1?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(t){let n=e_(t);return n.length?"?"+n:""}};var es=class extends Bt{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";let n=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){let n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};Y1(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,J1(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=xo()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}};var n_=!1;try{n_=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var r_=n_;function kj(){}var $c=class extends es{constructor(t){if(super(t),typeof location<"u"){let n=location.protocol==="https:",r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&t.hostname!==location.hostname||r!==t.port}}doWrite(t,n){let r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,s)=>{this.onError("xhr post error",i,s)})}doPoll(){let t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}},$t=class e extends ye{constructor(t,n,r){super(),this.createRequest=t,Rt(this,r),this._opts=r,this._method=r.method||"GET",this._uri=n,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var t;let n=Ao(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=kj,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};$t.requestsCount=0;$t.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",i_);else if(typeof addEventListener=="function"){let e="onpagehide"in Ue?"pagehide":"unload";addEventListener(e,i_,!1)}}function i_(){for(let e in $t.requests)$t.requests.hasOwnProperty(e)&&$t.requests[e].abort()}var Aj=function(){let e=s_({xdomain:!1});return e&&e.responseType!==null}(),Xt=class extends $c{constructor(t){super(t);let n=t&&t.forceBase64;this.supportsBinary=Aj&&!n}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new $t(s_,this.uri(),t)}};function s_(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||r_))return new XMLHttpRequest}catch{}if(!t)try{return new Ue[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var o_=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Qc=class extends Bt{get name(){return"websocket"}doOpen(){let t=this.uri(),n=this.opts.protocols,r=o_?{}:Ao(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n<t.length;n++){let r=t[n],i=n===t.length-1;Xi(r,this.supportsBinary,s=>{try{this.doWrite(r,s)}catch{}i&&Dt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=xo()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}},Xc=Ue.WebSocket||Ue.MozWebSocket,Qt=class extends Qc{createSocket(t,n,r){return o_?new Xc(t,n,r):n?new Xc(t,n):new Xc(t)}doWrite(t,n){this.ws.send(n)}};var sr=class extends Bt{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{let n=X1(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=$1();i.readable.pipeTo(t.writable),this._writer=i.writable.getWriter();let s=()=>{r.read().then(({done:a,value:u})=>{a||(this.onPacket(u),s())}).catch(a=>{})};s();let o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let n=0;n<t.length;n++){let r=t[n],i=n===t.length-1;this._writer.write(r).then(()=>{i&&Dt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this._transport)===null||t===void 0||t.close()}};var Zc={websocket:Qt,webtransport:sr,polling:Xt};var xj=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Sj=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function or(e){if(e.length>8e3)throw"URI too long";let t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=xj.exec(e||""),s={},o=14;for(;o--;)s[Sj[o]]=i[o]||"";return n!=-1&&r!=-1&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=Tj(s,s.path),s.queryKey=Mj(s,s.query),s}function Tj(e,t){let n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function Mj(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,s){i&&(n[i]=s)}),n}var el=typeof addEventListener=="function"&&typeof removeEventListener=="function",To=[];el&&addEventListener("offline",()=>{To.forEach(e=>e())},!1);var Pn=class e extends ye{constructor(t,n){if(super(),this.binaryType=Q1,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(n=t,t=null),t){let r=or(t);n.hostname=r.host,n.secure=r.protocol==="https"||r.protocol==="wss",n.port=r.port,r.query&&(n.query=r.query)}else n.host&&(n.hostname=or(n.host).host);Rt(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},n.transports.forEach(r=>{let i=r.prototype.name;this.transports.push(i),this._transportsByName[i]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=t_(this.opts.query)),el&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},To.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){let n=Object.assign({},this.opts.query);n.EIO=Yc,n.transport=t,this.id&&(n.sid=this.id);let r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let n=this.createTransport(t);n.open(),this.setTransport(n)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",n=>this._onClose("transport close",n))}onOpen(){this.readyState="open",e.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let n=new Error("server error");n.code=t.data,this._onError(n);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r<this.writeBuffer.length;r++){let i=this.writeBuffer[r].data;if(i&&(n+=Z1(i)),r>0&&n>this._maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Dt(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,n,r){return this._sendPacket("message",t,n,r),this}send(t,n,r){return this._sendPacket("message",t,n,r),this}_sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;let s={type:t,data:n,options:r};this.emitReserved("packetCreate",s),this.writeBuffer.push(s),i&&this.once("flush",i),this.flush()}close(){let t=()=>{this._onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),el&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let r=To.indexOf(this._offlineEventListener);r!==-1&&To.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this._prevBufferLen=0}}};Pn.protocol=Yc;var Mo=class extends Pn{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let n=this.createTransport(t),r=!1;Pn.priorWebsocketSuccess=!1;let i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;Pn.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(l(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{let p=new Error("probe error");p.transport=n.name,this.emitReserved("upgradeError",p)}}))};function s(){r||(r=!0,l(),n.close(),n=null)}let o=f=>{let p=new Error("probe error: "+f);p.transport=n.name,s(),this.emitReserved("upgradeError",p)};function a(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&s()}let l=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",a),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",a),this.once("close",u),this.once("upgrading",c),this._upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){let n=[];for(let r=0;r<t.length;r++)~this.transports.indexOf(t[r])&&n.push(t[r]);return n}},ar=class extends Mo{constructor(t,n={}){let r=typeof t=="object"?t:n;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(i=>Zc[i]).filter(i=>!!i)),super(t,r)}};var QG=ar.protocol;function a_(e,t="",n){let r=e;n=n||typeof location<"u"&&location,e==null&&(e=n.protocol+"//"+n.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=n.protocol+e:e=n.host+e),/^(https?|wss?):\/\//.test(e)||(typeof n<"u"?e=n.protocol+"//"+e:e="https://"+e),r=or(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";let s=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+s+":"+r.port+t,r.href=r.protocol+"://"+s+(n&&n.port===r.port?"":":"+r.port),r}var ol={};ll(ol,{Decoder:()=>il,Encoder:()=>rl,PacketType:()=>X,isPacketValid:()=>Gj,protocol:()=>p_});var Nj=typeof ArrayBuffer=="function",Cj=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,u_=Object.prototype.toString,qj=typeof Blob=="function"||typeof Blob<"u"&&u_.call(Blob)==="[object BlobConstructor]",jj=typeof File=="function"||typeof File<"u"&&u_.call(File)==="[object FileConstructor]";function ns(e){return Nj&&(e instanceof ArrayBuffer||Cj(e))||qj&&e instanceof Blob||jj&&e instanceof File}function ts(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n<r;n++)if(ts(e[n]))return!0;return!1}if(ns(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return ts(e.toJSON(),!0);for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&ts(e[n]))return!0;return!1}function c_(e){let t=[],n=e.data,r=e;return r.data=tl(n,t),r.attachments=t.length,{packet:r,buffers:t}}function tl(e,t){if(!e)return e;if(ns(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}else if(Array.isArray(e)){let n=new Array(e.length);for(let r=0;r<e.length;r++)n[r]=tl(e[r],t);return n}else if(typeof e=="object"&&!(e instanceof Date)){let n={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=tl(e[r],t));return n}return e}function l_(e,t){return e.data=nl(e.data,t),delete e.attachments,e}function nl(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=nl(e[n],t);else if(typeof e=="object")for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=nl(e[n],t));return e}var f_=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],p_=5,X;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(X||(X={}));var rl=class{constructor(t){this.replacer=t}encode(t){return(t.type===X.EVENT||t.type===X.ACK)&&ts(t)?this.encodeAsBinary({type:t.type===X.EVENT?X.BINARY_EVENT:X.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id}):[this.encodeAsString(t)]}encodeAsString(t){let n=""+t.type;return(t.type===X.BINARY_EVENT||t.type===X.BINARY_ACK)&&(n+=t.attachments+"-"),t.nsp&&t.nsp!=="/"&&(n+=t.nsp+","),t.id!=null&&(n+=t.id),t.data!=null&&(n+=JSON.stringify(t.data,this.replacer)),n}encodeAsBinary(t){let n=c_(t),r=this.encodeAsString(n.packet),i=n.buffers;return i.unshift(r),i}},il=class e extends ye{constructor(t){super(),this.reviver=t}add(t){let n;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");n=this.decodeString(t);let r=n.type===X.BINARY_EVENT;r||n.type===X.BINARY_ACK?(n.type=r?X.EVENT:X.ACK,this.reconstructor=new sl(n),n.attachments===0&&super.emitReserved("decoded",n)):super.emitReserved("decoded",n)}else if(ns(t)||t.base64)if(this.reconstructor)n=this.reconstructor.takeBinaryData(t),n&&(this.reconstructor=null,super.emitReserved("decoded",n));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(X[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===X.BINARY_EVENT||r.type===X.BINARY_ACK){let s=n+1;for(;t.charAt(++n)!=="-"&&n!=t.length;);let o=t.substring(s,n);if(o!=Number(o)||t.charAt(n)!=="-")throw new Error("Illegal attachments");r.attachments=Number(o)}if(t.charAt(n+1)==="/"){let s=n+1;for(;++n&&!(t.charAt(n)===","||n===t.length););r.nsp=t.substring(s,n)}else r.nsp="/";let i=t.charAt(n+1);if(i!==""&&Number(i)==i){let s=n+1;for(;++n;){let o=t.charAt(n);if(o==null||Number(o)!=o){--n;break}if(n===t.length)break}r.id=Number(t.substring(s,n+1))}if(t.charAt(++n)){let s=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,s))r.data=s;else throw new Error("invalid payload")}return r}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,n){switch(t){case X.CONNECT:return Io(n);case X.DISCONNECT:return n===void 0;case X.CONNECT_ERROR:return typeof n=="string"||Io(n);case X.EVENT:case X.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&f_.indexOf(n[0])===-1);case X.ACK:case X.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},sl=class{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){let n=l_(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function Dj(e){return typeof e=="string"}var Rj=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};function Bj(e){return e===void 0||Rj(e)}function Io(e){return Object.prototype.toString.call(e)==="[object Object]"}function Lj(e,t){switch(e){case X.CONNECT:return t===void 0||Io(t);case X.DISCONNECT:return t===void 0;case X.EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&f_.indexOf(t[0])===-1);case X.ACK:return Array.isArray(t);case X.CONNECT_ERROR:return typeof t=="string"||Io(t);default:return!1}}function Gj(e){return Dj(e.nsp)&&Bj(e.id)&&Lj(e.type,e.data)}function Qe(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Fj=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),ur=class extends ye{constructor(t,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let t=this.io;this.subs=[Qe(t,"open",this.onopen.bind(this)),Qe(t,"packet",this.onpacket.bind(this)),Qe(t,"error",this.onerror.bind(this)),Qe(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...n){var r,i,s;if(Fj.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(n.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;let o={type:X.EVENT,data:n};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){let l=this.ids++,f=n.pop();this._registerAckCallback(l,f),o.id=l}let a=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,u=this.connected&&!(!((s=this.io.engine)===null||s===void 0)&&s._hasPingExpired());return this.flags.volatile&&!a||(u?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(t,n){var r;let i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[t]=n;return}let s=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let a=0;a<this.sendBuffer.length;a++)this.sendBuffer[a].id===t&&this.sendBuffer.splice(a,1);n.call(this,new Error("operation has timed out"))},i),o=(...a)=>{this.io.clearTimeoutFn(s),n.apply(this,a)};o.withError=!0,this.acks[t]=o}emitWithAck(t,...n){return new Promise((r,i)=>{let s=(o,a)=>o?i(o):r(a);s.withError=!0,n.push(s),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());let r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...s)=>(this._queue[0],i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...s)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;let n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:X.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){let r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case X.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case X.EVENT:case X.BINARY_EVENT:this.onevent(t);break;case X.ACK:case X.BINARY_ACK:this.onack(t);break;case X.DISCONNECT:this.ondisconnect();break;case X.CONNECT_ERROR:this.destroy();let r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){let n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){let n=this._anyListeners.slice();for(let r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){let n=this,r=!1;return function(...i){r||(r=!0,n.packet({type:X.ACK,id:t,data:i}))}}onack(t){let n=this.acks[t.id];typeof n=="function"&&(delete this.acks[t.id],n.withError&&t.data.unshift(null),n.apply(this,t.data))}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:X.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){let n=this._anyListeners;for(let r=0;r<n.length;r++)if(t===n[r])return n.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){let n=this._anyOutgoingListeners;for(let r=0;r<n.length;r++)if(t===n[r])return n.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let n=this._anyOutgoingListeners.slice();for(let r of n)r.apply(this,t.data)}}};function En(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}En.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};En.prototype.reset=function(){this.attempts=0};En.prototype.setMin=function(e){this.ms=e};En.prototype.setMax=function(e){this.max=e};En.prototype.setJitter=function(e){this.jitter=e};var cr=class extends ye{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,Rt(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new En({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;let i=n.parser||ol;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new ar(this.uri,this.opts);let n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;let i=Qe(n,"open",function(){r.onopen(),t&&t()}),s=a=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",a),t?t(a):this.maybeReconnectOnOpen()},o=Qe(n,"error",s);if(this._timeout!==!1){let a=this._timeout,u=this.setTimeoutFn(()=>{i(),s(new Error("timeout")),n.close()},a);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let t=this.engine;this.subs.push(Qe(t,"ping",this.onping.bind(this)),Qe(t,"data",this.ondata.bind(this)),Qe(t,"error",this.onerror.bind(this)),Qe(t,"close",this.onclose.bind(this)),Qe(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){Dt(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new ur(this,t,n),this.nsps[t]=r),r}_destroy(t){let n=Object.keys(this.nsps);for(let r of n)if(this.nsps[r].active)return;this._close()}_packet(t){let n=this.encoder.encode(t);for(let r=0;r<n.length;r++)this.engine.write(n[r],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,n){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let n=this.backoff.duration();this._reconnecting=!0;let r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){let t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}};var rs={};function is(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};let n=a_(e,t.path||"/socket.io"),r=n.source,i=n.id,s=n.path,o=rs[i]&&s in rs[i].nsps,a=t.forceNew||t["force new connection"]||t.multiplex===!1||o,u;return a?u=new cr(r,t):(rs[i]||(rs[i]=new cr(r,t)),u=rs[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(is,{Manager:cr,Socket:ur,io:is,connect:is});var h_=is,al=class extends ir{constructor({socket:t,socketOpts:n,server:r,...i}){super(i),this.server=r,this.socket=t,this.socketOpts=n}sendAction(t,n){let r=[n,t._stateID,this.matchID,this.playerID];this.socket.emit("update",...r)}sendChatMessage(t,n){let r=[t,n,this.credentials];this.socket.emit("chat",...r)}connect(){if(!this.socket)if(this.server){let t=this.server;t.search(/^https?:\/\//)==-1&&(t="http://"+this.server),t.slice(-1)!="/"&&(t=t+"/"),this.socket=h_(t+this.gameName,this.socketOpts)}else this.socket=h_("/"+this.gameName,this.socketOpts);this.socket.on("patch",(t,n,r,i,s)=>{this.notifyClient({type:"patch",args:[t,n,r,i,s]})}),this.socket.on("update",(t,n,r)=>{this.notifyClient({type:"update",args:[t,n,r]})}),this.socket.on("sync",(t,n)=>{this.notifyClient({type:"sync",args:[t,n]})}),this.socket.on("matchData",(t,n)=>{this.notifyClient({type:"matchData",args:[t,n]})}),this.socket.on("chat",(t,n)=>{this.notifyClient({type:"chat",args:[t,n]})}),this.socket.on("connect",()=>{this.requestSync(),this.setConnectionStatus(!0)}),this.socket.on("disconnect",()=>{this.setConnectionStatus(!1)})}disconnect(){this.socket.close(),this.socket=null,this.setConnectionStatus(!1)}requestSync(){if(this.socket){let t=[this.matchID,this.playerID,this.credentials,this.numPlayers];this.socket.emit("sync",...t)}}updateMatchID(t){this.matchID=t,this.requestSync()}updatePlayerID(t){this.playerID=t,this.requestSync()}updateCredentials(t){this.credentials=t,this.requestSync()}};function ul({server:e,socketOpts:t}={}){return n=>new al({server:e,socketOpts:t,...n})}var G9=he(tn()),F9=he(qi());function No(e){if(e?.arguments){let t={...e};return t.arguments=Object.entries(t.arguments).reduce((n,[r,i])=>({...n,[r]:i.abstract?i:i.entityId}),{}),JSON.parse(He(t,{deduplicateInstances:!1}))}else return e}var Vj={PlaceNew:["destination"],RemoveEntity:["entity"],MoveEntity:["entity","destination"],TakeFrom:["source","destination"],SetState:["entity","state"]};function lr(e,t){return Vj[t.moveType].filter(n=>t.arguments[n].playerChoice).map(n=>({argName:n,getClickable:n==="state"?()=>t.arguments[n].possibleValues.map(r=>({abstract:!0,...t.arguments[n],value:r})):r=>e.G.bank.findAll(e,t.arguments[n],r)}))}function Co(e,t,n,r){let i=lr(e,t,r).map(s=>s.argName);return{arguments:n.reduce((s,o,a)=>({...s,[i[a]]:o}),{})}}var qo=class{constructor(t){this.options=t,this.game=t.boardgameIOGame||gi(JSON.parse(t.gameRules)),t.boardgameIOGame||(this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]},this.optimisticWinner=null)}connect(){let{server:t,numPlayers:n,debug:r={collapseOnLoad:!0,impl:Ki},matchID:i,playerID:s,credentials:o,multiplayer:a=ul({server:t,socketOpts:{transports:["websocket","polling"]}})}=this.options;try{let u=o?{game:this.game,multiplayer:a,matchID:i,playerID:s,credentials:o,numPlayers:n,debug:r}:{game:this.game,numPlayers:n,debug:r};return this.client=Hc(u),this.client.subscribe(()=>this.update()),this.client.start(),this}catch(u){console.error("Failed to join game:",u?.message??u),u?.stack&&console.error(u.stack)}}update(){this.options.onClientUpdate?.()}getState(){let t=this.client?.getState();if(!t)return{};let n=this.options.boardgameIOGame?t:{...t,G:Ft(JSON.stringify(t.G),ht)},r=this.optimisticWinner??n?.ctx?.gameover,i=r?[]:ti(n,this.client);if(this.options.boardgameIOGame)return{state:n,gameover:r,moves:this.client.moves,currentMoves:i};let s=Object.entries(i).reduce((u,[c,l])=>{let f=p=>{this.client.moves[c](No(p))};return f.moveInstance=l.moveInstance,{...u,[c]:f}},{}),{allClickable:o,_possibleMoveMeta:a}=Kj(n,s,this.moveBuilder);return{state:n,gameover:r,allClickable:o,_wrappedMoves:s,_possibleMoveMeta:a}}doStep(t){if(this.options.boardgameIOGame)return;let{state:n,_wrappedMoves:r,_possibleMoveMeta:i}=this.getState(),s=t.abstract?t:n.G.bank.locate(t.entityId),o=Object.entries(i).filter(([u,c])=>!zj(c.clickableForMove,s)).map(([u])=>u).concat(this.moveBuilder.eliminatedMoves);if(o.length===Object.keys(r).length){console.error("invalid move with target:",s?.rule);return}let a=Object.entries(i).filter(([u])=>!o.includes(u));if(Hj(n,r,a,this.moveBuilder.stepIndex)){let[u]=a[0],c=r[u],l=Co(n,c.moveInstance.rule,[...this.moveBuilder.targets,s],{moveInstance:c.moveInstance});this.optimisticWinner=Wj(n,this.game,c.moveInstance,l),c(l),this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]}}else this.moveBuilder={eliminatedMoves:o,stepIndex:this.moveBuilder.stepIndex+1,targets:[...this.moveBuilder.targets,s]};this.update()}reset(){this.options.boardgameIOGame||(this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]},this.optimisticWinner=null,this.update())}undoStep(){this.options.boardgameIOGame||(this.moveBuilder.targets.length&&(this.moveBuilder={targets:this.moveBuilder.targets.slice(0,-1),stepIndex:Math.max(0,this.moveBuilder.stepIndex-1),eliminatedMoves:[]}),this.update())}};function zj(e,t){return t.abstract?[...e].some(n=>n.abstract&&n.value===t.value):e.has(t)}function Kj(e,t,n){let{eliminatedMoves:r,stepIndex:i}=n,s={},o=new Set;return Object.entries(t).filter(([a])=>!r.includes(a)).forEach(([a,u])=>{let c=pe(e,{...u.moveInstance.rule,moveName:a}),l={moveInstance:u.moveInstance,moveArguments:c.arguments},f=n.targets.map(m=>m.abstract?m:e.G.bank.locate(m.entityId)),p=Co(e,c,f,l);l.moveArguments={...l.moveArguments,...p.arguments};let h=ke(e,c,{},l).conditionsAreMet,d=lr(e,c),y=new Set(h&&d?.[i]?.getClickable(l)||[]);s[a]={clickableForMove:y},y.forEach(m=>o.add(m))}),{_possibleMoveMeta:s,allClickable:o}}function Hj(e,t,n,r){return n.length===1&&lr(e,t[n[0][0]].moveInstance.rule).length===r+1}function Wj(e,t,n,r){let i=Zr(e,No(r),{moveInstance:n});return t.endIf?.({...e,G:JSON.parse(He(i))})}return w_(Jj);})();
|
|
32
|
+
normal forwards}.closer.svelte-8ymctk .icon.svelte-8ymctk{animation-direction:reverse}.pane.svelte-8ymctk.svelte-8ymctk{flex-grow:2;overflow-x:hidden;overflow-y:scroll;background:#fefefe;padding:20px;border-left:1px solid #ccc;box-shadow:-1px 0 5px rgba(0, 0, 0, 0.2);box-sizing:border-box;width:280px}.secondary-pane.svelte-8ymctk.svelte-8ymctk{background:#fefefe;overflow-y:scroll}.debug-panel.svelte-8ymctk button,.debug-panel.svelte-8ymctk select{cursor:pointer;font-size:14px;font-family:monospace}.debug-panel.svelte-8ymctk select{background:#eee;border:1px solid #bbb;color:#555;padding:3px;border-radius:3px}.debug-panel.svelte-8ymctk section{margin-bottom:20px}.debug-panel.svelte-8ymctk .screen-reader-only{clip:rect(0 0 0 0);clip-path:inset(50%);height:1px;overflow:hidden;position:absolute;white-space:nowrap;width:1px}`)}function oj(e){let t,n,r,i,s,o,a,u,c,l=e[10]&&uj(e);r=new sc({props:{panes:e[6],pane:e[2]}}),r.$on("change",e[8]);var f=e[6][e[2]].component;function p(d){return{props:{client:d[4],clientManager:d[0],ToggleVisibility:d[9]}}}f&&(o=new f(p(e)));let h=e[5]&&d1(e);return{c(){t=A("div"),l&&l.c(),n=q(),L(r.$$.fragment),i=q(),s=A("div"),o&&L(o.$$.fragment),a=q(),h&&h.c(),k(s,"class","pane svelte-8ymctk"),k(s,"role","region"),k(s,"aria-label",e[2]),k(s,"tabindex","-1"),k(t,"class","panel svelte-8ymctk")},m(d,y){M(d,t,y),l&&l.m(t,null),w(t,n),R(r,t,null),w(t,i),w(t,s),o&&R(o,s,null),e[16](s),w(t,a),h&&h.m(t,null),c=!0},p(d,y){e=d,e[10]&&l.p(e,y);let m={};y&4&&(m.pane=e[2]),r.$set(m);let b={};if(y&16&&(b.client=e[4]),y&1&&(b.clientManager=e[0]),f!==(f=e[6][e[2]].component)){if(o){ce();let g=o;x(g.$$.fragment,1,0,()=>{B(g,1)}),le()}f?(o=new f(p(e)),L(o.$$.fragment),P(o.$$.fragment,1),R(o,s,null)):o=null}else f&&o.$set(b);(!c||y&4)&&k(s,"aria-label",e[2]),e[5]?h?(h.p(e,y),y&32&&P(h,1)):(h=d1(e),h.c(),P(h,1),h.m(t,null)):h&&(ce(),x(h,1,1,()=>{h=null}),le())},i(d){c||(P(l),P(r.$$.fragment,d),o&&P(o.$$.fragment,d),P(h),ot(()=>{u||(u=mb(t,yb,{x:400,...e[12]},!0)),u.run(1)}),c=!0)},o(d){x(l),x(r.$$.fragment,d),o&&x(o.$$.fragment,d),x(h),u||(u=mb(t,yb,{x:400,...e[12]},!1)),u.run(0),c=!1},d(d){d&&S(t),l&&l.d(),B(r),o&&B(o),e[16](null),h&&h.d(),d&&u&&u.end()}}}function aj(e){let t,n,r=e[10]&&cj(e);return{c(){r&&r.c(),t=at()},m(i,s){r&&r.m(i,s),M(i,t,s),n=!0},p(i,s){i[10]&&r.p(i,s)},i(i){n||(P(r),n=!0)},o(i){x(r),n=!1},d(i){r&&r.d(i),i&&S(t)}}}function uj(e){let t,n,r,i,s,o,a,u;return r=new bo({}),{c(){t=A("button"),n=A("span"),L(r.$$.fragment),k(n,"class","icon svelte-8ymctk"),k(n,"aria-hidden","true"),k(t,"class","visibility-toggle closer svelte-8ymctk"),k(t,"title","Hide Debug Panel")},m(c,l){M(c,t,l),w(t,n),R(r,n,null),o=!0,a||(u=Q(t,"click",e[9]),a=!0)},p:U,i(c){o||(P(r.$$.fragment,c),ot(()=>{s&&s.end(1),i=k1(t,e[14],{key:"toggle"}),i.start()}),o=!0)},o(c){x(r.$$.fragment,c),i&&i.invalidate(),s=A1(t,e[13],{key:"toggle"}),o=!1},d(c){c&&S(t),B(r),c&&s&&s.end(),a=!1,u()}}}function d1(e){let t,n,r;var i=e[5].component;function s(o){return{props:{metadata:o[5].metadata}}}return i&&(n=new i(s(e))),{c(){t=A("div"),n&&L(n.$$.fragment),k(t,"class","secondary-pane svelte-8ymctk")},m(o,a){M(o,t,a),n&&R(n,t,null),r=!0},p(o,a){let u={};if(a&32&&(u.metadata=o[5].metadata),i!==(i=o[5].component)){if(n){ce();let c=n;x(c.$$.fragment,1,0,()=>{B(c,1)}),le()}i?(n=new i(s(o)),L(n.$$.fragment),P(n.$$.fragment,1),R(n,t,null)):n=null}else i&&n.$set(u)},i(o){r||(n&&P(n.$$.fragment,o),r=!0)},o(o){n&&x(n.$$.fragment,o),r=!1},d(o){o&&S(t),n&&B(n)}}}function cj(e){let t,n,r,i,s,o,a,u;return r=new bo({}),{c(){t=A("button"),n=A("span"),L(r.$$.fragment),k(n,"class","icon svelte-8ymctk"),k(n,"aria-hidden","true"),k(t,"class","visibility-toggle opener svelte-8ymctk"),k(t,"title","Show Debug Panel")},m(c,l){M(c,t,l),w(t,n),R(r,n,null),o=!0,a||(u=Q(t,"click",e[9]),a=!0)},p:U,i(c){o||(P(r.$$.fragment,c),ot(()=>{s&&s.end(1),i=k1(t,e[14],{key:"toggle"}),i.start()}),o=!0)},o(c){x(r.$$.fragment,c),i&&i.invalidate(),s=A1(t,e[13],{key:"toggle"}),o=!1},d(c){c&&S(t),B(r),c&&s&&s.end(),a=!1,u()}}}function lj(e){let t,n,r,i,s,o,a=[aj,oj],u=[];function c(l,f){return l[3]?1:0}return n=c(e),r=u[n]=a[n](e),{c(){t=A("section"),r.c(),k(t,"aria-label","boardgame.io Debug Panel"),k(t,"class","debug-panel svelte-8ymctk")},m(l,f){M(l,t,f),u[n].m(t,null),i=!0,s||(o=Q(window,"keypress",e[11]),s=!0)},p(l,[f]){let p=n;n=c(l),n===p?u[n].p(l,f):(ce(),x(u[p],1,1,()=>{u[p]=null}),le(),r=u[n],r?r.p(l,f):(r=u[n]=a[n](l),r.c()),P(r,1),r.m(t,null))},i(l){i||(P(r),i=!0)},o(l){x(r),i=!1},d(l){l&&S(t),u[n].d(),s=!1,o()}}}function fj(e,t,n){let r,i,s=U,o=()=>(s(),s=Hi(u,J=>n(15,i=J)),u),a;e.$$.on_destroy.push(()=>s());let{clientManager:u}=t;o();let c={main:{label:"Main",shortcut:"m",component:vc},log:{label:"Log",shortcut:"l",component:kc},info:{label:"Info",shortcut:"i",component:bc},ai:{label:"AI",shortcut:"a",component:xc}},l=gb(!1),f=gb(null);g1(e,f,J=>n(5,a=J)),Fi("hotkeys",{disableHotkeys:l}),Fi("secondaryPane",{secondaryPane:f});let p,h="main";function d(J){n(2,h=J.detail),p.focus()}function y(){n(3,b=!b)}let m=i.client.debugOpt,b=!m||!m.collapseOnLoad,g=!m||!m.hideToggleButton;function O(J){if(J.key=="."){y();return}b&&Object.entries(c).forEach(([fe,{shortcut:V}])=>{J.key==V&&n(2,h=fe)})}let I={duration:150,easing:Dc},[j,N]=WC(I);function D(J){yo[J?"unshift":"push"](()=>{p=J,n(1,p)})}return e.$$set=J=>{"clientManager"in J&&o(n(0,u=J.clientManager))},e.$$.update=()=>{e.$$.dirty&32768&&n(4,r=i.client)},[u,p,h,b,r,a,c,f,d,y,g,O,I,j,N,i,D]}var Ki=class extends Z{constructor(t){super(),te(this,t,fj,lj,ee,{clientManager:0},sj)}};function On(e){"@babel/helpers - typeof";return On=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(t){return typeof t}:function(t){return t&&typeof Symbol=="function"&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},On(e)}function M1(e,t){if(On(e)!="object"||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(On(r)!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function I1(e){var t=M1(e,"string");return On(t)=="symbol"?t:t+""}function N1(e,t,n){return(t=I1(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function C1(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(i){return Object.getOwnPropertyDescriptor(e,i).enumerable})),n.push.apply(n,r)}return n}function Rc(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?C1(Object(n),!0).forEach(function(r){N1(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):C1(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function Xe(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}var q1=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}(),Bc=function(){return Math.random().toString(36).substring(7).split("").join(".")},j1={INIT:"@@redux/INIT"+Bc(),REPLACE:"@@redux/REPLACE"+Bc(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+Bc()}};function pj(e){if(typeof e!="object"||e===null)return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Lc(e,t,n){var r;if(typeof t=="function"&&typeof n=="function"||typeof n=="function"&&typeof arguments[3]=="function")throw new Error(Xe(0));if(typeof t=="function"&&typeof n>"u"&&(n=t,t=void 0),typeof n<"u"){if(typeof n!="function")throw new Error(Xe(1));return n(Lc)(e,t)}if(typeof e!="function")throw new Error(Xe(2));var i=e,s=t,o=[],a=o,u=!1;function c(){a===o&&(a=o.slice())}function l(){if(u)throw new Error(Xe(3));return s}function f(y){if(typeof y!="function")throw new Error(Xe(4));if(u)throw new Error(Xe(5));var m=!0;return c(),a.push(y),function(){if(m){if(u)throw new Error(Xe(6));m=!1,c();var g=a.indexOf(y);a.splice(g,1),o=null}}}function p(y){if(!pj(y))throw new Error(Xe(7));if(typeof y.type>"u")throw new Error(Xe(8));if(u)throw new Error(Xe(9));try{u=!0,s=i(s,y)}finally{u=!1}for(var m=o=a,b=0;b<m.length;b++){var g=m[b];g()}return y}function h(y){if(typeof y!="function")throw new Error(Xe(10));i=y,p({type:j1.REPLACE})}function d(){var y,m=f;return y={subscribe:function(g){if(typeof g!="object"||g===null)throw new Error(Xe(11));function O(){g.next&&g.next(l())}O();var I=m(O);return{unsubscribe:I}}},y[q1]=function(){return this},y}return p({type:j1.INIT}),r={dispatch:p,subscribe:f,getState:l,replaceReducer:h},r[q1]=d,r}function Gc(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return t.length===0?function(r){return r}:t.length===1?t[0]:t.reduce(function(r,i){return function(){return r(i.apply(void 0,arguments))}})}function D1(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(r){return function(){var i=r.apply(void 0,arguments),s=function(){throw new Error(Xe(15))},o={getState:i.getState,dispatch:function(){return s.apply(void 0,arguments)}},a=t.map(function(u){return u(o)});return s=Gc.apply(void 0,a)(i.dispatch),Rc(Rc({},i),{},{dispatch:s})}}}function R1({game:e,numPlayers:t,setupData:n}){e=ji(e),t||(t=2);let r=e.flow.ctx(t),i={G:{},ctx:r,plugins:{}};i=Nv(i,{game:e}),i=Ti(i,{game:e,playerID:void 0});let s=Wt(i);i.G=e.setup({...s,ctx:i.ctx},n);let o={...i,_undo:[],_redo:[],_stateID:0};return o=e.flow.init(o),[o]=eo(o,{game:e}),e.disableUndo||(o._undo=[{G:o.G,ctx:o.ctx,plugins:o.plugins}]),o}var ir=class{constructor({transportDataCallback:t,gameName:n,playerID:r,matchID:i,credentials:s,numPlayers:o}){this.connectionStatusCallback=()=>{},this.isConnected=!1,this.transportDataCallback=t,this.gameName=n||"default",this.playerID=r||null,this.matchID=i||"default",this.credentials=s,this.numPlayers=o||2}subscribeToConnectionStatus(t){this.connectionStatusCallback=t}setConnectionStatus(t){this.isConnected=t,this.connectionStatusCallback()}notifyClient(t){this.transportDataCallback(t)}};var Fc=class extends ir{connect(){}disconnect(){}sendAction(){}sendChatMessage(){}requestSync(){}updateCredentials(){}updateMatchID(){}updatePlayerID(){}},hj=e=>new Fc(e),Uc=class{constructor(){this.debugPanel=null,this.currentClient=null,this.clients=new Map,this.subscribers=new Map}register(t){this.clients.set(t,t),this.mountDebug(t),this.notifySubscribers()}unregister(t){if(this.clients.delete(t),this.currentClient===t){this.unmountDebug();for(let[n]of this.clients){if(this.debugPanel)break;this.mountDebug(n)}}this.notifySubscribers()}subscribe(t){let n=Symbol();return this.subscribers.set(n,t),t(this.getState()),()=>{this.subscribers.delete(n)}}switchPlayerID(t){if(this.currentClient.multiplayer){for(let[n]of this.clients)if(n.playerID===t&&n.debugOpt!==!1&&n.multiplayer===this.currentClient.multiplayer){this.switchToClient(n);return}}this.currentClient.updatePlayerID(t),this.notifySubscribers()}switchToClient(t){t!==this.currentClient&&(this.unmountDebug(),this.mountDebug(t),this.notifySubscribers())}notifySubscribers(){let t=this.getState();this.subscribers.forEach(n=>{n(t)})}getState(){return{client:this.currentClient,debuggableClients:this.getDebuggableClients()}}getDebuggableClients(){return[...this.clients.values()].filter(t=>t.debugOpt!==!1)}mountDebug(t){if(t.debugOpt===!1||this.debugPanel!==null||typeof document>"u")return;let n,r=document.body;t.debugOpt&&t.debugOpt!==!0&&(n=t.debugOpt.impl||n,r=t.debugOpt.target||r),n&&(this.currentClient=t,this.debugPanel=new n({target:r,props:{clientManager:this}}))}unmountDebug(){this.debugPanel.$destroy(),this.debugPanel=null,this.currentClient=null}},dj=new Uc;function Vc(e,t,n){return!n&&e==null&&(e=t.getState().ctx.currentPlayer),e}function Kc(e,t,n,r,i,s){let o={};for(let a of t)o[a]=(...u)=>{let c=Mv[e](a,u,Vc(r,n,s),i);n.dispatch(c)};return o}var mj=Kc.bind(null,"makeMove"),gj=Kc.bind(null,"gameEvent"),yj=Kc.bind(null,"plugin"),zc=class{constructor({game:t,debug:n,numPlayers:r,multiplayer:i,matchID:s,playerID:o,credentials:a,enhancer:u}){this.game=ji(t),this.playerID=o,this.matchID=s||"default",this.credentials=a,this.multiplayer=i,this.debugOpt=n,this.manager=dj,this.gameStateOverride=null,this.subscribers={},this._running=!1,this.reducer=Xn({game:this.game,isClient:i!==void 0}),this.initialState=null,i||(this.initialState=R1({game:this.game,numPlayers:r})),this.reset=()=>{this.store.dispatch(Nu(this.initialState))},this.undo=()=>{let h=Cu(Vc(this.playerID,this.store,this.multiplayer),this.credentials);this.store.dispatch(h)},this.redo=()=>{let h=qu(Vc(this.playerID,this.store,this.multiplayer),this.credentials);this.store.dispatch(h)},this.log=[];let p=D1(cb,()=>h=>d=>{let y=h(d);return this.notifySubscribers(),y},h=>d=>y=>{let m=h.getState(),b=d(y);return!("clientOnly"in y)&&y.type!==$n&&this.transport.sendAction(m,y),b},h=>d=>y=>{let m=d(y),b=h.getState();switch(y.type){case _i:case Yn:case Ei:case wi:{let g=b.deltalog;this.log=[...this.log,...g];break}case Oi:{this.log=[];break}case Ai:case ki:{let g=-1;this.log.length>0&&(g=this.log[this.log.length-1]._stateID);let O=y.deltalog||[];O=O.filter(I=>I._stateID>g),this.log=[...this.log,...O];break}case Pi:{this.initialState=y.initialState,this.log=y.log||[];break}}return m});u=u!==void 0?Gc(p,u):p,this.store=Lc(this.reducer,this.initialState,u),i||(i=hj),this.transport=i({transportDataCallback:h=>this.receiveTransportData(h),gameKey:t,game:this.game,matchID:s,playerID:o,credentials:a,gameName:this.game.name,numPlayers:r}),this.createDispatchers(),this.chatMessages=[],this.sendChatMessage=h=>{this.transport.sendChatMessage(this.matchID,{id:mv(7),sender:this.playerID,payload:h})}}receiveMatchData(t){this.matchData=t,this.notifySubscribers()}receiveChatMessage(t){this.chatMessages=[...this.chatMessages,t],this.notifySubscribers()}receiveTransportData(t){let[n]=t.args;if(n===this.matchID)switch(t.type){case"sync":{let[,r]=t.args,i=xi(r);this.receiveMatchData(r.filteredMetadata),this.store.dispatch(i);break}case"update":{let[,r,i]=t.args,s=this.store.getState();if(r._stateID>=s._stateID){let o=Iu(r,i);this.store.dispatch(o)}break}case"patch":{let[,r,i,s,o]=t.args,a=this.store.getState()._stateID;if(r!==a)break;let u=Mu(r,i,s,o);this.store.dispatch(u),this.store.getState()._stateID===a&&this.transport.requestSync();break}case"matchData":{let[,r]=t.args;this.receiveMatchData(r);break}case"chat":{let[,r]=t.args;this.receiveChatMessage(r);break}}}notifySubscribers(){Object.values(this.subscribers).forEach(t=>t(this.getState()))}overrideGameState(t){this.gameStateOverride=t,this.notifySubscribers()}start(){this.transport.connect(),this._running=!0,this.manager.register(this)}stop(){this.transport.disconnect(),this._running=!1,this.manager.unregister(this)}subscribe(t){let n=Object.keys(this.subscribers).length;return this.subscribers[n]=t,this.transport.subscribeToConnectionStatus(()=>this.notifySubscribers()),(this._running||!this.multiplayer)&&t(this.getState()),()=>{delete this.subscribers[n]}}getInitialState(){return this.initialState}getState(){let t=this.store.getState();if(this.gameStateOverride!==null&&(t=this.gameStateOverride),t===null)return t;let n=!0,r=this.game.flow.isPlayerActive(t.G,t.ctx,this.playerID);return this.multiplayer&&!r&&(n=!1),!this.multiplayer&&this.playerID!==null&&this.playerID!==void 0&&!r&&(n=!1),t.ctx.gameover!==void 0&&(n=!1),this.multiplayer||(t={...t,G:this.game.playerView({G:t.G,ctx:t.ctx,playerID:this.playerID}),plugins:qv(t,this)}),{...t,log:this.log,isActive:n,isConnected:this.transport.isConnected}}createDispatchers(){this.moves=mj(this.game.moveNames,this.store,this.playerID,this.credentials,this.multiplayer),this.events=gj(this.game.flow.enabledEventNames,this.store,this.playerID,this.credentials,this.multiplayer),this.plugins=yj(this.game.pluginNames,this.store,this.playerID,this.credentials,this.multiplayer)}updatePlayerID(t){this.playerID=t,this.createDispatchers(),this.transport.updatePlayerID(t),this.notifySubscribers()}updateMatchID(t){this.matchID=t,this.createDispatchers(),this.transport.updateMatchID(t),this.notifySubscribers()}updateCredentials(t){this.credentials=t,this.createDispatchers(),this.transport.updateCredentials(t),this.notifySubscribers()}};function Hc(e){return new zc(e)}var DL=he(tn());var BL=he(qi());var LL=he(io());var UL=he(tn());var zL=he(qi());var KL=he(io());var ut=Object.create(null);ut.open="0";ut.close="1";ut.ping="2";ut.pong="3";ut.message="4";ut.upgrade="5";ut.noop="6";var Yi=Object.create(null);Object.keys(ut).forEach(e=>{Yi[ut[e]]=e});var $i={type:"error",data:"parser error"};var G1=typeof Blob=="function"||typeof Blob<"u"&&Object.prototype.toString.call(Blob)==="[object BlobConstructor]",F1=typeof ArrayBuffer=="function",U1=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e&&e.buffer instanceof ArrayBuffer,Xi=({type:e,data:t},n,r)=>G1&&t instanceof Blob?n?r(t):B1(t,r):F1&&(t instanceof ArrayBuffer||U1(t))?n?r(t):B1(new Blob([t]),r):r(ut[e]+(t||"")),B1=(e,t)=>{let n=new FileReader;return n.onload=function(){let r=n.result.split(",")[1];t("b"+(r||""))},n.readAsDataURL(e)};function L1(e){return e instanceof Uint8Array?e:e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}var Wc;function V1(e,t){if(G1&&e.data instanceof Blob)return e.data.arrayBuffer().then(L1).then(t);if(F1&&(e.data instanceof ArrayBuffer||U1(e.data)))return t(L1(e.data));Xi(e,!1,n=>{Wc||(Wc=new TextEncoder),t(Wc.encode(n))})}var z1="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Qi=typeof Uint8Array>"u"?[]:new Uint8Array(256);for(let e=0;e<z1.length;e++)Qi[z1.charCodeAt(e)]=e;var K1=e=>{let t=e.length*.75,n=e.length,r,i=0,s,o,a,u;e[e.length-1]==="="&&(t--,e[e.length-2]==="="&&t--);let c=new ArrayBuffer(t),l=new Uint8Array(c);for(r=0;r<n;r+=4)s=Qi[e.charCodeAt(r)],o=Qi[e.charCodeAt(r+1)],a=Qi[e.charCodeAt(r+2)],u=Qi[e.charCodeAt(r+3)],l[i++]=s<<2|o>>4,l[i++]=(o&15)<<4|a>>2,l[i++]=(a&3)<<6|u&63;return c};var vj=typeof ArrayBuffer=="function",Zi=(e,t)=>{if(typeof e!="string")return{type:"message",data:H1(e,t)};let n=e.charAt(0);return n==="b"?{type:"message",data:bj(e.substring(1),t)}:Yi[n]?e.length>1?{type:Yi[n],data:e.substring(1)}:{type:Yi[n]}:$i},bj=(e,t)=>{if(vj){let n=K1(e);return H1(n,t)}else return{base64:!0,data:e}},H1=(e,t)=>{switch(t){case"blob":return e instanceof Blob?e:new Blob([e]);case"arraybuffer":default:return e instanceof ArrayBuffer?e:e.buffer}};var W1="",J1=(e,t)=>{let n=e.length,r=new Array(n),i=0;e.forEach((s,o)=>{Xi(s,!1,a=>{r[o]=a,++i===n&&t(r.join(W1))})})},Y1=(e,t)=>{let n=e.split(W1),r=[];for(let i=0;i<n.length;i++){let s=Zi(n[i],t);if(r.push(s),s.type==="error")break}return r};function $1(){return new TransformStream({transform(e,t){V1(e,n=>{let r=n.length,i;if(r<126)i=new Uint8Array(1),new DataView(i.buffer).setUint8(0,r);else if(r<65536){i=new Uint8Array(3);let s=new DataView(i.buffer);s.setUint8(0,126),s.setUint16(1,r)}else{i=new Uint8Array(9);let s=new DataView(i.buffer);s.setUint8(0,127),s.setBigUint64(1,BigInt(r))}e.data&&typeof e.data!="string"&&(i[0]|=128),t.enqueue(i),t.enqueue(n)})}})}var Jc;function Eo(e){return e.reduce((t,n)=>t+n.length,0)}function ko(e,t){if(e[0].length===t)return e.shift();let n=new Uint8Array(t),r=0;for(let i=0;i<t;i++)n[i]=e[0][r++],r===e[0].length&&(e.shift(),r=0);return e.length&&r<e[0].length&&(e[0]=e[0].slice(r)),n}function X1(e,t){Jc||(Jc=new TextDecoder);let n=[],r=0,i=-1,s=!1;return new TransformStream({transform(o,a){for(n.push(o);;){if(r===0){if(Eo(n)<1)break;let u=ko(n,1);s=(u[0]&128)===128,i=u[0]&127,i<126?r=3:i===126?r=1:r=2}else if(r===1){if(Eo(n)<2)break;let u=ko(n,2);i=new DataView(u.buffer,u.byteOffset,u.length).getUint16(0),r=3}else if(r===2){if(Eo(n)<8)break;let u=ko(n,8),c=new DataView(u.buffer,u.byteOffset,u.length),l=c.getUint32(0);if(l>Math.pow(2,21)-1){a.enqueue($i);break}i=l*Math.pow(2,32)+c.getUint32(4),r=3}else{if(Eo(n)<i)break;let u=ko(n,i);a.enqueue(Zi(s?u:Jc.decode(u),t)),r=0}if(i===0||i>e){a.enqueue($i);break}}}})}var Yc=4;function ye(e){if(e)return _j(e)}function _j(e){for(var t in ye.prototype)e[t]=ye.prototype[t];return e}ye.prototype.on=ye.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this};ye.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this};ye.prototype.off=ye.prototype.removeListener=ye.prototype.removeAllListeners=ye.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},arguments.length==0)return this._callbacks={},this;var n=this._callbacks["$"+e];if(!n)return this;if(arguments.length==1)return delete this._callbacks["$"+e],this;for(var r,i=0;i<n.length;i++)if(r=n[i],r===t||r.fn===t){n.splice(i,1);break}return n.length===0&&delete this._callbacks["$"+e],this};ye.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),n=this._callbacks["$"+e],r=1;r<arguments.length;r++)t[r-1]=arguments[r];if(n){n=n.slice(0);for(var r=0,i=n.length;r<i;++r)n[r].apply(this,t)}return this};ye.prototype.emitReserved=ye.prototype.emit;ye.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]};ye.prototype.hasListeners=function(e){return!!this.listeners(e).length};var Dt=typeof Promise=="function"&&typeof Promise.resolve=="function"?t=>Promise.resolve().then(t):(t,n)=>n(t,0),Ue=typeof self<"u"?self:typeof window<"u"?window:Function("return this")(),Q1="arraybuffer";function Ao(e,...t){return t.reduce((n,r)=>(e.hasOwnProperty(r)&&(n[r]=e[r]),n),{})}var wj=Ue.setTimeout,Oj=Ue.clearTimeout;function Rt(e,t){t.useNativeTimers?(e.setTimeoutFn=wj.bind(Ue),e.clearTimeoutFn=Oj.bind(Ue)):(e.setTimeoutFn=Ue.setTimeout.bind(Ue),e.clearTimeoutFn=Ue.clearTimeout.bind(Ue))}var Pj=1.33;function Z1(e){return typeof e=="string"?Ej(e):Math.ceil((e.byteLength||e.size)*Pj)}function Ej(e){let t=0,n=0;for(let r=0,i=e.length;r<i;r++)t=e.charCodeAt(r),t<128?n+=1:t<2048?n+=2:t<55296||t>=57344?n+=3:(r++,n+=4);return n}function xo(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}function e_(e){let t="";for(let n in e)e.hasOwnProperty(n)&&(t.length&&(t+="&"),t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n]));return t}function t_(e){let t={},n=e.split("&");for(let r=0,i=n.length;r<i;r++){let s=n[r].split("=");t[decodeURIComponent(s[0])]=decodeURIComponent(s[1])}return t}var So=class extends Error{constructor(t,n,r){super(t),this.description=n,this.context=r,this.type="TransportError"}},Bt=class extends ye{constructor(t){super(),this.writable=!1,Rt(this,t),this.opts=t,this.query=t.query,this.socket=t.socket,this.supportsBinary=!t.forceBase64}onError(t,n,r){return super.emitReserved("error",new So(t,n,r)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(t){this.readyState==="open"&&this.write(t)}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(t){let n=Zi(t,this.socket.binaryType);this.onPacket(n)}onPacket(t){super.emitReserved("packet",t)}onClose(t){this.readyState="closed",super.emitReserved("close",t)}pause(t){}createUri(t,n={}){return t+"://"+this._hostname()+this._port()+this.opts.path+this._query(n)}_hostname(){let t=this.opts.hostname;return t.indexOf(":")===-1?t:"["+t+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port)!==443||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(t){let n=e_(t);return n.length?"?"+n:""}};var es=class extends Bt{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(t){this.readyState="pausing";let n=()=>{this.readyState="paused",t()};if(this._polling||!this.writable){let r=0;this._polling&&(r++,this.once("pollComplete",function(){--r||n()})),this.writable||(r++,this.once("drain",function(){--r||n()}))}else n()}_poll(){this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(t){let n=r=>{if(this.readyState==="opening"&&r.type==="open"&&this.onOpen(),r.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(r)};Y1(t,this.socket.binaryType).forEach(n),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"&&this._poll())}doClose(){let t=()=>{this.write([{type:"close"}])};this.readyState==="open"?t():this.once("open",t)}write(t){this.writable=!1,J1(t,n=>{this.doWrite(n,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){let t=this.opts.secure?"https":"http",n=this.query||{};return this.opts.timestampRequests!==!1&&(n[this.opts.timestampParam]=xo()),!this.supportsBinary&&!n.sid&&(n.b64=1),this.createUri(t,n)}};var n_=!1;try{n_=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}var r_=n_;function kj(){}var $c=class extends es{constructor(t){if(super(t),typeof location<"u"){let n=location.protocol==="https:",r=location.port;r||(r=n?"443":"80"),this.xd=typeof location<"u"&&t.hostname!==location.hostname||r!==t.port}}doWrite(t,n){let r=this.request({method:"POST",data:t});r.on("success",n),r.on("error",(i,s)=>{this.onError("xhr post error",i,s)})}doPoll(){let t=this.request();t.on("data",this.onData.bind(this)),t.on("error",(n,r)=>{this.onError("xhr poll error",n,r)}),this.pollXhr=t}},$t=class e extends ye{constructor(t,n,r){super(),this.createRequest=t,Rt(this,r),this._opts=r,this._method=r.method||"GET",this._uri=n,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var t;let n=Ao(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");n.xdomain=!!this._opts.xd;let r=this._xhr=this.createRequest(n);try{r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let i in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(i)&&r.setRequestHeader(i,this._opts.extraHeaders[i])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(t=this._opts.cookieJar)===null||t===void 0||t.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var i;r.readyState===3&&((i=this._opts.cookieJar)===null||i===void 0||i.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},r.send(this._data)}catch(i){this.setTimeoutFn(()=>{this._onError(i)},0);return}typeof document<"u"&&(this._index=e.requestsCount++,e.requests[this._index]=this)}_onError(t){this.emitReserved("error",t,this._xhr),this._cleanup(!0)}_cleanup(t){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=kj,t)try{this._xhr.abort()}catch{}typeof document<"u"&&delete e.requests[this._index],this._xhr=null}}_onLoad(){let t=this._xhr.responseText;t!==null&&(this.emitReserved("data",t),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}};$t.requestsCount=0;$t.requests={};if(typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",i_);else if(typeof addEventListener=="function"){let e="onpagehide"in Ue?"pagehide":"unload";addEventListener(e,i_,!1)}}function i_(){for(let e in $t.requests)$t.requests.hasOwnProperty(e)&&$t.requests[e].abort()}var Aj=function(){let e=s_({xdomain:!1});return e&&e.responseType!==null}(),Xt=class extends $c{constructor(t){super(t);let n=t&&t.forceBase64;this.supportsBinary=Aj&&!n}request(t={}){return Object.assign(t,{xd:this.xd},this.opts),new $t(s_,this.uri(),t)}};function s_(e){let t=e.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!t||r_))return new XMLHttpRequest}catch{}if(!t)try{return new Ue[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}var o_=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative",Qc=class extends Bt{get name(){return"websocket"}doOpen(){let t=this.uri(),n=this.opts.protocols,r=o_?{}:Ao(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(r.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(t,n,r)}catch(i){return this.emitReserved("error",i)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=t=>this.onClose({description:"websocket connection closed",context:t}),this.ws.onmessage=t=>this.onData(t.data),this.ws.onerror=t=>this.onError("websocket error",t)}write(t){this.writable=!1;for(let n=0;n<t.length;n++){let r=t[n],i=n===t.length-1;Xi(r,this.supportsBinary,s=>{try{this.doWrite(r,s)}catch{}i&&Dt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){let t=this.opts.secure?"wss":"ws",n=this.query||{};return this.opts.timestampRequests&&(n[this.opts.timestampParam]=xo()),this.supportsBinary||(n.b64=1),this.createUri(t,n)}},Xc=Ue.WebSocket||Ue.MozWebSocket,Qt=class extends Qc{createSocket(t,n,r){return o_?new Xc(t,n,r):n?new Xc(t,n):new Xc(t)}doWrite(t,n){this.ws.send(n)}};var sr=class extends Bt{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(t){return this.emitReserved("error",t)}this._transport.closed.then(()=>{this.onClose()}).catch(t=>{this.onError("webtransport error",t)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(t=>{let n=X1(Number.MAX_SAFE_INTEGER,this.socket.binaryType),r=t.readable.pipeThrough(n).getReader(),i=$1();i.readable.pipeTo(t.writable),this._writer=i.writable.getWriter();let s=()=>{r.read().then(({done:a,value:u})=>{a||(this.onPacket(u),s())}).catch(a=>{})};s();let o={type:"open"};this.query.sid&&(o.data=`{"sid":"${this.query.sid}"}`),this._writer.write(o).then(()=>this.onOpen())})})}write(t){this.writable=!1;for(let n=0;n<t.length;n++){let r=t[n],i=n===t.length-1;this._writer.write(r).then(()=>{i&&Dt(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var t;(t=this._transport)===null||t===void 0||t.close()}};var Zc={websocket:Qt,webtransport:sr,polling:Xt};var xj=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,Sj=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function or(e){if(e.length>8e3)throw"URI too long";let t=e,n=e.indexOf("["),r=e.indexOf("]");n!=-1&&r!=-1&&(e=e.substring(0,n)+e.substring(n,r).replace(/:/g,";")+e.substring(r,e.length));let i=xj.exec(e||""),s={},o=14;for(;o--;)s[Sj[o]]=i[o]||"";return n!=-1&&r!=-1&&(s.source=t,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=Tj(s,s.path),s.queryKey=Mj(s,s.query),s}function Tj(e,t){let n=/\/{2,9}/g,r=t.replace(n,"/").split("/");return(t.slice(0,1)=="/"||t.length===0)&&r.splice(0,1),t.slice(-1)=="/"&&r.splice(r.length-1,1),r}function Mj(e,t){let n={};return t.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(r,i,s){i&&(n[i]=s)}),n}var el=typeof addEventListener=="function"&&typeof removeEventListener=="function",To=[];el&&addEventListener("offline",()=>{To.forEach(e=>e())},!1);var Pn=class e extends ye{constructor(t,n){if(super(),this.binaryType=Q1,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,t&&typeof t=="object"&&(n=t,t=null),t){let r=or(t);n.hostname=r.host,n.secure=r.protocol==="https"||r.protocol==="wss",n.port=r.port,r.query&&(n.query=r.query)}else n.host&&(n.hostname=or(n.host).host);Rt(this,n),this.secure=n.secure!=null?n.secure:typeof location<"u"&&location.protocol==="https:",n.hostname&&!n.port&&(n.port=this.secure?"443":"80"),this.hostname=n.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=n.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},n.transports.forEach(r=>{let i=r.prototype.name;this.transports.push(i),this._transportsByName[i]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},n),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=t_(this.opts.query)),el&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},To.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=void 0),this._open()}createTransport(t){let n=Object.assign({},this.opts.query);n.EIO=Yc,n.transport=t,this.id&&(n.sid=this.id);let r=Object.assign({},this.opts,{query:n,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[t]);return new this._transportsByName[t](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}let t=this.opts.rememberUpgrade&&e.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";let n=this.createTransport(t);n.open(),this.setTransport(n)}setTransport(t){this.transport&&this.transport.removeAllListeners(),this.transport=t,t.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",n=>this._onClose("transport close",n))}onOpen(){this.readyState="open",e.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(this.emitReserved("packet",t),this.emitReserved("heartbeat"),t.type){case"open":this.onHandshake(JSON.parse(t.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":let n=new Error("server error");n.code=t.data,this._onError(n);break;case"message":this.emitReserved("data",t.data),this.emitReserved("message",t.data);break}}onHandshake(t){this.emitReserved("handshake",t),this.id=t.sid,this.transport.query.sid=t.sid,this._pingInterval=t.pingInterval,this._pingTimeout=t.pingTimeout,this._maxPayload=t.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);let t=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+t,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},t),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){let t=this._getWritablePackets();this.transport.send(t),this._prevBufferLen=t.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let n=1;for(let r=0;r<this.writeBuffer.length;r++){let i=this.writeBuffer[r].data;if(i&&(n+=Z1(i)),r>0&&n>this._maxPayload)return this.writeBuffer.slice(0,r);n+=2}return this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;let t=Date.now()>this._pingTimeoutTime;return t&&(this._pingTimeoutTime=0,Dt(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),t}write(t,n,r){return this._sendPacket("message",t,n,r),this}send(t,n,r){return this._sendPacket("message",t,n,r),this}_sendPacket(t,n,r,i){if(typeof n=="function"&&(i=n,n=void 0),typeof r=="function"&&(i=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;let s={type:t,data:n,options:r};this.emitReserved("packetCreate",s),this.writeBuffer.push(s),i&&this.once("flush",i),this.flush()}close(){let t=()=>{this._onClose("forced close"),this.transport.close()},n=()=>{this.off("upgrade",n),this.off("upgradeError",n),t()},r=()=>{this.once("upgrade",n),this.once("upgradeError",n)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():t()}):this.upgrading?r():t()),this}_onError(t){if(e.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return this.transports.shift(),this._open();this.emitReserved("error",t),this._onClose("transport error",t)}_onClose(t,n){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),el&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){let r=To.indexOf(this._offlineEventListener);r!==-1&&To.splice(r,1)}this.readyState="closed",this.id=null,this.emitReserved("close",t,n),this.writeBuffer=[],this._prevBufferLen=0}}};Pn.protocol=Yc;var Mo=class extends Pn{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade)for(let t=0;t<this._upgrades.length;t++)this._probe(this._upgrades[t])}_probe(t){let n=this.createTransport(t),r=!1;Pn.priorWebsocketSuccess=!1;let i=()=>{r||(n.send([{type:"ping",data:"probe"}]),n.once("packet",f=>{if(!r)if(f.type==="pong"&&f.data==="probe"){if(this.upgrading=!0,this.emitReserved("upgrading",n),!n)return;Pn.priorWebsocketSuccess=n.name==="websocket",this.transport.pause(()=>{r||this.readyState!=="closed"&&(l(),this.setTransport(n),n.send([{type:"upgrade"}]),this.emitReserved("upgrade",n),n=null,this.upgrading=!1,this.flush())})}else{let p=new Error("probe error");p.transport=n.name,this.emitReserved("upgradeError",p)}}))};function s(){r||(r=!0,l(),n.close(),n=null)}let o=f=>{let p=new Error("probe error: "+f);p.transport=n.name,s(),this.emitReserved("upgradeError",p)};function a(){o("transport closed")}function u(){o("socket closed")}function c(f){n&&f.name!==n.name&&s()}let l=()=>{n.removeListener("open",i),n.removeListener("error",o),n.removeListener("close",a),this.off("close",u),this.off("upgrading",c)};n.once("open",i),n.once("error",o),n.once("close",a),this.once("close",u),this.once("upgrading",c),this._upgrades.indexOf("webtransport")!==-1&&t!=="webtransport"?this.setTimeoutFn(()=>{r||n.open()},200):n.open()}onHandshake(t){this._upgrades=this._filterUpgrades(t.upgrades),super.onHandshake(t)}_filterUpgrades(t){let n=[];for(let r=0;r<t.length;r++)~this.transports.indexOf(t[r])&&n.push(t[r]);return n}},ar=class extends Mo{constructor(t,n={}){let r=typeof t=="object"?t:n;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(i=>Zc[i]).filter(i=>!!i)),super(t,r)}};var QG=ar.protocol;function a_(e,t="",n){let r=e;n=n||typeof location<"u"&&location,e==null&&(e=n.protocol+"//"+n.host),typeof e=="string"&&(e.charAt(0)==="/"&&(e.charAt(1)==="/"?e=n.protocol+e:e=n.host+e),/^(https?|wss?):\/\//.test(e)||(typeof n<"u"?e=n.protocol+"//"+e:e="https://"+e),r=or(e)),r.port||(/^(http|ws)$/.test(r.protocol)?r.port="80":/^(http|ws)s$/.test(r.protocol)&&(r.port="443")),r.path=r.path||"/";let s=r.host.indexOf(":")!==-1?"["+r.host+"]":r.host;return r.id=r.protocol+"://"+s+":"+r.port+t,r.href=r.protocol+"://"+s+(n&&n.port===r.port?"":":"+r.port),r}var ol={};ll(ol,{Decoder:()=>il,Encoder:()=>rl,PacketType:()=>X,isPacketValid:()=>Gj,protocol:()=>p_});var Nj=typeof ArrayBuffer=="function",Cj=e=>typeof ArrayBuffer.isView=="function"?ArrayBuffer.isView(e):e.buffer instanceof ArrayBuffer,u_=Object.prototype.toString,qj=typeof Blob=="function"||typeof Blob<"u"&&u_.call(Blob)==="[object BlobConstructor]",jj=typeof File=="function"||typeof File<"u"&&u_.call(File)==="[object FileConstructor]";function ns(e){return Nj&&(e instanceof ArrayBuffer||Cj(e))||qj&&e instanceof Blob||jj&&e instanceof File}function ts(e,t){if(!e||typeof e!="object")return!1;if(Array.isArray(e)){for(let n=0,r=e.length;n<r;n++)if(ts(e[n]))return!0;return!1}if(ns(e))return!0;if(e.toJSON&&typeof e.toJSON=="function"&&arguments.length===1)return ts(e.toJSON(),!0);for(let n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&ts(e[n]))return!0;return!1}function c_(e){let t=[],n=e.data,r=e;return r.data=tl(n,t),r.attachments=t.length,{packet:r,buffers:t}}function tl(e,t){if(!e)return e;if(ns(e)){let n={_placeholder:!0,num:t.length};return t.push(e),n}else if(Array.isArray(e)){let n=new Array(e.length);for(let r=0;r<e.length;r++)n[r]=tl(e[r],t);return n}else if(typeof e=="object"&&!(e instanceof Date)){let n={};for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=tl(e[r],t));return n}return e}function l_(e,t){return e.data=nl(e.data,t),delete e.attachments,e}function nl(e,t){if(!e)return e;if(e&&e._placeholder===!0){if(typeof e.num=="number"&&e.num>=0&&e.num<t.length)return t[e.num];throw new Error("illegal attachments")}else if(Array.isArray(e))for(let n=0;n<e.length;n++)e[n]=nl(e[n],t);else if(typeof e=="object")for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&(e[n]=nl(e[n],t));return e}var f_=["connect","connect_error","disconnect","disconnecting","newListener","removeListener"],p_=5,X;(function(e){e[e.CONNECT=0]="CONNECT",e[e.DISCONNECT=1]="DISCONNECT",e[e.EVENT=2]="EVENT",e[e.ACK=3]="ACK",e[e.CONNECT_ERROR=4]="CONNECT_ERROR",e[e.BINARY_EVENT=5]="BINARY_EVENT",e[e.BINARY_ACK=6]="BINARY_ACK"})(X||(X={}));var rl=class{constructor(t){this.replacer=t}encode(t){return(t.type===X.EVENT||t.type===X.ACK)&&ts(t)?this.encodeAsBinary({type:t.type===X.EVENT?X.BINARY_EVENT:X.BINARY_ACK,nsp:t.nsp,data:t.data,id:t.id}):[this.encodeAsString(t)]}encodeAsString(t){let n=""+t.type;return(t.type===X.BINARY_EVENT||t.type===X.BINARY_ACK)&&(n+=t.attachments+"-"),t.nsp&&t.nsp!=="/"&&(n+=t.nsp+","),t.id!=null&&(n+=t.id),t.data!=null&&(n+=JSON.stringify(t.data,this.replacer)),n}encodeAsBinary(t){let n=c_(t),r=this.encodeAsString(n.packet),i=n.buffers;return i.unshift(r),i}},il=class e extends ye{constructor(t){super(),this.reviver=t}add(t){let n;if(typeof t=="string"){if(this.reconstructor)throw new Error("got plaintext data when reconstructing a packet");n=this.decodeString(t);let r=n.type===X.BINARY_EVENT;r||n.type===X.BINARY_ACK?(n.type=r?X.EVENT:X.ACK,this.reconstructor=new sl(n),n.attachments===0&&super.emitReserved("decoded",n)):super.emitReserved("decoded",n)}else if(ns(t)||t.base64)if(this.reconstructor)n=this.reconstructor.takeBinaryData(t),n&&(this.reconstructor=null,super.emitReserved("decoded",n));else throw new Error("got binary data when not reconstructing a packet");else throw new Error("Unknown type: "+t)}decodeString(t){let n=0,r={type:Number(t.charAt(0))};if(X[r.type]===void 0)throw new Error("unknown packet type "+r.type);if(r.type===X.BINARY_EVENT||r.type===X.BINARY_ACK){let s=n+1;for(;t.charAt(++n)!=="-"&&n!=t.length;);let o=t.substring(s,n);if(o!=Number(o)||t.charAt(n)!=="-")throw new Error("Illegal attachments");r.attachments=Number(o)}if(t.charAt(n+1)==="/"){let s=n+1;for(;++n&&!(t.charAt(n)===","||n===t.length););r.nsp=t.substring(s,n)}else r.nsp="/";let i=t.charAt(n+1);if(i!==""&&Number(i)==i){let s=n+1;for(;++n;){let o=t.charAt(n);if(o==null||Number(o)!=o){--n;break}if(n===t.length)break}r.id=Number(t.substring(s,n+1))}if(t.charAt(++n)){let s=this.tryParse(t.substr(n));if(e.isPayloadValid(r.type,s))r.data=s;else throw new Error("invalid payload")}return r}tryParse(t){try{return JSON.parse(t,this.reviver)}catch{return!1}}static isPayloadValid(t,n){switch(t){case X.CONNECT:return Io(n);case X.DISCONNECT:return n===void 0;case X.CONNECT_ERROR:return typeof n=="string"||Io(n);case X.EVENT:case X.BINARY_EVENT:return Array.isArray(n)&&(typeof n[0]=="number"||typeof n[0]=="string"&&f_.indexOf(n[0])===-1);case X.ACK:case X.BINARY_ACK:return Array.isArray(n)}}destroy(){this.reconstructor&&(this.reconstructor.finishedReconstruction(),this.reconstructor=null)}},sl=class{constructor(t){this.packet=t,this.buffers=[],this.reconPack=t}takeBinaryData(t){if(this.buffers.push(t),this.buffers.length===this.reconPack.attachments){let n=l_(this.reconPack,this.buffers);return this.finishedReconstruction(),n}return null}finishedReconstruction(){this.reconPack=null,this.buffers=[]}};function Dj(e){return typeof e=="string"}var Rj=Number.isInteger||function(e){return typeof e=="number"&&isFinite(e)&&Math.floor(e)===e};function Bj(e){return e===void 0||Rj(e)}function Io(e){return Object.prototype.toString.call(e)==="[object Object]"}function Lj(e,t){switch(e){case X.CONNECT:return t===void 0||Io(t);case X.DISCONNECT:return t===void 0;case X.EVENT:return Array.isArray(t)&&(typeof t[0]=="number"||typeof t[0]=="string"&&f_.indexOf(t[0])===-1);case X.ACK:return Array.isArray(t);case X.CONNECT_ERROR:return typeof t=="string"||Io(t);default:return!1}}function Gj(e){return Dj(e.nsp)&&Bj(e.id)&&Lj(e.type,e.data)}function Qe(e,t,n){return e.on(t,n),function(){e.off(t,n)}}var Fj=Object.freeze({connect:1,connect_error:1,disconnect:1,disconnecting:1,newListener:1,removeListener:1}),ur=class extends ye{constructor(t,n,r){super(),this.connected=!1,this.recovered=!1,this.receiveBuffer=[],this.sendBuffer=[],this._queue=[],this._queueSeq=0,this.ids=0,this.acks={},this.flags={},this.io=t,this.nsp=n,r&&r.auth&&(this.auth=r.auth),this._opts=Object.assign({},r),this.io._autoConnect&&this.open()}get disconnected(){return!this.connected}subEvents(){if(this.subs)return;let t=this.io;this.subs=[Qe(t,"open",this.onopen.bind(this)),Qe(t,"packet",this.onpacket.bind(this)),Qe(t,"error",this.onerror.bind(this)),Qe(t,"close",this.onclose.bind(this))]}get active(){return!!this.subs}connect(){return this.connected?this:(this.subEvents(),this.io._reconnecting||this.io.open(),this.io._readyState==="open"&&this.onopen(),this)}open(){return this.connect()}send(...t){return t.unshift("message"),this.emit.apply(this,t),this}emit(t,...n){var r,i,s;if(Fj.hasOwnProperty(t))throw new Error('"'+t.toString()+'" is a reserved event name');if(n.unshift(t),this._opts.retries&&!this.flags.fromQueue&&!this.flags.volatile)return this._addToQueue(n),this;let o={type:X.EVENT,data:n};if(o.options={},o.options.compress=this.flags.compress!==!1,typeof n[n.length-1]=="function"){let l=this.ids++,f=n.pop();this._registerAckCallback(l,f),o.id=l}let a=(i=(r=this.io.engine)===null||r===void 0?void 0:r.transport)===null||i===void 0?void 0:i.writable,u=this.connected&&!(!((s=this.io.engine)===null||s===void 0)&&s._hasPingExpired());return this.flags.volatile&&!a||(u?(this.notifyOutgoingListeners(o),this.packet(o)):this.sendBuffer.push(o)),this.flags={},this}_registerAckCallback(t,n){var r;let i=(r=this.flags.timeout)!==null&&r!==void 0?r:this._opts.ackTimeout;if(i===void 0){this.acks[t]=n;return}let s=this.io.setTimeoutFn(()=>{delete this.acks[t];for(let a=0;a<this.sendBuffer.length;a++)this.sendBuffer[a].id===t&&this.sendBuffer.splice(a,1);n.call(this,new Error("operation has timed out"))},i),o=(...a)=>{this.io.clearTimeoutFn(s),n.apply(this,a)};o.withError=!0,this.acks[t]=o}emitWithAck(t,...n){return new Promise((r,i)=>{let s=(o,a)=>o?i(o):r(a);s.withError=!0,n.push(s),this.emit(t,...n)})}_addToQueue(t){let n;typeof t[t.length-1]=="function"&&(n=t.pop());let r={id:this._queueSeq++,tryCount:0,pending:!1,args:t,flags:Object.assign({fromQueue:!0},this.flags)};t.push((i,...s)=>(this._queue[0],i!==null?r.tryCount>this._opts.retries&&(this._queue.shift(),n&&n(i)):(this._queue.shift(),n&&n(null,...s)),r.pending=!1,this._drainQueue())),this._queue.push(r),this._drainQueue()}_drainQueue(t=!1){if(!this.connected||this._queue.length===0)return;let n=this._queue[0];n.pending&&!t||(n.pending=!0,n.tryCount++,this.flags=n.flags,this.emit.apply(this,n.args))}packet(t){t.nsp=this.nsp,this.io._packet(t)}onopen(){typeof this.auth=="function"?this.auth(t=>{this._sendConnectPacket(t)}):this._sendConnectPacket(this.auth)}_sendConnectPacket(t){this.packet({type:X.CONNECT,data:this._pid?Object.assign({pid:this._pid,offset:this._lastOffset},t):t})}onerror(t){this.connected||this.emitReserved("connect_error",t)}onclose(t,n){this.connected=!1,delete this.id,this.emitReserved("disconnect",t,n),this._clearAcks()}_clearAcks(){Object.keys(this.acks).forEach(t=>{if(!this.sendBuffer.some(r=>String(r.id)===t)){let r=this.acks[t];delete this.acks[t],r.withError&&r.call(this,new Error("socket has been disconnected"))}})}onpacket(t){if(t.nsp===this.nsp)switch(t.type){case X.CONNECT:t.data&&t.data.sid?this.onconnect(t.data.sid,t.data.pid):this.emitReserved("connect_error",new Error("It seems you are trying to reach a Socket.IO server in v2.x with a v3.x client, but they are not compatible (more information here: https://socket.io/docs/v3/migrating-from-2-x-to-3-0/)"));break;case X.EVENT:case X.BINARY_EVENT:this.onevent(t);break;case X.ACK:case X.BINARY_ACK:this.onack(t);break;case X.DISCONNECT:this.ondisconnect();break;case X.CONNECT_ERROR:this.destroy();let r=new Error(t.data.message);r.data=t.data.data,this.emitReserved("connect_error",r);break}}onevent(t){let n=t.data||[];t.id!=null&&n.push(this.ack(t.id)),this.connected?this.emitEvent(n):this.receiveBuffer.push(Object.freeze(n))}emitEvent(t){if(this._anyListeners&&this._anyListeners.length){let n=this._anyListeners.slice();for(let r of n)r.apply(this,t)}super.emit.apply(this,t),this._pid&&t.length&&typeof t[t.length-1]=="string"&&(this._lastOffset=t[t.length-1])}ack(t){let n=this,r=!1;return function(...i){r||(r=!0,n.packet({type:X.ACK,id:t,data:i}))}}onack(t){let n=this.acks[t.id];typeof n=="function"&&(delete this.acks[t.id],n.withError&&t.data.unshift(null),n.apply(this,t.data))}onconnect(t,n){this.id=t,this.recovered=n&&this._pid===n,this._pid=n,this.connected=!0,this.emitBuffered(),this._drainQueue(!0),this.emitReserved("connect")}emitBuffered(){this.receiveBuffer.forEach(t=>this.emitEvent(t)),this.receiveBuffer=[],this.sendBuffer.forEach(t=>{this.notifyOutgoingListeners(t),this.packet(t)}),this.sendBuffer=[]}ondisconnect(){this.destroy(),this.onclose("io server disconnect")}destroy(){this.subs&&(this.subs.forEach(t=>t()),this.subs=void 0),this.io._destroy(this)}disconnect(){return this.connected&&this.packet({type:X.DISCONNECT}),this.destroy(),this.connected&&this.onclose("io client disconnect"),this}close(){return this.disconnect()}compress(t){return this.flags.compress=t,this}get volatile(){return this.flags.volatile=!0,this}timeout(t){return this.flags.timeout=t,this}onAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.push(t),this}prependAny(t){return this._anyListeners=this._anyListeners||[],this._anyListeners.unshift(t),this}offAny(t){if(!this._anyListeners)return this;if(t){let n=this._anyListeners;for(let r=0;r<n.length;r++)if(t===n[r])return n.splice(r,1),this}else this._anyListeners=[];return this}listenersAny(){return this._anyListeners||[]}onAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.push(t),this}prependAnyOutgoing(t){return this._anyOutgoingListeners=this._anyOutgoingListeners||[],this._anyOutgoingListeners.unshift(t),this}offAnyOutgoing(t){if(!this._anyOutgoingListeners)return this;if(t){let n=this._anyOutgoingListeners;for(let r=0;r<n.length;r++)if(t===n[r])return n.splice(r,1),this}else this._anyOutgoingListeners=[];return this}listenersAnyOutgoing(){return this._anyOutgoingListeners||[]}notifyOutgoingListeners(t){if(this._anyOutgoingListeners&&this._anyOutgoingListeners.length){let n=this._anyOutgoingListeners.slice();for(let r of n)r.apply(this,t.data)}}};function En(e){e=e||{},this.ms=e.min||100,this.max=e.max||1e4,this.factor=e.factor||2,this.jitter=e.jitter>0&&e.jitter<=1?e.jitter:0,this.attempts=0}En.prototype.duration=function(){var e=this.ms*Math.pow(this.factor,this.attempts++);if(this.jitter){var t=Math.random(),n=Math.floor(t*this.jitter*e);e=Math.floor(t*10)&1?e+n:e-n}return Math.min(e,this.max)|0};En.prototype.reset=function(){this.attempts=0};En.prototype.setMin=function(e){this.ms=e};En.prototype.setMax=function(e){this.max=e};En.prototype.setJitter=function(e){this.jitter=e};var cr=class extends ye{constructor(t,n){var r;super(),this.nsps={},this.subs=[],t&&typeof t=="object"&&(n=t,t=void 0),n=n||{},n.path=n.path||"/socket.io",this.opts=n,Rt(this,n),this.reconnection(n.reconnection!==!1),this.reconnectionAttempts(n.reconnectionAttempts||1/0),this.reconnectionDelay(n.reconnectionDelay||1e3),this.reconnectionDelayMax(n.reconnectionDelayMax||5e3),this.randomizationFactor((r=n.randomizationFactor)!==null&&r!==void 0?r:.5),this.backoff=new En({min:this.reconnectionDelay(),max:this.reconnectionDelayMax(),jitter:this.randomizationFactor()}),this.timeout(n.timeout==null?2e4:n.timeout),this._readyState="closed",this.uri=t;let i=n.parser||ol;this.encoder=new i.Encoder,this.decoder=new i.Decoder,this._autoConnect=n.autoConnect!==!1,this._autoConnect&&this.open()}reconnection(t){return arguments.length?(this._reconnection=!!t,t||(this.skipReconnect=!0),this):this._reconnection}reconnectionAttempts(t){return t===void 0?this._reconnectionAttempts:(this._reconnectionAttempts=t,this)}reconnectionDelay(t){var n;return t===void 0?this._reconnectionDelay:(this._reconnectionDelay=t,(n=this.backoff)===null||n===void 0||n.setMin(t),this)}randomizationFactor(t){var n;return t===void 0?this._randomizationFactor:(this._randomizationFactor=t,(n=this.backoff)===null||n===void 0||n.setJitter(t),this)}reconnectionDelayMax(t){var n;return t===void 0?this._reconnectionDelayMax:(this._reconnectionDelayMax=t,(n=this.backoff)===null||n===void 0||n.setMax(t),this)}timeout(t){return arguments.length?(this._timeout=t,this):this._timeout}maybeReconnectOnOpen(){!this._reconnecting&&this._reconnection&&this.backoff.attempts===0&&this.reconnect()}open(t){if(~this._readyState.indexOf("open"))return this;this.engine=new ar(this.uri,this.opts);let n=this.engine,r=this;this._readyState="opening",this.skipReconnect=!1;let i=Qe(n,"open",function(){r.onopen(),t&&t()}),s=a=>{this.cleanup(),this._readyState="closed",this.emitReserved("error",a),t?t(a):this.maybeReconnectOnOpen()},o=Qe(n,"error",s);if(this._timeout!==!1){let a=this._timeout,u=this.setTimeoutFn(()=>{i(),s(new Error("timeout")),n.close()},a);this.opts.autoUnref&&u.unref(),this.subs.push(()=>{this.clearTimeoutFn(u)})}return this.subs.push(i),this.subs.push(o),this}connect(t){return this.open(t)}onopen(){this.cleanup(),this._readyState="open",this.emitReserved("open");let t=this.engine;this.subs.push(Qe(t,"ping",this.onping.bind(this)),Qe(t,"data",this.ondata.bind(this)),Qe(t,"error",this.onerror.bind(this)),Qe(t,"close",this.onclose.bind(this)),Qe(this.decoder,"decoded",this.ondecoded.bind(this)))}onping(){this.emitReserved("ping")}ondata(t){try{this.decoder.add(t)}catch(n){this.onclose("parse error",n)}}ondecoded(t){Dt(()=>{this.emitReserved("packet",t)},this.setTimeoutFn)}onerror(t){this.emitReserved("error",t)}socket(t,n){let r=this.nsps[t];return r?this._autoConnect&&!r.active&&r.connect():(r=new ur(this,t,n),this.nsps[t]=r),r}_destroy(t){let n=Object.keys(this.nsps);for(let r of n)if(this.nsps[r].active)return;this._close()}_packet(t){let n=this.encoder.encode(t);for(let r=0;r<n.length;r++)this.engine.write(n[r],t.options)}cleanup(){this.subs.forEach(t=>t()),this.subs.length=0,this.decoder.destroy()}_close(){this.skipReconnect=!0,this._reconnecting=!1,this.onclose("forced close")}disconnect(){return this._close()}onclose(t,n){var r;this.cleanup(),(r=this.engine)===null||r===void 0||r.close(),this.backoff.reset(),this._readyState="closed",this.emitReserved("close",t,n),this._reconnection&&!this.skipReconnect&&this.reconnect()}reconnect(){if(this._reconnecting||this.skipReconnect)return this;let t=this;if(this.backoff.attempts>=this._reconnectionAttempts)this.backoff.reset(),this.emitReserved("reconnect_failed"),this._reconnecting=!1;else{let n=this.backoff.duration();this._reconnecting=!0;let r=this.setTimeoutFn(()=>{t.skipReconnect||(this.emitReserved("reconnect_attempt",t.backoff.attempts),!t.skipReconnect&&t.open(i=>{i?(t._reconnecting=!1,t.reconnect(),this.emitReserved("reconnect_error",i)):t.onreconnect()}))},n);this.opts.autoUnref&&r.unref(),this.subs.push(()=>{this.clearTimeoutFn(r)})}}onreconnect(){let t=this.backoff.attempts;this._reconnecting=!1,this.backoff.reset(),this.emitReserved("reconnect",t)}};var rs={};function is(e,t){typeof e=="object"&&(t=e,e=void 0),t=t||{};let n=a_(e,t.path||"/socket.io"),r=n.source,i=n.id,s=n.path,o=rs[i]&&s in rs[i].nsps,a=t.forceNew||t["force new connection"]||t.multiplex===!1||o,u;return a?u=new cr(r,t):(rs[i]||(rs[i]=new cr(r,t)),u=rs[i]),n.query&&!t.query&&(t.query=n.queryKey),u.socket(n.path,t)}Object.assign(is,{Manager:cr,Socket:ur,io:is,connect:is});var h_=is,al=class extends ir{constructor({socket:t,socketOpts:n,server:r,...i}){super(i),this.server=r,this.socket=t,this.socketOpts=n}sendAction(t,n){let r=[n,t._stateID,this.matchID,this.playerID];this.socket.emit("update",...r)}sendChatMessage(t,n){let r=[t,n,this.credentials];this.socket.emit("chat",...r)}connect(){if(!this.socket)if(this.server){let t=this.server;t.search(/^https?:\/\//)==-1&&(t="http://"+this.server),t.slice(-1)!="/"&&(t=t+"/"),this.socket=h_(t+this.gameName,this.socketOpts)}else this.socket=h_("/"+this.gameName,this.socketOpts);this.socket.on("patch",(t,n,r,i,s)=>{this.notifyClient({type:"patch",args:[t,n,r,i,s]})}),this.socket.on("update",(t,n,r)=>{this.notifyClient({type:"update",args:[t,n,r]})}),this.socket.on("sync",(t,n)=>{this.notifyClient({type:"sync",args:[t,n]})}),this.socket.on("matchData",(t,n)=>{this.notifyClient({type:"matchData",args:[t,n]})}),this.socket.on("chat",(t,n)=>{this.notifyClient({type:"chat",args:[t,n]})}),this.socket.on("connect",()=>{this.requestSync(),this.setConnectionStatus(!0)}),this.socket.on("disconnect",()=>{this.setConnectionStatus(!1)})}disconnect(){this.socket.close(),this.socket=null,this.setConnectionStatus(!1)}requestSync(){if(this.socket){let t=[this.matchID,this.playerID,this.credentials,this.numPlayers];this.socket.emit("sync",...t)}}updateMatchID(t){this.matchID=t,this.requestSync()}updatePlayerID(t){this.playerID=t,this.requestSync()}updateCredentials(t){this.credentials=t,this.requestSync()}};function ul({server:e,socketOpts:t}={}){return n=>new al({server:e,socketOpts:t,...n})}var G9=he(tn()),F9=he(qi());function No(e){if(e?.arguments){let t={...e};return t.arguments=Object.entries(t.arguments).reduce((n,[r,i])=>({...n,[r]:i.abstract?i:i.entityId}),{}),JSON.parse(He(t,{deduplicateInstances:!1}))}else return e}var Vj={PlaceNew:["destination"],RemoveEntity:["entity"],MoveEntity:["entity","destination"],TakeFrom:["source","destination"],SetState:["entity","state"]};function lr(e,t){return Vj[t.moveType].filter(n=>t.arguments[n].playerChoice).map(n=>({argName:n,getClickable:n==="state"?()=>t.arguments[n].possibleValues.map(r=>({abstract:!0,...t.arguments[n],value:r})):r=>e.G.bank.findAll(e,t.arguments[n],r)}))}function Co(e,t,n,r){let i=lr(e,t,r).map(s=>s.argName);return{arguments:n.reduce((s,o,a)=>({...s,[i[a]]:o}),{})}}var qo=class{constructor(t){this.options=t,this.game=t.boardgameIOGame||gi(JSON.parse(t.gameRules),t.gameName),t.boardgameIOGame||(this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]},this.optimisticWinner=null)}connect(){let{server:t,numPlayers:n,debug:r={collapseOnLoad:!0,impl:Ki},matchID:i,playerID:s,credentials:o,multiplayer:a=ul({server:t,socketOpts:{transports:["websocket","polling"]}})}=this.options;try{let u=o?{game:this.game,multiplayer:a,matchID:i,playerID:s,credentials:o,numPlayers:n,debug:r}:{game:this.game,numPlayers:n,debug:r};return this.client=Hc(u),this.client.subscribe(()=>this.update()),this.client.start(),this}catch(u){console.error("Failed to join game:",u?.message??u),u?.stack&&console.error(u.stack)}}update(){this.options.onClientUpdate?.()}getState(){let t=this.client?.getState();if(!t)return{};let n=this.options.boardgameIOGame?t:{...t,G:Ft(JSON.stringify(t.G),ht)},r=this.optimisticWinner??n?.ctx?.gameover,i=r?[]:ti(n,this.client);if(this.options.boardgameIOGame)return{state:n,gameover:r,moves:this.client.moves,currentMoves:i};let s=Object.entries(i).reduce((u,[c,l])=>{let f=p=>{this.client.moves[c](No(p))};return f.moveInstance=l.moveInstance,{...u,[c]:f}},{}),{allClickable:o,_possibleMoveMeta:a}=Kj(n,s,this.moveBuilder);return{state:n,gameover:r,allClickable:o,_wrappedMoves:s,_possibleMoveMeta:a}}doStep(t){if(this.options.boardgameIOGame)return;let{state:n,_wrappedMoves:r,_possibleMoveMeta:i}=this.getState(),s=t.abstract?t:n.G.bank.locate(t.entityId),o=Object.entries(i).filter(([u,c])=>!zj(c.clickableForMove,s)).map(([u])=>u).concat(this.moveBuilder.eliminatedMoves);if(o.length===Object.keys(r).length){console.error("invalid move with target:",s?.rule);return}let a=Object.entries(i).filter(([u])=>!o.includes(u));if(Hj(n,r,a,this.moveBuilder.stepIndex)){let[u]=a[0],c=r[u],l=Co(n,c.moveInstance.rule,[...this.moveBuilder.targets,s],{moveInstance:c.moveInstance});this.optimisticWinner=Wj(n,this.game,c.moveInstance,l),c(l),this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]}}else this.moveBuilder={eliminatedMoves:o,stepIndex:this.moveBuilder.stepIndex+1,targets:[...this.moveBuilder.targets,s]};this.update()}reset(){this.options.boardgameIOGame||(this.moveBuilder={targets:[],stepIndex:0,eliminatedMoves:[]},this.optimisticWinner=null,this.update())}undoStep(){this.options.boardgameIOGame||(this.moveBuilder.targets.length&&(this.moveBuilder={targets:this.moveBuilder.targets.slice(0,-1),stepIndex:Math.max(0,this.moveBuilder.stepIndex-1),eliminatedMoves:[]}),this.update())}};function zj(e,t){return t.abstract?[...e].some(n=>n.abstract&&n.value===t.value):e.has(t)}function Kj(e,t,n){let{eliminatedMoves:r,stepIndex:i}=n,s={},o=new Set;return Object.entries(t).filter(([a])=>!r.includes(a)).forEach(([a,u])=>{let c=pe(e,{...u.moveInstance.rule,moveName:a}),l={moveInstance:u.moveInstance,moveArguments:c.arguments},f=n.targets.map(m=>m.abstract?m:e.G.bank.locate(m.entityId)),p=Co(e,c,f,l);l.moveArguments={...l.moveArguments,...p.arguments};let h=ke(e,c,{},l).conditionsAreMet,d=lr(e,c),y=new Set(h&&d?.[i]?.getClickable(l)||[]);s[a]={clickableForMove:y},y.forEach(m=>o.add(m))}),{_possibleMoveMeta:s,allClickable:o}}function Hj(e,t,n,r){return n.length===1&&lr(e,t[n[0][0]].moveInstance.rule).length===r+1}function Wj(e,t,n,r){let i=Zr(e,No(r),{moveInstance:n});return t.endIf?.({...e,G:JSON.parse(He(i))})}return w_(Jj);})();
|
|
33
33
|
/*! Bundled license information:
|
|
34
34
|
|
|
35
35
|
expr-eval/dist/index.mjs:
|