UNPKG

reactant-share

Version:

A framework for building shared web applications with Reactant

1 lines 50.2 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("reactant"),require("data-transport"),require("reactant-last-action"),require("reactant-router"),require("reactant-storage"),require("broadcast-channel")):"function"==typeof define&&define.amd?define(["exports","reactant","data-transport","reactant-last-action","reactant-router","reactant-storage","broadcast-channel"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).reactantShare={},e.reactant,e.dataTransport,e.reactantLastAction,e.reactantRouter,e.reactantStorage,e.broadcastChannel)}(this,(function(e,t,r,o,n,i,a){"use strict";var s="@@reactant:proxyClient",c="@@reactant:isClient",l="@@reactant:loadFullState",u="@@reactant:syncRouter",p="@@reactant:syncClientIdToServer",h="@@reactant:removeClientIdToServer",d="@@reactant:proxyServer",f="@@reactant:lastAction",v="@@reactant:syncToClients",y="@@reactant:syncWorkerRouter",g="@@reactant:syncClientIdsFromClients",m=Symbol("SharedAppOptions"),b="Storage",w="Router",S=Symbol("proxyExecutor"),k="@@reactant:coworkerProxyWorkerExecute",O="@@reactant:coworkerSyncState",C="@@reactant:coworkerRequestSyncAllState",R="@@reactant:coworkerPushAllState",D=Symbol("coworker"),P="@@reactant:syncState",A="@@reactant:syncModuleState",x=function(e,t){return x=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},x(e,t)};function j(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}x(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var E=function(){return E=Object.assign||function(e){for(var t,r=1,o=arguments.length;r<o;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},E.apply(this,arguments)};function I(e,t){var r={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(r[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n<o.length;n++)t.indexOf(o[n])<0&&Object.prototype.propertyIsEnumerable.call(e,o[n])&&(r[o[n]]=e[o[n]])}return r}function T(e,t,r,o){var n,i=arguments.length,a=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,o);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(i<3?n(a):i>3?n(t,r,a):n(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function _(e,t){return function(r,o){t(r,o,e)}}function N(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function H(e,t,r,o){return new(r||(r=Promise))((function(n,i){function a(e){try{c(o.next(e))}catch(e){i(e)}}function s(e){try{c(o.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((o=o.apply(e,t||[])).next())}))}function q(e,t){var r,o,n,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=s(0),a.throw=s(1),a.return=s(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(s){return function(c){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;a&&(a=0,s[0]&&(i=0)),i;)try{if(r=1,o&&(n=2&s[0]?o.return:s[0]?o.throw||((n=o.return)&&n.call(o),0):o.next)&&!(n=n.call(o,s[1])).done)return n;switch(o=0,n&&(s=[2&s[0],n.value]),s[0]){case 0:case 1:n=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,o=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!n||s[1]>n[0]&&s[1]<n[3])){i.label=s[1];break}if(6===s[0]&&i.label<n[1]){i.label=n[1],n=s;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(s);break}n[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],o=0}finally{r=n=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,c])}}}function M(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],o=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&o>=e.length&&(e=void 0),{value:e&&e[o++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function K(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var o,n,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(o=i.next()).done;)a.push(o.value)}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return a}function L(e,t,r){if(r||2===arguments.length)for(var o,n=0,i=t.length;n<i;n++)!o&&n in t||(o||(o=Array.prototype.slice.call(t,0,n)),o[n]=t[n]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var W,F,B=function(){return Math.random().toString(36).slice(2)},J=!!globalThis.SharedWorkerGlobalScope,G=function(){function e(e,r){var o=this;this.sharedAppOptions=e,this.lastAction=r,this.serverCallbacks=new Set,this.clientCallbacks=new Set,this.clientDestroyCallbacks=new Set,this.clientId=null,this.allowDisableSync=function(){return!0},this.clientIds=[],this.serverHooks={},this.isolatedModules=[],this.onServer=function(e){if("function"!=typeof e)throw new Error("'onServer' argument should be a function.");if(o.serverCallbacks.add(e),o.lastHooks&&o.lastHooks.size>0&&o.isServer&&o.transport)try{var t=e(o.transport);o.lastHooks.add(t)}catch(e){console.error(e)}return function(){o.serverCallbacks.delete(e)}},this.onClient=function(e){if("function"!=typeof e)throw new Error("'onClient' argument should be a function.");if(o.clientCallbacks.add(e),o.lastHooks&&o.lastHooks.size>0&&o.isClient&&o.transport)try{var t=e(o.transport);o.lastHooks.add(t)}catch(e){console.error(e)}return function(){o.clientCallbacks.delete(e)}},this.onClientDestroy=function(e){if("function"!=typeof e)throw new Error("'onClientDestroy' argument should be a function.");return o.clientDestroyCallbacks.add(e),function(){o.clientDestroyCallbacks.delete(e)}},this.onClient((function(e){o.clientId=B(),o.clientIds=[],o.syncFullState({forceSync:!1});var r=e.listen(v,(function(e){return H(o,void 0,void 0,(function(){return q(this,(function(r){return e?(this[t.storeKey].dispatch({type:"".concat(t.actionIdentifier,"_").concat(l),state:this.getNextState(e),_reactant:t.actionIdentifier}),this.lastAction.sequence=e[this.lastAction.stateKey]._sequence,[2]):[2]}))}))}));e.emit({name:p,respond:!1},o.clientId);var n=e.listen(g,(function(){return H(o,void 0,void 0,(function(){return q(this,(function(t){return this.clientId&&e.emit({name:p,respond:!1},this.clientId),[2]}))}))})),i=function(){e.emit({name:h,respond:!1},o.clientId)};return window.addEventListener("pagehide",i),function(){o.previousPort="client",null==r||r(),null==n||n(),window.removeEventListener("pagehide",i)}})),this.onServer((function(e){o.clientId=null,e.emit({name:g,respond:!1});var t=e.listen(p,(function(e){o.clientIds.includes(e)||o.clientIds.push(e)})),r=e.listen(h,(function(e){var t,r,n=o.clientIds.findIndex((function(t){return t===e}));if(-1!==n){o.clientIds.splice(n,1);var i=o.clientDestroyCallbacks;try{for(var a=M(i),s=a.next();!s.done;s=a.next()){var c=s.value;try{c(e)}catch(e){console.error(e)}}}catch(e){t={error:e}}finally{try{s&&!s.done&&(r=a.return)&&r.call(a)}finally{if(t)throw t.error}}}}));return function(){o.previousPort="server",null==t||t(),null==r||r()}}))}var r;return e.prototype.disableShare=function(e){this.isolatedModules=this.isolatedModules.concat(e)},Object.defineProperty(e.prototype,"isolatedInstanceKeys",{get:function(){var e;return this.lastIsolatedInstances!==this.isolatedModules&&(this.lastIsolatedInstanceKeys=this.isolatedModules.map((function(e){return e[t.identifierKey]}))),null!==(e=this.lastIsolatedInstanceKeys)&&void 0!==e?e:[]},enumerable:!1,configurable:!0}),e.prototype.hasIsolatedState=function(e){return this.isolatedInstanceKeys.includes(e)},Object.defineProperty(e.prototype,"id",{get:function(){var e;return null!==(e=this.clientId)&&void 0!==e?e:"__SERVER__"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"shared",{get:function(){return!(!this.sharedAppOptions.port||!this.sharedAppOptions.type)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){var e;return null!==(e=this.sharedAppOptions.portName)&&void 0!==e?e:"default"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disableSyncClient",{get:function(){return"hidden"===document.visibilityState&&!this.sharedAppOptions.forcedSyncClient&&this.allowDisableSync()},enumerable:!1,configurable:!0}),e.prototype.detectPort=function(e){var t;return null===(t=this.portApp)||void 0===t?void 0:t[e]},Object.defineProperty(e.prototype,"isWorkerMode",{get:function(){return"SharedWorker"===this.sharedAppOptions.type},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isServerWorker",{get:function(){return this.isWorkerMode&&this.isServer},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isServer",{get:function(){return!!this.detectPort("server")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isClient",{get:function(){return!!this.detectPort("client")},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"transports",{get:function(){var e;return null!==(e=this.sharedAppOptions.transports)&&void 0!==e?e:{}},enumerable:!1,configurable:!0}),e.prototype.setPort=function(e,t){var r,o,n,i;if(this.transport=t,this.lastHooks)try{for(var a=M(this.lastHooks),s=a.next();!s.done;s=a.next()){var c=s.value;try{null==c||c()}catch(e){console.error(e)}}}catch(e){r={error:e}}finally{try{s&&!s.done&&(o=a.return)&&o.call(a)}finally{if(r)throw r.error}}this.lastHooks=new Set,this.portApp=e;var l=this.isClient?this.clientCallbacks:this.serverCallbacks;try{for(var u=M(l),p=u.next();!p.done;p=u.next()){var h=p.value;try{c=h(t);this.lastHooks.add(c)}catch(e){console.error(e)}}}catch(e){n={error:e}}finally{try{p&&!p.done&&(i=u.return)&&i.call(u)}finally{if(n)throw n.error}}},e.prototype.syncToClients=function(){var e,r=this[t.storeKey];if(!this.transports.server)throw new Error("Failed to 'syncToClients()', 'transports.server' does not exist.");null===(e=this.transports.server)||void 0===e||e.emit({name:v,respond:!1},r.getState())},e.prototype.syncFullState=function(){return H(this,arguments,void 0,(function(e){var r,o=(void 0===e?{}:e).forceSync,n=void 0===o||o;return q(this,(function(e){switch(e.label){case 0:return n&&(this.syncFullStatePromise=void 0),this.syncFullStatePromise?[4,this.syncFullStatePromise]:[3,2];case 1:return e.sent(),[2];case 2:if(void 0===this.transports.client)throw new Error("The current client transport does not exist.");return this.syncFullStatePromise=this.transports.client.emit(l,n?-1:this.lastAction.sequence),[4,this.syncFullStatePromise];case 3:if(r=e.sent(),this.syncFullStatePromise=void 0,void 0===r)throw new Error("Failed to sync full state from server port.");return null===r||!n&&this.lastAction.sequence>r[this.lastAction.stateKey]._sequence||(this[t.storeKey].dispatch({type:"".concat(t.actionIdentifier,"_").concat(l),state:this.getNextState(r),_reactant:t.actionIdentifier}),this.lastAction.sequence=r[this.lastAction.stateKey]._sequence),[2]}}))}))},e.prototype.getNextState=function(e){var r=this[t.storeKey].getState(),o=E(E({},e),{router:r.router});return this.isolatedInstanceKeys.length&&this.isolatedInstanceKeys.forEach((function(e){e&&(o[e]=r[e])})),o},e.prototype.transform=function(e,t){if("server"!==e&&"client"!==e)throw new Error("The port '".concat(e,"' is not supported."));this.sharedAppOptions.transports[e]=null!=t?t:this.sharedAppOptions.transports[e],this.sharedAppOptions.transform(e)},e=T([t.injectable(),_(0,t.inject(m)),N("design:paramtypes",[Object,"function"==typeof(r=void 0!==o.LastAction&&o.LastAction)?r:Object])],e)}(),U=function(e){function r(t,r){var o=e.call(this,r)||this;return o.portDetector=t,o.options=r,o.onRehydrated((function(){o.portDetector.onServer((function(){o.persist()})),o.portDetector.onClient((function(){o.pause()})),o.portDetector.isServer&&o.portDetector.syncToClients()})),o}return j(r,e),r.prototype.setStorage=function(t,r){return e.prototype.setStorage.call(this,t,this.options.disableClientRehydrated&&this.portDetector.isClient?E(E({},r),{blacklist:[],whitelist:[]}):r)},r=T([t.injectable({name:b}),_(1,t.inject(i.StorageOptions)),N("design:paramtypes",[G,Object])],r)}(i.Storage),V=function(e){function r(t,r){var o=e.call(this)||this;return o.portDetector=t,o.storage=r,o.middleware=function(e){return function(e){return function(t){var r,n=t._patches,i=t.type,a=t.method;return null==n||n.forEach((function(e,t){var n=e.path;e.op,e.value;var s=o.portDetector.hasIsolatedState("".concat(n[0]));if(t){if(r!==s){var c="".concat(i,".").concat(a);throw new Error("Update state error: Mixed update of shared state and isolated state is not supported, please check method '".concat(c,"'."))}}else r=s})),e(t)}}},o}return j(r,e),r.prototype.checkPatches=function(e,t){t._patches.forEach((function(r){var o=r.op,n=r.path,i=r.value;if("replace"===o&&("[object Object]"===toString.call(i)||Array.isArray(i))){var a=n.reduce((function(e,t){return null==e?void 0:e[t]}),e);if(a&&"object"==typeof a&&n[0]!==w){var s=n.join(".");console.warn("The state '".concat(s,"' operation in the method '").concat(t.method,"' of the module '").concat(String(t.type),"' is a replacement update operation, be sure to check the state '").concat(s,"' update operation and use mutation updates to ensure the minimum set of update patches."))}}}))},r=T([t.injectable(),_(1,t.optional()),N("design:paramtypes",[G,U])],r)}(t.PluginModule),z=function(e,r){var o=e.instance[t.modulesKey][r.module];if(!o)throw new Error("The module '".concat(r.module,"' is not a multiple instances injected module, and it does not exist."));var n=o[r.method];if("function"!=typeof n)throw new Error("The '".concat(r.method,"' method for module '").concat(r.module,"' does not exist."));return o[S]?o[S](r):n.apply(o,r.args)},Y=function(e){var r,n=e.app,i=e.transport,a=e.disposeServer,u=e.disposeClient,p=e.enablePatchesChecker;if(!i)throw new Error("The server transport does not exist.");null==a||a(),null==u||u();var h=n.instance[t.containerKey],d=h.get(o.LastAction),v=h.get(G);p&&h.get(V);if(J){var y=!1;globalThis.addEventListener("connect",(function(){y||(y=!0,v.setPort({server:n},i))}))}else v.setPort({server:n},i);var g=[];return g.push(i.listen(c,(function(){return H(void 0,void 0,void 0,(function(){return q(this,(function(e){return[2,!0]}))}))}))),g.push(i.listen(l,(function(e){return H(void 0,void 0,void 0,(function(){var t;return q(this,(function(r){return[2,d.sequence>e?null===(t=n.store)||void 0===t?void 0:t.getState():null]}))}))}))),g.push(i.listen(s,(function(e){return H(void 0,void 0,void 0,(function(){var t,r,o;return q(this,(function(i){switch(i.label){case 0:return e.hook?"function"!=typeof(t=v.serverHooks[e.hook])?[3,2]:[4,t(e)]:[3,2];case 1:return r=i.sent(),[2,[v.lastAction.sequence,r]];case 2:return[4,z(n,e)];case 3:return o=i.sent(),[2,[v.lastAction.sequence,o]]}}))}))}))),g.push((function(){return i.dispose()})),g.push(null===(r=n.store)||void 0===r?void 0:r.subscribe((function(){var e,t;try{if(d.action){var r=d.action;(null===(t=null===(e=v.lastAction.options)||void 0===e?void 0:e.ignoreAction)||void 0===t?void 0:t.call(e,r))||i.emit({name:f,respond:!1},r)}}finally{}}))),"client"===v.previousPort&&v.syncToClients(),function(){var e,t;try{for(var r=M(g),o=r.next();!o.done;o=r.next()){var n=o.value;null==n||n()}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}}},Q=function(e){var r=e.app,n=e.transport,i=e.disposeServer,a=e.disposeClient,s=e.enablePatchesFilter,c=e.preloadedState;if(!n)throw new Error("The client transport does not exist.");null==i||i(),null==a||a();var l=r.instance[t.containerKey],u=l.get(o.LastAction),p=l.get(G);p.setPort({client:r},n);var h=[];return c&&(u.sequence=c[u.stateKey]._sequence),h.push(n.listen(f,(function(e){return H(void 0,void 0,void 0,(function(){var o,n,i,a,c;return q(this,(function(l){return p.disableSyncClient||(e._sequence&&e._sequence===u.sequence+1?(e._reactant===t.actionIdentifier?(o=r.store.getState(),n=null!==(c=e._patches)&&void 0!==c?c:[],i=s?n.filter((function(e){return o[e.path[0]]})):n,a=t.applyPatches(o,i),r.store.dispatch(E(E({},e),{state:a}))):r.store.dispatch(e),u.sequence=e._sequence):p.syncFullState({forceSync:!1})),[2]}))}))}))),h.push(n.listen(d,(function(e){return H(void 0,void 0,void 0,(function(){var t=e.clientIds,o=e.portName,n=I(e,["clientIds","portName"]);return q(this,(function(e){switch(e.label){case 0:return Array.isArray(t)&&p.clientId&&!t.includes(p.clientId)||o&&o!==p.name?[2,new Promise((function(){}))]:[4,z(r,n)];case 1:return[2,e.sent()]}}))}))}))),h.push((function(){return n.dispose()})),function(){var e,t;try{for(var r=M(h),o=r.next();!o.done;o=r.next()){var n=o.value;null==n||n()}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}}},X=function(e,t,o){var n=new a.BroadcastChannel("reactant-share-channel:".concat(e));return r.createTransport("Base",{listener:function(e){return n.onmessage=function(t){e(JSON.parse(t))},function(){return n.onmessage=null,n.close()}},sender:function(e){return n.postMessage(JSON.stringify(e))},prefix:"reactant-share:".concat(e),verbose:t,logger:o})},Z=new Map,$=B(),ee="reactant:lock",te="reactant:tab",re=!1,oe=function(e,t){0!==e.length&&(Object.keys(localStorage).forEach((function(r){var o;if(!r.indexOf(ee)){var n=JSON.parse(null!==(o=localStorage.getItem(r))&&void 0!==o?o:"[]"),i=JSON.stringify(n.filter((function(t){return-1===e.indexOf(t.tabId)})));t.setItem(r,i)}})),e.forEach((function(e){return t.removeItem("".concat(te,":").concat(e))})))},ne=function(e,t){var r;return(r=document.createElement("iframe")).src="about:blank",r.setAttribute("style","display: none;"),document.body.appendChild(r),F=r.contentWindow.localStorage,re||(re=!0,window.addEventListener("pagehide",(function(){oe([$],localStorage)}))),function(){if(void 0===W){var e="".concat(te,":").concat($);F.setItem(e,Date.now().toString()),W=window.setInterval((function(){return F.setItem(e,Date.now().toString())}),1e3)}}(),new Promise((function(r,o){var n,i=B();Z.set(e,null!==(n=Z.get(e))&&void 0!==n?n:new Map),Z.get(e).set(i,t);var a="".concat(ee,":").concat(e),s=localStorage.getItem(a),c=JSON.parse(null!=s?s:"[]");c.push({tabId:$,lockId:i});var l,u=function(t){return H(void 0,void 0,void 0,(function(){var n,s,c,l,p,h;return q(this,(function(d){switch(d.label){case 0:if(t.key!==a||!t.newValue)return[3,5];if(n=K(JSON.parse(t.newValue),1),(null==(s=n[0])?void 0:s.tabId)!==$||(null==s?void 0:s.lockId)!==i)return[3,5];window.removeEventListener("storage",u),d.label=1;case 1:return d.trys.push([1,3,,4]),[4,Z.get(e).get(i)({name:e,mode:"exclusive"})];case 2:return c=d.sent(),r(c),[3,4];case 3:return l=d.sent(),o(l),[3,4];case 4:Z.get(e).delete(i),(p=JSON.parse(null!==(h=localStorage.getItem(a))&&void 0!==h?h:"[]")).splice(0,1),F.setItem(a,JSON.stringify(p)),d.label=5;case 5:return[2]}}))}))};window.addEventListener("storage",u),F.setItem(a,JSON.stringify(c)),oe((l=[],Object.keys(localStorage).forEach((function(e){var t;if(e.indexOf(te))e.indexOf(ee)||JSON.parse(null!==(t=localStorage.getItem(e))&&void 0!==t?t:"[]").forEach((function(e){localStorage.getItem("".concat(te,":").concat(e.tabId))||l.push(e.tabId)}));else{var r=localStorage.getItem(e);if(r&&Date.now()-Number(r)>2999){var o=e.replace("".concat(te,":"),"");l.push(o)}}})),l),F)}))},ie=function(e,t){var r;return!!(null===(r=navigator.locks)||void 0===r?void 0:r.request)?navigator.locks.request(e,t).catch((function(r){return 18===r.code&&r.toString().startsWith("SecurityError")?ne(e,t):r})):ne(e,t)};!function(e){function r(){var t=e.apply(this,L([],K(arguments),!1))||this;return t.beforeCombineRootReducers=function(e){return Object.keys(e).forEach((function(e){var t=K(e.split("/"),2),r=t[0],o=t[1];"@@reactant"===r&&console.error("The decorator for class ".concat(o," should set \"@injectable({ name: '").concat(o,"' })\"."))})),e},t}j(r,e),r=T([t.injectable()],r)}(t.PluginModule);var ae=function(e){var r,i,a,s,c,l,u,p=e.share,h=I(e,["share"]);null!==(r=h.modules)&&void 0!==r||(h.modules=[]),null!==(i=h.devOptions)&&void 0!==i||(h.devOptions={}),h.devOptions.enablePatches=!0,h.modules.push(o.LastAction,{provide:o.LastActionOptions,useFactory:function(e){var t;return{stateKey:"lastAction-".concat(p.name),ignoreAction:function(r){var o,i;t||(t=e.get(G));var a=null===(i=null===(o=r._patches)||void 0===o?void 0:o[0])||void 0===i?void 0:i.path[0];return r.type===n.LOCATION_CHANGE||a&&t.hasIsolatedState("".concat(a))}}},deps:[t.ModuleRef]},{provide:m,useValue:p},G),p.enablePatchesChecker&&h.modules.push(V);var d=null===(a=p.transports)||void 0===a?void 0:a.server,f=null===(s=p.transports)||void 0===s?void 0:s.client,v="server"===p.port,y=p.transform;if(p.transform=function(e){var t,r,o=null===(t=p.transports)||void 0===t?void 0:t.server,n=null===(r=p.transports)||void 0===r?void 0:r.client;if("server"===e){if(!o)throw new Error("'transports.server' does not exist.");l=Y({app:c,transport:o,disposeServer:l,disposeClient:u,enablePatchesChecker:p.enablePatchesChecker})}else{if(!n)throw new Error("'transports.client' does not exist.");u=Q({app:c,transport:n,disposeServer:l,disposeClient:u,enablePatchesFilter:p.enablePatchesFilter})}null==y||y(e)},c=t.createApp(h),p.port)if(v){if(!d)throw new Error("'transports.server' does not exist.");l=Y({app:c,transport:d,enablePatchesChecker:p.enablePatchesChecker})}else{if(!f)throw new Error("'transports.client' does not exist.");u=Q({app:c,transport:f,enablePatchesFilter:p.enablePatchesFilter})}return c},se=function(e){return H(void 0,void 0,void 0,(function(){var t,r,o,n,i,a,s,l;return q(this,(function(u){switch(u.label){case 0:return e.share.forcedSyncClient=!0,/^((?!chrome|android).)*safari/i.test(navigator.userAgent)&&!e.share.forcedShare?(e.share.transports={},e.share.port=void 0,e.share.type="Base",[2,ae(e)]):(null!==(o=(a=e.share).transports)&&void 0!==o||(a.transports={}),null!==(n=(s=e.share.transports).client)&&void 0!==n||(s.client=X(e.share.name,e.share.enableTransportDebugger,e.share.transportLogger)),null!==(i=(l=e.share.transports).server)&&void 0!==i||(l.server=X(e.share.name,e.share.enableTransportDebugger,e.share.transportLogger)),e.share.port?[2,ae(e)]:(r=!1,[4,Promise.race([new Promise((function(o){ie("reactant-share-app-lock:".concat(e.share.name),(function(){return H(void 0,void 0,void 0,(function(){var n,i;return q(this,(function(a){return t?null===(i=(n=e.share).transform)||void 0===i||i.call(n,"server"):(e.share.port="server",t=ae(e)),r=!0,o(t),[2,new Promise((function(){}))]}))}))}))})),new Promise((function(t){return H(void 0,void 0,void 0,(function(){var o,n,i;return q(this,(function(a){switch(a.label){case 0:return[4,null===(i=null===(n=e.share.transports)||void 0===n?void 0:n.client)||void 0===i?void 0:i.emit(c)];case 1:return a.sent()&&!r&&(e.share.port="client",o=ae(e),t(o)),[2]}}))}))}))])]));case 1:return[2,t=u.sent()]}}))}))},ce=function(e,r,o,n){var i,a;void 0===n&&(n={});var c=e[r],l=null!=o?o:[];if("string"!=typeof r)throw new Error("'delegate()' is valid only for method name with string type.");if("function"!=typeof c)throw new Error("The property '".concat(r,"'' must be a method in class '").concat(e.constructor.name,"'."));if(!Array.isArray(l))throw new Error("The parameters of the method '".concat(r,"' must be an array."));var u=e;if(null===(i=u[t.containerKey])||void 0===i?void 0:i.isBound(G)){var p=u[t.containerKey].get(G);if(u[S])return u[S]({module:u[t.identifierKey],method:r,args:l});if(p.isClient)return p.transports.client?p.transports.client.emit(E(E({},n),{name:s}),{module:u[t.identifierKey],method:r,args:l,hook:null===(a=n._extra)||void 0===a?void 0:a.serverHook}).then((function(e){if(e){var t=K(e,2),r=t[0],o=t[1];return p.lastAction.sequence>=r?o:p.syncFullState({forceSync:!1}).then((function(){return o}))}})):Promise.reject(new Error("Detected that the current client transport does not exist."))}return c.apply(u,l)},le=function(e,r,o,n){var i=null!=o?o:[],a=null!=n?n:{},s=a.clientIds,c=a.portName,l=I(a,["clientIds","portName"]),u=e[r];if("string"!=typeof r)throw new Error("'fork()' is valid only for method name with string type.");if("function"!=typeof u)throw new Error("The property '".concat(r,"'' must be a method in class '").concat(e.constructor.name,"'."));if(!Array.isArray(i))throw new Error("The parameters of the method '".concat(r,"' must be an array."));var p=e;if(p[t.containerKey].isBound(G)){var h=p[t.containerKey].get(G);if(!h.isServer)throw new Error("'fork()' should be running in server port.");return h.transports.server?h.transports.server.emit(E(E({},l),{name:d}),{module:p[t.identifierKey],method:r,args:i,clientIds:s,portName:c}):Promise.reject(new Error("Detected that the current server transport does not exist."))}return u.apply(p,i)},ue=function(e){function r(r,o,i){var a,s=e.call(this,E(E({},i),{autoCreateHistory:!("SharedWorker"===o.type&&"server"===o.port||!globalThis.document)}))||this;if(s.portDetector=r,s.sharedAppOptions=o,s.options=i,s.passiveRoute=!1,s.cachedHistory=[],s.forwardHistory=[],s.lastRoutedTimestamp=J?0:Date.now(),s.toBeRouted=null,s._routers=((a={})[s.portDetector.name]=s.router,a),s.defaultHistory={action:"POP",location:{pathname:s.defaultRoute,search:"",hash:"",state:void 0}},s.firstRenderingSync=new Promise((function(e){s.firstRenderingSyncResolve=e})),s.firstActiveSync=new Promise((function(e){s.firstActiveSyncResolve=e})),s.firstClientSync=Promise.all([s.firstRenderingSync,s.firstActiveSync]),s.portDetector.onClient((function(){var e=t.watch(s,(function(){return s.portDetector.lastAction.action}),(function(){var t=s.portDetector.lastAction.action;if(t.type===n.LOCATION_CHANGE&&t.payload.isFirstRendering){e();var r=s._routers[s.portDetector.name];r&&s.compareRouter(r,s.router)&&s.history.replace(r.location),s.firstRenderingSyncResolve()}}))})),globalThis.document&&window.addEventListener("popstate",(function(){s.passiveRoute||(s.lastRoutedTimestamp=Date.now())})),!s.portDetector.shared){var c=s.watchRehydratedRouting();t.watch(s,(function(){return s.router}),(function(){s.router&&s._setRouters(s.portDetector.name,s.router),s.enableCacheRouting||c()}))}return s.portDetector.onClient((function(){if(!s.portDetector.sharedAppOptions.forcedSyncClient){var e=function(){return H(s,void 0,void 0,(function(){var e;return q(this,(function(t){switch(t.label){case 0:return"visible"!==document.visibilityState?[3,2]:[4,this.portDetector.syncFullState({forceSync:!1})];case 1:t.sent(),this.toBeRouted&&(e=this.toBeRouted,this.toBeRouted=null,e()),t.label=2;case 2:return[2]}}))}))};return document.addEventListener("visibilitychange",e),function(){document.removeEventListener("visibilitychange",e)}}})),s.portDetector.onServer((function(e){if(t.watch(s,(function(){return s.router}),(function(e){!e||s.cachedHistory[0]&&!s.compareRouter(e,s.cachedHistory[0])||("REPLACE"===e.action?s.cachedHistory[0]=e:s.cachedHistory.unshift(e),s.cachedHistory.length=s.maxHistoryLength)})),s.portDetector.isWorkerMode&&!s.enableCacheRouting)e.emit(y,s.portDetector.name).then((function(e){e&&s._changeRoutingOnSever(s.portDetector.name,e,Date.now())}));else if(s.enableCacheRouting)return s.watchRehydratedRouting()})),s.portDetector.onClient((function(e){if(s.portDetector.isWorkerMode)return e.listen(y,(function(e){return H(s,void 0,void 0,(function(){return q(this,(function(t){return e===this.portDetector.name?[2,this.router]:[2]}))}))}))})),s.portDetector.onClient((function(){return t.watch(s,(function(){return s.router}),(function(){ce(s,"_changeRoutingOnSever",[s.portDetector.name,s.router,s.lastRoutedTimestamp,s.portDetector.clientId],{respond:!1})}))})),s.portDetector.onServer((function(){return t.watch(s,(function(){return s.router}),(function(){s.portDetector.isWorkerMode||(globalThis.document&&s._setRouters(s.portDetector.name,s.router),le(s,"_changeRoutingOnClient",[s.portDetector.name,s.router,s.lastRoutedTimestamp],{silent:!0}))}))})),s.portDetector.onServer((function(e){var r=s.enableCacheRouting?new Promise((function(e){var r=t.watch(s,(function(){var e;return null===(e=s[t.stateKey]._persist)||void 0===e?void 0:e.rehydrated}),(function(t){t&&(r(),e())}))})):Promise.resolve();return e.listen(u,(function(e,t,o){return H(s,void 0,void 0,(function(){var n;return q(this,(function(i){switch(i.label){case 0:return[4,r];case 1:return i.sent(),!(n=this._routers[e])&&o&&this._changeRoutingOnSever(e,o,t),[2,n]}}))}))}))})),s.portDetector.onClient((function(e){e.emit(u,s.portDetector.name,s.lastRoutedTimestamp,s.router).then((function(e){e?(s.passiveRoute=!0,s.history.replace(e.location),s.passiveRoute=!1,s.firstActiveSyncResolve()):s.firstActiveSyncResolve()}))})),s}return j(r,e),Object.defineProperty(r.prototype,"maxHistoryLength",{get:function(){var e;return null!==(e=this.options.maxHistoryLength)&&void 0!==e?e:50},enumerable:!1,configurable:!0}),r.prototype.watchRehydratedRouting=function(){var e=this,r=!1,o=t.watch(this,(function(){var r;return null===(r=e[t.stateKey]._persist)||void 0===r?void 0:r.rehydrated}),(function(t){if(e.enableCacheRouting||o(),t){if(o(),!r)return void(r=!0);var n=e._routers[e.portDetector.name];e._changeRoutingOnSever(e.portDetector.name,null!=n?n:e.defaultHistory,Date.now())}})),i=t.watch(this,(function(){return e.portDetector.lastAction.action}),(function(){e.enableCacheRouting||i();var t=e.portDetector.lastAction.action;if(t.type===n.LOCATION_CHANGE&&t.payload.isFirstRendering){if(i(),!r)return void(r=!0);var o=e._routers[e.portDetector.name];e._changeRoutingOnSever(e.portDetector.name,null!=o?o:e.defaultHistory,Date.now())}}));return function(){o(),i()}},r.prototype.compareRouter=function(e,t){return e.location.pathname!==t.location.pathname||e.location.hash!==t.location.hash||e.location.search!==t.location.search||JSON.stringify(e.location.state)!==JSON.stringify(t.location.state)||JSON.stringify(e.location.query)!==JSON.stringify(t.location.query)},r.prototype._changeRoutingOnSever=function(e,t,r,o){if(!this.portDetector.isServerWorker&&globalThis.document){if(this.lastRoutedTimestamp>=r)return;this.lastRoutedTimestamp=r}this._setRouters(e,t),e===this.portDetector.name?(this.portDetector.isWorkerMode?this.dispatchChanged(t):this.compareRouter(t,this.router)&&(this.passiveRoute=!0,this.history.push(t.location),this.passiveRoute=!1),this.portDetector.shared&&le(this,"_changeRoutingOnClient",[this.portDetector.name,this.router,r],{silent:!0,clientIds:o?this.portDetector.clientIds.filter((function(e){return e!==o})):void 0})):this.portDetector.shared&&le(this,"_changeRoutingOnClient",[e,t,r],{silent:!0,clientIds:o?this.portDetector.clientIds.filter((function(e){return e!==o})):void 0})},r.prototype._changeRoutingOnClient=function(e,t,r){var o=this;if(!(e!==this.portDetector.name||r&&this.lastRoutedTimestamp>=r)){var n=function(){o.history&&o.compareRouter(t,o.router)&&(o.passiveRoute=!0,o.history.push(t.location),o.passiveRoute=!1)};this.portDetector.disableSyncClient?this.toBeRouted=n:n()}},r.prototype._makeRoutingOnClient=function(t){var r=this,o=t.args,n=t.action,i=t.name;return new Promise((function(t){var a=function(){i===r.portDetector.name&&(e.prototype[n].apply(r,L([],K(o),!1)),t(r.router))};r.portDetector.disableSyncClient?r.toBeRouted=a:a()}))},r.prototype._setRouters=function(e,r){var o;(!this.enableCacheRouting||this.enableCacheRouting&&(null===(o=this[t.stateKey]._persist)||void 0===o?void 0:o.rehydrated))&&(this._routers[e]=r)},Object.defineProperty(r.prototype,"defaultRoute",{get:function(){var e;return null!==(e=this.options.defaultRoute)&&void 0!==e?e:"/"},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"enableCacheRouting",{get:function(){var e,r,o=this[t.modulesKey][b],n=null==o?void 0:o.persistConfig[w];return n&&((null===(e=n.whitelist)||void 0===e?void 0:e.includes("_routers"))||!1===(null===(r=n.blacklist)||void 0===r?void 0:r.includes("_routers")))},enumerable:!1,configurable:!0}),r.prototype.dispatchChanged=function(e){var t;e&&(null===(t=this.store)||void 0===t||t.dispatch(this.onLocationChanged(e.location,e.action)))},Object.defineProperty(r.prototype,"currentPath",{get:function(){var e,t;return null!==(t=null===(e=this.router)||void 0===e?void 0:e.location.pathname)&&void 0!==t?t:this.defaultRoute},enumerable:!1,configurable:!0}),r.prototype.push=function(t,r){return H(this,void 0,void 0,(function(){var o;return q(this,(function(n){switch(n.label){case 0:return this.portDetector.isServerWorker?[4,le(this,"_makeRoutingOnClient",[{args:[t,r],action:"push",name:this.portDetector.name}])]:[3,2];case 1:return o=n.sent(),this.dispatchChanged(o),[3,3];case 2:this.lastRoutedTimestamp=Date.now(),e.prototype.push.call(this,t,r),n.label=3;case 3:return[2]}}))}))},r.prototype.replace=function(t,r){return H(this,void 0,void 0,(function(){var o;return q(this,(function(n){switch(n.label){case 0:return this.portDetector.isServerWorker?[4,le(this,"_makeRoutingOnClient",[{args:[t,r],action:"replace",name:this.portDetector.name}])]:[3,2];case 1:return o=n.sent(),this.dispatchChanged(o),[3,3];case 2:this.lastRoutedTimestamp=Date.now(),e.prototype.replace.call(this,t,r),n.label=3;case 3:return[2]}}))}))},r.prototype.go=function(t){return H(this,void 0,void 0,(function(){var r,o,n,i,a;return q(this,(function(s){switch(s.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,ce(this,"go",[t])]:t<0?(r=Math.abs(t),this.cachedHistory.length>r?(o=this.cachedHistory.shift(),this.forwardHistory.unshift(o),(i=this.cachedHistory[r-1])?[4,le(this,"_makeRoutingOnClient",[{args:[i.location.pathname,i.location.state],action:"replace",name:this.portDetector.name}])]:[3,2]):[3,4]):[3,6]:(this.lastRoutedTimestamp=Date.now(),e.prototype.go.call(this,t),[2]);case 1:return a=s.sent(),this.dispatchChanged(a),[3,3];case 2:console.warn("No more history to go back."),s.label=3;case 3:return[3,5];case 4:console.warn("No more history to go back."),s.label=5;case 5:return[3,13];case 6:return t>0?(n=t,this.forwardHistory.length>=n?(i=this.forwardHistory[n-1])?[4,le(this,"_makeRoutingOnClient",[{args:[i.location.pathname,i.location.state],action:"push",name:this.portDetector.name}])]:[3,8]:[3,10]):[3,12];case 7:return a=s.sent(),this.dispatchChanged(a),[3,9];case 8:console.warn("No more history to go forward."),s.label=9;case 9:return this.forwardHistory.splice(0,n),[3,11];case 10:console.warn("No more history to go forward."),s.label=11;case 11:return[3,13];case 12:console.warn("Going to the current route (n = 0) does nothing."),s.label=13;case 13:return[2]}}))}))},r.prototype.goBack=function(){return H(this,void 0,void 0,(function(){var t,r,o;return q(this,(function(n){switch(n.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,ce(this,"goBack",[])]:this.cachedHistory.length>1?(t=this.cachedHistory.shift(),this.forwardHistory.unshift(t),this.forwardHistory.length=this.maxHistoryLength,(r=this.cachedHistory[0])?[4,le(this,"_makeRoutingOnClient",[{args:[r.location.pathname,r.location.state],action:"push",name:this.portDetector.name}])]:[3,2]):[3,4]:(this.lastRoutedTimestamp=Date.now(),e.prototype.goBack.call(this),[2]);case 1:return o=n.sent(),this.dispatchChanged(o),[3,3];case 2:console.warn("No forward route available."),n.label=3;case 3:return[3,5];case 4:console.warn("No previous route available."),n.label=5;case 5:return[2]}}))}))},r.prototype.goForward=function(){return H(this,void 0,void 0,(function(){var t,r;return q(this,(function(o){switch(o.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,ce(this,"goForward",[])]:this.forwardHistory.length>0?(t=this.forwardHistory.shift())?[4,le(this,"_makeRoutingOnClient",[{args:[t.location.pathname,t.location.state],action:"push",name:this.portDetector.name}])]:[3,2]:[3,3]:(this.lastRoutedTimestamp=Date.now(),e.prototype.goForward.call(this),[2]);case 1:r=o.sent(),this.dispatchChanged(r),o.label=2;case 2:return[3,4];case 3:console.warn("No forward route available."),o.label=4;case 4:return[2]}}))}))},T([t.state,N("design:type",Object)],r.prototype,"_routers",void 0),T([t.action,N("design:type",Function),N("design:paramtypes",[String,Object]),N("design:returntype",void 0)],r.prototype,"_setRouters",null),r=T([t.injectable({name:w}),_(1,t.inject(m)),_(2,t.inject(n.RouterOptions)),N("design:paramtypes",[G,Object,Object])],r)}(n.Router),pe=Symbol("CoworkerOptions"),he=function(e){function o(r,o,n){var i,a,s=e.call(this)||this;return s.portDetector=r,s.coworkerOptions=o,s.storage=n,s.proxyModuleKeys=[],s.ignoreSyncStateKeys=null!==(a=null===(i=s.coworkerOptions)||void 0===i?void 0:i.ignoreSyncStateKeys)&&void 0!==a?a:[],s.afterCreateStore=function(e){return s.applyProxyExecute(),s.applyProxyModules(s.proxyModules),s.applyProxyState(),s.isCoworker&&(-1===s.sequence&&(s.sequence=0,s.pushAllState()),s.storage&&s.proxyModules.forEach((function(e){s.ref.container.getAll(e).forEach((function(e){if(s.storage.storageSettingMap.has(e))var r=t.watch(e,(function(){return s.storage.getRehydrated(e)}),(function(o){if(o){r();var n=t.getRef(e),i=n.identifier,a=n.state;s.sequence+=1,s.transport.emit({name:O,respond:!1},{_reactant:t.actionIdentifier,type:"".concat(t.actionIdentifier,"_").concat(A),params:[],_patches:[{op:"replace",path:[i],value:a}]},s.sequence)}}))}))}))),s.isMain&&-1===s.sequence&&s.requestSyncAllState(),e},s.sequence=-1,s.portDetector.isClient||(s.transport=s.createTransport()),s.proxyModules=L([],K(s.coworkerOptions.useModules),!1),s.isCoworker&&s.enablePatchesChecker&&(s.middleware=function(e){return function(e){return function(t){var r,o=t._patches,n=t.type,i=t.method;return n===b||null==o||o.forEach((function(e,t){var o=e.path;e.op,e.value;var a=s.proxyModuleKeys.includes("".concat(o[0]));if(t){if(r!==a){var c="".concat(n,".").concat(i);throw new Error("Update state error: Mixed update of coworker proxy state and isolated state is not supported, please check method '".concat(c,"'."))}}else r=a})),e(t)}}}),s.storage&&s.isMain&&(s.storage.beforeCombinePersistReducer=function(){var e=[];s.proxyModules.forEach((function(t){var r=s.ref.container.getAll(t);e.push.apply(e,L([],K(r),!1))})),s.storage.storageSettingMap.forEach((function(t,r){e.includes(r)&&s.storage.storageSettingMap.delete(r)}))}),s}return j(o,e),o.prototype.createTransport=function(){var e,t,o,n,i,a,s,c,l,u,p,h,d,f,v,y;if(this.portDetector.isWorkerMode){if(this.isCoworker)return null!==(t=null===(e=this.coworkerOptions.transports)||void 0===e?void 0:e.coworker)&&void 0!==t?t:r.createTransport("Broadcast",{prefix:this.prefix,verbose:null===(o=this.coworkerOptions)||void 0===o?void 0:o.enableTransportDebugger,logger:null===(n=this.coworkerOptions)||void 0===n?void 0:n.logger});if("server"===this.portDetector.sharedAppOptions.port)return null!==(a=null===(i=this.coworkerOptions.transports)||void 0===i?void 0:i.main)&&void 0!==a?a:r.createTransport("Broadcast",{prefix:this.prefix,verbose:null===(s=this.coworkerOptions)||void 0===s?void 0:s.enableTransportDebugger,logger:null===(c=this.coworkerOptions)||void 0===c?void 0:c.logger})}else{if(this.isCoworker){var g=!globalThis.SharedWorkerGlobalScope&&globalThis.WorkerGlobalScope;return null!==(u=null===(l=this.coworkerOptions.transports)||void 0===l?void 0:l.coworker)&&void 0!==u?u:r.createTransport(g?"WebWorkerInternal":"SharedWorkerInternal",{prefix:this.prefix,verbose:null===(p=this.coworkerOptions)||void 0===p?void 0:p.enableTransportDebugger,logger:null===(h=this.coworkerOptions)||void 0===h?void 0:h.logger})}if("client"!==this.portDetector.sharedAppOptions.port){if(null===(d=this.coworkerOptions.transports)||void 0===d?void 0:d.main)return this.coworkerOptions.transports.main;if(!(null===(f=this.coworkerOptions)||void 0===f?void 0:f.worker))return;return this.coworkerOptions.worker instanceof Worker?r.createTransport("WebWorkerClient",{worker:this.coworkerOptions.worker,prefix:this.prefix,verbose:this.coworkerOptions.enableTransportDebugger,logger:null===(v=this.coworkerOptions)||void 0===v?void 0:v.logger}):r.createTransport("SharedWorkerClient",{worker:this.coworkerOptions.worker,prefix:this.prefix,verbose:this.coworkerOptions.enableTransportDebugger,logger:null===(y=this.coworkerOptions)||void 0===y?void 0:y.logger})}}},Object.defineProperty(o.prototype,"prefix",{get:function(){return"reactant-share:".concat(this.portDetector.sharedAppOptions.name,":coworker:").concat(this.name)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"name",{get:function(){return this[t.nameKey]},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isCoworker",{get:function(){return this.coworkerOptions.isCoworker},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"isMain",{get:function(){return!this.isCoworker&&!!this.transport},enumerable:!1,configurable:!0}),o.prototype.addProxyModules=function(e){var t;(t=this.proxyModules).push.apply(t,L([],K(e),!1))},o.prototype.addIgnoreSyncStateKeys=function(e){var t;(t=this.ignoreSyncStateKeys).push.apply(t,L([],K(e),!1))},Object.defineProperty(o.prototype,"enablePatchesChecker",{get:function(){var e,t;return null!==(t=null===(e=this.coworkerOptions)||void 0===e?void 0:e.enablePatchesChecker)&&void 0!==t&&t},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"ref",{get:function(){return t.getRef(this)},enumerable:!1,configurable:!0}),o.prototype.applyProxyState=function(){var e=this;this.isMain&&(this.transport.listen(R,(function(t){return H(e,void 0,void 0,(function(){return q(this,(function(e){return this.handleSyncAllState(t),[2]}))}))})),this.transport.listen(O,(function(r,o){return H(e,void 0,void 0,(function(){var e,n,i;return q(this,(function(a){return this.sequence+1!==o?(this.requestSyncAllState(),[2]):(e=this.ref.store.getState(),n=this.portDetector.lastAction.sequence,i=t.applyPatches(e,r._patches),this.ignoreStates(i,e),this.ref.store.dispatch(E(E({},r),{state:i,_sequence:n})),this.sequence=o,[2])}))}))}))),this.isCoworker&&(t.watch(this,(function(){return e.portDetector.lastAction.action}),(function(t){var r,o=null===(r=t._patches)||void 0===r?void 0:r.filter((function(t){var r=K(t.path,2),o=r[0],n=r[1];return e.proxyModuleKeys.includes(o)&&!e.ignoreSyncStateKeys.includes(n)}));o&&0!==o.length&&(e.sequence+=1,e.transport.emit({name:O,respond:!1},E(E({},t),{_patches:o}),e.sequence))})),this.transport.listen(C,(function(){return H(e,void 0,void 0,(function(){return q(this,(function(e){return this.pushAllState(),[2]}))}))})))},o.prototype.pushAllState=function(){var e=this,t=this.ref.store.getState(),r={};this.proxyModuleKeys.forEach((function(o){r[o]=E({},t[o]),e.ignoreSyncStateKeys.forEach((function(e){delete r[o][e]}))})),this.transport.emit({name:R,respond:!1},{state:r,sequence:this.sequence})},o.prototype.handleSyncAllState=function(e){if(e.sequence!==this.sequence||-1===this.sequence){this.sequence=e.sequence;var r=this.ref.store.getState(),o=this.portDetector.lastAction.sequence,n=E(E({},r),e.state);this.ignoreStates(n,r),this.ref.store.dispatch({_reactant:t.actionIdentifier,type:"".concat(t.actionIdentifier,"_").concat(P),state:n,_sequence:o})}},o.prototype.requestSyncAllState=function(){this.transport.emit({name:C,respond:!1})},o.prototype.ignoreStates=function(e,t){var r=this;this.ignoreSyncStateKeys.forEach((function(o){r.proxyModuleKeys.forEach((function(r){e[r][o]=t[r][o]}))}))},o.prototype.applyProxyExecute=function(){var e=this;this.isCoworker&&this.transport.listen(k,(function(t){return H(e,[t],void 0,(function(e){var t,r,o=e.module,n=e.method,i=e.args;return q(this,(function(e){return t=this.ref.modules[o],[2,null===(r=t[n])||void 0===r?void 0:r.call.apply(r,L([t],K(i),!1))]}))}))}))},o.prototype.applyProxyModules=function(e){var r=this;e.forEach((function(e){r.ref.container.getAll(e).forEach((function(o){if(r.portDetector.isolatedModules.includes(o))throw new Error('\n The module "'.concat(e.toString(),"\" is isolated, and cannot be used as a proxy module in '").concat(r.name,"' coworker.\n "));o[D]=r,r.proxyModuleKeys.push(t.getRef(o).identifier),r.isMain&&(o[S]=function(e){return r.transport.emit(k,e)})}))}))},o=T([t.injectable({name:"Coworker"}),_(1,t.inject(pe)),_(2,t.optional()),N("design:paramtypes",[G,Object,U])],o)}(t.PluginModule),de=he;Object.defineProperty(e,"RouterOptions",{enumerable:!0,get:function(){return n.RouterOptions}}),Object.defineProperty(e,"createBrowserHistory",{enumerable:!0,get:function(){return n.createBrowserHistory}}),Object.defineProperty(e,"createHashHistory",{enumerable:!0,get:function(){return n.createHashHistory}}),Object.defineProperty(e,"createMemoryHistory",{enumerable:!0,get:function(){return n.createMemoryHistory}}),Object.defineProperty(e,"REHYDRATE",{enumerable:!0,get:function(){return i.REHYDRATE}}),Object.defineProperty(e,"StorageOptions",{enumerable:!0,get:function(){return i.StorageOptions}}),Object.defineProperty(e,"getRehydrated",{enumerable:!0,get:function(){return i.getRehydrated}}),e.Coworker=he,e.CoworkerOptions=pe,e.PortDetector=G,e.Router=ue,e.SharedAppOptions=m,e.Storage=U,e.applyMethod=z,e.coworkerKey=D,e.createBroadcastTransport=X,e.createCoworker=function(e){var r=Symbol("".concat(e,"CoworkerOptions")),o=function(o){function n(e,t,r){var n=o.call(this,e,t,r)||this;return n.portDetector=e,n.coworkerOptions=t,n.storage=r,n}return j(n,o),n=T([t.injectable({name:"".concat(e,"Coworker")}),_(1,t.inject(r)),_(2,t.optional()),N("design:paramtypes",[G,Object,U])],n)}(de);return[o,r]},e.createSharedApp=function(e){return H(void 0,void 0,void 0,(function(){var t,o,n,i,a,s,c,l,u,p,h,d,f,v,y;return q(this,(function(g){switch(g.label){case 0:if(void 0===e.share)throw new Error("'createSharedApp(options)' should be set 'share' option.");switch(null!==(l=(v=e.share).enablePatchesChecker)&&void 0!==l||(v.enablePatchesChecker=!1),null!==(u=(y=e.share).forcedSyncClient)&&void 0!==u||(y.forcedSyncClient=!0),e.share.type){case"SharedWorker":return[3,1];case"SharedTab":return[3,5];case"Base":return[3,7]}return[3,8];case 1:if(g.trys.push([1,2,,4]),o={server:null===(p=e.share.transports)||void 0===p?void 0:p.server,client:null===(h=e.share.transports)||void 0===h?void 0:h.client},"client"===e.share.port&&e.share.worker&&(null!==(d=o.client)&&void 0!==d||(o.client=r.createTransport("SharedWorkerClient",{worker:e.share.worker,prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger,logger:e.share.transportLogger}))),"server"===e.share.port)null!==(f=o.server)&&void 0!==f||(o.server=r.createTransport("SharedWorkerInternal",{prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger,logger:e.share.transportLogger}));else if("client"===e.share.port&&!o.client){if("string"!=typeof e.share.workerURL)throw new Error("The value of 'options.share.workerURL' should be a string.");o.client=r.createTransport("SharedWorkerClient",{worker:new SharedWorker(e.share.workerURL),prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger,logger:e.share.transportLogger})}return e.share.transports=o,t=ae(e),[3,4];case 2:return n=g.sent(),console.warn(n),(i=e.share).port,i.workerURL,a=i.name,s=I(i,["port","workerURL","name"]),[4,se(E(E({},e),{share:E(E({},s),{type:"SharedTab",name:a,forcedSyncClient:!0})}))];case 3:return t=g.sent(),[3,4];case 4:return[3,9];case 5:return[4,se(e)];case 6:return t=g.sent(),[3,9];case 7:return t=ae(e),[3,9];case 8:throw new Error("The value of 'options.share.type' be 'SharedTab', 'SharedWorker' or 'Base'.");case 9:return c=t.bootstrap,[2,E(E({},t),{destroy:function(){var r,o,n,i;t.destroy(),null===(o=null===(r=e.share.transports)||void 0===r?void 0:r.client)||void 0===o||o.dispose(),null===(i=null===(n=e.share.transports)||void 0===n?void 0:n.server)||void 0===i||i.dispose()},bootstrap:function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return H(void 0,void 0,void 0,(function(){var r,o;return q(this,(function(n){switch(n.label){case 0:return r=c.apply(void 0,L([],K(e),!1)),(o=t.container.get(G)).isClient?[4,o.syncFullStatePromise]:[3,2];case 1:n.sent(),n.label=2;case 2:return[2,r]}}))}))}})]}}))}))},e.delegate=ce,e.fork=le,e.getCoworker=function(e){return null==e?void 0:e[D]},e.isClientName=c,e.lastActionName=f,e.loadFullStateActionName=l,e.mockPairTransports=function(e){var t=r.mockPorts(),o=t.create,n=t.main;return[r.createTransport("Base",E(E({},n),{logger:null==e?void 0:e.serverLogger,verbose:null==e?void 0:e.serverVerbose})),r.createTransport("Base",E(E({},o()),{logger:null==e?void 0:e.clientLogger,verbose:null==e?void 0:e.clientVerbose}))]},e.preloadedStateActionName="@@reactant:preloadedState",e.proxyClientActionName=s,e.proxyExecutorKey=S,e.proxyServerActionName=d,e.proxyWorkerExecuteName=k,e.pushAllStateName=R,e.removeClientIdToServerName=h,e.requestSyncAllStateName=C,e.routerModuleName=w,e.storageModuleName=b,e.syncClientIdToServerName=p,e.syncClientIdsFromClientsName=g,e.syncModuleStateActionName=A,e.syncRouterName=u,e.syncStateActionName=P,e.syncStateName=O,e.syncToClientsName=v,e.syncWorkerRouterName=y,e.useLock=ie,Object.keys(t).forEach((function(r){"default"===r||Object.prototype.hasOwnProperty.call(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[r]}})})),Object.keys(r).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return r[t]}})})),Obje