boardgame.io
Version:
library for turn-based games
1 lines • 108 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";var t=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")()),n=function(){return Math.random().toString(36).substring(7).split("").join(".")},r={INIT:"@@redux/INIT"+n(),REPLACE:"@@redux/REPLACE"+n(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+n()}};function o(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 a(e,n,i){var s;if("function"==typeof n&&"function"==typeof i||"function"==typeof i&&"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 n&&void 0===i&&(i=n,n=void 0),void 0!==i){if("function"!=typeof i)throw new Error("Expected the enhancer to be a function.");return i(a)(e,n)}if("function"!=typeof e)throw new Error("Expected the reducer to be a function.");var l=e,c=n,u=[],d=u,p=!1;function f(){d===u&&(d=u.slice())}function v(){if(p)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 c}function h(e){if("function"!=typeof e)throw new Error("Expected the listener to be a function.");if(p)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 f(),d.push(e),function(){if(t){if(p)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,f();var n=d.indexOf(e);d.splice(n,1)}}}function m(e){if(!o(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(p)throw new Error("Reducers may not dispatch actions.");try{p=!0,c=l(c,e)}finally{p=!1}for(var t=u=d,n=0;n<t.length;n++){(0,t[n])()}return e}function g(e){if("function"!=typeof e)throw new Error("Expected the nextReducer to be a function.");l=e,m({type:r.REPLACE})}function y(){var e,n=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new TypeError("Expected the observer to be an object.");function t(){e.next&&e.next(v())}return t(),{unsubscribe:n(t)}}})[t]=function(){return this},e}return m({type:r.INIT}),(s={dispatch:m,subscribe:h,getState:v,replaceReducer:g})[t]=y,s}function i(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(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 l(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(n,!0).forEach((function(t){i(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(n).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(){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 u(){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 l({},n,{dispatch:r=c.apply(void 0,a)(n.dispatch)})}}}const d=(e,t,n,r)=>({type:"MAKE_MOVE",payload:{type:e,args:t,playerID:n,credentials:r}}),p=(e,t,n,r)=>({type:"GAME_EVENT",payload:{type:e,args:t,playerID:n,credentials:r}}),f=(e,t,n,r)=>({type:"GAME_EVENT",payload:{type:e,args:t,playerID:n,credentials:r},automatic:!0}),v=e=>({type:"SYNC",state:e.state,log:e.log,initialState:e.initialState,clientOnly:!0}),h=e=>({type:"RESET",state:e,clientOnly:!0}),m=(e,t)=>({type:"UNDO",payload:{type:null,args:null,playerID:e,credentials:t}}),g=(e,t)=>({type:"REDO",payload:{type:null,args:null,playerID:e,credentials:t}});var y,b,x,$=Object.freeze({makeMove:d,gameEvent:p,automaticGameEvent:f,sync:v,update:(e,t)=>({type:"UPDATE",state:e,deltalog:t,clientOnly:!0}),reset:h,undo:m,redo:g,plugin:(e,t,n,r)=>({type:"PLUGIN",payload:{type:e,args:t,playerID:n,credentials:r}})}),w="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},P=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}}(),O="undefined"!=typeof Symbol?Symbol("immer-nothing"):(x=!0,(b="immer-nothing")in(y={})?Object.defineProperty(y,b,{value:x,enumerable:!0,configurable:!0,writable:!0}):y[b]=x,y),k="undefined"!=typeof Symbol?Symbol("immer-draftable"):"__$immer_draftable",I="undefined"!=typeof Symbol?Symbol("immer-state"):"__$immer_state";function _(e){return!!e&&!!e[I]}function E(e){if(!e||"object"!==(void 0===e?"undefined":w(e)))return!1;if(Array.isArray(e))return!0;var t=Object.getPrototypeOf(e);return!t||t===Object.prototype||(!!e[k]||!!e.constructor[k])}var D=Object.assign||function(e,t){for(var n in t)M(t,n)&&(e[n]=t[n]);return e},j="undefined"!=typeof Reflect&&Reflect.ownKeys?Reflect.ownKeys:void 0!==Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Object.getOwnPropertyNames;function S(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 j(e).forEach((function(r){if(r!==I){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 A(e,t){if(Array.isArray(e))for(var n=0;n<e.length;n++)t(n,e[n],e);else j(e).forEach((function(n){return t(n,e[n],e)}))}function C(e,t){return Object.getOwnPropertyDescriptor(e,t).enumerable}function M(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function z(e,t){return e===t?0!==e||1/e==1/t:e!=e&&t!=t}var N={},B=[],G=function(){return B[B.length-1]};function q(e,t){var n=Array.isArray(e),r=K(e);A(r,(function(t){!function(e,t,n){var r=N[t];r?r.enumerable=n:N[t]=r={configurable:!0,enumerable:n,get:function(){return function(e,t){F(e);var n=T(e)[t];if(!e.finalizing&&n===e.base[t]&&E(n))return U(e),e.copy[t]=q(n,e);return n}(this[I],t)},set:function(e){!function(e,t,n){if(F(e),e.assigned[t]=!0,!e.modified){if(z(T(e)[t],n))return;R(e),U(e)}e.copy[t]=n}(this[I],t,e)}};Object.defineProperty(e,t,r)}(r,t,n||C(e,t))}));var o={scope:t?t.scope:G(),modified:!1,finalizing:!1,finalized:!1,assigned:{},parent:t,base:e,draft:r,copy:null,revoke:L,revoked:!1};return function(e,t,n){Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0})}(r,I,o),o.scope.push(o),r}function L(){this.revoked=!0}function T(e){return e.copy||e.base}function R(e){e.modified||(e.modified=!0,e.parent&&R(e.parent))}function U(e){e.copy||(e.copy=K(e.base))}function K(e){var t=e&&e[I];if(t){t.finalizing=!0;var n=S(t.draft,!0);return t.finalizing=!1,n}return S(e)}function F(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(T(e)))}function V(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]]&&!M(t,r[o]))return!0;return r.length!==Object.keys(t).length}function J(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 H=Object.freeze({scopes:B,currentScope:G,willFinalize:function(e,t,n){var r=G();r.forEach((function(e){return e.finalizing=!0})),void 0!==e&&e!==t||(n&&function e(t){if(!t||"object"!==(void 0===t?"undefined":w(t)))return;var n=t[I];if(!n)return;var r=n.base,o=n.draft,a=n.assigned;if(Array.isArray(t)){if(J(n)){if(R(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]||M(r,t)?a[t]||e(o[t]):(a[t]=!0,R(n))})),Object.keys(r).forEach((function(e){void 0!==o[e]||M(o,e)||(a[e]=!1,R(n))}))}(t),function(e){for(var t=e.length-1;t>=0;t--){var n=e[t];!1===n.modified&&(Array.isArray(n.base)?J(n)&&R(n):V(n)&&R(n))}}(r))},createDraft:q}),W=[],Y=function(){return W[W.length-1]};function Q(e,t){var n={scope:t?t.scope:Y(),modified:!1,finalized:!1,assigned:{},parent:t,base:e,draft:null,drafts:{},copy:null,revoke:null},r=Array.isArray(e)?Proxy.revocable([n],Z):Proxy.revocable(n,X),o=r.revoke,a=r.proxy;return n.draft=a,n.revoke=o,n.scope.push(n),a}var X={get:function(e,t){if(t===I)return e;var n=e.drafts;if(!e.modified&&M(n,t))return n[t];var r=ee(e)[t];if(e.finalized||!E(r))return r;if(e.modified){if(r!==e.base[t])return r;n=e.copy}return n[t]=Q(r,e)},has:function(e,t){return t in ee(e)},ownKeys:function(e){return Reflect.ownKeys(ee(e))},set:function(e,t,n){if(!e.modified){if(n?z(e.base[t],n)||n===e.drafts[t]:z(e.base[t],n)&&t in e.base)return!0;te(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,te(e));e.copy&&delete e.copy[t];return!0},getOwnPropertyDescriptor:function(e,t){var n=ee(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")}},Z={};function ee(e){return e.copy||e.base}function te(e){e.modified||(e.modified=!0,e.copy=D(S(e.base),e.drafts),e.drafts=null,e.parent&&te(e.parent))}A(X,(function(e,t){Z[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}})),Z.deleteProperty=function(e,t){if(isNaN(parseInt(t)))throw new Error("Immer only supports deleting array indices");return X.deleteProperty.call(this,e[0],t)},Z.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 X.set.call(this,e[0],t,n)};var ne=Object.freeze({scopes:W,currentScope:Y,willFinalize:function(){},createDraft:Q});function re(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;A(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 oe(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":w(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 ae={useProxies:"undefined"!=typeof Proxy&&"undefined"!=typeof Reflect,autoFreeze:"undefined"==typeof process&&"verifyMinified"===function(){}.name,onAssign:null,onDelete:null,onCopy:null},ie=new(function(){function e(t){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),D(this,ae,t),this.setUseProxies(this.useProxies),this.produce=this.produce.bind(this)}return P(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(E(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[I].modified)throw new Error("An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.");E(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===O?void 0:a}},{key:"setAutoFreeze",value:function(e){this.autoFreeze=e}},{key:"setUseProxies",value:function(e){this.useProxies=e,D(this,e?ne:H)}},{key:"applyPatches",value:function(e,t){return _(e)?oe(e,t):this.produce(e,(function(e){return oe(e,t)}))}},{key:"finalize",value:function(e,t,n,r){var o=this,a=e[I];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;A(l,(function(e){M(c,e)||o.onDelete(a,e)}))}this.onCopy&&this.onCopy(a),this.autoFreeze&&1===this.scopes.length&&Object.freeze(a.copy),n&&re(a,t,n,r)}return a.copy}},{key:"finalizeTree",value:function(e,t,n,r){var o=this,a=e[I];a&&(this.useProxies||(a.finalizing=!0,a.copy=S(a.draft,!0),a.finalizing=!1),e=a.copy);var i=this.onAssign;return A(e,(function s(l,c,u){if(c===u)throw Error("Immer forbids circular references");var d=!!a&&u===e;if(_(c)){if(c=n&&d&&!a.assigned[l]?o.finalize(c,t.concat(l),n,r):o.finalize(c),Array.isArray(u)||C(u,l)?u[l]=c:Object.defineProperty(u,l,{value:c}),d&&c===a.base[l])return}else{if(d&&z(c,a.base[l]))return;E(c)&&!Object.isFrozen(c)&&A(c,s)}d&&i&&i(a,l,c)})),e}}]),e}()),se=ie.produce;ie.setAutoFreeze.bind(ie),ie.setUseProxies.bind(ie),ie.applyPatches.bind(ie);const le={name:"plugin-immer",fnWrap:e=>(t,n,...r)=>{let o=!1;const a=se(t,t=>{const a=e(t,n,...r);if("INVALID_MOVE"!==a)return a;o=!0});return o?"INVALID_MOVE":a}};function ce(e){return(ce="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 ue(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 de(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);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 fe(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?pe(n,!0).forEach((function(t){de(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 ve(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 he(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 me(e,t){return t.c=e.c,t.s0=e.s0,t.s1=e.s1,t.s2=e.s2,t}function ge(e,t){var n=new he(e),r=t&&t.state,o=n.next;return o.quick=o,r&&("object"==ce(r)&&me(r,n),o.state=function(){return me(n,{})}),o}var ye=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 ge(t.seed,{state:!0}):new ge("",{state:t.prngstate}))();return this.state=fe({},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:ve(new Array(t).keys()).map((function(){return Math.floor(e()*o)+1}))}};for(var o in t)r(o);return fe({},n,{Die:function(t,n){return void 0===t&&(t=6),void 0===n?Math.floor(e()*t)+1:ve(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})}}])&&ue(t.prototype,n),r&&ue(t,r),e}();ye.seed=function(){return(+new Date).toString(36).slice(-10)};class be{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=f(n.key,n.args,this.playerID);e={...e,...this.flow.processEvent(e,r)}}return e}}const xe=[le,{name:"random",noClient:({api:e})=>e._obj.isUsed(),flush:({api:e})=>e._obj.getState(),api:({data:e})=>new ye(e).api(),setup:({game:e})=>{let t=e.seed;return void 0===t&&(t=ye.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 be(e.flow,t).api(n)}],$e=e=>{let t={...e.ctx};const n=e.plugins||{};return Object.entries(n).forEach(([e,{api:n}])=>{t[e]=n}),t},we=(e,t)=>[...xe,...t].filter(e=>void 0!==e.fnWrap).reduce((e,{fnWrap:t})=>t(e),e),Pe=(e,t)=>([...xe,...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),Oe=(e,t)=>([...xe,...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),ke=console.log,Ie=console.error;function _e(e){Ie("ERROR:",e)}function Ee(e,t,n){return{...e,ctx:De(e.ctx,n)}}function De(e,t){let{_prevActivePlayers:n}=e,r={},o=null,a={};if(Array.isArray(t)){let e={};t.forEach(t=>e[t]=Ce.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&&je(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&&je(r,a,o,t.others)}if(void 0!==t.all)for(let n=0;n<e.playOrder.length;n++){je(r,a,e.playOrder[n],t.all)}if(t.value)for(const e in t.value)je(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 je(e,t,n,r){"object"==typeof r&&r!==Ce.NULL||(r={stage:r}),void 0!==r.stage&&(e[n]=r.stage,r.moveLimit&&(t[n]=r.moveLimit))}function Se(e,t){return e[t]+""}const Ae={first:(e,t)=>0===t.turn?t.playOrderPos:(t.playOrderPos+1)%t.playOrder.length,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length},Ce={NULL:null};function Me({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&&_e("cannot specify phase with empty name"),l[""]={};let c={},u=new Set,d=null;Object.keys(e).forEach(e=>u.add(e));const f=e=>{const t=we(e,i);return e=>{const n=$e(e);return t(e.G,n)}},v=e=>t=>{let n=$e(t);return e(t.G,n)},h={onEnd:f(r),endIf:v(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=Ae),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:f(t.onBegin),onEnd:f(t.onEnd),endIf:v(t.endIf)},t.turn.wrapped={onMove:f(t.turn.onMove),onBegin:f(t.turn.onBegin),onEnd:f(t.turn.onEnd),endIf:v(t.turn.endIf)}}function m(e){return e.phase?l[e.phase]:l[""]}function g(e){return e}function y(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===D){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===E)break;const c=k(e);if(c){t.push({fn:E,arg:c,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}const u=I(e);if(u)t.push({fn:D,arg:u,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});else{if(a===g){const n=_(e);if(n){t.push({fn:j,arg:n,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}}t.push(...l)}}return e}function b(e,{next:t}){return t.push({fn:x}),e}function x(e,{next:t}){let{G:n,ctx:r}=e;return n=m(r).wrapped.onBegin(e),t.push({fn:$}),{...e,G:n,ctx:r}}function $(e,{currentPlayer:t}){let{G:n,ctx:r}=e;const o=m(r);t?(r={...r,currentPlayer:t},o.turn.activePlayers&&(r=De(r,o.turn.activePlayers))):r=function(e,t){let{G:n,ctx:r}=e;const o=$e(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&&_e(`invalid value returned by turn.order.first — expected number got ${l} “${s}”.`);const c=Se(i,s);return r={...r,currentPlayer:c,playOrderPos:s,playOrder:i},r=De(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 w(e,{arg:t,next:n,phase:r}){const o=m({phase:r});let{ctx:a}=e;if(t&&t.next){if(!(t.next in l))return _e("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:x}),e}function P(e,{arg:t,currentPlayer:n,next:r}){let{G:o,ctx:a}=e;const i=m(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&&_e(`invalid argument to endTurn: ${r}`),Object.keys(r).forEach(e=>{switch(e){case"remove":t=Se(i.playOrder,s);break;case"next":s=i.playOrder.indexOf(r.next),t=r.next;break;default:_e(`invalid argument to endTurn: ${e}`)}});else{const n=$e(e),r=o.next(a,n),c=typeof r;void 0!==r&&"number"!==c&&_e(`invalid value returned by turn.order.next — expected number or undefined got ${c} “${r}”.`),void 0===r?l=!0:(s=r,t=Se(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:D,turn:a.turn,phase:a.phase}):r.push({fn:$,currentPlayer:a.currentPlayer}),e}function O(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 k(e){return h.endIf(e)}function I(e){return m(e.ctx).wrapped.endIf(e)}function _(e){const t=m(e.ctx),n=e.ctx.numMoves||0;return!!(t.turn.moveLimit&&n>=t.turn.moveLimit)||t.turn.wrapped.endIf(e)}function E(e,{arg:t,phase:n}){e=D(e,{phase:n}),void 0===t&&(t=!0),e={...e,ctx:{...e.ctx,gameover:t}};const r=h.onEnd(e);return{...e,G:r}}function D(e,{arg:t,next:n,turn:r,automatic:o}){let a=(e=j(e,{turn:r,force:!0})).G,i=e.ctx;if(n&&n.push({fn:w,arg:t,phase:i.phase}),null===i.phase)return e;a=m(i).wrapped.onEnd(e),i={...i,phase:null};const s={action:p("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 j(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=m(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`,ke(`INFO: ${d}`),e;var d;if(s=c.turn.wrapped.onEnd(e),n&&n.push({fn:P,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:D,turn:l.turn,phase:l.phase}),e}const f={action:p("endTurn",t),_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase};a&&(f.automatic=!0);const v=[...e.deltalog||[],f];return{...e,G:s,ctx:l,deltalog:v,_undo:[],_redo:[]}}function S(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=m(a).turn.stages[i[o]];e&&e.next&&(t=e.next)}if(n&&t&&n.push({fn:O,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=De(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:p("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 A(t,n,r){const o=m(t),a=o.turn.stages,{activePlayers:i}=t;if(i&&void 0!==i[r]&&i[r]!==Ce.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 C={endStage:function(e,t){return y(e,[{fn:S,playerID:t}])},setStage:function(e,t,n){return y(e,[{fn:S,arg:n,playerID:t}])},endTurn:function(e,t,n){return y(e,[{fn:j,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},pass:function(e,t,n){return y(e,[{fn:j,turn:e.ctx.turn,phase:e.ctx.phase,force:!0,arg:n}])},endPhase:function(e){return y(e,[{fn:D,phase:e.ctx.phase,turn:e.ctx.turn}])},setPhase:function(e,t,n){return y(e,[{fn:D,phase:e.ctx.phase,turn:e.ctx.turn,arg:{next:n}}])},endGame:function(e,t,n){return y(e,[{fn:E,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},setActivePlayers:Ee};let M=[];return!1!==a.endTurn&&M.push("endTurn"),!1!==a.pass&&M.push("pass"),!1!==a.endPhase&&M.push("endPhase"),!1!==a.setPhase&&M.push("setPhase"),!1!==a.endGame&&M.push("endGame"),!1!==a.setActivePlayers&&M.push("setActivePlayers"),!1!==a.endStage&&M.push("endStage"),!1!==a.setStage&&M.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=>y(e,[{fn:b}]),isPlayerActive:function(e,t,n){return t.activePlayers?n in t.activePlayers:t.currentPlayer===n},eventHandlers:C,eventNames:Object.keys(C),enabledEventNames:M,moveMap:c,moveNames:[...u.values()],processMove:function(e,t){let n=m(e.ctx);const r=A(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=S(e,{playerID:s,automatic:!0}));const c=n.turn.wrapped.onMove(e);return y(e={...e,G:c},[{fn:g}])},processEvent:function(e,t){const{type:n,playerID:r,args:o}=t.payload;if(C.hasOwnProperty(n)){const t=[e,r].concat(o);return C[n].apply({},t)}return e},getMove:A}}function ze(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=Me(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=we(o,e.plugins),a={...$e(n),playerID:r.playerID};let i=[];return void 0!==r.args&&(i=i.concat(r.args)),t(n.G,a,...i)}return _e(`invalid move object: ${r.type}`),n.G}}}function Ne(){}const Be=e=>e;function Ge(e,t){for(const n in t)e[n]=t[n];return e}function qe(e){return e()}function Le(){return Object.create(null)}function Te(e){e.forEach(qe)}function Re(e){return"function"==typeof e}function Ue(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function Ke(e,t,n){e.$$.on_destroy.push(function(e,t){const n=e.subscribe(t);return n.unsubscribe?()=>n.unsubscribe():n}(t,n))}function Fe(e,t,n){return e[1]?Ge({},Ge(t.$$scope.ctx,e[1](n?n(t):{}))):t.$$scope.ctx}function Ve(e){const t={};for(const n in e)"$"!==n[0]&&(t[n]=e[n]);return t}const Je="undefined"!=typeof window;let He=Je?()=>window.performance.now():()=>Date.now(),We=Je?e=>requestAnimationFrame(e):Ne;const Ye=new Set;let Qe,Xe=!1;function Ze(){Ye.forEach(e=>{e[0](He())||(Ye.delete(e),e[1]())}),Xe=Ye.size>0,Xe&&We(Ze)}function et(e,t){e.appendChild(t)}function tt(e,t,n){e.insertBefore(t,n||null)}function nt(e){e.parentNode.removeChild(e)}function rt(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function ot(e){return document.createElement(e)}function at(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function it(e){return document.createTextNode(e)}function st(){return it(" ")}function lt(){return it("")}function ct(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function ut(e,t,n){null==n?e.removeAttribute(t):e.setAttribute(t,n)}function dt(e,t){t=""+t,e.data!==t&&(e.data=t)}function pt(e,t){(null!=t||e.value)&&(e.value=t)}function ft(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 vt(e,t,n){e.classList[n?"add":"remove"](t)}function ht(e,t){const n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!1,!1,t),n}let mt,gt=0,yt={};function bt(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(!yt[d]){if(!Qe){const e=ot("style");document.head.appendChild(e),Qe=e.sheet}yt[d]=!0,Qe.insertRule(`@keyframes ${d} ${u}`,Qe.cssRules.length)}const p=e.style.animation||"";return e.style.animation=`${p?`${p}, `:""}${d} ${r}ms linear ${o}ms 1 both`,gt+=1,d}function xt(e,t){e.style.animation=(e.style.animation||"").split(", ").filter(t?e=>e.indexOf(t)<0:e=>-1===e.indexOf("__svelte")).join(", "),t&&!--gt&&We(()=>{if(gt)return;let e=Qe.cssRules.length;for(;e--;)Qe.deleteRule(e);yt={}})}function $t(e){mt=e}function wt(){if(!mt)throw new Error("Function called outside component initialization");return mt}function Pt(e){wt().$$.on_destroy.push(e)}function Ot(){const e=mt;return(t,n)=>{const r=e.$$.callbacks[t];if(r){const o=ht(t,n);r.slice().forEach(t=>{t.call(e,o)})}}}function kt(e,t){wt().$$.context.set(e,t)}function It(e){return wt().$$.context.get(e)}const _t=[],Et=[],Dt=[],jt=[],St=Promise.resolve();let At,Ct=!1;function Mt(e){Dt.push(e)}function zt(){const e=new Set;do{for(;_t.length;){const e=_t.shift();$t(e),Nt(e.$$)}for(;Et.length;)Et.pop()();for(let t=0;t<Dt.length;t+=1){const n=Dt[t];e.has(n)||(n(),e.add(n))}Dt.length=0}while(_t.length);for(;jt.length;)jt.pop()();Ct=!1}function Nt(e){e.fragment&&(e.update(e.dirty),Te(e.before_update),e.fragment.p(e.dirty,e.ctx),e.dirty=null,e.after_update.forEach(Mt))}function Bt(e,t,n){e.dispatchEvent(ht(`${t?"intro":"outro"}${n}`))}const Gt=new Set;let qt;function Lt(){qt={r:0,c:[],p:qt}}function Tt(){qt.r||Te(qt.c),qt=qt.p}function Rt(e,t){e&&e.i&&(Gt.delete(e),e.i(t))}function Ut(e,t,n,r){if(e&&e.o){if(Gt.has(e))return;Gt.add(e),qt.c.push(()=>{Gt.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}}const Kt={duration:0};function Ft(e,t,n,r){let o=t(e,n),a=r?0:1,i=null,s=null,l=null;function c(){l&&xt(e,l)}function u(e,t){const n=e.b-a;return t*=Math.abs(n),{a:a,b:e.b,d:n,duration:t,start:e.start,end:e.start+t,group:e.group}}function d(t){const{delay:n=0,duration:r=300,easing:d=Be,tick:p=Ne,css:f}=o||Kt,v={start:He()+n,b:t};t||(v.group=qt,qt.r+=1),i?s=v:(f&&(c(),l=bt(e,a,t,r,n,d,f)),t&&p(0,1),i=u(v,r),Mt(()=>Bt(e,t,"start")),function(e){let t;Xe||(Xe=!0,We(Ze)),new Promise(n=>{Ye.add(t=[e,n])})}(t=>{if(s&&t>s.start&&(i=u(s,r),s=null,Bt(e,i.b,"start"),f&&(c(),l=bt(e,a,i.b,i.duration,0,d,o.css))),i)if(t>=i.end)p(a=i.b,1-a),Bt(e,i.b,"end"),s||(i.b?c():--i.group.r||Te(i.group.c)),i=null;else if(t>=i.start){const e=t-i.start;a=i.a+i.d*d(e/i.duration),p(a,1-a)}return!(!i&&!s)}))}return{run(e){Re(o)?(At||(At=Promise.resolve(),At.then(()=>{At=null})),At).then(()=>{o=o(),d(e)}):d(e)},end(){c(),i=s=null}}}const Vt="undefined"!=typeof window?window:global;function Jt(e,t,n){const{fragment:r,on_mount:o,on_destroy:a,after_update:i}=e.$$;r.m(t,n),Mt(()=>{const t=o.map(qe).filter(Re);a?a.push(...t):Te(t),e.$$.on_mount=[]}),i.forEach(Mt)}function Ht(e,t){e.$$.fragment&&(Te(e.$$.on_destroy),e.$$.fragment.d(t),e.$$.on_destroy=e.$$.fragment=null,e.$$.ctx={})}function Wt(e,t){e.$$.dirty||(_t.push(e),Ct||(Ct=!0,St.then(zt)),e.$$.dirty=Le()),e.$$.dirty[t]=!0}function Yt(e,t,n,r,o,a){const i=mt;$t(e);const s=t.props||{},l=e.$$={fragment:null,ctx:null,props:a,update:Ne,not_equal:o,bound:Le(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(i?i.$$.context:[]),callbacks:Le(),dirty:null};let c=!1;l.ctx=n?n(e,s,(t,n,r=n)=>(l.ctx&&o(l.ctx[t],l.ctx[t]=r)&&(l.bound[t]&&l.bound[t](r),c&&Wt(e,t)),n)):s,l.update(),c=!0,Te(l.before_update),l.fragment=r(l.ctx),t.target&&(t.hydrate?l.fragment.l(function(e){return Array.from(e.childNodes)}(t.target)):l.fragment.c(),t.intro&&Rt(e.$$.fragment),Jt(e,t.target,t.anchor),zt()),$t(i)}class Qt{$destroy(){Ht(this,1),this.$destroy=Ne}$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(){}}const Xt=[];function Zt(e,t=Ne){let n;const r=[];function o(t){if(Ue(e,t)&&(e=t,n)){const t=!Xt.length;for(let t=0;t<r.length;t+=1){const n=r[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:o,update:function(t){o(t(e))},subscribe:function(a,i=Ne){const s=[a,i];return r.push(s),1===r.length&&(n=t(o)||Ne),a(e),()=>{const e=r.indexOf(s);-1!==e&&r.splice(e,1),0===r.length&&(n(),n=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=ot("div"),n=it(a),r=st(),ut(t,"class","menu-item svelte-19bfq8g"),vt(t,"active",e.pane==e.key),o=ct(t,"click",i)},m(e,o){tt(e,t,o),et(t,n),et(t,r)},p(r,o){e=o,r.panes&&a!==(a=e.label+"")&&dt(n,a),(r.pane||r.panes)&&vt(t,"active",e.pane==e.key)},d(e){e&&nt(t),o()}}}function on(e){var t;let n=Object.entries(e.panes).reverse(),r=[];for(let t=0;t<n.length;t+=1)r[t]=rn(nn(e,n,t));return{c(){t=ot("div");for(let e=0;e<r.length;e+=1)r[e].c();ut(t,"class","menu svelte-19bfq8g")},m(e,n){tt(e,t,n);for(let e=0;e<r.length;e+=1)r[e].m(t,null)},p(e,o){if(e.pane||e.panes){let a;for(n=Object.entries(o.panes).reverse(),a=0;a<n.length;a+=1){const i=nn(o,n,a);r[a]?r[a].p(e,i):(r[a]=rn(i),r[a].c(),r[a].m(t,null))}for(;a<r.length;a+=1)r[a].d(1);r.length=n.length}},i:Ne,o:Ne,d(e){e&&nt(t),rt(r,e)}}}function an(e,t,n){let{pane:r,panes:o}=t;const a=Ot();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 Qt{constructor(e){var t;super(),document.getElementById("svelte-19bfq8g-style")||((t=ot("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}",et(document.head,t)),Yt(this,e,an,on,Ue,["pane","panes"])}}function ln(e){var t,n;return{c(){t=ot("div"),n=it(e.label),ut(t,"class","label svelte-1olzq4i")},m(e,r){tt(e,t,r),et(t,n)},p(e,t){e.label&&dt(n,t.label)},d(e){e&&nt(t)}}}function cn(e){var t,n,r,o,a,i=e.label&&ln(e);return{c(){t=ot("div"),n=ot("div"),r=it(e.value),o=st(),i&&i.c(),ut(n,"class","key-box svelte-1olzq4i"),ut(t,"class","key svelte-1olzq4i"),vt(t,"active",e.active),a=[ct(window,"keydown",e.Keypress),ct(n,"click",e.Activate)]},m(e,a){tt(e,t,a),et(t,n),et(n,r),et(t,o),i&&i.m(t,null)},p(e,n){e.value&&dt(r,n.value),n.label?i?i.p(e,n):((i=ln(n)).c(),i.m(t,null)):i&&(i.d(1),i=null),e.active&&vt(t,"active",n.active)},i:Ne,o:Ne,d(e){e&&nt(t),i&&i.d(),Te(a)}}}function un(e,t,n){let r,{value:o,onPress:a=null,label:i=null,disable:s=!1}=t;const{disableHotkeys:l}=It("hotkeys");Ke(e,l,e=>{r=e,n("$disableHotkeys",r)});let c=!1;function u(){n("active",c=!1)}function d(){n("active",c=!0),setTimeout(u,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:c,Activate:d,Keypress:function(e){r||s||e.ctrlKey||e.metaKey||e.key!=o||(e.preventDefault(),d())}}}class dn extends Qt{constructor(e){var t;super(),document.getElementById("svelte-1olzq4i-style")||((t=ot("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}",et(document.head,t)),Yt(this,e,un,cn,Ue,["value","onPress","label","disable"])}}function pn(e){var t,n,r,o,a,i,s,l,c,u;return{c(){var d;t=ot("div"),n=ot("span"),r=it(e.name),o=st(),(a=ot("span")).textContent="(",i=st(),s=ot("span"),l=st(),(c=ot("span")).textContent=")",ut(s,"class","arg-field svelte-1mppqmp"),ut(s,"contenteditable",""),ut(t,"class","move svelte-1mppqmp"),vt(t,"active",e.active),u=[ct(s,"blur",e.Deactivate),ct(s,"keypress",(d=fn,function(e){return e.stopPropagation(),d.call(this,e)})),ct(s,"keydown",e.OnKeyDown),ct(t,"click",e.Activate)]},m(u,d){tt(u,t,d),et(t,n),et(n,r),et(t,o),et(t,a),et(t,i),et(t,s),e.span2_binding(s),et(t,l),et(t,c)},p(e,n){e.name&&dt(r,n.name),e.active&&vt(t,"active",n.active)},i:Ne,o:Ne,d(n){n&&nt(t),e.span2_binding(null),Te(u)}}}const fn=()=>{};function vn(e,t,n){let r,{Activate:o,Deactivate:a,name:i,active:s}=t;const l=Ot();var c;return c=()=>{s?r.focus():r.blur()},wt().$$.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){Et[e?"unshift":"push"](()=>{n("span",r=e)})}}}class hn extends Qt{constructor(e){var t;super(),document.getElementById("svelte-1mppqmp-style")||((t=ot("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}",et(document.head,t)),Yt(this,e,vn,pn,Ue,["Activate","Deactivate","name","active"])}}function mn(e){var t,n;return{c(){t=ot("span"),n=it(e.error),ut(t,"class","move-error svelte-smqssc")},m(e,r){tt(e,t,r),et(t,n)},p(e,t){e.error&&dt(n,t.error)},d(e){e&&nt(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=ot("div"),n=ot("div"),i.$$.fragment.c(),r=st(),s.$$.fragment.c(),o=st(),l&&l.c(),ut(n,"class","wrapper svelte-smqssc")},m(e,c){tt(e,t,c),et(t,n),Jt(i,n,null),et(n,r),Jt(s,n,null),et(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||(Rt(i.$$.fragment,e),Rt(s.$$.fragment,e),a=!0)},o(e){Ut(i.$$.fragment,e),Ut(s.$$.fragment,e),a=!1},d(e){e&&nt(t),Ht(i),Ht(s),l&&l.d()}}}function yn(e,t,n){let{shortcut:r,name:o,fn:a}=t;const{disableHotkeys:i}=It("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),_e(e.detail)}}}class bn extends Qt{constructor(e){var t;super(),document.getElementById("svelte-smqssc-style")||((t=ot("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}",et(document.head,t)),Yt(this,e,yn,gn,Ue,["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=ot("section"),n=ot("li"),u.$$.fragment.c(),r=st(),o=ot("li"),d.$$.fragment.c(),a=st(),i=ot("li"),p.$$.fragment.c(),s=st(),l=ot("li"),f.$$.fragment.c(),ut(n,"class","svelte-1x2w9i0"),ut(o,"class","svelte-1x2w9i0"),ut(i,"class","svelte-1x2w9i0"),ut(l,"class","svelte-1x2w9i0"),ut(t,"id","debug-controls"),ut(t,"class","controls")},m(e,v){tt(e,t,v),et(t,n),Jt(u,n,null),et(t,r),et(t,o),Jt(d,o,null),et(t,a),et(t,i),Jt(p,i,null),et(t,s),et(t,l),Jt(f,l,null),c=!0},p(e,t){var n={};e.client&&(n.onPress=t.client.reset),u.$set(n)},i(e){c||(Rt(u.$$.fragment,e),Rt(d.$$.fragment,e),Rt(p.$$.fragment,e),Rt(f.$$.fragment,e),c=!0)},o(e){Ut(u.$$.fragment,e),Ut(d.$$.fragment,e),Ut(p.$$.fragment,e),Ut(f.$$.fragment,e),c=!1},d(e){e&&nt(t),Ht(u),Ht(d),Ht(p),Ht(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(v({state:n,initialState:o}))}}}}class kn extends Qt{constructor(e){var t;super(),document.getElementById("svelte-1x2w9i0-style")||((t=ot("style")).id="svelte-1x2w9i0-style",t.textContent="li.svelte-1x2w9i