@fluixi/reactive 1.0.0-alpha.75 → 1.0.0-alpha.77

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.
Files changed (39) hide show
  1. package/README.md +153 -220
  2. package/dist/cdn/reactive.cjs +1 -1
  3. package/dist/cdn/reactive.global.js +1 -1
  4. package/dist/cdn/reactive.mjs +1 -1
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.mjs +1 -1
  7. package/dist/lib/index.cjs +1 -1
  8. package/dist/lib/index.mjs +1 -1
  9. package/dist/lib/signal/api.cjs +1 -0
  10. package/dist/lib/signal/api.d.ts +13 -0
  11. package/dist/lib/signal/api.d.ts.map +1 -0
  12. package/dist/lib/signal/api.js +31 -0
  13. package/dist/lib/signal/api.mjs +1 -0
  14. package/dist/lib/signal/index.cjs +1 -1
  15. package/dist/lib/signal/index.d.ts +3 -0
  16. package/dist/lib/signal/index.d.ts.map +1 -1
  17. package/dist/lib/signal/index.js +3 -0
  18. package/dist/lib/signal/index.mjs +1 -1
  19. package/dist/lib/signal/resource-api.cjs +1 -0
  20. package/dist/lib/signal/resource-api.d.ts +27 -0
  21. package/dist/lib/signal/resource-api.d.ts.map +1 -0
  22. package/dist/lib/signal/resource-api.js +27 -0
  23. package/dist/lib/signal/resource-api.mjs +1 -0
  24. package/dist/lib/store/api.cjs +1 -0
  25. package/dist/lib/store/api.d.ts +7 -0
  26. package/dist/lib/store/api.d.ts.map +1 -0
  27. package/dist/lib/store/api.js +30 -0
  28. package/dist/lib/store/api.mjs +1 -0
  29. package/dist/lib/store/index.cjs +1 -1
  30. package/dist/lib/store/index.d.ts +2 -0
  31. package/dist/lib/store/index.d.ts.map +1 -1
  32. package/dist/lib/store/index.js +2 -0
  33. package/dist/lib/store/index.mjs +1 -1
  34. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  35. package/dist/version.generated.cjs +1 -1
  36. package/dist/version.generated.d.ts +1 -1
  37. package/dist/version.generated.js +1 -1
  38. package/dist/version.generated.mjs +1 -1
  39. package/package.json +2 -8
