@fluixi/reactive 1.0.0-alpha.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +343 -0
- package/dist/cdn/reactive.cjs +1 -0
- package/dist/cdn/reactive.d.ts +11 -0
- package/dist/cdn/reactive.d.ts.map +1 -0
- package/dist/cdn/reactive.global.js +1 -0
- package/dist/cdn/reactive.js +10 -0
- package/dist/cdn/reactive.mjs +1 -0
- package/dist/cdn/signal.cjs +1 -0
- package/dist/cdn/signal.d.ts +19 -0
- package/dist/cdn/signal.d.ts.map +1 -0
- package/dist/cdn/signal.global.js +1 -0
- package/dist/cdn/signal.js +18 -0
- package/dist/cdn/signal.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +4 -0
- package/dist/lib/index.mjs +1 -0
- package/dist/lib/observable/index.cjs +1 -0
- package/dist/lib/observable/index.d.ts +4 -0
- package/dist/lib/observable/index.d.ts.map +1 -0
- package/dist/lib/observable/index.js +3 -0
- package/dist/lib/observable/index.mjs +1 -0
- package/dist/lib/observable/observable.cjs +1 -0
- package/dist/lib/observable/observable.d.ts +383 -0
- package/dist/lib/observable/observable.d.ts.map +1 -0
- package/dist/lib/observable/observable.js +339 -0
- package/dist/lib/observable/observable.mjs +1 -0
- package/dist/lib/observable/subscription.cjs +1 -0
- package/dist/lib/observable/subscription.d.ts +70 -0
- package/dist/lib/observable/subscription.d.ts.map +1 -0
- package/dist/lib/observable/subscription.js +190 -0
- package/dist/lib/observable/subscription.mjs +1 -0
- package/dist/lib/observable/types.cjs +1 -0
- package/dist/lib/observable/types.d.ts +44 -0
- package/dist/lib/observable/types.d.ts.map +1 -0
- package/dist/lib/observable/types.js +1 -0
- package/dist/lib/observable/types.mjs +0 -0
- package/dist/lib/signal/cached-resource.cjs +1 -0
- package/dist/lib/signal/cached-resource.d.ts +94 -0
- package/dist/lib/signal/cached-resource.d.ts.map +1 -0
- package/dist/lib/signal/cached-resource.js +257 -0
- package/dist/lib/signal/cached-resource.mjs +1 -0
- package/dist/lib/signal/graph/children.cjs +1 -0
- package/dist/lib/signal/graph/children.d.ts +2 -0
- package/dist/lib/signal/graph/children.d.ts.map +1 -0
- package/dist/lib/signal/graph/children.js +30 -0
- package/dist/lib/signal/graph/children.mjs +1 -0
- package/dist/lib/signal/graph/compat.cjs +1 -0
- package/dist/lib/signal/graph/compat.d.ts +64 -0
- package/dist/lib/signal/graph/compat.d.ts.map +1 -0
- package/dist/lib/signal/graph/compat.js +178 -0
- package/dist/lib/signal/graph/compat.mjs +1 -0
- package/dist/lib/signal/graph/core.cjs +1 -0
- package/dist/lib/signal/graph/core.d.ts +95 -0
- package/dist/lib/signal/graph/core.d.ts.map +1 -0
- package/dist/lib/signal/graph/core.js +254 -0
- package/dist/lib/signal/graph/core.mjs +1 -0
- package/dist/lib/signal/graph/derived.cjs +1 -0
- package/dist/lib/signal/graph/derived.d.ts +14 -0
- package/dist/lib/signal/graph/derived.d.ts.map +1 -0
- package/dist/lib/signal/graph/derived.js +81 -0
- package/dist/lib/signal/graph/derived.mjs +1 -0
- package/dist/lib/signal/graph/detect.cjs +1 -0
- package/dist/lib/signal/graph/detect.d.ts +16 -0
- package/dist/lib/signal/graph/detect.d.ts.map +1 -0
- package/dist/lib/signal/graph/detect.js +36 -0
- package/dist/lib/signal/graph/detect.mjs +1 -0
- package/dist/lib/signal/graph/error-boundary.cjs +1 -0
- package/dist/lib/signal/graph/error-boundary.d.ts +16 -0
- package/dist/lib/signal/graph/error-boundary.d.ts.map +1 -0
- package/dist/lib/signal/graph/error-boundary.js +34 -0
- package/dist/lib/signal/graph/error-boundary.mjs +1 -0
- package/dist/lib/signal/graph/index.cjs +1 -0
- package/dist/lib/signal/graph/index.d.ts +21 -0
- package/dist/lib/signal/graph/index.d.ts.map +1 -0
- package/dist/lib/signal/graph/index.js +20 -0
- package/dist/lib/signal/graph/index.mjs +1 -0
- package/dist/lib/signal/graph/resource.cjs +1 -0
- package/dist/lib/signal/graph/resource.d.ts +36 -0
- package/dist/lib/signal/graph/resource.d.ts.map +1 -0
- package/dist/lib/signal/graph/resource.js +156 -0
- package/dist/lib/signal/graph/resource.mjs +1 -0
- package/dist/lib/signal/graph/runtime.cjs +1 -0
- package/dist/lib/signal/graph/runtime.d.ts +56 -0
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -0
- package/dist/lib/signal/graph/runtime.js +277 -0
- package/dist/lib/signal/graph/runtime.mjs +1 -0
- package/dist/lib/signal/graph/signal-next.cjs +1 -0
- package/dist/lib/signal/graph/signal-next.d.ts +37 -0
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -0
- package/dist/lib/signal/graph/signal-next.js +41 -0
- package/dist/lib/signal/graph/signal-next.mjs +1 -0
- package/dist/lib/signal/graph/ssr-hooks.cjs +1 -0
- package/dist/lib/signal/graph/ssr-hooks.d.ts +28 -0
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -0
- package/dist/lib/signal/graph/ssr-hooks.js +45 -0
- package/dist/lib/signal/graph/ssr-hooks.mjs +1 -0
- package/dist/lib/signal/graph/state.cjs +1 -0
- package/dist/lib/signal/graph/state.d.ts +43 -0
- package/dist/lib/signal/graph/state.d.ts.map +1 -0
- package/dist/lib/signal/graph/state.js +37 -0
- package/dist/lib/signal/graph/state.mjs +1 -0
- package/dist/lib/signal/graph/suspense.cjs +1 -0
- package/dist/lib/signal/graph/suspense.d.ts +13 -0
- package/dist/lib/signal/graph/suspense.d.ts.map +1 -0
- package/dist/lib/signal/graph/suspense.js +36 -0
- package/dist/lib/signal/graph/suspense.mjs +1 -0
- package/dist/lib/signal/index-legacy.cjs +1 -0
- package/dist/lib/signal/index-legacy.d.ts +12 -0
- package/dist/lib/signal/index-legacy.d.ts.map +1 -0
- package/dist/lib/signal/index-legacy.js +11 -0
- package/dist/lib/signal/index-legacy.mjs +1 -0
- package/dist/lib/signal/index.cjs +1 -0
- package/dist/lib/signal/index.d.ts +12 -0
- package/dist/lib/signal/index.d.ts.map +1 -0
- package/dist/lib/signal/index.js +11 -0
- package/dist/lib/signal/index.mjs +1 -0
- package/dist/lib/signal/list.cjs +1 -0
- package/dist/lib/signal/list.d.ts +39 -0
- package/dist/lib/signal/list.d.ts.map +1 -0
- package/dist/lib/signal/list.js +172 -0
- package/dist/lib/signal/list.mjs +1 -0
- package/dist/lib/signal/signal.cjs +1 -0
- package/dist/lib/signal/signal.d.ts +295 -0
- package/dist/lib/signal/signal.d.ts.map +1 -0
- package/dist/lib/signal/signal.js +1219 -0
- package/dist/lib/signal/signal.mjs +1 -0
- package/dist/lib/signal/types.cjs +1 -0
- package/dist/lib/signal/types.d.ts +133 -0
- package/dist/lib/signal/types.d.ts.map +1 -0
- package/dist/lib/signal/types.js +38 -0
- package/dist/lib/signal/types.mjs +1 -0
- package/dist/lib/signal/utilities.cjs +1 -0
- package/dist/lib/signal/utilities.d.ts +355 -0
- package/dist/lib/signal/utilities.d.ts.map +1 -0
- package/dist/lib/signal/utilities.js +504 -0
- package/dist/lib/signal/utilities.mjs +1 -0
- package/dist/lib/store/index.cjs +1 -0
- package/dist/lib/store/index.d.ts +14 -0
- package/dist/lib/store/index.d.ts.map +1 -0
- package/dist/lib/store/index.js +11 -0
- package/dist/lib/store/index.mjs +1 -0
- package/dist/lib/store/setter.types.cjs +1 -0
- package/dist/lib/store/setter.types.d.ts +79 -0
- package/dist/lib/store/setter.types.d.ts.map +1 -0
- package/dist/lib/store/setter.types.js +65 -0
- package/dist/lib/store/setter.types.mjs +0 -0
- package/dist/lib/store/store.cjs +1 -0
- package/dist/lib/store/store.d.ts +86 -0
- package/dist/lib/store/store.d.ts.map +1 -0
- package/dist/lib/store/store.js +442 -0
- package/dist/lib/store/store.mjs +1 -0
- package/dist/lib/store/types.cjs +1 -0
- package/dist/lib/store/types.d.ts +57 -0
- package/dist/lib/store/types.d.ts.map +1 -0
- package/dist/lib/store/types.js +1 -0
- package/dist/lib/store/types.mjs +0 -0
- package/dist/lib/store/utils.cjs +1 -0
- package/dist/lib/store/utils.d.ts +13 -0
- package/dist/lib/store/utils.d.ts.map +1 -0
- package/dist/lib/store/utils.js +29 -0
- package/dist/lib/store/utils.mjs +1 -0
- package/dist/lib/subject.cjs +1 -0
- package/dist/lib/subject.d.ts +14 -0
- package/dist/lib/subject.d.ts.map +1 -0
- package/dist/lib/subject.js +169 -0
- package/dist/lib/subject.mjs +1 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +114 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SuspenseBoundary {
|
|
2
|
+
increment(): void;
|
|
3
|
+
decrement(): void;
|
|
4
|
+
/** Reactive: true while any descendant read is still pending. */
|
|
5
|
+
inFallback(): boolean;
|
|
6
|
+
}
|
|
7
|
+
declare const SuspenseContext: import("./runtime.js").Context<SuspenseBoundary | undefined>;
|
|
8
|
+
/** Create a boundary's reactive state (pending counter + inFallback). */
|
|
9
|
+
export declare function createSuspenseBoundary(): SuspenseBoundary;
|
|
10
|
+
/** Run `fn` (the boundary's children) under a Suspense scope, so suspended reads inside report to `boundary`. */
|
|
11
|
+
export declare function provideSuspense<R>(boundary: SuspenseBoundary, fn: () => R): R;
|
|
12
|
+
export { SuspenseContext };
|
|
13
|
+
//# sourceMappingURL=suspense.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suspense.d.ts","sourceRoot":"","sources":["../../../../src/lib/signal/graph/suspense.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,gBAAgB;IAC/B,SAAS,IAAI,IAAI,CAAC;IAClB,SAAS,IAAI,IAAI,CAAC;IAClB,iEAAiE;IACjE,UAAU,IAAI,OAAO,CAAC;CACvB;AAED,QAAA,MAAM,eAAe,8DAAgD,CAAC;AAUtE,yEAAyE;AACzE,wBAAgB,sBAAsB,IAAI,gBAAgB,CAQzD;AAED,iHAAiH;AACjH,wBAAgB,eAAe,CAAC,CAAC,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAE7E;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Suspense ported onto the TC39 core (additive; legacy signal.ts untouched).
|
|
3
|
+
*
|
|
4
|
+
* A Suspense boundary is just a context carrying a pending counter. A suspended read
|
|
5
|
+
* (createResource while pending throws its promise) bubbles to the L1 effect's run(),
|
|
6
|
+
* which calls the injected suspend handler registered here — it finds the nearest
|
|
7
|
+
* boundary (via the effect's owner chain) and increments it; the promise settling
|
|
8
|
+
* decrements it. The effect itself re-runs through normal reactivity once the
|
|
9
|
+
* resource's state signal changes, so the resolved content replaces the fallback.
|
|
10
|
+
*/
|
|
11
|
+
import { createContext, provide, readContextFrom, setSuspendHandler, } from './runtime.js';
|
|
12
|
+
import { createSignal } from './compat.js';
|
|
13
|
+
const SuspenseContext = createContext();
|
|
14
|
+
// Wire the L1 effect's suspend path to the nearest boundary. Registered once.
|
|
15
|
+
setSuspendHandler((promise, owner) => {
|
|
16
|
+
const boundary = readContextFrom(owner, SuspenseContext);
|
|
17
|
+
if (!boundary)
|
|
18
|
+
return; // no boundary above → let it stay pending (no crash)
|
|
19
|
+
boundary.increment();
|
|
20
|
+
promise.finally(() => boundary.decrement());
|
|
21
|
+
});
|
|
22
|
+
/** Create a boundary's reactive state (pending counter + inFallback). */
|
|
23
|
+
export function createSuspenseBoundary() {
|
|
24
|
+
const [pending, setPending] = createSignal(0);
|
|
25
|
+
let count = 0;
|
|
26
|
+
return {
|
|
27
|
+
increment: () => setPending((count += 1)),
|
|
28
|
+
decrement: () => setPending((count -= 1)),
|
|
29
|
+
inFallback: () => pending() > 0,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Run `fn` (the boundary's children) under a Suspense scope, so suspended reads inside report to `boundary`. */
|
|
33
|
+
export function provideSuspense(boundary, fn) {
|
|
34
|
+
return provide(SuspenseContext, boundary, fn);
|
|
35
|
+
}
|
|
36
|
+
export { SuspenseContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var b="__fluixi_signal_next_state__",x=n=>{typeof queueMicrotask=="function"?queueMicrotask(n):Promise.resolve().then(n)},r=globalThis[b]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:x,onSuspend:null,onError:null};var S=2,a=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))}},u=class extends a{constructor(e,t){super(),this._value=e,this._equals=t?.equals===!1?()=>!1:t?.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 t of[...this.observers])t.markDirty(S);_(this)}}peek(){return this._value}};function _(n){if(n.watchers)for(let e of[...n.watchers])e._notify(n)}function c(n){return{cleanups:null,owned:null,parent:n,contexts:null}}function d(n){let e=Symbol("context");return{id:e,defaultValue:n,Provider:o=>{let s=r.owner,i=c(s);(i.contexts=new Map).set(e,o.value),s&&(s.owned??=[]).push(i),r.owner=i;try{return o.children}finally{r.owner=s}}}}function f(n,e){let t=n;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function p(n,e,t){let o=c(r.owner);(o.contexts=new Map).set(n.id,e),r.owner&&(r.owner.owned??=[]).push(o);let s=r.owner;r.owner=o;try{return t()}finally{r.owner=s}}function h(n){r.onSuspend=n}function w(n){r.hostSchedule=n??(e=>{Promise.resolve().then(e)})}function v(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let n=0;try{for(;r.queue.length;){if(++n>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let e=r.queue;r.queue=[];for(let t of e)t.queued=!1,t.disposed||t.run()}}finally{r.flushing=!1}}function T(){r.batchDepth===0&&v()}w(()=>{});var g=Symbol.for("signal");var k=Symbol.for("signal-node");function y(n,e){let t=new u(n,{equals:e?.equals}),o=(()=>t.get()),s=(i=>{let l=typeof i=="function"?i(t.peek()):i;return t.set(l),T(),l});return Object.defineProperty(o,g,{value:!0,enumerable:!0}),Object.defineProperty(o,k,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),[o,s]}var m=d();h((n,e)=>{let t=f(e,m);t&&(t.increment(),n.finally(()=>t.decrement()))});function H(){let[n,e]=y(0),t=0;return{increment:()=>e(t+=1),decrement:()=>e(t-=1),inFallback:()=>n()>0}}function V(n,e){return p(m,n,e)}export{m as SuspenseContext,H as createSuspenseBoundary,V as provideSuspense};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var Me=Object.defineProperty;var Kt=Object.getOwnPropertyDescriptor;var $t=Object.getOwnPropertyNames;var Wt=Object.prototype.hasOwnProperty;var zt=(e,t)=>{for(var n in t)Me(e,n,{get:t[n],enumerable:!0})},Ht=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of $t(t))!Wt.call(e,r)&&r!==n&&Me(e,r,{get:()=>t[r],enumerable:!(o=Kt(t,r))||o.enumerable});return e};var Yt=e=>Ht(Me({},"__esModule",{value:!0}),e);var or={};zt(or,{$MEMO:()=>Pt,$PROXY:()=>Ze,$RESOURCE:()=>Ft,$SIGNAL:()=>De,__DEV__:()=>de,batch:()=>k,clearAllCachedResources:()=>er,clearCachedResourceNamespace:()=>Zn,combineSignal:()=>In,combineSignals:()=>Nn,createCachedResource:()=>Qn,createComputed:()=>wn,createContext:()=>ot,createDebounce:()=>Ot,createDeferred:()=>wt,createEffect:()=>te,createMemo:()=>hn,createProvider:()=>Lt,createRenderEffect:()=>Vt,createResource:()=>yn,createRoot:()=>vn,createSelector:()=>gt,createSignal:()=>U,debounceSignal:()=>Wn,distinctSignal:()=>Mn,everySignal:()=>Dn,filterSignal:()=>kn,findSignal:()=>Fn,flush:()=>xn,getOwner:()=>bn,getServerData:()=>Ye,getSharedConfig:()=>dn,getSuspenseContext:()=>st,getSuspenseListContext:()=>On,guardSignal:()=>$n,indexArray:()=>rr,isComponent:()=>lt,isMemo:()=>at,isProvider:()=>dt,isResource:()=>ct,isSignal:()=>we,isSuspense:()=>ft,keyArray:()=>nr,makeArrayFlat:()=>Le,mapArray:()=>tr,mapSignal:()=>En,mergeSignal:()=>Ln,nextResourceId:()=>Je,omitSignal:()=>Gn,on:()=>gn,onCleanup:()=>be,onResolve:()=>An,pickSignal:()=>jn,readChildren:()=>Ke,readSignal:()=>Hn,reduceSignal:()=>Pn,reportResourceData:()=>Xe,resumeEffects:()=>Rn,runWithOwner:()=>mn,selectSignal:()=>Vn,setOwner:()=>fn,setResourceDataSink:()=>_t,setResourceIdSource:()=>Ct,setResourceTracker:()=>Rt,setScheduler:()=>Cn,setServerDataGetter:()=>At,sharedConfig:()=>Ue,someSignal:()=>Un,sortSignal:()=>qn,startTransition:()=>Bt,throttleSignal:()=>zn,trackPromise:()=>_n,trackResourcePromise:()=>ve,untrack:()=>L,useContext:()=>I,useTransition:()=>Sn,whenSignal:()=>Kn,zipSignal:()=>Bn});module.exports=Yt(or);var ut=require("@fluixi/utils/object"),Ie=require("@fluixi/utils/functions"),fe=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if((0,Ie.isFunction)(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if((0,ut.isObject)(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if((0,Ie.isFunction)(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var ge=class extends fe{constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ne=class extends ge{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof ge?r=t:r=new Ne(t,n,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};var me=require("@fluixi/utils");var de=!1,Jt=Symbol.for("signal"),Xt=Symbol.for("memo"),Qt=Symbol.for("resource");function we(e){return typeof e=="function"&&e[Jt]===!0}function at(e){return typeof e=="function"&&e[Xt]===!0}function ct(e){return typeof e=="function"&&e[Qt]===!0}function lt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function ft(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function dt(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Zt="__fluixi_signal_next_state__",en=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},l=globalThis[Zt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:en,onSuspend:null,onError:null};var pt=0,Tt=1,pe=2,Oe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(l.untracked)return;let t=l.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},Re=class extends Oe{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(pe);Be(this)}}peek(){return this._value}},ue=class extends Oe{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=pe;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(l.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===Tt&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===pe)break}(this.state===pe||!this._initialized)&&this.recompute(),this.state=pt}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=l.consumer,o=l.untracked;l.consumer=this,l.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{l.consumer=n,l.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(pe);Be(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===pt;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(Tt);Be(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Be(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var Ae=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 ht(e){if(l.untracked)return e();l.untracked=!0;try{return e()}finally{l.untracked=!1}}function vt(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function yt(e){return l.onSuspend?(l.onSuspend(e,l.owner),!0):!1}function je(){return l.owner}function _e(e,t){let n=l.owner;l.owner=e;try{return t()}finally{l.owner=n}}function ee(e){l.owner&&(l.owner.cleanups??=[]).push(e)}function Ce(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)Ce(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function Te(e){let t=vt(l.owner);l.owner&&(l.owner.owned??=[]).push(t);let n=l.owner;l.owner=t;try{return e(()=>Ce(t))}finally{l.owner=n}}function bt(e){l.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function tn(e){e.queued||(e.queued=!0,l.queue.push(e),!l.scheduled&&l.batchDepth===0&&(l.scheduled=!0,l.hostSchedule(Ge)))}function Ge(){if(l.scheduled=!1,l.flushing)return;l.flushing=!0;let e=0;try{for(;l.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=l.queue;l.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{l.flushing=!1}}function mt(){l.batchDepth===0&&Ge()}var Ve=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=vt(l.owner),l.owner&&(l.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ue(()=>{Ce(this.owner),_e(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new Ae(()=>tn(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"&&l.onSuspend){l.onSuspend(t,this.owner);return}if(l.onError&&l.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),Ce(this.owner))}};function xt(e){let t=new Ve(e);return()=>t.dispose()}function nn(e){return!!e&&typeof e.then=="function"}bt(()=>{});var St=Symbol.for("signal"),rn=Symbol.for("memo"),on=Symbol.for("signal-node");function N(e,t){let n=new Re(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let u=typeof s=="function"?s(n.peek()):s;return n.set(u),mt(),u});return Object.defineProperty(o,St,{value:!0,enumerable:!0}),Object.defineProperty(o,on,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function x(e,t,n){let o=t,r=je(),s=new ue(()=>_e(r,()=>{try{return o=e(o)}catch(a){if(nn(a))return yt(a),o;throw a}}),{equals:n?.equals}),u=(()=>s.get());return Object.defineProperty(u,St,{value:!0,enumerable:!0}),Object.defineProperty(u,rn,{value:!0,enumerable:!0}),u}function he(e,t){let n=t;return xt(()=>{n=e(n)})}function Ee(e){return ht(e)}function gt(e,t=(n,o)=>n===o){let n=new Map;return he(()=>{let o=e();for(let[r,s]of n){let[u,a]=s,i=t(r,o);u()!==i&&a(i)}}),o=>{let r=n.get(o);if(!r){let[s,u]=N(!1);r=[s,u],n.set(o,r);let a=e();u(t(o,a))}return r[0]()}}function wt(e,t){let[n,o]=N(e(),t);return he(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function Ot(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,r.length>0){let s=r[r.length-1];typeof s=="object"&&s&&!s.tagName&&s.target&&s.target.tagName&&(s=s.target),s&&typeof s=="object"&&s.tagName&&(s.tagName.toLowerCase()==="input"||s.tagName.toLowerCase()==="textarea")&&s.focus()}e(...r)},t)};return ee(()=>{n!==void 0&&clearTimeout(n)}),o}function ke(e){if(typeof e=="function"&&!e.length){let t=e();return we(t)?t:ke(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=ke(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function Ke(e){let t=x(e);return x(()=>ke(t()))}var $e=null;function Rt(e){$e=e}function ve(e){$e&&$e(e)}var We=null;function At(e){We=e}function Ye(e){return We?We(e):void 0}var ze=null;function Ct(e){ze=e}function Je(){return ze?ze():void 0}var He=null;function _t(e){He=e}function Xe(e,t){He&&He(e,t)}var De=Symbol.for("signal"),Pt=Symbol.for("memo"),Ft=Symbol.for("resource"),Ze=Symbol("fluixi-proxy"),Ut=Symbol.for("signal-node"),K=0,ye=1,W=2,$=3,f=null,v=null,c=null,Pe=null,Fe=0,sn=!1,Qe=!1,ae=0,un=1e6,F=new WeakMap,M=null;var an=null,cn=new Map,ln=0,Ue={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function fn(e){f=e,Ue.owner=e,Ue.context=e}function dn(){return Ue}function pn(){return`node_${++ln}_${Date.now()}`}function Tn(e){!1}function Dt(e,t,n){let o={id:pn(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return Tn(o),o}function qt(e,t){return e===t}function nt(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var et=null,tt=null;function Mt(){if(!et){let[e,t]=U(!1);et=e,tt=t}}function It(e){if(c)c.indexOf(e)===-1&&c.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)xe(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=c;v=null,c=[],e.accessor(),v=t;let o=c;if(c=n,o.length>0){let r=c;qe(o),c=r}}}function Et(e,t){for(let n=0;n<e.length;n++)t(e[n])}function U(e,t){let n=e;typeof n=="object"&&n&&Ze in n&&delete n[Ze];let o=Dt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[u,a];F.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=F.get(r);d&&!d.has(i)&&d.add(i)}return n}function a(i){let d=typeof i=="function"?i(n):i,y=o.equals||qt;if(t?.equals===!1||!y(n,d)){n=d,o.value=d,o.version++,o.updated=Date.now();let g=F.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===$&&p===v)){if(b&&!p.pure){C===K&&(p.state=ye,sn&&(c!==null&&c.indexOf(p)===-1?c.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=W,C===K||C===ye?w.push(p):!p.pure&&c!==null&&c.indexOf(p)===-1&&c.push(p),p.pure&&p.accessor)){let P=F.get(p.accessor);P&&Et(Array.from(P),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;Et(S,E);for(let p of w)It(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return te(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,De,{value:!0,enumerable:!0}),Object.defineProperty(u,Ut,{value:o,enumerable:!1}),r}function te(e,t,n){let o={fn:e,state:W,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),rt(o,t),()=>J(o)}function rt(e,t){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,o=f;if(v=e,f=e,Fe++,Fe>un)throw Fe=0,v=n,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=$;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}nt(r)}finally{v=n,f=o}}function xe(e){if(!(e.disposed||!e.fn||e.state===K)&&(e.state===W||e.state===ye||e.state===$)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)J(e.owned[t]);e.owned=null}e.renderEffect?jt(e):rt(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=F.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)J(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function hn(e,t,n){let o=Dt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:W,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;F.has(a)||F.set(a,new Set);let i=F.get(a);i&&i.add(v)}if(r.state!==K){if(r.sources){for(let d of r.sources){let y=F.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=$;try{let d=r.fn(r.value),y=o.equals||qt;if(n?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=F.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let P=b.state;if(P!==$){if(C&&!b.pure){P===K&&(b.state=ye,c!==null&&c.indexOf(b)===-1?c.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=W,P===K||P===ye?m.push(b):!b.pure&&c!==null&&c.indexOf(b)===-1&&c.push(b),b.pure&&b.accessor)){let _=F.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)It(b)}}r.state===$&&(r.state=K)}catch(d){if((0,me.isPromise)(d)){let y=O&&I(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}nt(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,F.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return te(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,De,{value:!0,enumerable:!0}),Object.defineProperty(s,Pt,{value:!0,enumerable:!0}),Object.defineProperty(s,Ut,{value:o,enumerable:!1}),s}function qe(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);c=[];let o=0;for(;o<t.length;){let r=t[o++],s=F.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=c.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?t.indexOf(a)===-1&&t.push(a):(a.computed||!a.pure)&&n.indexOf(a)===-1&&n.push(a)}c=null;for(let r of n)(r.computed||!r.pure)&&xe(r)}function k(e){if(c&&ae>0)return e();if(c&&ae===0){let t=c,n=[];c=n,ae++;let o;try{o=e()}finally{ae--,c=t}let r=c;return qe(n),c=r,o}ae++,c=[],Pe=[];try{return e()}finally{ae--,Nt()}}function Nt(){if(!Qe){Qe=!0,Fe=0;try{for(;c&&c.length>0;){let e=c;c=null,qe(e)}if(c=null,Pe){let e=Pe;Pe=null;for(let t=0;t<e.length;t++)xe(e[t])}}finally{Qe=!1}}}function vn(e){let t={owned:null,cleanups:null,contexts:null,owner:f},n=v;v=null;let o=f;f=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)J(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{f=o,v=n}}function L(e){let t=v;v=null;try{return e()}finally{v=t}}function be(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function yn(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:u}=n,a=Je(),i=a!==void 0?Ye(a):void 0,d=i!==void 0,[y,T]=U(i!==void 0?i.value:n.initialValue,{equals:!1}),[g,S]=U(void 0,{equals:!1}),[w,m]=U(i!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),P=Symbol(),_=P,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(B){console.error(`Failed to save resource to cache (${u}):`,B)}},ce=te(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=P,k(()=>{m("unresolved"),p(void 0),S(void 0)});return}let B=z;if(z=!1,_!==P&&A===_&&!B)return;if(_=A,d){d=!1;return}let V=!1;be(()=>V=!0);let le=L(w),oe=L(y),Q=le==="ready"||le==="refreshing";k(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let j=r(A,{value:oe,refetching:Q});if((0,me.isPromise)(j)){p(j),ve(j),j.then(h=>{V||(a!==void 0&&Xe(a,h),k(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{V||k(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{V||k(()=>{S(h),m("errored"),p(void 0)})});let Se=O&&I(O);Se&&(Se.increment(),j.finally(()=>Se.decrement()))}else{if(V)return;k(()=>{T(()=>j),m("ready"),p(void 0)})}}catch(j){if(V)return;k(()=>{S(j),m("errored"),p(void 0)})}});be(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let B=E();if(B)throw B}return y()});return Object.defineProperty(Y,Ft,{value:!0,enumerable:!0}),Object.defineProperty(Y,De,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function bn(){return f}function mn(e,t){let n=f,o=v;f=e,v=null;try{return t()}finally{f=n,v=o}}function ot(e){let t=Symbol("context"),n=Lt(t);return{id:t,Provider:n,defaultValue:e}}function Lt(e){return t=>{let n=f;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return Vt(()=>{o=L(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),Ke(()=>t.children)})}),o}}function I(e){let t=f;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function xn(){return new Promise(e=>{queueMicrotask(()=>{Nt(),e()})})}function Bt(e){if(M&&M.running)return e(),M.done;Mt();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};M=o;try{e()}finally{o.running=!1}return o.effects.length?(tt(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,tt(!1),r.length&&k(()=>{for(let s of r)s.state=W,xe(s)}),t()}),n):(M=null,t(),n)}function Sn(){return Mt(),[et,Bt]}function gn(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):L(()=>t(u,s))}}function Vt(e,t,n){let o={fn:e,state:W,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&I(O);return r&&(o.suspense=r),jt(o),()=>J(o)}function jt(e){if(e.sources){for(let r of e.sources){let s=F.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,n=f,o=c;v=e,f=e,c===null&&(c=[]),e.state=$;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===$&&(e.state=K)}catch(r){if((0,me.isPromise)(r)){let s=O&&I(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}nt(r)}finally{v=t,f=n;let r=c;if(c=o,r!==o&&r&&r.length>0){let s=c;qe(r),c=s}}}function wn(e,t,n){let o={fn:e,state:W,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(c||(c=[]),c.indexOf(o)===-1&&c.push(o)):c?c.indexOf(o)===-1&&c.push(o):rt(o,t)}var O;function st(){return O||(O=ot())}var kt;function On(){return kt||(kt=ot())}function Rn(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=W,xe(n)}function An(e){let t=O&&I(O);t&&t.inFallback()?te(()=>{t.inFallback()||e()}):e()}function Cn(e){an=e}function _n(e){let t=O&&I(O);return t&&(t.increment(),e.finally(()=>t.decrement())),e}function En(e,t,n){return x(()=>t(e()),void 0,n)}function kn(e,t,n){return x(()=>e().filter(t),void 0,n)}function Pn(e,t,n,o){return x(()=>e().reduce(t,n),void 0,o)}function Fn(e,t,n){return x(()=>e().find(t),void 0,n)}function Un(e,t,n){return x(()=>e().some(t),void 0,n)}function Dn(e,t,n){return x(()=>e().every(t),void 0,n)}function qn(e,t,n){return x(()=>[...e()].sort(t),void 0,n)}function Mn(e,t){return x(()=>[...new Set(e())],void 0,t)}function In(e,t,n){return x(()=>{let o=e.map(r=>r());return t(o)},void 0,n)}function Nn(...e){return new Z(t=>{let n=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{t.next(n())}):typeof r!="function"?r.subscribe(()=>{t.next(n())}):he(()=>{t.next(n())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function Ln(e,t,n){return x(()=>e()||t(),void 0,n)}function Bn(e,t,n,o){return x(()=>n(e(),t()),void 0,o)}function Vn(e,t,n){return x(()=>t(e()),void 0,{equals:n,internal:!0})}function jn(e,t,n){return x(()=>{let o=e(),r={};for(let s of t)r[s]=o[s];return r},void 0,n)}function Gn(e,t,n){return x(()=>{let r={...e()};for(let s of t)delete r[s];return r},void 0,n)}function Kn(e,t,n,o){return x(()=>e()?t():n(),void 0,o)}function $n(e,t,n){return x(()=>e()?t():void 0,void 0,n)}function Wn(e,t,n){let[o,r]=N(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),t)}),o}function zn(e,t,n){let[o,r]=N(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=t?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},t-(i-s)))}),o}function Hn(e){let t=e;for(;typeof t=="function";)t=t();return t}var re=new Map,ne=new Map,Yn=0,Jn=Symbol.for("signal"),Xn=Symbol.for("resource");function Qn(e,t,n={}){let o,r,s;typeof t=="function"?(o=e,r=t,s=n):(o=()=>!0,r=e,s=t??n);let{ttl:u=1/0,name:a=`_auto_${Yn++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=U(void 0,{equals:!1}),[w,m]=U("unresolved",{equals:!1}),[E,p]=U(void 0,{equals:!1}),[b,C]=U(void 0,{equals:!1}),[P,_]=U(!1),[z,H]=U(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function B(h,D,q,G){if(ne.has(D)){ne.get(D).then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)}),q||C(ne.get(D));return}let se=Promise.resolve(r(h)).then(R=>(re.set(D,{value:R,timestamp:Date.now()}),ne.delete(D),R),R=>{throw ne.delete(D),R});if(ne.set(D,se),!q){ve(se),C(se);let R=oe&&I(oe);R&&(R.increment(),se.finally(()=>R.decrement()))}se.then(R=>{G()||V(R,q)},R=>{!G()&&!q&&le(R)})}function V(h,D){k(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){k(()=>{p(h),m("errored"),C(void 0)})}let oe;te(()=>{oe===void 0&&(oe=st());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,k(()=>{m("unresolved"),C(void 0),p(void 0)});return}let D=Y,q=A;Y=!1,A=!1;let G=y(h);q&&re.delete(G);let se=X===ce||h!==X;X=h;let R=!1;be(()=>{R=!0});let ie=re.get(G);if(ie&&T(ie)&&!D&&!q){(L(w)!=="ready"||L(g)!==ie.value)&&k(()=>{S(()=>ie.value),m("ready"),_(!1),p(void 0)});return}if(ie&&i&&!q){k(()=>{S(()=>ie.value),m("ready"),_(!0),p(void 0),C(void 0)}),B(h,G,!0,()=>R);return}let it=L(w),Gt=it==="ready"||it==="refreshing";k(()=>{m(Gt?"refreshing":"pending"),p(void 0),_(!1)}),B(h,G,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let q=b();if(q)throw q}return g()});return Object.defineProperty(Q,Xn,{value:!0,enumerable:!0}),Object.defineProperty(Q,Jn,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:P}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=L(o);h!=null&&h!==!1&&re.delete(y(h)),A=!0,H(D=>D+1)}}]}function Zn(e){let t=`${e}:`;for(let n of re.keys())n.startsWith(t)&&re.delete(n)}function er(){re.clear(),ne.clear()}function tr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;Te(m=>{S=m;let[E,p]=N(i);g=p,T=t(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function nr(e,t,n,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Ee(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=t(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;Te(p=>{E=p;let[b,C]=N(T);m=C;let P=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=n(P,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function rr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Ee(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];Te(S=>{T=S;let[w,m]=N(g);y=m,d=t(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legacy (pre-TC39) reactive core — available ONLY at `@fluixi/reactive/signal-legacy`.
|
|
3
|
+
*
|
|
4
|
+
* `@fluixi/reactive/signal` (and the relative `./index.js`) now resolve to the TC39 core
|
|
5
|
+
* (see ./index.ts). This module keeps the original implementation intact as an explicit
|
|
6
|
+
* opt-out / fallback. Nothing here is changed; it is the former contents of ./index.ts.
|
|
7
|
+
*/
|
|
8
|
+
export * from './signal.js';
|
|
9
|
+
export * from './utilities.js';
|
|
10
|
+
export * from './cached-resource.js';
|
|
11
|
+
export * from './list.js';
|
|
12
|
+
//# sourceMappingURL=index-legacy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-legacy.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/index-legacy.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The legacy (pre-TC39) reactive core — available ONLY at `@fluixi/reactive/signal-legacy`.
|
|
3
|
+
*
|
|
4
|
+
* `@fluixi/reactive/signal` (and the relative `./index.js`) now resolve to the TC39 core
|
|
5
|
+
* (see ./index.ts). This module keeps the original implementation intact as an explicit
|
|
6
|
+
* opt-out / fallback. Nothing here is changed; it is the former contents of ./index.ts.
|
|
7
|
+
*/
|
|
8
|
+
export * from './signal.js';
|
|
9
|
+
export * from './utilities.js';
|
|
10
|
+
export * from './cached-resource.js';
|
|
11
|
+
export * from './list.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObject as Rt}from"@fluixi/utils/object";import{isFunction as Xe}from"@fluixi/utils/functions";var fe=class e{constructor(t){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;t&&(this._subscriptions=[t])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:t,_subscriptions:n}=this;if(t instanceof e)t.remove(this);else if(t!==null)for(let o of t)o.remove(this);if(n){for(let o of n)if(Xe(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(Rt(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(t){if(!t||t===this)return this;if(t.closed)return this;let{_closed:n,_subscriptions:o}=this;if(n){if(Xe(t))try{t()}catch(r){console.error("Error in unsubscribe function:",r)}else if(t.unsubscribe)try{t.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(t),t instanceof e&&t._addParent(this),this}remove(t){let{_subscriptions:n}=this;if(!n)return;let o=n.indexOf(t);o!==-1&&(n.splice(o,1),t._removeParent(this))}_addParent(t){let{_parentOrParents:n}=this;n?Array.isArray(n)?n.push(t):this._parentOrParents=[n,t]:this._parentOrParents=t}_removeParent(t){let{_parentOrParents:n}=this;if(n===t)this._parentOrParents=null;else if(Array.isArray(n)){let o=n.indexOf(t);o!==-1&&(n.splice(o,1),n.length===1&&(this._parentOrParents=n[0]))}}};var be=class extends fe{constructor(n,o,r){super();this.isStopped=!1;let s;n?typeof n=="object"?s=n:s={next:n,error:o,complete:r}:s={},this.destination=s}next(n){if(!this.isStopped&&this.destination.next)try{this.destination.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(n)}catch(o){throw o}else throw n;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(n){this.error(n);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},Ue=class extends be{constructor(n,o,r,s){super(n,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(n){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(n)}catch(o){this.error(o)}}error(n){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(n)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Z=class extends fe{constructor(t){if(super(),t)this._subscribe=t;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(t,n,o){let r;t instanceof be?r=t:r=new Ue(t,n,o);let{_subscribe:s}=this;try{let u=s.call(this,r);u&&(typeof u=="function"||typeof u.unsubscribe=="function")&&r.add(u)}catch(u){r.error(u)}return r}pipe(...t){return t.length===0?this:t.reduce((n,o)=>o(n),this)}toPromise(){return new Promise((t,n)=>{let o;this.subscribe({next:r=>o=r,error:n,complete:()=>t(o)})})}};import{isPromise as Pe}from"@fluixi/utils";var me=!1,At=Symbol.for("signal"),Ct=Symbol.for("memo"),_t=Symbol.for("resource");function De(e){return typeof e=="function"&&e[At]===!0}function Et(e){return typeof e=="function"&&e[Ct]===!0}function kt(e){return typeof e=="function"&&e[_t]===!0}function Pt(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ft(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ut(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function Qe(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?Qe(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var Dt="__fluixi_signal_next_state__",qt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},l=globalThis[Dt]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:qt,onSuspend:null,onError:null};var Ze=0,et=1,de=2,xe=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(l.untracked)return;let t=l.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},Se=class extends xe{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(de);qe(this)}}peek(){return this._value}},ie=class extends xe{constructor(n,o){super();this._threw=!1;this._initialized=!1;this.state=de;this.sources=null;this._fn=n,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(l.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===et&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===de)break}(this.state===de||!this._initialized)&&this.recompute(),this.state=Ze}recompute(){if(this.sources){for(let i of this.sources)i.observers?.delete(this);this.sources.clear()}let n=l.consumer,o=l.untracked;l.consumer=this,l.untracked=!1;let r,s=!1,u;try{r=this._fn()}catch(i){s=!0,u=i,r=this._value}finally{l.consumer=n,l.untracked=o}let a=!this._initialized||this._threw!==s||(s?u!==this._error:!this._equals(this._value,r));if(this._initialized=!0,this._threw=s,this._error=u,this._value=r,a){if(this.version++,this.observers)for(let i of[...this.observers])i.markDirty(de);qe(this)}}markDirty(n){if(this.state>=n)return;let o=this.state===Ze;if(this.state=n,o){if(this.observers)for(let r of[...this.observers])r.markDirty(et);qe(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function qe(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var ge=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function tt(e){if(l.untracked)return e();l.untracked=!0;try{return e()}finally{l.untracked=!1}}function nt(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function rt(e){return l.onSuspend?(l.onSuspend(e,l.owner),!0):!1}function Ie(){return l.owner}function Oe(e,t){let n=l.owner;l.owner=e;try{return t()}finally{l.owner=n}}function ee(e){l.owner&&(l.owner.cleanups??=[]).push(e)}function we(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)we(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function pe(e){let t=nt(l.owner);l.owner&&(l.owner.owned??=[]).push(t);let n=l.owner;l.owner=t;try{return e(()=>we(t))}finally{l.owner=n}}function ot(e){l.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function Mt(e){e.queued||(e.queued=!0,l.queue.push(e),!l.scheduled&&l.batchDepth===0&&(l.scheduled=!0,l.hostSchedule(Ne)))}function Ne(){if(l.scheduled=!1,l.flushing)return;l.flushing=!0;let e=0;try{for(;l.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=l.queue;l.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{l.flushing=!1}}function st(){l.batchDepth===0&&Ne()}var Me=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=nt(l.owner),l.owner&&(l.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new ie(()=>{we(this.owner),Oe(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new ge(()=>Mt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&l.onSuspend){l.onSuspend(t,this.owner);return}if(l.onError&&l.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),we(this.owner))}};function it(e){let t=new Me(e);return()=>t.dispose()}function It(e){return!!e&&typeof e.then=="function"}ot(()=>{});var ut=Symbol.for("signal"),Nt=Symbol.for("memo"),Lt=Symbol.for("signal-node");function I(e,t){let n=new Se(e,{equals:t?.equals}),o=(()=>n.get()),r=(s=>{let u=typeof s=="function"?s(n.peek()):s;return n.set(u),st(),u});return Object.defineProperty(o,ut,{value:!0,enumerable:!0}),Object.defineProperty(o,Lt,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[o,r]}function x(e,t,n){let o=t,r=Ie(),s=new ie(()=>Oe(r,()=>{try{return o=e(o)}catch(a){if(It(a))return rt(a),o;throw a}}),{equals:n?.equals}),u=(()=>s.get());return Object.defineProperty(u,ut,{value:!0,enumerable:!0}),Object.defineProperty(u,Nt,{value:!0,enumerable:!0}),u}function Te(e,t){let n=t;return it(()=>{n=e(n)})}function Re(e){return tt(e)}function Bt(e,t=(n,o)=>n===o){let n=new Map;return Te(()=>{let o=e();for(let[r,s]of n){let[u,a]=s,i=t(r,o);u()!==i&&a(i)}}),o=>{let r=n.get(o);if(!r){let[s,u]=I(!1);r=[s,u],n.set(o,r);let a=e();u(t(o,a))}return r[0]()}}function Vt(e,t){let[n,o]=I(e(),t);return Te(()=>{let r=e();t?.timeoutMs?setTimeout(()=>o(()=>r),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),n}function jt(e,t){let n,o=(...r)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,r.length>0){let s=r[r.length-1];typeof s=="object"&&s&&!s.tagName&&s.target&&s.target.tagName&&(s=s.target),s&&typeof s=="object"&&s.tagName&&(s.tagName.toLowerCase()==="input"||s.tagName.toLowerCase()==="textarea")&&s.focus()}e(...r)},t)};return ee(()=>{n!==void 0&&clearTimeout(n)}),o}function Ae(e){if(typeof e=="function"&&!e.length){let t=e();return De(t)?t:Ae(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let o=Ae(e[n]);Array.isArray(o)?t.push.apply(t,o):t.push(o)}return t}return e}function at(e){let t=x(e);return x(()=>Ae(t()))}var Le=null;function Gt(e){Le=e}function Ce(e){Le&&Le(e)}var Be=null;function Kt(e){Be=e}function ct(e){return Be?Be(e):void 0}var Ve=null;function $t(e){Ve=e}function lt(){return Ve?Ve():void 0}var je=null;function Wt(e){je=e}function ft(e,t){je&&je(e,t)}var ze=Symbol.for("signal"),zt=Symbol.for("memo"),Ht=Symbol.for("resource"),dt=Symbol("fluixi-proxy"),ht=Symbol.for("signal-node"),G=0,he=1,$=2,K=3,f=null,v=null,c=null,_e=null,Ee=0,Yt=!1,Ge=!1,ue=0,Jt=1e6,P=new WeakMap,M=null;var Xt=null,Qt=new Map,Zt=0,Ke={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Ln(e){f=e,Ke.owner=e,Ke.context=e}function Bn(){return Ke}function en(){return`node_${++Zt}_${Date.now()}`}function tn(e){!1}function vt(e,t,n){let o={id:en(),type:e,value:t,version:0,equals:n?.equals,name:n?.name,created:Date.now(),updated:Date.now()};return tn(o),o}function yt(e,t){return e===t}function He(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var $e=null,We=null;function bt(){if(!$e){let[e,t]=q(!1);$e=e,We=t}}function mt(e){if(c)c.indexOf(e)===-1&&c.push(e);else if(M&&M.running&&!e.pure)M.effects.indexOf(e)===-1&&M.effects.push(e);else if(!e.pure||e.computed)ve(e);else if(e.pure&&!e.computed&&e.accessor){let t=v,n=c;v=null,c=[],e.accessor(),v=t;let o=c;if(c=n,o.length>0){let r=c;Fe(o),c=r}}}function pt(e,t){for(let n=0;n<e.length;n++)t(e[n])}function q(e,t){let n=e;typeof n=="object"&&n&&dt in n&&delete n[dt];let o=vt("signal",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r=[u,a];P.set(r,new Set);let s;function u(){let i=v;if(i){i.sources?i.sources.indexOf(r)===-1&&i.sources.push(r):i.sources=[r];let d=P.get(r);d&&!d.has(i)&&d.add(i)}return n}function a(i){let d=typeof i=="function"?i(n):i,y=o.equals||yt;if(t?.equals===!1||!y(n,d)){n=d,o.value=d,o.version++,o.updated=Date.now();let g=P.get(r);if(g&&g.size>0){let E=function(p,b=!1){let C=p.state;if(!(C===K&&p===v)){if(b&&!p.pure){C===G&&(p.state=he,Yt&&(c!==null&&c.indexOf(p)===-1?c.push(p):w.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=$,C===G||C===he?w.push(p):!p.pure&&c!==null&&c.indexOf(p)===-1&&c.push(p),p.pure&&p.accessor)){let k=P.get(p.accessor);k&&pt(Array.from(k),_=>E(_,!0))}}};var T=E;let S=Array.from(g),w=[],m=new Set;pt(S,E);for(let p of w)mt(p)}}}return u.toObservable=()=>new Z(i=>{let d=!0;return ae(()=>{let T=u();d?d=!1:i.next(T)})}),Object.defineProperty(u,ze,{value:!0,enumerable:!0}),Object.defineProperty(u,ht,{value:o,enumerable:!1}),r}function ae(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),Ye(o,t),()=>J(o)}function Ye(e,t){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let n=v,o=f;if(v=e,f=e,Ee++,Ee>Jt)throw Ee=0,v=n,f=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=K;let r=e.fn(t);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=n,f=o}}function ve(e){if(!(e.disposed||!e.fn||e.state===G)&&(e.state===$||e.state===he||e.state===K)){if(e.cleanups){for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();e.cleanups=null}if(e.owned){for(let t=0;t<e.owned.length;t++)J(e.owned[t]);e.owned=null}e.renderEffect?gt(e):Ye(e,e.value)}}function J(e){if(e.disposed=!0,e.sources)for(let t of e.sources){let n=P.get(t);n&&n.delete(e)}if(e.cleanups)for(let t=0;t<e.cleanups.length;t++)e.cleanups[t]();if(e.owned)for(let t=0;t<e.owned.length;t++)J(e.owned[t]);if(e.owner&&e.owner.owned){let t=e.owner.owned.indexOf(e);t!==-1&&e.owner.owned.splice(t,1)}}function jn(e,t,n){let o=vt("memo",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};f&&(f.owned?f.owned.push(r):f.owned=[r]);let s=()=>{if(v&&v!==r){v.sources?v.sources.indexOf(s)===-1&&v.sources.push(s):v.sources=[s];let a=s;P.has(a)||P.set(a,new Set);let i=P.get(a);i&&i.add(v)}if(r.state!==G){if(r.sources){for(let d of r.sources){let y=P.get(d);y&&y.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let d=0;d<r.cleanups.length;d++)r.cleanups[d]();r.cleanups=null}if(r.owned){for(let d=0;d<r.owned.length;d++)J(r.owned[d]);r.owned=null}let a=v,i=f;v=r,f=r,r.state=K;try{let d=r.fn(r.value),y=o.equals||yt;if(n?.equals===!1||!y(r.value,d)){r.value=d,o.value=d,o.version++,o.updated=Date.now();let g=s,S=P.get(g);if(S&&S.size>0){let p=function(b,C=!1){if(b===r)return;let k=b.state;if(k!==K){if(C&&!b.pure){k===G&&(b.state=he,c!==null&&c.indexOf(b)===-1?c.push(b):m.push(b));return}if(!E.has(b)&&(E.add(b),b.state=$,k===G||k===he?m.push(b):!b.pure&&c!==null&&c.indexOf(b)===-1&&c.push(b),b.pure&&b.accessor)){let _=P.get(b.accessor);if(_&&_.size>0)for(let z of Array.from(_))p(z,!0)}}};var u=p;let w=Array.from(S),m=[],E=new Set;for(let b=0;b<w.length;b++)p(w[b]);for(let b of m)mt(b)}}r.state===K&&(r.state=G)}catch(d){if(Pe(d)){let y=O&&N(O);if(!y&&O){let T=i;for(;T;){if(T.contexts?.has(O.id)){y=T.contexts.get(O.id);break}T=T.owner}}return y&&(y.increment(),d.finally(()=>y.decrement())),r.value}He(d)}finally{v=a,f=i}}return r.value};return r.accessor=s,P.set(s,new Set),s.toObservable=()=>new Z(u=>{let a=!0;return ae(()=>{let d=s();a?a=!1:u.next(d)})}),Object.defineProperty(s,ze,{value:!0,enumerable:!0}),Object.defineProperty(s,zt,{value:!0,enumerable:!0}),Object.defineProperty(s,ht,{value:o,enumerable:!1}),s}function Fe(e){let t=[],n=[];for(let r of e)r.pure&&!r.computed&&r.accessor?t.indexOf(r)===-1&&t.push(r):(r.computed||!r.pure)&&n.indexOf(r)===-1&&n.push(r);c=[];let o=0;for(;o<t.length;){let r=t[o++],s=P.get(r.accessor);if(s&&s.size>0){let a=v;v=null,r.accessor(),v=a}let u=c.splice(0);for(let a of u)a.pure&&!a.computed&&a.accessor?t.indexOf(a)===-1&&t.push(a):(a.computed||!a.pure)&&n.indexOf(a)===-1&&n.push(a)}c=null;for(let r of n)(r.computed||!r.pure)&&ve(r)}function F(e){if(c&&ue>0)return e();if(c&&ue===0){let t=c,n=[];c=n,ue++;let o;try{o=e()}finally{ue--,c=t}let r=c;return Fe(n),c=r,o}ue++,c=[],_e=[];try{return e()}finally{ue--,xt()}}function xt(){if(!Ge){Ge=!0,Ee=0;try{for(;c&&c.length>0;){let e=c;c=null,Fe(e)}if(c=null,_e){let e=_e;_e=null;for(let t=0;t<e.length;t++)ve(e[t])}}finally{Ge=!1}}}function Gn(e){let t={owned:null,cleanups:null,contexts:null,owner:f},n=v;v=null;let o=f;f=t;try{return e(()=>{if(t.owned)for(let r=0;r<t.owned.length;r++)J(t.owned[r]);if(t.cleanups)for(let r=0;r<t.cleanups.length;r++)t.cleanups[r]()})}finally{f=o,v=n}}function W(e){let t=v;v=null;try{return e()}finally{v=t}}function ke(e){f&&(f.cleanups?f.cleanups.push(e):f.cleanups=[e])}function Kn(e,t,n={}){let o,r;typeof t=="function"?(o=typeof e=="function"?e:()=>e,r=t):(o=()=>!0,r=e,t&&typeof t=="object"&&(n=t));let{initialValue:s,name:u}=n,a=lt(),i=a!==void 0?ct(a):void 0,d=i!==void 0,[y,T]=q(i!==void 0?i.value:n.initialValue,{equals:!1}),[g,S]=q(void 0,{equals:!1}),[w,m]=q(i!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),k=Symbol(),_=k,z=!1,H=A=>{if(!(typeof localStorage>"u"))try{A&&localStorage.setItem("storage",JSON.stringify({data:A,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${u}):`,L)}},ce=ae(()=>{let A=o?o():e;if(b(),A===!1||A===null||A===void 0){_=k,F(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=z;if(z=!1,_!==k&&A===_&&!L)return;if(_=A,d){d=!1;return}let B=!1;ke(()=>B=!0);let le=W(w),re=W(y),Q=le==="ready"||le==="refreshing";F(()=>{m(Q?"refreshing":"pending"),S(void 0)});try{let V=r(A,{value:re,refetching:Q});if(Pe(V)){p(V),Ce(V),V.then(h=>{B||(a!==void 0&&ft(a,h),F(()=>{T(()=>h),H(h),m("ready"),p(void 0)}))},h=>{B||F(()=>{S(h),m("errored"),p(void 0)})}).catch(h=>{B||F(()=>{S(h),m("errored"),p(void 0)})});let ye=O&&N(O);ye&&(ye.increment(),V.finally(()=>ye.decrement()))}else{if(B)return;F(()=>{T(()=>V),m("ready"),p(void 0)})}}catch(V){if(B)return;F(()=>{S(V),m("errored"),p(void 0)})}});ke(ce);let X=()=>{let A=w();return A==="pending"||A==="refreshing"},Y=(()=>{let A=g();if(A)throw A;if(X()){let L=E();if(L)throw L}return y()});return Object.defineProperty(Y,Ht,{value:!0,enumerable:!0}),Object.defineProperty(Y,ze,{value:!0,enumerable:!0}),Object.defineProperties(Y,{state:{get:w},loading:{get:()=>X()},error:{get:g},latest:{get:y}}),[Y,{mutate:T,refetch:()=>{z=!0,C(void 0)}}]}function $n(){return f}function Wn(e,t){let n=f,o=v;f=e,v=null;try{return t()}finally{f=n,v=o}}function St(e){let t=Symbol("context"),n=nn(t);return{id:t,Provider:n,defaultValue:e}}function nn(e){return t=>{let n=f;for(;n;)n.contexts||(n.contexts=new Map),n.contexts.has(e)||n.contexts.set(e,t.value),n=n.owner;let o;return on(()=>{o=W(()=>{let r=f;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,t.value)),at(()=>t.children)})}),o}}function N(e){let t=f;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.owner}if(e)return e.defaultValue}function zn(){return new Promise(e=>{queueMicrotask(()=>{xt(),e()})})}function rn(e){if(M&&M.running)return e(),M.done;bt();let t,n=new Promise(r=>t=r),o={running:!0,effects:[],resolve:t,done:n};M=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);M=null,We(!1),r.length&&F(()=>{for(let s of r)s.state=$,ve(s)}),t()}),n):(M=null,t(),n)}function Hn(){return bt(),[$e,rn]}function Yn(e,t,n){let o=n?.defer??!1,r=!0;return s=>{let u=e();return o&&r?(r=!1,s):W(()=>t(u,s))}}function on(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};f&&(f.owned?f.owned.push(o):f.owned=[o]);let r=O&&N(O);return r&&(o.suspense=r),gt(o),()=>J(o)}function gt(e){if(e.sources){for(let r of e.sources){let s=P.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)J(e.owned[r]);e.owned=null}let t=v,n=f,o=c;v=e,f=e,c===null&&(c=[]),e.state=K;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===K&&(e.state=G)}catch(r){if(Pe(r)){let s=O&&N(O);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}He(r)}finally{v=t,f=n;let r=c;if(c=o,r!==o&&r&&r.length>0){let s=c;Fe(r),c=s}}}function Jn(e,t,n){let o={fn:e,state:$,sources:null,sourceSlots:null,value:t,owned:null,cleanups:null,owner:f,contexts:null,pure:!0,computed:!0,updatedAt:null};f&&(f.owned?f.owned.push(o):f.owned=[o]),M&&M.running?(c||(c=[]),c.indexOf(o)===-1&&c.push(o)):c?c.indexOf(o)===-1&&c.push(o):Ye(o,t)}var O;function wt(){return O||(O=St())}var Tt;function Xn(){return Tt||(Tt=St())}function Qn(e){if(!e.length)return;let t=e.slice();e.length=0;for(let n of t)n.state=$,ve(n)}function Zn(e){let t=O&&N(O);t&&t.inFallback()?ae(()=>{t.inFallback()||e()}):e()}function er(e){Xt=e}function tr(e){let t=O&&N(O);return t&&(t.increment(),e.finally(()=>t.decrement())),e}function sr(e,t,n){return x(()=>t(e()),void 0,n)}function ir(e,t,n){return x(()=>e().filter(t),void 0,n)}function ur(e,t,n,o){return x(()=>e().reduce(t,n),void 0,o)}function ar(e,t,n){return x(()=>e().find(t),void 0,n)}function cr(e,t,n){return x(()=>e().some(t),void 0,n)}function lr(e,t,n){return x(()=>e().every(t),void 0,n)}function fr(e,t,n){return x(()=>[...e()].sort(t),void 0,n)}function dr(e,t){return x(()=>[...new Set(e())],void 0,t)}function pr(e,t,n){return x(()=>{let o=e.map(r=>r());return t(o)},void 0,n)}function Tr(...e){return new Z(t=>{let n=()=>e.map(r=>typeof r=="function"?r():r.get()),o=e.map(r=>typeof r=="function"&&r.subscribe?r.subscribe(()=>{t.next(n())}):typeof r!="function"?r.subscribe(()=>{t.next(n())}):Te(()=>{t.next(n())}));return()=>{o.forEach(r=>{typeof r=="function"?r():r&&typeof r.unsubscribe=="function"&&r.unsubscribe()})}})}function hr(e,t,n){return x(()=>e()||t(),void 0,n)}function vr(e,t,n,o){return x(()=>n(e(),t()),void 0,o)}function yr(e,t,n){return x(()=>t(e()),void 0,{equals:n,internal:!0})}function br(e,t,n){return x(()=>{let o=e(),r={};for(let s of t)r[s]=o[s];return r},void 0,n)}function mr(e,t,n){return x(()=>{let r={...e()};for(let s of t)delete r[s];return r},void 0,n)}function xr(e,t,n,o){return x(()=>e()?t():n(),void 0,o)}function Sr(e,t,n){return x(()=>e()?t():void 0,void 0,n)}function gr(e,t,n){let[o,r]=I(e()),s;return x(()=>{let u=e();clearTimeout(s),s=setTimeout(()=>r(()=>u),t)}),o}function wr(e,t,n){let[o,r]=I(e()),s=0,u;return x(()=>{let a=e(),i=Date.now();i-s>=t?(s=i,r(()=>a)):(clearTimeout(u),u=setTimeout(()=>{s=Date.now(),r(()=>a)},t-(i-s)))}),o}function Or(e){let t=e;for(;typeof t=="function";)t=t();return t}var ne=new Map,te=new Map,sn=0,un=Symbol.for("signal"),an=Symbol.for("resource");function Cr(e,t,n={}){let o,r,s;typeof t=="function"?(o=e,r=t,s=n):(o=()=>!0,r=e,s=t??n);let{ttl:u=1/0,name:a=`_auto_${sn++}`,staleWhileRevalidate:i=!0}=s,d=a,y=h=>`${d}:${JSON.stringify(h)}`,T=h=>u===1/0||Date.now()-h.timestamp<=u,[g,S]=q(void 0,{equals:!1}),[w,m]=q("unresolved",{equals:!1}),[E,p]=q(void 0,{equals:!1}),[b,C]=q(void 0,{equals:!1}),[k,_]=q(!1),[z,H]=q(0,{equals:!1}),ce=Symbol("unset"),X=ce,Y=!1,A=!1;function L(h,U,D,j){if(te.has(U)){te.get(U).then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)}),D||C(te.get(U));return}let oe=Promise.resolve(r(h)).then(R=>(ne.set(U,{value:R,timestamp:Date.now()}),te.delete(U),R),R=>{throw te.delete(U),R});if(te.set(U,oe),!D){Ce(oe),C(oe);let R=re&&N(re);R&&(R.increment(),oe.finally(()=>R.decrement()))}oe.then(R=>{j()||B(R,D)},R=>{!j()&&!D&&le(R)})}function B(h,U){F(()=>{S(()=>h),m("ready"),_(!1),C(void 0),p(void 0)})}function le(h){F(()=>{p(h),m("errored"),C(void 0)})}let re;ae(()=>{re===void 0&&(re=wt());let h=o();if(z(),h===!1||h===null||h===void 0){X=ce,F(()=>{m("unresolved"),C(void 0),p(void 0)});return}let U=Y,D=A;Y=!1,A=!1;let j=y(h);D&&ne.delete(j);let oe=X===ce||h!==X;X=h;let R=!1;ke(()=>{R=!0});let se=ne.get(j);if(se&&T(se)&&!U&&!D){(W(w)!=="ready"||W(g)!==se.value)&&F(()=>{S(()=>se.value),m("ready"),_(!1),p(void 0)});return}if(se&&i&&!D){F(()=>{S(()=>se.value),m("ready"),_(!0),p(void 0),C(void 0)}),L(h,j,!0,()=>R);return}let Je=W(w),Ot=Je==="ready"||Je==="refreshing";F(()=>{m(Ot?"refreshing":"pending"),p(void 0),_(!1)}),L(h,j,!1,()=>R)});let Q=(()=>{let h=E();if(h)throw h;if(w()==="pending"){let D=b();if(D)throw D}return g()});return Object.defineProperty(Q,an,{value:!0,enumerable:!0}),Object.defineProperty(Q,un,{value:!0,enumerable:!0}),Object.defineProperties(Q,{state:{get:w},loading:{get:()=>{let h=w();return h==="pending"||h==="refreshing"}},error:{get:E},latest:{get:g},stale:{get:k}}),[Q,{mutate:S,refetch:()=>{Y=!0,H(h=>h+1)},invalidate:()=>{let h=W(o);h!=null&&h!==!1&&ne.delete(y(h)),A=!0,H(U=>U+1)}}]}function _r(e){let t=`${e}:`;for(let n of ne.keys())n.startsWith(t)&&ne.delete(n)}function Er(){ne.clear(),te.clear()}function Fr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=new Map;for(let i of o)s.has(i.item)||s.set(i.item,i);let u=[],a=new Set;for(let i=0;i<r.length;i++){let d=r[i],y=s.get(d);if(y&&!a.has(y))y.setIndex(i),u.push(y),a.add(y);else{let T,g,S;pe(m=>{S=m;let[E,p]=I(i);g=p,T=t(d,E)});let w={item:d,rendered:T,dispose:S,setIndex:g};u.push(w),a.add(w)}}for(let i of o)a.has(i)||i.dispose();return o=u,u.map(i=>i.rendered)})})}function Ur(e,t,n,o){let r=[],s=[];return ee(()=>{for(let u of s)u.dispose();r=[],s=[]}),x(()=>{let u=e()||[];return Re(()=>{if(u.length===0){for(let T of s)T.dispose();return r=[],s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let T=0;T<r.length;T++)a.set(r[T],s[T]);let i=[],d=[],y=new Set;for(let T=0;T<u.length;T++){let g=t(u[T]),S=a.get(g);if(S&&!y.has(g))S.setIndex(T),i.push(S);else{let w,m,E;pe(p=>{E=p;let[b,C]=I(T);m=C;let k=x(_=>{let H=(e()||[])[b()];return H??_},u[T]);w=n(k,b)}),i.push({rendered:w,dispose:E,setIndex:m})}d.push(g),y.add(g)}for(let[T,g]of a)y.has(T)||g.dispose();return r=d,s=i,i.map(T=>T.rendered)})})}function Dr(e,t,n){let o=[];return ee(()=>{for(let r of o)r.dispose();o=[]}),x(()=>{let r=e()||[];return Re(()=>{if(r.length===0){for(let i of o)i.dispose();return o=[],n?.fallback?n.fallback():[]}let s=o.length,u=r.length;for(let i=s;i<u;i++){let d,y,T,g=r[i];pe(S=>{T=S;let[w,m]=I(g);y=m,d=t(w,i)}),o.push({rendered:d,setItem:y,dispose:T})}for(let i=u;i<s;i++)o[i].dispose();u<s&&(o=o.slice(0,u));let a=Math.min(s,u);for(let i=0;i<a;i++)o[i].setItem(r[i]);return o.map(i=>i.rendered)})})}export{zt as $MEMO,dt as $PROXY,Ht as $RESOURCE,ze as $SIGNAL,me as __DEV__,F as batch,Er as clearAllCachedResources,_r as clearCachedResourceNamespace,pr as combineSignal,Tr as combineSignals,Cr as createCachedResource,Jn as createComputed,St as createContext,jt as createDebounce,Vt as createDeferred,ae as createEffect,jn as createMemo,nn as createProvider,on as createRenderEffect,Kn as createResource,Gn as createRoot,Bt as createSelector,q as createSignal,gr as debounceSignal,dr as distinctSignal,lr as everySignal,ir as filterSignal,ar as findSignal,zn as flush,$n as getOwner,ct as getServerData,Bn as getSharedConfig,wt as getSuspenseContext,Xn as getSuspenseListContext,Sr as guardSignal,Dr as indexArray,Pt as isComponent,Et as isMemo,Ut as isProvider,kt as isResource,De as isSignal,Ft as isSuspense,Ur as keyArray,Qe as makeArrayFlat,Fr as mapArray,sr as mapSignal,hr as mergeSignal,lt as nextResourceId,mr as omitSignal,Yn as on,ke as onCleanup,Zn as onResolve,br as pickSignal,at as readChildren,Or as readSignal,ur as reduceSignal,ft as reportResourceData,Qn as resumeEffects,Wn as runWithOwner,yr as selectSignal,Ln as setOwner,Wt as setResourceDataSink,$t as setResourceIdSource,Gt as setResourceTracker,er as setScheduler,Kt as setServerDataGetter,Ke as sharedConfig,cr as someSignal,fr as sortSignal,rn as startTransition,wr as throttleSignal,tr as trackPromise,Ce as trackResourcePromise,W as untrack,N as useContext,Hn as useTransition,xr as whenSignal,vr as zipSignal};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var oe=Object.defineProperty;var tt=Object.getOwnPropertyDescriptor;var nt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var ot=(e,t)=>{for(var n in t)oe(e,n,{get:t[n],enumerable:!0})},st=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of nt(t))!rt.call(e,s)&&s!==n&&oe(e,s,{get:()=>t[s],enumerable:!(r=tt(t,s))||r.enumerable});return e};var it=e=>st(oe({},"__esModule",{value:!0}),e);var gt={};ot(gt,{$PROXY:()=>xt,$SIGNAL:()=>St,Signal:()=>Ze,SuspenseContext:()=>re,__DEV__:()=>X,batch:()=>x,createComputed:()=>Ce,createContext:()=>D,createDebounce:()=>ze,createDeferred:()=>We,createEffect:()=>O,createErrorBoundary:()=>Je,createMemo:()=>w,createRenderEffect:()=>Ae,createResource:()=>He,createRoot:()=>E,createSelector:()=>Ge,createSignal:()=>d,createSuspenseBoundary:()=>Ke,flush:()=>qe,getOwner:()=>F,getServerData:()=>Z,indexArray:()=>yt,isComponent:()=>Ne,isMemo:()=>Ie,isProvider:()=>Be,isResource:()=>Me,isSignal:()=>J,isSuspense:()=>Ue,keyArray:()=>ht,makeArrayFlat:()=>le,mapArray:()=>pt,nextResourceId:()=>ee,on:()=>De,onCleanup:()=>v,provide:()=>I,provideErrorBoundary:()=>Qe,provideSuspense:()=>Ye,readChildren:()=>$e,reportResourceData:()=>te,runWithOwner:()=>M,setOwner:()=>ue,setResourceDataSink:()=>je,setResourceIdSource:()=>Ve,setResourceTracker:()=>Le,setServerDataGetter:()=>Fe,startTransition:()=>ce,trackResourcePromise:()=>Q,untrack:()=>g,useContext:()=>ge,useTransition:()=>Pe});module.exports=it(gt);var ut="__fluixi_signal_next_state__",at=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[ut]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:at,onSuspend:null,onError:null};var ve=0,we=1,B=2,z=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},P=class extends z{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(B);se(this)}}peek(){return this._value}},k=class extends z{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=B;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===we&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===B)break}(this.state===B||!this._initialized)&&this.recompute(),this.state=ve}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(B);se(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===ve;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(we);se(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function se(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var q=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function L(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function Se(){return o.consumer}function xe(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function H(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function D(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=H(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function ge(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function K(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function I(e,t,n){let r=H(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function be(e){o.onSuspend=e}function ke(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function Re(e){o.onError=e}function F(){return o.owner}function ue(e){let t=o.owner;return o.owner=e,t}function M(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){o.owner&&(o.owner.cleanups??=[]).push(e)}function $(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)$(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function E(e){let t=H(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>$(t))}finally{o.owner=n}}function _e(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function ct(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(V)))}function V(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function Ee(){o.batchDepth===0&&V()}function ae(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&V()}}var ie=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=H(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new k(()=>{$(this.owner),M(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new q(()=>ct(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),$(this.owner))}};function Y(e){let t=new ie(e);return()=>t.dispose()}function lt(e){return!!e&&typeof e.then=="function"}_e(()=>{});var Oe=Symbol.for("signal"),dt=Symbol.for("memo"),ft=Symbol.for("signal-node");function d(e,t){let n=new P(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),Ee(),a});return Object.defineProperty(r,Oe,{value:!0,enumerable:!0}),Object.defineProperty(r,ft,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=F(),i=new k(()=>M(s,()=>{try{return r=e(r)}catch(l){if(lt(l))return ke(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,Oe,{value:!0,enumerable:!0}),Object.defineProperty(a,dt,{value:!0,enumerable:!0}),a}function O(e,t){let n=t;return Y(()=>{n=e(n)})}function Ce(e,t){let n=t;Y(()=>{n=e(n)})}function Ae(e,t){let n=t;return Y(()=>{n=e(n)})}function x(e){return ae(e)}function g(e){return L(e)}function ce(e){return ae(e),Promise.resolve()}function Pe(){return[()=>!1,ce]}function qe(){return V(),Promise.resolve()}function De(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=L(()=>t(l,s,a));return s=l,u}}function pt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;E(m=>{y=m;let[C,N]=d(u);h=N,c=t(f,C)});let S={item:f,rendered:c,dispose:y,setIndex:h};a.push(S),l.add(S)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function ht(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return g(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let S,m,C;E(N=>{C=N;let[R,U]=d(c);m=U;let j=w(A=>{let b=(e()||[])[R()];return b??A},a[c]);S=n(j,R)}),u.push({rendered:S,dispose:C,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function yt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return g(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];E(y=>{c=y;let[S,m]=d(h);p=m,f=t(S,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var X=!1,mt=Symbol.for("signal"),Tt=Symbol.for("memo"),vt=Symbol.for("resource");function J(e){return typeof e=="function"&&e[mt]===!0}function Ie(e){return typeof e=="function"&&e[Tt]===!0}function Me(e){return typeof e=="function"&&e[vt]===!0}function Ne(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function Ue(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Be(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function le(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?le(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var de=null;function Le(e){de=e}function Q(e){de&&de(e)}var fe=null;function Fe(e){fe=e}function Z(e){return fe?fe(e):void 0}var pe=null;function Ve(e){pe=e}function ee(){return pe?pe():void 0}var he=null;function je(e){he=e}function te(e,t){he&&he(e,t)}function Ge(e,t=(n,r)=>n===r){let n=new Map;return O(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function We(e,t){let[n,r]=d(e(),t);return O(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function ze(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function ne(e){if(typeof e=="function"&&!e.length){let t=e();return J(t)?t:ne(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=ne(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function $e(e){let t=w(e);return w(()=>ne(t()))}function wt(e){return!!e&&typeof e.then=="function"}var ye=Symbol();function He(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ee(),a=i!==void 0?Z(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[S,m]=d(void 0,{equals:!1}),[C,N]=d(void 0,{equals:!1}),R=ye,U=!1;O(()=>{let T=r();if(C(),T===!1||T===null||T===void 0){R=ye,x(()=>{y("unresolved"),m(void 0),c(void 0)});return}let b=U;if(U=!1,R!==ye&&T===R&&!b)return;if(R=T,l){l=!1;return}let G=!1;v(()=>G=!0);let me=g(h),et=g(u),Te=me==="ready"||me==="refreshing";x(()=>{y(Te?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:et,refetching:Te});wt(_)?(m(_),Q(_),_.then(W=>{G||(i!==void 0&&te(i,W),x(()=>{f(()=>W),y("ready"),m(void 0)}))},W=>{G||x(()=>{c(W),y("errored"),m(void 0)})})):x(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(G)return;x(()=>{c(_),y("errored"),m(void 0)})}});let j=()=>{let T=h();return T==="pending"||T==="refreshing"},A=(()=>{let T=p();if(T)throw T;if(j()){let b=S();if(b)throw b}return u()});return Object.defineProperties(A,{state:{get:h},loading:{get:j},error:{get:p},latest:{get:u}}),Object.defineProperty(A,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(A,Symbol.for("signal"),{value:!0,enumerable:!0}),[A,{mutate:f,refetch:()=>{U=!0,N(void 0)}}]}var re=D();be((e,t)=>{let n=K(t,re);n&&(n.increment(),e.finally(()=>n.decrement()))});function Ke(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function Ye(e,t){return I(re,e,t)}var Xe=D();Re((e,t)=>{let n=K(t,Xe);return n?(n.setError(e),!0):!1});function Je(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function Qe(e,t){return I(Xe,e,t)}var Ze={State:P,Computed:k,subtle:{Watcher:q,untrack:L,currentComputed:Se,hasSinks:xe}};var St=Symbol.for("signal"),xt=Symbol.for("fluixi-proxy");
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@fluixi/reactive/signal` — now the TC39 core. This re-exports the complete reactive
|
|
3
|
+
* API running on the TC39 Signals graph (graph/signal-next.ts): the full legacy surface
|
|
4
|
+
* with the core primitives (createSignal/createMemo/createEffect/createRoot/…) swapped to
|
|
5
|
+
* the new graph, plus `Signal.State`/`Computed`/`subtle.Watcher`, resources, Suspense,
|
|
6
|
+
* context, and error boundaries.
|
|
7
|
+
*
|
|
8
|
+
* The pre-TC39 implementation is preserved, byte-for-byte, behind the explicit
|
|
9
|
+
* `@fluixi/reactive/signal-legacy` entry (./index-legacy.ts).
|
|
10
|
+
*/
|
|
11
|
+
export * from './graph/signal-next.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@fluixi/reactive/signal` — now the TC39 core. This re-exports the complete reactive
|
|
3
|
+
* API running on the TC39 Signals graph (graph/signal-next.ts): the full legacy surface
|
|
4
|
+
* with the core primitives (createSignal/createMemo/createEffect/createRoot/…) swapped to
|
|
5
|
+
* the new graph, plus `Signal.State`/`Computed`/`subtle.Watcher`, resources, Suspense,
|
|
6
|
+
* context, and error boundaries.
|
|
7
|
+
*
|
|
8
|
+
* The pre-TC39 implementation is preserved, byte-for-byte, behind the explicit
|
|
9
|
+
* `@fluixi/reactive/signal-legacy` entry (./index-legacy.ts).
|
|
10
|
+
*/
|
|
11
|
+
export * from './graph/signal-next.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Ce="__fluixi_signal_next_state__",Ae=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},o=globalThis[Ce]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Ae,onSuspend:null,onError:null};var he=0,ye=1,M=2,W=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(o.untracked)return;let t=o.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},C=class extends W{constructor(t,n){super(),this._value=t,this._equals=n?.equals===!1?()=>!1:n?.equals??Object.is}get(){return this.track(),this._value}set(t){if(!this._equals(this._value,t)){if(this._value=t,this.version++,this.observers)for(let n of[...this.observers])n.markDirty(M);J(this)}}peek(){return this._value}},g=class extends W{constructor(n,r){super();this._threw=!1;this._initialized=!1;this.state=M;this.sources=null;this._fn=n,this._equals=r?.equals===!1?()=>!1:r?.equals??Object.is}get(){if(o.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===ye&&this.sources){for(let n of this.sources)if(n.updateIfNecessary(),this.state===M)break}(this.state===M||!this._initialized)&&this.recompute(),this.state=he}recompute(){if(this.sources){for(let u of this.sources)u.observers?.delete(this);this.sources.clear()}let n=o.consumer,r=o.untracked;o.consumer=this,o.untracked=!1;let s,i=!1,a;try{s=this._fn()}catch(u){i=!0,a=u,s=this._value}finally{o.consumer=n,o.untracked=r}let l=!this._initialized||this._threw!==i||(i?a!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=i,this._error=a,this._value=s,l){if(this.version++,this.observers)for(let u of[...this.observers])u.markDirty(M);J(this)}}markDirty(n){if(this.state>=n)return;let r=this.state===he;if(this.state=n,r){if(this.observers)for(let s of[...this.observers])s.markDirty(ye);J(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function J(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}var A=class{constructor(t){this._watched=new Set;this._pending=new Set;this._notifyFn=t}watch(...t){for(let n of t)this._watched.add(n),(n.watchers??=new Set).add(this)}unwatch(...t){for(let n of t)this._watched.delete(n),n.watchers?.delete(this),this._pending.delete(n)}getPending(){let t=[...this._pending];return this._pending.clear(),t}_notify(t){if(!this._watched.has(t)||this._pending.has(t))return;let n=this._pending.size===0;this._pending.add(t),n&&this._notifyFn()}};function N(e){if(o.untracked)return e();o.untracked=!0;try{return e()}finally{o.untracked=!1}}function me(){return o.consumer}function Te(e){return!!(e.observers&&e.observers.size)||!!(e.watchers&&e.watchers.size)}function $(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function U(e){let t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>{let s=o.owner,i=$(s);(i.contexts=new Map).set(t,r.value),s&&(s.owned??=[]).push(i),o.owner=i;try{return r.children}finally{o.owner=s}}}}function Pe(e){let t=o.owner;for(;t;){if(t.contexts&&t.contexts.has(e.id))return t.contexts.get(e.id);t=t.parent}return e.defaultValue}function H(e,t){let n=e;for(;n;){if(n.contexts&&n.contexts.has(t.id))return n.contexts.get(t.id);n=n.parent}return t.defaultValue}function B(e,t,n){let r=$(o.owner);(r.contexts=new Map).set(e.id,t),o.owner&&(o.owner.owned??=[]).push(r);let s=o.owner;o.owner=r;try{return n()}finally{o.owner=s}}function ve(e){o.onSuspend=e}function we(e){return o.onSuspend?(o.onSuspend(e,o.owner),!0):!1}function Se(e){o.onError=e}function K(){return o.owner}function xe(e){let t=o.owner;return o.owner=e,t}function L(e,t){let n=o.owner;o.owner=e;try{return t()}finally{o.owner=n}}function v(e){o.owner&&(o.owner.cleanups??=[]).push(e)}function z(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)z(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function P(e){let t=$(o.owner);o.owner&&(o.owner.owned??=[]).push(t);let n=o.owner;o.owner=t;try{return e(()=>z(t))}finally{o.owner=n}}function ge(e){o.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function qe(e){e.queued||(e.queued=!0,o.queue.push(e),!o.scheduled&&o.batchDepth===0&&(o.scheduled=!0,o.hostSchedule(F)))}function F(){if(o.scheduled=!1,o.flushing)return;o.flushing=!0;let e=0;try{for(;o.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=o.queue;o.queue=[];for(let n of t)n.queued=!1,n.disposed||n.run()}}finally{o.flushing=!1}}function be(){o.batchDepth===0&&F()}function Z(e){o.batchDepth++;try{return e()}finally{--o.batchDepth===0&&F()}}var Q=class{constructor(t){this.queued=!1;this.disposed=!1;this.owner=$(o.owner),o.owner&&(o.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new g(()=>{z(this.owner),L(this.owner,()=>{let n=t();typeof n=="function"&&(this.owner.cleanups??=[]).push(n)})}),this.watcher=new A(()=>qe(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(t){if(t&&typeof t.then=="function"&&o.onSuspend){o.onSuspend(t,this.owner);return}if(o.onError&&o.onError(t,this.owner))return;throw t}}}dispose(){this.disposed||(this.disposed=!0,this.watcher.unwatch(this.computed),z(this.owner))}};function Y(e){let t=new Q(e);return()=>t.dispose()}function De(e){return!!e&&typeof e.then=="function"}ge(()=>{});var ke=Symbol.for("signal"),Ie=Symbol.for("memo"),Me=Symbol.for("signal-node");function d(e,t){let n=new C(e,{equals:t?.equals}),r=(()=>n.get()),s=(i=>{let a=typeof i=="function"?i(n.peek()):i;return n.set(a),be(),a});return Object.defineProperty(r,ke,{value:!0,enumerable:!0}),Object.defineProperty(r,Me,{value:{get value(){return n.peek()},get version(){return n.version}},enumerable:!1}),[r,s]}function w(e,t,n){let r=t,s=K(),i=new g(()=>L(s,()=>{try{return r=e(r)}catch(l){if(De(l))return we(l),r;throw l}}),{equals:n?.equals}),a=(()=>i.get());return Object.defineProperty(a,ke,{value:!0,enumerable:!0}),Object.defineProperty(a,Ie,{value:!0,enumerable:!0}),a}function q(e,t){let n=t;return Y(()=>{n=e(n)})}function Ne(e,t){let n=t;Y(()=>{n=e(n)})}function Ue(e,t){let n=t;return Y(()=>{n=e(n)})}function b(e){return Z(e)}function k(e){return N(e)}function Re(e){return Z(e),Promise.resolve()}function Be(){return[()=>!1,Re]}function Le(){return F(),Promise.resolve()}function Fe(e,t,n){let r=Array.isArray(e),s,i=n?.defer??!1;return a=>{let l=r?e.map(f=>f()):e();if(i){i=!1,s=l;return}let u=N(()=>t(l,s,a));return s=l,u}}function xt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=new Map;for(let u of r)i.has(u.item)||i.set(u.item,u);let a=[],l=new Set;for(let u=0;u<s.length;u++){let f=s[u],p=i.get(f);if(p&&!l.has(p))p.setIndex(u),a.push(p),l.add(p);else{let c,h,y;P(m=>{y=m;let[E,D]=d(u);h=D,c=t(f,E)});let S={item:f,rendered:c,dispose:y,setIndex:h};a.push(S),l.add(S)}}for(let u of r)l.has(u)||u.dispose();return r=a,a.map(u=>u.rendered)})})}function gt(e,t,n,r){let s=[],i=[];return v(()=>{for(let a of i)a.dispose();s=[],i=[]}),w(()=>{let a=e()||[];return k(()=>{if(a.length===0){for(let c of i)c.dispose();return s=[],i=[],r?.fallback?r.fallback():[]}let l=new Map;for(let c=0;c<s.length;c++)l.set(s[c],i[c]);let u=[],f=[],p=new Set;for(let c=0;c<a.length;c++){let h=t(a[c]),y=l.get(h);if(y&&!p.has(h))y.setIndex(c),u.push(y);else{let S,m,E;P(D=>{E=D;let[R,I]=d(c);m=I;let V=w(O=>{let x=(e()||[])[R()];return x??O},a[c]);S=n(V,R)}),u.push({rendered:S,dispose:E,setIndex:m})}f.push(h),p.add(h)}for(let[c,h]of l)p.has(c)||h.dispose();return s=f,i=u,u.map(c=>c.rendered)})})}function bt(e,t,n){let r=[];return v(()=>{for(let s of r)s.dispose();r=[]}),w(()=>{let s=e()||[];return k(()=>{if(s.length===0){for(let u of r)u.dispose();return r=[],n?.fallback?n.fallback():[]}let i=r.length,a=s.length;for(let u=i;u<a;u++){let f,p,c,h=s[u];P(y=>{c=y;let[S,m]=d(h);p=m,f=t(S,u)}),r.push({rendered:f,setItem:p,dispose:c})}for(let u=a;u<i;u++)r[u].dispose();a<i&&(r=r.slice(0,a));let l=Math.min(i,a);for(let u=0;u<l;u++)r[u].setItem(s[u]);return r.map(u=>u.rendered)})})}var ee=!1,Ve=Symbol.for("signal"),je=Symbol.for("memo"),Ge=Symbol.for("resource");function te(e){return typeof e=="function"&&e[Ve]===!0}function We(e){return typeof e=="function"&&e[je]===!0}function ze(e){return typeof e=="function"&&e[Ge]===!0}function $e(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function He(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function Ke(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function _e(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?_e(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var ne=null;function Ye(e){ne=e}function ie(e){ne&&ne(e)}var re=null;function Xe(e){re=e}function ue(e){return re?re(e):void 0}var oe=null;function Je(e){oe=e}function ae(){return oe?oe():void 0}var se=null;function Qe(e){se=e}function ce(e,t){se&&se(e,t)}function Ze(e,t=(n,r)=>n===r){let n=new Map;return q(()=>{let r=e();for(let[s,i]of n){let[a,l]=i,u=t(s,r);a()!==u&&l(u)}}),r=>{let s=n.get(r);if(!s){let[i,a]=d(!1);s=[i,a],n.set(r,s);let l=e();a(t(r,l))}return s[0]()}}function et(e,t){let[n,r]=d(e(),t);return q(()=>{let s=e();t?.timeoutMs?setTimeout(()=>r(()=>s),t.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>r(()=>s)):Promise.resolve().then(()=>r(()=>s))}),n}function tt(e,t){let n,r=(...s)=>{n!==void 0&&clearTimeout(n),n=setTimeout(()=>{if(n=void 0,s.length>0){let i=s[s.length-1];typeof i=="object"&&i&&!i.tagName&&i.target&&i.target.tagName&&(i=i.target),i&&typeof i=="object"&&i.tagName&&(i.tagName.toLowerCase()==="input"||i.tagName.toLowerCase()==="textarea")&&i.focus()}e(...s)},t)};return v(()=>{n!==void 0&&clearTimeout(n)}),r}function X(e){if(typeof e=="function"&&!e.length){let t=e();return te(t)?t:X(t)}if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=X(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function nt(e){let t=w(e);return w(()=>X(t()))}function rt(e){return!!e&&typeof e.then=="function"}var le=Symbol();function ot(e,t,n={}){let r,s;typeof t=="function"?(r=typeof e=="function"?e:()=>e,s=t):(r=()=>!0,s=e,t&&typeof t=="object"&&(n=t));let i=ae(),a=i!==void 0?ue(i):void 0,l=a!==void 0,[u,f]=d(a!==void 0?a.value:n.initialValue,{equals:!1}),[p,c]=d(void 0,{equals:!1}),[h,y]=d(a!==void 0||n.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[S,m]=d(void 0,{equals:!1}),[E,D]=d(void 0,{equals:!1}),R=le,I=!1;q(()=>{let T=r();if(E(),T===!1||T===null||T===void 0){R=le,b(()=>{y("unresolved"),m(void 0),c(void 0)});return}let x=I;if(I=!1,R!==le&&T===R&&!x)return;if(R=T,l){l=!1;return}let j=!1;v(()=>j=!0);let fe=k(h),Oe=k(u),pe=fe==="ready"||fe==="refreshing";b(()=>{y(pe?"refreshing":"pending"),c(void 0)});try{let _=s(T,{value:Oe,refetching:pe});rt(_)?(m(_),ie(_),_.then(G=>{j||(i!==void 0&&ce(i,G),b(()=>{f(()=>G),y("ready"),m(void 0)}))},G=>{j||b(()=>{c(G),y("errored"),m(void 0)})})):b(()=>{f(()=>_),y("ready"),m(void 0)})}catch(_){if(j)return;b(()=>{c(_),y("errored"),m(void 0)})}});let V=()=>{let T=h();return T==="pending"||T==="refreshing"},O=(()=>{let T=p();if(T)throw T;if(V()){let x=S();if(x)throw x}return u()});return Object.defineProperties(O,{state:{get:h},loading:{get:V},error:{get:p},latest:{get:u}}),Object.defineProperty(O,Symbol.for("resource"),{value:!0,enumerable:!0}),Object.defineProperty(O,Symbol.for("signal"),{value:!0,enumerable:!0}),[O,{mutate:f,refetch:()=>{I=!0,D(void 0)}}]}var de=U();ve((e,t)=>{let n=H(t,de);n&&(n.increment(),e.finally(()=>n.decrement()))});function st(){let[e,t]=d(0),n=0;return{increment:()=>t(n+=1),decrement:()=>t(n-=1),inFallback:()=>e()>0}}function it(e,t){return B(de,e,t)}var Ee=U();Se((e,t)=>{let n=H(t,Ee);return n?(n.setError(e),!0):!1});function ut(){let[e,t]=d(void 0,{equals:!1});return{error:e,reset:()=>t(()=>{}),setError:r=>t(()=>r)}}function at(e,t){return B(Ee,e,t)}var ct={State:C,Computed:g,subtle:{Watcher:A,untrack:N,currentComputed:me,hasSinks:Te}};var Gt=Symbol.for("signal"),Wt=Symbol.for("fluixi-proxy");export{Wt as $PROXY,Gt as $SIGNAL,ct as Signal,de as SuspenseContext,ee as __DEV__,b as batch,Ne as createComputed,U as createContext,tt as createDebounce,et as createDeferred,q as createEffect,ut as createErrorBoundary,w as createMemo,Ue as createRenderEffect,ot as createResource,P as createRoot,Ze as createSelector,d as createSignal,st as createSuspenseBoundary,Le as flush,K as getOwner,ue as getServerData,bt as indexArray,$e as isComponent,We as isMemo,Ke as isProvider,ze as isResource,te as isSignal,He as isSuspense,gt as keyArray,_e as makeArrayFlat,xt as mapArray,ae as nextResourceId,Fe as on,v as onCleanup,B as provide,at as provideErrorBoundary,it as provideSuspense,nt as readChildren,ce as reportResourceData,L as runWithOwner,xe as setOwner,Qe as setResourceDataSink,Je as setResourceIdSource,Ye as setResourceTracker,Xe as setServerDataGetter,Re as startTransition,ie as trackResourcePromise,k as untrack,Pe as useContext,Be as useTransition};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var E=Object.defineProperty;var H=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var B=(e,t)=>{for(var r in t)E(e,r,{get:t[r],enumerable:!0})},J=(e,t,r,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Y(t))!$.call(e,i)&&i!==r&&E(e,i,{get:()=>t[i],enumerable:!(o=H(t,i))||o.enumerable});return e};var Q=e=>J(E({},"__esModule",{value:!0}),e);var ue={};B(ue,{indexArray:()=>ie,keyArray:()=>se,mapArray:()=>oe});module.exports=Q(ue);var X="__fluixi_signal_next_state__",Z=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},s=globalThis[X]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:Z,onSuspend:null,onError:null};var R=0,U=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(s.untracked)return;let t=s.consumer;t&&((this.observers??=new Set).add(t),(t.sources??=new Set).add(this))}},g=class extends S{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(T);C(this)}}peek(){return this._value}},k=class extends S{constructor(r,o){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=r,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(s.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===U&&this.sources){for(let r of this.sources)if(r.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=R}recompute(){if(this.sources){for(let n of this.sources)n.observers?.delete(this);this.sources.clear()}let r=s.consumer,o=s.untracked;s.consumer=this,s.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(n){a=!0,u=n,i=this._value}finally{s.consumer=r,s.untracked=o}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let n of[...this.observers])n.markDirty(T);C(this)}}markDirty(r){if(this.state>=r)return;let o=this.state===R;if(this.state=r,o){if(this.observers)for(let i of[...this.observers])i.markDirty(U);C(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function C(e){if(e.watchers)for(let t of[...e.watchers])t._notify(e)}function L(e){if(s.untracked)return e();s.untracked=!0;try{return e()}finally{s.untracked=!1}}function ee(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function M(e){return s.onSuspend?(s.onSuspend(e,s.owner),!0):!1}function P(){return s.owner}function D(e,t){let r=s.owner;s.owner=e;try{return t()}finally{s.owner=r}}function y(e){s.owner&&(s.owner.cleanups??=[]).push(e)}function N(e){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)N(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}}function m(e){let t=ee(s.owner);s.owner&&(s.owner.owned??=[]).push(t);let r=s.owner;s.owner=t;try{return e(()=>N(t))}finally{s.owner=r}}function W(e){s.hostSchedule=e??(t=>{Promise.resolve().then(t)})}function z(){if(s.scheduled=!1,s.flushing)return;s.flushing=!0;let e=0;try{for(;s.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let t=s.queue;s.queue=[];for(let r of t)r.queued=!1,r.disposed||r.run()}}finally{s.flushing=!1}}function G(){s.batchDepth===0&&z()}function te(e){return!!e&&typeof e.then=="function"}W(()=>{});var j=Symbol.for("signal"),ne=Symbol.for("memo"),re=Symbol.for("signal-node");function _(e,t){let r=new g(e,{equals:t?.equals}),o=(()=>r.get()),i=(a=>{let u=typeof a=="function"?a(r.peek()):a;return r.set(u),G(),u});return Object.defineProperty(o,j,{value:!0,enumerable:!0}),Object.defineProperty(o,re,{value:{get value(){return r.peek()},get version(){return r.version}},enumerable:!1}),[o,i]}function b(e,t,r){let o=t,i=P(),a=new k(()=>D(i,()=>{try{return o=e(o)}catch(l){if(te(l))return M(l),o;throw l}}),{equals:r?.equals}),u=(()=>a.get());return Object.defineProperty(u,j,{value:!0,enumerable:!0}),Object.defineProperty(u,ne,{value:!0,enumerable:!0}),u}function O(e){return L(e)}function oe(e,t,r){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),b(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],r?.fallback?r.fallback():[]}let a=new Map;for(let n of o)a.has(n.item)||a.set(n.item,n);let u=[],l=new Set;for(let n=0;n<i.length;n++){let p=i[n],d=a.get(p);if(d&&!l.has(d))d.setIndex(n),u.push(d),l.add(d);else{let c,f,h;m(w=>{h=w;let[x,q]=_(n);f=q,c=t(p,x)});let v={item:p,rendered:c,dispose:h,setIndex:f};u.push(v),l.add(v)}}for(let n of o)l.has(n)||n.dispose();return o=u,u.map(n=>n.rendered)})})}function se(e,t,r,o){let i=[],a=[];return y(()=>{for(let u of a)u.dispose();i=[],a=[]}),b(()=>{let u=e()||[];return O(()=>{if(u.length===0){for(let c of a)c.dispose();return i=[],a=[],o?.fallback?o.fallback():[]}let l=new Map;for(let c=0;c<i.length;c++)l.set(i[c],a[c]);let n=[],p=[],d=new Set;for(let c=0;c<u.length;c++){let f=t(u[c]),h=l.get(f);if(h&&!d.has(f))h.setIndex(c),n.push(h);else{let v,w,x;m(q=>{x=q;let[I,K]=_(c);w=K;let V=b(F=>{let A=(e()||[])[I()];return A??F},u[c]);v=r(V,I)}),n.push({rendered:v,dispose:x,setIndex:w})}p.push(f),d.add(f)}for(let[c,f]of l)d.has(c)||f.dispose();return i=p,a=n,n.map(c=>c.rendered)})})}function ie(e,t,r){let o=[];return y(()=>{for(let i of o)i.dispose();o=[]}),b(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let n of o)n.dispose();return o=[],r?.fallback?r.fallback():[]}let a=o.length,u=i.length;for(let n=a;n<u;n++){let p,d,c,f=i[n];m(h=>{c=h;let[v,w]=_(f);d=w,p=t(v,n)}),o.push({rendered:p,setItem:d,dispose:c})}for(let n=u;n<a;n++)o[n].dispose();u<a&&(o=o.slice(0,u));let l=Math.min(a,u);for(let n=0;n<l;n++)o[n].setItem(i[n]);return o.map(n=>n.rendered)})})}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyed list reconciliation primitives — the reactive foundation for `<For>`,
|
|
3
|
+
* `<For by>` and `<Index>` (mirrors SolidJS `mapArray`/`keyArray`/`indexArray`).
|
|
4
|
+
*
|
|
5
|
+
* Each maps a reactive array to an array of mapped values and reuses per-item
|
|
6
|
+
* reactive scopes across updates so only changed items re-run their map fn. Every
|
|
7
|
+
* mapped item lives in its own `createRoot`, so it has a disposable owner scope —
|
|
8
|
+
* this is what keeps list items owner-stable (the thing ad-hoc array handling gets
|
|
9
|
+
* wrong).
|
|
10
|
+
*/
|
|
11
|
+
import { type Accessor } from './graph/compat.js';
|
|
12
|
+
type ListSource<T> = Accessor<readonly T[] | null | undefined | false>;
|
|
13
|
+
interface ListOptions {
|
|
14
|
+
/** Returned (as-is, not wrapped) when the list is empty/nullish. */
|
|
15
|
+
fallback?: () => any;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Reference-keyed map. Reuses an item's mapped value while the same value (by
|
|
19
|
+
* `===`) stays in the list; new values get a fresh root + index signal; removed
|
|
20
|
+
* values are disposed. The map fn receives the plain value (a snapshot) and a
|
|
21
|
+
* reactive index accessor. Backs `<For>`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapArray<T, U>(list: ListSource<T>, mapFn: (item: T, index: Accessor<number>) => U, options?: ListOptions): Accessor<U[]>;
|
|
24
|
+
/**
|
|
25
|
+
* Key-function map. Like `mapArray` but reuse is keyed by `keyFn(item)` (so the
|
|
26
|
+
* same key survives object recreation), and the map fn receives a *live* item
|
|
27
|
+
* accessor (reads through to the current list value, so sub-property updates
|
|
28
|
+
* propagate). Backs `<For by={…}>`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function keyArray<T, U>(list: ListSource<T>, keyFn: (item: T) => any, mapFn: (item: Accessor<T>, index: Accessor<number>) => U, options?: ListOptions): Accessor<U[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Index-keyed map. Reuse is keyed by *position*: growing adds slots, shrinking
|
|
33
|
+
* disposes trailing slots, and when the value at a position changes only that
|
|
34
|
+
* slot's item signal updates (the map fn is NOT re-run). The map fn receives a
|
|
35
|
+
* live item accessor and a plain (stable) index. Backs `<Index>`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function indexArray<T, U>(list: ListSource<T>, mapFn: (item: Accessor<T>, index: number) => U, options?: ListOptions): Accessor<U[]>;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../src/lib/signal/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,KAAK,QAAQ,EAA4D,MAAM,mBAAmB,CAAC;AAE5G,KAAK,UAAU,CAAC,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,CAAC;AAEvE,UAAU,WAAW;IACnB,oEAAoE;IACpE,QAAQ,CAAC,EAAE,MAAM,GAAG,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EAC9C,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CA6Cf;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,EACvB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,EACxD,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAuDf;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAC7B,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,KAAK,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,EAC9C,OAAO,CAAC,EAAE,WAAW,GACpB,QAAQ,CAAC,CAAC,EAAE,CAAC,CAuCf"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyed list reconciliation primitives — the reactive foundation for `<For>`,
|
|
3
|
+
* `<For by>` and `<Index>` (mirrors SolidJS `mapArray`/`keyArray`/`indexArray`).
|
|
4
|
+
*
|
|
5
|
+
* Each maps a reactive array to an array of mapped values and reuses per-item
|
|
6
|
+
* reactive scopes across updates so only changed items re-run their map fn. Every
|
|
7
|
+
* mapped item lives in its own `createRoot`, so it has a disposable owner scope —
|
|
8
|
+
* this is what keeps list items owner-stable (the thing ad-hoc array handling gets
|
|
9
|
+
* wrong).
|
|
10
|
+
*/
|
|
11
|
+
import { createMemo, createRoot, createSignal, onCleanup, untrack } from './graph/compat.js';
|
|
12
|
+
/**
|
|
13
|
+
* Reference-keyed map. Reuses an item's mapped value while the same value (by
|
|
14
|
+
* `===`) stays in the list; new values get a fresh root + index signal; removed
|
|
15
|
+
* values are disposed. The map fn receives the plain value (a snapshot) and a
|
|
16
|
+
* reactive index accessor. Backs `<For>`.
|
|
17
|
+
*/
|
|
18
|
+
export function mapArray(list, mapFn, options) {
|
|
19
|
+
let items = [];
|
|
20
|
+
onCleanup(() => { for (const e of items)
|
|
21
|
+
e.dispose(); items = []; });
|
|
22
|
+
return createMemo(() => {
|
|
23
|
+
const next = (list() || []);
|
|
24
|
+
return untrack(() => {
|
|
25
|
+
if (next.length === 0) {
|
|
26
|
+
for (const e of items)
|
|
27
|
+
e.dispose();
|
|
28
|
+
items = [];
|
|
29
|
+
return options?.fallback ? options.fallback() : [];
|
|
30
|
+
}
|
|
31
|
+
const prevByItem = new Map();
|
|
32
|
+
for (const e of items)
|
|
33
|
+
if (!prevByItem.has(e.item))
|
|
34
|
+
prevByItem.set(e.item, e);
|
|
35
|
+
const result = [];
|
|
36
|
+
const used = new Set();
|
|
37
|
+
for (let i = 0; i < next.length; i++) {
|
|
38
|
+
const value = next[i];
|
|
39
|
+
const reuse = prevByItem.get(value);
|
|
40
|
+
if (reuse && !used.has(reuse)) {
|
|
41
|
+
reuse.setIndex(i);
|
|
42
|
+
result.push(reuse);
|
|
43
|
+
used.add(reuse);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
let rendered, setIndex, dispose;
|
|
47
|
+
createRoot((d) => {
|
|
48
|
+
dispose = d;
|
|
49
|
+
const [index, setIdx] = createSignal(i);
|
|
50
|
+
setIndex = setIdx;
|
|
51
|
+
rendered = mapFn(value, index);
|
|
52
|
+
});
|
|
53
|
+
const entry = { item: value, rendered, dispose, setIndex };
|
|
54
|
+
result.push(entry);
|
|
55
|
+
used.add(entry);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const e of items)
|
|
59
|
+
if (!used.has(e))
|
|
60
|
+
e.dispose();
|
|
61
|
+
items = result;
|
|
62
|
+
return result.map((e) => e.rendered);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Key-function map. Like `mapArray` but reuse is keyed by `keyFn(item)` (so the
|
|
68
|
+
* same key survives object recreation), and the map fn receives a *live* item
|
|
69
|
+
* accessor (reads through to the current list value, so sub-property updates
|
|
70
|
+
* propagate). Backs `<For by={…}>`.
|
|
71
|
+
*/
|
|
72
|
+
export function keyArray(list, keyFn, mapFn, options) {
|
|
73
|
+
let keys = [];
|
|
74
|
+
let entries = [];
|
|
75
|
+
onCleanup(() => { for (const e of entries)
|
|
76
|
+
e.dispose(); keys = []; entries = []; });
|
|
77
|
+
return createMemo(() => {
|
|
78
|
+
const next = (list() || []);
|
|
79
|
+
return untrack(() => {
|
|
80
|
+
if (next.length === 0) {
|
|
81
|
+
for (const e of entries)
|
|
82
|
+
e.dispose();
|
|
83
|
+
keys = [];
|
|
84
|
+
entries = [];
|
|
85
|
+
return options?.fallback ? options.fallback() : [];
|
|
86
|
+
}
|
|
87
|
+
const prevByKey = new Map();
|
|
88
|
+
for (let i = 0; i < keys.length; i++)
|
|
89
|
+
prevByKey.set(keys[i], entries[i]);
|
|
90
|
+
const resultEntries = [];
|
|
91
|
+
const resultKeys = [];
|
|
92
|
+
const usedKeys = new Set();
|
|
93
|
+
for (let i = 0; i < next.length; i++) {
|
|
94
|
+
const key = keyFn(next[i]);
|
|
95
|
+
const reuse = prevByKey.get(key);
|
|
96
|
+
if (reuse && !usedKeys.has(key)) {
|
|
97
|
+
reuse.setIndex(i);
|
|
98
|
+
resultEntries.push(reuse);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
let rendered, setIndex, dispose;
|
|
102
|
+
createRoot((d) => {
|
|
103
|
+
dispose = d;
|
|
104
|
+
const [index, setIdx] = createSignal(i);
|
|
105
|
+
setIndex = setIdx;
|
|
106
|
+
// Live accessor: reads the current list at this index. Falls back to the
|
|
107
|
+
// last known value while the array is mid-shrink (idx out of bounds)
|
|
108
|
+
// so render fns don't read undefined before disposal completes.
|
|
109
|
+
const item = createMemo((prev) => {
|
|
110
|
+
const cur = (list() || []);
|
|
111
|
+
const v = cur[index()];
|
|
112
|
+
return v !== undefined && v !== null ? v : prev;
|
|
113
|
+
}, next[i]);
|
|
114
|
+
rendered = mapFn(item, index);
|
|
115
|
+
});
|
|
116
|
+
resultEntries.push({ rendered, dispose, setIndex });
|
|
117
|
+
}
|
|
118
|
+
resultKeys.push(key);
|
|
119
|
+
usedKeys.add(key);
|
|
120
|
+
}
|
|
121
|
+
for (const [key, e] of prevByKey)
|
|
122
|
+
if (!usedKeys.has(key))
|
|
123
|
+
e.dispose();
|
|
124
|
+
keys = resultKeys;
|
|
125
|
+
entries = resultEntries;
|
|
126
|
+
return resultEntries.map((e) => e.rendered);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Index-keyed map. Reuse is keyed by *position*: growing adds slots, shrinking
|
|
132
|
+
* disposes trailing slots, and when the value at a position changes only that
|
|
133
|
+
* slot's item signal updates (the map fn is NOT re-run). The map fn receives a
|
|
134
|
+
* live item accessor and a plain (stable) index. Backs `<Index>`.
|
|
135
|
+
*/
|
|
136
|
+
export function indexArray(list, mapFn, options) {
|
|
137
|
+
let slots = [];
|
|
138
|
+
onCleanup(() => { for (const s of slots)
|
|
139
|
+
s.dispose(); slots = []; });
|
|
140
|
+
return createMemo(() => {
|
|
141
|
+
const next = (list() || []);
|
|
142
|
+
return untrack(() => {
|
|
143
|
+
if (next.length === 0) {
|
|
144
|
+
for (const s of slots)
|
|
145
|
+
s.dispose();
|
|
146
|
+
slots = [];
|
|
147
|
+
return options?.fallback ? options.fallback() : [];
|
|
148
|
+
}
|
|
149
|
+
const prevLen = slots.length;
|
|
150
|
+
const nextLen = next.length;
|
|
151
|
+
for (let i = prevLen; i < nextLen; i++) {
|
|
152
|
+
let rendered, setItem, dispose;
|
|
153
|
+
const value = next[i];
|
|
154
|
+
createRoot((d) => {
|
|
155
|
+
dispose = d;
|
|
156
|
+
const [item, setVal] = createSignal(value);
|
|
157
|
+
setItem = setVal;
|
|
158
|
+
rendered = mapFn(item, i);
|
|
159
|
+
});
|
|
160
|
+
slots.push({ rendered, setItem, dispose });
|
|
161
|
+
}
|
|
162
|
+
for (let i = nextLen; i < prevLen; i++)
|
|
163
|
+
slots[i].dispose();
|
|
164
|
+
if (nextLen < prevLen)
|
|
165
|
+
slots = slots.slice(0, nextLen);
|
|
166
|
+
const survive = Math.min(prevLen, nextLen);
|
|
167
|
+
for (let i = 0; i < survive; i++)
|
|
168
|
+
slots[i].setItem(next[i]);
|
|
169
|
+
return slots.map((s) => s.rendered);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var F="__fluixi_signal_next_state__",H=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},r=globalThis[F]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:H,onSuspend:null,onError:null};var I=0,R=1,T=2,S=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(r.untracked)return;let n=r.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},g=class extends S{constructor(n,o){super(),this._value=n,this._equals=o?.equals===!1?()=>!1:o?.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 o of[...this.observers])o.markDirty(T);E(this)}}peek(){return this._value}},k=class extends S{constructor(o,s){super();this._threw=!1;this._initialized=!1;this.state=T;this.sources=null;this._fn=o,this._equals=s?.equals===!1?()=>!1:s?.equals??Object.is}get(){if(r.consumer===this)throw new Error("Signal.Computed cannot read itself");if(this.track(),this.updateIfNecessary(),this._threw)throw this._error;return this._value}updateIfNecessary(){if(this.state===R&&this.sources){for(let o of this.sources)if(o.updateIfNecessary(),this.state===T)break}(this.state===T||!this._initialized)&&this.recompute(),this.state=I}recompute(){if(this.sources){for(let t of this.sources)t.observers?.delete(this);this.sources.clear()}let o=r.consumer,s=r.untracked;r.consumer=this,r.untracked=!1;let i,a=!1,u;try{i=this._fn()}catch(t){a=!0,u=t,i=this._value}finally{r.consumer=o,r.untracked=s}let l=!this._initialized||this._threw!==a||(a?u!==this._error:!this._equals(this._value,i));if(this._initialized=!0,this._threw=a,this._error=u,this._value=i,l){if(this.version++,this.observers)for(let t of[...this.observers])t.markDirty(T);E(this)}}markDirty(o){if(this.state>=o)return;let s=this.state===I;if(this.state=o,s){if(this.observers)for(let i of[...this.observers])i.markDirty(R);E(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function E(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}function U(e){if(r.untracked)return e();r.untracked=!0;try{return e()}finally{r.untracked=!1}}function Y(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function L(e){return r.onSuspend?(r.onSuspend(e,r.owner),!0):!1}function C(){return r.owner}function P(e,n){let o=r.owner;r.owner=e;try{return n()}finally{r.owner=o}}function y(e){r.owner&&(r.owner.cleanups??=[]).push(e)}function M(e){if(e.owned){for(let n=e.owned.length-1;n>=0;n--)M(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}}function m(e){let n=Y(r.owner);r.owner&&(r.owner.owned??=[]).push(n);let o=r.owner;r.owner=n;try{return e(()=>M(n))}finally{r.owner=o}}function N(e){r.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function W(){if(r.scheduled=!1,r.flushing)return;r.flushing=!0;let e=0;try{for(;r.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=r.queue;r.queue=[];for(let o of n)o.queued=!1,o.disposed||o.run()}}finally{r.flushing=!1}}function z(){r.batchDepth===0&&W()}function $(e){return!!e&&typeof e.then=="function"}N(()=>{});var G=Symbol.for("signal"),B=Symbol.for("memo"),J=Symbol.for("signal-node");function _(e,n){let o=new g(e,{equals:n?.equals}),s=(()=>o.get()),i=(a=>{let u=typeof a=="function"?a(o.peek()):a;return o.set(u),z(),u});return Object.defineProperty(s,G,{value:!0,enumerable:!0}),Object.defineProperty(s,J,{value:{get value(){return o.peek()},get version(){return o.version}},enumerable:!1}),[s,i]}function b(e,n,o){let s=n,i=C(),a=new k(()=>P(i,()=>{try{return s=e(s)}catch(l){if($(l))return L(l),s;throw l}}),{equals:o?.equals}),u=(()=>a.get());return Object.defineProperty(u,G,{value:!0,enumerable:!0}),Object.defineProperty(u,B,{value:!0,enumerable:!0}),u}function O(e){return U(e)}function de(e,n,o){let s=[];return y(()=>{for(let i of s)i.dispose();s=[]}),b(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let t of s)t.dispose();return s=[],o?.fallback?o.fallback():[]}let a=new Map;for(let t of s)a.has(t.item)||a.set(t.item,t);let u=[],l=new Set;for(let t=0;t<i.length;t++){let p=i[t],d=a.get(p);if(d&&!l.has(d))d.setIndex(t),u.push(d),l.add(d);else{let c,f,h;m(w=>{h=w;let[x,q]=_(t);f=q,c=n(p,x)});let v={item:p,rendered:c,dispose:h,setIndex:f};u.push(v),l.add(v)}}for(let t of s)l.has(t)||t.dispose();return s=u,u.map(t=>t.rendered)})})}function fe(e,n,o,s){let i=[],a=[];return y(()=>{for(let u of a)u.dispose();i=[],a=[]}),b(()=>{let u=e()||[];return O(()=>{if(u.length===0){for(let c of a)c.dispose();return i=[],a=[],s?.fallback?s.fallback():[]}let l=new Map;for(let c=0;c<i.length;c++)l.set(i[c],a[c]);let t=[],p=[],d=new Set;for(let c=0;c<u.length;c++){let f=n(u[c]),h=l.get(f);if(h&&!d.has(f))h.setIndex(c),t.push(h);else{let v,w,x;m(q=>{x=q;let[D,j]=_(c);w=j;let K=b(V=>{let A=(e()||[])[D()];return A??V},u[c]);v=o(K,D)}),t.push({rendered:v,dispose:x,setIndex:w})}p.push(f),d.add(f)}for(let[c,f]of l)d.has(c)||f.dispose();return i=p,a=t,t.map(c=>c.rendered)})})}function pe(e,n,o){let s=[];return y(()=>{for(let i of s)i.dispose();s=[]}),b(()=>{let i=e()||[];return O(()=>{if(i.length===0){for(let t of s)t.dispose();return s=[],o?.fallback?o.fallback():[]}let a=s.length,u=i.length;for(let t=a;t<u;t++){let p,d,c,f=i[t];m(h=>{c=h;let[v,w]=_(f);d=w,p=n(v,t)}),s.push({rendered:p,setItem:d,dispose:c})}for(let t=u;t<a;t++)s[t].dispose();u<a&&(s=s.slice(0,u));let l=Math.min(a,u);for(let t=0;t<l;t++)s[t].setItem(i[t]);return s.map(t=>t.rendered)})})}export{pe as indexArray,fe as keyArray,de as mapArray};
|