@storix-js/sync 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +47 -564
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var fe=Symbol.for("preact-signals");function G(){if(H>1)H--;else{var t,e=!1;for((function(){var w=K;for(K=void 0;w!==void 0;)w.S.v===w.v&&(w.S.i=w.i),w=w.o})();Z!==void 0;){var s=Z;for(Z=void 0,B++;s!==void 0;){var l=s.u;if(s.u=void 0,s.f&=-3,!(8&s.f)&&ae(s))try{s.c()}catch(w){e||(t=w,e=!0)}s=l}}if(B=0,H--,e)throw t}}function L(t){if(H>0)return t();X=++ve,H++;try{return t()}finally{G()}}var p=void 0;function Y(t){var e=p;p=void 0;try{return t()}finally{p=e}}var Z=void 0,H=0,B=0,ve=0,X=0,K=void 0,F=0;function re(t){if(p!==void 0){var e=t.n;if(e===void 0||e.t!==p)return e={i:0,S:t,p:p.s,n:void 0,t:p,e:void 0,x:void 0,r:e},p.s!==void 0&&(p.s.n=e),p.s=e,t.n=e,32&p.f&&t.S(e),e;if(e.i===-1)return e.i=0,e.n!==void 0&&(e.n.p=e.p,e.p!==void 0&&(e.p.n=e.n),e.p=p.s,e.n=void 0,p.s.n=e,p.s=e),e}}function x(t,e){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}x.prototype.brand=fe;x.prototype.h=function(){return!0};x.prototype.S=function(t){var e=this,s=this.t;s!==t&&t.e===void 0&&(t.x=s,this.t=t,s!==void 0?s.e=t:Y(function(){var l;(l=e.W)==null||l.call(e)}))};x.prototype.U=function(t){var e=this;if(this.t!==void 0){var s=t.e,l=t.x;s!==void 0&&(s.x=l,t.e=void 0),l!==void 0&&(l.e=s,t.x=void 0),t===this.t&&(this.t=l,l===void 0&&Y(function(){var w;(w=e.Z)==null||w.call(e)}))}};x.prototype.subscribe=function(t){var e=this;return he(function(){var s=e.value,l=p;p=void 0;try{t(s)}finally{p=l}},{name:"sub"})};x.prototype.valueOf=function(){return this.value};x.prototype.toString=function(){return this.value+""};x.prototype.toJSON=function(){return this.value};x.prototype.peek=function(){var t=this;return Y(function(){return t.value})};Object.defineProperty(x.prototype,"value",{get:function(){var t=re(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(B>100)throw new Error("Cycle detected");(function(s){H!==0&&B===0&&s.l!==X&&(s.l=X,K={S:s,v:s.v,i:s.i,o:K})})(this),this.v=t,this.i++,F++,H++;try{for(var e=this.t;e!==void 0;e=e.x)e.t.N()}finally{G()}}}});function Q(t,e){return new x(t,e)}function ae(t){for(var e=t.s;e!==void 0;e=e.n)if(e.S.i!==e.i||!e.S.h()||e.S.i!==e.i)return!0;return!1}function ce(t){for(var e=t.s;e!==void 0;e=e.n){var s=e.S.n;if(s!==void 0&&(e.r=s),e.S.n=e,e.i=-1,e.n===void 0){t.s=e;break}}}function ue(t){for(var e=t.s,s=void 0;e!==void 0;){var l=e.p;e.i===-1?(e.S.U(e),l!==void 0&&(l.n=e.n),e.n!==void 0&&(e.n.p=l)):s=e,e.S.n=e.r,e.r!==void 0&&(e.r=void 0),e=l}t.s=s}function A(t,e){x.call(this,void 0),this.x=t,this.s=void 0,this.g=F-1,this.f=4,this.W=e==null?void 0:e.watched,this.Z=e==null?void 0:e.unwatched,this.name=e==null?void 0:e.name}A.prototype=new x;A.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===F))return!0;if(this.g=F,this.f|=1,this.i>0&&!ae(this))return this.f&=-2,!0;var t=p;try{ce(this),p=this;var e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(s){this.v=s,this.f|=16,this.i++}return p=t,ue(this),this.f&=-2,!0};A.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var e=this.s;e!==void 0;e=e.n)e.S.S(e)}x.prototype.S.call(this,t)};A.prototype.U=function(t){if(this.t!==void 0&&(x.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var e=this.s;e!==void 0;e=e.n)e.S.U(e)}};A.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}};Object.defineProperty(A.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=re(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function se(t,e){return new A(t,e)}function le(t){var e=t.m;if(t.m=void 0,typeof e=="function"){H++;var s=p;p=void 0;try{e()}catch(l){throw t.f&=-2,t.f|=8,ee(t),l}finally{p=s,G()}}}function ee(t){for(var e=t.s;e!==void 0;e=e.n)e.S.U(e);t.x=void 0,t.s=void 0,le(t)}function de(t){if(p!==this)throw new Error("Out-of-order effect");ue(this),p=t,this.f&=-2,8&this.f&&ee(this),G()}function _(t,e){this.x=t,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=e==null?void 0:e.name}_.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var e=this.x();typeof e=="function"&&(this.m=e)}finally{t()}};_.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,le(this),ce(this),H++;var t=p;return p=this,de.bind(this,t)};_.prototype.N=function(){2&this.f||(this.f|=2,this.u=Z,Z=this)};_.prototype.d=function(){this.f|=8,1&this.f||ee(this)};_.prototype.dispose=function(){this.d()};function he(t,e){var s=new _(t,e);try{s.c()}catch(w){throw s.d(),w}var l=s.d.bind(s);return l[Symbol.dispose]=l,l}function pe(t={}){const e=(t.namespace??"default").trim()||"default",s=t.plugins??[],l=new Map;function w(S,I){return function(){var E;const M=`${e}:${S}`,P=l.get(S);if(P)return P;const R=I.state(),g=I.modules??{},b={...R};for(const[r,o]of Object.entries(g))b[r]=o.state();const h=Q(b),j=new Map,T=new Map,U=new Map,N=new Map,m=new Map,i=new Set,n=new Set(Object.keys(R)),c=new Set(Object.keys(I.getters??{})),d=new Set(Object.keys(I.actions??{})),$=r=>h.value[r]??{},W=(r,o)=>{h.value={...h.value,[r]:o}},q=new Proxy({},{get(r,o){var u,f;if(j.has(o))return(u=j.get(o))==null?void 0:u.value;if(m.has(o))return(f=m.get(o))==null?void 0:f.value;if(n.has(o))return h.value[o];const y=N.get(o);return y?$(y.moduleName)[y.key]:h.value[o]}});for(const[r,o]of Object.entries(I.getters??{}))j.set(r,se(()=>o(h.value,q)));const te=(r,o)=>{var u;for(const f of i)f(r);for(const f of s)(u=f.onMutation)==null||u.call(f,o,r)},ne=(r,o,u,f)=>{const y=h.value[r];Object.is(y,o)||(h.value={...h.value,[r]:o},te({namespace:e,scopeId:M,storeId:S,key:r,oldValue:y,newValue:o,origin:u},f))},C=(r,o,u,f,y)=>{const O=$(r),a=O[o];Object.is(a,u)||(W(r,{...O,[o]:u}),te({namespace:e,scopeId:M,storeId:S,key:`${r}.${o}`,oldValue:a,newValue:u,origin:f},y))},D={$id:S,$namespace:e,$scopeId:M,$subscribe(r){return i.add(r),()=>i.delete(r)},$dispose(){var r;i.clear();for(const o of s)(r=o.onDispose)==null||r.call(o,k);l.delete(S)},$patch(r,o="local"){L(()=>{for(const[u,f]of Object.entries(r)){const y=N.get(u);if(y){C(y.moduleName,y.key,f,o,k);continue}if(u.includes(".")){const[O,a]=u.split(".",2);if(g[O]){C(O,a,f,o,k);continue}}if(g[u]&&f&&typeof f=="object"&&!Array.isArray(f)){for(const[O,a]of Object.entries(f))C(u,O,a,o,k);continue}ne(u,f,o,k)}})},$snapshot(){return{...h.value}}};for(const[r,o]of Object.entries(g)){const u=new Map,f=new Map,y=new Proxy({},{get(a,v){var V,z,ie;if(u.has(v))return(V=u.get(v))==null?void 0:V.value;if(j.has(v))return(z=j.get(v))==null?void 0:z.value;if(m.has(v))return(ie=m.get(v))==null?void 0:ie.value;const oe=$(r);if(v in oe)return oe[v];if(n.has(v))return h.value[v]}});for(const[a,v]of Object.entries(o.getters??{}))u.set(a,se(()=>v($(r),h.value,y)));let O;for(const[a,v]of Object.entries(o.actions??{}))f.set(a,(...V)=>L(()=>v.apply(O,V)));O=new Proxy({},{get(a,v){var V;if(f.has(v))return f.get(v);if(u.has(v))return(V=u.get(v))==null?void 0:V.value;const z=$(r);return v in z?z[v]:k[v]},set(a,v,V){if(f.has(v)||u.has(v))return!1;const z=$(r);return v in z?C(r,v,V,"local",k):k[v]=V,!0}}),U.set(r,O),T.set(r,u);for(const a of Object.keys($(r)))!(n.has(a)||c.has(a)||d.has(a)||Reflect.has(D,a)||g[a]!==void 0)&&!N.has(a)&&N.set(a,{moduleName:r,key:a});for(const[a,v]of u.entries())!(n.has(a)||c.has(a)||d.has(a)||Reflect.has(D,a)||g[a]!==void 0)&&!m.has(a)&&m.set(a,v);for(const[a,v]of f.entries())!(n.has(a)||c.has(a)||d.has(a)||Reflect.has(D,a)||g[a]!==void 0)&&!Reflect.has(D,a)&&(D[a]=v)}const k=new Proxy(D,{get(r,o,u){var f,y;if(Reflect.has(r,o))return Reflect.get(r,o,u);if(U.has(o))return U.get(o);if(j.has(o))return(f=j.get(o))==null?void 0:f.value;if(m.has(o))return(y=m.get(o))==null?void 0:y.value;if(n.has(o))return h.value[o];const O=N.get(o);return O?$(O.moduleName)[O.key]:h.value[o]},set(r,o,u,f){if(Reflect.has(r,o))return Reflect.set(r,o,u,f);const y=N.get(o);return y?(C(y.moduleName,y.key,u,"local",f),!0):(ne(o,u,"local",f),!0)}});for(const[r,o]of Object.entries(I.actions??{}))D[r]=(...u)=>L(()=>o.apply(k,u));for(const r of s)(E=r.onInit)==null||E.call(r,k);return l.set(S,k),k}}function J(S,I){return function(){var E;const M=`\0machine:${S}`,P=l.get(M);if(P)return P;const R=`${e}:${S}`,g=Q(I.initial),b=Q((I.context??(()=>({})))()),h=new Set,j=(i,n)=>{var c;for(const d of h)d(i);for(const d of s)(c=d.onMutation)==null||c.call(d,n,i)},T=(i,n,c,d)=>{const $=b.value[i];Object.is($,n)||(b.value={...b.value,[i]:n},j({namespace:e,scopeId:R,storeId:S,key:i,oldValue:$,newValue:n,origin:c},d))},U=(i,n,c)=>{const d=g.value;Object.is(d,i)||(g.value=i,j({namespace:e,scopeId:R,storeId:S,key:"$state",oldValue:d,newValue:i,origin:n},c))},N={$id:S,$namespace:e,$scopeId:R,$subscribe(i){return h.add(i),()=>h.delete(i)},$dispose(){var i;h.clear();for(const n of s)(i=n.onDispose)==null||i.call(n,m);l.delete(M)},$patch(i,n="local"){L(()=>{for(const[c,d]of Object.entries(i))c==="$state"?U(d,n,m):T(c,d,n,m)})},$snapshot(){return{$state:g.value,...b.value}},send(i,n){L(()=>{var c,d,$;const W=(c=I.actions)==null?void 0:c[i];W&&W.call(m,n);const q=($=(d=I.states[g.value])==null?void 0:d.on)==null?void 0:$[i];q!==void 0&&U(q,"local",m)})},matches(i){return g.value===i},can(i){const n=I.states[g.value];return!!(n!=null&&n.on&&i in n.on)}},m=new Proxy(N,{get(i,n,c){return n==="state"?g.value:Reflect.has(i,n)?Reflect.get(i,n,c):b.value[n]},set(i,n,c,d){return n==="state"?!1:Reflect.has(i,n)?Reflect.set(i,n,c,d):(T(n,c,"local",d),!0)}});for(const i of s)(E=i.onInit)==null||E.call(i,m);return l.set(M,m),m}}return{defineStore:w,defineMachine:J,use(S){s.push(S)}}}pe();function ye(t={}){const e=t.channelName??"storix-sync",s=new Set(t.include??[]),l=new Set(t.exclude??[]),w=t.namespaces??[],J=w==="*"?null:new Set(w),S=t.debounce??16,I=crypto.randomUUID(),E=`__storix_sync__:${e}`,M=new Map,P=new Set,R=new Map,g=new Map;let b=null;const h=typeof window<"u"&&"BroadcastChannel"in window?new BroadcastChannel(e):null,j=i=>{const n=[i.$id,i.$scopeId];return!(n.some(c=>l.has(c))||s.size>0&&!n.some(c=>s.has(c)))},T=(i,n)=>n===i||J===null?!0:J.has(n),U=(i,n)=>{!n||n.originTabId===I||T(i.$namespace,n.namespace)&&n.storeId===i.$id&&j(i)&&i.$patch({[n.key]:n.newValue},"remote")},N=()=>{if(b=null,M.size===0)return;const i=Array.from(M.values());M.clear();for(const n of i){const c={...n,originTabId:I};if(h&&h.postMessage(c),typeof window<"u"&&"localStorage"in window)try{window.localStorage.setItem(E,JSON.stringify(c)),window.localStorage.removeItem(E)}catch{}}},m=i=>{if(M.set(`${i.scopeId}:${i.key}`,i),S<=0){N();return}b||(b=setTimeout(N,S))};return{name:"sync",onInit(i){const n=i;if(j(n)){if(P.add(n.$scopeId),h){const c=d=>{U(n,d.data)};R.set(n.$scopeId,c),h.addEventListener("message",c)}if(typeof window<"u"){const c=d=>{if(!(d.key!==E||!d.newValue))try{const $=JSON.parse(d.newValue);U(n,$)}catch{}};g.set(n.$scopeId,c),window.addEventListener("storage",c)}}},onMutation(i,n){n.origin!=="remote"&&j(i)&&m(n)},onDispose(i){const n=i;P.delete(n.$scopeId);const c=R.get(n.$scopeId);h&&c&&(h.removeEventListener("message",c),R.delete(n.$scopeId));const d=g.get(n.$scopeId);typeof window<"u"&&d&&(window.removeEventListener("storage",d),g.delete(n.$scopeId)),b&&(clearTimeout(b),b=null),N(),P.size===0&&(h==null||h.close())}}}exports.syncPlugin=ye;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("@storix-js/core");function T(c={}){const g=c.channelName??"storix-sync",m=new Set(c.include??[]),h=new Set(c.exclude??[]),p=c.namespaces??[],I=p==="*"?null:new Set(p),y=c.debounce??16,S=crypto.randomUUID(),a=`__storix_sync__:${g}`,i=new Map,d=new Set,u=new Map,l=new Map;let r=null;const s=typeof window<"u"&&"BroadcastChannel"in window?new BroadcastChannel(g):null,f=n=>{const e=[n.$id,n.$scopeId];return!(e.some(t=>h.has(t))||m.size>0&&!e.some(t=>m.has(t)))},v=(n,e)=>e===n||I===null?!0:I.has(e),$=(n,e)=>{!e||e.originTabId===S||v(n.$namespace,e.namespace)&&e.storeId===n.$id&&f(n)&&n.$patch({[e.key]:e.newValue},"remote")},w=()=>{if(r=null,i.size===0)return;const n=Array.from(i.values());i.clear();for(const e of n){const t={...e,originTabId:S};if(s&&s.postMessage(t),typeof window<"u"&&"localStorage"in window)try{window.localStorage.setItem(a,JSON.stringify(t)),window.localStorage.removeItem(a)}catch{}}},M=n=>{if(i.set(`${n.scopeId}:${n.key}`,n),y<=0){w();return}r||(r=setTimeout(w,y))};return H.definePlugin({name:"sync",onInit(n){const e=n;if(f(e)){if(d.add(e.$scopeId),s){const t=o=>{$(e,o.data)};u.set(e.$scopeId,t),s.addEventListener("message",t)}if(typeof window<"u"){const t=o=>{if(!(o.key!==a||!o.newValue))try{const b=JSON.parse(o.newValue);$(e,b)}catch{}};l.set(e.$scopeId,t),window.addEventListener("storage",t)}}},onMutation(n,e){e.origin!=="remote"&&f(n)&&M(e)},onDispose(n){const e=n;d.delete(e.$scopeId);const t=u.get(e.$scopeId);s&&t&&(s.removeEventListener("message",t),u.delete(e.$scopeId));const o=l.get(e.$scopeId);typeof window<"u"&&o&&(window.removeEventListener("storage",o),l.delete(e.$scopeId)),r&&(clearTimeout(r),r=null),w(),d.size===0&&(s==null||s.close())}})}exports.syncPlugin=T;
|
package/dist/index.js
CHANGED
|
@@ -1,588 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
e || (t = w, e = !0);
|
|
19
|
-
}
|
|
20
|
-
s = l;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (B = 0, H--, e) throw t;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function T(t) {
|
|
27
|
-
if (H > 0) return t();
|
|
28
|
-
X = ++ve, H++;
|
|
29
|
-
try {
|
|
30
|
-
return t();
|
|
31
|
-
} finally {
|
|
32
|
-
G();
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
var p = void 0;
|
|
36
|
-
function Y(t) {
|
|
37
|
-
var e = p;
|
|
38
|
-
p = void 0;
|
|
39
|
-
try {
|
|
40
|
-
return t();
|
|
41
|
-
} finally {
|
|
42
|
-
p = e;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
var Z = void 0, H = 0, B = 0, ve = 0, X = 0, K = void 0, F = 0;
|
|
46
|
-
function re(t) {
|
|
47
|
-
if (p !== void 0) {
|
|
48
|
-
var e = t.n;
|
|
49
|
-
if (e === void 0 || e.t !== p)
|
|
50
|
-
return e = { i: 0, S: t, p: p.s, n: void 0, t: p, e: void 0, x: void 0, r: e }, p.s !== void 0 && (p.s.n = e), p.s = e, t.n = e, 32 & p.f && t.S(e), e;
|
|
51
|
-
if (e.i === -1)
|
|
52
|
-
return e.i = 0, e.n !== void 0 && (e.n.p = e.p, e.p !== void 0 && (e.p.n = e.n), e.p = p.s, e.n = void 0, p.s.n = e, p.s = e), e;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function O(t, e) {
|
|
56
|
-
this.v = t, this.i = 0, this.n = void 0, this.t = void 0, this.l = 0, this.W = e == null ? void 0 : e.watched, this.Z = e == null ? void 0 : e.unwatched, this.name = e == null ? void 0 : e.name;
|
|
57
|
-
}
|
|
58
|
-
O.prototype.brand = fe;
|
|
59
|
-
O.prototype.h = function() {
|
|
60
|
-
return !0;
|
|
61
|
-
};
|
|
62
|
-
O.prototype.S = function(t) {
|
|
63
|
-
var e = this, s = this.t;
|
|
64
|
-
s !== t && t.e === void 0 && (t.x = s, this.t = t, s !== void 0 ? s.e = t : Y(function() {
|
|
65
|
-
var l;
|
|
66
|
-
(l = e.W) == null || l.call(e);
|
|
67
|
-
}));
|
|
68
|
-
};
|
|
69
|
-
O.prototype.U = function(t) {
|
|
70
|
-
var e = this;
|
|
71
|
-
if (this.t !== void 0) {
|
|
72
|
-
var s = t.e, l = t.x;
|
|
73
|
-
s !== void 0 && (s.x = l, t.e = void 0), l !== void 0 && (l.e = s, t.x = void 0), t === this.t && (this.t = l, l === void 0 && Y(function() {
|
|
74
|
-
var w;
|
|
75
|
-
(w = e.Z) == null || w.call(e);
|
|
76
|
-
}));
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
O.prototype.subscribe = function(t) {
|
|
80
|
-
var e = this;
|
|
81
|
-
return he(function() {
|
|
82
|
-
var s = e.value, l = p;
|
|
83
|
-
p = void 0;
|
|
84
|
-
try {
|
|
85
|
-
t(s);
|
|
86
|
-
} finally {
|
|
87
|
-
p = l;
|
|
88
|
-
}
|
|
89
|
-
}, { name: "sub" });
|
|
90
|
-
};
|
|
91
|
-
O.prototype.valueOf = function() {
|
|
92
|
-
return this.value;
|
|
93
|
-
};
|
|
94
|
-
O.prototype.toString = function() {
|
|
95
|
-
return this.value + "";
|
|
96
|
-
};
|
|
97
|
-
O.prototype.toJSON = function() {
|
|
98
|
-
return this.value;
|
|
99
|
-
};
|
|
100
|
-
O.prototype.peek = function() {
|
|
101
|
-
var t = this;
|
|
102
|
-
return Y(function() {
|
|
103
|
-
return t.value;
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
Object.defineProperty(O.prototype, "value", { get: function() {
|
|
107
|
-
var t = re(this);
|
|
108
|
-
return t !== void 0 && (t.i = this.i), this.v;
|
|
109
|
-
}, set: function(t) {
|
|
110
|
-
if (t !== this.v) {
|
|
111
|
-
if (B > 100) throw new Error("Cycle detected");
|
|
112
|
-
(function(s) {
|
|
113
|
-
H !== 0 && B === 0 && s.l !== X && (s.l = X, K = { S: s, v: s.v, i: s.i, o: K });
|
|
114
|
-
})(this), this.v = t, this.i++, F++, H++;
|
|
115
|
-
try {
|
|
116
|
-
for (var e = this.t; e !== void 0; e = e.x) e.t.N();
|
|
117
|
-
} finally {
|
|
118
|
-
G();
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
} });
|
|
122
|
-
function Q(t, e) {
|
|
123
|
-
return new O(t, e);
|
|
124
|
-
}
|
|
125
|
-
function ae(t) {
|
|
126
|
-
for (var e = t.s; e !== void 0; e = e.n) if (e.S.i !== e.i || !e.S.h() || e.S.i !== e.i) return !0;
|
|
127
|
-
return !1;
|
|
128
|
-
}
|
|
129
|
-
function ce(t) {
|
|
130
|
-
for (var e = t.s; e !== void 0; e = e.n) {
|
|
131
|
-
var s = e.S.n;
|
|
132
|
-
if (s !== void 0 && (e.r = s), e.S.n = e, e.i = -1, e.n === void 0) {
|
|
133
|
-
t.s = e;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
function ue(t) {
|
|
139
|
-
for (var e = t.s, s = void 0; e !== void 0; ) {
|
|
140
|
-
var l = e.p;
|
|
141
|
-
e.i === -1 ? (e.S.U(e), l !== void 0 && (l.n = e.n), e.n !== void 0 && (e.n.p = l)) : s = e, e.S.n = e.r, e.r !== void 0 && (e.r = void 0), e = l;
|
|
142
|
-
}
|
|
143
|
-
t.s = s;
|
|
144
|
-
}
|
|
145
|
-
function A(t, e) {
|
|
146
|
-
O.call(this, void 0), this.x = t, this.s = void 0, this.g = F - 1, this.f = 4, this.W = e == null ? void 0 : e.watched, this.Z = e == null ? void 0 : e.unwatched, this.name = e == null ? void 0 : e.name;
|
|
147
|
-
}
|
|
148
|
-
A.prototype = new O();
|
|
149
|
-
A.prototype.h = function() {
|
|
150
|
-
if (this.f &= -3, 1 & this.f) return !1;
|
|
151
|
-
if ((36 & this.f) == 32 || (this.f &= -5, this.g === F)) return !0;
|
|
152
|
-
if (this.g = F, this.f |= 1, this.i > 0 && !ae(this))
|
|
153
|
-
return this.f &= -2, !0;
|
|
154
|
-
var t = p;
|
|
155
|
-
try {
|
|
156
|
-
ce(this), p = this;
|
|
157
|
-
var e = this.x();
|
|
158
|
-
(16 & this.f || this.v !== e || this.i === 0) && (this.v = e, this.f &= -17, this.i++);
|
|
159
|
-
} catch (s) {
|
|
160
|
-
this.v = s, this.f |= 16, this.i++;
|
|
161
|
-
}
|
|
162
|
-
return p = t, ue(this), this.f &= -2, !0;
|
|
163
|
-
};
|
|
164
|
-
A.prototype.S = function(t) {
|
|
165
|
-
if (this.t === void 0) {
|
|
166
|
-
this.f |= 36;
|
|
167
|
-
for (var e = this.s; e !== void 0; e = e.n) e.S.S(e);
|
|
168
|
-
}
|
|
169
|
-
O.prototype.S.call(this, t);
|
|
170
|
-
};
|
|
171
|
-
A.prototype.U = function(t) {
|
|
172
|
-
if (this.t !== void 0 && (O.prototype.U.call(this, t), this.t === void 0)) {
|
|
173
|
-
this.f &= -33;
|
|
174
|
-
for (var e = this.s; e !== void 0; e = e.n) e.S.U(e);
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
A.prototype.N = function() {
|
|
178
|
-
if (!(2 & this.f)) {
|
|
179
|
-
this.f |= 6;
|
|
180
|
-
for (var t = this.t; t !== void 0; t = t.x) t.t.N();
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
Object.defineProperty(A.prototype, "value", { get: function() {
|
|
184
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
185
|
-
var t = re(this);
|
|
186
|
-
if (this.h(), t !== void 0 && (t.i = this.i), 16 & this.f) throw this.v;
|
|
187
|
-
return this.v;
|
|
188
|
-
} });
|
|
189
|
-
function se(t, e) {
|
|
190
|
-
return new A(t, e);
|
|
191
|
-
}
|
|
192
|
-
function le(t) {
|
|
193
|
-
var e = t.m;
|
|
194
|
-
if (t.m = void 0, typeof e == "function") {
|
|
195
|
-
H++;
|
|
196
|
-
var s = p;
|
|
197
|
-
p = void 0;
|
|
198
|
-
try {
|
|
199
|
-
e();
|
|
200
|
-
} catch (l) {
|
|
201
|
-
throw t.f &= -2, t.f |= 8, ee(t), l;
|
|
202
|
-
} finally {
|
|
203
|
-
p = s, G();
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function ee(t) {
|
|
208
|
-
for (var e = t.s; e !== void 0; e = e.n) e.S.U(e);
|
|
209
|
-
t.x = void 0, t.s = void 0, le(t);
|
|
210
|
-
}
|
|
211
|
-
function de(t) {
|
|
212
|
-
if (p !== this) throw new Error("Out-of-order effect");
|
|
213
|
-
ue(this), p = t, this.f &= -2, 8 & this.f && ee(this), G();
|
|
214
|
-
}
|
|
215
|
-
function C(t, e) {
|
|
216
|
-
this.x = t, this.m = void 0, this.s = void 0, this.u = void 0, this.f = 32, this.name = e == null ? void 0 : e.name;
|
|
217
|
-
}
|
|
218
|
-
C.prototype.c = function() {
|
|
219
|
-
var t = this.S();
|
|
220
|
-
try {
|
|
221
|
-
if (8 & this.f || this.x === void 0) return;
|
|
222
|
-
var e = this.x();
|
|
223
|
-
typeof e == "function" && (this.m = e);
|
|
224
|
-
} finally {
|
|
225
|
-
t();
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
C.prototype.S = function() {
|
|
229
|
-
if (1 & this.f) throw new Error("Cycle detected");
|
|
230
|
-
this.f |= 1, this.f &= -9, le(this), ce(this), H++;
|
|
231
|
-
var t = p;
|
|
232
|
-
return p = this, de.bind(this, t);
|
|
233
|
-
};
|
|
234
|
-
C.prototype.N = function() {
|
|
235
|
-
2 & this.f || (this.f |= 2, this.u = Z, Z = this);
|
|
236
|
-
};
|
|
237
|
-
C.prototype.d = function() {
|
|
238
|
-
this.f |= 8, 1 & this.f || ee(this);
|
|
239
|
-
};
|
|
240
|
-
C.prototype.dispose = function() {
|
|
241
|
-
this.d();
|
|
242
|
-
};
|
|
243
|
-
function he(t, e) {
|
|
244
|
-
var s = new C(t, e);
|
|
245
|
-
try {
|
|
246
|
-
s.c();
|
|
247
|
-
} catch (w) {
|
|
248
|
-
throw s.d(), w;
|
|
249
|
-
}
|
|
250
|
-
var l = s.d.bind(s);
|
|
251
|
-
return l[Symbol.dispose] = l, l;
|
|
252
|
-
}
|
|
253
|
-
function pe(t = {}) {
|
|
254
|
-
const e = (t.namespace ?? "default").trim() || "default", s = t.plugins ?? [], l = /* @__PURE__ */ new Map();
|
|
255
|
-
function w(S, I) {
|
|
256
|
-
return function() {
|
|
257
|
-
var E;
|
|
258
|
-
const M = `${e}:${S}`, U = l.get(S);
|
|
259
|
-
if (U) return U;
|
|
260
|
-
const R = I.state(), m = I.modules ?? {}, b = { ...R };
|
|
261
|
-
for (const [r, i] of Object.entries(m))
|
|
262
|
-
b[r] = i.state();
|
|
263
|
-
const h = Q(b), j = /* @__PURE__ */ new Map(), _ = /* @__PURE__ */ new Map(), P = /* @__PURE__ */ new Map(), N = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), n = new Set(Object.keys(R)), c = new Set(Object.keys(I.getters ?? {})), d = new Set(Object.keys(I.actions ?? {})), $ = (r) => h.value[r] ?? {}, W = (r, i) => {
|
|
264
|
-
h.value = {
|
|
265
|
-
...h.value,
|
|
266
|
-
[r]: i
|
|
267
|
-
};
|
|
268
|
-
}, q = new Proxy(
|
|
269
|
-
{},
|
|
270
|
-
{
|
|
271
|
-
get(r, i) {
|
|
272
|
-
var u, f;
|
|
273
|
-
if (j.has(i)) return (u = j.get(i)) == null ? void 0 : u.value;
|
|
274
|
-
if (g.has(i)) return (f = g.get(i)) == null ? void 0 : f.value;
|
|
275
|
-
if (n.has(i)) return h.value[i];
|
|
276
|
-
const y = N.get(i);
|
|
277
|
-
return y ? $(y.moduleName)[y.key] : h.value[i];
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
);
|
|
281
|
-
for (const [r, i] of Object.entries(I.getters ?? {}))
|
|
282
|
-
j.set(
|
|
283
|
-
r,
|
|
284
|
-
se(() => i(h.value, q))
|
|
285
|
-
);
|
|
286
|
-
const te = (r, i) => {
|
|
287
|
-
var u;
|
|
288
|
-
for (const f of o) f(r);
|
|
289
|
-
for (const f of s)
|
|
290
|
-
(u = f.onMutation) == null || u.call(f, i, r);
|
|
291
|
-
}, ne = (r, i, u, f) => {
|
|
292
|
-
const y = h.value[r];
|
|
293
|
-
Object.is(y, i) || (h.value = {
|
|
294
|
-
...h.value,
|
|
295
|
-
[r]: i
|
|
296
|
-
}, te(
|
|
297
|
-
{
|
|
298
|
-
namespace: e,
|
|
299
|
-
scopeId: M,
|
|
300
|
-
storeId: S,
|
|
301
|
-
key: r,
|
|
302
|
-
oldValue: y,
|
|
303
|
-
newValue: i,
|
|
304
|
-
origin: u
|
|
305
|
-
},
|
|
306
|
-
f
|
|
307
|
-
));
|
|
308
|
-
}, L = (r, i, u, f, y) => {
|
|
309
|
-
const x = $(r), a = x[i];
|
|
310
|
-
Object.is(a, u) || (W(r, {
|
|
311
|
-
...x,
|
|
312
|
-
[i]: u
|
|
313
|
-
}), te(
|
|
314
|
-
{
|
|
315
|
-
namespace: e,
|
|
316
|
-
scopeId: M,
|
|
317
|
-
storeId: S,
|
|
318
|
-
key: `${r}.${i}`,
|
|
319
|
-
oldValue: a,
|
|
320
|
-
newValue: u,
|
|
321
|
-
origin: f
|
|
322
|
-
},
|
|
323
|
-
y
|
|
324
|
-
));
|
|
325
|
-
}, D = {
|
|
326
|
-
$id: S,
|
|
327
|
-
$namespace: e,
|
|
328
|
-
$scopeId: M,
|
|
329
|
-
$subscribe(r) {
|
|
330
|
-
return o.add(r), () => o.delete(r);
|
|
331
|
-
},
|
|
332
|
-
$dispose() {
|
|
333
|
-
var r;
|
|
334
|
-
o.clear();
|
|
335
|
-
for (const i of s)
|
|
336
|
-
(r = i.onDispose) == null || r.call(i, k);
|
|
337
|
-
l.delete(S);
|
|
338
|
-
},
|
|
339
|
-
$patch(r, i = "local") {
|
|
340
|
-
T(() => {
|
|
341
|
-
for (const [u, f] of Object.entries(r)) {
|
|
342
|
-
const y = N.get(u);
|
|
343
|
-
if (y) {
|
|
344
|
-
L(y.moduleName, y.key, f, i, k);
|
|
345
|
-
continue;
|
|
346
|
-
}
|
|
347
|
-
if (u.includes(".")) {
|
|
348
|
-
const [x, a] = u.split(".", 2);
|
|
349
|
-
if (m[x]) {
|
|
350
|
-
L(x, a, f, i, k);
|
|
351
|
-
continue;
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (m[u] && f && typeof f == "object" && !Array.isArray(f)) {
|
|
355
|
-
for (const [x, a] of Object.entries(f))
|
|
356
|
-
L(u, x, a, i, k);
|
|
357
|
-
continue;
|
|
358
|
-
}
|
|
359
|
-
ne(u, f, i, k);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
$snapshot() {
|
|
364
|
-
return { ...h.value };
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
for (const [r, i] of Object.entries(m)) {
|
|
368
|
-
const u = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map(), y = new Proxy(
|
|
369
|
-
{},
|
|
370
|
-
{
|
|
371
|
-
get(a, v) {
|
|
372
|
-
var V, z, oe;
|
|
373
|
-
if (u.has(v)) return (V = u.get(v)) == null ? void 0 : V.value;
|
|
374
|
-
if (j.has(v)) return (z = j.get(v)) == null ? void 0 : z.value;
|
|
375
|
-
if (g.has(v)) return (oe = g.get(v)) == null ? void 0 : oe.value;
|
|
376
|
-
const ie = $(r);
|
|
377
|
-
if (v in ie) return ie[v];
|
|
378
|
-
if (n.has(v)) return h.value[v];
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
);
|
|
382
|
-
for (const [a, v] of Object.entries(i.getters ?? {}))
|
|
383
|
-
u.set(
|
|
384
|
-
a,
|
|
385
|
-
se(() => v($(r), h.value, y))
|
|
386
|
-
);
|
|
387
|
-
let x;
|
|
388
|
-
for (const [a, v] of Object.entries(i.actions ?? {}))
|
|
389
|
-
f.set(a, (...V) => T(() => v.apply(x, V)));
|
|
390
|
-
x = new Proxy(
|
|
391
|
-
{},
|
|
392
|
-
{
|
|
393
|
-
get(a, v) {
|
|
394
|
-
var V;
|
|
395
|
-
if (f.has(v)) return f.get(v);
|
|
396
|
-
if (u.has(v)) return (V = u.get(v)) == null ? void 0 : V.value;
|
|
397
|
-
const z = $(r);
|
|
398
|
-
return v in z ? z[v] : k[v];
|
|
399
|
-
},
|
|
400
|
-
set(a, v, V) {
|
|
401
|
-
if (f.has(v) || u.has(v)) return !1;
|
|
402
|
-
const z = $(r);
|
|
403
|
-
return v in z ? L(r, v, V, "local", k) : k[v] = V, !0;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
), P.set(r, x), _.set(r, u);
|
|
407
|
-
for (const a of Object.keys($(r)))
|
|
408
|
-
!(n.has(a) || c.has(a) || d.has(a) || Reflect.has(D, a) || m[a] !== void 0) && !N.has(a) && N.set(a, { moduleName: r, key: a });
|
|
409
|
-
for (const [a, v] of u.entries())
|
|
410
|
-
!(n.has(a) || c.has(a) || d.has(a) || Reflect.has(D, a) || m[a] !== void 0) && !g.has(a) && g.set(a, v);
|
|
411
|
-
for (const [a, v] of f.entries())
|
|
412
|
-
!(n.has(a) || c.has(a) || d.has(a) || Reflect.has(D, a) || m[a] !== void 0) && !Reflect.has(D, a) && (D[a] = v);
|
|
413
|
-
}
|
|
414
|
-
const k = new Proxy(D, {
|
|
415
|
-
get(r, i, u) {
|
|
416
|
-
var f, y;
|
|
417
|
-
if (Reflect.has(r, i)) return Reflect.get(r, i, u);
|
|
418
|
-
if (P.has(i)) return P.get(i);
|
|
419
|
-
if (j.has(i)) return (f = j.get(i)) == null ? void 0 : f.value;
|
|
420
|
-
if (g.has(i)) return (y = g.get(i)) == null ? void 0 : y.value;
|
|
421
|
-
if (n.has(i)) return h.value[i];
|
|
422
|
-
const x = N.get(i);
|
|
423
|
-
return x ? $(x.moduleName)[x.key] : h.value[i];
|
|
424
|
-
},
|
|
425
|
-
set(r, i, u, f) {
|
|
426
|
-
if (Reflect.has(r, i))
|
|
427
|
-
return Reflect.set(r, i, u, f);
|
|
428
|
-
const y = N.get(i);
|
|
429
|
-
return y ? (L(y.moduleName, y.key, u, "local", f), !0) : (ne(i, u, "local", f), !0);
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
for (const [r, i] of Object.entries(I.actions ?? {}))
|
|
433
|
-
D[r] = (...u) => T(() => i.apply(k, u));
|
|
434
|
-
for (const r of s)
|
|
435
|
-
(E = r.onInit) == null || E.call(r, k);
|
|
436
|
-
return l.set(S, k), k;
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
function J(S, I) {
|
|
440
|
-
return function() {
|
|
441
|
-
var E;
|
|
442
|
-
const M = `\0machine:${S}`, U = l.get(M);
|
|
443
|
-
if (U) return U;
|
|
444
|
-
const R = `${e}:${S}`, m = Q(I.initial), b = Q((I.context ?? (() => ({})))()), h = /* @__PURE__ */ new Set(), j = (o, n) => {
|
|
445
|
-
var c;
|
|
446
|
-
for (const d of h) d(o);
|
|
447
|
-
for (const d of s)
|
|
448
|
-
(c = d.onMutation) == null || c.call(d, n, o);
|
|
449
|
-
}, _ = (o, n, c, d) => {
|
|
450
|
-
const $ = b.value[o];
|
|
451
|
-
Object.is($, n) || (b.value = { ...b.value, [o]: n }, j({ namespace: e, scopeId: R, storeId: S, key: o, oldValue: $, newValue: n, origin: c }, d));
|
|
452
|
-
}, P = (o, n, c) => {
|
|
453
|
-
const d = m.value;
|
|
454
|
-
Object.is(d, o) || (m.value = o, j(
|
|
455
|
-
{ namespace: e, scopeId: R, storeId: S, key: "$state", oldValue: d, newValue: o, origin: n },
|
|
456
|
-
c
|
|
457
|
-
));
|
|
458
|
-
}, N = {
|
|
459
|
-
$id: S,
|
|
460
|
-
$namespace: e,
|
|
461
|
-
$scopeId: R,
|
|
462
|
-
$subscribe(o) {
|
|
463
|
-
return h.add(o), () => h.delete(o);
|
|
464
|
-
},
|
|
465
|
-
$dispose() {
|
|
466
|
-
var o;
|
|
467
|
-
h.clear();
|
|
468
|
-
for (const n of s)
|
|
469
|
-
(o = n.onDispose) == null || o.call(n, g);
|
|
470
|
-
l.delete(M);
|
|
471
|
-
},
|
|
472
|
-
$patch(o, n = "local") {
|
|
473
|
-
T(() => {
|
|
474
|
-
for (const [c, d] of Object.entries(o))
|
|
475
|
-
c === "$state" ? P(d, n, g) : _(c, d, n, g);
|
|
476
|
-
});
|
|
477
|
-
},
|
|
478
|
-
$snapshot() {
|
|
479
|
-
return { $state: m.value, ...b.value };
|
|
480
|
-
},
|
|
481
|
-
send(o, n) {
|
|
482
|
-
T(() => {
|
|
483
|
-
var c, d, $;
|
|
484
|
-
const W = (c = I.actions) == null ? void 0 : c[o];
|
|
485
|
-
W && W.call(g, n);
|
|
486
|
-
const q = ($ = (d = I.states[m.value]) == null ? void 0 : d.on) == null ? void 0 : $[o];
|
|
487
|
-
q !== void 0 && P(q, "local", g);
|
|
488
|
-
});
|
|
489
|
-
},
|
|
490
|
-
matches(o) {
|
|
491
|
-
return m.value === o;
|
|
492
|
-
},
|
|
493
|
-
can(o) {
|
|
494
|
-
const n = I.states[m.value];
|
|
495
|
-
return !!(n != null && n.on && o in n.on);
|
|
496
|
-
}
|
|
497
|
-
}, g = new Proxy(N, {
|
|
498
|
-
get(o, n, c) {
|
|
499
|
-
return n === "state" ? m.value : Reflect.has(o, n) ? Reflect.get(o, n, c) : b.value[n];
|
|
500
|
-
},
|
|
501
|
-
set(o, n, c, d) {
|
|
502
|
-
return n === "state" ? !1 : Reflect.has(o, n) ? Reflect.set(o, n, c, d) : (_(n, c, "local", d), !0);
|
|
503
|
-
}
|
|
504
|
-
});
|
|
505
|
-
for (const o of s)
|
|
506
|
-
(E = o.onInit) == null || E.call(o, g);
|
|
507
|
-
return l.set(M, g), g;
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
return {
|
|
511
|
-
defineStore: w,
|
|
512
|
-
defineMachine: J,
|
|
513
|
-
use(S) {
|
|
514
|
-
s.push(S);
|
|
515
|
-
}
|
|
516
|
-
};
|
|
517
|
-
}
|
|
518
|
-
pe();
|
|
519
|
-
function ye(t = {}) {
|
|
520
|
-
const e = t.channelName ?? "storix-sync", s = new Set(t.include ?? []), l = new Set(t.exclude ?? []), w = t.namespaces ?? [], J = w === "*" ? null : new Set(w), S = t.debounce ?? 16, I = crypto.randomUUID(), E = `__storix_sync__:${e}`, M = /* @__PURE__ */ new Map(), U = /* @__PURE__ */ new Set(), R = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
|
|
521
|
-
let b = null;
|
|
522
|
-
const h = typeof window < "u" && "BroadcastChannel" in window ? new BroadcastChannel(e) : null, j = (o) => {
|
|
523
|
-
const n = [o.$id, o.$scopeId];
|
|
524
|
-
return !(n.some((c) => l.has(c)) || s.size > 0 && !n.some((c) => s.has(c)));
|
|
525
|
-
}, _ = (o, n) => n === o || J === null ? !0 : J.has(n), P = (o, n) => {
|
|
526
|
-
!n || n.originTabId === I || _(o.$namespace, n.namespace) && n.storeId === o.$id && j(o) && o.$patch({ [n.key]: n.newValue }, "remote");
|
|
527
|
-
}, N = () => {
|
|
528
|
-
if (b = null, M.size === 0) return;
|
|
529
|
-
const o = Array.from(M.values());
|
|
530
|
-
M.clear();
|
|
531
|
-
for (const n of o) {
|
|
532
|
-
const c = {
|
|
533
|
-
...n,
|
|
534
|
-
originTabId: I
|
|
1
|
+
import { definePlugin as b } from "@storix-js/core";
|
|
2
|
+
function E(c = {}) {
|
|
3
|
+
const m = c.channelName ?? "storix-sync", g = new Set(c.include ?? []), h = new Set(c.exclude ?? []), p = c.namespaces ?? [], I = p === "*" ? null : new Set(p), $ = c.debounce ?? 16, S = crypto.randomUUID(), a = `__storix_sync__:${m}`, i = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map();
|
|
4
|
+
let r = null;
|
|
5
|
+
const t = typeof window < "u" && "BroadcastChannel" in window ? new BroadcastChannel(m) : null, f = (n) => {
|
|
6
|
+
const e = [n.$id, n.$scopeId];
|
|
7
|
+
return !(e.some((s) => h.has(s)) || g.size > 0 && !e.some((s) => g.has(s)));
|
|
8
|
+
}, v = (n, e) => e === n || I === null ? !0 : I.has(e), y = (n, e) => {
|
|
9
|
+
!e || e.originTabId === S || v(n.$namespace, e.namespace) && e.storeId === n.$id && f(n) && n.$patch({ [e.key]: e.newValue }, "remote");
|
|
10
|
+
}, w = () => {
|
|
11
|
+
if (r = null, i.size === 0) return;
|
|
12
|
+
const n = Array.from(i.values());
|
|
13
|
+
i.clear();
|
|
14
|
+
for (const e of n) {
|
|
15
|
+
const s = {
|
|
16
|
+
...e,
|
|
17
|
+
originTabId: S
|
|
535
18
|
};
|
|
536
|
-
if (
|
|
19
|
+
if (t && t.postMessage(s), typeof window < "u" && "localStorage" in window)
|
|
537
20
|
try {
|
|
538
|
-
window.localStorage.setItem(
|
|
21
|
+
window.localStorage.setItem(a, JSON.stringify(s)), window.localStorage.removeItem(a);
|
|
539
22
|
} catch {
|
|
540
23
|
}
|
|
541
24
|
}
|
|
542
|
-
},
|
|
543
|
-
if (
|
|
544
|
-
|
|
25
|
+
}, M = (n) => {
|
|
26
|
+
if (i.set(`${n.scopeId}:${n.key}`, n), $ <= 0) {
|
|
27
|
+
w();
|
|
545
28
|
return;
|
|
546
29
|
}
|
|
547
|
-
|
|
30
|
+
r || (r = setTimeout(w, $));
|
|
548
31
|
};
|
|
549
|
-
return {
|
|
32
|
+
return b({
|
|
550
33
|
name: "sync",
|
|
551
|
-
onInit(
|
|
552
|
-
const
|
|
553
|
-
if (
|
|
554
|
-
if (
|
|
555
|
-
const
|
|
556
|
-
|
|
34
|
+
onInit(n) {
|
|
35
|
+
const e = n;
|
|
36
|
+
if (f(e)) {
|
|
37
|
+
if (d.add(e.$scopeId), t) {
|
|
38
|
+
const s = (o) => {
|
|
39
|
+
y(e, o.data);
|
|
557
40
|
};
|
|
558
|
-
|
|
41
|
+
u.set(e.$scopeId, s), t.addEventListener("message", s);
|
|
559
42
|
}
|
|
560
43
|
if (typeof window < "u") {
|
|
561
|
-
const
|
|
562
|
-
if (!(
|
|
44
|
+
const s = (o) => {
|
|
45
|
+
if (!(o.key !== a || !o.newValue))
|
|
563
46
|
try {
|
|
564
|
-
const
|
|
565
|
-
|
|
47
|
+
const H = JSON.parse(o.newValue);
|
|
48
|
+
y(e, H);
|
|
566
49
|
} catch {
|
|
567
50
|
}
|
|
568
51
|
};
|
|
569
|
-
|
|
52
|
+
l.set(e.$scopeId, s), window.addEventListener("storage", s);
|
|
570
53
|
}
|
|
571
54
|
}
|
|
572
55
|
},
|
|
573
|
-
onMutation(
|
|
574
|
-
|
|
56
|
+
onMutation(n, e) {
|
|
57
|
+
e.origin !== "remote" && f(n) && M(e);
|
|
575
58
|
},
|
|
576
|
-
onDispose(
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
const
|
|
580
|
-
|
|
581
|
-
const
|
|
582
|
-
typeof window < "u" &&
|
|
59
|
+
onDispose(n) {
|
|
60
|
+
const e = n;
|
|
61
|
+
d.delete(e.$scopeId);
|
|
62
|
+
const s = u.get(e.$scopeId);
|
|
63
|
+
t && s && (t.removeEventListener("message", s), u.delete(e.$scopeId));
|
|
64
|
+
const o = l.get(e.$scopeId);
|
|
65
|
+
typeof window < "u" && o && (window.removeEventListener("storage", o), l.delete(e.$scopeId)), r && (clearTimeout(r), r = null), w(), d.size === 0 && (t == null || t.close());
|
|
583
66
|
}
|
|
584
|
-
};
|
|
67
|
+
});
|
|
585
68
|
}
|
|
586
69
|
export {
|
|
587
|
-
|
|
70
|
+
E as syncPlugin
|
|
588
71
|
};
|