@@ -1 +1 @@
1
- "use strict";var xe=Object.defineProperty;var or=Object.getOwnPropertyDescriptor;var sr=Object.getOwnPropertyNames;var ir=Object.prototype.hasOwnProperty;var ar=(e,t)=>{for(var r in t)xe(e,r,{get:t[r],enumerable:!0})},ur=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of sr(t))!ir.call(e,o)&&o!==r&&xe(e,o,{get:()=>t[o],enumerable:!(n=or(t,o))||n.enumerable});return e};var cr=e=>ur(xe({},"__esModule",{value:!0}),e);var Pr={};ar(Pr,{$NAME:()=>Mt,$NODE:()=>D,$PROXY:()=>Rr,$RAW:()=>Z,$SELF:()=>Te,$SIGNAL:()=>Ar,$STORE:()=>$t,$TRACK:()=>me,Observable:()=>j,SafeSubscriber:()=>ne,Signal:()=>Ct,Store:()=>R,StoreAPI:()=>er,Subject:()=>Oe,Subscriber:()=>U,Subscription:()=>I,SuspenseContext:()=>he,VERSION:()=>Ke,__DEV__:()=>ae,batch:()=>O,createChildOwner:()=>Je,createComputed:()=>ut,createComputedStore:()=>Kt,createContext:()=>N,createDebounce:()=>gt,createDebouncedResource:()=>At,createDebouncedSignal:()=>Ue,createDeferred:()=>Ot,createEffect:()=>P,createErrorBoundary:()=>Pt,createMemo:()=>x,createMutableStore:()=>$e,createRenderEffect:()=>ct,createResource:()=>de,createRoot:()=>E,createSelector:()=>wt,createSignal:()=>f,createStore:()=>Me,createStoreEffect:()=>Ht,createStoreMemo:()=>zt,createSuspenseBoundary:()=>_t,disposeScope:()=>Ze,flush:()=>pt,getNode:()=>Qt,getOwner:()=>X,getServerData:()=>le,getStoreNode:()=>Jt,indexArray:()=>vr,isComponent:()=>ht,isMemo:()=>dt,isOwnerDisposed:()=>et,isProvider:()=>Tt,isResource:()=>yt,isSignal:()=>ue,isStore:()=>Xt,isStoreProxy:()=>Se,isSuspense:()=>bt,keyArray:()=>mr,makeArrayFlat:()=>Ee,mapArray:()=>Tr,modifiable:()=>Zt,nextResourceId:()=>pe,on:()=>ft,onCleanup:()=>v,operate:()=>lr,produceUtil:()=>tr,provide:()=>M,provideErrorBoundary:()=>Dt,provideSuspense:()=>kt,readChildren:()=>Rt,reconcileUtil:()=>rr,reportResourceData:()=>fe,runWithOwner:()=>$,setOwner:()=>Re,setResourceDataSink:()=>xt,setResourceIdSource:()=>St,setResourceTracker:()=>mt,setServerDataGetter:()=>vt,startTransition:()=>ke,trackResourcePromise:()=>ce,untrack:()=>S,untrackStore:()=>Le,unwrap:()=>V,useContext:()=>tt,useTransition:()=>lt,wrap:()=>Yt});module.exports=cr(Pr);var Ke="1.0.0-alpha.75";var He=require("@fluixi/utils/object"),we=require("@fluixi/utils/functions"),I=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if((0,we.isFunction)(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,He.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,we.isFunction)(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var U=class extends I{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ne=class extends U{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};function lr(e){return new U(e.next,e.error,e.complete)}var j=class extends I{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof U?o=t:o=new ne(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Oe=class extends j{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new j(n=>this.subscribe(n))}};var pr="__fluixi_signal_next_state__",fr=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[pr]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:fr,onSuspend:null,onError:null};var ze=0,Ye=1,K=2,oe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},B=class extends oe{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(K);ge(this)}}peek(){return this._value}},A=class extends oe{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=K;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Ye&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===K)break}(this.state===K||!this._initialized)&&this.recompute(),this.state=ze}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(K);ge(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===ze;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(Ye);ge(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function ge(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function H(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Xe(){return a.consumer}function Qe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Je(e){let t=Y(e);return e&&(e.owned??=[]).push(t),t}function Ze(e,t=!0){z(e,t)}function et(e){return!!e&&e.disposed===!0}function Y(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function N(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=Y(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function tt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function se(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function M(e,t,r){let n=Y(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function rt(e){a.onSuspend=e}function nt(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function ot(e){a.onError=e}function X(){return a.owner}function Re(e){let t=a.owner;return a.owner=e,t}function $(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function v(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function z(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)z(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function E(e){let t=Y(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>z(t))}finally{a.owner=r}}function st(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function dr(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(Q)))}function Q(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function it(){a.batchDepth===0&&Q()}function _e(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&Q()}}var Ae=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=Y(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new A(()=>{z(this.owner,!1),$(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new q(()=>dr(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function ie(e){let t=new Ae(e);return()=>t.dispose()}function yr(e){return!!e&&typeof e.then=="function"}st(()=>{});var at=Symbol.for("signal"),hr=Symbol.for("memo"),br=Symbol.for("signal-node");function f(e,t){let r=new B(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),it(),i});return Object.defineProperty(n,at,{value:!0,enumerable:!0}),Object.defineProperty(n,br,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function x(e,t,r){let n=t,o=X(),s=new A(()=>$(o,()=>{try{return n=e(n)}catch(c){if(yr(c))return nt(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,at,{value:!0,enumerable:!0}),Object.defineProperty(i,hr,{value:!0,enumerable:!0}),i}function P(e,t){let r=t;return ie(()=>{r=e(r)})}function ut(e,t){let r=t;ie(()=>{r=e(r)})}function ct(e,t){let r=t;return ie(()=>{r=e(r)})}function O(e){return _e(e)}function S(e){return H(e)}function ke(e){return _e(e),Promise.resolve()}function lt(){return[()=>!1,ke]}function pt(){return Q(),Promise.resolve()}function ft(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=H(()=>t(c,o,i));return o=c,u}}function Tr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],h=s.get(p);if(h&&!c.has(h))h.setIndex(u),i.push(h),c.add(h);else{let l,d,b;E(T=>{b=T;let[C,G]=f(u);d=G,l=t(p,C)});let w={item:p,rendered:l,dispose:b,setIndex:d};i.push(w),c.add(w)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function mr(e,t,r,n){let o=[],s=[];return v(()=>{for(let i of s)i.dispose();o=[],s=[]}),x(()=>{let i=e()||[];return S(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],h=new Set;for(let l=0;l<i.length;l++){let d=t(i[l]),b=c.get(d);if(b&&!h.has(d))b.setIndex(l),u.push(b);else{let w,T,C;E(G=>{C=G;let[_,W]=f(l);T=W;let ee=x(F=>{let g=(e()||[])[_()];return g??F},i[l]);w=r(ee,_)}),u.push({rendered:w,dispose:C,setIndex:T})}p.push(d),h.add(d)}for(let[l,d]of c)h.has(l)||d.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function vr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),x(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,h,l,d=o[u];E(b=>{l=b;let[w,T]=f(d);h=T,p=t(w,u)}),n.push({rendered:p,setItem:h,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var ae=!1,Sr=Symbol.for("signal"),xr=Symbol.for("memo"),wr=Symbol.for("resource");function ue(e){return typeof e=="function"&&e[Sr]===!0}function dt(e){return typeof e=="function"&&e[xr]===!0}function yt(e){return typeof e=="function"&&e[wr]===!0}function ht(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function bt(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Tt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Ee(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Ee(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Pe=null;function mt(e){Pe=e}function ce(e){Pe&&Pe(e)}var De=null;function vt(e){De=e}function le(e){return De?De(e):void 0}var Ce=null;function St(e){Ce=e}function pe(){return Ce?Ce():void 0}var Fe=null;function xt(e){Fe=e}function fe(e,t){Fe&&Fe(e,t)}function wt(e,t=(r,n)=>r===n){let r=new Map;return P(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=f(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Ot(e,t){let[r,n]=f(e(),t);return P(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function gt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return v(()=>{r!==void 0&&clearTimeout(r)}),n}function Or(e){return!!e&&typeof e.then=="function"}var Ie=Symbol();function de(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=r.transport===!1?void 0:pe(),i=s!==void 0?le(s):void 0,c=i!==void 0,[u,p]=f(i!==void 0?i.value:r.initialValue,{equals:!1}),[h,l]=f(void 0,{equals:!1}),[d,b]=f(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[w,T]=f(void 0,{equals:!1}),[C,G]=f(void 0,{equals:!1}),_=Ie,W=!1;P(()=>{let m=n();if(C(),m===!1||m===null||m===void 0){_=Ie,O(()=>{b("unresolved"),T(void 0),l(void 0)});return}let g=W;if(W=!1,_!==Ie&&m===_&&!g)return;if(_=m,c){c=!1;return}let te=!1;v(()=>te=!0);let Ge=S(d),nr=S(u),We=Ge==="ready"||Ge==="refreshing";O(()=>{b(We?"refreshing":"pending"),l(void 0)});try{let k=o(m,{value:nr,refetching:We});Or(k)?(T(k),ce(k),k.then(re=>{te||(s!==void 0&&fe(s,re),O(()=>{p(()=>re),b("ready"),T(void 0)}))},re=>{te||O(()=>{l(re),b("errored"),T(void 0)})})):O(()=>{p(()=>k),b("ready"),T(void 0)})}catch(k){if(te)return;O(()=>{l(k),b("errored"),T(void 0)})}});let ee=()=>{let m=d();return m==="pending"||m==="refreshing"},F=(()=>{let m=h();if(m)throw m;if(ee()){let g=w();if(g)throw g}return u()});return Object.defineProperties(F,{state:{get:d},loading:{get:ee},error:{get:h},latest:{get:u}}),Object.defineProperty(F,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(F,Symbol.for("signal"),{value:!0,enumerable:!0}),[F,{mutate:p,refetch:()=>{W=!0,G(void 0)}}]}function Ue(e,t=300){let[r,n]=f(e),[o,s]=f(e),[i,c]=f(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},h=()=>{p();let d=S(r);return s(()=>d),c(!1),d},l=(d=>{let b=typeof d=="function"?d(S(r)):d;return n(()=>b),c(!0),p(),u=setTimeout(h,t),b});return v(p),[o,l,{immediate:r,pending:i,flush:h,cancel:()=>{p(),c(!1)}}]}function gr(e){return e!=null&&e!==""}function At(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=gr}=r,[i,c,u]=Ue(e,n),p=()=>s(i())?i():!1,[h,{refetch:l}]=de(p,t,o===void 0?{}:{initialValue:o});return[h,{...u,query:i,setQuery:c,refetch:l}]}function ye(e){if(typeof e=="function"&&!e.length){let t=e();return ue(t)?t:ye(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=ye(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Rt(e){let t=x(e);return x(()=>ye(t()))}var he=N();rt((e,t)=>{let r=se(t,he);r&&(r.increment(),e.finally(()=>r.decrement()))});function _t(){let[e,t]=f(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function kt(e,t){return M(he,e,t)}var Et=N();ot((e,t)=>{let r=se(t,Et);return r?(r.setError(e),!0):!1});function Pt(){let[e,t]=f(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function Dt(e,t){return M(Et,e,t)}var Ct={State:B,Computed:A,subtle:{Watcher:q,untrack:H,currentComputed:Xe,hasSinks:Qe}};var Ar=Symbol.for("signal"),Rr=Symbol.for("fluixi-proxy");var y=require("@fluixi/reactive/signal"),Z=Symbol("store-raw"),D=Symbol("store-node"),Ft=Symbol("store-has"),Te=Symbol("store-self"),me=Symbol("store-track"),Mt=Symbol("store-name"),$t=Symbol("store-store"),It=new WeakMap,Ut=new WeakMap;function Lt(e){let[t,r]=(0,y.createSignal)(e),n=t;return n.$=r,n}function ve(e){let t=It.get(e);return t||It.set(e,t={keys:new Map}),t}function jt(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=Lt(r)),n}function Bt(e){let t=ve(e);(t.all||(t.all=Lt()))()}function qt(e,t){e.$(typeof t=="function"?()=>t:t)}function Vt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function be(e){if(!Vt(e))return e;let t=Ut.get(e);if(t)return t;let r=new Proxy(e,_r);return Ut.set(e,r),r}var _r={get(e,t,r){if(t===Z||t===D)return e;if(t===y.$PROXY)return r;if(t===Ft)return i=>i in e;if(t==="__proxy")return!0;if(t===me||t===Te)return Bt(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=jt(ve(e),t,n)();return Vt(s)?be(s):s},set(){return!0},deleteProperty(e,t){return t in e&&J(e,t,void 0),!0},has(e,t){return t===Z||t===y.$PROXY||t===D||t===Ft||t===Te||t===me?!0:(jt(ve(e),t,e[t])(),t in e)},ownKeys(e){return Bt(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function J(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ve(e),c=i.keys.get(t);if(c&&qt(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&qt(u,e.length)}i.all&&i.all.$(void 0)}function Nt(e,t){return typeof e=="function"?e(t):e}function Be(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?Be(o,n):J(e,r,n)}}function Ne(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function Gt(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)Gt(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},J(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)J(e,s,Nt(r,e[s]));return}J(e,o,Nt(r,e[o]))}function je(e,t,r){Gt(e,Ne(t),r)}function kr(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&Be(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&je(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){Be(e,r);return}if(Array.isArray(t[1])&&t.length>=3){je(e,`${r}.${t[1].join(".")}`,t[2]);return}je(e,String(r),t[1])}function qe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(qe);let t={};for(let r of Object.keys(e))t[r]=qe(e[r]);return t}function L(e,t){let r=e;for(let n of Ne(t)){if(r==null)return;r=r[n]}return r}var R=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>(0,y.batch)(()=>kr(this.root,n)))}get state(){return be(this.root)}get proxy(){return be(this.root)}get accessor(){return(()=>be(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return V(this.state);let r=this.state;for(let n of Ne(t)){if(r==null)return;r=r[n]}return V(r)}select(t){return(0,y.createMemo)(()=>t(this.state))}subscribe(t){return(0,y.createEffect)(()=>t(this.state))}watch(t,r){let n;return(0,y.createEffect)(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return(0,y.createMemo)(()=>this.state[t])}produce(t){this.set((r=>{let n=qe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=L(this.root,t);this.set(t,n.concat(r))}pop(t){let r=L(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=L(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=L(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=L(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=L(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=(0,y.createSignal)(this.state);return t.toObservable()}dispose(){}},Er=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function Wt(e,t){for(let r of Er)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function Me(e,t={immutable:!0}){let r=new R(e,t);return Wt(r.set,r),[r.proxy,r.set]}function $e(e,t={}){return new R(e,{...t,immutable:!1})}function Kt(e,t={}){let r=new R(e(),t);return(0,y.createEffect)(()=>r.set(e())),r}function Ht(e,t,r){return(0,y.createEffect)(()=>r(t(e)))}function zt(e,t,r){return(0,y.createMemo)(()=>t(e),void 0,r)}function Yt(e,t={}){let r=new R(e,t),n=(()=>r.proxy);return Wt(n,r),n}function V(e){if(e==null||typeof e!="object")return e;let t=e[Z];return t!==void 0?t:e}function Le(e){return(0,y.untrack)(()=>V(e))}function Xt(e){return Se(e)}function Qt(e){return Se(e)?e[D]:null}function Jt(e){return e&&typeof e=="object"&&D in e?e[D]:null}function Se(e){return!!e&&typeof e=="object"&&(y.$PROXY in e||e.__proxy===!0)}function Zt(e){return e}var er=Object.freeze({createStore:Me,createMutableStore:$e,batch:y.batch,unwrap:V,untrackStore:Le});function Ve(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ve);let t={};for(let r of Object.keys(e))t[r]=Ve(e[r]);return t}function tr(e){return t=>{let r=Ve(t);return e(r),r}}function rr(e,t={}){return()=>e}
1
+ "use strict";var we=Object.defineProperty;var ir=Object.getOwnPropertyDescriptor;var ar=Object.getOwnPropertyNames;var ur=Object.prototype.hasOwnProperty;var cr=(e,t)=>{for(var r in t)we(e,r,{get:t[r],enumerable:!0})},lr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ar(t))!ur.call(e,o)&&o!==r&&we(e,o,{get:()=>t[o],enumerable:!(n=ir(t,o))||n.enumerable});return e};var pr=e=>lr(we({},"__esModule",{value:!0}),e);var Ur={};cr(Ur,{$NAME:()=>Ht,$NODE:()=>D,$PROXY:()=>Er,$RAW:()=>ee,$SELF:()=>me,$SIGNAL:()=>_r,$STORE:()=>$t,$TRACK:()=>ve,Observable:()=>j,SafeSubscriber:()=>se,Signal:()=>Ct,Store:()=>_,StoreAPI:()=>tr,Subject:()=>ge,Subscriber:()=>U,Subscription:()=>I,SuspenseContext:()=>he,VERSION:()=>Ke,__DEV__:()=>ce,batch:()=>g,createChildOwner:()=>Je,createComputed:()=>ut,createComputedStore:()=>Wt,createContext:()=>N,createDebounce:()=>gt,createDebouncedResource:()=>At,createDebouncedSignal:()=>je,createDeferred:()=>Ot,createEffect:()=>O,createErrorBoundary:()=>Pt,createMemo:()=>S,createMutableStore:()=>He,createRenderEffect:()=>ct,createResource:()=>$,createRoot:()=>P,createSelector:()=>wt,createSignal:()=>f,createStore:()=>te,createStoreEffect:()=>zt,createStoreMemo:()=>Yt,createSuspenseBoundary:()=>_t,disposeScope:()=>Ze,effect:()=>Dr,flush:()=>pt,getNode:()=>Jt,getOwner:()=>Q,getServerData:()=>fe,getStoreNode:()=>Zt,indexArray:()=>xr,isComponent:()=>Tt,isMemo:()=>dt,isOwnerDisposed:()=>et,isProvider:()=>bt,isResource:()=>yt,isSignal:()=>le,isStore:()=>Qt,isStoreProxy:()=>xe,isSuspense:()=>ht,keyArray:()=>Sr,makeArrayFlat:()=>Pe,mapArray:()=>vr,memo:()=>Pr,modifiable:()=>er,nextResourceId:()=>de,on:()=>ft,onCleanup:()=>v,operate:()=>fr,produceUtil:()=>rr,provide:()=>M,provideErrorBoundary:()=>Dt,provideSuspense:()=>Et,readChildren:()=>Rt,reconcileUtil:()=>nr,reportResourceData:()=>ye,resource:()=>Ft,runWithOwner:()=>H,setOwner:()=>_e,setResourceDataSink:()=>xt,setResourceIdSource:()=>St,setResourceTracker:()=>mt,setServerDataGetter:()=>vt,signal:()=>kr,startTransition:()=>ke,store:()=>or,trackResourcePromise:()=>pe,untrack:()=>x,untrackStore:()=>$e,unwrap:()=>V,useContext:()=>tt,useTransition:()=>lt,wrap:()=>Xt});module.exports=pr(Ur);var Ke="1.0.0-alpha.77";var We=require("@fluixi/utils/object"),Oe=require("@fluixi/utils/functions"),I=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if((0,Oe.isFunction)(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if((0,We.isObject)(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if((0,Oe.isFunction)(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var U=class extends I{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},se=class extends U{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};function fr(e){return new U(e.next,e.error,e.complete)}var j=class extends I{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof U?o=t:o=new se(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var ge=class extends j{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new j(n=>this.subscribe(n))}};var dr="__fluixi_signal_next_state__",yr=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[dr]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:yr,onSuspend:null,onError:null};var ze=0,Ye=1,W=2,ie=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},B=class extends ie{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(W);Ae(this)}}peek(){return this._value}},R=class extends ie{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=W;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===Ye&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===W)break}(this.state===W||!this._initialized)&&this.recompute(),this.state=ze}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(W);Ae(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===ze;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty(Ye);Ae(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Ae(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function z(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Xe(){return a.consumer}function Qe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Je(e){let t=X(e);return e&&(e.owned??=[]).push(t),t}function Ze(e,t=!0){Y(e,t)}function et(e){return!!e&&e.disposed===!0}function X(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function N(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=X(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function tt(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function ae(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function M(e,t,r){let n=X(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function rt(e){a.onSuspend=e}function nt(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function ot(e){a.onError=e}function Q(){return a.owner}function _e(e){let t=a.owner;return a.owner=e,t}function H(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function v(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function Y(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)Y(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function P(e){let t=X(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>Y(t))}finally{a.owner=r}}function st(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Tr(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(J)))}function J(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function it(){a.batchDepth===0&&J()}function Ee(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&J()}}var Re=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=X(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new R(()=>{Y(this.owner,!1),H(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new q(()=>Tr(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),Y(this.owner))}};function ue(e){let t=new Re(e);return()=>t.dispose()}function hr(e){return!!e&&typeof e.then=="function"}st(()=>{});var at=Symbol.for("signal"),br=Symbol.for("memo"),mr=Symbol.for("signal-node");function f(e,t){let r=new B(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),it(),i});return Object.defineProperty(n,at,{value:!0,enumerable:!0}),Object.defineProperty(n,mr,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=Q(),s=new R(()=>H(o,()=>{try{return n=e(n)}catch(c){if(hr(c))return nt(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,at,{value:!0,enumerable:!0}),Object.defineProperty(i,br,{value:!0,enumerable:!0}),i}function O(e,t){let r=t;return ue(()=>{r=e(r)})}function ut(e,t){let r=t;ue(()=>{r=e(r)})}function ct(e,t){let r=t;return ue(()=>{r=e(r)})}function g(e){return Ee(e)}function x(e){return z(e)}function ke(e){return Ee(e),Promise.resolve()}function lt(){return[()=>!1,ke]}function pt(){return J(),Promise.resolve()}function ft(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=z(()=>t(c,o,i));return o=c,u}}function vr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return x(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],T=s.get(p);if(T&&!c.has(T))T.setIndex(u),i.push(T),c.add(T);else{let l,d,h;P(b=>{h=b;let[C,G]=f(u);d=G,l=t(p,C)});let w={item:p,rendered:l,dispose:h,setIndex:d};i.push(w),c.add(w)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Sr(e,t,r,n){let o=[],s=[];return v(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return x(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],T=new Set;for(let l=0;l<i.length;l++){let d=t(i[l]),h=c.get(d);if(h&&!T.has(d))h.setIndex(l),u.push(h);else{let w,b,C;P(G=>{C=G;let[E,K]=f(l);b=K;let re=S(F=>{let A=(e()||[])[E()];return A??F},i[l]);w=r(re,E)}),u.push({rendered:w,dispose:C,setIndex:b})}p.push(d),T.add(d)}for(let[l,d]of c)T.has(l)||d.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function xr(e,t,r){let n=[];return v(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return x(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,T,l,d=o[u];P(h=>{l=h;let[w,b]=f(d);T=b,p=t(w,u)}),n.push({rendered:p,setItem:T,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var ce=!1,wr=Symbol.for("signal"),Or=Symbol.for("memo"),gr=Symbol.for("resource");function le(e){return typeof e=="function"&&e[wr]===!0}function dt(e){return typeof e=="function"&&e[Or]===!0}function yt(e){return typeof e=="function"&&e[gr]===!0}function Tt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function ht(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function bt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Pe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Pe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var De=null;function mt(e){De=e}function pe(e){De&&De(e)}var Ce=null;function vt(e){Ce=e}function fe(e){return Ce?Ce(e):void 0}var Fe=null;function St(e){Fe=e}function de(){return Fe?Fe():void 0}var Ie=null;function xt(e){Ie=e}function ye(e,t){Ie&&Ie(e,t)}function wt(e,t=(r,n)=>r===n){let r=new Map;return O(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=f(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function Ot(e,t){let[r,n]=f(e(),t);return O(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function gt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return v(()=>{r!==void 0&&clearTimeout(r)}),n}function Ar(e){return!!e&&typeof e.then=="function"}var Ue=Symbol();function $(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=r.transport===!1?void 0:de(),i=s!==void 0?fe(s):void 0,c=i!==void 0,[u,p]=f(i!==void 0?i.value:r.initialValue,{equals:!1}),[T,l]=f(void 0,{equals:!1}),[d,h]=f(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[w,b]=f(void 0,{equals:!1}),[C,G]=f(void 0,{equals:!1}),E=Ue,K=!1;O(()=>{let m=n();if(C(),m===!1||m===null||m===void 0){E=Ue,g(()=>{h("unresolved"),b(void 0),l(void 0)});return}let A=K;if(K=!1,E!==Ue&&m===E&&!A)return;if(E=m,c){c=!1;return}let ne=!1;v(()=>ne=!0);let Ve=x(d),sr=x(u),Ge=Ve==="ready"||Ve==="refreshing";g(()=>{h(Ge?"refreshing":"pending"),l(void 0)});try{let k=o(m,{value:sr,refetching:Ge});Ar(k)?(b(k),pe(k),k.then(oe=>{ne||(s!==void 0&&ye(s,oe),g(()=>{p(()=>oe),h("ready"),b(void 0)}))},oe=>{ne||g(()=>{l(oe),h("errored"),b(void 0)})})):g(()=>{p(()=>k),h("ready"),b(void 0)})}catch(k){if(ne)return;g(()=>{l(k),h("errored"),b(void 0)})}});let re=()=>{let m=d();return m==="pending"||m==="refreshing"},F=(()=>{let m=T();if(m)throw m;if(re()){let A=w();if(A)throw A}return u()});return Object.defineProperties(F,{state:{get:d},loading:{get:re},error:{get:T},latest:{get:u}}),Object.defineProperty(F,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(F,Symbol.for("signal"),{value:!0,enumerable:!0}),[F,{mutate:p,refetch:()=>{K=!0,G(void 0)}}]}function je(e,t=300){let[r,n]=f(e),[o,s]=f(e),[i,c]=f(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},T=()=>{p();let d=x(r);return s(()=>d),c(!1),d},l=(d=>{let h=typeof d=="function"?d(x(r)):d;return n(()=>h),c(!0),p(),u=setTimeout(T,t),h});return v(p),[o,l,{immediate:r,pending:i,flush:T,cancel:()=>{p(),c(!1)}}]}function Rr(e){return e!=null&&e!==""}function At(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Rr}=r,[i,c,u]=je(e,n),p=()=>s(i())?i():!1,[T,{refetch:l}]=$(p,t,o===void 0?{}:{initialValue:o});return[T,{...u,query:i,setQuery:c,refetch:l}]}function Te(e){if(typeof e=="function"&&!e.length){let t=e();return le(t)?t:Te(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=Te(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Rt(e){let t=S(e);return S(()=>Te(t()))}var he=N();rt((e,t)=>{let r=ae(t,he);r&&(r.increment(),e.finally(()=>r.decrement()))});function _t(){let[e,t]=f(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function Et(e,t){return M(he,e,t)}var kt=N();ot((e,t)=>{let r=ae(t,kt);return r?(r.setError(e),!0):!1});function Pt(){let[e,t]=f(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function Dt(e,t){return M(kt,e,t)}var Ct={State:B,Computed:R,subtle:{Watcher:q,untrack:z,currentComputed:Xe,hasSinks:Qe}};var _r=Symbol.for("signal"),Er=Symbol.for("fluixi-proxy");function kr(e,t){let[r,n]=f(e,t);return Object.assign(r,{set:n})}function Pr(e,t,r){return S(e,t,r)}function Dr(e,t){return O(e,t)}function Ft(...e){let[t,r]=$(...e);return Object.assign(t,r)}var y=require("@fluixi/reactive/signal"),ee=Symbol("store-raw"),D=Symbol("store-node"),It=Symbol("store-has"),me=Symbol("store-self"),ve=Symbol("store-track"),Ht=Symbol("store-name"),$t=Symbol("store-store"),Ut=new WeakMap,jt=new WeakMap;function Lt(e){let[t,r]=(0,y.createSignal)(e),n=t;return n.$=r,n}function Se(e){let t=Ut.get(e);return t||Ut.set(e,t={keys:new Map}),t}function Bt(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=Lt(r)),n}function qt(e){let t=Se(e);(t.all||(t.all=Lt()))()}function Nt(e,t){e.$(typeof t=="function"?()=>t:t)}function Vt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function be(e){if(!Vt(e))return e;let t=jt.get(e);if(t)return t;let r=new Proxy(e,Cr);return jt.set(e,r),r}var Cr={get(e,t,r){if(t===ee||t===D)return e;if(t===y.$PROXY)return r;if(t===It)return i=>i in e;if(t==="__proxy")return!0;if(t===ve||t===me)return qt(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=Bt(Se(e),t,n)();return Vt(s)?be(s):s},set(){return!0},deleteProperty(e,t){return t in e&&Z(e,t,void 0),!0},has(e,t){return t===ee||t===y.$PROXY||t===D||t===It||t===me||t===ve?!0:(Bt(Se(e),t,e[t])(),t in e)},ownKeys(e){return qt(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function Z(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=Se(e),c=i.keys.get(t);if(c&&Nt(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&Nt(u,e.length)}i.all&&i.all.$(void 0)}function Mt(e,t){return typeof e=="function"?e(t):e}function qe(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?qe(o,n):Z(e,r,n)}}function Me(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function Gt(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)Gt(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},Z(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)Z(e,s,Mt(r,e[s]));return}Z(e,o,Mt(r,e[o]))}function Be(e,t,r){Gt(e,Me(t),r)}function Fr(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&qe(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Be(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){qe(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Be(e,`${r}.${t[1].join(".")}`,t[2]);return}Be(e,String(r),t[1])}function Ne(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ne);let t={};for(let r of Object.keys(e))t[r]=Ne(e[r]);return t}function L(e,t){let r=e;for(let n of Me(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>(0,y.batch)(()=>Fr(this.root,n)))}get state(){return be(this.root)}get proxy(){return be(this.root)}get accessor(){return(()=>be(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return V(this.state);let r=this.state;for(let n of Me(t)){if(r==null)return;r=r[n]}return V(r)}select(t){return(0,y.createMemo)(()=>t(this.state))}subscribe(t){return(0,y.createEffect)(()=>t(this.state))}watch(t,r){let n;return(0,y.createEffect)(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return(0,y.createMemo)(()=>this.state[t])}produce(t){this.set((r=>{let n=Ne(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=L(this.root,t);this.set(t,n.concat(r))}pop(t){let r=L(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=L(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=L(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=L(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=L(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=(0,y.createSignal)(this.state);return t.toObservable()}dispose(){}},Ir=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function Kt(e,t){for(let r of Ir)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function te(e,t={immutable:!0}){let r=new _(e,t);return Kt(r.set,r),[r.proxy,r.set]}function He(e,t={}){return new _(e,{...t,immutable:!1})}function Wt(e,t={}){let r=new _(e(),t);return(0,y.createEffect)(()=>r.set(e())),r}function zt(e,t,r){return(0,y.createEffect)(()=>r(t(e)))}function Yt(e,t,r){return(0,y.createMemo)(()=>t(e),void 0,r)}function Xt(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return Kt(n,r),n}function V(e){if(e==null||typeof e!="object")return e;let t=e[ee];return t!==void 0?t:e}function $e(e){return(0,y.untrack)(()=>V(e))}function Qt(e){return xe(e)}function Jt(e){return xe(e)?e[D]:null}function Zt(e){return e&&typeof e=="object"&&D in e?e[D]:null}function xe(e){return!!e&&typeof e=="object"&&(y.$PROXY in e||e.__proxy===!0)}function er(e){return e}var tr=Object.freeze({createStore:te,createMutableStore:He,batch:y.batch,unwrap:V,untrackStore:$e});function Le(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Le);let t={};for(let r of Object.keys(e))t[r]=Le(e[r]);return t}function rr(e){return t=>{let r=Le(t);return e(r),r}}function nr(e,t={}){return()=>e}function or(e,t){let[r,n]=te(e,t);return new Proxy(r,{get:(o,s)=>s==="set"?n:o[s],has:(o,s)=>s==="set"||Reflect.has(o,s)})}
@@ -1 +1 @@
1
- var mt="1.0.0-alpha.75";import{isObject as vt}from"@fluixi/utils/object";import{isFunction as qe}from"@fluixi/utils/functions";var q=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(qe(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(vt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(qe(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var N=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},ce=class extends N{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};function _r(e){return new N(e.next,e.error,e.complete)}var M=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof N?o=t:o=new ce(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Ne=class extends M{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new M(n=>this.subscribe(n))}};var St="__fluixi_signal_next_state__",xt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[St]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:xt,onSuspend:null,onError:null};var Me=0,$e=1,$=2,ee=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},P=class extends ee{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let r of[...this.observers])r.markDirty($);le(this)}}peek(){return this._value}},O=class extends ee{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=$;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===$)break}(this.state===$||!this._initialized)&&this.recompute(),this.state=Me}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty($);le(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===Me;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);le(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function le(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var D=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function L(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function wt(e){let t=G(e);return e&&(e.owned??=[]).push(t),t}function Ot(e,t=!0){V(e,t)}function gt(e){return!!e&&e.disposed===!0}function G(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function W(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=G(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function At(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function te(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function K(e,t,r){let n=G(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ge(e){a.onSuspend=e}function We(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function Ke(e){a.onError=e}function re(){return a.owner}function He(e){let t=a.owner;return a.owner=e,t}function H(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function V(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)V(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function C(e){let t=G(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>V(t))}finally{a.owner=r}}function ze(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Rt(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(z)))}function z(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Ye(){a.batchDepth===0&&z()}function fe(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&z()}}var pe=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=G(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{V(this.owner,!1),H(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new D(()=>Rt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),V(this.owner))}};function ne(e){let t=new pe(e);return()=>t.dispose()}function _t(e){return!!e&&typeof e.then=="function"}ze(()=>{});var Xe=Symbol.for("signal"),kt=Symbol.for("memo"),Et=Symbol.for("signal-node");function d(e,t){let r=new P(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Ye(),i});return Object.defineProperty(n,Xe,{value:!0,enumerable:!0}),Object.defineProperty(n,Et,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function S(e,t,r){let n=t,o=re(),s=new O(()=>H(o,()=>{try{return n=e(n)}catch(c){if(_t(c))return We(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Xe,{value:!0,enumerable:!0}),Object.defineProperty(i,kt,{value:!0,enumerable:!0}),i}function F(e,t){let r=t;return ne(()=>{r=e(r)})}function Pt(e,t){let r=t;ne(()=>{r=e(r)})}function Dt(e,t){let r=t;return ne(()=>{r=e(r)})}function g(e){return fe(e)}function v(e){return L(e)}function Qe(e){return fe(e),Promise.resolve()}function Ct(){return[()=>!1,Qe]}function Ft(){return z(),Promise.resolve()}function It(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=L(()=>t(c,o,i));return o=c,u}}function Lr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,f,h;C(b=>{h=b;let[k,j]=d(u);f=j,l=t(p,k)});let x={item:p,rendered:l,dispose:h,setIndex:f};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Vr(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),S(()=>{let i=e()||[];return v(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let f=t(i[l]),h=c.get(f);if(h&&!y.has(f))h.setIndex(l),u.push(h);else{let x,b,k;C(j=>{k=j;let[A,B]=d(l);b=B;let Q=S(E=>{let w=(e()||[])[A()];return w??E},i[l]);x=r(Q,A)}),u.push({rendered:x,dispose:k,setIndex:b})}p.push(f),y.add(f)}for(let[l,f]of c)y.has(l)||f.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Gr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),S(()=>{let o=e()||[];return v(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,f=o[u];C(h=>{l=h;let[x,b]=d(f);y=b,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var de=!1,Ut=Symbol.for("signal"),jt=Symbol.for("memo"),Bt=Symbol.for("resource");function ye(e){return typeof e=="function"&&e[Ut]===!0}function qt(e){return typeof e=="function"&&e[jt]===!0}function Nt(e){return typeof e=="function"&&e[Bt]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function $t(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Lt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Je(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Je(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var he=null;function Vt(e){he=e}function ve(e){he&&he(e)}var be=null;function Gt(e){be=e}function Se(e){return be?be(e):void 0}var Te=null;function Wt(e){Te=e}function xe(){return Te?Te():void 0}var me=null;function Kt(e){me=e}function we(e,t){me&&me(e,t)}function Ht(e,t=(r,n)=>r===n){let r=new Map;return F(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=d(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function zt(e,t){let[r,n]=d(e(),t);return F(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function Yt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Xt(e){return!!e&&typeof e.then=="function"}var Oe=Symbol();function ge(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=r.transport===!1?void 0:xe(),i=s!==void 0?Se(s):void 0,c=i!==void 0,[u,p]=d(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=d(void 0,{equals:!1}),[f,h]=d(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,b]=d(void 0,{equals:!1}),[k,j]=d(void 0,{equals:!1}),A=Oe,B=!1;F(()=>{let T=n();if(k(),T===!1||T===null||T===void 0){A=Oe,g(()=>{h("unresolved"),b(void 0),l(void 0)});return}let w=B;if(B=!1,A!==Oe&&T===A&&!w)return;if(A=T,c){c=!1;return}let J=!1;m(()=>J=!0);let je=v(f),Tt=v(u),Be=je==="ready"||je==="refreshing";g(()=>{h(Be?"refreshing":"pending"),l(void 0)});try{let R=o(T,{value:Tt,refetching:Be});Xt(R)?(b(R),ve(R),R.then(Z=>{J||(s!==void 0&&we(s,Z),g(()=>{p(()=>Z),h("ready"),b(void 0)}))},Z=>{J||g(()=>{l(Z),h("errored"),b(void 0)})})):g(()=>{p(()=>R),h("ready"),b(void 0)})}catch(R){if(J)return;g(()=>{l(R),h("errored"),b(void 0)})}});let Q=()=>{let T=f();return T==="pending"||T==="refreshing"},E=(()=>{let T=y();if(T)throw T;if(Q()){let w=x();if(w)throw w}return u()});return Object.defineProperties(E,{state:{get:f},loading:{get:Q},error:{get:y},latest:{get:u}}),Object.defineProperty(E,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(E,Symbol.for("signal"),{value:!0,enumerable:!0}),[E,{mutate:p,refetch:()=>{B=!0,j(void 0)}}]}function Ze(e,t=300){let[r,n]=d(e),[o,s]=d(e),[i,c]=d(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let f=v(r);return s(()=>f),c(!1),f},l=(f=>{let h=typeof f=="function"?f(v(r)):f;return n(()=>h),c(!0),p(),u=setTimeout(y,t),h});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function Qt(e){return e!=null&&e!==""}function Jt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Qt}=r,[i,c,u]=Ze(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=ge(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function oe(e){if(typeof e=="function"&&!e.length){let t=e();return ye(t)?t:oe(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=oe(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Zt(e){let t=S(e);return S(()=>oe(t()))}var Ae=W();Ge((e,t)=>{let r=te(t,Ae);r&&(r.increment(),e.finally(()=>r.decrement()))});function er(){let[e,t]=d(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function tr(e,t){return K(Ae,e,t)}var et=W();Ke((e,t)=>{let r=te(t,et);return r?(r.setError(e),!0):!1});function rr(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function nr(e,t){return K(et,e,t)}var or={State:P,Computed:O,subtle:{Watcher:D,untrack:L,currentComputed:Le,hasSinks:Ve}};var yn=Symbol.for("signal"),hn=Symbol.for("fluixi-proxy");import{$PROXY as _e,batch as ut,createEffect as ie,createMemo as ke,createSignal as ct,untrack as sr}from"@fluixi/reactive/signal";var ae=Symbol("store-raw"),U=Symbol("store-node"),tt=Symbol("store-has"),Ee=Symbol("store-self"),Pe=Symbol("store-track"),ir=Symbol("store-name"),ar=Symbol("store-store"),rt=new WeakMap,nt=new WeakMap;function lt(e){let[t,r]=ct(e),n=t;return n.$=r,n}function ue(e){let t=rt.get(e);return t||rt.set(e,t={keys:new Map}),t}function ot(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=lt(r)),n}function st(e){let t=ue(e);(t.all||(t.all=lt()))()}function it(e,t){e.$(typeof t=="function"?()=>t:t)}function pt(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function se(e){if(!pt(e))return e;let t=nt.get(e);if(t)return t;let r=new Proxy(e,ur);return nt.set(e,r),r}var ur={get(e,t,r){if(t===ae||t===U)return e;if(t===_e)return r;if(t===tt)return i=>i in e;if(t==="__proxy")return!0;if(t===Pe||t===Ee)return st(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=ot(ue(e),t,n)();return pt(s)?se(s):s},set(){return!0},deleteProperty(e,t){return t in e&&Y(e,t,void 0),!0},has(e,t){return t===ae||t===_e||t===U||t===tt||t===Ee||t===Pe?!0:(ot(ue(e),t,e[t])(),t in e)},ownKeys(e){return st(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function Y(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ue(e),c=i.keys.get(t);if(c&&it(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&it(u,e.length)}i.all&&i.all.$(void 0)}function at(e,t){return typeof e=="function"?e(t):e}function De(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?De(o,n):Y(e,r,n)}}function Fe(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function ft(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)ft(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},Y(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)Y(e,s,at(r,e[s]));return}Y(e,o,at(r,e[o]))}function Re(e,t,r){ft(e,Fe(t),r)}function cr(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&De(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&Re(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){De(e,r);return}if(Array.isArray(t[1])&&t.length>=3){Re(e,`${r}.${t[1].join(".")}`,t[2]);return}Re(e,String(r),t[1])}function Ce(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ce);let t={};for(let r of Object.keys(e))t[r]=Ce(e[r]);return t}function I(e,t){let r=e;for(let n of Fe(t)){if(r==null)return;r=r[n]}return r}var _=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ut(()=>cr(this.root,n)))}get state(){return se(this.root)}get proxy(){return se(this.root)}get accessor(){return(()=>se(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return X(this.state);let r=this.state;for(let n of Fe(t)){if(r==null)return;r=r[n]}return X(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ie(()=>t(this.state))}watch(t,r){let n;return ie(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Ce(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=ct(this.state);return t.toObservable()}dispose(){}},lr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function dt(e,t){for(let r of lr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function yt(e,t={immutable:!0}){let r=new _(e,t);return dt(r.set,r),[r.proxy,r.set]}function ht(e,t={}){return new _(e,{...t,immutable:!1})}function pr(e,t={}){let r=new _(e(),t);return ie(()=>r.set(e())),r}function fr(e,t,r){return ie(()=>r(t(e)))}function dr(e,t,r){return ke(()=>t(e),void 0,r)}function yr(e,t={}){let r=new _(e,t),n=(()=>r.proxy);return dt(n,r),n}function X(e){if(e==null||typeof e!="object")return e;let t=e[ae];return t!==void 0?t:e}function bt(e){return sr(()=>X(e))}function hr(e){return Ie(e)}function br(e){return Ie(e)?e[U]:null}function Tr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ie(e){return!!e&&typeof e=="object"&&(_e in e||e.__proxy===!0)}function mr(e){return e}var vr=Object.freeze({createStore:yt,createMutableStore:ht,batch:ut,unwrap:X,untrackStore:bt});function Ue(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Ue);let t={};for(let r of Object.keys(e))t[r]=Ue(e[r]);return t}function Sr(e){return t=>{let r=Ue(t);return e(r),r}}function xr(e,t={}){return()=>e}export{ir as $NAME,U as $NODE,hn as $PROXY,ae as $RAW,Ee as $SELF,yn as $SIGNAL,ar as $STORE,Pe as $TRACK,M as Observable,ce as SafeSubscriber,or as Signal,_ as Store,vr as StoreAPI,Ne as Subject,N as Subscriber,q as Subscription,Ae as SuspenseContext,mt as VERSION,de as __DEV__,g as batch,wt as createChildOwner,Pt as createComputed,pr as createComputedStore,W as createContext,Yt as createDebounce,Jt as createDebouncedResource,Ze as createDebouncedSignal,zt as createDeferred,F as createEffect,rr as createErrorBoundary,S as createMemo,ht as createMutableStore,Dt as createRenderEffect,ge as createResource,C as createRoot,Ht as createSelector,d as createSignal,yt as createStore,fr as createStoreEffect,dr as createStoreMemo,er as createSuspenseBoundary,Ot as disposeScope,Ft as flush,br as getNode,re as getOwner,Se as getServerData,Tr as getStoreNode,Gr as indexArray,Mt as isComponent,qt as isMemo,gt as isOwnerDisposed,Lt as isProvider,Nt as isResource,ye as isSignal,hr as isStore,Ie as isStoreProxy,$t as isSuspense,Vr as keyArray,Je as makeArrayFlat,Lr as mapArray,mr as modifiable,xe as nextResourceId,It as on,m as onCleanup,_r as operate,Sr as produceUtil,K as provide,nr as provideErrorBoundary,tr as provideSuspense,Zt as readChildren,xr as reconcileUtil,we as reportResourceData,H as runWithOwner,He as setOwner,Kt as setResourceDataSink,Wt as setResourceIdSource,Vt as setResourceTracker,Gt as setServerDataGetter,Qe as startTransition,ve as trackResourcePromise,v as untrack,bt as untrackStore,X as unwrap,At as useContext,Ct as useTransition,yr as wrap};
1
+ var mt="1.0.0-alpha.77";import{isObject as vt}from"@fluixi/utils/object";import{isFunction as Ne}from"@fluixi/utils/functions";var q=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:r}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let n of t)n.remove(this);if(r){for(let n of r)if(Ne(n)&&!(n instanceof e))try{n()}catch(o){console.error("Error in unsubscribe function:",o)}else if(vt(n)&&typeof n.unsubscribe=="function")try{n.unsubscribe()}catch(o){console.error("Error unsubscribing child:",o)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:r,_subscriptions:n}=this;if(r){if(Ne(t))try{t()}catch(o){console.error("Error in unsubscribe function:",o)}else if(t.unsubscribe)try{t.unsubscribe()}catch(o){console.error("Error unsubscribing:",o)}return this}return n||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:r}=this;if(!r)return;let n=r.indexOf(t);n!==-1&&(r.splice(n,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:r}=this;r?Array.isArray(r)?r.push(t):this._parentOrParents=[r,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:r}=this;if(r===t)this._parentOrParents=null;else if(Array.isArray(r)){let n=r.indexOf(t);n!==-1&&(r.splice(n,1),r.length===1&&(this._parentOrParents=r[0]))}}};var N=class extends q{constructor(r,n,o){super();this.isStopped=!1;let s;r?typeof r=="object"?s=r:s={next:r,error:n,complete:o}:s={},this.destination=s}next(r){if(!this.isStopped&&this.destination.next)try{this.destination.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(r)}catch(n){throw n}else throw r;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(r){this.error(r);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},pe=class extends N{constructor(r,n,o,s){super(r,n,o);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(r){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(r)}catch(n){this.error(n)}}error(r){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(r)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};function kr(e){return new N(e.next,e.error,e.complete)}var M=class extends q{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,r,n){let o;t instanceof N?o=t:o=new pe(t,r,n);let{_subscribe:s}=this;try{let i=s.call(this,o);i&&(typeof i=="function"||typeof i.unsubscribe=="function")&&o.add(i)}catch(i){o.error(i)}return o}pipe(...t){return t.length===0?this:t.reduce((r,n)=>n(r),this)}toPromise(){return new Promise((t,r)=>{let n;this.subscribe({next:o=>n=o,error:r,complete:()=>t(n)})})}};var Me=class extends M{constructor(){super(r=>{if(this.closed)throw new Error("Subject has been closed");if(this.hasError)r.error(this.thrownError);else if(this.isStopped)r.complete();else return this.observers.push(r),()=>{let n=this.observers.indexOf(r);n!==-1&&this.observers.splice(n,1)}});this.observers=[];this.isStopped=!1;this.hasError=!1;this.thrownError=null}next(r){if(this.isStopped)return;let{observers:n}=this,o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].next?.(r)}error(r){if(this.isStopped)return;this.hasError=!0,this.thrownError=r,this.isStopped=!0;let{observers:n}=this;this.observers=[];let o=n.length,s=n.slice();for(let i=0;i<o;i++)s[i].error?.(r)}complete(){if(this.isStopped)return;this.isStopped=!0;let{observers:r}=this;this.observers=[];let n=r.length,o=r.slice();for(let s=0;s<n;s++)o[s].complete?.()}unsubscribe(){this.isStopped=!0,this.observers=[]}asObservable(){return new M(n=>this.subscribe(n))}};var St="__fluixi_signal_next_state__",xt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},a=globalThis[St]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:xt,onSuspend:null,onError:null};var He=0,$e=1,H=2,te=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(a.untracked)return;let t=a.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},D=class extends te{constructor(t,r){super(),this._value=t,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let r of[...this.observers])r.markDirty(H);fe(this)}}peek(){return this._value}},O=class extends te{constructor(r,n){super();this._threw=!1;this._initialized=!1;this.state=H;this.sources=null;this._fn=r,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){if(a.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===$e&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===H)break}(this.state===H||!this._initialized)&&this.recompute(),this.state=He}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let r=a.consumer,n=a.untracked;a.consumer=this,a.untracked=!1;let o,s=!1,i;try{o=this._fn()}catch(u){s=!0,i=u,o=this._value}finally{a.consumer=r,a.untracked=n}let c=!this._initialized||this._threw!==s||(s?i!==this._error:!this._equals(this._value,o));if(this._initialized=!0,this._threw=s,this._error=i,this._value=o,c){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(H);fe(this)}}markDirty(r){if(this.state>=r)return;let n=this.state===He;if(this.state=r,n){if(this.observers)for(let o of[...this.observers])o.markDirty($e);fe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function fe(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var C=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let r of t)this._watched.add(r),(r.watchers??=new Set).add(this)}unwatch(...t){for(let r of t)this._watched.delete(r),r.watchers?.delete(this),this._pending.delete(r)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let r=this._pending.size===0;this._pending.add(t),r&&this._notifyFn()}};function $(e){if(a.untracked)return e();a.untracked=!0;try{return e()}finally{a.untracked=!1}}function Le(){return a.consumer}function Ve(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function wt(e){let t=V(e);return e&&(e.owned??=[]).push(t),t}function Ot(e,t=!0){L(e,t)}function gt(e){return!!e&&e.disposed===!0}function V(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function G(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:n=>{let o=a.owner,s=V(o);(s.contexts=new Map).set(t,n.value),o&&(o.owned??=[]).push(s),a.owner=s;try{return n.children}finally{a.owner=o}}}}function At(e){let t=a.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function re(e,t){let r=e;for(;r;){if(r.contexts&&r.contexts.has(t.id))return r.contexts.get(t.id);r=r.parent}return t.defaultValue}function K(e,t,r){let n=V(a.owner);(n.contexts=new Map).set(e.id,t),a.owner&&(a.owner.owned??=[]).push(n);let o=a.owner;a.owner=n;try{return r()}finally{a.owner=o}}function Ge(e){a.onSuspend=e}function Ke(e){return a.onSuspend?(a.onSuspend(e,a.owner),!0):!1}function We(e){a.onError=e}function ne(){return a.owner}function ze(e){let t=a.owner;return a.owner=e,t}function W(e,t){let r=a.owner;a.owner=e;try{return t()}finally{a.owner=r}}function m(e){if(a.owner){if(a.owner.disposed){e();return}(a.owner.cleanups??=[]).push(e)}}function L(e,t=!0){if(!e.disposed){if(e.owned){for(let r=e.owned.length-1;r>=0;r--)L(e.owned[r]);e.owned=null}if(e.cleanups){for(let r=e.cleanups.length-1;r>=0;r--)e.cleanups[r]();e.cleanups=null}t&&(e.disposed=!0)}}function F(e){let t=V(a.owner);a.owner&&(a.owner.owned??=[]).push(t);let r=a.owner;a.owner=t;try{return e(()=>L(t))}finally{a.owner=r}}function Ye(e){a.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Rt(e){e.queued||(e.queued=!0,a.queue.push(e),!a.scheduled&&a.batchDepth===0&&(a.scheduled=!0,a.hostSchedule(z)))}function z(){if(a.scheduled=!1,a.flushing)return;a.flushing=!0;let e=0;try{for(;a.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=a.queue;a.queue=[];for(let r of t)r.queued=!1,r.disposed||r.run()}}finally{a.flushing=!1}}function Xe(){a.batchDepth===0&&z()}function ye(e){a.batchDepth++;try{return e()}finally{--a.batchDepth===0&&z()}}var de=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=V(a.owner),a.owner&&(a.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new O(()=>{L(this.owner,!1),W(this.owner,()=>{let r=t();typeof r=="function"&&(this.owner.cleanups??=[]).push(r)})}),this.watcher=new C(()=>Rt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&a.onSuspend){a.onSuspend(t,this.owner);return}if(a.onError&&a.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),L(this.owner))}};function oe(e){let t=new de(e);return()=>t.dispose()}function _t(e){return!!e&&typeof e.then=="function"}Ye(()=>{});var Qe=Symbol.for("signal"),Et=Symbol.for("memo"),kt=Symbol.for("signal-node");function f(e,t){let r=new D(e,{equals:t?.equals}),n=(()=>r.get()),o=(s=>{let i=typeof s=="function"?s(r.peek()):s;return r.set(i),Xe(),i});return Object.defineProperty(n,Qe,{value:!0,enumerable:!0}),Object.defineProperty(n,kt,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[n,o]}function v(e,t,r){let n=t,o=ne(),s=new O(()=>W(o,()=>{try{return n=e(n)}catch(c){if(_t(c))return Ke(c),n;throw c}}),{equals:r?.equals}),i=(()=>s.get());return Object.defineProperty(i,Qe,{value:!0,enumerable:!0}),Object.defineProperty(i,Et,{value:!0,enumerable:!0}),i}function g(e,t){let r=t;return oe(()=>{r=e(r)})}function Pt(e,t){let r=t;oe(()=>{r=e(r)})}function Dt(e,t){let r=t;return oe(()=>{r=e(r)})}function A(e){return ye(e)}function S(e){return $(e)}function Je(e){return ye(e),Promise.resolve()}function Ct(){return[()=>!1,Je]}function Ft(){return z(),Promise.resolve()}function It(e,t,r){let n=Array.isArray(e),o,s=r?.defer??!1;return i=>{let c=n?e.map(p=>p()):e();if(s){s=!1,o=c;return}let u=$(()=>t(c,o,i));return o=c,u}}function Vr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),v(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=new Map;for(let u of n)s.has(u.item)||s.set(u.item,u);let i=[],c=new Set;for(let u=0;u<o.length;u++){let p=o[u],y=s.get(p);if(y&&!c.has(y))y.setIndex(u),i.push(y),c.add(y);else{let l,d,T;F(h=>{T=h;let[k,j]=f(u);d=j,l=t(p,k)});let x={item:p,rendered:l,dispose:T,setIndex:d};i.push(x),c.add(x)}}for(let u of n)c.has(u)||u.dispose();return n=i,i.map(u=>u.rendered)})})}function Gr(e,t,r,n){let o=[],s=[];return m(()=>{for(let i of s)i.dispose();o=[],s=[]}),v(()=>{let i=e()||[];return S(()=>{if(i.length===0){for(let l of s)l.dispose();return o=[],s=[],n?.fallback?n.fallback():[]}let c=new Map;for(let l=0;l<o.length;l++)c.set(o[l],s[l]);let u=[],p=[],y=new Set;for(let l=0;l<i.length;l++){let d=t(i[l]),T=c.get(d);if(T&&!y.has(d))T.setIndex(l),u.push(T);else{let x,h,k;F(j=>{k=j;let[R,B]=f(l);h=B;let J=v(P=>{let w=(e()||[])[R()];return w??P},i[l]);x=r(J,R)}),u.push({rendered:x,dispose:k,setIndex:h})}p.push(d),y.add(d)}for(let[l,d]of c)y.has(l)||d.dispose();return o=p,s=u,u.map(l=>l.rendered)})})}function Kr(e,t,r){let n=[];return m(()=>{for(let o of n)o.dispose();n=[]}),v(()=>{let o=e()||[];return S(()=>{if(o.length===0){for(let u of n)u.dispose();return n=[],r?.fallback?r.fallback():[]}let s=n.length,i=o.length;for(let u=s;u<i;u++){let p,y,l,d=o[u];F(T=>{l=T;let[x,h]=f(d);y=h,p=t(x,u)}),n.push({rendered:p,setItem:y,dispose:l})}for(let u=i;u<s;u++)n[u].dispose();i<s&&(n=n.slice(0,i));let c=Math.min(s,i);for(let u=0;u<c;u++)n[u].setItem(o[u]);return n.map(u=>u.rendered)})})}var Te=!1,Ut=Symbol.for("signal"),jt=Symbol.for("memo"),Bt=Symbol.for("resource");function he(e){return typeof e=="function"&&e[Ut]===!0}function qt(e){return typeof e=="function"&&e[jt]===!0}function Nt(e){return typeof e=="function"&&e[Bt]===!0}function Mt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ht(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function $t(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Ze(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Ze(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var be=null;function Lt(e){be=e}function xe(e){be&&be(e)}var me=null;function Vt(e){me=e}function we(e){return me?me(e):void 0}var ve=null;function Gt(e){ve=e}function Oe(){return ve?ve():void 0}var Se=null;function Kt(e){Se=e}function ge(e,t){Se&&Se(e,t)}function Wt(e,t=(r,n)=>r===n){let r=new Map;return g(()=>{let n=e();for(let[o,s]of r){let[i,c]=s,u=t(o,n);i()!==u&&c(u)}}),n=>{let o=r.get(n);if(!o){let[s,i]=f(!1);o=[s,i],r.set(n,o);let c=e();i(t(n,c))}return o[0]()}}function zt(e,t){let[r,n]=f(e(),t);return g(()=>{let o=e();t?.timeoutMs?setTimeout(()=>n(()=>o),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>n(()=>o)):Promise.resolve().then(()=>n(()=>o))}),r}function Yt(e,t){let r,n=(...o)=>{r!==void 0&&clearTimeout(r),r=setTimeout(()=>{r=void 0,e(...o)},t)};return m(()=>{r!==void 0&&clearTimeout(r)}),n}function Xt(e){return!!e&&typeof e.then=="function"}var Ae=Symbol();function Y(e,t,r={}){let n,o;typeof t=="function"?(n=typeof e=="function"?e:()=>e,o=t):(n=()=>!0,o=e,t&&typeof t=="object"&&(r=t));let s=r.transport===!1?void 0:Oe(),i=s!==void 0?we(s):void 0,c=i!==void 0,[u,p]=f(i!==void 0?i.value:r.initialValue,{equals:!1}),[y,l]=f(void 0,{equals:!1}),[d,T]=f(i!==void 0||r.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,h]=f(void 0,{equals:!1}),[k,j]=f(void 0,{equals:!1}),R=Ae,B=!1;g(()=>{let b=n();if(k(),b===!1||b===null||b===void 0){R=Ae,A(()=>{T("unresolved"),h(void 0),l(void 0)});return}let w=B;if(B=!1,R!==Ae&&b===R&&!w)return;if(R=b,c){c=!1;return}let Z=!1;m(()=>Z=!0);let Be=S(d),bt=S(u),qe=Be==="ready"||Be==="refreshing";A(()=>{T(qe?"refreshing":"pending"),l(void 0)});try{let _=o(b,{value:bt,refetching:qe});Xt(_)?(h(_),xe(_),_.then(ee=>{Z||(s!==void 0&&ge(s,ee),A(()=>{p(()=>ee),T("ready"),h(void 0)}))},ee=>{Z||A(()=>{l(ee),T("errored"),h(void 0)})})):A(()=>{p(()=>_),T("ready"),h(void 0)})}catch(_){if(Z)return;A(()=>{l(_),T("errored"),h(void 0)})}});let J=()=>{let b=d();return b==="pending"||b==="refreshing"},P=(()=>{let b=y();if(b)throw b;if(J()){let w=x();if(w)throw w}return u()});return Object.defineProperties(P,{state:{get:d},loading:{get:J},error:{get:y},latest:{get:u}}),Object.defineProperty(P,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(P,Symbol.for("signal"),{value:!0,enumerable:!0}),[P,{mutate:p,refetch:()=>{B=!0,j(void 0)}}]}function et(e,t=300){let[r,n]=f(e),[o,s]=f(e),[i,c]=f(!1),u,p=()=>{u!==void 0&&(clearTimeout(u),u=void 0)},y=()=>{p();let d=S(r);return s(()=>d),c(!1),d},l=(d=>{let T=typeof d=="function"?d(S(r)):d;return n(()=>T),c(!0),p(),u=setTimeout(y,t),T});return m(p),[o,l,{immediate:r,pending:i,flush:y,cancel:()=>{p(),c(!1)}}]}function Qt(e){return e!=null&&e!==""}function Jt(e,t,r={}){let{delay:n=300,initialValue:o,shouldFetch:s=Qt}=r,[i,c,u]=et(e,n),p=()=>s(i())?i():!1,[y,{refetch:l}]=Y(p,t,o===void 0?{}:{initialValue:o});return[y,{...u,query:i,setQuery:c,refetch:l}]}function se(e){if(typeof e=="function"&&!e.length){let t=e();return he(t)?t:se(t)}if(Array.isArray(e)){let t=[];for(let r=0;r<e.length;r++){let n=se(e[r]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Zt(e){let t=v(e);return v(()=>se(t()))}var Re=G();Ge((e,t)=>{let r=re(t,Re);r&&(r.increment(),e.finally(()=>r.decrement()))});function er(){let[e,t]=f(0),r=0;return{increment:()=>t(r+=1),decrement:()=>t(r-=1),inFallback:()=>e()>0}}function tr(e,t){return K(Re,e,t)}var tt=G();We((e,t)=>{let r=re(t,tt);return r?(r.setError(e),!0):!1});function rr(){let[e,t]=f(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:n=>t(()=>n)}}function nr(e,t){return K(tt,e,t)}var or={State:D,Computed:O,subtle:{Watcher:C,untrack:$,currentComputed:Le,hasSinks:Ve}};var hn=Symbol.for("signal"),bn=Symbol.for("fluixi-proxy");function Cn(e,t){let[r,n]=f(e,t);return Object.assign(r,{set:n})}function Fn(e,t,r){return v(e,t,r)}function In(e,t){return g(e,t)}function sr(...e){let[t,r]=Y(...e);return Object.assign(t,r)}import{$PROXY as Ee,batch as ct,createEffect as ae,createMemo as ke,createSignal as lt,untrack as ir}from"@fluixi/reactive/signal";var ue=Symbol("store-raw"),U=Symbol("store-node"),rt=Symbol("store-has"),Pe=Symbol("store-self"),De=Symbol("store-track"),ar=Symbol("store-name"),ur=Symbol("store-store"),nt=new WeakMap,ot=new WeakMap;function pt(e){let[t,r]=lt(e),n=t;return n.$=r,n}function ce(e){let t=nt.get(e);return t||nt.set(e,t={keys:new Map}),t}function st(e,t,r){let n=e.keys.get(t);return n||e.keys.set(t,n=pt(r)),n}function it(e){let t=ce(e);(t.all||(t.all=pt()))()}function at(e,t){e.$(typeof t=="function"?()=>t:t)}function ft(e){if(e==null||typeof e!="object")return!1;if(Array.isArray(e))return!0;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function ie(e){if(!ft(e))return e;let t=ot.get(e);if(t)return t;let r=new Proxy(e,cr);return ot.set(e,r),r}var cr={get(e,t,r){if(t===ue||t===U)return e;if(t===Ee)return r;if(t===rt)return i=>i in e;if(t==="__proxy")return!0;if(t===De||t===Pe)return it(e),r;let n=e[t];if(typeof n=="function"&&!Object.prototype.hasOwnProperty.call(e,t))return n;let o=Object.getOwnPropertyDescriptor(e,t);if(o&&o.get)return o.get.call(r);let s=st(ce(e),t,n)();return ft(s)?ie(s):s},set(){return!0},deleteProperty(e,t){return t in e&&X(e,t,void 0),!0},has(e,t){return t===ue||t===Ee||t===U||t===rt||t===Pe||t===De?!0:(st(ce(e),t,e[t])(),t in e)},ownKeys(e){return it(e),Reflect.ownKeys(e)},getOwnPropertyDescriptor(e,t){return Reflect.getOwnPropertyDescriptor(e,t)}};function X(e,t,r){if(e[t]===r&&(r!==void 0||t in e))return;let o=Array.isArray(e),s=o?e.length:0;r===void 0?delete e[t]:e[t]=r;let i=ce(e),c=i.keys.get(t);if(c&&at(c,r),o&&e.length!==s){let u=i.keys.get("length");u&&at(u,e.length)}i.all&&i.all.$(void 0)}function ut(e,t){return typeof e=="function"?e(t):e}function Ce(e,t){for(let r of Object.keys(t)){let n=t[r],o=e[r];n&&typeof n=="object"&&!Array.isArray(n)&&o&&typeof o=="object"&&!Array.isArray(o)?Ce(o,n):X(e,r,n)}}function Ie(e){let t=[],r=e.replace(/\[([^\]]*)\]/g,".$1");for(let n of r.split("."))n.length&&t.push(n);return t}function dt(e,t,r){let n=t.length-1;for(let s=0;s<n;s++){let i=t[s];if(i==="*"){let u=t.slice(s+1);if(Array.isArray(e))for(let p=0;p<e.length;p++)dt(e[p],u,r);return}let c=e[i];(c==null||typeof c!="object")&&(c=/^\d+$/.test(t[s+1])?[]:{},X(e,i,c)),e=c}let o=t[n];if(o==="*"){if(Array.isArray(e))for(let s=0;s<e.length;s++)X(e,s,ut(r,e[s]));return}X(e,o,ut(r,e[o]))}function _e(e,t,r){dt(e,Ie(t),r)}function lr(e,t){let r=t[0];if(typeof r=="function"&&t.length===1){let n=r(e);n&&n!==e&&Ce(e,n);return}if(Array.isArray(r)&&t.length===1){for(let n of r)Array.isArray(n)&&_e(e,n[0],n[1]);return}if(r&&typeof r=="object"&&!Array.isArray(r)&&t.length===1){Ce(e,r);return}if(Array.isArray(t[1])&&t.length>=3){_e(e,`${r}.${t[1].join(".")}`,t[2]);return}_e(e,String(r),t[1])}function Fe(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(Fe);let t={};for(let r of Object.keys(e))t[r]=Fe(e[r]);return t}function I(e,t){let r=e;for(let n of Ie(t)){if(r==null)return;r=r[n]}return r}var E=class{constructor(t,r={immutable:!0}){this.options=r;this.root=t,this.set=((...n)=>ct(()=>lr(this.root,n)))}get state(){return ie(this.root)}get proxy(){return ie(this.root)}get accessor(){return(()=>ie(this.root))}unwrap(){return this.root}getNode(t){return this.root&&this.root[t]}get(t){if(t==null||t==="")return Q(this.state);let r=this.state;for(let n of Ie(t)){if(r==null)return;r=r[n]}return Q(r)}select(t){return ke(()=>t(this.state))}subscribe(t){return ae(()=>t(this.state))}watch(t,r){let n;return ae(()=>{let o=t(this.state);Object.is(o,n)||(r(o,n),n=o)})}reactive(t){return ke(()=>this.state[t])}produce(t){this.set((r=>{let n=Fe(r);return t(n),n}))}reconcile(t,r={}){this.set(t)}push(t,...r){let n=I(this.root,t);this.set(t,n.concat(r))}pop(t){let r=I(this.root,t).slice(),n=r.pop();return this.set(t,r),n}shift(t){let r=I(this.root,t).slice(),n=r.shift();return this.set(t,r),n}splice(t,r,n,...o){let s=I(this.root,t).slice(),i=s.splice(r,n,...o);return this.set(t,s),i}insert(t,r,n){let o=I(this.root,t).slice();o.splice(r,0,n),this.set(t,o)}removeAt(t,r){let n=I(this.root,t).slice(),o=n.splice(r,1);return this.set(t,n),o}toObservable(){let[t]=lt(this.state);return t.toObservable()}dispose(){}},pr=["get","select","watch","subscribe","produce","reconcile","push","pop","shift","splice","insert","removeAt","unwrap","toObservable"];function yt(e,t){for(let r of pr)e[r]=t[r].bind(t);e.$=t.reactive.bind(t)}function le(e,t={immutable:!0}){let r=new E(e,t);return yt(r.set,r),[r.proxy,r.set]}function Tt(e,t={}){return new E(e,{...t,immutable:!1})}function fr(e,t={}){let r=new E(e(),t);return ae(()=>r.set(e())),r}function dr(e,t,r){return ae(()=>r(t(e)))}function yr(e,t,r){return ke(()=>t(e),void 0,r)}function Tr(e,t={}){let r=new E(e,t),n=(()=>r.proxy);return yt(n,r),n}function Q(e){if(e==null||typeof e!="object")return e;let t=e[ue];return t!==void 0?t:e}function ht(e){return ir(()=>Q(e))}function hr(e){return Ue(e)}function br(e){return Ue(e)?e[U]:null}function mr(e){return e&&typeof e=="object"&&U in e?e[U]:null}function Ue(e){return!!e&&typeof e=="object"&&(Ee in e||e.__proxy===!0)}function vr(e){return e}var Sr=Object.freeze({createStore:le,createMutableStore:Tt,batch:ct,unwrap:Q,untrackStore:ht});function je(e){if(e==null||typeof e!="object")return e;if(Array.isArray(e))return e.map(je);let t={};for(let r of Object.keys(e))t[r]=je(e[r]);return t}function xr(e){return t=>{let r=je(t);return e(r),r}}function wr(e,t={}){return()=>e}function Or(e,t){let[r,n]=le(e,t);return new Proxy(r,{get:(o,s)=>s==="set"?n:o[s],has:(o,s)=>s==="set"||Reflect.has(o,s)})}export{ar as $NAME,U as $NODE,bn as $PROXY,ue as $RAW,Pe as $SELF,hn as $SIGNAL,ur as $STORE,De as $TRACK,M as Observable,pe as SafeSubscriber,or as Signal,E as Store,Sr as StoreAPI,Me as Subject,N as Subscriber,q as Subscription,Re as SuspenseContext,mt as VERSION,Te as __DEV__,A as batch,wt as createChildOwner,Pt as createComputed,fr as createComputedStore,G as createContext,Yt as createDebounce,Jt as createDebouncedResource,et as createDebouncedSignal,zt as createDeferred,g as createEffect,rr as createErrorBoundary,v as createMemo,Tt as createMutableStore,Dt as createRenderEffect,Y as createResource,F as createRoot,Wt as createSelector,f as createSignal,le as createStore,dr as createStoreEffect,yr as createStoreMemo,er as createSuspenseBoundary,Ot as disposeScope,In as effect,Ft as flush,br as getNode,ne as getOwner,we as getServerData,mr as getStoreNode,Kr as indexArray,Mt as isComponent,qt as isMemo,gt as isOwnerDisposed,$t as isProvider,Nt as isResource,he as isSignal,hr as isStore,Ue as isStoreProxy,Ht as isSuspense,Gr as keyArray,Ze as makeArrayFlat,Vr as mapArray,Fn as memo,vr as modifiable,Oe as nextResourceId,It as on,m as onCleanup,kr as operate,xr as produceUtil,K as provide,nr as provideErrorBoundary,tr as provideSuspense,Zt as readChildren,wr as reconcileUtil,ge as reportResourceData,sr as resource,W as runWithOwner,ze as setOwner,Kt as setResourceDataSink,Gt as setResourceIdSource,Lt as setResourceTracker,Vt as setServerDataGetter,Cn as signal,Je as startTransition,Or as store,xe as trackResourcePromise,S as untrack,ht as untrackStore,Q as unwrap,At as useContext,Ct as useTransition,Tr as wrap};
@@ -0,0 +1 @@
1
+ "use strict";var w=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var M=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},H=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of R(e))!N.call(t,s)&&s!==n&&w(t,s,{get:()=>e[s],enumerable:!(o=E(e,s))||o.enumerable});return t};var j=t=>H(w({},"__esModule",{value:!0}),t);var U={};M(U,{effect:()=>$,memo:()=>Y,signal:()=>L});module.exports=j(U);var I="__fluixi_signal_next_state__",W=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},r=globalThis[I]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:W,onSuspend:null,onError:null};var x=0,S=1,d=2,f=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let e=r.consumer;e&&((this.observers??=new Set).add(e),(e.sources??=new Set).add(this))}},p=class extends f{constructor(e,n){super(),this._value=e,this._equals=n?.equals===!1?()=>!1:n?.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 n of[...this.observers])n.markDirty(d);T(this)}}peek(){return this._value}},a=class extends f{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=d;this.sources=null;this._fn=n,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===S&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===d)break}(this.state===d||!this._initialized)&&this.recompute(),this.state=x}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let s,i=!1,u;try{s=this._fn()}catch(c){i=!0,u=c,s=this._value}finally{r.consumer=n,r.untracked=o}let l=!this._initialized||this._threw!==i||(i?u!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=u,this._value=s,l){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(d);T(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===x;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(S);T(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function T(t){if(t.watchers)for(let e of[...t.watchers])e._notify(t)}var h=class{constructor(e){this._watched=new Set;this._pending=new Set;this._notifyFn=e}watch(...e){for(let n of e)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...e){for(let n of e)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let e=[...this._pending];return this._pending.clear(),e}_notify(e){if(!this._watched.has(e)||this._pending.has(e))return;let n=this._pending.size===0;this._pending.add(e),n&&this._notifyFn()}};function z(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function g(t){return r.onSuspend?(r.onSuspend(t,r.owner),!0):!1}function _(){return r.owner}function m(t,e){let n=r.owner;r.owner=t;try{return e()}finally{r.owner=n}}function v(t,e=!0){if(!t.disposed){if(t.owned){for(let n=t.owned.length-1;n>=0;n--)v(t.owned[n]);t.owned=null}if(t.cleanups){for(let n=t.cleanups.length-1;n>=0;n--)t.cleanups[n]();t.cleanups=null}e&&(t.disposed=!0)}}function O(t){r.hostSchedule=t??(e=>{Promise.resolve().then(e)})}function G(t){t.queued||(t.queued=!0,r.queue.push(t),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(b)))}function b(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let t=0;try{for(;r.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=r.queue;r.queue=[];for(let n of e)n.queued=!1,n.disposed||n.run()}}finally{r.flushing=!1}}function k(){r.batchDepth===0&&b()}var y=class{constructor(e){this.queued=!1;this.disposed=!1;this.owner=z(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new a(()=>{v(this.owner,!1),m(this.owner,()=>{let n=e();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new h(()=>G(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"&&r.onSuspend){r.onSuspend(e,this.owner);return}if(r.onError&&r.onError(e,this.owner))return;throw e}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),v(this.owner))}};function q(t){let e=new y(t);return()=>e.dispose()}function V(t){return!!t&&typeof t.then=="function"}O(()=>{});var C=Symbol.for("signal"),F=Symbol.for("memo"),K=Symbol.for("signal-node");function A(t,e){let n=new p(t,{equals:e?.equals}),o=(()=>n.get()),s=(i=>{let u=typeof i=="function"?i(n.peek()):i;return n.set(u),k(),u});return Object.defineProperty(o,C,{value:!0,enumerable:!0}),Object.defineProperty(o,K,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,s]}function D(t,e,n){let o=e,s=_(),i=new a(()=>m(s,()=>{try{return o=t(o)}catch(l){if(V(l))return g(l),o;throw l}}),{equals:n?.equals}),u=(()=>i.get());return Object.defineProperty(u,C,{value:!0,enumerable:!0}),Object.defineProperty(u,F,{value:!0,enumerable:!0}),u}function P(t,e){let n=e;return q(()=>{n=t(n)})}function L(t,e){let[n,o]=A(t,e);return Object.assign(n,{set:o})}function Y(t,e,n){return D(t,e,n)}function $(t,e){return P(t,e)}
@@ -0,0 +1,13 @@
1
+ import type { Accessor, Setter, SignalOptions } from './signal.js';
2
+ /** A writable reactive value: call it to read, `.set()` to write. */
3
+ export type SignalHandle<T> = Accessor<T> & {
4
+ set: Setter<T>;
5
+ };
6
+ /** A derived value. Read-only, so it is just the accessor. */
7
+ export type MemoHandle<T> = Accessor<T>;
8
+ export declare function signal<T>(value: T, options?: SignalOptions<T>): SignalHandle<T>;
9
+ export declare function signal<T = undefined>(): SignalHandle<T | undefined>;
10
+ export declare function memo<T>(fn: (prev?: T) => T, value?: T, options?: SignalOptions<T>): MemoHandle<T>;
11
+ /** Run `fn` and re-run it when anything it read changes. Returns its disposer. */
12
+ export declare function effect<T>(fn: (prev?: T) => T | (() => void), value?: T): () => void;
13
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/api.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEnE,qEAAqE;AACrE,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAE/D,8DAA8D;AAC9D,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC;AAExC,wBAAgB,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;AACjF,wBAAgB,MAAM,CAAC,CAAC,GAAG,SAAS,KAAK,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;AAMrE,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAEjG;AAED,kFAAkF;AAClF,wBAAgB,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,MAAM,IAAI,CAEnF"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The short reactive API: `signal`, `memo`, `effect`.
3
+ *
4
+ * const count = signal(0);
5
+ * count(); // read
6
+ * count.set(1); // write
7
+ *
8
+ * `signal` is `createSignal` with the setter attached to the accessor instead of handed
9
+ * back beside it. The function IS that accessor, so a read is the same call it always
10
+ * was, `count` passes anywhere an accessor is expected, and only the write changes
11
+ * spelling. `memo` is `createMemo` under a shorter name — a derived value has nothing to
12
+ * set, so there is nothing to attach.
13
+ *
14
+ * The rule across the API: read it the way its shape implies — a call for a value, a
15
+ * property for an object (see `store`) — and `.set()` writes.
16
+ *
17
+ * `createSignal` and friends are unchanged; the two forms are one primitive and mix
18
+ * freely.
19
+ */
20
+ import { createEffect, createMemo, createSignal } from './graph/compat.js';
21
+ export function signal(value, options) {
22
+ const [read, write] = createSignal(value, options);
23
+ return Object.assign(read, { set: write });
24
+ }
25
+ export function memo(fn, value, options) {
26
+ return createMemo(fn, value, options);
27
+ }
28
+ /** Run `fn` and re-run it when anything it read changes. Returns its disposer. */
29
+ export function effect(fn, value) {
30
+ return createEffect(fn, value);
31
+ }
@@ -0,0 +1 @@
1
+ var P="__fluixi_signal_next_state__",E=t=>{typeof queueMicrotask=="function"?queueMicrotask(t):Promise.resolve().then(t)},r=globalThis[P]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:E,onSuspend:null,onError:null};var b=0,x=1,d=2,f=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let n=r.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},p=class extends f{constructor(n,e){super(),this._value=n,this._equals=e?.equals===!1?()=>!1:e?.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 e of[...this.observers])e.markDirty(d);w(this)}}peek(){return this._value}},a=class extends f{constructor(e,o){super();this._threw=!1;this._initialized=!1;this.state=d;this.sources=null;this._fn=e,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===x&&this.sources){for(let e of this.sources)if(e.updateIfNecessary(),this.state===d)break}(this.state===d||!this._initialized)&&this.recompute(),this.state=b}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let e=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let s,i=!1,u;try{s=this._fn()}catch(c){i=!0,u=c,s=this._value}finally{r.consumer=e,r.untracked=o}let l=!this._initialized||this._threw!==i||(i?u!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=u,this._value=s,l){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(d);w(this)}}markDirty(e){if(this.state>=e)return;let o=this.state===b;if(this.state=e,o){if(this.observers)for(let s of[...this.observers])s.markDirty(x);w(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function w(t){if(t.watchers)for(let n of[...t.watchers])n._notify(t)}var h=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let e of n)this._watched.add(e),(e.watchers??=new Set).add(this)}unwatch(...n){for(let e of n)this._watched.delete(e),e.watchers?.delete(this),this._pending.delete(e)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let e=this._pending.size===0;this._pending.add(n),e&&this._notifyFn()}};function R(t){return{cleanups:null,owned:null,parent:t,contexts:null}}function S(t){return r.onSuspend?(r.onSuspend(t,r.owner),!0):!1}function g(){return r.owner}function y(t,n){let e=r.owner;r.owner=t;try{return n()}finally{r.owner=e}}function T(t,n=!0){if(!t.disposed){if(t.owned){for(let e=t.owned.length-1;e>=0;e--)T(t.owned[e]);t.owned=null}if(t.cleanups){for(let e=t.cleanups.length-1;e>=0;e--)t.cleanups[e]();t.cleanups=null}n&&(t.disposed=!0)}}function _(t){r.hostSchedule=t??(n=>{Promise.resolve().then(n)})}function N(t){t.queued||(t.queued=!0,r.queue.push(t),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(m)))}function m(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let t=0;try{for(;r.queue.length;){if(++t>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=r.queue;r.queue=[];for(let e of n)e.queued=!1,e.disposed||e.run()}}finally{r.flushing=!1}}function O(){r.batchDepth===0&&m()}var v=class{constructor(n){this.queued=!1;this.disposed=!1;this.owner=R(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new a(()=>{T(this.owner,!1),y(this.owner,()=>{let e=n();typeof e=="function"&&(this.owner.cleanups??=[]).push(e)})}),this.watcher=new h(()=>N(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&r.onSuspend){r.onSuspend(n,this.owner);return}if(r.onError&&r.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),T(this.owner))}};function k(t){let n=new v(t);return()=>n.dispose()}function M(t){return!!t&&typeof t.then=="function"}_(()=>{});var q=Symbol.for("signal"),H=Symbol.for("memo"),j=Symbol.for("signal-node");function C(t,n){let e=new p(t,{equals:n?.equals}),o=(()=>e.get()),s=(i=>{let u=typeof i=="function"?i(e.peek()):i;return e.set(u),O(),u});return Object.defineProperty(o,q,{value:!0,enumerable:!0}),Object.defineProperty(o,j,{value:{get value(){return e.peek()},get version(){return e.version}},enumerable:!1}),[o,s]}function A(t,n,e){let o=n,s=g(),i=new a(()=>y(s,()=>{try{return o=t(o)}catch(l){if(M(l))return S(l),o;throw l}}),{equals:e?.equals}),u=(()=>i.get());return Object.defineProperty(u,q,{value:!0,enumerable:!0}),Object.defineProperty(u,H,{value:!0,enumerable:!0}),u}function D(t,n){let e=n;return k(()=>{e=t(e)})}function J(t,n){let[e,o]=C(t,n);return Object.assign(e,{set:o})}function Q(t,n,e){return A(t,n,e)}function X(t,n){return D(t,n)}export{X as effect,Q as memo,J as signal};
@@ -1 +1 @@
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=t.transport===!1?void 0: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
+ "use strict";var se=Object.defineProperty;var an=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var ln=Object.prototype.hasOwnProperty;var dn=(e,n)=>{for(var t in n)se(e,t,{get:n[t],enumerable:!0})},fn=(e,n,t,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let o of cn(n))!ln.call(e,o)&&o!==t&&se(e,o,{get:()=>n[o],enumerable:!(r=an(n,o))||r.enumerable});return e};var pn=e=>fn(se({},"__esModule",{value:!0}),e);var qn={};dn(qn,{$PROXY:()=>En,$SIGNAL:()=>An,Signal:()=>on,SuspenseContext:()=>oe,__DEV__:()=>X,batch:()=>b,createChildOwner:()=>Re,createComputed:()=>Ie,createContext:()=>q,createDebounce:()=>Qe,createDebouncedResource:()=>Xe,createDebouncedSignal:()=>me,createDeferred:()=>Ye,createEffect:()=>g,createErrorBoundary:()=>tn,createMemo:()=>S,createRenderEffect:()=>Me,createResource:()=>U,createRoot:()=>A,createSelector:()=>Ke,createSignal:()=>d,createSuspenseBoundary:()=>Ze,disposeScope:()=>ke,effect:()=>Pn,flush:()=>Fe,getOwner:()=>L,getServerData:()=>ee,indexArray:()=>gn,isComponent:()=>Ve,isMemo:()=>je,isOwnerDisposed:()=>Oe,isProvider:()=>Le,isResource:()=>Ne,isSignal:()=>J,isSuspense:()=>He,keyArray:()=>xn,makeArrayFlat:()=>de,mapArray:()=>wn,memo:()=>Dn,nextResourceId:()=>ne,on:()=>Be,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>rn,provideSuspense:()=>en,readChildren:()=>Je,reportResourceData:()=>te,resource:()=>sn,runWithOwner:()=>M,setOwner:()=>ae,setResourceDataSink:()=>$e,setResourceIdSource:()=>ze,setResourceTracker:()=>Ge,setServerDataGetter:()=>We,signal:()=>Cn,startTransition:()=>le,trackResourcePromise:()=>Z,untrack:()=>w,useContext:()=>_e,useTransition:()=>Ue});module.exports=pn(qn);var hn="__fluixi_signal_next_state__",Tn=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[hn]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Tn,onSuspend:null,onError:null};var we=0,xe=1,j=2,K=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 K{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(j);ie(this)}}peek(){return this._value}},k=class extends K{constructor(t,r){super();this._threw=!1;this._initialized=!1;this.state=j;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===j)break}(this.state===j||!this._initialized)&&this.recompute(),this.state=we}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(j);ie(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===we;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 ge(){return s.consumer}function be(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function Re(e){let n=H(e);return e&&(e.owned??=[]).push(n),n}function ke(e,n=!0){V(e,n)}function Oe(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 _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 Y(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 Ae(e){s.onSuspend=e}function Ee(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function Ce(e){s.onError=e}function L(){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 A(e){let n=H(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=H(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 Q(e){let n=new ue(e);return()=>n.dispose()}function mn(e){return!!e&&typeof e.then=="function"}De(()=>{});var qe=Symbol.for("signal"),vn=Symbol.for("memo"),Sn=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,Sn,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,o]}function S(e,n,t){let r=n,o=L(),u=new k(()=>M(o,()=>{try{return r=e(r)}catch(c){if(mn(c))return Ee(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,qe,{value:!0,enumerable:!0}),Object.defineProperty(a,vn,{value:!0,enumerable:!0}),a}function g(e,n){let t=n;return Q(()=>{t=e(t)})}function Ie(e,n){let t=n;Q(()=>{t=e(t)})}function Me(e,n){let t=n;return Q(()=>{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,T;A(y=>{T=y;let[E,F]=d(i);p=F,l=n(f,E)});let x={item:f,rendered:l,dispose:T,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 xn(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]),T=c.get(p);if(T&&!h.has(p))T.setIndex(l),i.push(T);else{let x,y,E;A(F=>{E=F;let[O,B]=d(l);y=B;let W=S(C=>{let R=(e()||[])[O()];return R??C},a[l]);x=t(W,O)}),i.push({rendered:x,dispose:E,setIndex:y})}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 gn(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];A(T=>{l=T;let[x,y]=d(p);h=y,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 X=!1,bn=Symbol.for("signal"),Rn=Symbol.for("memo"),kn=Symbol.for("resource");function J(e){return typeof e=="function"&&e[bn]===!0}function je(e){return typeof e=="function"&&e[Rn]===!0}function Ne(e){return typeof e=="function"&&e[kn]===!0}function Ve(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function He(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 Ge(e){fe=e}function Z(e){fe&&fe(e)}var pe=null;function We(e){pe=e}function ee(e){return pe?pe(e):void 0}var he=null;function ze(e){he=e}function ne(){return he?he():void 0}var Te=null;function $e(e){Te=e}function te(e,n){Te&&Te(e,n)}function Ke(e,n=(t,r)=>t===r){let t=new Map;return g(()=>{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 g(()=>{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 On(e){return!!e&&typeof e.then=="function"}var ye=Symbol();function U(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=t.transport===!1?void 0:ne(),a=u!==void 0?ee(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,T]=d(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,y]=d(void 0,{equals:!1}),[E,F]=d(void 0,{equals:!1}),O=ye,B=!1;g(()=>{let m=r();if(E(),m===!1||m===null||m===void 0){O=ye,b(()=>{T("unresolved"),y(void 0),l(void 0)});return}let R=B;if(B=!1,O!==ye&&m===O&&!R)return;if(O=m,c){c=!1;return}let z=!1;v(()=>z=!0);let ve=w(p),un=w(i),Se=ve==="ready"||ve==="refreshing";b(()=>{T(Se?"refreshing":"pending"),l(void 0)});try{let _=o(m,{value:un,refetching:Se});On(_)?(y(_),Z(_),_.then($=>{z||(u!==void 0&&te(u,$),b(()=>{f(()=>$),T("ready"),y(void 0)}))},$=>{z||b(()=>{l($),T("errored"),y(void 0)})})):b(()=>{f(()=>_),T("ready"),y(void 0)})}catch(_){if(z)return;b(()=>{l(_),T("errored"),y(void 0)})}});let W=()=>{let m=p();return m==="pending"||m==="refreshing"},C=(()=>{let m=h();if(m)throw m;if(W()){let R=x();if(R)throw R}return i()});return Object.defineProperties(C,{state:{get:p},loading:{get:W},error:{get:h},latest:{get:i}}),Object.defineProperty(C,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(C,Symbol.for("signal"),{value:!0,enumerable:!0}),[C,{mutate:f,refetch:()=>{B=!0,F(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 T=typeof p=="function"?p(w(t)):p;return r(()=>T),c(!0),f(),i=setTimeout(h,n),T});return v(f),[o,l,{immediate:t,pending:a,flush:h,cancel:()=>{f(),c(!1)}}]}function _n(e){return e!=null&&e!==""}function Xe(e,n,t={}){let{delay:r=300,initialValue:o,shouldFetch:u=_n}=t,[a,c,i]=me(e,r),f=()=>u(a())?a():!1,[h,{refetch:l}]=U(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 J(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();Ae((e,n)=>{let t=Y(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();Ce((e,n)=>{let t=Y(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:ge,hasSinks:be}};var An=Symbol.for("signal"),En=Symbol.for("fluixi-proxy");function Cn(e,n){let[t,r]=d(e,n);return Object.assign(t,{set:r})}function Dn(e,n,t){return S(e,n,t)}function Pn(e,n){return g(e,n)}function sn(...e){let[n,t]=U(...e);return Object.assign(n,t)}
@@ -9,4 +9,7 @@
9
9
  * `@fluixi/reactive/signal-legacy` entry (./index-legacy.ts).
10
10
  */
11
11
  export * from './graph/signal-next.js';
12
+ export * from './api.js';
13
+ export { resource } from './resource-api.js';
14
+ export type { ResourceHandle } from './resource-api.js';
12
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,wBAAwB,CAAC;AAGvC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,YAAY,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC"}
@@ -9,3 +9,6 @@
9
9
  * `@fluixi/reactive/signal-legacy` entry (./index-legacy.ts).
10
10
  */
11
11
  export * from './graph/signal-next.js';
12
+ // The short API — `signal`/`memo`/`effect` over the same primitives.
13
+ export * from './api.js';
14
+ export { resource } from './resource-api.js';
@@ -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,$=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=t.transport===!1?void 0: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};
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 Te=0,ye=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);J(this)}}peek(){return this._value}},b=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===ye&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=Te}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);J(this)}}markDirty(t){if(this.state>=t)return;let r=this.state===Te;if(this.state=t,r){if(this.observers)for(let s of[...this.observers])s.markDirty(ye);J(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function J(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var D=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 j(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 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 N(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 Se(e){o.onSuspend=e}function we(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function xe(e){o.onError=e}function Y(){return o.owner}function ge(e){let n=o.owner;return o.owner=e,n}function V(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 P(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 be(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(H)))}function H(){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 Re(){o.batchDepth===0&&H()}function ee(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&H()}}var Z=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 b(()=>{F(this.owner,!1),V(this.owner,()=>{let t=n();typeof t=="function"&&(this.owner.cleanups??=[]).push(t)})}),this.watcher=new D(()=>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 Q(e){let n=new Z(e);return()=>n.dispose()}function Be(e){return!!e&&typeof e.then=="function"}be(()=>{});var ke=Symbol.for("signal"),je=Symbol.for("memo"),Ne=Symbol.for("signal-node");function d(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),Re(),a});return Object.defineProperty(r,ke,{value:!0,enumerable:!0}),Object.defineProperty(r,Ne,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[r,s]}function S(e,n,t){let r=n,s=Y(),u=new b(()=>V(s,()=>{try{return r=e(r)}catch(c){if(Be(c))return we(c),r;throw c}}),{equals:t?.equals}),a=(()=>u.get());return Object.defineProperty(a,ke,{value:!0,enumerable:!0}),Object.defineProperty(a,je,{value:!0,enumerable:!0}),a}function R(e,n){let t=n;return Q(()=>{t=e(t)})}function Ve(e,n){let t=n;Q(()=>{t=e(t)})}function He(e,n){let t=n;return Q(()=>{t=e(t)})}function k(e){return ee(e)}function w(e){return U(e)}function Oe(e){return ee(e),Promise.resolve()}function Le(){return[()=>!1,Oe]}function Ge(){return H(),Promise.resolve()}function We(e,n,t){let r=Array.isArray(e),s,u=t?.defer??!1;return a=>{let c=r?e.map(f=>f()):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 f=s[i],h=u.get(f);if(h&&!c.has(h))h.setIndex(i),a.push(h),c.add(h);else{let l,p,T;P(y=>{T=y;let[A,q]=d(i);p=q,l=n(f,A)});let x={item:f,rendered:l,dispose:T,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 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=[],f=[],h=new Set;for(let l=0;l<a.length;l++){let p=n(a[l]),T=c.get(p);if(T&&!h.has(p))T.setIndex(l),i.push(T);else{let x,y,A;P(q=>{A=q;let[O,I]=d(l);y=I;let G=S(E=>{let g=(e()||[])[O()];return g??E},a[l]);x=t(G,O)}),i.push({rendered:x,dispose:A,setIndex:y})}f.push(p),h.add(p)}for(let[l,p]of c)h.has(l)||p.dispose();return s=f,u=i,i.map(l=>l.rendered)})})}function Dn(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 f,h,l,p=s[i];P(T=>{l=T;let[x,y]=d(p);h=y,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(s[i]);return r.map(i=>i.rendered)})})}var ne=!1,ze=Symbol.for("signal"),$e=Symbol.for("memo"),Ke=Symbol.for("resource");function te(e){return typeof e=="function"&&e[ze]===!0}function Ye(e){return typeof e=="function"&&e[$e]===!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 re=null;function en(e){re=e}function ue(e){re&&re(e)}var oe=null;function nn(e){oe=e}function ae(e){return oe?oe(e):void 0}var se=null;function tn(e){se=e}function ce(){return se?se():void 0}var ie=null;function rn(e){ie=e}function le(e,n){ie&&ie(e,n)}function on(e,n=(t,r)=>t===r){let t=new Map;return R(()=>{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]=d(!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]=d(e(),n);return R(()=>{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 de=Symbol();function L(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=t.transport===!1?void 0:ce(),a=u!==void 0?ae(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,T]=d(a!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[x,y]=d(void 0,{equals:!1}),[A,q]=d(void 0,{equals:!1}),O=de,I=!1;R(()=>{let m=r();if(A(),m===!1||m===null||m===void 0){O=de,k(()=>{T("unresolved"),y(void 0),l(void 0)});return}let g=I;if(I=!1,O!==de&&m===O&&!g)return;if(O=m,c){c=!1;return}let W=!1;v(()=>W=!0);let pe=w(p),Ce=w(i),he=pe==="ready"||pe==="refreshing";k(()=>{T(he?"refreshing":"pending"),l(void 0)});try{let _=s(m,{value:Ce,refetching:he});an(_)?(y(_),ue(_),_.then(z=>{W||(u!==void 0&&le(u,z),k(()=>{f(()=>z),T("ready"),y(void 0)}))},z=>{W||k(()=>{l(z),T("errored"),y(void 0)})})):k(()=>{f(()=>_),T("ready"),y(void 0)})}catch(_){if(W)return;k(()=>{l(_),T("errored"),y(void 0)})}});let G=()=>{let m=p();return m==="pending"||m==="refreshing"},E=(()=>{let m=h();if(m)throw m;if(G()){let g=x();if(g)throw g}return i()});return Object.defineProperties(E,{state:{get:p},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:f,refetch:()=>{I=!0,q(void 0)}}]}function Ae(e,n=300){let[t,r]=d(e),[s,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 T=typeof p=="function"?p(w(t)):p;return r(()=>T),c(!0),f(),i=setTimeout(h,n),T});return v(f),[s,l,{immediate:t,pending:a,flush:h,cancel:()=>{f(),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]=Ae(e,r),f=()=>u(a())?a():!1,[h,{refetch:l}]=L(f,n,s===void 0?{}:{initialValue:s});return[h,{...i,query:a,setQuery:c,refetch:l}]}function X(e){if(typeof e=="function"&&!e.length){let n=e();return te(n)?n:X(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let r=X(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(()=>X(n()))}var fe=j();Se((e,n)=>{let t=K(n,fe);t&&(t.increment(),e.finally(()=>t.decrement()))});function fn(){let[e,n]=d(0),t=0;return{increment:()=>n(t+=1),decrement:()=>n(t-=1),inFallback:()=>e()>0}}function pn(e,n){return N(fe,e,n)}var Ee=j();xe((e,n)=>{let t=K(n,Ee);return t?(t.setError(e),!0):!1});function hn(){let[e,n]=d(void 0,{equals:!1});return{error:e,reset:()=>n(()=>{}),setError:r=>n(()=>r)}}function Tn(e,n){return N(Ee,e,n)}var yn={State:C,Computed:b,subtle:{Watcher:D,untrack:U,currentComputed:me,hasSinks:ve}};var et=Symbol.for("signal"),nt=Symbol.for("fluixi-proxy");function yt(e,n){let[t,r]=d(e,n);return Object.assign(t,{set:r})}function mt(e,n,t){return S(e,n,t)}function vt(e,n){return R(e,n)}function mn(...e){let[n,t]=L(...e);return Object.assign(n,t)}export{nt as $PROXY,et as $SIGNAL,yn as Signal,fe as SuspenseContext,ne as __DEV__,k as batch,qe as createChildOwner,Ve as createComputed,j as createContext,un as createDebounce,ln as createDebouncedResource,Ae as createDebouncedSignal,sn as createDeferred,R as createEffect,hn as createErrorBoundary,S as createMemo,He as createRenderEffect,L as createResource,P as createRoot,on as createSelector,d as createSignal,fn as createSuspenseBoundary,Ie as disposeScope,vt as effect,Ge as flush,Y as getOwner,ae as getServerData,Dn as indexArray,Xe as isComponent,Ye as isMemo,Me as isOwnerDisposed,Ze as isProvider,Qe as isResource,te as isSignal,Je as isSuspense,Cn as keyArray,_e as makeArrayFlat,En as mapArray,mt as memo,ce as nextResourceId,We as on,v as onCleanup,N as provide,Tn as provideErrorBoundary,pn as provideSuspense,dn as readChildren,le as reportResourceData,mn as resource,V as runWithOwner,ge as setOwner,rn as setResourceDataSink,tn as setResourceIdSource,en as setResourceTracker,nn as setServerDataGetter,yt as signal,Oe as startTransition,ue as trackResourcePromise,w as untrack,Ue as useContext,Le as useTransition};
@@ -0,0 +1 @@
1
+ "use strict";var A=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var de=Object.getOwnPropertyNames;var fe=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)A(e,n,{get:t[n],enumerable:!0})},he=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of de(t))!fe.call(e,s)&&s!==n&&A(e,s,{get:()=>t[s],enumerable:!(o=le(t,s))||o.enumerable});return e};var ve=e=>he(A({},"__esModule",{value:!0}),e);var Re={};pe(Re,{resource:()=>ke});module.exports=ve(Re);var Te="__fluixi_signal_next_state__",we=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[Te]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:we,onSuspend:null,onError:null};var F=0,K=1,v=2,k=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let t=r.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},R=class extends k{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(v);C(this)}}peek(){return this._value}},T=class extends k{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=v;this.sources=null;this._fn=n,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===K&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===v)break}(this.state===v||!this._initialized)&&this.recompute(),this.state=F}recompute(){if(this.sources){for(let c of this.sources)c.observers?.delete(this);this.sources.clear()}let n=r.consumer,o=r.untracked;r.consumer=this,r.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(c){i=!0,a=c,s=this._value}finally{r.consumer=n,r.untracked=o}let w=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,w){if(this.version++,this.observers)for(let c of[...this.observers])c.markDirty(v);C(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===F;if(this.state=n,o){if(this.observers)for(let s of[...this.observers])s.markDirty(K);C(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function C(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var _=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function L(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function ye(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function N(e,t){let n=r.owner;r.owner=e;try{return t()}finally{r.owner=n}}function j(e){if(r.owner){if(r.owner.disposed){e();return}(r.owner.cleanups??=[]).push(e)}}function E(e,t=!0){if(!e.disposed){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)E(e.owned[n]);e.owned=null}if(e.cleanups){for(let n=e.cleanups.length-1;n>=0;n--)e.cleanups[n]();e.cleanups=null}t&&(e.disposed=!0)}}function U(e){r.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function me(e){e.queued||(e.queued=!0,r.queue.push(e),!r.scheduled&&r.batchDepth===0&&(r.scheduled=!0,r.hostSchedule(O)))}function O(){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 t=r.queue;r.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{r.flushing=!1}}function Y(){r.batchDepth===0&&O()}function $(e){r.batchDepth++;try{return e()}finally{--r.batchDepth===0&&O()}}var I=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=ye(r.owner),r.owner&&(r.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new T(()=>{E(this.owner,!1),N(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new _(()=>me(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&r.onSuspend){r.onSuspend(t,this.owner);return}if(r.onError&&r.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),E(this.owner))}};function B(e){let t=new I(e);return()=>t.dispose()}U(()=>{});var Se=Symbol.for("signal");var ge=Symbol.for("signal-node");function h(e,t){let n=new R(e,{equals:t?.equals}),o=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),Y(),a});return Object.defineProperty(o,Se,{value:!0,enumerable:!0}),Object.defineProperty(o,ge,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,s]}function J(e,t){let n=t;return B(()=>{n=e(n)})}function d(e){return $(e)}function V(e){return L(e)}var Q=null;function te(e){Q&&Q(e)}var X=null;function ne(e){return X?X(e):void 0}var Z=null;function re(){return Z?Z():void 0}var ee=null;function oe(e,t){ee&&ee(e,t)}function xe(e){return!!e&&typeof e.then=="function"}var M=Symbol();function se(e,t,n={}){let o,s;typeof t=="function"?(o=typeof e=="function"?e:()=>e,s=t):(o=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=n.transport===!1?void 0:re(),a=i!==void 0?ne(i):void 0,w=a!==void 0,[c,P]=h(a!==void 0?a.value:n.initialValue,{equals:!1}),[G,y]=h(void 0,{equals:!1}),[q,f]=h(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[ie,p]=h(void 0,{equals:!1}),[ue,ae]=h(void 0,{equals:!1}),m=M,D=!1;J(()=>{let u=o();if(ue(),u===!1||u===null||u===void 0){m=M,d(()=>{f("unresolved"),p(void 0),y(void 0)});return}let S=D;if(D=!1,m!==M&&u===m&&!S)return;if(m=u,w){w=!1;return}let g=!1;j(()=>g=!0);let z=V(q),ce=V(c),H=z==="ready"||z==="refreshing";d(()=>{f(H?"refreshing":"pending"),y(void 0)});try{let l=s(u,{value:ce,refetching:H});xe(l)?(p(l),te(l),l.then(x=>{g||(i!==void 0&&oe(i,x),d(()=>{P(()=>x),f("ready"),p(void 0)}))},x=>{g||d(()=>{y(x),f("errored"),p(void 0)})})):d(()=>{P(()=>l),f("ready"),p(void 0)})}catch(l){if(g)return;d(()=>{y(l),f("errored"),p(void 0)})}});let W=()=>{let u=q();return u==="pending"||u==="refreshing"},b=(()=>{let u=G();if(u)throw u;if(W()){let S=ie();if(S)throw S}return c()});return Object.defineProperties(b,{state:{get:q},loading:{get:W},error:{get:G},latest:{get:c}}),Object.defineProperty(b,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(b,Symbol.for("signal"),{value:!0,enumerable:!0}),[b,{mutate:P,refetch:()=>{D=!0,ae(void 0)}}]}function ke(...e){let[t,n]=se(...e);return Object.assign(t,n)}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `resource` — `createResource` as one binding instead of a tuple.
3
+ *
4
+ * const user = resource(userId, fetchUser);
5
+ *
6
+ * user(); // the value — suspends under <Suspense>, exactly as before
7
+ * user.latest; // last settled value, kept across a refetch
8
+ * user.loading; // boolean
9
+ * user.error;
10
+ * user.refetch();
11
+ * user.mutate(next);
12
+ *
13
+ * `createResource` already hands back a callable carrying `loading`/`error`/`latest`,
14
+ * with only the two actions split into a second tuple slot — so this mostly folds that
15
+ * split away.
16
+ *
17
+ * The returned function IS the accessor `createResource` gave back, with the two actions
18
+ * assigned onto it — so suspending, tracking and SSR seeding are untouched, and a read is
19
+ * the same call it always was.
20
+ */
21
+ import { createResource } from './graph/resource.js';
22
+ import type { ResourceActions, ResourceReturn } from './graph/resource.js';
23
+ type ResourceAccessor<T> = ResourceReturn<T>[0];
24
+ export type ResourceHandle<T> = ResourceAccessor<T> & ResourceActions<T>;
25
+ export declare function resource<T>(...args: Parameters<typeof createResource>): ResourceHandle<T>;
26
+ export {};
27
+ //# sourceMappingURL=resource-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource-api.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/resource-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE3E,KAAK,gBAAgB,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEhD,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;AAEzE,wBAAgB,QAAQ,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAMzF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `resource` — `createResource` as one binding instead of a tuple.
3
+ *
4
+ * const user = resource(userId, fetchUser);
5
+ *
6
+ * user(); // the value — suspends under <Suspense>, exactly as before
7
+ * user.latest; // last settled value, kept across a refetch
8
+ * user.loading; // boolean
9
+ * user.error;
10
+ * user.refetch();
11
+ * user.mutate(next);
12
+ *
13
+ * `createResource` already hands back a callable carrying `loading`/`error`/`latest`,
14
+ * with only the two actions split into a second tuple slot — so this mostly folds that
15
+ * split away.
16
+ *
17
+ * The returned function IS the accessor `createResource` gave back, with the two actions
18
+ * assigned onto it — so suspending, tracking and SSR seeding are untouched, and a read is
19
+ * the same call it always was.
20
+ */
21
+ import { createResource } from './graph/resource.js';
22
+ export function resource(...args) {
23
+ const [read, actions] = createResource(...args);
24
+ // Assigned onto the accessor itself, so `loading`/`error`/`latest` stay the live
25
+ // properties createResource put there rather than copies that would latch.
26
+ return Object.assign(read, actions);
27
+ }