@fluixi/reactive 1.0.0-alpha.66 → 1.0.0-alpha.68
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
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Me=Object.defineProperty;var $n=Object.getOwnPropertyDescriptor;var Wn=Object.getOwnPropertyNames;var zn=Object.prototype.hasOwnProperty;var Hn=(e,n)=>{for(var t in n)Me(e,t,{get:n[t],enumerable:!0})},Yn=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Wn(n))!zn.call(e,r)&&r!==t&&Me(e,r,{get:()=>n[r],enumerable:!(o=$n(n,r))||o.enumerable});return e};var Jn=e=>Yn(Me({},"__esModule",{value:!0}),e);var or={};Hn(or,{$MEMO:()=>Fn,$PROXY:()=>Ze,$RESOURCE:()=>Un,$SIGNAL:()=>De,__DEV__:()=>de,batch:()=>k,clearAllCachedResources:()=>er,clearCachedResourceNamespace:()=>Zt,combineSignal:()=>It,combineSignals:()=>Nt,createCachedResource:()=>Qt,createComputed:()=>wt,createContext:()=>on,createDebounce:()=>Rn,createDeferred:()=>On,createEffect:()=>ne,createMemo:()=>ht,createProvider:()=>Bn,createRenderEffect:()=>jn,createResource:()=>yt,createRoot:()=>vt,createSelector:()=>wn,createSignal:()=>U,debounceSignal:()=>Wt,distinctSignal:()=>Mt,everySignal:()=>Dt,filterSignal:()=>kt,findSignal:()=>Ft,flush:()=>xt,getOwner:()=>bt,getServerData:()=>Ye,getSharedConfig:()=>dt,getSuspenseContext:()=>sn,getSuspenseListContext:()=>Ot,guardSignal:()=>$t,indexArray:()=>rr,isComponent:()=>fn,isMemo:()=>cn,isProvider:()=>pn,isResource:()=>ln,isSignal:()=>we,isSuspense:()=>dn,keyArray:()=>tr,makeArrayFlat:()=>Le,mapArray:()=>nr,mapSignal:()=>Et,mergeSignal:()=>Lt,nextResourceId:()=>Je,omitSignal:()=>Gt,on:()=>gt,onCleanup:()=>be,onResolve:()=>At,pickSignal:()=>jt,readChildren:()=>Ke,readSignal:()=>Ht,reduceSignal:()=>Pt,reportResourceData:()=>Xe,resumeEffects:()=>Rt,runWithOwner:()=>mt,selectSignal:()=>Vt,setOwner:()=>ft,setResourceDataSink:()=>En,setResourceIdSource:()=>_n,setResourceTracker:()=>An,setScheduler:()=>Ct,setServerDataGetter:()=>Cn,sharedConfig:()=>Ue,someSignal:()=>Ut,sortSignal:()=>qt,startTransition:()=>Vn,throttleSignal:()=>zt,trackPromise:()=>_t,trackResourcePromise:()=>ve,untrack:()=>L,useContext:()=>I,useTransition:()=>St,whenSignal:()=>Kt,zipSignal:()=>Bt});module.exports=Jn(or);var an=require("@fluixi/utils/object"),Ie=require("@fluixi/utils/functions"),fe=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if((0,Ie.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,an.isObject)(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if((0,Ie.isFunction)(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var ge=class extends fe{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ne=class extends ge{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof ge?r=n:r=new Ne(n,t,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};var me=require("@fluixi/utils");var de=!1,Xn=Symbol.for("signal"),Qn=Symbol.for("memo"),Zn=Symbol.for("resource");function we(e){return typeof e=="function"&&e[Xn]===!0}function cn(e){return typeof e=="function"&&e[Qn]===!0}function ln(e){return typeof e=="function"&&e[Zn]===!0}function fn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function dn(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function pn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var et="__fluixi_signal_next_state__",nt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[et]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:nt,onSuspend:null,onError:null};var Tn=0,hn=1,pe=2,Oe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let n=c.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},Re=class extends Oe{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(pe);Be(this)}}peek(){return this._value}},ue=class extends Oe{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=pe;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===hn&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===pe)break}(this.state===pe||!this._initialized)&&this.recompute(),this.state=Tn}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=t,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(pe);Be(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Tn;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(hn);Be(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Be(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var Ae=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 vn(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function yn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function bn(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function je(){return c.owner}function _e(e,n){let t=c.owner;c.owner=e;try{return n()}finally{c.owner=t}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function Ce(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)Ce(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 Te(e){let n=yn(c.owner);c.owner&&(c.owner.owned??=[]).push(n);let t=c.owner;c.owner=n;try{return e(()=>Ce(n))}finally{c.owner=t}}function mn(e){c.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function tt(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ge)))}function Ge(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=c.queue;c.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{c.flushing=!1}}function xn(){c.batchDepth===0&&Ge()}var Ve=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=yn(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ue(()=>{Ce(this.owner,!1),_e(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new Ae(()=>tt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&c.onSuspend){c.onSuspend(n,this.owner);return}if(c.onError&&c.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),Ce(this.owner))}};function Sn(e){let n=new Ve(e);return()=>n.dispose()}function rt(e){return!!e&&typeof e.then=="function"}mn(()=>{});var gn=Symbol.for("signal"),ot=Symbol.for("memo"),st=Symbol.for("signal-node");function N(e,n){let t=new Re(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),xn(),u});return Object.defineProperty(o,gn,{value:!0,enumerable:!0}),Object.defineProperty(o,st,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function x(e,n,t){let o=n,r=je(),s=new ue(()=>_e(r,()=>{try{return o=e(o)}catch(a){if(rt(a))return bn(a),o;throw a}}),{equals:t?.equals}),u=(()=>s.get());return Object.defineProperty(u,gn,{value:!0,enumerable:!0}),Object.defineProperty(u,ot,{value:!0,enumerable:!0}),u}function he(e,n){let t=n;return Sn(()=>{t=e(t)})}function Ee(e){return vn(e)}function wn(e,n=(t,o)=>t===o){let t=new Map;return he(()=>{let o=e();for(let[r,s]of t){let[u,a]=s,i=n(r,o);u()!==i&&a(i)}}),o=>{let r=t.get(o);if(!r){let[s,u]=N(!1);r=[s,u],t.set(o,r);let a=e();u(n(o,a))}return r[0]()}}function On(e,n){let[t,o]=N(e(),n);return he(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function Rn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ee(()=>{t!==void 0&&clearTimeout(t)}),o}function ke(e){if(typeof e=="function"&&!e.length){let n=e();return we(n)?n:ke(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=ke(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function Ke(e){let n=x(e);return x(()=>ke(n()))}var $e=null;function An(e){$e=e}function ve(e){$e&&$e(e)}var We=null;function Cn(e){We=e}function Ye(e){return We?We(e):void 0}var ze=null;function _n(e){ze=e}function Je(){return ze?ze():void 0}var He=null;function En(e){He=e}function Xe(e,n){He&&He(e,n)}var De=Symbol.for("signal"),Fn=Symbol.for("memo"),Un=Symbol.for("resource"),Ze=Symbol("fluixi-proxy"),Dn=Symbol.for("signal-node"),K=0,ye=1,W=2,$=3,f=null,v=null,l=null,Pe=null,Fe=0,it=!1,Qe=!1,ae=0,ut=1e6,F=new WeakMap,M=null;var at=null,ct=new Map,lt=0,Ue={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function ft(e){f=e,Ue.owner=e,Ue.context=e}function dt(){return Ue}function pt(){return`node_${++lt}_${Date.now()}`}function Tt(e){!1}function qn(e,n,t){let o={id:pt(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return Tt(o),o}function Mn(e,n){return e===n}function tn(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var en=null,nn=null;function In(){if(!en){let[e,n]=U(!1);en=e,nn=n}}function Nn(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)xe(e);else if(e.pure&&!e.computed&&e.accessor){let n=v,t=l;v=null,l=[],e.accessor(),v=n;let o=l;if(l=t,o.length>0){let r=l;qe(o),l=r}}}function kn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function U(e,n){let t=e;typeof t=="object"&&t&&Ze in t&&delete t[Ze];let o=qn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[u,a];F.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=F.get(r);d&&!d.has(i)&&d.add(i)}return t}function a(i){let d=typeof i=="function"?i(t):i,y=o.equals||Mn;if(n?.equals===!1||!y(t,d)){t=d,o.value=d,o.version++,o.updated=Date.now();let g=F.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===$&&p===v)){if(b&&!p.pure){C===K&&(p.state=ye,it&&(l!==null&&l.indexOf(p)===-1?l.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=W,C===K||C===ye?w.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let P=F.get(p.accessor);P&&kn(Array.from(P),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;kn(S,E);for(let p of w)Nn(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ne(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,De,{value:!0,enumerable:!0}),Object.defineProperty(u,Dn,{value:o,enumerable:!1}),r}function ne(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),rn(o,n),()=>J(o)}function rn(e,n){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,o=f;if(v=e,f=e,Fe++,Fe>ut)throw Fe=0,v=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=$;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}tn(r)}finally{v=t,f=o}}function xe(e){if(!(e.disposed||!e.fn||e.state===K)&&(e.state===W||e.state===ye||e.state===$)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)J(e.owned[n]);e.owned=null}e.renderEffect?Gn(e):rn(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=F.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)J(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function ht(e,n,t){let o=qn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;F.has(a)||F.set(a,new Set);let i=F.get(a);i&&i.add(v)}if(r.state!==K){if(r.sources){for(let d of r.sources){let y=F.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=$;try{let d=r.fn(r.value),y=o.equals||Mn;if(t?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=F.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let P=b.state;if(P!==$){if(C&&!b.pure){P===K&&(b.state=ye,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=W,P===K||P===ye?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=F.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)Nn(b)}}r.state===$&&(r.state=K)}catch(d){if((0,me.isPromise)(d)){let y=O&&I(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}tn(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,F.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ne(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,De,{value:!0,enumerable:!0}),Object.defineProperty(s,Fn,{value:!0,enumerable:!0}),Object.defineProperty(s,Dn,{value:o,enumerable:!1}),s}function qe(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);l=[];let o=0;for(;o<n.length;){let r=n[o++],s=F.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?n.indexOf(a)===-1&&n.push(a):(a.computed||!a.pure)&&t.indexOf(a)===-1&&t.push(a)}l=null;for(let r of t)(r.computed||!r.pure)&&xe(r)}function k(e){if(l&&ae>0)return e();if(l&&ae===0){let n=l,t=[];l=t,ae++;let o;try{o=e()}finally{ae--,l=n}let r=l;return qe(t),l=r,o}ae++,l=[],Pe=[];try{return e()}finally{ae--,Ln()}}function Ln(){if(!Qe){Qe=!0,Fe=0;try{for(;l&&l.length>0;){let e=l;l=null,qe(e)}if(l=null,Pe){let e=Pe;Pe=null;for(let n=0;n<e.length;n++)xe(e[n])}}finally{Qe=!1}}}function vt(e){let n={owned:null,cleanups:null,contexts:null,owner:f},t=v;v=null;let o=f;f=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)J(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{f=o,v=t}}function L(e){let n=v;v=null;try{return e()}finally{v=n}}function be(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function yt(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:u}=t,a=Je(),i=a!==void 0?Ye(a):void 0,d=i!==void 0,[y,T]=U(i!==void 0?i.value:t.initialValue,{equals:!1}),[g,S]=U(void 0,{equals:!1}),[w,m]=U(i!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),P=Symbol(),_=P,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(B){console.error(`Failed to save resource to cache (${u}):`,B)}},ce=ne(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=P,k(()=>{m("unresolved"),p(void 0),S(void 0)});return}let B=z;if(z=!1,_!==P&&A===_&&!B)return;if(_=A,d){d=!1;return}let V=!1;be(()=>V=!0);let le=L(w),oe=L(y),Q=le==="ready"||le==="refreshing";k(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let j=r(A,{value:oe,refetching:Q});if((0,me.isPromise)(j)){p(j),ve(j),j.then(h=>{V||(a!==void 0&&Xe(a,h),k(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{V||k(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{V||k(()=>{S(h),m("errored"),p(void 0)})});let Se=O&&I(O);Se&&(Se.increment(),j.finally(()=>Se.decrement()))}else{if(V)return;k(()=>{T(()=>j),m("ready"),p(void 0)})}}catch(j){if(V)return;k(()=>{S(j),m("errored"),p(void 0)})}});be(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let B=E();if(B)throw B}return y()});return Object.defineProperty(Y,Un,{value:!0,enumerable:!0}),Object.defineProperty(Y,De,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function bt(){return f}function mt(e,n){let t=f,o=v;f=e,v=null;try{return n()}finally{f=t,v=o}}function on(e){let n=Symbol("context"),t=Bn(n);return{id:n,Provider:t,defaultValue:e}}function Bn(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return jn(()=>{o=L(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),Ke(()=>n.children)})}),o}}function I(e){let n=f;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function xt(){return new Promise(e=>{queueMicrotask(()=>{Ln(),e()})})}function Vn(e){if(M&&M.running)return e(),M.done;In();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};M=o;try{e()}finally{o.running=!1}return o.effects.length?(nn(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,nn(!1),r.length&&k(()=>{for(let s of r)s.state=W,xe(s)}),n()}),t):(M=null,n(),t)}function St(){return In(),[en,Vn]}function gt(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):L(()=>n(u,s))}}function jn(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),Gn(o),()=>J(o)}function Gn(e){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,t=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=$;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}tn(r)}finally{v=n,f=t;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;qe(r),l=s}}}function wt(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):rn(o,n)}var O;function sn(){return O||(O=on())}var Pn;function Ot(){return Pn||(Pn=on())}function Rt(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=W,xe(t)}function At(e){let n=O&&I(O);n&&n.inFallback()?ne(()=>{n.inFallback()||e()}):e()}function Ct(e){at=e}function _t(e){let n=O&&I(O);return n&&(n.increment(),e.finally(()=>n.decrement())),e}function Et(e,n,t){return x(()=>n(e()),void 0,t)}function kt(e,n,t){return x(()=>e().filter(n),void 0,t)}function Pt(e,n,t,o){return x(()=>e().reduce(n,t),void 0,o)}function Ft(e,n,t){return x(()=>e().find(n),void 0,t)}function Ut(e,n,t){return x(()=>e().some(n),void 0,t)}function Dt(e,n,t){return x(()=>e().every(n),void 0,t)}function qt(e,n,t){return x(()=>[...e()].sort(n),void 0,t)}function Mt(e,n){return x(()=>[...new Set(e())],void 0,n)}function It(e,n,t){return x(()=>{let o=e.map(r=>r());return n(o)},void 0,t)}function Nt(...e){return new Z(n=>{let t=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{n.next(t())}):typeof r!="function"?r.subscribe(()=>{n.next(t())}):he(()=>{n.next(t())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function Lt(e,n,t){return x(()=>e()||n(),void 0,t)}function Bt(e,n,t,o){return x(()=>t(e(),n()),void 0,o)}function Vt(e,n,t){return x(()=>n(e()),void 0,{equals:t,internal:!0})}function jt(e,n,t){return x(()=>{let o=e(),r={};for(let s of n)r[s]=o[s];return r},void 0,t)}function Gt(e,n,t){return x(()=>{let r={...e()};for(let s of n)delete r[s];return r},void 0,t)}function Kt(e,n,t,o){return x(()=>e()?n():t(),void 0,o)}function $t(e,n,t){return x(()=>e()?n():void 0,void 0,t)}function Wt(e,n,t){let[o,r]=N(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),n)}),o}function zt(e,n,t){let[o,r]=N(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=n?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},n-(i-s)))}),o}function Ht(e){let n=e;for(;typeof n=="function";)n=n();return n}var re=new Map,te=new Map,Yt=0,Jt=Symbol.for("signal"),Xt=Symbol.for("resource");function Qt(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:u=1/0,name:a=`_auto_${Yt++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=U(void 0,{equals:!1}),[w,m]=U("unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),[P,_]=U(!1),[z,H]=U(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function B(h,D,q,G){if(te.has(D)){te.get(D).then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)}),q||C(te.get(D));return}let se=Promise.resolve(r(h)).then(R=>(re.set(D,{value:R,timestamp:Date.now()}),te.delete(D),R),R=>{throw te.delete(D),R});if(te.set(D,se),!q){ve(se),C(se);let R=oe&&I(oe);R&&(R.increment(),se.finally(()=>R.decrement()))}se.then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)})}function V(h,D){k(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){k(()=>{p(h),m("errored"),C(void 0)})}let oe;ne(()=>{oe===void 0&&(oe=sn());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,k(()=>{m("unresolved"),C(void 0),p(void 0)});return}let D=Y,q=A;Y=!1,A=!1;let G=y(h);q&&re.delete(G);let se=X===ce||h!==X;X=h;let R=!1;be(()=>{R=!0});let ie=re.get(G);if(ie&&T(ie)&&!D&&!q){(L(w)!=="ready"||L(g)!==ie.value)&&k(()=>{S(()=>ie.value),m("ready"),_(!1),p(void 0)});return}if(ie&&i&&!q){k(()=>{S(()=>ie.value),m("ready"),_(!0),p(void 0),C(void 0)}),B(h,G,!0,()=>R);return}let un=L(w),Kn=un==="ready"||un==="refreshing";k(()=>{m(Kn?"refreshing":"pending"),p(void 0),_(!1)}),B(h,G,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let q=b();if(q)throw q}return g()});return Object.defineProperty(Q,Xt,{value:!0,enumerable:!0}),Object.defineProperty(Q,Jt,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:P}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=L(o);h!=null&&h!==!1&&re.delete(y(h)),A=!0,H(D=>D+1)}}]}function Zt(e){let n=`${e}:`;for(let t of re.keys())t.startsWith(n)&&re.delete(t)}function er(){re.clear(),te.clear()}function nr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;Te(m=>{S=m;let[E,p]=N(i);g=p,T=n(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function tr(e,n,t,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Ee(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=n(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;Te(p=>{E=p;let[b,C]=N(T);m=C;let P=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=t(P,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function rr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];Te(S=>{T=S;let[w,m]=N(g);y=m,d=n(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}
|
|
1
|
+
"use strict";var Me=Object.defineProperty;var $n=Object.getOwnPropertyDescriptor;var Wn=Object.getOwnPropertyNames;var zn=Object.prototype.hasOwnProperty;var Hn=(e,n)=>{for(var t in n)Me(e,t,{get:n[t],enumerable:!0})},Yn=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of Wn(n))!zn.call(e,r)&&r!==t&&Me(e,r,{get:()=>n[r],enumerable:!(o=$n(n,r))||o.enumerable});return e};var Jn=e=>Yn(Me({},"__esModule",{value:!0}),e);var or={};Hn(or,{$MEMO:()=>Fn,$PROXY:()=>Ze,$RESOURCE:()=>Un,$SIGNAL:()=>De,__DEV__:()=>de,batch:()=>k,clearAllCachedResources:()=>er,clearCachedResourceNamespace:()=>Zt,combineSignal:()=>It,combineSignals:()=>Nt,createCachedResource:()=>Qt,createComputed:()=>gt,createContext:()=>on,createDebounce:()=>Rn,createDeferred:()=>On,createEffect:()=>ne,createMemo:()=>ht,createProvider:()=>Bn,createRenderEffect:()=>jn,createResource:()=>yt,createRoot:()=>vt,createSelector:()=>gn,createSignal:()=>U,debounceSignal:()=>Wt,distinctSignal:()=>Mt,everySignal:()=>Dt,filterSignal:()=>kt,findSignal:()=>Ft,flush:()=>xt,getOwner:()=>bt,getServerData:()=>Ye,getSharedConfig:()=>dt,getSuspenseContext:()=>sn,getSuspenseListContext:()=>Ot,guardSignal:()=>$t,indexArray:()=>rr,isComponent:()=>fn,isMemo:()=>cn,isProvider:()=>pn,isResource:()=>ln,isSignal:()=>ge,isSuspense:()=>dn,keyArray:()=>tr,makeArrayFlat:()=>Le,mapArray:()=>nr,mapSignal:()=>Et,mergeSignal:()=>Lt,nextResourceId:()=>Je,omitSignal:()=>Gt,on:()=>wt,onCleanup:()=>be,onResolve:()=>At,pickSignal:()=>jt,readChildren:()=>Ke,readSignal:()=>Ht,reduceSignal:()=>Pt,reportResourceData:()=>Xe,resumeEffects:()=>Rt,runWithOwner:()=>mt,selectSignal:()=>Vt,setOwner:()=>ft,setResourceDataSink:()=>En,setResourceIdSource:()=>_n,setResourceTracker:()=>An,setScheduler:()=>Ct,setServerDataGetter:()=>Cn,sharedConfig:()=>Ue,someSignal:()=>Ut,sortSignal:()=>qt,startTransition:()=>Vn,throttleSignal:()=>zt,trackPromise:()=>_t,trackResourcePromise:()=>ve,untrack:()=>L,useContext:()=>I,useTransition:()=>St,whenSignal:()=>Kt,zipSignal:()=>Bt});module.exports=Jn(or);var an=require("@fluixi/utils/object"),Ie=require("@fluixi/utils/functions"),fe=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if((0,Ie.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,an.isObject)(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if((0,Ie.isFunction)(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var we=class extends fe{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ne=class extends we{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof we?r=n:r=new Ne(n,t,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};var me=require("@fluixi/utils");var de=!1,Xn=Symbol.for("signal"),Qn=Symbol.for("memo"),Zn=Symbol.for("resource");function ge(e){return typeof e=="function"&&e[Xn]===!0}function cn(e){return typeof e=="function"&&e[Qn]===!0}function ln(e){return typeof e=="function"&&e[Zn]===!0}function fn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function dn(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function pn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var et="__fluixi_signal_next_state__",nt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[et]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:nt,onSuspend:null,onError:null};var Tn=0,hn=1,pe=2,Oe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let n=c.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},Re=class extends Oe{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(pe);Be(this)}}peek(){return this._value}},ue=class extends Oe{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=pe;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===hn&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===pe)break}(this.state===pe||!this._initialized)&&this.recompute(),this.state=Tn}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=t,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(pe);Be(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Tn;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(hn);Be(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Be(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var Ae=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 vn(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function yn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function bn(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function je(){return c.owner}function _e(e,n){let t=c.owner;c.owner=e;try{return n()}finally{c.owner=t}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function Ce(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)Ce(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 Te(e){let n=yn(c.owner);c.owner&&(c.owner.owned??=[]).push(n);let t=c.owner;c.owner=n;try{return e(()=>Ce(n))}finally{c.owner=t}}function mn(e){c.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function tt(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ge)))}function Ge(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=c.queue;c.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{c.flushing=!1}}function xn(){c.batchDepth===0&&Ge()}var Ve=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=yn(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ue(()=>{Ce(this.owner,!1),_e(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new Ae(()=>tt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&c.onSuspend){c.onSuspend(n,this.owner);return}if(c.onError&&c.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),Ce(this.owner))}};function Sn(e){let n=new Ve(e);return()=>n.dispose()}function rt(e){return!!e&&typeof e.then=="function"}mn(()=>{});var wn=Symbol.for("signal"),ot=Symbol.for("memo"),st=Symbol.for("signal-node");function N(e,n){let t=new Re(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),xn(),u});return Object.defineProperty(o,wn,{value:!0,enumerable:!0}),Object.defineProperty(o,st,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function x(e,n,t){let o=n,r=je(),s=new ue(()=>_e(r,()=>{try{return o=e(o)}catch(a){if(rt(a))return bn(a),o;throw a}}),{equals:t?.equals}),u=(()=>s.get());return Object.defineProperty(u,wn,{value:!0,enumerable:!0}),Object.defineProperty(u,ot,{value:!0,enumerable:!0}),u}function he(e,n){let t=n;return Sn(()=>{t=e(t)})}function Ee(e){return vn(e)}function gn(e,n=(t,o)=>t===o){let t=new Map;return he(()=>{let o=e();for(let[r,s]of t){let[u,a]=s,i=n(r,o);u()!==i&&a(i)}}),o=>{let r=t.get(o);if(!r){let[s,u]=N(!1);r=[s,u],t.set(o,r);let a=e();u(n(o,a))}return r[0]()}}function On(e,n){let[t,o]=N(e(),n);return he(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function Rn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ee(()=>{t!==void 0&&clearTimeout(t)}),o}function ke(e){if(typeof e=="function"&&!e.length){let n=e();return ge(n)?n:ke(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=ke(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function Ke(e){let n=x(e);return x(()=>ke(n()))}var $e=null;function An(e){$e=e}function ve(e){$e&&$e(e)}var We=null;function Cn(e){We=e}function Ye(e){return We?We(e):void 0}var ze=null;function _n(e){ze=e}function Je(){return ze?ze():void 0}var He=null;function En(e){He=e}function Xe(e,n){He&&He(e,n)}var De=Symbol.for("signal"),Fn=Symbol.for("memo"),Un=Symbol.for("resource"),Ze=Symbol("fluixi-proxy"),Dn=Symbol.for("signal-node"),K=0,ye=1,W=2,$=3,f=null,v=null,l=null,Pe=null,Fe=0,it=!1,Qe=!1,ae=0,ut=1e6,F=new WeakMap,M=null;var at=null,ct=new Map,lt=0,Ue={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function ft(e){f=e,Ue.owner=e,Ue.context=e}function dt(){return Ue}function pt(){return`node_${++lt}_${Date.now()}`}function Tt(e){!1}function qn(e,n,t){let o={id:pt(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return Tt(o),o}function Mn(e,n){return e===n}function tn(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var en=null,nn=null;function In(){if(!en){let[e,n]=U(!1);en=e,nn=n}}function Nn(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)xe(e);else if(e.pure&&!e.computed&&e.accessor){let n=v,t=l;v=null,l=[],e.accessor(),v=n;let o=l;if(l=t,o.length>0){let r=l;qe(o),l=r}}}function kn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function U(e,n){let t=e;typeof t=="object"&&t&&Ze in t&&delete t[Ze];let o=qn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[u,a];F.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=F.get(r);d&&!d.has(i)&&d.add(i)}return t}function a(i){let d=typeof i=="function"?i(t):i,y=o.equals||Mn;if(n?.equals===!1||!y(t,d)){t=d,o.value=d,o.version++,o.updated=Date.now();let w=F.get(r);if(w&&w.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===$&&p===v)){if(b&&!p.pure){C===K&&(p.state=ye,it&&(l!==null&&l.indexOf(p)===-1?l.push(p):g.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=W,C===K||C===ye?g.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let P=F.get(p.accessor);P&&kn(Array.from(P),_=>E(_,!0))}}};var T=E;let S=Array.from(w),g=[],m=new Set;kn(S,E);for(let p of g)Nn(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ne(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,De,{value:!0,enumerable:!0}),Object.defineProperty(u,Dn,{value:o,enumerable:!1}),r}function ne(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),rn(o,n),()=>J(o)}function rn(e,n){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,o=f;if(v=e,f=e,Fe++,Fe>ut)throw Fe=0,v=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=$;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}tn(r)}finally{v=t,f=o}}function xe(e){if(!(e.disposed||!e.fn||e.state===K)&&(e.state===W||e.state===ye||e.state===$)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)J(e.owned[n]);e.owned=null}e.renderEffect?Gn(e):rn(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=F.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)J(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function ht(e,n,t){let o=qn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;F.has(a)||F.set(a,new Set);let i=F.get(a);i&&i.add(v)}if(r.state!==K){if(r.sources){for(let d of r.sources){let y=F.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=$;try{let d=r.fn(r.value),y=o.equals||Mn;if(t?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let w=s,S=F.get(w);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let P=b.state;if(P!==$){if(C&&!b.pure){P===K&&(b.state=ye,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=W,P===K||P===ye?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=F.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let g=Array.from(S),m=[],E=new Set;for(let b=0;b<g.length;b++)p(g[b]);for(let b of m)Nn(b)}}r.state===$&&(r.state=K)}catch(d){if((0,me.isPromise)(d)){let y=O&&I(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}tn(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,F.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ne(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,De,{value:!0,enumerable:!0}),Object.defineProperty(s,Fn,{value:!0,enumerable:!0}),Object.defineProperty(s,Dn,{value:o,enumerable:!1}),s}function qe(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);l=[];let o=0;for(;o<n.length;){let r=n[o++],s=F.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?n.indexOf(a)===-1&&n.push(a):(a.computed||!a.pure)&&t.indexOf(a)===-1&&t.push(a)}l=null;for(let r of t)(r.computed||!r.pure)&&xe(r)}function k(e){if(l&&ae>0)return e();if(l&&ae===0){let n=l,t=[];l=t,ae++;let o;try{o=e()}finally{ae--,l=n}let r=l;return qe(t),l=r,o}ae++,l=[],Pe=[];try{return e()}finally{ae--,Ln()}}function Ln(){if(!Qe){Qe=!0,Fe=0;try{for(;l&&l.length>0;){let e=l;l=null,qe(e)}if(l=null,Pe){let e=Pe;Pe=null;for(let n=0;n<e.length;n++)xe(e[n])}}finally{Qe=!1}}}function vt(e){let n={owned:null,cleanups:null,contexts:null,owner:f},t=v;v=null;let o=f;f=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)J(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{f=o,v=t}}function L(e){let n=v;v=null;try{return e()}finally{v=n}}function be(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function yt(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:u}=t,a=Je(),i=a!==void 0?Ye(a):void 0,d=i!==void 0,[y,T]=U(i!==void 0?i.value:t.initialValue,{equals:!1}),[w,S]=U(void 0,{equals:!1}),[g,m]=U(i!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),P=Symbol(),_=P,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(B){console.error(`Failed to save resource to cache (${u}):`,B)}},ce=ne(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=P,k(()=>{m("unresolved"),p(void 0),S(void 0)});return}let B=z;if(z=!1,_!==P&&A===_&&!B)return;if(_=A,d){d=!1;return}let V=!1;be(()=>V=!0);let le=L(g),oe=L(y),Q=le==="ready"||le==="refreshing";k(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let j=r(A,{value:oe,refetching:Q});if((0,me.isPromise)(j)){p(j),ve(j),j.then(h=>{V||(a!==void 0&&Xe(a,h),k(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{V||k(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{V||k(()=>{S(h),m("errored"),p(void 0)})});let Se=O&&I(O);Se&&(Se.increment(),j.finally(()=>Se.decrement()))}else{if(V)return;k(()=>{T(()=>j),m("ready"),p(void 0)})}}catch(j){if(V)return;k(()=>{S(j),m("errored"),p(void 0)})}});be(ce);let X=()=>{let A=g();return A==="pending"||A==="refreshing"},Y=(()=>{let A=w();if(A)throw A;if(X()){let B=E();if(B)throw B}return y()});return Object.defineProperty(Y,Un,{value:!0,enumerable:!0}),Object.defineProperty(Y,De,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:g},loading:{get:()=>X()},error:{get:w},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function bt(){return f}function mt(e,n){let t=f,o=v;f=e,v=null;try{return n()}finally{f=t,v=o}}function on(e){let n=Symbol("context"),t=Bn(n);return{id:n,Provider:t,defaultValue:e}}function Bn(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return jn(()=>{o=L(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),Ke(()=>n.children)})}),o}}function I(e){let n=f;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function xt(){return new Promise(e=>{queueMicrotask(()=>{Ln(),e()})})}function Vn(e){if(M&&M.running)return e(),M.done;In();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};M=o;try{e()}finally{o.running=!1}return o.effects.length?(nn(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,nn(!1),r.length&&k(()=>{for(let s of r)s.state=W,xe(s)}),n()}),t):(M=null,n(),t)}function St(){return In(),[en,Vn]}function wt(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):L(()=>n(u,s))}}function jn(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),Gn(o),()=>J(o)}function Gn(e){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,t=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=$;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}tn(r)}finally{v=n,f=t;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;qe(r),l=s}}}function gt(e,n,t){let o={fn:e,state:W,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):rn(o,n)}var O;function sn(){return O||(O=on())}var Pn;function Ot(){return Pn||(Pn=on())}function Rt(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=W,xe(t)}function At(e){let n=O&&I(O);n&&n.inFallback()?ne(()=>{n.inFallback()||e()}):e()}function Ct(e){at=e}function _t(e){let n=O&&I(O);return n&&(n.increment(),e.finally(()=>n.decrement())),e}function Et(e,n,t){return x(()=>n(e()),void 0,t)}function kt(e,n,t){return x(()=>e().filter(n),void 0,t)}function Pt(e,n,t,o){return x(()=>e().reduce(n,t),void 0,o)}function Ft(e,n,t){return x(()=>e().find(n),void 0,t)}function Ut(e,n,t){return x(()=>e().some(n),void 0,t)}function Dt(e,n,t){return x(()=>e().every(n),void 0,t)}function qt(e,n,t){return x(()=>[...e()].sort(n),void 0,t)}function Mt(e,n){return x(()=>[...new Set(e())],void 0,n)}function It(e,n,t){return x(()=>{let o=e.map(r=>r());return n(o)},void 0,t)}function Nt(...e){return new Z(n=>{let t=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{n.next(t())}):typeof r!="function"?r.subscribe(()=>{n.next(t())}):he(()=>{n.next(t())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function Lt(e,n,t){return x(()=>e()||n(),void 0,t)}function Bt(e,n,t,o){return x(()=>t(e(),n()),void 0,o)}function Vt(e,n,t){return x(()=>n(e()),void 0,{equals:t,internal:!0})}function jt(e,n,t){return x(()=>{let o=e(),r={};for(let s of n)r[s]=o[s];return r},void 0,t)}function Gt(e,n,t){return x(()=>{let r={...e()};for(let s of n)delete r[s];return r},void 0,t)}function Kt(e,n,t,o){return x(()=>e()?n():t(),void 0,o)}function $t(e,n,t){return x(()=>e()?n():void 0,void 0,t)}function Wt(e,n,t){let[o,r]=N(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),n)}),o}function zt(e,n,t){let[o,r]=N(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=n?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},n-(i-s)))}),o}function Ht(e){let n=e;for(;typeof n=="function";)n=n();return n}var re=new Map,te=new Map,Yt=0,Jt=Symbol.for("signal"),Xt=Symbol.for("resource");function Qt(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:u=1/0,name:a=`_auto_${Yt++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[w,S]=U(void 0,{equals:!1}),[g,m]=U("unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),[P,_]=U(!1),[z,H]=U(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function B(h,D,q,G){if(te.has(D)){te.get(D).then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)}),q||C(te.get(D));return}let se=Promise.resolve(r(h)).then(R=>(re.set(D,{value:R,timestamp:Date.now()}),te.delete(D),R),R=>{throw te.delete(D),R});if(te.set(D,se),!q){ve(se),C(se);let R=oe&&I(oe);R&&(R.increment(),se.finally(()=>R.decrement()))}se.then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)})}function V(h,D){k(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){k(()=>{p(h),m("errored"),C(void 0)})}let oe;ne(()=>{oe===void 0&&(oe=sn());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,k(()=>{m("unresolved"),C(void 0),p(void 0)});return}let D=Y,q=A;Y=!1,A=!1;let G=y(h);q&&re.delete(G);let se=X===ce||h!==X;X=h;let R=!1;be(()=>{R=!0});let ie=re.get(G);if(ie&&T(ie)&&!D&&!q){(L(g)!=="ready"||L(w)!==ie.value)&&k(()=>{S(()=>ie.value),m("ready"),_(!1),p(void 0)});return}if(ie&&i&&!q){k(()=>{S(()=>ie.value),m("ready"),_(!0),p(void 0),C(void 0)}),B(h,G,!0,()=>R);return}let un=L(g),Kn=un==="ready"||un==="refreshing";k(()=>{m(Kn?"refreshing":"pending"),p(void 0),_(!1)}),B(h,G,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(g()==="pending"){let q=b();if(q)throw q}return w()});return Object.defineProperty(Q,Xt,{value:!0,enumerable:!0}),Object.defineProperty(Q,Jt,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:g},loading:{get:()=>{let h=g();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:w},stale:{get:P}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=L(o);h!=null&&h!==!1&&re.delete(y(h)),A=!0,H(D=>D+1)}}]}function Zt(e){let n=`${e}:`;for(let t of re.keys())t.startsWith(n)&&re.delete(t)}function er(){re.clear(),te.clear()}function nr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,w,S;Te(m=>{S=m;let[E,p]=N(i);w=p,T=n(d,E)});let g={item:d,rendered:T,dispose:S,setIndex:w};u.push(g),a.add(g)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function tr(e,n,t,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Ee(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let w=n(u[T]),S=a.get(w);if(S&&!y.has(w))S.setIndex(T),i.push(S);else{let g,m,E;Te(p=>{E=p;let[b,C]=N(T);m=C;let P=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);g=t(P,b)}),i.push({rendered:g,dispose:E,setIndex:m})}d.push(w),y.add(w)}for(let[T,w]of a)y.has(T)||w.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function rr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,w=r[i];Te(S=>{T=S;let[g,m]=N(w);y=m,d=n(g,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObject as An}from"@fluixi/utils/object";import{isFunction as Xe}from"@fluixi/utils/functions";var fe=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if(Xe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(An(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if(Xe(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var be=class extends fe{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ue=class extends be{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof be?r=n:r=new Ue(n,t,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};import{isPromise as Pe}from"@fluixi/utils";var me=!1,Cn=Symbol.for("signal"),_n=Symbol.for("memo"),En=Symbol.for("resource");function De(e){return typeof e=="function"&&e[Cn]===!0}function kn(e){return typeof e=="function"&&e[_n]===!0}function Pn(e){return typeof e=="function"&&e[En]===!0}function Fn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Un(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Dn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Qe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Qe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var qn="__fluixi_signal_next_state__",Mn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[qn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Mn,onSuspend:null,onError:null};var Ze=0,en=1,de=2,xe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let n=c.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},Se=class extends xe{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(de);qe(this)}}peek(){return this._value}},ie=class extends xe{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=de;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===en&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===de)break}(this.state===de||!this._initialized)&&this.recompute(),this.state=Ze}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=t,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(de);qe(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Ze;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(en);qe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function qe(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var ge=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function nn(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function tn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rn(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function Ie(){return c.owner}function Oe(e,n){let t=c.owner;c.owner=e;try{return n()}finally{c.owner=t}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function we(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)we(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function pe(e){let n=tn(c.owner);c.owner&&(c.owner.owned??=[]).push(n);let t=c.owner;c.owner=n;try{return e(()=>we(n))}finally{c.owner=t}}function on(e){c.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function In(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ne)))}function Ne(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=c.queue;c.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{c.flushing=!1}}function sn(){c.batchDepth===0&&Ne()}var Me=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=tn(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ie(()=>{we(this.owner,!1),Oe(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new ge(()=>In(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&c.onSuspend){c.onSuspend(n,this.owner);return}if(c.onError&&c.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),we(this.owner))}};function un(e){let n=new Me(e);return()=>n.dispose()}function Nn(e){return!!e&&typeof e.then=="function"}on(()=>{});var an=Symbol.for("signal"),Ln=Symbol.for("memo"),Bn=Symbol.for("signal-node");function I(e,n){let t=new Se(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),sn(),u});return Object.defineProperty(o,an,{value:!0,enumerable:!0}),Object.defineProperty(o,Bn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function x(e,n,t){let o=n,r=Ie(),s=new ie(()=>Oe(r,()=>{try{return o=e(o)}catch(a){if(Nn(a))return rn(a),o;throw a}}),{equals:t?.equals}),u=(()=>s.get());return Object.defineProperty(u,an,{value:!0,enumerable:!0}),Object.defineProperty(u,Ln,{value:!0,enumerable:!0}),u}function Te(e,n){let t=n;return un(()=>{t=e(t)})}function Re(e){return nn(e)}function Vn(e,n=(t,o)=>t===o){let t=new Map;return Te(()=>{let o=e();for(let[r,s]of t){let[u,a]=s,i=n(r,o);u()!==i&&a(i)}}),o=>{let r=t.get(o);if(!r){let[s,u]=I(!1);r=[s,u],t.set(o,r);let a=e();u(n(o,a))}return r[0]()}}function jn(e,n){let[t,o]=I(e(),n);return Te(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function Gn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ee(()=>{t!==void 0&&clearTimeout(t)}),o}function Ae(e){if(typeof e=="function"&&!e.length){let n=e();return De(n)?n:Ae(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=Ae(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function cn(e){let n=x(e);return x(()=>Ae(n()))}var Le=null;function Kn(e){Le=e}function Ce(e){Le&&Le(e)}var Be=null;function $n(e){Be=e}function ln(e){return Be?Be(e):void 0}var Ve=null;function Wn(e){Ve=e}function fn(){return Ve?Ve():void 0}var je=null;function zn(e){je=e}function dn(e,n){je&&je(e,n)}var ze=Symbol.for("signal"),Hn=Symbol.for("memo"),Yn=Symbol.for("resource"),pn=Symbol("fluixi-proxy"),vn=Symbol.for("signal-node"),G=0,he=1,$=2,K=3,f=null,v=null,l=null,_e=null,Ee=0,Jn=!1,Ge=!1,ue=0,Xn=1e6,P=new WeakMap,M=null;var Qn=null,Zn=new Map,et=0,Ke={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Lt(e){f=e,Ke.owner=e,Ke.context=e}function Bt(){return Ke}function nt(){return`node_${++et}_${Date.now()}`}function tt(e){!1}function yn(e,n,t){let o={id:nt(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return tt(o),o}function bn(e,n){return e===n}function He(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var $e=null,We=null;function mn(){if(!$e){let[e,n]=q(!1);$e=e,We=n}}function xn(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let n=v,t=l;v=null,l=[],e.accessor(),v=n;let o=l;if(l=t,o.length>0){let r=l;Fe(o),l=r}}}function Tn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function q(e,n){let t=e;typeof t=="object"&&t&&pn in t&&delete t[pn];let o=yn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[u,a];P.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=P.get(r);d&&!d.has(i)&&d.add(i)}return t}function a(i){let d=typeof i=="function"?i(t):i,y=o.equals||bn;if(n?.equals===!1||!y(t,d)){t=d,o.value=d,o.version++,o.updated=Date.now();let g=P.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===K&&p===v)){if(b&&!p.pure){C===G&&(p.state=he,Jn&&(l!==null&&l.indexOf(p)===-1?l.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=$,C===G||C===he?w.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let k=P.get(p.accessor);k&&Tn(Array.from(k),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;Tn(S,E);for(let p of w)xn(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ae(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,ze,{value:!0,enumerable:!0}),Object.defineProperty(u,vn,{value:o,enumerable:!1}),r}function ae(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),Ye(o,n),()=>J(o)}function Ye(e,n){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,o=f;if(v=e,f=e,Ee++,Ee>Xn)throw Ee=0,v=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=K;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=t,f=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===G)&&(e.state===$||e.state===he||e.state===K)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)J(e.owned[n]);e.owned=null}e.renderEffect?wn(e):Ye(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=P.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)J(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function jt(e,n,t){let o=yn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;P.has(a)||P.set(a,new Set);let i=P.get(a);i&&i.add(v)}if(r.state!==G){if(r.sources){for(let d of r.sources){let y=P.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=K;try{let d=r.fn(r.value),y=o.equals||bn;if(t?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=P.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let k=b.state;if(k!==K){if(C&&!b.pure){k===G&&(b.state=he,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=$,k===G||k===he?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=P.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)xn(b)}}r.state===K&&(r.state=G)}catch(d){if(Pe(d)){let y=O&&N(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}He(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,P.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ae(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,ze,{value:!0,enumerable:!0}),Object.defineProperty(s,Hn,{value:!0,enumerable:!0}),Object.defineProperty(s,vn,{value:o,enumerable:!1}),s}function Fe(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);l=[];let o=0;for(;o<n.length;){let r=n[o++],s=P.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?n.indexOf(a)===-1&&n.push(a):(a.computed||!a.pure)&&t.indexOf(a)===-1&&t.push(a)}l=null;for(let r of t)(r.computed||!r.pure)&&ve(r)}function F(e){if(l&&ue>0)return e();if(l&&ue===0){let n=l,t=[];l=t,ue++;let o;try{o=e()}finally{ue--,l=n}let r=l;return Fe(t),l=r,o}ue++,l=[],_e=[];try{return e()}finally{ue--,Sn()}}function Sn(){if(!Ge){Ge=!0,Ee=0;try{for(;l&&l.length>0;){let e=l;l=null,Fe(e)}if(l=null,_e){let e=_e;_e=null;for(let n=0;n<e.length;n++)ve(e[n])}}finally{Ge=!1}}}function Gt(e){let n={owned:null,cleanups:null,contexts:null,owner:f},t=v;v=null;let o=f;f=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)J(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{f=o,v=t}}function W(e){let n=v;v=null;try{return e()}finally{v=n}}function ke(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function Kt(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:u}=t,a=fn(),i=a!==void 0?ln(a):void 0,d=i!==void 0,[y,T]=q(i!==void 0?i.value:t.initialValue,{equals:!1}),[g,S]=q(void 0,{equals:!1}),[w,m]=q(i!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),k=Symbol(),_=k,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${u}):`,L)}},ce=ae(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=k,F(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=z;if(z=!1,_!==k&&A===_&&!L)return;if(_=A,d){d=!1;return}let B=!1;ke(()=>B=!0);let le=W(w),re=W(y),Q=le==="ready"||le==="refreshing";F(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let V=r(A,{value:re,refetching:Q});if(Pe(V)){p(V),Ce(V),V.then(h=>{B||(a!==void 0&&dn(a,h),F(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{B||F(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{B||F(()=>{S(h),m("errored"),p(void 0)})});let ye=O&&N(O);ye&&(ye.increment(),V.finally(()=>ye.decrement()))}else{if(B)return;F(()=>{T(()=>V),m("ready"),p(void 0)})}}catch(V){if(B)return;F(()=>{S(V),m("errored"),p(void 0)})}});ke(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let L=E();if(L)throw L}return y()});return Object.defineProperty(Y,Yn,{value:!0,enumerable:!0}),Object.defineProperty(Y,ze,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function $t(){return f}function Wt(e,n){let t=f,o=v;f=e,v=null;try{return n()}finally{f=t,v=o}}function gn(e){let n=Symbol("context"),t=rt(n);return{id:n,Provider:t,defaultValue:e}}function rt(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return st(()=>{o=W(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),cn(()=>n.children)})}),o}}function N(e){let n=f;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function zt(){return new Promise(e=>{queueMicrotask(()=>{Sn(),e()})})}function ot(e){if(M&&M.running)return e(),M.done;mn();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};M=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,We(!1),r.length&&F(()=>{for(let s of r)s.state=$,ve(s)}),n()}),t):(M=null,n(),t)}function Ht(){return mn(),[$e,ot]}function Yt(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):W(()=>n(u,s))}}function st(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),wn(o),()=>J(o)}function wn(e){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,t=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=K;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=n,f=t;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;Fe(r),l=s}}}function Jt(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):Ye(o,n)}var O;function On(){return O||(O=gn())}var hn;function Xt(){return hn||(hn=gn())}function Qt(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=$,ve(t)}function Zt(e){let n=O&&N(O);n&&n.inFallback()?ae(()=>{n.inFallback()||e()}):e()}function er(e){Qn=e}function nr(e){let n=O&&N(O);return n&&(n.increment(),e.finally(()=>n.decrement())),e}function sr(e,n,t){return x(()=>n(e()),void 0,t)}function ir(e,n,t){return x(()=>e().filter(n),void 0,t)}function ur(e,n,t,o){return x(()=>e().reduce(n,t),void 0,o)}function ar(e,n,t){return x(()=>e().find(n),void 0,t)}function cr(e,n,t){return x(()=>e().some(n),void 0,t)}function lr(e,n,t){return x(()=>e().every(n),void 0,t)}function fr(e,n,t){return x(()=>[...e()].sort(n),void 0,t)}function dr(e,n){return x(()=>[...new Set(e())],void 0,n)}function pr(e,n,t){return x(()=>{let o=e.map(r=>r());return n(o)},void 0,t)}function Tr(...e){return new Z(n=>{let t=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{n.next(t())}):typeof r!="function"?r.subscribe(()=>{n.next(t())}):Te(()=>{n.next(t())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function hr(e,n,t){return x(()=>e()||n(),void 0,t)}function vr(e,n,t,o){return x(()=>t(e(),n()),void 0,o)}function yr(e,n,t){return x(()=>n(e()),void 0,{equals:t,internal:!0})}function br(e,n,t){return x(()=>{let o=e(),r={};for(let s of n)r[s]=o[s];return r},void 0,t)}function mr(e,n,t){return x(()=>{let r={...e()};for(let s of n)delete r[s];return r},void 0,t)}function xr(e,n,t,o){return x(()=>e()?n():t(),void 0,o)}function Sr(e,n,t){return x(()=>e()?n():void 0,void 0,t)}function gr(e,n,t){let[o,r]=I(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),n)}),o}function wr(e,n,t){let[o,r]=I(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=n?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},n-(i-s)))}),o}function Or(e){let n=e;for(;typeof n=="function";)n=n();return n}var te=new Map,ne=new Map,it=0,ut=Symbol.for("signal"),at=Symbol.for("resource");function Cr(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:u=1/0,name:a=`_auto_${it++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=q(void 0,{equals:!1}),[w,m]=q("unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),[k,_]=q(!1),[z,H]=q(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function L(h,U,D,j){if(ne.has(U)){ne.get(U).then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)}),D||C(ne.get(U));return}let oe=Promise.resolve(r(h)).then(R=>(te.set(U,{value:R,timestamp:Date.now()}),ne.delete(U),R),R=>{throw ne.delete(U),R});if(ne.set(U,oe),!D){Ce(oe),C(oe);let R=re&&N(re);R&&(R.increment(),oe.finally(()=>R.decrement()))}oe.then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)})}function B(h,U){F(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){F(()=>{p(h),m("errored"),C(void 0)})}let re;ae(()=>{re===void 0&&(re=On());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,F(()=>{m("unresolved"),C(void 0),p(void 0)});return}let U=Y,D=A;Y=!1,A=!1;let j=y(h);D&&te.delete(j);let oe=X===ce||h!==X;X=h;let R=!1;ke(()=>{R=!0});let se=te.get(j);if(se&&T(se)&&!U&&!D){(W(w)!=="ready"||W(g)!==se.value)&&F(()=>{S(()=>se.value),m("ready"),_(!1),p(void 0)});return}if(se&&i&&!D){F(()=>{S(()=>se.value),m("ready"),_(!0),p(void 0),C(void 0)}),L(h,j,!0,()=>R);return}let Je=W(w),Rn=Je==="ready"||Je==="refreshing";F(()=>{m(Rn?"refreshing":"pending"),p(void 0),_(!1)}),L(h,j,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let D=b();if(D)throw D}return g()});return Object.defineProperty(Q,at,{value:!0,enumerable:!0}),Object.defineProperty(Q,ut,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:k}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=W(o);h!=null&&h!==!1&&te.delete(y(h)),A=!0,H(U=>U+1)}}]}function _r(e){let n=`${e}:`;for(let t of te.keys())t.startsWith(n)&&te.delete(t)}function Er(){te.clear(),ne.clear()}function Fr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;pe(m=>{S=m;let[E,p]=I(i);g=p,T=n(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function Ur(e,n,t,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Re(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=n(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;pe(p=>{E=p;let[b,C]=I(T);m=C;let k=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=t(k,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function Dr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];pe(S=>{T=S;let[w,m]=I(g);y=m,d=n(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}export{Hn as $MEMO,pn as $PROXY,Yn as $RESOURCE,ze as $SIGNAL,me as __DEV__,F as batch,Er as clearAllCachedResources,_r as clearCachedResourceNamespace,pr as combineSignal,Tr as combineSignals,Cr as createCachedResource,Jt as createComputed,gn as createContext,Gn as createDebounce,jn as createDeferred,ae as createEffect,jt as createMemo,rt as createProvider,st as createRenderEffect,Kt as createResource,Gt as createRoot,Vn as createSelector,q as createSignal,gr as debounceSignal,dr as distinctSignal,lr as everySignal,ir as filterSignal,ar as findSignal,zt as flush,$t as getOwner,ln as getServerData,Bt as getSharedConfig,On as getSuspenseContext,Xt as getSuspenseListContext,Sr as guardSignal,Dr as indexArray,Fn as isComponent,kn as isMemo,Dn as isProvider,Pn as isResource,De as isSignal,Un as isSuspense,Ur as keyArray,Qe as makeArrayFlat,Fr as mapArray,sr as mapSignal,hr as mergeSignal,fn as nextResourceId,mr as omitSignal,Yt as on,ke as onCleanup,Zt as onResolve,br as pickSignal,cn as readChildren,Or as readSignal,ur as reduceSignal,dn as reportResourceData,Qt as resumeEffects,Wt as runWithOwner,yr as selectSignal,Lt as setOwner,zn as setResourceDataSink,Wn as setResourceIdSource,Kn as setResourceTracker,er as setScheduler,$n as setServerDataGetter,Ke as sharedConfig,cr as someSignal,fr as sortSignal,ot as startTransition,wr as throttleSignal,nr as trackPromise,Ce as trackResourcePromise,W as untrack,N as useContext,Ht as useTransition,xr as whenSignal,vr as zipSignal};
|
|
1
|
+
import{isObject as An}from"@fluixi/utils/object";import{isFunction as Xe}from"@fluixi/utils/functions";var fe=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if(Xe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(An(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if(Xe(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var be=class extends fe{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ue=class extends be{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof be?r=n:r=new Ue(n,t,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};import{isPromise as Pe}from"@fluixi/utils";var me=!1,Cn=Symbol.for("signal"),_n=Symbol.for("memo"),En=Symbol.for("resource");function De(e){return typeof e=="function"&&e[Cn]===!0}function kn(e){return typeof e=="function"&&e[_n]===!0}function Pn(e){return typeof e=="function"&&e[En]===!0}function Fn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Un(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Dn(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Qe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Qe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var qn="__fluixi_signal_next_state__",Mn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},c=globalThis[qn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Mn,onSuspend:null,onError:null};var Ze=0,en=1,de=2,xe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(c.untracked)return;let n=c.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},Se=class extends xe{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(de);qe(this)}}peek(){return this._value}},ie=class extends xe{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=de;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(c.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===en&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===de)break}(this.state===de||!this._initialized)&&this.recompute(),this.state=Ze}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=c.consumer,o=c.untracked;c.consumer=this,c.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{c.consumer=t,c.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(de);qe(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===Ze;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(en);qe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function qe(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var we=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function nn(e){if(c.untracked)return e();c.untracked=!0;try{return e()}finally{c.untracked=!1}}function tn(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rn(e){return c.onSuspend?(c.onSuspend(e,c.owner),!0):!1}function Ie(){return c.owner}function Oe(e,n){let t=c.owner;c.owner=e;try{return n()}finally{c.owner=t}}function ee(e){if(c.owner){if(c.owner.disposed){e();return}(c.owner.cleanups??=[]).push(e)}}function ge(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)ge(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function pe(e){let n=tn(c.owner);c.owner&&(c.owner.owned??=[]).push(n);let t=c.owner;c.owner=n;try{return e(()=>ge(n))}finally{c.owner=t}}function on(e){c.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function In(e){e.queued||(e.queued=!0,c.queue.push(e),!c.scheduled&&c.batchDepth===0&&(c.scheduled=!0,c.hostSchedule(Ne)))}function Ne(){if(c.scheduled=!1,c.flushing)return;c.flushing=!0;let e=0;try{for(;c.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=c.queue;c.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{c.flushing=!1}}function sn(){c.batchDepth===0&&Ne()}var Me=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=tn(c.owner),c.owner&&(c.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ie(()=>{ge(this.owner,!1),Oe(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new we(()=>In(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&c.onSuspend){c.onSuspend(n,this.owner);return}if(c.onError&&c.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),ge(this.owner))}};function un(e){let n=new Me(e);return()=>n.dispose()}function Nn(e){return!!e&&typeof e.then=="function"}on(()=>{});var an=Symbol.for("signal"),Ln=Symbol.for("memo"),Bn=Symbol.for("signal-node");function I(e,n){let t=new Se(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let u=typeof s=="function"?s(t.peek()):s;return t.set(u),sn(),u});return Object.defineProperty(o,an,{value:!0,enumerable:!0}),Object.defineProperty(o,Bn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,r]}function x(e,n,t){let o=n,r=Ie(),s=new ie(()=>Oe(r,()=>{try{return o=e(o)}catch(a){if(Nn(a))return rn(a),o;throw a}}),{equals:t?.equals}),u=(()=>s.get());return Object.defineProperty(u,an,{value:!0,enumerable:!0}),Object.defineProperty(u,Ln,{value:!0,enumerable:!0}),u}function Te(e,n){let t=n;return un(()=>{t=e(t)})}function Re(e){return nn(e)}function Vn(e,n=(t,o)=>t===o){let t=new Map;return Te(()=>{let o=e();for(let[r,s]of t){let[u,a]=s,i=n(r,o);u()!==i&&a(i)}}),o=>{let r=t.get(o);if(!r){let[s,u]=I(!1);r=[s,u],t.set(o,r);let a=e();u(n(o,a))}return r[0]()}}function jn(e,n){let[t,o]=I(e(),n);return Te(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function Gn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return ee(()=>{t!==void 0&&clearTimeout(t)}),o}function Ae(e){if(typeof e=="function"&&!e.length){let n=e();return De(n)?n:Ae(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=Ae(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function cn(e){let n=x(e);return x(()=>Ae(n()))}var Le=null;function Kn(e){Le=e}function Ce(e){Le&&Le(e)}var Be=null;function $n(e){Be=e}function ln(e){return Be?Be(e):void 0}var Ve=null;function Wn(e){Ve=e}function fn(){return Ve?Ve():void 0}var je=null;function zn(e){je=e}function dn(e,n){je&&je(e,n)}var ze=Symbol.for("signal"),Hn=Symbol.for("memo"),Yn=Symbol.for("resource"),pn=Symbol("fluixi-proxy"),vn=Symbol.for("signal-node"),G=0,he=1,$=2,K=3,f=null,v=null,l=null,_e=null,Ee=0,Jn=!1,Ge=!1,ue=0,Xn=1e6,P=new WeakMap,M=null;var Qn=null,Zn=new Map,et=0,Ke={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Lt(e){f=e,Ke.owner=e,Ke.context=e}function Bt(){return Ke}function nt(){return`node_${++et}_${Date.now()}`}function tt(e){!1}function yn(e,n,t){let o={id:nt(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return tt(o),o}function bn(e,n){return e===n}function He(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var $e=null,We=null;function mn(){if(!$e){let[e,n]=q(!1);$e=e,We=n}}function xn(e){if(l)l.indexOf(e)===-1&&l.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let n=v,t=l;v=null,l=[],e.accessor(),v=n;let o=l;if(l=t,o.length>0){let r=l;Fe(o),l=r}}}function Tn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function q(e,n){let t=e;typeof t=="object"&&t&&pn in t&&delete t[pn];let o=yn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[u,a];P.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=P.get(r);d&&!d.has(i)&&d.add(i)}return t}function a(i){let d=typeof i=="function"?i(t):i,y=o.equals||bn;if(n?.equals===!1||!y(t,d)){t=d,o.value=d,o.version++,o.updated=Date.now();let w=P.get(r);if(w&&w.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===K&&p===v)){if(b&&!p.pure){C===G&&(p.state=he,Jn&&(l!==null&&l.indexOf(p)===-1?l.push(p):g.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=$,C===G||C===he?g.push(p):!p.pure&&l!==null&&l.indexOf(p)===-1&&l.push(p),p.pure&&p.accessor)){let k=P.get(p.accessor);k&&Tn(Array.from(k),_=>E(_,!0))}}};var T=E;let S=Array.from(w),g=[],m=new Set;Tn(S,E);for(let p of g)xn(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ae(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,ze,{value:!0,enumerable:!0}),Object.defineProperty(u,vn,{value:o,enumerable:!1}),r}function ae(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),Ye(o,n),()=>J(o)}function Ye(e,n){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,o=f;if(v=e,f=e,Ee++,Ee>Xn)throw Ee=0,v=t,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=K;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=t,f=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===G)&&(e.state===$||e.state===he||e.state===K)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)J(e.owned[n]);e.owned=null}e.renderEffect?gn(e):Ye(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=P.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)J(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function jt(e,n,t){let o=yn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;P.has(a)||P.set(a,new Set);let i=P.get(a);i&&i.add(v)}if(r.state!==G){if(r.sources){for(let d of r.sources){let y=P.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=K;try{let d=r.fn(r.value),y=o.equals||bn;if(t?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let w=s,S=P.get(w);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let k=b.state;if(k!==K){if(C&&!b.pure){k===G&&(b.state=he,l!==null&&l.indexOf(b)===-1?l.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=$,k===G||k===he?m.push(b):!b.pure&&l!==null&&l.indexOf(b)===-1&&l.push(b),b.pure&&b.accessor)){let _=P.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let g=Array.from(S),m=[],E=new Set;for(let b=0;b<g.length;b++)p(g[b]);for(let b of m)xn(b)}}r.state===K&&(r.state=G)}catch(d){if(Pe(d)){let y=O&&N(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}He(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,P.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ae(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,ze,{value:!0,enumerable:!0}),Object.defineProperty(s,Hn,{value:!0,enumerable:!0}),Object.defineProperty(s,vn,{value:o,enumerable:!1}),s}function Fe(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);l=[];let o=0;for(;o<n.length;){let r=n[o++],s=P.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=l.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?n.indexOf(a)===-1&&n.push(a):(a.computed||!a.pure)&&t.indexOf(a)===-1&&t.push(a)}l=null;for(let r of t)(r.computed||!r.pure)&&ve(r)}function F(e){if(l&&ue>0)return e();if(l&&ue===0){let n=l,t=[];l=t,ue++;let o;try{o=e()}finally{ue--,l=n}let r=l;return Fe(t),l=r,o}ue++,l=[],_e=[];try{return e()}finally{ue--,Sn()}}function Sn(){if(!Ge){Ge=!0,Ee=0;try{for(;l&&l.length>0;){let e=l;l=null,Fe(e)}if(l=null,_e){let e=_e;_e=null;for(let n=0;n<e.length;n++)ve(e[n])}}finally{Ge=!1}}}function Gt(e){let n={owned:null,cleanups:null,contexts:null,owner:f},t=v;v=null;let o=f;f=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)J(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{f=o,v=t}}function W(e){let n=v;v=null;try{return e()}finally{v=n}}function ke(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function Kt(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:u}=t,a=fn(),i=a!==void 0?ln(a):void 0,d=i!==void 0,[y,T]=q(i!==void 0?i.value:t.initialValue,{equals:!1}),[w,S]=q(void 0,{equals:!1}),[g,m]=q(i!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),k=Symbol(),_=k,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${u}):`,L)}},ce=ae(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=k,F(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=z;if(z=!1,_!==k&&A===_&&!L)return;if(_=A,d){d=!1;return}let B=!1;ke(()=>B=!0);let le=W(g),re=W(y),Q=le==="ready"||le==="refreshing";F(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let V=r(A,{value:re,refetching:Q});if(Pe(V)){p(V),Ce(V),V.then(h=>{B||(a!==void 0&&dn(a,h),F(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{B||F(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{B||F(()=>{S(h),m("errored"),p(void 0)})});let ye=O&&N(O);ye&&(ye.increment(),V.finally(()=>ye.decrement()))}else{if(B)return;F(()=>{T(()=>V),m("ready"),p(void 0)})}}catch(V){if(B)return;F(()=>{S(V),m("errored"),p(void 0)})}});ke(ce);let X=()=>{let A=g();return A==="pending"||A==="refreshing"},Y=(()=>{let A=w();if(A)throw A;if(X()){let L=E();if(L)throw L}return y()});return Object.defineProperty(Y,Yn,{value:!0,enumerable:!0}),Object.defineProperty(Y,ze,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:g},loading:{get:()=>X()},error:{get:w},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function $t(){return f}function Wt(e,n){let t=f,o=v;f=e,v=null;try{return n()}finally{f=t,v=o}}function wn(e){let n=Symbol("context"),t=rt(n);return{id:n,Provider:t,defaultValue:e}}function rt(e){return n=>{let t=f;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return st(()=>{o=W(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),cn(()=>n.children)})}),o}}function N(e){let n=f;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function zt(){return new Promise(e=>{queueMicrotask(()=>{Sn(),e()})})}function ot(e){if(M&&M.running)return e(),M.done;mn();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};M=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,We(!1),r.length&&F(()=>{for(let s of r)s.state=$,ve(s)}),n()}),t):(M=null,n(),t)}function Ht(){return mn(),[$e,ot]}function Yt(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):W(()=>n(u,s))}}function st(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),gn(o),()=>J(o)}function gn(e){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,t=f,o=l;v=e,f=e,l===null&&(l=[]),e.state=K;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=n,f=t;let r=l;if(l=o,r!==o&&r&&r.length>0){let s=l;Fe(r),l=s}}}function Jt(e,n,t){let o={fn:e,state:$,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(l||(l=[]),l.indexOf(o)===-1&&l.push(o)):l?l.indexOf(o)===-1&&l.push(o):Ye(o,n)}var O;function On(){return O||(O=wn())}var hn;function Xt(){return hn||(hn=wn())}function Qt(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=$,ve(t)}function Zt(e){let n=O&&N(O);n&&n.inFallback()?ae(()=>{n.inFallback()||e()}):e()}function er(e){Qn=e}function nr(e){let n=O&&N(O);return n&&(n.increment(),e.finally(()=>n.decrement())),e}function sr(e,n,t){return x(()=>n(e()),void 0,t)}function ir(e,n,t){return x(()=>e().filter(n),void 0,t)}function ur(e,n,t,o){return x(()=>e().reduce(n,t),void 0,o)}function ar(e,n,t){return x(()=>e().find(n),void 0,t)}function cr(e,n,t){return x(()=>e().some(n),void 0,t)}function lr(e,n,t){return x(()=>e().every(n),void 0,t)}function fr(e,n,t){return x(()=>[...e()].sort(n),void 0,t)}function dr(e,n){return x(()=>[...new Set(e())],void 0,n)}function pr(e,n,t){return x(()=>{let o=e.map(r=>r());return n(o)},void 0,t)}function Tr(...e){return new Z(n=>{let t=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{n.next(t())}):typeof r!="function"?r.subscribe(()=>{n.next(t())}):Te(()=>{n.next(t())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function hr(e,n,t){return x(()=>e()||n(),void 0,t)}function vr(e,n,t,o){return x(()=>t(e(),n()),void 0,o)}function yr(e,n,t){return x(()=>n(e()),void 0,{equals:t,internal:!0})}function br(e,n,t){return x(()=>{let o=e(),r={};for(let s of n)r[s]=o[s];return r},void 0,t)}function mr(e,n,t){return x(()=>{let r={...e()};for(let s of n)delete r[s];return r},void 0,t)}function xr(e,n,t,o){return x(()=>e()?n():t(),void 0,o)}function Sr(e,n,t){return x(()=>e()?n():void 0,void 0,t)}function wr(e,n,t){let[o,r]=I(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),n)}),o}function gr(e,n,t){let[o,r]=I(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=n?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},n-(i-s)))}),o}function Or(e){let n=e;for(;typeof n=="function";)n=n();return n}var te=new Map,ne=new Map,it=0,ut=Symbol.for("signal"),at=Symbol.for("resource");function Cr(e,n,t={}){let o,r,s;typeof n=="function"?(o=e,r=n,s=t):(o=()=>!0,r=e,s=n??t);let{ttl:u=1/0,name:a=`_auto_${it++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[w,S]=q(void 0,{equals:!1}),[g,m]=q("unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),[k,_]=q(!1),[z,H]=q(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function L(h,U,D,j){if(ne.has(U)){ne.get(U).then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)}),D||C(ne.get(U));return}let oe=Promise.resolve(r(h)).then(R=>(te.set(U,{value:R,timestamp:Date.now()}),ne.delete(U),R),R=>{throw ne.delete(U),R});if(ne.set(U,oe),!D){Ce(oe),C(oe);let R=re&&N(re);R&&(R.increment(),oe.finally(()=>R.decrement()))}oe.then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)})}function B(h,U){F(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){F(()=>{p(h),m("errored"),C(void 0)})}let re;ae(()=>{re===void 0&&(re=On());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,F(()=>{m("unresolved"),C(void 0),p(void 0)});return}let U=Y,D=A;Y=!1,A=!1;let j=y(h);D&&te.delete(j);let oe=X===ce||h!==X;X=h;let R=!1;ke(()=>{R=!0});let se=te.get(j);if(se&&T(se)&&!U&&!D){(W(g)!=="ready"||W(w)!==se.value)&&F(()=>{S(()=>se.value),m("ready"),_(!1),p(void 0)});return}if(se&&i&&!D){F(()=>{S(()=>se.value),m("ready"),_(!0),p(void 0),C(void 0)}),L(h,j,!0,()=>R);return}let Je=W(g),Rn=Je==="ready"||Je==="refreshing";F(()=>{m(Rn?"refreshing":"pending"),p(void 0),_(!1)}),L(h,j,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(g()==="pending"){let D=b();if(D)throw D}return w()});return Object.defineProperty(Q,at,{value:!0,enumerable:!0}),Object.defineProperty(Q,ut,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:g},loading:{get:()=>{let h=g();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:w},stale:{get:k}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=W(o);h!=null&&h!==!1&&te.delete(y(h)),A=!0,H(U=>U+1)}}]}function _r(e){let n=`${e}:`;for(let t of te.keys())t.startsWith(n)&&te.delete(t)}function Er(){te.clear(),ne.clear()}function Fr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,w,S;pe(m=>{S=m;let[E,p]=I(i);w=p,T=n(d,E)});let g={item:d,rendered:T,dispose:S,setIndex:w};u.push(g),a.add(g)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function Ur(e,n,t,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Re(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let w=n(u[T]),S=a.get(w);if(S&&!y.has(w))S.setIndex(T),i.push(S);else{let g,m,E;pe(p=>{E=p;let[b,C]=I(T);m=C;let k=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);g=t(k,b)}),i.push({rendered:g,dispose:E,setIndex:m})}d.push(w),y.add(w)}for(let[T,w]of a)y.has(T)||w.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function Dr(e,n,t){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],t?.fallback?t.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,w=r[i];pe(S=>{T=S;let[g,m]=I(w);y=m,d=n(g,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}export{Hn as $MEMO,pn as $PROXY,Yn as $RESOURCE,ze as $SIGNAL,me as __DEV__,F as batch,Er as clearAllCachedResources,_r as clearCachedResourceNamespace,pr as combineSignal,Tr as combineSignals,Cr as createCachedResource,Jt as createComputed,wn as createContext,Gn as createDebounce,jn as createDeferred,ae as createEffect,jt as createMemo,rt as createProvider,st as createRenderEffect,Kt as createResource,Gt as createRoot,Vn as createSelector,q as createSignal,wr as debounceSignal,dr as distinctSignal,lr as everySignal,ir as filterSignal,ar as findSignal,zt as flush,$t as getOwner,ln as getServerData,Bt as getSharedConfig,On as getSuspenseContext,Xt as getSuspenseListContext,Sr as guardSignal,Dr as indexArray,Fn as isComponent,kn as isMemo,Dn as isProvider,Pn as isResource,De as isSignal,Un as isSuspense,Ur as keyArray,Qe as makeArrayFlat,Fr as mapArray,sr as mapSignal,hr as mergeSignal,fn as nextResourceId,mr as omitSignal,Yt as on,ke as onCleanup,Zt as onResolve,br as pickSignal,cn as readChildren,Or as readSignal,ur as reduceSignal,dn as reportResourceData,Qt as resumeEffects,Wt as runWithOwner,yr as selectSignal,Lt as setOwner,zn as setResourceDataSink,Wn as setResourceIdSource,Kn as setResourceTracker,er as setScheduler,$n as setServerDataGetter,Ke as sharedConfig,cr as someSignal,fr as sortSignal,ot as startTransition,gr as throttleSignal,nr as trackPromise,Ce as trackResourcePromise,W as untrack,N as useContext,Ht as useTransition,xr as whenSignal,vr as zipSignal};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var se=Object.defineProperty;var on=Object.getOwnPropertyDescriptor;var sn=Object.getOwnPropertyNames;var un=Object.prototype.hasOwnProperty;var an=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},cn=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of sn(n))!un.call(e,o)&&o!==t&&se(e,o,{get:()=>n[o],enumerable:!(r=on(n,o))||r.enumerable});return e};var ln=e=>cn(se({},"__esModule",{value:!0}),e);var On={};an(On,{$PROXY:()=>_n,$SIGNAL:()=>Rn,Signal:()=>tn,SuspenseContext:()=>oe,__DEV__:()=>Q,batch:()=>b,createComputed:()=>Pe,createContext:()=>q,createDebounce:()=>Ke,createDebouncedResource:()=>Ye,createDebouncedSignal:()=>me,createDeferred:()=>He,createEffect:()=>E,createErrorBoundary:()=>en,createMemo:()=>S,createRenderEffect:()=>qe,createResource:()=>te,createRoot:()=>O,createSelector:()=>$e,createSignal:()=>d,createSuspenseBoundary:()=>Xe,flush:()=>Me,getOwner:()=>V,getServerData:()=>Z,indexArray:()=>wn,isComponent:()=>Ne,isMemo:()=>Fe,isOwnerDisposed:()=>ke,isProvider:()=>Le,isResource:()=>Be,isSignal:()=>X,isSuspense:()=>Ve,keyArray:()=>vn,makeArrayFlat:()=>de,mapArray:()=>mn,nextResourceId:()=>ee,on:()=>Ue,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>nn,provideSuspense:()=>Je,readChildren:()=>Qe,reportResourceData:()=>ne,runWithOwner:()=>M,setOwner:()=>ae,setResourceDataSink:()=>ze,setResourceIdSource:()=>We,setResourceTracker:()=>je,setServerDataGetter:()=>Ge,startTransition:()=>le,trackResourcePromise:()=>J,untrack:()=>w,useContext:()=>Re,useTransition:()=>Ie});module.exports=ln(On);var dn="__fluixi_signal_next_state__",fn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[dn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:fn,onSuspend:null,onError:null};var Se=0,xe=1,B=2,z=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let n=s.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},D=class extends z{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(B);ie(this)}}peek(){return this._value}},k=class extends z{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===xe&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=Se}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=s.consumer,r=s.untracked;s.consumer=this,s.untracked=!1;let o,u=!1,a;try{o=this._fn()}catch(i){u=!0,a=i,o=this._value}finally{s.consumer=t,s.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=u,this._error=a,this._value=o,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(B);ie(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===Se;if(this.state=t,r){if(this.observers)for(let o of[...this.observers])o.markDirty(xe);ie(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ie(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var P=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function N(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function be(){return s.consumer}function ge(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function ke(e){return!!e&&e.disposed===!0}function H(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function q(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let o=s.owner,u=H(o);(u.contexts=new Map).set(n,r.value),o&&(o.owned??=[]).push(u),s.owner=u;try{return r.children}finally{s.owner=o}}}}function Re(e){let n=s.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function K(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function I(e,n,t){let r=H(s.owner);(r.contexts=new Map).set(e.id,n),s.owner&&(s.owner.owned??=[]).push(r);let o=s.owner;s.owner=r;try{return t()}finally{s.owner=o}}function _e(e){s.onSuspend=e}function Oe(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function Ee(e){s.onError=e}function V(){return s.owner}function ae(e){let n=s.owner;return s.owner=e,n}function M(e,n){let t=s.owner;s.owner=e;try{return n()}finally{s.owner=t}}function v(e){if(s.owner){if(s.owner.disposed){e();return}(s.owner.cleanups??=[]).push(e)}}function $(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)$(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function O(e){let n=H(s.owner);s.owner&&(s.owner.owned??=[]).push(n);let t=s.owner;s.owner=n;try{return e(()=>$(n))}finally{s.owner=t}}function Ce(e){s.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function pn(e){e.queued||(e.queued=!0,s.queue.push(e),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(L)))}function L(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=s.queue;s.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{s.flushing=!1}}function Ae(){s.batchDepth===0&&L()}function ce(e){s.batchDepth++;try{return e()}finally{--s.batchDepth===0&&L()}}var ue=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=H(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{$(this.owner,!1),M(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new P(()=>pn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&s.onSuspend){s.onSuspend(n,this.owner);return}if(s.onError&&s.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),$(this.owner))}};function Y(e){let n=new ue(e);return()=>n.dispose()}function hn(e){return!!e&&typeof e.then=="function"}Ce(()=>{});var De=Symbol.for("signal"),yn=Symbol.for("memo"),Tn=Symbol.for("signal-node");function d(e,n){let t=new D(e,{equals:n?.equals}),r=(()=>t.get()),o=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),Ae(),a});return Object.defineProperty(r,De,{value:!0,enumerable:!0}),Object.defineProperty(r,Tn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,o]}function S(e,n,t){let r=n,o=V(),u=new k(()=>M(o,()=>{try{return r=e(r)}catch(c){if(hn(c))return Oe(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,De,{value:!0,enumerable:!0}),Object.defineProperty(a,yn,{value:!0,enumerable:!0}),a}function E(e,n){let t=n;return Y(()=>{t=e(t)})}function Pe(e,n){let t=n;Y(()=>{t=e(t)})}function qe(e,n){let t=n;return Y(()=>{t=e(t)})}function b(e){return ce(e)}function w(e){return N(e)}function le(e){return ce(e),Promise.resolve()}function Ie(){return[()=>!1,le]}function Me(){return L(),Promise.resolve()}function Ue(e,n,t){let r=Array.isArray(e),o,u=t?.defer??!1;return a=>{let c=r?e.map(f=>f()):e();if(u){u=!1,o=c;return}let i=N(()=>n(c,o,a));return o=c,i}}function mn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<o.length;i++){let f=o[i],h=u.get(f);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,p,y;O(T=>{y=T;let[C,U]=d(i);p=U,l=n(f,C)});let x={item:f,rendered:l,dispose:y,setIndex:p};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function vn(e,n,t,r){let o=[],u=[];return v(()=>{for(let a of u)a.dispose();o=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return o=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],u[l]);let i=[],f=[],h=new Set;for(let l=0;l<a.length;l++){let p=n(a[l]),y=c.get(p);if(y&&!h.has(p))y.setIndex(l),i.push(y);else{let x,T,C;O(U=>{C=U;let[R,F]=d(l);T=F;let j=S(A=>{let g=(e()||[])[R()];return g??A},a[l]);x=t(j,R)}),i.push({rendered:x,dispose:C,setIndex:T})}f.push(p),h.add(p)}for(let[l,p]of c)h.has(l)||p.dispose();return o=f,u=i,i.map(l=>l.rendered)})})}function wn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=o.length;for(let i=u;i<a;i++){let f,h,l,p=o[i];O(y=>{l=y;let[x,T]=d(p);h=T,f=n(x,i)}),r.push({rendered:f,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(o[i]);return r.map(i=>i.rendered)})})}var Q=!1,Sn=Symbol.for("signal"),xn=Symbol.for("memo"),bn=Symbol.for("resource");function X(e){return typeof e=="function"&&e[Sn]===!0}function Fe(e){return typeof e=="function"&&e[xn]===!0}function Be(e){return typeof e=="function"&&e[bn]===!0}function Ne(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ve(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Le(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function de(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?de(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var fe=null;function je(e){fe=e}function J(e){fe&&fe(e)}var pe=null;function Ge(e){pe=e}function Z(e){return pe?pe(e):void 0}var he=null;function We(e){he=e}function ee(){return he?he():void 0}var ye=null;function ze(e){ye=e}function ne(e,n){ye&&ye(e,n)}function $e(e,n=(t,r)=>t===r){let t=new Map;return E(()=>{let r=e();for(let[o,u]of t){let[a,c]=u,i=n(o,r);a()!==i&&c(i)}}),r=>{let o=t.get(r);if(!o){let[u,a]=d(!1);o=[u,a],t.set(r,o);let c=e();a(n(r,c))}return o[0]()}}function He(e,n){let[t,r]=d(e(),n);return E(()=>{let o=e();n?.timeoutMs?setTimeout(()=>r(()=>o),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>o)):Promise.resolve().then(()=>r(()=>o))}),t}function Ke(e,n){let t,r=(...o)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...o)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function gn(e){return!!e&&typeof e.then=="function"}var Te=Symbol();function te(e,n,t={}){let r,o;typeof n=="function"?(r=typeof e=="function"?e:()=>e,o=n):(r=()=>!0,o=e,n&&typeof n=="object"&&(t=n));let u=ee(),a=u!==void 0?Z(u):void 0,c=a!==void 0,[i,f]=d(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=d(void 0,{equals:!1}),[p,y]=d(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=d(void 0,{equals:!1}),[C,U]=d(void 0,{equals:!1}),R=Te,F=!1;E(()=>{let m=r();if(C(),m===!1||m===null||m===void 0){R=Te,b(()=>{y("unresolved"),T(void 0),l(void 0)});return}let g=F;if(F=!1,R!==Te&&m===R&&!g)return;if(R=m,c){c=!1;return}let G=!1;v(()=>G=!0);let ve=w(p),rn=w(i),we=ve==="ready"||ve==="refreshing";b(()=>{y(we?"refreshing":"pending"),l(void 0)});try{let _=o(m,{value:rn,refetching:we});gn(_)?(T(_),J(_),_.then(W=>{G||(u!==void 0&&ne(u,W),b(()=>{f(()=>W),y("ready"),T(void 0)}))},W=>{G||b(()=>{l(W),y("errored"),T(void 0)})})):b(()=>{f(()=>_),y("ready"),T(void 0)})}catch(_){if(G)return;b(()=>{l(_),y("errored"),T(void 0)})}});let j=()=>{let m=p();return m==="pending"||m==="refreshing"},A=(()=>{let m=h();if(m)throw m;if(j()){let g=x();if(g)throw g}return i()});return Object.defineProperties(A,{state:{get:p},loading:{get:j},error:{get:h},latest:{get:i}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{F=!0,U(void 0)}}]}function me(e,n=300){let[t,r]=d(e),[o,u]=d(e),[a,c]=d(!1),i,f=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{f();let p=w(t);return u(()=>p),c(!1),p},l=(p=>{let y=typeof p=="function"?p(w(t)):p;return r(()=>y),c(!0),f(),i=setTimeout(h,n),y});return v(f),[o,l,{immediate:t,pending:a,flush:h,cancel:()=>{f(),c(!1)}}]}function kn(e){return e!=null&&e!==""}function Ye(e,n,t={}){let{delay:r=300,initialValue:o,shouldFetch:u=kn}=t,[a,c,i]=me(e,r),f=()=>u(a())?a():!1,[h,{refetch:l}]=te(f,n,o===void 0?{}:{initialValue:o});return[h,{...i,query:a,setQuery:c,refetch:l}]}function re(e){if(typeof e=="function"&&!e.length){let n=e();return X(n)?n:re(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=re(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function Qe(e){let n=S(e);return S(()=>re(n()))}var oe=q();_e((e,n)=>{let t=K(n,oe);t&&(t.increment(),e.finally(()=>t.decrement()))});function Xe(){let[e,n]=d(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function Je(e,n){return I(oe,e,n)}var Ze=q();Ee((e,n)=>{let t=K(n,Ze);return t?(t.setError(e),!0):!1});function en(){let[e,n]=d(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function nn(e,n){return I(Ze,e,n)}var tn={State:D,Computed:k,subtle:{Watcher:P,untrack:N,currentComputed:be,hasSinks:ge}};var Rn=Symbol.for("signal"),_n=Symbol.for("fluixi-proxy");
|
|
1
|
+
"use strict";var se=Object.defineProperty;var un=Object.getOwnPropertyDescriptor;var an=Object.getOwnPropertyNames;var cn=Object.prototype.hasOwnProperty;var ln=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},dn=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of an(n))!cn.call(e,o)&&o!==t&&se(e,o,{get:()=>n[o],enumerable:!(r=un(n,o))||r.enumerable});return e};var fn=e=>dn(se({},"__esModule",{value:!0}),e);var Cn={};ln(Cn,{$PROXY:()=>En,$SIGNAL:()=>_n,Signal:()=>on,SuspenseContext:()=>oe,__DEV__:()=>Q,batch:()=>b,createChildOwner:()=>ke,createComputed:()=>Ie,createContext:()=>q,createDebounce:()=>Qe,createDebouncedResource:()=>Xe,createDebouncedSignal:()=>me,createDeferred:()=>Ye,createEffect:()=>E,createErrorBoundary:()=>tn,createMemo:()=>S,createRenderEffect:()=>Me,createResource:()=>te,createRoot:()=>_,createSelector:()=>Ke,createSignal:()=>d,createSuspenseBoundary:()=>Ze,disposeScope:()=>Re,flush:()=>Fe,getOwner:()=>j,getServerData:()=>Z,indexArray:()=>xn,isComponent:()=>Le,isMemo:()=>Ne,isOwnerDisposed:()=>Oe,isProvider:()=>Ge,isResource:()=>Ve,isSignal:()=>X,isSuspense:()=>je,keyArray:()=>Sn,makeArrayFlat:()=>de,mapArray:()=>wn,nextResourceId:()=>ee,on:()=>Be,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>rn,provideSuspense:()=>en,readChildren:()=>Je,reportResourceData:()=>ne,runWithOwner:()=>M,setOwner:()=>ae,setResourceDataSink:()=>He,setResourceIdSource:()=>$e,setResourceTracker:()=>We,setServerDataGetter:()=>ze,startTransition:()=>le,trackResourcePromise:()=>J,untrack:()=>w,useContext:()=>_e,useTransition:()=>Ue});module.exports=fn(Cn);var pn="__fluixi_signal_next_state__",hn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[pn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:hn,onSuspend:null,onError:null};var Se=0,xe=1,B=2,H=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let n=s.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},D=class extends H{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(B);ie(this)}}peek(){return this._value}},k=class extends H{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===xe&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=Se}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=s.consumer,r=s.untracked;s.consumer=this,s.untracked=!1;let o,u=!1,a;try{o=this._fn()}catch(i){u=!0,a=i,o=this._value}finally{s.consumer=t,s.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=u,this._error=a,this._value=o,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(B);ie(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===Se;if(this.state=t,r){if(this.observers)for(let o of[...this.observers])o.markDirty(xe);ie(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ie(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var P=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function N(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function be(){return s.consumer}function ge(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function ke(e){let n=L(e);return e&&(e.owned??=[]).push(n),n}function Re(e,n=!0){V(e,n)}function Oe(e){return!!e&&e.disposed===!0}function L(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function q(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let o=s.owner,u=L(o);(u.contexts=new Map).set(n,r.value),o&&(o.owned??=[]).push(u),s.owner=u;try{return r.children}finally{s.owner=o}}}}function _e(e){let n=s.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function K(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function I(e,n,t){let r=L(s.owner);(r.contexts=new Map).set(e.id,n),s.owner&&(s.owner.owned??=[]).push(r);let o=s.owner;s.owner=r;try{return t()}finally{s.owner=o}}function Ee(e){s.onSuspend=e}function Ce(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function Ae(e){s.onError=e}function j(){return s.owner}function ae(e){let n=s.owner;return s.owner=e,n}function M(e,n){let t=s.owner;s.owner=e;try{return n()}finally{s.owner=t}}function v(e){if(s.owner){if(s.owner.disposed){e();return}(s.owner.cleanups??=[]).push(e)}}function 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 _(e){let n=L(s.owner);s.owner&&(s.owner.owned??=[]).push(n);let t=s.owner;s.owner=n;try{return e(()=>V(n))}finally{s.owner=t}}function De(e){s.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function yn(e){e.queued||(e.queued=!0,s.queue.push(e),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(G)))}function G(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=s.queue;s.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{s.flushing=!1}}function Pe(){s.batchDepth===0&&G()}function ce(e){s.batchDepth++;try{return e()}finally{--s.batchDepth===0&&G()}}var ue=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=L(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{V(this.owner,!1),M(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new P(()=>yn(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&s.onSuspend){s.onSuspend(n,this.owner);return}if(s.onError&&s.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),V(this.owner))}};function Y(e){let n=new ue(e);return()=>n.dispose()}function Tn(e){return!!e&&typeof e.then=="function"}De(()=>{});var qe=Symbol.for("signal"),mn=Symbol.for("memo"),vn=Symbol.for("signal-node");function d(e,n){let t=new D(e,{equals:n?.equals}),r=(()=>t.get()),o=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),Pe(),a});return Object.defineProperty(r,qe,{value:!0,enumerable:!0}),Object.defineProperty(r,vn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,o]}function S(e,n,t){let r=n,o=j(),u=new k(()=>M(o,()=>{try{return r=e(r)}catch(c){if(Tn(c))return Ce(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,qe,{value:!0,enumerable:!0}),Object.defineProperty(a,mn,{value:!0,enumerable:!0}),a}function E(e,n){let t=n;return Y(()=>{t=e(t)})}function Ie(e,n){let t=n;Y(()=>{t=e(t)})}function Me(e,n){let t=n;return Y(()=>{t=e(t)})}function b(e){return ce(e)}function w(e){return N(e)}function le(e){return ce(e),Promise.resolve()}function Ue(){return[()=>!1,le]}function Fe(){return G(),Promise.resolve()}function Be(e,n,t){let r=Array.isArray(e),o,u=t?.defer??!1;return a=>{let c=r?e.map(f=>f()):e();if(u){u=!1,o=c;return}let i=N(()=>n(c,o,a));return o=c,i}}function wn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<o.length;i++){let f=o[i],h=u.get(f);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,p,y;_(T=>{y=T;let[C,U]=d(i);p=U,l=n(f,C)});let x={item:f,rendered:l,dispose:y,setIndex:p};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function Sn(e,n,t,r){let o=[],u=[];return v(()=>{for(let a of u)a.dispose();o=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return o=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],u[l]);let i=[],f=[],h=new Set;for(let l=0;l<a.length;l++){let p=n(a[l]),y=c.get(p);if(y&&!h.has(p))y.setIndex(l),i.push(y);else{let x,T,C;_(U=>{C=U;let[R,F]=d(l);T=F;let W=S(A=>{let g=(e()||[])[R()];return g??A},a[l]);x=t(W,R)}),i.push({rendered:x,dispose:C,setIndex:T})}f.push(p),h.add(p)}for(let[l,p]of c)h.has(l)||p.dispose();return o=f,u=i,i.map(l=>l.rendered)})})}function xn(e,n,t){let r=[];return v(()=>{for(let o of r)o.dispose();r=[]}),S(()=>{let o=e()||[];return w(()=>{if(o.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=o.length;for(let i=u;i<a;i++){let f,h,l,p=o[i];_(y=>{l=y;let[x,T]=d(p);h=T,f=n(x,i)}),r.push({rendered:f,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(o[i]);return r.map(i=>i.rendered)})})}var Q=!1,bn=Symbol.for("signal"),gn=Symbol.for("memo"),kn=Symbol.for("resource");function X(e){return typeof e=="function"&&e[bn]===!0}function Ne(e){return typeof e=="function"&&e[gn]===!0}function Ve(e){return typeof e=="function"&&e[kn]===!0}function Le(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function je(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ge(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function de(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?de(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var fe=null;function We(e){fe=e}function J(e){fe&&fe(e)}var pe=null;function ze(e){pe=e}function Z(e){return pe?pe(e):void 0}var he=null;function $e(e){he=e}function ee(){return he?he():void 0}var ye=null;function He(e){ye=e}function ne(e,n){ye&&ye(e,n)}function Ke(e,n=(t,r)=>t===r){let t=new Map;return E(()=>{let r=e();for(let[o,u]of t){let[a,c]=u,i=n(o,r);a()!==i&&c(i)}}),r=>{let o=t.get(r);if(!o){let[u,a]=d(!1);o=[u,a],t.set(r,o);let c=e();a(n(r,c))}return o[0]()}}function Ye(e,n){let[t,r]=d(e(),n);return E(()=>{let o=e();n?.timeoutMs?setTimeout(()=>r(()=>o),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>o)):Promise.resolve().then(()=>r(()=>o))}),t}function Qe(e,n){let t,r=(...o)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...o)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function Rn(e){return!!e&&typeof e.then=="function"}var Te=Symbol();function te(e,n,t={}){let r,o;typeof n=="function"?(r=typeof e=="function"?e:()=>e,o=n):(r=()=>!0,o=e,n&&typeof n=="object"&&(t=n));let u=ee(),a=u!==void 0?Z(u):void 0,c=a!==void 0,[i,f]=d(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=d(void 0,{equals:!1}),[p,y]=d(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=d(void 0,{equals:!1}),[C,U]=d(void 0,{equals:!1}),R=Te,F=!1;E(()=>{let m=r();if(C(),m===!1||m===null||m===void 0){R=Te,b(()=>{y("unresolved"),T(void 0),l(void 0)});return}let g=F;if(F=!1,R!==Te&&m===R&&!g)return;if(R=m,c){c=!1;return}let z=!1;v(()=>z=!0);let ve=w(p),sn=w(i),we=ve==="ready"||ve==="refreshing";b(()=>{y(we?"refreshing":"pending"),l(void 0)});try{let O=o(m,{value:sn,refetching:we});Rn(O)?(T(O),J(O),O.then($=>{z||(u!==void 0&&ne(u,$),b(()=>{f(()=>$),y("ready"),T(void 0)}))},$=>{z||b(()=>{l($),y("errored"),T(void 0)})})):b(()=>{f(()=>O),y("ready"),T(void 0)})}catch(O){if(z)return;b(()=>{l(O),y("errored"),T(void 0)})}});let W=()=>{let m=p();return m==="pending"||m==="refreshing"},A=(()=>{let m=h();if(m)throw m;if(W()){let g=x();if(g)throw g}return i()});return Object.defineProperties(A,{state:{get:p},loading:{get:W},error:{get:h},latest:{get:i}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{F=!0,U(void 0)}}]}function me(e,n=300){let[t,r]=d(e),[o,u]=d(e),[a,c]=d(!1),i,f=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{f();let p=w(t);return u(()=>p),c(!1),p},l=(p=>{let y=typeof p=="function"?p(w(t)):p;return r(()=>y),c(!0),f(),i=setTimeout(h,n),y});return v(f),[o,l,{immediate:t,pending:a,flush:h,cancel:()=>{f(),c(!1)}}]}function On(e){return e!=null&&e!==""}function Xe(e,n,t={}){let{delay:r=300,initialValue:o,shouldFetch:u=On}=t,[a,c,i]=me(e,r),f=()=>u(a())?a():!1,[h,{refetch:l}]=te(f,n,o===void 0?{}:{initialValue:o});return[h,{...i,query:a,setQuery:c,refetch:l}]}function re(e){if(typeof e=="function"&&!e.length){let n=e();return X(n)?n:re(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=re(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function Je(e){let n=S(e);return S(()=>re(n()))}var oe=q();Ee((e,n)=>{let t=K(n,oe);t&&(t.increment(),e.finally(()=>t.decrement()))});function Ze(){let[e,n]=d(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function en(e,n){return I(oe,e,n)}var nn=q();Ae((e,n)=>{let t=K(n,nn);return t?(t.setError(e),!0):!1});function tn(){let[e,n]=d(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function rn(e,n){return I(nn,e,n)}var on={State:D,Computed:k,subtle:{Watcher:P,untrack:N,currentComputed:be,hasSinks:ge}};var _n=Symbol.for("signal"),En=Symbol.for("fluixi-proxy");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var De="__fluixi_signal_next_state__",Pe=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[De]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Pe,onSuspend:null,onError:null};var ye=0,Te=1,M=2,W=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let n=o.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},C=class extends W{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(M);X(this)}}peek(){return this._value}},g=class extends W{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Te&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=ye}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,u=!1,a;try{s=this._fn()}catch(i){u=!0,a=i,s=this._value}finally{o.consumer=t,o.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=u,this._error=a,this._value=s,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(M);X(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===ye;if(this.state=t,r){if(this.observers)for(let s of[...this.observers])s.markDirty(Te);X(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function X(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var A=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function U(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function qe(e){return!!e&&e.disposed===!0}function $(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function F(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let s=o.owner,u=$(s);(u.contexts=new Map).set(n,r.value),s&&(s.owned??=[]).push(u),o.owner=u;try{return r.children}finally{o.owner=s}}}}function Ie(e){let n=o.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function H(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function B(e,n,t){let r=$(o.owner);(r.contexts=new Map).set(e.id,n),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return t()}finally{o.owner=s}}function we(e){o.onSuspend=e}function Se(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function xe(e){o.onError=e}function K(){return o.owner}function be(e){let n=o.owner;return o.owner=e,n}function N(e,n){let t=o.owner;o.owner=e;try{return n()}finally{o.owner=t}}function v(e){if(o.owner){if(o.owner.disposed){e();return}(o.owner.cleanups??=[]).push(e)}}function z(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)z(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function D(e){let n=$(o.owner);o.owner&&(o.owner.owned??=[]).push(n);let t=o.owner;o.owner=n;try{return e(()=>z(n))}finally{o.owner=t}}function ge(e){o.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Me(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(V)))}function V(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=o.queue;o.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{o.flushing=!1}}function ke(){o.batchDepth===0&&V()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&V()}}var J=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=$(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{z(this.owner,!1),N(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new A(()=>Me(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&o.onSuspend){o.onSuspend(n,this.owner);return}if(o.onError&&o.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function Y(e){let n=new J(e);return()=>n.dispose()}function Ue(e){return!!e&&typeof e.then=="function"}ge(()=>{});var Re=Symbol.for("signal"),Fe=Symbol.for("memo"),Be=Symbol.for("signal-node");function p(e,n){let t=new C(e,{equals:n?.equals}),r=(()=>t.get()),s=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),ke(),a});return Object.defineProperty(r,Re,{value:!0,enumerable:!0}),Object.defineProperty(r,Be,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,s]}function S(e,n,t){let r=n,s=K(),u=new g(()=>N(s,()=>{try{return r=e(r)}catch(c){if(Ue(c))return Se(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,Re,{value:!0,enumerable:!0}),Object.defineProperty(a,Fe,{value:!0,enumerable:!0}),a}function P(e,n){let t=n;return Y(()=>{t=e(t)})}function Ne(e,n){let t=n;Y(()=>{t=e(t)})}function Ve(e,n){let t=n;return Y(()=>{t=e(t)})}function k(e){return Z(e)}function w(e){return U(e)}function _e(e){return Z(e),Promise.resolve()}function Le(){return[()=>!1,_e]}function je(){return V(),Promise.resolve()}function Ge(e,n,t){let r=Array.isArray(e),s,u=t?.defer??!1;return a=>{let c=r?e.map(d=>d()):e();if(u){u=!1,s=c;return}let i=U(()=>n(c,s,a));return s=c,i}}function _n(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<s.length;i++){let d=s[i],h=u.get(d);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,f,y;D(T=>{y=T;let[O,q]=p(i);f=q,l=n(d,O)});let x={item:d,rendered:l,dispose:y,setIndex:f};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function On(e,n,t,r){let s=[],u=[];return v(()=>{for(let a of u)a.dispose();s=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return s=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<s.length;l++)c.set(s[l],u[l]);let i=[],d=[],h=new Set;for(let l=0;l<a.length;l++){let f=n(a[l]),y=c.get(f);if(y&&!h.has(f))y.setIndex(l),i.push(y);else{let x,T,O;D(q=>{O=q;let[R,I]=p(l);T=I;let L=S(E=>{let b=(e()||[])[R()];return b??E},a[l]);x=t(L,R)}),i.push({rendered:x,dispose:O,setIndex:T})}d.push(f),h.add(f)}for(let[l,f]of c)h.has(l)||f.dispose();return s=d,u=i,i.map(l=>l.rendered)})})}function En(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=s.length;for(let i=u;i<a;i++){let d,h,l,f=s[i];D(y=>{l=y;let[x,T]=p(f);h=T,d=n(x,i)}),r.push({rendered:d,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(s[i]);return r.map(i=>i.rendered)})})}var ee=!1,We=Symbol.for("signal"),ze=Symbol.for("memo"),$e=Symbol.for("resource");function ne(e){return typeof e=="function"&&e[We]===!0}function He(e){return typeof e=="function"&&e[ze]===!0}function Ke(e){return typeof e=="function"&&e[$e]===!0}function Ye(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Qe(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Xe(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Oe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Oe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var te=null;function Je(e){te=e}function ie(e){te&&te(e)}var re=null;function Ze(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function en(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function nn(e){se=e}function ce(e,n){se&&se(e,n)}function tn(e,n=(t,r)=>t===r){let t=new Map;return P(()=>{let r=e();for(let[s,u]of t){let[a,c]=u,i=n(s,r);a()!==i&&c(i)}}),r=>{let s=t.get(r);if(!s){let[u,a]=p(!1);s=[u,a],t.set(r,s);let c=e();a(n(r,c))}return s[0]()}}function rn(e,n){let[t,r]=p(e(),n);return P(()=>{let s=e();n?.timeoutMs?setTimeout(()=>r(()=>s),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),t}function on(e,n){let t,r=(...s)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...s)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function sn(e){return!!e&&typeof e.then=="function"}var le=Symbol();function de(e,n,t={}){let r,s;typeof n=="function"?(r=typeof e=="function"?e:()=>e,s=n):(r=()=>!0,s=e,n&&typeof n=="object"&&(t=n));let u=ae(),a=u!==void 0?ue(u):void 0,c=a!==void 0,[i,d]=p(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=p(void 0,{equals:!1}),[f,y]=p(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=p(void 0,{equals:!1}),[O,q]=p(void 0,{equals:!1}),R=le,I=!1;P(()=>{let m=r();if(O(),m===!1||m===null||m===void 0){R=le,k(()=>{y("unresolved"),T(void 0),l(void 0)});return}let b=I;if(I=!1,R!==le&&m===R&&!b)return;if(R=m,c){c=!1;return}let j=!1;v(()=>j=!0);let pe=w(f),Ae=w(i),he=pe==="ready"||pe==="refreshing";k(()=>{y(he?"refreshing":"pending"),l(void 0)});try{let _=s(m,{value:Ae,refetching:he});sn(_)?(T(_),ie(_),_.then(G=>{j||(u!==void 0&&ce(u,G),k(()=>{d(()=>G),y("ready"),T(void 0)}))},G=>{j||k(()=>{l(G),y("errored"),T(void 0)})})):k(()=>{d(()=>_),y("ready"),T(void 0)})}catch(_){if(j)return;k(()=>{l(_),y("errored"),T(void 0)})}});let L=()=>{let m=f();return m==="pending"||m==="refreshing"},E=(()=>{let m=h();if(m)throw m;if(L()){let b=x();if(b)throw b}return i()});return Object.defineProperties(E,{state:{get:f},loading:{get:L},error:{get:h},latest:{get:i}}),Object.defineProperty(E,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(E,Symbol.for("signal"),{value:!0,enumerable:!0}),[E,{mutate:d,refetch:()=>{I=!0,q(void 0)}}]}function Ee(e,n=300){let[t,r]=p(e),[s,u]=p(e),[a,c]=p(!1),i,d=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{d();let f=w(t);return u(()=>f),c(!1),f},l=(f=>{let y=typeof f=="function"?f(w(t)):f;return r(()=>y),c(!0),d(),i=setTimeout(h,n),y});return v(d),[s,l,{immediate:t,pending:a,flush:h,cancel:()=>{d(),c(!1)}}]}function un(e){return e!=null&&e!==""}function an(e,n,t={}){let{delay:r=300,initialValue:s,shouldFetch:u=un}=t,[a,c,i]=Ee(e,r),d=()=>u(a())?a():!1,[h,{refetch:l}]=de(d,n,s===void 0?{}:{initialValue:s});return[h,{...i,query:a,setQuery:c,refetch:l}]}function Q(e){if(typeof e=="function"&&!e.length){let n=e();return ne(n)?n:Q(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=Q(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function cn(e){let n=S(e);return S(()=>Q(n()))}var fe=F();we((e,n)=>{let t=H(n,fe);t&&(t.increment(),e.finally(()=>t.decrement()))});function ln(){let[e,n]=p(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function dn(e,n){return B(fe,e,n)}var Ce=F();xe((e,n)=>{let t=H(n,Ce);return t?(t.setError(e),!0):!1});function fn(){let[e,n]=p(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function pn(e,n){return B(Ce,e,n)}var hn={State:C,Computed:g,subtle:{Watcher:A,untrack:U,currentComputed:me,hasSinks:ve}};var Xn=Symbol.for("signal"),Jn=Symbol.for("fluixi-proxy");export{Jn as $PROXY,Xn as $SIGNAL,hn as Signal,fe as SuspenseContext,ee as __DEV__,k as batch,Ne as createComputed,F as createContext,on as createDebounce,an as createDebouncedResource,Ee as createDebouncedSignal,rn as createDeferred,P as createEffect,fn as createErrorBoundary,S as createMemo,Ve as createRenderEffect,de as createResource,D as createRoot,tn as createSelector,p as createSignal,ln as createSuspenseBoundary,je as flush,K as getOwner,ue as getServerData,En as indexArray,Ye as isComponent,He as isMemo,qe as isOwnerDisposed,Xe as isProvider,Ke as isResource,ne as isSignal,Qe as isSuspense,On as keyArray,Oe as makeArrayFlat,_n as mapArray,ae as nextResourceId,Ge as on,v as onCleanup,B as provide,pn as provideErrorBoundary,dn as provideSuspense,cn as readChildren,ce as reportResourceData,N as runWithOwner,be as setOwner,nn as setResourceDataSink,en as setResourceIdSource,Je as setResourceTracker,Ze as setServerDataGetter,_e as startTransition,ie as trackResourcePromise,w as untrack,Ie as useContext,Le as useTransition};
|
|
1
|
+
var De="__fluixi_signal_next_state__",Pe=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[De]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Pe,onSuspend:null,onError:null};var ye=0,Te=1,M=2,$=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let n=o.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},C=class extends ${constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(M);X(this)}}peek(){return this._value}},g=class extends ${constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Te&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=ye}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let t=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,u=!1,a;try{s=this._fn()}catch(i){u=!0,a=i,s=this._value}finally{o.consumer=t,o.untracked=r}let c=!this._initialized||this._threw!==u||(u?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=u,this._error=a,this._value=s,c){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(M);X(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===ye;if(this.state=t,r){if(this.observers)for(let s of[...this.observers])s.markDirty(Te);X(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function X(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var A=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function U(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function qe(e){let n=B(e);return e&&(e.owned??=[]).push(n),n}function Ie(e,n=!0){F(e,n)}function Me(e){return!!e&&e.disposed===!0}function B(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function N(e){let n=Symbol("context");return{id:n,defaultValue:e,Provider:r=>{let s=o.owner,u=B(s);(u.contexts=new Map).set(n,r.value),s&&(s.owned??=[]).push(u),o.owner=u;try{return r.children}finally{o.owner=s}}}}function Ue(e){let n=o.owner;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.parent}return e.defaultValue}function H(e,n){let t=e;for(;t;){if(t.contexts&&t.contexts.has(n.id))return t.contexts.get(n.id);t=t.parent}return n.defaultValue}function V(e,n,t){let r=B(o.owner);(r.contexts=new Map).set(e.id,n),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return t()}finally{o.owner=s}}function we(e){o.onSuspend=e}function Se(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function xe(e){o.onError=e}function K(){return o.owner}function be(e){let n=o.owner;return o.owner=e,n}function L(e,n){let t=o.owner;o.owner=e;try{return n()}finally{o.owner=t}}function v(e){if(o.owner){if(o.owner.disposed){e();return}(o.owner.cleanups??=[]).push(e)}}function F(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)F(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function D(e){let n=B(o.owner);o.owner&&(o.owner.owned??=[]).push(n);let t=o.owner;o.owner=n;try{return e(()=>F(n))}finally{o.owner=t}}function ge(e){o.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Fe(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(j)))}function j(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=o.queue;o.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{o.flushing=!1}}function ke(){o.batchDepth===0&&j()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&j()}}var J=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=B(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{F(this.owner,!1),L(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new A(()=>Fe(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&o.onSuspend){o.onSuspend(n,this.owner);return}if(o.onError&&o.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),F(this.owner))}};function Y(e){let n=new J(e);return()=>n.dispose()}function Be(e){return!!e&&typeof e.then=="function"}ge(()=>{});var Re=Symbol.for("signal"),Ne=Symbol.for("memo"),Ve=Symbol.for("signal-node");function p(e,n){let t=new C(e,{equals:n?.equals}),r=(()=>t.get()),s=(u=>{let a=typeof u=="function"?u(t.peek()):u;return t.set(a),ke(),a});return Object.defineProperty(r,Re,{value:!0,enumerable:!0}),Object.defineProperty(r,Ve,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,s]}function S(e,n,t){let r=n,s=K(),u=new g(()=>L(s,()=>{try{return r=e(r)}catch(c){if(Be(c))return Se(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,Re,{value:!0,enumerable:!0}),Object.defineProperty(a,Ne,{value:!0,enumerable:!0}),a}function P(e,n){let t=n;return Y(()=>{t=e(t)})}function Le(e,n){let t=n;Y(()=>{t=e(t)})}function je(e,n){let t=n;return Y(()=>{t=e(t)})}function k(e){return Z(e)}function w(e){return U(e)}function Oe(e){return Z(e),Promise.resolve()}function Ge(){return[()=>!1,Oe]}function We(){return j(),Promise.resolve()}function ze(e,n,t){let r=Array.isArray(e),s,u=t?.defer??!1;return a=>{let c=r?e.map(d=>d()):e();if(u){u=!1,s=c;return}let i=U(()=>n(c,s,a));return s=c,i}}function En(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=new Map;for(let i of r)u.has(i.item)||u.set(i.item,i);let a=[],c=new Set;for(let i=0;i<s.length;i++){let d=s[i],h=u.get(d);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,f,y;D(T=>{y=T;let[_,q]=p(i);f=q,l=n(d,_)});let x={item:d,rendered:l,dispose:y,setIndex:f};a.push(x),c.add(x)}}for(let i of r)c.has(i)||i.dispose();return r=a,a.map(i=>i.rendered)})})}function Cn(e,n,t,r){let s=[],u=[];return v(()=>{for(let a of u)a.dispose();s=[],u=[]}),S(()=>{let a=e()||[];return w(()=>{if(a.length===0){for(let l of u)l.dispose();return s=[],u=[],r?.fallback?r.fallback():[]}let c=new Map;for(let l=0;l<s.length;l++)c.set(s[l],u[l]);let i=[],d=[],h=new Set;for(let l=0;l<a.length;l++){let f=n(a[l]),y=c.get(f);if(y&&!h.has(f))y.setIndex(l),i.push(y);else{let x,T,_;D(q=>{_=q;let[R,I]=p(l);T=I;let G=S(E=>{let b=(e()||[])[R()];return b??E},a[l]);x=t(G,R)}),i.push({rendered:x,dispose:_,setIndex:T})}d.push(f),h.add(f)}for(let[l,f]of c)h.has(l)||f.dispose();return s=d,u=i,i.map(l=>l.rendered)})})}function An(e,n,t){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),S(()=>{let s=e()||[];return w(()=>{if(s.length===0){for(let i of r)i.dispose();return r=[],t?.fallback?t.fallback():[]}let u=r.length,a=s.length;for(let i=u;i<a;i++){let d,h,l,f=s[i];D(y=>{l=y;let[x,T]=p(f);h=T,d=n(x,i)}),r.push({rendered:d,setItem:h,dispose:l})}for(let i=a;i<u;i++)r[i].dispose();a<u&&(r=r.slice(0,a));let c=Math.min(u,a);for(let i=0;i<c;i++)r[i].setItem(s[i]);return r.map(i=>i.rendered)})})}var ee=!1,$e=Symbol.for("signal"),He=Symbol.for("memo"),Ke=Symbol.for("resource");function ne(e){return typeof e=="function"&&e[$e]===!0}function Ye(e){return typeof e=="function"&&e[He]===!0}function Qe(e){return typeof e=="function"&&e[Ke]===!0}function Xe(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Je(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ze(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function _e(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?_e(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var te=null;function en(e){te=e}function ie(e){te&&te(e)}var re=null;function nn(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function tn(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function rn(e){se=e}function ce(e,n){se&&se(e,n)}function on(e,n=(t,r)=>t===r){let t=new Map;return P(()=>{let r=e();for(let[s,u]of t){let[a,c]=u,i=n(s,r);a()!==i&&c(i)}}),r=>{let s=t.get(r);if(!s){let[u,a]=p(!1);s=[u,a],t.set(r,s);let c=e();a(n(r,c))}return s[0]()}}function sn(e,n){let[t,r]=p(e(),n);return P(()=>{let s=e();n?.timeoutMs?setTimeout(()=>r(()=>s),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),t}function un(e,n){let t,r=(...s)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...s)},n)};return v(()=>{t!==void 0&&clearTimeout(t)}),r}function an(e){return!!e&&typeof e.then=="function"}var le=Symbol();function de(e,n,t={}){let r,s;typeof n=="function"?(r=typeof e=="function"?e:()=>e,s=n):(r=()=>!0,s=e,n&&typeof n=="object"&&(t=n));let u=ae(),a=u!==void 0?ue(u):void 0,c=a!==void 0,[i,d]=p(a!==void 0?a.value:t.initialValue,{equals:!1}),[h,l]=p(void 0,{equals:!1}),[f,y]=p(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,T]=p(void 0,{equals:!1}),[_,q]=p(void 0,{equals:!1}),R=le,I=!1;P(()=>{let m=r();if(_(),m===!1||m===null||m===void 0){R=le,k(()=>{y("unresolved"),T(void 0),l(void 0)});return}let b=I;if(I=!1,R!==le&&m===R&&!b)return;if(R=m,c){c=!1;return}let W=!1;v(()=>W=!0);let pe=w(f),Ae=w(i),he=pe==="ready"||pe==="refreshing";k(()=>{y(he?"refreshing":"pending"),l(void 0)});try{let O=s(m,{value:Ae,refetching:he});an(O)?(T(O),ie(O),O.then(z=>{W||(u!==void 0&&ce(u,z),k(()=>{d(()=>z),y("ready"),T(void 0)}))},z=>{W||k(()=>{l(z),y("errored"),T(void 0)})})):k(()=>{d(()=>O),y("ready"),T(void 0)})}catch(O){if(W)return;k(()=>{l(O),y("errored"),T(void 0)})}});let G=()=>{let m=f();return m==="pending"||m==="refreshing"},E=(()=>{let m=h();if(m)throw m;if(G()){let b=x();if(b)throw b}return i()});return Object.defineProperties(E,{state:{get:f},loading:{get:G},error:{get:h},latest:{get:i}}),Object.defineProperty(E,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(E,Symbol.for("signal"),{value:!0,enumerable:!0}),[E,{mutate:d,refetch:()=>{I=!0,q(void 0)}}]}function Ee(e,n=300){let[t,r]=p(e),[s,u]=p(e),[a,c]=p(!1),i,d=()=>{i!==void 0&&(clearTimeout(i),i=void 0)},h=()=>{d();let f=w(t);return u(()=>f),c(!1),f},l=(f=>{let y=typeof f=="function"?f(w(t)):f;return r(()=>y),c(!0),d(),i=setTimeout(h,n),y});return v(d),[s,l,{immediate:t,pending:a,flush:h,cancel:()=>{d(),c(!1)}}]}function cn(e){return e!=null&&e!==""}function ln(e,n,t={}){let{delay:r=300,initialValue:s,shouldFetch:u=cn}=t,[a,c,i]=Ee(e,r),d=()=>u(a())?a():!1,[h,{refetch:l}]=de(d,n,s===void 0?{}:{initialValue:s});return[h,{...i,query:a,setQuery:c,refetch:l}]}function Q(e){if(typeof e=="function"&&!e.length){let n=e();return ne(n)?n:Q(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=Q(e[t]);Array.isArray(r)?n.push.apply(n,r):n.push(r)}return n}return e}function dn(e){let n=S(e);return S(()=>Q(n()))}var fe=N();we((e,n)=>{let t=H(n,fe);t&&(t.increment(),e.finally(()=>t.decrement()))});function fn(){let[e,n]=p(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function pn(e,n){return V(fe,e,n)}var Ce=N();xe((e,n)=>{let t=H(n,Ce);return t?(t.setError(e),!0):!1});function hn(){let[e,n]=p(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function yn(e,n){return V(Ce,e,n)}var Tn={State:C,Computed:g,subtle:{Watcher:A,untrack:U,currentComputed:me,hasSinks:ve}};var Zn=Symbol.for("signal"),et=Symbol.for("fluixi-proxy");export{et as $PROXY,Zn as $SIGNAL,Tn as Signal,fe as SuspenseContext,ee as __DEV__,k as batch,qe as createChildOwner,Le as createComputed,N as createContext,un as createDebounce,ln as createDebouncedResource,Ee as createDebouncedSignal,sn as createDeferred,P as createEffect,hn as createErrorBoundary,S as createMemo,je as createRenderEffect,de as createResource,D as createRoot,on as createSelector,p as createSignal,fn as createSuspenseBoundary,Ie as disposeScope,We as flush,K as getOwner,ue as getServerData,An as indexArray,Xe as isComponent,Ye as isMemo,Me as isOwnerDisposed,Ze as isProvider,Qe as isResource,ne as isSignal,Je as isSuspense,Cn as keyArray,_e as makeArrayFlat,En as mapArray,ae as nextResourceId,ze as on,v as onCleanup,V as provide,yn as provideErrorBoundary,pn as provideSuspense,dn as readChildren,ce as reportResourceData,L as runWithOwner,be as setOwner,rn as setResourceDataSink,tn as setResourceIdSource,en as setResourceTracker,nn as setServerDataGetter,Oe as startTransition,ie as trackResourcePromise,w as untrack,Ue as useContext,Ge as useTransition};
|
package/dist/lib/signal/list.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)E(e,t,{get:r[t],enumerable:!0})},J=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Y(r))!$.call(e,i)&&i!==t&&E(e,i,{get:()=>r[i],enumerable:!(o=H(r,i))||o.enumerable});return e};var Q=e=>J(E({},"__esModule",{value:!0}),e);var ue={};B(ue,{indexArray:()=>ie,keyArray:()=>se,mapArray:()=>oe});module.exports=Q(ue);var X="__fluixi_signal_next_state__",Z=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[X]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Z,onSuspend:null,onError:null};var R=0,U=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let r=s.consumer;r&&((this.observers??=new Set).add(r),(r.sources??=new Set).add(this))}},g=class extends S{constructor(r,t){super(),this._value=r,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(r){if(!this._equals(this._value,r)){if(this._value=r,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(T);C(this)}}peek(){return this._value}},k=class extends S{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===U&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=R}recompute(){if(this.sources){for(let n of this.sources)n.observers?.delete(this);this.sources.clear()}let t=s.consumer,o=s.untracked;s.consumer=this,s.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(n){a=!0,u=n,i=this._value}finally{s.consumer=t,s.untracked=o}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let n of[...this.observers])n.markDirty(T);C(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===R;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(U);C(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function C(e){if(e.watchers)for(let r of[...e.watchers])r._notify(e)}function L(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function ee(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function D(){return s.owner}function P(e,r){let t=s.owner;s.owner=e;try{return r()}finally{s.owner=t}}function y(e){if(s.owner){if(s.owner.disposed){e();return}(s.owner.cleanups??=[]).push(e)}}function N(e,r=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)N(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}r&&(e.disposed=!0)}}function m(e){let r=ee(s.owner);s.owner&&(s.owner.owned??=[]).push(r);let t=s.owner;s.owner=r;try{return e(()=>N(r))}finally{s.owner=t}}function W(e){s.hostSchedule=e??(r=>{Promise.resolve().then(r)})}function z(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let r=s.queue;s.queue=[];for(let t of r)t.queued=!1,t.disposed||t.run()}}finally{s.flushing=!1}}function G(){s.batchDepth===0&&z()}function te(e){return!!e&&typeof e.then=="function"}W(()=>{});var j=Symbol.for("signal"),ne=Symbol.for("memo"),re=Symbol.for("signal-node");function _(e,r){let t=new g(e,{equals:r?.equals}),o=(()=>t.get()),i=(a=>{let u=typeof a=="function"?a(t.peek()):a;return t.set(u),G(),u});return Object.defineProperty(o,j,{value:!0,enumerable:!0}),Object.defineProperty(o,re,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,i]}function
|
|
1
|
+
"use strict";var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var B=(e,r)=>{for(var t in r)E(e,t,{get:r[t],enumerable:!0})},J=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Y(r))!$.call(e,i)&&i!==t&&E(e,i,{get:()=>r[i],enumerable:!(o=H(r,i))||o.enumerable});return e};var Q=e=>J(E({},"__esModule",{value:!0}),e);var ue={};B(ue,{indexArray:()=>ie,keyArray:()=>se,mapArray:()=>oe});module.exports=Q(ue);var X="__fluixi_signal_next_state__",Z=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[X]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Z,onSuspend:null,onError:null};var R=0,U=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let r=s.consumer;r&&((this.observers??=new Set).add(r),(r.sources??=new Set).add(this))}},g=class extends S{constructor(r,t){super(),this._value=r,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(r){if(!this._equals(this._value,r)){if(this._value=r,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(T);C(this)}}peek(){return this._value}},k=class extends S{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===U&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=R}recompute(){if(this.sources){for(let n of this.sources)n.observers?.delete(this);this.sources.clear()}let t=s.consumer,o=s.untracked;s.consumer=this,s.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(n){a=!0,u=n,i=this._value}finally{s.consumer=t,s.untracked=o}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let n of[...this.observers])n.markDirty(T);C(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===R;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(U);C(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function C(e){if(e.watchers)for(let r of[...e.watchers])r._notify(e)}function L(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function ee(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function D(){return s.owner}function P(e,r){let t=s.owner;s.owner=e;try{return r()}finally{s.owner=t}}function y(e){if(s.owner){if(s.owner.disposed){e();return}(s.owner.cleanups??=[]).push(e)}}function N(e,r=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)N(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}r&&(e.disposed=!0)}}function m(e){let r=ee(s.owner);s.owner&&(s.owner.owned??=[]).push(r);let t=s.owner;s.owner=r;try{return e(()=>N(r))}finally{s.owner=t}}function W(e){s.hostSchedule=e??(r=>{Promise.resolve().then(r)})}function z(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let r=s.queue;s.queue=[];for(let t of r)t.queued=!1,t.disposed||t.run()}}finally{s.flushing=!1}}function G(){s.batchDepth===0&&z()}function te(e){return!!e&&typeof e.then=="function"}W(()=>{});var j=Symbol.for("signal"),ne=Symbol.for("memo"),re=Symbol.for("signal-node");function _(e,r){let t=new g(e,{equals:r?.equals}),o=(()=>t.get()),i=(a=>{let u=typeof a=="function"?a(t.peek()):a;return t.set(u),G(),u});return Object.defineProperty(o,j,{value:!0,enumerable:!0}),Object.defineProperty(o,re,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,i]}function x(e,r,t){let o=r,i=D(),a=new k(()=>P(i,()=>{try{return o=e(o)}catch(l){if(te(l))return M(l),o;throw l}}),{equals:t?.equals}),u=(()=>a.get());return Object.defineProperty(u,j,{value:!0,enumerable:!0}),Object.defineProperty(u,ne,{value:!0,enumerable:!0}),u}function O(e){return L(e)}function oe(e,r,t){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),x(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],t?.fallback?t.fallback():[]}let a=new Map;for(let n of o)a.has(n.item)||a.set(n.item,n);let u=[],l=new Set;for(let n=0;n<i.length;n++){let p=i[n],d=a.get(p);if(d&&!l.has(d))d.setIndex(n),u.push(d),l.add(d);else{let c,f,h;m(w=>{h=w;let[b,q]=_(n);f=q,c=r(p,b)});let v={item:p,rendered:c,dispose:h,setIndex:f};u.push(v),l.add(v)}}for(let n of o)l.has(n)||n.dispose();return o=u,u.map(n=>n.rendered)})})}function se(e,r,t,o){let i=[],a=[];return y(()=>{for(let u of a)u.dispose();i=[],a=[]}),x(()=>{let u=e()||[];return O(()=>{if(u.length===0){for(let c of a)c.dispose();return i=[],a=[],o?.fallback?o.fallback():[]}let l=new Map;for(let c=0;c<i.length;c++)l.set(i[c],a[c]);let n=[],p=[],d=new Set;for(let c=0;c<u.length;c++){let f=r(u[c]),h=l.get(f);if(h&&!d.has(f))h.setIndex(c),n.push(h);else{let v,w,b;m(q=>{b=q;let[I,K]=_(c);w=K;let V=x(F=>{let A=(e()||[])[I()];return A??F},u[c]);v=t(V,I)}),n.push({rendered:v,dispose:b,setIndex:w})}p.push(f),d.add(f)}for(let[c,f]of l)d.has(c)||f.dispose();return i=p,a=n,n.map(c=>c.rendered)})})}function ie(e,r,t){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),x(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],t?.fallback?t.fallback():[]}let a=o.length,u=i.length;for(let n=a;n<u;n++){let p,d,c,f=i[n];m(h=>{c=h;let[v,w]=_(f);d=w,p=r(v,n)}),o.push({rendered:p,setItem:d,dispose:c})}for(let n=u;n<a;n++)o[n].dispose();u<a&&(o=o.slice(0,u));let l=Math.min(a,u);for(let n=0;n<l;n++)o[n].setItem(i[n]);return o.map(n=>n.rendered)})})}
|
package/dist/lib/signal/list.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var F="__fluixi_signal_next_state__",H=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[F]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:H,onSuspend:null,onError:null};var I=0,R=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let s=r.consumer;s&&((this.observers??=new Set).add(s),(s.sources??=new Set).add(this))}},g=class extends S{constructor(s,t){super(),this._value=s,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(s){if(!this._equals(this._value,s)){if(this._value=s,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(T);E(this)}}peek(){return this._value}},k=class extends S{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.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===R&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=I}recompute(){if(this.sources){for(let n of this.sources)n.observers?.delete(this);this.sources.clear()}let t=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(n){a=!0,u=n,i=this._value}finally{r.consumer=t,r.untracked=o}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let n of[...this.observers])n.markDirty(T);E(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===I;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(R);E(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function E(e){if(e.watchers)for(let s of[...e.watchers])s._notify(e)}function U(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function Y(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function L(e){return r.onSuspend?(r.onSuspend(e,r.owner),!0):!1}function C(){return r.owner}function D(e,s){let t=r.owner;r.owner=e;try{return s()}finally{r.owner=t}}function y(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function M(e,s=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)M(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}s&&(e.disposed=!0)}}function m(e){let s=Y(r.owner);r.owner&&(r.owner.owned??=[]).push(s);let t=r.owner;r.owner=s;try{return e(()=>M(s))}finally{r.owner=t}}function N(e){r.hostSchedule=e??(s=>{Promise.resolve().then(s)})}function W(){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 s=r.queue;r.queue=[];for(let t of s)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function z(){r.batchDepth===0&&W()}function $(e){return!!e&&typeof e.then=="function"}N(()=>{});var G=Symbol.for("signal"),B=Symbol.for("memo"),J=Symbol.for("signal-node");function _(e,s){let t=new g(e,{equals:s?.equals}),o=(()=>t.get()),i=(a=>{let u=typeof a=="function"?a(t.peek()):a;return t.set(u),z(),u});return Object.defineProperty(o,G,{value:!0,enumerable:!0}),Object.defineProperty(o,J,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,i]}function
|
|
1
|
+
var F="__fluixi_signal_next_state__",H=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[F]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:H,onSuspend:null,onError:null};var I=0,R=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let s=r.consumer;s&&((this.observers??=new Set).add(s),(s.sources??=new Set).add(this))}},g=class extends S{constructor(s,t){super(),this._value=s,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(s){if(!this._equals(this._value,s)){if(this._value=s,this.version++,this.observers)for(let t of[...this.observers])t.markDirty(T);E(this)}}peek(){return this._value}},k=class extends S{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.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===R&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=I}recompute(){if(this.sources){for(let n of this.sources)n.observers?.delete(this);this.sources.clear()}let t=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(n){a=!0,u=n,i=this._value}finally{r.consumer=t,r.untracked=o}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let n of[...this.observers])n.markDirty(T);E(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===I;if(this.state=t,o){if(this.observers)for(let i of[...this.observers])i.markDirty(R);E(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function E(e){if(e.watchers)for(let s of[...e.watchers])s._notify(e)}function U(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function Y(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function L(e){return r.onSuspend?(r.onSuspend(e,r.owner),!0):!1}function C(){return r.owner}function D(e,s){let t=r.owner;r.owner=e;try{return s()}finally{r.owner=t}}function y(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function M(e,s=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)M(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}s&&(e.disposed=!0)}}function m(e){let s=Y(r.owner);r.owner&&(r.owner.owned??=[]).push(s);let t=r.owner;r.owner=s;try{return e(()=>M(s))}finally{r.owner=t}}function N(e){r.hostSchedule=e??(s=>{Promise.resolve().then(s)})}function W(){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 s=r.queue;r.queue=[];for(let t of s)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function z(){r.batchDepth===0&&W()}function $(e){return!!e&&typeof e.then=="function"}N(()=>{});var G=Symbol.for("signal"),B=Symbol.for("memo"),J=Symbol.for("signal-node");function _(e,s){let t=new g(e,{equals:s?.equals}),o=(()=>t.get()),i=(a=>{let u=typeof a=="function"?a(t.peek()):a;return t.set(u),z(),u});return Object.defineProperty(o,G,{value:!0,enumerable:!0}),Object.defineProperty(o,J,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,i]}function x(e,s,t){let o=s,i=C(),a=new k(()=>D(i,()=>{try{return o=e(o)}catch(l){if($(l))return L(l),o;throw l}}),{equals:t?.equals}),u=(()=>a.get());return Object.defineProperty(u,G,{value:!0,enumerable:!0}),Object.defineProperty(u,B,{value:!0,enumerable:!0}),u}function O(e){return U(e)}function de(e,s,t){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),x(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],t?.fallback?t.fallback():[]}let a=new Map;for(let n of o)a.has(n.item)||a.set(n.item,n);let u=[],l=new Set;for(let n=0;n<i.length;n++){let p=i[n],d=a.get(p);if(d&&!l.has(d))d.setIndex(n),u.push(d),l.add(d);else{let c,f,h;m(w=>{h=w;let[b,q]=_(n);f=q,c=s(p,b)});let v={item:p,rendered:c,dispose:h,setIndex:f};u.push(v),l.add(v)}}for(let n of o)l.has(n)||n.dispose();return o=u,u.map(n=>n.rendered)})})}function fe(e,s,t,o){let i=[],a=[];return y(()=>{for(let u of a)u.dispose();i=[],a=[]}),x(()=>{let u=e()||[];return O(()=>{if(u.length===0){for(let c of a)c.dispose();return i=[],a=[],o?.fallback?o.fallback():[]}let l=new Map;for(let c=0;c<i.length;c++)l.set(i[c],a[c]);let n=[],p=[],d=new Set;for(let c=0;c<u.length;c++){let f=s(u[c]),h=l.get(f);if(h&&!d.has(f))h.setIndex(c),n.push(h);else{let v,w,b;m(q=>{b=q;let[P,j]=_(c);w=j;let K=x(V=>{let A=(e()||[])[P()];return A??V},u[c]);v=t(K,P)}),n.push({rendered:v,dispose:b,setIndex:w})}p.push(f),d.add(f)}for(let[c,f]of l)d.has(c)||f.dispose();return i=p,a=n,n.map(c=>c.rendered)})})}function pe(e,s,t){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),x(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],t?.fallback?t.fallback():[]}let a=o.length,u=i.length;for(let n=a;n<u;n++){let p,d,c,f=i[n];m(h=>{c=h;let[v,w]=_(f);d=w,p=s(v,n)}),o.push({rendered:p,setItem:d,dispose:c})}for(let n=u;n<a;n++)o[n].dispose();u<a&&(o=o.slice(0,u));let l=Math.min(a,u);for(let n=0;n<l;n++)o[n].setItem(i[n]);return o.map(n=>n.rendered)})})}export{pe as indexArray,fe as keyArray,de as mapArray};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var m=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var V=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},j=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of K(e))!G.call(t,o)&&o!==r&&m(t,o,{get:()=>e[o],enumerable:!(n=I(e,o))||n.enumerable});return t};var H=t=>j(m({},"__esModule",{value:!0}),t);var ve={};V(ve,{combineSignal:()=>se,combineSignals:()=>ie,debounceSignal:()=>he,distinctSignal:()=>oe,everySignal:()=>te,filterSignal:()=>X,findSignal:()=>ee,guardSignal:()=>fe,mapSignal:()=>Q,mergeSignal:()=>ue,omitSignal:()=>le,pickSignal:()=>pe,readSignal:()=>Te,reduceSignal:()=>Z,selectSignal:()=>ce,someSignal:()=>re,sortSignal:()=>ne,throttleSignal:()=>be,whenSignal:()=>de,zipSignal:()=>ae});module.exports=H(ve);var L="__fluixi_signal_next_state__",N=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},s=globalThis[L]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:N,onSuspend:null,onError:null};var k=0,C=1,d=2,h=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let e=s.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},b=class extends h{constructor(e,r){super(),this._value=e,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(d);w(this)}}peek(){return this._value}},l=class extends h{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=d;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===C&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===d)break}(this.state===d||!this._initialized)&&this.recompute(),this.state=k}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let r=s.consumer,n=s.untracked;s.consumer=this,s.untracked=!1;let o,i=!1,u;try{o=this._fn()}catch(c){i=!0,u=c,o=this._value}finally{s.consumer=r,s.untracked=n}let p=!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,p){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(d);w(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===k;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(C);w(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function w(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}var T=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let r of e)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...e){for(let r of e)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let r=this._pending.size===0;this._pending.add(e),r&&this._notifyFn()}};function z(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function P(t){return s.onSuspend?(s.onSuspend(t,s.owner),!0):!1}function U(){return s.owner}function S(t,e){let r=s.owner;s.owner=t;try{return e()}finally{s.owner=r}}function O(t,e=!0){if(!t.disposed){if(t.owned){for(let r=t.owned.length-1;r>=0;r--)O(t.owned[r]);t.owned=null}if(t.cleanups){for(let r=t.cleanups.length-1;r>=0;r--)t.cleanups[r]();t.cleanups=null}e&&(t.disposed=!0)}}function D(t){s.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function W(t){t.queued||(t.queued=!0,s.queue.push(t),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(A)))}function A(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let t=0;try{for(;s.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=s.queue;s.queue=[];for(let r of e)r.queued=!1,r.disposed||r.run()}}finally{s.flushing=!1}}function E(){s.batchDepth===0&&A()}var x=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=z(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new l(()=>{O(this.owner,!1),S(this.owner,()=>{let r=e();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new T(()=>W(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&s.onSuspend){s.onSuspend(e,this.owner);return}if(s.onError&&s.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),O(this.owner))}};function R(t){let e=new x(t);return()=>e.dispose()}function Y(t){return!!t&&typeof t.then=="function"}D(()=>{});var q=Symbol.for("signal"),$=Symbol.for("memo"),J=Symbol.for("signal-node");function g(t,e){let r=new b(t,{equals:e?.equals}),n=(()=>r.get()),o=(i=>{let u=typeof i=="function"?i(r.peek()):i;return r.set(u),E(),u});return Object.defineProperty(n,q,{value:!0,enumerable:!0}),Object.defineProperty(n,J,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function a(t,e,r){let n=e,o=U(),i=new l(()=>S(o,()=>{try{return n=t(n)}catch(p){if(Y(p))return P(p),n;throw p}}),{equals:r?.equals}),u=(()=>i.get());return Object.defineProperty(u,q,{value:!0,enumerable:!0}),Object.defineProperty(u,$,{value:!0,enumerable:!0}),u}function M(t,e){let r=e;return R(()=>{r=t(r)})}var B=require("@fluixi/utils/object"),_=require("@fluixi/utils/functions"),f=class t{constructor(e){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;e&&(this._subscriptions=[e])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:e,_subscriptions:r}=this;if(e instanceof t)e.remove(this);else if(e!==null)for(let n of e)n.remove(this);if(r){for(let n of r)if((0,_.isFunction)(n)&&!(n instanceof t))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,B.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(e){if(!e||e===this)return this;if(e.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,_.isFunction)(e))try{e()}catch(o){console.error("Error in unsubscribe function:",o)}else if(e.unsubscribe)try{e.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(e),e instanceof t&&e._addParent(this),this}remove(e){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(e);n!==-1&&(r.splice(n,1),e._removeParent(this))}_addParent(e){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(e):this._parentOrParents=[r,e]:this._parentOrParents=e}_removeParent(e){let{_parentOrParents:r}=this;if(r===e)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(e);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var v=class extends f{constructor(r,n,o){super();this.isStopped=!1;let i;r?typeof r=="object"?i=r:i={next:r,error:n,complete:o}:i={},this.destination=i}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())}},F=class extends v{constructor(r,n,o,i){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=i||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)}};var y=class extends f{constructor(e){if(super(),e)this._subscribe=e;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(e,r,n){let o;e instanceof v?o=e:o=new F(e,r,n);let{_subscribe:i}=this;try{let u=i.call(this,o);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&o.add(u)}catch(u){o.error(u)}return o}pipe(...e){return e.length===0?this:e.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((e,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>e(n)})})}};function Q(t,e,r){return a(()=>e(t()),void 0,r)}function X(t,e,r){return a(()=>t().filter(e),void 0,r)}function Z(t,e,r,n){return a(()=>t().reduce(e,r),void 0,n)}function ee(t,e,r){return a(()=>t().find(e),void 0,r)}function re(t,e,r){return a(()=>t().some(e),void 0,r)}function te(t,e,r){return a(()=>t().every(e),void 0,r)}function ne(t,e,r){return a(()=>[...t()].sort(e),void 0,r)}function oe(t,e){return a(()=>[...new Set(t())],void 0,e)}function se(t,e,r){return a(()=>{let n=t.map(o=>o());return e(n)},void 0,r)}function ie(...t){return new y(e=>{let r=()=>t.map(o=>typeof o=="function"?o():o.get()),n=t.map(o=>typeof o=="function"&&o.subscribe?o.subscribe(()=>{e.next(r())}):typeof o!="function"?o.subscribe(()=>{e.next(r())}):M(()=>{e.next(r())}));return()=>{n.forEach(o=>{typeof o=="function"?o():o&&typeof o.unsubscribe=="function"&&o.unsubscribe()})}})}function ue(t,e,r){return a(()=>t()||e(),void 0,r)}function ae(t,e,r,n){return a(()=>r(t(),e()),void 0,n)}function ce(t,e,r){return a(()=>e(t()),void 0,{equals:r,internal:!0})}function pe(t,e,r){return a(()=>{let n=t(),o={};for(let i of e)o[i]=n[i];return o},void 0,r)}function le(t,e,r){return a(()=>{let o={...t()};for(let i of e)delete o[i];return o},void 0,r)}function de(t,e,r,n){return a(()=>t()?e():r(),void 0,n)}function fe(t,e,r){return a(()=>t()?e():void 0,void 0,r)}function he(t,e,r){let[n,o]=g(t()),i;return a(()=>{let u=t();clearTimeout(i),i=setTimeout(()=>o(()=>u),e)}),n}function be(t,e,r){let[n,o]=g(t()),i=0,u;return a(()=>{let p=t(),c=Date.now();c-i>=e?(i=c,o(()=>p)):(clearTimeout(u),u=setTimeout(()=>{i=Date.now(),o(()=>p)},e-(c-i)))}),n}function Te(t){let e=t;for(;typeof e=="function";)e=e();return e}
|
|
1
|
+
"use strict";var w=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var V=(t,e)=>{for(var r in e)w(t,r,{get:e[r],enumerable:!0})},j=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of K(e))!G.call(t,o)&&o!==r&&w(t,o,{get:()=>e[o],enumerable:!(n=I(e,o))||n.enumerable});return t};var H=t=>j(w({},"__esModule",{value:!0}),t);var ve={};V(ve,{combineSignal:()=>se,combineSignals:()=>ie,debounceSignal:()=>he,distinctSignal:()=>oe,everySignal:()=>te,filterSignal:()=>X,findSignal:()=>ee,guardSignal:()=>fe,mapSignal:()=>Q,mergeSignal:()=>ue,omitSignal:()=>le,pickSignal:()=>pe,readSignal:()=>Te,reduceSignal:()=>Z,selectSignal:()=>ae,someSignal:()=>re,sortSignal:()=>ne,throttleSignal:()=>be,whenSignal:()=>de,zipSignal:()=>ce});module.exports=H(ve);var L="__fluixi_signal_next_state__",N=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},s=globalThis[L]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:N,onSuspend:null,onError:null};var k=0,C=1,d=2,h=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let e=s.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},b=class extends h{constructor(e,r){super(),this._value=e,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(e){if(!this._equals(this._value,e)){if(this._value=e,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(d);O(this)}}peek(){return this._value}},l=class extends h{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=d;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===C&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===d)break}(this.state===d||!this._initialized)&&this.recompute(),this.state=k}recompute(){if(this.sources){for(let a of this.sources)a.observers?.delete(this);this.sources.clear()}let r=s.consumer,n=s.untracked;s.consumer=this,s.untracked=!1;let o,i=!1,u;try{o=this._fn()}catch(a){i=!0,u=a,o=this._value}finally{s.consumer=r,s.untracked=n}let p=!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,p){if(this.version++,this.observers)for(let a of[...this.observers])a.markDirty(d);O(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===k;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(C);O(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function O(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}var T=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let r of e)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...e){for(let r of e)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let r=this._pending.size===0;this._pending.add(e),r&&this._notifyFn()}};function z(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function P(t){return s.onSuspend?(s.onSuspend(t,s.owner),!0):!1}function U(){return s.owner}function S(t,e){let r=s.owner;s.owner=t;try{return e()}finally{s.owner=r}}function m(t,e=!0){if(!t.disposed){if(t.owned){for(let r=t.owned.length-1;r>=0;r--)m(t.owned[r]);t.owned=null}if(t.cleanups){for(let r=t.cleanups.length-1;r>=0;r--)t.cleanups[r]();t.cleanups=null}e&&(t.disposed=!0)}}function D(t){s.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function W(t){t.queued||(t.queued=!0,s.queue.push(t),!s.scheduled&&s.batchDepth===0&&(s.scheduled=!0,s.hostSchedule(A)))}function A(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let t=0;try{for(;s.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=s.queue;s.queue=[];for(let r of e)r.queued=!1,r.disposed||r.run()}}finally{s.flushing=!1}}function E(){s.batchDepth===0&&A()}var x=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=z(s.owner),s.owner&&(s.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new l(()=>{m(this.owner,!1),S(this.owner,()=>{let r=e();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new T(()=>W(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(e){if(e&&typeof e.then=="function"&&s.onSuspend){s.onSuspend(e,this.owner);return}if(s.onError&&s.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),m(this.owner))}};function R(t){let e=new x(t);return()=>e.dispose()}function Y(t){return!!t&&typeof t.then=="function"}D(()=>{});var q=Symbol.for("signal"),$=Symbol.for("memo"),J=Symbol.for("signal-node");function g(t,e){let r=new b(t,{equals:e?.equals}),n=(()=>r.get()),o=(i=>{let u=typeof i=="function"?i(r.peek()):i;return r.set(u),E(),u});return Object.defineProperty(n,q,{value:!0,enumerable:!0}),Object.defineProperty(n,J,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function c(t,e,r){let n=e,o=U(),i=new l(()=>S(o,()=>{try{return n=t(n)}catch(p){if(Y(p))return P(p),n;throw p}}),{equals:r?.equals}),u=(()=>i.get());return Object.defineProperty(u,q,{value:!0,enumerable:!0}),Object.defineProperty(u,$,{value:!0,enumerable:!0}),u}function M(t,e){let r=e;return R(()=>{r=t(r)})}var B=require("@fluixi/utils/object"),_=require("@fluixi/utils/functions"),f=class t{constructor(e){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;e&&(this._subscriptions=[e])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:e,_subscriptions:r}=this;if(e instanceof t)e.remove(this);else if(e!==null)for(let n of e)n.remove(this);if(r){for(let n of r)if((0,_.isFunction)(n)&&!(n instanceof t))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,B.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(e){if(!e||e===this)return this;if(e.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,_.isFunction)(e))try{e()}catch(o){console.error("Error in unsubscribe function:",o)}else if(e.unsubscribe)try{e.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(e),e instanceof t&&e._addParent(this),this}remove(e){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(e);n!==-1&&(r.splice(n,1),e._removeParent(this))}_addParent(e){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(e):this._parentOrParents=[r,e]:this._parentOrParents=e}_removeParent(e){let{_parentOrParents:r}=this;if(r===e)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(e);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var v=class extends f{constructor(r,n,o){super();this.isStopped=!1;let i;r?typeof r=="object"?i=r:i={next:r,error:n,complete:o}:i={},this.destination=i}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())}},F=class extends v{constructor(r,n,o,i){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=i||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)}};var y=class extends f{constructor(e){if(super(),e)this._subscribe=e;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(e,r,n){let o;e instanceof v?o=e:o=new F(e,r,n);let{_subscribe:i}=this;try{let u=i.call(this,o);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&o.add(u)}catch(u){o.error(u)}return o}pipe(...e){return e.length===0?this:e.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((e,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>e(n)})})}};function Q(t,e,r){return c(()=>e(t()),void 0,r)}function X(t,e,r){return c(()=>t().filter(e),void 0,r)}function Z(t,e,r,n){return c(()=>t().reduce(e,r),void 0,n)}function ee(t,e,r){return c(()=>t().find(e),void 0,r)}function re(t,e,r){return c(()=>t().some(e),void 0,r)}function te(t,e,r){return c(()=>t().every(e),void 0,r)}function ne(t,e,r){return c(()=>[...t()].sort(e),void 0,r)}function oe(t,e){return c(()=>[...new Set(t())],void 0,e)}function se(t,e,r){return c(()=>{let n=t.map(o=>o());return e(n)},void 0,r)}function ie(...t){return new y(e=>{let r=()=>t.map(o=>typeof o=="function"?o():o.get()),n=t.map(o=>typeof o=="function"&&o.subscribe?o.subscribe(()=>{e.next(r())}):typeof o!="function"?o.subscribe(()=>{e.next(r())}):M(()=>{e.next(r())}));return()=>{n.forEach(o=>{typeof o=="function"?o():o&&typeof o.unsubscribe=="function"&&o.unsubscribe()})}})}function ue(t,e,r){return c(()=>t()||e(),void 0,r)}function ce(t,e,r,n){return c(()=>r(t(),e()),void 0,n)}function ae(t,e,r){return c(()=>e(t()),void 0,{equals:r,internal:!0})}function pe(t,e,r){return c(()=>{let n=t(),o={};for(let i of e)o[i]=n[i];return o},void 0,r)}function le(t,e,r){return c(()=>{let o={...t()};for(let i of e)delete o[i];return o},void 0,r)}function de(t,e,r,n){return c(()=>t()?e():r(),void 0,n)}function fe(t,e,r){return c(()=>t()?e():void 0,void 0,r)}function he(t,e,r){let[n,o]=g(t()),i;return c(()=>{let u=t();clearTimeout(i),i=setTimeout(()=>o(()=>u),e)}),n}function be(t,e,r){let[n,o]=g(t()),i=0,u;return c(()=>{let p=t(),a=Date.now();a-i>=e?(i=a,o(()=>p)):(clearTimeout(u),u=setTimeout(()=>{i=Date.now(),o(()=>p)},e-(a-i)))}),n}function Te(t){let e=t;for(;typeof e=="function";)e=e();return e}
|