@fluixi/reactive 1.0.0-alpha.63 → 1.0.0-alpha.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- import{isObject as Rt}from"@fluixi/utils/object";import{isFunction as Xe}from"@fluixi/utils/functions";var fe=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if(Xe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(Rt(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if(Xe(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var be=class extends fe{constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ue=class extends be{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof be?r=t:r=new Ue(t,n,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};import{isPromise as Pe}from"@fluixi/utils";var me=!1,At=Symbol.for("signal"),Ct=Symbol.for("memo"),_t=Symbol.for("resource");function De(e){return typeof e=="function"&&e[At]===!0}function Et(e){return typeof e=="function"&&e[Ct]===!0}function kt(e){return typeof e=="function"&&e[_t]===!0}function Pt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ft(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ut(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Qe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Qe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Dt="__fluixi_signal_next_state__",qt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[Dt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:qt,onSuspend:null,onError:null};var Ze=0,et=1,de=2,xe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let t=c.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},Se=class extends xe{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(de);qe(this)}}peek(){return this._value}},ie=class extends xe{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=de;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===et&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===de)break}(this.state===de||!this._initialized)&&this.recompute(),this.state=Ze}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=n,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(de);qe(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Ze;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(et);qe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function qe(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var ge=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function tt(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function nt(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rt(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function Ie(){return c.owner}function Oe(e,t){let n=c.owner;c.owner=e;try{return t()}finally{c.owner=n}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function we(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)we(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function pe(e){let t=nt(c.owner);c.owner&&(c.owner.owned??=[]).push(t);let n=c.owner;c.owner=t;try{return e(()=>we(t))}finally{c.owner=n}}function ot(e){c.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Mt(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ne)))}function Ne(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=c.queue;c.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{c.flushing=!1}}function st(){c.batchDepth===0&&Ne()}var Me=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=nt(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ie(()=>{we(this.owner,!1),Oe(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new ge(()=>Mt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&c.onSuspend){c.onSuspend(t,this.owner);return}if(c.onError&&c.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),we(this.owner))}};function it(e){let t=new Me(e);return()=>t.dispose()}function It(e){return!!e&&typeof e.then=="function"}ot(()=>{});var ut=Symbol.for("signal"),Nt=Symbol.for("memo"),Lt=Symbol.for("signal-node");function I(e,t){let n=new Se(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let u=typeof s=="function"?s(n.peek()):s;return n.set(u),st(),u});return Object.defineProperty(o,ut,{value:!0,enumerable:!0}),Object.defineProperty(o,Lt,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function x(e,t,n){let o=t,r=Ie(),s=new ie(()=>Oe(r,()=>{try{return o=e(o)}catch(a){if(It(a))return rt(a),o;throw a}}),{equals:n?.equals}),u=(()=>s.get());return Object.defineProperty(u,ut,{value:!0,enumerable:!0}),Object.defineProperty(u,Nt,{value:!0,enumerable:!0}),u}function Te(e,t){let n=t;return it(()=>{n=e(n)})}function Re(e){return tt(e)}function Bt(e,t=(n,o)=>n===o){let n=new Map;return Te(()=>{let o=e();for(let[r,s]of n){let[u,a]=s,i=t(r,o);u()!==i&&a(i)}}),o=>{let r=n.get(o);if(!r){let[s,u]=I(!1);r=[s,u],n.set(o,r);let a=e();u(t(o,a))}return r[0]()}}function Vt(e,t){let[n,o]=I(e(),t);return Te(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function jt(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,r.length>0){let s=r[r.length-1];typeof s=="object"&&s&&!s.tagName&&s.target&&s.target.tagName&&(s=s.target),s&&typeof s=="object"&&s.tagName&&(s.tagName.toLowerCase()==="input"||s.tagName.toLowerCase()==="textarea")&&s.focus()}e(...r)},t)};return ee(()=>{n!==void 0&&clearTimeout(n)}),o}function Ae(e){if(typeof e=="function"&&!e.length){let t=e();return De(t)?t:Ae(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Ae(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function at(e){let t=x(e);return x(()=>Ae(t()))}var Le=null;function Gt(e){Le=e}function Ce(e){Le&&Le(e)}var Be=null;function Kt(e){Be=e}function ct(e){return Be?Be(e):void 0}var Ve=null;function $t(e){Ve=e}function lt(){return Ve?Ve():void 0}var je=null;function Wt(e){je=e}function ft(e,t){je&&je(e,t)}var ze=Symbol.for("signal"),zt=Symbol.for("memo"),Ht=Symbol.for("resource"),dt=Symbol("fluixi-proxy"),ht=Symbol.for("signal-node"),G=0,he=1,$=2,K=3,f=null,v=null,l=null,_e=null,Ee=0,Yt=!1,Ge=!1,ue=0,Jt=1e6,P=new WeakMap,M=null;var Xt=null,Qt=new Map,Zt=0,Ke={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Ln(e){f=e,Ke.owner=e,Ke.context=e}function Bn(){return Ke}function en(){return`node_${++Zt}_${Date.now()}`}function tn(e){!1}function vt(e,t,n){let o={id:en(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return tn(o),o}function yt(e,t){return e===t}function He(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var $e=null,We=null;function bt(){if(!$e){let[e,t]=q(!1);$e=e,We=t}}function mt(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=l;v=null,l=[],e.accessor(),v=t;let o=l;if(l=n,o.length>0){let r=l;Fe(o),l=r}}}function pt(e,t){for(let n=0;n<e.length;n++)t(e[n])}function q(e,t){let n=e;typeof n=="object"&&n&&dt in n&&delete n[dt];let o=vt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[u,a];P.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=P.get(r);d&&!d.has(i)&&d.add(i)}return n}function a(i){let d=typeof i=="function"?i(n):i,y=o.equals||yt;if(t?.equals===!1||!y(n,d)){n=d,o.value=d,o.version++,o.updated=Date.now();let g=P.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===K&&p===v)){if(b&&!p.pure){C===G&&(p.state=he,Yt&&(l!==null&&l.indexOf(p)===-1?l.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=$,C===G||C===he?w.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let k=P.get(p.accessor);k&&pt(Array.from(k),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;pt(S,E);for(let p of w)mt(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ae(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,ze,{value:!0,enumerable:!0}),Object.defineProperty(u,ht,{value:o,enumerable:!1}),r}function ae(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),Ye(o,t),()=>J(o)}function Ye(e,t){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,o=f;if(v=e,f=e,Ee++,Ee>Jt)throw Ee=0,v=n,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=K;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=n,f=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===G)&&(e.state===$||e.state===he||e.state===K)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)J(e.owned[t]);e.owned=null}e.renderEffect?gt(e):Ye(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=P.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)J(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function jn(e,t,n){let o=vt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;P.has(a)||P.set(a,new Set);let i=P.get(a);i&&i.add(v)}if(r.state!==G){if(r.sources){for(let d of r.sources){let y=P.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=K;try{let d=r.fn(r.value),y=o.equals||yt;if(n?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=P.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let k=b.state;if(k!==K){if(C&&!b.pure){k===G&&(b.state=he,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=$,k===G||k===he?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=P.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)mt(b)}}r.state===K&&(r.state=G)}catch(d){if(Pe(d)){let y=O&&N(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}He(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,P.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ae(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,ze,{value:!0,enumerable:!0}),Object.defineProperty(s,zt,{value:!0,enumerable:!0}),Object.defineProperty(s,ht,{value:o,enumerable:!1}),s}function Fe(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);l=[];let o=0;for(;o<t.length;){let r=t[o++],s=P.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?t.indexOf(a)===-1&&t.push(a):(a.computed||!a.pure)&&n.indexOf(a)===-1&&n.push(a)}l=null;for(let r of n)(r.computed||!r.pure)&&ve(r)}function F(e){if(l&&ue>0)return e();if(l&&ue===0){let t=l,n=[];l=n,ue++;let o;try{o=e()}finally{ue--,l=t}let r=l;return Fe(n),l=r,o}ue++,l=[],_e=[];try{return e()}finally{ue--,xt()}}function xt(){if(!Ge){Ge=!0,Ee=0;try{for(;l&&l.length>0;){let e=l;l=null,Fe(e)}if(l=null,_e){let e=_e;_e=null;for(let t=0;t<e.length;t++)ve(e[t])}}finally{Ge=!1}}}function Gn(e){let t={owned:null,cleanups:null,contexts:null,owner:f},n=v;v=null;let o=f;f=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)J(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{f=o,v=n}}function W(e){let t=v;v=null;try{return e()}finally{v=t}}function ke(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function Kn(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:u}=n,a=lt(),i=a!==void 0?ct(a):void 0,d=i!==void 0,[y,T]=q(i!==void 0?i.value:n.initialValue,{equals:!1}),[g,S]=q(void 0,{equals:!1}),[w,m]=q(i!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),k=Symbol(),_=k,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${u}):`,L)}},ce=ae(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=k,F(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=z;if(z=!1,_!==k&&A===_&&!L)return;if(_=A,d){d=!1;return}let B=!1;ke(()=>B=!0);let le=W(w),re=W(y),Q=le==="ready"||le==="refreshing";F(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let V=r(A,{value:re,refetching:Q});if(Pe(V)){p(V),Ce(V),V.then(h=>{B||(a!==void 0&&ft(a,h),F(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{B||F(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{B||F(()=>{S(h),m("errored"),p(void 0)})});let ye=O&&N(O);ye&&(ye.increment(),V.finally(()=>ye.decrement()))}else{if(B)return;F(()=>{T(()=>V),m("ready"),p(void 0)})}}catch(V){if(B)return;F(()=>{S(V),m("errored"),p(void 0)})}});ke(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let L=E();if(L)throw L}return y()});return Object.defineProperty(Y,Ht,{value:!0,enumerable:!0}),Object.defineProperty(Y,ze,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function $n(){return f}function Wn(e,t){let n=f,o=v;f=e,v=null;try{return t()}finally{f=n,v=o}}function St(e){let t=Symbol("context"),n=nn(t);return{id:t,Provider:n,defaultValue:e}}function nn(e){return t=>{let n=f;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return on(()=>{o=W(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),at(()=>t.children)})}),o}}function N(e){let t=f;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function zn(){return new Promise(e=>{queueMicrotask(()=>{xt(),e()})})}function rn(e){if(M&&M.running)return e(),M.done;bt();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};M=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,We(!1),r.length&&F(()=>{for(let s of r)s.state=$,ve(s)}),t()}),n):(M=null,t(),n)}function Hn(){return bt(),[$e,rn]}function Yn(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):W(()=>t(u,s))}}function on(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),gt(o),()=>J(o)}function gt(e){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,n=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=K;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=t,f=n;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;Fe(r),l=s}}}function Jn(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):Ye(o,t)}var O;function wt(){return O||(O=St())}var Tt;function Xn(){return Tt||(Tt=St())}function Qn(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=$,ve(n)}function Zn(e){let t=O&&N(O);t&&t.inFallback()?ae(()=>{t.inFallback()||e()}):e()}function er(e){Xt=e}function tr(e){let t=O&&N(O);return t&&(t.increment(),e.finally(()=>t.decrement())),e}function sr(e,t,n){return x(()=>t(e()),void 0,n)}function ir(e,t,n){return x(()=>e().filter(t),void 0,n)}function ur(e,t,n,o){return x(()=>e().reduce(t,n),void 0,o)}function ar(e,t,n){return x(()=>e().find(t),void 0,n)}function cr(e,t,n){return x(()=>e().some(t),void 0,n)}function lr(e,t,n){return x(()=>e().every(t),void 0,n)}function fr(e,t,n){return x(()=>[...e()].sort(t),void 0,n)}function dr(e,t){return x(()=>[...new Set(e())],void 0,t)}function pr(e,t,n){return x(()=>{let o=e.map(r=>r());return t(o)},void 0,n)}function Tr(...e){return new Z(t=>{let n=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{t.next(n())}):typeof r!="function"?r.subscribe(()=>{t.next(n())}):Te(()=>{t.next(n())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function hr(e,t,n){return x(()=>e()||t(),void 0,n)}function vr(e,t,n,o){return x(()=>n(e(),t()),void 0,o)}function yr(e,t,n){return x(()=>t(e()),void 0,{equals:n,internal:!0})}function br(e,t,n){return x(()=>{let o=e(),r={};for(let s of t)r[s]=o[s];return r},void 0,n)}function mr(e,t,n){return x(()=>{let r={...e()};for(let s of t)delete r[s];return r},void 0,n)}function xr(e,t,n,o){return x(()=>e()?t():n(),void 0,o)}function Sr(e,t,n){return x(()=>e()?t():void 0,void 0,n)}function gr(e,t,n){let[o,r]=I(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),t)}),o}function wr(e,t,n){let[o,r]=I(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=t?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},t-(i-s)))}),o}function Or(e){let t=e;for(;typeof t=="function";)t=t();return t}var ne=new Map,te=new Map,sn=0,un=Symbol.for("signal"),an=Symbol.for("resource");function Cr(e,t,n={}){let o,r,s;typeof t=="function"?(o=e,r=t,s=n):(o=()=>!0,r=e,s=t??n);let{ttl:u=1/0,name:a=`_auto_${sn++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=q(void 0,{equals:!1}),[w,m]=q("unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),[k,_]=q(!1),[z,H]=q(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function L(h,U,D,j){if(te.has(U)){te.get(U).then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)}),D||C(te.get(U));return}let oe=Promise.resolve(r(h)).then(R=>(ne.set(U,{value:R,timestamp:Date.now()}),te.delete(U),R),R=>{throw te.delete(U),R});if(te.set(U,oe),!D){Ce(oe),C(oe);let R=re&&N(re);R&&(R.increment(),oe.finally(()=>R.decrement()))}oe.then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)})}function B(h,U){F(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){F(()=>{p(h),m("errored"),C(void 0)})}let re;ae(()=>{re===void 0&&(re=wt());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,F(()=>{m("unresolved"),C(void 0),p(void 0)});return}let U=Y,D=A;Y=!1,A=!1;let j=y(h);D&&ne.delete(j);let oe=X===ce||h!==X;X=h;let R=!1;ke(()=>{R=!0});let se=ne.get(j);if(se&&T(se)&&!U&&!D){(W(w)!=="ready"||W(g)!==se.value)&&F(()=>{S(()=>se.value),m("ready"),_(!1),p(void 0)});return}if(se&&i&&!D){F(()=>{S(()=>se.value),m("ready"),_(!0),p(void 0),C(void 0)}),L(h,j,!0,()=>R);return}let Je=W(w),Ot=Je==="ready"||Je==="refreshing";F(()=>{m(Ot?"refreshing":"pending"),p(void 0),_(!1)}),L(h,j,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let D=b();if(D)throw D}return g()});return Object.defineProperty(Q,an,{value:!0,enumerable:!0}),Object.defineProperty(Q,un,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:k}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=W(o);h!=null&&h!==!1&&ne.delete(y(h)),A=!0,H(U=>U+1)}}]}function _r(e){let t=`${e}:`;for(let n of ne.keys())n.startsWith(t)&&ne.delete(n)}function Er(){ne.clear(),te.clear()}function Fr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;pe(m=>{S=m;let[E,p]=I(i);g=p,T=t(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function Ur(e,t,n,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Re(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=t(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;pe(p=>{E=p;let[b,C]=I(T);m=C;let k=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=n(k,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function Dr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];pe(S=>{T=S;let[w,m]=I(g);y=m,d=t(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}export{zt as $MEMO,dt as $PROXY,Ht as $RESOURCE,ze as $SIGNAL,me as __DEV__,F as batch,Er as clearAllCachedResources,_r as clearCachedResourceNamespace,pr as combineSignal,Tr as combineSignals,Cr as createCachedResource,Jn as createComputed,St as createContext,jt as createDebounce,Vt as createDeferred,ae as createEffect,jn as createMemo,nn as createProvider,on as createRenderEffect,Kn as createResource,Gn as createRoot,Bt as createSelector,q as createSignal,gr as debounceSignal,dr as distinctSignal,lr as everySignal,ir as filterSignal,ar as findSignal,zn as flush,$n as getOwner,ct as getServerData,Bn as getSharedConfig,wt as getSuspenseContext,Xn as getSuspenseListContext,Sr as guardSignal,Dr as indexArray,Pt as isComponent,Et as isMemo,Ut as isProvider,kt as isResource,De as isSignal,Ft as isSuspense,Ur as keyArray,Qe as makeArrayFlat,Fr as mapArray,sr as mapSignal,hr as mergeSignal,lt as nextResourceId,mr as omitSignal,Yn as on,ke as onCleanup,Zn as onResolve,br as pickSignal,at as readChildren,Or as readSignal,ur as reduceSignal,ft as reportResourceData,Qn as resumeEffects,Wn as runWithOwner,yr as selectSignal,Ln as setOwner,Wt as setResourceDataSink,$t as setResourceIdSource,Gt as setResourceTracker,er as setScheduler,Kt as setServerDataGetter,Ke as sharedConfig,cr as someSignal,fr as sortSignal,rn as startTransition,wr as throttleSignal,tr as trackPromise,Ce as trackResourcePromise,W as untrack,N as useContext,Hn as useTransition,xr as whenSignal,vr as zipSignal};
1
+ import{isObject as An}from"@fluixi/utils/object";import{isFunction as Xe}from"@fluixi/utils/functions";var fe=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if(Xe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(An(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if(Xe(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var be=class extends fe{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ue=class extends be{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof be?r=n:r=new Ue(n,t,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};import{isPromise as Pe}from"@fluixi/utils";var me=!1,Cn=Symbol.for("signal"),_n=Symbol.for("memo"),En=Symbol.for("resource");function De(e){return typeof e=="function"&&e[Cn]===!0}function kn(e){return typeof e=="function"&&e[_n]===!0}function Pn(e){return typeof e=="function"&&e[En]===!0}function Fn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Un(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Dn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Qe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Qe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var qn="__fluixi_signal_next_state__",Mn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[qn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Mn,onSuspend:null,onError:null};var Ze=0,en=1,de=2,xe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let n=c.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},Se=class extends xe{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(de);qe(this)}}peek(){return this._value}},ie=class extends xe{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=de;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===en&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===de)break}(this.state===de||!this._initialized)&&this.recompute(),this.state=Ze}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=t,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(de);qe(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Ze;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(en);qe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function qe(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var ge=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function nn(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function tn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rn(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function Ie(){return c.owner}function Oe(e,n){let t=c.owner;c.owner=e;try{return n()}finally{c.owner=t}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function we(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)we(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function pe(e){let n=tn(c.owner);c.owner&&(c.owner.owned??=[]).push(n);let t=c.owner;c.owner=n;try{return e(()=>we(n))}finally{c.owner=t}}function on(e){c.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function In(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ne)))}function Ne(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=c.queue;c.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{c.flushing=!1}}function sn(){c.batchDepth===0&&Ne()}var Me=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=tn(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ie(()=>{we(this.owner,!1),Oe(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new ge(()=>In(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&c.onSuspend){c.onSuspend(n,this.owner);return}if(c.onError&&c.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),we(this.owner))}};function un(e){let n=new Me(e);return()=>n.dispose()}function Nn(e){return!!e&&typeof e.then=="function"}on(()=>{});var an=Symbol.for("signal"),Ln=Symbol.for("memo"),Bn=Symbol.for("signal-node");function I(e,n){let t=new Se(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),sn(),u});return Object.defineProperty(o,an,{value:!0,enumerable:!0}),Object.defineProperty(o,Bn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function x(e,n,t){let o=n,r=Ie(),s=new ie(()=>Oe(r,()=>{try{return o=e(o)}catch(a){if(Nn(a))return rn(a),o;throw a}}),{equals:t?.equals}),u=(()=>s.get());return Object.defineProperty(u,an,{value:!0,enumerable:!0}),Object.defineProperty(u,Ln,{value:!0,enumerable:!0}),u}function Te(e,n){let t=n;return un(()=>{t=e(t)})}function Re(e){return nn(e)}function Vn(e,n=(t,o)=>t===o){let t=new Map;return Te(()=>{let o=e();for(let[r,s]of t){let[u,a]=s,i=n(r,o);u()!==i&&a(i)}}),o=>{let r=t.get(o);if(!r){let[s,u]=I(!1);r=[s,u],t.set(o,r);let a=e();u(n(o,a))}return r[0]()}}function jn(e,n){let[t,o]=I(e(),n);return Te(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function Gn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ee(()=>{t!==void 0&&clearTimeout(t)}),o}function Ae(e){if(typeof e=="function"&&!e.length){let n=e();return De(n)?n:Ae(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=Ae(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function cn(e){let n=x(e);return x(()=>Ae(n()))}var Le=null;function Kn(e){Le=e}function Ce(e){Le&&Le(e)}var Be=null;function $n(e){Be=e}function ln(e){return Be?Be(e):void 0}var Ve=null;function Wn(e){Ve=e}function fn(){return Ve?Ve():void 0}var je=null;function zn(e){je=e}function dn(e,n){je&&je(e,n)}var ze=Symbol.for("signal"),Hn=Symbol.for("memo"),Yn=Symbol.for("resource"),pn=Symbol("fluixi-proxy"),vn=Symbol.for("signal-node"),G=0,he=1,$=2,K=3,f=null,v=null,l=null,_e=null,Ee=0,Jn=!1,Ge=!1,ue=0,Xn=1e6,P=new WeakMap,M=null;var Qn=null,Zn=new Map,et=0,Ke={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Lt(e){f=e,Ke.owner=e,Ke.context=e}function Bt(){return Ke}function nt(){return`node_${++et}_${Date.now()}`}function tt(e){!1}function yn(e,n,t){let o={id:nt(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return tt(o),o}function bn(e,n){return e===n}function He(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var $e=null,We=null;function mn(){if(!$e){let[e,n]=q(!1);$e=e,We=n}}function xn(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let n=v,t=l;v=null,l=[],e.accessor(),v=n;let o=l;if(l=t,o.length>0){let r=l;Fe(o),l=r}}}function Tn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function q(e,n){let t=e;typeof t=="object"&&t&&pn in t&&delete t[pn];let o=yn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[u,a];P.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=P.get(r);d&&!d.has(i)&&d.add(i)}return t}function a(i){let d=typeof i=="function"?i(t):i,y=o.equals||bn;if(n?.equals===!1||!y(t,d)){t=d,o.value=d,o.version++,o.updated=Date.now();let g=P.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===K&&p===v)){if(b&&!p.pure){C===G&&(p.state=he,Jn&&(l!==null&&l.indexOf(p)===-1?l.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=$,C===G||C===he?w.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let k=P.get(p.accessor);k&&Tn(Array.from(k),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;Tn(S,E);for(let p of w)xn(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ae(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,ze,{value:!0,enumerable:!0}),Object.defineProperty(u,vn,{value:o,enumerable:!1}),r}function ae(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),Ye(o,n),()=>J(o)}function Ye(e,n){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,o=f;if(v=e,f=e,Ee++,Ee>Xn)throw Ee=0,v=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=K;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=t,f=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===G)&&(e.state===$||e.state===he||e.state===K)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)J(e.owned[n]);e.owned=null}e.renderEffect?wn(e):Ye(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=P.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)J(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function jt(e,n,t){let o=yn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;P.has(a)||P.set(a,new Set);let i=P.get(a);i&&i.add(v)}if(r.state!==G){if(r.sources){for(let d of r.sources){let y=P.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=K;try{let d=r.fn(r.value),y=o.equals||bn;if(t?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=P.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let k=b.state;if(k!==K){if(C&&!b.pure){k===G&&(b.state=he,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=$,k===G||k===he?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=P.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)xn(b)}}r.state===K&&(r.state=G)}catch(d){if(Pe(d)){let y=O&&N(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}He(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,P.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ae(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,ze,{value:!0,enumerable:!0}),Object.defineProperty(s,Hn,{value:!0,enumerable:!0}),Object.defineProperty(s,vn,{value:o,enumerable:!1}),s}function Fe(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);l=[];let o=0;for(;o<n.length;){let r=n[o++],s=P.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?n.indexOf(a)===-1&&n.push(a):(a.computed||!a.pure)&&t.indexOf(a)===-1&&t.push(a)}l=null;for(let r of t)(r.computed||!r.pure)&&ve(r)}function F(e){if(l&&ue>0)return e();if(l&&ue===0){let n=l,t=[];l=t,ue++;let o;try{o=e()}finally{ue--,l=n}let r=l;return Fe(t),l=r,o}ue++,l=[],_e=[];try{return e()}finally{ue--,Sn()}}function Sn(){if(!Ge){Ge=!0,Ee=0;try{for(;l&&l.length>0;){let e=l;l=null,Fe(e)}if(l=null,_e){let e=_e;_e=null;for(let n=0;n<e.length;n++)ve(e[n])}}finally{Ge=!1}}}function Gt(e){let n={owned:null,cleanups:null,contexts:null,owner:f},t=v;v=null;let o=f;f=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)J(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{f=o,v=t}}function W(e){let n=v;v=null;try{return e()}finally{v=n}}function ke(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function Kt(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:u}=t,a=fn(),i=a!==void 0?ln(a):void 0,d=i!==void 0,[y,T]=q(i!==void 0?i.value:t.initialValue,{equals:!1}),[g,S]=q(void 0,{equals:!1}),[w,m]=q(i!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),k=Symbol(),_=k,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${u}):`,L)}},ce=ae(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=k,F(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=z;if(z=!1,_!==k&&A===_&&!L)return;if(_=A,d){d=!1;return}let B=!1;ke(()=>B=!0);let le=W(w),re=W(y),Q=le==="ready"||le==="refreshing";F(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let V=r(A,{value:re,refetching:Q});if(Pe(V)){p(V),Ce(V),V.then(h=>{B||(a!==void 0&&dn(a,h),F(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{B||F(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{B||F(()=>{S(h),m("errored"),p(void 0)})});let ye=O&&N(O);ye&&(ye.increment(),V.finally(()=>ye.decrement()))}else{if(B)return;F(()=>{T(()=>V),m("ready"),p(void 0)})}}catch(V){if(B)return;F(()=>{S(V),m("errored"),p(void 0)})}});ke(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let L=E();if(L)throw L}return y()});return Object.defineProperty(Y,Yn,{value:!0,enumerable:!0}),Object.defineProperty(Y,ze,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function $t(){return f}function Wt(e,n){let t=f,o=v;f=e,v=null;try{return n()}finally{f=t,v=o}}function gn(e){let n=Symbol("context"),t=rt(n);return{id:n,Provider:t,defaultValue:e}}function rt(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return st(()=>{o=W(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),cn(()=>n.children)})}),o}}function N(e){let n=f;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function zt(){return new Promise(e=>{queueMicrotask(()=>{Sn(),e()})})}function ot(e){if(M&&M.running)return e(),M.done;mn();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};M=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,We(!1),r.length&&F(()=>{for(let s of r)s.state=$,ve(s)}),n()}),t):(M=null,n(),t)}function Ht(){return mn(),[$e,ot]}function Yt(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):W(()=>n(u,s))}}function st(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),wn(o),()=>J(o)}function wn(e){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,t=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=K;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=n,f=t;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;Fe(r),l=s}}}function Jt(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):Ye(o,n)}var O;function On(){return O||(O=gn())}var hn;function Xt(){return hn||(hn=gn())}function Qt(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=$,ve(t)}function Zt(e){let n=O&&N(O);n&&n.inFallback()?ae(()=>{n.inFallback()||e()}):e()}function er(e){Qn=e}function nr(e){let n=O&&N(O);return n&&(n.increment(),e.finally(()=>n.decrement())),e}function sr(e,n,t){return x(()=>n(e()),void 0,t)}function ir(e,n,t){return x(()=>e().filter(n),void 0,t)}function ur(e,n,t,o){return x(()=>e().reduce(n,t),void 0,o)}function ar(e,n,t){return x(()=>e().find(n),void 0,t)}function cr(e,n,t){return x(()=>e().some(n),void 0,t)}function lr(e,n,t){return x(()=>e().every(n),void 0,t)}function fr(e,n,t){return x(()=>[...e()].sort(n),void 0,t)}function dr(e,n){return x(()=>[...new Set(e())],void 0,n)}function pr(e,n,t){return x(()=>{let o=e.map(r=>r());return n(o)},void 0,t)}function Tr(...e){return new Z(n=>{let t=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{n.next(t())}):typeof r!="function"?r.subscribe(()=>{n.next(t())}):Te(()=>{n.next(t())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function hr(e,n,t){return x(()=>e()||n(),void 0,t)}function vr(e,n,t,o){return x(()=>t(e(),n()),void 0,o)}function yr(e,n,t){return x(()=>n(e()),void 0,{equals:t,internal:!0})}function br(e,n,t){return x(()=>{let o=e(),r={};for(let s of n)r[s]=o[s];return r},void 0,t)}function mr(e,n,t){return x(()=>{let r={...e()};for(let s of n)delete r[s];return r},void 0,t)}function xr(e,n,t,o){return x(()=>e()?n():t(),void 0,o)}function Sr(e,n,t){return x(()=>e()?n():void 0,void 0,t)}function gr(e,n,t){let[o,r]=I(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),n)}),o}function wr(e,n,t){let[o,r]=I(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=n?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},n-(i-s)))}),o}function Or(e){let n=e;for(;typeof n=="function";)n=n();return n}var te=new Map,ne=new Map,it=0,ut=Symbol.for("signal"),at=Symbol.for("resource");function Cr(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:u=1/0,name:a=`_auto_${it++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=q(void 0,{equals:!1}),[w,m]=q("unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),[k,_]=q(!1),[z,H]=q(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function L(h,U,D,j){if(ne.has(U)){ne.get(U).then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)}),D||C(ne.get(U));return}let oe=Promise.resolve(r(h)).then(R=>(te.set(U,{value:R,timestamp:Date.now()}),ne.delete(U),R),R=>{throw ne.delete(U),R});if(ne.set(U,oe),!D){Ce(oe),C(oe);let R=re&&N(re);R&&(R.increment(),oe.finally(()=>R.decrement()))}oe.then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)})}function B(h,U){F(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){F(()=>{p(h),m("errored"),C(void 0)})}let re;ae(()=>{re===void 0&&(re=On());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,F(()=>{m("unresolved"),C(void 0),p(void 0)});return}let U=Y,D=A;Y=!1,A=!1;let j=y(h);D&&te.delete(j);let oe=X===ce||h!==X;X=h;let R=!1;ke(()=>{R=!0});let se=te.get(j);if(se&&T(se)&&!U&&!D){(W(w)!=="ready"||W(g)!==se.value)&&F(()=>{S(()=>se.value),m("ready"),_(!1),p(void 0)});return}if(se&&i&&!D){F(()=>{S(()=>se.value),m("ready"),_(!0),p(void 0),C(void 0)}),L(h,j,!0,()=>R);return}let Je=W(w),Rn=Je==="ready"||Je==="refreshing";F(()=>{m(Rn?"refreshing":"pending"),p(void 0),_(!1)}),L(h,j,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let D=b();if(D)throw D}return g()});return Object.defineProperty(Q,at,{value:!0,enumerable:!0}),Object.defineProperty(Q,ut,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:k}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=W(o);h!=null&&h!==!1&&te.delete(y(h)),A=!0,H(U=>U+1)}}]}function _r(e){let n=`${e}:`;for(let t of te.keys())t.startsWith(n)&&te.delete(t)}function Er(){te.clear(),ne.clear()}function Fr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;pe(m=>{S=m;let[E,p]=I(i);g=p,T=n(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function Ur(e,n,t,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Re(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=n(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;pe(p=>{E=p;let[b,C]=I(T);m=C;let k=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=t(k,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function Dr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];pe(S=>{T=S;let[w,m]=I(g);y=m,d=n(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}export{Hn as $MEMO,pn as $PROXY,Yn as $RESOURCE,ze as $SIGNAL,me as __DEV__,F as batch,Er as clearAllCachedResources,_r as clearCachedResourceNamespace,pr as combineSignal,Tr as combineSignals,Cr as createCachedResource,Jt as createComputed,gn as createContext,Gn as createDebounce,jn as createDeferred,ae as createEffect,jt as createMemo,rt as createProvider,st as createRenderEffect,Kt as createResource,Gt as createRoot,Vn as createSelector,q as createSignal,gr as debounceSignal,dr as distinctSignal,lr as everySignal,ir as filterSignal,ar as findSignal,zt as flush,$t as getOwner,ln as getServerData,Bt as getSharedConfig,On as getSuspenseContext,Xt as getSuspenseListContext,Sr as guardSignal,Dr as indexArray,Fn as isComponent,kn as isMemo,Dn as isProvider,Pn as isResource,De as isSignal,Un as isSuspense,Ur as keyArray,Qe as makeArrayFlat,Fr as mapArray,sr as mapSignal,hr as mergeSignal,fn as nextResourceId,mr as omitSignal,Yt as on,ke as onCleanup,Zt as onResolve,br as pickSignal,cn as readChildren,Or as readSignal,ur as reduceSignal,dn as reportResourceData,Qt as resumeEffects,Wt as runWithOwner,yr as selectSignal,Lt as setOwner,zn as setResourceDataSink,Wn as setResourceIdSource,Kn as setResourceTracker,er as setScheduler,$n as setServerDataGetter,Ke as sharedConfig,cr as someSignal,fr as sortSignal,ot as startTransition,wr as throttleSignal,nr as trackPromise,Ce as trackResourcePromise,W as untrack,N as useContext,Ht as useTransition,xr as whenSignal,vr as zipSignal};
@@ -1 +1 @@
1
- "use strict";var oe=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var ot=Object.prototype.hasOwnProperty;var st=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},it=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rt(t))!ot.call(e,s)&&s!==n&&oe(e,s,{get:()=>t[s],enumerable:!(r=nt(t,s))||r.enumerable});return e};var ut=e=>it(oe({},"__esModule",{value:!0}),e);var bt={};st(bt,{$PROXY:()=>gt,$SIGNAL:()=>St,Signal:()=>et,SuspenseContext:()=>re,__DEV__:()=>X,batch:()=>S,createComputed:()=>Ae,createContext:()=>q,createDebounce:()=>$e,createDeferred:()=>ze,createEffect:()=>E,createErrorBoundary:()=>Qe,createMemo:()=>w,createRenderEffect:()=>Pe,createResource:()=>Ke,createRoot:()=>O,createSelector:()=>We,createSignal:()=>d,createSuspenseBoundary:()=>Ye,flush:()=>qe,getOwner:()=>F,getServerData:()=>Z,indexArray:()=>mt,isComponent:()=>Ue,isMemo:()=>Me,isOwnerDisposed:()=>ge,isProvider:()=>Le,isResource:()=>Ne,isSignal:()=>J,isSuspense:()=>Be,keyArray:()=>yt,makeArrayFlat:()=>le,mapArray:()=>ht,nextResourceId:()=>ee,on:()=>Ie,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>Ze,provideSuspense:()=>Xe,readChildren:()=>He,reportResourceData:()=>te,runWithOwner:()=>M,setOwner:()=>ue,setResourceDataSink:()=>Ge,setResourceIdSource:()=>je,setResourceTracker:()=>Fe,setServerDataGetter:()=>Ve,startTransition:()=>ce,trackResourcePromise:()=>Q,untrack:()=>g,useContext:()=>be,useTransition:()=>De});module.exports=ut(bt);var at="__fluixi_signal_next_state__",ct=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[at]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:ct,onSuspend:null,onError:null};var ve=0,we=1,B=2,z=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},P=class extends z{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(B);se(this)}}peek(){return this._value}},k=class extends z{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===we&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=ve}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(B);se(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===ve;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(we);se(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function se(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var D=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function L(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function xe(){return o.consumer}function Se(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function ge(e){return!!e&&e.disposed===!0}function H(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function q(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=H(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function be(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function K(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function I(e,t,n){let r=H(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function ke(e){o.onSuspend=e}function Re(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function _e(e){o.onError=e}function F(){return o.owner}function ue(e){let t=o.owner;return o.owner=e,t}function M(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){if(o.owner){if(o.owner.disposed){e();return}(o.owner.cleanups??=[]).push(e)}}function $(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)$(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function O(e){let t=H(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>$(t))}finally{o.owner=n}}function Oe(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function lt(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(V)))}function V(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function Ee(){o.batchDepth===0&&V()}function ae(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&V()}}var ie=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=H(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{$(this.owner,!1),M(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new D(()=>lt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),$(this.owner))}};function Y(e){let t=new ie(e);return()=>t.dispose()}function dt(e){return!!e&&typeof e.then=="function"}Oe(()=>{});var Ce=Symbol.for("signal"),ft=Symbol.for("memo"),pt=Symbol.for("signal-node");function d(e,t){let n=new P(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),Ee(),a});return Object.defineProperty(r,Ce,{value:!0,enumerable:!0}),Object.defineProperty(r,pt,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=F(),i=new k(()=>M(s,()=>{try{return r=e(r)}catch(l){if(dt(l))return Re(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,Ce,{value:!0,enumerable:!0}),Object.defineProperty(a,ft,{value:!0,enumerable:!0}),a}function E(e,t){let n=t;return Y(()=>{n=e(n)})}function Ae(e,t){let n=t;Y(()=>{n=e(n)})}function Pe(e,t){let n=t;return Y(()=>{n=e(n)})}function S(e){return ae(e)}function g(e){return L(e)}function ce(e){return ae(e),Promise.resolve()}function De(){return[()=>!1,ce]}function qe(){return V(),Promise.resolve()}function Ie(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=L(()=>t(l,s,a));return s=l,u}}function ht(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;O(m=>{y=m;let[C,N]=d(u);h=N,c=t(f,C)});let x={item:f,rendered:c,dispose:y,setIndex:h};a.push(x),l.add(x)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function yt(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return g(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let x,m,C;O(N=>{C=N;let[R,U]=d(c);m=U;let j=w(A=>{let b=(e()||[])[R()];return b??A},a[c]);x=n(j,R)}),u.push({rendered:x,dispose:C,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function mt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];O(y=>{c=y;let[x,m]=d(h);p=m,f=t(x,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var X=!1,Tt=Symbol.for("signal"),vt=Symbol.for("memo"),wt=Symbol.for("resource");function J(e){return typeof e=="function"&&e[Tt]===!0}function Me(e){return typeof e=="function"&&e[vt]===!0}function Ne(e){return typeof e=="function"&&e[wt]===!0}function Ue(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Be(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Le(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var de=null;function Fe(e){de=e}function Q(e){de&&de(e)}var fe=null;function Ve(e){fe=e}function Z(e){return fe?fe(e):void 0}var pe=null;function je(e){pe=e}function ee(){return pe?pe():void 0}var he=null;function Ge(e){he=e}function te(e,t){he&&he(e,t)}function We(e,t=(n,r)=>n===r){let n=new Map;return E(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function ze(e,t){let[n,r]=d(e(),t);return E(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function $e(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function ne(e){if(typeof e=="function"&&!e.length){let t=e();return J(t)?t:ne(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=ne(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function He(e){let t=w(e);return w(()=>ne(t()))}function xt(e){return!!e&&typeof e.then=="function"}var ye=Symbol();function Ke(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ee(),a=i!==void 0?Z(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,m]=d(void 0,{equals:!1}),[C,N]=d(void 0,{equals:!1}),R=ye,U=!1;E(()=>{let T=r();if(C(),T===!1||T===null||T===void 0){R=ye,S(()=>{y("unresolved"),m(void 0),c(void 0)});return}let b=U;if(U=!1,R!==ye&&T===R&&!b)return;if(R=T,l){l=!1;return}let G=!1;v(()=>G=!0);let me=g(h),tt=g(u),Te=me==="ready"||me==="refreshing";S(()=>{y(Te?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:tt,refetching:Te});xt(_)?(m(_),Q(_),_.then(W=>{G||(i!==void 0&&te(i,W),S(()=>{f(()=>W),y("ready"),m(void 0)}))},W=>{G||S(()=>{c(W),y("errored"),m(void 0)})})):S(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(G)return;S(()=>{c(_),y("errored"),m(void 0)})}});let j=()=>{let T=h();return T==="pending"||T==="refreshing"},A=(()=>{let T=p();if(T)throw T;if(j()){let b=x();if(b)throw b}return u()});return Object.defineProperties(A,{state:{get:h},loading:{get:j},error:{get:p},latest:{get:u}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{U=!0,N(void 0)}}]}var re=q();ke((e,t)=>{let n=K(t,re);n&&(n.increment(),e.finally(()=>n.decrement()))});function Ye(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function Xe(e,t){return I(re,e,t)}var Je=q();_e((e,t)=>{let n=K(t,Je);return n?(n.setError(e),!0):!1});function Qe(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function Ze(e,t){return I(Je,e,t)}var et={State:P,Computed:k,subtle:{Watcher:D,untrack:L,currentComputed:xe,hasSinks:Se}};var St=Symbol.for("signal"),gt=Symbol.for("fluixi-proxy");
1
+ "use strict";var se=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var un=Object.prototype.hasOwnProperty;var an=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},cn=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of sn(n))!un.call(e,o)&&o!==t&&se(e,o,{get:()=>n[o],enumerable:!(r=on(n,o))||r.enumerable});return e};var ln=e=>cn(se({},"__esModule",{value:!0}),e);var On={};an(On,{$PROXY:()=>_n,$SIGNAL:()=>Rn,Signal:()=>tn,SuspenseContext:()=>oe,__DEV__:()=>Q,batch:()=>b,createComputed:()=>Pe,createContext:()=>q,createDebounce:()=>Ke,createDebouncedResource:()=>Ye,createDebouncedSignal:()=>me,createDeferred:()=>He,createEffect:()=>E,createErrorBoundary:()=>en,createMemo:()=>S,createRenderEffect:()=>qe,createResource:()=>te,createRoot:()=>O,createSelector:()=>$e,createSignal:()=>d,createSuspenseBoundary:()=>Xe,flush:()=>Me,getOwner:()=>V,getServerData:()=>Z,indexArray:()=>wn,isComponent:()=>Ne,isMemo:()=>Fe,isOwnerDisposed:()=>ke,isProvider:()=>Le,isResource:()=>Be,isSignal:()=>X,isSuspense:()=>Ve,keyArray:()=>vn,makeArrayFlat:()=>de,mapArray:()=>mn,nextResourceId:()=>ee,on:()=>Ue,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>nn,provideSuspense:()=>Je,readChildren:()=>Qe,reportResourceData:()=>ne,runWithOwner:()=>M,setOwner:()=>ae,setResourceDataSink:()=>ze,setResourceIdSource:()=>We,setResourceTracker:()=>je,setServerDataGetter:()=>Ge,startTransition:()=>le,trackResourcePromise:()=>J,untrack:()=>w,useContext:()=>Re,useTransition:()=>Ie});module.exports=ln(On);var dn="__fluixi_signal_next_state__",fn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[dn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:fn,onSuspend:null,onError:null};var Se=0,xe=1,B=2,z=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let n=s.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},D=class extends z{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(B);ie(this)}}peek(){return this._value}},k=class extends z{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===xe&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=Se}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=s.consumer,r=s.untracked;s.consumer=this,s.untracked=!1;let o,u=!1,a;try{o=this._fn()}catch(i){u=!0,a=i,o=this._value}finally{s.consumer=t,s.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=u,this._error=a,this._value=o,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(B);ie(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===Se;if(this.state=t,r){if(this.observers)for(let o of[...this.observers])o.markDirty(xe);ie(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ie(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var P=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function N(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function be(){return s.consumer}function ge(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function ke(e){return!!e&&e.disposed===!0}function H(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function q(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let o=s.owner,u=H(o);(u.contexts=new Map).set(n,r.value),o&&(o.owned??=[]).push(u),s.owner=u;try{return r.children}finally{s.owner=o}}}}function Re(e){let n=s.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function K(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function I(e,n,t){let r=H(s.owner);(r.contexts=new Map).set(e.id,n),s.owner&&(s.owner.owned??=[]).push(r);let o=s.owner;s.owner=r;try{return t()}finally{s.owner=o}}function _e(e){s.onSuspend=e}function Oe(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function Ee(e){s.onError=e}function V(){return s.owner}function ae(e){let n=s.owner;return s.owner=e,n}function M(e,n){let t=s.owner;s.owner=e;try{return n()}finally{s.owner=t}}function v(e){if(s.owner){if(s.owner.disposed){e();return}(s.owner.cleanups??=[]).push(e)}}function $(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)$(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function O(e){let n=H(s.owner);s.owner&&(s.owner.owned??=[]).push(n);let t=s.owner;s.owner=n;try{return e(()=>$(n))}finally{s.owner=t}}function Ce(e){s.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function pn(e){e.queued||(e.queued=!0,s.queue.push(e),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(L)))}function L(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=s.queue;s.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{s.flushing=!1}}function Ae(){s.batchDepth===0&&L()}function ce(e){s.batchDepth++;try{return e()}finally{--s.batchDepth===0&&L()}}var ue=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=H(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{$(this.owner,!1),M(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new P(()=>pn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&s.onSuspend){s.onSuspend(n,this.owner);return}if(s.onError&&s.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),$(this.owner))}};function Y(e){let n=new ue(e);return()=>n.dispose()}function hn(e){return!!e&&typeof e.then=="function"}Ce(()=>{});var De=Symbol.for("signal"),yn=Symbol.for("memo"),Tn=Symbol.for("signal-node");function d(e,n){let t=new D(e,{equals:n?.equals}),r=(()=>t.get()),o=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),Ae(),a});return Object.defineProperty(r,De,{value:!0,enumerable:!0}),Object.defineProperty(r,Tn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,o]}function S(e,n,t){let r=n,o=V(),u=new k(()=>M(o,()=>{try{return r=e(r)}catch(c){if(hn(c))return Oe(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,De,{value:!0,enumerable:!0}),Object.defineProperty(a,yn,{value:!0,enumerable:!0}),a}function E(e,n){let t=n;return Y(()=>{t=e(t)})}function Pe(e,n){let t=n;Y(()=>{t=e(t)})}function qe(e,n){let t=n;return Y(()=>{t=e(t)})}function b(e){return ce(e)}function w(e){return N(e)}function le(e){return ce(e),Promise.resolve()}function Ie(){return[()=>!1,le]}function Me(){return L(),Promise.resolve()}function Ue(e,n,t){let r=Array.isArray(e),o,u=t?.defer??!1;return a=>{let c=r?e.map(f=>f()):e();if(u){u=!1,o=c;return}let i=N(()=>n(c,o,a));return o=c,i}}function mn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<o.length;i++){let f=o[i],h=u.get(f);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,p,y;O(T=>{y=T;let[C,U]=d(i);p=U,l=n(f,C)});let x={item:f,rendered:l,dispose:y,setIndex:p};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function vn(e,n,t,r){let o=[],u=[];return v(()=>{for(let a of u)a.dispose();o=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return o=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],u[l]);let i=[],f=[],h=new Set;for(let l=0;l<a.length;l++){let p=n(a[l]),y=c.get(p);if(y&&!h.has(p))y.setIndex(l),i.push(y);else{let x,T,C;O(U=>{C=U;let[R,F]=d(l);T=F;let j=S(A=>{let g=(e()||[])[R()];return g??A},a[l]);x=t(j,R)}),i.push({rendered:x,dispose:C,setIndex:T})}f.push(p),h.add(p)}for(let[l,p]of c)h.has(l)||p.dispose();return o=f,u=i,i.map(l=>l.rendered)})})}function wn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=o.length;for(let i=u;i<a;i++){let f,h,l,p=o[i];O(y=>{l=y;let[x,T]=d(p);h=T,f=n(x,i)}),r.push({rendered:f,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(o[i]);return r.map(i=>i.rendered)})})}var Q=!1,Sn=Symbol.for("signal"),xn=Symbol.for("memo"),bn=Symbol.for("resource");function X(e){return typeof e=="function"&&e[Sn]===!0}function Fe(e){return typeof e=="function"&&e[xn]===!0}function Be(e){return typeof e=="function"&&e[bn]===!0}function Ne(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ve(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Le(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function de(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?de(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var fe=null;function je(e){fe=e}function J(e){fe&&fe(e)}var pe=null;function Ge(e){pe=e}function Z(e){return pe?pe(e):void 0}var he=null;function We(e){he=e}function ee(){return he?he():void 0}var ye=null;function ze(e){ye=e}function ne(e,n){ye&&ye(e,n)}function $e(e,n=(t,r)=>t===r){let t=new Map;return E(()=>{let r=e();for(let[o,u]of t){let[a,c]=u,i=n(o,r);a()!==i&&c(i)}}),r=>{let o=t.get(r);if(!o){let[u,a]=d(!1);o=[u,a],t.set(r,o);let c=e();a(n(r,c))}return o[0]()}}function He(e,n){let[t,r]=d(e(),n);return E(()=>{let o=e();n?.timeoutMs?setTimeout(()=>r(()=>o),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>o)):Promise.resolve().then(()=>r(()=>o))}),t}function Ke(e,n){let t,r=(...o)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...o)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function gn(e){return!!e&&typeof e.then=="function"}var Te=Symbol();function te(e,n,t={}){let r,o;typeof n=="function"?(r=typeof e=="function"?e:()=>e,o=n):(r=()=>!0,o=e,n&&typeof n=="object"&&(t=n));let u=ee(),a=u!==void 0?Z(u):void 0,c=a!==void 0,[i,f]=d(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=d(void 0,{equals:!1}),[p,y]=d(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=d(void 0,{equals:!1}),[C,U]=d(void 0,{equals:!1}),R=Te,F=!1;E(()=>{let m=r();if(C(),m===!1||m===null||m===void 0){R=Te,b(()=>{y("unresolved"),T(void 0),l(void 0)});return}let g=F;if(F=!1,R!==Te&&m===R&&!g)return;if(R=m,c){c=!1;return}let G=!1;v(()=>G=!0);let ve=w(p),rn=w(i),we=ve==="ready"||ve==="refreshing";b(()=>{y(we?"refreshing":"pending"),l(void 0)});try{let _=o(m,{value:rn,refetching:we});gn(_)?(T(_),J(_),_.then(W=>{G||(u!==void 0&&ne(u,W),b(()=>{f(()=>W),y("ready"),T(void 0)}))},W=>{G||b(()=>{l(W),y("errored"),T(void 0)})})):b(()=>{f(()=>_),y("ready"),T(void 0)})}catch(_){if(G)return;b(()=>{l(_),y("errored"),T(void 0)})}});let j=()=>{let m=p();return m==="pending"||m==="refreshing"},A=(()=>{let m=h();if(m)throw m;if(j()){let g=x();if(g)throw g}return i()});return Object.defineProperties(A,{state:{get:p},loading:{get:j},error:{get:h},latest:{get:i}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{F=!0,U(void 0)}}]}function me(e,n=300){let[t,r]=d(e),[o,u]=d(e),[a,c]=d(!1),i,f=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{f();let p=w(t);return u(()=>p),c(!1),p},l=(p=>{let y=typeof p=="function"?p(w(t)):p;return r(()=>y),c(!0),f(),i=setTimeout(h,n),y});return v(f),[o,l,{immediate:t,pending:a,flush:h,cancel:()=>{f(),c(!1)}}]}function kn(e){return e!=null&&e!==""}function Ye(e,n,t={}){let{delay:r=300,initialValue:o,shouldFetch:u=kn}=t,[a,c,i]=me(e,r),f=()=>u(a())?a():!1,[h,{refetch:l}]=te(f,n,o===void 0?{}:{initialValue:o});return[h,{...i,query:a,setQuery:c,refetch:l}]}function re(e){if(typeof e=="function"&&!e.length){let n=e();return X(n)?n:re(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=re(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function Qe(e){let n=S(e);return S(()=>re(n()))}var oe=q();_e((e,n)=>{let t=K(n,oe);t&&(t.increment(),e.finally(()=>t.decrement()))});function Xe(){let[e,n]=d(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function Je(e,n){return I(oe,e,n)}var Ze=q();Ee((e,n)=>{let t=K(n,Ze);return t?(t.setError(e),!0):!1});function en(){let[e,n]=d(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function nn(e,n){return I(Ze,e,n)}var tn={State:D,Computed:k,subtle:{Watcher:P,untrack:N,currentComputed:be,hasSinks:ge}};var Rn=Symbol.for("signal"),_n=Symbol.for("fluixi-proxy");
@@ -1 +1 @@
1
- var Ce="__fluixi_signal_next_state__",Ae=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[Ce]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Ae,onSuspend:null,onError:null};var he=0,ye=1,M=2,W=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},C=class extends W{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(M);J(this)}}peek(){return this._value}},g=class extends W{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===ye&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=he}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(M);J(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===he;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(ye);J(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function J(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var A=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function N(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function Te(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Pe(e){return!!e&&e.disposed===!0}function $(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function U(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=$(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function De(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function H(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function B(e,t,n){let r=$(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function ve(e){o.onSuspend=e}function we(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function xe(e){o.onError=e}function K(){return o.owner}function Se(e){let t=o.owner;return o.owner=e,t}function L(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){if(o.owner){if(o.owner.disposed){e();return}(o.owner.cleanups??=[]).push(e)}}function z(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)z(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function P(e){let t=$(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>z(t))}finally{o.owner=n}}function ge(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function qe(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(F)))}function F(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function be(){o.batchDepth===0&&F()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&F()}}var Q=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=$(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{z(this.owner,!1),L(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new A(()=>qe(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function Y(e){let t=new Q(e);return()=>t.dispose()}function Ie(e){return!!e&&typeof e.then=="function"}ge(()=>{});var ke=Symbol.for("signal"),Me=Symbol.for("memo"),Ne=Symbol.for("signal-node");function d(e,t){let n=new C(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),be(),a});return Object.defineProperty(r,ke,{value:!0,enumerable:!0}),Object.defineProperty(r,Ne,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=K(),i=new g(()=>L(s,()=>{try{return r=e(r)}catch(l){if(Ie(l))return we(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,ke,{value:!0,enumerable:!0}),Object.defineProperty(a,Me,{value:!0,enumerable:!0}),a}function D(e,t){let n=t;return Y(()=>{n=e(n)})}function Ue(e,t){let n=t;Y(()=>{n=e(n)})}function Be(e,t){let n=t;return Y(()=>{n=e(n)})}function b(e){return Z(e)}function k(e){return N(e)}function Re(e){return Z(e),Promise.resolve()}function Le(){return[()=>!1,Re]}function Fe(){return F(),Promise.resolve()}function Ve(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=N(()=>t(l,s,a));return s=l,u}}function gt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;P(m=>{y=m;let[O,q]=d(u);h=q,c=t(f,O)});let x={item:f,rendered:c,dispose:y,setIndex:h};a.push(x),l.add(x)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function bt(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return k(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let x,m,O;P(q=>{O=q;let[R,I]=d(c);m=I;let V=w(E=>{let S=(e()||[])[R()];return S??E},a[c]);x=n(V,R)}),u.push({rendered:x,dispose:O,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function kt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];P(y=>{c=y;let[x,m]=d(h);p=m,f=t(x,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var ee=!1,je=Symbol.for("signal"),Ge=Symbol.for("memo"),We=Symbol.for("resource");function te(e){return typeof e=="function"&&e[je]===!0}function ze(e){return typeof e=="function"&&e[Ge]===!0}function $e(e){return typeof e=="function"&&e[We]===!0}function He(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ke(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ye(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function _e(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?_e(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var ne=null;function Xe(e){ne=e}function ie(e){ne&&ne(e)}var re=null;function Je(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function Qe(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function Ze(e){se=e}function ce(e,t){se&&se(e,t)}function et(e,t=(n,r)=>n===r){let n=new Map;return D(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function tt(e,t){let[n,r]=d(e(),t);return D(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function nt(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function X(e){if(typeof e=="function"&&!e.length){let t=e();return te(t)?t:X(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=X(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function rt(e){let t=w(e);return w(()=>X(t()))}function ot(e){return!!e&&typeof e.then=="function"}var le=Symbol();function st(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ae(),a=i!==void 0?ue(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,m]=d(void 0,{equals:!1}),[O,q]=d(void 0,{equals:!1}),R=le,I=!1;D(()=>{let T=r();if(O(),T===!1||T===null||T===void 0){R=le,b(()=>{y("unresolved"),m(void 0),c(void 0)});return}let S=I;if(I=!1,R!==le&&T===R&&!S)return;if(R=T,l){l=!1;return}let j=!1;v(()=>j=!0);let fe=k(h),Ee=k(u),pe=fe==="ready"||fe==="refreshing";b(()=>{y(pe?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:Ee,refetching:pe});ot(_)?(m(_),ie(_),_.then(G=>{j||(i!==void 0&&ce(i,G),b(()=>{f(()=>G),y("ready"),m(void 0)}))},G=>{j||b(()=>{c(G),y("errored"),m(void 0)})})):b(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(j)return;b(()=>{c(_),y("errored"),m(void 0)})}});let V=()=>{let T=h();return T==="pending"||T==="refreshing"},E=(()=>{let T=p();if(T)throw T;if(V()){let S=x();if(S)throw S}return u()});return Object.defineProperties(E,{state:{get:h},loading:{get:V},error:{get:p},latest:{get:u}}),Object.defineProperty(E,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(E,Symbol.for("signal"),{value:!0,enumerable:!0}),[E,{mutate:f,refetch:()=>{I=!0,q(void 0)}}]}var de=U();ve((e,t)=>{let n=H(t,de);n&&(n.increment(),e.finally(()=>n.decrement()))});function it(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function ut(e,t){return B(de,e,t)}var Oe=U();xe((e,t)=>{let n=H(t,Oe);return n?(n.setError(e),!0):!1});function at(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function ct(e,t){return B(Oe,e,t)}var lt={State:C,Computed:g,subtle:{Watcher:A,untrack:N,currentComputed:me,hasSinks:Te}};var Wt=Symbol.for("signal"),zt=Symbol.for("fluixi-proxy");export{zt as $PROXY,Wt as $SIGNAL,lt as Signal,de as SuspenseContext,ee as __DEV__,b as batch,Ue as createComputed,U as createContext,nt as createDebounce,tt as createDeferred,D as createEffect,at as createErrorBoundary,w as createMemo,Be as createRenderEffect,st as createResource,P as createRoot,et as createSelector,d as createSignal,it as createSuspenseBoundary,Fe as flush,K as getOwner,ue as getServerData,kt as indexArray,He as isComponent,ze as isMemo,Pe as isOwnerDisposed,Ye as isProvider,$e as isResource,te as isSignal,Ke as isSuspense,bt as keyArray,_e as makeArrayFlat,gt as mapArray,ae as nextResourceId,Ve as on,v as onCleanup,B as provide,ct as provideErrorBoundary,ut as provideSuspense,rt as readChildren,ce as reportResourceData,L as runWithOwner,Se as setOwner,Ze as setResourceDataSink,Qe as setResourceIdSource,Xe as setResourceTracker,Je as setServerDataGetter,Re as startTransition,ie as trackResourcePromise,k as untrack,De as useContext,Le as useTransition};
1
+ var De="__fluixi_signal_next_state__",Pe=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[De]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Pe,onSuspend:null,onError:null};var ye=0,Te=1,M=2,W=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let n=o.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},C=class extends W{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(M);X(this)}}peek(){return this._value}},g=class extends W{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Te&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=ye}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,u=!1,a;try{s=this._fn()}catch(i){u=!0,a=i,s=this._value}finally{o.consumer=t,o.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=u,this._error=a,this._value=s,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(M);X(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===ye;if(this.state=t,r){if(this.observers)for(let s of[...this.observers])s.markDirty(Te);X(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function X(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var A=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function U(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function qe(e){return!!e&&e.disposed===!0}function $(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function F(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let s=o.owner,u=$(s);(u.contexts=new Map).set(n,r.value),s&&(s.owned??=[]).push(u),o.owner=u;try{return r.children}finally{o.owner=s}}}}function Ie(e){let n=o.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function H(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function B(e,n,t){let r=$(o.owner);(r.contexts=new Map).set(e.id,n),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return t()}finally{o.owner=s}}function we(e){o.onSuspend=e}function Se(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function xe(e){o.onError=e}function K(){return o.owner}function be(e){let n=o.owner;return o.owner=e,n}function N(e,n){let t=o.owner;o.owner=e;try{return n()}finally{o.owner=t}}function v(e){if(o.owner){if(o.owner.disposed){e();return}(o.owner.cleanups??=[]).push(e)}}function z(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)z(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function D(e){let n=$(o.owner);o.owner&&(o.owner.owned??=[]).push(n);let t=o.owner;o.owner=n;try{return e(()=>z(n))}finally{o.owner=t}}function ge(e){o.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Me(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(V)))}function V(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=o.queue;o.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{o.flushing=!1}}function ke(){o.batchDepth===0&&V()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&V()}}var J=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=$(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{z(this.owner,!1),N(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new A(()=>Me(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&o.onSuspend){o.onSuspend(n,this.owner);return}if(o.onError&&o.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function Y(e){let n=new J(e);return()=>n.dispose()}function Ue(e){return!!e&&typeof e.then=="function"}ge(()=>{});var Re=Symbol.for("signal"),Fe=Symbol.for("memo"),Be=Symbol.for("signal-node");function p(e,n){let t=new C(e,{equals:n?.equals}),r=(()=>t.get()),s=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),ke(),a});return Object.defineProperty(r,Re,{value:!0,enumerable:!0}),Object.defineProperty(r,Be,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,s]}function S(e,n,t){let r=n,s=K(),u=new g(()=>N(s,()=>{try{return r=e(r)}catch(c){if(Ue(c))return Se(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,Re,{value:!0,enumerable:!0}),Object.defineProperty(a,Fe,{value:!0,enumerable:!0}),a}function P(e,n){let t=n;return Y(()=>{t=e(t)})}function Ne(e,n){let t=n;Y(()=>{t=e(t)})}function Ve(e,n){let t=n;return Y(()=>{t=e(t)})}function k(e){return Z(e)}function w(e){return U(e)}function _e(e){return Z(e),Promise.resolve()}function Le(){return[()=>!1,_e]}function je(){return V(),Promise.resolve()}function Ge(e,n,t){let r=Array.isArray(e),s,u=t?.defer??!1;return a=>{let c=r?e.map(d=>d()):e();if(u){u=!1,s=c;return}let i=U(()=>n(c,s,a));return s=c,i}}function _n(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<s.length;i++){let d=s[i],h=u.get(d);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,f,y;D(T=>{y=T;let[O,q]=p(i);f=q,l=n(d,O)});let x={item:d,rendered:l,dispose:y,setIndex:f};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function On(e,n,t,r){let s=[],u=[];return v(()=>{for(let a of u)a.dispose();s=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return s=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<s.length;l++)c.set(s[l],u[l]);let i=[],d=[],h=new Set;for(let l=0;l<a.length;l++){let f=n(a[l]),y=c.get(f);if(y&&!h.has(f))y.setIndex(l),i.push(y);else{let x,T,O;D(q=>{O=q;let[R,I]=p(l);T=I;let L=S(E=>{let b=(e()||[])[R()];return b??E},a[l]);x=t(L,R)}),i.push({rendered:x,dispose:O,setIndex:T})}d.push(f),h.add(f)}for(let[l,f]of c)h.has(l)||f.dispose();return s=d,u=i,i.map(l=>l.rendered)})})}function En(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=s.length;for(let i=u;i<a;i++){let d,h,l,f=s[i];D(y=>{l=y;let[x,T]=p(f);h=T,d=n(x,i)}),r.push({rendered:d,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(s[i]);return r.map(i=>i.rendered)})})}var ee=!1,We=Symbol.for("signal"),ze=Symbol.for("memo"),$e=Symbol.for("resource");function ne(e){return typeof e=="function"&&e[We]===!0}function He(e){return typeof e=="function"&&e[ze]===!0}function Ke(e){return typeof e=="function"&&e[$e]===!0}function Ye(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Qe(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Xe(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Oe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Oe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var te=null;function Je(e){te=e}function ie(e){te&&te(e)}var re=null;function Ze(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function en(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function nn(e){se=e}function ce(e,n){se&&se(e,n)}function tn(e,n=(t,r)=>t===r){let t=new Map;return P(()=>{let r=e();for(let[s,u]of t){let[a,c]=u,i=n(s,r);a()!==i&&c(i)}}),r=>{let s=t.get(r);if(!s){let[u,a]=p(!1);s=[u,a],t.set(r,s);let c=e();a(n(r,c))}return s[0]()}}function rn(e,n){let[t,r]=p(e(),n);return P(()=>{let s=e();n?.timeoutMs?setTimeout(()=>r(()=>s),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),t}function on(e,n){let t,r=(...s)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...s)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function sn(e){return!!e&&typeof e.then=="function"}var le=Symbol();function de(e,n,t={}){let r,s;typeof n=="function"?(r=typeof e=="function"?e:()=>e,s=n):(r=()=>!0,s=e,n&&typeof n=="object"&&(t=n));let u=ae(),a=u!==void 0?ue(u):void 0,c=a!==void 0,[i,d]=p(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=p(void 0,{equals:!1}),[f,y]=p(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=p(void 0,{equals:!1}),[O,q]=p(void 0,{equals:!1}),R=le,I=!1;P(()=>{let m=r();if(O(),m===!1||m===null||m===void 0){R=le,k(()=>{y("unresolved"),T(void 0),l(void 0)});return}let b=I;if(I=!1,R!==le&&m===R&&!b)return;if(R=m,c){c=!1;return}let j=!1;v(()=>j=!0);let pe=w(f),Ae=w(i),he=pe==="ready"||pe==="refreshing";k(()=>{y(he?"refreshing":"pending"),l(void 0)});try{let _=s(m,{value:Ae,refetching:he});sn(_)?(T(_),ie(_),_.then(G=>{j||(u!==void 0&&ce(u,G),k(()=>{d(()=>G),y("ready"),T(void 0)}))},G=>{j||k(()=>{l(G),y("errored"),T(void 0)})})):k(()=>{d(()=>_),y("ready"),T(void 0)})}catch(_){if(j)return;k(()=>{l(_),y("errored"),T(void 0)})}});let L=()=>{let m=f();return m==="pending"||m==="refreshing"},E=(()=>{let m=h();if(m)throw m;if(L()){let b=x();if(b)throw b}return i()});return Object.defineProperties(E,{state:{get:f},loading:{get:L},error:{get:h},latest:{get:i}}),Object.defineProperty(E,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(E,Symbol.for("signal"),{value:!0,enumerable:!0}),[E,{mutate:d,refetch:()=>{I=!0,q(void 0)}}]}function Ee(e,n=300){let[t,r]=p(e),[s,u]=p(e),[a,c]=p(!1),i,d=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{d();let f=w(t);return u(()=>f),c(!1),f},l=(f=>{let y=typeof f=="function"?f(w(t)):f;return r(()=>y),c(!0),d(),i=setTimeout(h,n),y});return v(d),[s,l,{immediate:t,pending:a,flush:h,cancel:()=>{d(),c(!1)}}]}function un(e){return e!=null&&e!==""}function an(e,n,t={}){let{delay:r=300,initialValue:s,shouldFetch:u=un}=t,[a,c,i]=Ee(e,r),d=()=>u(a())?a():!1,[h,{refetch:l}]=de(d,n,s===void 0?{}:{initialValue:s});return[h,{...i,query:a,setQuery:c,refetch:l}]}function Q(e){if(typeof e=="function"&&!e.length){let n=e();return ne(n)?n:Q(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=Q(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function cn(e){let n=S(e);return S(()=>Q(n()))}var fe=F();we((e,n)=>{let t=H(n,fe);t&&(t.increment(),e.finally(()=>t.decrement()))});function ln(){let[e,n]=p(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function dn(e,n){return B(fe,e,n)}var Ce=F();xe((e,n)=>{let t=H(n,Ce);return t?(t.setError(e),!0):!1});function fn(){let[e,n]=p(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function pn(e,n){return B(Ce,e,n)}var hn={State:C,Computed:g,subtle:{Watcher:A,untrack:U,currentComputed:me,hasSinks:ve}};var Xn=Symbol.for("signal"),Jn=Symbol.for("fluixi-proxy");export{Jn as $PROXY,Xn as $SIGNAL,hn as Signal,fe as SuspenseContext,ee as __DEV__,k as batch,Ne as createComputed,F as createContext,on as createDebounce,an as createDebouncedResource,Ee as createDebouncedSignal,rn as createDeferred,P as createEffect,fn as createErrorBoundary,S as createMemo,Ve as createRenderEffect,de as createResource,D as createRoot,tn as createSelector,p as createSignal,ln as createSuspenseBoundary,je as flush,K as getOwner,ue as getServerData,En as indexArray,Ye as isComponent,He as isMemo,qe as isOwnerDisposed,Xe as isProvider,Ke as isResource,ne as isSignal,Qe as isSuspense,On as keyArray,Oe as makeArrayFlat,_n as mapArray,ae as nextResourceId,Ge as on,v as onCleanup,B as provide,pn as provideErrorBoundary,dn as provideSuspense,cn as readChildren,ce as reportResourceData,N as runWithOwner,be as setOwner,nn as setResourceDataSink,en as setResourceIdSource,Je as setResourceTracker,Ze as setServerDataGetter,_e as startTransition,ie as trackResourcePromise,w as untrack,Ie as useContext,Le as useTransition};
@@ -1 +1 @@
1
- "use strict";var Te=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var zt=Object.prototype.hasOwnProperty;var Ht=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},Yt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Wt(t))!zt.call(e,r)&&r!==n&&Te(e,r,{get:()=>t[r],enumerable:!(o=$t(t,r))||o.enumerable});return e};var Kt=e=>Yt(Te({},"__esModule",{value:!0}),e);var bn={};Ht(bn,{$MEMO:()=>Tt,$PROXY:()=>Le,$RESOURCE:()=>bt,$SIGNAL:()=>de,__DEV__:()=>Y,batch:()=>_,createComputed:()=>qt,createContext:()=>ve,createDebounce:()=>lt,createDeferred:()=>at,createEffect:()=>$,createMemo:()=>St,createProvider:()=>Ft,createRenderEffect:()=>We,createResource:()=>Rt,createRoot:()=>Ct,createSelector:()=>Ae,createSignal:()=>U,default:()=>Tn,flush:()=>Et,getOwner:()=>_t,getServerData:()=>Ne,getSharedConfig:()=>pn,getSuspenseContext:()=>Nt,getSuspenseListContext:()=>Ut,isComponent:()=>Qe,isMemo:()=>Xe,isProvider:()=>et,isResource:()=>Je,isSignal:()=>K,isSuspense:()=>Ze,makeArrayFlat:()=>me,nextResourceId:()=>Ue,on:()=>kt,onCleanup:()=>fe,onResolve:()=>Mt,readChildren:()=>Fe,reportResourceData:()=>Ie,resumeEffects:()=>It,runWithOwner:()=>At,setOwner:()=>dn,setResourceDataSink:()=>pt,setResourceIdSource:()=>dt,setResourceTracker:()=>ct,setScheduler:()=>Lt,setServerDataGetter:()=>ft,sharedConfig:()=>ce,startTransition:()=>$e,trackPromise:()=>Bt,trackResourcePromise:()=>qe,untrack:()=>V,useContext:()=>A,useTransition:()=>Pt});module.exports=Kt(bn);var Ke=require("@fluixi/utils/object"),be=require("@fluixi/utils/functions"),z=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if((0,be.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,Ke.isObject)(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if((0,be.isFunction)(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var te=class extends z{constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ye=class extends te{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var H=class extends z{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof te?r=t:r=new ye(t,n,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};var Q=require("@fluixi/utils");var Y=!1,Xt=Symbol.for("signal"),Jt=Symbol.for("memo"),Qt=Symbol.for("resource");function K(e){return typeof e=="function"&&e[Xt]===!0}function Xe(e){return typeof e=="function"&&e[Jt]===!0}function Je(e){return typeof e=="function"&&e[Qt]===!0}function Qe(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ze(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function et(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function me(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?me(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Zt="__fluixi_signal_next_state__",en=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[Zt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:en,onSuspend:null,onError:null};var tt=0,nt=1,X=2,ne=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},re=class extends ne{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(X);we(this)}}peek(){return this._value}},G=class extends ne{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=X;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===nt&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===X)break}(this.state===X||!this._initialized)&&this.recompute(),this.state=tt}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let n=a.consumer,o=a.untracked;a.consumer=this,a.untracked=!1;let r,s=!1,l;try{r=this._fn()}catch(f){s=!0,l=f,r=this._value}finally{a.consumer=n,a.untracked=o}let c=!this._initialized||this._threw!==s||(s?l!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=l,this._value=r,c){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(X);we(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===tt;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(nt);we(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function we(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var oe=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function tn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rt(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Se(){return a.owner}function se(e,t){let n=a.owner;a.owner=e;try{return t()}finally{a.owner=n}}function Oe(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function xe(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)xe(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function ot(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function nn(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(Ce)))}function Ce(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{a.flushing=!1}}function st(){a.batchDepth===0&&Ce()}var ge=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=tn(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new G(()=>{xe(this.owner,!1),se(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new oe(()=>nn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),xe(this.owner))}};function it(e){let t=new ge(e);return()=>t.dispose()}function rn(e){return!!e&&typeof e.then=="function"}ot(()=>{});var ut=Symbol.for("signal"),on=Symbol.for("memo"),sn=Symbol.for("signal-node");function Re(e,t){let n=new re(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let l=typeof s=="function"?s(n.peek()):s;return n.set(l),st(),l});return Object.defineProperty(o,ut,{value:!0,enumerable:!0}),Object.defineProperty(o,sn,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function ie(e,t,n){let o=t,r=Se(),s=new G(()=>se(r,()=>{try{return o=e(o)}catch(c){if(rn(c))return rt(c),o;throw c}}),{equals:n?.equals}),l=(()=>s.get());return Object.defineProperty(l,ut,{value:!0,enumerable:!0}),Object.defineProperty(l,on,{value:!0,enumerable:!0}),l}function _e(e,t){let n=t;return it(()=>{n=e(n)})}function Ae(e,t=(n,o)=>n===o){let n=new Map;return _e(()=>{let o=e();for(let[r,s]of n){let[l,c]=s,f=t(r,o);l()!==f&&c(f)}}),o=>{let r=n.get(o);if(!r){let[s,l]=Re(!1);r=[s,l],n.set(o,r);let c=e();l(t(o,c))}return r[0]()}}function at(e,t){let[n,o]=Re(e(),t);return _e(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function lt(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,r.length>0){let s=r[r.length-1];typeof s=="object"&&s&&!s.tagName&&s.target&&s.target.tagName&&(s=s.target),s&&typeof s=="object"&&s.tagName&&(s.tagName.toLowerCase()==="input"||s.tagName.toLowerCase()==="textarea")&&s.focus()}e(...r)},t)};return Oe(()=>{n!==void 0&&clearTimeout(n)}),o}function ue(e){if(typeof e=="function"&&!e.length){let t=e();return K(t)?t:ue(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=ue(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function Fe(e){let t=ie(e);return ie(()=>ue(t()))}var Ee=null;function ct(e){Ee=e}function qe(e){Ee&&Ee(e)}var Pe=null;function ft(e){Pe=e}function Ne(e){return Pe?Pe(e):void 0}var ke=null;function dt(e){ke=e}function Ue(){return ke?ke():void 0}var De=null;function pt(e){De=e}function Ie(e,t){De&&De(e,t)}var de=Symbol.for("signal"),Tt=Symbol.for("memo"),bt=Symbol.for("resource"),Le=Symbol("fluixi-proxy"),yt=Symbol.for("signal-node"),F=0,J=1,P=2,E=3,u=null,d=null,i=null,ae=null,le=0,un=!1,Me=!1,j=0,an=1e6,m=new WeakMap,g=null;var ln=null,cn=new Map,fn=0,ce={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function dn(e){u=e,ce.owner=e,ce.context=e}function pn(){return ce}function vn(){return`node_${++fn}_${Date.now()}`}function hn(e){!1}function mt(e,t,n){let o={id:vn(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return hn(o),o}function wt(e,t){return e===t}function je(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var Be=null,Ge=null;function xt(){if(!Be){let[e,t]=U(!1);Be=e,Ge=t}}function gt(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)Z(e);else if(e.pure&&!e.computed&&e.accessor){let t=d,n=i;d=null,i=[],e.accessor(),d=t;let o=i;if(i=n,o.length>0){let r=i;pe(o),i=r}}}function vt(e,t){for(let n=0;n<e.length;n++)t(e[n])}function U(e,t){let n=e;typeof n=="object"&&n&&Le in n&&delete n[Le];let o=mt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[l,c];m.set(r,new Set);let s;function l(){let f=d;if(f){f.sources?f.sources.indexOf(r)===-1&&f.sources.push(r):f.sources=[r];let p=m.get(r);p&&!p.has(f)&&p.add(f)}return n}function c(f){let p=typeof f=="function"?f(n):f,b=o.equals||wt;if(t?.equals===!1||!b(n,p)){n=p,o.value=p,o.version++,o.updated=Date.now();let k=m.get(r);if(k&&k.size>0){let D=function(v,h=!1){let q=v.state;if(!(q===E&&v===d)){if(h&&!v.pure){q===F&&(v.state=J,un&&(i!==null&&i.indexOf(v)===-1?i.push(v):C.push(v)));return}if(!w.has(v)&&(w.add(v),v.state=P,q===F||q===J?C.push(v):!v.pure&&i!==null&&i.indexOf(v)===-1&&i.push(v),v.pure&&v.accessor)){let O=m.get(v.accessor);O&&vt(Array.from(O),R=>D(R,!0))}}};var x=D;let S=Array.from(k),C=[],w=new Set;vt(S,D);for(let v of C)gt(v)}}}return l.toObservable=()=>new H(f=>{let p=!0;return $(()=>{let x=l();p?p=!1:f.next(x)})}),Object.defineProperty(l,de,{value:!0,enumerable:!0}),Object.defineProperty(l,yt,{value:o,enumerable:!1}),r}function $(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&A(T);return r&&(o.suspense=r),Ve(o,t),()=>I(o)}function Ve(e,t){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)I(e.owned[r]);e.owned=null}let n=d,o=u;if(d=e,u=e,le++,le>an)throw le=0,d=n,u=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=E;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===E&&(e.state=F)}catch(r){if((0,Q.isPromise)(r)){let s=T&&A(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}je(r)}finally{d=n,u=o}}function Z(e){if(!(e.disposed||!e.fn||e.state===F)&&(e.state===P||e.state===J||e.state===E)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)I(e.owned[t]);e.owned=null}e.renderEffect?Dt(e):Ve(e,e.value)}}function I(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=m.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)I(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function St(e,t,n){let o=mt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};u&&(u.owned?u.owned.push(r):u.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;m.has(c)||m.set(c,new Set);let f=m.get(c);f&&f.add(d)}if(r.state!==F){if(r.sources){for(let p of r.sources){let b=m.get(p);b&&b.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let p=0;p<r.cleanups.length;p++)r.cleanups[p]();r.cleanups=null}if(r.owned){for(let p=0;p<r.owned.length;p++)I(r.owned[p]);r.owned=null}let c=d,f=u;d=r,u=r,r.state=E;try{let p=r.fn(r.value),b=o.equals||wt;if(n?.equals===!1||!b(r.value,p)){r.value=p,o.value=p,o.version++,o.updated=Date.now();let k=s,S=m.get(k);if(S&&S.size>0){let v=function(h,q=!1){if(h===r)return;let O=h.state;if(O!==E){if(q&&!h.pure){O===F&&(h.state=J,i!==null&&i.indexOf(h)===-1?i.push(h):w.push(h));return}if(!D.has(h)&&(D.add(h),h.state=P,O===F||O===J?w.push(h):!h.pure&&i!==null&&i.indexOf(h)===-1&&i.push(h),h.pure&&h.accessor)){let R=m.get(h.accessor);if(R&&R.size>0)for(let W of Array.from(R))v(W,!0)}}};var l=v;let C=Array.from(S),w=[],D=new Set;for(let h=0;h<C.length;h++)v(C[h]);for(let h of w)gt(h)}}r.state===E&&(r.state=F)}catch(p){if((0,Q.isPromise)(p)){let b=T&&A(T);if(!b&&T){let x=f;for(;x;){if(x.contexts?.has(T.id)){b=x.contexts.get(T.id);break}x=x.owner}}return b&&(b.increment(),p.finally(()=>b.decrement())),r.value}je(p)}finally{d=c,u=f}}return r.value};return r.accessor=s,m.set(s,new Set),s.toObservable=()=>new H(l=>{let c=!0;return $(()=>{let p=s();c?c=!1:l.next(p)})}),Object.defineProperty(s,de,{value:!0,enumerable:!0}),Object.defineProperty(s,Tt,{value:!0,enumerable:!0}),Object.defineProperty(s,yt,{value:o,enumerable:!1}),s}function pe(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);i=[];let o=0;for(;o<t.length;){let r=t[o++],s=m.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=i.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?t.indexOf(c)===-1&&t.push(c):(c.computed||!c.pure)&&n.indexOf(c)===-1&&n.push(c)}i=null;for(let r of n)(r.computed||!r.pure)&&Z(r)}function _(e){if(i&&j>0)return e();if(i&&j===0){let t=i,n=[];i=n,j++;let o;try{o=e()}finally{j--,i=t}let r=i;return pe(n),i=r,o}j++,i=[],ae=[];try{return e()}finally{j--,Ot()}}function Ot(){if(!Me){Me=!0,le=0;try{for(;i&&i.length>0;){let e=i;i=null,pe(e)}if(i=null,ae){let e=ae;ae=null;for(let t=0;t<e.length;t++)Z(e[t])}}finally{Me=!1}}}function Ct(e){let t={owned:null,cleanups:null,contexts:null,owner:u},n=d;d=null;let o=u;u=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)I(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{u=o,d=n}}function V(e){let t=d;d=null;try{return e()}finally{d=t}}function fe(e){u&&(u.cleanups?u.cleanups.push(e):u.cleanups=[e])}function Rt(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:l}=n,c=Ue(),f=c!==void 0?Ne(c):void 0,p=f!==void 0,[b,x]=U(f!==void 0?f.value:n.initialValue,{equals:!1}),[k,S]=U(void 0,{equals:!1}),[C,w]=U(f!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,v]=U(void 0,{equals:!1}),[h,q]=U(void 0,{equals:!1}),O=Symbol(),R=O,W=!1,Gt=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},jt=$(()=>{let y=o?o():e;if(h(),y===!1||y===null||y===void 0){R=O,_(()=>{w("unresolved"),v(void 0),S(void 0)});return}let L=W;if(W=!1,R!==O&&y===R&&!L)return;if(R=y,p){p=!1;return}let B=!1;fe(()=>B=!0);let He=V(C),Vt=V(b),Ye=He==="ready"||He==="refreshing";_(()=>{w(Ye?"refreshing":"pending"),S(void 0)});try{let N=r(y,{value:Vt,refetching:Ye});if((0,Q.isPromise)(N)){v(N),qe(N),N.then(M=>{B||(c!==void 0&&Ie(c,M),_(()=>{x(()=>M),Gt(M),w("ready"),v(void 0)}))},M=>{B||_(()=>{S(M),w("errored"),v(void 0)})}).catch(M=>{B||_(()=>{S(M),w("errored"),v(void 0)})});let he=T&&A(T);he&&(he.increment(),N.finally(()=>he.decrement()))}else{if(B)return;_(()=>{x(()=>N),w("ready"),v(void 0)})}}catch(N){if(B)return;_(()=>{S(N),w("errored"),v(void 0)})}});fe(jt);let ze=()=>{let y=C();return y==="pending"||y==="refreshing"},ee=(()=>{let y=k();if(y)throw y;if(ze()){let L=D();if(L)throw L}return b()});return Object.defineProperty(ee,bt,{value:!0,enumerable:!0}),Object.defineProperty(ee,de,{value:!0,enumerable:!0}),Object.defineProperties(ee,{state:{get:C},loading:{get:()=>ze()},error:{get:k},latest:{get:b}}),[ee,{mutate:x,refetch:()=>{W=!0,q(void 0)}}]}function _t(){return u}function At(e,t){let n=u,o=d;u=e,d=null;try{return t()}finally{u=n,d=o}}function ve(e){let t=Symbol("context"),n=Ft(t);return{id:t,Provider:n,defaultValue:e}}function Ft(e){return t=>{let n=u;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return We(()=>{o=V(()=>{let r=u;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),Fe(()=>t.children)})}),o}}function A(e){let t=u;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function Et(){return new Promise(e=>{queueMicrotask(()=>{Ot(),e()})})}function $e(e){if(g&&g.running)return e(),g.done;xt();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};g=o;try{e()}finally{o.running=!1}return o.effects.length?(Ge(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,Ge(!1),r.length&&_(()=>{for(let s of r)s.state=P,Z(s)}),t()}),n):(g=null,t(),n)}function Pt(){return xt(),[Be,$e]}function kt(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):V(()=>t(l,s))}}function We(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&A(T);return r&&(o.suspense=r),Dt(o),()=>I(o)}function Dt(e){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)I(e.owned[r]);e.owned=null}let t=d,n=u,o=i;d=e,u=e,i===null&&(i=[]),e.state=E;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===E&&(e.state=F)}catch(r){if((0,Q.isPromise)(r)){let s=T&&A(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}je(r)}finally{d=t,u=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;pe(r),i=s}}}function qt(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,computed:!0,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]),g&&g.running?(i||(i=[]),i.indexOf(o)===-1&&i.push(o)):i?i.indexOf(o)===-1&&i.push(o):Ve(o,t)}var T;function Nt(){return T||(T=ve())}var ht;function Ut(){return ht||(ht=ve())}function It(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=P,Z(n)}function Mt(e){let t=T&&A(T);t&&t.inFallback()?$(()=>{t.inFallback()||e()}):e()}function Lt(e){ln=e}function Bt(e){let t=T&&A(T);return t&&(t.increment(),e.finally(()=>t.decrement())),e}var Tn={createSignal:U,createEffect:$,createMemo:St,createComputed:qt,createRoot:Ct,createSelector:Ae,createResource:Rt,batch:_,untrack:V,onCleanup:fe,getOwner:_t,runWithOwner:At,createContext:ve,useContext:A,flush:Et,startTransition:$e,useTransition:Pt,isSignal:K,on:kt,createRenderEffect:We,getSuspenseContext:Nt,getSuspenseListContext:Ut,resumeEffects:It,onResolve:Mt,setScheduler:Lt,trackPromise:Bt};
1
+ "use strict";var Te=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Wt=Object.getOwnPropertyNames;var zt=Object.prototype.hasOwnProperty;var Ht=(e,t)=>{for(var n in t)Te(e,n,{get:t[n],enumerable:!0})},Yt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Wt(t))!zt.call(e,r)&&r!==n&&Te(e,r,{get:()=>t[r],enumerable:!(o=$t(t,r))||o.enumerable});return e};var Kt=e=>Yt(Te({},"__esModule",{value:!0}),e);var bn={};Ht(bn,{$MEMO:()=>Tt,$PROXY:()=>Le,$RESOURCE:()=>bt,$SIGNAL:()=>de,__DEV__:()=>Y,batch:()=>_,createComputed:()=>qt,createContext:()=>ve,createDebounce:()=>lt,createDeferred:()=>at,createEffect:()=>$,createMemo:()=>St,createProvider:()=>Ft,createRenderEffect:()=>We,createResource:()=>Rt,createRoot:()=>Ct,createSelector:()=>Ae,createSignal:()=>U,default:()=>Tn,flush:()=>Et,getOwner:()=>_t,getServerData:()=>Ne,getSharedConfig:()=>pn,getSuspenseContext:()=>Nt,getSuspenseListContext:()=>Ut,isComponent:()=>Qe,isMemo:()=>Xe,isProvider:()=>et,isResource:()=>Je,isSignal:()=>K,isSuspense:()=>Ze,makeArrayFlat:()=>me,nextResourceId:()=>Ue,on:()=>kt,onCleanup:()=>fe,onResolve:()=>Mt,readChildren:()=>Fe,reportResourceData:()=>Ie,resumeEffects:()=>It,runWithOwner:()=>At,setOwner:()=>dn,setResourceDataSink:()=>pt,setResourceIdSource:()=>dt,setResourceTracker:()=>ct,setScheduler:()=>Lt,setServerDataGetter:()=>ft,sharedConfig:()=>ce,startTransition:()=>$e,trackPromise:()=>Bt,trackResourcePromise:()=>qe,untrack:()=>j,useContext:()=>A,useTransition:()=>Pt});module.exports=Kt(bn);var Ke=require("@fluixi/utils/object"),be=require("@fluixi/utils/functions"),z=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if((0,be.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,Ke.isObject)(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if((0,be.isFunction)(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var te=class extends z{constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ye=class extends te{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var H=class extends z{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof te?r=t:r=new ye(t,n,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};var Q=require("@fluixi/utils");var Y=!1,Xt=Symbol.for("signal"),Jt=Symbol.for("memo"),Qt=Symbol.for("resource");function K(e){return typeof e=="function"&&e[Xt]===!0}function Xe(e){return typeof e=="function"&&e[Jt]===!0}function Je(e){return typeof e=="function"&&e[Qt]===!0}function Qe(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ze(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function et(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function me(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?me(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Zt="__fluixi_signal_next_state__",en=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[Zt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:en,onSuspend:null,onError:null};var tt=0,nt=1,X=2,ne=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},re=class extends ne{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(X);we(this)}}peek(){return this._value}},G=class extends ne{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=X;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===nt&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===X)break}(this.state===X||!this._initialized)&&this.recompute(),this.state=tt}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let n=a.consumer,o=a.untracked;a.consumer=this,a.untracked=!1;let r,s=!1,l;try{r=this._fn()}catch(f){s=!0,l=f,r=this._value}finally{a.consumer=n,a.untracked=o}let c=!this._initialized||this._threw!==s||(s?l!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=l,this._value=r,c){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(X);we(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===tt;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(nt);we(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function we(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var oe=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function tn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rt(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Se(){return a.owner}function se(e,t){let n=a.owner;a.owner=e;try{return t()}finally{a.owner=n}}function Oe(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function xe(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)xe(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function ot(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function nn(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(Ce)))}function Ce(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{a.flushing=!1}}function st(){a.batchDepth===0&&Ce()}var ge=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=tn(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new G(()=>{xe(this.owner,!1),se(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new oe(()=>nn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),xe(this.owner))}};function it(e){let t=new ge(e);return()=>t.dispose()}function rn(e){return!!e&&typeof e.then=="function"}ot(()=>{});var ut=Symbol.for("signal"),on=Symbol.for("memo"),sn=Symbol.for("signal-node");function Re(e,t){let n=new re(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let l=typeof s=="function"?s(n.peek()):s;return n.set(l),st(),l});return Object.defineProperty(o,ut,{value:!0,enumerable:!0}),Object.defineProperty(o,sn,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function ie(e,t,n){let o=t,r=Se(),s=new G(()=>se(r,()=>{try{return o=e(o)}catch(c){if(rn(c))return rt(c),o;throw c}}),{equals:n?.equals}),l=(()=>s.get());return Object.defineProperty(l,ut,{value:!0,enumerable:!0}),Object.defineProperty(l,on,{value:!0,enumerable:!0}),l}function _e(e,t){let n=t;return it(()=>{n=e(n)})}function Ae(e,t=(n,o)=>n===o){let n=new Map;return _e(()=>{let o=e();for(let[r,s]of n){let[l,c]=s,f=t(r,o);l()!==f&&c(f)}}),o=>{let r=n.get(o);if(!r){let[s,l]=Re(!1);r=[s,l],n.set(o,r);let c=e();l(t(o,c))}return r[0]()}}function at(e,t){let[n,o]=Re(e(),t);return _e(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function lt(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{n=void 0,e(...r)},t)};return Oe(()=>{n!==void 0&&clearTimeout(n)}),o}function ue(e){if(typeof e=="function"&&!e.length){let t=e();return K(t)?t:ue(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=ue(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function Fe(e){let t=ie(e);return ie(()=>ue(t()))}var Ee=null;function ct(e){Ee=e}function qe(e){Ee&&Ee(e)}var Pe=null;function ft(e){Pe=e}function Ne(e){return Pe?Pe(e):void 0}var ke=null;function dt(e){ke=e}function Ue(){return ke?ke():void 0}var De=null;function pt(e){De=e}function Ie(e,t){De&&De(e,t)}var de=Symbol.for("signal"),Tt=Symbol.for("memo"),bt=Symbol.for("resource"),Le=Symbol("fluixi-proxy"),yt=Symbol.for("signal-node"),F=0,J=1,P=2,E=3,u=null,d=null,i=null,ae=null,le=0,un=!1,Me=!1,V=0,an=1e6,m=new WeakMap,g=null;var ln=null,cn=new Map,fn=0,ce={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function dn(e){u=e,ce.owner=e,ce.context=e}function pn(){return ce}function vn(){return`node_${++fn}_${Date.now()}`}function hn(e){!1}function mt(e,t,n){let o={id:vn(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return hn(o),o}function wt(e,t){return e===t}function Ve(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var Be=null,Ge=null;function xt(){if(!Be){let[e,t]=U(!1);Be=e,Ge=t}}function gt(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)Z(e);else if(e.pure&&!e.computed&&e.accessor){let t=d,n=i;d=null,i=[],e.accessor(),d=t;let o=i;if(i=n,o.length>0){let r=i;pe(o),i=r}}}function vt(e,t){for(let n=0;n<e.length;n++)t(e[n])}function U(e,t){let n=e;typeof n=="object"&&n&&Le in n&&delete n[Le];let o=mt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[l,c];m.set(r,new Set);let s;function l(){let f=d;if(f){f.sources?f.sources.indexOf(r)===-1&&f.sources.push(r):f.sources=[r];let p=m.get(r);p&&!p.has(f)&&p.add(f)}return n}function c(f){let p=typeof f=="function"?f(n):f,b=o.equals||wt;if(t?.equals===!1||!b(n,p)){n=p,o.value=p,o.version++,o.updated=Date.now();let k=m.get(r);if(k&&k.size>0){let D=function(v,h=!1){let q=v.state;if(!(q===E&&v===d)){if(h&&!v.pure){q===F&&(v.state=J,un&&(i!==null&&i.indexOf(v)===-1?i.push(v):C.push(v)));return}if(!w.has(v)&&(w.add(v),v.state=P,q===F||q===J?C.push(v):!v.pure&&i!==null&&i.indexOf(v)===-1&&i.push(v),v.pure&&v.accessor)){let O=m.get(v.accessor);O&&vt(Array.from(O),R=>D(R,!0))}}};var x=D;let S=Array.from(k),C=[],w=new Set;vt(S,D);for(let v of C)gt(v)}}}return l.toObservable=()=>new H(f=>{let p=!0;return $(()=>{let x=l();p?p=!1:f.next(x)})}),Object.defineProperty(l,de,{value:!0,enumerable:!0}),Object.defineProperty(l,yt,{value:o,enumerable:!1}),r}function $(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&A(T);return r&&(o.suspense=r),je(o,t),()=>I(o)}function je(e,t){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)I(e.owned[r]);e.owned=null}let n=d,o=u;if(d=e,u=e,le++,le>an)throw le=0,d=n,u=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=E;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===E&&(e.state=F)}catch(r){if((0,Q.isPromise)(r)){let s=T&&A(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ve(r)}finally{d=n,u=o}}function Z(e){if(!(e.disposed||!e.fn||e.state===F)&&(e.state===P||e.state===J||e.state===E)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)I(e.owned[t]);e.owned=null}e.renderEffect?Dt(e):je(e,e.value)}}function I(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=m.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)I(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function St(e,t,n){let o=mt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};u&&(u.owned?u.owned.push(r):u.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;m.has(c)||m.set(c,new Set);let f=m.get(c);f&&f.add(d)}if(r.state!==F){if(r.sources){for(let p of r.sources){let b=m.get(p);b&&b.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let p=0;p<r.cleanups.length;p++)r.cleanups[p]();r.cleanups=null}if(r.owned){for(let p=0;p<r.owned.length;p++)I(r.owned[p]);r.owned=null}let c=d,f=u;d=r,u=r,r.state=E;try{let p=r.fn(r.value),b=o.equals||wt;if(n?.equals===!1||!b(r.value,p)){r.value=p,o.value=p,o.version++,o.updated=Date.now();let k=s,S=m.get(k);if(S&&S.size>0){let v=function(h,q=!1){if(h===r)return;let O=h.state;if(O!==E){if(q&&!h.pure){O===F&&(h.state=J,i!==null&&i.indexOf(h)===-1?i.push(h):w.push(h));return}if(!D.has(h)&&(D.add(h),h.state=P,O===F||O===J?w.push(h):!h.pure&&i!==null&&i.indexOf(h)===-1&&i.push(h),h.pure&&h.accessor)){let R=m.get(h.accessor);if(R&&R.size>0)for(let W of Array.from(R))v(W,!0)}}};var l=v;let C=Array.from(S),w=[],D=new Set;for(let h=0;h<C.length;h++)v(C[h]);for(let h of w)gt(h)}}r.state===E&&(r.state=F)}catch(p){if((0,Q.isPromise)(p)){let b=T&&A(T);if(!b&&T){let x=f;for(;x;){if(x.contexts?.has(T.id)){b=x.contexts.get(T.id);break}x=x.owner}}return b&&(b.increment(),p.finally(()=>b.decrement())),r.value}Ve(p)}finally{d=c,u=f}}return r.value};return r.accessor=s,m.set(s,new Set),s.toObservable=()=>new H(l=>{let c=!0;return $(()=>{let p=s();c?c=!1:l.next(p)})}),Object.defineProperty(s,de,{value:!0,enumerable:!0}),Object.defineProperty(s,Tt,{value:!0,enumerable:!0}),Object.defineProperty(s,yt,{value:o,enumerable:!1}),s}function pe(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);i=[];let o=0;for(;o<t.length;){let r=t[o++],s=m.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=i.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?t.indexOf(c)===-1&&t.push(c):(c.computed||!c.pure)&&n.indexOf(c)===-1&&n.push(c)}i=null;for(let r of n)(r.computed||!r.pure)&&Z(r)}function _(e){if(i&&V>0)return e();if(i&&V===0){let t=i,n=[];i=n,V++;let o;try{o=e()}finally{V--,i=t}let r=i;return pe(n),i=r,o}V++,i=[],ae=[];try{return e()}finally{V--,Ot()}}function Ot(){if(!Me){Me=!0,le=0;try{for(;i&&i.length>0;){let e=i;i=null,pe(e)}if(i=null,ae){let e=ae;ae=null;for(let t=0;t<e.length;t++)Z(e[t])}}finally{Me=!1}}}function Ct(e){let t={owned:null,cleanups:null,contexts:null,owner:u},n=d;d=null;let o=u;u=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)I(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{u=o,d=n}}function j(e){let t=d;d=null;try{return e()}finally{d=t}}function fe(e){u&&(u.cleanups?u.cleanups.push(e):u.cleanups=[e])}function Rt(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:l}=n,c=Ue(),f=c!==void 0?Ne(c):void 0,p=f!==void 0,[b,x]=U(f!==void 0?f.value:n.initialValue,{equals:!1}),[k,S]=U(void 0,{equals:!1}),[C,w]=U(f!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,v]=U(void 0,{equals:!1}),[h,q]=U(void 0,{equals:!1}),O=Symbol(),R=O,W=!1,Gt=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},Vt=$(()=>{let y=o?o():e;if(h(),y===!1||y===null||y===void 0){R=O,_(()=>{w("unresolved"),v(void 0),S(void 0)});return}let L=W;if(W=!1,R!==O&&y===R&&!L)return;if(R=y,p){p=!1;return}let B=!1;fe(()=>B=!0);let He=j(C),jt=j(b),Ye=He==="ready"||He==="refreshing";_(()=>{w(Ye?"refreshing":"pending"),S(void 0)});try{let N=r(y,{value:jt,refetching:Ye});if((0,Q.isPromise)(N)){v(N),qe(N),N.then(M=>{B||(c!==void 0&&Ie(c,M),_(()=>{x(()=>M),Gt(M),w("ready"),v(void 0)}))},M=>{B||_(()=>{S(M),w("errored"),v(void 0)})}).catch(M=>{B||_(()=>{S(M),w("errored"),v(void 0)})});let he=T&&A(T);he&&(he.increment(),N.finally(()=>he.decrement()))}else{if(B)return;_(()=>{x(()=>N),w("ready"),v(void 0)})}}catch(N){if(B)return;_(()=>{S(N),w("errored"),v(void 0)})}});fe(Vt);let ze=()=>{let y=C();return y==="pending"||y==="refreshing"},ee=(()=>{let y=k();if(y)throw y;if(ze()){let L=D();if(L)throw L}return b()});return Object.defineProperty(ee,bt,{value:!0,enumerable:!0}),Object.defineProperty(ee,de,{value:!0,enumerable:!0}),Object.defineProperties(ee,{state:{get:C},loading:{get:()=>ze()},error:{get:k},latest:{get:b}}),[ee,{mutate:x,refetch:()=>{W=!0,q(void 0)}}]}function _t(){return u}function At(e,t){let n=u,o=d;u=e,d=null;try{return t()}finally{u=n,d=o}}function ve(e){let t=Symbol("context"),n=Ft(t);return{id:t,Provider:n,defaultValue:e}}function Ft(e){return t=>{let n=u;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return We(()=>{o=j(()=>{let r=u;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),Fe(()=>t.children)})}),o}}function A(e){let t=u;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function Et(){return new Promise(e=>{queueMicrotask(()=>{Ot(),e()})})}function $e(e){if(g&&g.running)return e(),g.done;xt();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};g=o;try{e()}finally{o.running=!1}return o.effects.length?(Ge(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,Ge(!1),r.length&&_(()=>{for(let s of r)s.state=P,Z(s)}),t()}),n):(g=null,t(),n)}function Pt(){return xt(),[Be,$e]}function kt(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):j(()=>t(l,s))}}function We(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&A(T);return r&&(o.suspense=r),Dt(o),()=>I(o)}function Dt(e){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)I(e.owned[r]);e.owned=null}let t=d,n=u,o=i;d=e,u=e,i===null&&(i=[]),e.state=E;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===E&&(e.state=F)}catch(r){if((0,Q.isPromise)(r)){let s=T&&A(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ve(r)}finally{d=t,u=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;pe(r),i=s}}}function qt(e,t,n){let o={fn:e,state:P,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,computed:!0,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]),g&&g.running?(i||(i=[]),i.indexOf(o)===-1&&i.push(o)):i?i.indexOf(o)===-1&&i.push(o):je(o,t)}var T;function Nt(){return T||(T=ve())}var ht;function Ut(){return ht||(ht=ve())}function It(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=P,Z(n)}function Mt(e){let t=T&&A(T);t&&t.inFallback()?$(()=>{t.inFallback()||e()}):e()}function Lt(e){ln=e}function Bt(e){let t=T&&A(T);return t&&(t.increment(),e.finally(()=>t.decrement())),e}var Tn={createSignal:U,createEffect:$,createMemo:St,createComputed:qt,createRoot:Ct,createSelector:Ae,createResource:Rt,batch:_,untrack:j,onCleanup:fe,getOwner:_t,runWithOwner:At,createContext:ve,useContext:A,flush:Et,startTransition:$e,useTransition:Pt,isSignal:K,on:kt,createRenderEffect:We,getSuspenseContext:Nt,getSuspenseListContext:Ut,resumeEffects:It,onResolve:Mt,setScheduler:Lt,trackPromise:Bt};
@@ -1 +1 @@
1
- import{isObject as pt}from"@fluixi/utils/object";import{isFunction as Ie}from"@fluixi/utils/functions";var $=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if(Ie(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(pt(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if(Ie(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var Q=class extends ${constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},de=class extends Q{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var W=class extends ${constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof Q?r=t:r=new de(t,n,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};import{isPromise as le}from"@fluixi/utils";var Z=!1,vt=Symbol.for("signal"),ht=Symbol.for("memo"),Tt=Symbol.for("resource");function ee(e){return typeof e=="function"&&e[vt]===!0}function bt(e){return typeof e=="function"&&e[ht]===!0}function yt(e){return typeof e=="function"&&e[Tt]===!0}function mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function wt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function xt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Me(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Me(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var gt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[gt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Le=0,Be=1,z=2,te=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},ne=class extends te{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(z);pe(this)}}peek(){return this._value}},G=class extends te{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=z;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Be&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===z)break}(this.state===z||!this._initialized)&&this.recompute(),this.state=Le}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let n=a.consumer,o=a.untracked;a.consumer=this,a.untracked=!1;let r,s=!1,l;try{r=this._fn()}catch(f){s=!0,l=f,r=this._value}finally{a.consumer=n,a.untracked=o}let c=!this._initialized||this._threw!==s||(s?l!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=l,this._value=r,c){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(z);pe(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Le;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Be);pe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function pe(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var re=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function Ot(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Te(){return a.owner}function oe(e,t){let n=a.owner;a.owner=e;try{return t()}finally{a.owner=n}}function be(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function ve(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)ve(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function je(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Ct(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(ye)))}function ye(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{a.flushing=!1}}function Ve(){a.batchDepth===0&&ye()}var he=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=Ot(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new G(()=>{ve(this.owner,!1),oe(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new re(()=>Ct(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),ve(this.owner))}};function $e(e){let t=new he(e);return()=>t.dispose()}function Rt(e){return!!e&&typeof e.then=="function"}je(()=>{});var We=Symbol.for("signal"),_t=Symbol.for("memo"),At=Symbol.for("signal-node");function me(e,t){let n=new ne(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let l=typeof s=="function"?s(n.peek()):s;return n.set(l),Ve(),l});return Object.defineProperty(o,We,{value:!0,enumerable:!0}),Object.defineProperty(o,At,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function se(e,t,n){let o=t,r=Te(),s=new G(()=>oe(r,()=>{try{return o=e(o)}catch(c){if(Rt(c))return Ge(c),o;throw c}}),{equals:n?.equals}),l=(()=>s.get());return Object.defineProperty(l,We,{value:!0,enumerable:!0}),Object.defineProperty(l,_t,{value:!0,enumerable:!0}),l}function we(e,t){let n=t;return $e(()=>{n=e(n)})}function ze(e,t=(n,o)=>n===o){let n=new Map;return we(()=>{let o=e();for(let[r,s]of n){let[l,c]=s,f=t(r,o);l()!==f&&c(f)}}),o=>{let r=n.get(o);if(!r){let[s,l]=me(!1);r=[s,l],n.set(o,r);let c=e();l(t(o,c))}return r[0]()}}function Ft(e,t){let[n,o]=me(e(),t);return we(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function Et(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,r.length>0){let s=r[r.length-1];typeof s=="object"&&s&&!s.tagName&&s.target&&s.target.tagName&&(s=s.target),s&&typeof s=="object"&&s.tagName&&(s.tagName.toLowerCase()==="input"||s.tagName.toLowerCase()==="textarea")&&s.focus()}e(...r)},t)};return be(()=>{n!==void 0&&clearTimeout(n)}),o}function ie(e){if(typeof e=="function"&&!e.length){let t=e();return ee(t)?t:ie(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=ie(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function He(e){let t=se(e);return se(()=>ie(t()))}var xe=null;function Pt(e){xe=e}function Ye(e){xe&&xe(e)}var ge=null;function kt(e){ge=e}function Ke(e){return ge?ge(e):void 0}var Se=null;function Dt(e){Se=e}function Xe(){return Se?Se():void 0}var Oe=null;function qt(e){Oe=e}function Je(e,t){Oe&&Oe(e,t)}var Ee=Symbol.for("signal"),Nt=Symbol.for("memo"),Ut=Symbol.for("resource"),Qe=Symbol("fluixi-proxy"),tt=Symbol.for("signal-node"),A=0,H=1,E=2,F=3,u=null,d=null,i=null,ue=null,ae=0,It=!1,Ce=!1,j=0,Mt=1e6,m=new WeakMap,g=null;var Lt=null,Bt=new Map,Gt=0,Re={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Mn(e){u=e,Re.owner=e,Re.context=e}function Ln(){return Re}function jt(){return`node_${++Gt}_${Date.now()}`}function Vt(e){!1}function nt(e,t,n){let o={id:jt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return Vt(o),o}function rt(e,t){return e===t}function Pe(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var _e=null,Ae=null;function ot(){if(!_e){let[e,t]=M(!1);_e=e,Ae=t}}function st(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)X(e);else if(e.pure&&!e.computed&&e.accessor){let t=d,n=i;d=null,i=[],e.accessor(),d=t;let o=i;if(i=n,o.length>0){let r=i;ce(o),i=r}}}function Ze(e,t){for(let n=0;n<e.length;n++)t(e[n])}function M(e,t){let n=e;typeof n=="object"&&n&&Qe in n&&delete n[Qe];let o=nt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[l,c];m.set(r,new Set);let s;function l(){let f=d;if(f){f.sources?f.sources.indexOf(r)===-1&&f.sources.push(r):f.sources=[r];let p=m.get(r);p&&!p.has(f)&&p.add(f)}return n}function c(f){let p=typeof f=="function"?f(n):f,b=o.equals||rt;if(t?.equals===!1||!b(n,p)){n=p,o.value=p,o.version++,o.updated=Date.now();let k=m.get(r);if(k&&k.size>0){let D=function(v,h=!1){let q=v.state;if(!(q===F&&v===d)){if(h&&!v.pure){q===A&&(v.state=H,It&&(i!==null&&i.indexOf(v)===-1?i.push(v):C.push(v)));return}if(!w.has(v)&&(w.add(v),v.state=E,q===A||q===H?C.push(v):!v.pure&&i!==null&&i.indexOf(v)===-1&&i.push(v),v.pure&&v.accessor)){let O=m.get(v.accessor);O&&Ze(Array.from(O),R=>D(R,!0))}}};var x=D;let S=Array.from(k),C=[],w=new Set;Ze(S,D);for(let v of C)st(v)}}}return l.toObservable=()=>new W(f=>{let p=!0;return K(()=>{let x=l();p?p=!1:f.next(x)})}),Object.defineProperty(l,Ee,{value:!0,enumerable:!0}),Object.defineProperty(l,tt,{value:o,enumerable:!1}),r}function K(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),ke(o,t),()=>U(o)}function ke(e,t){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let n=d,o=u;if(d=e,u=e,ae++,ae>Mt)throw ae=0,d=n,u=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=F;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===F&&(e.state=A)}catch(r){if(le(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Pe(r)}finally{d=n,u=o}}function X(e){if(!(e.disposed||!e.fn||e.state===A)&&(e.state===E||e.state===H||e.state===F)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)U(e.owned[t]);e.owned=null}e.renderEffect?lt(e):ke(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=m.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)U(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function $t(e,t,n){let o=nt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};u&&(u.owned?u.owned.push(r):u.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;m.has(c)||m.set(c,new Set);let f=m.get(c);f&&f.add(d)}if(r.state!==A){if(r.sources){for(let p of r.sources){let b=m.get(p);b&&b.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let p=0;p<r.cleanups.length;p++)r.cleanups[p]();r.cleanups=null}if(r.owned){for(let p=0;p<r.owned.length;p++)U(r.owned[p]);r.owned=null}let c=d,f=u;d=r,u=r,r.state=F;try{let p=r.fn(r.value),b=o.equals||rt;if(n?.equals===!1||!b(r.value,p)){r.value=p,o.value=p,o.version++,o.updated=Date.now();let k=s,S=m.get(k);if(S&&S.size>0){let v=function(h,q=!1){if(h===r)return;let O=h.state;if(O!==F){if(q&&!h.pure){O===A&&(h.state=H,i!==null&&i.indexOf(h)===-1?i.push(h):w.push(h));return}if(!D.has(h)&&(D.add(h),h.state=E,O===A||O===H?w.push(h):!h.pure&&i!==null&&i.indexOf(h)===-1&&i.push(h),h.pure&&h.accessor)){let R=m.get(h.accessor);if(R&&R.size>0)for(let V of Array.from(R))v(V,!0)}}};var l=v;let C=Array.from(S),w=[],D=new Set;for(let h=0;h<C.length;h++)v(C[h]);for(let h of w)st(h)}}r.state===F&&(r.state=A)}catch(p){if(le(p)){let b=T&&P(T);if(!b&&T){let x=f;for(;x;){if(x.contexts?.has(T.id)){b=x.contexts.get(T.id);break}x=x.owner}}return b&&(b.increment(),p.finally(()=>b.decrement())),r.value}Pe(p)}finally{d=c,u=f}}return r.value};return r.accessor=s,m.set(s,new Set),s.toObservable=()=>new W(l=>{let c=!0;return K(()=>{let p=s();c?c=!1:l.next(p)})}),Object.defineProperty(s,Ee,{value:!0,enumerable:!0}),Object.defineProperty(s,Nt,{value:!0,enumerable:!0}),Object.defineProperty(s,tt,{value:o,enumerable:!1}),s}function ce(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);i=[];let o=0;for(;o<t.length;){let r=t[o++],s=m.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=i.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?t.indexOf(c)===-1&&t.push(c):(c.computed||!c.pure)&&n.indexOf(c)===-1&&n.push(c)}i=null;for(let r of n)(r.computed||!r.pure)&&X(r)}function _(e){if(i&&j>0)return e();if(i&&j===0){let t=i,n=[];i=n,j++;let o;try{o=e()}finally{j--,i=t}let r=i;return ce(n),i=r,o}j++,i=[],ue=[];try{return e()}finally{j--,it()}}function it(){if(!Ce){Ce=!0,ae=0;try{for(;i&&i.length>0;){let e=i;i=null,ce(e)}if(i=null,ue){let e=ue;ue=null;for(let t=0;t<e.length;t++)X(e[t])}}finally{Ce=!1}}}function Wt(e){let t={owned:null,cleanups:null,contexts:null,owner:u},n=d;d=null;let o=u;u=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)U(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{u=o,d=n}}function Y(e){let t=d;d=null;try{return e()}finally{d=t}}function Fe(e){u&&(u.cleanups?u.cleanups.push(e):u.cleanups=[e])}function zt(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:l}=n,c=Xe(),f=c!==void 0?Ke(c):void 0,p=f!==void 0,[b,x]=M(f!==void 0?f.value:n.initialValue,{equals:!1}),[k,S]=M(void 0,{equals:!1}),[C,w]=M(f!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,v]=M(void 0,{equals:!1}),[h,q]=M(void 0,{equals:!1}),O=Symbol(),R=O,V=!1,ct=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},ft=K(()=>{let y=o?o():e;if(h(),y===!1||y===null||y===void 0){R=O,_(()=>{w("unresolved"),v(void 0),S(void 0)});return}let L=V;if(V=!1,R!==O&&y===R&&!L)return;if(R=y,p){p=!1;return}let B=!1;Fe(()=>B=!0);let Ne=Y(C),dt=Y(b),Ue=Ne==="ready"||Ne==="refreshing";_(()=>{w(Ue?"refreshing":"pending"),S(void 0)});try{let N=r(y,{value:dt,refetching:Ue});if(le(N)){v(N),Ye(N),N.then(I=>{B||(c!==void 0&&Je(c,I),_(()=>{x(()=>I),ct(I),w("ready"),v(void 0)}))},I=>{B||_(()=>{S(I),w("errored"),v(void 0)})}).catch(I=>{B||_(()=>{S(I),w("errored"),v(void 0)})});let fe=T&&P(T);fe&&(fe.increment(),N.finally(()=>fe.decrement()))}else{if(B)return;_(()=>{x(()=>N),w("ready"),v(void 0)})}}catch(N){if(B)return;_(()=>{S(N),w("errored"),v(void 0)})}});Fe(ft);let qe=()=>{let y=C();return y==="pending"||y==="refreshing"},J=(()=>{let y=k();if(y)throw y;if(qe()){let L=D();if(L)throw L}return b()});return Object.defineProperty(J,Ut,{value:!0,enumerable:!0}),Object.defineProperty(J,Ee,{value:!0,enumerable:!0}),Object.defineProperties(J,{state:{get:C},loading:{get:()=>qe()},error:{get:k},latest:{get:b}}),[J,{mutate:x,refetch:()=>{V=!0,q(void 0)}}]}function Ht(){return u}function Yt(e,t){let n=u,o=d;u=e,d=null;try{return t()}finally{u=n,d=o}}function De(e){let t=Symbol("context"),n=Kt(t);return{id:t,Provider:n,defaultValue:e}}function Kt(e){return t=>{let n=u;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return at(()=>{o=Y(()=>{let r=u;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),He(()=>t.children)})}),o}}function P(e){let t=u;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function Xt(){return new Promise(e=>{queueMicrotask(()=>{it(),e()})})}function ut(e){if(g&&g.running)return e(),g.done;ot();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};g=o;try{e()}finally{o.running=!1}return o.effects.length?(Ae(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,Ae(!1),r.length&&_(()=>{for(let s of r)s.state=E,X(s)}),t()}),n):(g=null,t(),n)}function Jt(){return ot(),[_e,ut]}function Qt(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):Y(()=>t(l,s))}}function at(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),lt(o),()=>U(o)}function lt(e){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let t=d,n=u,o=i;d=e,u=e,i===null&&(i=[]),e.state=F;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===F&&(e.state=A)}catch(r){if(le(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Pe(r)}finally{d=t,u=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;ce(r),i=s}}}function Zt(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,computed:!0,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]),g&&g.running?(i||(i=[]),i.indexOf(o)===-1&&i.push(o)):i?i.indexOf(o)===-1&&i.push(o):ke(o,t)}var T;function en(){return T||(T=De())}var et;function tn(){return et||(et=De())}function nn(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=E,X(n)}function rn(e){let t=T&&P(T);t&&t.inFallback()?K(()=>{t.inFallback()||e()}):e()}function on(e){Lt=e}function sn(e){let t=T&&P(T);return t&&(t.increment(),e.finally(()=>t.decrement())),e}var Gn={createSignal:M,createEffect:K,createMemo:$t,createComputed:Zt,createRoot:Wt,createSelector:ze,createResource:zt,batch:_,untrack:Y,onCleanup:Fe,getOwner:Ht,runWithOwner:Yt,createContext:De,useContext:P,flush:Xt,startTransition:ut,useTransition:Jt,isSignal:ee,on:Qt,createRenderEffect:at,getSuspenseContext:en,getSuspenseListContext:tn,resumeEffects:nn,onResolve:rn,setScheduler:on,trackPromise:sn};export{Nt as $MEMO,Qe as $PROXY,Ut as $RESOURCE,Ee as $SIGNAL,Z as __DEV__,_ as batch,Zt as createComputed,De as createContext,Et as createDebounce,Ft as createDeferred,K as createEffect,$t as createMemo,Kt as createProvider,at as createRenderEffect,zt as createResource,Wt as createRoot,ze as createSelector,M as createSignal,Gn as default,Xt as flush,Ht as getOwner,Ke as getServerData,Ln as getSharedConfig,en as getSuspenseContext,tn as getSuspenseListContext,mt as isComponent,bt as isMemo,xt as isProvider,yt as isResource,ee as isSignal,wt as isSuspense,Me as makeArrayFlat,Xe as nextResourceId,Qt as on,Fe as onCleanup,rn as onResolve,He as readChildren,Je as reportResourceData,nn as resumeEffects,Yt as runWithOwner,Mn as setOwner,qt as setResourceDataSink,Dt as setResourceIdSource,Pt as setResourceTracker,on as setScheduler,kt as setServerDataGetter,Re as sharedConfig,ut as startTransition,sn as trackPromise,Ye as trackResourcePromise,Y as untrack,P as useContext,Jt as useTransition};
1
+ import{isObject as pt}from"@fluixi/utils/object";import{isFunction as Ie}from"@fluixi/utils/functions";var $=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if(Ie(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(pt(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if(Ie(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var Q=class extends ${constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},de=class extends Q{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var W=class extends ${constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof Q?r=t:r=new de(t,n,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};import{isPromise as le}from"@fluixi/utils";var Z=!1,vt=Symbol.for("signal"),ht=Symbol.for("memo"),Tt=Symbol.for("resource");function ee(e){return typeof e=="function"&&e[vt]===!0}function bt(e){return typeof e=="function"&&e[ht]===!0}function yt(e){return typeof e=="function"&&e[Tt]===!0}function mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function wt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function xt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Me(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Me(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var gt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[gt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Le=0,Be=1,z=2,te=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},ne=class extends te{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(z);pe(this)}}peek(){return this._value}},G=class extends te{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=z;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Be&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===z)break}(this.state===z||!this._initialized)&&this.recompute(),this.state=Le}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let n=a.consumer,o=a.untracked;a.consumer=this,a.untracked=!1;let r,s=!1,l;try{r=this._fn()}catch(f){s=!0,l=f,r=this._value}finally{a.consumer=n,a.untracked=o}let c=!this._initialized||this._threw!==s||(s?l!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=l,this._value=r,c){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(z);pe(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Le;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Be);pe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function pe(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var re=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function Ot(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Te(){return a.owner}function oe(e,t){let n=a.owner;a.owner=e;try{return t()}finally{a.owner=n}}function be(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function ve(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)ve(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function Ve(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Ct(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(ye)))}function ye(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{a.flushing=!1}}function je(){a.batchDepth===0&&ye()}var he=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=Ot(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new G(()=>{ve(this.owner,!1),oe(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new re(()=>Ct(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),ve(this.owner))}};function $e(e){let t=new he(e);return()=>t.dispose()}function Rt(e){return!!e&&typeof e.then=="function"}Ve(()=>{});var We=Symbol.for("signal"),_t=Symbol.for("memo"),At=Symbol.for("signal-node");function me(e,t){let n=new ne(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let l=typeof s=="function"?s(n.peek()):s;return n.set(l),je(),l});return Object.defineProperty(o,We,{value:!0,enumerable:!0}),Object.defineProperty(o,At,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function se(e,t,n){let o=t,r=Te(),s=new G(()=>oe(r,()=>{try{return o=e(o)}catch(c){if(Rt(c))return Ge(c),o;throw c}}),{equals:n?.equals}),l=(()=>s.get());return Object.defineProperty(l,We,{value:!0,enumerable:!0}),Object.defineProperty(l,_t,{value:!0,enumerable:!0}),l}function we(e,t){let n=t;return $e(()=>{n=e(n)})}function ze(e,t=(n,o)=>n===o){let n=new Map;return we(()=>{let o=e();for(let[r,s]of n){let[l,c]=s,f=t(r,o);l()!==f&&c(f)}}),o=>{let r=n.get(o);if(!r){let[s,l]=me(!1);r=[s,l],n.set(o,r);let c=e();l(t(o,c))}return r[0]()}}function Ft(e,t){let[n,o]=me(e(),t);return we(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function Et(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{n=void 0,e(...r)},t)};return be(()=>{n!==void 0&&clearTimeout(n)}),o}function ie(e){if(typeof e=="function"&&!e.length){let t=e();return ee(t)?t:ie(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=ie(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function He(e){let t=se(e);return se(()=>ie(t()))}var xe=null;function Pt(e){xe=e}function Ye(e){xe&&xe(e)}var ge=null;function kt(e){ge=e}function Ke(e){return ge?ge(e):void 0}var Se=null;function Dt(e){Se=e}function Xe(){return Se?Se():void 0}var Oe=null;function qt(e){Oe=e}function Je(e,t){Oe&&Oe(e,t)}var Ee=Symbol.for("signal"),Nt=Symbol.for("memo"),Ut=Symbol.for("resource"),Qe=Symbol("fluixi-proxy"),tt=Symbol.for("signal-node"),A=0,H=1,E=2,F=3,u=null,d=null,i=null,ue=null,ae=0,It=!1,Ce=!1,V=0,Mt=1e6,m=new WeakMap,g=null;var Lt=null,Bt=new Map,Gt=0,Re={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Mn(e){u=e,Re.owner=e,Re.context=e}function Ln(){return Re}function Vt(){return`node_${++Gt}_${Date.now()}`}function jt(e){!1}function nt(e,t,n){let o={id:Vt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return jt(o),o}function rt(e,t){return e===t}function Pe(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var _e=null,Ae=null;function ot(){if(!_e){let[e,t]=M(!1);_e=e,Ae=t}}function st(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)X(e);else if(e.pure&&!e.computed&&e.accessor){let t=d,n=i;d=null,i=[],e.accessor(),d=t;let o=i;if(i=n,o.length>0){let r=i;ce(o),i=r}}}function Ze(e,t){for(let n=0;n<e.length;n++)t(e[n])}function M(e,t){let n=e;typeof n=="object"&&n&&Qe in n&&delete n[Qe];let o=nt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[l,c];m.set(r,new Set);let s;function l(){let f=d;if(f){f.sources?f.sources.indexOf(r)===-1&&f.sources.push(r):f.sources=[r];let p=m.get(r);p&&!p.has(f)&&p.add(f)}return n}function c(f){let p=typeof f=="function"?f(n):f,b=o.equals||rt;if(t?.equals===!1||!b(n,p)){n=p,o.value=p,o.version++,o.updated=Date.now();let k=m.get(r);if(k&&k.size>0){let D=function(v,h=!1){let q=v.state;if(!(q===F&&v===d)){if(h&&!v.pure){q===A&&(v.state=H,It&&(i!==null&&i.indexOf(v)===-1?i.push(v):C.push(v)));return}if(!w.has(v)&&(w.add(v),v.state=E,q===A||q===H?C.push(v):!v.pure&&i!==null&&i.indexOf(v)===-1&&i.push(v),v.pure&&v.accessor)){let O=m.get(v.accessor);O&&Ze(Array.from(O),R=>D(R,!0))}}};var x=D;let S=Array.from(k),C=[],w=new Set;Ze(S,D);for(let v of C)st(v)}}}return l.toObservable=()=>new W(f=>{let p=!0;return K(()=>{let x=l();p?p=!1:f.next(x)})}),Object.defineProperty(l,Ee,{value:!0,enumerable:!0}),Object.defineProperty(l,tt,{value:o,enumerable:!1}),r}function K(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),ke(o,t),()=>U(o)}function ke(e,t){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let n=d,o=u;if(d=e,u=e,ae++,ae>Mt)throw ae=0,d=n,u=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=F;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===F&&(e.state=A)}catch(r){if(le(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Pe(r)}finally{d=n,u=o}}function X(e){if(!(e.disposed||!e.fn||e.state===A)&&(e.state===E||e.state===H||e.state===F)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)U(e.owned[t]);e.owned=null}e.renderEffect?lt(e):ke(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=m.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)U(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function $t(e,t,n){let o=nt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};u&&(u.owned?u.owned.push(r):u.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;m.has(c)||m.set(c,new Set);let f=m.get(c);f&&f.add(d)}if(r.state!==A){if(r.sources){for(let p of r.sources){let b=m.get(p);b&&b.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let p=0;p<r.cleanups.length;p++)r.cleanups[p]();r.cleanups=null}if(r.owned){for(let p=0;p<r.owned.length;p++)U(r.owned[p]);r.owned=null}let c=d,f=u;d=r,u=r,r.state=F;try{let p=r.fn(r.value),b=o.equals||rt;if(n?.equals===!1||!b(r.value,p)){r.value=p,o.value=p,o.version++,o.updated=Date.now();let k=s,S=m.get(k);if(S&&S.size>0){let v=function(h,q=!1){if(h===r)return;let O=h.state;if(O!==F){if(q&&!h.pure){O===A&&(h.state=H,i!==null&&i.indexOf(h)===-1?i.push(h):w.push(h));return}if(!D.has(h)&&(D.add(h),h.state=E,O===A||O===H?w.push(h):!h.pure&&i!==null&&i.indexOf(h)===-1&&i.push(h),h.pure&&h.accessor)){let R=m.get(h.accessor);if(R&&R.size>0)for(let j of Array.from(R))v(j,!0)}}};var l=v;let C=Array.from(S),w=[],D=new Set;for(let h=0;h<C.length;h++)v(C[h]);for(let h of w)st(h)}}r.state===F&&(r.state=A)}catch(p){if(le(p)){let b=T&&P(T);if(!b&&T){let x=f;for(;x;){if(x.contexts?.has(T.id)){b=x.contexts.get(T.id);break}x=x.owner}}return b&&(b.increment(),p.finally(()=>b.decrement())),r.value}Pe(p)}finally{d=c,u=f}}return r.value};return r.accessor=s,m.set(s,new Set),s.toObservable=()=>new W(l=>{let c=!0;return K(()=>{let p=s();c?c=!1:l.next(p)})}),Object.defineProperty(s,Ee,{value:!0,enumerable:!0}),Object.defineProperty(s,Nt,{value:!0,enumerable:!0}),Object.defineProperty(s,tt,{value:o,enumerable:!1}),s}function ce(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);i=[];let o=0;for(;o<t.length;){let r=t[o++],s=m.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=i.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?t.indexOf(c)===-1&&t.push(c):(c.computed||!c.pure)&&n.indexOf(c)===-1&&n.push(c)}i=null;for(let r of n)(r.computed||!r.pure)&&X(r)}function _(e){if(i&&V>0)return e();if(i&&V===0){let t=i,n=[];i=n,V++;let o;try{o=e()}finally{V--,i=t}let r=i;return ce(n),i=r,o}V++,i=[],ue=[];try{return e()}finally{V--,it()}}function it(){if(!Ce){Ce=!0,ae=0;try{for(;i&&i.length>0;){let e=i;i=null,ce(e)}if(i=null,ue){let e=ue;ue=null;for(let t=0;t<e.length;t++)X(e[t])}}finally{Ce=!1}}}function Wt(e){let t={owned:null,cleanups:null,contexts:null,owner:u},n=d;d=null;let o=u;u=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)U(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{u=o,d=n}}function Y(e){let t=d;d=null;try{return e()}finally{d=t}}function Fe(e){u&&(u.cleanups?u.cleanups.push(e):u.cleanups=[e])}function zt(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:l}=n,c=Xe(),f=c!==void 0?Ke(c):void 0,p=f!==void 0,[b,x]=M(f!==void 0?f.value:n.initialValue,{equals:!1}),[k,S]=M(void 0,{equals:!1}),[C,w]=M(f!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,v]=M(void 0,{equals:!1}),[h,q]=M(void 0,{equals:!1}),O=Symbol(),R=O,j=!1,ct=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},ft=K(()=>{let y=o?o():e;if(h(),y===!1||y===null||y===void 0){R=O,_(()=>{w("unresolved"),v(void 0),S(void 0)});return}let L=j;if(j=!1,R!==O&&y===R&&!L)return;if(R=y,p){p=!1;return}let B=!1;Fe(()=>B=!0);let Ne=Y(C),dt=Y(b),Ue=Ne==="ready"||Ne==="refreshing";_(()=>{w(Ue?"refreshing":"pending"),S(void 0)});try{let N=r(y,{value:dt,refetching:Ue});if(le(N)){v(N),Ye(N),N.then(I=>{B||(c!==void 0&&Je(c,I),_(()=>{x(()=>I),ct(I),w("ready"),v(void 0)}))},I=>{B||_(()=>{S(I),w("errored"),v(void 0)})}).catch(I=>{B||_(()=>{S(I),w("errored"),v(void 0)})});let fe=T&&P(T);fe&&(fe.increment(),N.finally(()=>fe.decrement()))}else{if(B)return;_(()=>{x(()=>N),w("ready"),v(void 0)})}}catch(N){if(B)return;_(()=>{S(N),w("errored"),v(void 0)})}});Fe(ft);let qe=()=>{let y=C();return y==="pending"||y==="refreshing"},J=(()=>{let y=k();if(y)throw y;if(qe()){let L=D();if(L)throw L}return b()});return Object.defineProperty(J,Ut,{value:!0,enumerable:!0}),Object.defineProperty(J,Ee,{value:!0,enumerable:!0}),Object.defineProperties(J,{state:{get:C},loading:{get:()=>qe()},error:{get:k},latest:{get:b}}),[J,{mutate:x,refetch:()=>{j=!0,q(void 0)}}]}function Ht(){return u}function Yt(e,t){let n=u,o=d;u=e,d=null;try{return t()}finally{u=n,d=o}}function De(e){let t=Symbol("context"),n=Kt(t);return{id:t,Provider:n,defaultValue:e}}function Kt(e){return t=>{let n=u;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return at(()=>{o=Y(()=>{let r=u;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),He(()=>t.children)})}),o}}function P(e){let t=u;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function Xt(){return new Promise(e=>{queueMicrotask(()=>{it(),e()})})}function ut(e){if(g&&g.running)return e(),g.done;ot();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};g=o;try{e()}finally{o.running=!1}return o.effects.length?(Ae(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,Ae(!1),r.length&&_(()=>{for(let s of r)s.state=E,X(s)}),t()}),n):(g=null,t(),n)}function Jt(){return ot(),[_e,ut]}function Qt(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):Y(()=>t(l,s))}}function at(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};u&&(u.owned?u.owned.push(o):u.owned=[o]);let r=T&&P(T);return r&&(o.suspense=r),lt(o),()=>U(o)}function lt(e){if(e.sources){for(let r of e.sources){let s=m.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let t=d,n=u,o=i;d=e,u=e,i===null&&(i=[]),e.state=F;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===F&&(e.state=A)}catch(r){if(le(r)){let s=T&&P(T);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Pe(r)}finally{d=t,u=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;ce(r),i=s}}}function Zt(e,t,n){let o={fn:e,state:E,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:u,contexts:null,pure:!0,computed:!0,updatedAt:null};u&&(u.owned?u.owned.push(o):u.owned=[o]),g&&g.running?(i||(i=[]),i.indexOf(o)===-1&&i.push(o)):i?i.indexOf(o)===-1&&i.push(o):ke(o,t)}var T;function en(){return T||(T=De())}var et;function tn(){return et||(et=De())}function nn(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=E,X(n)}function rn(e){let t=T&&P(T);t&&t.inFallback()?K(()=>{t.inFallback()||e()}):e()}function on(e){Lt=e}function sn(e){let t=T&&P(T);return t&&(t.increment(),e.finally(()=>t.decrement())),e}var Gn={createSignal:M,createEffect:K,createMemo:$t,createComputed:Zt,createRoot:Wt,createSelector:ze,createResource:zt,batch:_,untrack:Y,onCleanup:Fe,getOwner:Ht,runWithOwner:Yt,createContext:De,useContext:P,flush:Xt,startTransition:ut,useTransition:Jt,isSignal:ee,on:Qt,createRenderEffect:at,getSuspenseContext:en,getSuspenseListContext:tn,resumeEffects:nn,onResolve:rn,setScheduler:on,trackPromise:sn};export{Nt as $MEMO,Qe as $PROXY,Ut as $RESOURCE,Ee as $SIGNAL,Z as __DEV__,_ as batch,Zt as createComputed,De as createContext,Et as createDebounce,Ft as createDeferred,K as createEffect,$t as createMemo,Kt as createProvider,at as createRenderEffect,zt as createResource,Wt as createRoot,ze as createSelector,M as createSignal,Gn as default,Xt as flush,Ht as getOwner,Ke as getServerData,Ln as getSharedConfig,en as getSuspenseContext,tn as getSuspenseListContext,mt as isComponent,bt as isMemo,xt as isProvider,yt as isResource,ee as isSignal,wt as isSuspense,Me as makeArrayFlat,Xe as nextResourceId,Qt as on,Fe as onCleanup,rn as onResolve,He as readChildren,Je as reportResourceData,nn as resumeEffects,Yt as runWithOwner,Mn as setOwner,qt as setResourceDataSink,Dt as setResourceIdSource,Pt as setResourceTracker,on as setScheduler,kt as setServerDataGetter,Re as sharedConfig,ut as startTransition,sn as trackPromise,Ye as trackResourcePromise,Y as untrack,P as useContext,Jt as useTransition};