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;xe.setAutoFreeze.bind(xe),xe.setUseProxies.bind(xe),xe.applyPatches.bind(xe);const $e={name:"plugin-immer",fnWrap:e=>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)};class De{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=I(n.key,n.args,this.playerID);e={...e,...this.flow.processEvent(e,r)}}return e}}const Ee=[$e,{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}}},{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 De(e.flow,t).api(n)}],Ae=e=>{let t={...e.ctx};const n=e.plugins||{};return Object.entries(n).forEach(([e,{api:n}])=>{t[e]=n}),t},Se=(e,t)=>[...Ee,...t].filter(e=>void 0!==e.fnWrap).reduce((e,{fnWrap:t})=>t(e),e),_e=(e,t)=>([...Ee,...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,playerID:t.playerID});e={...e,plugins:{...e.plugins,[r]:{...o,api:i}}}}),e),je=(e,t)=>([...Ee,...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.dangerouslyFlushRawState){const i=(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:i}}}}}),e),Be=console.log,Ne=console.error;function Me(e){Ne("ERROR:",e)}function Te(e,t,n){return{...e,ctx:Re(e.ctx,n)}}function Re(e,t){let{_prevActivePlayers:n}=e,r={},o=null,i={};if(Array.isArray(t)){let e={};t.forEach(t=>e[t]=Le.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&&qe(r,i,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&&qe(r,i,o,t.others)}if(void 0!==t.all)for(let n=0;n<e.playOrder.length;n++){qe(r,i,e.playOrder[n],t.all)}if(t.value)for(const e in t.value)qe(r,i,e,t.value[e]);if(t.moveLimit)for(const e in r)void 0===i[e]&&(i[e]=t.moveLimit)}0==Object.keys(r).length&&(r=null),0==Object.keys(i).length&&(i=null);let a={};for(const e in r)a[e]=0;return{...e,activePlayers:r,_activePlayersMoveLimit:i,_activePlayersNumMoves:a,_prevActivePlayers:n,_nextActivePlayers:o}}function qe(e,t,n,r){"object"==typeof r&&r!==Le.NULL||(r={stage:r}),void 0!==r.stage&&(e[n]=r.stage,r.moveLimit&&(t[n]=r.moveLimit))}function ze(e,t){return e[t]+""}const Fe={DEFAULT:{first:(e,t)=>0===t.turn?t.playOrderPos:(t.playOrderPos+1)%t.playOrder.length,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length},RESET:{first:()=>0,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length},CONTINUE:{first:(e,t)=>t.playOrderPos,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length},ONCE:{first:()=>0,next:(e,t)=>{if(t.playOrderPos<t.playOrder.length-1)return t.playOrderPos+1}},CUSTOM:e=>({playOrder:()=>e,first:()=>0,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length}),CUSTOM_FROM:e=>({playOrder:t=>t[e],first:()=>0,next:(e,t)=>(t.playOrderPos+1)%t.playOrder.length})},Le={NULL:null};function Ue({moves:e,phases:t,endIf:n,onEnd:r,turn:o,events:i,plugins:a}){void 0===e&&(e={}),void 0===i&&(i={}),void 0===a&&(a=[]),void 0===t&&(t={}),n||(n=()=>{}),r||(r=e=>e),o||(o={});const s={...t};""in s&&Me("cannot specify phase with empty name"),s[""]={};let c={},l=new Set,u=null;Object.keys(e).forEach(e=>l.add(e));const p=e=>{const t=Se(e,a);return e=>{const n=Ae(e);return t(e.G,n)}},f=e=>t=>{let n=Ae(t);return e(t.G,n)},d={onEnd:p(r),endIf:f(n)};for(let e in s){const t=s[e];if(!0===t.start&&(u=e),void 0!==t.moves)for(let n of Object.keys(t.moves))c[e+"."+n]=t.moves[n],l.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=Fe.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)){c[e+"."+n+"."+t]=r[t],l.add(t)}}t.wrapped={onBegin:p(t.onBegin),onEnd:p(t.onEnd),endIf:f(t.endIf)},t.turn.wrapped={onMove:p(t.turn.onMove),onBegin:p(t.turn.onBegin),onEnd:p(t.turn.onEnd),endIf:f(t.turn.endIf)}}function h(e){return e.phase?s[e.phase]:s[""]}function y(e){return e}function v(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===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 c=[];if(e=i(e,{...s,arg:a,next:c}),i===I)break;const l=$(e);if(l){t.push({fn:I,arg:l,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}const u=P(e);if(u)t.push({fn:D,arg:u,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});else{if(i===y){const n=C(e);if(n){t.push({fn:E,arg:n,turn:e.ctx.turn,phase:e.ctx.phase,automatic:!0});continue}}t.push(...c)}}return e}function m(e,{next:t}){return t.push({fn:g}),e}function g(e,{next:t}){let{G:n,ctx:r}=e;return n=h(r).wrapped.onBegin(e),t.push({fn:b}),{...e,G:n,ctx:r}}function b(e,{currentPlayer:t}){let{G:n,ctx:r}=e;const o=h(r);t?(r={...r,currentPlayer:t},o.turn.activePlayers&&(r=Re(r,o.turn.activePlayers))):r=function(e,t,n){const r=n.order;let o=[...new Array(t.numPlayers)].map((e,t)=>t+"");void 0!==r.playOrder&&(o=r.playOrder(e,t));const i=r.first(e,t),a=typeof i;"number"!==a&&Me(`invalid value returned by turn.order.first — expected number got ${a} “${i}”.`);const s=ze(o,i);return t=Re(t={...t,currentPlayer:s,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 w(e,{arg:t,next:n,phase:r}){const o=h({phase:r});let{ctx:i}=e;if(t&&t.next){if(!(t.next in s))return Me("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:g}),e}function x(e,{arg:t,currentPlayer:n,next:r}){let{G:o,ctx:i}=e;const a=h(i),{endPhase:s,ctx:c}=function(e,t,n,r){const o=n.order;let i=t.playOrderPos,a=t.currentPlayer,s=!1;if(r&&!0!==r)"object"!=typeof r&&Me(`invalid argument to endTurn: ${r}`),Object.keys(r).forEach(e=>{switch(e){case"remove":a=ze(t.playOrder,i);break;case"next":i=t.playOrder.indexOf(r.next),a=r.next;break;default:Me(`invalid argument to endTurn: ${e}`)}});else{const n=o.next(e,t),r=typeof n;"number"!==r&&Me(`invalid value returned by turn.order.next — expected number got ${r} “${n}”.`),void 0===n?s=!0:(i=n,a=ze(t.playOrder,i))}return{endPhase:s,ctx:t={...t,playOrderPos:i,currentPlayer:a}}}(o,{...i,currentPlayer:n},a.turn,t);return i=c,e={...e,G:o,ctx:i},s?r.push({fn:D,turn:i.turn,phase:i.phase}):r.push({fn:b,currentPlayer:i.currentPlayer}),e}function k(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 $(e){return d.endIf(e)}function P(e){return h(e.ctx).wrapped.endIf(e)}function C(e){const t=h(e.ctx),n=e.ctx.numMoves||0;return!!(t.turn.moveLimit&&n>=t.turn.moveLimit)||t.turn.wrapped.endIf(e)}function I(e,{arg:t,phase:n}){e=D(e,{phase:n}),void 0===t&&(t=!0),e={...e,ctx:{...e.ctx,gameover:t}};const r=d.onEnd(e);return{...e,G:r}}function D(e,{arg:t,next:n,turn:r,automatic:o}){let i=(e=E(e,{turn:r,force:!0})).G,a=e.ctx;if(n&&n.push({fn:w,arg:t,phase:a.phase}),null===a.phase)return e;i=h(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(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=h(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`,Be(`INFO: ${p}`),e;var p;if(s=l.turn.wrapped.onEnd(e),n&&n.push({fn:x,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:D,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 A(e,{arg:t,next:n,automatic:r,playerID:o}){o=o||e.ctx.currentPlayer;let{ctx:i}=e,{activePlayers:a,_activePlayersMoveLimit:s}=i;const c=null!==a&&o in a;if(!t&&c){const e=h(i).turn.stages[a[o]];e&&e.next&&(t=e.next)}if(n&&t&&n.push({fn:k,arg:t,playerID:o}),!c)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){let{activePlayers:t,_activePlayersMoveLimit:n,_activePlayersNumMoves:r,_prevActivePlayers:o}=e;if(t&&0==Object.keys(t).length)if(e._nextActivePlayers)e=Re(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}}({...i,activePlayers:a,_activePlayersMoveLimit:s});const l={action:O("endStage",t),_stateID:e._stateID,turn:e.ctx.turn,phase:e.ctx.phase};r&&(l.automatic=!0);const u=[...e.deltalog||[],l];return{...e,ctx:i,deltalog:u}}const S={endStage:function(e,t){return v(e,[{fn:A,playerID:t}])},setStage:function(e,t,n){return v(e,[{fn:A,arg:n,playerID:t}])},endTurn:function(e,t,n){return v(e,[{fn:E,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},pass:function(e,t,n){return v(e,[{fn:E,turn:e.ctx.turn,phase:e.ctx.phase,force:!0,arg:n}])},endPhase:function(e){return v(e,[{fn:D,phase:e.ctx.phase,turn:e.ctx.turn}])},setPhase:function(e,t,n){return v(e,[{fn:D,phase:e.ctx.phase,turn:e.ctx.turn,arg:{next:n}}])},endGame:function(e,t,n){return v(e,[{fn:I,turn:e.ctx.turn,phase:e.ctx.phase,arg:n}])},setActivePlayers:Te};let _=[];return!1!==i.endTurn&&_.push("endTurn"),!1!==i.pass&&_.push("pass"),!1!==i.endPhase&&_.push("endPhase"),!1!==i.setPhase&&_.push("setPhase"),!1!==i.endGame&&_.push("endGame"),!1!==i.setActivePlayers&&_.push("setActivePlayers"),!1!==i.endStage&&_.push("endStage"),!1!==i.setStage&&_.push("setStage"),{ctx:e=>({numPlayers:e,turn:0,currentPlayer:"0",playOrder:[...new Array(e)].map((e,t)=>t+""),playOrderPos:0,phase:u,activePlayers:null}),init:e=>v(e,[{fn:m}]),isPlayerActive:function(e,t,n){return t.activePlayers?n in t.activePlayers:t.currentPlayer===n},eventHandlers:S,eventNames:Object.keys(S),enabledEventNames:_,moveMap:c,moveNames:[...l.values()],processMove:function(e,t){let n=h(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=A(e,{playerID:i,automatic:!0}));const s=n.turn.wrapped.onMove(e),c=(e={...e,G:s})._undo||[],l=t.type;return v(e={...e,_undo:[...c,{G:e.G,ctx:e.ctx,moveType:l}],_redo:[]},[{fn:y}])},processEvent:function(e,t){const{type:n,playerID:r,args:o}=t.payload;if(S.hasOwnProperty(n)){const t=[e,r].concat(o);return S[n].apply({},t)}return e},getMove:function(t,n,r){const o=h(t),i=o.turn.stages,{activePlayers:a}=t;if(a&&void 0!==a[r]&&a[r]!==Le.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 Ge(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=Ue(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=Se(o,e.plugins),i={...Ae(n),playerID:r.playerID};let a=[];return void 0!==r.args&&(a=a.concat(r.args)),t(n.G,i,...a)}return Me(`invalid move object: ${r.type}`),n.G}}}function He(){}const Ke=e=>e;function Ve(e,t){for(const n in t)e[n]=t[n];return e}function We(e){return e()}function Je(){return Object.create(null)}function Ye(e){e.forEach(We)}function Xe(e){return"function"==typeof e}function Qe(e,t){return e!=e?t==t:e!==t||e&&"object"==typeof e||"function"==typeof e}function Ze(e,t,n){e.$$.on_destroy.push(function(e,t){const n=e.subscribe(t);return n.unsubscribe?()=>n.unsubscribe():n}(t,n))}function et(e,t,n){return e[1]?Ve({},Ve(t.$$scope.ctx,e[1](n?n(t):{}))):t.$$scope.ctx}function tt(e){const t={};for(const n in e)"$"!==n[0]&&(t[n]=e[n]);return t}const nt="undefined"!=typeof window;let rt=nt?()=>window.performance.now():()=>Date.now(),ot=nt?e=>requestAnimationFrame(e):He;const it=new Set;let at,st=!1;function ct(){it.forEach(e=>{e[0](rt())||(it.delete(e),e[1]())}),st=it.size>0,st&&ot(ct)}function lt(e,t){e.appendChild(t)}function ut(e,t,n){e.insertBefore(t,n||null)}function pt(e){e.parentNode.removeChild(e)}function ft(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function dt(e){return document.createElement(e)}function ht(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function yt(e){return document.createTextNode(e)}function vt(){return yt(" ")}function mt(){return yt("")}function gt(e,t,n,r){return e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)}function bt(e,t,n){null==n?e.removeAttribute(t):e.setAttribute(t,n)}function wt(e,t){t=""+t,e.data!==t&&(e.data=t)}function xt(e,t){(null!=t||e.value)&&(e.value=t)}function kt(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 $t(e,t,n){e.classList[n?"add":"remove"](t)}function Pt(e,t){const n=document.createEvent("CustomEvent");return n.initCustomEvent(e,!1,!1,t),n}let Ct,Ot=0,It={};function Dt(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(!It[p]){if(!at){const e=dt("style");document.head.appendChild(e),at=e.sheet}It[p]=!0,at.insertRule(`@keyframes ${p} ${u}`,at.cssRules.length)}const f=e.style.animation||"";return e.style.animation=`${f?`${f}, `:""}${p} ${r}ms linear ${o}ms 1 both`,Ot+=1,p}function Et(e,t){e.style.animation=(e.style.animation||"").split(", ").filter(t?e=>e.indexOf(t)<0:e=>-1===e.indexOf("__svelte")).join(", "),t&&!--Ot&&ot(()=>{if(Ot)return;let e=at.cssRules.length;for(;e--;)at.deleteRule(e);It={}})}function At(e){Ct=e}function St(){if(!Ct)throw new Error("Function called outside component initialization");return Ct}function _t(e){St().$$.on_destroy.push(e)}function jt(){const e=Ct;return(t,n)=>{const r=e.$$.callbacks[t];if(r){const o=Pt(t,n);r.slice().forEach(t=>{t.call(e,o)})}}}function Bt(e,t){St().$$.context.set(e,t)}function Nt(e){return St().$$.context.get(e)}const Mt=[],Tt=[],Rt=[],qt=[],zt=Promise.resolve();let Ft,Lt=!1;function Ut(e){Rt.push(e)}function Gt(){const e=new Set;do{for(;Mt.length;){const e=Mt.shift();At(e),Ht(e.$$)}for(;Tt.length;)Tt.pop()();for(let t=0;t<Rt.length;t+=1){const n=Rt[t];e.has(n)||(n(),e.add(n))}Rt.length=0}while(Mt.length);for(;qt.length;)qt.pop()();Lt=!1}function Ht(e){e.fragment&&(e.update(e.dirty),Ye(e.before_update),e.fragment.p(e.dirty,e.ctx),e.dirty=null,e.after_update.forEach(Ut))}function Kt(e,t,n){e.dispatchEvent(Pt(`${t?"intro":"outro"}${n}`))}const Vt=new Set;let Wt;function Jt(){Wt={r:0,c:[],p:Wt}}function Yt(){Wt.r||Ye(Wt.c),Wt=Wt.p}function Xt(e,t){e&&e.i&&(Vt.delete(e),e.i(t))}function Qt(e,t,n,r){if(e&&e.o){if(Vt.has(e))return;Vt.add(e),Wt.c.push(()=>{Vt.delete(e),r&&(n&&e.d(1),r())}),e.o(t)}}const Zt={duration:0};function en(e,t,n,r){let o=t(e,n),i=r?0:1,a=null,s=null,c=null;function l(){c&&Et(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=Ke,tick:f=He,css:d}=o||Zt,h={start:rt()+n,b:t};t||(h.group=Wt,Wt.r+=1),a?s=h:(d&&(l(),c=Dt(e,i,t,r,n,p,d)),t&&f(0,1),a=u(h,r),Ut(()=>Kt(e,t,"start")),function(e){let t;st||(st=!0,ot(ct)),new Promise(n=>{it.add(t=[e,n])})}(t=>{if(s&&t>s.start&&(a=u(s,r),s=null,Kt(e,a.b,"start"),d&&(l(),c=Dt(e,i,a.b,a.duration,0,p,o.css))),a)if(t>=a.end)f(i=a.b,1-i),Kt(e,a.b,"end"),s||(a.b?l():--a.group.r||Ye(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){Xe(o)?(Ft||(Ft=Promise.resolve(),Ft.then(()=>{Ft=null})),Ft).then(()=>{o=o(),p(e)}):p(e)},end(){l(),a=s=null}}}const tn="undefined"!=typeof window?window:global;function nn(e,t,n){const{fragment:r,on_mount:o,on_destroy:i,after_update:a}=e.$$;r.m(t,n),Ut(()=>{const t=o.map(We).filter(Xe);i?i.push(...t):Ye(t),e.$$.on_mount=[]}),a.forEach(Ut)}function rn(e,t){e.$$.fragment&&(Ye(e.$$.on_destroy),e.$$.fragment.d(t),e.$$.on_destroy=e.$$.fragment=null,e.$$.ctx={})}function on(e,t){e.$$.dirty||(Mt.push(e),Lt||(Lt=!0,zt.then(Gt)),e.$$.dirty=Je()),e.$$.dirty[t]=!0}function an(e,t,n,r,o,i){const a=Ct;At(e);const s=t.props||{},c=e.$$={fragment:null,ctx:null,props:i,update:He,not_equal:o,bound:Je(),on_mount:[],on_destroy:[],before_update:[],after_update:[],context:new Map(a?a.$$.context:[]),callbacks:Je(),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&&on(e,t)),n)):s,c.update(),l=!0,Ye(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&&Xt(e.$$.fragment),nn(e,t.target,t.anchor),Gt()),At(a)}class sn{$destroy(){rn(this,1),this.$destroy=He}$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 cn=[];function ln(e,t=He){let n;const r=[];function o(t){if(Qe(e,t)&&(e=t,n)){const t=!cn.length;for(let t=0;t<r.length;t+=1){const n=r[t];n[1](),cn.push(n,e)}if(t){for(let e=0;e<cn.length;e+=2)cn[e][0](cn[e+1]);cn.length=0}}}return{set:o,update:function(t){o(t(e))},subscribe:function(i,a=He){const s=[i,a];return r.push(s),1===r.length&&(n=t(o)||He),i(e),()=>{const e=r.indexOf(s);-1!==e&&r.splice(e,1),0===r.length&&(n(),n=null)}}}}function un(e){const t=e-1;return t*t*t+1}function pn(e,{delay:t=0,duration:n=400,easing:r=un,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 fn(e,t,n){const r=Object.create(e);return r.key=t[n][0],r.label=t[n][1].label,r}function dn(e){var t,n,r,o,i=e.label+"";function a(){return e.click_handler(e)}return{c(){t=dt("div"),n=yt(i),r=vt(),bt(t,"class","menu-item svelte-19bfq8g"),$t(t,"active",e.pane==e.key),o=gt(t,"click",a)},m(e,o){ut(e,t,o),lt(t,n),lt(t,r)},p(r,o){e=o,r.panes&&i!==(i=e.label+"")&&wt(n,i),(r.pane||r.panes)&&$t(t,"active",e.pane==e.key)},d(e){e&&pt(t),o()}}}function hn(e){var t;let n=Object.entries(e.panes).reverse(),r=[];for(let t=0;t<n.length;t+=1)r[t]=dn(fn(e,n,t));return{c(){t=dt("div");for(let e=0;e<r.length;e+=1)r[e].c();bt(t,"class","menu svelte-19bfq8g")},m(e,n){ut(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=fn(o,n,i);r[i]?r[i].p(e,a):(r[i]=dn(a),r[i].c(),r[i].m(t,null))}for(;i<r.length;i+=1)r[i].d(1);r.length=n.length}},i:He,o:He,d(e){e&&pt(t),ft(r,e)}}}function yn(e,t,n){let{pane:r,panes:o}=t;const i=jt();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 vn extends sn{constructor(e){var t;super(),document.getElementById("svelte-19bfq8g-style")||((t=dt("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}",lt(document.head,t)),an(this,e,yn,hn,Qe,["pane","panes"])}}function mn(e){var t,n;return{c(){t=dt("div"),n=yt(e.label),bt(t,"class","label svelte-1olzq4i")},m(e,r){ut(e,t,r),lt(t,n)},p(e,t){e.label&&wt(n,t.label)},d(e){e&&pt(t)}}}function gn(e){var t,n,r,o,i,a=e.label&&mn(e);return{c(){t=dt("div"),n=dt("div"),r=yt(e.value),o=vt(),a&&a.c(),bt(n,"class","key-box svelte-1olzq4i"),bt(t,"class","key svelte-1olzq4i"),$t(t,"active",e.active),i=[gt(window,"keydown",e.Keypress),gt(n,"click",e.Activate)]},m(e,i){ut(e,t,i),lt(t,n),lt(n,r),lt(t,o),a&&a.m(t,null)},p(e,n){e.value&&wt(r,n.value),n.label?a?a.p(e,n):((a=mn(n)).c(),a.m(t,null)):a&&(a.d(1),a=null),e.active&&$t(t,"active",n.active)},i:He,o:He,d(e){e&&pt(t),a&&a.d(),Ye(i)}}}function bn(e,t,n){let r,{value:o,onPress:i=null,label:a=null,disable:s=!1}=t;const{disableHotkeys:c}=Nt("hotkeys");Ze(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 wn extends sn{constructor(e){var t;super(),document.getElementById("svelte-1olzq4i-style")||((t=dt("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}",lt(document.head,t)),an(this,e,bn,gn,Qe,["value","onPress","label","disable"])}}function xn(e){var t,n,r,o,i,a;return{c(){t=dt("div"),n=yt(e.name),r=yt("("),o=dt("span"),i=yt(")"),bt(o,"class","arg-field svelte-khot71"),bt(o,"contenteditable",""),bt(t,"class","move svelte-khot71"),$t(t,"active",e.active),a=[gt(o,"blur",e.Deactivate),gt(o,"keydown",e.OnKeyDown),gt(t,"click",e.Activate)]},m(a,s){ut(a,t,s),lt(t,n),lt(t,r),lt(t,o),e.span_1_binding(o),lt(t,i)},p(e,r){e.name&&wt(n,r.name),e.active&&$t(t,"active",r.active)},i:He,o:He,d(n){n&&pt(t),e.span_1_binding(null),Ye(a)}}}function kn(e,t,n){let r,{Activate:o,Deactivate:i,name:a,active:s}=t;const c=jt();var l;return l=()=>{s?r.focus():r.blur()},St().$$.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){Tt[e?"unshift":"push"](()=>{n("span",r=e)})}}}class $n extends sn{constructor(e){var t;super(),document.getElementById("svelte-khot71-style")||((t=dt("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}",lt(document.head,t)),an(this,e,kn,xn,Qe,["Activate","Deactivate","name","active"])}}function Pn(e){var t,n;return{c(){t=dt("span"),n=yt(e.error),bt(t,"class","move-error svelte-smqssc")},m(e,r){ut(e,t,r),lt(t,n)},p(e,t){e.error&&wt(n,t.error)},d(e){e&&pt(t)}}}function Cn(e){var t,n,r,o,i,a=new wn({props:{value:e.shortcut,onPress:e.Activate}}),s=new $n({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&&Pn(e);return{c(){t=dt("div"),n=dt("div"),a.$$.fragment.c(),r=vt(),s.$$.fragment.c(),o=vt(),c&&c.c(),bt(n,"class","wrapper svelte-smqssc")},m(e,l){ut(e,t,l),lt(t,n),nn(a,n,null),lt(n,r),nn(s,n,null),lt(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=Pn(n)).c(),c.m(t,null)):c&&(c.d(1),c=null)},i(e){i||(Xt(a.$$.fragment,e),Xt(s.$$.fragment,e),i=!0)},o(e){Qt(a.$$.fragment,e),Qt(s.$$.fragment,e),i=!1},d(e){e&&pt(t),rn(a),rn(s),c&&c.d()}}}function On(e,t,n){let{shortcut:r,name:o,fn:i}=t;const{disableHotkeys:a}=Nt("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),Me(e.detail)}}}class In extends sn{constructor(e){var t;super(),document.getElementById("svelte-smqssc-style")||((t=dt("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}",lt(document.head,t)),an(this,e,On,Cn,Qe,["shortcut","name","fn"])}}var Dn=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 En=Dn.parse,An=Dn.stringify;function Sn(e){var t,n,r,o,i,a,s,c,l,u=new wn({props:{value:"1",onPress:e.client.reset,label:"reset"}}),p=new wn({props:{value:"2",onPress:e.Save,label:"save"}}),f=new wn({props:{value:"3",onPress:e.Restore,label:"restore"}}),d=new wn({props:{value:".",disable:!0,label:"hide"}});return{c(){t=dt("section"),n=dt("li"),u.$$.fragment.c(),r=vt(),o=dt("li"),p.$$.fragment.c(),i=vt(),a=dt("li"),f.$$.fragment.c(),s=vt(),c=dt("li"),d.$$.fragment.c(),bt(n,"class","svelte-1x2w9i0"),bt(o,"class","svelte-1x2w9i0"),bt(a,"class","svelte-1x2w9i0"),bt(c,"class","svelte-1x2w9i0"),bt(t,"id","debug-controls"),bt(t,"class","controls")},m(e,h){ut(e,t,h),lt(t,n),nn(u,n,null),lt(t,r),lt(t,o),nn(p,o,null),lt(t,i),lt(t,a),nn(f,a,null),