boardgame.io
Version:
library for turn-based games
1 lines • 155 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e=e||self).BoardgameIO={})}(this,(function(e){"use strict";let t=(e=21)=>{let t="",n=e;for(;n--;)t+="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict"[64*Math.random()|0];return t};function n(){}const r=e=>e;function a(e,t){for(const n in t)e[n]=t[n];return e}function o(e){return e()}function i(){return Object.create(null)}function s(e){e.forEach(o)}function l(e){return"function"==typeof e}function c(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function u(e,...t){if(null==e)return n;const r=e.subscribe(...t);return r.unsubscribe?()=>r.unsubscribe():r}function d(e,t,n){e.$$.on_destroy.push(u(t,n))}function f(e,t,n,r){return e[1]&&r?a(n.ctx.slice(),e[1](r(t))):n.ctx}function p(e){const t={};for(const n in e)"$"!==n[0]&&(t[n]=e[n]);return t}function g(e){return null==e?"":e}const v="undefined"!=typeof window;let h=v?()=>window.performance.now():()=>Date.now(),m=v?e=>requestAnimationFrame(e):n;const y=new Set;function b(e){y.forEach(t=>{t.c(e)||(y.delete(t),t.f())}),0!==y.size&&m(b)}function $(e){let t;return 0===y.size&&m(b),{promise:new Promise(n=>{y.add(t={c:e,f:n})}),abort(){y.delete(t)}}}function x(e,t){e.appendChild(t)}function P(e,t,n){const r=w(e);if(!r.getElementById(t)){const e=A("style");e.id=t,e.textContent=n,E(r,e)}}function w(e){if(!e)return document;const t=e.getRootNode?e.getRootNode():e.ownerDocument;return t&&t.host?t:e.ownerDocument}function k(e){const t=A("style");return E(w(e),t),t.sheet}function E(e,t){x(e.head||e,t)}function O(e,t,n){e.insertBefore(t,n||null)}function I(e){e.parentNode.removeChild(e)}function _(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 S(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function D(e){return document.createTextNode(e)}function M(){return D(" ")}function j(){return D("")}function N(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function T(e){return function(t){return t.stopPropagation(),e.call(this,t)}}function C(e,t,n){null==n?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function G(e,t){t=""+t,e.wholeText!==t&&(e.data=t)}function z(e,t){e.value=null==t?"":t}function q(e,t){for(let n=0;n<e.options.length;n+=1){const r=e.options[n];if(r.__value===t)return void(r.selected=!0)}e.selectedIndex=-1}function V(e){const t=e.querySelector(":checked")||e.options[0];return t&&t.__value}function R(e,t,n){e.classList[n?"add":"remove"](t)}function B(e,t,{bubbles:n=!1,cancelable:r=!1}={}){const a=document.createEvent("CustomEvent");return a.initCustomEvent(e,n,r,t),a}const U=new Map;let F,L=0;function J(e,t,n,r,a,o,i,s=0){const l=16.666/r;let c="{\n";for(let e=0;e<=1;e+=l){const r=t+(n-t)*o(e);c+=100*e+`%{${i(r,1-r)}}\n`}const u=c+`100% {${i(n,1-n)}}\n}`,d=`__svelte_${function(e){let t=5381,n=e.length;for(;n--;)t=(t<<5)-t^e.charCodeAt(n);return t>>>0}(u)}_${s}`,f=w(e),{stylesheet:p,rules:g}=U.get(f)||function(e,t){const n={stylesheet:k(t),rules:{}};return U.set(e,n),n}(f,e);g[d]||(g[d]=!0,p.insertRule(`@keyframes ${d} ${u}`,p.cssRules.length));const v=e.style.animation||"";return e.style.animation=`${v?v+", ":""}${d} ${r}ms linear ${a}ms 1 both`,L+=1,d}function K(e,t){const n=(e.style.animation||"").split(", "),r=n.filter(t?e=>e.indexOf(t)<0:e=>-1===e.indexOf("__svelte")),a=n.length-r.length;a&&(e.style.animation=r.join(", "),L-=a,L||m(()=>{L||(U.forEach(e=>{const{stylesheet:t}=e;let n=t.cssRules.length;for(;n--;)t.deleteRule(n);e.rules={}}),U.clear())}))}function H(e){F=e}function W(){if(!F)throw new Error("Function called outside component initialization");return F}function Z(e){W().$$.on_destroy.push(e)}function Y(){const e=W();return(t,n,{cancelable:r=!1}={})=>{const a=e.$$.callbacks[t];if(a){const o=B(t,n,{cancelable:r});return a.slice().forEach(t=>{t.call(e,o)}),!o.defaultPrevented}return!0}}function X(e,t){return W().$$.context.set(e,t),t}function Q(e){return W().$$.context.get(e)}function ee(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(e=>e.call(this,t))}const te=[],ne=[],re=[],ae=[],oe=Promise.resolve();let ie=!1;function se(e){re.push(e)}const le=new Set;let ce,ue=0;function de(){const e=F;do{for(;ue<te.length;){const e=te[ue];ue++,H(e),fe(e.$$)}for(H(null),te.length=0,ue=0;ne.length;)ne.pop()();for(let e=0;e<re.length;e+=1){const t=re[e];le.has(t)||(le.add(t),t())}re.length=0}while(te.length);for(;ae.length;)ae.pop()();ie=!1,le.clear(),H(e)}function fe(e){if(null!==e.fragment){e.update(),s(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(se)}}function pe(){return ce||(ce=Promise.resolve(),ce.then(()=>{ce=null})),ce}function ge(e,t,n){e.dispatchEvent(B(`${t?"intro":"outro"}${n}`))}const ve=new Set;let he;function me(){he={r:0,c:[],p:he}}function ye(){he.r||s(he.c),he=he.p}function be(e,t){e&&e.i&&(ve.delete(e),e.i(t))}function $e(e,t,n,r){if(e&&e.o){if(ve.has(e))return;ve.add(e),he.c.push(()=>{ve.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}else r&&r()}const xe={duration:0};function Pe(e,t,a){let o,i,s=t(e,a),c=!1,u=0;function d(){o&&K(e,o)}function f(){const{delay:t=0,duration:a=300,easing:l=r,tick:f=n,css:p}=s||xe;p&&(o=J(e,0,1,a,t,l,p,u++)),f(0,1);const g=h()+t,v=g+a;i&&i.abort(),c=!0,se(()=>ge(e,!0,"start")),i=$(t=>{if(c){if(t>=v)return f(1,0),ge(e,!0,"end"),d(),c=!1;if(t>=g){const e=l((t-g)/a);f(e,1-e)}}return c})}let p=!1;return{start(){p||(p=!0,K(e),l(s)?(s=s(),pe().then(f)):f())},invalidate(){p=!1},end(){c&&(d(),c=!1)}}}function we(e,t,a){let o,i=t(e,a),c=!0;const u=he;function d(){const{delay:t=0,duration:a=300,easing:l=r,tick:d=n,css:f}=i||xe;f&&(o=J(e,1,0,a,t,l,f));const p=h()+t,g=p+a;se(()=>ge(e,!1,"start")),$(t=>{if(c){if(t>=g)return d(0,1),ge(e,!1,"end"),--u.r||s(u.c),!1;if(t>=p){const e=l((t-p)/a);d(1-e,e)}}return c})}return u.r+=1,l(i)?pe().then(()=>{i=i(),d()}):d(),{end(t){t&&i.tick&&i.tick(1,0),c&&(o&&K(e,o),c=!1)}}}function ke(e,t,a,o){let i=t(e,a),c=o?0:1,u=null,d=null,f=null;function p(){f&&K(e,f)}function g(e,t){const n=e.b-c;return t*=Math.abs(n),{a:c,b:e.b,d:n,duration:t,start:e.start,end:e.start+t,group:e.group}}function v(t){const{delay:a=0,duration:o=300,easing:l=r,tick:v=n,css:m}=i||xe,y={start:h()+a,b:t};t||(y.group=he,he.r+=1),u||d?d=y:(m&&(p(),f=J(e,c,t,o,a,l,m)),t&&v(0,1),u=g(y,o),se(()=>ge(e,t,"start")),$(t=>{if(d&&t>d.start&&(u=g(d,o),d=null,ge(e,u.b,"start"),m&&(p(),f=J(e,c,u.b,u.duration,0,l,i.css))),u)if(t>=u.end)v(c=u.b,1-c),ge(e,u.b,"end"),d||(u.b?p():--u.group.r||s(u.group.c)),u=null;else if(t>=u.start){const e=t-u.start;c=u.a+u.d*l(e/u.duration),v(c,1-c)}return!(!u&&!d)}))}return{run(e){l(i)?pe().then(()=>{i=i(),v(e)}):v(e)},end(){p(),u=d=null}}}function Ee(e,t){const n={},r={},a={$$scope:1};let o=e.length;for(;o--;){const i=e[o],s=t[o];if(s){for(const e in i)e in s||(r[e]=1);for(const e in s)a[e]||(n[e]=s[e],a[e]=1);e[o]=s}else for(const e in i)a[e]=1}for(const e in r)e in n||(n[e]=void 0);return n}function Oe(e){return"object"==typeof e&&null!==e?e:{}}function Ie(e){e&&e.c()}function _e(e,t,n,r){const{fragment:a,on_mount:i,on_destroy:c,after_update:u}=e.$$;a&&a.m(t,n),r||se(()=>{const t=i.map(o).filter(l);c?c.push(...t):s(t),e.$$.on_mount=[]}),u.forEach(se)}function Ae(e,t){const n=e.$$;null!==n.fragment&&(s(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function Se(e,t){-1===e.$$.dirty[0]&&(te.push(e),ie||(ie=!0,oe.then(de)),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function De(e,t,r,a,o,l,c,u=[-1]){const d=F;H(e);const f=e.$$={fragment:null,ctx:null,props:l,update:n,not_equal:o,bound:i(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(d?d.$$.context:[])),callbacks:i(),dirty:u,skip_bound:!1,root:t.target||d.$$.root};c&&c(f.root);let p=!1;if(f.ctx=r?r(e,t.props||{},(t,n,...r)=>{const a=r.length?r[0]:n;return f.ctx&&o(f.ctx[t],f.ctx[t]=a)&&(!f.skip_bound&&f.bound[t]&&f.bound[t](a),p&&Se(e,t)),n}):[],f.update(),p=!0,s(f.before_update),f.fragment=!!a&&a(f.ctx),t.target){if(t.hydrate){const e=function(e){return Array.from(e.childNodes)}(t.target);f.fragment&&f.fragment.l(e),e.forEach(I)}else f.fragment&&f.fragment.c();t.intro&&be(e.$$.fragment),_e(e,t.target,t.anchor,t.customElement),de()}H(d)}class Me{$destroy(){Ae(this,1),this.$destroy=n}$on(e,t){const n=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return n.push(t),()=>{const e=n.indexOf(t);-1!==e&&n.splice(e,1)}}$set(e){var t;this.$$set&&(t=e,0!==Object.keys(t).length)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}function je(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Ne(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function Te(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Ne(Object(n),!0).forEach((function(t){je(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Ne(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function Ce(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 Ge="function"==typeof Symbol&&Symbol.observable||"@@observable",ze=function(){return Math.random().toString(36).substring(7).split("").join(".")},qe={INIT:"@@redux/INIT"+ze(),REPLACE:"@@redux/REPLACE"+ze(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+ze()}};function Ve(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Re(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(Ce(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(Ce(1));return n(Re)(e,t)}if("function"!=typeof e)throw new Error(Ce(2));var a=e,o=t,i=[],s=i,l=!1;function c(){s===i&&(s=i.slice())}function u(){if(l)throw new Error(Ce(3));return o}function d(e){if("function"!=typeof e)throw new Error(Ce(4));if(l)throw new Error(Ce(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(Ce(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),i=null}}}function f(e){if(!Ve(e))throw new Error(Ce(7));if(void 0===e.type)throw new Error(Ce(8));if(l)throw new Error(Ce(9));try{l=!0,o=a(o,e)}finally{l=!1}for(var t=i=s,n=0;n<t.length;n++){(0,t[n])()}return e}function p(e){if("function"!=typeof e)throw new Error(Ce(10));a=e,f({type:qe.REPLACE})}function g(){var e,t=d;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(Ce(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[Ge]=function(){return this},e}return f({type:qe.INIT}),(r={dispatch:f,subscribe:d,getState:u,replaceReducer:p})[Ge]=g,r}function Be(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}const Ue=(e,t,n,r)=>({type:"MAKE_MOVE",payload:{type:e,args:t,playerID:n,credentials:r}}),Fe=(e,t,n,r)=>({type:"GAME_EVENT",payload:{type:e,args:t,playerID:n,credentials:r}}),Le=(e,t,n,r)=>({type:"GAME_EVENT",payload:{type:e,args:t,playerID:n,credentials:r},automatic:!0}),Je=e=>({type:"SYNC",state:e.state,log:e.log,initialState:e.initialState,clientOnly:!0}),Ke=(e,t,n,r)=>({type:"PATCH",prevStateID:e,stateID:t,patch:n,deltalog:r,clientOnly:!0}),He=(e,t)=>({type:"UPDATE",state:e,deltalog:t,clientOnly:!0}),We=e=>({type:"RESET",state:e,clientOnly:!0}),Ze=(e,t)=>({type:"UNDO",payload:{type:null,args:null,playerID:e,credentials:t}}),Ye=(e,t)=>({type:"REDO",payload:{type:null,args:null,playerID:e,credentials:t}}),Xe=()=>({type:"STRIP_TRANSIENTS"});var Qe=Object.freeze({__proto__:null,makeMove:Ue,gameEvent:Fe,automaticGameEvent:Le,sync:Je,patch:Ke,update:He,reset:We,undo:Ze,redo:Ye,plugin:(e,t,n,r)=>({type:"PLUGIN",payload:{type:e,args:t,playerID:n,credentials:r}}),stripTransients:Xe});function et(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];throw Error("[Immer] minified error nr: "+e+(n.length?" "+n.map((function(e){return"'"+e+"'"})).join(","):"")+". Find the full error at: https://bit.ly/3cXEKWf")}function tt(e){return!!e&&!!e[Vt]}function nt(e){return!!e&&(function(e){if(!e||"object"!=typeof e)return!1;var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;return n===Object||"function"==typeof n&&Function.toString.call(n)===Rt}(e)||Array.isArray(e)||!!e[qt]||!!e.constructor[qt]||st(e)||lt(e))}function rt(e,t,n){void 0===n&&(n=!1),0===at(e)?(n?Object.keys:Bt)(e).forEach((function(r){n&&"symbol"==typeof r||t(r,e[r],e)})):e.forEach((function(n,r){return t(r,n,e)}))}function at(e){var t=e[Vt];return t?t.i>3?t.i-4:t.i:Array.isArray(e)?1:st(e)?2:lt(e)?3:0}function ot(e,t){return 2===at(e)?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function it(e,t,n){var r=at(e);2===r?e.set(t,n):3===r?(e.delete(t),e.add(n)):e[t]=n}function st(e){return Tt&&e instanceof Map}function lt(e){return Ct&&e instanceof Set}function ct(e){return e.o||e.t}function ut(e){if(Array.isArray(e))return Array.prototype.slice.call(e);var t=Ut(e);delete t[Vt];for(var n=Bt(t),r=0;r<n.length;r++){var a=n[r],o=t[a];!1===o.writable&&(o.writable=!0,o.configurable=!0),(o.get||o.set)&&(t[a]={configurable:!0,writable:!0,enumerable:o.enumerable,value:e[a]})}return Object.create(Object.getPrototypeOf(e),t)}function dt(e,t){return void 0===t&&(t=!1),pt(e)||tt(e)||!nt(e)||(at(e)>1&&(e.set=e.add=e.clear=e.delete=ft),Object.freeze(e),t&&rt(e,(function(e,t){return dt(t,!0)}),!0)),e}function ft(){et(2)}function pt(e){return null==e||"object"!=typeof e||Object.isFrozen(e)}function gt(e){var t=Ft[e];return t||et(18,e),t}function vt(){return jt}function ht(e,t){t&&(gt("Patches"),e.u=[],e.s=[],e.v=t)}function mt(e){yt(e),e.p.forEach($t),e.p=null}function yt(e){e===jt&&(jt=e.l)}function bt(e){return jt={p:[],l:jt,h:e,m:!0,_:0}}function $t(e){var t=e[Vt];0===t.i||1===t.i?t.j():t.O=!0}function xt(e,t){t._=t.p.length;var n=t.p[0],r=void 0!==e&&e!==n;return t.h.g||gt("ES5").S(t,e,r),r?(n[Vt].P&&(mt(t),et(4)),nt(e)&&(e=Pt(t,e),t.l||kt(t,e)),t.u&>("Patches").M(n[Vt],e,t.u,t.s)):e=Pt(t,n,[]),mt(t),t.u&&t.v(t.u,t.s),e!==zt?e:void 0}function Pt(e,t,n){if(pt(t))return t;var r=t[Vt];if(!r)return rt(t,(function(a,o){return wt(e,r,t,a,o,n)}),!0),t;if(r.A!==e)return t;if(!r.P)return kt(e,r.t,!0),r.t;if(!r.I){r.I=!0,r.A._--;var a=4===r.i||5===r.i?r.o=ut(r.k):r.o;rt(3===r.i?new Set(a):a,(function(t,o){return wt(e,r,a,t,o,n)})),kt(e,a,!1),n&&e.u&>("Patches").R(r,n,e.u,e.s)}return r.o}function wt(e,t,n,r,a,o){if(tt(a)){var i=Pt(e,a,o&&t&&3!==t.i&&!ot(t.D,r)?o.concat(r):void 0);if(it(n,r,i),!tt(i))return;e.m=!1}if(nt(a)&&!pt(a)){if(!e.h.F&&e._<1)return;Pt(e,a),t&&t.A.l||kt(e,a)}}function kt(e,t,n){void 0===n&&(n=!1),e.h.F&&e.m&&dt(t,n)}function Et(e,t){var n=e[Vt];return(n?ct(n):e)[t]}function Ot(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 It(e){e.P||(e.P=!0,e.l&&It(e.l))}function _t(e){e.o||(e.o=ut(e.t))}function At(e,t,n){var r=st(t)?gt("MapSet").N(t,n):lt(t)?gt("MapSet").T(t,n):e.g?function(e,t){var n=Array.isArray(e),r={i:n?1:0,A:t?t.A:vt(),P:!1,I:!1,D:{},l:t,t:e,k:null,o:null,j:null,C:!1},a=r,o=Lt;n&&(a=[r],o=Jt);var i=Proxy.revocable(a,o),s=i.revoke,l=i.proxy;return r.k=l,r.j=s,l}(t,n):gt("ES5").J(t,n);return(n?n.A:vt()).p.push(r),r}function St(e){return tt(e)||et(22,e),function e(t){if(!nt(t))return t;var n,r=t[Vt],a=at(t);if(r){if(!r.P&&(r.i<4||!gt("ES5").K(r)))return r.t;r.I=!0,n=Dt(t,a),r.I=!1}else n=Dt(t,a);return rt(n,(function(t,a){r&&function(e,t){return 2===at(e)?e.get(t):e[t]}(r.t,t)===a||it(n,t,e(a))})),3===a?new Set(n):n}(e)}function Dt(e,t){switch(t){case 2:return new Map(e);case 3:return Array.from(e)}return ut(e)}var Mt,jt,Nt="undefined"!=typeof Symbol&&"symbol"==typeof Symbol("x"),Tt="undefined"!=typeof Map,Ct="undefined"!=typeof Set,Gt="undefined"!=typeof Proxy&&void 0!==Proxy.revocable&&"undefined"!=typeof Reflect,zt=Nt?Symbol.for("immer-nothing"):((Mt={})["immer-nothing"]=!0,Mt),qt=Nt?Symbol.for("immer-draftable"):"__$immer_draftable",Vt=Nt?Symbol.for("immer-state"):"__$immer_state",Rt=""+Object.prototype.constructor,Bt="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames,Ut=Object.getOwnPropertyDescriptors||function(e){var t={};return Bt(e).forEach((function(n){t[n]=Object.getOwnPropertyDescriptor(e,n)})),t},Ft={},Lt={get:function(e,t){if(t===Vt)return e;var n=ct(e);if(!ot(n,t))return function(e,t,n){var r,a=Ot(t,n);return a?"value"in a?a.value:null===(r=a.get)||void 0===r?void 0:r.call(e.k):void 0}(e,n,t);var r=n[t];return e.I||!nt(r)?r:r===Et(e.t,t)?(_t(e),e.o[t]=At(e.A.h,r,e)):r},has:function(e,t){return t in ct(e)},ownKeys:function(e){return Reflect.ownKeys(ct(e))},set:function(e,t,n){var r=Ot(ct(e),t);if(null==r?void 0:r.set)return r.set.call(e.k,n),!0;if(!e.P){var a=Et(ct(e),t),o=null==a?void 0:a[Vt];if(o&&o.t===n)return e.o[t]=n,e.D[t]=!1,!0;if(function(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}(n,a)&&(void 0!==n||ot(e.t,t)))return!0;_t(e),It(e)}return e.o[t]===n&&"number"!=typeof n&&(void 0!==n||t in e.o)||(e.o[t]=n,e.D[t]=!0,!0)},deleteProperty:function(e,t){return void 0!==Et(e.t,t)||t in e.t?(e.D[t]=!1,_t(e),It(e)):delete e.D[t],e.o&&delete e.o[t],!0},getOwnPropertyDescriptor:function(e,t){var n=ct(e),r=Reflect.getOwnPropertyDescriptor(n,t);return r?{writable:!0,configurable:1!==e.i||"length"!==t,enumerable:r.enumerable,value:n[t]}:r},defineProperty:function(){et(11)},getPrototypeOf:function(e){return Object.getPrototypeOf(e.t)},setPrototypeOf:function(){et(12)}},Jt={};rt(Lt,(function(e,t){Jt[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),Jt.deleteProperty=function(e,t){return Lt.deleteProperty.call(this,e[0],t)},Jt.set=function(e,t,n){return Lt.set.call(this,e[0],t,n,e[0])};var Kt=new(function(){function e(e){var t=this;this.g=Gt,this.F=!0,this.produce=function(e,n,r){if("function"==typeof e&&"function"!=typeof n){var a=n;n=e;var o=t;return function(e){var t=this;void 0===e&&(e=a);for(var r=arguments.length,i=Array(r>1?r-1:0),s=1;s<r;s++)i[s-1]=arguments[s];return o.produce(e,(function(e){var r;return(r=n).call.apply(r,[t,e].concat(i))}))}}var i;if("function"!=typeof n&&et(6),void 0!==r&&"function"!=typeof r&&et(7),nt(e)){var s=bt(t),l=At(t,e,void 0),c=!0;try{i=n(l),c=!1}finally{c?mt(s):yt(s)}return"undefined"!=typeof Promise&&i instanceof Promise?i.then((function(e){return ht(s,r),xt(e,s)}),(function(e){throw mt(s),e})):(ht(s,r),xt(i,s))}if(!e||"object"!=typeof e){if((i=n(e))===zt)return;return void 0===i&&(i=e),t.F&&dt(i,!0),i}et(21,e)},this.produceWithPatches=function(e,n){return"function"==typeof e?function(n){for(var r=arguments.length,a=Array(r>1?r-1:0),o=1;o<r;o++)a[o-1]=arguments[o];return t.produceWithPatches(n,(function(t){return e.apply(void 0,[t].concat(a))}))}:[t.produce(e,n,(function(e,t){r=e,a=t})),r,a];var r,a},"boolean"==typeof(null==e?void 0:e.useProxies)&&this.setUseProxies(e.useProxies),"boolean"==typeof(null==e?void 0:e.autoFreeze)&&this.setAutoFreeze(e.autoFreeze)}var t=e.prototype;return t.createDraft=function(e){nt(e)||et(8),tt(e)&&(e=St(e));var t=bt(this),n=At(this,e,void 0);return n[Vt].C=!0,yt(t),n},t.finishDraft=function(e,t){var n=(e&&e[Vt]).A;return ht(n,t),xt(void 0,n)},t.setAutoFreeze=function(e){this.F=e},t.setUseProxies=function(e){e&&!Gt&&et(20),this.g=e},t.applyPatches=function(e,t){var n;for(n=t.length-1;n>=0;n--){var r=t[n];if(0===r.path.length&&"replace"===r.op){e=r.value;break}}var a=gt("Patches").$;return tt(e)?a(e,t):this.produce(e,(function(e){return a(e,t.slice(n+1))}))},e}()),Ht=Kt.produce;Kt.produceWithPatches.bind(Kt),Kt.setAutoFreeze.bind(Kt),Kt.setUseProxies.bind(Kt),Kt.applyPatches.bind(Kt),Kt.createDraft.bind(Kt),Kt.finishDraft.bind(Kt);const Wt={name:"plugin-immer",fnWrap:e=>(t,...n)=>{let r=!1;const a=Ht(t.G,a=>{const o=e({...t,G:a},...n);if("INVALID_MOVE"!==o)return o;r=!0});return r?"INVALID_MOVE":a}};class Zt{constructor(e){const t=function(){let e=4022871197;return function(t){const n=t.toString();for(let t=0;t<n.length;t++){e+=n.charCodeAt(t);let r=.02519603282416938*e;e=r>>>0,r-=e,r*=e,e=r>>>0,r-=e,e+=4294967296*r}return 2.3283064365386963e-10*(e>>>0)}}();this.c=1,this.s0=t(" "),this.s1=t(" "),this.s2=t(" "),this.s0-=t(e),this.s0<0&&(this.s0+=1),this.s1-=t(e),this.s1<0&&(this.s1+=1),this.s2-=t(e),this.s2<0&&(this.s2+=1)}next(){const e=2091639*this.s0+2.3283064365386963e-10*this.c;return this.s0=this.s1,this.s1=this.s2,this.s2=e-(this.c=Math.trunc(e))}}function Yt(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function Xt(e,t){const n=new Zt(e),r=n.next.bind(n);return t&&Yt(t,n),r.state=()=>Yt(n,{}),r}class Qt{constructor(e){this.state=e||{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;const e=this.state,t=Xt(e.prngstate?"":e.seed,e.prngstate),n=t();return this.state={...e,prngstate:t.state()},n}api(){const e=this._random.bind(this),t={D4:4,D6:6,D8:8,D10:10,D12:12,D20:20},n={};for(const r in t){const a=t[r];n[r]=t=>void 0===t?Math.floor(e()*a)+1:Array.from({length:t}).map(()=>Math.floor(e()*a)+1)}return{...n,Die:function(t=6,n){return void 0===n?Math.floor(e()*t)+1:Array.from({length:n}).map(()=>Math.floor(e()*t)+1)},Number:()=>e(),Shuffle:t=>{const n=[...t];let r=t.length,a=0;const o=Array.from({length:r});for(;r;){const t=Math.trunc(r*e());o[a++]=n[t],n[t]=n[--r]}return o},_private:this}}}const en={name:"random",noClient:({api:e})=>e._private.isUsed(),flush:({api:e})=>e._private.getState(),api:({data:e})=>new Qt(e).api(),setup:({game:e})=>{let{seed:t}=e;return void 0===t&&(t=Qt.seed()),{seed:t}},playerView:()=>{}};var tn,nn;!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"}(tn||(tn={})),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 — the turn is already ending.",e.MaxTurnEndings="Maximum number of turn endings exceeded for this update.\nThis likely means game code is triggering an infinite loop.",e.PhaseEventInOnEnd="`setPhase` & `endPhase` are disallowed in a phase’s `onEnd` hook — the phase is already ending.\nIf you’re trying to dynamically choose the next phase when a phase ends, use the phase’s `next` trigger.",e.StageEventInOnEnd="`setStage`, `endStage` & `setActivePlayers` are disallowed in `onEnd` hooks.",e.StageEventInPhaseBegin="`setStage`, `endStage` & `setActivePlayers` are disallowed in a phase’s `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."}(nn||(nn={}));class rn{constructor(e,t,n){this.flow=e,this.playerID=n,this.dispatch=[],this.initialTurn=t.turn,this.updateTurnContext(t,void 0),this.maxEndedTurnsPerAction=100*t.numPlayers}api(){const e={_private:this};for(const t of this.flow.eventNames)e[t]=(...e)=>{this.dispatch.push({type:t,args:e,phase:this.currentPhase,turn:this.currentTurn,calledFrom:this.currentMethod,error:new Error("Events Plugin Error")})};return e}isUsed(){return this.dispatch.length>0}updateTurnContext(e,t){this.currentPhase=e.phase,this.currentTurn=e.turn,this.currentMethod=t}unsetCurrentMethod(){this.currentMethod=void 0}update(e){const t=e,n=({stack:e},n)=>({...t,plugins:{...t.plugins,events:{...t.plugins.events,data:{error:n+"\n"+e}}}});e:for(let t=0;t<this.dispatch.length;t++){const r=this.dispatch[t],a=r.turn!==e.ctx.turn;if(this.currentTurn-this.initialTurn>=this.maxEndedTurnsPerAction)return n(r.error,nn.MaxTurnEndings);if(void 0===r.calledFrom)return n(r.error,nn.CalledOutsideHook);if(e.ctx.gameover)break e;switch(r.type){case"endStage":case"setStage":case"setActivePlayers":switch(r.calledFrom){case tn.TURN_ON_END:case tn.PHASE_ON_END:return n(r.error,nn.StageEventInOnEnd);case tn.PHASE_ON_BEGIN:return n(r.error,nn.StageEventInPhaseBegin);case tn.TURN_ON_BEGIN:if("setActivePlayers"===r.type)break;return n(r.error,nn.StageEventInTurnBegin)}if(a)continue e;break;case"endTurn":if(r.calledFrom===tn.TURN_ON_END||r.calledFrom===tn.PHASE_ON_END)return n(r.error,nn.EndTurnInOnEnd);if(a)continue e;break;case"endPhase":case"setPhase":if(r.calledFrom===tn.PHASE_ON_END)return n(r.error,nn.PhaseEventInOnEnd);if(r.phase!==e.ctx.phase)continue e}const o=Le(r.type,r.args,this.playerID);e=this.flow.processEvent(e,o)}return e}}const an={name:"events",noClient:({api:e})=>e._private.isUsed(),isInvalid:({data:e})=>e.error||!1,fnWrap:(e,t)=>(n,...r)=>{const a=n.events;a&&a._private.updateTurnContext(n.ctx,t);const o=e(n,...r);return a&&a._private.unsetCurrentMethod(),o},dangerouslyFlushRawState:({state:e,api:t})=>t._private.update(e),api:({game:e,ctx:t,playerID:n})=>new rn(e.flow,t,n).api()};var on,sn,ln=Function.prototype,cn=Object.prototype,un=ln.toString,dn=cn.hasOwnProperty,fn=un.call(Object),pn=cn.toString,gn=(on=Object.getPrototypeOf,sn=Object,function(e){return on(sn(e))});var vn=function(e){if(!function(e){return!!e&&"object"==typeof e}(e)||"[object Object]"!=pn.call(e)||function(e){var t=!1;if(null!=e&&"function"!=typeof e.toString)try{t=!!(e+"")}catch(e){}return t}(e))return!1;var t=gn(e);if(null===t)return!0;var n=dn.call(t,"constructor")&&t.constructor;return"function"==typeof n&&n instanceof n&&un.call(n)==fn};function hn(e){((...e)=>{console.log(...e)})("INFO: "+e)}function mn(e){((...e)=>{console.error(...e)})("ERROR:",e)}const yn=[Wt,en,{name:"log",flush:()=>({}),api:({data:e})=>({setMetadata:t=>{e.metadata=t}}),setup:()=>({})},{name:"plugin-serializable",fnWrap:e=>(t,...n)=>{const r=e(t,...n);if(!function e(t){if(null==t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t)return!0;if(!vn(t)&&!Array.isArray(t))return!1;for(const n in t)if(!e(t[n]))return!1;return!0}(r))throw new Error("Move state is not JSON-serialiazable.\nSee https://boardgame.io/documentation/#/?id=state for more information.");return r}}],bn=[...yn,an],$n=({plugins:e})=>Object.entries(e||{}).reduce((e,[t,{api:n}])=>(e[t]=n,e),{}),xn=(e,t,n)=>[...yn,...n,an].filter(e=>void 0!==e.fnWrap).reduce((e,{fnWrap:n})=>n(e,t),e),Pn=(e,t)=>([...bn,...t.game.plugins].filter(e=>void 0!==e.api).forEach(n=>{const r=n.name,a=e.plugins[r]||{data:{}},o=n.api({G:e.G,ctx:e.ctx,data:a.data,game:t.game,playerID:t.playerID});e={...e,plugins:{...e.plugins,[r]:{...a,api:o}}}}),e),wn=(e,t)=>{const n=((e,t)=>([...yn,...t.game.plugins,an].reverse().forEach(n=>{const r=n.name,a=e.plugins[r]||{data:{}};if(n.flush){const r=n.flush({G:e.G,ctx:e.ctx,game:t.game,api:a.api,data:a.data});e={...e,plugins:{...e.plugins,[n.name]:{data:r}}}}else if(n.dangerouslyFlushRawState){const o=(e=n.dangerouslyFlushRawState({state:e,game:t.game,api:a.api,data:a.data})).plugins[r].data;e={...e,plugins:{...e.plugins,[n.name]:{data:o}}}}}),e))(e,t),r=((e,t)=>[...bn,...t.game.plugins].filter(e=>void 0!==e.isInvalid).map(n=>{const{name:r}=n,a=e.plugins[r],o=n.isInvalid({G:e.G,ctx:e.ctx,game:t.game,data:a&&a.data});return!!o&&{plugin:r,message:o}}).find(e=>e)||!1)(n,t);if(!r)return[n];const{plugin:a,message:o}=r;return mn(`${a} plugin declared action invalid:\n${o}`),[e,r]},kn=({G:e,ctx:t,plugins:n={}},{game:r,playerID:a})=>([...bn,...r.plugins].forEach(({name:o,playerView:i})=>{if(!i)return;const{data:s}=n[o]||{data:{}},l=i({G:e,ctx:t,game:r,data:s,playerID:a});n={...n,[o]:{data:l}}}),n);function En(e,t=!1){e.moveLimit&&(t&&(e.minMoves=e.moveLimit),e.maxMoves=e.moveLimit,delete e.moveLimit)}function On(e,t){let n={},r=[],a=null,o={},i={};if(Array.isArray(t)){const e={};t.forEach(t=>e[t]=Sn.NULL),n=e}else{if(En(t),t.next&&(a=t.next),t.revert&&(r=[...e._prevActivePlayers,{activePlayers:e.activePlayers,_activePlayersMinMoves:e._activePlayersMinMoves,_activePlayersMaxMoves:e._activePlayersMaxMoves,_activePlayersNumMoves:e._activePlayersNumMoves}]),void 0!==t.currentPlayer&&In(n,o,i,e.currentPlayer,t.currentPlayer),void 0!==t.others)for(let r=0;r<e.playOrder.length;r++){const a=e.playOrder[r];a!==e.currentPlayer&&In(n,o,i,a,t.others)}if(void 0!==t.all)for(let r=0;r<e.playOrder.length;r++){In(n,o,i,e.playOrder[r],t.all)}if(t.value)for(const e in t.value)In(n,o,i,e,t.value[e]);if(t.minMoves)for(const e in n)void 0===o[e]&&(o[e]=t.minMoves);if(t.maxMoves)for(const e in n)void 0===i[e]&&(i[e]=t.maxMoves)}0===Object.keys(n).length&&(n=null),0===Object.keys(o).length&&(o=null),0===Object.keys(i).length&&(i=null);const s={};for(const e in n)s[e]=0;return{...e,activePlayers:n,_activePlayersMinMoves:o,_activePlayersMaxMoves:i,_activePlayersNumMoves:s,_prevActivePlayers:r,_nextActivePlayers:a}}function In(e,t,n,r,a){"object"==typeof a&&a!==Sn.NULL||(a={stage:a}),void 0!==a.stage&&(En(a),e[r]=a.stage,a.minMoves&&(t[r]=a.minMoves),a.maxMoves&&(n[r]=a.maxMoves))}function _n(e,t){return e[t]+""}const An={first:({ctx:e})=>0===e.turn?e.playOrderPos:(e.playOrderPos+1)%e.playOrder.length,next:({ctx:e})=>(e.playOrderPos+1)%e.playOrder.length},Sn={NULL:null};function Dn({moves:e,phases:t,endIf:n,onEnd:r,turn:a,events:o,plugins:i}){void 0===e&&(e={}),void 0===o&&(o={}),void 0===i&&(i=[]),void 0===t&&(t={}),n||(n=()=>{}),r||(r=({G:e})=>e),a||(a={});const s={...t};""in s&&mn("cannot specify phase with empty name"),s[""]={};const l={},c=new Set;let u=null;Object.keys(e).forEach(e=>c.add(e));const d=(e,t)=>{const n=xn(e,t,i);return e=>{const t=$n(e);return n({...t,G:e.G,ctx:e.ctx,playerID:e.playerID})}},f=e=>t=>{const n=$n(t);return e({...n,G:t.G,ctx:t.ctx})},p={onEnd:d(r,tn.GAME_ON_END),endIf:f(n)};for(const e in s){const t=s[e];if(!0===t.start&&(u=e),void 0!==t.moves)for(const n of Object.keys(t.moves))l[e+"."+n]=t.moves[n],c.add(n);void 0===t.endIf&&(t.endIf=()=>{}),void 0===t.onBegin&&(t.onBegin=({G:e})=>e),void 0===t.onEnd&&(t.onEnd=({G:e})=>e),void 0===t.turn&&(t.turn=a),void 0===t.turn.order&&(t.turn.order=An),void 0===t.turn.onBegin&&(t.turn.onBegin=({G:e})=>e),void 0===t.turn.onEnd&&(t.turn.onEnd=({G:e})=>e),void 0===t.turn.endIf&&(t.turn.endIf=()=>!1),void 0===t.turn.onMove&&(t.turn.onMove=({G:e})=>e),void 0===t.turn.stages&&(t.turn.stages={}),En(t.turn,!0);for(const n in t.turn.stages){const r=t.turn.stages[n].moves||{};for(const t of Object.keys(r)){l[e+"."+n+"."+t]=r[t],c.add(t)}}if(t.wrapped={onBegin:d(t.onBegin,tn.PHASE_ON_BEGIN),onEnd:d(t.onEnd,tn.PHASE_ON_END),endIf:f(t.endIf)},t.turn.wrapped={onMove:d(t.turn.onMove,tn.TURN_ON_MOVE),onBegin:d(t.turn.onBegin,tn.TURN_ON_BEGIN),onEnd:d(t.turn.onEnd,tn.TURN_ON_END),endIf:f(t.turn.endIf)},"function"!=typeof t.next){const{next:e}=t;t.next=()=>e||null}t.wrapped.next=f(t.next)}function g(e){return e.phase?s[e.phase]:s[""]}function v(e){return e}function h(e,t){const n=new Set,r=new Set;for(let a=0;a<t.length;a++){const{fn:o,arg:i,...s}=t[a];if(o===_){r.clear();const t=e.ctx.phase;if(n.has(t)){const t={...e.ctx,phase:null};return{...e,ctx:t}}n.add(t)}const l=[];if(e=o(e,{...s,arg:i,next:l}),o===I)break;const c=k(e);if(c){t.push({fn:I,arg:c,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}const u=E(e);if(u)t.push({fn:_,arg:u,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});else{if([v,P,w].includes(o)){const n=O(e);if(n){t.push({fn:A,arg:n,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}}t.push(...l)}}return e}function m(e,{next:t}){return t.push({fn:y}),e}function y(e,{next:t}){let{G:n,ctx:r}=e;return n=g(r).wrapped.onBegin(e),t.push({fn:b}),{...e,G:n,ctx:r}}function b(e,{currentPlayer:t}){let{ctx:n}=e;const r=g(n);t?(n={...n,currentPlayer:t},r.turn.activePlayers&&(n=On(n,r.turn.activePlayers))):n=function(e,t){let{G:n,ctx:r}=e;const{numPlayers:a}=r,o={...$n(e),G:n,ctx:r},i=t.order;let s=[...Array.from({length:a})].map((e,t)=>t+"");void 0!==i.playOrder&&(s=i.playOrder(o));const l=i.first(o),c=typeof l;"number"!==c&&mn(`invalid value returned by turn.order.first — expected number got ${c} “${l}”.`);const u=_n(s,l);return r={...r,currentPlayer:u,playOrderPos:l,playOrder:s},r=On(r,t.activePlayers||{}),r}(e,r.turn);const a=n.turn+1;n={...n,turn:a,numMoves:0,_prevActivePlayers:[]};const o=r.turn.wrapped.onBegin({...e,ctx:n});return{...e,G:o,ctx:n,_undo:[],_redo:[]}}function $(e,{arg:t,next:n,phase:r}){const a=g({phase:r});let{ctx:o}=e;if(t&&t.next){if(!(t.next in s))return mn("invalid phase: "+t.next),e;o={...o,phase:t.next}}else o={...o,phase:a.wrapped.next(e)||null};return e={...e,ctx:o},n.push({fn:y}),e}function x(e,{arg:t,currentPlayer:n,next:r}){let{G:a,ctx:o}=e;const i=g(o),{endPhase:s,ctx:l}=function(e,t,n,r){const a=n.order;let{G:o,ctx:i}=e,s=i.playOrderPos,l=!1;if(r&&!0!==r)"object"!=typeof r&&mn("invalid argument to endTurn: "+r),Object.keys(r).forEach(e=>{switch(e){case"remove":t=_n(i.playOrder,s);break;case"next":s=i.playOrder.indexOf(r.next),t=r.next;break;default:mn("invalid argument to endTurn: "+e)}});else{const n={...$n(e),G:o,ctx:i},r=a.next(n),c=typeof r;void 0!==r&&"number"!==c&&mn(`invalid value returned by turn.order.next — expected number or undefined got ${c} “${r}”.`),void 0===r?l=!0:(s=r,t=_n(i.playOrder,s))}return i={...i,playOrderPos:s,currentPlayer:t},{endPhase:l,ctx:i}}(e,n,i.turn,t);return o=l,e={...e,G:a,ctx:o},s?r.push({fn:_,turn:o.turn,phase:o.phase}):r.push({fn:b,currentPlayer:o.currentPlayer}),e}function P(e,{arg:t,playerID:n}){if("string"!=typeof t&&t!==Sn.NULL||(t={stage:t}),"object"!=typeof t)return e;En(t);let{ctx:r}=e,{activePlayers:a,_activePlayersMinMoves:o,_activePlayersMaxMoves:i,_activePlayersNumMoves:s}=r;return void 0!==t.stage&&(null===a&&(a={}),a[n]=t.stage,s[n]=0,t.minMoves&&(null===o&&(o={}),o[n]=t.minMoves),t.maxMoves&&(null===i&&(i={}),i[n]=t.maxMoves)),r={...r,activePlayers:a,_activePlayersMinMoves:o,_activePlayersMaxMoves:i,_activePlayersNumMoves:s},{...e,ctx:r}}function w(e,{arg:t}){return{...e,ctx:On(e.ctx,t)}}function k(e){return p.endIf(e)}function E(e){return g(e.ctx).wrapped.endIf(e)}function O(e){const t=g(e.ctx),n=e.ctx.numMoves||0;return!!(t.turn.maxMoves&&n>=t.turn.maxMoves)||t.turn.wrapped.endIf(e)}function I(e,{arg:t,phase:n}){e=_(e,{phase:n}),void 0===t&&(t=!0),e={...e,ctx:{...e.ctx,gameover:t}};const r=p.onEnd(e);return{...e,G:r}}function _(e,{arg:t,next:n,turn:r,automatic:a}){e=A(e,{turn:r,force:!0,automatic:!0});const{phase:o,turn:i}=e.ctx;if(n&&n.push({fn:$,arg:t,phase:o}),null===o)return e;const s=g(e.ctx).wrapped.onEnd(e),l={...e.ctx,phase:null},c=Fe("endPhase",t),{_stateID:u}=e,d={action:c,_stateID:u,turn:i,phase:o};a&&(d.automatic=!0);const f=[...e.deltalog||[],d];return{...e,G:s,ctx:l,deltalog:f}}function A(e,{arg:t,next:n,turn:r,force:a,automatic:o,playerID:i}){if(r!==e.ctx.turn)return e;const{currentPlayer:s,numMoves:l,phase:c,turn:u}=e.ctx,d=g(e.ctx),f=l||0;if(!a&&d.turn.minMoves&&f<d.turn.minMoves)return hn(`cannot end turn before making ${d.turn.minMoves} moves`),e;const p=d.turn.wrapped.onEnd(e);n&&n.push({fn:x,arg:t,currentPlayer:s});let v={...e.ctx,activePlayers:null};if(t&&t.remove){i=i||s;const t=v.playOrder.filter(e=>e!=i),r=v.playOrderPos>t.length-1?0:v.playOrderPos;if(v={...v,playOrder:t,playOrderPos:r},0===t.length)return n.push({fn:_,turn:u,phase:c}),e}const h=Fe("endTurn",t),{_stateID:m}=e,y={action:h,_stateID:m,turn:u,phase:c};o&&(y.automatic=!0);const b=[...e.deltalog||[],y];return{...e,G:p,ctx:v,deltalog:b,_undo:[],_redo:[]}}function S(e,{arg:t,next:n,automatic:r,playerID:a}){a=a||e.ctx.currentPlayer;let{ctx:o,_stateID:i}=e,{activePlayers:s,_activePlayersNumMoves:l,_activePlayersMinMoves:c,_activePlayersMaxMoves:u,phase:d,turn:f}=o;const p=null!==s&&a in s,v=g(o);if(!t&&p){const e=v.turn.stages[s[a]];e&&e.next&&(t=e.next)}if(n&&n.push({fn:P,arg:t,playerID:a}),!p)return e;const h=l[a]||0;if(c&&c[a]&&h<c[a])return hn(`cannot end stage before making ${c[a]} moves`),e;s={...s},delete s[a],c&&(c={...c},delete c[a]),u&&(u={...u},delete u[a]),o=function(e){let{activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:a,_prevActivePlayers:o,_nextActivePlayers:i}=e;if(t&&0===Object.keys(t).length)if(i)e=On(e,i),({activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:a,_prevActivePlayers:o}=e);else if(o.length>0){const e=o.length-1;({activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:a}=o[e]),o=o.slice(0,e)}else t=null,n=null,r=null;return{...e,activePlayers:t,_activePlayersMinMoves:n,_activePlayersMaxMoves:r,_activePlayersNumMoves:a,_prevActivePlayers:o}}({...o,activePlayers:s,_activePlayersMinMoves:c,_activePlayersMaxMoves:u});const m={action:Fe("endStage",t),_stateID:i,turn:f,phase:d};r&&(m.automatic=!0);const y=[...e.deltalog||[],m];return{...e,ctx:o,deltalog:y}}function D(t,n,r){const a=g(t),o=a.turn.stages,{activePlayers:i}=t;if(i&&void 0!==i[r]&&i[r]!==Sn.NULL&&void 0!==o[i[r]]&&void 0!==o[i[r]].moves){const e=o[i[r]].moves;if(n in e)return e[n]}else if(a.moves){if(n in a.moves)return a.moves[n]}else if(n in e)return e[n];return null}const M={endStage:function(e,t){return h(e,[{fn:S,playerID:t}])},setStage:function(e,t,n){return h(e,[{fn:S,arg:n,playerID:t}])},endTurn:function(e,t,n){return h(e,[{fn:A,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},pass:function(e,t,n){return h(e,[{fn:A,turn:e.ctx.turn,phase:e.ctx.phase,force:!0,arg:n}])},endPhase:function(e){return h(e,[{fn:_,phase:e.ctx.phase,turn:e.ctx.turn}])},setPhase:function(e,t,n){return h(e,[{fn:_,phase:e.ctx.phase,turn:e.ctx.turn,arg:{next:n}}])},endGame:function(e,t,n){return h(e,[{fn:I,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},setActivePlayers:function(e,t,n){return h(e,[{fn:w,arg:n}])}},j=[];return!1!==o.endTurn&&j.push("endTurn"),!1!==o.pass&&j.push("pass"),!1!==o.endPhase&&j.push("endPhase"),!1!==o.setPhase&&j.push("setPhase"),!1!==o.endGame&&j.push("endGame"),!1!==o.setActivePlayers&&j.push("setActivePlayers"),!1!==o.endStage&&j.push("endStage"),!1!==o.setStage&&j.push("setStage"),{ctx:e=>({numPlayers:e,turn:0,currentPlayer:"0",playOrder:[...Array.from({length:e})].map((e,t)=>t+""),playOrderPos:0,phase:u,activePlayers:null}),init:e=>h(e,[{fn:m}]),isPlayerActive:function(e,t,n){return t.activePlayers?n in t.activePlayers:t.currentPlayer===n},eventHandlers:M,eventNames:Object.keys(M),enabledEventNames:j,moveMap:l,moveNames:[...c.values()],processMove:function(e,t){const{playerID:n,type:r}=t,{currentPlayer:a,activePlayers:o,_activePlayersMaxMoves:i}=e.ctx,s=D(e.ctx,r,n),l=!s||"function"==typeof s||!0!==s.noLimit;let{numMoves:c,_activePlayersNumMoves:u}=e.ctx;l&&(n===a&&c++,o&&u[n]++),e={...e,ctx:{...e.ctx,numMoves:c,_activePlayersNumMoves:u}},i&&u[n]>=i[n]&&(e=S(e,{playerID:n,automatic:!0}));const d=g(e.ctx).turn.wrapped.onMove({...e,playerID:n});return h(e={...e,G:d},[{fn:v}])},processEvent:function(e,t){const{type:n,playerID:r,args:a}=t.payload;return"function"!=typeof M[n]?e:M[n](e,r,...Array.isArray(a)?a:[a])},getMove:D}}function Mn(e){if(function(e){return void 0!==e.processMove}(e))return e;if(void 0===e.name&&(e.name="default"),void 0===e.deltaState&&(e.deltaState=!1),void 0===e.disableUndo&&(e.disableUndo=!1),void 0===e.setup&&(e.setup=()=>({})),void 0===e.moves&&(e.moves={}),void 0===e.playerView&&(e.playerView=({G:e})=>e),void 0===e.plugins&&(e.plugins=[]),e.plugins.forEach(e=>{if(void 0===e.name)throw new Error("Plugin missing name attribute");if(e.name.includes(" "))throw new Error(e.name+": Plugin name must not include spaces")}),e.name.includes(" "))throw new Error(e.name+": Game name must not include spaces");const t=Dn(e);return{...e,flow:t,moveNames:t.moveNames,pluginNames:e.plugins.map(e=>e.name),processMove:(n,r)=>{let a=t.getMove(n.ctx,r.type,r.playerID);var o;if((o=a)instanceof Object&&void 0!==o.move&&(a=a.move),a instanceof Function){const t=xn(a,tn.MOVE,e.plugins);let o=[];void 0!==r.args&&(o=Array.isArray(r.args)?r.args:[r.args]);return t({...$n(n),G:n.G,ctx:n.ctx,playerID:r.playerID},...o)}return mn("invalid move object: "+r.type),n.G}}}var jn,Nn;!function(e){e.UnauthorizedAction="update/unauthorized_action",e.MatchNotFound="update/match_not_found",e.PatchFailed="update/patch_failed"}(jn||(jn={})),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"}(Nn||(Nn={}));var Tn="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function Cn(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Gn(e,t){return e(t={exports:{}},t.exports),t.exports}var zn=Gn((function(e,t){function n(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function r(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}Object.defineProperty(t,"__esModule",{value:!0}),t.Pointer=void 0;var a=function(){function e(e){void 0===e&&(e=[""]),this.tokens=e}return e.fromJSON=function(t){var r=t.split("/").map(n);if(""!==r[0])throw new Error("Invalid JSON Pointer: "+t);return new e(r)},e.prototype.toString=function(){return this.tokens.map(r).join("/")},e.prototype.evaluate=function(e){for(var t=null,n="",r=e,a=1,o=this.tokens.length;a<o;a++)t=r,"__proto__"!=(n=this.tokens[a])&&"constructor"!=n&&"prototype"!=n&&(r=(t||{})[n]);return{parent:t,key:n,value:r}},e.prototype.get=function(e){return this.evaluate(e).value},e.prototype.set=function(e,t){for(var n=e,r=1,a=this.tokens.length-1,o=this.tokens[r];r<a;r++)n=(n||{})[o];n&&(n[this.tokens[this.tokens.length-1]]=t)},e.prototype.push=function(e){this.tokens.push(e)},e.prototype.add=function(t){return new e(this.tokens.concat(String(t)))},e}();t.Pointer=a}));Cn(zn);zn.Pointer;var qn=Gn((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.clone=t.objectType=t.hasOwnProperty=void 0,t.hasOwnProperty=Object.prototype.hasOwnProperty,t.objectType=function(e){return void 0===e?"undefined":null===e?"null":Array.isArray(e)?"array":typeof e},t.clone=function e(n){if(null==(r=n)||"object"!=typeof r)return n;var r;if(n.constructor==Array){for(var a=n.length,o=new Array(a),i=0;i<a;i++)o[i]=e(n[i]);return o}if(n.constructor==Date)return new Date(+n);var s={};for(var l in n)t.hasOwnProperty.call(n,l)&&(s[l]=e(n[l]));return s}}));Cn(qn);qn.clone,qn.objectType;var Vn=Gn((function(e,t){function n(e,t){var n={};for(var r in e)qn.hasOwnProperty.call(e,r)&&void 0!==e[r]&&(n[r]=1);for(var a in t)qn.hasOwnProperty.call(t,a)&&void 0!==t[a]&&delete n[a];return Object.keys(n)}function r(e){for(var t=e.length,n={},r=0;r<t;r++){var a=e[r];for(var o in a)qn.hasOwnProperty.call(a,o)&&void 0!==a[o]&&(n[o]=(n[o]||0)+1)}for(var o in n)n[o]<t&&delete n[o];return Object.keys(n)}function a(e,t){return{operations:e.operations.concat(t),cost:e.cost+1}}function o(e,t,n,r){void 0===r&&(r=s);var o={"0,0":{operations:[],cost:0}};var i=isNaN(e.length)||e.length<=0?0:e.length,l=isNaN(t.length)||t.length<=0?0:t.length;return function n(i,s){var l=i+","+s,c=o[l];if(void 0===c){if(i>0&&s>0&&!r(e[i-1],t[s-1],new zn.Pointer).length)c=n(i-1,s-1);else{var u=[];if(i>0){var d=n(i-1,s),f={op:"remove",index:i-1};u.push(a(d,f))}if(s>0){var p=n(i,s-1),g={op:"add",index:i-1,value:t[s-1]};u.push(a(p,g))}if(i>0&&s>0){var v=n(i-1,s-1),h={op:"replace",index:i-1,original:e[i-1],value:t[s-1]};u.push(a(v,h))}c=u.sort((function(e,t){return e.cost-t.cost}))[0]}o[l]=c}return c}(i,l).operations.reduce((function(e,t){var a=e[0],o=e[1];if(function(e){return"add"===e.op}(t)){var s=t.index+1+o,l=s<i+o?String(s):"-",c={op:t.op,path:n.add(l).toString(),value:t.value};return[a.concat(c),o+1]}if(function(e){return"remove"===e.op}(t)){c={op:t.op,path:n.add(String(t.index+o)).toString()};return[a.concat(c),o-1]}var u=n.add(String(t.index+o)),d=r(t.original,t.value,u);return[a.concat.apply(a,d),o]}),[[],0])[0]}function i(e,t,a,o){void 0===o&&(o=s);var i=[];return n(e,t).forEach((function(e){i.push({op:"remove",path:a.add(e).toString()})})),n(t,e).forEach((function(e){i.push({op:"add",path:a.add(e).toString(),value:t[e]})})),r([e,t]).forEach((function(n){i.push.apply(i,o(e[n],t[n],a.add(n)))})),i}function s(e,t,n,r){if(void 0===r&&(r=s),e===t)return[];var a=qn.objectType(e),l=qn.objectType(t);return"array"==a&&"array"==l?o(e,t,n,r):"object"==a&&"object"==l?i(e,t,n,r):[{op:"replace",path:n.toString(),value:t}]}Object.defineProperty(t,"__esModule",{value:!0}),t.diffAny=t.diffObjects=t.diffArrays=t.intersection=t.subtract=t.isDestructive=void 0,t.isDestructive=function(e){var t=e.op;return"remove"===t||"replace"===t||"copy"===t||"move"===t},t.subtract=n,t.intersection=r,t.diffArrays=o,t.diffObjects=i,t.diffAny=s}));Cn(Vn);Vn.diffAny,Vn.diffObjects,Vn.diffArrays,Vn.intersection,Vn.subtract,Vn.isDestructive;var Rn=Gn((function(e,t){var n,r=Tn&&Tn.__extends||(n=function(e,t){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])})(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}n(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)});Object.defineProperty(t,"__esModule",{value:!0}),t.apply=t.InvalidOperationError=t.test=t.copy=t.move=t.replace=t.remove=t.add=t.TestError=t.MissingError=void 0;var a=function(e){function t(t){var n=e.call(this,"Value required at path: "+t)||this;return n.path=t,n.name="MissingError",n}return r(t,e),t}(Error);t.MissingError=a;var o=function(e){function t(t,n){var r=e.call(this,"Test failed: "+t+" != "+n)||this;return r.actual=t,r.expected=n,r.name="TestError",r}return r(t,e),t}(Error);function i(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 s(e,t){if(Array.isArray(e)){var n=parseInt(t,10);e.splice(n,1)}else delete e[t]}function l(e,t){var n=zn.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.parent?new a(t.path):(i(n.parent,n.key,qn.clone(t.value)),null)}function c(e,t){var n=zn.Pointer.fromJSON(t.path).evaluate(e);return void 0===n.value?new a(t.path):(s(n.parent,n.key),null)}function u(e,t){var n=zn.Pointer.fromJSON(t.path).evaluate(e);if(null===n.parent)return new a(t.path);if(Array.isArray(n.parent)){if(parseInt(n.key,10)>=n.parent.length)return new a(t.path)}else if(void 0===n.value)return new a(t.path);return n.parent[n.key]=t.value,null}function d(e,t){var n=zn.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new a(t.from);var r=zn.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new a(t.path):(s(n.parent,n.key),i(r.parent,r.key,n.value),null)}function f(e,t){var n=zn.Pointer.fromJSON(t.from).evaluate(e);if(void 0===n.value)return new a(t.from);var r=zn.Pointer.fromJSON(t.path).evaluate(e);return void 0===r.parent?new a(t.path):(i(r.parent,r.key,qn.clone(n.value)),null)}function p(e,t){var n=zn.Pointer.fromJSON(t.path).evaluate(e);return Vn.diffAny(n.value,t.value,new zn.Pointer).length?new o(n.value,t.value):null}t.TestError=o,t.add=l,t.remove=c,t.replace=u,t.move=d,t.copy=f,t.test=p;var g=function(e){function t(t){var n=e.call(this,"Invalid operation: "+t.op)||this;return n.operation=t,n.name="InvalidOperationError",n}return r(t,e),t}(Error);t.InvalidOperationError=g,t.apply=function(e,t){switch(t.op){case"add":return l(e,t);case"remove":return c(e,t);case"replace":return u(e,t);case"move":return d(e,t);case"copy":return f(e,t);case"test":return p(e,t)}return new g(t)}}));Cn(Rn);Rn.apply,Rn.InvalidOperationError,Rn.test,Rn.copy,Rn.move,Rn.replace,Rn.remove,Rn.add,Rn.TestError,Rn.MissingError;var Bn=Gn((function(e,t){function n(e,t){var n=zn.Pointer.fromJSON(t).evaluate(e);if(void 0!==n)return{op:"test",path:t,value:n.value}}Object.defineProperty(t,"__esModule",{value:!0}),t.createTests=t.createPatch=t.applyPatch=void 0,t.applyPatch=function(e,t){return t.map((function(t){return Rn.apply(e,t)}))},t.createPatch=function(e,t,n){var r=new zn.Pointer;return(n?function(e){return function t(n,r,a){var o=e(n,r,a);return Array.isArray(o)?o:Vn.diffAny(n,r,a,t)}}(n):Vn.diffAny)(e,t,r)},t.createTests=function(e,t){var r=new Array;return t.filter(Vn.isDestructive).forEach((function(t){var a=n(e,t.path);if(a&&r.push(a),"from"in t){var o=n(e,t.from);o&&r.push(o)}})),r}}));Cn(Bn);Bn.createTests,Bn.createPatch;var Un=Bn.applyPatch;const Fn=e=>null!==e.payload.playerID&&void 0!==e.payload.playerID;function Ln(e,t){if(t.game.disableUndo)return e;const n={G:e.G,ctx:e.ctx,plugins:e.plugins,playerID:t.action.payload.playerID||e.ctx.currentPlayer};return"MAKE_MOVE"===t.action.type&&(n.moveType=t.action.payload.type),{...e,_undo:[...e._undo,n],_redo:[]}}function Jn(e,t,n){const r={action:t,_stateID:e._stateID,turn:e.c