UNPKG

reactant-share

Version:

A framework for building shared web applications with Reactant

2 lines (1 loc) 49.5 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,n,o,i,a){"use strict";var s="@@reactant:proxyClient",c="@@reactant:isClient",u="@@reactant:loadFullState",l="@@reactant:syncRouter",p="@@reactant:syncClientIdToServer",h="@@reactant:removeClientIdToServer",d="@@reactant:proxyServer",f="@@reactant:lastAction",v="@@reactant:syncToClients",y="@@reactant:syncWorkerRouter",m="@@reactant:syncClientIdsFromClients",g=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,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},E.apply(this,arguments)};function I(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(r[n[o]]=e[n[o]])}return r}function T(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function _(e,t){return function(r,n){t(r,n,e)}}function N(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function H(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{c(n.next(e))}catch(e){i(e)}}function s(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}c((n=n.apply(e,t||[])).next())}))}function q(e,t){var r,n,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[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,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,n=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],n=0}finally{r=o=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],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],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 n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function W(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;o<i;o++)!n&&o in t||(n||(n=Array.prototype.slice.call(t,0,o)),n[o]=t[o]);return e.concat(n||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var L,F,B=function(){return Math.random().toString(36).slice(2)},J=function(){function e(e,r){var n=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(n.serverCallbacks.add(e),n.lastHooks&&n.lastHooks.size>0&&n.isServer&&n.transport)try{var t=e(n.transport);n.lastHooks.add(t)}catch(e){console.error(e)}return function(){n.serverCallbacks.delete(e)}},this.onClient=function(e){if("function"!=typeof e)throw new Error("'onClient' argument should be a function.");if(n.clientCallbacks.add(e),n.lastHooks&&n.lastHooks.size>0&&n.isClient&&n.transport)try{var t=e(n.transport);n.lastHooks.add(t)}catch(e){console.error(e)}return function(){n.clientCallbacks.delete(e)}},this.onClientDestroy=function(e){if("function"!=typeof e)throw new Error("'onClientDestroy' argument should be a function.");return n.clientDestroyCallbacks.add(e),function(){n.clientDestroyCallbacks.delete(e)}},this.onClient((function(e){n.clientId=B(),n.clientIds=[],n.syncFullState({forceSync:!1});var r=e.listen(v,(function(e){return H(n,void 0,void 0,(function(){return q(this,(function(r){return e?(this[t.storeKey].dispatch({type:"".concat(t.actionIdentifier,"_").concat(u),state:this.getNextState(e),_reactant:t.actionIdentifier}),this.lastAction.sequence=e[this.lastAction.stateKey]._sequence,[2]):[2]}))}))}));e.emit({name:p,respond:!1},n.clientId);var o=e.listen(m,(function(){return H(n,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},n.clientId)};return window.addEventListener("pagehide",i),function(){n.previousPort="client",null==r||r(),null==o||o(),window.removeEventListener("pagehide",i)}})),this.onServer((function(e){n.clientId=null,e.emit({name:m,respond:!1});var t=e.listen(p,(function(e){n.clientIds.includes(e)||n.clientIds.push(e)})),r=e.listen(h,(function(e){var t,r,o=n.clientIds.findIndex((function(t){return t===e}));if(-1!==o){n.clientIds.splice(o,1);var i=n.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(){n.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,n,o,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&&(n=a.return)&&n.call(a)}finally{if(r)throw r.error}}this.lastHooks=new Set,this.portApp=e;var u=this.isClient?this.clientCallbacks:this.serverCallbacks;try{for(var l=M(u),p=l.next();!p.done;p=l.next()){var h=p.value;try{c=h(t);this.lastHooks.add(c)}catch(e){console.error(e)}}}catch(e){o={error:e}}finally{try{p&&!p.done&&(i=l.return)&&i.call(l)}finally{if(o)throw o.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,n=(void 0===e?{}:e).forceSync,o=void 0===n||n;return q(this,(function(e){switch(e.label){case 0:return o&&(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(u,o?-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||!o&&this.lastAction.sequence>r[this.lastAction.stateKey]._sequence||(this[t.storeKey].dispatch({type:"".concat(t.actionIdentifier,"_").concat(u),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(),n=E(E({},e),{router:r.router});return this.isolatedInstanceKeys.length&&this.isolatedInstanceKeys.forEach((function(e){e&&(n[e]=r[e])})),n},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(g)),N("design:paramtypes",[Object,"function"==typeof(r=void 0!==n.LastAction&&n.LastAction)?r:Object])],e)}(),G=function(e){function r(t,r){var n=e.call(this,r)||this;return n.portDetector=t,n.options=r,n.onRehydrated((function(){n.portDetector.onServer((function(){n.persist()})),n.portDetector.onClient((function(){n.pause()})),n.portDetector.isServer&&n.portDetector.syncToClients()})),n}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",[J,Object])],r)}(i.Storage),U=function(e){function r(t,r){var n=e.call(this)||this;return n.portDetector=t,n.storage=r,n.middleware=function(e){return function(e){return function(t){var r,o=t._patches,i=t.type,a=t.method;return null==o||o.forEach((function(e,t){var o=e.path;e.op,e.value;var s=n.portDetector.hasIsolatedState("".concat(o[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)}}},n}return j(r,e),r.prototype.checkPatches=function(e,t){t._patches.forEach((function(r){var n=r.op,o=r.path,i=r.value;if("replace"===n&&("[object Object]"===toString.call(i)||Array.isArray(i))){var a=o.reduce((function(e,t){return null==e?void 0:e[t]}),e);if(a&&"object"==typeof a&&o[0]!==w){var s=o.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",[J,G])],r)}(t.PluginModule),V=function(e,r){var n=e.instance[t.modulesKey][r.module];if(!n)throw new Error("The module '".concat(r.module,"' is not a multiple instances injected module, and it does not exist."));var o=n[r.method];if("function"!=typeof o)throw new Error("The '".concat(r.method,"' method for module '").concat(r.module,"' does not exist."));return n[S]?n[S](r):o.apply(n,r.args)},z=function(e){var r,o=e.app,i=e.transport,a=e.disposeServer,l=e.disposeClient,p=e.enablePatchesChecker;if(!i)throw new Error("The server transport does not exist.");null==a||a(),null==l||l();var h=o.instance[t.containerKey],d=h.get(n.LastAction),v=h.get(J);p&&h.get(U);if(globalThis.SharedWorkerGlobalScope){var y=!1;globalThis.addEventListener("connect",(function(){y||(y=!0,v.setPort({server:o},i))}))}else v.setPort({server:o},i);var m=[];return m.push(i.listen(c,(function(){return H(void 0,void 0,void 0,(function(){return q(this,(function(e){return[2,!0]}))}))}))),m.push(i.listen(u,(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=o.store)||void 0===t?void 0:t.getState():null]}))}))}))),m.push(i.listen(s,(function(e){return H(void 0,void 0,void 0,(function(){var t,r,n;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,V(o,e)];case 3:return n=i.sent(),[2,[v.lastAction.sequence,n]]}}))}))}))),m.push((function(){return i.dispose()})),m.push(null===(r=o.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(m),n=r.next();!n.done;n=r.next()){var o=n.value;null==o||o()}}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}}},Y=function(e){var r=e.app,o=e.transport,i=e.disposeServer,a=e.disposeClient,s=e.enablePatchesFilter,c=e.preloadedState;if(!o)throw new Error("The client transport does not exist.");null==i||i(),null==a||a();var u=r.instance[t.containerKey],l=u.get(n.LastAction),p=u.get(J);p.setPort({client:r},o);var h=[];return c&&(l.sequence=c[l.stateKey]._sequence),h.push(o.listen(f,(function(e){return H(void 0,void 0,void 0,(function(){var n,o,i,a,c;return q(this,(function(u){return p.disableSyncClient||(e._sequence&&e._sequence===l.sequence+1?(e._reactant===t.actionIdentifier?(n=r.store.getState(),o=null!==(c=e._patches)&&void 0!==c?c:[],i=s?o.filter((function(e){return n[e.path[0]]})):o,a=t.applyPatches(n,i),r.store.dispatch(E(E({},e),{state:a}))):r.store.dispatch(e),l.sequence=e._sequence):p.syncFullState({forceSync:!1})),[2]}))}))}))),h.push(o.listen(d,(function(e){return H(void 0,void 0,void 0,(function(){var t=e.clientIds,n=e.portName,o=I(e,["clientIds","portName"]);return q(this,(function(e){switch(e.label){case 0:return Array.isArray(t)&&p.clientId&&!t.includes(p.clientId)||n&&n!==p.name?[2,new Promise((function(){}))]:[4,V(r,o)];case 1:return[2,e.sent()]}}))}))}))),h.push((function(){return o.dispose()})),function(){var e,t;try{for(var r=M(h),n=r.next();!n.done;n=r.next()){var o=n.value;null==o||o()}}catch(t){e={error:t}}finally{try{n&&!n.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}}},Q=function(e,t){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})},X=new Map,Z=B(),$="reactant:lock",ee="reactant:tab",te=!1,re=function(e,t){0!==e.length&&(Object.keys(localStorage).forEach((function(r){var n;if(!r.indexOf($)){var o=JSON.parse(null!==(n=localStorage.getItem(r))&&void 0!==n?n:"[]"),i=JSON.stringify(o.filter((function(t){return-1===e.indexOf(t.tabId)})));t.setItem(r,i)}})),e.forEach((function(e){return t.removeItem("".concat(ee,":").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,te||(te=!0,window.addEventListener("pagehide",(function(){re([Z],localStorage)}))),function(){if(void 0===L){var e="".concat(ee,":").concat(Z);F.setItem(e,Date.now().toString()),L=window.setInterval((function(){return F.setItem(e,Date.now().toString())}),1e3)}}(),new Promise((function(r,n){var o,i=B();X.set(e,null!==(o=X.get(e))&&void 0!==o?o:new Map),X.get(e).set(i,t);var a="".concat($,":").concat(e),s=localStorage.getItem(a),c=JSON.parse(null!=s?s:"[]");c.push({tabId:Z,lockId:i});var u,l=function(t){return H(void 0,void 0,void 0,(function(){var o,s,c,u,p,h;return q(this,(function(d){switch(d.label){case 0:if(t.key!==a||!t.newValue)return[3,5];if(o=K(JSON.parse(t.newValue),1),(null==(s=o[0])?void 0:s.tabId)!==Z||(null==s?void 0:s.lockId)!==i)return[3,5];window.removeEventListener("storage",l),d.label=1;case 1:return d.trys.push([1,3,,4]),[4,X.get(e).get(i)({name:e,mode:"exclusive"})];case 2:return c=d.sent(),r(c),[3,4];case 3:return u=d.sent(),n(u),[3,4];case 4:X.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",l),F.setItem(a,JSON.stringify(c)),re((u=[],Object.keys(localStorage).forEach((function(e){var t;if(e.indexOf(ee))e.indexOf($)||JSON.parse(null!==(t=localStorage.getItem(e))&&void 0!==t?t:"[]").forEach((function(e){localStorage.getItem("".concat(ee,":").concat(e.tabId))||u.push(e.tabId)}));else{var r=localStorage.getItem(e);if(r&&Date.now()-Number(r)>2999){var n=e.replace("".concat(ee,":"),"");u.push(n)}}})),u),F)}))},oe=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,W([],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],n=t[1];"@@reactant"===r&&console.error("The decorator for class ".concat(n," should set \"@injectable({ name: '").concat(n,"' })\"."))})),e},t}j(r,e),r=T([t.injectable()],r)}(t.PluginModule);var ie=function(e){var r,i,a,s,c,u,l,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(n.LastAction,{provide:n.LastActionOptions,useFactory:function(e){var t;return{stateKey:"lastAction-".concat(p.name),ignoreAction:function(r){var n,i;t||(t=e.get(J));var a=null===(i=null===(n=r._patches)||void 0===n?void 0:n[0])||void 0===i?void 0:i.path[0];return r.type===o.LOCATION_CHANGE||a&&t.hasIsolatedState("".concat(a))}}},deps:[t.ModuleRef]},{provide:g,useValue:p},J),p.enablePatchesChecker&&h.modules.push(U);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,n=null===(t=p.transports)||void 0===t?void 0:t.server,o=null===(r=p.transports)||void 0===r?void 0:r.client;if("server"===e){if(!n)throw new Error("'transports.server' does not exist.");u=z({app:c,transport:n,disposeServer:u,disposeClient:l,enablePatchesChecker:p.enablePatchesChecker})}else{if(!o)throw new Error("'transports.client' does not exist.");l=Y({app:c,transport:o,disposeServer:u,disposeClient:l,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.");u=z({app:c,transport:d,enablePatchesChecker:p.enablePatchesChecker})}else{if(!f)throw new Error("'transports.client' does not exist.");l=Y({app:c,transport:f,enablePatchesFilter:p.enablePatchesFilter})}return c},ae=function(e){return H(void 0,void 0,void 0,(function(){var t,r,n,o,i,a,s,u;return q(this,(function(l){switch(l.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,ie(e)]):(null!==(n=(a=e.share).transports)&&void 0!==n||(a.transports={}),null!==(o=(s=e.share.transports).client)&&void 0!==o||(s.client=Q(e.share.name,e.share.enableTransportDebugger)),null!==(i=(u=e.share.transports).server)&&void 0!==i||(u.server=Q(e.share.name,e.share.enableTransportDebugger)),e.share.port?[2,ie(e)]:(r=!1,[4,Promise.race([new Promise((function(n){oe("reactant-share-app-lock:".concat(e.share.name),(function(){return H(void 0,void 0,void 0,(function(){var o,i;return q(this,(function(a){return t?null===(i=(o=e.share).transform)||void 0===i||i.call(o,"server"):(e.share.port="server",t=ie(e)),r=!0,n(t),[2,new Promise((function(){}))]}))}))}))})),new Promise((function(t){return H(void 0,void 0,void 0,(function(){var n,o,i;return q(this,(function(a){switch(a.label){case 0:return[4,null===(i=null===(o=e.share.transports)||void 0===o?void 0:o.client)||void 0===i?void 0:i.emit(c)];case 1:return a.sent()&&!r&&(e.share.port="client",n=ie(e),t(n)),[2]}}))}))}))])]));case 1:return[2,t=l.sent()]}}))}))},se=function(e,r,n,o){var i,a;void 0===o&&(o={});var c=e[r],u=null!=n?n:[];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(u))throw new Error("The parameters of the method '".concat(r,"' must be an array."));var l=e;if(null===(i=l[t.containerKey])||void 0===i?void 0:i.isBound(J)){var p=l[t.containerKey].get(J);if(l[S])return l[S]({module:l[t.identifierKey],method:r,args:u});if(p.isClient)return p.transports.client?p.transports.client.emit(E(E({},o),{name:s}),{module:l[t.identifierKey],method:r,args:u,hook:null===(a=o._extra)||void 0===a?void 0:a.serverHook}).then((function(e){if(e){var t=K(e,2),r=t[0],n=t[1];return p.lastAction.sequence>=r?n:p.syncFullState({forceSync:!1}).then((function(){return n}))}})):Promise.reject(new Error("Detected that the current client transport does not exist."))}return c.apply(l,u)},ce=function(e,r,n,o){var i=null!=n?n:[],a=null!=o?o:{},s=a.clientIds,c=a.portName,u=I(a,["clientIds","portName"]),l=e[r];if("string"!=typeof r)throw new Error("'fork()' is valid only for method name with string type.");if("function"!=typeof l)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(J)){var h=p[t.containerKey].get(J);if(!h.isServer)throw new Error("'fork()' should be running in server port.");return h.transports.server?h.transports.server.emit(E(E({},u),{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 l.apply(p,i)},ue=function(e){function r(r,n,i){var a,s=e.call(this,E(E({},i),{autoCreateHistory:!("SharedWorker"===n.type&&"server"===n.port||!globalThis.document)}))||this;if(s.portDetector=r,s.sharedAppOptions=n,s.options=i,s.passiveRoute=!1,s.cachedHistory=[],s.forwardHistory=[],s.lastRoutedTimestamp=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===o.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(){se(s,"_changeRoutingOnSever",[s.portDetector.name,s.router,s.lastRoutedTimestamp,s.portDetector.clientId])}))})),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),ce(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(l,(function(e,t,n){return H(s,void 0,void 0,(function(){var o;return q(this,(function(i){switch(i.label){case 0:return[4,r];case 1:return i.sent(),!(o=this._routers[e])&&n&&this._changeRoutingOnSever(e,n,t),[2,o]}}))}))}))})),s.portDetector.onClient((function(e){e.emit(l,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,n=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||n(),t){if(n(),!r)return void(r=!0);var o=e._routers[e.portDetector.name];e._changeRoutingOnSever(e.portDetector.name,null!=o?o: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===o.LOCATION_CHANGE&&t.payload.isFirstRendering){if(i(),!r)return void(r=!0);var n=e._routers[e.portDetector.name];e._changeRoutingOnSever(e.portDetector.name,null!=n?n:e.defaultHistory,Date.now())}}));return function(){n(),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,n){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&&ce(this,"_changeRoutingOnClient",[this.portDetector.name,this.router,r],{silent:!0,clientIds:n?this.portDetector.clientIds.filter((function(e){return e!==n})):void 0})):this.portDetector.shared&&ce(this,"_changeRoutingOnClient",[e,t,r],{silent:!0,clientIds:n?this.portDetector.clientIds.filter((function(e){return e!==n})):void 0})},r.prototype._changeRoutingOnClient=function(e,t,r){var n=this;if(!(e!==this.portDetector.name||r&&this.lastRoutedTimestamp>=r)){var o=function(){n.history&&n.compareRouter(t,n.router)&&(n.passiveRoute=!0,n.history.push(t.location),n.passiveRoute=!1)};this.portDetector.disableSyncClient?this.toBeRouted=o:o()}},r.prototype._makeRoutingOnClient=function(t){var r=this,n=t.args,o=t.action,i=t.name;return new Promise((function(t){var a=function(){i===r.portDetector.name&&(e.prototype[o].apply(r,W([],K(n),!1)),t(r.router))};r.portDetector.disableSyncClient?r.toBeRouted=a:a()}))},r.prototype._setRouters=function(e,r){var n;(!this.enableCacheRouting||this.enableCacheRouting&&(null===(n=this[t.stateKey]._persist)||void 0===n?void 0:n.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,n=this[t.modulesKey][b],o=null==n?void 0:n.persistConfig[w];return o&&((null===(e=o.whitelist)||void 0===e?void 0:e.includes("_routers"))||!1===(null===(r=o.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 n;return q(this,(function(o){switch(o.label){case 0:return this.portDetector.isServerWorker?[4,ce(this,"_makeRoutingOnClient",[{args:[t,r],action:"push",name:this.portDetector.name}])]:[3,2];case 1:return n=o.sent(),this.dispatchChanged(n),[3,3];case 2:this.lastRoutedTimestamp=Date.now(),e.prototype.push.call(this,t,r),o.label=3;case 3:return[2]}}))}))},r.prototype.replace=function(t,r){return H(this,void 0,void 0,(function(){var n;return q(this,(function(o){switch(o.label){case 0:return this.portDetector.isServerWorker?[4,ce(this,"_makeRoutingOnClient",[{args:[t,r],action:"replace",name:this.portDetector.name}])]:[3,2];case 1:return n=o.sent(),this.dispatchChanged(n),[3,3];case 2:this.lastRoutedTimestamp=Date.now(),e.prototype.replace.call(this,t,r),o.label=3;case 3:return[2]}}))}))},r.prototype.go=function(t){return H(this,void 0,void 0,(function(){var r,n,o,i,a;return q(this,(function(s){switch(s.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,se(this,"go",[t])]:t<0?(r=Math.abs(t),this.cachedHistory.length>r?(n=this.cachedHistory.shift(),this.forwardHistory.unshift(n),(i=this.cachedHistory[r-1])?[4,ce(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?(o=t,this.forwardHistory.length>=o?(i=this.forwardHistory[o-1])?[4,ce(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,o),[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,n;return q(this,(function(o){switch(o.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,se(this,"goBack",[])]:this.cachedHistory.length>1?(t=this.cachedHistory.shift(),this.forwardHistory.unshift(t),this.forwardHistory.length=this.maxHistoryLength,(r=this.cachedHistory[0])?[4,ce(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 n=o.sent(),this.dispatchChanged(n),[3,3];case 2:console.warn("No forward route available."),o.label=3;case 3:return[3,5];case 4:console.warn("No previous route available."),o.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(n){switch(n.label){case 0:return this.portDetector.shared?this.portDetector.isClient?[2,se(this,"goForward",[])]:this.forwardHistory.length>0?(t=this.forwardHistory.shift())?[4,ce(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=n.sent(),this.dispatchChanged(r),n.label=2;case 2:return[3,4];case 3:console.warn("No forward route available."),n.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(g)),_(2,t.inject(o.RouterOptions)),N("design:paramtypes",[J,Object,Object])],r)}(o.Router),le=Symbol("CoworkerOptions"),pe=function(e){function n(r,n,o){var i,a,s=e.call(this)||this;return s.portDetector=r,s.coworkerOptions=n,s.storage=o,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(n){if(n){r();var o=t.getRef(e),i=o.identifier,a=o.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=W([],K(s.coworkerOptions.useModules),!1),s.isCoworker&&s.enablePatchesChecker&&(s.middleware=function(e){return function(e){return function(t){var r,n=t._patches,o=t.type,i=t.method;return o===b||null==n||n.forEach((function(e,t){var n=e.path;e.op,e.value;var a=s.proxyModuleKeys.includes("".concat(n[0]));if(t){if(r!==a){var c="".concat(o,".").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,W([],K(r),!1))})),s.storage.storageSettingMap.forEach((function(t,r){e.includes(r)&&s.storage.storageSettingMap.delete(r)}))}),s}return j(n,e),n.prototype.createTransport=function(){var e,t,n,o,i,a,s,c,u,l,p;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===(n=this.coworkerOptions)||void 0===n?void 0:n.enableTransportDebugger});if("server"===this.portDetector.sharedAppOptions.port)return null!==(i=null===(o=this.coworkerOptions.transports)||void 0===o?void 0:o.main)&&void 0!==i?i:r.createTransport("Broadcast",{prefix:this.prefix,verbose:null===(a=this.coworkerOptions)||void 0===a?void 0:a.enableTransportDebugger})}else{if(this.isCoworker){var h=!globalThis.SharedWorkerGlobalScope&&globalThis.WorkerGlobalScope;return null!==(c=null===(s=this.coworkerOptions.transports)||void 0===s?void 0:s.coworker)&&void 0!==c?c:r.createTransport(h?"WebWorkerInternal":"SharedWorkerInternal",{prefix:this.prefix,verbose:null===(u=this.coworkerOptions)||void 0===u?void 0:u.enableTransportDebugger})}if("client"!==this.portDetector.sharedAppOptions.port){if(null===(l=this.coworkerOptions.transports)||void 0===l?void 0:l.main)return this.coworkerOptions.transports.main;if(!(null===(p=this.coworkerOptions)||void 0===p?void 0:p.worker))return;return this.coworkerOptions.worker instanceof Worker?r.createTransport("WebWorkerClient",{worker:this.coworkerOptions.worker,prefix:this.prefix,verbose:this.coworkerOptions.enableTransportDebugger}):r.createTransport("SharedWorkerClient",{worker:this.coworkerOptions.worker,prefix:this.prefix,verbose:this.coworkerOptions.enableTransportDebugger})}}},Object.defineProperty(n.prototype,"prefix",{get:function(){return"reactant-share:".concat(this.portDetector.sharedAppOptions.name,":coworker:").concat(this.name)},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"name",{get:function(){return this[t.nameKey]},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isCoworker",{get:function(){return this.coworkerOptions.isCoworker},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isMain",{get:function(){return!this.isCoworker&&!!this.transport},enumerable:!1,configurable:!0}),n.prototype.addProxyModules=function(e){var t;(t=this.proxyModules).push.apply(t,W([],K(e),!1))},n.prototype.addIgnoreSyncStateKeys=function(e){var t;(t=this.ignoreSyncStateKeys).push.apply(t,W([],K(e),!1))},Object.defineProperty(n.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(n.prototype,"ref",{get:function(){return t.getRef(this)},enumerable:!1,configurable:!0}),n.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,n){return H(e,void 0,void 0,(function(){var e,o,i;return q(this,(function(a){return this.sequence+1!==n?(this.requestSyncAllState(),[2]):(e=this.ref.store.getState(),o=this.portDetector.lastAction.sequence,i=t.applyPatches(e,r._patches),this.ignoreStates(i,e),this.ref.store.dispatch(E(E({},r),{state:i,_sequence:o})),this.sequence=n,[2])}))}))}))),this.isCoworker&&(t.watch(this,(function(){return e.portDetector.lastAction.action}),(function(t){var r,n=null===(r=t._patches)||void 0===r?void 0:r.filter((function(t){var r=K(t.path,2),n=r[0],o=r[1];return e.proxyModuleKeys.includes(n)&&!e.ignoreSyncStateKeys.includes(o)}));n&&0!==n.length&&(e.sequence+=1,e.transport.emit({name:O,respond:!1},E(E({},t),{_patches:n}),e.sequence))})),this.transport.listen(C,(function(){return H(e,void 0,void 0,(function(){return q(this,(function(e){return this.pushAllState(),[2]}))}))})))},n.prototype.pushAllState=function(){var e=this,t=this.ref.store.getState(),r={};this.proxyModuleKeys.forEach((function(n){r[n]=E({},t[n]),e.ignoreSyncStateKeys.forEach((function(e){delete r[n][e]}))})),this.transport.emit({name:R,respond:!1},{state:r,sequence:this.sequence})},n.prototype.handleSyncAllState=function(e){if(e.sequence!==this.sequence||-1===this.sequence){this.sequence=e.sequence;var r=this.ref.store.getState(),n=this.portDetector.lastAction.sequence,o=E(E({},r),e.state);this.ignoreStates(o,r),this.ref.store.dispatch({_reactant:t.actionIdentifier,type:"".concat(t.actionIdentifier,"_").concat(P),state:o,_sequence:n})}},n.prototype.requestSyncAllState=function(){this.transport.emit({name:C,respond:!1})},n.prototype.ignoreStates=function(e,t){var r=this;this.ignoreSyncStateKeys.forEach((function(n){r.proxyModuleKeys.forEach((function(r){e[r][n]=t[r][n]}))}))},n.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,n=e.module,o=e.method,i=e.args;return q(this,(function(e){return t=this.ref.modules[n],[2,null===(r=t[o])||void 0===r?void 0:r.call.apply(r,W([t],K(i),!1))]}))}))}))},n.prototype.applyProxyModules=function(e){var r=this;e.forEach((function(e){r.ref.container.getAll(e).forEach((function(n){if(r.portDetector.isolatedModules.includes(n))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 "));n[D]=r,r.proxyModuleKeys.push(t.getRef(n).identifier),r.isMain&&(n[S]=function(e){return r.transport.emit(k,e)})}))}))},n=T([t.injectable({name:"Coworker"}),_(1,t.inject(le)),_(2,t.optional()),N("design:paramtypes",[J,Object,G])],n)}(t.PluginModule),he=pe;Object.defineProperty(e,"RouterOptions",{enumerable:!0,get:function(){return o.RouterOptions}}),Object.defineProperty(e,"createBrowserHistory",{enumerable:!0,get:function(){return o.createBrowserHistory}}),Object.defineProperty(e,"createHashHistory",{enumerable:!0,get:function(){return o.createHashHistory}}),Object.defineProperty(e,"createMemoryHistory",{enumerable:!0,get:function(){return o.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=pe,e.CoworkerOptions=le,e.PortDetector=J,e.Router=ue,e.SharedAppOptions=g,e.Storage=G,e.applyMethod=V,e.coworkerKey=D,e.createBroadcastTransport=Q,e.createCoworker=function(e){var r=Symbol("".concat(e,"CoworkerOptions")),n=function(n){function o(e,t,r){var o=n.call(this,e,t,r)||this;return o.portDetector=e,o.coworkerOptions=t,o.storage=r,o}return j(o,n),o=T([t.injectable({name:"".concat(e,"Coworker")}),_(1,t.inject(r)),_(2,t.optional()),N("design:paramtypes",[J,Object,G])],o)}(he);return[n,r]},e.createSharedApp=function(e){return H(void 0,void 0,void 0,(function(){var t,n,o,i,a,s,c,u,l,p,h,d,f,v,y;return q(this,(function(m){switch(m.label){case 0:if(void 0===e.share)throw new Error("'createSharedApp(options)' should be set 'share' option.");switch(null!==(u=(v=e.share).enablePatchesChecker)&&void 0!==u||(v.enablePatchesChecker=!1),null!==(l=(y=e.share).forcedSyncClient)&&void 0!==l||(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(m.trys.push([1,2,,4]),n={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=n.client)&&void 0!==d||(n.client=r.createTransport("SharedWorkerClient",{worker:e.share.worker,prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger}))),"server"===e.share.port)null!==(f=n.server)&&void 0!==f||(n.server=r.createTransport("SharedWorkerInternal",{prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger}));else if("client"===e.share.port&&!n.client){if("string"!=typeof e.share.workerURL)throw new Error("The value of 'options.share.workerURL' should be a string.");n.client=r.createTransport("SharedWorkerClient",{worker:new SharedWorker(e.share.workerURL),prefix:"reactant-share:".concat(e.share.name),verbose:e.share.enableTransportDebugger})}return e.share.transports=n,t=ie(e),[3,4];case 2:return o=m.sent(),console.warn(o),(i=e.share).port,i.workerURL,a=i.name,s=I(i,["port","workerURL","name"]),[4,ae(E(E({},e),{share:E(E({},s),{type:"SharedTab",name:a,forcedSyncClient:!0})}))];case 3:return t=m.sent(),[3,4];case 4:return[3,9];case 5:return[4,ae(e)];case 6:return t=m.sent(),[3,9];case 7:return t=ie(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,n,o,i;t.destroy(),null===(n=null===(r=e.share.transports)||void 0===r?void 0:r.client)||void 0===n||n.dispose(),null===(i=null===(o=e.share.transports)||void 0===o?void 0:o.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,n;return q(this,(function(o){switch(o.label){case 0:return r=c.apply(void 0,W([],K(e),!1)),(n=t.container.get(J)).isClient?[4,n.syncFullStatePromise]:[3,2];case 1:o.sent(),o.label=2;case 2:return[2,r]}}))}))}})]}}))}))},e.delegate=se,e.fork=ce,e.getCoworker=function(e){return null==e?void 0:e[D]},e.isClientName=c,e.lastActionName=f,e.loadFullStateActionName=u,e.mockPairTransports=function(){var e=r.mockPorts(),t=e.create,n=e.main;return[r.createTransport("Base",n),r.createTransport("Base",t())]},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=m,e.syncModuleStateActionName=A,e.syncRouterName=l,e.syncStateActionName=P,e.syncStateName=O,e.syncToClientsName=v,e.syncWorkerRouterName=y,e.useLock=oe,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]}})})),Object.keys(n).forEach((function(t){"default"===t||Object.prototype.hasOwnProperty.call(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:function(){return n[t]}})}))}));