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