UNPKG

boardgame.io

Version:
1 lines 107 kB
!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";function t(){}const n=e=>e;function r(e,t){for(const n in t)e[n]=t[n];return e}function o(e){return e()}function a(){return Object.create(null)}function i(e){e.forEach(o)}function s(e){return"function"==typeof e}function l(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function c(e,t,n){e.$$.on_destroy.push(function(e,t){const n=e.subscribe(t);return n.unsubscribe?()=>n.unsubscribe():n}(t,n))}function u(e,t,n){return e[1]?r({},r(t.$$scope.ctx,e[1](n?n(t):{}))):t.$$scope.ctx}function d(e){const t={};for(const n in e)"$"!==n[0]&&(t[n]=e[n]);return t}const p="undefined"!=typeof window;let f=p?()=>window.performance.now():()=>Date.now(),v=p?e=>requestAnimationFrame(e):t;const h=new Set;let m,g=!1;function y(){h.forEach(e=>{e[0](f())||(h.delete(e),e[1]())}),g=h.size>0,g&&v(y)}function b(e,t){e.appendChild(t)}function x(e,t,n){e.insertBefore(t,n||null)}function $(e){e.parentNode.removeChild(e)}function w(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function P(e){return document.createElement(e)}function O(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function k(e){return document.createTextNode(e)}function I(){return k(" ")}function _(){return k("")}function E(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function D(e,t,n){null==n?e.removeAttribute(t):e.setAttribute(t,n)}function j(e,t){t=""+t,e.data!==t&&(e.data=t)}function S(e,t){(null!=t||e.value)&&(e.value=t)}function A(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)}}function C(e,t,n){e.classList[n?"add":"remove"](t)}function M(e,t){const n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!1,!1,t),n}let z,N=0,B={};function G(e,t,n,r,o,a,i,s=0){const l=16.666/r;let c="{\n";for(let e=0;e<=1;e+=l){const r=t+(n-t)*a(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}`;if(!B[d]){if(!m){const e=P("style");document.head.appendChild(e),m=e.sheet}B[d]=!0,m.insertRule(`@keyframes ${d} ${u}`,m.cssRules.length)}const p=e.style.animation||"";return e.style.animation=`${p?`${p}, `:""}${d} ${r}ms linear ${o}ms 1 both`,N+=1,d}function q(e,t){e.style.animation=(e.style.animation||"").split(", ").filter(t?e=>e.indexOf(t)<0:e=>-1===e.indexOf("__svelte")).join(", "),t&&!--N&&v(()=>{if(N)return;let e=m.cssRules.length;for(;e--;)m.deleteRule(e);B={}})}function L(e){z=e}function T(){if(!z)throw new Error("Function called outside component initialization");return z}function R(e){T().$$.on_destroy.push(e)}function U(){const e=z;return(t,n)=>{const r=e.$$.callbacks[t];if(r){const o=M(t,n);r.slice().forEach(t=>{t.call(e,o)})}}}function K(e,t){T().$$.context.set(e,t)}function F(e){return T().$$.context.get(e)}const V=[],J=[],H=[],W=[],Y=Promise.resolve();let Q,X=!1;function Z(e){H.push(e)}function ee(){const e=new Set;do{for(;V.length;){const e=V.shift();L(e),te(e.$$)}for(;J.length;)J.pop()();for(let t=0;t<H.length;t+=1){const n=H[t];e.has(n)||(n(),e.add(n))}H.length=0}while(V.length);for(;W.length;)W.pop()();X=!1}function te(e){e.fragment&&(e.update(e.dirty),i(e.before_update),e.fragment.p(e.dirty,e.ctx),e.dirty=null,e.after_update.forEach(Z))}function ne(e,t,n){e.dispatchEvent(M(`${t?"intro":"outro"}${n}`))}const re=new Set;let oe;function ae(){oe={r:0,c:[],p:oe}}function ie(){oe.r||i(oe.c),oe=oe.p}function se(e,t){e&&e.i&&(re.delete(e),e.i(t))}function le(e,t,n,r){if(e&&e.o){if(re.has(e))return;re.add(e),oe.c.push(()=>{re.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}}const ce={duration:0};function ue(e,r,o,a){let l=r(e,o),c=a?0:1,u=null,d=null,p=null;function m(){p&&q(e,p)}function b(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 x(r){const{delay:o=0,duration:a=300,easing:s=n,tick:x=t,css:$}=l||ce,w={start:f()+o,b:r};r||(w.group=oe,oe.r+=1),u?d=w:($&&(m(),p=G(e,c,r,a,o,s,$)),r&&x(0,1),u=b(w,a),Z(()=>ne(e,r,"start")),function(e){let t;g||(g=!0,v(y)),new Promise(n=>{h.add(t=[e,n])})}(t=>{if(d&&t>d.start&&(u=b(d,a),d=null,ne(e,u.b,"start"),$&&(m(),p=G(e,c,u.b,u.duration,0,s,l.css))),u)if(t>=u.end)x(c=u.b,1-c),ne(e,u.b,"end"),d||(u.b?m():--u.group.r||i(u.group.c)),u=null;else if(t>=u.start){const e=t-u.start;c=u.a+u.d*s(e/u.duration),x(c,1-c)}return!(!u&&!d)}))}return{run(e){s(l)?(Q||(Q=Promise.resolve(),Q.then(()=>{Q=null})),Q).then(()=>{l=l(),x(e)}):x(e)},end(){m(),u=d=null}}}const de="undefined"!=typeof window?window:global;function pe(e,t,n){const{fragment:r,on_mount:a,on_destroy:l,after_update:c}=e.$$;r.m(t,n),Z(()=>{const t=a.map(o).filter(s);l?l.push(...t):i(t),e.$$.on_mount=[]}),c.forEach(Z)}function fe(e,t){e.$$.fragment&&(i(e.$$.on_destroy),e.$$.fragment.d(t),e.$$.on_destroy=e.$$.fragment=null,e.$$.ctx={})}function ve(e,t){e.$$.dirty||(V.push(e),X||(X=!0,Y.then(ee)),e.$$.dirty=a()),e.$$.dirty[t]=!0}function he(e,n,r,o,s,l){const c=z;L(e);const u=n.props||{},d=e.$$={fragment:null,ctx:null,props:l,update:t,not_equal:s,bound:a(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(c?c.$$.context:[]),callbacks:a(),dirty:null};let p=!1;d.ctx=r?r(e,u,(t,n,r=n)=>(d.ctx&&s(d.ctx[t],d.ctx[t]=r)&&(d.bound[t]&&d.bound[t](r),p&&ve(e,t)),n)):u,d.update(),p=!0,i(d.before_update),d.fragment=o(d.ctx),n.target&&(n.hydrate?d.fragment.l(function(e){return Array.from(e.childNodes)}(n.target)):d.fragment.c(),n.intro&&se(e.$$.fragment),pe(e,n.target,n.anchor),ee()),L(c)}class me{$destroy(){fe(this,1),this.$destroy=t}$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(){}}var ge=function(e){var t,n=e.Symbol;return"function"==typeof n?n.observable?t=n.observable:(t=n("observable"),n.observable=t):t="@@observable",t}("undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof module?module:Function("return this")()),ye=function(){return Math.random().toString(36).substring(7).split("").join(".")},be={INIT:"@@redux/INIT"+ye(),REPLACE:"@@redux/REPLACE"+ye(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+ye()}};function xe(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 $e(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error("It looks like you are passing several store enhancers to createStore(). This is not supported. Instead, compose them together to a single function.");if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error("Expected the enhancer to be a function.");return n($e)(e,t)}if("function"!=typeof e)throw new Error("Expected the reducer to be a function.");var o=e,a=t,i=[],s=i,l=!1;function c(){s===i&&(s=i.slice())}function u(){if(l)throw new Error("You may not call store.getState() while the reducer is executing. The reducer has already received the state as an argument. Pass it down from the top reducer instead of reading it from the store.");return a}function d(e){if("function"!=typeof e)throw new Error("Expected the listener to be a function.");if(l)throw new Error("You may not call store.subscribe() while the reducer is executing. If you would like to be notified after the store has been updated, subscribe from a component and invoke store.getState() in the callback to access the latest state. See https://redux.js.org/api-reference/store#subscribe(listener) for more details.");var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error("You may not unsubscribe from a store listener while the reducer is executing. See https://redux.js.org/api-reference/store#subscribe(listener) for more details.");t=!1,c();var n=s.indexOf(e);s.splice(n,1)}}}function p(e){if(!xe(e))throw new Error("Actions must be plain objects. Use custom middleware for async actions.");if(void 0===e.type)throw new Error('Actions may not have an undefined "type" property. Have you misspelled a constant?');if(l)throw new Error("Reducers may not dispatch actions.");try{l=!0,a=o(a,e)}finally{l=!1}for(var t=i=s,n=0;n<t.length;n++){(0,t[n])()}return e}function f(e){if("function"!=typeof e)throw new Error("Expected the nextReducer to be a function.");o=e,p({type:be.REPLACE})}function v(){var e,t=d;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new TypeError("Expected the observer to be an object.");function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[ge]=function(){return this},e}return p({type:be.INIT}),(r={dispatch:p,subscribe:d,getState:u,replaceReducer:f})[ge]=v,r}function we(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Pe(e,t){var n=Object.keys(e);return Object.getOwnPropertySymbols&&n.push.apply(n,Object.getOwnPropertySymbols(e)),t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n}function Oe(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Pe(n,!0).forEach((function(t){we(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Pe(n).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function ke(){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))}}))}function Ie(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){return function(){var n=e.apply(void 0,arguments),r=function(){throw new Error("Dispatching while constructing your middleware is not allowed. Other middleware would not be applied to this dispatch.")},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},a=t.map((function(e){return e(o)}));return Oe({},n,{dispatch:r=ke.apply(void 0,a)(n.dispatch)})}}}const _e=(e,t,n,r)=>({type:"MAKE_MOVE",payload:{type:e,args:t,playerID:n,credentials:r}}),Ee=(e,t,n,r)=>({type:"GAME_EVENT",payload:{type:e,args:t,playerID:n,credentials:r}}),De=(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}),Se=e=>({type:"RESET",state:e,clientOnly:!0}),Ae=(e,t)=>({type:"UNDO",payload:{type:null,args:null,playerID:e,credentials:t}}),Ce=(e,t)=>({type:"REDO",payload:{type:null,args:null,playerID:e,credentials:t}});var Me,ze,Ne,Be=Object.freeze({makeMove:_e,gameEvent:Ee,automaticGameEvent:De,sync:je,update:(e,t)=>({type:"UPDATE",state:e,deltalog:t,clientOnly:!0}),reset:Se,undo:Ae,redo:Ce,plugin:(e,t,n,r)=>({type:"PLUGIN",payload:{type:e,args:t,playerID:n,credentials:r}})}),Ge="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},qe=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),Le="undefined"!=typeof Symbol?Symbol("immer-nothing"):(Ne=!0,(ze="immer-nothing")in(Me={})?Object.defineProperty(Me,ze,{value:Ne,enumerable:!0,configurable:!0,writable:!0}):Me[ze]=Ne,Me),Te="undefined"!=typeof Symbol?Symbol("immer-draftable"):"__$immer_draftable",Re="undefined"!=typeof Symbol?Symbol("immer-state"):"__$immer_state";function Ue(e){return!!e&&!!e[Re]}function Ke(e){if(!e||"object"!==(void 0===e?"undefined":Ge(e)))return!1;if(Array.isArray(e))return!0;var t=Object.getPrototypeOf(e);return!t||t===Object.prototype||(!!e[Te]||!!e.constructor[Te])}var Fe=Object.assign||function(e,t){for(var n in t)Ye(t,n)&&(e[n]=t[n]);return e},Ve="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function Je(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(Array.isArray(e))return e.slice();var n=Object.create(Object.getPrototypeOf(e));return Ve(e).forEach((function(r){if(r!==Re){var o=Object.getOwnPropertyDescriptor(e,r);if(o.get){if(!t)throw new Error("Immer drafts cannot have computed properties");o.value=o.get.call(e)}o.enumerable?n[r]=o.value:Object.defineProperty(n,r,{value:o.value,writable:!0,configurable:!0})}})),n}function He(e,t){if(Array.isArray(e))for(var n=0;n<e.length;n++)t(n,e[n],e);else Ve(e).forEach((function(n){return t(n,e[n],e)}))}function We(e,t){return Object.getOwnPropertyDescriptor(e,t).enumerable}function Ye(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Qe(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}var Xe={},Ze=[],et=function(){return Ze[Ze.length-1]};function tt(e,t){var n=Array.isArray(e),r=it(e);He(r,(function(t){!function(e,t,n){var r=Xe[t];r?r.enumerable=n:Xe[t]=r={configurable:!0,enumerable:n,get:function(){return function(e,t){st(e);var n=rt(e)[t];if(!e.finalizing&&n===e.base[t]&&Ke(n))return at(e),e.copy[t]=tt(n,e);return n}(this[Re],t)},set:function(e){!function(e,t,n){if(st(e),e.assigned[t]=!0,!e.modified){if(Qe(rt(e)[t],n))return;ot(e),at(e)}e.copy[t]=n}(this[Re],t,e)}};Object.defineProperty(e,t,r)}(r,t,n||We(e,t))}));var o={scope:t?t.scope:et(),modified:!1,finalizing:!1,finalized:!1,assigned:{},parent:t,base:e,draft:r,copy:null,revoke:nt,revoked:!1};return function(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0})}(r,Re,o),o.scope.push(o),r}function nt(){this.revoked=!0}function rt(e){return e.copy||e.base}function ot(e){e.modified||(e.modified=!0,e.parent&&ot(e.parent))}function at(e){e.copy||(e.copy=it(e.base))}function it(e){var t=e&&e[Re];if(t){t.finalizing=!0;var n=Je(t.draft,!0);return t.finalizing=!1,n}return Je(e)}function st(e){if(!0===e.revoked)throw new Error("Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? "+JSON.stringify(rt(e)))}function lt(e){for(var t=e.base,n=e.draft,r=Object.keys(n),o=r.length-1;o>=0;o--)if(void 0===t[r[o]]&&!Ye(t,r[o]))return!0;return r.length!==Object.keys(t).length}function ct(e){var t=e.draft;if(t.length!==e.base.length)return!0;var n=Object.getOwnPropertyDescriptor(t,t.length-1);return!(!n||n.get)}var ut=Object.freeze({scopes:Ze,currentScope:et,willFinalize:function(e,t,n){var r=et();r.forEach((function(e){return e.finalizing=!0})),void 0!==e&&e!==t||(n&&function e(t){if(!t||"object"!==(void 0===t?"undefined":Ge(t)))return;var n=t[Re];if(!n)return;var r=n.base,o=n.draft,a=n.assigned;if(Array.isArray(t)){if(ct(n)){if(ot(n),a.length=!0,o.length<r.length)for(var i=o.length;i<r.length;i++)a[i]=!1;else for(var s=r.length;s<o.length;s++)a[s]=!0;for(var l=0;l<o.length;l++)void 0===a[l]&&e(o[l])}}else Object.keys(o).forEach((function(t){void 0!==r[t]||Ye(r,t)?a[t]||e(o[t]):(a[t]=!0,ot(n))})),Object.keys(r).forEach((function(e){void 0!==o[e]||Ye(o,e)||(a[e]=!1,ot(n))}))}(t),function(e){for(var t=e.length-1;t>=0;t--){var n=e[t];!1===n.modified&&(Array.isArray(n.base)?ct(n)&&ot(n):lt(n)&&ot(n))}}(r))},createDraft:tt}),dt=[],pt=function(){return dt[dt.length-1]};function ft(e,t){var n={scope:t?t.scope:pt(),modified:!1,finalized:!1,assigned:{},parent:t,base:e,draft:null,drafts:{},copy:null,revoke:null},r=Array.isArray(e)?Proxy.revocable([n],ht):Proxy.revocable(n,vt),o=r.revoke,a=r.proxy;return n.draft=a,n.revoke=o,n.scope.push(n),a}var vt={get:function(e,t){if(t===Re)return e;var n=e.drafts;if(!e.modified&&Ye(n,t))return n[t];var r=mt(e)[t];if(e.finalized||!Ke(r))return r;if(e.modified){if(r!==e.base[t])return r;n=e.copy}return n[t]=ft(r,e)},has:function(e,t){return t in mt(e)},ownKeys:function(e){return Reflect.ownKeys(mt(e))},set:function(e,t,n){if(!e.modified){if(n?Qe(e.base[t],n)||n===e.drafts[t]:Qe(e.base[t],n)&&t in e.base)return!0;gt(e)}return e.assigned[t]=!0,e.copy[t]=n,!0},deleteProperty:function(e,t){(void 0!==e.base[t]||t in e.base)&&(e.assigned[t]=!1,gt(e));e.copy&&delete e.copy[t];return!0},getOwnPropertyDescriptor:function(e,t){var n=mt(e),r=Reflect.getOwnPropertyDescriptor(n,t);r&&(r.writable=!0,r.configurable=!Array.isArray(n)||"length"!==t);return r},defineProperty:function(){throw new Error("Object.defineProperty() cannot be used on an Immer draft")},getPrototypeOf:function(e){return Object.getPrototypeOf(e.base)},setPrototypeOf:function(){throw new Error("Object.setPrototypeOf() cannot be used on an Immer draft")}},ht={};function mt(e){return e.copy||e.base}function gt(e){e.modified||(e.modified=!0,e.copy=Fe(Je(e.base),e.drafts),e.drafts=null,e.parent&&gt(e.parent))}He(vt,(function(e,t){ht[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),ht.deleteProperty=function(e,t){if(isNaN(parseInt(t)))throw new Error("Immer only supports deleting array indices");return vt.deleteProperty.call(this,e[0],t)},ht.set=function(e,t,n){if("length"!==t&&isNaN(parseInt(t)))throw new Error("Immer only supports setting array indices and the 'length' property");return vt.set.call(this,e[0],t,n)};var yt=Object.freeze({scopes:dt,currentScope:pt,willFinalize:function(){},createDraft:ft});function bt(e,t,n,r){Array.isArray(e.base)?function(e,t,n,r){for(var o=e.base,a=e.copy,i=e.assigned,s=Math.min(o.length,a.length),l=0;l<s;l++)if(i[l]&&o[l]!==a[l]){var c=t.concat(l);n.push({op:"replace",path:c,value:a[l]}),r.push({op:"replace",path:c,value:o[l]})}if(s<a.length){for(var u=s;u<a.length;u++)n.push({op:"add",path:t.concat(u),value:a[u]});r.push({op:"replace",path:t.concat("length"),value:o.length})}else if(s<o.length){n.push({op:"replace",path:t.concat("length"),value:a.length});for(var d=s;d<o.length;d++)r.push({op:"add",path:t.concat(d),value:o[d]})}}(e,t,n,r):function(e,t,n,r){var o=e.base,a=e.copy;He(e.assigned,(function(e,i){var s=o[e],l=a[e],c=i?e in o?"replace":"add":"remove";if(s!==l||"replace"!==c){var u=t.concat(e);n.push("remove"===c?{op:c,path:u}:{op:c,path:u,value:l}),r.push("add"===c?{op:"remove",path:u}:"remove"===c?{op:"add",path:u,value:s}:{op:"replace",path:u,value:s})}}))}(e,t,n,r)}function xt(e,t){for(var n=0;n<t.length;n++){var r=t[n],o=r.path;if(0===o.length&&"replace"===r.op)e=r.value;else{for(var a=e,i=0;i<o.length-1;i++)if(!(a=a[o[i]])||"object"!==(void 0===a?"undefined":Ge(a)))throw new Error("Cannot apply patch, path doesn't resolve: "+o.join("/"));var s=o[o.length-1];switch(r.op){case"replace":case"add":a[s]=r.value;break;case"remove":if(Array.isArray(a)){if(s!==a.length-1)throw new Error("Only the last index of an array can be removed, index: "+s+", length: "+a.length);a.length-=1}else delete a[s];break;default:throw new Error("Unsupported patch operation: "+r.op)}}}return e}var $t={useProxies:"undefined"!=typeof Proxy&&"undefined"!=typeof Reflect,autoFreeze:"undefined"==typeof process&&"verifyMinified"===function(){}.name,onAssign:null,onDelete:null,onCopy:null},wt=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),Fe(this,$t,t),this.setUseProxies(this.useProxies),this.produce=this.produce.bind(this)}return qe(e,[{key:"produce",value:function(e,t,n){var r=this;if("function"==typeof e&&"function"!=typeof t){var o=t;return t=e,function(){for(var e=arguments.length,n=Array(e>1?e-1:0),a=1;a<e;a++)n[a-1]=arguments[a];var i=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o;return r.produce(i,(function(e){var r;return(r=t).call.apply(r,[e,e].concat(n))}))}}if("function"!=typeof t)throw new Error("if first argument is not a function, the second argument to produce should be a function");if(void 0!==n&&"function"!=typeof n)throw new Error("the third argument of a producer should not be set or a function");var a=void 0;if(Ke(e)){this.scopes.push([]);var i=this.createDraft(e);try{a=t.call(i,i),this.willFinalize(a,i,!!n);var s=n&&[],l=n&&[];if(void 0===a||a===i)a=this.finalize(i,[],s,l);else{if(i[Re].modified)throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.");Ke(a)&&(a=this.finalize(a)),n&&(s.push({op:"replace",path:[],value:a}),l.push({op:"replace",path:[],value:e}))}}finally{this.currentScope().forEach((function(e){return e.revoke()})),this.scopes.pop()}n&&n(s,l)}else if(void 0===(a=t(e)))return e;return a===Le?void 0:a}},{key:"setAutoFreeze",value:function(e){this.autoFreeze=e}},{key:"setUseProxies",value:function(e){this.useProxies=e,Fe(this,e?yt:ut)}},{key:"applyPatches",value:function(e,t){return Ue(e)?xt(e,t):this.produce(e,(function(e){return xt(e,t)}))}},{key:"finalize",value:function(e,t,n,r){var o=this,a=e[Re];if(!a)return Object.isFrozen(e)?e:this.finalizeTree(e);if(a.scope!==this.currentScope())return e;if(!a.modified)return a.base;if(!a.finalized){if(a.finalized=!0,this.finalizeTree(a.draft,t,n,r),this.onDelete)if(this.useProxies){var i=a.assigned;for(var s in i)i[s]||this.onDelete(a,s)}else{var l=a.base,c=a.copy;He(l,(function(e){Ye(c,e)||o.onDelete(a,e)}))}this.onCopy&&this.onCopy(a),this.autoFreeze&&1===this.scopes.length&&Object.freeze(a.copy),n&&bt(a,t,n,r)}return a.copy}},{key:"finalizeTree",value:function(e,t,n,r){var o=this,a=e[Re];a&&(this.useProxies||(a.finalizing=!0,a.copy=Je(a.draft,!0),a.finalizing=!1),e=a.copy);var i=this.onAssign;return He(e,(function s(l,c,u){if(c===u)throw Error("Immer forbids circular references");var d=!!a&&u===e;if(Ue(c)){if(c=n&&d&&!a.assigned[l]?o.finalize(c,t.concat(l),n,r):o.finalize(c),Array.isArray(u)||We(u,l)?u[l]=c:Object.defineProperty(u,l,{value:c}),d&&c===a.base[l])return}else{if(d&&Qe(c,a.base[l]))return;Ke(c)&&!Object.isFrozen(c)&&He(c,s)}d&&i&&i(a,l,c)})),e}}]),e}()),Pt=wt.produce;wt.setAutoFreeze.bind(wt),wt.setUseProxies.bind(wt),wt.applyPatches.bind(wt);const Ot={name:"plugin-immer",fnWrap:e=>(t,n,...r)=>{let o=!1;const a=Pt(t,t=>{const a=e(t,n,...r);if("INVALID_MOVE"!==a)return a;o=!0});return o?"INVALID_MOVE":a}};function kt(e){return(kt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function It(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _t(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function Et(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 Dt(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?Et(n,!0).forEach((function(t){_t(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):Et(n).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function jt(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function St(e){var t,n=this,r=(t=4022871197,function(e){e=e.toString();for(var n=0;n<e.length;n++){var r=.02519603282416938*(t+=e.charCodeAt(n));r-=t=r>>>0,t=(r*=t)>>>0,t+=4294967296*(r-=t)}return 2.3283064365386963e-10*(t>>>0)});n.next=function(){var e=2091639*n.s0+2.3283064365386963e-10*n.c;return n.s0=n.s1,n.s1=n.s2,n.s2=e-(n.c=0|e)},n.c=1,n.s0=r(" "),n.s1=r(" "),n.s2=r(" "),n.s0-=r(e),n.s0<0&&(n.s0+=1),n.s1-=r(e),n.s1<0&&(n.s1+=1),n.s2-=r(e),n.s2<0&&(n.s2+=1),r=null}function At(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function Ct(e,t){var n=new St(e),r=t&&t.state,o=n.next;return o.quick=o,r&&("object"==kt(r)&&At(r,n),o.state=function(){return At(n,{})}),o}var Mt=function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.state=t,this.used=!1}var t,n,r;return t=e,(n=[{key:"isUsed",value:function(){return this.used}},{key:"getState",value:function(){return this.state}},{key:"_random",value:function(){this.used=!0;var e,t=this.state,n=(e=void 0===t.prngstate?new Ct(t.seed,{state:!0}):new Ct("",{state:t.prngstate}))();return this.state=Dt({},t,{prngstate:e.state()}),n}},{key:"api",value:function(){var e=this._random.bind(this),t={D4:4,D6:6,D8:8,D10:10,D12:12,D20:20},n={},r=function(r){var o=t[r];n[r]=function(t){return void 0===t?Math.floor(e()*o)+1:jt(new Array(t).keys()).map((function(){return Math.floor(e()*o)+1}))}};for(var o in t)r(o);return Dt({},n,{Die:function(t,n){return void 0===t&&(t=6),void 0===n?Math.floor(e()*t)+1:jt(new Array(n).keys()).map((function(){return Math.floor(e()*t)+1}))},Number:function(){return e()},Shuffle:function(t){for(var n=t.slice(0),r=t.length,o=0,a=new Array(r);r;){var i=r*e()|0;a[o++]=n[i],n[i]=n[--r]}return a},_obj:this})}}])&&It(t.prototype,n),r&&It(t,r),e}();Mt.seed=function(){return(+new Date).toString(36).slice(-10)};class zt{constructor(e,t){this.flow=e,this.playerID=t,this.dispatch=[]}api(e){const t={_obj:this},{phase:n,turn:r}=e;for(const e of this.flow.eventNames)t[e]=(...t)=>{this.dispatch.push({key:e,args:t,phase:n,turn:r})};return t}isUsed(){return this.dispatch.length>0}update(e){for(let t=0;t<this.dispatch.length;t++){const n=this.dispatch[t];if("endTurn"===n.key&&n.turn!==e.ctx.turn)continue;if(("endPhase"===n.key||"setPhase"===n.key)&&n.phase!==e.ctx.phase)continue;const r=De(n.key,n.args,this.playerID);e={...e,...this.flow.processEvent(e,r)}}return e}}const Nt=[Ot,{name:"random",noClient:({api:e})=>e._obj.isUsed(),flush:({api:e})=>e._obj.getState(),api:({data:e})=>new Mt(e).api(),setup:({game:e})=>{let t=e.seed;return void 0===t&&(t=Mt.seed()),{seed:t}}},{name:"events",noClient:({api:e})=>e._obj.isUsed(),dangerouslyFlushRawState:({state:e,api:t})=>t._obj.update(e),api:({game:e,playerID:t,ctx:n})=>new zt(e.flow,t).api(n)}],Bt=e=>{let t={...e.ctx};const n=e.plugins||{};return Object.entries(n).forEach(([e,{api:n}])=>{t[e]=n}),t},Gt=(e,t)=>[...Nt,...t].filter(e=>void 0!==e.fnWrap).reduce((e,{fnWrap:t})=>t(e),e),qt=(e,t)=>([...Nt,...t.game.plugins].filter(e=>void 0!==e.api).forEach(n=>{const r=n.name,o=e.plugins[r]||{data:{}},a=n.api({G:e.G,ctx:e.ctx,data:o.data,game:t.game,playerID:t.playerID});e={...e,plugins:{...e.plugins,[r]:{...o,api:a}}}}),e),Lt=(e,t)=>([...Nt,...t.game.plugins].reverse().forEach(n=>{const r=n.name,o=e.plugins[r]||{data:{}};if(n.flush){const r=n.flush({G:e.G,ctx:e.ctx,game:t.game,api:o.api,data:o.data});e={...e,plugins:{...e.plugins,[n.name]:{data:r}}}}else if(n.dangerouslyFlushRawState){const a=(e=n.dangerouslyFlushRawState({state:e,game:t.game,api:o.api,data:o.data})).plugins[r].data;e={...e,plugins:{...e.plugins,[n.name]:{data:a}}}}}),e),Tt=console.log,Rt=console.error;function Ut(e){Rt("ERROR:",e)}function Kt(e,t,n){return{...e,ctx:Ft(e.ctx,n)}}function Ft(e,t){let{_prevActivePlayers:n}=e,r={},o=null,a={};if(Array.isArray(t)){let e={};t.forEach(t=>e[t]=Wt.NULL),r=e}else{if(t.next&&(o=t.next),n=t.revert?n.concat({activePlayers:e.activePlayers,_activePlayersMoveLimit:e._activePlayersMoveLimit,_activePlayersNumMoves:e._activePlayersNumMoves}):[],void 0!==t.currentPlayer&&Vt(r,a,e.currentPlayer,t.currentPlayer),void 0!==t.others)for(let n=0;n<e.playOrder.length;n++){const o=e.playOrder[n];o!==e.currentPlayer&&Vt(r,a,o,t.others)}if(void 0!==t.all)for(let n=0;n<e.playOrder.length;n++){Vt(r,a,e.playOrder[n],t.all)}if(t.value)for(const e in t.value)Vt(r,a,e,t.value[e]);if(t.moveLimit)for(const e in r)void 0===a[e]&&(a[e]=t.moveLimit)}0==Object.keys(r).length&&(r=null),0==Object.keys(a).length&&(a=null);let i={};for(const e in r)i[e]=0;return{...e,activePlayers:r,_activePlayersMoveLimit:a,_activePlayersNumMoves:i,_prevActivePlayers:n,_nextActivePlayers:o}}function Vt(e,t,n,r){"object"==typeof r&&r!==Wt.NULL||(r={stage:r}),void 0!==r.stage&&(e[n]=r.stage,r.moveLimit&&(t[n]=r.moveLimit))}function Jt(e,t){return e[t]+""}const Ht={first:(e,t)=>0===t.turn?t.playOrderPos:(t.playOrderPos+1)%t.playOrder.length,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length},Wt={NULL:null};function Yt({moves:e,phases:t,endIf:n,onEnd:r,turn:o,events:a,plugins:i,disableUndo:s}){void 0===e&&(e={}),void 0===a&&(a={}),void 0===i&&(i=[]),void 0===t&&(t={}),n||(n=()=>{}),r||(r=e=>e),o||(o={});const l={...t};""in l&&Ut("cannot specify phase with empty name"),l[""]={};let c={},u=new Set,d=null;Object.keys(e).forEach(e=>u.add(e));const p=e=>{const t=Gt(e,i);return e=>{const n=Bt(e);return t(e.G,n)}},f=e=>t=>{let n=Bt(t);return e(t.G,n)},v={onEnd:p(r),endIf:f(n)};for(let e in l){const t=l[e];if(!0===t.start&&(d=e),void 0!==t.moves)for(let n of Object.keys(t.moves))c[e+"."+n]=t.moves[n],u.add(n);void 0===t.endIf&&(t.endIf=()=>{}),void 0===t.onBegin&&(t.onBegin=e=>e),void 0===t.onEnd&&(t.onEnd=e=>e),void 0===t.turn&&(t.turn=o),void 0===t.turn.order&&(t.turn.order=Ht),void 0===t.turn.onBegin&&(t.turn.onBegin=e=>e),void 0===t.turn.onEnd&&(t.turn.onEnd=e=>e),void 0===t.turn.endIf&&(t.turn.endIf=()=>!1),void 0===t.turn.onMove&&(t.turn.onMove=e=>e),void 0===t.turn.stages&&(t.turn.stages={});for(const n in t.turn.stages){const r=t.turn.stages[n].moves||{};for(let t of Object.keys(r)){c[e+"."+n+"."+t]=r[t],u.add(t)}}t.wrapped={onBegin:p(t.onBegin),onEnd:p(t.onEnd),endIf:f(t.endIf)},t.turn.wrapped={onMove:p(t.turn.onMove),onBegin:p(t.turn.onBegin),onEnd:p(t.turn.onEnd),endIf:f(t.turn.endIf)}}function h(e){return e.phase?l[e.phase]:l[""]}function m(e){return e}function g(e,t){const n=new Set,r=new Set;for(let o=0;o<t.length;o++){const{fn:a,arg:i,...s}=t[o];if(a===E){r.clear();const t=e.ctx.phase;if(n.has(t)){const t={...e.ctx,phase:null};return{...e,ctx:t}}n.add(t)}let l=[];if(e=a(e,{...s,arg:i,next:l}),a===_)break;const c=O(e);if(c){t.push({fn:_,arg:c,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}const u=k(e);if(u)t.push({fn:E,arg:u,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});else{if(a===m){const n=I(e);if(n){t.push({fn:D,arg:n,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}}t.push(...l)}}return e}function y(e,{next:t}){return t.push({fn:b}),e}function b(e,{next:t}){let{G:n,ctx:r}=e;return n=h(r).wrapped.onBegin(e),t.push({fn:x}),{...e,G:n,ctx:r}}function x(e,{currentPlayer:t}){let{G:n,ctx:r}=e;const o=h(r);t?(r={...r,currentPlayer:t},o.turn.activePlayers&&(r=Ft(r,o.turn.activePlayers))):r=function(e,t){let{G:n,ctx:r}=e;const o=Bt(e),a=t.order;let i=[...new Array(r.numPlayers)].map((e,t)=>t+"");void 0!==a.playOrder&&(i=a.playOrder(n,o));const s=a.first(n,o),l=typeof s;"number"!==l&&Ut(`invalid value returned by turn.order.first — expected number got ${l} “${s}”.`);const c=Jt(i,s);return r={...r,currentPlayer:c,playOrderPos:s,playOrder:i},r=Ft(r,t.activePlayers||{}),r}(e,o.turn);const a=r.turn+1;r={...r,turn:a,numMoves:0,_prevActivePlayers:[]},n=o.turn.wrapped.onBegin({...e,G:n,ctx:r});const i=s?[]:[{G:n,ctx:r}];return{...e,G:n,ctx:r,_undo:i,_redo:[]}}function $(e,{arg:t,next:n,phase:r}){const o=h({phase:r});let{ctx:a}=e;if(t&&t.next){if(!(t.next in l))return Ut("invalid phase: "+t.next),e;a={...a,phase:t.next}}else a=void 0!==o.next?{...a,phase:o.next}:{...a,phase:null};return e={...e,ctx:a},n.push({fn:b}),e}function w(e,{arg:t,currentPlayer:n,next:r}){let{G:o,ctx:a}=e;const i=h(a),{endPhase:s,ctx:l}=function(e,t,n,r){const o=n.order;let{G:a,ctx:i}=e,s=i.playOrderPos,l=!1;if(r&&!0!==r)"object"!=typeof r&&Ut(`invalid argument to endTurn: ${r}`),Object.keys(r).forEach(e=>{switch(e){case"remove":t=Jt(i.playOrder,s);break;case"next":s=i.playOrder.indexOf(r.next),t=r.next;break;default:Ut(`invalid argument to endTurn: ${e}`)}});else{const n=Bt(e),r=o.next(a,n),c=typeof r;void 0!==r&&"number"!==c&&Ut(`invalid value returned by turn.order.next — expected number or undefined got ${c} “${r}”.`),void 0===r?l=!0:(s=r,t=Jt(i.playOrder,s))}return i={...i,playOrderPos:s,currentPlayer:t},{endPhase:l,ctx:i}}(e,n,i.turn,t);return a=l,e={...e,G:o,ctx:a},s?r.push({fn:E,turn:a.turn,phase:a.phase}):r.push({fn:x,currentPlayer:a.currentPlayer}),e}function P(e,{arg:t,playerID:n}){"string"==typeof t&&(t={stage:t});let{ctx:r}=e,{activePlayers:o,_activePlayersMoveLimit:a,_activePlayersNumMoves:i}=r;return t.stage&&(null===o&&(o={}),o[n]=t.stage,i[n]=0,t.moveLimit&&(null===a&&(a={}),a[n]=t.moveLimit)),r={...r,activePlayers:o,_activePlayersMoveLimit:a,_activePlayersNumMoves:i},{...e,ctx:r}}function O(e){return v.endIf(e)}function k(e){return h(e.ctx).wrapped.endIf(e)}function I(e){const t=h(e.ctx),n=e.ctx.numMoves||0;return!!(t.turn.moveLimit&&n>=t.turn.moveLimit)||t.turn.wrapped.endIf(e)}function _(e,{arg:t,phase:n}){e=E(e,{phase:n}),void 0===t&&(t=!0),e={...e,ctx:{...e.ctx,gameover:t}};const r=v.onEnd(e);return{...e,G:r}}function E(e,{arg:t,next:n,turn:r,automatic:o}){let a=(e=D(e,{turn:r,force:!0})).G,i=e.ctx;if(n&&n.push({fn:$,arg:t,phase:i.phase}),null===i.phase)return e;a=h(i).wrapped.onEnd(e),i={...i,phase:null};const s={action:Ee("endPhase",t),_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase};o&&(s.automatic=!0);const l=[...e.deltalog,s];return{...e,G:a,ctx:i,deltalog:l}}function D(e,{arg:t,next:n,turn:r,force:o,automatic:a,playerID:i}){if(r!==e.ctx.turn)return e;let{G:s,ctx:l}=e;const c=h(l),u=l.numMoves||0;if(!o&&c.turn.moveLimit&&u<c.turn.moveLimit)return d=`cannot end turn before making ${c.turn.moveLimit} moves`,Tt(`INFO: ${d}`),e;var d;if(s=c.turn.wrapped.onEnd(e),n&&n.push({fn:w,arg:t,currentPlayer:l.currentPlayer}),l={...l,activePlayers:null},t&&t.remove){i=i||l.currentPlayer;const t=l.playOrder.filter(e=>e!=i),r=l.playOrderPos>t.length-1?0:l.playOrderPos;if(l={...l,playOrder:t,playOrderPos:r},0===t.length)return n.push({fn:E,turn:l.turn,phase:l.phase}),e}const p={action:Ee("endTurn",t),_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase};a&&(p.automatic=!0);const f=[...e.deltalog||[],p];return{...e,G:s,ctx:l,deltalog:f,_undo:[],_redo:[]}}function j(e,{arg:t,next:n,automatic:r,playerID:o}){o=o||e.ctx.currentPlayer;let{ctx:a}=e,{activePlayers:i,_activePlayersMoveLimit:s}=a;const l=null!==i&&o in i;if(!t&&l){const e=h(a).turn.stages[i[o]];e&&e.next&&(t=e.next)}if(n&&t&&n.push({fn:P,arg:t,playerID:o}),!l)return e;i=Object.keys(i).filter(e=>e!==o).reduce((e,t)=>(e[t]=i[t],e),{}),s&&(s=Object.keys(s).filter(e=>e!==o).reduce((e,t)=>(e[t]=s[t],e),{})),a=function(e){let{activePlayers:t,_activePlayersMoveLimit:n,_activePlayersNumMoves:r,_prevActivePlayers:o}=e;if(t&&0==Object.keys(t).length)if(e._nextActivePlayers)e=Ft(e,e._nextActivePlayers),({activePlayers:t,_activePlayersMoveLimit:n,_activePlayersNumMoves:r,_prevActivePlayers:o}=e);else if(o.length>0){const e=o.length-1;({activePlayers:t,_activePlayersMoveLimit:n,_activePlayersNumMoves:r}=o[e]),o=o.slice(0,e)}else t=null,n=null;return{...e,activePlayers:t,_activePlayersMoveLimit:n,_activePlayersNumMoves:r,_prevActivePlayers:o}}({...a,activePlayers:i,_activePlayersMoveLimit:s});const c={action:Ee("endStage",t),_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase};r&&(c.automatic=!0);const u=[...e.deltalog||[],c];return{...e,ctx:a,deltalog:u}}function S(t,n,r){const o=h(t),a=o.turn.stages,{activePlayers:i}=t;if(i&&void 0!==i[r]&&i[r]!==Wt.NULL&&void 0!==a[i[r]]&&void 0!==a[i[r]].moves){const e=a[i[r]].moves;if(n in e)return e[n]}else if(o.moves){if(n in o.moves)return o.moves[n]}else if(n in e)return e[n];return null}const A={endStage:function(e,t){return g(e,[{fn:j,playerID:t}])},setStage:function(e,t,n){return g(e,[{fn:j,arg:n,playerID:t}])},endTurn:function(e,t,n){return g(e,[{fn:D,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},pass:function(e,t,n){return g(e,[{fn:D,turn:e.ctx.turn,phase:e.ctx.phase,force:!0,arg:n}])},endPhase:function(e){return g(e,[{fn:E,phase:e.ctx.phase,turn:e.ctx.turn}])},setPhase:function(e,t,n){return g(e,[{fn:E,phase:e.ctx.phase,turn:e.ctx.turn,arg:{next:n}}])},endGame:function(e,t,n){return g(e,[{fn:_,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},setActivePlayers:Kt};let C=[];return!1!==a.endTurn&&C.push("endTurn"),!1!==a.pass&&C.push("pass"),!1!==a.endPhase&&C.push("endPhase"),!1!==a.setPhase&&C.push("setPhase"),!1!==a.endGame&&C.push("endGame"),!1!==a.setActivePlayers&&C.push("setActivePlayers"),!1!==a.endStage&&C.push("endStage"),!1!==a.setStage&&C.push("setStage"),{ctx:e=>({numPlayers:e,turn:0,currentPlayer:"0",playOrder:[...new Array(e)].map((e,t)=>t+""),playOrderPos:0,phase:d,activePlayers:null}),init:e=>g(e,[{fn:y}]),isPlayerActive:function(e,t,n){return t.activePlayers?n in t.activePlayers:t.currentPlayer===n},eventHandlers:A,eventNames:Object.keys(A),enabledEventNames:C,moveMap:c,moveNames:[...u.values()],processMove:function(e,t){let n=h(e.ctx);const r=S(e.ctx,t.type,t.playerID),o=!r||"function"==typeof r||!0!==r.noLimit;let{ctx:a}=e,{_activePlayersNumMoves:i}=a;const{playerID:s}=t;let l=e.ctx.numMoves;o&&(s==e.ctx.currentPlayer&&l++,a.activePlayers&&i[s]++),e={...e,ctx:{...a,numMoves:l,_activePlayersNumMoves:i}},a._activePlayersMoveLimit&&i[s]>=a._activePlayersMoveLimit[s]&&(e=j(e,{playerID:s,automatic:!0}));const c=n.turn.wrapped.onMove(e);return g(e={...e,G:c},[{fn:m}])},processEvent:function(e,t){const{type:n,playerID:r,args:o}=t.payload;if(A.hasOwnProperty(n)){const t=[e,r].concat(o);return A[n].apply({},t)}return e},getMove:S}}function Qt(e){if(function(e){return void 0!==e.processMove}(e))return e;if(void 0===e.name&&(e.name="default"),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=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=Yt(e);return{...e,flow:t,moveNames:t.moveNames,pluginNames:e.plugins.map(e=>e.name),processMove:(n,r)=>{let o=t.getMove(n.ctx,r.type,r.playerID);var a;if((a=o)instanceof Object&&void 0!==a.move&&(o=o.move),o instanceof Function){const t=Gt(o,e.plugins),a={...Bt(n),playerID:r.playerID};let i=[];return void 0!==r.args&&(i=i.concat(r.args)),t(n.G,a,...i)}return Ut(`invalid move object: ${r.type}`),n.G}}}const Xt=[];function Zt(e,n=t){let r;const o=[];function a(t){if(l(e,t)&&(e=t,r)){const t=!Xt.length;for(let t=0;t<o.length;t+=1){const n=o[t];n[1](),Xt.push(n,e)}if(t){for(let e=0;e<Xt.length;e+=2)Xt[e][0](Xt[e+1]);Xt.length=0}}}return{set:a,update:function(t){a(t(e))},subscribe:function(i,s=t){const l=[i,s];return o.push(l),1===o.length&&(r=n(a)||t),i(e),()=>{const e=o.indexOf(l);-1!==e&&o.splice(e,1),0===o.length&&(r(),r=null)}}}}function en(e){const t=e-1;return t*t*t+1}function tn(e,{delay:t=0,duration:n=400,easing:r=en,x:o=0,y:a=0,opacity:i=0}){const s=getComputedStyle(e),l=+s.opacity,c="none"===s.transform?"":s.transform,u=l*(1-i);return{delay:t,duration:n,easing:r,css:(e,t)=>`\n\t\t\ttransform: ${c} translate(${(1-e)*o}px, ${(1-e)*a}px);\n\t\t\topacity: ${l-u*t}`}}function nn(e,t,n){const r=Object.create(e);return r.key=t[n][0],r.label=t[n][1].label,r}function rn(e){var t,n,r,o,a=e.label+"";function i(){return e.click_handler(e)}return{c(){t=P("div"),n=k(a),r=I(),D(t,"class","menu-item svelte-19bfq8g"),C(t,"active",e.pane==e.key),o=E(t,"click",i)},m(e,o){x(e,t,o),b(t,n),b(t,r)},p(r,o){e=o,r.panes&&a!==(a=e.label+"")&&j(n,a),(r.pane||r.panes)&&C(t,"active",e.pane==e.key)},d(e){e&&$(t),o()}}}function on(e){var n;let r=Object.entries(e.panes).reverse(),o=[];for(let t=0;t<r.length;t+=1)o[t]=rn(nn(e,r,t));return{c(){n=P("div");for(let e=0;e<o.length;e+=1)o[e].c();D(n,"class","menu svelte-19bfq8g")},m(e,t){x(e,n,t);for(let e=0;e<o.length;e+=1)o[e].m(n,null)},p(e,t){if(e.pane||e.panes){let a;for(r=Object.entries(t.panes).reverse(),a=0;a<r.length;a+=1){const i=nn(t,r,a);o[a]?o[a].p(e,i):(o[a]=rn(i),o[a].c(),o[a].m(n,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=r.length}},i:t,o:t,d(e){e&&$(n),w(o,e)}}}function an(e,t,n){let{pane:r,panes:o}=t;const a=U();return e.$set=e=>{"pane"in e&&n("pane",r=e.pane),"panes"in e&&n("panes",o=e.panes)},{pane:r,panes:o,dispatch:a,click_handler:({key:e})=>a("change",e)}}class sn extends me{constructor(e){var t;super(),document.getElementById("svelte-19bfq8g-style")||((t=P("style")).id="svelte-19bfq8g-style",t.textContent=".menu.svelte-19bfq8g{display:flex;margin-top:-10px;flex-direction:row;border:1px solid #ccc;border-radius:5px 5px 0 0;height:25px;line-height:25px;margin-right:-500px;transform-origin:bottom right;transform:rotate(-90deg) translate(0, -500px)}.menu-item.svelte-19bfq8g{line-height:25px;cursor:pointer;background:#fefefe;color:#555;padding-left:15px;padding-right:15px;text-align:center}.menu-item.svelte-19bfq8g:last-child{border-radius:0 5px 0 0}.menu-item.svelte-19bfq8g:first-child{border-radius:5px 0 0 0}.menu-item.active.svelte-19bfq8g{cursor:default;font-weight:bold;background:#ddd;color:#555}.menu-item.svelte-19bfq8g:hover{background:#ddd;color:#555}",b(document.head,t)),he(this,e,an,on,l,["pane","panes"])}}function ln(e){var t,n;return{c(){t=P("div"),n=k(e.label),D(t,"class","label svelte-1olzq4i")},m(e,r){x(e,t,r),b(t,n)},p(e,t){e.label&&j(n,t.label)},d(e){e&&$(t)}}}function cn(e){var n,r,o,a,s,l=e.label&&ln(e);return{c(){n=P("div"),r=P("div"),o=k(e.value),a=I(),l&&l.c(),D(r,"class","key-box svelte-1olzq4i"),D(n,"class","key svelte-1olzq4i"),C(n,"active",e.active),s=[E(window,"keydown",e.Keypress),E(r,"click",e.Activate)]},m(e,t){x(e,n,t),b(n,r),b(r,o),b(n,a),l&&l.m(n,null)},p(e,t){e.value&&j(o,t.value),t.label?l?l.p(e,t):((l=ln(t)).c(),l.m(n,null)):l&&(l.d(1),l=null),e.active&&C(n,"active",t.active)},i:t,o:t,d(e){e&&$(n),l&&l.d(),i(s)}}}function un(e,t,n){let r,{value:o,onPress:a=null,label:i=null,disable:s=!1}=t;const{disableHotkeys:l}=F("hotkeys");c(e,l,e=>{r=e,n("$disableHotkeys",r)});let u=!1;function d(){n("active",u=!1)}function p(){n("active",u=!0),setTimeout(d,200),a&&setTimeout(a,1)}return e.$set=e=>{"value"in e&&n("value",o=e.value),"onPress"in e&&n("onPress",a=e.onPress),"label"in e&&n("label",i=e.label),"disable"in e&&n("disable",s=e.disable)},{value:o,onPress:a,label:i,disable:s,disableHotkeys:l,active:u,Activate:p,Keypress:function(e){r||s||e.ctrlKey||e.metaKey||e.key!=o||(e.preventDefault(),p())}}}class dn extends me{constructor(e){var t;super(),document.getElementById("svelte-1olzq4i-style")||((t=P("style")).id="svelte-1olzq4i-style",t.textContent=".key.svelte-1olzq4i{display:flex;flex-direction:row;align-items:center}.key-box.svelte-1olzq4i{cursor:pointer;min-width:10px;padding-left:5px;padding-right:5px;height:20px;line-height:20px;text-align:center;border:1px solid #ccc;box-shadow:1px 1px 1px #888;background:#eee;color:#444}.key-box.svelte-1olzq4i:hover{background:#ddd}.key.active.svelte-1olzq4i .key-box.svelte-1olzq4i{background:#ddd;border:1px solid #999;box-shadow:none}.label.svelte-1olzq4i{margin-left:10px}",b(document.head,t)),he(this,e,un,cn,l,["value","onPress","label","disable"])}}function pn(e){var n,r,o,a,s,l,c,u,d,p;return{c(){var t;n=P("div"),r=P("span"),o=k(e.name),a=I(),(s=P("span")).textContent="(",l=I(),c=P("span"),u=I(),(d=P("span")).textContent=")",D(c,"class","arg-field svelte-1mppqmp"),D(c,"contenteditable",""),D(n,"class","move svelte-1mppqmp"),C(n,"active",e.active),p=[E(c,"blur",e.Deactivate),E(c,"keypress",(t=fn,function(e){return e.stopPropagation(),t.call(this,e)})),E(c,"keydown",e.OnKeyDown),E(n,"click",e.Activate)]},m(t,i){x(t,n,i),b(n,r),b(r,o),b(n,a),b(n,s),b(n,l),b(n,c),e.span2_binding(c),b(n,u),b(n,d)},p(e,t){e.name&&j(o,t.name),e.active&&C(n,"active",t.active)},i:t,o:t,d(t){t&&$(n),e.span2_binding(null),i(p)}}}const fn=()=>{};function vn(e,t,n){let r,{Activate:o,Deactivate:a,name:i,active:s}=t;const l=U();var c;return c=()=>{s?r.focus():r.blur()},T().$$.after_update.push(c),e.$set=e=>{"Activate"in e&&n("Activate",o=e.Activate),"Deactivate"in e&&n("Deactivate",a=e.Deactivate),"name"in e&&n("name",i=e.name),"active"in e&&n("active",s=e.active)},{Activate:o,Deactivate:a,name:i,active:s,span:r,OnKeyDown:function(e){"Enter"==e.key&&(e.preventDefault(),function(){try{const e=r.innerText;let t=new Function(`return [${e}]`)();l("submit",t)}catch(e){l("error",e)}n("span",r.innerText="",r)}()),"Escape"==e.key&&(e.preventDefault(),a())},span2_binding:function(e){J[e?"unshift":"push"](()=>{n("span",r=e)})}}}class hn extends me{constructor(e){var t;super(),document.getElementById("svelte-1mppqmp-style")||((t=P("style")).id="svelte-1mppqmp-style",t.textContent=".move.svelte-1mppqmp{display:flex;flex-direction:row;cursor:pointer;margin-left:10px;color:#666}.move.svelte-1mppqmp:hover{color:#333}.move.active.svelte-1mppqmp{color:#111;font-weight:bold}.arg-field.svelte-1mppqmp{outline:none;font-family:monospace}",b(document.head,t)),he(this,e,vn,pn,l,["Activate","Deactivate","name","active"])}}function mn(e){var t,n;return{c(){t=P("span"),n=k(e.error),D(t,"class","move-error svelte-smqssc")},m(e,r){x(e,t,r),b(t,n)},p(e,t){e.error&&j(n,t.error)},d(e){e&&$(t)}}}function gn(e){var t,n,r,o,a,i=new dn({props:{value:e.shortcut,onPress:e.Activate}}),s=new hn({props:{Activate:e.Activate,Deactivate:e.Deactivate,name:e.name,active:e.active}});s.$on("submit",e.Submit),s.$on("error",e.Error);var l=e.error&&mn(e);return{c(){t=P("div"),n=P("div"),i.$$.fragment.c(),r=I(),s.$$.fragment.c(),o=I(),l&&l.c(),D(n,"class","wrapper svelte-smqssc")},m(e,c){x(e,t,c),b(t,n),pe(i,n,null),b(n,r),pe(s,n,null),b(t,o),l&&l.m(t,null),a=!0},p(e,n){var r={};e.shortcut&&(r.value=n.shortcut),i.$set(r);var o={};e.name&&(o.name=n.name),e.active&&(o.active=n.active),s.$set(o),n.error?l?l.p(e,n):((l=mn(n)).c(),l.m(t,null)):l&&(l.d(1),l=null)},i(e){a||(se(i.$$.fragment,e),se(s.$$.fragment,e),a=!0)},o(e){le(i.$$.fragment,e),le(s.$$.fragment,e),a=!1},d(e){e&&$(t),fe(i),fe(s),l&&l.d()}}}function yn(e,t,n){let{shortcut:r,name:o,fn:a}=t;const{disableHotkeys:i}=F("hotkeys");let s="",l=!1;function c(){i.set(!1),n("error",s=""),n("active",l=!1)}return e.$set=e=>{"shortcut"in e&&n("shortcut",r=e.shortcut),"name"in e&&n("name",o=e.name),"fn"in e&&n("fn",a=e.fn)},{shortcut:r,name:o,fn:a,error:s,active:l,Activate:function(){i.set(!0),n("active",l=!0)},Deactivate:c,Submit:function(e){n("error",s=""),c(),a.apply(this,e.detail)},Error:function(e){n("error",s=e.detail),Ut(e.detail)}}}class bn extends me{constructor(e){var t;super(),document.getElementById("svelte-smqssc-style")||((t=P("style")).id="svelte-smqssc-style",t.textContent=".move-error.svelte-smqssc{color:#a00;font-weight:bold}.wrapper.svelte-smqssc{display:flex;flex-direction:row;align-items:center}",b(document.head,t)),he(this,e,yn,gn,l,["shortcut","name","fn"])}}var xn=function(e,t){return{parse:function(t){var n=JSON.parse(t,o).map(r),a=n[0];return"object"==typeof a&&a?function t(n,r,o){return Object.keys(o).reduce((function(o,a){var i=o[a];if(i instanceof e){var s=n[i];"object"!=typeof s||r.has(s)?o[a]=s:(r.add(s),o[a]=t(n,r,s))}return o}),o)}(n,new Set,a):a},stringify:function(e){for(var t,r=new Map,o=[],a=[],i=+n(r,o,e),s=function(e,a){if(t)return t=!t,a;switch(typeof a){case"object":if(null===a)return a;case"string":return r.get(a)||n(r,o,a)}return a};i<o.length;i++)t=!0,a[i]=JSON.stringify(o[i],s);return"["+a.join(",")+"]"}};function n(t,n,r){var o=e(n.push(r)-1);return t.set(r,o),o}function r(t){return t instanceof e?e(t):t}function o(t,n){return"string"==typeof n?new e(n):n}}(String);const $n=xn.parse,wn=xn.stringify;function Pn(e){var t,n,r,o,a,i,s,l,c,u=new dn({props:{value:"1",onPress:e.client.reset,label:"reset"}}),d=new dn({props:{value:"2",onPress:e.Save,label:"save"}}),p=new dn({props:{value:"3",onPress:e.Restore,label:"restore"}}),f=new dn({props:{value:".",disable:!0,label:"hide"}});return{c(){t=P("section"),n=P("li"),u.$$.fragment.c(),r=I(),o=P("li"),d.$$.fragment.c(),a=I(),i=P("li"),p.$$.fragment.c(),s=I(),l=P("li"),f.$$.fragment.c(),D(n,"class","svelte-1x2w9i0"),D(o,"class","svelte-1x2w9i0"),D(i,"class","svelte-1x2w9i0"),D(l,"class","svelte-1x2w9i0"),D(t,"id","debug-controls"),D(t,"class","controls")},m(e,v){x(e,t,v),b(t,n),pe(u,n,null),b(t,r),b(t,o),pe(d,o,null),b(t,a),b(t,i),pe(p,i,null),b(t,s),b(t,l),pe(f,l,null),c=!0},p(e,t){var n={};e.client&&(n.onPress=t.client.reset),u.$set(n)},i(e){c||(se(u.$$.fragment,e),se(d.$$.fragment,e),se(p.$$.fragment,e),se(f.$$.fragment,e),c=!0)},o(e){le(u.$$.fragment,e),le(d.$$.fragment,e),le(p.$$.fragment,e),le(f.$$.fragment,e),c=!1},d(e){e&&$(t),fe(u),fe(d),fe(p),fe(f)}}}function On(e,t,n){let{client:r}=t;return e.$set=e=>{"client"in e&&n("client",r=e.client)},{client:r,Save:function(){const e=r.getState(),t=wn({...e,_undo:[],_redo:[],deltalog:[]});window.localStorage.setItem("gamestate",t),window.localStorage.setItem("initialState",wn(r.initialState))},Restore:function(){const e=window.localStorage.getItem("gamestate"),t=window.localStorage.getItem("initialState");if(null!==e&&null!==t){const n=$n(e),o=$n(t);r.store.dispatch(je({state:n,initialState:o}))}}}}class kn extends me{constructor(e){var t;super(),document.getElementById("svelte-1x2w9i0-style")||((t=P("style")).id="svelte-1x2w9i0-style",t.textContent="li.svelte-1x2w9i0{list-style:none;margin:none;margin-bottom:5px}",b(document.head,t)),he(this,e,On,Pn,l,["client"])}