@fluixi/reactive 1.0.0-alpha.83 → 1.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/reactive.cjs +2673 -1
- package/dist/cdn/reactive.global.js +2 -1
- package/dist/cdn/reactive.mjs +2657 -1
- package/dist/cdn/signal.cjs +299 -1
- package/dist/cdn/signal.d.ts +1 -1
- package/dist/cdn/signal.global.js +2 -1
- package/dist/cdn/signal.js +1 -1
- package/dist/cdn/signal.mjs +276 -1
- package/dist/index.cjs +2673 -1
- package/dist/index.mjs +2657 -1
- package/dist/lib/index.cjs +2674 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.mjs +2659 -1
- package/dist/lib/observable/index.cjs +386 -1
- package/dist/lib/observable/index.mjs +364 -1
- package/dist/lib/observable/observable.cjs +384 -1
- package/dist/lib/observable/observable.d.ts +0 -137
- package/dist/lib/observable/observable.d.ts.map +1 -1
- package/dist/lib/observable/observable.js +0 -71
- package/dist/lib/observable/observable.mjs +361 -1
- package/dist/lib/observable/subscription.cjs +180 -1
- package/dist/lib/observable/subscription.d.ts +0 -12
- package/dist/lib/observable/subscription.d.ts.map +1 -1
- package/dist/lib/observable/subscription.js +0 -12
- package/dist/lib/observable/subscription.mjs +157 -1
- package/dist/lib/observable/types.cjs +18 -1
- package/dist/lib/observable/types.d.ts.map +1 -1
- package/dist/lib/predicates.cjs +44 -1
- package/dist/lib/predicates.d.ts +2 -2
- package/dist/lib/predicates.js +2 -2
- package/dist/lib/predicates.mjs +23 -1
- package/dist/lib/signal/api.cjs +571 -1
- package/dist/lib/signal/api.d.ts +211 -1
- package/dist/lib/signal/api.d.ts.map +1 -1
- package/dist/lib/signal/api.js +207 -12
- package/dist/lib/signal/api.mjs +548 -1
- package/dist/lib/signal/cached-resource.cjs +672 -1
- package/dist/lib/signal/cached-resource.d.ts +28 -16
- package/dist/lib/signal/cached-resource.d.ts.map +1 -1
- package/dist/lib/signal/cached-resource.js +35 -29
- package/dist/lib/signal/cached-resource.mjs +650 -1
- package/dist/lib/signal/graph/children.cjs +325 -1
- package/dist/lib/signal/graph/children.js +1 -1
- package/dist/lib/signal/graph/children.mjs +302 -1
- package/dist/lib/signal/graph/compat.cjs +578 -1
- package/dist/lib/signal/graph/compat.d.ts +13 -13
- package/dist/lib/signal/graph/compat.d.ts.map +1 -1
- package/dist/lib/signal/graph/compat.js +33 -31
- package/dist/lib/signal/graph/compat.mjs +556 -1
- package/dist/lib/signal/graph/core.cjs +295 -1
- package/dist/lib/signal/graph/core.d.ts +28 -24
- package/dist/lib/signal/graph/core.d.ts.map +1 -1
- package/dist/lib/signal/graph/core.js +38 -31
- package/dist/lib/signal/graph/core.mjs +273 -1
- package/dist/lib/signal/graph/debounced.cjs +668 -1
- package/dist/lib/signal/graph/debounced.d.ts +5 -5
- package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
- package/dist/lib/signal/graph/debounced.js +5 -5
- package/dist/lib/signal/graph/debounced.mjs +645 -1
- package/dist/lib/signal/graph/derived.cjs +496 -1
- package/dist/lib/signal/graph/derived.d.ts +1 -1
- package/dist/lib/signal/graph/derived.js +1 -1
- package/dist/lib/signal/graph/derived.mjs +473 -1
- package/dist/lib/signal/graph/detect.cjs +66 -1
- package/dist/lib/signal/graph/detect.mjs +45 -1
- package/dist/lib/signal/graph/error-boundary.cjs +301 -1
- package/dist/lib/signal/graph/error-boundary.js +3 -3
- package/dist/lib/signal/graph/error-boundary.mjs +278 -1
- package/dist/lib/signal/graph/index.cjs +305 -1
- package/dist/lib/signal/graph/index.d.ts +7 -6
- package/dist/lib/signal/graph/index.d.ts.map +1 -1
- package/dist/lib/signal/graph/index.js +7 -6
- package/dist/lib/signal/graph/index.mjs +283 -1
- package/dist/lib/signal/graph/observe.cjs +163 -1
- package/dist/lib/signal/graph/observe.d.ts +8 -8
- package/dist/lib/signal/graph/observe.js +5 -5
- package/dist/lib/signal/graph/observe.mjs +140 -1
- package/dist/lib/signal/graph/resource.cjs +620 -1
- package/dist/lib/signal/graph/resource.d.ts +1 -1
- package/dist/lib/signal/graph/resource.js +7 -8
- package/dist/lib/signal/graph/resource.mjs +597 -1
- package/dist/lib/signal/graph/runtime.cjs +501 -1
- package/dist/lib/signal/graph/runtime.d.ts +7 -7
- package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
- package/dist/lib/signal/graph/runtime.js +34 -30
- package/dist/lib/signal/graph/runtime.mjs +478 -1
- package/dist/lib/signal/graph/signal-next.cjs +1208 -1
- package/dist/lib/signal/graph/signal-next.d.ts +5 -5
- package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
- package/dist/lib/signal/graph/signal-next.js +14 -12
- package/dist/lib/signal/graph/signal-next.mjs +1186 -1
- package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
- package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
- package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
- package/dist/lib/signal/graph/ssr-hooks.js +6 -7
- package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
- package/dist/lib/signal/graph/state.cjs +72 -1
- package/dist/lib/signal/graph/state.d.ts +41 -10
- package/dist/lib/signal/graph/state.d.ts.map +1 -1
- package/dist/lib/signal/graph/state.js +83 -22
- package/dist/lib/signal/graph/state.mjs +49 -1
- package/dist/lib/signal/graph/suspense.cjs +301 -1
- package/dist/lib/signal/graph/suspense.js +4 -4
- package/dist/lib/signal/graph/suspense.mjs +278 -1
- package/dist/lib/signal/index-legacy.cjs +2540 -1
- package/dist/lib/signal/index-legacy.d.ts +1 -1
- package/dist/lib/signal/index-legacy.js +1 -1
- package/dist/lib/signal/index-legacy.mjs +2518 -1
- package/dist/lib/signal/index.cjs +1275 -1
- package/dist/lib/signal/index.d.ts +3 -2
- package/dist/lib/signal/index.d.ts.map +1 -1
- package/dist/lib/signal/index.js +7 -4
- package/dist/lib/signal/index.mjs +1253 -1
- package/dist/lib/signal/list.cjs +549 -1
- package/dist/lib/signal/list.d.ts +5 -5
- package/dist/lib/signal/list.js +5 -5
- package/dist/lib/signal/list.mjs +526 -1
- package/dist/lib/signal/resource-api.cjs +626 -1
- package/dist/lib/signal/resource-api.d.ts +5 -5
- package/dist/lib/signal/resource-api.js +5 -5
- package/dist/lib/signal/resource-api.mjs +603 -1
- package/dist/lib/signal/signal.cjs +2023 -1
- package/dist/lib/signal/signal.d.ts +4 -4
- package/dist/lib/signal/signal.d.ts.map +1 -1
- package/dist/lib/signal/signal.js +22 -23
- package/dist/lib/signal/signal.mjs +2000 -1
- package/dist/lib/signal/types.cjs +38 -1
- package/dist/lib/signal/types.d.ts.map +1 -1
- package/dist/lib/signal/types.js +2 -2
- package/dist/lib/signal/types.mjs +17 -1
- package/dist/lib/signal/utilities.cjs +1012 -1
- package/dist/lib/signal/utilities.d.ts +0 -108
- package/dist/lib/signal/utilities.d.ts.map +1 -1
- package/dist/lib/signal/utilities.js +0 -158
- package/dist/lib/signal/utilities.mjs +990 -1
- package/dist/lib/store/api.cjs +612 -1
- package/dist/lib/store/api.d.ts +33 -0
- package/dist/lib/store/api.d.ts.map +1 -1
- package/dist/lib/store/api.js +41 -8
- package/dist/lib/store/api.mjs +596 -1
- package/dist/lib/store/index.cjs +691 -1
- package/dist/lib/store/index.js +1 -1
- package/dist/lib/store/index.mjs +676 -1
- package/dist/lib/store/setter.types.cjs +18 -1
- package/dist/lib/store/setter.types.d.ts +43 -3
- package/dist/lib/store/setter.types.d.ts.map +1 -1
- package/dist/lib/store/store.cjs +658 -1
- package/dist/lib/store/store.d.ts +72 -0
- package/dist/lib/store/store.d.ts.map +1 -1
- package/dist/lib/store/store.js +148 -5
- package/dist/lib/store/store.mjs +644 -1
- package/dist/lib/store/types.cjs +18 -1
- package/dist/lib/store/types.d.ts +1 -1
- package/dist/lib/store/types.d.ts.map +1 -1
- package/dist/lib/store/utils.cjs +43 -1
- package/dist/lib/store/utils.d.ts +1 -1
- package/dist/lib/store/utils.js +1 -1
- package/dist/lib/store/utils.mjs +22 -1
- package/dist/lib/subject.cjs +450 -1
- package/dist/lib/subject.js +3 -91
- package/dist/lib/subject.mjs +427 -1
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/version.generated.cjs +27 -1
- package/dist/version.generated.d.ts +1 -1
- package/dist/version.generated.js +2 -2
- package/dist/version.generated.mjs +7 -1
- package/package.json +5 -4
|
@@ -1 +1,2023 @@
|
|
|
1
|
-
"use strict";var we=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.prototype.hasOwnProperty;var ot=(e,n)=>{for(var t in n)we(e,t,{get:n[t],enumerable:!0})},st=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of tt(n))!rt.call(e,r)&&r!==t&&we(e,r,{get:()=>n[r],enumerable:!(o=nt(n,r))||o.enumerable});return e};var it=e=>st(we({},"__esModule",{value:!0}),e);var Et={};ot(Et,{$MEMO:()=>kn,$PROXY:()=>Ge,$RESOURCE:()=>_n,$SIGNAL:()=>he,__DEV__:()=>X,batch:()=>k,createComputed:()=>Wn,createContext:()=>Te,createDebounce:()=>mn,createDeferred:()=>wn,createEffect:()=>W,createMemo:()=>qn,createProvider:()=>Bn,createRenderEffect:()=>Ye,createResource:()=>Un,createRoot:()=>In,createSelector:()=>Pe,createSignal:()=>I,default:()=>Ft,flush:()=>jn,getOwner:()=>Mn,getServerData:()=>Le,getSharedConfig:()=>kt,getSuspenseContext:()=>$n,getSuspenseListContext:()=>zn,isComponent:()=>tn,isMemo:()=>en,isProvider:()=>on,isResource:()=>nn,isSignal:()=>J,isSuspense:()=>rn,makeArrayFlat:()=>ge,nextResourceId:()=>Be,on:()=>Gn,onCleanup:()=>ve,onResolve:()=>Yn,readChildren:()=>De,reportResourceData:()=>je,resumeEffects:()=>Kn,runWithOwner:()=>Ln,setOwner:()=>Ct,setResourceDataSink:()=>On,setResourceIdSource:()=>Sn,setResourceTracker:()=>xn,setScheduler:()=>Xn,setServerDataGetter:()=>gn,sharedConfig:()=>pe,startTransition:()=>Ke,trackPromise:()=>Jn,trackResourcePromise:()=>Me,untrack:()=>H,useContext:()=>_,useTransition:()=>Vn});module.exports=it(Et);function me(e){return typeof e=="function"&&!/^class\s/.test(Function.prototype.toString.call(e))}function Ze(e){return e==null||Array.isArray(e)||typeof e=="function"||e instanceof Date||e instanceof RegExp||e instanceof Map||e instanceof Set||e instanceof Error?!1:typeof e=="object"}function z(e){return e instanceof Promise||!!e&&(typeof e=="object"||typeof e=="function")&&"then"in e}var K=class e{constructor(n){this._closed=!1;this._parentOrParents=null;this._subscriptions=null;n&&(this._subscriptions=[n])}get closed(){return this._closed}unsubscribe(){if(this._closed)return;this._closed=!0;let{_parentOrParents:n,_subscriptions:t}=this;if(n instanceof e)n.remove(this);else if(n!==null)for(let o of n)o.remove(this);if(t){for(let o of t)if(me(o)&&!(o instanceof e))try{o()}catch(r){console.error("Error in unsubscribe function:",r)}else if(Ze(o)&&typeof o.unsubscribe=="function")try{o.unsubscribe()}catch(r){console.error("Error unsubscribing child:",r)}this._subscriptions=null}}add(n){if(!n||n===this)return this;if(n.closed)return this;let{_closed:t,_subscriptions:o}=this;if(t){if(me(n))try{n()}catch(r){console.error("Error in unsubscribe function:",r)}else if(n.unsubscribe)try{n.unsubscribe()}catch(r){console.error("Error unsubscribing:",r)}return this}return o||(this._subscriptions=[]),this._subscriptions.push(n),n instanceof e&&n._addParent(this),this}remove(n){let{_subscriptions:t}=this;if(!t)return;let o=t.indexOf(n);o!==-1&&(t.splice(o,1),n._removeParent(this))}_addParent(n){let{_parentOrParents:t}=this;t?Array.isArray(t)?t.push(n):this._parentOrParents=[t,n]:this._parentOrParents=n}_removeParent(n){let{_parentOrParents:t}=this;if(t===n)this._parentOrParents=null;else if(Array.isArray(t)){let o=t.indexOf(n);o!==-1&&(t.splice(o,1),t.length===1&&(this._parentOrParents=t[0]))}}};var oe=class extends K{constructor(t,o,r){super();this.isStopped=!1;let s;t?typeof t=="object"?s=t:s={next:t,error:o,complete:r}:s={},this.destination=s}next(t){if(!this.isStopped&&this.destination.next)try{this.destination.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped){if(this.isStopped=!0,this.destination.error)try{this.destination.error(t)}catch(o){throw o}else throw t;this.unsubscribe()}}complete(){if(!this.isStopped){if(this.isStopped=!0,this.destination.complete)try{this.destination.complete()}catch(t){this.error(t);return}this.unsubscribe()}}unsubscribe(){this.closed||(this.isStopped=!0,super.unsubscribe())}},xe=class extends oe{constructor(t,o,r,s){super(t,o,r);this._isUnsubscribing=!1;this._parentSubscriber=null;this._parentSubscriber=s||null}next(t){if(!this.isStopped&&!this._isUnsubscribing)try{super.next(t)}catch(o){this.error(o)}}error(t){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.error(t)}finally{this._isUnsubscribing=!1}}}complete(){if(!this.isStopped&&!this._isUnsubscribing){this._isUnsubscribing=!0;try{super.complete()}finally{this._isUnsubscribing=!1}}}unsubscribe(){this.closed||(this._isUnsubscribing=!0,super.unsubscribe(),this._isUnsubscribing=!1)}};var Y=class extends K{constructor(n){if(super(),n)this._subscribe=n;else throw new TypeError("Observable constructor requires a subscribe function")}subscribe(n,t,o){let r;n instanceof oe?r=n:r=new xe(n,t,o);let{_subscribe:s}=this;try{let l=s.call(this,r);l&&(typeof l=="function"||typeof l.unsubscribe=="function")&&r.add(l)}catch(l){r.error(l)}return r}pipe(...n){return n.length===0?this:n.reduce((t,o)=>o(t),this)}toPromise(){return new Promise((n,t)=>{let o;this.subscribe({next:r=>o=r,error:t,complete:()=>n(o)})})}};var ut=typeof window>"u"?!1:window.__FLUIXI_PROD__===!0,X=typeof process>"u"?ut:!1,at=Symbol.for("signal"),lt=Symbol.for("memo"),ct=Symbol.for("resource");function J(e){return typeof e=="function"&&e[at]===!0}function en(e){return typeof e=="function"&&e[lt]===!0}function nn(e){return typeof e=="function"&&e[ct]===!0}function tn(e){return typeof e=="function"&&e[Symbol.for("fluixi-component")]===!0}function rn(e){return typeof e=="function"&&e[Symbol.for("fluixi-suspense")]===!0}function on(e){return typeof e=="function"&&e[Symbol.for("fluixi-provider")]===!0}function ge(e){return Array.isArray(e)?e.length===2&&e[1]===" "?Array.isArray(e[0])?ge(e[0]):(typeof e[0]=="function",e[0]):e.length===1&&typeof e[0]=="function"?e[0]:e:e}var ft="__fluixi_signal_next_state__",dt=e=>{typeof queueMicrotask=="function"?queueMicrotask(e):Promise.resolve().then(e)},i=globalThis[ft]??={consumer:null,untracked:!1,owner:null,queue:[],scheduled:!1,flushing:!1,batchDepth:0,hostSchedule:dt,onSuspend:null,onError:null,observer:null};var sn="1.0.0-alpha.83";function pt(e){return i.observer=e,()=>{i.observer===e&&(i.observer=null)}}var Se=[],vt;function Q(e){let n=i.observer;n&&n.created(e.parents===void 0?{...e,parents:Se,origin:e.origin??vt}:e)}function an(e){return i.observer?(Se.push(e),!0):!1}function ln(){Se.pop()}function cn(e){i.observer?.ran?.(e)}function fn(e,n){i.observer?.wrote?.(e,n)}function Z(e){i.observer?.disposed?.(e)}var ht="__FLUIXI_DEVTOOLS_HOOK__",un=globalThis[ht];if(typeof un?.inject=="function")try{un.inject({observeReactiveNodes:pt,version:sn})}catch{}function Oe(){return i.observer!=null}var dn=0,pn=1,ee=2,se=class{constructor(){this.observers=null;this.watchers=null;this.version=0}updateIfNecessary(){}track(){if(i.untracked)return;let n=i.consumer;n&&((this.observers??=new Set).add(n),(n.sources??=new Set).add(this))}},ie=class extends se{constructor(n,t){super(),this._value=n,this._equals=t?.equals===!1?()=>!1:t?.equals??Object.is}get(){return this.track(),this._value}set(n){if(!this._equals(this._value,n)){if(this._value=n,this.version++,fn(this,i.consumer),this.observers)for(let t of[...this.observers])t.markDirty(ee);Re(this)}}peek(){return this._value}},j=class extends se{constructor(t,o){super();this._threw=!1;this._initialized=!1;this.state=ee;this.sources=null;this._fn=t,this._equals=o?.equals===!1?()=>!1:o?.equals??Object.is}get(){if(i.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===pn&&this.sources){for(let t of this.sources)if(t.updateIfNecessary(),this.state===ee)break}(this.state===ee||!this._initialized)&&this.recompute(),this.state=dn}recompute(){if(this.sources){for(let f of this.sources)f.observers?.delete(this);this.sources.clear()}let t=i.consumer,o=i.untracked,r=an(this);i.consumer=this,i.untracked=!1;let s,l=!1,c;try{s=this._fn()}catch(f){l=!0,c=f,s=this._value}finally{i.consumer=t,i.untracked=o,r&&ln()}let v=!this._initialized||this._threw!==l||(l?c!==this._error:!this._equals(this._value,s));if(this._initialized=!0,this._threw=l,this._error=c,this._value=s,cn(this),v){if(this.version++,this.observers)for(let f of[...this.observers])f.markDirty(ee);Re(this)}}markDirty(t){if(this.state>=t)return;let o=this.state===dn;if(this.state=t,o){if(this.observers)for(let r of[...this.observers])r.markDirty(pn);Re(this)}}peek(){if(this.updateIfNecessary(),this._threw)throw this._error;return this._value}};function Re(e){if(e.watchers)for(let n of[...e.watchers])n._notify(e)}var ue=class{constructor(n){this._watched=new Set;this._pending=new Set;this._notifyFn=n}watch(...n){for(let t of n)this._watched.add(t),(t.watchers??=new Set).add(this)}unwatch(...n){for(let t of n)this._watched.delete(t),t.watchers?.delete(this),this._pending.delete(t)}getPending(){let n=[...this._pending];return this._pending.clear(),n}_notify(n){if(!this._watched.has(n)||this._pending.has(n))return;let t=this._pending.size===0;this._pending.add(n),t&&this._notifyFn()}};function bt(e){return{cleanups:null,owned:null,parent:e,contexts:null}}function vn(e){return i.onSuspend?(i.onSuspend(e,i.owner),!0):!1}function _e(){return i.owner}function ae(e,n){let t=i.owner;i.owner=e;try{return n()}finally{i.owner=t}}function V(e){if(i.owner){if(i.owner.disposed){e();return}(i.owner.cleanups??=[]).push(e)}}function Ce(e,n=!0){if(!e.disposed){if(e.owned){for(let t=e.owned.length-1;t>=0;t--)Ce(e.owned[t]);e.owned=null}if(e.cleanups){for(let t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}n&&(e.disposed=!0)}}function hn(e){i.hostSchedule=e??(n=>{Promise.resolve().then(n)})}function Tt(e){e.queued||(e.queued=!0,i.queue.push(e),!i.scheduled&&i.batchDepth===0&&(i.scheduled=!0,i.hostSchedule(Ae)))}function Ae(){if(i.scheduled=!1,i.flushing)return;i.flushing=!0;let e=0;try{for(;i.queue.length;){if(++e>1e5)throw new Error("[fluixi] effect flush did not settle (cycle?)");let n=i.queue;i.queue=[];for(let t of n)t.queued=!1,t.disposed||t.run()}}finally{i.flushing=!1}}function bn(){i.batchDepth===0&&Ae()}var ke=class{constructor(n,t=!1){this.queued=!1;this.disposed=!1;this.owner=bt(i.owner),i.owner&&(i.owner.cleanups??=[]).push(()=>this.dispose()),this.computed=new j(()=>{Ce(this.owner,!1),ae(this.owner,()=>{let o=n();typeof o=="function"&&(this.owner.cleanups??=[]).push(o)})}),Q({kind:"effect",node:this.computed,handle:this,internal:!t}),this.watcher=new ue(()=>Tt(this)),this.run(),this.watcher.watch(this.computed)}run(){if(!this.disposed){this.watcher.getPending();try{this.computed.get()}catch(n){if(n&&typeof n.then=="function"&&i.onSuspend){i.onSuspend(n,this.owner);return}if(i.onError&&i.onError(n,this.owner))return;throw n}}}dispose(){this.disposed||(this.disposed=!0,Z(this.computed),this.watcher.unwatch(this.computed),Ce(this.owner))}};function Tn(e,n=!1){let t=new ke(e,n);return()=>t.dispose()}function yt(e){return!!e&&typeof e.then=="function"}hn(()=>{});var yn=Symbol.for("signal"),wt=Symbol.for("memo"),mt=Symbol.for("signal-node");function Fe(e,n){let t=new ie(e,{equals:n?.equals}),o=(()=>t.get()),r=(s=>{let l=typeof s=="function"?s(t.peek()):s;return t.set(l),bn(),l});return Object.defineProperty(o,yn,{value:!0,enumerable:!0}),Object.defineProperty(o,mt,{value:{get value(){return t.peek()},get version(){return t.version}},enumerable:!1}),Q({kind:"signal",node:t,handle:o,name:n?.name,set:r}),Oe()&&V(()=>Z(t)),[o,r]}function le(e,n,t){let o=n,r=_e(),s=new j(()=>ae(r,()=>{try{return o=e(o)}catch(c){if(yt(c))return vn(c),o;throw c}}),{equals:t?.equals}),l=(()=>s.get());return Object.defineProperty(l,yn,{value:!0,enumerable:!0}),Object.defineProperty(l,wt,{value:!0,enumerable:!0}),Q({kind:"memo",node:s,handle:l,name:t?.name}),Oe()&&V(()=>Z(s)),l}function Ee(e,n){let t=n;return Tn(()=>{t=e(t)},!0)}function Pe(e,n=(t,o)=>t===o){let t=new Map;return Ee(()=>{let o=e();for(let[r,s]of t){let[l,c]=s,v=n(r,o);l()!==v&&c(v)}}),o=>{let r=t.get(o);if(!r){let[s,l]=Fe(!1);r=[s,l],t.set(o,r);let c=e();l(n(o,c))}return r[0]()}}function wn(e,n){let[t,o]=Fe(e(),n);return Ee(()=>{let r=e();n?.timeoutMs?setTimeout(()=>o(()=>r),n.timeoutMs):typeof requestIdleCallback=="function"?requestIdleCallback(()=>o(()=>r)):Promise.resolve().then(()=>o(()=>r))}),t}function mn(e,n){let t,o=(...r)=>{t!==void 0&&clearTimeout(t),t=setTimeout(()=>{t=void 0,e(...r)},n)};return V(()=>{t!==void 0&&clearTimeout(t)}),o}function ce(e){if(typeof e=="function"&&!e.length){let n=e();return J(n)?n:ce(n)}if(Array.isArray(e)){let n=[];for(let t=0;t<e.length;t++){let o=ce(e[t]);Array.isArray(o)?n.push.apply(n,o):n.push(o)}return n}return e}function De(e){let n=le(e);return X?le(()=>ce(n()),void 0,{name:"children"}):le(()=>ce(n()))}var qe=null;function xn(e){qe=e}function Me(e){qe&&qe(e)}var Ne=null;function gn(e){Ne=e}function Le(e){return Ne?Ne(e):void 0}var Ie=null;function Sn(e){Ie=e}function Be(){return Ie?Ie():void 0}var Ue=null;function On(e){Ue=e}function je(e,n){Ue&&Ue(e,n)}var he=Symbol.for("signal"),kn=Symbol.for("memo"),_n=Symbol.for("resource"),Ge=Symbol("fluixi-proxy"),An=Symbol.for("signal-node"),A=0,ne=1,E=2,F=3,a=null,d=null,u=null,fe=null,de=0,xt=!1,Ve=!1,G=0,gt=1e6,w=new WeakMap,g=null;var St=null,Ot=new Map,Rt=0,pe={context:null,owner:null,routeData:new Map,matchedRoute:new Map};function Ct(e){a=e,pe.owner=e,pe.context=e}function kt(){return pe}function _t(){return`node_${++Rt}_${Date.now()}`}function At(e){X&&Ot.set(e.id,new WeakRef(e))}function Fn(e,n,t){let o={id:_t(),type:e,value:n,version:0,equals:t?.equals,name:t?.name,created:Date.now(),updated:Date.now()};return At(o),o}function En(e,n){return e===n}function $e(e){throw typeof console<"u"&&console.error("Reactive error:",e),e}var He=null,We=null;function Pn(){if(!He){let[e,n]=I(!1);He=e,We=n}}function Dn(e){if(u)u.indexOf(e)===-1&&u.push(e);else if(g&&g.running&&!e.pure)g.effects.indexOf(e)===-1&&g.effects.push(e);else if(!e.pure||e.computed)te(e);else if(e.pure&&!e.computed&&e.accessor){let n=d,t=u;d=null,u=[],e.accessor(),d=n;let o=u;if(u=t,o.length>0){let r=u;be(o),u=r}}}function Rn(e,n){for(let t=0;t<e.length;t++)n(e[t])}function I(e,n){let t=e;typeof t=="object"&&t&&Ge in t&&delete t[Ge];let o=Fn("signal",t,{equals:n?.equals===!1?void 0:n?.equals,name:n?.name}),r=[l,c];w.set(r,new Set);let s;function l(){let v=d;if(v){v.sources?v.sources.indexOf(r)===-1&&v.sources.push(r):v.sources=[r];let f=w.get(r);f&&!f.has(v)&&f.add(v)}return t}function c(v){let f=typeof v=="function"?v(t):v,T=o.equals||En;if(n?.equals===!1||!T(t,f)){t=f,o.value=f,o.version++,o.updated=Date.now();let P=w.get(r);if(P&&P.size>0){let D=function(p,h=!1){let q=p.state;if(!(q===F&&p===d)){if(h&&!p.pure){q===A&&(p.state=ne,xt&&(u!==null&&u.indexOf(p)===-1?u.push(p):R.push(p)));return}if(!m.has(p)&&(m.add(p),p.state=E,q===A||q===ne?R.push(p):!p.pure&&u!==null&&u.indexOf(p)===-1&&u.push(p),p.pure&&p.accessor)){let O=w.get(p.accessor);O&&Rn(Array.from(O),C=>D(C,!0))}}};var x=D;let S=Array.from(P),R=[],m=new Set;Rn(S,D);for(let p of R)Dn(p)}}}return l.toObservable=()=>new Y(v=>{let f=!0;return W(()=>{let x=l();f?f=!1:v.next(x)})}),Object.defineProperty(l,he,{value:!0,enumerable:!0}),Object.defineProperty(l,An,{value:o,enumerable:!1}),r}function W(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,owned:null,cleanups:null,owner:a,contexts:null,pure:!1,updatedAt:null};a&&(a.owned?a.owned.push(o):a.owned=[o]);let r=b&&_(b);return r&&(o.suspense=r),ze(o,n),()=>U(o)}function ze(e,n){if(e.sources){for(let r of e.sources){let s=w.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let t=d,o=a;if(d=e,a=e,de++,de>gt)throw de=0,d=t,a=o,new Error("Potential infinite loop detected. Exceeded maximum iterations.");try{e.state=F;let r=e.fn(n);typeof r=="function"&&(e.cleanups?e.cleanups.push(r):e.cleanups=[r]),e.state===F&&(e.state=A)}catch(r){if(z(r)){let s=b&&_(b);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}$e(r)}finally{d=t,a=o}}function te(e){if(!(e.disposed||!e.fn||e.state===A)&&(e.state===E||e.state===ne||e.state===F)){if(e.cleanups){for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();e.cleanups=null}if(e.owned){for(let n=0;n<e.owned.length;n++)U(e.owned[n]);e.owned=null}e.renderEffect?Hn(e):ze(e,e.value)}}function U(e){if(e.disposed=!0,e.sources)for(let n of e.sources){let t=w.get(n);t&&t.delete(e)}if(e.cleanups)for(let n=0;n<e.cleanups.length;n++)e.cleanups[n]();if(e.owned)for(let n=0;n<e.owned.length;n++)U(e.owned[n]);if(e.owner&&e.owner.owned){let n=e.owner.owned.indexOf(e);n!==-1&&e.owner.owned.splice(n,1)}}function qn(e,n,t){let o=Fn("memo",n,{equals:t?.equals===!1?void 0:t?.equals,name:t?.name}),r={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:a,contexts:null,pure:!0,updatedAt:null,node:o,accessor:void 0};a&&(a.owned?a.owned.push(r):a.owned=[r]);let s=()=>{if(d&&d!==r){d.sources?d.sources.indexOf(s)===-1&&d.sources.push(s):d.sources=[s];let c=s;w.has(c)||w.set(c,new Set);let v=w.get(c);v&&v.add(d)}if(r.state!==A){if(r.sources){for(let f of r.sources){let T=w.get(f);T&&T.delete(r)}r.sources=null,r.sourceSlots=null}if(r.cleanups){for(let f=0;f<r.cleanups.length;f++)r.cleanups[f]();r.cleanups=null}if(r.owned){for(let f=0;f<r.owned.length;f++)U(r.owned[f]);r.owned=null}let c=d,v=a;d=r,a=r,r.state=F;try{let f=r.fn(r.value),T=o.equals||En;if(t?.equals===!1||!T(r.value,f)){r.value=f,o.value=f,o.version++,o.updated=Date.now();let P=s,S=w.get(P);if(S&&S.size>0){let p=function(h,q=!1){if(h===r)return;let O=h.state;if(O!==F){if(q&&!h.pure){O===A&&(h.state=ne,u!==null&&u.indexOf(h)===-1?u.push(h):m.push(h));return}if(!D.has(h)&&(D.add(h),h.state=E,O===A||O===ne?m.push(h):!h.pure&&u!==null&&u.indexOf(h)===-1&&u.push(h),h.pure&&h.accessor)){let C=w.get(h.accessor);if(C&&C.size>0)for(let $ of Array.from(C))p($,!0)}}};var l=p;let R=Array.from(S),m=[],D=new Set;for(let h=0;h<R.length;h++)p(R[h]);for(let h of m)Dn(h)}}r.state===F&&(r.state=A)}catch(f){if(z(f)){let T=b&&_(b);if(!T&&b){let x=v;for(;x;){if(x.contexts?.has(b.id)){T=x.contexts.get(b.id);break}x=x.owner}}return T&&(T.increment(),f.finally(()=>T.decrement())),r.value}$e(f)}finally{d=c,a=v}}return r.value};return r.accessor=s,w.set(s,new Set),s.toObservable=()=>new Y(l=>{let c=!0;return W(()=>{let f=s();c?c=!1:l.next(f)})}),Object.defineProperty(s,he,{value:!0,enumerable:!0}),Object.defineProperty(s,kn,{value:!0,enumerable:!0}),Object.defineProperty(s,An,{value:o,enumerable:!1}),s}function be(e){let n=[],t=[];for(let r of e)r.pure&&!r.computed&&r.accessor?n.indexOf(r)===-1&&n.push(r):(r.computed||!r.pure)&&t.indexOf(r)===-1&&t.push(r);u=[];let o=0;for(;o<n.length;){let r=n[o++],s=w.get(r.accessor);if(s&&s.size>0){let c=d;d=null,r.accessor(),d=c}let l=u.splice(0);for(let c of l)c.pure&&!c.computed&&c.accessor?n.indexOf(c)===-1&&n.push(c):(c.computed||!c.pure)&&t.indexOf(c)===-1&&t.push(c)}u=null;for(let r of t)(r.computed||!r.pure)&&te(r)}function k(e){if(u&&G>0)return e();if(u&&G===0){let n=u,t=[];u=t,G++;let o;try{o=e()}finally{G--,u=n}let r=u;return be(t),u=r,o}G++,u=[],fe=[];try{return e()}finally{G--,Nn()}}function Nn(){if(!Ve){Ve=!0,de=0;try{for(;u&&u.length>0;){let e=u;u=null,be(e)}if(u=null,fe){let e=fe;fe=null;for(let n=0;n<e.length;n++)te(e[n])}}finally{Ve=!1}}}function In(e){let n={owned:null,cleanups:null,contexts:null,owner:a},t=d;d=null;let o=a;a=n;try{return e(()=>{if(n.owned)for(let r=0;r<n.owned.length;r++)U(n.owned[r]);if(n.cleanups)for(let r=0;r<n.cleanups.length;r++)n.cleanups[r]()})}finally{a=o,d=t}}function H(e){let n=d;d=null;try{return e()}finally{d=n}}function ve(e){a&&(a.cleanups?a.cleanups.push(e):a.cleanups=[e])}function Un(e,n,t={}){let o,r;typeof n=="function"?(o=typeof e=="function"?e:()=>e,r=n):(o=()=>!0,r=e,n&&typeof n=="object"&&(t=n));let{initialValue:s,name:l}=t,c=t.transport===!1?void 0:Be(),v=c!==void 0?Le(c):void 0,f=v!==void 0,[T,x]=I(v!==void 0?v.value:t.initialValue,{equals:!1}),[P,S]=I(void 0,{equals:!1}),[R,m]=I(v!==void 0||t.initialValue!==void 0?"ready":"unresolved",{equals:!1}),[D,p]=I(void 0,{equals:!1}),[h,q]=I(void 0,{equals:!1}),O=Symbol(),C=O,$=!1,Qn=y=>{if(!(typeof localStorage>"u"))try{y&&localStorage.setItem("storage",JSON.stringify({data:y,timestamp:Date.now()}))}catch(L){console.error(`Failed to save resource to cache (${l}):`,L)}},Zn=W(()=>{let y=o?o():e;if(h(),y===!1||y===null||y===void 0){C=O,k(()=>{m("unresolved"),p(void 0),S(void 0)});return}let L=$;if($=!1,C!==O&&y===C&&!L)return;if(C=y,f){f=!1;return}let B=!1;ve(()=>B=!0);let Je=H(R),et=H(T),Qe=Je==="ready"||Je==="refreshing";k(()=>{m(Qe?"refreshing":"pending"),S(void 0)});try{let N=r(y,{value:et,refetching:Qe});if(z(N)){p(N),Me(N),N.then(M=>{B||(c!==void 0&&je(c,M),k(()=>{x(()=>M),Qn(M),m("ready"),p(void 0)}))},M=>{B||k(()=>{S(M),m("errored"),p(void 0)})}).catch(M=>{B||k(()=>{S(M),m("errored"),p(void 0)})});let ye=b&&_(b);ye&&(ye.increment(),N.finally(()=>ye.decrement()))}else{if(B)return;k(()=>{x(()=>N),m("ready"),p(void 0)})}}catch(N){if(B)return;k(()=>{S(N),m("errored"),p(void 0)})}});ve(Zn);let Xe=()=>{let y=R();return y==="pending"||y==="refreshing"},re=(()=>{let y=P();if(y)throw y;if(Xe()){let L=D();if(L)throw L}return T()});return Object.defineProperty(re,_n,{value:!0,enumerable:!0}),Object.defineProperty(re,he,{value:!0,enumerable:!0}),Object.defineProperties(re,{state:{get:R},loading:{get:()=>Xe()},error:{get:P},latest:{get:T}}),[re,{mutate:x,refetch:()=>{$=!0,q(void 0)}}]}function Mn(){return a}function Ln(e,n){let t=a,o=d;a=e,d=null;try{return n()}finally{a=t,d=o}}function Te(e){let n=Symbol("context"),t=Bn(n);return{id:n,Provider:t,defaultValue:e}}function Bn(e){return n=>{let t=a;for(;t;)t.contexts||(t.contexts=new Map),t.contexts.has(e)||t.contexts.set(e,n.value),t=t.owner;let o;return Ye(()=>{o=H(()=>{let r=a;return r&&(r.contexts||(r.contexts=new Map),r.contexts.set(e,n.value)),De(()=>n.children)})}),o}}function _(e){let n=a;for(;n;){if(n.contexts&&n.contexts.has(e.id))return n.contexts.get(e.id);n=n.owner}if(e)return e.defaultValue}function jn(){return new Promise(e=>{queueMicrotask(()=>{Nn(),e()})})}function Ke(e){if(g&&g.running)return e(),g.done;Pn();let n,t=new Promise(r=>n=r),o={running:!0,effects:[],resolve:n,done:t};g=o;try{e()}finally{o.running=!1}return o.effects.length?(We(!0),Promise.resolve().then(()=>{let r=o.effects.splice(0);g=null,We(!1),r.length&&k(()=>{for(let s of r)s.state=E,te(s)}),n()}),t):(g=null,n(),t)}function Vn(){return Pn(),[He,Ke]}function Gn(e,n,t){let o=t?.defer??!1,r=!0;return s=>{let l=e();return o&&r?(r=!1,s):H(()=>n(l,s))}}function Ye(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:a,contexts:null,pure:!1,updatedAt:null,renderEffect:!0};a&&(a.owned?a.owned.push(o):a.owned=[o]);let r=b&&_(b);return r&&(o.suspense=r),Hn(o),()=>U(o)}function Hn(e){if(e.sources){for(let r of e.sources){let s=w.get(r);s&&s.delete(e)}e.sources=null,e.sourceSlots=null}if(e.cleanups){for(let r=0;r<e.cleanups.length;r++)e.cleanups[r]();e.cleanups=null}if(e.owned){for(let r=0;r<e.owned.length;r++)U(e.owned[r]);e.owned=null}let n=d,t=a,o=u;d=e,a=e,u===null&&(u=[]),e.state=F;try{let r=e.fn(e.value);typeof r=="function"&&(e.cleanups||(e.cleanups=[]),e.cleanups.push(r)),e.value=r,e.state===F&&(e.state=A)}catch(r){if(z(r)){let s=b&&_(b);s&&(s.increment(),r.finally(()=>s.decrement()),e.suspense&&s.effects.push(e));return}$e(r)}finally{d=n,a=t;let r=u;if(u=o,r!==o&&r&&r.length>0){let s=u;be(r),u=s}}}function Wn(e,n,t){let o={fn:e,state:E,sources:null,sourceSlots:null,value:n,owned:null,cleanups:null,owner:a,contexts:null,pure:!0,computed:!0,updatedAt:null};a&&(a.owned?a.owned.push(o):a.owned=[o]),g&&g.running?(u||(u=[]),u.indexOf(o)===-1&&u.push(o)):u?u.indexOf(o)===-1&&u.push(o):ze(o,n)}var b;function $n(){return b||(b=Te())}var Cn;function zn(){return Cn||(Cn=Te())}function Kn(e){if(!e.length)return;let n=e.slice();e.length=0;for(let t of n)t.state=E,te(t)}function Yn(e){let n=b&&_(b);n&&n.inFallback()?W(()=>{n.inFallback()||e()}):e()}function Xn(e){St=e}function Jn(e){let n=b&&_(b);return n&&(n.increment(),e.finally(()=>n.decrement())),e}var Ft={createSignal:I,createEffect:W,createMemo:qn,createComputed:Wn,createRoot:In,createSelector:Pe,createResource:Un,batch:k,untrack:H,onCleanup:ve,getOwner:Mn,runWithOwner:Ln,createContext:Te,useContext:_,flush:jn,startTransition:Ke,useTransition:Vn,isSignal:J,on:Gn,createRenderEffect:Ye,getSuspenseContext:$n,getSuspenseListContext:zn,resumeEffects:Kn,onResolve:Yn,setScheduler:Xn,trackPromise:Jn};
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/lib/signal/signal.ts
|
|
21
|
+
var signal_exports = {};
|
|
22
|
+
__export(signal_exports, {
|
|
23
|
+
$MEMO: () => $MEMO3,
|
|
24
|
+
$PROXY: () => $PROXY,
|
|
25
|
+
$RESOURCE: () => $RESOURCE2,
|
|
26
|
+
$SIGNAL: () => $SIGNAL3,
|
|
27
|
+
__DEV__: () => __DEV__,
|
|
28
|
+
batch: () => batch2,
|
|
29
|
+
createComputed: () => createComputed,
|
|
30
|
+
createContext: () => createContext,
|
|
31
|
+
createDebounce: () => createDebounce,
|
|
32
|
+
createDeferred: () => createDeferred,
|
|
33
|
+
createEffect: () => createEffect2,
|
|
34
|
+
createMemo: () => createMemo2,
|
|
35
|
+
createProvider: () => createProvider,
|
|
36
|
+
createRenderEffect: () => createRenderEffect,
|
|
37
|
+
createResource: () => createResource,
|
|
38
|
+
createRoot: () => createRoot2,
|
|
39
|
+
createSelector: () => createSelector,
|
|
40
|
+
createSignal: () => createSignal2,
|
|
41
|
+
default: () => signal_default,
|
|
42
|
+
flush: () => flush,
|
|
43
|
+
getOwner: () => getOwner2,
|
|
44
|
+
getServerData: () => getServerData,
|
|
45
|
+
getSharedConfig: () => getSharedConfig,
|
|
46
|
+
getSuspenseContext: () => getSuspenseContext,
|
|
47
|
+
getSuspenseListContext: () => getSuspenseListContext,
|
|
48
|
+
isComponent: () => isComponent,
|
|
49
|
+
isMemo: () => isMemo,
|
|
50
|
+
isProvider: () => isProvider,
|
|
51
|
+
isResource: () => isResource,
|
|
52
|
+
isSignal: () => isSignal,
|
|
53
|
+
isSuspense: () => isSuspense,
|
|
54
|
+
makeArrayFlat: () => makeArrayFlat,
|
|
55
|
+
nextResourceId: () => nextResourceId,
|
|
56
|
+
on: () => on,
|
|
57
|
+
onCleanup: () => onCleanup2,
|
|
58
|
+
onResolve: () => onResolve,
|
|
59
|
+
readChildren: () => readChildren,
|
|
60
|
+
reportResourceData: () => reportResourceData,
|
|
61
|
+
resumeEffects: () => resumeEffects,
|
|
62
|
+
runWithOwner: () => runWithOwner2,
|
|
63
|
+
setOwner: () => setOwner2,
|
|
64
|
+
setResourceDataSink: () => setResourceDataSink,
|
|
65
|
+
setResourceIdSource: () => setResourceIdSource,
|
|
66
|
+
setResourceTracker: () => setResourceTracker,
|
|
67
|
+
setScheduler: () => setScheduler2,
|
|
68
|
+
setServerDataGetter: () => setServerDataGetter,
|
|
69
|
+
sharedConfig: () => sharedConfig,
|
|
70
|
+
startTransition: () => startTransition,
|
|
71
|
+
trackPromise: () => trackPromise,
|
|
72
|
+
trackResourcePromise: () => trackResourcePromise,
|
|
73
|
+
untrack: () => untrack2,
|
|
74
|
+
useContext: () => useContext,
|
|
75
|
+
useTransition: () => useTransition
|
|
76
|
+
});
|
|
77
|
+
module.exports = __toCommonJS(signal_exports);
|
|
78
|
+
|
|
79
|
+
// src/lib/predicates.ts
|
|
80
|
+
function isFunction(value) {
|
|
81
|
+
return typeof value === "function" && !/^class\s/.test(Function.prototype.toString.call(value));
|
|
82
|
+
}
|
|
83
|
+
function isObject(value) {
|
|
84
|
+
if (value == null) return false;
|
|
85
|
+
if (Array.isArray(value)) return false;
|
|
86
|
+
if (typeof value === "function") return false;
|
|
87
|
+
if (value instanceof Date) return false;
|
|
88
|
+
if (value instanceof RegExp) return false;
|
|
89
|
+
if (value instanceof Map) return false;
|
|
90
|
+
if (value instanceof Set) return false;
|
|
91
|
+
if (value instanceof Error) return false;
|
|
92
|
+
return typeof value === "object";
|
|
93
|
+
}
|
|
94
|
+
function isPromise(value) {
|
|
95
|
+
return value instanceof Promise || !!value && (typeof value === "object" || typeof value === "function") && "then" in value;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// src/lib/observable/subscription.ts
|
|
99
|
+
var Subscription = class _Subscription {
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new Subscription.
|
|
102
|
+
*/
|
|
103
|
+
constructor(unsubscribe) {
|
|
104
|
+
/** @private */
|
|
105
|
+
this._closed = false;
|
|
106
|
+
/** @private */
|
|
107
|
+
this._parentOrParents = null;
|
|
108
|
+
/** @private */
|
|
109
|
+
this._subscriptions = null;
|
|
110
|
+
if (unsubscribe) {
|
|
111
|
+
this._subscriptions = [unsubscribe];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether the subscription is closed.
|
|
116
|
+
*/
|
|
117
|
+
get closed() {
|
|
118
|
+
return this._closed;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Disposes the resources held by the subscription.
|
|
122
|
+
* May be called multiple times (idempotent).
|
|
123
|
+
*/
|
|
124
|
+
unsubscribe() {
|
|
125
|
+
if (this._closed) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
this._closed = true;
|
|
129
|
+
const { _parentOrParents, _subscriptions } = this;
|
|
130
|
+
if (_parentOrParents instanceof _Subscription) {
|
|
131
|
+
_parentOrParents.remove(this);
|
|
132
|
+
} else if (_parentOrParents !== null) {
|
|
133
|
+
for (const parent of _parentOrParents) {
|
|
134
|
+
parent.remove(this);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (_subscriptions) {
|
|
138
|
+
for (const sub of _subscriptions) {
|
|
139
|
+
if (isFunction(sub) && !(sub instanceof _Subscription)) {
|
|
140
|
+
try {
|
|
141
|
+
sub();
|
|
142
|
+
} catch (error) {
|
|
143
|
+
console.error("Error in unsubscribe function:", error);
|
|
144
|
+
}
|
|
145
|
+
} else if (isObject(sub) && typeof sub.unsubscribe === "function") {
|
|
146
|
+
try {
|
|
147
|
+
sub.unsubscribe();
|
|
148
|
+
} catch (error) {
|
|
149
|
+
console.error("Error unsubscribing child:", error);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
this._subscriptions = null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Adds a child subscription or cleanup function to this subscription.
|
|
158
|
+
* When this subscription is unsubscribed, all added subscriptions/functions will be unsubscribed/called.
|
|
159
|
+
*
|
|
160
|
+
* @throws {TypeError} If the argument is not a subscription-like object or function
|
|
161
|
+
*/
|
|
162
|
+
add(subscription) {
|
|
163
|
+
if (!subscription || subscription === this) {
|
|
164
|
+
return this;
|
|
165
|
+
}
|
|
166
|
+
if (subscription.closed) {
|
|
167
|
+
return this;
|
|
168
|
+
}
|
|
169
|
+
let { _closed, _subscriptions } = this;
|
|
170
|
+
if (_closed) {
|
|
171
|
+
if (isFunction(subscription)) {
|
|
172
|
+
try {
|
|
173
|
+
subscription();
|
|
174
|
+
} catch (error) {
|
|
175
|
+
console.error("Error in unsubscribe function:", error);
|
|
176
|
+
}
|
|
177
|
+
} else if (subscription.unsubscribe) {
|
|
178
|
+
try {
|
|
179
|
+
subscription.unsubscribe();
|
|
180
|
+
} catch (error) {
|
|
181
|
+
console.error("Error unsubscribing:", error);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
}
|
|
186
|
+
if (!_subscriptions) {
|
|
187
|
+
this._subscriptions = [];
|
|
188
|
+
}
|
|
189
|
+
this._subscriptions.push(subscription);
|
|
190
|
+
if (subscription instanceof _Subscription) {
|
|
191
|
+
subscription._addParent(this);
|
|
192
|
+
}
|
|
193
|
+
return this;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Removes a child subscription from this subscription.
|
|
197
|
+
*/
|
|
198
|
+
remove(subscription) {
|
|
199
|
+
const { _subscriptions } = this;
|
|
200
|
+
if (!_subscriptions) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const index = _subscriptions.indexOf(subscription);
|
|
204
|
+
if (index !== -1) {
|
|
205
|
+
_subscriptions.splice(index, 1);
|
|
206
|
+
subscription._removeParent(this);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** @private */
|
|
210
|
+
_addParent(parent) {
|
|
211
|
+
const { _parentOrParents } = this;
|
|
212
|
+
if (!_parentOrParents) {
|
|
213
|
+
this._parentOrParents = parent;
|
|
214
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
215
|
+
_parentOrParents.push(parent);
|
|
216
|
+
} else {
|
|
217
|
+
this._parentOrParents = [_parentOrParents, parent];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/** @private */
|
|
221
|
+
_removeParent(parent) {
|
|
222
|
+
const { _parentOrParents } = this;
|
|
223
|
+
if (_parentOrParents === parent) {
|
|
224
|
+
this._parentOrParents = null;
|
|
225
|
+
} else if (Array.isArray(_parentOrParents)) {
|
|
226
|
+
const index = _parentOrParents.indexOf(parent);
|
|
227
|
+
if (index !== -1) {
|
|
228
|
+
_parentOrParents.splice(index, 1);
|
|
229
|
+
if (_parentOrParents.length === 1) {
|
|
230
|
+
this._parentOrParents = _parentOrParents[0];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// src/lib/observable/observable.ts
|
|
238
|
+
var Subscriber = class extends Subscription {
|
|
239
|
+
/**
|
|
240
|
+
* Creates a new Subscriber.
|
|
241
|
+
*/
|
|
242
|
+
constructor(destinationOrNext, error, complete) {
|
|
243
|
+
super();
|
|
244
|
+
/** @private */
|
|
245
|
+
this.isStopped = false;
|
|
246
|
+
let observer;
|
|
247
|
+
if (!destinationOrNext) {
|
|
248
|
+
observer = {};
|
|
249
|
+
} else if (typeof destinationOrNext === "object") {
|
|
250
|
+
observer = destinationOrNext;
|
|
251
|
+
} else {
|
|
252
|
+
observer = {
|
|
253
|
+
next: destinationOrNext,
|
|
254
|
+
error,
|
|
255
|
+
complete
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
this.destination = observer;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Sends the next value to the observer.
|
|
262
|
+
*/
|
|
263
|
+
next(value) {
|
|
264
|
+
if (!this.isStopped && this.destination.next) {
|
|
265
|
+
try {
|
|
266
|
+
this.destination.next(value);
|
|
267
|
+
} catch (error) {
|
|
268
|
+
this.error(error);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Sends an error notification to the observer.
|
|
274
|
+
*/
|
|
275
|
+
error(err) {
|
|
276
|
+
if (!this.isStopped) {
|
|
277
|
+
this.isStopped = true;
|
|
278
|
+
if (this.destination.error) {
|
|
279
|
+
try {
|
|
280
|
+
this.destination.error(err);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
throw error;
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
throw err;
|
|
286
|
+
}
|
|
287
|
+
this.unsubscribe();
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Sends a complete notification to the observer.
|
|
292
|
+
*/
|
|
293
|
+
complete() {
|
|
294
|
+
if (!this.isStopped) {
|
|
295
|
+
this.isStopped = true;
|
|
296
|
+
if (this.destination.complete) {
|
|
297
|
+
try {
|
|
298
|
+
this.destination.complete();
|
|
299
|
+
} catch (error) {
|
|
300
|
+
this.error(error);
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
this.unsubscribe();
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Unsubscribes the subscriber.
|
|
309
|
+
*/
|
|
310
|
+
unsubscribe() {
|
|
311
|
+
if (this.closed) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
this.isStopped = true;
|
|
315
|
+
super.unsubscribe();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
var SafeSubscriber = class extends Subscriber {
|
|
319
|
+
constructor(observerOrNext, error, complete, parentSubscriber) {
|
|
320
|
+
super(observerOrNext, error, complete);
|
|
321
|
+
/** @private */
|
|
322
|
+
this._isUnsubscribing = false;
|
|
323
|
+
/** @private */
|
|
324
|
+
this._parentSubscriber = null;
|
|
325
|
+
this._parentSubscriber = parentSubscriber || null;
|
|
326
|
+
}
|
|
327
|
+
next(value) {
|
|
328
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
329
|
+
try {
|
|
330
|
+
super.next(value);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
this.error(error);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
error(err) {
|
|
337
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
338
|
+
this._isUnsubscribing = true;
|
|
339
|
+
try {
|
|
340
|
+
super.error(err);
|
|
341
|
+
} finally {
|
|
342
|
+
this._isUnsubscribing = false;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
complete() {
|
|
347
|
+
if (!this.isStopped && !this._isUnsubscribing) {
|
|
348
|
+
this._isUnsubscribing = true;
|
|
349
|
+
try {
|
|
350
|
+
super.complete();
|
|
351
|
+
} finally {
|
|
352
|
+
this._isUnsubscribing = false;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
unsubscribe() {
|
|
357
|
+
if (this.closed) {
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
this._isUnsubscribing = true;
|
|
361
|
+
super.unsubscribe();
|
|
362
|
+
this._isUnsubscribing = false;
|
|
363
|
+
}
|
|
364
|
+
};
|
|
365
|
+
var Observable = class extends Subscription {
|
|
366
|
+
/**
|
|
367
|
+
* Creates a new Observable.
|
|
368
|
+
*/
|
|
369
|
+
constructor(subscribe) {
|
|
370
|
+
super();
|
|
371
|
+
if (subscribe) {
|
|
372
|
+
this._subscribe = subscribe;
|
|
373
|
+
} else {
|
|
374
|
+
throw new TypeError("Observable constructor requires a subscribe function");
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
subscribe(observerOrNext, error, complete) {
|
|
378
|
+
let subscriber;
|
|
379
|
+
if (observerOrNext instanceof Subscriber) {
|
|
380
|
+
subscriber = observerOrNext;
|
|
381
|
+
} else {
|
|
382
|
+
subscriber = new SafeSubscriber(observerOrNext, error, complete);
|
|
383
|
+
}
|
|
384
|
+
const { _subscribe } = this;
|
|
385
|
+
try {
|
|
386
|
+
const result = _subscribe.call(this, subscriber);
|
|
387
|
+
if (result) {
|
|
388
|
+
if (typeof result === "function") {
|
|
389
|
+
subscriber.add(result);
|
|
390
|
+
} else if (typeof result.unsubscribe === "function") {
|
|
391
|
+
subscriber.add(result);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
} catch (err) {
|
|
395
|
+
subscriber.error(err);
|
|
396
|
+
}
|
|
397
|
+
return subscriber;
|
|
398
|
+
}
|
|
399
|
+
pipe(...operations) {
|
|
400
|
+
if (operations.length === 0) {
|
|
401
|
+
return this;
|
|
402
|
+
}
|
|
403
|
+
return operations.reduce(
|
|
404
|
+
(prev, fn) => fn(prev),
|
|
405
|
+
this
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Converts the Observable to a Promise.
|
|
410
|
+
* The Promise resolves with the last emitted value when the Observable completes,
|
|
411
|
+
* or rejects if the Observable errors.
|
|
412
|
+
*
|
|
413
|
+
* @example
|
|
414
|
+
* // Convert Observable to Promise
|
|
415
|
+
* const value = await of(1, 2, 3).toPromise();
|
|
416
|
+
* console.log(value); // 3
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* // Handle empty Observable
|
|
420
|
+
* const value = await EMPTY.toPromise();
|
|
421
|
+
* console.log(value); // undefined
|
|
422
|
+
*/
|
|
423
|
+
toPromise() {
|
|
424
|
+
return new Promise((resolve, reject) => {
|
|
425
|
+
let lastValue;
|
|
426
|
+
this.subscribe({
|
|
427
|
+
next: (value) => lastValue = value,
|
|
428
|
+
error: reject,
|
|
429
|
+
complete: () => resolve(lastValue)
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
|
|
435
|
+
// src/lib/signal/graph/detect.ts
|
|
436
|
+
var __BROWSER_PROD__ = typeof window === "undefined" ? false : window.__FLUIXI_PROD__ === true;
|
|
437
|
+
var __DEV__ = typeof process === "undefined" ? __BROWSER_PROD__ : false;
|
|
438
|
+
var $SIGNAL = /* @__PURE__ */ Symbol.for("signal");
|
|
439
|
+
var $MEMO = /* @__PURE__ */ Symbol.for("memo");
|
|
440
|
+
var $RESOURCE = /* @__PURE__ */ Symbol.for("resource");
|
|
441
|
+
function isSignal(value) {
|
|
442
|
+
return typeof value === "function" && value[$SIGNAL] === true;
|
|
443
|
+
}
|
|
444
|
+
function isMemo(value) {
|
|
445
|
+
return typeof value === "function" && value[$MEMO] === true;
|
|
446
|
+
}
|
|
447
|
+
function isResource(value) {
|
|
448
|
+
return typeof value === "function" && value[$RESOURCE] === true;
|
|
449
|
+
}
|
|
450
|
+
function isComponent(value) {
|
|
451
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-component")] === true;
|
|
452
|
+
}
|
|
453
|
+
function isSuspense(value) {
|
|
454
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-suspense")] === true;
|
|
455
|
+
}
|
|
456
|
+
function isProvider(value) {
|
|
457
|
+
return typeof value === "function" && value[/* @__PURE__ */ Symbol.for("fluixi-provider")] === true;
|
|
458
|
+
}
|
|
459
|
+
function makeArrayFlat(values) {
|
|
460
|
+
if (!Array.isArray(values)) return values;
|
|
461
|
+
if (values.length === 2 && values[1] === " ") {
|
|
462
|
+
if (Array.isArray(values[0])) return makeArrayFlat(values[0]);
|
|
463
|
+
if (typeof values[0] === "function") return values[0];
|
|
464
|
+
return values[0];
|
|
465
|
+
}
|
|
466
|
+
if (values.length === 1 && typeof values[0] === "function") return values[0];
|
|
467
|
+
return values;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/version.generated.ts
|
|
471
|
+
var VERSION = "1.0.0-alpha.84";
|
|
472
|
+
|
|
473
|
+
// src/lib/signal/graph/state.ts
|
|
474
|
+
var MAJOR = VERSION.split(".")[0];
|
|
475
|
+
var KEY = `__fluixi_signal_state_v${MAJOR}__`;
|
|
476
|
+
var VERSIONS_KEY = `__fluixi_signal_builds_v${MAJOR}__`;
|
|
477
|
+
var defaultSchedule = (run) => {
|
|
478
|
+
if (typeof queueMicrotask === "function") queueMicrotask(run);
|
|
479
|
+
else void Promise.resolve().then(run);
|
|
480
|
+
};
|
|
481
|
+
function defaults() {
|
|
482
|
+
return {
|
|
483
|
+
consumer: null,
|
|
484
|
+
untracked: false,
|
|
485
|
+
owner: null,
|
|
486
|
+
queue: [],
|
|
487
|
+
scheduled: false,
|
|
488
|
+
flushing: false,
|
|
489
|
+
batchDepth: 0,
|
|
490
|
+
hostSchedule: defaultSchedule,
|
|
491
|
+
onSuspend: null,
|
|
492
|
+
onError: null,
|
|
493
|
+
observer: null
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
var realm = globalThis;
|
|
497
|
+
function backfillState(existing) {
|
|
498
|
+
const fresh = defaults();
|
|
499
|
+
const target = existing;
|
|
500
|
+
for (const field of Object.keys(fresh)) {
|
|
501
|
+
if (!(field in existing)) target[field] = fresh[field];
|
|
502
|
+
}
|
|
503
|
+
return existing;
|
|
504
|
+
}
|
|
505
|
+
function claim() {
|
|
506
|
+
const existing = realm[KEY];
|
|
507
|
+
return existing ? backfillState(existing) : realm[KEY] = defaults();
|
|
508
|
+
}
|
|
509
|
+
var G = claim();
|
|
510
|
+
(realm[VERSIONS_KEY] ??= []).push(VERSION);
|
|
511
|
+
|
|
512
|
+
// src/lib/signal/graph/observe.ts
|
|
513
|
+
function observeReactiveNodes(next) {
|
|
514
|
+
G.observer = next;
|
|
515
|
+
return () => {
|
|
516
|
+
if (G.observer === next) G.observer = null;
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
var running = [];
|
|
520
|
+
var origin;
|
|
521
|
+
function reportReactiveNode(report) {
|
|
522
|
+
const observer = G.observer;
|
|
523
|
+
if (observer) {
|
|
524
|
+
observer.created(
|
|
525
|
+
report.parents === void 0 ? { ...report, parents: running, origin: report.origin ?? origin } : report
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
function enterReactiveRun(node) {
|
|
530
|
+
if (!G.observer) return false;
|
|
531
|
+
running.push(node);
|
|
532
|
+
return true;
|
|
533
|
+
}
|
|
534
|
+
function exitReactiveRun() {
|
|
535
|
+
running.pop();
|
|
536
|
+
}
|
|
537
|
+
function reportReactiveRun(node) {
|
|
538
|
+
G.observer?.ran?.(node);
|
|
539
|
+
}
|
|
540
|
+
function reportReactiveWrite(node, by) {
|
|
541
|
+
G.observer?.wrote?.(node, by);
|
|
542
|
+
}
|
|
543
|
+
function reportReactiveDispose(node) {
|
|
544
|
+
G.observer?.disposed?.(node);
|
|
545
|
+
}
|
|
546
|
+
var HOOK = "__FLUIXI_DEVTOOLS_HOOK__";
|
|
547
|
+
var hook = globalThis[HOOK];
|
|
548
|
+
if (typeof hook?.inject === "function") {
|
|
549
|
+
try {
|
|
550
|
+
hook.inject({ observeReactiveNodes, version: VERSION });
|
|
551
|
+
} catch {
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
function isObserved() {
|
|
555
|
+
return G.observer != null;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// src/lib/signal/graph/core.ts
|
|
559
|
+
var CLEAN = 0;
|
|
560
|
+
var CHECK = 1;
|
|
561
|
+
var DIRTY = 2;
|
|
562
|
+
var Source = class {
|
|
563
|
+
constructor() {
|
|
564
|
+
/** Computeds, and watched leaves, that read this node. */
|
|
565
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
566
|
+
this.observers = null;
|
|
567
|
+
/** Watchers eagerly observing this node, which is how `runtime.ts` schedules effects. */
|
|
568
|
+
this.watchers = null;
|
|
569
|
+
/** Bumped whenever this node's value actually changes (equality-gated). */
|
|
570
|
+
this.version = 0;
|
|
571
|
+
}
|
|
572
|
+
/** Settle this node so a reader sees a current value/version. Overridden by Computed. */
|
|
573
|
+
updateIfNecessary() {
|
|
574
|
+
}
|
|
575
|
+
/** Link the current consumer (if any) as an observer of this node. */
|
|
576
|
+
track() {
|
|
577
|
+
if (G.untracked) return;
|
|
578
|
+
const consumer = G.consumer;
|
|
579
|
+
if (!consumer) return;
|
|
580
|
+
(this.observers ??= /* @__PURE__ */ new Set()).add(consumer);
|
|
581
|
+
(consumer.sources ??= /* @__PURE__ */ new Set()).add(this);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
var State = class extends Source {
|
|
585
|
+
constructor(value, options) {
|
|
586
|
+
super();
|
|
587
|
+
this._value = value;
|
|
588
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
589
|
+
}
|
|
590
|
+
get() {
|
|
591
|
+
this.track();
|
|
592
|
+
return this._value;
|
|
593
|
+
}
|
|
594
|
+
set(next) {
|
|
595
|
+
if (this._equals(this._value, next)) return;
|
|
596
|
+
this._value = next;
|
|
597
|
+
this.version++;
|
|
598
|
+
reportReactiveWrite(this, G.consumer);
|
|
599
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
600
|
+
notifyWatchers(this);
|
|
601
|
+
}
|
|
602
|
+
/** Read without subscribing (peek). */
|
|
603
|
+
peek() {
|
|
604
|
+
return this._value;
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
var Computed = class extends Source {
|
|
608
|
+
constructor(fn, options) {
|
|
609
|
+
super();
|
|
610
|
+
this._threw = false;
|
|
611
|
+
this._initialized = false;
|
|
612
|
+
this.state = DIRTY;
|
|
613
|
+
/** Nodes this computation read on its last run. Rebuilt on every run. */
|
|
614
|
+
this.sources = null;
|
|
615
|
+
this._fn = fn;
|
|
616
|
+
this._equals = options?.equals === false ? () => false : options?.equals ?? Object.is;
|
|
617
|
+
}
|
|
618
|
+
get() {
|
|
619
|
+
if (G.consumer === this) {
|
|
620
|
+
throw new Error("Signal.Computed cannot read itself");
|
|
621
|
+
}
|
|
622
|
+
this.track();
|
|
623
|
+
this.updateIfNecessary();
|
|
624
|
+
if (this._threw) throw this._error;
|
|
625
|
+
return this._value;
|
|
626
|
+
}
|
|
627
|
+
/** Settle, if CHECK, verify sources; if DIRTY (or never run), recompute. */
|
|
628
|
+
updateIfNecessary() {
|
|
629
|
+
if (this.state === CHECK) {
|
|
630
|
+
if (this.sources) {
|
|
631
|
+
for (const s of this.sources) {
|
|
632
|
+
s.updateIfNecessary();
|
|
633
|
+
if (this.state === DIRTY) break;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (this.state === DIRTY || !this._initialized) this.recompute();
|
|
638
|
+
this.state = CLEAN;
|
|
639
|
+
}
|
|
640
|
+
recompute() {
|
|
641
|
+
if (this.sources) {
|
|
642
|
+
for (const s of this.sources) s.observers?.delete(this);
|
|
643
|
+
this.sources.clear();
|
|
644
|
+
}
|
|
645
|
+
const prevConsumer = G.consumer;
|
|
646
|
+
const prevUntracked = G.untracked;
|
|
647
|
+
const watched = enterReactiveRun(this);
|
|
648
|
+
G.consumer = this;
|
|
649
|
+
G.untracked = false;
|
|
650
|
+
let next;
|
|
651
|
+
let threw = false;
|
|
652
|
+
let err;
|
|
653
|
+
try {
|
|
654
|
+
next = this._fn();
|
|
655
|
+
} catch (e) {
|
|
656
|
+
threw = true;
|
|
657
|
+
err = e;
|
|
658
|
+
next = this._value;
|
|
659
|
+
} finally {
|
|
660
|
+
G.consumer = prevConsumer;
|
|
661
|
+
G.untracked = prevUntracked;
|
|
662
|
+
if (watched) exitReactiveRun();
|
|
663
|
+
}
|
|
664
|
+
const changed = !this._initialized || this._threw !== threw || (threw ? err !== this._error : !this._equals(this._value, next));
|
|
665
|
+
this._initialized = true;
|
|
666
|
+
this._threw = threw;
|
|
667
|
+
this._error = err;
|
|
668
|
+
this._value = next;
|
|
669
|
+
reportReactiveRun(this);
|
|
670
|
+
if (changed) {
|
|
671
|
+
this.version++;
|
|
672
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(DIRTY);
|
|
673
|
+
notifyWatchers(this);
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Push a maybe-dirty mark. A direct observer of a changed node gets DIRTY; its
|
|
678
|
+
* own observers get CHECK (recurse), stopping where already marked, so the
|
|
679
|
+
* push is O(newly-dirtied) and never recomputes.
|
|
680
|
+
*/
|
|
681
|
+
markDirty(level) {
|
|
682
|
+
if (this.state >= level) return;
|
|
683
|
+
const wasClean = this.state === CLEAN;
|
|
684
|
+
this.state = level;
|
|
685
|
+
if (wasClean) {
|
|
686
|
+
if (this.observers) for (const o of [...this.observers]) o.markDirty(CHECK);
|
|
687
|
+
notifyWatchers(this);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
peek() {
|
|
691
|
+
this.updateIfNecessary();
|
|
692
|
+
if (this._threw) throw this._error;
|
|
693
|
+
return this._value;
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
function notifyWatchers(node) {
|
|
697
|
+
if (!node.watchers) return;
|
|
698
|
+
for (const w of [...node.watchers]) w._notify(node);
|
|
699
|
+
}
|
|
700
|
+
var Watcher = class {
|
|
701
|
+
constructor(notify) {
|
|
702
|
+
this._watched = /* @__PURE__ */ new Set();
|
|
703
|
+
this._pending = /* @__PURE__ */ new Set();
|
|
704
|
+
this._notifyFn = notify;
|
|
705
|
+
}
|
|
706
|
+
watch(...nodes) {
|
|
707
|
+
for (const n of nodes) {
|
|
708
|
+
this._watched.add(n);
|
|
709
|
+
(n.watchers ??= /* @__PURE__ */ new Set()).add(this);
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
unwatch(...nodes) {
|
|
713
|
+
for (const n of nodes) {
|
|
714
|
+
this._watched.delete(n);
|
|
715
|
+
n.watchers?.delete(this);
|
|
716
|
+
this._pending.delete(n);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
/** Watched nodes that may have changed since the last getPending(). */
|
|
720
|
+
getPending() {
|
|
721
|
+
const out = [...this._pending];
|
|
722
|
+
this._pending.clear();
|
|
723
|
+
return out;
|
|
724
|
+
}
|
|
725
|
+
/** @internal, a watched node became non-clean. Edge-triggered: notify once. */
|
|
726
|
+
_notify(node) {
|
|
727
|
+
if (!this._watched.has(node) || this._pending.has(node)) return;
|
|
728
|
+
const wasEmpty = this._pending.size === 0;
|
|
729
|
+
this._pending.add(node);
|
|
730
|
+
if (wasEmpty) this._notifyFn();
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
// src/lib/signal/graph/runtime.ts
|
|
735
|
+
function makeOwner(parent) {
|
|
736
|
+
return { cleanups: null, owned: null, parent, contexts: null };
|
|
737
|
+
}
|
|
738
|
+
function reportSuspend(promise) {
|
|
739
|
+
if (G.onSuspend) {
|
|
740
|
+
G.onSuspend(promise, G.owner);
|
|
741
|
+
return true;
|
|
742
|
+
}
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
function getOwner() {
|
|
746
|
+
return G.owner;
|
|
747
|
+
}
|
|
748
|
+
function runWithOwner(owner, fn) {
|
|
749
|
+
const prev = G.owner;
|
|
750
|
+
G.owner = owner;
|
|
751
|
+
try {
|
|
752
|
+
return fn();
|
|
753
|
+
} finally {
|
|
754
|
+
G.owner = prev;
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
function onCleanup(fn) {
|
|
758
|
+
if (!G.owner) return;
|
|
759
|
+
if (G.owner.disposed) {
|
|
760
|
+
fn();
|
|
761
|
+
return;
|
|
762
|
+
}
|
|
763
|
+
(G.owner.cleanups ??= []).push(fn);
|
|
764
|
+
}
|
|
765
|
+
function disposeOwner(owner, final = true) {
|
|
766
|
+
if (owner.disposed) return;
|
|
767
|
+
if (owner.owned) {
|
|
768
|
+
for (let i = owner.owned.length - 1; i >= 0; i--) disposeOwner(owner.owned[i]);
|
|
769
|
+
owner.owned = null;
|
|
770
|
+
}
|
|
771
|
+
if (owner.cleanups) {
|
|
772
|
+
for (let i = owner.cleanups.length - 1; i >= 0; i--) owner.cleanups[i]();
|
|
773
|
+
owner.cleanups = null;
|
|
774
|
+
}
|
|
775
|
+
if (final) owner.disposed = true;
|
|
776
|
+
}
|
|
777
|
+
function setScheduler(fn) {
|
|
778
|
+
G.hostSchedule = fn ?? ((run) => void Promise.resolve().then(run));
|
|
779
|
+
}
|
|
780
|
+
function enqueue(e) {
|
|
781
|
+
if (e.queued) return;
|
|
782
|
+
e.queued = true;
|
|
783
|
+
G.queue.push(e);
|
|
784
|
+
if (!G.scheduled && G.batchDepth === 0) {
|
|
785
|
+
G.scheduled = true;
|
|
786
|
+
G.hostSchedule(flushSync);
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
function flushSync() {
|
|
790
|
+
G.scheduled = false;
|
|
791
|
+
if (G.flushing) return;
|
|
792
|
+
G.flushing = true;
|
|
793
|
+
let guard = 0;
|
|
794
|
+
try {
|
|
795
|
+
while (G.queue.length) {
|
|
796
|
+
if (++guard > 1e5) throw new Error("[fluixi] effect flush did not settle (cycle?)");
|
|
797
|
+
const batchOf = G.queue;
|
|
798
|
+
G.queue = [];
|
|
799
|
+
for (const e of batchOf) {
|
|
800
|
+
e.queued = false;
|
|
801
|
+
if (!e.disposed) e.run();
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
} finally {
|
|
805
|
+
G.flushing = false;
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function afterWrite() {
|
|
809
|
+
if (G.batchDepth === 0) flushSync();
|
|
810
|
+
}
|
|
811
|
+
var EffectNode = class {
|
|
812
|
+
constructor(fn, report = false) {
|
|
813
|
+
this.queued = false;
|
|
814
|
+
this.disposed = false;
|
|
815
|
+
this.owner = makeOwner(G.owner);
|
|
816
|
+
if (G.owner) (G.owner.cleanups ??= []).push(() => this.dispose());
|
|
817
|
+
this.computed = new Computed(() => {
|
|
818
|
+
disposeOwner(this.owner, false);
|
|
819
|
+
runWithOwner(this.owner, () => {
|
|
820
|
+
const r = fn();
|
|
821
|
+
if (typeof r === "function") (this.owner.cleanups ??= []).push(r);
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
reportReactiveNode({ kind: "effect", node: this.computed, handle: this, internal: !report });
|
|
825
|
+
this.watcher = new Watcher(() => enqueue(this));
|
|
826
|
+
this.run();
|
|
827
|
+
this.watcher.watch(this.computed);
|
|
828
|
+
}
|
|
829
|
+
run() {
|
|
830
|
+
if (this.disposed) return;
|
|
831
|
+
this.watcher.getPending();
|
|
832
|
+
try {
|
|
833
|
+
this.computed.get();
|
|
834
|
+
} catch (e) {
|
|
835
|
+
if (e && typeof e.then === "function" && G.onSuspend) {
|
|
836
|
+
G.onSuspend(e, this.owner);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
if (G.onError && G.onError(e, this.owner)) return;
|
|
840
|
+
throw e;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
dispose() {
|
|
844
|
+
if (this.disposed) return;
|
|
845
|
+
this.disposed = true;
|
|
846
|
+
reportReactiveDispose(this.computed);
|
|
847
|
+
this.watcher.unwatch(this.computed);
|
|
848
|
+
disposeOwner(this.owner);
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
function effect(fn, report = false) {
|
|
852
|
+
const node = new EffectNode(fn, report);
|
|
853
|
+
return () => node.dispose();
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
// src/lib/signal/graph/compat.ts
|
|
857
|
+
function isThenable(v) {
|
|
858
|
+
return !!v && typeof v.then === "function";
|
|
859
|
+
}
|
|
860
|
+
setScheduler(() => {
|
|
861
|
+
});
|
|
862
|
+
var $SIGNAL2 = /* @__PURE__ */ Symbol.for("signal");
|
|
863
|
+
var $MEMO2 = /* @__PURE__ */ Symbol.for("memo");
|
|
864
|
+
var $NODE = /* @__PURE__ */ Symbol.for("signal-node");
|
|
865
|
+
function createSignal(value, options) {
|
|
866
|
+
const state = new State(value, { equals: options?.equals });
|
|
867
|
+
const read = (() => state.get());
|
|
868
|
+
const write = ((next) => {
|
|
869
|
+
const v = typeof next === "function" ? next(state.peek()) : next;
|
|
870
|
+
state.set(v);
|
|
871
|
+
afterWrite();
|
|
872
|
+
return v;
|
|
873
|
+
});
|
|
874
|
+
Object.defineProperty(read, $SIGNAL2, { value: true, enumerable: true });
|
|
875
|
+
Object.defineProperty(read, $NODE, {
|
|
876
|
+
value: {
|
|
877
|
+
get value() {
|
|
878
|
+
return state.peek();
|
|
879
|
+
},
|
|
880
|
+
get version() {
|
|
881
|
+
return state.version;
|
|
882
|
+
}
|
|
883
|
+
},
|
|
884
|
+
enumerable: false
|
|
885
|
+
});
|
|
886
|
+
reportReactiveNode({
|
|
887
|
+
kind: "signal",
|
|
888
|
+
node: state,
|
|
889
|
+
handle: read,
|
|
890
|
+
name: options?.name,
|
|
891
|
+
set: write
|
|
892
|
+
});
|
|
893
|
+
if (isObserved()) onCleanup(() => reportReactiveDispose(state));
|
|
894
|
+
return [read, write];
|
|
895
|
+
}
|
|
896
|
+
function createMemo(fn, value, options) {
|
|
897
|
+
let prev = value;
|
|
898
|
+
const owner = getOwner();
|
|
899
|
+
const c = new Computed(
|
|
900
|
+
() => runWithOwner(owner, () => {
|
|
901
|
+
try {
|
|
902
|
+
return prev = fn(prev);
|
|
903
|
+
} catch (e) {
|
|
904
|
+
if (isThenable(e)) {
|
|
905
|
+
reportSuspend(e);
|
|
906
|
+
return prev;
|
|
907
|
+
}
|
|
908
|
+
throw e;
|
|
909
|
+
}
|
|
910
|
+
}),
|
|
911
|
+
{ equals: options?.equals }
|
|
912
|
+
);
|
|
913
|
+
const read = (() => c.get());
|
|
914
|
+
Object.defineProperty(read, $SIGNAL2, { value: true, enumerable: true });
|
|
915
|
+
Object.defineProperty(read, $MEMO2, { value: true, enumerable: true });
|
|
916
|
+
reportReactiveNode({ kind: "memo", node: c, handle: read, name: options?.name });
|
|
917
|
+
if (isObserved()) onCleanup(() => reportReactiveDispose(c));
|
|
918
|
+
return read;
|
|
919
|
+
}
|
|
920
|
+
function createEffect(fn, value) {
|
|
921
|
+
let prev = value;
|
|
922
|
+
return effect(() => {
|
|
923
|
+
const r = fn(prev);
|
|
924
|
+
prev = r;
|
|
925
|
+
}, true);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/lib/signal/graph/derived.ts
|
|
929
|
+
function createSelector(source, fn = (k, v) => k === v) {
|
|
930
|
+
const map = /* @__PURE__ */ new Map();
|
|
931
|
+
createEffect(() => {
|
|
932
|
+
const value = source();
|
|
933
|
+
for (const [key, signal] of map) {
|
|
934
|
+
const [get, set] = signal;
|
|
935
|
+
const match = fn(key, value);
|
|
936
|
+
if (get() !== match) set(match);
|
|
937
|
+
}
|
|
938
|
+
});
|
|
939
|
+
return (key) => {
|
|
940
|
+
let signal = map.get(key);
|
|
941
|
+
if (!signal) {
|
|
942
|
+
const [get, set] = createSignal(false);
|
|
943
|
+
signal = [get, set];
|
|
944
|
+
map.set(key, signal);
|
|
945
|
+
const value = source();
|
|
946
|
+
set(fn(key, value));
|
|
947
|
+
}
|
|
948
|
+
return signal[0]();
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
function createDeferred(source, options) {
|
|
952
|
+
const [delayed, setDelayed] = createSignal(source(), options);
|
|
953
|
+
createEffect(() => {
|
|
954
|
+
const v = source();
|
|
955
|
+
if (options?.timeoutMs) setTimeout(() => setDelayed(() => v), options.timeoutMs);
|
|
956
|
+
else if (typeof requestIdleCallback === "function")
|
|
957
|
+
requestIdleCallback(() => setDelayed(() => v));
|
|
958
|
+
else Promise.resolve().then(() => setDelayed(() => v));
|
|
959
|
+
});
|
|
960
|
+
return delayed;
|
|
961
|
+
}
|
|
962
|
+
function createDebounce(fn, delay) {
|
|
963
|
+
let timer;
|
|
964
|
+
const debounced = (...args) => {
|
|
965
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
966
|
+
timer = setTimeout(() => {
|
|
967
|
+
timer = void 0;
|
|
968
|
+
fn(...args);
|
|
969
|
+
}, delay);
|
|
970
|
+
};
|
|
971
|
+
onCleanup(() => {
|
|
972
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
973
|
+
});
|
|
974
|
+
return debounced;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
// src/lib/signal/graph/children.ts
|
|
978
|
+
function resolveChildrenValue(children) {
|
|
979
|
+
if (typeof children === "function" && !children.length) {
|
|
980
|
+
const result = children();
|
|
981
|
+
if (isSignal(result)) return result;
|
|
982
|
+
return resolveChildrenValue(result);
|
|
983
|
+
}
|
|
984
|
+
if (Array.isArray(children)) {
|
|
985
|
+
const results = [];
|
|
986
|
+
for (let i = 0; i < children.length; i++) {
|
|
987
|
+
const result = resolveChildrenValue(children[i]);
|
|
988
|
+
Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
|
|
989
|
+
}
|
|
990
|
+
return results;
|
|
991
|
+
}
|
|
992
|
+
return children;
|
|
993
|
+
}
|
|
994
|
+
function readChildren(fn) {
|
|
995
|
+
const children = createMemo(fn);
|
|
996
|
+
return __DEV__ ? createMemo(() => resolveChildrenValue(children()), void 0, { name: "children" }) : createMemo(() => resolveChildrenValue(children()));
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// src/lib/signal/graph/ssr-hooks.ts
|
|
1000
|
+
var _resourceTracker = null;
|
|
1001
|
+
function setResourceTracker(fn) {
|
|
1002
|
+
_resourceTracker = fn;
|
|
1003
|
+
}
|
|
1004
|
+
function trackResourcePromise(p) {
|
|
1005
|
+
if (_resourceTracker) _resourceTracker(p);
|
|
1006
|
+
}
|
|
1007
|
+
var _serverDataGetter = null;
|
|
1008
|
+
function setServerDataGetter(fn) {
|
|
1009
|
+
_serverDataGetter = fn;
|
|
1010
|
+
}
|
|
1011
|
+
function getServerData(id) {
|
|
1012
|
+
return _serverDataGetter ? _serverDataGetter(id) : void 0;
|
|
1013
|
+
}
|
|
1014
|
+
var _resourceIdSource = null;
|
|
1015
|
+
function setResourceIdSource(fn) {
|
|
1016
|
+
_resourceIdSource = fn;
|
|
1017
|
+
}
|
|
1018
|
+
function nextResourceId() {
|
|
1019
|
+
return _resourceIdSource ? _resourceIdSource() : void 0;
|
|
1020
|
+
}
|
|
1021
|
+
var _resourceDataSink = null;
|
|
1022
|
+
function setResourceDataSink(fn) {
|
|
1023
|
+
_resourceDataSink = fn;
|
|
1024
|
+
}
|
|
1025
|
+
function reportResourceData(id, value) {
|
|
1026
|
+
if (_resourceDataSink) _resourceDataSink(id, value);
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
// src/lib/signal/signal.ts
|
|
1030
|
+
var $SIGNAL3 = /* @__PURE__ */ Symbol.for("signal");
|
|
1031
|
+
var $MEMO3 = /* @__PURE__ */ Symbol.for("memo");
|
|
1032
|
+
var $RESOURCE2 = /* @__PURE__ */ Symbol.for("resource");
|
|
1033
|
+
var $PROXY = /* @__PURE__ */ Symbol("fluixi-proxy");
|
|
1034
|
+
var $NODE2 = /* @__PURE__ */ Symbol.for("signal-node");
|
|
1035
|
+
var CLEAN2 = 0;
|
|
1036
|
+
var STALE = 1;
|
|
1037
|
+
var DIRTY2 = 2;
|
|
1038
|
+
var RUNNING = 3;
|
|
1039
|
+
var Owner = null;
|
|
1040
|
+
var Listener = null;
|
|
1041
|
+
var Updates = null;
|
|
1042
|
+
var Effects = null;
|
|
1043
|
+
var ExecCount = 0;
|
|
1044
|
+
var _eagerStaleEffects = false;
|
|
1045
|
+
var Pending = false;
|
|
1046
|
+
var BatchDepth = 0;
|
|
1047
|
+
var MAX_ITERATIONS = 1e6;
|
|
1048
|
+
var signalObservers = /* @__PURE__ */ new WeakMap();
|
|
1049
|
+
var Transition = null;
|
|
1050
|
+
var Scheduler = null;
|
|
1051
|
+
var nodeRegistry = /* @__PURE__ */ new Map();
|
|
1052
|
+
var nodeIdCounter = 0;
|
|
1053
|
+
var sharedConfig = {
|
|
1054
|
+
context: null,
|
|
1055
|
+
owner: null,
|
|
1056
|
+
routeData: /* @__PURE__ */ new Map(),
|
|
1057
|
+
matchedRoute: /* @__PURE__ */ new Map()
|
|
1058
|
+
};
|
|
1059
|
+
function setOwner2(owner) {
|
|
1060
|
+
Owner = owner;
|
|
1061
|
+
sharedConfig.owner = owner;
|
|
1062
|
+
sharedConfig.context = owner;
|
|
1063
|
+
}
|
|
1064
|
+
function getSharedConfig() {
|
|
1065
|
+
return sharedConfig;
|
|
1066
|
+
}
|
|
1067
|
+
function createNodeId() {
|
|
1068
|
+
return `node_${++nodeIdCounter}_${Date.now()}`;
|
|
1069
|
+
}
|
|
1070
|
+
function registerNode(node) {
|
|
1071
|
+
if (__DEV__) nodeRegistry.set(node.id, new WeakRef(node));
|
|
1072
|
+
}
|
|
1073
|
+
function createReactiveNode(type, initialValue, options) {
|
|
1074
|
+
const node = {
|
|
1075
|
+
id: createNodeId(),
|
|
1076
|
+
type,
|
|
1077
|
+
value: initialValue,
|
|
1078
|
+
version: 0,
|
|
1079
|
+
equals: options?.equals,
|
|
1080
|
+
name: options?.name,
|
|
1081
|
+
created: Date.now(),
|
|
1082
|
+
updated: Date.now()
|
|
1083
|
+
};
|
|
1084
|
+
registerNode(node);
|
|
1085
|
+
return node;
|
|
1086
|
+
}
|
|
1087
|
+
function defaultEquals(a, b) {
|
|
1088
|
+
return a === b;
|
|
1089
|
+
}
|
|
1090
|
+
function handleError(err) {
|
|
1091
|
+
if (typeof console !== "undefined") console.error("Reactive error:", err);
|
|
1092
|
+
throw err;
|
|
1093
|
+
}
|
|
1094
|
+
var _transPending = null;
|
|
1095
|
+
var _setTransPending = null;
|
|
1096
|
+
function ensureTransPending() {
|
|
1097
|
+
if (!_transPending) {
|
|
1098
|
+
const [get, set] = createSignal2(false);
|
|
1099
|
+
_transPending = get;
|
|
1100
|
+
_setTransPending = set;
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
function scheduleComputation(c) {
|
|
1104
|
+
if (Updates) {
|
|
1105
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1106
|
+
} else if (Transition && Transition.running && !c.pure) {
|
|
1107
|
+
if (Transition.effects.indexOf(c) === -1) Transition.effects.push(c);
|
|
1108
|
+
} else if (!c.pure || c.computed) {
|
|
1109
|
+
updateComputation(c);
|
|
1110
|
+
} else if (c.pure && !c.computed && c.accessor) {
|
|
1111
|
+
const prevListener = Listener;
|
|
1112
|
+
const prevUpdatesM = Updates;
|
|
1113
|
+
Listener = null;
|
|
1114
|
+
Updates = [];
|
|
1115
|
+
c.accessor();
|
|
1116
|
+
Listener = prevListener;
|
|
1117
|
+
const memoDeferred = Updates;
|
|
1118
|
+
Updates = prevUpdatesM;
|
|
1119
|
+
if (memoDeferred.length > 0) {
|
|
1120
|
+
const savedU = Updates;
|
|
1121
|
+
runCascadeAndEffects(memoDeferred);
|
|
1122
|
+
Updates = savedU;
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
function propagate(observerList, propagator) {
|
|
1127
|
+
for (let i = 0; i < observerList.length; i++) propagator(observerList[i]);
|
|
1128
|
+
}
|
|
1129
|
+
function createSignal2(_value, options) {
|
|
1130
|
+
let value = _value;
|
|
1131
|
+
if (typeof value === "object" && value && $PROXY in value)
|
|
1132
|
+
delete value[$PROXY];
|
|
1133
|
+
const node = createReactiveNode("signal", value, {
|
|
1134
|
+
equals: options?.equals === false ? void 0 : options?.equals,
|
|
1135
|
+
name: options?.name
|
|
1136
|
+
});
|
|
1137
|
+
const s = [read, write];
|
|
1138
|
+
signalObservers.set(s, /* @__PURE__ */ new Set());
|
|
1139
|
+
let lastObs;
|
|
1140
|
+
function read() {
|
|
1141
|
+
let observer = Listener;
|
|
1142
|
+
if (observer) {
|
|
1143
|
+
if (!observer.sources) observer.sources = [s];
|
|
1144
|
+
else if (observer.sources.indexOf(s) === -1) observer.sources.push(s);
|
|
1145
|
+
const observers = signalObservers.get(s);
|
|
1146
|
+
if (observers && !observers.has(observer)) observers.add(observer);
|
|
1147
|
+
}
|
|
1148
|
+
return value;
|
|
1149
|
+
}
|
|
1150
|
+
function write(nextValue) {
|
|
1151
|
+
const v = typeof nextValue === "function" ? nextValue(value) : nextValue;
|
|
1152
|
+
const equals = node.equals || defaultEquals;
|
|
1153
|
+
if (options?.equals === false || !equals(value, v)) {
|
|
1154
|
+
value = v;
|
|
1155
|
+
node.value = v;
|
|
1156
|
+
node.version++;
|
|
1157
|
+
node.updated = Date.now();
|
|
1158
|
+
const observers = signalObservers.get(s);
|
|
1159
|
+
if (observers && observers.size > 0) {
|
|
1160
|
+
let propagateDirty2 = function(comp, viaPureMemo = false) {
|
|
1161
|
+
const prevState = comp.state;
|
|
1162
|
+
if (prevState === RUNNING && comp === Listener) return;
|
|
1163
|
+
if (viaPureMemo && !comp.pure) {
|
|
1164
|
+
if (prevState === CLEAN2) {
|
|
1165
|
+
comp.state = STALE;
|
|
1166
|
+
if (_eagerStaleEffects) {
|
|
1167
|
+
if (Updates !== null && Updates.indexOf(comp) === -1)
|
|
1168
|
+
Updates.push(comp);
|
|
1169
|
+
else toUpdate.push(comp);
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
if (visited.has(comp)) return;
|
|
1175
|
+
visited.add(comp);
|
|
1176
|
+
comp.state = DIRTY2;
|
|
1177
|
+
if (prevState === CLEAN2 || prevState === STALE) toUpdate.push(comp);
|
|
1178
|
+
else if (!comp.pure && Updates !== null && Updates.indexOf(comp) === -1)
|
|
1179
|
+
Updates.push(comp);
|
|
1180
|
+
if (comp.pure && comp.accessor) {
|
|
1181
|
+
const memoObservers = signalObservers.get(comp.accessor);
|
|
1182
|
+
if (memoObservers)
|
|
1183
|
+
propagate(
|
|
1184
|
+
Array.from(memoObservers),
|
|
1185
|
+
(c) => propagateDirty2(c, true)
|
|
1186
|
+
);
|
|
1187
|
+
}
|
|
1188
|
+
};
|
|
1189
|
+
var propagateDirty = propagateDirty2;
|
|
1190
|
+
const observerList = Array.from(observers);
|
|
1191
|
+
const toUpdate = [];
|
|
1192
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1193
|
+
propagate(observerList, propagateDirty2);
|
|
1194
|
+
for (const comp of toUpdate) scheduleComputation(comp);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
read.toObservable = () => new Observable((observer) => {
|
|
1199
|
+
let first = true;
|
|
1200
|
+
const dispose2 = createEffect2(() => {
|
|
1201
|
+
const val = read();
|
|
1202
|
+
if (first) first = false;
|
|
1203
|
+
else observer.next(val);
|
|
1204
|
+
});
|
|
1205
|
+
return dispose2;
|
|
1206
|
+
});
|
|
1207
|
+
Object.defineProperty(read, $SIGNAL3, { value: true, enumerable: true });
|
|
1208
|
+
Object.defineProperty(read, $NODE2, { value: node, enumerable: false });
|
|
1209
|
+
return s;
|
|
1210
|
+
}
|
|
1211
|
+
function createEffect2(fn, value, options) {
|
|
1212
|
+
const c = {
|
|
1213
|
+
fn,
|
|
1214
|
+
state: DIRTY2,
|
|
1215
|
+
sources: null,
|
|
1216
|
+
sourceSlots: null,
|
|
1217
|
+
owned: null,
|
|
1218
|
+
cleanups: null,
|
|
1219
|
+
owner: Owner,
|
|
1220
|
+
contexts: null,
|
|
1221
|
+
pure: false,
|
|
1222
|
+
updatedAt: null
|
|
1223
|
+
};
|
|
1224
|
+
if (Owner) {
|
|
1225
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1226
|
+
else Owner.owned.push(c);
|
|
1227
|
+
}
|
|
1228
|
+
const SC = _SuspenseContext && useContext(_SuspenseContext);
|
|
1229
|
+
if (SC) c.suspense = SC;
|
|
1230
|
+
runComputation(c, value);
|
|
1231
|
+
return () => dispose(c);
|
|
1232
|
+
}
|
|
1233
|
+
function runComputation(c, value) {
|
|
1234
|
+
if (c.sources) {
|
|
1235
|
+
for (const source of c.sources) {
|
|
1236
|
+
const observers = signalObservers.get(source);
|
|
1237
|
+
if (observers) observers.delete(c);
|
|
1238
|
+
}
|
|
1239
|
+
c.sources = null;
|
|
1240
|
+
c.sourceSlots = null;
|
|
1241
|
+
}
|
|
1242
|
+
if (c.owned) {
|
|
1243
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1244
|
+
c.owned = null;
|
|
1245
|
+
}
|
|
1246
|
+
const prevListener = Listener;
|
|
1247
|
+
const prevOwner = Owner;
|
|
1248
|
+
Listener = c;
|
|
1249
|
+
Owner = c;
|
|
1250
|
+
ExecCount++;
|
|
1251
|
+
if (ExecCount > MAX_ITERATIONS) {
|
|
1252
|
+
ExecCount = 0;
|
|
1253
|
+
Listener = prevListener;
|
|
1254
|
+
Owner = prevOwner;
|
|
1255
|
+
throw new Error(
|
|
1256
|
+
"Potential infinite loop detected. Exceeded maximum iterations."
|
|
1257
|
+
);
|
|
1258
|
+
}
|
|
1259
|
+
try {
|
|
1260
|
+
c.state = RUNNING;
|
|
1261
|
+
const result = c.fn(value);
|
|
1262
|
+
if (typeof result === "function") {
|
|
1263
|
+
if (!c.cleanups) c.cleanups = [result];
|
|
1264
|
+
else c.cleanups.push(result);
|
|
1265
|
+
}
|
|
1266
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1267
|
+
} catch (err) {
|
|
1268
|
+
if (isPromise(err)) {
|
|
1269
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1270
|
+
if (ctx) {
|
|
1271
|
+
ctx.increment();
|
|
1272
|
+
err.finally(() => ctx.decrement());
|
|
1273
|
+
if (c.suspense) ctx.effects.push(c);
|
|
1274
|
+
}
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
handleError(err);
|
|
1278
|
+
} finally {
|
|
1279
|
+
Listener = prevListener;
|
|
1280
|
+
Owner = prevOwner;
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
function updateComputation(c) {
|
|
1284
|
+
if (c.disposed || !c.fn || c.state === CLEAN2) return;
|
|
1285
|
+
if (c.state === DIRTY2 || c.state === STALE || c.state === RUNNING) {
|
|
1286
|
+
if (c.cleanups) {
|
|
1287
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1288
|
+
c.cleanups = null;
|
|
1289
|
+
}
|
|
1290
|
+
if (c.owned) {
|
|
1291
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1292
|
+
c.owned = null;
|
|
1293
|
+
}
|
|
1294
|
+
if (c.renderEffect) runRenderComputation(c);
|
|
1295
|
+
else runComputation(c, c.value);
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
function dispose(c) {
|
|
1299
|
+
c.disposed = true;
|
|
1300
|
+
if (c.sources) {
|
|
1301
|
+
for (const source of c.sources) {
|
|
1302
|
+
const observers = signalObservers.get(source);
|
|
1303
|
+
if (observers) observers.delete(c);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
if (c.cleanups) for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1307
|
+
if (c.owned) for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1308
|
+
if (c.owner && c.owner.owned) {
|
|
1309
|
+
const index = c.owner.owned.indexOf(c);
|
|
1310
|
+
if (index !== -1) c.owner.owned.splice(index, 1);
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
function createMemo2(fn, value, options) {
|
|
1314
|
+
const node = createReactiveNode("memo", value, {
|
|
1315
|
+
equals: options?.equals === false ? void 0 : options?.equals,
|
|
1316
|
+
name: options?.name
|
|
1317
|
+
});
|
|
1318
|
+
const c = {
|
|
1319
|
+
fn,
|
|
1320
|
+
state: DIRTY2,
|
|
1321
|
+
sources: null,
|
|
1322
|
+
sourceSlots: null,
|
|
1323
|
+
value,
|
|
1324
|
+
owned: null,
|
|
1325
|
+
cleanups: null,
|
|
1326
|
+
owner: Owner,
|
|
1327
|
+
contexts: null,
|
|
1328
|
+
pure: true,
|
|
1329
|
+
updatedAt: null,
|
|
1330
|
+
node,
|
|
1331
|
+
accessor: void 0
|
|
1332
|
+
};
|
|
1333
|
+
if (Owner) {
|
|
1334
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1335
|
+
else Owner.owned.push(c);
|
|
1336
|
+
}
|
|
1337
|
+
const read = () => {
|
|
1338
|
+
if (Listener && Listener !== c) {
|
|
1339
|
+
if (!Listener.sources) Listener.sources = [read];
|
|
1340
|
+
else if (Listener.sources.indexOf(read) === -1)
|
|
1341
|
+
Listener.sources.push(read);
|
|
1342
|
+
const memoAsSignal = read;
|
|
1343
|
+
if (!signalObservers.has(memoAsSignal))
|
|
1344
|
+
signalObservers.set(memoAsSignal, /* @__PURE__ */ new Set());
|
|
1345
|
+
const observers = signalObservers.get(memoAsSignal);
|
|
1346
|
+
if (observers) observers.add(Listener);
|
|
1347
|
+
}
|
|
1348
|
+
if (c.state !== CLEAN2) {
|
|
1349
|
+
if (c.sources) {
|
|
1350
|
+
for (const source of c.sources) {
|
|
1351
|
+
const observers = signalObservers.get(source);
|
|
1352
|
+
if (observers) observers.delete(c);
|
|
1353
|
+
}
|
|
1354
|
+
c.sources = null;
|
|
1355
|
+
c.sourceSlots = null;
|
|
1356
|
+
}
|
|
1357
|
+
if (c.cleanups) {
|
|
1358
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1359
|
+
c.cleanups = null;
|
|
1360
|
+
}
|
|
1361
|
+
if (c.owned) {
|
|
1362
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1363
|
+
c.owned = null;
|
|
1364
|
+
}
|
|
1365
|
+
const prevListener = Listener;
|
|
1366
|
+
const prevOwner = Owner;
|
|
1367
|
+
Listener = c;
|
|
1368
|
+
Owner = c;
|
|
1369
|
+
c.state = RUNNING;
|
|
1370
|
+
try {
|
|
1371
|
+
const nextValue = c.fn(c.value);
|
|
1372
|
+
const equals = node.equals || defaultEquals;
|
|
1373
|
+
const hasChanged = options?.equals === false || !equals(c.value, nextValue);
|
|
1374
|
+
if (hasChanged) {
|
|
1375
|
+
c.value = nextValue;
|
|
1376
|
+
node.value = nextValue;
|
|
1377
|
+
node.version++;
|
|
1378
|
+
node.updated = Date.now();
|
|
1379
|
+
const memoAsSignal = read;
|
|
1380
|
+
const observers = signalObservers.get(memoAsSignal);
|
|
1381
|
+
if (observers && observers.size > 0) {
|
|
1382
|
+
let propagateDirty2 = function(comp, viaPureMemo = false) {
|
|
1383
|
+
if (comp === c) return;
|
|
1384
|
+
const prevState = comp.state;
|
|
1385
|
+
if (prevState === RUNNING) return;
|
|
1386
|
+
if (viaPureMemo && !comp.pure) {
|
|
1387
|
+
if (prevState === CLEAN2) {
|
|
1388
|
+
comp.state = STALE;
|
|
1389
|
+
if (Updates !== null && Updates.indexOf(comp) === -1)
|
|
1390
|
+
Updates.push(comp);
|
|
1391
|
+
else toUpdate.push(comp);
|
|
1392
|
+
}
|
|
1393
|
+
return;
|
|
1394
|
+
}
|
|
1395
|
+
if (visited.has(comp)) return;
|
|
1396
|
+
visited.add(comp);
|
|
1397
|
+
comp.state = DIRTY2;
|
|
1398
|
+
if (prevState === CLEAN2 || prevState === STALE)
|
|
1399
|
+
toUpdate.push(comp);
|
|
1400
|
+
else if (!comp.pure && Updates !== null && Updates.indexOf(comp) === -1)
|
|
1401
|
+
Updates.push(comp);
|
|
1402
|
+
if (comp.pure && comp.accessor) {
|
|
1403
|
+
const memoObservers = signalObservers.get(comp.accessor);
|
|
1404
|
+
if (memoObservers && memoObservers.size > 0)
|
|
1405
|
+
for (const o of Array.from(memoObservers))
|
|
1406
|
+
propagateDirty2(o, true);
|
|
1407
|
+
}
|
|
1408
|
+
};
|
|
1409
|
+
var propagateDirty = propagateDirty2;
|
|
1410
|
+
const observerList = Array.from(observers);
|
|
1411
|
+
const toUpdate = [];
|
|
1412
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1413
|
+
for (let i = 0; i < observerList.length; i++)
|
|
1414
|
+
propagateDirty2(observerList[i]);
|
|
1415
|
+
for (const comp of toUpdate) scheduleComputation(comp);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1419
|
+
} catch (err) {
|
|
1420
|
+
if (isPromise(err)) {
|
|
1421
|
+
let ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1422
|
+
if (!ctx && _SuspenseContext) {
|
|
1423
|
+
let owner = prevOwner;
|
|
1424
|
+
while (owner) {
|
|
1425
|
+
if (owner.contexts?.has(_SuspenseContext.id)) {
|
|
1426
|
+
ctx = owner.contexts.get(_SuspenseContext.id);
|
|
1427
|
+
break;
|
|
1428
|
+
}
|
|
1429
|
+
owner = owner.owner;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
if (ctx) {
|
|
1433
|
+
ctx.increment();
|
|
1434
|
+
err.finally(() => ctx.decrement());
|
|
1435
|
+
}
|
|
1436
|
+
return c.value;
|
|
1437
|
+
}
|
|
1438
|
+
handleError(err);
|
|
1439
|
+
} finally {
|
|
1440
|
+
Listener = prevListener;
|
|
1441
|
+
Owner = prevOwner;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
return c.value;
|
|
1445
|
+
};
|
|
1446
|
+
c.accessor = read;
|
|
1447
|
+
signalObservers.set(read, /* @__PURE__ */ new Set());
|
|
1448
|
+
read.toObservable = () => new Observable((observer) => {
|
|
1449
|
+
let first = true;
|
|
1450
|
+
const dispose2 = createEffect2(() => {
|
|
1451
|
+
const val = read();
|
|
1452
|
+
if (first) first = false;
|
|
1453
|
+
else observer.next(val);
|
|
1454
|
+
});
|
|
1455
|
+
return dispose2;
|
|
1456
|
+
});
|
|
1457
|
+
Object.defineProperty(read, $SIGNAL3, { value: true, enumerable: true });
|
|
1458
|
+
Object.defineProperty(read, $MEMO3, { value: true, enumerable: true });
|
|
1459
|
+
Object.defineProperty(read, $NODE2, { value: node, enumerable: false });
|
|
1460
|
+
return read;
|
|
1461
|
+
}
|
|
1462
|
+
function runCascadeAndEffects(initial) {
|
|
1463
|
+
const cascadeQueue = [];
|
|
1464
|
+
const effectsToRun = [];
|
|
1465
|
+
for (const comp of initial) {
|
|
1466
|
+
if (comp.pure && !comp.computed && comp.accessor) {
|
|
1467
|
+
if (cascadeQueue.indexOf(comp) === -1) cascadeQueue.push(comp);
|
|
1468
|
+
} else if ((comp.computed || !comp.pure) && effectsToRun.indexOf(comp) === -1)
|
|
1469
|
+
effectsToRun.push(comp);
|
|
1470
|
+
}
|
|
1471
|
+
Updates = [];
|
|
1472
|
+
let ci = 0;
|
|
1473
|
+
while (ci < cascadeQueue.length) {
|
|
1474
|
+
const comp = cascadeQueue[ci++];
|
|
1475
|
+
const observers = signalObservers.get(comp.accessor);
|
|
1476
|
+
if (observers && observers.size > 0) {
|
|
1477
|
+
const prevListener = Listener;
|
|
1478
|
+
Listener = null;
|
|
1479
|
+
comp.accessor();
|
|
1480
|
+
Listener = prevListener;
|
|
1481
|
+
}
|
|
1482
|
+
const fresh = Updates.splice(0);
|
|
1483
|
+
for (const c of fresh) {
|
|
1484
|
+
if (c.pure && !c.computed && c.accessor) {
|
|
1485
|
+
if (cascadeQueue.indexOf(c) === -1) cascadeQueue.push(c);
|
|
1486
|
+
} else if ((c.computed || !c.pure) && effectsToRun.indexOf(c) === -1)
|
|
1487
|
+
effectsToRun.push(c);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
Updates = null;
|
|
1491
|
+
for (const comp of effectsToRun)
|
|
1492
|
+
if (comp.computed || !comp.pure) updateComputation(comp);
|
|
1493
|
+
}
|
|
1494
|
+
function batch2(fn) {
|
|
1495
|
+
if (Updates && BatchDepth > 0) return fn();
|
|
1496
|
+
if (Updates && BatchDepth === 0) {
|
|
1497
|
+
const prev = Updates;
|
|
1498
|
+
const nested = [];
|
|
1499
|
+
Updates = nested;
|
|
1500
|
+
BatchDepth++;
|
|
1501
|
+
let result;
|
|
1502
|
+
try {
|
|
1503
|
+
result = fn();
|
|
1504
|
+
} finally {
|
|
1505
|
+
BatchDepth--;
|
|
1506
|
+
Updates = prev;
|
|
1507
|
+
}
|
|
1508
|
+
const savedUpdates = Updates;
|
|
1509
|
+
runCascadeAndEffects(nested);
|
|
1510
|
+
Updates = savedUpdates;
|
|
1511
|
+
return result;
|
|
1512
|
+
}
|
|
1513
|
+
BatchDepth++;
|
|
1514
|
+
Updates = [];
|
|
1515
|
+
Effects = [];
|
|
1516
|
+
try {
|
|
1517
|
+
return fn();
|
|
1518
|
+
} finally {
|
|
1519
|
+
BatchDepth--;
|
|
1520
|
+
flushUpdates();
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
function flushUpdates() {
|
|
1524
|
+
if (Pending) return;
|
|
1525
|
+
Pending = true;
|
|
1526
|
+
ExecCount = 0;
|
|
1527
|
+
try {
|
|
1528
|
+
while (Updates && Updates.length > 0) {
|
|
1529
|
+
const updates = Updates;
|
|
1530
|
+
Updates = null;
|
|
1531
|
+
runCascadeAndEffects(updates);
|
|
1532
|
+
}
|
|
1533
|
+
Updates = null;
|
|
1534
|
+
if (Effects) {
|
|
1535
|
+
const effects = Effects;
|
|
1536
|
+
Effects = null;
|
|
1537
|
+
for (let i = 0; i < effects.length; i++) updateComputation(effects[i]);
|
|
1538
|
+
}
|
|
1539
|
+
} finally {
|
|
1540
|
+
Pending = false;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
function createRoot2(fn) {
|
|
1544
|
+
const owner = {
|
|
1545
|
+
owned: null,
|
|
1546
|
+
cleanups: null,
|
|
1547
|
+
contexts: null,
|
|
1548
|
+
owner: Owner
|
|
1549
|
+
};
|
|
1550
|
+
const prevListener = Listener;
|
|
1551
|
+
Listener = null;
|
|
1552
|
+
const prevOwner = Owner;
|
|
1553
|
+
Owner = owner;
|
|
1554
|
+
try {
|
|
1555
|
+
return fn(() => {
|
|
1556
|
+
if (owner.owned)
|
|
1557
|
+
for (let i = 0; i < owner.owned.length; i++) dispose(owner.owned[i]);
|
|
1558
|
+
if (owner.cleanups)
|
|
1559
|
+
for (let i = 0; i < owner.cleanups.length; i++) owner.cleanups[i]();
|
|
1560
|
+
});
|
|
1561
|
+
} finally {
|
|
1562
|
+
Owner = prevOwner;
|
|
1563
|
+
Listener = prevListener;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
function untrack2(fn) {
|
|
1567
|
+
const prevListener = Listener;
|
|
1568
|
+
Listener = null;
|
|
1569
|
+
try {
|
|
1570
|
+
return fn();
|
|
1571
|
+
} finally {
|
|
1572
|
+
Listener = prevListener;
|
|
1573
|
+
}
|
|
1574
|
+
}
|
|
1575
|
+
function onCleanup2(fn) {
|
|
1576
|
+
if (Owner) {
|
|
1577
|
+
if (!Owner.cleanups) Owner.cleanups = [fn];
|
|
1578
|
+
else Owner.cleanups.push(fn);
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
function createResource(source, fetcherFn, options = {}) {
|
|
1582
|
+
let s;
|
|
1583
|
+
let fetcher;
|
|
1584
|
+
if (typeof fetcherFn === "function") {
|
|
1585
|
+
s = typeof source === "function" ? source : () => source;
|
|
1586
|
+
fetcher = fetcherFn;
|
|
1587
|
+
} else {
|
|
1588
|
+
s = () => true;
|
|
1589
|
+
fetcher = source;
|
|
1590
|
+
if (fetcherFn && typeof fetcherFn === "object") options = fetcherFn;
|
|
1591
|
+
}
|
|
1592
|
+
const { initialValue, name } = options;
|
|
1593
|
+
const __ssrId = options.transport === false ? void 0 : nextResourceId();
|
|
1594
|
+
const __seed = __ssrId !== void 0 ? getServerData(__ssrId) : void 0;
|
|
1595
|
+
let skipFirstFetch = __seed !== void 0;
|
|
1596
|
+
const [value, setValue] = createSignal2(
|
|
1597
|
+
__seed !== void 0 ? __seed.value : options.initialValue,
|
|
1598
|
+
{ equals: false }
|
|
1599
|
+
);
|
|
1600
|
+
const [error, setError] = createSignal2(void 0, { equals: false });
|
|
1601
|
+
const [state, setState] = createSignal2(
|
|
1602
|
+
__seed !== void 0 || options.initialValue !== void 0 ? "ready" : "unresolved",
|
|
1603
|
+
{ equals: false }
|
|
1604
|
+
);
|
|
1605
|
+
const [promise, setPromise] = createSignal2(
|
|
1606
|
+
void 0,
|
|
1607
|
+
{ equals: false }
|
|
1608
|
+
);
|
|
1609
|
+
const [track, trigger] = createSignal2(void 0, { equals: false });
|
|
1610
|
+
const UNSET = /* @__PURE__ */ Symbol();
|
|
1611
|
+
let prevKey = UNSET;
|
|
1612
|
+
let manualRefetch = false;
|
|
1613
|
+
const saveToCache = (data) => {
|
|
1614
|
+
if (typeof localStorage === "undefined") return;
|
|
1615
|
+
try {
|
|
1616
|
+
if (data)
|
|
1617
|
+
localStorage.setItem(
|
|
1618
|
+
"storage",
|
|
1619
|
+
JSON.stringify({ data, timestamp: Date.now() })
|
|
1620
|
+
);
|
|
1621
|
+
} catch (error2) {
|
|
1622
|
+
console.error(`Failed to save resource to cache (${name}):`, error2);
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
const dispose2 = createEffect2(() => {
|
|
1626
|
+
const val = s ? s() : source;
|
|
1627
|
+
track();
|
|
1628
|
+
if (val === false || val === null || val === void 0) {
|
|
1629
|
+
prevKey = UNSET;
|
|
1630
|
+
batch2(() => {
|
|
1631
|
+
setState("unresolved");
|
|
1632
|
+
setPromise(void 0);
|
|
1633
|
+
setError(void 0);
|
|
1634
|
+
});
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const isManual = manualRefetch;
|
|
1638
|
+
manualRefetch = false;
|
|
1639
|
+
if (prevKey !== UNSET && val === prevKey && !isManual) return;
|
|
1640
|
+
prevKey = val;
|
|
1641
|
+
if (skipFirstFetch) {
|
|
1642
|
+
skipFirstFetch = false;
|
|
1643
|
+
return;
|
|
1644
|
+
}
|
|
1645
|
+
let cancelled = false;
|
|
1646
|
+
onCleanup2(() => cancelled = true);
|
|
1647
|
+
const currentState = untrack2(state);
|
|
1648
|
+
const currentValue = untrack2(value);
|
|
1649
|
+
const isRefreshing = currentState === "ready" || currentState === "refreshing";
|
|
1650
|
+
batch2(() => {
|
|
1651
|
+
setState(isRefreshing ? "refreshing" : "pending");
|
|
1652
|
+
setError(void 0);
|
|
1653
|
+
});
|
|
1654
|
+
try {
|
|
1655
|
+
const res = fetcher(val, {
|
|
1656
|
+
value: currentValue,
|
|
1657
|
+
refetching: isRefreshing
|
|
1658
|
+
});
|
|
1659
|
+
if (isPromise(res)) {
|
|
1660
|
+
setPromise(res);
|
|
1661
|
+
trackResourcePromise(res);
|
|
1662
|
+
res.then(
|
|
1663
|
+
(v) => {
|
|
1664
|
+
if (cancelled) return;
|
|
1665
|
+
if (__ssrId !== void 0) reportResourceData(__ssrId, v);
|
|
1666
|
+
batch2(() => {
|
|
1667
|
+
setValue(() => v);
|
|
1668
|
+
saveToCache(v);
|
|
1669
|
+
setState("ready");
|
|
1670
|
+
setPromise(void 0);
|
|
1671
|
+
});
|
|
1672
|
+
},
|
|
1673
|
+
(e) => {
|
|
1674
|
+
if (cancelled) return;
|
|
1675
|
+
batch2(() => {
|
|
1676
|
+
setError(e);
|
|
1677
|
+
setState("errored");
|
|
1678
|
+
setPromise(void 0);
|
|
1679
|
+
});
|
|
1680
|
+
}
|
|
1681
|
+
).catch((e) => {
|
|
1682
|
+
if (cancelled) return;
|
|
1683
|
+
batch2(() => {
|
|
1684
|
+
setError(e);
|
|
1685
|
+
setState("errored");
|
|
1686
|
+
setPromise(void 0);
|
|
1687
|
+
});
|
|
1688
|
+
});
|
|
1689
|
+
const suspenseCtx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1690
|
+
if (suspenseCtx) {
|
|
1691
|
+
suspenseCtx.increment();
|
|
1692
|
+
res.finally(() => suspenseCtx.decrement());
|
|
1693
|
+
}
|
|
1694
|
+
} else {
|
|
1695
|
+
if (cancelled) return;
|
|
1696
|
+
batch2(() => {
|
|
1697
|
+
setValue(() => res);
|
|
1698
|
+
setState("ready");
|
|
1699
|
+
setPromise(void 0);
|
|
1700
|
+
});
|
|
1701
|
+
}
|
|
1702
|
+
} catch (e) {
|
|
1703
|
+
if (cancelled) return;
|
|
1704
|
+
batch2(() => {
|
|
1705
|
+
setError(e);
|
|
1706
|
+
setState("errored");
|
|
1707
|
+
setPromise(void 0);
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
onCleanup2(dispose2);
|
|
1712
|
+
const loading = () => {
|
|
1713
|
+
const s2 = state();
|
|
1714
|
+
return s2 === "pending" || s2 === "refreshing";
|
|
1715
|
+
};
|
|
1716
|
+
const resource = (() => {
|
|
1717
|
+
const e = error();
|
|
1718
|
+
if (e) throw e;
|
|
1719
|
+
if (loading()) {
|
|
1720
|
+
const p = promise();
|
|
1721
|
+
if (p) throw p;
|
|
1722
|
+
}
|
|
1723
|
+
return value();
|
|
1724
|
+
});
|
|
1725
|
+
Object.defineProperty(resource, $RESOURCE2, { value: true, enumerable: true });
|
|
1726
|
+
Object.defineProperty(resource, $SIGNAL3, { value: true, enumerable: true });
|
|
1727
|
+
Object.defineProperties(resource, {
|
|
1728
|
+
state: { get: state },
|
|
1729
|
+
loading: { get: () => loading() },
|
|
1730
|
+
error: { get: error },
|
|
1731
|
+
latest: { get: value }
|
|
1732
|
+
});
|
|
1733
|
+
return [
|
|
1734
|
+
resource,
|
|
1735
|
+
{
|
|
1736
|
+
mutate: setValue,
|
|
1737
|
+
refetch: () => {
|
|
1738
|
+
manualRefetch = true;
|
|
1739
|
+
trigger(void 0);
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
];
|
|
1743
|
+
}
|
|
1744
|
+
function getOwner2() {
|
|
1745
|
+
return Owner;
|
|
1746
|
+
}
|
|
1747
|
+
function runWithOwner2(owner, fn) {
|
|
1748
|
+
const prevOwner = Owner;
|
|
1749
|
+
const prevListener = Listener;
|
|
1750
|
+
Owner = owner;
|
|
1751
|
+
Listener = null;
|
|
1752
|
+
try {
|
|
1753
|
+
return fn();
|
|
1754
|
+
} finally {
|
|
1755
|
+
Owner = prevOwner;
|
|
1756
|
+
Listener = prevListener;
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
function createContext(defaultValue) {
|
|
1760
|
+
const id = /* @__PURE__ */ Symbol("context");
|
|
1761
|
+
const Provider = createProvider(id);
|
|
1762
|
+
return { id, Provider, defaultValue };
|
|
1763
|
+
}
|
|
1764
|
+
function createProvider(id) {
|
|
1765
|
+
return (props) => {
|
|
1766
|
+
let _node = Owner;
|
|
1767
|
+
while (_node) {
|
|
1768
|
+
if (!_node.contexts) _node.contexts = /* @__PURE__ */ new Map();
|
|
1769
|
+
if (!_node.contexts.has(id)) _node.contexts.set(id, props.value);
|
|
1770
|
+
_node = _node.owner;
|
|
1771
|
+
}
|
|
1772
|
+
let provider;
|
|
1773
|
+
createRenderEffect(() => {
|
|
1774
|
+
provider = untrack2(() => {
|
|
1775
|
+
const owner = Owner;
|
|
1776
|
+
if (owner) {
|
|
1777
|
+
if (!owner.contexts) owner.contexts = /* @__PURE__ */ new Map();
|
|
1778
|
+
owner.contexts.set(id, props.value);
|
|
1779
|
+
}
|
|
1780
|
+
return readChildren(() => props.children);
|
|
1781
|
+
});
|
|
1782
|
+
});
|
|
1783
|
+
return provider;
|
|
1784
|
+
};
|
|
1785
|
+
}
|
|
1786
|
+
function useContext(context) {
|
|
1787
|
+
let owner = Owner;
|
|
1788
|
+
while (owner) {
|
|
1789
|
+
if (owner.contexts && owner.contexts.has(context.id))
|
|
1790
|
+
return owner.contexts.get(context.id);
|
|
1791
|
+
owner = owner.owner;
|
|
1792
|
+
}
|
|
1793
|
+
if (!context) return;
|
|
1794
|
+
return context.defaultValue;
|
|
1795
|
+
}
|
|
1796
|
+
function flush() {
|
|
1797
|
+
return new Promise((resolve) => {
|
|
1798
|
+
queueMicrotask(() => {
|
|
1799
|
+
flushUpdates();
|
|
1800
|
+
resolve();
|
|
1801
|
+
});
|
|
1802
|
+
});
|
|
1803
|
+
}
|
|
1804
|
+
function startTransition(fn) {
|
|
1805
|
+
if (Transition && Transition.running) {
|
|
1806
|
+
fn();
|
|
1807
|
+
return Transition.done;
|
|
1808
|
+
}
|
|
1809
|
+
ensureTransPending();
|
|
1810
|
+
let resolve;
|
|
1811
|
+
const done = new Promise((res) => resolve = res);
|
|
1812
|
+
const t = { running: true, effects: [], resolve, done };
|
|
1813
|
+
Transition = t;
|
|
1814
|
+
try {
|
|
1815
|
+
fn();
|
|
1816
|
+
} finally {
|
|
1817
|
+
t.running = false;
|
|
1818
|
+
}
|
|
1819
|
+
if (!t.effects.length) {
|
|
1820
|
+
Transition = null;
|
|
1821
|
+
resolve();
|
|
1822
|
+
return done;
|
|
1823
|
+
}
|
|
1824
|
+
_setTransPending(true);
|
|
1825
|
+
Promise.resolve().then(() => {
|
|
1826
|
+
const effects = t.effects.splice(0);
|
|
1827
|
+
Transition = null;
|
|
1828
|
+
_setTransPending(false);
|
|
1829
|
+
if (effects.length)
|
|
1830
|
+
batch2(() => {
|
|
1831
|
+
for (const e of effects) {
|
|
1832
|
+
e.state = DIRTY2;
|
|
1833
|
+
updateComputation(e);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
resolve();
|
|
1837
|
+
});
|
|
1838
|
+
return done;
|
|
1839
|
+
}
|
|
1840
|
+
function useTransition() {
|
|
1841
|
+
ensureTransPending();
|
|
1842
|
+
return [_transPending, startTransition];
|
|
1843
|
+
}
|
|
1844
|
+
function on(deps, fn, options) {
|
|
1845
|
+
const defer = options?.defer ?? false;
|
|
1846
|
+
let isFirst = true;
|
|
1847
|
+
return (prev) => {
|
|
1848
|
+
const values = deps();
|
|
1849
|
+
if (defer && isFirst) {
|
|
1850
|
+
isFirst = false;
|
|
1851
|
+
return prev;
|
|
1852
|
+
}
|
|
1853
|
+
return untrack2(() => fn(values, prev));
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
function createRenderEffect(fn, value, options) {
|
|
1857
|
+
const c = {
|
|
1858
|
+
fn,
|
|
1859
|
+
state: DIRTY2,
|
|
1860
|
+
sources: null,
|
|
1861
|
+
sourceSlots: null,
|
|
1862
|
+
value,
|
|
1863
|
+
owned: null,
|
|
1864
|
+
cleanups: null,
|
|
1865
|
+
owner: Owner,
|
|
1866
|
+
contexts: null,
|
|
1867
|
+
pure: false,
|
|
1868
|
+
updatedAt: null,
|
|
1869
|
+
renderEffect: true
|
|
1870
|
+
};
|
|
1871
|
+
if (Owner) {
|
|
1872
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1873
|
+
else Owner.owned.push(c);
|
|
1874
|
+
}
|
|
1875
|
+
const SC = _SuspenseContext && useContext(_SuspenseContext);
|
|
1876
|
+
if (SC) c.suspense = SC;
|
|
1877
|
+
runRenderComputation(c);
|
|
1878
|
+
return () => dispose(c);
|
|
1879
|
+
}
|
|
1880
|
+
function runRenderComputation(c) {
|
|
1881
|
+
if (c.sources) {
|
|
1882
|
+
for (const source of c.sources) {
|
|
1883
|
+
const observers = signalObservers.get(source);
|
|
1884
|
+
if (observers) observers.delete(c);
|
|
1885
|
+
}
|
|
1886
|
+
c.sources = null;
|
|
1887
|
+
c.sourceSlots = null;
|
|
1888
|
+
}
|
|
1889
|
+
if (c.cleanups) {
|
|
1890
|
+
for (let i = 0; i < c.cleanups.length; i++) c.cleanups[i]();
|
|
1891
|
+
c.cleanups = null;
|
|
1892
|
+
}
|
|
1893
|
+
if (c.owned) {
|
|
1894
|
+
for (let i = 0; i < c.owned.length; i++) dispose(c.owned[i]);
|
|
1895
|
+
c.owned = null;
|
|
1896
|
+
}
|
|
1897
|
+
const prevListener = Listener;
|
|
1898
|
+
const prevOwner = Owner;
|
|
1899
|
+
const prevUpdates = Updates;
|
|
1900
|
+
Listener = c;
|
|
1901
|
+
Owner = c;
|
|
1902
|
+
if (Updates === null) Updates = [];
|
|
1903
|
+
c.state = RUNNING;
|
|
1904
|
+
try {
|
|
1905
|
+
const result = c.fn(c.value);
|
|
1906
|
+
if (typeof result === "function") {
|
|
1907
|
+
if (!c.cleanups) c.cleanups = [];
|
|
1908
|
+
c.cleanups.push(result);
|
|
1909
|
+
}
|
|
1910
|
+
c.value = result;
|
|
1911
|
+
if (c.state === RUNNING) c.state = CLEAN2;
|
|
1912
|
+
} catch (err) {
|
|
1913
|
+
if (isPromise(err)) {
|
|
1914
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1915
|
+
if (ctx) {
|
|
1916
|
+
ctx.increment();
|
|
1917
|
+
err.finally(() => ctx.decrement());
|
|
1918
|
+
if (c.suspense) ctx.effects.push(c);
|
|
1919
|
+
}
|
|
1920
|
+
return;
|
|
1921
|
+
}
|
|
1922
|
+
handleError(err);
|
|
1923
|
+
} finally {
|
|
1924
|
+
Listener = prevListener;
|
|
1925
|
+
Owner = prevOwner;
|
|
1926
|
+
const deferred = Updates;
|
|
1927
|
+
Updates = prevUpdates;
|
|
1928
|
+
if (deferred !== prevUpdates && deferred && deferred.length > 0) {
|
|
1929
|
+
const saved = Updates;
|
|
1930
|
+
runCascadeAndEffects(deferred);
|
|
1931
|
+
Updates = saved;
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
}
|
|
1935
|
+
function createComputed(fn, value, options) {
|
|
1936
|
+
const c = {
|
|
1937
|
+
fn,
|
|
1938
|
+
state: DIRTY2,
|
|
1939
|
+
sources: null,
|
|
1940
|
+
sourceSlots: null,
|
|
1941
|
+
value,
|
|
1942
|
+
owned: null,
|
|
1943
|
+
cleanups: null,
|
|
1944
|
+
owner: Owner,
|
|
1945
|
+
contexts: null,
|
|
1946
|
+
pure: true,
|
|
1947
|
+
computed: true,
|
|
1948
|
+
updatedAt: null
|
|
1949
|
+
};
|
|
1950
|
+
if (Owner) {
|
|
1951
|
+
if (!Owner.owned) Owner.owned = [c];
|
|
1952
|
+
else Owner.owned.push(c);
|
|
1953
|
+
}
|
|
1954
|
+
if (Transition && Transition.running) {
|
|
1955
|
+
if (!Updates) Updates = [];
|
|
1956
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1957
|
+
} else if (Updates) {
|
|
1958
|
+
if (Updates.indexOf(c) === -1) Updates.push(c);
|
|
1959
|
+
} else runComputation(c, value);
|
|
1960
|
+
}
|
|
1961
|
+
var _SuspenseContext;
|
|
1962
|
+
function getSuspenseContext() {
|
|
1963
|
+
return _SuspenseContext || (_SuspenseContext = createContext());
|
|
1964
|
+
}
|
|
1965
|
+
var _SuspenseListContext;
|
|
1966
|
+
function getSuspenseListContext() {
|
|
1967
|
+
return _SuspenseListContext || (_SuspenseListContext = createContext());
|
|
1968
|
+
}
|
|
1969
|
+
function resumeEffects(effects) {
|
|
1970
|
+
if (!effects.length) return;
|
|
1971
|
+
const queued = effects.slice();
|
|
1972
|
+
effects.length = 0;
|
|
1973
|
+
for (const c of queued) {
|
|
1974
|
+
c.state = DIRTY2;
|
|
1975
|
+
updateComputation(c);
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
function onResolve(fn) {
|
|
1979
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1980
|
+
if (ctx && ctx.inFallback())
|
|
1981
|
+
createEffect2(() => {
|
|
1982
|
+
if (!ctx.inFallback()) fn();
|
|
1983
|
+
});
|
|
1984
|
+
else fn();
|
|
1985
|
+
}
|
|
1986
|
+
function setScheduler2(scheduler) {
|
|
1987
|
+
Scheduler = scheduler;
|
|
1988
|
+
}
|
|
1989
|
+
function trackPromise(promise) {
|
|
1990
|
+
const ctx = _SuspenseContext && useContext(_SuspenseContext);
|
|
1991
|
+
if (!ctx) return promise;
|
|
1992
|
+
ctx.increment();
|
|
1993
|
+
promise.finally(() => ctx.decrement());
|
|
1994
|
+
return promise;
|
|
1995
|
+
}
|
|
1996
|
+
var signal_default = {
|
|
1997
|
+
createSignal: createSignal2,
|
|
1998
|
+
createEffect: createEffect2,
|
|
1999
|
+
createMemo: createMemo2,
|
|
2000
|
+
createComputed,
|
|
2001
|
+
createRoot: createRoot2,
|
|
2002
|
+
createSelector,
|
|
2003
|
+
createResource,
|
|
2004
|
+
batch: batch2,
|
|
2005
|
+
untrack: untrack2,
|
|
2006
|
+
onCleanup: onCleanup2,
|
|
2007
|
+
getOwner: getOwner2,
|
|
2008
|
+
runWithOwner: runWithOwner2,
|
|
2009
|
+
createContext,
|
|
2010
|
+
useContext,
|
|
2011
|
+
flush,
|
|
2012
|
+
startTransition,
|
|
2013
|
+
useTransition,
|
|
2014
|
+
isSignal,
|
|
2015
|
+
on,
|
|
2016
|
+
createRenderEffect,
|
|
2017
|
+
getSuspenseContext,
|
|
2018
|
+
getSuspenseListContext,
|
|
2019
|
+
resumeEffects,
|
|
2020
|
+
onResolve,
|
|
2021
|
+
setScheduler: setScheduler2,
|
|
2022
|
+
trackPromise
|
|
2023
|
+
};
|