@autostorejs/syncer
Advanced tools
@@ -1,2 +0,2 @@ | ||
| var AutoStoreSyncer=(function(exports){'use strict';var C=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var W=class extends Error{operate};function st(s,...t){if(t.length===0)return s;let e=t.map((r,o)=>{let i=Object.entries(r||{});return i.some(([n,p])=>p===void 0)?i.reduce((n,[p,a])=>(a!==void 0&&(n[p]=a),n),{}):r});return Object.assign(s,...e)}function I(s){return s!=null&&typeof s[Symbol.iterator]=="function"&&typeof s!="string"}function b(s){if(typeof s!="object"||s===null)return false;var t=Object.getPrototypeOf(s);if(t===null)return true;for(var e=t;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return t===e}function ot(s,t=false){if(typeof s=="number")return true;if(typeof s!="string"||t)return false;try{if(s.includes(".")){let e=parseFloat(s);return s.endsWith(".")?!isNaN(e)&&String(e).length===s.length-1:!isNaN(e)&&String(e).length===s.length}else {let e=parseInt(s);return !isNaN(e)&&String(e).length===s.length}}catch{return false}}function w(s){if(ot(s)||typeof s=="boolean"||typeof s=="function"||s instanceof Error)return false;if(s==null||s==null||Array.isArray(s)&&s.length==0||b(s)&&Object.keys(s).length==0||typeof s=="string"&&s.trim()=="")return true;try{if(I(s)&&s.size==0)return !0}catch{}return false}function it(s,{empty:t,delimiter:e=","}){let r=s;try{return typeof r=="function"&&(r=r.call(this,r)),w(r)&&(r=t||""),Array.isArray(r)?r.map(o=>String(o)).join(e):b(r)?Object.entries(r).reduce((o,[i,n])=>(o.push(`${i}=${String(n)}`),o),[]).join(e):I(r)&&typeof r!="string"?[...r].map(o=>String(o)).join(e):r instanceof Error?r.message:String(r)}catch{return String(r)}}var $t=/\{(\<(.*?)\>)?\s*([^\{\}\>\<]*)(?<!\s)\s*(\<(.*?)\>)?\}/gm;function U(s,t,e){let r,o=st({empty:null,delimiter:",",forEach:null},e);typeof t=="function"&&(t=t.call(s)),Array.isArray(t)&&t.length==1&&(b(t[0])||Array.isArray(t[0]))&&(t=t[0]),["boolean","string","number"].includes(typeof t)?r=[t]:t instanceof Map?r=[...t.entries()].reduce((n,p)=>(n[p[0]]=p[1],n),{}):Symbol.iterator in t?r=[...t]:b(t)?r=t:t instanceof Error?r=[`Error:${t.message}`]:r=[t];let i=0;return s.replaceAll($t,function(){let n=arguments[2]||"",p=arguments[3]||"",a=arguments[5]||"",u="",c=false;if(Array.isArray(r)){let d=i>=r.length;u=d?"":it.call(s,r[i],o),c=w(u)||d,i++;}else if(b(r)){let d=p in r;u=d?it.call(s,r[p],o):"",c=w(u)||!d;}if(typeof o.forEach=="function"){let d=o.forEach(p,u,n,a);d!==void 0&&(Array.isArray(d)&&d.length==3?(n=d[0],u=d[1],a=d[2]):w(d)||(u=String(d)),c=w(u));}return c&&(o.empty==null?(u="",n="",a=""):u=o.empty),`${n}${u}${a}`})}function nt(s,...t){let e=s.valueOf(),r={},o=[...t];if(t.length>0&&b(t[t.length-1])){let i=t[t.length-1];("$delimiter"in i||"$empty"in i||"$forEach"in i)&&("$delimiter"in i&&(r.delimiter=i.$delimiter),"$empty"in i&&(r.empty=i.$empty),"$forEach"in i&&(r.forEach=i.$forEach),o.pop());}try{return o.length==1?U(e,o[0],r):U(e,[...o],r)}catch{return e}}String.prototype.params=function(){return nt(this,...arguments)};function kt(s,t,e){if(typeof t=="string"){let r=0,o;for(;(o=s.indexOf(t,r))>-1;){let i=typeof e=="function"?e(t):e,n=s.length;s=s.substring(0,o)+i+s.substring(o+t.length),r=o+i.length+s.length-n;}}else {let r;if(!t.global||!t.multiline)throw new Error("The search parameter must be enabled '/gm' option");for(;(r=t.exec(s))!==null;){r.index===t.lastIndex&&t.lastIndex++;let o=s.length,i=r[0].length,n=typeof e=="function"?e(r[0],...r):e;s=s.substring(0,r.index)+n+s.substring(r.index+i),t.lastIndex+=s.length-o;}}return s}String.prototype.replaceAll||(String.prototype.replaceAll=function(s,t){return kt(this,s,t)});(s=>typeof C<"u"?C:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof C<"u"?C:t)[e]}):s)(function(s){if(typeof C<"u")return C.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var B="__AS_SKIP_PROXY__";var H="__AS_ASYNC_COMPUTED_VALUE__";function z(s){try{return s[B]===!0}catch{}return false}function F(s){return toString.call(s)==="[object Map]"}function S(s){return s&&typeof s=="object"&&s.hasOwnProperty(H)}function Y(s,t){let e=s.get(t);if(e!==void 0)return e;let r=s.get(Number(t)||t);if(r!==void 0)return r}function f(s,t,e){if(!t||t.length===0)return s;let r=Array.isArray(t)?t:t.split("."),o,i=s;for(let n=0;n<r.length;n++){let p=r[n];if(F(i))o=Y(i,p);else if(p in i)o=i[p];else return e;i=o;}return o}function y(s,t,e,r){if(!t||!s)return s;let o=t;if(o.length===0)return typeof s=="object"&&Object.assign(s,e),s;{let i=s,n=[],p=(a,u,c)=>{a[u]=c;};for(let a=0;a<o.length;a++){let u=o[a];if(n.push(u),i)if(Array.isArray(i)){let c=parseInt(u,10);if(Number.isNaN(c)||c<0)throw new Error(`setVal: invalid array index ${n.join(".")}`);a===o.length-1?p(i,c,e):i=i[c];}else i instanceof Map||i instanceof WeakMap?a===o.length-1?i.set(u,e):(i.has(u)||i.set(u,{}),i=i.get(u)):typeof i=="object"&&u in i?a===o.length-1?p(i,u,e):i=i[u]:(i[u]=a===o.length-1?e:{},i=i[u]);else i[u]=a===o.length-1?e:{},i=i[u];}}return s}function T(s,t){function e(r,o){for(let i in r){let n=r[i];typeof t=="function"&&t({value:n,key:i,parent:r,path:o.concat(i)}),typeof n=="object"&&!z(n)&&e(n,o.concat(i));}}e(s,[]);}function $(s){return typeof s=="object"?JSON.parse(JSON.stringify(s)):s}function ct(s,t){return s.length>t.length?false:s.every((e,r)=>e===t[r])}function _(s){return s?typeof s=="function":false}function V(s,t){let{reserveAsync:e,includeFunc:r}=Object.assign({reserveAsync:false},t);if(Array.isArray(s)){let o=[...s];for(let i=0;i<o.length;i++)o[i]=V(o[i],t);return o}else if(typeof s=="object"){if(!e&&S(s))return s.value;{let o={...s};for(let i in o)o[i]=V(o[i],t);return o}}return r&&_(s)?`\`\`\`${s.toString()}\`\`\``:s}var gt=Object.defineProperty,Zt=(s,t,e)=>t in s?gt(s,t,{enumerable:true,configurable:true,writable:true,value:e}):s[t]=e,l=(s,t)=>gt(s,"name",{value:t,configurable:true}),g=(s,t,e)=>Zt(s,typeof t!="symbol"?t+"":t,e);var bt=class extends Error{constructor(t){super(t);}};l(bt,"FastEventError");var j=bt,te=class extends j{};l(te,"TimeoutError");var _t=class extends j{};l(_t,"UnboundError");var ee=_t,St=class extends j{};l(St,"AbortError");var yt=St,vt=class extends j{};l(vt,"CancelError");var re=vt,se=class extends j{};l(se,"QueueOverflowError");var Ot={clearRetain:Symbol.for("ClearRetain")},D=(function(s){return s[s.Transformed=1]="Transformed",s})({});function Z(s,t,e,r){let o,i={},n={};return typeof s[0]=="object"?(Object.assign(n,s[0]),i=typeof s[1]=="boolean"?{retain:s[1]}:s[1]||{},o=s[0].meta):(n.type=s[0],n.payload=s[1],i=typeof s[2]=="boolean"?{retain:s[2]}:s[2]||{}),o=Object.assign({},t,e,i.meta,o),Object.keys(o).length===0&&(o=void 0),n.meta=o,i.executor===void 0&&(i.executor=r),[n,i]}l(Z,"parseEmitArgs");function At(s){return s?typeof s=="object"&&"__FastEventScope__"in s:false}l(At,"isFastEventScope");function tt(s,t,e){let r=s[0],o=At(s[1])?s[1]:void 0,i=(o?s[2]:s[1])||{};return i.meta=Object.assign({},t,i?.meta),i.context=i.context!==void 0?i.context:e,[r,o,i]}l(tt,"parseScopeArgs");function k(s,t){return Object.defineProperty(s,"name",{value:t||"anonymous",configurable:true}),s}l(k,"renameFn");function h(s){return s&&typeof s=="function"}l(h,"isFunction");var Et=class xt{constructor(t){g(this,"__FastEventScope__",true),g(this,"_options",{}),g(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),g(this,"prefix",""),g(this,"emitter"),this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(t,e,r){this.emitter=t,this._options=Object.assign(this._options,{scope:e},r),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let r=this;return k(function(o,i){let n=i.rawEventType||o.type;if(n.startsWith(e)){let p=((i.flags||0)&D.Transformed)>0?o:Object.assign({},o,{type:n.substring(e.length)});return t.call(r.context,p,i)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new ee;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===Ot.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=Z(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){h(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|D.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let t=arguments[0],e=arguments[1],r=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},r,{type:this._fixScopeType(r.type)})}scope(){let[t,e,r]=tt(arguments,this.options.meta,this.options.context),o;return e?o=e:o=new xt,o.bind(this.emitter,this.prefix+t,r),o}onMessage(t,e){}};l(Et,"FastEventScope");var oe=Et;function Q(s,t){if(s.length!==t.length&&s.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:s.length-t.length+1}).fill("*"));for(let r=0;r<s.length;r++)if(e[r]!=="*"&&e[r]!==s[r])return false;return true}l(Q,"isPathMatched");function Ct(s,t){let e=[];for(;;){let r=s.findIndex(o=>t(o));if(r===-1){e.push(r);break}s.splice(r,1);}return e}l(Ct,"removeItem");var Rt=Symbol.for("__expandable__");function ie(s){return s[Rt]=true,s}l(ie,"expandable");function wt(s){return s&&s[Rt]}l(wt,"isExpandable");function Tt(s){for(let t=0;t<s.length;t++){let e=s[t];Array.isArray(e)&&wt(e)&&(s.splice(t,1,...e),t+=e.length-1);}return s}l(Tt,"expandEmitResults");function Vt(s){return s&&typeof s=="object"&&"off"in s&&"listener"in s}l(Vt,"isSubsctiber");function Dt(s,t){return s.catch(e=>(t&&t(e),Promise.resolve(e)))}l(Dt,"tryReturnError");var ne=class{constructor(t){g(this,"__FastEvent__",true),g(this,"listeners",{__listeners:[]}),g(this,"_options"),g(this,"_delimiter","/"),g(this,"_context"),g(this,"retainedMessages",new Map),g(this,"listenerCount",0),g(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,r){let{count:o,prepend:i}=r,n=0;return [this._forEachNodes(t,p=>{let a=[e,o,0,r.tag,r.flags];i?(p.__listeners.splice(0,0,a),n=0):(p.__listeners.push(a),n=p.__listeners.length-1),this.listenerCount++;}),n]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let r=this.listeners;for(let o=0;o<t.length;o++){let i=t[o];if(i in r||(r[i]={__listeners:[]}),o===t.length-1){let n=r[i];return e(n,r),n}else r=r[i];}}_removeListener(t,e,r){r&&Ct(t.__listeners,o=>{o=Array.isArray(o)?o[0]:o;let i=o===r;return i&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),r)),i});}_pipeListener(t,e){return e.forEach(r=>{t=k(r(t),t.name);}),t}on(){let t=arguments[0],e=h(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),r=Object.assign({count:0,flags:0,prepend:false},h(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(h(this._options.onAddListener)){let a=this._options.onAddListener(t,e,r);if(a===false)throw new re;if(Vt(a))return a}let o=t.split(this._delimiter);if(r.pipes&&r.pipes.length>0&&(e=this._pipeListener(e,r.pipes)),h(r.filter)||h(r.off)){let a=e;e=k(function(u,c){if(h(r.off)&&r.off.call(this,u,c)){p();return}if(h(r.filter)){if(r.filter.call(this,u,c))return a.call(this,u,c)}else return a.call(this,u,c)},e.name);}let[i,n]=this._addListener(o,e,r),p=l(()=>i&&this._removeListener(i,o,e),"off");return this._emitRetainMessage(t,i,n),{off:p,listener:e}}once(){return h(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=h(t[0])?void 0:t[0],r=h(t[0])?t[0]:t[1],o=e?e.split(this._delimiter):[],i=e?e.includes("*"):false;if(e&&!i)this._traverseToPath(this.listeners,o,n=>{r?this._removeListener(n,o,r):e&&(n.__listeners=[]);});else {let n=i?[]:o;this._traverseListeners(this.listeners,n,(p,a)=>{(r!==void 0||i&&Q(p,o))&&(r?this._removeListener(a,o,r):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),r=0;this._traverseListeners(this.listeners,e,(o,i)=>{r+=i.__listeners.length,i.__listeners=[];}),this.listenerCount-=r,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(r,o)=>{e+=o.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,r){let o=[];if(t.includes("*")){let i=t.split(this._delimiter);this.retainedMessages.forEach((n,p)=>{let a=p.split(this._delimiter);Q(a,i)&&o.push(n);});}else this.retainedMessages.has(t)&&o.push(this.retainedMessages.get(t));e&&o.forEach(i=>{this._executeListeners([e],i,{},n=>n[0]===e.__listeners[r][0]);});}_traverseToPath(t,e,r,o=0,i){if(o>=e.length){r(t);return}let n=e[o];if(i===true){this._traverseToPath(t,e,r,o+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,r,o+1),"**"in t&&this._traverseToPath(t["**"],e,r,o+1,true),n in t&&this._traverseToPath(t[n],e,r,o+1);}_traverseListeners(t,e,r){let o=t;e&&e.length>0&&this._traverseToPath(t,e,n=>{o=n;});let i=l((n,p,a)=>{p(a,n);for(let[u,c]of Object.entries(n))u.startsWith("__")||c&&i(c,p,[...a,u]);},"traverseNodes");i(o,r,[]);}_onListenerError(t,e,r,o){if(o instanceof Error&&(o._emitter=`${t.name||"anonymous"}:${e.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,o,t,e,r);}catch{}if(this._options.ignoreErrors)return o;throw o}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,r,o=false){try{if(r&&r.abortSignal&&r.abortSignal.aborted)return this._onListenerError(t,e,r,new yt(t.name));let i=((r?.flags||0)&D.Transformed)>0,n=t.call(this.context,i?e.payload:e,r);return o&&n&&n instanceof Promise&&(n=Dt(n,p=>this._onListenerError(t,e,r,p))),n}catch(i){return this._onListenerError(t,e,r,i)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(h(e))return e}_executeListeners(t,e,r,o){if(!t||t.length===0)return [];let i=t.reduce((p,a)=>p.concat(a.__listeners.filter(u=>h(o)?o(u,a):true).map((u,c)=>[u,c,a.__listeners])),[]);h(this._options.transform)&&(r||(r={}),r.rawEventType=e.type,e.payload=this._options.transform.call(this,e),r.flags=this._setListenerFlags(r.flags,D.Transformed)),this._decListenerExecCount(i);let n=this._getListenerExecutor(r);if(n){let p=n(i.map(a=>a[0]),e,r,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return i.map(p=>this._executeListener(p[0][0],e,r,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let r=t[e][0];r[2]++,r[1]>0&&r[1]<=r[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],r=t.split(this._delimiter);return this._traverseToPath(this.listeners,r,o=>{e.push(o);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===Ot.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=Z(arguments,this.options.meta);h(e.parseArgs)&&e.parseArgs(t,e);let r=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let o=[],i=[];if(this._traverseToPath(this.listeners,r,n=>{i.push(n);}),h(this._options.onBeforeExecuteListener)){let n=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(n))return n;if(n===false)throw new yt(t.type)}return h(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|D.Transformed),o.push(...this._executeListeners(i,t,e)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,o,i),this._options.expandEmitResults&&Tt(o),o}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((r,o)=>{let i,n,p=l(a=>{clearTimeout(i),n&&n.off(),r(a);},"listener");e&&e>0&&(i=setTimeout(()=>{n&&n.off(),o(new Error("wait for event<"+t+"> is timeout"));},e)),n=this.on(t,p);})}scope(){let[t,e,r]=tt(arguments,this.options.meta,this.options.context),o;return e?o=e:o=new oe,o.bind(this,t,r),o}};l(ne,"FastEvent");function ae(s){return s?typeof s=="object"&&"type"in s:false}l(ae,"isFastEventMessage");function pe(s){return s&&typeof s=="string"}l(pe,"isString");function ue(s){return typeof s=="function"&&(s.toString().startsWith("class ")||s.prototype?.constructor===s)}l(ue,"isClass");function ce(s){return s?typeof s=="object"&&"__FastEvent__"in s:false}l(ce,"isFastEvent");function Pt(s){return {all:s=s||new Map,on:function(t,e){var r=s.get(t);r?r.push(e):s.set(t,[e]);},off:function(t,e){var r=s.get(t);r&&(e?r.splice(r.indexOf(e)>>>0,1):s.set(t,[]));},emit:function(t,e){var r=s.get(t);r&&r.slice().map(function(o){o(e);}),(r=s.get("*"))&&r.slice().map(function(o){o(t,e);});}}}var x=class{#t;#e;constructor(){this.#t=Pt(),this.#e=new Map;}on(t,e){return this.#e.has(t)&&e(this.#e.get(t)),this.#t.on(t,e),{off:()=>this.#t.off(t,e)}}once(t,e){if(this.#e.has(t))return e(this.#e.get(t)),{off:()=>{}};let r=o=>{e(o),this.#t.off(t,r);};return this.#t.on(t,r),{off:()=>this.#t.off(t,r)}}off(t,e){this.#t.off(t,e);}emit(t,e,r=false){if(arguments.length===1){this.#e.delete(t);return}let o=e;r&&this.#e.set(t,o),this.#t.emit(t,o);}async wait(t,e){return new Promise((r,o)=>{let i=this.once(t,p=>{n!==void 0&&clearTimeout(n),r(p);}),n;e&&e>0&&(n=setTimeout(()=>{i.off(),o(new Error(`\u7B49\u5F85\u4E8B\u4EF6 "${String(t)}" \u8D85\u65F6 (${e}ms)`));},e));})}onAny(t){return this.#t.on("*",t),{off:()=>this.#t.off("*",t)}}clear(){this.#t.all.clear(),this.#e.clear();}clearRetained(t){this.#e.delete(t);}getRetained(t){return this.#e.get(t)}get listeners(){return this.#t.all}};var O=class extends x{static seq=99;_syncing=false;get syncing(){return this._syncing}_emitError(t){this.emit("error",t,true);}push(t){throw new Error(`${this.constructor.name} does not support push() operation. Please use a syncer that implements this method, or override it in a subclass.`)}pull(){throw new Error(`${this.constructor.name} does not support pull() operation. Please use a syncer that implements this method, or override it in a subclass.`)}};var et=-1,A=class s extends O{constructor(e,r){super();this.store=e;this._options=Object.assign({id:e.id,mode:"push",local:[],remote:[],autostart:true,maxCacheSize:100,direction:"both",pathMap:{},peers:["*"],debug:false},r),typeof this._options.local=="string"&&(this._options.local=this._options.local.split(".")),typeof this._options.remote=="string"&&(this._options.remote=this._options.remote.split(".")),this.seq=++s.seq,this._options.autostart&&this.start();}seq;_options;peer;_operateCache=[];_subscribers=[];get id(){return this._options.id}get options(){return this._options}get transport(){return this._options.transport}get localEntry(){return this._options.local}get remoteEntry(){return this._options.remote}_onConnect(){try{let e=this.options.direction,r=this.options.mode;(r==="push"||r=="both")&&this._pushStore(!0),(r==="pull"||r=="both")&&this._pullStore(!0),e==="forward"&&(this._syncing=!0);}finally{this.flush();}}createRemoteOperate(e){return {id:this.id,type:e.type,path:e.path,parentPath:e.parentPath,value:$(e.value),indexs:e.indexs,flags:e.flags??0}}isPeer(e){let r=this._options.peers;return r.includes("*")?true:r.includes(e.id)}start(){if(this.syncing)return;let e;try{this._syncing=!0,this._subscribers.push(this.store.watch(this._onWatchStore.bind(this),{operates:"write"})),this._subscribers.push(this.transport.addReceiver(this.id,r=>{r.id!==this.id&&(!r.type.startsWith("$")&&(this.options.direction==="forward"||!this.isPeer(r))||this._onReceiveFromRemote(r));})),this._subscribers.push(this.transport.on("connect",this._onConnect.bind(this))),this._subscribers.push(this.transport.on("disconnect",this.stop.bind(this))),this._subscribers.push(this.transport.on("error",this.stop.bind(this))),this._subscribers.push(this.transport.on("timeout",this.stop.bind(this))),this.transport.connect();}catch(r){throw e=r,this.stop(),this.emit("error",r,true),r}finally{e||this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._subscribers.forEach(e=>e.off()),this._options.transport.connected&&this._options.transport.send({id:this.id,type:"$stop",path:[],value:void 0,flags:0});}finally{this.emit("stop",void 0,true),this._syncing=false;}}_onWatchStore(e){try{if(this._isPass(e.path,e.value)===!1||Math.abs(e.flags||0)===this.seq||this.options.direction==="backward")return;this._sendToRemote(e);}finally{this.options.debug===true&&this.emit("localOperate",e);}}_isPass(e,r){return _(this._options.filter)?this._options.filter(e,r):true}_sendToRemote(e){let r=this.options.local,o=this.options.remote;if(!ct(this._options.local,e.path))return;if(typeof this._options.pathMap.toRemote=="function"){let n=this._options.pathMap.toRemote(e.path.slice(this._options.local.length),e.value);n&&(e.path=[...o,...n]);}else e.path=[...o,...e.path.slice(r.length)];let i=this.createRemoteOperate(e);this._sendOperate(i);}_onReceiveFromRemote(e){try{if(typeof this._options.onReceive=="function"&&this._options.onReceive.call(this,e)===!1)return;let r=e.type;if(r==="$stop")this.stop();else if(r==="$push")this._updateStore(e);else if(r==="$pull")this._sendStore(e);else if(r==="$update")this._updateStore(e);else if(r==="$ping")this._sendOperate({type:"$pong",value:e.value});else if(r==="$error"){let o=new W;o.operate=e,this.emit("error",o);}else this._applyOperate(e);}finally{this.options.debug===true&&this.emit("remoteOperate",e);}}_applyOperate(e){let{type:r,value:o,indexs:i}=e,n=this.store,p=this._mapPath(e.path,e.value,"toLocal");if(!p)return;e.path=p;let a=[...this.localEntry,...e.path.slice(this.options.remote.length)],u={flags:-this.seq};r==="set"||r==="update"?n.update(c=>{S(f(c,a,true))?y(c,a.concat("value"),o):y(c,a,o);},u):r==="delete"?n.update(c=>{y(c,a,void 0);},u):r==="insert"?n.update(c=>{let d=f(c,a);Array.isArray(i)&&d.splice(i[0],0,...o);},u):r==="remove"&&n.update(c=>{let d=f(c,a);Array.isArray(i)&&(i.length===0?d.splice(0):d.splice(i[0],i.length));},u);}flush(){this.transport.connected&&Promise.all(this._operateCache.map(e=>this.transport.send(e))).finally(()=>{this._operateCache=[];});}_assertConnected(e){return this.transport.connected?true:(this._operateCache.push(e),this._operateCache.length>this._options.maxCacheSize&&this._operateCache.shift(),false)}_sendOperate(e){if(this._assertConnected(e)){if(typeof this._options.onSend=="function"&&this._options.onSend.call(this,e)===false)return;this._options.transport.send(e);}}_getLocalSnap(){return this.store.getSnap({entry:this._options.local.join(".")})}push(){this._pushStore();}_pushStore(e=false){let r=this._getLocalSnap();if(typeof this._options.pathMap.toRemote=="function"){let o=new Map;return T(r,({value:i,path:n})=>{if(this._isPass(n,i)===false)return;let p=Array.isArray(i)?[]:typeof i=="object"?{}:i,a=this._mapPath(n,p,"toRemote");if(a){o.set(JSON.stringify(n),JSON.stringify(a));let u={type:"set",path:[...this.options.remote,...a],value:p};e&&(u.flags=et),this._sendOperate(u);}}),o}else this._sendOperate({id:this.id,type:"$push",path:this.options.remote,value:r,flags:e?et:0});}_sendStore(e){this._sendOperate({id:this.id,type:"$update",path:[],value:this.store.getSnap({entry:e.path.join(".")}),flags:this.seq});}_updateStore(e){try{let o=this.store,i=-this.seq;if(typeof this._options.pathMap.toLocal=="function")T(e.value,({value:n,path:p})=>{if(this._isPass(p,n)===!1)return;let a=Array.isArray(n)?[]:typeof n=="object"?{}:n,u=this._mapPath(p,a,"toLocal");u&&o.update(c=>{y(c,[...this.localEntry,...u],a);},{flags:i});});else {let n=[...this.localEntry,...e.path||[]];o.update(p=>{y(p,n,e.value);},{flags:i});}}catch(o){this.emit("error",o);}finally{this._syncing===false&&(this._syncing=true,this.emit("syncing",e.id,true));}}_pullStore(e=false){this._sendOperate({id:this.id,type:"$pull",path:this.options.remote,value:void 0,flags:e?et:0});}pull(){this._pullStore();}_mapPath(e,r,o){return this._options.pathMap&&_(this._options.pathMap[o])?this._options.pathMap[o](e,r):e}toString(){return `AutoStoreSyncer(${this.id})`}};function Lt(s){return !!s&&typeof s=="object"&&typeof s.then=="function"}var P=class extends x{constructor(e,r){super();this.transport=e;this.options=r;this._maxMissCount=r.maxMissCount??5,this._setupEventListeners();}_timer;_pingCounter=0;_pongMissCount=0;_maxMissCount;_pendingPingValue;_subscribers=[];_destroyed=false;_setupEventListeners(){this._subscribers.push(this.transport.on("connect",()=>{this._destroyed||this._start();})),this._subscribers.push(this.transport.on("disconnect",()=>{this._destroyed||this._stop();})),this._subscribers.push(this.transport.on("error",()=>{this._destroyed||this._stop();})),this.transport.connected&&this._start();}onOperate(e){return this._destroyed?false:e.type==="$pong"?(this.onPong(e),true):e.type==="$ping"?(this.onPing(e),true):false}_start(){this.options.interval<=0||(this._stop(),this._pingCounter=0,this._pongMissCount=0,this._sendPing(),this._timer=setInterval(()=>{this._sendPing();},this.options.interval));}_stop(){this._timer&&(clearInterval(this._timer),this._timer=void 0),this._pingCounter=0,this._pongMissCount=0,this._pendingPingValue=void 0;}destroy(){this._destroyed=true,this._stop(),this.transport.removeReceiver("__heartbeat__"),this._subscribers.forEach(e=>e.off()),this._subscribers=[];}onPong(e){e.type==="$pong"&&this._pendingPingValue!==void 0&&e.value===this._pendingPingValue&&(this._pongMissCount=0,this._pendingPingValue=void 0);}onPing(e){this.transport.connected&&e.type==="$ping"&&this.transport.send({type:"$pong",value:e.value});}_sendPing(){if(!this._destroyed){if(this._pendingPingValue!==void 0&&(this._pongMissCount++,this._pongMissCount>=this._maxMissCount)){this._stop(),this.emit("timeout",void 0);return}this._pingCounter++,this._pendingPingValue=this._pingCounter;try{this.transport.send({type:"$ping",value:this._pingCounter});}catch{}}}};function L(s){if(typeof s!="object"||s===null)return false;let t=s;return "type"in t&&"value"in t&&"path"in t&&Array.isArray(t.path)}var v=class s extends x{receivers=new Map;stopCallbacks=new Map;connected=false;options={};static seq=0;id;heartbeat;constructor(t){super(),Object.assign(this.options,t),this.id=++s.seq,this.options.autoConnect===true&&this.connect();}addReceiver(t,e){return this.receivers.set(String(t),e),{off:()=>this.receivers.delete(String(t))}}removeReceiver(t){this.receivers.delete(String(t));}_send(t){if(!this.connected)throw new Error}connect(){if(this.connected)return;let t=this.onConnect();if(Lt(t))return t.then(()=>{this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();},e=>{throw this.emit("error",e),e});this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();}onConnect(){return true}onDisconnect(){}startHeartbeat(){this.options.heartbeat&&this.options.heartbeat>0&&(this.heartbeat&&this.stopHeartbeat(),this.heartbeat=new P(this,{interval:this.options.heartbeat}),this.heartbeat.on("timeout",()=>{this.disconnect(),this.emit("timeout",void 0);}));}stopHeartbeat(){this.heartbeat&&(this.heartbeat.destroy(),this.heartbeat=void 0);}_handlePing(t){return typeof t=="object"&&t.type==="$ping"?(this.connected&&this.send({type:"$pong",value:t.value}),true):false}onSendOperate(t){}onReceiveOperate(t){if(this._handlePing(t))return true;if(this.heartbeat&&this.heartbeat.onOperate(t)||!L(t))return false;for(let e of this.receivers.values())try{e(t);}catch{}return true}send(t){if(!this.connected)throw new Error("Transport is not connected");this.onSendOperate(t),this.options.debug&&this.emit("operate",t);}disconnect(){if(this.connected)try{this.onDisconnect();}finally{this.connected=false,this.stopHeartbeat(),this.clearRetained("connect"),this.emit("disconnect",void 0,true);}}};var M=class extends v{getPeer;_peer;constructor(t,e){super(e),this.getPeer=t;}get peer(){return this._peer||(this._peer=this.getPeer()),this._peer}onConnect(){return !!this.peer}onDisconnect(){}onSendOperate(t){if(!this.connected)throw new Error("LocalTransport \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");if(!this.peer)throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5BF9\u7AEF transport");this.peer.connected&&this.peer.onReceiveOperate(t);}};function ye(){return s=>{s.sync=function(t,e){let r=new M(()=>o),o=new M(()=>r),i=new A(t,{mode:"none",transport:o}),n=new A(s,Object.assign({mode:"both"},e,{transport:r}));return n.peer=i,n},s.clone=function(t){let{sync:e,entry:r=[]}=Object.assign({sync:"both"},this._options,t),o=f(this.getSnap(),r);if(typeof o!="object")throw new Error(`The clone path must be an object, but got ${typeof o}`);let i=Object.assign({},this._options,t);i.id===this.id&&(i.id=`${this.id}_clone`);let n=new s.constructor(o,i);return e!=="none"&&(n.peer=this.sync(n,{local:r,immediate:true,direction:e})),n};}}function ge(){globalThis.__AUTOSTORE_EXTENDS__||(globalThis.__AUTOSTORE_EXTENDS__=[]),globalThis.__AUTOSTORE_EXTENDS__.push(ye());}ge();var G=class extends v{messageHandler;onConnect(){let t=this.options.worker;return t?(this.messageHandler=e=>{this.onReceiveOperate(e.data);},t.addEventListener("message",this.messageHandler),true):(console.warn("[WorkerTransport] \u6CA1\u6709\u914D\u7F6E worker \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u5EFA\u7ACB\u8FDE\u63A5"),false)}onDisconnect(){let t=this.options.worker;t&&this.messageHandler&&(t.removeEventListener("message",this.messageHandler),this.messageHandler=void 0);}onSendOperate(t){let e=this.options.worker;if(!e){console.warn("[WorkerTransport] \u6CA1\u6709\u914D\u7F6E worker \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F\u3002\u8BF7\u5728\u5916\u90E8\u76F4\u63A5\u8C03\u7528 worker.postMessage(operate)");return}e.postMessage(t);}receiveRemoteOperate(t){return L(t.data)?(this.onReceiveOperate(t.data),true):false}};function rt(s){return s&&typeof s.port=="object"&&s.port!==null}var Mt=class extends A{worker;constructor(t,e,r={}){let o=rt(e)?e.port:e,i=new G({worker:o}),n={mode:"pull",immediate:true,direction:"both",...r,transport:i,onSend:p=>(n.peers&&n.peers.length>0&&(p.id=n.peers[0]),r.onSend?r.onSend.call(this,p):true)};super(t,n),this.worker=e,rt(e)&&typeof e.port.start=="function"&&e.port.start();}get actualWorker(){return rt(this.worker)?this.worker.port:this.worker}pull(){let t=this.options.peers&&this.options.peers.length>0?this.options.peers[0]:this.id;this.transport.send({id:t,type:"$pull",path:this.options.remote,value:void 0,flags:0});}};var N=class extends v{channel;messageHandler;constructor(t){super(t);}onConnect(){try{return this.channel=new BroadcastChannel(this.options.channelName),this.messageHandler=t=>{this.onReceiveOperate(t.data);},this.channel.addEventListener("message",this.messageHandler),!0}catch(t){return console.error("[BroadcastChannelTransport] \u521B\u5EFA BroadcastChannel \u5931\u8D25:",t),false}}onDisconnect(){this.channel&&(this.messageHandler&&(this.channel.removeEventListener("message",this.messageHandler),this.messageHandler=void 0),this.channel.close(),this.channel=void 0);}onSendOperate(t){if(!this.channel){console.warn("[BroadcastChannelTransport] BroadcastChannel \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");return}this.channel.postMessage(t);}};var Wt=class extends A{get transport(){return super.transport}constructor(t,e,r={}){let o=new N({channelName:e});super(t,{mode:"pull",immediate:true,direction:"both",...r,transport:o});}};var It=class extends O{_store;_options;transports=new Map;_transportCleanup=new WeakMap;_watcher;constructor(t,e){super(),this._store=t,this._options=Object.assign({autostart:true,heartbeat:3e3},e),this._options.autostart&&this.start();}get store(){return this._store}get options(){return this._options}addTransport(t){let e=t.id;if(this.transports.has(e))return;this.transports.set(e,t);let r=t.on("timeout",()=>{console.warn(`[AutoStoreBroadcaster] Client ${e} heartbeat timeout, removing transport`),this.removeTransport(e);});t.addReceiver(this._store.id,n=>{t.heartbeat&&t.heartbeat.onOperate(n)||this._onReceiveFromTransport(n,t);});let o=t.on("disconnect",()=>{this.removeTransport(e);}),i=t.on("error",n=>{this._emitError(n),this.removeTransport(e);});this._transportCleanup.set(t,()=>{r.off(),o.off(),i.off();}),this.options.heartbeat&&this.options.heartbeat>0&&(t.options.heartbeat=this.options.heartbeat,t.startHeartbeat());}removeTransport(t){let e=this.transports.get(t);if(e){let r=this._transportCleanup.get(e);r&&(r(),this._transportCleanup.delete(e)),e.connected&&e.disconnect(),e.stopHeartbeat(),this.transports.delete(t);}}broadcast(t){let e=t?.flags||0,r=e<0?-e:0,o={id:this._store.id,type:t.type,path:t.path,parentPath:t.parentPath,value:t.value,indexs:t.indexs,flags:0};this.transports.forEach(i=>{i.id!==r&&i.send(o);});}sendTo(t,e){let r=this.transports.get(t);r?.connected&&r.send(e);}_onReceiveFromTransport(t,e){t.type!=="$stop"&&(t.type==="$pull"?this._sendStoreToTransport(t,e):t.type==="$update"?this._applyStoreUpdate(t,e):this._applyOperate(t,e));}_applyOperate(t,e){let{type:r,value:o,indexs:i,path:n}=t;this._store.update(p=>{let a=n;if(r==="set"||r==="update")y(p,a,o);else if(r==="delete")y(p,a,void 0);else if(r==="insert"){let u=f(p,a);Array.isArray(u)&&i&&u.splice(i[0],0,...o);}else if(r==="remove"){let u=f(p,a);Array.isArray(i)&&(i.length===0?u.splice(0):u.splice(i[0],i.length));}},{flags:-e.id});}_applyStoreUpdate(t,e){this._store.update(r=>{Object.assign(r,t.value);},{flags:-e.id});}_sendStoreToTransport(t,e){let r=t.path.length===0?this._store.getSnap():V(f(this._store.state,t.path)),o={id:this._store.id,type:"$update",path:[],value:r,flags:0};e.send(o);}start(){if(this.syncing)return;let t;try{this._syncing=!0,this._watcher=this._store.watch(e=>{this.broadcast(e);},{operates:"write"});}catch(e){t=e,this._emitError(e);}finally{t?this._syncing=false:this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._watcher&&(this._watcher.off(),this._watcher=void 0);}finally{this.emit("stop",void 0,true),this._syncing=false;}}destroy(){this.stop(),this.transports.forEach(t=>{let e=this._transportCleanup.get(t);e&&e(),t.connected&&t.disconnect(),t.stopHeartbeat();}),this.transports.clear();}toString(){return `AutoStoreBroadcaster(${this._store.id}, clients: ${this.transports.size})`}};var Bt=class extends O{stores=new Map;_transportStoreIds=new WeakMap;_storeTransports=new Map;_watchers=new Map;_options;_transportCleanup=new WeakMap;constructor(t=[],e){super(),this._options=Object.assign({autostart:true},e),t.forEach(r=>this.add(r)),this._options.autostart&&t.length>0&&this.start();}add(t){let e=t.id;if(this.stores.has(e)){console.warn(`[AutoStoreSwitchSyncer] Store with id "${e}" already exists, skipping.`);return}this.stores.set(e,t),this._storeTransports.set(e,new Set),this.syncing&&this._startWatch(t);}remove(t){if(this.stores.get(t)){let r=this._watchers.get(t);r&&(r.off(),this._watchers.delete(t));let o=this._storeTransports.get(t);o&&o.forEach(i=>{let n=this._transportStoreIds.get(i);n&&n.delete(t);}),this.stores.delete(t),this._storeTransports.delete(t);}}_startWatch(t){let e=t.id,r=t.watch(o=>{try{let i=o?.flags||0,n=i<0?-i:0,p=this._storeTransports.get(e);if(!p||p.size===0)return;let a={id:e,type:o.type,path:o.path,parentPath:o.parentPath,value:o.value,indexs:o.indexs,flags:0};console.log(`[AutoStoreSwitchSyncer] \u51C6\u5907\u5E7F\u64AD (store: ${e}, sourceTransportId: ${n}, transports: ${Array.from(p.values()).map(u=>u.id).join(", ")})`),p.forEach(u=>{if(u.id===n){console.log(`[AutoStoreSwitchSyncer] \u8DF3\u8FC7\u6E90\u7AEF (transport id: ${u.id})`);return}console.log(`[AutoStoreSwitchSyncer] \u53D1\u9001\u5230 transport ${u.id}`),u.send(a);});}finally{this._options.debug&&this.emit("localOperate",o);}},{operates:"write"});this._watchers.set(e,r);}addTransport(t){let e=new Set;this._transportStoreIds.set(t,e);let r=()=>{this.stores.forEach((n,p)=>{e.add(p);let a=this._storeTransports.get(p);a&&a.add(t);});};t.connected?r():t.once("connect",r),t.addReceiver("switch-router",n=>{try{let p=n.id,a=this.stores.get(p);if(!a){console.warn(`[AutoStoreSwitchSyncer] No store found for id "${p}", dropping message.`);return}n.type==="$pull"?this._handlePull(n,t,a):n.type==="$update"?this._handleUpdate(n,t,a):this._handleOperate(n,t,a);}finally{this._options.debug&&this.emit("remoteOperate",n);}});let o=t.on("disconnect",()=>{let n=this._transportCleanup.get(t);n&&(n(),this._transportCleanup.delete(t)),e.forEach(p=>{let a=this._storeTransports.get(p);a&&a.delete(t);}),this._transportStoreIds.delete(t);}),i=t.on("error",n=>{this._emitError(n);let p=this._transportCleanup.get(t);p&&(p(),this._transportCleanup.delete(t)),e.forEach(a=>{let u=this._storeTransports.get(a);u&&u.delete(t);}),this._transportStoreIds.delete(t);});this._transportCleanup.set(t,()=>{o.off(),i.off();});}_handlePull(t,e,r){let o={id:r.id,type:"$update",path:[],value:r.getSnap(),flags:0};e.send(o);}_handleUpdate(t,e,r){r.update(o=>{Object.assign(o,t.value);},{flags:-e.id});}_handleOperate(t,e,r){let{type:o,value:i,indexs:n,path:p}=t;r.update(a=>{let u=p;if(o==="set"||o==="update")y(a,u,i);else if(o==="delete")y(a,u,void 0);else if(o==="insert"){let c=f(a,u);Array.isArray(c)&&n&&c.splice(n[0],0,...i);}else if(o==="remove"){let c=f(a,u);Array.isArray(n)&&(n.length===0?c.splice(0):c.splice(n[0],n.length));}},{flags:-e.id});}removeTransport(t){for(let[e,r]of this._storeTransports)r.forEach(o=>{if(o.id===t){let i=this._transportCleanup.get(o);i&&(i(),this._transportCleanup.delete(o)),r.delete(o);let n=this._transportStoreIds.get(o);n&&n.delete(e);}});}getStore(t){return this.stores.get(t)}getStoreIds(){return Array.from(this.stores.keys())}start(){if(this.syncing)return;let t;try{this._syncing=!0,this.stores.forEach(e=>{this._watchers.has(e.id)||this._startWatch(e);});}catch(e){t=e,this._emitError(e);}finally{t?this._syncing=false:this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._watchers.forEach(t=>{t.off();}),this._watchers.clear();}finally{this.emit("stop",void 0,true),this._syncing=false;}}destroy(){this._watchers.forEach(t=>{t.off();}),this._watchers.clear(),this._storeTransports.forEach(t=>{t.forEach(e=>{let r=this._transportCleanup.get(e);r&&r();});}),this.stores.clear(),this._storeTransports.clear(),this._transportStoreIds=new WeakMap,this._transportCleanup=new WeakMap;}toString(){return `AutoStoreSwitchSyncer(stores: [${Array.from(this.stores.keys()).join(", ")}], total: ${this.stores.size})`}};var Ft=class extends v{handleReceive;constructor(t){super(t),this.handleReceive=e=>{this.onReceiveOperate(e);};}onConnect(){return this.options.emitter.on(this.options.localEventName||"local-transport",this.handleReceive),true}onDisconnect(){this.options.emitter.off(this.options.localEventName||"local-transport",this.handleReceive);}onSendOperate(t){this.options.emitter.emit(this.options.remoteEventName||"remote-transport",t);}};exports.AutoStoreBroadcastChannelSyncer=Wt;exports.AutoStoreBroadcastSyncer=It;exports.AutoStoreSwitchSyncer=Bt;exports.AutoStoreSyncError=W;exports.AutoStoreSyncTransportBase=v;exports.AutoStoreSyncer=A;exports.AutoStoreSyncerBase=O;exports.AutoStoreWorkerSyncer=Mt;exports.BroadcastChannelTransport=N;exports.EventEmitterTransport=Ft;exports.LocalTransport=M;exports.SYNC_INIT_FLAG=et;exports.WorkerTransport=G;exports.installSyncerPlugin=ge;return exports;})({});//# sourceMappingURL=index.global.js.map | ||
| var AutoStoreSyncer=(function(exports){'use strict';var C=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var W=class extends Error{operate};function st(s,...t){if(t.length===0)return s;let e=t.map((r,o)=>{let i=Object.entries(r||{});return i.some(([n,p])=>p===void 0)?i.reduce((n,[p,a])=>(a!==void 0&&(n[p]=a),n),{}):r});return Object.assign(s,...e)}function I(s){return s!=null&&typeof s[Symbol.iterator]=="function"&&typeof s!="string"}function _(s){if(typeof s!="object"||s===null)return false;var t=Object.getPrototypeOf(s);if(t===null)return true;for(var e=t;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return t===e}function ot(s,t=false){if(typeof s=="number")return true;if(typeof s!="string"||t)return false;try{if(s.includes(".")){let e=parseFloat(s);return s.endsWith(".")?!isNaN(e)&&String(e).length===s.length-1:!isNaN(e)&&String(e).length===s.length}else {let e=parseInt(s);return !isNaN(e)&&String(e).length===s.length}}catch{return false}}function w(s){if(ot(s)||typeof s=="boolean"||typeof s=="function"||s instanceof Error)return false;if(s==null||s==null||Array.isArray(s)&&s.length==0||_(s)&&Object.keys(s).length==0||typeof s=="string"&&s.trim()=="")return true;try{if(I(s)&&s.size==0)return !0}catch{}return false}function it(s,{empty:t,delimiter:e=","}){let r=s;try{return typeof r=="function"&&(r=r.call(this,r)),w(r)&&(r=t||""),Array.isArray(r)?r.map(o=>String(o)).join(e):_(r)?Object.entries(r).reduce((o,[i,n])=>(o.push(`${i}=${String(n)}`),o),[]).join(e):I(r)&&typeof r!="string"?[...r].map(o=>String(o)).join(e):r instanceof Error?r.message:String(r)}catch{return String(r)}}var Ft=/\{(\<(.*?)\>)?\s*([^\{\}\>\<]*)(?<!\s)\s*(\<(.*?)\>)?\}/gm;function H(s,t,e){let r,o=st({empty:null,delimiter:",",forEach:null},e);typeof t=="function"&&(t=t.call(s)),Array.isArray(t)&&t.length==1&&(_(t[0])||Array.isArray(t[0]))&&(t=t[0]),["boolean","string","number"].includes(typeof t)?r=[t]:t instanceof Map?r=[...t.entries()].reduce((n,p)=>(n[p[0]]=p[1],n),{}):Symbol.iterator in t?r=[...t]:_(t)?r=t:t instanceof Error?r=[`Error:${t.message}`]:r=[t];let i=0;return s.replaceAll(Ft,function(){let n=arguments[2]||"",p=arguments[3]||"",a=arguments[5]||"",u="",c=false;if(Array.isArray(r)){let d=i>=r.length;u=d?"":it.call(s,r[i],o),c=w(u)||d,i++;}else if(_(r)){let d=p in r;u=d?it.call(s,r[p],o):"",c=w(u)||!d;}if(typeof o.forEach=="function"){let d=o.forEach(p,u,n,a);d!==void 0&&(Array.isArray(d)&&d.length==3?(n=d[0],u=d[1],a=d[2]):w(d)||(u=String(d)),c=w(u));}return c&&(o.empty==null?(u="",n="",a=""):u=o.empty),`${n}${u}${a}`})}function nt(s,...t){let e=s.valueOf(),r={},o=[...t];if(t.length>0&&_(t[t.length-1])){let i=t[t.length-1];("$delimiter"in i||"$empty"in i||"$forEach"in i)&&("$delimiter"in i&&(r.delimiter=i.$delimiter),"$empty"in i&&(r.empty=i.$empty),"$forEach"in i&&(r.forEach=i.$forEach),o.pop());}try{return o.length==1?H(e,o[0],r):H(e,[...o],r)}catch{return e}}String.prototype.params=function(){return nt(this,...arguments)};function kt(s,t,e){if(typeof t=="string"){let r=0,o;for(;(o=s.indexOf(t,r))>-1;){let i=typeof e=="function"?e(t):e,n=s.length;s=s.substring(0,o)+i+s.substring(o+t.length),r=o+i.length+s.length-n;}}else {let r;if(!t.global||!t.multiline)throw new Error("The search parameter must be enabled '/gm' option");for(;(r=t.exec(s))!==null;){r.index===t.lastIndex&&t.lastIndex++;let o=s.length,i=r[0].length,n=typeof e=="function"?e(r[0],...r):e;s=s.substring(0,r.index)+n+s.substring(r.index+i),t.lastIndex+=s.length-o;}}return s}String.prototype.replaceAll||(String.prototype.replaceAll=function(s,t){return kt(this,s,t)});(s=>typeof C<"u"?C:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof C<"u"?C:t)[e]}):s)(function(s){if(typeof C<"u")return C.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var B="__AS_SKIP_PROXY__";var K="__AS_ASYNC_COMPUTED_VALUE__";function $(s){try{return s[B]===!0}catch{}return false}function F(s){return toString.call(s)==="[object Map]"}function S(s){return s&&typeof s=="object"&&s.hasOwnProperty(K)}function Y(s,t){let e=s.get(t);if(e!==void 0)return e;let r=s.get(Number(t)||t);if(r!==void 0)return r}function f(s,t,e){if(!t||t.length===0)return s;let r=Array.isArray(t)?t:t.split("."),o,i=s;for(let n=0;n<r.length;n++){let p=r[n];if(F(i))o=Y(i,p);else if(p in i)o=i[p];else return e;i=o;}return o}function y(s,t,e,r){if(!t||!s)return s;let o=t;if(o.length===0)return typeof s=="object"&&Object.assign(s,e),s;{let i=s,n=[],p=(a,u,c)=>{a[u]=c;};for(let a=0;a<o.length;a++){let u=o[a];if(n.push(u),i)if(Array.isArray(i)){let c=parseInt(u,10);if(Number.isNaN(c)||c<0)throw new Error(`setVal: invalid array index ${n.join(".")}`);a===o.length-1?p(i,c,e):i=i[c];}else i instanceof Map||i instanceof WeakMap?a===o.length-1?i.set(u,e):(i.has(u)||i.set(u,{}),i=i.get(u)):typeof i=="object"&&u in i?a===o.length-1?p(i,u,e):i=i[u]:(i[u]=a===o.length-1?e:{},i=i[u]);else i[u]=a===o.length-1?e:{},i=i[u];}}return s}function T(s,t){function e(r,o){for(let i in r){let n=r[i];typeof t=="function"&&t({value:n,key:i,parent:r,path:o.concat(i)}),typeof n=="object"&&!$(n)&&e(n,o.concat(i));}}e(s,[]);}function k(s){return typeof s=="object"?JSON.parse(JSON.stringify(s)):s}function ct(s,t){return s.length>t.length?false:s.every((e,r)=>e===t[r])}function b(s){return s?typeof s=="function":false}function V(s,t){let{reserveAsync:e,includeFunc:r}=Object.assign({reserveAsync:false},t);if(Array.isArray(s)){let o=[...s];for(let i=0;i<o.length;i++)o[i]=V(o[i],t);return o}else if(typeof s=="object"){if(!e&&S(s))return s.value;{let o={...s};for(let i in o)o[i]=V(o[i],t);return o}}return r&&b(s)?`\`\`\`${s.toString()}\`\`\``:s}var gt=Object.defineProperty,Zt=(s,t,e)=>t in s?gt(s,t,{enumerable:true,configurable:true,writable:true,value:e}):s[t]=e,l=(s,t)=>gt(s,"name",{value:t,configurable:true}),g=(s,t,e)=>Zt(s,typeof t!="symbol"?t+"":t,e);var _t=class extends Error{constructor(t){super(t);}};l(_t,"FastEventError");var D=_t,te=class extends D{};l(te,"TimeoutError");var bt=class extends D{};l(bt,"UnboundError");var ee=bt,St=class extends D{};l(St,"AbortError");var yt=St,vt=class extends D{};l(vt,"CancelError");var re=vt,se=class extends D{};l(se,"QueueOverflowError");var Ot={clearRetain:Symbol.for("ClearRetain")},j=(function(s){return s[s.Transformed=1]="Transformed",s})({});function Z(s,t,e,r){let o,i={},n={};return typeof s[0]=="object"?(Object.assign(n,s[0]),i=typeof s[1]=="boolean"?{retain:s[1]}:s[1]||{},o=s[0].meta):(n.type=s[0],n.payload=s[1],i=typeof s[2]=="boolean"?{retain:s[2]}:s[2]||{}),o=Object.assign({},t,e,i.meta,o),Object.keys(o).length===0&&(o=void 0),n.meta=o,i.executor===void 0&&(i.executor=r),[n,i]}l(Z,"parseEmitArgs");function At(s){return s?typeof s=="object"&&"__FastEventScope__"in s:false}l(At,"isFastEventScope");function tt(s,t,e){let r=s[0],o=At(s[1])?s[1]:void 0,i=(o?s[2]:s[1])||{};return i.meta=Object.assign({},t,i?.meta),i.context=i.context!==void 0?i.context:e,[r,o,i]}l(tt,"parseScopeArgs");function G(s,t){return Object.defineProperty(s,"name",{value:t||"anonymous",configurable:true}),s}l(G,"renameFn");function h(s){return s&&typeof s=="function"}l(h,"isFunction");var xt=class Et{constructor(t){g(this,"__FastEventScope__",true),g(this,"_options",{}),g(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),g(this,"prefix",""),g(this,"emitter"),this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(t,e,r){this.emitter=t,this._options=Object.assign(this._options,{scope:e},r),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let r=this;return G(function(o,i){let n=i.rawEventType||o.type;if(n.startsWith(e)){let p=((i.flags||0)&j.Transformed)>0?o:Object.assign({},o,{type:n.substring(e.length)});return t.call(r.context,p,i)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new ee;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===Ot.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=Z(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){h(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|j.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let t=arguments[0],e=arguments[1],r=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},r,{type:this._fixScopeType(r.type)})}scope(){let[t,e,r]=tt(arguments,this.options.meta,this.options.context),o;return e?o=e:o=new Et,o.bind(this.emitter,this.prefix+t,r),o}onMessage(t,e){}};l(xt,"FastEventScope");var oe=xt;function Q(s,t){if(s.length!==t.length&&s.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:s.length-t.length+1}).fill("*"));for(let r=0;r<s.length;r++)if(e[r]!=="*"&&e[r]!==s[r])return false;return true}l(Q,"isPathMatched");function Ct(s,t){let e=[];for(;;){let r=s.findIndex(o=>t(o));if(r===-1){e.push(r);break}s.splice(r,1);}return e}l(Ct,"removeItem");var Rt=Symbol.for("__expandable__");function ie(s){return s[Rt]=true,s}l(ie,"expandable");function wt(s){return s&&s[Rt]}l(wt,"isExpandable");function Tt(s){for(let t=0;t<s.length;t++){let e=s[t];Array.isArray(e)&&wt(e)&&(s.splice(t,1,...e),t+=e.length-1);}return s}l(Tt,"expandEmitResults");function Vt(s){return s&&typeof s=="object"&&"off"in s&&"listener"in s}l(Vt,"isSubsctiber");function jt(s,t){return s.catch(e=>(t&&t(e),Promise.resolve(e)))}l(jt,"tryReturnError");var ne=class{constructor(t){g(this,"__FastEvent__",true),g(this,"listeners",{__listeners:[]}),g(this,"_options"),g(this,"_delimiter","/"),g(this,"_context"),g(this,"retainedMessages",new Map),g(this,"listenerCount",0),g(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,r){let{count:o,prepend:i}=r,n=0;return [this._forEachNodes(t,p=>{let a=[e,o,0,r.tag,r.flags];i?(p.__listeners.splice(0,0,a),n=0):(p.__listeners.push(a),n=p.__listeners.length-1),this.listenerCount++;}),n]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let r=this.listeners;for(let o=0;o<t.length;o++){let i=t[o];if(i in r||(r[i]={__listeners:[]}),o===t.length-1){let n=r[i];return e(n,r),n}else r=r[i];}}_removeListener(t,e,r){r&&Ct(t.__listeners,o=>{o=Array.isArray(o)?o[0]:o;let i=o===r;return i&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),r)),i});}_pipeListener(t,e){return e.forEach(r=>{t=G(r(t),t.name);}),t}on(){let t=arguments[0],e=h(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),r=Object.assign({count:0,flags:0,prepend:false},h(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(h(this._options.onAddListener)){let a=this._options.onAddListener(t,e,r);if(a===false)throw new re;if(Vt(a))return a}let o=t.split(this._delimiter);if(r.pipes&&r.pipes.length>0&&(e=this._pipeListener(e,r.pipes)),h(r.filter)||h(r.off)){let a=e;e=G(function(u,c){if(h(r.off)&&r.off.call(this,u,c)){p();return}if(h(r.filter)){if(r.filter.call(this,u,c))return a.call(this,u,c)}else return a.call(this,u,c)},e.name);}let[i,n]=this._addListener(o,e,r),p=l(()=>i&&this._removeListener(i,o,e),"off");return this._emitRetainMessage(t,i,n),{off:p,listener:e}}once(){return h(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=h(t[0])?void 0:t[0],r=h(t[0])?t[0]:t[1],o=e?e.split(this._delimiter):[],i=e?e.includes("*"):false;if(e&&!i)this._traverseToPath(this.listeners,o,n=>{r?this._removeListener(n,o,r):e&&(n.__listeners=[]);});else {let n=i?[]:o;this._traverseListeners(this.listeners,n,(p,a)=>{(r!==void 0||i&&Q(p,o))&&(r?this._removeListener(a,o,r):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),r=0;this._traverseListeners(this.listeners,e,(o,i)=>{r+=i.__listeners.length,i.__listeners=[];}),this.listenerCount-=r,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(r,o)=>{e+=o.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,r){let o=[];if(t.includes("*")){let i=t.split(this._delimiter);this.retainedMessages.forEach((n,p)=>{let a=p.split(this._delimiter);Q(a,i)&&o.push(n);});}else this.retainedMessages.has(t)&&o.push(this.retainedMessages.get(t));e&&o.forEach(i=>{this._executeListeners([e],i,{},n=>n[0]===e.__listeners[r][0]);});}_traverseToPath(t,e,r,o=0,i){if(o>=e.length){r(t);return}let n=e[o];if(i===true){this._traverseToPath(t,e,r,o+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,r,o+1),"**"in t&&this._traverseToPath(t["**"],e,r,o+1,true),n in t&&this._traverseToPath(t[n],e,r,o+1);}_traverseListeners(t,e,r){let o=t;e&&e.length>0&&this._traverseToPath(t,e,n=>{o=n;});let i=l((n,p,a)=>{p(a,n);for(let[u,c]of Object.entries(n))u.startsWith("__")||c&&i(c,p,[...a,u]);},"traverseNodes");i(o,r,[]);}_onListenerError(t,e,r,o){if(o instanceof Error&&(o._emitter=`${t.name||"anonymous"}:${e.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,o,t,e,r);}catch{}if(this._options.ignoreErrors)return o;throw o}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,r,o=false){try{if(r&&r.abortSignal&&r.abortSignal.aborted)return this._onListenerError(t,e,r,new yt(t.name));let i=((r?.flags||0)&j.Transformed)>0,n=t.call(this.context,i?e.payload:e,r);return o&&n&&n instanceof Promise&&(n=jt(n,p=>this._onListenerError(t,e,r,p))),n}catch(i){return this._onListenerError(t,e,r,i)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(h(e))return e}_executeListeners(t,e,r,o){if(!t||t.length===0)return [];let i=t.reduce((p,a)=>p.concat(a.__listeners.filter(u=>h(o)?o(u,a):true).map((u,c)=>[u,c,a.__listeners])),[]);h(this._options.transform)&&(r||(r={}),r.rawEventType=e.type,e.payload=this._options.transform.call(this,e),r.flags=this._setListenerFlags(r.flags,j.Transformed)),this._decListenerExecCount(i);let n=this._getListenerExecutor(r);if(n){let p=n(i.map(a=>a[0]),e,r,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return i.map(p=>this._executeListener(p[0][0],e,r,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let r=t[e][0];r[2]++,r[1]>0&&r[1]<=r[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],r=t.split(this._delimiter);return this._traverseToPath(this.listeners,r,o=>{e.push(o);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===Ot.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=Z(arguments,this.options.meta);h(e.parseArgs)&&e.parseArgs(t,e);let r=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let o=[],i=[];if(this._traverseToPath(this.listeners,r,n=>{i.push(n);}),h(this._options.onBeforeExecuteListener)){let n=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(n))return n;if(n===false)throw new yt(t.type)}return h(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|j.Transformed),o.push(...this._executeListeners(i,t,e)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,o,i),this._options.expandEmitResults&&Tt(o),o}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((r,o)=>{let i,n,p=l(a=>{clearTimeout(i),n&&n.off(),r(a);},"listener");e&&e>0&&(i=setTimeout(()=>{n&&n.off(),o(new Error("wait for event<"+t+"> is timeout"));},e)),n=this.on(t,p);})}scope(){let[t,e,r]=tt(arguments,this.options.meta,this.options.context),o;return e?o=e:o=new oe,o.bind(this,t,r),o}};l(ne,"FastEvent");function ae(s){return s?typeof s=="object"&&"type"in s:false}l(ae,"isFastEventMessage");function pe(s){return s&&typeof s=="string"}l(pe,"isString");function ue(s){return typeof s=="function"&&(s.toString().startsWith("class ")||s.prototype?.constructor===s)}l(ue,"isClass");function ce(s){return s?typeof s=="object"&&"__FastEvent__"in s:false}l(ce,"isFastEvent");function Pt(s){return {all:s=s||new Map,on:function(t,e){var r=s.get(t);r?r.push(e):s.set(t,[e]);},off:function(t,e){var r=s.get(t);r&&(e?r.splice(r.indexOf(e)>>>0,1):s.set(t,[]));},emit:function(t,e){var r=s.get(t);r&&r.slice().map(function(o){o(e);}),(r=s.get("*"))&&r.slice().map(function(o){o(t,e);});}}}var E=class{#t;#e;constructor(){this.#t=Pt(),this.#e=new Map;}on(t,e){return this.#e.has(t)&&e(this.#e.get(t)),this.#t.on(t,e),{off:()=>this.#t.off(t,e)}}once(t,e){if(this.#e.has(t))return e(this.#e.get(t)),{off:()=>{}};let r=o=>{e(o),this.#t.off(t,r);};return this.#t.on(t,r),{off:()=>this.#t.off(t,r)}}off(t,e){this.#t.off(t,e);}emit(t,e,r=false){if(arguments.length===1){this.#e.delete(t);return}let o=e;r&&this.#e.set(t,o),this.#t.emit(t,o);}async wait(t,e){return new Promise((r,o)=>{let i=this.once(t,p=>{n!==void 0&&clearTimeout(n),r(p);}),n;e&&e>0&&(n=setTimeout(()=>{i.off(),o(new Error(`\u7B49\u5F85\u4E8B\u4EF6 "${String(t)}" \u8D85\u65F6 (${e}ms)`));},e));})}onAny(t){return this.#t.on("*",t),{off:()=>this.#t.off("*",t)}}clear(){this.#t.all.clear(),this.#e.clear();}clearRetained(t){this.#e.delete(t);}getRetained(t){return this.#e.get(t)}get listeners(){return this.#t.all}};var A=class extends E{static seq=99;_syncing=false;get syncing(){return this._syncing}_emitError(t){this.emit("error",t,true);}push(t){throw new Error(`${this.constructor.name} does not support push() operation. Please use a syncer that implements this method, or override it in a subclass.`)}pull(){throw new Error(`${this.constructor.name} does not support pull() operation. Please use a syncer that implements this method, or override it in a subclass.`)}};var et=-1,x=class s extends A{constructor(e,r){super();this.store=e;this._options=Object.assign({id:e.id,mode:"push",local:[],remote:[],autostart:true,maxCacheSize:100,direction:"both",pathMap:{},peers:["*"],debug:false},r),typeof this._options.local=="string"&&(this._options.local=this._options.local.split(".")),typeof this._options.remote=="string"&&(this._options.remote=this._options.remote.split(".")),this.seq=++s.seq,this._options.autostart&&this.start();}seq;_options;peer;_operateCache=[];_subscribers=[];get id(){return this._options.id}get options(){return this._options}get transport(){return this._options.transport}get localEntry(){return this._options.local}get remoteEntry(){return this._options.remote}_onConnect(){try{let e=this.options.direction,r=this.options.mode;(r==="push"||r=="both")&&this._pushStore(!0),(r==="pull"||r=="both")&&this._pullStore(!0),e==="forward"&&(this._syncing=!0);}finally{this.flush();}}createRemoteOperate(e){return {id:this.id,type:e.type,path:e.path,parentPath:e.parentPath,value:k(e.value),indexs:e.indexs,flags:e.flags??0}}isPeer(e){let r=this._options.peers;return r.includes("*")?true:r.includes(e.id)}start(){if(this.syncing)return;let e;try{this._syncing=!0,this._subscribers.push(this.store.watch(this._onWatchStore.bind(this),{operates:"write"})),this._subscribers.push(this.transport.addReceiver(this.id,r=>{r.id!==this.id&&(!r.type.startsWith("$")&&(this.options.direction==="forward"||!this.isPeer(r))||this._onReceiveFromRemote(r));})),this._subscribers.push(this.transport.on("connect",this._onConnect.bind(this))),this._subscribers.push(this.transport.on("disconnect",this.stop.bind(this))),this._subscribers.push(this.transport.on("error",this.stop.bind(this))),this._subscribers.push(this.transport.on("timeout",this.stop.bind(this))),this.transport.connect();}catch(r){throw e=r,this.stop(),this.emit("error",r,true),r}finally{e||this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._subscribers.forEach(e=>e.off()),this._options.transport.connected&&this._options.transport.send({id:this.id,type:"$stop",path:[],value:void 0,flags:0});}finally{this.emit("stop",void 0,true),this._syncing=false;}}_onWatchStore(e){try{if(this._isPass(e.path,e.value)===!1||Math.abs(e.flags||0)===this.seq||this.options.direction==="backward")return;this._sendToRemote(e);}finally{this.options.debug===true&&this.emit("localOperate",e);}}_isPass(e,r){return b(this._options.filter)?this._options.filter(e,r):true}_sendToRemote(e){let r=this.options.local,o=this.options.remote;if(!ct(this._options.local,e.path))return;if(typeof this._options.pathMap.toRemote=="function"){let n=this._options.pathMap.toRemote(e.path.slice(this._options.local.length),e.value);n&&(e.path=[...o,...n]);}else e.path=[...o,...e.path.slice(r.length)];let i=this.createRemoteOperate(e);this._sendOperate(i);}_onReceiveFromRemote(e){try{if(typeof this._options.onReceive=="function"&&this._options.onReceive.call(this,e)===!1)return;let r=e.type;if(r==="$stop")this.stop();else if(r==="$push")this._updateStore(e);else if(r==="$pull")this._sendStore(e);else if(r==="$update")this._updateStore(e);else if(r==="$ping")this._sendOperate({type:"$pong",value:e.value});else if(r==="$error"){let o=new W;o.operate=e,this.emit("error",o);}else this._applyOperate(e);}finally{this.options.debug===true&&this.emit("remoteOperate",e);}}_applyOperate(e){let{type:r,value:o,indexs:i}=e,n=this.store,p=this._mapPath(e.path,e.value,"toLocal");if(!p)return;e.path=p;let a=[...this.localEntry,...e.path.slice(this.options.remote.length)],u={flags:-this.seq};r==="set"||r==="update"?n.update(c=>{S(f(c,a,true))?y(c,a.concat("value"),o):y(c,a,o);},u):r==="delete"?n.update(c=>{y(c,a,void 0);},u):r==="insert"?n.update(c=>{let d=f(c,a);Array.isArray(i)&&d.splice(i[0],0,...o);},u):r==="remove"&&n.update(c=>{let d=f(c,a);Array.isArray(i)&&(i.length===0?d.splice(0):d.splice(i[0],i.length));},u);}flush(){this.transport.connected&&Promise.all(this._operateCache.map(e=>this.transport.send(e))).finally(()=>{this._operateCache=[];});}_assertConnected(e){return this.transport.connected?true:(this._operateCache.push(e),this._operateCache.length>this._options.maxCacheSize&&this._operateCache.shift(),false)}_sendOperate(e){if(this._assertConnected(e)){if(typeof this._options.onSend=="function"&&this._options.onSend.call(this,e)===false)return;this._options.transport.send(e);}}_getLocalSnap(){return this.store.getSnap({entry:this._options.local.join(".")})}push(){this._pushStore();}_pushStore(e=false){let r=this._getLocalSnap();if(typeof this._options.pathMap.toRemote=="function"){let o=new Map;return T(r,({value:i,path:n})=>{if(this._isPass(n,i)===false)return;let p=Array.isArray(i)?[]:typeof i=="object"?{}:i,a=this._mapPath(n,p,"toRemote");if(a){o.set(JSON.stringify(n),JSON.stringify(a));let u={type:"set",path:[...this.options.remote,...a],value:p};e&&(u.flags=et),this._sendOperate(u);}}),o}else this._sendOperate({id:this.id,type:"$push",path:this.options.remote,value:r,flags:e?et:0});}_sendStore(e){this._sendOperate({id:this.id,type:"$update",path:[],value:this.store.getSnap({entry:e.path.join(".")}),flags:this.seq});}_updateStore(e){try{let o=this.store,i=-this.seq;if(typeof this._options.pathMap.toLocal=="function")T(e.value,({value:n,path:p})=>{if(this._isPass(p,n)===!1)return;let a=Array.isArray(n)?[]:typeof n=="object"?{}:n,u=this._mapPath(p,a,"toLocal");u&&o.update(c=>{y(c,[...this.localEntry,...u],a);},{flags:i});});else {let n=[...this.localEntry,...e.path||[]];o.update(p=>{y(p,n,e.value);},{flags:i});}}catch(o){this.emit("error",o);}finally{this._syncing===false&&(this._syncing=true,this.emit("syncing",e.id,true));}}_pullStore(e=false){this._sendOperate({id:this.id,type:"$pull",path:this.options.remote,value:void 0,flags:e?et:0});}pull(){this._pullStore();}_mapPath(e,r,o){return this._options.pathMap&&b(this._options.pathMap[o])?this._options.pathMap[o](e,r):e}toString(){return `AutoStoreSyncer(${this.id})`}};function Lt(s){return !!s&&typeof s=="object"&&typeof s.then=="function"}var P=class extends E{constructor(e,r){super();this.transport=e;this.options=r;this._maxMissCount=r.maxMissCount??5,this._setupEventListeners();}_timer;_pingCounter=0;_pongMissCount=0;_maxMissCount;_pendingPingValue;_subscribers=[];_destroyed=false;_setupEventListeners(){this._subscribers.push(this.transport.on("connect",()=>{this._destroyed||this._start();})),this._subscribers.push(this.transport.on("disconnect",()=>{this._destroyed||this._stop();})),this._subscribers.push(this.transport.on("error",()=>{this._destroyed||this._stop();})),this.transport.connected&&this._start();}onOperate(e){return this._destroyed?false:e.type==="$pong"?(this.onPong(e),true):e.type==="$ping"?(this.onPing(e),true):false}_start(){this.options.interval<=0||(this._stop(),this._pingCounter=0,this._pongMissCount=0,this._sendPing(),this._timer=setInterval(()=>{this._sendPing();},this.options.interval));}_stop(){this._timer&&(clearInterval(this._timer),this._timer=void 0),this._pingCounter=0,this._pongMissCount=0,this._pendingPingValue=void 0;}destroy(){this._destroyed=true,this._stop(),this.transport.removeReceiver("__heartbeat__"),this._subscribers.forEach(e=>e.off()),this._subscribers=[];}onPong(e){e.type==="$pong"&&this._pendingPingValue!==void 0&&e.value===this._pendingPingValue&&(this._pongMissCount=0,this._pendingPingValue=void 0);}onPing(e){this.transport.connected&&e.type==="$ping"&&this.transport.send({type:"$pong",value:e.value});}_sendPing(){if(!this._destroyed){if(this._pendingPingValue!==void 0&&(this._pongMissCount++,this._pongMissCount>=this._maxMissCount)){this._stop(),this.emit("timeout",void 0);return}this._pingCounter++,this._pendingPingValue=this._pingCounter;try{this.transport.send({type:"$ping",value:this._pingCounter});}catch{}}}};function L(s){if(typeof s!="object"||s===null)return false;let t=s;return "type"in t&&"value"in t&&"path"in t&&Array.isArray(t.path)}var v=class s extends E{receivers=new Map;stopCallbacks=new Map;connected=false;options={};static seq=0;id;heartbeat;constructor(t){super(),Object.assign(this.options,t),this.id=++s.seq,this.options.autoConnect===true&&this.connect();}addReceiver(t,e){return this.receivers.set(String(t),e),{off:()=>this.receivers.delete(String(t))}}removeReceiver(t){this.receivers.delete(String(t));}_send(t){if(!this.connected)throw new Error}connect(){if(this.connected)return;let t=this.onConnect();if(Lt(t))return t.then(()=>{this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();},e=>{throw this.emit("error",e),e});this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();}onConnect(){return true}onDisconnect(){}startHeartbeat(){this.options.heartbeat&&this.options.heartbeat>0&&(this.heartbeat&&this.stopHeartbeat(),this.heartbeat=new P(this,{interval:this.options.heartbeat}),this.heartbeat.on("timeout",()=>{this.disconnect(),this.emit("timeout",void 0);}));}stopHeartbeat(){this.heartbeat&&(this.heartbeat.destroy(),this.heartbeat=void 0);}_handlePing(t){return typeof t=="object"&&t.type==="$ping"?(this.connected&&this.send({type:"$pong",value:t.value}),true):false}onSendOperate(t){}onReceiveOperate(t){if(this._handlePing(t))return true;if(this.heartbeat&&this.heartbeat.onOperate(t)||!L(t))return false;for(let e of this.receivers.values())try{e(t);}catch{}return true}send(t){if(!this.connected)throw new Error("Transport is not connected");this.onSendOperate(t),this.options.debug&&this.emit("operate",t);}disconnect(){if(this.connected)try{this.onDisconnect();}finally{this.connected=false,this.stopHeartbeat(),this.clearRetained("connect"),this.emit("disconnect",void 0,true);}}};var M=class extends v{getPeer;_peer;constructor(t,e){super(e),this.getPeer=t;}get peer(){return this._peer||(this._peer=this.getPeer()),this._peer}onConnect(){return !!this.peer}onDisconnect(){}onSendOperate(t){if(!this.connected)throw new Error("LocalTransport \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");if(!this.peer)throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5BF9\u7AEF transport");this.peer.connected&&this.peer.onReceiveOperate(t);}};function ye(){return s=>{s.sync=function(t,e){let r=new M(()=>o),o=new M(()=>r),i=new x(t,{mode:"none",transport:o}),n=new x(s,Object.assign({mode:"both"},e,{transport:r}));return n.peer=i,n},s.clone=function(t){let{sync:e,entry:r=[]}=Object.assign({sync:"both"},this._options,t),o=f(this.getSnap(),r);if(typeof o!="object")throw new Error(`The clone path must be an object, but got ${typeof o}`);let i=Object.assign({},this._options,t);i.id===this.id&&(i.id=`${this.id}_clone`);let n=new s.constructor(o,i);return e!=="none"&&(n.peer=this.sync(n,{local:r,immediate:true,direction:e})),n};}}function ge(){globalThis.__AUTOSTORE_EXTENDS__||(globalThis.__AUTOSTORE_EXTENDS__=[]),globalThis.__AUTOSTORE_EXTENDS__.push(ye());}ge();var N=class extends v{messageHandler;onConnect(){let t=this.options.worker;return t?(this.messageHandler=e=>{this.onReceiveOperate(e.data);},t.addEventListener("message",this.messageHandler),true):(console.warn("[WorkerTransport] \u6CA1\u6709\u914D\u7F6E worker \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u5EFA\u7ACB\u8FDE\u63A5"),false)}onDisconnect(){let t=this.options.worker;t&&this.messageHandler&&(t.removeEventListener("message",this.messageHandler),this.messageHandler=void 0);}onSendOperate(t){let e=this.options.worker;if(!e){console.warn("[WorkerTransport] \u6CA1\u6709\u914D\u7F6E worker \u5B9E\u4F8B\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F\u3002\u8BF7\u5728\u5916\u90E8\u76F4\u63A5\u8C03\u7528 worker.postMessage(operate)");return}e.postMessage(t);}receiveRemoteOperate(t){return L(t.data)?(this.onReceiveOperate(t.data),true):false}};function rt(s){return s&&typeof s.port=="object"&&s.port!==null}var Mt=class extends x{worker;constructor(t,e,r={}){let o=rt(e)?e.port:e,i=new N({worker:o}),n={mode:"pull",immediate:true,direction:"both",...r,transport:i,onSend:p=>(n.peers&&n.peers.length>0&&(p.id=n.peers[0]),r.onSend?r.onSend.call(this,p):true)};super(t,n),this.worker=e,rt(e)&&typeof e.port.start=="function"&&e.port.start();}get actualWorker(){return rt(this.worker)?this.worker.port:this.worker}pull(){let t=this.options.peers&&this.options.peers.length>0?this.options.peers[0]:this.id;this.transport.send({id:t,type:"$pull",path:this.options.remote,value:void 0,flags:0});}};var U=class extends v{channel;messageHandler;constructor(t){super(t);}onConnect(){try{return this.channel=new BroadcastChannel(this.options.channelName),this.messageHandler=t=>{this.onReceiveOperate(t.data);},this.channel.addEventListener("message",this.messageHandler),!0}catch(t){return console.error("[BroadcastChannelTransport] \u521B\u5EFA BroadcastChannel \u5931\u8D25:",t),false}}onDisconnect(){this.channel&&(this.messageHandler&&(this.channel.removeEventListener("message",this.messageHandler),this.messageHandler=void 0),this.channel.close(),this.channel=void 0);}onSendOperate(t){if(!this.channel){console.warn("[BroadcastChannelTransport] BroadcastChannel \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");return}this.channel.postMessage(t);}};var Wt=class extends x{get transport(){return super.transport}constructor(t,e,r={}){let o=new U({channelName:e});super(t,{mode:"pull",immediate:true,direction:"both",...r,transport:o});}};var It=class extends A{_store;_options;transports=new Map;_transportCleanup=new WeakMap;_watcher;constructor(t,e){super(),this._store=t,this._options=Object.assign({autostart:true,heartbeat:3e3},e),this._options.autostart&&this.start();}get store(){return this._store}get options(){return this._options}addTransport(t){let e=t.id;if(this.transports.has(e))return;this.transports.set(e,t);let r=t.on("timeout",()=>{console.warn(`[AutoStoreBroadcaster] Client ${e} heartbeat timeout, removing transport`),this.removeTransport(e);});t.addReceiver(this._store.id,n=>{t.heartbeat&&t.heartbeat.onOperate(n)||this._onReceiveFromTransport(n,t);});let o=t.on("disconnect",()=>{this.removeTransport(e);}),i=t.on("error",n=>{this._emitError(n),this.removeTransport(e);});this._transportCleanup.set(t,()=>{r.off(),o.off(),i.off();}),this.options.heartbeat&&this.options.heartbeat>0&&(t.options.heartbeat=this.options.heartbeat,t.startHeartbeat());}removeTransport(t){let e=this.transports.get(t);if(e){let r=this._transportCleanup.get(e);r&&(r(),this._transportCleanup.delete(e)),e.connected&&e.disconnect(),e.stopHeartbeat(),this.transports.delete(t);}}broadcast(t){let e=t?.flags||0,r=e<0?-e:0,o={id:this._store.id,type:t.type,path:t.path,parentPath:t.parentPath,value:t.value,indexs:t.indexs,flags:0};this.transports.forEach(i=>{i.id!==r&&i.send(o);});}sendTo(t,e){let r=this.transports.get(t);r?.connected&&r.send(e);}_onReceiveFromTransport(t,e){t.type!=="$stop"&&(t.type==="$pull"?this._sendStoreToTransport(t,e):t.type==="$update"?this._applyStoreUpdate(t,e):this._applyOperate(t,e));}_applyOperate(t,e){let{type:r,value:o,indexs:i,path:n}=t;this._store.update(p=>{let a=n;if(r==="set"||r==="update")y(p,a,o);else if(r==="delete")y(p,a,void 0);else if(r==="insert"){let u=f(p,a);Array.isArray(u)&&i&&u.splice(i[0],0,...o);}else if(r==="remove"){let u=f(p,a);Array.isArray(i)&&(i.length===0?u.splice(0):u.splice(i[0],i.length));}},{flags:-e.id});}_applyStoreUpdate(t,e){this._store.update(r=>{Object.assign(r,t.value);},{flags:-e.id});}_sendStoreToTransport(t,e){let r=t.path.length===0?this._store.getSnap():V(f(this._store.state,t.path)),o={id:this._store.id,type:"$update",path:[],value:r,flags:0};e.send(o);}start(){if(this.syncing)return;let t;try{this._syncing=!0,this._watcher=this._store.watch(e=>{this.broadcast(e);},{operates:"write"});}catch(e){t=e,this._emitError(e);}finally{t?this._syncing=false:this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._watcher&&(this._watcher.off(),this._watcher=void 0);}finally{this.emit("stop",void 0,true),this._syncing=false;}}destroy(){this.stop(),this.transports.forEach(t=>{let e=this._transportCleanup.get(t);e&&e(),t.connected&&t.disconnect(),t.stopHeartbeat();}),this.transports.clear();}toString(){return `AutoStoreBroadcaster(${this._store.id}, clients: ${this.transports.size})`}};var Bt=class extends A{stores=new Map;_transportStoreIds=new WeakMap;_storeTransports=new Map;_watchers=new Map;_options;_transportCleanup=new WeakMap;constructor(t=[],e){super(),this._options=Object.assign({autostart:true},e),t.forEach(r=>this.add(r)),this._options.autostart&&t.length>0&&this.start();}add(t){let e=t.id;if(this.stores.has(e)){console.warn(`[AutoStoreSwitchSyncer] Store with id "${e}" already exists, skipping.`);return}this.stores.set(e,t),this._storeTransports.set(e,new Set),this.syncing&&this._startWatch(t);}remove(t){if(this.stores.get(t)){let r=this._watchers.get(t);r&&(r.off(),this._watchers.delete(t));let o=this._storeTransports.get(t);o&&o.forEach(i=>{let n=this._transportStoreIds.get(i);n&&n.delete(t);}),this.stores.delete(t),this._storeTransports.delete(t);}}_startWatch(t){let e=t.id,r=t.watch(o=>{try{let i=o?.flags||0,n=i<0?-i:0,p=this._storeTransports.get(e);if(!p||p.size===0)return;let a={id:e,type:o.type,path:o.path,parentPath:o.parentPath,value:o.value,indexs:o.indexs,flags:0};console.log(`[AutoStoreSwitchSyncer] \u51C6\u5907\u5E7F\u64AD (store: ${e}, sourceTransportId: ${n}, transports: ${Array.from(p.values()).map(u=>u.id).join(", ")})`),p.forEach(u=>{if(u.id===n){console.log(`[AutoStoreSwitchSyncer] \u8DF3\u8FC7\u6E90\u7AEF (transport id: ${u.id})`);return}console.log(`[AutoStoreSwitchSyncer] \u53D1\u9001\u5230 transport ${u.id}`),u.send(a);});}finally{this._options.debug&&this.emit("localOperate",o);}},{operates:"write"});this._watchers.set(e,r);}addTransport(t){let e=new Set;this._transportStoreIds.set(t,e);let r=()=>{this.stores.forEach((n,p)=>{e.add(p);let a=this._storeTransports.get(p);a&&a.add(t);});};t.connected?r():t.once("connect",r),t.addReceiver("switch-router",n=>{try{let p=n.id,a=this.stores.get(p);if(!a){console.warn(`[AutoStoreSwitchSyncer] No store found for id "${p}", dropping message.`);return}n.type==="$pull"?this._handlePull(n,t,a):n.type==="$update"?this._handleUpdate(n,t,a):this._handleOperate(n,t,a);}finally{this._options.debug&&this.emit("remoteOperate",n);}});let o=t.on("disconnect",()=>{let n=this._transportCleanup.get(t);n&&(n(),this._transportCleanup.delete(t)),e.forEach(p=>{let a=this._storeTransports.get(p);a&&a.delete(t);}),this._transportStoreIds.delete(t);}),i=t.on("error",n=>{this._emitError(n);let p=this._transportCleanup.get(t);p&&(p(),this._transportCleanup.delete(t)),e.forEach(a=>{let u=this._storeTransports.get(a);u&&u.delete(t);}),this._transportStoreIds.delete(t);});this._transportCleanup.set(t,()=>{o.off(),i.off();});}_handlePull(t,e,r){let o={id:r.id,type:"$update",path:[],value:r.getSnap(),flags:0};e.send(o);}_handleUpdate(t,e,r){r.update(o=>{Object.assign(o,t.value);},{flags:-e.id});}_handleOperate(t,e,r){let{type:o,value:i,indexs:n,path:p}=t;r.update(a=>{let u=p;if(o==="set"||o==="update")y(a,u,i);else if(o==="delete")y(a,u,void 0);else if(o==="insert"){let c=f(a,u);Array.isArray(c)&&n&&c.splice(n[0],0,...i);}else if(o==="remove"){let c=f(a,u);Array.isArray(n)&&(n.length===0?c.splice(0):c.splice(n[0],n.length));}},{flags:-e.id});}removeTransport(t){for(let[e,r]of this._storeTransports)r.forEach(o=>{if(o.id===t){let i=this._transportCleanup.get(o);i&&(i(),this._transportCleanup.delete(o)),r.delete(o);let n=this._transportStoreIds.get(o);n&&n.delete(e);}});}getStore(t){return this.stores.get(t)}getStoreIds(){return Array.from(this.stores.keys())}start(){if(this.syncing)return;let t;try{this._syncing=!0,this.stores.forEach(e=>{this._watchers.has(e.id)||this._startWatch(e);});}catch(e){t=e,this._emitError(e);}finally{t?this._syncing=false:this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._watchers.forEach(t=>{t.off();}),this._watchers.clear();}finally{this.emit("stop",void 0,true),this._syncing=false;}}destroy(){this._watchers.forEach(t=>{t.off();}),this._watchers.clear(),this._storeTransports.forEach(t=>{t.forEach(e=>{let r=this._transportCleanup.get(e);r&&r();});}),this.stores.clear(),this._storeTransports.clear(),this._transportStoreIds=new WeakMap,this._transportCleanup=new WeakMap;}toString(){return `AutoStoreSwitchSyncer(stores: [${Array.from(this.stores.keys()).join(", ")}], total: ${this.stores.size})`}};var $t=class extends v{handleReceive;constructor(t){super(t),this.handleReceive=e=>{this.onReceiveOperate(e);};}onConnect(){return this.options.emitter.on(this.options.localEventName||"local-transport",this.handleReceive),true}onDisconnect(){this.options.emitter.off(this.options.localEventName||"local-transport",this.handleReceive);}onSendOperate(t){this.options.emitter.emit(this.options.remoteEventName||"remote-transport",t);}};exports.AutoStoreBroadcastChannelSyncer=Wt;exports.AutoStoreBroadcastSyncer=It;exports.AutoStoreSwitchSyncer=Bt;exports.AutoStoreSyncError=W;exports.AutoStoreSyncTransportBase=v;exports.AutoStoreSyncer=x;exports.AutoStoreSyncerBase=A;exports.AutoStoreWorkerSyncer=Mt;exports.BroadcastChannelTransport=U;exports.EventEmitterTransport=$t;exports.LocalTransport=M;exports.SYNC_INIT_FLAG=et;exports.WorkerTransport=N;exports.installSyncerPlugin=ge;return exports;})({});//# sourceMappingURL=index.global.js.map | ||
| //# sourceMappingURL=index.global.js.map |
@@ -1,2 +0,2 @@ | ||
| var AutoStoreSyncer=(function(exports){'use strict';var x=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var j=class extends Error{operate};function J(r){return {all:r=r||new Map,on:function(t,e){var s=r.get(t);s?s.push(e):r.set(t,[e]);},off:function(t,e){var s=r.get(t);s&&(e?s.splice(s.indexOf(e)>>>0,1):r.set(t,[]));},emit:function(t,e){var s=r.get(t);s&&s.slice().map(function(i){i(e);}),(s=r.get("*"))&&s.slice().map(function(i){i(t,e);});}}}var O=class{#t;#e;constructor(){this.#t=J(),this.#e=new Map;}on(t,e){return this.#e.has(t)&&e(this.#e.get(t)),this.#t.on(t,e),{off:()=>this.#t.off(t,e)}}once(t,e){if(this.#e.has(t))return e(this.#e.get(t)),{off:()=>{}};let s=i=>{e(i),this.#t.off(t,s);};return this.#t.on(t,s),{off:()=>this.#t.off(t,s)}}off(t,e){this.#t.off(t,e);}emit(t,e,s=false){if(arguments.length===1){this.#e.delete(t);return}let i=e;s&&this.#e.set(t,i),this.#t.emit(t,i);}async wait(t,e){return new Promise((s,i)=>{let o=this.once(t,p=>{n!==void 0&&clearTimeout(n),s(p);}),n;e&&e>0&&(n=setTimeout(()=>{o.off(),i(new Error(`\u7B49\u5F85\u4E8B\u4EF6 "${String(t)}" \u8D85\u65F6 (${e}ms)`));},e));})}onAny(t){return this.#t.on("*",t),{off:()=>this.#t.off("*",t)}}clear(){this.#t.all.clear(),this.#e.clear();}clearRetained(t){this.#e.delete(t);}getRetained(t){return this.#e.get(t)}get listeners(){return this.#t.all}};function Q(r){return !!r&&typeof r=="object"&&typeof r.then=="function"}var R=class extends O{constructor(e,s){super();this.transport=e;this.options=s;this._maxMissCount=s.maxMissCount??5,this._setupEventListeners();}_timer;_pingCounter=0;_pongMissCount=0;_maxMissCount;_pendingPingValue;_subscribers=[];_destroyed=false;_setupEventListeners(){this._subscribers.push(this.transport.on("connect",()=>{this._destroyed||this._start();})),this._subscribers.push(this.transport.on("disconnect",()=>{this._destroyed||this._stop();})),this._subscribers.push(this.transport.on("error",()=>{this._destroyed||this._stop();})),this.transport.connected&&this._start();}onOperate(e){return this._destroyed?false:e.type==="$pong"?(this.onPong(e),true):e.type==="$ping"?(this.onPing(e),true):false}_start(){this.options.interval<=0||(this._stop(),this._pingCounter=0,this._pongMissCount=0,this._sendPing(),this._timer=setInterval(()=>{this._sendPing();},this.options.interval));}_stop(){this._timer&&(clearInterval(this._timer),this._timer=void 0),this._pingCounter=0,this._pongMissCount=0,this._pendingPingValue=void 0;}destroy(){this._destroyed=true,this._stop(),this.transport.removeReceiver("__heartbeat__"),this._subscribers.forEach(e=>e.off()),this._subscribers=[];}onPong(e){e.type==="$pong"&&this._pendingPingValue!==void 0&&e.value===this._pendingPingValue&&(this._pongMissCount=0,this._pendingPingValue=void 0);}onPing(e){this.transport.connected&&e.type==="$ping"&&this.transport.send({type:"$pong",value:e.value});}_sendPing(){if(!this._destroyed){if(this._pendingPingValue!==void 0&&(this._pongMissCount++,this._pongMissCount>=this._maxMissCount)){this._stop(),this.emit("timeout",void 0);return}this._pingCounter++,this._pendingPingValue=this._pingCounter;try{this.transport.send({type:"$ping",value:this._pingCounter});}catch{}}}};function F(r){if(typeof r!="object"||r===null)return false;let t=r;return "type"in t&&"value"in t&&"path"in t&&Array.isArray(t.path)}var T=class r extends O{receivers=new Map;stopCallbacks=new Map;connected=false;options={};static seq=0;id;heartbeat;constructor(t){super(),Object.assign(this.options,t),this.id=++r.seq,this.options.autoConnect===true&&this.connect();}addReceiver(t,e){return this.receivers.set(String(t),e),{off:()=>this.receivers.delete(String(t))}}removeReceiver(t){this.receivers.delete(String(t));}_send(t){if(!this.connected)throw new Error}connect(){if(this.connected)return;let t=this.onConnect();if(Q(t))return t.then(()=>{this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();},e=>{throw this.emit("error",e),e});this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();}onConnect(){return true}onDisconnect(){}startHeartbeat(){this.options.heartbeat&&this.options.heartbeat>0&&(this.heartbeat&&this.stopHeartbeat(),this.heartbeat=new R(this,{interval:this.options.heartbeat}),this.heartbeat.on("timeout",()=>{this.disconnect(),this.emit("timeout",void 0);}));}stopHeartbeat(){this.heartbeat&&(this.heartbeat.destroy(),this.heartbeat=void 0);}_handlePing(t){return typeof t=="object"&&t.type==="$ping"?(this.connected&&this.send({type:"$pong",value:t.value}),true):false}onSendOperate(t){}onReceiveOperate(t){if(this._handlePing(t))return true;if(this.heartbeat&&this.heartbeat.onOperate(t)||!F(t))return false;for(let e of this.receivers.values())try{e(t);}catch{}return true}send(t){if(!this.connected)throw new Error("Transport is not connected");this.onSendOperate(t),this.options.debug&&this.emit("operate",t);}disconnect(){if(this.connected)try{this.onDisconnect();}finally{this.connected=false,this.stopHeartbeat(),this.clearRetained("connect"),this.emit("disconnect",void 0,true);}}};var Z=class extends T{getPeer;_peer;constructor(t,e){super(e),this.getPeer=t;}get peer(){return this._peer||(this._peer=this.getPeer()),this._peer}onConnect(){return !!this.peer}onDisconnect(){}onSendOperate(t){if(!this.connected)throw new Error("LocalTransport \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");if(!this.peer)throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5BF9\u7AEF transport");this.peer.connected&&this.peer.onReceiveOperate(t);}};var V=class extends O{static seq=99;_syncing=false;get syncing(){return this._syncing}_emitError(t){this.emit("error",t,true);}push(t){throw new Error(`${this.constructor.name} does not support push() operation. Please use a syncer that implements this method, or override it in a subclass.`)}pull(){throw new Error(`${this.constructor.name} does not support pull() operation. Please use a syncer that implements this method, or override it in a subclass.`)}};function tt(r,...t){if(t.length===0)return r;let e=t.map((s,i)=>{let o=Object.entries(s||{});return o.some(([n,p])=>p===void 0)?o.reduce((n,[p,a])=>(a!==void 0&&(n[p]=a),n),{}):s});return Object.assign(r,...e)}function P(r){return r!=null&&typeof r[Symbol.iterator]=="function"&&typeof r!="string"}function y(r){if(typeof r!="object"||r===null)return false;var t=Object.getPrototypeOf(r);if(t===null)return true;for(var e=t;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return t===e}function et(r,t=false){if(typeof r=="number")return true;if(typeof r!="string"||t)return false;try{if(r.includes(".")){let e=parseFloat(r);return r.endsWith(".")?!isNaN(e)&&String(e).length===r.length-1:!isNaN(e)&&String(e).length===r.length}else {let e=parseInt(r);return !isNaN(e)&&String(e).length===r.length}}catch{return false}}function A(r){if(et(r)||typeof r=="boolean"||typeof r=="function"||r instanceof Error)return false;if(r==null||r==null||Array.isArray(r)&&r.length==0||y(r)&&Object.keys(r).length==0||typeof r=="string"&&r.trim()=="")return true;try{if(P(r)&&r.size==0)return !0}catch{}return false}function rt(r,{empty:t,delimiter:e=","}){let s=r;try{return typeof s=="function"&&(s=s.call(this,s)),A(s)&&(s=t||""),Array.isArray(s)?s.map(i=>String(i)).join(e):y(s)?Object.entries(s).reduce((i,[o,n])=>(i.push(`${o}=${String(n)}`),i),[]).join(e):P(s)&&typeof s!="string"?[...s].map(i=>String(i)).join(e):s instanceof Error?s.message:String(s)}catch{return String(s)}}var jt=/\{(\<(.*?)\>)?\s*([^\{\}\>\<]*)(?<!\s)\s*(\<(.*?)\>)?\}/gm;function B(r,t,e){let s,i=tt({empty:null,delimiter:",",forEach:null},e);typeof t=="function"&&(t=t.call(r)),Array.isArray(t)&&t.length==1&&(y(t[0])||Array.isArray(t[0]))&&(t=t[0]),["boolean","string","number"].includes(typeof t)?s=[t]:t instanceof Map?s=[...t.entries()].reduce((n,p)=>(n[p[0]]=p[1],n),{}):Symbol.iterator in t?s=[...t]:y(t)?s=t:t instanceof Error?s=[`Error:${t.message}`]:s=[t];let o=0;return r.replaceAll(jt,function(){let n=arguments[2]||"",p=arguments[3]||"",a=arguments[5]||"",u="",c=false;if(Array.isArray(s)){let f=o>=s.length;u=f?"":rt.call(r,s[o],i),c=A(u)||f,o++;}else if(y(s)){let f=p in s;u=f?rt.call(r,s[p],i):"",c=A(u)||!f;}if(typeof i.forEach=="function"){let f=i.forEach(p,u,n,a);f!==void 0&&(Array.isArray(f)&&f.length==3?(n=f[0],u=f[1],a=f[2]):A(f)||(u=String(f)),c=A(u));}return c&&(i.empty==null?(u="",n="",a=""):u=i.empty),`${n}${u}${a}`})}function st(r,...t){let e=r.valueOf(),s={},i=[...t];if(t.length>0&&y(t[t.length-1])){let o=t[t.length-1];("$delimiter"in o||"$empty"in o||"$forEach"in o)&&("$delimiter"in o&&(s.delimiter=o.$delimiter),"$empty"in o&&(s.empty=o.$empty),"$forEach"in o&&(s.forEach=o.$forEach),i.pop());}try{return i.length==1?B(e,i[0],s):B(e,[...i],s)}catch{return e}}String.prototype.params=function(){return st(this,...arguments)};function Tt(r,t,e){if(typeof t=="string"){let s=0,i;for(;(i=r.indexOf(t,s))>-1;){let o=typeof e=="function"?e(t):e,n=r.length;r=r.substring(0,i)+o+r.substring(i+t.length),s=i+o.length+r.length-n;}}else {let s;if(!t.global||!t.multiline)throw new Error("The search parameter must be enabled '/gm' option");for(;(s=t.exec(r))!==null;){s.index===t.lastIndex&&t.lastIndex++;let i=r.length,o=s[0].length,n=typeof e=="function"?e(s[0],...s):e;r=r.substring(0,s.index)+n+r.substring(s.index+o),t.lastIndex+=r.length-i;}}return r}String.prototype.replaceAll||(String.prototype.replaceAll=function(r,t){return Tt(this,r,t)});(r=>typeof x<"u"?x:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof x<"u"?x:t)[e]}):r)(function(r){if(typeof x<"u")return x.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var L="__AS_SKIP_PROXY__";var $="__AS_ASYNC_COMPUTED_VALUE__";function U(r){try{return r[L]===!0}catch{}return false}function M(r){return toString.call(r)==="[object Map]"}function v(r){return r&&typeof r=="object"&&r.hasOwnProperty($)}function k(r,t){let e=r.get(t);if(e!==void 0)return e;let s=r.get(Number(t)||t);if(s!==void 0)return s}function g(r,t,e){if(!t||t.length===0)return r;let s=Array.isArray(t)?t:t.split("."),i,o=r;for(let n=0;n<s.length;n++){let p=s[n];if(M(o))i=k(o,p);else if(p in o)i=o[p];else return e;o=i;}return i}function b(r,t,e,s){if(!t||!r)return r;let i=t;if(i.length===0)return typeof r=="object"&&Object.assign(r,e),r;{let o=r,n=[],p=(a,u,c)=>{a[u]=c;};for(let a=0;a<i.length;a++){let u=i[a];if(n.push(u),o)if(Array.isArray(o)){let c=parseInt(u,10);if(Number.isNaN(c)||c<0)throw new Error(`setVal: invalid array index ${n.join(".")}`);a===i.length-1?p(o,c,e):o=o[c];}else o instanceof Map||o instanceof WeakMap?a===i.length-1?o.set(u,e):(o.has(u)||o.set(u,{}),o=o.get(u)):typeof o=="object"&&u in o?a===i.length-1?p(o,u,e):o=o[u]:(o[u]=a===i.length-1?e:{},o=o[u]);else o[u]=a===i.length-1?e:{},o=o[u];}}return r}function C(r,t){function e(s,i){for(let o in s){let n=s[o];typeof t=="function"&&t({value:n,key:o,parent:s,path:i.concat(o)}),typeof n=="object"&&!U(n)&&e(n,i.concat(o));}}e(r,[]);}function W(r){return typeof r=="object"?JSON.parse(JSON.stringify(r)):r}function at(r,t){return r.length>t.length?false:r.every((e,s)=>e===t[s])}function _(r){return r?typeof r=="function":false}var dt=Object.defineProperty,Kt=(r,t,e)=>t in r?dt(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e,l=(r,t)=>dt(r,"name",{value:t,configurable:true}),m=(r,t,e)=>Kt(r,typeof t!="symbol"?t+"":t,e);var mt=class extends Error{constructor(t){super(t);}};l(mt,"FastEventError");var D=mt,kt=class extends D{};l(kt,"TimeoutError");var yt=class extends D{};l(yt,"UnboundError");var Ht=yt,gt=class extends D{};l(gt,"AbortError");var ft=gt,bt=class extends D{};l(bt,"CancelError");var qt=bt,Yt=class extends D{};l(Yt,"QueueOverflowError");var _t={clearRetain:Symbol.for("ClearRetain")},w=(function(r){return r[r.Transformed=1]="Transformed",r})({});function Y(r,t,e,s){let i,o={},n={};return typeof r[0]=="object"?(Object.assign(n,r[0]),o=typeof r[1]=="boolean"?{retain:r[1]}:r[1]||{},i=r[0].meta):(n.type=r[0],n.payload=r[1],o=typeof r[2]=="boolean"?{retain:r[2]}:r[2]||{}),i=Object.assign({},t,e,o.meta,i),Object.keys(i).length===0&&(i=void 0),n.meta=i,o.executor===void 0&&(o.executor=s),[n,o]}l(Y,"parseEmitArgs");function vt(r){return r?typeof r=="object"&&"__FastEventScope__"in r:false}l(vt,"isFastEventScope");function z(r,t,e){let s=r[0],i=vt(r[1])?r[1]:void 0,o=(i?r[2]:r[1])||{};return o.meta=Object.assign({},t,o?.meta),o.context=o.context!==void 0?o.context:e,[s,i,o]}l(z,"parseScopeArgs");function I(r,t){return Object.defineProperty(r,"name",{value:t||"anonymous",configurable:true}),r}l(I,"renameFn");function h(r){return r&&typeof r=="function"}l(h,"isFunction");var Ot=class St{constructor(t){m(this,"__FastEventScope__",true),m(this,"_options",{}),m(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),m(this,"prefix",""),m(this,"emitter"),this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(t,e,s){this.emitter=t,this._options=Object.assign(this._options,{scope:e},s),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let s=this;return I(function(i,o){let n=o.rawEventType||i.type;if(n.startsWith(e)){let p=((o.flags||0)&w.Transformed)>0?i:Object.assign({},i,{type:n.substring(e.length)});return t.call(s.context,p,o)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new Ht;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===_t.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=Y(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){h(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|w.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let t=arguments[0],e=arguments[1],s=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[t,e,s]=z(arguments,this.options.meta,this.options.context),i;return e?i=e:i=new St,i.bind(this.emitter,this.prefix+t,s),i}onMessage(t,e){}};l(Ot,"FastEventScope");var zt=Ot;function q(r,t){if(r.length!==t.length&&r.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:r.length-t.length+1}).fill("*"));for(let s=0;s<r.length;s++)if(e[s]!=="*"&&e[s]!==r[s])return false;return true}l(q,"isPathMatched");function xt(r,t){let e=[];for(;;){let s=r.findIndex(i=>t(i));if(s===-1){e.push(s);break}r.splice(s,1);}return e}l(xt,"removeItem");var Et=Symbol.for("__expandable__");function Xt(r){return r[Et]=true,r}l(Xt,"expandable");function At(r){return r&&r[Et]}l(At,"isExpandable");function Ct(r){for(let t=0;t<r.length;t++){let e=r[t];Array.isArray(e)&&At(e)&&(r.splice(t,1,...e),t+=e.length-1);}return r}l(Ct,"expandEmitResults");function Rt(r){return r&&typeof r=="object"&&"off"in r&&"listener"in r}l(Rt,"isSubsctiber");function Vt(r,t){return r.catch(e=>(t&&t(e),Promise.resolve(e)))}l(Vt,"tryReturnError");var Jt=class{constructor(t){m(this,"__FastEvent__",true),m(this,"listeners",{__listeners:[]}),m(this,"_options"),m(this,"_delimiter","/"),m(this,"_context"),m(this,"retainedMessages",new Map),m(this,"listenerCount",0),m(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,s){let{count:i,prepend:o}=s,n=0;return [this._forEachNodes(t,p=>{let a=[e,i,0,s.tag,s.flags];o?(p.__listeners.splice(0,0,a),n=0):(p.__listeners.push(a),n=p.__listeners.length-1),this.listenerCount++;}),n]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let s=this.listeners;for(let i=0;i<t.length;i++){let o=t[i];if(o in s||(s[o]={__listeners:[]}),i===t.length-1){let n=s[o];return e(n,s),n}else s=s[o];}}_removeListener(t,e,s){s&&xt(t.__listeners,i=>{i=Array.isArray(i)?i[0]:i;let o=i===s;return o&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),s)),o});}_pipeListener(t,e){return e.forEach(s=>{t=I(s(t),t.name);}),t}on(){let t=arguments[0],e=h(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,flags:0,prepend:false},h(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(h(this._options.onAddListener)){let a=this._options.onAddListener(t,e,s);if(a===false)throw new qt;if(Rt(a))return a}let i=t.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(e=this._pipeListener(e,s.pipes)),h(s.filter)||h(s.off)){let a=e;e=I(function(u,c){if(h(s.off)&&s.off.call(this,u,c)){p();return}if(h(s.filter)){if(s.filter.call(this,u,c))return a.call(this,u,c)}else return a.call(this,u,c)},e.name);}let[o,n]=this._addListener(i,e,s),p=l(()=>o&&this._removeListener(o,i,e),"off");return this._emitRetainMessage(t,o,n),{off:p,listener:e}}once(){return h(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=h(t[0])?void 0:t[0],s=h(t[0])?t[0]:t[1],i=e?e.split(this._delimiter):[],o=e?e.includes("*"):false;if(e&&!o)this._traverseToPath(this.listeners,i,n=>{s?this._removeListener(n,i,s):e&&(n.__listeners=[]);});else {let n=o?[]:i;this._traverseListeners(this.listeners,n,(p,a)=>{(s!==void 0||o&&q(p,i))&&(s?this._removeListener(a,i,s):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),s=0;this._traverseListeners(this.listeners,e,(i,o)=>{s+=o.__listeners.length,o.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(s,i)=>{e+=i.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,s){let i=[];if(t.includes("*")){let o=t.split(this._delimiter);this.retainedMessages.forEach((n,p)=>{let a=p.split(this._delimiter);q(a,o)&&i.push(n);});}else this.retainedMessages.has(t)&&i.push(this.retainedMessages.get(t));e&&i.forEach(o=>{this._executeListeners([e],o,{},n=>n[0]===e.__listeners[s][0]);});}_traverseToPath(t,e,s,i=0,o){if(i>=e.length){s(t);return}let n=e[i];if(o===true){this._traverseToPath(t,e,s,i+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,s,i+1),"**"in t&&this._traverseToPath(t["**"],e,s,i+1,true),n in t&&this._traverseToPath(t[n],e,s,i+1);}_traverseListeners(t,e,s){let i=t;e&&e.length>0&&this._traverseToPath(t,e,n=>{i=n;});let o=l((n,p,a)=>{p(a,n);for(let[u,c]of Object.entries(n))u.startsWith("__")||c&&o(c,p,[...a,u]);},"traverseNodes");o(i,s,[]);}_onListenerError(t,e,s,i){if(i instanceof Error&&(i._emitter=`${t.name||"anonymous"}:${e.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,i,t,e,s);}catch{}if(this._options.ignoreErrors)return i;throw i}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,s,i=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(t,e,s,new ft(t.name));let o=((s?.flags||0)&w.Transformed)>0,n=t.call(this.context,o?e.payload:e,s);return i&&n&&n instanceof Promise&&(n=Vt(n,p=>this._onListenerError(t,e,s,p))),n}catch(o){return this._onListenerError(t,e,s,o)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(h(e))return e}_executeListeners(t,e,s,i){if(!t||t.length===0)return [];let o=t.reduce((p,a)=>p.concat(a.__listeners.filter(u=>h(i)?i(u,a):true).map((u,c)=>[u,c,a.__listeners])),[]);h(this._options.transform)&&(s||(s={}),s.rawEventType=e.type,e.payload=this._options.transform.call(this,e),s.flags=this._setListenerFlags(s.flags,w.Transformed)),this._decListenerExecCount(o);let n=this._getListenerExecutor(s);if(n){let p=n(o.map(a=>a[0]),e,s,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return o.map(p=>this._executeListener(p[0][0],e,s,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let s=t[e][0];s[2]++,s[1]>0&&s[1]<=s[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],s=t.split(this._delimiter);return this._traverseToPath(this.listeners,s,i=>{e.push(i);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===_t.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=Y(arguments,this.options.meta);h(e.parseArgs)&&e.parseArgs(t,e);let s=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let i=[],o=[];if(this._traverseToPath(this.listeners,s,n=>{o.push(n);}),h(this._options.onBeforeExecuteListener)){let n=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(n))return n;if(n===false)throw new ft(t.type)}return h(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|w.Transformed),i.push(...this._executeListeners(o,t,e)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,i,o),this._options.expandEmitResults&&Ct(i),i}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((s,i)=>{let o,n,p=l(a=>{clearTimeout(o),n&&n.off(),s(a);},"listener");e&&e>0&&(o=setTimeout(()=>{n&&n.off(),i(new Error("wait for event<"+t+"> is timeout"));},e)),n=this.on(t,p);})}scope(){let[t,e,s]=z(arguments,this.options.meta,this.options.context),i;return e?i=e:i=new zt,i.bind(this,t,s),i}};l(Jt,"FastEvent");function Qt(r){return r?typeof r=="object"&&"type"in r:false}l(Qt,"isFastEventMessage");function Zt(r){return r&&typeof r=="string"}l(Zt,"isString");function te(r){return typeof r=="function"&&(r.toString().startsWith("class ")||r.prototype?.constructor===r)}l(te,"isClass");function ee(r){return r?typeof r=="object"&&"__FastEvent__"in r:false}l(ee,"isFastEvent");var X=-1,Dt=class r extends V{constructor(e,s){super();this.store=e;this._options=Object.assign({id:e.id,mode:"push",local:[],remote:[],autostart:true,maxCacheSize:100,direction:"both",pathMap:{},peers:["*"],debug:false},s),typeof this._options.local=="string"&&(this._options.local=this._options.local.split(".")),typeof this._options.remote=="string"&&(this._options.remote=this._options.remote.split(".")),this.seq=++r.seq,this._options.autostart&&this.start();}seq;_options;peer;_operateCache=[];_subscribers=[];get id(){return this._options.id}get options(){return this._options}get transport(){return this._options.transport}get localEntry(){return this._options.local}get remoteEntry(){return this._options.remote}_onConnect(){try{let e=this.options.direction,s=this.options.mode;(s==="push"||s=="both")&&this._pushStore(!0),(s==="pull"||s=="both")&&this._pullStore(!0),e==="forward"&&(this._syncing=!0);}finally{this.flush();}}createRemoteOperate(e){return {id:this.id,type:e.type,path:e.path,parentPath:e.parentPath,value:W(e.value),indexs:e.indexs,flags:e.flags??0}}isPeer(e){let s=this._options.peers;return s.includes("*")?true:s.includes(e.id)}start(){if(this.syncing)return;let e;try{this._syncing=!0,this._subscribers.push(this.store.watch(this._onWatchStore.bind(this),{operates:"write"})),this._subscribers.push(this.transport.addReceiver(this.id,s=>{s.id!==this.id&&(!s.type.startsWith("$")&&(this.options.direction==="forward"||!this.isPeer(s))||this._onReceiveFromRemote(s));})),this._subscribers.push(this.transport.on("connect",this._onConnect.bind(this))),this._subscribers.push(this.transport.on("disconnect",this.stop.bind(this))),this._subscribers.push(this.transport.on("error",this.stop.bind(this))),this._subscribers.push(this.transport.on("timeout",this.stop.bind(this))),this.transport.connect();}catch(s){throw e=s,this.stop(),this.emit("error",s,true),s}finally{e||this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._subscribers.forEach(e=>e.off()),this._options.transport.connected&&this._options.transport.send({id:this.id,type:"$stop",path:[],value:void 0,flags:0});}finally{this.emit("stop",void 0,true),this._syncing=false;}}_onWatchStore(e){try{if(this._isPass(e.path,e.value)===!1||Math.abs(e.flags||0)===this.seq||this.options.direction==="backward")return;this._sendToRemote(e);}finally{this.options.debug===true&&this.emit("localOperate",e);}}_isPass(e,s){return _(this._options.filter)?this._options.filter(e,s):true}_sendToRemote(e){let s=this.options.local,i=this.options.remote;if(!at(this._options.local,e.path))return;if(typeof this._options.pathMap.toRemote=="function"){let n=this._options.pathMap.toRemote(e.path.slice(this._options.local.length),e.value);n&&(e.path=[...i,...n]);}else e.path=[...i,...e.path.slice(s.length)];let o=this.createRemoteOperate(e);this._sendOperate(o);}_onReceiveFromRemote(e){try{if(typeof this._options.onReceive=="function"&&this._options.onReceive.call(this,e)===!1)return;let s=e.type;if(s==="$stop")this.stop();else if(s==="$push")this._updateStore(e);else if(s==="$pull")this._sendStore(e);else if(s==="$update")this._updateStore(e);else if(s==="$ping")this._sendOperate({type:"$pong",value:e.value});else if(s==="$error"){let i=new j;i.operate=e,this.emit("error",i);}else this._applyOperate(e);}finally{this.options.debug===true&&this.emit("remoteOperate",e);}}_applyOperate(e){let{type:s,value:i,indexs:o}=e,n=this.store,p=this._mapPath(e.path,e.value,"toLocal");if(!p)return;e.path=p;let a=[...this.localEntry,...e.path.slice(this.options.remote.length)],u={flags:-this.seq};s==="set"||s==="update"?n.update(c=>{v(g(c,a,true))?b(c,a.concat("value"),i):b(c,a,i);},u):s==="delete"?n.update(c=>{b(c,a,void 0);},u):s==="insert"?n.update(c=>{let f=g(c,a);Array.isArray(o)&&f.splice(o[0],0,...i);},u):s==="remove"&&n.update(c=>{let f=g(c,a);Array.isArray(o)&&(o.length===0?f.splice(0):f.splice(o[0],o.length));},u);}flush(){this.transport.connected&&Promise.all(this._operateCache.map(e=>this.transport.send(e))).finally(()=>{this._operateCache=[];});}_assertConnected(e){return this.transport.connected?true:(this._operateCache.push(e),this._operateCache.length>this._options.maxCacheSize&&this._operateCache.shift(),false)}_sendOperate(e){if(this._assertConnected(e)){if(typeof this._options.onSend=="function"&&this._options.onSend.call(this,e)===false)return;this._options.transport.send(e);}}_getLocalSnap(){return this.store.getSnap({entry:this._options.local.join(".")})}push(){this._pushStore();}_pushStore(e=false){let s=this._getLocalSnap();if(typeof this._options.pathMap.toRemote=="function"){let i=new Map;return C(s,({value:o,path:n})=>{if(this._isPass(n,o)===false)return;let p=Array.isArray(o)?[]:typeof o=="object"?{}:o,a=this._mapPath(n,p,"toRemote");if(a){i.set(JSON.stringify(n),JSON.stringify(a));let u={type:"set",path:[...this.options.remote,...a],value:p};e&&(u.flags=X),this._sendOperate(u);}}),i}else this._sendOperate({id:this.id,type:"$push",path:this.options.remote,value:s,flags:e?X:0});}_sendStore(e){this._sendOperate({id:this.id,type:"$update",path:[],value:this.store.getSnap({entry:e.path.join(".")}),flags:this.seq});}_updateStore(e){try{let i=this.store,o=-this.seq;if(typeof this._options.pathMap.toLocal=="function")C(e.value,({value:n,path:p})=>{if(this._isPass(p,n)===!1)return;let a=Array.isArray(n)?[]:typeof n=="object"?{}:n,u=this._mapPath(p,a,"toLocal");u&&i.update(c=>{b(c,[...this.localEntry,...u],a);},{flags:o});});else {let n=[...this.localEntry,...e.path||[]];i.update(p=>{b(p,n,e.value);},{flags:o});}}catch(i){this.emit("error",i);}finally{this._syncing===false&&(this._syncing=true,this.emit("syncing",e.id,true));}}_pullStore(e=false){this._sendOperate({id:this.id,type:"$pull",path:this.options.remote,value:void 0,flags:e?X:0});}pull(){this._pullStore();}_mapPath(e,s,i){return this._options.pathMap&&_(this._options.pathMap[i])?this._options.pathMap[i](e,s):e}toString(){return `AutoStoreSyncer(${this.id})`}};exports.AutoStoreSyncError=j;exports.AutoStoreSyncTransportBase=T;exports.AutoStoreSyncer=Dt;exports.AutoStoreSyncerBase=V;exports.LocalTransport=Z;exports.SYNC_INIT_FLAG=X;return exports;})({});//# sourceMappingURL=index.lite.global.js.map | ||
| var AutoStoreSyncer=(function(exports){'use strict';var x=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var j=class extends Error{operate};function J(r){return {all:r=r||new Map,on:function(t,e){var s=r.get(t);s?s.push(e):r.set(t,[e]);},off:function(t,e){var s=r.get(t);s&&(e?s.splice(s.indexOf(e)>>>0,1):r.set(t,[]));},emit:function(t,e){var s=r.get(t);s&&s.slice().map(function(i){i(e);}),(s=r.get("*"))&&s.slice().map(function(i){i(t,e);});}}}var O=class{#t;#e;constructor(){this.#t=J(),this.#e=new Map;}on(t,e){return this.#e.has(t)&&e(this.#e.get(t)),this.#t.on(t,e),{off:()=>this.#t.off(t,e)}}once(t,e){if(this.#e.has(t))return e(this.#e.get(t)),{off:()=>{}};let s=i=>{e(i),this.#t.off(t,s);};return this.#t.on(t,s),{off:()=>this.#t.off(t,s)}}off(t,e){this.#t.off(t,e);}emit(t,e,s=false){if(arguments.length===1){this.#e.delete(t);return}let i=e;s&&this.#e.set(t,i),this.#t.emit(t,i);}async wait(t,e){return new Promise((s,i)=>{let o=this.once(t,p=>{n!==void 0&&clearTimeout(n),s(p);}),n;e&&e>0&&(n=setTimeout(()=>{o.off(),i(new Error(`\u7B49\u5F85\u4E8B\u4EF6 "${String(t)}" \u8D85\u65F6 (${e}ms)`));},e));})}onAny(t){return this.#t.on("*",t),{off:()=>this.#t.off("*",t)}}clear(){this.#t.all.clear(),this.#e.clear();}clearRetained(t){this.#e.delete(t);}getRetained(t){return this.#e.get(t)}get listeners(){return this.#t.all}};function Q(r){return !!r&&typeof r=="object"&&typeof r.then=="function"}var R=class extends O{constructor(e,s){super();this.transport=e;this.options=s;this._maxMissCount=s.maxMissCount??5,this._setupEventListeners();}_timer;_pingCounter=0;_pongMissCount=0;_maxMissCount;_pendingPingValue;_subscribers=[];_destroyed=false;_setupEventListeners(){this._subscribers.push(this.transport.on("connect",()=>{this._destroyed||this._start();})),this._subscribers.push(this.transport.on("disconnect",()=>{this._destroyed||this._stop();})),this._subscribers.push(this.transport.on("error",()=>{this._destroyed||this._stop();})),this.transport.connected&&this._start();}onOperate(e){return this._destroyed?false:e.type==="$pong"?(this.onPong(e),true):e.type==="$ping"?(this.onPing(e),true):false}_start(){this.options.interval<=0||(this._stop(),this._pingCounter=0,this._pongMissCount=0,this._sendPing(),this._timer=setInterval(()=>{this._sendPing();},this.options.interval));}_stop(){this._timer&&(clearInterval(this._timer),this._timer=void 0),this._pingCounter=0,this._pongMissCount=0,this._pendingPingValue=void 0;}destroy(){this._destroyed=true,this._stop(),this.transport.removeReceiver("__heartbeat__"),this._subscribers.forEach(e=>e.off()),this._subscribers=[];}onPong(e){e.type==="$pong"&&this._pendingPingValue!==void 0&&e.value===this._pendingPingValue&&(this._pongMissCount=0,this._pendingPingValue=void 0);}onPing(e){this.transport.connected&&e.type==="$ping"&&this.transport.send({type:"$pong",value:e.value});}_sendPing(){if(!this._destroyed){if(this._pendingPingValue!==void 0&&(this._pongMissCount++,this._pongMissCount>=this._maxMissCount)){this._stop(),this.emit("timeout",void 0);return}this._pingCounter++,this._pendingPingValue=this._pingCounter;try{this.transport.send({type:"$ping",value:this._pingCounter});}catch{}}}};function B(r){if(typeof r!="object"||r===null)return false;let t=r;return "type"in t&&"value"in t&&"path"in t&&Array.isArray(t.path)}var T=class r extends O{receivers=new Map;stopCallbacks=new Map;connected=false;options={};static seq=0;id;heartbeat;constructor(t){super(),Object.assign(this.options,t),this.id=++r.seq,this.options.autoConnect===true&&this.connect();}addReceiver(t,e){return this.receivers.set(String(t),e),{off:()=>this.receivers.delete(String(t))}}removeReceiver(t){this.receivers.delete(String(t));}_send(t){if(!this.connected)throw new Error}connect(){if(this.connected)return;let t=this.onConnect();if(Q(t))return t.then(()=>{this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();},e=>{throw this.emit("error",e),e});this.connected=true,this.clearRetained("disconnect"),this.emit("connect",void 0,true),this.startHeartbeat();}onConnect(){return true}onDisconnect(){}startHeartbeat(){this.options.heartbeat&&this.options.heartbeat>0&&(this.heartbeat&&this.stopHeartbeat(),this.heartbeat=new R(this,{interval:this.options.heartbeat}),this.heartbeat.on("timeout",()=>{this.disconnect(),this.emit("timeout",void 0);}));}stopHeartbeat(){this.heartbeat&&(this.heartbeat.destroy(),this.heartbeat=void 0);}_handlePing(t){return typeof t=="object"&&t.type==="$ping"?(this.connected&&this.send({type:"$pong",value:t.value}),true):false}onSendOperate(t){}onReceiveOperate(t){if(this._handlePing(t))return true;if(this.heartbeat&&this.heartbeat.onOperate(t)||!B(t))return false;for(let e of this.receivers.values())try{e(t);}catch{}return true}send(t){if(!this.connected)throw new Error("Transport is not connected");this.onSendOperate(t),this.options.debug&&this.emit("operate",t);}disconnect(){if(this.connected)try{this.onDisconnect();}finally{this.connected=false,this.stopHeartbeat(),this.clearRetained("connect"),this.emit("disconnect",void 0,true);}}};var Z=class extends T{getPeer;_peer;constructor(t,e){super(e),this.getPeer=t;}get peer(){return this._peer||(this._peer=this.getPeer()),this._peer}onConnect(){return !!this.peer}onDisconnect(){}onSendOperate(t){if(!this.connected)throw new Error("LocalTransport \u672A\u8FDE\u63A5\uFF0C\u65E0\u6CD5\u53D1\u9001\u6D88\u606F");if(!this.peer)throw new Error("\u65E0\u6CD5\u83B7\u53D6\u5BF9\u7AEF transport");this.peer.connected&&this.peer.onReceiveOperate(t);}};var V=class extends O{static seq=99;_syncing=false;get syncing(){return this._syncing}_emitError(t){this.emit("error",t,true);}push(t){throw new Error(`${this.constructor.name} does not support push() operation. Please use a syncer that implements this method, or override it in a subclass.`)}pull(){throw new Error(`${this.constructor.name} does not support pull() operation. Please use a syncer that implements this method, or override it in a subclass.`)}};function tt(r,...t){if(t.length===0)return r;let e=t.map((s,i)=>{let o=Object.entries(s||{});return o.some(([n,p])=>p===void 0)?o.reduce((n,[p,a])=>(a!==void 0&&(n[p]=a),n),{}):s});return Object.assign(r,...e)}function P(r){return r!=null&&typeof r[Symbol.iterator]=="function"&&typeof r!="string"}function g(r){if(typeof r!="object"||r===null)return false;var t=Object.getPrototypeOf(r);if(t===null)return true;for(var e=t;Object.getPrototypeOf(e)!==null;)e=Object.getPrototypeOf(e);return t===e}function et(r,t=false){if(typeof r=="number")return true;if(typeof r!="string"||t)return false;try{if(r.includes(".")){let e=parseFloat(r);return r.endsWith(".")?!isNaN(e)&&String(e).length===r.length-1:!isNaN(e)&&String(e).length===r.length}else {let e=parseInt(r);return !isNaN(e)&&String(e).length===r.length}}catch{return false}}function A(r){if(et(r)||typeof r=="boolean"||typeof r=="function"||r instanceof Error)return false;if(r==null||r==null||Array.isArray(r)&&r.length==0||g(r)&&Object.keys(r).length==0||typeof r=="string"&&r.trim()=="")return true;try{if(P(r)&&r.size==0)return !0}catch{}return false}function rt(r,{empty:t,delimiter:e=","}){let s=r;try{return typeof s=="function"&&(s=s.call(this,s)),A(s)&&(s=t||""),Array.isArray(s)?s.map(i=>String(i)).join(e):g(s)?Object.entries(s).reduce((i,[o,n])=>(i.push(`${o}=${String(n)}`),i),[]).join(e):P(s)&&typeof s!="string"?[...s].map(i=>String(i)).join(e):s instanceof Error?s.message:String(s)}catch{return String(s)}}var jt=/\{(\<(.*?)\>)?\s*([^\{\}\>\<]*)(?<!\s)\s*(\<(.*?)\>)?\}/gm;function $(r,t,e){let s,i=tt({empty:null,delimiter:",",forEach:null},e);typeof t=="function"&&(t=t.call(r)),Array.isArray(t)&&t.length==1&&(g(t[0])||Array.isArray(t[0]))&&(t=t[0]),["boolean","string","number"].includes(typeof t)?s=[t]:t instanceof Map?s=[...t.entries()].reduce((n,p)=>(n[p[0]]=p[1],n),{}):Symbol.iterator in t?s=[...t]:g(t)?s=t:t instanceof Error?s=[`Error:${t.message}`]:s=[t];let o=0;return r.replaceAll(jt,function(){let n=arguments[2]||"",p=arguments[3]||"",a=arguments[5]||"",u="",c=false;if(Array.isArray(s)){let h=o>=s.length;u=h?"":rt.call(r,s[o],i),c=A(u)||h,o++;}else if(g(s)){let h=p in s;u=h?rt.call(r,s[p],i):"",c=A(u)||!h;}if(typeof i.forEach=="function"){let h=i.forEach(p,u,n,a);h!==void 0&&(Array.isArray(h)&&h.length==3?(n=h[0],u=h[1],a=h[2]):A(h)||(u=String(h)),c=A(u));}return c&&(i.empty==null?(u="",n="",a=""):u=i.empty),`${n}${u}${a}`})}function st(r,...t){let e=r.valueOf(),s={},i=[...t];if(t.length>0&&g(t[t.length-1])){let o=t[t.length-1];("$delimiter"in o||"$empty"in o||"$forEach"in o)&&("$delimiter"in o&&(s.delimiter=o.$delimiter),"$empty"in o&&(s.empty=o.$empty),"$forEach"in o&&(s.forEach=o.$forEach),i.pop());}try{return i.length==1?$(e,i[0],s):$(e,[...i],s)}catch{return e}}String.prototype.params=function(){return st(this,...arguments)};function Tt(r,t,e){if(typeof t=="string"){let s=0,i;for(;(i=r.indexOf(t,s))>-1;){let o=typeof e=="function"?e(t):e,n=r.length;r=r.substring(0,i)+o+r.substring(i+t.length),s=i+o.length+r.length-n;}}else {let s;if(!t.global||!t.multiline)throw new Error("The search parameter must be enabled '/gm' option");for(;(s=t.exec(r))!==null;){s.index===t.lastIndex&&t.lastIndex++;let i=r.length,o=s[0].length,n=typeof e=="function"?e(s[0],...s):e;r=r.substring(0,s.index)+n+r.substring(s.index+o),t.lastIndex+=r.length-i;}}return r}String.prototype.replaceAll||(String.prototype.replaceAll=function(r,t){return Tt(this,r,t)});(r=>typeof x<"u"?x:typeof Proxy<"u"?new Proxy(r,{get:(t,e)=>(typeof x<"u"?x:t)[e]}):r)(function(r){if(typeof x<"u")return x.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var L="__AS_SKIP_PROXY__";var G="__AS_ASYNC_COMPUTED_VALUE__";function M(r){try{return r[L]===!0}catch{}return false}function W(r){return toString.call(r)==="[object Map]"}function S(r){return r&&typeof r=="object"&&r.hasOwnProperty(G)}function K(r,t){let e=r.get(t);if(e!==void 0)return e;let s=r.get(Number(t)||t);if(s!==void 0)return s}function y(r,t,e){if(!t||t.length===0)return r;let s=Array.isArray(t)?t:t.split("."),i,o=r;for(let n=0;n<s.length;n++){let p=s[n];if(W(o))i=K(o,p);else if(p in o)i=o[p];else return e;o=i;}return i}function b(r,t,e,s){if(!t||!r)return r;let i=t;if(i.length===0)return typeof r=="object"&&Object.assign(r,e),r;{let o=r,n=[],p=(a,u,c)=>{a[u]=c;};for(let a=0;a<i.length;a++){let u=i[a];if(n.push(u),o)if(Array.isArray(o)){let c=parseInt(u,10);if(Number.isNaN(c)||c<0)throw new Error(`setVal: invalid array index ${n.join(".")}`);a===i.length-1?p(o,c,e):o=o[c];}else o instanceof Map||o instanceof WeakMap?a===i.length-1?o.set(u,e):(o.has(u)||o.set(u,{}),o=o.get(u)):typeof o=="object"&&u in o?a===i.length-1?p(o,u,e):o=o[u]:(o[u]=a===i.length-1?e:{},o=o[u]);else o[u]=a===i.length-1?e:{},o=o[u];}}return r}function C(r,t){function e(s,i){for(let o in s){let n=s[o];typeof t=="function"&&t({value:n,key:o,parent:s,path:i.concat(o)}),typeof n=="object"&&!M(n)&&e(n,i.concat(o));}}e(r,[]);}function I(r){return typeof r=="object"?JSON.parse(JSON.stringify(r)):r}function at(r,t){return r.length>t.length?false:r.every((e,s)=>e===t[s])}function _(r){return r?typeof r=="function":false}var dt=Object.defineProperty,kt=(r,t,e)=>t in r?dt(r,t,{enumerable:true,configurable:true,writable:true,value:e}):r[t]=e,l=(r,t)=>dt(r,"name",{value:t,configurable:true}),m=(r,t,e)=>kt(r,typeof t!="symbol"?t+"":t,e);var mt=class extends Error{constructor(t){super(t);}};l(mt,"FastEventError");var D=mt,Kt=class extends D{};l(Kt,"TimeoutError");var yt=class extends D{};l(yt,"UnboundError");var Ht=yt,gt=class extends D{};l(gt,"AbortError");var ht=gt,bt=class extends D{};l(bt,"CancelError");var qt=bt,Yt=class extends D{};l(Yt,"QueueOverflowError");var _t={clearRetain:Symbol.for("ClearRetain")},w=(function(r){return r[r.Transformed=1]="Transformed",r})({});function Y(r,t,e,s){let i,o={},n={};return typeof r[0]=="object"?(Object.assign(n,r[0]),o=typeof r[1]=="boolean"?{retain:r[1]}:r[1]||{},i=r[0].meta):(n.type=r[0],n.payload=r[1],o=typeof r[2]=="boolean"?{retain:r[2]}:r[2]||{}),i=Object.assign({},t,e,o.meta,i),Object.keys(i).length===0&&(i=void 0),n.meta=i,o.executor===void 0&&(o.executor=s),[n,o]}l(Y,"parseEmitArgs");function St(r){return r?typeof r=="object"&&"__FastEventScope__"in r:false}l(St,"isFastEventScope");function z(r,t,e){let s=r[0],i=St(r[1])?r[1]:void 0,o=(i?r[2]:r[1])||{};return o.meta=Object.assign({},t,o?.meta),o.context=o.context!==void 0?o.context:e,[s,i,o]}l(z,"parseScopeArgs");function F(r,t){return Object.defineProperty(r,"name",{value:t||"anonymous",configurable:true}),r}l(F,"renameFn");function f(r){return r&&typeof r=="function"}l(f,"isFunction");var vt=class Ot{constructor(t){m(this,"__FastEventScope__",true),m(this,"_options",{}),m(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),m(this,"prefix",""),m(this,"emitter"),this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}get listeners(){return this.emitter.getListeners(this.prefix)}bind(t,e,s){this.emitter=t,this._options=Object.assign(this._options,{scope:e},s),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let s=this;return F(function(i,o){let n=o.rawEventType||i.type;if(n.startsWith(e)){let p=((o.flags||0)&w.Transformed)>0?i:Object.assign({},i,{type:n.substring(e.length)});return t.call(s.context,p,o)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new Ht;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===_t.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=Y(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){f(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|w.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let t=arguments[0],e=arguments[1],s=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[t,e,s]=z(arguments,this.options.meta,this.options.context),i;return e?i=e:i=new Ot,i.bind(this.emitter,this.prefix+t,s),i}onMessage(t,e){}};l(vt,"FastEventScope");var zt=vt;function q(r,t){if(r.length!==t.length&&r.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:r.length-t.length+1}).fill("*"));for(let s=0;s<r.length;s++)if(e[s]!=="*"&&e[s]!==r[s])return false;return true}l(q,"isPathMatched");function xt(r,t){let e=[];for(;;){let s=r.findIndex(i=>t(i));if(s===-1){e.push(s);break}r.splice(s,1);}return e}l(xt,"removeItem");var Et=Symbol.for("__expandable__");function Xt(r){return r[Et]=true,r}l(Xt,"expandable");function At(r){return r&&r[Et]}l(At,"isExpandable");function Ct(r){for(let t=0;t<r.length;t++){let e=r[t];Array.isArray(e)&&At(e)&&(r.splice(t,1,...e),t+=e.length-1);}return r}l(Ct,"expandEmitResults");function Rt(r){return r&&typeof r=="object"&&"off"in r&&"listener"in r}l(Rt,"isSubsctiber");function Vt(r,t){return r.catch(e=>(t&&t(e),Promise.resolve(e)))}l(Vt,"tryReturnError");var Jt=class{constructor(t){m(this,"__FastEvent__",true),m(this,"listeners",{__listeners:[]}),m(this,"_options"),m(this,"_delimiter","/"),m(this,"_context"),m(this,"retainedMessages",new Map),m(this,"listenerCount",0),m(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0}),this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,s){let{count:i,prepend:o}=s,n=0;return [this._forEachNodes(t,p=>{let a=[e,i,0,s.tag,s.flags];o?(p.__listeners.splice(0,0,a),n=0):(p.__listeners.push(a),n=p.__listeners.length-1),this.listenerCount++;}),n]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let s=this.listeners;for(let i=0;i<t.length;i++){let o=t[i];if(o in s||(s[o]={__listeners:[]}),i===t.length-1){let n=s[o];return e(n,s),n}else s=s[o];}}_removeListener(t,e,s){s&&xt(t.__listeners,i=>{i=Array.isArray(i)?i[0]:i;let o=i===s;return o&&(this.listenerCount--,f(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),s)),o});}_pipeListener(t,e){return e.forEach(s=>{t=F(s(t),t.name);}),t}on(){let t=arguments[0],e=f(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,flags:0,prepend:false},f(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(f(this._options.onAddListener)){let a=this._options.onAddListener(t,e,s);if(a===false)throw new qt;if(Rt(a))return a}let i=t.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(e=this._pipeListener(e,s.pipes)),f(s.filter)||f(s.off)){let a=e;e=F(function(u,c){if(f(s.off)&&s.off.call(this,u,c)){p();return}if(f(s.filter)){if(s.filter.call(this,u,c))return a.call(this,u,c)}else return a.call(this,u,c)},e.name);}let[o,n]=this._addListener(i,e,s),p=l(()=>o&&this._removeListener(o,i,e),"off");return this._emitRetainMessage(t,o,n),{off:p,listener:e}}once(){return f(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=f(t[0])?void 0:t[0],s=f(t[0])?t[0]:t[1],i=e?e.split(this._delimiter):[],o=e?e.includes("*"):false;if(e&&!o)this._traverseToPath(this.listeners,i,n=>{s?this._removeListener(n,i,s):e&&(n.__listeners=[]);});else {let n=o?[]:i;this._traverseListeners(this.listeners,n,(p,a)=>{(s!==void 0||o&&q(p,i))&&(s?this._removeListener(a,i,s):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),s=0;this._traverseListeners(this.listeners,e,(i,o)=>{s+=o.__listeners.length,o.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(s,i)=>{e+=i.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}f(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,s){let i=[];if(t.includes("*")){let o=t.split(this._delimiter);this.retainedMessages.forEach((n,p)=>{let a=p.split(this._delimiter);q(a,o)&&i.push(n);});}else this.retainedMessages.has(t)&&i.push(this.retainedMessages.get(t));e&&i.forEach(o=>{this._executeListeners([e],o,{},n=>n[0]===e.__listeners[s][0]);});}_traverseToPath(t,e,s,i=0,o){if(i>=e.length){s(t);return}let n=e[i];if(o===true){this._traverseToPath(t,e,s,i+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,s,i+1),"**"in t&&this._traverseToPath(t["**"],e,s,i+1,true),n in t&&this._traverseToPath(t[n],e,s,i+1);}_traverseListeners(t,e,s){let i=t;e&&e.length>0&&this._traverseToPath(t,e,n=>{i=n;});let o=l((n,p,a)=>{p(a,n);for(let[u,c]of Object.entries(n))u.startsWith("__")||c&&o(c,p,[...a,u]);},"traverseNodes");o(i,s,[]);}_onListenerError(t,e,s,i){if(i instanceof Error&&(i._emitter=`${t.name||"anonymous"}:${e.type}`),f(this._options.onListenerError))try{this._options.onListenerError.call(this,i,t,e,s);}catch{}if(this._options.ignoreErrors)return i;throw i}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,s,i=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(t,e,s,new ht(t.name));let o=((s?.flags||0)&w.Transformed)>0,n=t.call(this.context,o?e.payload:e,s);return i&&n&&n instanceof Promise&&(n=Vt(n,p=>this._onListenerError(t,e,s,p))),n}catch(o){return this._onListenerError(t,e,s,o)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(f(e))return e}_executeListeners(t,e,s,i){if(!t||t.length===0)return [];let o=t.reduce((p,a)=>p.concat(a.__listeners.filter(u=>f(i)?i(u,a):true).map((u,c)=>[u,c,a.__listeners])),[]);f(this._options.transform)&&(s||(s={}),s.rawEventType=e.type,e.payload=this._options.transform.call(this,e),s.flags=this._setListenerFlags(s.flags,w.Transformed)),this._decListenerExecCount(o);let n=this._getListenerExecutor(s);if(n){let p=n(o.map(a=>a[0]),e,s,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return o.map(p=>this._executeListener(p[0][0],e,s,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let s=t[e][0];s[2]++,s[1]>0&&s[1]<=s[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],s=t.split(this._delimiter);return this._traverseToPath(this.listeners,s,i=>{e.push(i);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===_t.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=Y(arguments,this.options.meta);f(e.parseArgs)&&e.parseArgs(t,e);let s=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let i=[],o=[];if(this._traverseToPath(this.listeners,s,n=>{o.push(n);}),f(this._options.onBeforeExecuteListener)){let n=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(n))return n;if(n===false)throw new ht(t.type)}return f(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|w.Transformed),i.push(...this._executeListeners(o,t,e)),f(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,i,o),this._options.expandEmitResults&&Ct(i),i}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((s,i)=>{let o,n,p=l(a=>{clearTimeout(o),n&&n.off(),s(a);},"listener");e&&e>0&&(o=setTimeout(()=>{n&&n.off(),i(new Error("wait for event<"+t+"> is timeout"));},e)),n=this.on(t,p);})}scope(){let[t,e,s]=z(arguments,this.options.meta,this.options.context),i;return e?i=e:i=new zt,i.bind(this,t,s),i}};l(Jt,"FastEvent");function Qt(r){return r?typeof r=="object"&&"type"in r:false}l(Qt,"isFastEventMessage");function Zt(r){return r&&typeof r=="string"}l(Zt,"isString");function te(r){return typeof r=="function"&&(r.toString().startsWith("class ")||r.prototype?.constructor===r)}l(te,"isClass");function ee(r){return r?typeof r=="object"&&"__FastEvent__"in r:false}l(ee,"isFastEvent");var X=-1,Dt=class r extends V{constructor(e,s){super();this.store=e;this._options=Object.assign({id:e.id,mode:"push",local:[],remote:[],autostart:true,maxCacheSize:100,direction:"both",pathMap:{},peers:["*"],debug:false},s),typeof this._options.local=="string"&&(this._options.local=this._options.local.split(".")),typeof this._options.remote=="string"&&(this._options.remote=this._options.remote.split(".")),this.seq=++r.seq,this._options.autostart&&this.start();}seq;_options;peer;_operateCache=[];_subscribers=[];get id(){return this._options.id}get options(){return this._options}get transport(){return this._options.transport}get localEntry(){return this._options.local}get remoteEntry(){return this._options.remote}_onConnect(){try{let e=this.options.direction,s=this.options.mode;(s==="push"||s=="both")&&this._pushStore(!0),(s==="pull"||s=="both")&&this._pullStore(!0),e==="forward"&&(this._syncing=!0);}finally{this.flush();}}createRemoteOperate(e){return {id:this.id,type:e.type,path:e.path,parentPath:e.parentPath,value:I(e.value),indexs:e.indexs,flags:e.flags??0}}isPeer(e){let s=this._options.peers;return s.includes("*")?true:s.includes(e.id)}start(){if(this.syncing)return;let e;try{this._syncing=!0,this._subscribers.push(this.store.watch(this._onWatchStore.bind(this),{operates:"write"})),this._subscribers.push(this.transport.addReceiver(this.id,s=>{s.id!==this.id&&(!s.type.startsWith("$")&&(this.options.direction==="forward"||!this.isPeer(s))||this._onReceiveFromRemote(s));})),this._subscribers.push(this.transport.on("connect",this._onConnect.bind(this))),this._subscribers.push(this.transport.on("disconnect",this.stop.bind(this))),this._subscribers.push(this.transport.on("error",this.stop.bind(this))),this._subscribers.push(this.transport.on("timeout",this.stop.bind(this))),this.transport.connect();}catch(s){throw e=s,this.stop(),this.emit("error",s,true),s}finally{e||this.emit("start",void 0,true);}}stop(){if(this.syncing)try{this._subscribers.forEach(e=>e.off()),this._options.transport.connected&&this._options.transport.send({id:this.id,type:"$stop",path:[],value:void 0,flags:0});}finally{this.emit("stop",void 0,true),this._syncing=false;}}_onWatchStore(e){try{if(this._isPass(e.path,e.value)===!1||Math.abs(e.flags||0)===this.seq||this.options.direction==="backward")return;this._sendToRemote(e);}finally{this.options.debug===true&&this.emit("localOperate",e);}}_isPass(e,s){return _(this._options.filter)?this._options.filter(e,s):true}_sendToRemote(e){let s=this.options.local,i=this.options.remote;if(!at(this._options.local,e.path))return;if(typeof this._options.pathMap.toRemote=="function"){let n=this._options.pathMap.toRemote(e.path.slice(this._options.local.length),e.value);n&&(e.path=[...i,...n]);}else e.path=[...i,...e.path.slice(s.length)];let o=this.createRemoteOperate(e);this._sendOperate(o);}_onReceiveFromRemote(e){try{if(typeof this._options.onReceive=="function"&&this._options.onReceive.call(this,e)===!1)return;let s=e.type;if(s==="$stop")this.stop();else if(s==="$push")this._updateStore(e);else if(s==="$pull")this._sendStore(e);else if(s==="$update")this._updateStore(e);else if(s==="$ping")this._sendOperate({type:"$pong",value:e.value});else if(s==="$error"){let i=new j;i.operate=e,this.emit("error",i);}else this._applyOperate(e);}finally{this.options.debug===true&&this.emit("remoteOperate",e);}}_applyOperate(e){let{type:s,value:i,indexs:o}=e,n=this.store,p=this._mapPath(e.path,e.value,"toLocal");if(!p)return;e.path=p;let a=[...this.localEntry,...e.path.slice(this.options.remote.length)],u={flags:-this.seq};s==="set"||s==="update"?n.update(c=>{S(y(c,a,true))?b(c,a.concat("value"),i):b(c,a,i);},u):s==="delete"?n.update(c=>{b(c,a,void 0);},u):s==="insert"?n.update(c=>{let h=y(c,a);Array.isArray(o)&&h.splice(o[0],0,...i);},u):s==="remove"&&n.update(c=>{let h=y(c,a);Array.isArray(o)&&(o.length===0?h.splice(0):h.splice(o[0],o.length));},u);}flush(){this.transport.connected&&Promise.all(this._operateCache.map(e=>this.transport.send(e))).finally(()=>{this._operateCache=[];});}_assertConnected(e){return this.transport.connected?true:(this._operateCache.push(e),this._operateCache.length>this._options.maxCacheSize&&this._operateCache.shift(),false)}_sendOperate(e){if(this._assertConnected(e)){if(typeof this._options.onSend=="function"&&this._options.onSend.call(this,e)===false)return;this._options.transport.send(e);}}_getLocalSnap(){return this.store.getSnap({entry:this._options.local.join(".")})}push(){this._pushStore();}_pushStore(e=false){let s=this._getLocalSnap();if(typeof this._options.pathMap.toRemote=="function"){let i=new Map;return C(s,({value:o,path:n})=>{if(this._isPass(n,o)===false)return;let p=Array.isArray(o)?[]:typeof o=="object"?{}:o,a=this._mapPath(n,p,"toRemote");if(a){i.set(JSON.stringify(n),JSON.stringify(a));let u={type:"set",path:[...this.options.remote,...a],value:p};e&&(u.flags=X),this._sendOperate(u);}}),i}else this._sendOperate({id:this.id,type:"$push",path:this.options.remote,value:s,flags:e?X:0});}_sendStore(e){this._sendOperate({id:this.id,type:"$update",path:[],value:this.store.getSnap({entry:e.path.join(".")}),flags:this.seq});}_updateStore(e){try{let i=this.store,o=-this.seq;if(typeof this._options.pathMap.toLocal=="function")C(e.value,({value:n,path:p})=>{if(this._isPass(p,n)===!1)return;let a=Array.isArray(n)?[]:typeof n=="object"?{}:n,u=this._mapPath(p,a,"toLocal");u&&i.update(c=>{b(c,[...this.localEntry,...u],a);},{flags:o});});else {let n=[...this.localEntry,...e.path||[]];i.update(p=>{b(p,n,e.value);},{flags:o});}}catch(i){this.emit("error",i);}finally{this._syncing===false&&(this._syncing=true,this.emit("syncing",e.id,true));}}_pullStore(e=false){this._sendOperate({id:this.id,type:"$pull",path:this.options.remote,value:void 0,flags:e?X:0});}pull(){this._pullStore();}_mapPath(e,s,i){return this._options.pathMap&&_(this._options.pathMap[i])?this._options.pathMap[i](e,s):e}toString(){return `AutoStoreSyncer(${this.id})`}};exports.AutoStoreSyncError=j;exports.AutoStoreSyncTransportBase=T;exports.AutoStoreSyncer=Dt;exports.AutoStoreSyncerBase=V;exports.LocalTransport=Z;exports.SYNC_INIT_FLAG=X;return exports;})({});//# sourceMappingURL=index.lite.global.js.map | ||
| //# sourceMappingURL=index.lite.global.js.map |
+3
-3
| { | ||
| "name": "@autostorejs/syncer", | ||
| "version": "4.0.13", | ||
| "version": "4.1.0", | ||
| "main": "./dist/index.js", | ||
@@ -21,3 +21,3 @@ "repository": { | ||
| "peerDependencies": { | ||
| "autostore": "^4.0.13" | ||
| "autostore": "^4.1.0" | ||
| }, | ||
@@ -35,3 +35,3 @@ "dependencies": { | ||
| "@types/bun": "^1.3.7", | ||
| "autostore": "^4.0.13", | ||
| "autostore": "^4.1.0", | ||
| "tsup": "^8.5.1", | ||
@@ -38,0 +38,0 @@ "typescript": "^5.9.3", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
1361012
0.02%