@fluixi/reactive 1.0.0-alpha.67 → 1.0.0-alpha.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/reactive.cjs +1 -1
- package/dist/cdn/reactive.global.js +1 -1
- package/dist/cdn/reactive.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/lib/index.cjs +1 -1
- package/dist/lib/index.mjs +1 -1
- package/dist/lib/signal/cached-resource.cjs +1 -1
- package/dist/lib/signal/cached-resource.mjs +1 -1
- package/dist/lib/signal/graph/debounced.cjs +1 -1
- package/dist/lib/signal/graph/debounced.mjs +1 -1
- package/dist/lib/signal/graph/resource.cjs +1 -1
- package/dist/lib/signal/graph/resource.mjs +1 -1
- package/dist/lib/signal/graph/runtime.cjs +1 -1
- package/dist/lib/signal/graph/runtime.d.ts +16 -0
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +23 -0
- package/dist/lib/signal/graph/runtime.mjs +1 -1
- package/dist/lib/signal/graph/signal-next.cjs +1 -1
- package/dist/lib/signal/graph/signal-next.d.ts +1 -1
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
- package/dist/lib/signal/graph/signal-next.js +1 -1
- package/dist/lib/signal/graph/signal-next.mjs +1 -1
- package/dist/lib/signal/index-legacy.cjs +1 -1
- package/dist/lib/signal/index-legacy.mjs +1 -1
- package/dist/lib/signal/index.cjs +1 -1
- package/dist/lib/signal/index.mjs +1 -1
- package/dist/lib/signal/list.cjs +1 -1
- package/dist/lib/signal/list.mjs +1 -1
- package/dist/lib/signal/utilities.cjs +1 -1
- package/dist/lib/signal/utilities.mjs +1 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as mt}from"@fluixi/utils/object";import{isFunction as qe}from"@fluixi/utils/functions";var q=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(qe(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(mt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(qe(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var M=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ce=class extends M{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function Or(e){return new M(e.next,e.error,e.complete)}var N=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof M?o=t:o=new ce(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Me=class extends N{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new N(n=>this.subscribe(n))}};var vt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[vt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Ne=0,$e=1,$=2,J=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))}},P=class extends J{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty($);le(this)}}peek(){return this._value}},O=class extends J{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=$;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===$)break}(this.state===$||!this._initialized)&&this.recompute(),this.state=Ne}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty($);le(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===Ne;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function le(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 r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function L(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function xt(e){return!!e&&e.disposed===!0}function ee(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function V(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=ee(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function wt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function te(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function K(e,t,r){let n=ee(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ke(e){a.onSuspend=e}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function We(e){a.onError=e}function re(){return a.owner}function He(e){let t=a.owner;return a.owner=e,t}function G(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function Z(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)Z(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function F(e){let t=ee(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>Z(t))}finally{a.owner=r}}function ze(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Ot(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(W)))}function W(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Ye(){a.batchDepth===0&&W()}function fe(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&W()}}var pe=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=ee(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{Z(this.owner,!1),G(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new D(()=>Ot(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),Z(this.owner))}};function ne(e){let t=new pe(e);return()=>t.dispose()}function gt(e){return!!e&&typeof e.then=="function"}ze(()=>{});var Xe=Symbol.for("signal"),At=Symbol.for("memo"),Rt=Symbol.for("signal-node");function d(e,t){let r=new P(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Ye(),i});return Object.defineProperty(n,Xe,{value:!0,enumerable:!0}),Object.defineProperty(n,Rt,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=re(),s=new O(()=>G(o,()=>{try{return n=e(n)}catch(c){if(gt(c))return Ge(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Xe,{value:!0,enumerable:!0}),Object.defineProperty(i,At,{value:!0,enumerable:!0}),i}function C(e,t){let r=t;return ne(()=>{r=e(r)})}function _t(e,t){let r=t;ne(()=>{r=e(r)})}function kt(e,t){let r=t;return ne(()=>{r=e(r)})}function g(e){return fe(e)}function v(e){return L(e)}function Qe(e){return fe(e),Promise.resolve()}function Et(){return[()=>!1,Qe]}function Pt(){return W(),Promise.resolve()}function Dt(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=L(()=>t(c,o,i));return o=c,u}}function qr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,f,b;F(h=>{b=h;let[k,B]=d(u);f=B,l=t(p,k)});let x={item:p,rendered:l,dispose:b,setIndex:f};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Mr(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return v(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let f=t(i[l]),b=c.get(f);if(b&&!y.has(f))b.setIndex(l),u.push(b);else{let x,h,k;F(B=>{k=B;let[A,j]=d(l);h=j;let Y=S(E=>{let w=(e()||[])[A()];return w??E},i[l]);x=r(Y,A)}),u.push({rendered:x,dispose:k,setIndex:h})}p.push(f),y.add(f)}for(let[l,f]of c)y.has(l)||f.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Nr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,f=o[u];F(b=>{l=b;let[x,h]=d(f);y=h,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var de=!1,Ft=Symbol.for("signal"),Ct=Symbol.for("memo"),It=Symbol.for("resource");function ye(e){return typeof e=="function"&&e[Ft]===!0}function Ut(e){return typeof e=="function"&&e[Ct]===!0}function Bt(e){return typeof e=="function"&&e[It]===!0}function jt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function qt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Je(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Je(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var be=null;function Nt(e){be=e}function ve(e){be&&be(e)}var he=null;function $t(e){he=e}function Se(e){return he?he(e):void 0}var Te=null;function Lt(e){Te=e}function xe(){return Te?Te():void 0}var me=null;function Vt(e){me=e}function we(e,t){me&&me(e,t)}function Kt(e,t=(r,n)=>r===n){let r=new Map;return C(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=d(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Gt(e,t){let[r,n]=d(e(),t);return C(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function Wt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Ht(e){return!!e&&typeof e.then=="function"}var Oe=Symbol();function ge(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=xe(),i=s!==void 0?Se(s):void 0,c=i!==void 0,[u,p]=d(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=d(void 0,{equals:!1}),[f,b]=d(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,h]=d(void 0,{equals:!1}),[k,B]=d(void 0,{equals:!1}),A=Oe,j=!1;C(()=>{let T=n();if(k(),T===!1||T===null||T===void 0){A=Oe,g(()=>{b("unresolved"),h(void 0),l(void 0)});return}let w=j;if(j=!1,A!==Oe&&T===A&&!w)return;if(A=T,c){c=!1;return}let X=!1;m(()=>X=!0);let Be=v(f),Tt=v(u),je=Be==="ready"||Be==="refreshing";g(()=>{b(je?"refreshing":"pending"),l(void 0)});try{let R=o(T,{value:Tt,refetching:je});Ht(R)?(h(R),ve(R),R.then(Q=>{X||(s!==void 0&&we(s,Q),g(()=>{p(()=>Q),b("ready"),h(void 0)}))},Q=>{X||g(()=>{l(Q),b("errored"),h(void 0)})})):g(()=>{p(()=>R),b("ready"),h(void 0)})}catch(R){if(X)return;g(()=>{l(R),b("errored"),h(void 0)})}});let Y=()=>{let T=f();return T==="pending"||T==="refreshing"},E=(()=>{let T=y();if(T)throw T;if(Y()){let w=x();if(w)throw w}return u()});return Object.defineProperties(E,{state:{get:f},loading:{get:Y},error:{get:y},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:p,refetch:()=>{j=!0,B(void 0)}}]}function Ze(e,t=300){let[r,n]=d(e),[o,s]=d(e),[i,c]=d(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let f=v(r);return s(()=>f),c(!1),f},l=(f=>{let b=typeof f=="function"?f(v(r)):f;return n(()=>b),c(!0),p(),u=setTimeout(y,t),b});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function zt(e){return e!=null&&e!==""}function Yt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=zt}=r,[i,c,u]=Ze(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=ge(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function oe(e){if(typeof e=="function"&&!e.length){let t=e();return ye(t)?t:oe(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=oe(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Xt(e){let t=S(e);return S(()=>oe(t()))}var Ae=V();Ke((e,t)=>{let r=te(t,Ae);r&&(r.increment(),e.finally(()=>r.decrement()))});function Qt(){let[e,t]=d(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function Jt(e,t){return K(Ae,e,t)}var et=V();We((e,t)=>{let r=te(t,et);return r?(r.setError(e),!0):!1});function Zt(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function er(e,t){return K(et,e,t)}var tr={State:P,Computed:O,subtle:{Watcher:D,untrack:L,currentComputed:Le,hasSinks:Ve}};var ln=Symbol.for("signal"),pn=Symbol.for("fluixi-proxy");import{$PROXY as _e,batch as ut,createEffect as ie,createMemo as ke,createSignal as ct,untrack as rr}from"@fluixi/reactive/signal";var ae=Symbol("store-raw"),U=Symbol("store-node"),tt=Symbol("store-has"),Ee=Symbol("store-self"),Pe=Symbol("store-track"),nr=Symbol("store-name"),or=Symbol("store-store"),rt=new WeakMap,nt=new WeakMap;function lt(e){let[t,r]=ct(e),n=t;return n.$=r,n}function ue(e){let t=rt.get(e);return t||rt.set(e,t={keys:new Map}),t}function ot(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=lt(r)),n}function st(e){let t=ue(e);(t.all||(t.all=lt()))()}function it(e,t){e.$(typeof t=="function"?()=>t:t)}function pt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e){if(!pt(e))return e;let t=nt.get(e);if(t)return t;let r=new Proxy(e,sr);return nt.set(e,r),r}var sr={get(e,t,r){if(t===ae||t===U)return e;if(t===_e)return r;if(t===tt)return i=>i in e;if(t==="__proxy")return!0;if(t===Pe||t===Ee)return st(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=ot(ue(e),t,n)();return pt(s)?se(s):s},set(){return!0},deleteProperty(e,t){return t in e&&H(e,t,void 0),!0},has(e,t){return t===ae||t===_e||t===U||t===tt||t===Ee||t===Pe?!0:(ot(ue(e),t,e[t])(),t in e)},ownKeys(e){return st(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function H(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ue(e),c=i.keys.get(t);if(c&&it(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&it(u,e.length)}i.all&&i.all.$(void 0)}function at(e,t){return typeof e=="function"?e(t):e}function De(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?De(o,n):H(e,r,n)}}function Ce(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function ft(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)ft(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},H(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)H(e,s,at(r,e[s]));return}H(e,o,at(r,e[o]))}function Re(e,t,r){ft(e,Ce(t),r)}function ir(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&De(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Re(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){De(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Re(e,`${r}.${t[1].join(".")}`,t[2]);return}Re(e,String(r),t[1])}function Fe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Fe);let t={};for(let r of Object.keys(e))t[r]=Fe(e[r]);return t}function I(e,t){let r=e;for(let n of Ce(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ut(()=>ir(this.root,n)))}get state(){return se(this.root)}get proxy(){return se(this.root)}get accessor(){return(()=>se(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return z(this.state);let r=this.state;for(let n of Ce(t)){if(r==null)return;r=r[n]}return z(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ie(()=>t(this.state))}watch(t,r){let n;return ie(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Fe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=ct(this.state);return t.toObservable()}dispose(){}},ar=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function dt(e,t){for(let r of ar)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function yt(e,t={immutable:!0}){let r=new _(e,t);return dt(r.set,r),[r.proxy,r.set]}function bt(e,t={}){return new _(e,{...t,immutable:!1})}function ur(e,t={}){let r=new _(e(),t);return ie(()=>r.set(e())),r}function cr(e,t,r){return ie(()=>r(t(e)))}function lr(e,t,r){return ke(()=>t(e),void 0,r)}function pr(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return dt(n,r),n}function z(e){if(e==null||typeof e!="object")return e;let t=e[ae];return t!==void 0?t:e}function ht(e){return rr(()=>z(e))}function fr(e){return Ie(e)}function dr(e){return Ie(e)?e[U]:null}function yr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ie(e){return!!e&&typeof e=="object"&&(_e in e||e.__proxy===!0)}function br(e){return e}var hr=Object.freeze({createStore:yt,createMutableStore:bt,batch:ut,unwrap:z,untrackStore:ht});function Ue(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ue);let t={};for(let r of Object.keys(e))t[r]=Ue(e[r]);return t}function Tr(e){return t=>{let r=Ue(t);return e(r),r}}function mr(e,t={}){return()=>e}export{nr as $NAME,U as $NODE,pn as $PROXY,ae as $RAW,Ee as $SELF,ln as $SIGNAL,or as $STORE,Pe as $TRACK,N as Observable,ce as SafeSubscriber,tr as Signal,_ as Store,hr as StoreAPI,Me as Subject,M as Subscriber,q as Subscription,Ae as SuspenseContext,de as __DEV__,g as batch,_t as createComputed,ur as createComputedStore,V as createContext,Wt as createDebounce,Yt as createDebouncedResource,Ze as createDebouncedSignal,Gt as createDeferred,C as createEffect,Zt as createErrorBoundary,S as createMemo,bt as createMutableStore,kt as createRenderEffect,ge as createResource,F as createRoot,Kt as createSelector,d as createSignal,yt as createStore,cr as createStoreEffect,lr as createStoreMemo,Qt as createSuspenseBoundary,Pt as flush,dr as getNode,re as getOwner,Se as getServerData,yr as getStoreNode,Nr as indexArray,jt as isComponent,Ut as isMemo,xt as isOwnerDisposed,Mt as isProvider,Bt as isResource,ye as isSignal,fr as isStore,Ie as isStoreProxy,qt as isSuspense,Mr as keyArray,Je as makeArrayFlat,qr as mapArray,br as modifiable,xe as nextResourceId,Dt as on,m as onCleanup,Or as operate,Tr as produceUtil,K as provide,er as provideErrorBoundary,Jt as provideSuspense,Xt as readChildren,mr as reconcileUtil,we as reportResourceData,G as runWithOwner,He as setOwner,Vt as setResourceDataSink,Lt as setResourceIdSource,Nt as setResourceTracker,$t as setServerDataGetter,Qe as startTransition,ve as trackResourcePromise,v as untrack,ht as untrackStore,z as unwrap,wt as useContext,Et as useTransition,pr as wrap};
|
|
1
|
+
import{isObject as mt}from"@fluixi/utils/object";import{isFunction as qe}from"@fluixi/utils/functions";var q=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(qe(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(mt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(qe(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var M=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ce=class extends M{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function Ar(e){return new M(e.next,e.error,e.complete)}var N=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof M?o=t:o=new ce(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Me=class extends N{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new N(n=>this.subscribe(n))}};var vt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[vt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Ne=0,$e=1,$=2,ee=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))}},P=class extends ee{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty($);le(this)}}peek(){return this._value}},O=class extends ee{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=$;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===$)break}(this.state===$||!this._initialized)&&this.recompute(),this.state=Ne}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty($);le(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===Ne;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function le(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 r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function L(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function xt(e){let t=K(e);return e&&(e.owned??=[]).push(t),t}function wt(e,t=!0){V(e,t)}function Ot(e){return!!e&&e.disposed===!0}function K(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function G(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=K(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function gt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function te(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function W(e,t,r){let n=K(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ke(e){a.onSuspend=e}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function We(e){a.onError=e}function re(){return a.owner}function He(e){let t=a.owner;return a.owner=e,t}function H(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function V(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)V(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function C(e){let t=K(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>V(t))}finally{a.owner=r}}function ze(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function At(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(z)))}function z(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Ye(){a.batchDepth===0&&z()}function fe(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&z()}}var pe=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=K(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{V(this.owner,!1),H(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new D(()=>At(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),V(this.owner))}};function ne(e){let t=new pe(e);return()=>t.dispose()}function Rt(e){return!!e&&typeof e.then=="function"}ze(()=>{});var Xe=Symbol.for("signal"),_t=Symbol.for("memo"),kt=Symbol.for("signal-node");function d(e,t){let r=new P(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Ye(),i});return Object.defineProperty(n,Xe,{value:!0,enumerable:!0}),Object.defineProperty(n,kt,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=re(),s=new O(()=>H(o,()=>{try{return n=e(n)}catch(c){if(Rt(c))return Ge(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Xe,{value:!0,enumerable:!0}),Object.defineProperty(i,_t,{value:!0,enumerable:!0}),i}function F(e,t){let r=t;return ne(()=>{r=e(r)})}function Et(e,t){let r=t;ne(()=>{r=e(r)})}function Pt(e,t){let r=t;return ne(()=>{r=e(r)})}function g(e){return fe(e)}function v(e){return L(e)}function Qe(e){return fe(e),Promise.resolve()}function Dt(){return[()=>!1,Qe]}function Ct(){return z(),Promise.resolve()}function Ft(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=L(()=>t(c,o,i));return o=c,u}}function Nr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,f,b;C(h=>{b=h;let[k,B]=d(u);f=B,l=t(p,k)});let x={item:p,rendered:l,dispose:b,setIndex:f};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function $r(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return v(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let f=t(i[l]),b=c.get(f);if(b&&!y.has(f))b.setIndex(l),u.push(b);else{let x,h,k;C(B=>{k=B;let[A,j]=d(l);h=j;let Q=S(E=>{let w=(e()||[])[A()];return w??E},i[l]);x=r(Q,A)}),u.push({rendered:x,dispose:k,setIndex:h})}p.push(f),y.add(f)}for(let[l,f]of c)y.has(l)||f.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Lr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,f=o[u];C(b=>{l=b;let[x,h]=d(f);y=h,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var de=!1,It=Symbol.for("signal"),Ut=Symbol.for("memo"),Bt=Symbol.for("resource");function ye(e){return typeof e=="function"&&e[It]===!0}function jt(e){return typeof e=="function"&&e[Ut]===!0}function qt(e){return typeof e=="function"&&e[Bt]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Nt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function $t(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Je(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Je(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var be=null;function Lt(e){be=e}function ve(e){be&&be(e)}var he=null;function Vt(e){he=e}function Se(e){return he?he(e):void 0}var Te=null;function Kt(e){Te=e}function xe(){return Te?Te():void 0}var me=null;function Gt(e){me=e}function we(e,t){me&&me(e,t)}function Wt(e,t=(r,n)=>r===n){let r=new Map;return F(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=d(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Ht(e,t){let[r,n]=d(e(),t);return F(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function zt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Yt(e){return!!e&&typeof e.then=="function"}var Oe=Symbol();function ge(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=xe(),i=s!==void 0?Se(s):void 0,c=i!==void 0,[u,p]=d(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=d(void 0,{equals:!1}),[f,b]=d(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,h]=d(void 0,{equals:!1}),[k,B]=d(void 0,{equals:!1}),A=Oe,j=!1;F(()=>{let T=n();if(k(),T===!1||T===null||T===void 0){A=Oe,g(()=>{b("unresolved"),h(void 0),l(void 0)});return}let w=j;if(j=!1,A!==Oe&&T===A&&!w)return;if(A=T,c){c=!1;return}let J=!1;m(()=>J=!0);let Be=v(f),Tt=v(u),je=Be==="ready"||Be==="refreshing";g(()=>{b(je?"refreshing":"pending"),l(void 0)});try{let R=o(T,{value:Tt,refetching:je});Yt(R)?(h(R),ve(R),R.then(Z=>{J||(s!==void 0&&we(s,Z),g(()=>{p(()=>Z),b("ready"),h(void 0)}))},Z=>{J||g(()=>{l(Z),b("errored"),h(void 0)})})):g(()=>{p(()=>R),b("ready"),h(void 0)})}catch(R){if(J)return;g(()=>{l(R),b("errored"),h(void 0)})}});let Q=()=>{let T=f();return T==="pending"||T==="refreshing"},E=(()=>{let T=y();if(T)throw T;if(Q()){let w=x();if(w)throw w}return u()});return Object.defineProperties(E,{state:{get:f},loading:{get:Q},error:{get:y},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:p,refetch:()=>{j=!0,B(void 0)}}]}function Ze(e,t=300){let[r,n]=d(e),[o,s]=d(e),[i,c]=d(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let f=v(r);return s(()=>f),c(!1),f},l=(f=>{let b=typeof f=="function"?f(v(r)):f;return n(()=>b),c(!0),p(),u=setTimeout(y,t),b});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function Xt(e){return e!=null&&e!==""}function Qt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Xt}=r,[i,c,u]=Ze(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=ge(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function oe(e){if(typeof e=="function"&&!e.length){let t=e();return ye(t)?t:oe(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=oe(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Jt(e){let t=S(e);return S(()=>oe(t()))}var Ae=G();Ke((e,t)=>{let r=te(t,Ae);r&&(r.increment(),e.finally(()=>r.decrement()))});function Zt(){let[e,t]=d(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function er(e,t){return W(Ae,e,t)}var et=G();We((e,t)=>{let r=te(t,et);return r?(r.setError(e),!0):!1});function tr(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function rr(e,t){return W(et,e,t)}var nr={State:P,Computed:O,subtle:{Watcher:D,untrack:L,currentComputed:Le,hasSinks:Ve}};var fn=Symbol.for("signal"),dn=Symbol.for("fluixi-proxy");import{$PROXY as _e,batch as ut,createEffect as ie,createMemo as ke,createSignal as ct,untrack as or}from"@fluixi/reactive/signal";var ae=Symbol("store-raw"),U=Symbol("store-node"),tt=Symbol("store-has"),Ee=Symbol("store-self"),Pe=Symbol("store-track"),sr=Symbol("store-name"),ir=Symbol("store-store"),rt=new WeakMap,nt=new WeakMap;function lt(e){let[t,r]=ct(e),n=t;return n.$=r,n}function ue(e){let t=rt.get(e);return t||rt.set(e,t={keys:new Map}),t}function ot(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=lt(r)),n}function st(e){let t=ue(e);(t.all||(t.all=lt()))()}function it(e,t){e.$(typeof t=="function"?()=>t:t)}function pt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e){if(!pt(e))return e;let t=nt.get(e);if(t)return t;let r=new Proxy(e,ar);return nt.set(e,r),r}var ar={get(e,t,r){if(t===ae||t===U)return e;if(t===_e)return r;if(t===tt)return i=>i in e;if(t==="__proxy")return!0;if(t===Pe||t===Ee)return st(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=ot(ue(e),t,n)();return pt(s)?se(s):s},set(){return!0},deleteProperty(e,t){return t in e&&Y(e,t,void 0),!0},has(e,t){return t===ae||t===_e||t===U||t===tt||t===Ee||t===Pe?!0:(ot(ue(e),t,e[t])(),t in e)},ownKeys(e){return st(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function Y(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ue(e),c=i.keys.get(t);if(c&&it(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&it(u,e.length)}i.all&&i.all.$(void 0)}function at(e,t){return typeof e=="function"?e(t):e}function De(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?De(o,n):Y(e,r,n)}}function Fe(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function ft(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)ft(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},Y(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)Y(e,s,at(r,e[s]));return}Y(e,o,at(r,e[o]))}function Re(e,t,r){ft(e,Fe(t),r)}function ur(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&De(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Re(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){De(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Re(e,`${r}.${t[1].join(".")}`,t[2]);return}Re(e,String(r),t[1])}function Ce(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ce);let t={};for(let r of Object.keys(e))t[r]=Ce(e[r]);return t}function I(e,t){let r=e;for(let n of Fe(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ut(()=>ur(this.root,n)))}get state(){return se(this.root)}get proxy(){return se(this.root)}get accessor(){return(()=>se(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return X(this.state);let r=this.state;for(let n of Fe(t)){if(r==null)return;r=r[n]}return X(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ie(()=>t(this.state))}watch(t,r){let n;return ie(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Ce(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=ct(this.state);return t.toObservable()}dispose(){}},cr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function dt(e,t){for(let r of cr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function yt(e,t={immutable:!0}){let r=new _(e,t);return dt(r.set,r),[r.proxy,r.set]}function bt(e,t={}){return new _(e,{...t,immutable:!1})}function lr(e,t={}){let r=new _(e(),t);return ie(()=>r.set(e())),r}function pr(e,t,r){return ie(()=>r(t(e)))}function fr(e,t,r){return ke(()=>t(e),void 0,r)}function dr(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return dt(n,r),n}function X(e){if(e==null||typeof e!="object")return e;let t=e[ae];return t!==void 0?t:e}function ht(e){return or(()=>X(e))}function yr(e){return Ie(e)}function br(e){return Ie(e)?e[U]:null}function hr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ie(e){return!!e&&typeof e=="object"&&(_e in e||e.__proxy===!0)}function Tr(e){return e}var mr=Object.freeze({createStore:yt,createMutableStore:bt,batch:ut,unwrap:X,untrackStore:ht});function Ue(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ue);let t={};for(let r of Object.keys(e))t[r]=Ue(e[r]);return t}function vr(e){return t=>{let r=Ue(t);return e(r),r}}function Sr(e,t={}){return()=>e}export{sr as $NAME,U as $NODE,dn as $PROXY,ae as $RAW,Ee as $SELF,fn as $SIGNAL,ir as $STORE,Pe as $TRACK,N as Observable,ce as SafeSubscriber,nr as Signal,_ as Store,mr as StoreAPI,Me as Subject,M as Subscriber,q as Subscription,Ae as SuspenseContext,de as __DEV__,g as batch,xt as createChildOwner,Et as createComputed,lr as createComputedStore,G as createContext,zt as createDebounce,Qt as createDebouncedResource,Ze as createDebouncedSignal,Ht as createDeferred,F as createEffect,tr as createErrorBoundary,S as createMemo,bt as createMutableStore,Pt as createRenderEffect,ge as createResource,C as createRoot,Wt as createSelector,d as createSignal,yt as createStore,pr as createStoreEffect,fr as createStoreMemo,Zt as createSuspenseBoundary,wt as disposeScope,Ct as flush,br as getNode,re as getOwner,Se as getServerData,hr as getStoreNode,Lr as indexArray,Mt as isComponent,jt as isMemo,Ot as isOwnerDisposed,$t as isProvider,qt as isResource,ye as isSignal,yr as isStore,Ie as isStoreProxy,Nt as isSuspense,$r as keyArray,Je as makeArrayFlat,Nr as mapArray,Tr as modifiable,xe as nextResourceId,Ft as on,m as onCleanup,Ar as operate,vr as produceUtil,W as provide,rr as provideErrorBoundary,er as provideSuspense,Jt as readChildren,Sr as reconcileUtil,we as reportResourceData,H as runWithOwner,He as setOwner,Gt as setResourceDataSink,Kt as setResourceIdSource,Lt as setResourceTracker,Vt as setServerDataGetter,Qe as startTransition,ve as trackResourcePromise,v as untrack,ht as untrackStore,X as unwrap,gt as useContext,Dt as useTransition,dr as wrap};
|
package/dist/lib/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var xe=Object.defineProperty;var tr=Object.getOwnPropertyDescriptor;var rr=Object.getOwnPropertyNames;var nr=Object.prototype.hasOwnProperty;var or=(e,t)=>{for(var r in t)xe(e,r,{get:t[r],enumerable:!0})},sr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of rr(t))!nr.call(e,o)&&o!==r&&xe(e,o,{get:()=>t[o],enumerable:!(n=tr(t,o))||n.enumerable});return e};var ir=e=>sr(xe({},"__esModule",{value:!0}),e);var _r={};or(_r,{$NAME:()=>jt,$NODE:()=>D,$PROXY:()=>Or,$RAW:()=>Q,$SELF:()=>Te,$SIGNAL:()=>wr,$STORE:()=>qt,$TRACK:()=>me,Observable:()=>B,SafeSubscriber:()=>te,Signal:()=>Et,Store:()=>R,StoreAPI:()=>Qt,Subject:()=>Oe,Subscriber:()=>U,Subscription:()=>I,SuspenseContext:()=>be,__DEV__:()=>ae,batch:()=>O,createComputed:()=>st,createComputedStore:()=>Vt,createContext:()=>M,createDebounce:()=>xt,createDebouncedResource:()=>wt,createDebouncedSignal:()=>Ue,createDeferred:()=>St,createEffect:()=>P,createErrorBoundary:()=>_t,createMemo:()=>x,createMutableStore:()=>$e,createRenderEffect:()=>it,createResource:()=>de,createRoot:()=>E,createSelector:()=>vt,createSignal:()=>f,createStore:()=>Ne,createStoreEffect:()=>Kt,createStoreMemo:()=>Gt,createSuspenseBoundary:()=>gt,flush:()=>ut,getNode:()=>zt,getOwner:()=>z,getServerData:()=>le,getStoreNode:()=>Yt,indexArray:()=>hr,isComponent:()=>ft,isMemo:()=>lt,isOwnerDisposed:()=>Qe,isProvider:()=>yt,isResource:()=>pt,isSignal:()=>ue,isStore:()=>Ht,isStoreProxy:()=>Se,isSuspense:()=>dt,keyArray:()=>br,makeArrayFlat:()=>Ee,mapArray:()=>yr,modifiable:()=>Xt,nextResourceId:()=>pe,on:()=>ct,onCleanup:()=>v,operate:()=>ar,produceUtil:()=>Jt,provide:()=>N,provideErrorBoundary:()=>kt,provideSuspense:()=>At,readChildren:()=>Ot,reconcileUtil:()=>Zt,reportResourceData:()=>fe,runWithOwner:()=>$,setOwner:()=>Re,setResourceDataSink:()=>mt,setResourceIdSource:()=>Tt,setResourceTracker:()=>bt,setServerDataGetter:()=>ht,startTransition:()=>ke,trackResourcePromise:()=>ce,untrack:()=>S,untrackStore:()=>Le,unwrap:()=>V,useContext:()=>Je,useTransition:()=>at,wrap:()=>Wt});module.exports=ir(_r);var We=require("@fluixi/utils/object"),we=require("@fluixi/utils/functions"),I=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if((0,we.isFunction)(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,We.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,we.isFunction)(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var U=class extends I{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},te=class extends U{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function ar(e){return new U(e.next,e.error,e.complete)}var B=class extends I{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof U?o=t:o=new te(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Oe=class extends B{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new B(n=>this.subscribe(n))}};var ur="__fluixi_signal_next_state__",cr=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[ur]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:cr,onSuspend:null,onError:null};var He=0,ze=1,W=2,re=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))}},j=class extends re{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty(W);ge(this)}}peek(){return this._value}},A=class extends re{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=W;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===ze&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===W)break}(this.state===W||!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 r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(W);ge(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===He;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(ze);ge(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ge(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function H(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Ye(){return a.consumer}function Xe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Qe(e){return!!e&&e.disposed===!0}function oe(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=oe(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function Je(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function se(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function N(e,t,r){let n=oe(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ze(e){a.onSuspend=e}function et(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function tt(e){a.onError=e}function z(){return a.owner}function Re(e){let t=a.owner;return a.owner=e,t}function $(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function v(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function ne(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)ne(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function E(e){let t=oe(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>ne(t))}finally{a.owner=r}}function rt(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function lr(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(Y)))}function Y(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function nt(){a.batchDepth===0&&Y()}function _e(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&Y()}}var Ae=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=oe(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new A(()=>{ne(this.owner,!1),$(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new q(()=>lr(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),ne(this.owner))}};function ie(e){let t=new Ae(e);return()=>t.dispose()}function pr(e){return!!e&&typeof e.then=="function"}rt(()=>{});var ot=Symbol.for("signal"),fr=Symbol.for("memo"),dr=Symbol.for("signal-node");function f(e,t){let r=new j(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),nt(),i});return Object.defineProperty(n,ot,{value:!0,enumerable:!0}),Object.defineProperty(n,dr,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function x(e,t,r){let n=t,o=z(),s=new A(()=>$(o,()=>{try{return n=e(n)}catch(c){if(pr(c))return et(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,ot,{value:!0,enumerable:!0}),Object.defineProperty(i,fr,{value:!0,enumerable:!0}),i}function P(e,t){let r=t;return ie(()=>{r=e(r)})}function st(e,t){let r=t;ie(()=>{r=e(r)})}function it(e,t){let r=t;return ie(()=>{r=e(r)})}function O(e){return _e(e)}function S(e){return H(e)}function ke(e){return _e(e),Promise.resolve()}function at(){return[()=>!1,ke]}function ut(){return Y(),Promise.resolve()}function ct(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=H(()=>t(c,o,i));return o=c,u}}function yr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],b=s.get(p);if(b&&!c.has(b))b.setIndex(u),i.push(b),c.add(b);else{let l,d,h;E(T=>{h=T;let[F,K]=f(u);d=K,l=t(p,F)});let w={item:p,rendered:l,dispose:h,setIndex:d};i.push(w),c.add(w)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function br(e,t,r,n){let o=[],s=[];return v(()=>{for(let i of s)i.dispose();o=[],s=[]}),x(()=>{let i=e()||[];return S(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],b=new Set;for(let l=0;l<i.length;l++){let d=t(i[l]),h=c.get(d);if(h&&!b.has(d))h.setIndex(l),u.push(h);else{let w,T,F;E(K=>{F=K;let[_,G]=f(l);T=G;let J=x(C=>{let g=(e()||[])[_()];return g??C},i[l]);w=r(J,_)}),u.push({rendered:w,dispose:F,setIndex:T})}p.push(d),b.add(d)}for(let[l,d]of c)b.has(l)||d.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function hr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,b,l,d=o[u];E(h=>{l=h;let[w,T]=f(d);b=T,p=t(w,u)}),n.push({rendered:p,setItem:b,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var ae=!1,Tr=Symbol.for("signal"),mr=Symbol.for("memo"),vr=Symbol.for("resource");function ue(e){return typeof e=="function"&&e[Tr]===!0}function lt(e){return typeof e=="function"&&e[mr]===!0}function pt(e){return typeof e=="function"&&e[vr]===!0}function ft(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function dt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function yt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Ee(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Ee(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Pe=null;function bt(e){Pe=e}function ce(e){Pe&&Pe(e)}var De=null;function ht(e){De=e}function le(e){return De?De(e):void 0}var Fe=null;function Tt(e){Fe=e}function pe(){return Fe?Fe():void 0}var Ce=null;function mt(e){Ce=e}function fe(e,t){Ce&&Ce(e,t)}function vt(e,t=(r,n)=>r===n){let r=new Map;return P(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=f(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function St(e,t){let[r,n]=f(e(),t);return P(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function xt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return v(()=>{r!==void 0&&clearTimeout(r)}),n}function Sr(e){return!!e&&typeof e.then=="function"}var Ie=Symbol();function de(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=pe(),i=s!==void 0?le(s):void 0,c=i!==void 0,[u,p]=f(i!==void 0?i.value:r.initialValue,{equals:!1}),[b,l]=f(void 0,{equals:!1}),[d,h]=f(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[w,T]=f(void 0,{equals:!1}),[F,K]=f(void 0,{equals:!1}),_=Ie,G=!1;P(()=>{let m=n();if(F(),m===!1||m===null||m===void 0){_=Ie,O(()=>{h("unresolved"),T(void 0),l(void 0)});return}let g=G;if(G=!1,_!==Ie&&m===_&&!g)return;if(_=m,c){c=!1;return}let Z=!1;v(()=>Z=!0);let Ke=S(d),er=S(u),Ge=Ke==="ready"||Ke==="refreshing";O(()=>{h(Ge?"refreshing":"pending"),l(void 0)});try{let k=o(m,{value:er,refetching:Ge});Sr(k)?(T(k),ce(k),k.then(ee=>{Z||(s!==void 0&&fe(s,ee),O(()=>{p(()=>ee),h("ready"),T(void 0)}))},ee=>{Z||O(()=>{l(ee),h("errored"),T(void 0)})})):O(()=>{p(()=>k),h("ready"),T(void 0)})}catch(k){if(Z)return;O(()=>{l(k),h("errored"),T(void 0)})}});let J=()=>{let m=d();return m==="pending"||m==="refreshing"},C=(()=>{let m=b();if(m)throw m;if(J()){let g=w();if(g)throw g}return u()});return Object.defineProperties(C,{state:{get:d},loading:{get:J},error:{get:b},latest:{get:u}}),Object.defineProperty(C,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(C,Symbol.for("signal"),{value:!0,enumerable:!0}),[C,{mutate:p,refetch:()=>{G=!0,K(void 0)}}]}function Ue(e,t=300){let[r,n]=f(e),[o,s]=f(e),[i,c]=f(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},b=()=>{p();let d=S(r);return s(()=>d),c(!1),d},l=(d=>{let h=typeof d=="function"?d(S(r)):d;return n(()=>h),c(!0),p(),u=setTimeout(b,t),h});return v(p),[o,l,{immediate:r,pending:i,flush:b,cancel:()=>{p(),c(!1)}}]}function xr(e){return e!=null&&e!==""}function wt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=xr}=r,[i,c,u]=Ue(e,n),p=()=>s(i())?i():!1,[b,{refetch:l}]=de(p,t,o===void 0?{}:{initialValue:o});return[b,{...u,query:i,setQuery:c,refetch:l}]}function ye(e){if(typeof e=="function"&&!e.length){let t=e();return ue(t)?t:ye(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=ye(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Ot(e){let t=x(e);return x(()=>ye(t()))}var be=M();Ze((e,t)=>{let r=se(t,be);r&&(r.increment(),e.finally(()=>r.decrement()))});function gt(){let[e,t]=f(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function At(e,t){return N(be,e,t)}var Rt=M();tt((e,t)=>{let r=se(t,Rt);return r?(r.setError(e),!0):!1});function _t(){let[e,t]=f(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function kt(e,t){return N(Rt,e,t)}var Et={State:j,Computed:A,subtle:{Watcher:q,untrack:H,currentComputed:Ye,hasSinks:Xe}};var wr=Symbol.for("signal"),Or=Symbol.for("fluixi-proxy");var y=require("@fluixi/reactive/signal"),Q=Symbol("store-raw"),D=Symbol("store-node"),Pt=Symbol("store-has"),Te=Symbol("store-self"),me=Symbol("store-track"),jt=Symbol("store-name"),qt=Symbol("store-store"),Dt=new WeakMap,Ft=new WeakMap;function Mt(e){let[t,r]=(0,y.createSignal)(e),n=t;return n.$=r,n}function ve(e){let t=Dt.get(e);return t||Dt.set(e,t={keys:new Map}),t}function Ct(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=Mt(r)),n}function It(e){let t=ve(e);(t.all||(t.all=Mt()))()}function Ut(e,t){e.$(typeof t=="function"?()=>t:t)}function Nt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function he(e){if(!Nt(e))return e;let t=Ft.get(e);if(t)return t;let r=new Proxy(e,gr);return Ft.set(e,r),r}var gr={get(e,t,r){if(t===Q||t===D)return e;if(t===y.$PROXY)return r;if(t===Pt)return i=>i in e;if(t==="__proxy")return!0;if(t===me||t===Te)return It(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=Ct(ve(e),t,n)();return Nt(s)?he(s):s},set(){return!0},deleteProperty(e,t){return t in e&&X(e,t,void 0),!0},has(e,t){return t===Q||t===y.$PROXY||t===D||t===Pt||t===Te||t===me?!0:(Ct(ve(e),t,e[t])(),t in e)},ownKeys(e){return It(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function X(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ve(e),c=i.keys.get(t);if(c&&Ut(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&Ut(u,e.length)}i.all&&i.all.$(void 0)}function Bt(e,t){return typeof e=="function"?e(t):e}function je(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?je(o,n):X(e,r,n)}}function Me(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function $t(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)$t(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},X(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)X(e,s,Bt(r,e[s]));return}X(e,o,Bt(r,e[o]))}function Be(e,t,r){$t(e,Me(t),r)}function Ar(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&je(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Be(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){je(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Be(e,`${r}.${t[1].join(".")}`,t[2]);return}Be(e,String(r),t[1])}function qe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qe);let t={};for(let r of Object.keys(e))t[r]=qe(e[r]);return t}function L(e,t){let r=e;for(let n of Me(t)){if(r==null)return;r=r[n]}return r}var R=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>(0,y.batch)(()=>Ar(this.root,n)))}get state(){return he(this.root)}get proxy(){return he(this.root)}get accessor(){return(()=>he(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return V(this.state);let r=this.state;for(let n of Me(t)){if(r==null)return;r=r[n]}return V(r)}select(t){return(0,y.createMemo)(()=>t(this.state))}subscribe(t){return(0,y.createEffect)(()=>t(this.state))}watch(t,r){let n;return(0,y.createEffect)(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return(0,y.createMemo)(()=>this.state[t])}produce(t){this.set((r=>{let n=qe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=L(this.root,t);this.set(t,n.concat(r))}pop(t){let r=L(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=L(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=L(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=L(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=L(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=(0,y.createSignal)(this.state);return t.toObservable()}dispose(){}},Rr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function Lt(e,t){for(let r of Rr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function Ne(e,t={immutable:!0}){let r=new R(e,t);return Lt(r.set,r),[r.proxy,r.set]}function $e(e,t={}){return new R(e,{...t,immutable:!1})}function Vt(e,t={}){let r=new R(e(),t);return(0,y.createEffect)(()=>r.set(e())),r}function Kt(e,t,r){return(0,y.createEffect)(()=>r(t(e)))}function Gt(e,t,r){return(0,y.createMemo)(()=>t(e),void 0,r)}function Wt(e,t={}){let r=new R(e,t),n=(()=>r.proxy);return Lt(n,r),n}function V(e){if(e==null||typeof e!="object")return e;let t=e[Q];return t!==void 0?t:e}function Le(e){return(0,y.untrack)(()=>V(e))}function Ht(e){return Se(e)}function zt(e){return Se(e)?e[D]:null}function Yt(e){return e&&typeof e=="object"&&D in e?e[D]:null}function Se(e){return!!e&&typeof e=="object"&&(y.$PROXY in e||e.__proxy===!0)}function Xt(e){return e}var Qt=Object.freeze({createStore:Ne,createMutableStore:$e,batch:y.batch,unwrap:V,untrackStore:Le});function Ve(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ve);let t={};for(let r of Object.keys(e))t[r]=Ve(e[r]);return t}function Jt(e){return t=>{let r=Ve(t);return e(r),r}}function Zt(e,t={}){return()=>e}
|
|
1
|
+
"use strict";var xe=Object.defineProperty;var nr=Object.getOwnPropertyDescriptor;var or=Object.getOwnPropertyNames;var sr=Object.prototype.hasOwnProperty;var ir=(e,t)=>{for(var r in t)xe(e,r,{get:t[r],enumerable:!0})},ar=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of or(t))!sr.call(e,o)&&o!==r&&xe(e,o,{get:()=>t[o],enumerable:!(n=nr(t,o))||n.enumerable});return e};var ur=e=>ar(xe({},"__esModule",{value:!0}),e);var Er={};ir(Er,{$NAME:()=>Mt,$NODE:()=>D,$PROXY:()=>Ar,$RAW:()=>Z,$SELF:()=>Te,$SIGNAL:()=>gr,$STORE:()=>Nt,$TRACK:()=>me,Observable:()=>B,SafeSubscriber:()=>ne,Signal:()=>Dt,Store:()=>R,StoreAPI:()=>Zt,Subject:()=>Oe,Subscriber:()=>U,Subscription:()=>I,SuspenseContext:()=>be,__DEV__:()=>ae,batch:()=>O,createChildOwner:()=>Qe,createComputed:()=>at,createComputedStore:()=>Gt,createContext:()=>M,createDebounce:()=>Ot,createDebouncedResource:()=>gt,createDebouncedSignal:()=>Ue,createDeferred:()=>wt,createEffect:()=>P,createErrorBoundary:()=>Et,createMemo:()=>x,createMutableStore:()=>$e,createRenderEffect:()=>ut,createResource:()=>de,createRoot:()=>E,createSelector:()=>xt,createSignal:()=>f,createStore:()=>Ne,createStoreEffect:()=>Wt,createStoreMemo:()=>Ht,createSuspenseBoundary:()=>Rt,disposeScope:()=>Je,flush:()=>lt,getNode:()=>Xt,getOwner:()=>X,getServerData:()=>le,getStoreNode:()=>Qt,indexArray:()=>mr,isComponent:()=>yt,isMemo:()=>ft,isOwnerDisposed:()=>Ze,isProvider:()=>ht,isResource:()=>dt,isSignal:()=>ue,isStore:()=>Yt,isStoreProxy:()=>Se,isSuspense:()=>bt,keyArray:()=>Tr,makeArrayFlat:()=>Ee,mapArray:()=>hr,modifiable:()=>Jt,nextResourceId:()=>pe,on:()=>pt,onCleanup:()=>v,operate:()=>cr,produceUtil:()=>er,provide:()=>N,provideErrorBoundary:()=>Pt,provideSuspense:()=>_t,readChildren:()=>At,reconcileUtil:()=>tr,reportResourceData:()=>fe,runWithOwner:()=>$,setOwner:()=>Re,setResourceDataSink:()=>St,setResourceIdSource:()=>vt,setResourceTracker:()=>Tt,setServerDataGetter:()=>mt,startTransition:()=>ke,trackResourcePromise:()=>ce,untrack:()=>S,untrackStore:()=>Le,unwrap:()=>V,useContext:()=>et,useTransition:()=>ct,wrap:()=>zt});module.exports=ur(Er);var We=require("@fluixi/utils/object"),we=require("@fluixi/utils/functions"),I=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if((0,we.isFunction)(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,We.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,we.isFunction)(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var U=class extends I{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ne=class extends U{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function cr(e){return new U(e.next,e.error,e.complete)}var B=class extends I{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof U?o=t:o=new ne(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Oe=class extends B{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new B(n=>this.subscribe(n))}};var lr="__fluixi_signal_next_state__",pr=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[lr]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:pr,onSuspend:null,onError:null};var He=0,ze=1,W=2,oe=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))}},j=class extends oe{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty(W);ge(this)}}peek(){return this._value}},A=class extends oe{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=W;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===ze&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===W)break}(this.state===W||!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 r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(W);ge(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===He;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(ze);ge(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ge(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function H(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Ye(){return a.consumer}function Xe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Qe(e){let t=Y(e);return e&&(e.owned??=[]).push(t),t}function Je(e,t=!0){z(e,t)}function Ze(e){return!!e&&e.disposed===!0}function Y(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=Y(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function et(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function se(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function N(e,t,r){let n=Y(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function tt(e){a.onSuspend=e}function rt(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function nt(e){a.onError=e}function X(){return a.owner}function Re(e){let t=a.owner;return a.owner=e,t}function $(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function v(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function z(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)z(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function E(e){let t=Y(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>z(t))}finally{a.owner=r}}function ot(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function fr(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(Q)))}function Q(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function st(){a.batchDepth===0&&Q()}function _e(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&Q()}}var Ae=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=Y(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new A(()=>{z(this.owner,!1),$(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new q(()=>fr(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),z(this.owner))}};function ie(e){let t=new Ae(e);return()=>t.dispose()}function dr(e){return!!e&&typeof e.then=="function"}ot(()=>{});var it=Symbol.for("signal"),yr=Symbol.for("memo"),br=Symbol.for("signal-node");function f(e,t){let r=new j(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),st(),i});return Object.defineProperty(n,it,{value:!0,enumerable:!0}),Object.defineProperty(n,br,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function x(e,t,r){let n=t,o=X(),s=new A(()=>$(o,()=>{try{return n=e(n)}catch(c){if(dr(c))return rt(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,it,{value:!0,enumerable:!0}),Object.defineProperty(i,yr,{value:!0,enumerable:!0}),i}function P(e,t){let r=t;return ie(()=>{r=e(r)})}function at(e,t){let r=t;ie(()=>{r=e(r)})}function ut(e,t){let r=t;return ie(()=>{r=e(r)})}function O(e){return _e(e)}function S(e){return H(e)}function ke(e){return _e(e),Promise.resolve()}function ct(){return[()=>!1,ke]}function lt(){return Q(),Promise.resolve()}function pt(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=H(()=>t(c,o,i));return o=c,u}}function hr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],b=s.get(p);if(b&&!c.has(b))b.setIndex(u),i.push(b),c.add(b);else{let l,d,h;E(T=>{h=T;let[C,K]=f(u);d=K,l=t(p,C)});let w={item:p,rendered:l,dispose:h,setIndex:d};i.push(w),c.add(w)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Tr(e,t,r,n){let o=[],s=[];return v(()=>{for(let i of s)i.dispose();o=[],s=[]}),x(()=>{let i=e()||[];return S(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],b=new Set;for(let l=0;l<i.length;l++){let d=t(i[l]),h=c.get(d);if(h&&!b.has(d))h.setIndex(l),u.push(h);else{let w,T,C;E(K=>{C=K;let[_,G]=f(l);T=G;let ee=x(F=>{let g=(e()||[])[_()];return g??F},i[l]);w=r(ee,_)}),u.push({rendered:w,dispose:C,setIndex:T})}p.push(d),b.add(d)}for(let[l,d]of c)b.has(l)||d.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function mr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,b,l,d=o[u];E(h=>{l=h;let[w,T]=f(d);b=T,p=t(w,u)}),n.push({rendered:p,setItem:b,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var ae=!1,vr=Symbol.for("signal"),Sr=Symbol.for("memo"),xr=Symbol.for("resource");function ue(e){return typeof e=="function"&&e[vr]===!0}function ft(e){return typeof e=="function"&&e[Sr]===!0}function dt(e){return typeof e=="function"&&e[xr]===!0}function yt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function bt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function ht(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Ee(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Ee(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Pe=null;function Tt(e){Pe=e}function ce(e){Pe&&Pe(e)}var De=null;function mt(e){De=e}function le(e){return De?De(e):void 0}var Ce=null;function vt(e){Ce=e}function pe(){return Ce?Ce():void 0}var Fe=null;function St(e){Fe=e}function fe(e,t){Fe&&Fe(e,t)}function xt(e,t=(r,n)=>r===n){let r=new Map;return P(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=f(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function wt(e,t){let[r,n]=f(e(),t);return P(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function Ot(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return v(()=>{r!==void 0&&clearTimeout(r)}),n}function wr(e){return!!e&&typeof e.then=="function"}var Ie=Symbol();function de(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=pe(),i=s!==void 0?le(s):void 0,c=i!==void 0,[u,p]=f(i!==void 0?i.value:r.initialValue,{equals:!1}),[b,l]=f(void 0,{equals:!1}),[d,h]=f(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[w,T]=f(void 0,{equals:!1}),[C,K]=f(void 0,{equals:!1}),_=Ie,G=!1;P(()=>{let m=n();if(C(),m===!1||m===null||m===void 0){_=Ie,O(()=>{h("unresolved"),T(void 0),l(void 0)});return}let g=G;if(G=!1,_!==Ie&&m===_&&!g)return;if(_=m,c){c=!1;return}let te=!1;v(()=>te=!0);let Ke=S(d),rr=S(u),Ge=Ke==="ready"||Ke==="refreshing";O(()=>{h(Ge?"refreshing":"pending"),l(void 0)});try{let k=o(m,{value:rr,refetching:Ge});wr(k)?(T(k),ce(k),k.then(re=>{te||(s!==void 0&&fe(s,re),O(()=>{p(()=>re),h("ready"),T(void 0)}))},re=>{te||O(()=>{l(re),h("errored"),T(void 0)})})):O(()=>{p(()=>k),h("ready"),T(void 0)})}catch(k){if(te)return;O(()=>{l(k),h("errored"),T(void 0)})}});let ee=()=>{let m=d();return m==="pending"||m==="refreshing"},F=(()=>{let m=b();if(m)throw m;if(ee()){let g=w();if(g)throw g}return u()});return Object.defineProperties(F,{state:{get:d},loading:{get:ee},error:{get:b},latest:{get:u}}),Object.defineProperty(F,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(F,Symbol.for("signal"),{value:!0,enumerable:!0}),[F,{mutate:p,refetch:()=>{G=!0,K(void 0)}}]}function Ue(e,t=300){let[r,n]=f(e),[o,s]=f(e),[i,c]=f(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},b=()=>{p();let d=S(r);return s(()=>d),c(!1),d},l=(d=>{let h=typeof d=="function"?d(S(r)):d;return n(()=>h),c(!0),p(),u=setTimeout(b,t),h});return v(p),[o,l,{immediate:r,pending:i,flush:b,cancel:()=>{p(),c(!1)}}]}function Or(e){return e!=null&&e!==""}function gt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Or}=r,[i,c,u]=Ue(e,n),p=()=>s(i())?i():!1,[b,{refetch:l}]=de(p,t,o===void 0?{}:{initialValue:o});return[b,{...u,query:i,setQuery:c,refetch:l}]}function ye(e){if(typeof e=="function"&&!e.length){let t=e();return ue(t)?t:ye(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=ye(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function At(e){let t=x(e);return x(()=>ye(t()))}var be=M();tt((e,t)=>{let r=se(t,be);r&&(r.increment(),e.finally(()=>r.decrement()))});function Rt(){let[e,t]=f(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function _t(e,t){return N(be,e,t)}var kt=M();nt((e,t)=>{let r=se(t,kt);return r?(r.setError(e),!0):!1});function Et(){let[e,t]=f(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function Pt(e,t){return N(kt,e,t)}var Dt={State:j,Computed:A,subtle:{Watcher:q,untrack:H,currentComputed:Ye,hasSinks:Xe}};var gr=Symbol.for("signal"),Ar=Symbol.for("fluixi-proxy");var y=require("@fluixi/reactive/signal"),Z=Symbol("store-raw"),D=Symbol("store-node"),Ct=Symbol("store-has"),Te=Symbol("store-self"),me=Symbol("store-track"),Mt=Symbol("store-name"),Nt=Symbol("store-store"),Ft=new WeakMap,It=new WeakMap;function $t(e){let[t,r]=(0,y.createSignal)(e),n=t;return n.$=r,n}function ve(e){let t=Ft.get(e);return t||Ft.set(e,t={keys:new Map}),t}function Ut(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=$t(r)),n}function Bt(e){let t=ve(e);(t.all||(t.all=$t()))()}function jt(e,t){e.$(typeof t=="function"?()=>t:t)}function Lt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function he(e){if(!Lt(e))return e;let t=It.get(e);if(t)return t;let r=new Proxy(e,Rr);return It.set(e,r),r}var Rr={get(e,t,r){if(t===Z||t===D)return e;if(t===y.$PROXY)return r;if(t===Ct)return i=>i in e;if(t==="__proxy")return!0;if(t===me||t===Te)return Bt(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=Ut(ve(e),t,n)();return Lt(s)?he(s):s},set(){return!0},deleteProperty(e,t){return t in e&&J(e,t,void 0),!0},has(e,t){return t===Z||t===y.$PROXY||t===D||t===Ct||t===Te||t===me?!0:(Ut(ve(e),t,e[t])(),t in e)},ownKeys(e){return Bt(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function J(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ve(e),c=i.keys.get(t);if(c&&jt(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&jt(u,e.length)}i.all&&i.all.$(void 0)}function qt(e,t){return typeof e=="function"?e(t):e}function je(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?je(o,n):J(e,r,n)}}function Me(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function Vt(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)Vt(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},J(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)J(e,s,qt(r,e[s]));return}J(e,o,qt(r,e[o]))}function Be(e,t,r){Vt(e,Me(t),r)}function _r(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&je(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Be(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){je(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Be(e,`${r}.${t[1].join(".")}`,t[2]);return}Be(e,String(r),t[1])}function qe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qe);let t={};for(let r of Object.keys(e))t[r]=qe(e[r]);return t}function L(e,t){let r=e;for(let n of Me(t)){if(r==null)return;r=r[n]}return r}var R=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>(0,y.batch)(()=>_r(this.root,n)))}get state(){return he(this.root)}get proxy(){return he(this.root)}get accessor(){return(()=>he(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return V(this.state);let r=this.state;for(let n of Me(t)){if(r==null)return;r=r[n]}return V(r)}select(t){return(0,y.createMemo)(()=>t(this.state))}subscribe(t){return(0,y.createEffect)(()=>t(this.state))}watch(t,r){let n;return(0,y.createEffect)(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return(0,y.createMemo)(()=>this.state[t])}produce(t){this.set((r=>{let n=qe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=L(this.root,t);this.set(t,n.concat(r))}pop(t){let r=L(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=L(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=L(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=L(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=L(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=(0,y.createSignal)(this.state);return t.toObservable()}dispose(){}},kr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function Kt(e,t){for(let r of kr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function Ne(e,t={immutable:!0}){let r=new R(e,t);return Kt(r.set,r),[r.proxy,r.set]}function $e(e,t={}){return new R(e,{...t,immutable:!1})}function Gt(e,t={}){let r=new R(e(),t);return(0,y.createEffect)(()=>r.set(e())),r}function Wt(e,t,r){return(0,y.createEffect)(()=>r(t(e)))}function Ht(e,t,r){return(0,y.createMemo)(()=>t(e),void 0,r)}function zt(e,t={}){let r=new R(e,t),n=(()=>r.proxy);return Kt(n,r),n}function V(e){if(e==null||typeof e!="object")return e;let t=e[Z];return t!==void 0?t:e}function Le(e){return(0,y.untrack)(()=>V(e))}function Yt(e){return Se(e)}function Xt(e){return Se(e)?e[D]:null}function Qt(e){return e&&typeof e=="object"&&D in e?e[D]:null}function Se(e){return!!e&&typeof e=="object"&&(y.$PROXY in e||e.__proxy===!0)}function Jt(e){return e}var Zt=Object.freeze({createStore:Ne,createMutableStore:$e,batch:y.batch,unwrap:V,untrackStore:Le});function Ve(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ve);let t={};for(let r of Object.keys(e))t[r]=Ve(e[r]);return t}function er(e){return t=>{let r=Ve(t);return e(r),r}}function tr(e,t={}){return()=>e}
|
package/dist/lib/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as mt}from"@fluixi/utils/object";import{isFunction as qe}from"@fluixi/utils/functions";var q=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(qe(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(mt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(qe(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var M=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ce=class extends M{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function Or(e){return new M(e.next,e.error,e.complete)}var N=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof M?o=t:o=new ce(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Me=class extends N{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new N(n=>this.subscribe(n))}};var vt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[vt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Ne=0,$e=1,$=2,J=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))}},P=class extends J{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty($);le(this)}}peek(){return this._value}},O=class extends J{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=$;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===$)break}(this.state===$||!this._initialized)&&this.recompute(),this.state=Ne}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty($);le(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===Ne;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function le(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 r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function L(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function xt(e){return!!e&&e.disposed===!0}function ee(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function V(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=ee(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function wt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function te(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function K(e,t,r){let n=ee(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ke(e){a.onSuspend=e}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function We(e){a.onError=e}function re(){return a.owner}function He(e){let t=a.owner;return a.owner=e,t}function G(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function Z(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)Z(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function F(e){let t=ee(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>Z(t))}finally{a.owner=r}}function ze(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Ot(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(W)))}function W(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Ye(){a.batchDepth===0&&W()}function fe(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&W()}}var pe=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=ee(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{Z(this.owner,!1),G(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new D(()=>Ot(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),Z(this.owner))}};function ne(e){let t=new pe(e);return()=>t.dispose()}function gt(e){return!!e&&typeof e.then=="function"}ze(()=>{});var Xe=Symbol.for("signal"),At=Symbol.for("memo"),Rt=Symbol.for("signal-node");function d(e,t){let r=new P(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Ye(),i});return Object.defineProperty(n,Xe,{value:!0,enumerable:!0}),Object.defineProperty(n,Rt,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=re(),s=new O(()=>G(o,()=>{try{return n=e(n)}catch(c){if(gt(c))return Ge(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Xe,{value:!0,enumerable:!0}),Object.defineProperty(i,At,{value:!0,enumerable:!0}),i}function C(e,t){let r=t;return ne(()=>{r=e(r)})}function _t(e,t){let r=t;ne(()=>{r=e(r)})}function kt(e,t){let r=t;return ne(()=>{r=e(r)})}function g(e){return fe(e)}function v(e){return L(e)}function Qe(e){return fe(e),Promise.resolve()}function Et(){return[()=>!1,Qe]}function Pt(){return W(),Promise.resolve()}function Dt(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=L(()=>t(c,o,i));return o=c,u}}function qr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,f,b;F(h=>{b=h;let[k,B]=d(u);f=B,l=t(p,k)});let x={item:p,rendered:l,dispose:b,setIndex:f};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Mr(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return v(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let f=t(i[l]),b=c.get(f);if(b&&!y.has(f))b.setIndex(l),u.push(b);else{let x,h,k;F(B=>{k=B;let[A,j]=d(l);h=j;let Y=S(E=>{let w=(e()||[])[A()];return w??E},i[l]);x=r(Y,A)}),u.push({rendered:x,dispose:k,setIndex:h})}p.push(f),y.add(f)}for(let[l,f]of c)y.has(l)||f.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Nr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,f=o[u];F(b=>{l=b;let[x,h]=d(f);y=h,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var de=!1,Ft=Symbol.for("signal"),Ct=Symbol.for("memo"),It=Symbol.for("resource");function ye(e){return typeof e=="function"&&e[Ft]===!0}function Ut(e){return typeof e=="function"&&e[Ct]===!0}function Bt(e){return typeof e=="function"&&e[It]===!0}function jt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function qt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Je(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Je(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var be=null;function Nt(e){be=e}function ve(e){be&&be(e)}var he=null;function $t(e){he=e}function Se(e){return he?he(e):void 0}var Te=null;function Lt(e){Te=e}function xe(){return Te?Te():void 0}var me=null;function Vt(e){me=e}function we(e,t){me&&me(e,t)}function Kt(e,t=(r,n)=>r===n){let r=new Map;return C(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=d(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Gt(e,t){let[r,n]=d(e(),t);return C(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function Wt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Ht(e){return!!e&&typeof e.then=="function"}var Oe=Symbol();function ge(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=xe(),i=s!==void 0?Se(s):void 0,c=i!==void 0,[u,p]=d(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=d(void 0,{equals:!1}),[f,b]=d(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,h]=d(void 0,{equals:!1}),[k,B]=d(void 0,{equals:!1}),A=Oe,j=!1;C(()=>{let T=n();if(k(),T===!1||T===null||T===void 0){A=Oe,g(()=>{b("unresolved"),h(void 0),l(void 0)});return}let w=j;if(j=!1,A!==Oe&&T===A&&!w)return;if(A=T,c){c=!1;return}let X=!1;m(()=>X=!0);let Be=v(f),Tt=v(u),je=Be==="ready"||Be==="refreshing";g(()=>{b(je?"refreshing":"pending"),l(void 0)});try{let R=o(T,{value:Tt,refetching:je});Ht(R)?(h(R),ve(R),R.then(Q=>{X||(s!==void 0&&we(s,Q),g(()=>{p(()=>Q),b("ready"),h(void 0)}))},Q=>{X||g(()=>{l(Q),b("errored"),h(void 0)})})):g(()=>{p(()=>R),b("ready"),h(void 0)})}catch(R){if(X)return;g(()=>{l(R),b("errored"),h(void 0)})}});let Y=()=>{let T=f();return T==="pending"||T==="refreshing"},E=(()=>{let T=y();if(T)throw T;if(Y()){let w=x();if(w)throw w}return u()});return Object.defineProperties(E,{state:{get:f},loading:{get:Y},error:{get:y},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:p,refetch:()=>{j=!0,B(void 0)}}]}function Ze(e,t=300){let[r,n]=d(e),[o,s]=d(e),[i,c]=d(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let f=v(r);return s(()=>f),c(!1),f},l=(f=>{let b=typeof f=="function"?f(v(r)):f;return n(()=>b),c(!0),p(),u=setTimeout(y,t),b});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function zt(e){return e!=null&&e!==""}function Yt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=zt}=r,[i,c,u]=Ze(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=ge(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function oe(e){if(typeof e=="function"&&!e.length){let t=e();return ye(t)?t:oe(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=oe(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Xt(e){let t=S(e);return S(()=>oe(t()))}var Ae=V();Ke((e,t)=>{let r=te(t,Ae);r&&(r.increment(),e.finally(()=>r.decrement()))});function Qt(){let[e,t]=d(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function Jt(e,t){return K(Ae,e,t)}var et=V();We((e,t)=>{let r=te(t,et);return r?(r.setError(e),!0):!1});function Zt(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function er(e,t){return K(et,e,t)}var tr={State:P,Computed:O,subtle:{Watcher:D,untrack:L,currentComputed:Le,hasSinks:Ve}};var ln=Symbol.for("signal"),pn=Symbol.for("fluixi-proxy");import{$PROXY as _e,batch as ut,createEffect as ie,createMemo as ke,createSignal as ct,untrack as rr}from"@fluixi/reactive/signal";var ae=Symbol("store-raw"),U=Symbol("store-node"),tt=Symbol("store-has"),Ee=Symbol("store-self"),Pe=Symbol("store-track"),nr=Symbol("store-name"),or=Symbol("store-store"),rt=new WeakMap,nt=new WeakMap;function lt(e){let[t,r]=ct(e),n=t;return n.$=r,n}function ue(e){let t=rt.get(e);return t||rt.set(e,t={keys:new Map}),t}function ot(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=lt(r)),n}function st(e){let t=ue(e);(t.all||(t.all=lt()))()}function it(e,t){e.$(typeof t=="function"?()=>t:t)}function pt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e){if(!pt(e))return e;let t=nt.get(e);if(t)return t;let r=new Proxy(e,sr);return nt.set(e,r),r}var sr={get(e,t,r){if(t===ae||t===U)return e;if(t===_e)return r;if(t===tt)return i=>i in e;if(t==="__proxy")return!0;if(t===Pe||t===Ee)return st(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=ot(ue(e),t,n)();return pt(s)?se(s):s},set(){return!0},deleteProperty(e,t){return t in e&&H(e,t,void 0),!0},has(e,t){return t===ae||t===_e||t===U||t===tt||t===Ee||t===Pe?!0:(ot(ue(e),t,e[t])(),t in e)},ownKeys(e){return st(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function H(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ue(e),c=i.keys.get(t);if(c&&it(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&it(u,e.length)}i.all&&i.all.$(void 0)}function at(e,t){return typeof e=="function"?e(t):e}function De(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?De(o,n):H(e,r,n)}}function Ce(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function ft(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)ft(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},H(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)H(e,s,at(r,e[s]));return}H(e,o,at(r,e[o]))}function Re(e,t,r){ft(e,Ce(t),r)}function ir(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&De(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Re(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){De(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Re(e,`${r}.${t[1].join(".")}`,t[2]);return}Re(e,String(r),t[1])}function Fe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Fe);let t={};for(let r of Object.keys(e))t[r]=Fe(e[r]);return t}function I(e,t){let r=e;for(let n of Ce(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ut(()=>ir(this.root,n)))}get state(){return se(this.root)}get proxy(){return se(this.root)}get accessor(){return(()=>se(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return z(this.state);let r=this.state;for(let n of Ce(t)){if(r==null)return;r=r[n]}return z(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ie(()=>t(this.state))}watch(t,r){let n;return ie(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Fe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=ct(this.state);return t.toObservable()}dispose(){}},ar=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function dt(e,t){for(let r of ar)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function yt(e,t={immutable:!0}){let r=new _(e,t);return dt(r.set,r),[r.proxy,r.set]}function bt(e,t={}){return new _(e,{...t,immutable:!1})}function ur(e,t={}){let r=new _(e(),t);return ie(()=>r.set(e())),r}function cr(e,t,r){return ie(()=>r(t(e)))}function lr(e,t,r){return ke(()=>t(e),void 0,r)}function pr(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return dt(n,r),n}function z(e){if(e==null||typeof e!="object")return e;let t=e[ae];return t!==void 0?t:e}function ht(e){return rr(()=>z(e))}function fr(e){return Ie(e)}function dr(e){return Ie(e)?e[U]:null}function yr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ie(e){return!!e&&typeof e=="object"&&(_e in e||e.__proxy===!0)}function br(e){return e}var hr=Object.freeze({createStore:yt,createMutableStore:bt,batch:ut,unwrap:z,untrackStore:ht});function Ue(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ue);let t={};for(let r of Object.keys(e))t[r]=Ue(e[r]);return t}function Tr(e){return t=>{let r=Ue(t);return e(r),r}}function mr(e,t={}){return()=>e}export{nr as $NAME,U as $NODE,pn as $PROXY,ae as $RAW,Ee as $SELF,ln as $SIGNAL,or as $STORE,Pe as $TRACK,N as Observable,ce as SafeSubscriber,tr as Signal,_ as Store,hr as StoreAPI,Me as Subject,M as Subscriber,q as Subscription,Ae as SuspenseContext,de as __DEV__,g as batch,_t as createComputed,ur as createComputedStore,V as createContext,Wt as createDebounce,Yt as createDebouncedResource,Ze as createDebouncedSignal,Gt as createDeferred,C as createEffect,Zt as createErrorBoundary,S as createMemo,bt as createMutableStore,kt as createRenderEffect,ge as createResource,F as createRoot,Kt as createSelector,d as createSignal,yt as createStore,cr as createStoreEffect,lr as createStoreMemo,Qt as createSuspenseBoundary,Pt as flush,dr as getNode,re as getOwner,Se as getServerData,yr as getStoreNode,Nr as indexArray,jt as isComponent,Ut as isMemo,xt as isOwnerDisposed,Mt as isProvider,Bt as isResource,ye as isSignal,fr as isStore,Ie as isStoreProxy,qt as isSuspense,Mr as keyArray,Je as makeArrayFlat,qr as mapArray,br as modifiable,xe as nextResourceId,Dt as on,m as onCleanup,Or as operate,Tr as produceUtil,K as provide,er as provideErrorBoundary,Jt as provideSuspense,Xt as readChildren,mr as reconcileUtil,we as reportResourceData,G as runWithOwner,He as setOwner,Vt as setResourceDataSink,Lt as setResourceIdSource,Nt as setResourceTracker,$t as setServerDataGetter,Qe as startTransition,ve as trackResourcePromise,v as untrack,ht as untrackStore,z as unwrap,wt as useContext,Et as useTransition,pr as wrap};
|
|
1
|
+
import{isObject as mt}from"@fluixi/utils/object";import{isFunction as qe}from"@fluixi/utils/functions";var q=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:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(qe(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(mt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(qe(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var M=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ce=class extends M{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}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)}};function Ar(e){return new M(e.next,e.error,e.complete)}var N=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof M?o=t:o=new ce(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Me=class extends N{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new N(n=>this.subscribe(n))}};var vt="__fluixi_signal_next_state__",St=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[vt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:St,onSuspend:null,onError:null};var Ne=0,$e=1,$=2,ee=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))}},P=class extends ee{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.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 r of[...this.observers])r.markDirty($);le(this)}}peek(){return this._value}},O=class extends ee{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=$;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.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===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===$)break}(this.state===$||!this._initialized)&&this.recompute(),this.state=Ne}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty($);le(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===Ne;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function le(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 r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function L(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function xt(e){let t=K(e);return e&&(e.owned??=[]).push(t),t}function wt(e,t=!0){V(e,t)}function Ot(e){return!!e&&e.disposed===!0}function K(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function G(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=K(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function gt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function te(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function W(e,t,r){let n=K(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ke(e){a.onSuspend=e}function Ge(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function We(e){a.onError=e}function re(){return a.owner}function He(e){let t=a.owner;return a.owner=e,t}function H(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function V(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)V(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function C(e){let t=K(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>V(t))}finally{a.owner=r}}function ze(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function At(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(z)))}function z(){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 r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Ye(){a.batchDepth===0&&z()}function fe(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&z()}}var pe=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=K(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{V(this.owner,!1),H(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new D(()=>At(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),V(this.owner))}};function ne(e){let t=new pe(e);return()=>t.dispose()}function Rt(e){return!!e&&typeof e.then=="function"}ze(()=>{});var Xe=Symbol.for("signal"),_t=Symbol.for("memo"),kt=Symbol.for("signal-node");function d(e,t){let r=new P(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Ye(),i});return Object.defineProperty(n,Xe,{value:!0,enumerable:!0}),Object.defineProperty(n,kt,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=re(),s=new O(()=>H(o,()=>{try{return n=e(n)}catch(c){if(Rt(c))return Ge(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Xe,{value:!0,enumerable:!0}),Object.defineProperty(i,_t,{value:!0,enumerable:!0}),i}function F(e,t){let r=t;return ne(()=>{r=e(r)})}function Et(e,t){let r=t;ne(()=>{r=e(r)})}function Pt(e,t){let r=t;return ne(()=>{r=e(r)})}function g(e){return fe(e)}function v(e){return L(e)}function Qe(e){return fe(e),Promise.resolve()}function Dt(){return[()=>!1,Qe]}function Ct(){return z(),Promise.resolve()}function Ft(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=L(()=>t(c,o,i));return o=c,u}}function Nr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,f,b;C(h=>{b=h;let[k,B]=d(u);f=B,l=t(p,k)});let x={item:p,rendered:l,dispose:b,setIndex:f};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function $r(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return v(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let f=t(i[l]),b=c.get(f);if(b&&!y.has(f))b.setIndex(l),u.push(b);else{let x,h,k;C(B=>{k=B;let[A,j]=d(l);h=j;let Q=S(E=>{let w=(e()||[])[A()];return w??E},i[l]);x=r(Q,A)}),u.push({rendered:x,dispose:k,setIndex:h})}p.push(f),y.add(f)}for(let[l,f]of c)y.has(l)||f.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Lr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,f=o[u];C(b=>{l=b;let[x,h]=d(f);y=h,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var de=!1,It=Symbol.for("signal"),Ut=Symbol.for("memo"),Bt=Symbol.for("resource");function ye(e){return typeof e=="function"&&e[It]===!0}function jt(e){return typeof e=="function"&&e[Ut]===!0}function qt(e){return typeof e=="function"&&e[Bt]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Nt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function $t(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Je(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Je(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var be=null;function Lt(e){be=e}function ve(e){be&&be(e)}var he=null;function Vt(e){he=e}function Se(e){return he?he(e):void 0}var Te=null;function Kt(e){Te=e}function xe(){return Te?Te():void 0}var me=null;function Gt(e){me=e}function we(e,t){me&&me(e,t)}function Wt(e,t=(r,n)=>r===n){let r=new Map;return F(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=d(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Ht(e,t){let[r,n]=d(e(),t);return F(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function zt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Yt(e){return!!e&&typeof e.then=="function"}var Oe=Symbol();function ge(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=xe(),i=s!==void 0?Se(s):void 0,c=i!==void 0,[u,p]=d(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=d(void 0,{equals:!1}),[f,b]=d(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,h]=d(void 0,{equals:!1}),[k,B]=d(void 0,{equals:!1}),A=Oe,j=!1;F(()=>{let T=n();if(k(),T===!1||T===null||T===void 0){A=Oe,g(()=>{b("unresolved"),h(void 0),l(void 0)});return}let w=j;if(j=!1,A!==Oe&&T===A&&!w)return;if(A=T,c){c=!1;return}let J=!1;m(()=>J=!0);let Be=v(f),Tt=v(u),je=Be==="ready"||Be==="refreshing";g(()=>{b(je?"refreshing":"pending"),l(void 0)});try{let R=o(T,{value:Tt,refetching:je});Yt(R)?(h(R),ve(R),R.then(Z=>{J||(s!==void 0&&we(s,Z),g(()=>{p(()=>Z),b("ready"),h(void 0)}))},Z=>{J||g(()=>{l(Z),b("errored"),h(void 0)})})):g(()=>{p(()=>R),b("ready"),h(void 0)})}catch(R){if(J)return;g(()=>{l(R),b("errored"),h(void 0)})}});let Q=()=>{let T=f();return T==="pending"||T==="refreshing"},E=(()=>{let T=y();if(T)throw T;if(Q()){let w=x();if(w)throw w}return u()});return Object.defineProperties(E,{state:{get:f},loading:{get:Q},error:{get:y},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:p,refetch:()=>{j=!0,B(void 0)}}]}function Ze(e,t=300){let[r,n]=d(e),[o,s]=d(e),[i,c]=d(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let f=v(r);return s(()=>f),c(!1),f},l=(f=>{let b=typeof f=="function"?f(v(r)):f;return n(()=>b),c(!0),p(),u=setTimeout(y,t),b});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function Xt(e){return e!=null&&e!==""}function Qt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Xt}=r,[i,c,u]=Ze(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=ge(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function oe(e){if(typeof e=="function"&&!e.length){let t=e();return ye(t)?t:oe(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=oe(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Jt(e){let t=S(e);return S(()=>oe(t()))}var Ae=G();Ke((e,t)=>{let r=te(t,Ae);r&&(r.increment(),e.finally(()=>r.decrement()))});function Zt(){let[e,t]=d(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function er(e,t){return W(Ae,e,t)}var et=G();We((e,t)=>{let r=te(t,et);return r?(r.setError(e),!0):!1});function tr(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function rr(e,t){return W(et,e,t)}var nr={State:P,Computed:O,subtle:{Watcher:D,untrack:L,currentComputed:Le,hasSinks:Ve}};var fn=Symbol.for("signal"),dn=Symbol.for("fluixi-proxy");import{$PROXY as _e,batch as ut,createEffect as ie,createMemo as ke,createSignal as ct,untrack as or}from"@fluixi/reactive/signal";var ae=Symbol("store-raw"),U=Symbol("store-node"),tt=Symbol("store-has"),Ee=Symbol("store-self"),Pe=Symbol("store-track"),sr=Symbol("store-name"),ir=Symbol("store-store"),rt=new WeakMap,nt=new WeakMap;function lt(e){let[t,r]=ct(e),n=t;return n.$=r,n}function ue(e){let t=rt.get(e);return t||rt.set(e,t={keys:new Map}),t}function ot(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=lt(r)),n}function st(e){let t=ue(e);(t.all||(t.all=lt()))()}function it(e,t){e.$(typeof t=="function"?()=>t:t)}function pt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e){if(!pt(e))return e;let t=nt.get(e);if(t)return t;let r=new Proxy(e,ar);return nt.set(e,r),r}var ar={get(e,t,r){if(t===ae||t===U)return e;if(t===_e)return r;if(t===tt)return i=>i in e;if(t==="__proxy")return!0;if(t===Pe||t===Ee)return st(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=ot(ue(e),t,n)();return pt(s)?se(s):s},set(){return!0},deleteProperty(e,t){return t in e&&Y(e,t,void 0),!0},has(e,t){return t===ae||t===_e||t===U||t===tt||t===Ee||t===Pe?!0:(ot(ue(e),t,e[t])(),t in e)},ownKeys(e){return st(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function Y(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ue(e),c=i.keys.get(t);if(c&&it(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&it(u,e.length)}i.all&&i.all.$(void 0)}function at(e,t){return typeof e=="function"?e(t):e}function De(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?De(o,n):Y(e,r,n)}}function Fe(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function ft(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)ft(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},Y(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)Y(e,s,at(r,e[s]));return}Y(e,o,at(r,e[o]))}function Re(e,t,r){ft(e,Fe(t),r)}function ur(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&De(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Re(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){De(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Re(e,`${r}.${t[1].join(".")}`,t[2]);return}Re(e,String(r),t[1])}function Ce(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ce);let t={};for(let r of Object.keys(e))t[r]=Ce(e[r]);return t}function I(e,t){let r=e;for(let n of Fe(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ut(()=>ur(this.root,n)))}get state(){return se(this.root)}get proxy(){return se(this.root)}get accessor(){return(()=>se(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return X(this.state);let r=this.state;for(let n of Fe(t)){if(r==null)return;r=r[n]}return X(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ie(()=>t(this.state))}watch(t,r){let n;return ie(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Ce(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=ct(this.state);return t.toObservable()}dispose(){}},cr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function dt(e,t){for(let r of cr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function yt(e,t={immutable:!0}){let r=new _(e,t);return dt(r.set,r),[r.proxy,r.set]}function bt(e,t={}){return new _(e,{...t,immutable:!1})}function lr(e,t={}){let r=new _(e(),t);return ie(()=>r.set(e())),r}function pr(e,t,r){return ie(()=>r(t(e)))}function fr(e,t,r){return ke(()=>t(e),void 0,r)}function dr(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return dt(n,r),n}function X(e){if(e==null||typeof e!="object")return e;let t=e[ae];return t!==void 0?t:e}function ht(e){return or(()=>X(e))}function yr(e){return Ie(e)}function br(e){return Ie(e)?e[U]:null}function hr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ie(e){return!!e&&typeof e=="object"&&(_e in e||e.__proxy===!0)}function Tr(e){return e}var mr=Object.freeze({createStore:yt,createMutableStore:bt,batch:ut,unwrap:X,untrackStore:ht});function Ue(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ue);let t={};for(let r of Object.keys(e))t[r]=Ue(e[r]);return t}function vr(e){return t=>{let r=Ue(t);return e(r),r}}function Sr(e,t={}){return()=>e}export{sr as $NAME,U as $NODE,dn as $PROXY,ae as $RAW,Ee as $SELF,fn as $SIGNAL,ir as $STORE,Pe as $TRACK,N as Observable,ce as SafeSubscriber,nr as Signal,_ as Store,mr as StoreAPI,Me as Subject,M as Subscriber,q as Subscription,Ae as SuspenseContext,de as __DEV__,g as batch,xt as createChildOwner,Et as createComputed,lr as createComputedStore,G as createContext,zt as createDebounce,Qt as createDebouncedResource,Ze as createDebouncedSignal,Ht as createDeferred,F as createEffect,tr as createErrorBoundary,S as createMemo,bt as createMutableStore,Pt as createRenderEffect,ge as createResource,C as createRoot,Wt as createSelector,d as createSignal,yt as createStore,pr as createStoreEffect,fr as createStoreMemo,Zt as createSuspenseBoundary,wt as disposeScope,Ct as flush,br as getNode,re as getOwner,Se as getServerData,hr as getStoreNode,Lr as indexArray,Mt as isComponent,jt as isMemo,Ot as isOwnerDisposed,$t as isProvider,qt as isResource,ye as isSignal,yr as isStore,Ie as isStoreProxy,Nt as isSuspense,$r as keyArray,Je as makeArrayFlat,Nr as mapArray,Tr as modifiable,xe as nextResourceId,Ft as on,m as onCleanup,Ar as operate,vr as produceUtil,W as provide,rr as provideErrorBoundary,er as provideSuspense,Jt as readChildren,Sr as reconcileUtil,we as reportResourceData,H as runWithOwner,He as setOwner,Gt as setResourceDataSink,Kt as setResourceIdSource,Lt as setResourceTracker,Vt as setServerDataGetter,Qe as startTransition,ve as trackResourcePromise,v as untrack,ht as untrackStore,X as unwrap,gt as useContext,Dt as useTransition,dr as wrap};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var le=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Ke=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},Ye=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ze(t))!He.call(e,r)&&r!==n&&le(e,r,{get:()=>t[r],enumerable:!(o=We(t,r))||o.enumerable});return e};var Je=e=>Ye(le({},"__esModule",{value:!0}),e);var Ot={};Ke(Ot,{clearAllCachedResources:()=>gt,clearCachedResourceNamespace:()=>St,createCachedResource:()=>xt});module.exports=Je(Ot);var Oe=require("@fluixi/utils/object"),ce=require("@fluixi/utils/functions"),G=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,ce.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,Oe.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,ce.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 K=class extends G{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())}},fe=class extends K{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 Y=class extends G{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 K?r=t:r=new fe(t,n,o);let{_subscribe:s}=this;try{let a=s.call(this,r);a&&(typeof a=="function"||typeof a.unsubscribe=="function")&&r.add(a)}catch(a){r.error(a)}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 Te=require("@fluixi/utils");var Xe=Symbol.for("signal");function Re(e){return typeof e=="function"&&e[Xe]===!0}var Qe="__fluixi_signal_next_state__",Ze=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},h=globalThis[Qe]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Ze,onSuspend:null,onError:null};var Ce=0,_e=1,J=2,de=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(h.untracked)return;let t=h.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}};var X=class extends de{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=J;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(h.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===_e&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===J)break}(this.state===J||!this._initialized)&&this.recompute(),this.state=Ce}recompute(){if(this.sources){for(let d of this.sources)d.observers?.delete(this);this.sources.clear()}let n=h.consumer,o=h.untracked;h.consumer=this,h.untracked=!1;let r,s=!1,a;try{r=this._fn()}catch(d){s=!0,a=d,r=this._value}finally{h.consumer=n,h.untracked=o}let f=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=a,this._value=r,f){if(this.version++,this.observers)for(let d of[...this.observers])d.markDirty(J);Ae(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Ce;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(_e);Ae(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Ae(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function Ee(e){return h.onSuspend?(h.onSuspend(e,h.owner),!0):!1}function Pe(){return h.owner}function Fe(e,t){let n=h.owner;h.owner=e;try{return t()}finally{h.owner=n}}function ke(e){h.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function et(e){return!!e&&typeof e.then=="function"}ke(()=>{});var tt=Symbol.for("signal"),nt=Symbol.for("memo");function Q(e,t,n){let o=t,r=Pe(),s=new X(()=>Fe(r,()=>{try{return o=e(o)}catch(f){if(et(f))return Ee(f),o;throw f}}),{equals:n?.equals}),a=(()=>s.get());return Object.defineProperty(a,tt,{value:!0,enumerable:!0}),Object.defineProperty(a,nt,{value:!0,enumerable:!0}),a}function Z(e){if(typeof e=="function"&&!e.length){let t=e();return Re(t)?t:Z(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Z(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function qe(e){let t=Q(e);return Q(()=>Z(t()))}var Ne=null;function pe(e){Ne&&Ne(e)}var rt=Symbol.for("signal");var Ie=Symbol("fluixi-proxy"),ot=Symbol.for("signal-node"),V=0,ve=1,re=2,I=3,c=null,v=null,i=null,te=null,ne=0,st=!1,he=!1,N=0,it=1e6,O=new WeakMap,ee=null;var ut=new Map,at=0;function lt(){return`node_${++at}_${Date.now()}`}function ct(e){!1}function ft(e,t,n){let o={id:lt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return ct(o),o}function dt(e,t){return e===t}function Le(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}function pt(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(ee&&ee.running&&!e.pure)ee.effects.indexOf(e)===-1&&ee.effects.push(e);else if(!e.pure||e.computed)be(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=i;v=null,i=[],e.accessor(),v=t;let o=i;if(i=n,o.length>0){let r=i;oe(o),i=r}}}function Ue(e,t){for(let n=0;n<e.length;n++)t(e[n])}function C(e,t){let n=e;typeof n=="object"&&n&&Ie in n&&delete n[Ie];let o=ft("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[a,f];O.set(r,new Set);let s;function a(){let d=v;if(d){d.sources?d.sources.indexOf(r)===-1&&d.sources.push(r):d.sources=[r];let b=O.get(r);b&&!b.has(d)&&b.add(d)}return n}function f(d){let b=typeof d=="function"?d(n):d,B=o.equals||dt;if(t?.equals===!1||!B(n,b)){n=b,o.value=b,o.version++,o.updated=Date.now();let R=O.get(r);if(R&&R.size>0){let F=function(l,se=!1){let m=l.state;if(!(m===I&&l===v)){if(se&&!l.pure){m===V&&(l.state=ve,st&&(i!==null&&i.indexOf(l)===-1?i.push(l):x.push(l)));return}if(!S.has(l)&&(S.add(l),l.state=re,m===V||m===ve?x.push(l):!l.pure&&i!==null&&i.indexOf(l)===-1&&i.push(l),l.pure&&l.accessor)){let $=O.get(l.accessor);$&&Ue(Array.from($),k=>F(k,!0))}}};var j=F;let P=Array.from(R),x=[],S=new Set;Ue(P,F);for(let l of x)pt(l)}}}return a.toObservable=()=>new Y(d=>{let b=!0;return ye(()=>{let j=a();b?b=!1:d.next(j)})}),Object.defineProperty(a,rt,{value:!0,enumerable:!0}),Object.defineProperty(a,ot,{value:o,enumerable:!1}),r}function ye(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Me(o,t),()=>U(o)}function Me(e,t){if(e.sources){for(let r of e.sources){let s=O.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=v,o=c;if(v=e,c=e,ne++,ne>it)throw ne=0,v=n,c=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=I;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===I&&(e.state=V)}catch(r){if((0,Te.isPromise)(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Le(r)}finally{v=n,c=o}}function be(e){if(!(e.disposed||!e.fn||e.state===V)&&(e.state===re||e.state===ve||e.state===I)){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?Ge(e):Me(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=O.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 oe(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=O.get(r.accessor);if(s&&s.size>0){let f=v;v=null,r.accessor(),v=f}let a=i.splice(0);for(let f of a)f.pure&&!f.computed&&f.accessor?t.indexOf(f)===-1&&t.push(f):(f.computed||!f.pure)&&n.indexOf(f)===-1&&n.push(f)}i=null;for(let r of n)(r.computed||!r.pure)&&be(r)}function _(e){if(i&&N>0)return e();if(i&&N===0){let t=i,n=[];i=n,N++;let o;try{o=e()}finally{N--,i=t}let r=i;return oe(n),i=r,o}N++,i=[],te=[];try{return e()}finally{N--,ht()}}function ht(){if(!he){he=!0,ne=0;try{for(;i&&i.length>0;){let e=i;i=null,oe(e)}if(i=null,te){let e=te;te=null;for(let t=0;t<e.length;t++)be(e[t])}}finally{he=!1}}}function L(e){let t=v;v=null;try{return e()}finally{v=t}}function Be(e){c&&(c.cleanups?c.cleanups.push(e):c.cleanups=[e])}function vt(e){let t=Symbol("context"),n=Tt(t);return{id:t,Provider:n,defaultValue:e}}function Tt(e){return t=>{let n=c;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return yt(()=>{o=L(()=>{let r=c;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),qe(()=>t.children)})}),o}}function M(e){let t=c;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 yt(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Ge(o),()=>U(o)}function Ge(e){if(e.sources){for(let r of e.sources){let s=O.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=v,n=c,o=i;v=e,c=e,i===null&&(i=[]),e.state=I;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===I&&(e.state=V)}catch(r){if((0,Te.isPromise)(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Le(r)}finally{v=t,c=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;oe(r),i=s}}}var w;function Ve(){return w||(w=vt())}var E=new Map,A=new Map,bt=0,mt=Symbol.for("signal"),wt=Symbol.for("resource");function xt(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:a=1/0,name:f=`_auto_${bt++}`,staleWhileRevalidate:d=!0}=s,b=f,B=u=>`${b}:${JSON.stringify(u)}`,j=u=>a===1/0||Date.now()-u.timestamp<=a,[R,P]=C(void 0,{equals:!1}),[x,S]=C("unresolved",{equals:!1}),[F,l]=C(void 0,{equals:!1}),[se,m]=C(void 0,{equals:!1}),[$,k]=C(!1),[je,me]=C(0,{equals:!1}),ie=Symbol("unset"),W=ie,ue=!1,ae=!1;function we(u,T,y,g){if(A.has(T)){A.get(T).then(p=>{g()||xe(p,y)},p=>{!g()&&!y&&Se(p)}),y||m(A.get(T));return}let D=Promise.resolve(r(u)).then(p=>(E.set(T,{value:p,timestamp:Date.now()}),A.delete(T),p),p=>{throw A.delete(T),p});if(A.set(T,D),!y){pe(D),m(D);let p=z&&M(z);p&&(p.increment(),D.finally(()=>p.decrement()))}D.then(p=>{g()||xe(p,y)},p=>{!g()&&!y&&Se(p)})}function xe(u,T){_(()=>{P(()=>u),S("ready"),k(!1),m(void 0),l(void 0)})}function Se(u){_(()=>{l(u),S("errored"),m(void 0)})}let z;ye(()=>{z===void 0&&(z=Ve());let u=o();if(je(),u===!1||u===null||u===void 0){W=ie,_(()=>{S("unresolved"),m(void 0),l(void 0)});return}let T=ue,y=ae;ue=!1,ae=!1;let g=B(u);y&&E.delete(g);let D=W===ie||u!==W;W=u;let p=!1;Be(()=>{p=!0});let q=E.get(g);if(q&&j(q)&&!T&&!y){(L(x)!=="ready"||L(R)!==q.value)&&_(()=>{P(()=>q.value),S("ready"),k(!1),l(void 0)});return}if(q&&d&&!y){_(()=>{P(()=>q.value),S("ready"),k(!0),l(void 0),m(void 0)}),we(u,g,!0,()=>p);return}let ge=L(x),$e=ge==="ready"||ge==="refreshing";_(()=>{S($e?"refreshing":"pending"),l(void 0),k(!1)}),we(u,g,!1,()=>p)});let H=(()=>{let u=F();if(u)throw u;if(x()==="pending"){let y=se();if(y)throw y}return R()});return Object.defineProperty(H,wt,{value:!0,enumerable:!0}),Object.defineProperty(H,mt,{value:!0,enumerable:!0}),Object.defineProperties(H,{state:{get:x},loading:{get:()=>{let u=x();return u==="pending"||u==="refreshing"}},error:{get:F},latest:{get:R},stale:{get:$}}),[H,{mutate:P,refetch:()=>{ue=!0,me(u=>u+1)},invalidate:()=>{let u=L(o);u!=null&&u!==!1&&E.delete(B(u)),ae=!0,me(T=>T+1)}}]}function St(e){let t=`${e}:`;for(let n of E.keys())n.startsWith(t)&&E.delete(n)}function gt(){E.clear(),A.clear()}
|
|
1
|
+
"use strict";var le=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var He=Object.prototype.hasOwnProperty;var Ke=(e,t)=>{for(var n in t)le(e,n,{get:t[n],enumerable:!0})},Ye=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ze(t))!He.call(e,r)&&r!==n&&le(e,r,{get:()=>t[r],enumerable:!(o=We(t,r))||o.enumerable});return e};var Je=e=>Ye(le({},"__esModule",{value:!0}),e);var Ot={};Ke(Ot,{clearAllCachedResources:()=>gt,clearCachedResourceNamespace:()=>St,createCachedResource:()=>xt});module.exports=Je(Ot);var Oe=require("@fluixi/utils/object"),ce=require("@fluixi/utils/functions"),G=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,ce.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,Oe.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,ce.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 K=class extends G{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())}},fe=class extends K{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 Y=class extends G{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 K?r=t:r=new fe(t,n,o);let{_subscribe:s}=this;try{let a=s.call(this,r);a&&(typeof a=="function"||typeof a.unsubscribe=="function")&&r.add(a)}catch(a){r.error(a)}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 Te=require("@fluixi/utils");var Xe=Symbol.for("signal");function Ce(e){return typeof e=="function"&&e[Xe]===!0}var Qe="__fluixi_signal_next_state__",Ze=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},h=globalThis[Qe]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Ze,onSuspend:null,onError:null};var Re=0,_e=1,J=2,de=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(h.untracked)return;let t=h.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}};var X=class extends de{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=J;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(h.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===_e&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===J)break}(this.state===J||!this._initialized)&&this.recompute(),this.state=Re}recompute(){if(this.sources){for(let d of this.sources)d.observers?.delete(this);this.sources.clear()}let n=h.consumer,o=h.untracked;h.consumer=this,h.untracked=!1;let r,s=!1,a;try{r=this._fn()}catch(d){s=!0,a=d,r=this._value}finally{h.consumer=n,h.untracked=o}let f=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=a,this._value=r,f){if(this.version++,this.observers)for(let d of[...this.observers])d.markDirty(J);Ae(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Re;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(_e);Ae(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Ae(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function Ee(e){return h.onSuspend?(h.onSuspend(e,h.owner),!0):!1}function Pe(){return h.owner}function Fe(e,t){let n=h.owner;h.owner=e;try{return t()}finally{h.owner=n}}function ke(e){h.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function et(e){return!!e&&typeof e.then=="function"}ke(()=>{});var tt=Symbol.for("signal"),nt=Symbol.for("memo");function Q(e,t,n){let o=t,r=Pe(),s=new X(()=>Fe(r,()=>{try{return o=e(o)}catch(f){if(et(f))return Ee(f),o;throw f}}),{equals:n?.equals}),a=(()=>s.get());return Object.defineProperty(a,tt,{value:!0,enumerable:!0}),Object.defineProperty(a,nt,{value:!0,enumerable:!0}),a}function Z(e){if(typeof e=="function"&&!e.length){let t=e();return Ce(t)?t:Z(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Z(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function qe(e){let t=Q(e);return Q(()=>Z(t()))}var Ne=null;function pe(e){Ne&&Ne(e)}var rt=Symbol.for("signal");var Ie=Symbol("fluixi-proxy"),ot=Symbol.for("signal-node"),V=0,ve=1,re=2,I=3,c=null,v=null,i=null,te=null,ne=0,st=!1,he=!1,N=0,it=1e6,O=new WeakMap,ee=null;var ut=new Map,at=0;function lt(){return`node_${++at}_${Date.now()}`}function ct(e){!1}function ft(e,t,n){let o={id:lt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return ct(o),o}function dt(e,t){return e===t}function Le(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}function pt(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(ee&&ee.running&&!e.pure)ee.effects.indexOf(e)===-1&&ee.effects.push(e);else if(!e.pure||e.computed)be(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=i;v=null,i=[],e.accessor(),v=t;let o=i;if(i=n,o.length>0){let r=i;oe(o),i=r}}}function Ue(e,t){for(let n=0;n<e.length;n++)t(e[n])}function R(e,t){let n=e;typeof n=="object"&&n&&Ie in n&&delete n[Ie];let o=ft("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[a,f];O.set(r,new Set);let s;function a(){let d=v;if(d){d.sources?d.sources.indexOf(r)===-1&&d.sources.push(r):d.sources=[r];let b=O.get(r);b&&!b.has(d)&&b.add(d)}return n}function f(d){let b=typeof d=="function"?d(n):d,B=o.equals||dt;if(t?.equals===!1||!B(n,b)){n=b,o.value=b,o.version++,o.updated=Date.now();let C=O.get(r);if(C&&C.size>0){let F=function(l,se=!1){let m=l.state;if(!(m===I&&l===v)){if(se&&!l.pure){m===V&&(l.state=ve,st&&(i!==null&&i.indexOf(l)===-1?i.push(l):x.push(l)));return}if(!S.has(l)&&(S.add(l),l.state=re,m===V||m===ve?x.push(l):!l.pure&&i!==null&&i.indexOf(l)===-1&&i.push(l),l.pure&&l.accessor)){let $=O.get(l.accessor);$&&Ue(Array.from($),k=>F(k,!0))}}};var j=F;let P=Array.from(C),x=[],S=new Set;Ue(P,F);for(let l of x)pt(l)}}}return a.toObservable=()=>new Y(d=>{let b=!0;return ye(()=>{let j=a();b?b=!1:d.next(j)})}),Object.defineProperty(a,rt,{value:!0,enumerable:!0}),Object.defineProperty(a,ot,{value:o,enumerable:!1}),r}function ye(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Me(o,t),()=>U(o)}function Me(e,t){if(e.sources){for(let r of e.sources){let s=O.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=v,o=c;if(v=e,c=e,ne++,ne>it)throw ne=0,v=n,c=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=I;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===I&&(e.state=V)}catch(r){if((0,Te.isPromise)(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Le(r)}finally{v=n,c=o}}function be(e){if(!(e.disposed||!e.fn||e.state===V)&&(e.state===re||e.state===ve||e.state===I)){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?Ge(e):Me(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=O.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 oe(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=O.get(r.accessor);if(s&&s.size>0){let f=v;v=null,r.accessor(),v=f}let a=i.splice(0);for(let f of a)f.pure&&!f.computed&&f.accessor?t.indexOf(f)===-1&&t.push(f):(f.computed||!f.pure)&&n.indexOf(f)===-1&&n.push(f)}i=null;for(let r of n)(r.computed||!r.pure)&&be(r)}function _(e){if(i&&N>0)return e();if(i&&N===0){let t=i,n=[];i=n,N++;let o;try{o=e()}finally{N--,i=t}let r=i;return oe(n),i=r,o}N++,i=[],te=[];try{return e()}finally{N--,ht()}}function ht(){if(!he){he=!0,ne=0;try{for(;i&&i.length>0;){let e=i;i=null,oe(e)}if(i=null,te){let e=te;te=null;for(let t=0;t<e.length;t++)be(e[t])}}finally{he=!1}}}function L(e){let t=v;v=null;try{return e()}finally{v=t}}function Be(e){c&&(c.cleanups?c.cleanups.push(e):c.cleanups=[e])}function vt(e){let t=Symbol("context"),n=Tt(t);return{id:t,Provider:n,defaultValue:e}}function Tt(e){return t=>{let n=c;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return yt(()=>{o=L(()=>{let r=c;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),qe(()=>t.children)})}),o}}function M(e){let t=c;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 yt(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Ge(o),()=>U(o)}function Ge(e){if(e.sources){for(let r of e.sources){let s=O.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=v,n=c,o=i;v=e,c=e,i===null&&(i=[]),e.state=I;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===I&&(e.state=V)}catch(r){if((0,Te.isPromise)(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Le(r)}finally{v=t,c=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;oe(r),i=s}}}var w;function Ve(){return w||(w=vt())}var E=new Map,A=new Map,bt=0,mt=Symbol.for("signal"),wt=Symbol.for("resource");function xt(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:a=1/0,name:f=`_auto_${bt++}`,staleWhileRevalidate:d=!0}=s,b=f,B=u=>`${b}:${JSON.stringify(u)}`,j=u=>a===1/0||Date.now()-u.timestamp<=a,[C,P]=R(void 0,{equals:!1}),[x,S]=R("unresolved",{equals:!1}),[F,l]=R(void 0,{equals:!1}),[se,m]=R(void 0,{equals:!1}),[$,k]=R(!1),[je,me]=R(0,{equals:!1}),ie=Symbol("unset"),W=ie,ue=!1,ae=!1;function we(u,T,y,g){if(A.has(T)){A.get(T).then(p=>{g()||xe(p,y)},p=>{!g()&&!y&&Se(p)}),y||m(A.get(T));return}let D=Promise.resolve(r(u)).then(p=>(E.set(T,{value:p,timestamp:Date.now()}),A.delete(T),p),p=>{throw A.delete(T),p});if(A.set(T,D),!y){pe(D),m(D);let p=z&&M(z);p&&(p.increment(),D.finally(()=>p.decrement()))}D.then(p=>{g()||xe(p,y)},p=>{!g()&&!y&&Se(p)})}function xe(u,T){_(()=>{P(()=>u),S("ready"),k(!1),m(void 0),l(void 0)})}function Se(u){_(()=>{l(u),S("errored"),m(void 0)})}let z;ye(()=>{z===void 0&&(z=Ve());let u=o();if(je(),u===!1||u===null||u===void 0){W=ie,_(()=>{S("unresolved"),m(void 0),l(void 0)});return}let T=ue,y=ae;ue=!1,ae=!1;let g=B(u);y&&E.delete(g);let D=W===ie||u!==W;W=u;let p=!1;Be(()=>{p=!0});let q=E.get(g);if(q&&j(q)&&!T&&!y){(L(x)!=="ready"||L(C)!==q.value)&&_(()=>{P(()=>q.value),S("ready"),k(!1),l(void 0)});return}if(q&&d&&!y){_(()=>{P(()=>q.value),S("ready"),k(!0),l(void 0),m(void 0)}),we(u,g,!0,()=>p);return}let ge=L(x),$e=ge==="ready"||ge==="refreshing";_(()=>{S($e?"refreshing":"pending"),l(void 0),k(!1)}),we(u,g,!1,()=>p)});let H=(()=>{let u=F();if(u)throw u;if(x()==="pending"){let y=se();if(y)throw y}return C()});return Object.defineProperty(H,wt,{value:!0,enumerable:!0}),Object.defineProperty(H,mt,{value:!0,enumerable:!0}),Object.defineProperties(H,{state:{get:x},loading:{get:()=>{let u=x();return u==="pending"||u==="refreshing"}},error:{get:F},latest:{get:C},stale:{get:$}}),[H,{mutate:P,refetch:()=>{ue=!0,me(u=>u+1)},invalidate:()=>{let u=L(o);u!=null&&u!==!1&&E.delete(B(u)),ae=!0,me(T=>T+1)}}]}function St(e){let t=`${e}:`;for(let n of E.keys())n.startsWith(t)&&E.delete(n)}function gt(){E.clear(),A.clear()}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as je}from"@fluixi/utils/object";import{isFunction as xe}from"@fluixi/utils/functions";var G=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(je(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 K=class extends G{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())}},le=class extends K{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 Y=class extends G{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 K?r=t:r=new le(t,n,o);let{_subscribe:s}=this;try{let a=s.call(this,r);a&&(typeof a=="function"||typeof a.unsubscribe=="function")&&r.add(a)}catch(a){r.error(a)}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 Ne}from"@fluixi/utils";var $e=Symbol.for("signal");function Se(e){return typeof e=="function"&&e[$e]===!0}var We="__fluixi_signal_next_state__",ze=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},h=globalThis[We]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:ze,onSuspend:null,onError:null};var ge=0,Oe=1,J=2,ce=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(h.untracked)return;let t=h.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}};var X=class extends ce{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=J;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(h.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===Oe&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===J)break}(this.state===J||!this._initialized)&&this.recompute(),this.state=ge}recompute(){if(this.sources){for(let d of this.sources)d.observers?.delete(this);this.sources.clear()}let n=h.consumer,o=h.untracked;h.consumer=this,h.untracked=!1;let r,s=!1,a;try{r=this._fn()}catch(d){s=!0,a=d,r=this._value}finally{h.consumer=n,h.untracked=o}let f=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=a,this._value=r,f){if(this.version++,this.observers)for(let d of[...this.observers])d.markDirty(J);Re(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===ge;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Oe);Re(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Re(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function Ce(e){return h.onSuspend?(h.onSuspend(e,h.owner),!0):!1}function _e(){return h.owner}function Ae(e,t){let n=h.owner;h.owner=e;try{return t()}finally{h.owner=n}}function Ee(e){h.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function He(e){return!!e&&typeof e.then=="function"}Ee(()=>{});var Ke=Symbol.for("signal"),Ye=Symbol.for("memo");function Q(e,t,n){let o=t,r=_e(),s=new X(()=>Ae(r,()=>{try{return o=e(o)}catch(f){if(He(f))return Ce(f),o;throw f}}),{equals:n?.equals}),a=(()=>s.get());return Object.defineProperty(a,Ke,{value:!0,enumerable:!0}),Object.defineProperty(a,Ye,{value:!0,enumerable:!0}),a}function Z(e){if(typeof e=="function"&&!e.length){let t=e();return Se(t)?t:Z(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Z(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function Fe(e){let t=Q(e);return Q(()=>Z(t()))}var ke=null;function fe(e){ke&&ke(e)}var Je=Symbol.for("signal");var De=Symbol("fluixi-proxy"),Xe=Symbol.for("signal-node"),V=0,pe=1,re=2,I=3,c=null,v=null,i=null,te=null,ne=0,Qe=!1,de=!1,N=0,Ze=1e6,O=new WeakMap,ee=null;var et=new Map,tt=0;function nt(){return`node_${++tt}_${Date.now()}`}function rt(e){!1}function ot(e,t,n){let o={id:nt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return rt(o),o}function st(e,t){return e===t}function Ie(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}function it(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(ee&&ee.running&&!e.pure)ee.effects.indexOf(e)===-1&&ee.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=i;v=null,i=[],e.accessor(),v=t;let o=i;if(i=n,o.length>0){let r=i;oe(o),i=r}}}function qe(e,t){for(let n=0;n<e.length;n++)t(e[n])}function C(e,t){let n=e;typeof n=="object"&&n&&De in n&&delete n[De];let o=ot("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[a,f];O.set(r,new Set);let s;function a(){let d=v;if(d){d.sources?d.sources.indexOf(r)===-1&&d.sources.push(r):d.sources=[r];let b=O.get(r);b&&!b.has(d)&&b.add(d)}return n}function f(d){let b=typeof d=="function"?d(n):d,B=o.equals||st;if(t?.equals===!1||!B(n,b)){n=b,o.value=b,o.version++,o.updated=Date.now();let R=O.get(r);if(R&&R.size>0){let F=function(l,se=!1){let m=l.state;if(!(m===I&&l===v)){if(se&&!l.pure){m===V&&(l.state=pe,Qe&&(i!==null&&i.indexOf(l)===-1?i.push(l):x.push(l)));return}if(!S.has(l)&&(S.add(l),l.state=re,m===V||m===pe?x.push(l):!l.pure&&i!==null&&i.indexOf(l)===-1&&i.push(l),l.pure&&l.accessor)){let $=O.get(l.accessor);$&&qe(Array.from($),k=>F(k,!0))}}};var j=F;let P=Array.from(R),x=[],S=new Set;qe(P,F);for(let l of x)it(l)}}}return a.toObservable=()=>new Y(d=>{let b=!0;return he(()=>{let j=a();b?b=!1:d.next(j)})}),Object.defineProperty(a,Je,{value:!0,enumerable:!0}),Object.defineProperty(a,Xe,{value:o,enumerable:!1}),r}function he(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Ue(o,t),()=>U(o)}function Ue(e,t){if(e.sources){for(let r of e.sources){let s=O.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=v,o=c;if(v=e,c=e,ne++,ne>Ze)throw ne=0,v=n,c=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=I;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===I&&(e.state=V)}catch(r){if(Ne(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ie(r)}finally{v=n,c=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===V)&&(e.state===re||e.state===pe||e.state===I)){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?Me(e):Ue(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=O.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 oe(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=O.get(r.accessor);if(s&&s.size>0){let f=v;v=null,r.accessor(),v=f}let a=i.splice(0);for(let f of a)f.pure&&!f.computed&&f.accessor?t.indexOf(f)===-1&&t.push(f):(f.computed||!f.pure)&&n.indexOf(f)===-1&&n.push(f)}i=null;for(let r of n)(r.computed||!r.pure)&&ve(r)}function _(e){if(i&&N>0)return e();if(i&&N===0){let t=i,n=[];i=n,N++;let o;try{o=e()}finally{N--,i=t}let r=i;return oe(n),i=r,o}N++,i=[],te=[];try{return e()}finally{N--,ut()}}function ut(){if(!de){de=!0,ne=0;try{for(;i&&i.length>0;){let e=i;i=null,oe(e)}if(i=null,te){let e=te;te=null;for(let t=0;t<e.length;t++)ve(e[t])}}finally{de=!1}}}function L(e){let t=v;v=null;try{return e()}finally{v=t}}function Le(e){c&&(c.cleanups?c.cleanups.push(e):c.cleanups=[e])}function at(e){let t=Symbol("context"),n=lt(t);return{id:t,Provider:n,defaultValue:e}}function lt(e){return t=>{let n=c;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return ct(()=>{o=L(()=>{let r=c;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),Fe(()=>t.children)})}),o}}function M(e){let t=c;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 ct(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Me(o),()=>U(o)}function Me(e){if(e.sources){for(let r of e.sources){let s=O.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=v,n=c,o=i;v=e,c=e,i===null&&(i=[]),e.state=I;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===I&&(e.state=V)}catch(r){if(Ne(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ie(r)}finally{v=t,c=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;oe(r),i=s}}}var w;function Be(){return w||(w=at())}var E=new Map,A=new Map,ft=0,dt=Symbol.for("signal"),pt=Symbol.for("resource");function en(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:a=1/0,name:f=`_auto_${ft++}`,staleWhileRevalidate:d=!0}=s,b=f,B=u=>`${b}:${JSON.stringify(u)}`,j=u=>a===1/0||Date.now()-u.timestamp<=a,[R,P]=C(void 0,{equals:!1}),[x,S]=C("unresolved",{equals:!1}),[F,l]=C(void 0,{equals:!1}),[se,m]=C(void 0,{equals:!1}),[$,k]=C(!1),[Ge,Te]=C(0,{equals:!1}),ie=Symbol("unset"),W=ie,ue=!1,ae=!1;function ye(u,T,y,g){if(A.has(T)){A.get(T).then(p=>{g()||be(p,y)},p=>{!g()&&!y&&me(p)}),y||m(A.get(T));return}let D=Promise.resolve(r(u)).then(p=>(E.set(T,{value:p,timestamp:Date.now()}),A.delete(T),p),p=>{throw A.delete(T),p});if(A.set(T,D),!y){fe(D),m(D);let p=z&&M(z);p&&(p.increment(),D.finally(()=>p.decrement()))}D.then(p=>{g()||be(p,y)},p=>{!g()&&!y&&me(p)})}function be(u,T){_(()=>{P(()=>u),S("ready"),k(!1),m(void 0),l(void 0)})}function me(u){_(()=>{l(u),S("errored"),m(void 0)})}let z;he(()=>{z===void 0&&(z=Be());let u=o();if(Ge(),u===!1||u===null||u===void 0){W=ie,_(()=>{S("unresolved"),m(void 0),l(void 0)});return}let T=ue,y=ae;ue=!1,ae=!1;let g=B(u);y&&E.delete(g);let D=W===ie||u!==W;W=u;let p=!1;Le(()=>{p=!0});let q=E.get(g);if(q&&j(q)&&!T&&!y){(L(x)!=="ready"||L(R)!==q.value)&&_(()=>{P(()=>q.value),S("ready"),k(!1),l(void 0)});return}if(q&&d&&!y){_(()=>{P(()=>q.value),S("ready"),k(!0),l(void 0),m(void 0)}),ye(u,g,!0,()=>p);return}let we=L(x),Ve=we==="ready"||we==="refreshing";_(()=>{S(Ve?"refreshing":"pending"),l(void 0),k(!1)}),ye(u,g,!1,()=>p)});let H=(()=>{let u=F();if(u)throw u;if(x()==="pending"){let y=se();if(y)throw y}return R()});return Object.defineProperty(H,pt,{value:!0,enumerable:!0}),Object.defineProperty(H,dt,{value:!0,enumerable:!0}),Object.defineProperties(H,{state:{get:x},loading:{get:()=>{let u=x();return u==="pending"||u==="refreshing"}},error:{get:F},latest:{get:R},stale:{get:$}}),[H,{mutate:P,refetch:()=>{ue=!0,Te(u=>u+1)},invalidate:()=>{let u=L(o);u!=null&&u!==!1&&E.delete(B(u)),ae=!0,Te(T=>T+1)}}]}function tn(e){let t=`${e}:`;for(let n of E.keys())n.startsWith(t)&&E.delete(n)}function nn(){E.clear(),A.clear()}export{nn as clearAllCachedResources,tn as clearCachedResourceNamespace,en as createCachedResource};
|
|
1
|
+
import{isObject as je}from"@fluixi/utils/object";import{isFunction as xe}from"@fluixi/utils/functions";var G=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(je(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 K=class extends G{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())}},le=class extends K{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 Y=class extends G{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 K?r=t:r=new le(t,n,o);let{_subscribe:s}=this;try{let a=s.call(this,r);a&&(typeof a=="function"||typeof a.unsubscribe=="function")&&r.add(a)}catch(a){r.error(a)}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 Ne}from"@fluixi/utils";var $e=Symbol.for("signal");function Se(e){return typeof e=="function"&&e[$e]===!0}var We="__fluixi_signal_next_state__",ze=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},h=globalThis[We]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:ze,onSuspend:null,onError:null};var ge=0,Oe=1,J=2,ce=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(h.untracked)return;let t=h.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}};var X=class extends ce{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=J;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(h.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===Oe&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===J)break}(this.state===J||!this._initialized)&&this.recompute(),this.state=ge}recompute(){if(this.sources){for(let d of this.sources)d.observers?.delete(this);this.sources.clear()}let n=h.consumer,o=h.untracked;h.consumer=this,h.untracked=!1;let r,s=!1,a;try{r=this._fn()}catch(d){s=!0,a=d,r=this._value}finally{h.consumer=n,h.untracked=o}let f=!this._initialized||this._threw!==s||(s?a!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=a,this._value=r,f){if(this.version++,this.observers)for(let d of[...this.observers])d.markDirty(J);Ce(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===ge;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Oe);Ce(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Ce(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function Re(e){return h.onSuspend?(h.onSuspend(e,h.owner),!0):!1}function _e(){return h.owner}function Ae(e,t){let n=h.owner;h.owner=e;try{return t()}finally{h.owner=n}}function Ee(e){h.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function He(e){return!!e&&typeof e.then=="function"}Ee(()=>{});var Ke=Symbol.for("signal"),Ye=Symbol.for("memo");function Q(e,t,n){let o=t,r=_e(),s=new X(()=>Ae(r,()=>{try{return o=e(o)}catch(f){if(He(f))return Re(f),o;throw f}}),{equals:n?.equals}),a=(()=>s.get());return Object.defineProperty(a,Ke,{value:!0,enumerable:!0}),Object.defineProperty(a,Ye,{value:!0,enumerable:!0}),a}function Z(e){if(typeof e=="function"&&!e.length){let t=e();return Se(t)?t:Z(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Z(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function Fe(e){let t=Q(e);return Q(()=>Z(t()))}var ke=null;function fe(e){ke&&ke(e)}var Je=Symbol.for("signal");var De=Symbol("fluixi-proxy"),Xe=Symbol.for("signal-node"),V=0,pe=1,re=2,I=3,c=null,v=null,i=null,te=null,ne=0,Qe=!1,de=!1,N=0,Ze=1e6,O=new WeakMap,ee=null;var et=new Map,tt=0;function nt(){return`node_${++tt}_${Date.now()}`}function rt(e){!1}function ot(e,t,n){let o={id:nt(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return rt(o),o}function st(e,t){return e===t}function Ie(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}function it(e){if(i)i.indexOf(e)===-1&&i.push(e);else if(ee&&ee.running&&!e.pure)ee.effects.indexOf(e)===-1&&ee.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=i;v=null,i=[],e.accessor(),v=t;let o=i;if(i=n,o.length>0){let r=i;oe(o),i=r}}}function qe(e,t){for(let n=0;n<e.length;n++)t(e[n])}function R(e,t){let n=e;typeof n=="object"&&n&&De in n&&delete n[De];let o=ot("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[a,f];O.set(r,new Set);let s;function a(){let d=v;if(d){d.sources?d.sources.indexOf(r)===-1&&d.sources.push(r):d.sources=[r];let b=O.get(r);b&&!b.has(d)&&b.add(d)}return n}function f(d){let b=typeof d=="function"?d(n):d,B=o.equals||st;if(t?.equals===!1||!B(n,b)){n=b,o.value=b,o.version++,o.updated=Date.now();let C=O.get(r);if(C&&C.size>0){let F=function(l,se=!1){let m=l.state;if(!(m===I&&l===v)){if(se&&!l.pure){m===V&&(l.state=pe,Qe&&(i!==null&&i.indexOf(l)===-1?i.push(l):x.push(l)));return}if(!S.has(l)&&(S.add(l),l.state=re,m===V||m===pe?x.push(l):!l.pure&&i!==null&&i.indexOf(l)===-1&&i.push(l),l.pure&&l.accessor)){let $=O.get(l.accessor);$&&qe(Array.from($),k=>F(k,!0))}}};var j=F;let P=Array.from(C),x=[],S=new Set;qe(P,F);for(let l of x)it(l)}}}return a.toObservable=()=>new Y(d=>{let b=!0;return he(()=>{let j=a();b?b=!1:d.next(j)})}),Object.defineProperty(a,Je,{value:!0,enumerable:!0}),Object.defineProperty(a,Xe,{value:o,enumerable:!1}),r}function he(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Ue(o,t),()=>U(o)}function Ue(e,t){if(e.sources){for(let r of e.sources){let s=O.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=v,o=c;if(v=e,c=e,ne++,ne>Ze)throw ne=0,v=n,c=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=I;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===I&&(e.state=V)}catch(r){if(Ne(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ie(r)}finally{v=n,c=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===V)&&(e.state===re||e.state===pe||e.state===I)){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?Me(e):Ue(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=O.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 oe(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=O.get(r.accessor);if(s&&s.size>0){let f=v;v=null,r.accessor(),v=f}let a=i.splice(0);for(let f of a)f.pure&&!f.computed&&f.accessor?t.indexOf(f)===-1&&t.push(f):(f.computed||!f.pure)&&n.indexOf(f)===-1&&n.push(f)}i=null;for(let r of n)(r.computed||!r.pure)&&ve(r)}function _(e){if(i&&N>0)return e();if(i&&N===0){let t=i,n=[];i=n,N++;let o;try{o=e()}finally{N--,i=t}let r=i;return oe(n),i=r,o}N++,i=[],te=[];try{return e()}finally{N--,ut()}}function ut(){if(!de){de=!0,ne=0;try{for(;i&&i.length>0;){let e=i;i=null,oe(e)}if(i=null,te){let e=te;te=null;for(let t=0;t<e.length;t++)ve(e[t])}}finally{de=!1}}}function L(e){let t=v;v=null;try{return e()}finally{v=t}}function Le(e){c&&(c.cleanups?c.cleanups.push(e):c.cleanups=[e])}function at(e){let t=Symbol("context"),n=lt(t);return{id:t,Provider:n,defaultValue:e}}function lt(e){return t=>{let n=c;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return ct(()=>{o=L(()=>{let r=c;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),Fe(()=>t.children)})}),o}}function M(e){let t=c;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 ct(e,t,n){let o={fn:e,state:re,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:c,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};c&&(c.owned?c.owned.push(o):c.owned=[o]);let r=w&&M(w);return r&&(o.suspense=r),Me(o),()=>U(o)}function Me(e){if(e.sources){for(let r of e.sources){let s=O.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=v,n=c,o=i;v=e,c=e,i===null&&(i=[]),e.state=I;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===I&&(e.state=V)}catch(r){if(Ne(r)){let s=w&&M(w);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}Ie(r)}finally{v=t,c=n;let r=i;if(i=o,r!==o&&r&&r.length>0){let s=i;oe(r),i=s}}}var w;function Be(){return w||(w=at())}var E=new Map,A=new Map,ft=0,dt=Symbol.for("signal"),pt=Symbol.for("resource");function en(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:a=1/0,name:f=`_auto_${ft++}`,staleWhileRevalidate:d=!0}=s,b=f,B=u=>`${b}:${JSON.stringify(u)}`,j=u=>a===1/0||Date.now()-u.timestamp<=a,[C,P]=R(void 0,{equals:!1}),[x,S]=R("unresolved",{equals:!1}),[F,l]=R(void 0,{equals:!1}),[se,m]=R(void 0,{equals:!1}),[$,k]=R(!1),[Ge,Te]=R(0,{equals:!1}),ie=Symbol("unset"),W=ie,ue=!1,ae=!1;function ye(u,T,y,g){if(A.has(T)){A.get(T).then(p=>{g()||be(p,y)},p=>{!g()&&!y&&me(p)}),y||m(A.get(T));return}let D=Promise.resolve(r(u)).then(p=>(E.set(T,{value:p,timestamp:Date.now()}),A.delete(T),p),p=>{throw A.delete(T),p});if(A.set(T,D),!y){fe(D),m(D);let p=z&&M(z);p&&(p.increment(),D.finally(()=>p.decrement()))}D.then(p=>{g()||be(p,y)},p=>{!g()&&!y&&me(p)})}function be(u,T){_(()=>{P(()=>u),S("ready"),k(!1),m(void 0),l(void 0)})}function me(u){_(()=>{l(u),S("errored"),m(void 0)})}let z;he(()=>{z===void 0&&(z=Be());let u=o();if(Ge(),u===!1||u===null||u===void 0){W=ie,_(()=>{S("unresolved"),m(void 0),l(void 0)});return}let T=ue,y=ae;ue=!1,ae=!1;let g=B(u);y&&E.delete(g);let D=W===ie||u!==W;W=u;let p=!1;Le(()=>{p=!0});let q=E.get(g);if(q&&j(q)&&!T&&!y){(L(x)!=="ready"||L(C)!==q.value)&&_(()=>{P(()=>q.value),S("ready"),k(!1),l(void 0)});return}if(q&&d&&!y){_(()=>{P(()=>q.value),S("ready"),k(!0),l(void 0),m(void 0)}),ye(u,g,!0,()=>p);return}let we=L(x),Ve=we==="ready"||we==="refreshing";_(()=>{S(Ve?"refreshing":"pending"),l(void 0),k(!1)}),ye(u,g,!1,()=>p)});let H=(()=>{let u=F();if(u)throw u;if(x()==="pending"){let y=se();if(y)throw y}return C()});return Object.defineProperty(H,pt,{value:!0,enumerable:!0}),Object.defineProperty(H,dt,{value:!0,enumerable:!0}),Object.defineProperties(H,{state:{get:x},loading:{get:()=>{let u=x();return u==="pending"||u==="refreshing"}},error:{get:F},latest:{get:C},stale:{get:$}}),[H,{mutate:P,refetch:()=>{ue=!0,Te(u=>u+1)},invalidate:()=>{let u=L(o);u!=null&&u!==!1&&E.delete(B(u)),ae=!0,Te(T=>T+1)}}]}function tn(e){let t=`${e}:`;for(let n of E.keys())n.startsWith(t)&&E.delete(n)}function nn(){E.clear(),A.clear()}export{nn as clearAllCachedResources,tn as clearCachedResourceNamespace,en as createCachedResource};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var I=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var he=(e,
|
|
1
|
+
"use strict";var I=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var pe=Object.prototype.hasOwnProperty;var he=(e,n)=>{for(var t in n)I(e,t,{get:n[t],enumerable:!0})},Te=(e,n,t,s)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of fe(n))!pe.call(e,o)&&o!==t&&I(e,o,{get:()=>n[o],enumerable:!(s=de(n,o))||s.enumerable});return e};var ve=e=>Te(I({},"__esModule",{value:!0}),e);var Oe={};he(Oe,{createDebouncedResource:()=>Re,createDebouncedSignal:()=>ie});module.exports=ve(Oe);var we="__fluixi_signal_next_state__",me=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[we]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:me,onSuspend:null,onError:null};var H=0,K=1,b=2,q=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let n=r.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},D=class extends q{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);N(this)}}peek(){return this._value}},g=class extends q{constructor(t,s){super();this._threw=!1;this._initialized=!1;this.state=b;this.sources=null;this._fn=t,this._equals=s?.equals===!1?()=>!1:s?.equals??Object.is}get(){if(r.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===K&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===b)break}(this.state===b||!this._initialized)&&this.recompute(),this.state=H}recompute(){if(this.sources){for(let a of this.sources)a.observers?.delete(this);this.sources.clear()}let t=r.consumer,s=r.untracked;r.consumer=this,r.untracked=!1;let o,i=!1,u;try{o=this._fn()}catch(a){i=!0,u=a,o=this._value}finally{r.consumer=t,r.untracked=s}let l=!this._initialized||this._threw!==i||(i?u!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=i,this._error=u,this._value=o,l){if(this.version++,this.observers)for(let a of[...this.observers])a.markDirty(b);N(this)}}markDirty(t){if(this.state>=t)return;let s=this.state===H;if(this.state=t,s){if(this.observers)for(let o of[...this.observers])o.markDirty(K);N(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function N(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var C=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 L(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function ye(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e,n){let t=r.owner;r.owner=e;try{return n()}finally{r.owner=t}}function x(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function V(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)V(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 U(e){r.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Se(e){e.queued||(e.queued=!0,r.queue.push(e),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(A)))}function A(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let e=0;try{for(;r.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=r.queue;r.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function Y(){r.batchDepth===0&&A()}function $(e){r.batchDepth++;try{return e()}finally{--r.batchDepth===0&&A()}}var j=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=ye(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{V(this.owner,!1),M(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new C(()=>Se(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"&&r.onSuspend){r.onSuspend(n,this.owner);return}if(r.onError&&r.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),V(this.owner))}};function Q(e){let n=new j(e);return()=>n.dispose()}U(()=>{});var ge=Symbol.for("signal");var xe=Symbol.for("signal-node");function p(e,n){let t=new D(e,{equals:n?.equals}),s=(()=>t.get()),o=(i=>{let u=typeof i=="function"?i(t.peek()):i;return t.set(u),Y(),u});return Object.defineProperty(s,ge,{value:!0,enumerable:!0}),Object.defineProperty(s,xe,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[s,o]}function B(e,n){let t=n;return Q(()=>{t=e(t)})}function m(e){return $(e)}function S(e){return L(e)}var J=null;function ne(e){J&&J(e)}var X=null;function te(e){return X?X(e):void 0}var Z=null;function re(){return Z?Z():void 0}var ee=null;function oe(e,n){ee&&ee(e,n)}function ke(e){return!!e&&typeof e.then=="function"}var F=Symbol();function se(e,n,t={}){let s,o;typeof n=="function"?(s=typeof e=="function"?e:()=>e,o=n):(s=()=>!0,o=e,n&&typeof n=="object"&&(t=n));let i=re(),u=i!==void 0?te(i):void 0,l=u!==void 0,[a,d]=p(u!==void 0?u.value:t.initialValue,{equals:!1}),[v,T]=p(void 0,{equals:!1}),[f,h]=p(u!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[ue,y]=p(void 0,{equals:!1}),[ae,ce]=p(void 0,{equals:!1}),k=F,E=!1;B(()=>{let c=s();if(ae(),c===!1||c===null||c===void 0){k=F,m(()=>{h("unresolved"),y(void 0),T(void 0)});return}let R=E;if(E=!1,k!==F&&c===k&&!R)return;if(k=c,l){l=!1;return}let O=!1;x(()=>O=!0);let W=S(f),le=S(a),z=W==="ready"||W==="refreshing";m(()=>{h(z?"refreshing":"pending"),T(void 0)});try{let w=o(c,{value:le,refetching:z});ke(w)?(y(w),ne(w),w.then(P=>{O||(i!==void 0&&oe(i,P),m(()=>{d(()=>P),h("ready"),y(void 0)}))},P=>{O||m(()=>{T(P),h("errored"),y(void 0)})})):m(()=>{d(()=>w),h("ready"),y(void 0)})}catch(w){if(O)return;m(()=>{T(w),h("errored"),y(void 0)})}});let G=()=>{let c=f();return c==="pending"||c==="refreshing"},_=(()=>{let c=v();if(c)throw c;if(G()){let R=ue();if(R)throw R}return a()});return Object.defineProperties(_,{state:{get:f},loading:{get:G},error:{get:v},latest:{get:a}}),Object.defineProperty(_,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(_,Symbol.for("signal"),{value:!0,enumerable:!0}),[_,{mutate:d,refetch:()=>{E=!0,ce(void 0)}}]}function ie(e,n=300){let[t,s]=p(e),[o,i]=p(e),[u,l]=p(!1),a,d=()=>{a!==void 0&&(clearTimeout(a),a=void 0)},v=()=>{d();let f=S(t);return i(()=>f),l(!1),f},T=(f=>{let h=typeof f=="function"?f(S(t)):f;return s(()=>h),l(!0),d(),a=setTimeout(v,n),h});return x(d),[o,T,{immediate:t,pending:u,flush:v,cancel:()=>{d(),l(!1)}}]}function _e(e){return e!=null&&e!==""}function Re(e,n,t={}){let{delay:s=300,initialValue:o,shouldFetch:i=_e}=t,[u,l,a]=ie(e,s),d=()=>i(u())?u():!1,[v,{refetch:T}]=se(d,n,o===void 0?{}:{initialValue:o});return[v,{...a,query:u,setQuery:l,refetch:T}]}
|