@but212/atom-effect 0.28.0 → 0.30.0
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/atom-effect.min.js +1 -1
- package/dist/atom-effect.min.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +222 -117
- package/dist/index.mjs +767 -827
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var A={IDLE:"idle",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"},D={DISPOSED:1,EXECUTING:8},X={DISPOSED:1,IS_COMPUTED:2,DIRTY:8,IDLE:16,PENDING:32,RESOLVED:64,REJECTED:128,RECOMPUTING:256,HAS_ERROR:512,FORCE_COMPUTE:1024},a={DISPOSED:1,SYNC:8,NOTIFICATION_SCHEDULED:16},p={MAX_EXECUTIONS_PER_SECOND:1e3,MAX_EXECUTIONS_PER_EFFECT:100,MAX_EXECUTIONS_PER_FLUSH:1e4,MAX_FLUSH_ITERATIONS:1e3,MIN_FLUSH_ITERATIONS:10,BATCH_QUEUE_SHRINK_THRESHOLD:1e3},V={WARN_INFINITE_LOOP:!0,EFFECT_FREQUENCY_WINDOW:1e3},J={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:Number.MAX_SAFE_INTEGER-1},T={UNINITIALIZED:-1,MIN:1},L=1073741823,Et={VERSION_BITS:16},Ht=(typeof process<"u"&&process.env,!1),tt=Object.freeze([]),G=class{constructor(t,s,e=void 0){this.node=t,this.version=s,this.unsub=e}},dt=class{constructor(t,s){this.fn=t,this.sub=s}notify(t,s){const e=this.fn;if(e!==void 0){e(t,s);return}const i=this.sub;i!==void 0&&i.execute()}},g=class extends Error{constructor(t,s=null,e=!0){super(t),this.cause=s,this.recoverable=e,this.name="AtomError"}},S=class extends g{constructor(t,s=null){super(t,s,!0),this.name="ComputedError"}},I=class extends g{constructor(t,s=null){super(t,s,!1),this.name="EffectError"}},w=class extends g{constructor(t,s=null){super(t,s,!1),this.name="SchedulerError"}},_={COMPUTED_MUST_BE_FUNCTION:"Computed target must be a function",COMPUTED_ASYNC_PENDING_NO_DEFAULT:"Async computation pending with no default value",COMPUTED_COMPUTATION_FAILED:"Computation execution failed",COMPUTED_ASYNC_COMPUTATION_FAILED:"Async computation execution failed",COMPUTED_CIRCULAR_DEPENDENCY:"Circular dependency detected",COMPUTED_DISPOSED:"Attempted to access disposed computed",ATOM_SUBSCRIBER_MUST_BE_FUNCTION:"Subscriber must be a function or Subscriber object",ATOM_INDIVIDUAL_SUBSCRIBER_FAILED:"Subscriber execution failed",EFFECT_MUST_BE_FUNCTION:"Effect target must be a function",EFFECT_EXECUTION_FAILED:"Effect execution failed",EFFECT_CLEANUP_FAILED:"Effect cleanup failed",EFFECT_DISPOSED:"Attempted to run disposed effect",SCHEDULER_FLUSH_OVERFLOW:(t,s)=>`Maximum flush iterations (${t}) exceeded. ${s} jobs dropped. Possible infinite loop.`,CALLBACK_ERROR_IN_ERROR_HANDLER:"Exception encountered in onError handler",EFFECT_FREQUENCY_LIMIT_EXCEEDED:"Effect executed too frequently within 1 second. Suspected infinite loop.",SCHEDULER_CALLBACK_MUST_BE_FUNCTION:"Scheduler callback must be a function",SCHEDULER_END_BATCH_WITHOUT_START:"endBatch() called without matching startBatch(). Ignoring.",BATCH_CALLBACK_MUST_BE_FUNCTION:"Batch callback must be a function"},rt=class{constructor(){this._s0=null,this._s1=null,this._s2=null,this._s3=null,this._count=0,this._overflow=null,this._freeIndices=null}get size(){return this._count}getAt(t){if(t<4)switch(t){case 0:return this._s0;case 1:return this._s1;case 2:return this._s2;case 3:return this._s3}const s=this._overflow;if(s!==null){const e=s[t-4];return e===void 0?null:e}return null}setAt(t,s){switch(t){case 0:this._s0=s;break;case 1:this._s1=s;break;case 2:this._s2=s;break;case 3:this._s3=s;break;default:this._overflow??=[],this._overflow[t-4]=s}t>=this._count&&(this._count=t+1)}truncateFrom(t){const s=this._count;if(t>=s)return;if(t<=3){if(t<=0){const i=this._s0;i!=null&&(this._onItemRemoved(i),this._s0=null)}if(t<=1){const i=this._s1;i!=null&&(this._onItemRemoved(i),this._s1=null)}if(t<=2){const i=this._s2;i!=null&&(this._onItemRemoved(i),this._s2=null)}if(t<=3){const i=this._s3;i!=null&&(this._onItemRemoved(i),this._s3=null)}}const e=this._overflow;if(e!==null&&s>4){const i=t>4?t-4:0,r=e.length;for(let n=i;n<r;n++){const o=e[n];o!=null&&(this._onItemRemoved(o),e[n]=null)}t<=4?(e.length=0,this._overflow=null):e.length=t-4}this._freeIndices!==null&&(this._freeIndices=null),this._count=t}_onItemRemoved(t){}add(t){if(this._s0===null){this._s0=t,this._count++;return}if(this._s1===null){this._s1=t,this._count++;return}if(this._s2===null){this._s2=t,this._count++;return}if(this._s3===null){this._s3=t,this._count++;return}this._addToOverflow(t)}_addToOverflow(t){const s=this._overflow;if(s===null)this._overflow=[t];else{const e=this._freeIndices;e!==null&&e.length>0?s[e.pop()]=t:s.push(t)}this._count++}remove(t){if(this._s0===t)return this._s0=null,this._count--,!0;if(this._s1===t)return this._s1=null,this._count--,!0;if(this._s2===t)return this._s2=null,this._count--,!0;if(this._s3===t)return this._s3=null,this._count--,!0;const s=this._overflow;if(s==null)return!1;for(let e=0,i=s.length;e<i;e++)if(s[e]===t){s[e]=null,this._count--;let r=this._freeIndices;return r===null&&(r=this._freeIndices=[]),r.push(e),!0}return!1}has(t){if(this._count===0)return!1;if(this._s0===t||this._s1===t||this._s2===t||this._s3===t)return!0;const s=this._overflow;if(s!=null){for(let e=0,i=s.length;e<i;e++)if(s[e]===t)return!0}return!1}forEach(t){const s=this._count;if(s===0)return;let e=0;const i=this._s0;if(i!=null&&(t(i),++e===s))return;const r=this._s1;if(r!=null&&(t(r),++e===s))return;const n=this._s2;if(n!=null&&(t(n),++e===s))return;const o=this._s3;if(o!=null&&(t(o),++e===s))return;const u=this._overflow;if(u!=null)for(let l=0,h=u.length;l<h;l++){const c=u[l];if(c!=null&&(t(c),++e===s))return}}forEachIndexed(t){const s=this._count;if(s===0)return 0;let e=0;const i=this._s0;if(i!=null&&(t(i),++e===s))return e;const r=this._s1;if(r!=null&&(t(r),++e===s))return e;const n=this._s2;if(n!=null&&(t(n),++e===s))return e;const o=this._s3;if(o!=null&&(t(o),++e===s))return e;const u=this._overflow;if(u!=null)for(let l=0,h=u.length;l<h;l++){const c=u[l];if(c!=null&&(t(c),++e===s))return e}return e}compact(){const t=this._overflow;if(t===null)return;let s=t.length;if(s===0)return;let e=0;for(;e<s;)if(t[e]===null){for(;s>e&&t[s-1]===null;)t.pop(),s--;s>e&&(t[e]=t.pop(),s--,e++)}else e++;this._freeIndices=null,s===0&&(this._overflow=null)}clear(){this._s0=null,this._s1=null,this._s2=null,this._s3=null,this._count=0,this._overflow!==null&&(this._overflow.length=0,this._overflow=null),this._freeIndices=null}dispose(){this.clear()}},st=Symbol("AtomEffect.DebugName"),pt=Symbol("AtomEffect.Id"),et=Symbol("AtomEffect.Type"),x=Symbol("AtomEffect.NoDefaultValue"),Ct=class{constructor(){this.enabled=!1,this.warnInfiniteLoop=V.WARN_INFINITE_LOOP}warn(t,s){}attachDebugInfo(t,s,e){}getDebugName(t){if(t!=null)return t[st]}getDebugType(t){if(t!=null)return t[et]}},P=new Ct,It=1,Dt=()=>It++|0;function N(t,s,e){return t instanceof g?t:t instanceof Error?new s(`${t.name||t.constructor.name||"Error"} (${e}): ${t.message}`,t):new s(`Unexpected error (${e}): ${String(t)}`)}var k=class{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=T.UNINITIALIZED,this._notifying=0,this._hotIndex=-1,this._slots=null,this._deps=null,this.id=Dt()&L}get isDisposed(){return(this.flags&X.DISPOSED)!==0}get isComputed(){return(this.flags&X.IS_COMPUTED)!==0}get hasError(){return!1}subscribe(t){const s=typeof t=="function";if(!s&&(!t||typeof t.execute!="function"))throw N(new TypeError("Invalid subscriber"),g,_.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);let e=this._slots;e||(e=new rt,this._slots=e);let i=!1;if(e._s0!=null&&(s?e._s0.fn===t:e._s0.sub===t))i=!0;else if(e._s1!=null&&(s?e._s1.fn===t:e._s1.sub===t))i=!0;else if(e._s2!=null&&(s?e._s2.fn===t:e._s2.sub===t))i=!0;else if(e._s3!=null&&(s?e._s3.fn===t:e._s3.sub===t))i=!0;else{const n=e._overflow;if(n!=null)for(let o=0,u=n.length;o<u;o++){const l=n[o];if(l!=null&&(s?l.fn===t:l.sub===t)){i=!0;break}}}if(i)return()=>{};const r=new dt(s?t:void 0,s?void 0:t);return e.add(r),()=>this._unsubscribe(r)}_unsubscribe(t){const s=this._slots;s&&(s.remove(t),this._notifying===0&&s.compact())}subscriberCount(){const t=this._slots;return t===null?0:t.size}_notifySubscribers(t,s){const e=this._slots;if(!(e===null||e.size===0)){this._notifying++;try{let i=e._s0;if(i!=null)try{i.notify(t,s)}catch(n){this._logNotifyError(n)}if(i=e._s1,i!=null)try{i.notify(t,s)}catch(n){this._logNotifyError(n)}if(i=e._s2,i!=null)try{i.notify(t,s)}catch(n){this._logNotifyError(n)}if(i=e._s3,i!=null)try{i.notify(t,s)}catch(n){this._logNotifyError(n)}const r=e._overflow;if(r!=null)for(let n=0,o=r.length;n<o;n++){const u=r[n];if(u!=null)try{u.notify(t,s)}catch(l){this._logNotifyError(l)}}}finally{--this._notifying===0&&e.compact()}}}_logNotifyError(t){console.error(N(t,g,_.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}_isDirty(){const t=this._deps;if(t===null||t.size===0)return!1;const s=this._hotIndex;if(s!==-1){const e=t.getAt(s);if(e!=null&&e.node.version!==e.version)return!0}return!t.hasComputeds&&!t.isDirtyFast()?!1:this._deepDirtyCheck()}},B=0;function Y(){const t=B+1&L;return B=t===0?1:t,B}function Q(t){const s=t+1&L;return s===0?1:s}var $=0,U=!1,ot=0;function ut(){return ot}function it(){return U?!1:(U=!0,ot=Y(),$=0,!0)}function nt(){U=!1}function vt(){if(!U)return 0;const t=++$;if(t<=p.MAX_EXECUTIONS_PER_FLUSH)return t;throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${p.MAX_EXECUTIONS_PER_FLUSH}`)}var St=class{constructor(){this._queueBuffer=[[],[]],this._bufferIndex=0,this._size=0,this._epoch=0,this._isProcessing=!1,this._isFlushingSync=!1,this._batchDepth=0,this._batchQueue=[],this._batchQueueSize=0,this._maxFlushIterations=p.MAX_FLUSH_ITERATIONS,this.onOverflow=null,this._boundRunLoop=this._runLoop.bind(this)}get queueSize(){return this._size}get isBatching(){return this._batchDepth>0}schedule(t){const s=this._epoch;if(t._nextEpoch===s)return;if(t._nextEpoch=s,this._batchDepth>0||this._isFlushingSync){this._batchQueue[this._batchQueueSize++]=t;return}const e=this._bufferIndex,i=this._queueBuffer[e];i[this._size++]=t,this._isProcessing||this._flush()}_flush(){this._isProcessing||this._size===0||(this._isProcessing=!0,queueMicrotask(this._boundRunLoop))}_runLoop(){try{if(this._size===0)return;const t=it();this._drainQueue(),t&&nt()}finally{this._isProcessing=!1,this._size>0&&this._batchDepth===0&&this._flush()}}_flushSync(){this._isFlushingSync=!0;const t=it();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,t&&nt()}}_mergeBatchQueue(){const t=this._batchQueueSize;if(t===0)return;const s=++this._epoch,e=this._batchQueue,i=this._bufferIndex,r=this._queueBuffer[i];let n=this._size;for(let o=0;o<t;o++){const u=e[o];u._nextEpoch!==s&&(u._nextEpoch=s,r[n++]=u)}this._size=n,this._batchQueueSize=0,e.length=0}_drainQueue(){let t=0;for(;this._size>0;){if(++t>this._maxFlushIterations){this._handleFlushOverflow();return}this._processQueue(),this._mergeBatchQueue()}}_processQueue(){const t=this._bufferIndex,s=this._queueBuffer[t],e=this._size;this._bufferIndex=t^1,this._size=0,this._epoch=this._epoch+1|0;for(let i=0;i<e;i++){const r=s[i];try{typeof r=="function"?r():r.execute()}catch(n){console.error(new w("Error occurred during scheduler execution",n))}}s.length=0}_handleFlushOverflow(){const t=this._size+this._batchQueueSize,s=this._maxFlushIterations;console.error(new w(_.SCHEDULER_FLUSH_OVERFLOW(s,t))),this._size=0;const e=this._bufferIndex;this._queueBuffer[e].length=0,this._batchQueueSize=0;const i=this.onOverflow;if(i)try{i(t)}catch{}}startBatch(){this._batchDepth++}endBatch(){this._batchDepth!==0&&--this._batchDepth===0&&this._flushSync()}setMaxFlushIterations(t){if(t<p.MIN_FLUSH_ITERATIONS)throw new w(`Max flush iterations must be at least ${p.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=t}},O=new St,j=Symbol.for("atom-effect/atom"),lt=Symbol.for("atom-effect/computed"),ht=Symbol.for("atom-effect/effect"),gt=Symbol.for("atom-effect/writable"),mt=class{constructor(){this.current=null}run(t,s){if(this.current===t)return s();const e=this.current;this.current=t;try{return s()}finally{this.current=e}}},f=new mt;function Tt(t){const s=f,e=s.current;if(e===null)return t();s.current=null;try{return t()}finally{s.current=e}}var Nt=class extends k{constructor(t,s){super(),this[j]=!0,this[gt]=!0,this._value=t,s&&(this.flags|=a.SYNC),P.attachDebugInfo(this,"atom",this.id)}get isNotificationScheduled(){return(this.flags&a.NOTIFICATION_SCHEDULED)!==0}get isSync(){return(this.flags&a.SYNC)!==0}get value(){const t=f.current;return t?.addDependency(this),this._value}set value(t){const s=this._value;if(Object.is(s,t))return;this._value=t,this.version=Q(this.version);const e=this.flags;if((e&a.NOTIFICATION_SCHEDULED)!==0)return;const i=this._slots;i==null||i.size===0||(this._pendingOldValue=s,this.flags=e|a.NOTIFICATION_SCHEDULED,(e&a.SYNC)!==0&&!O.isBatching?this._flushNotifications():O.schedule(this))}execute(){this._flushNotifications()}_flushNotifications(){const t=this.flags;if((t&(a.NOTIFICATION_SCHEDULED|a.DISPOSED))!==a.NOTIFICATION_SCHEDULED)return;const s=this._pendingOldValue;this._pendingOldValue=void 0,this.flags=t&~a.NOTIFICATION_SCHEDULED,this._notifySubscribers(this._value,s)}peek(){return this._value}dispose(){const t=this.flags;(t&a.DISPOSED)===0&&(this._slots?.clear(),this.flags=t|a.DISPOSED,this._value=void 0,this._pendingOldValue=void 0)}_deepDirtyCheck(){return!1}[Symbol.dispose](){this.dispose()}};function yt(t,s={}){return new Nt(t,s.sync??!1)}var ct=class extends rt{constructor(...t){super(...t),this._map=null,this._SCAN_THRESHOLD=32,this.hasComputeds=!1,this._depsHash=0}prepareTracking(){this.hasComputeds=!1}_onItemRemoved(t){const s=t.unsub;s&&s()}claimExisting(t,s){const e=this._count;if(s>=e)return!1;const i=e-s;if(this._map!==null||i>this._SCAN_THRESHOLD)return this._claimViaMap(t,s);if(s<4)switch(s){case 0:{const n=this._s0;if(n&&n.node===t&&n.unsub)return n.version=t.version,!0}case 1:if(e>1){const n=this._s1;if(n&&n.node===t&&n.unsub)return n.version=t.version,s!==1&&(this._s1=this._s0,this._s0=n),!0}case 2:if(e>2){const n=this._s2;if(n&&n.node===t&&n.unsub){if(n.version=t.version,s!==2){const o=s===0?this._s0:this._s1;s===0?this._s0=n:this._s1=n,this._s2=o}return!0}}case 3:if(e>3){const n=this._s3;if(n&&n.node===t&&n.unsub){if(n.version=t.version,s!==3){let o;s===0?(o=this._s0,this._s0=n):s===1?(o=this._s1,this._s1=n):(o=this._s2,this._s2=n),this._s3=o}return!0}}}const r=this._overflow;if(r){const n=t.version,o=s>4?s:4,u=r.length;for(let l=o-4;l<u;l++){const h=r[l];if(h&&h.node===t&&h.unsub)return h.version=n,this._swapGeneral(l+4,s,h),!0}}return!1}_claimViaMap(t,s){let e=this._map;if(e===null){e=this._map=new Map;const n=this._count;if(s<4){const u=this._s0;s<=0&&u?.unsub&&e.set(u.node,0);const l=this._s1;s<=1&&l?.unsub&&e.set(l.node,1);const h=this._s2;s<=2&&h?.unsub&&e.set(h.node,2);const c=this._s3;s<=3&&c?.unsub&&e.set(c.node,3)}const o=this._overflow;if(o&&n>4){const u=s>4?s:4,l=o.length;for(let h=u-4;h<l;h++){const c=o[h];c?.unsub&&e.set(c.node,h+4)}}}const i=e.get(t);if(i===void 0||i<s)return!1;const r=this.getAt(i);if(r==null||!r.unsub)return!1;if(r.version=t.version,i!==s){let n;s===0?n=this._s0:s===1?n=this._s1:s===2?n=this._s2:s===3?n=this._s3:n=this._overflow[s-4]??null,this.setAt(s,r),this.setAt(i,n),n?.unsub&&e.set(n.node,i),e.set(t,s)}return!0}_swapGeneral(t,s,e){if(t===s)return;let i;if(s===0?i=this._s0:s===1?i=this._s1:s===2?i=this._s2:s===3?i=this._s3:i=this._overflow[s-4]??null,this.setAt(s,e),t===0)this._s0=i;else if(t===1)this._s1=i;else if(t===2)this._s2=i;else if(t===3)this._s3=i;else{const r=this._overflow;r[t-4]=i}}insertNew(t,s){const e=this._count;if(t<e){let i;t===0?i=this._s0:t===1?i=this._s1:t===2?i=this._s2:t===3?i=this._s3:i=this._overflow[t-4]??null,i!=null&&(this._addToOverflow(i),this._map!==null&&i.unsub&&this._map.set(i.node,this._count-1))}if(t===0)this._s0=s;else if(t===1)this._s1=s;else if(t===2)this._s2=s;else if(t===3)this._s3=s;else{let i=this._overflow;i||(i=[],this._overflow=i),i[t-4]=s}t>=e&&(this._count=t+1)}truncateFrom(t){t>=this._count||(super.truncateFrom(t),this._map!==null&&(this._map.clear(),this._map=null))}seal(){this._depsHash=this._calculateHash(!1)}isDirtyFast(){return this._calculateHash(!0)!==this._depsHash}_calculateHash(t){const s=this._count;if(s===0)return 0;const e=Et.VERSION_BITS;let i=0;const r=this._s0;if(r!=null){const n=r.node,o=t?n.version:r.version;i=i+(o<<e)+n.id|0;const u=this._s1;if(s>1&&u!=null){const l=u.node,h=t?l.version:u.version;i=i+(h<<e)+l.id|0;const c=this._s2;if(s>2&&c!=null){const K=c.node,ft=t?K.version:c.version;i=i+(ft<<e)+K.id|0;const M=this._s3;if(s>3&&M!=null){const Z=M.node,at=t?Z.version:M.version;i=i+(at<<e)+Z.id|0}}}}if(s>4){const n=this._overflow;for(let o=0,u=n.length;o<u;o++){const l=n[o],h=l.node,c=t?h.version:l.version;i=i+(c<<e)+h.id|0}}return i}disposeAll(){this._count>0&&this.truncateFrom(0),this.hasComputeds=!1}remove(t){throw new Error("remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.")}compact(){}};function At(t){return typeof t=="object"&&t!==null&&j in t}function bt(t){return typeof t=="object"&&t!==null&< in t}function Ot(t){return typeof t=="object"&&t!==null&&ht in t}function _t(t){return typeof t=="object"&&t!==null&&typeof t.then=="function"}var{IDLE:C,DIRTY:E,PENDING:m,RESOLVED:d,REJECTED:v,HAS_ERROR:R,RECOMPUTING:y,DISPOSED:H,IS_COMPUTED:F,FORCE_COMPUTE:z}=X,Rt=class extends k{constructor(t,s={}){if(typeof t!="function")throw new S(_.COMPUTED_MUST_BE_FUNCTION);if(super(),this[j]=!0,this[lt]=!0,this._error=null,this._promiseId=0,this._deps=new ct,this._asyncRetryCount=0,this._lastDriftEpoch=T.UNINITIALIZED,this._trackEpoch=T.UNINITIALIZED,this._trackCount=0,this._value=void 0,this.flags=F|E|C,this._equal=s.equal??Object.is,this._fn=t,this._defaultValue="defaultValue"in s?s.defaultValue:x,this._onError=s.onError??null,this._maxAsyncRetries=(s.maxAsyncRetries??J.MAX_ASYNC_RETRIES)&L,P.attachDebugInfo(this,"computed",this.id),s.lazy===!1)try{this._recompute()}catch{}}get isDirty(){return(this.flags&E)!==0}get isRejected(){return(this.flags&v)!==0}get isRecomputing(){return(this.flags&y)!==0}get _hasErrorInternal(){return(this.flags&R)!==0}_track(){f.current?.addDependency(this)}get value(){const t=f.current;t?.addDependency(this);let s=this.flags;if((s&(d|E|C))===d)return this._value;if((s&H)!==0)throw new S(_.COMPUTED_DISPOSED);if((s&y)!==0){const r=this._defaultValue;if(r!==x)return r;throw new S(_.COMPUTED_CIRCULAR_DEPENDENCY)}if((s&(E|C))!==0){const r=this._deps;if((s&C)===0&&(s&z)===0&&r.size>0&&!this._isDirty()?s=this.flags&=~E:(this._recompute(),s=this.flags),(s&d)!==0)return this._value}const e=this._defaultValue,i=e!==x;if((s&m)!==0){if(i)return e;throw new S(_.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if((s&v)!==0){if(i)return e;throw this._error}return this._value}peek(){return this._value}get state(){const t=f.current;t?.addDependency(this);const s=this.flags;return(s&d)!==0?A.RESOLVED:(s&m)!==0?A.PENDING:(s&v)!==0?A.REJECTED:A.IDLE}get hasError(){const t=f.current;if(t?.addDependency(this),(this.flags&(v|R))!==0)return!0;const s=this._deps;if(!s.hasComputeds)return!1;const e=s.size;for(let i=0;i<e;i++)if(s.getAt(i)?.node.hasError)return!0;return!1}get isValid(){return!this.hasError}get errors(){const t=f.current;t?.addDependency(this);const s=this._error,e=this._deps;if(!e.hasComputeds)return s==null?tt:Object.freeze([s]);const i=[];s!=null&&i.push(s);const r=e.size;for(let n=0;n<r;n++){const o=e.getAt(n);if(o==null)continue;const u=o.node;(u.flags&F)!==0&&u.hasError&&this._collectErrorsFromDep(u,i)}return i.length===0?tt:Object.freeze(i)}_collectErrorsFromDep(t,s){const e=t.errors,i=e.length;for(let r=0;r<i;r++){const n=e[r];n!=null&&!s.includes(n)&&s.push(n)}}get lastError(){const t=f.current;return t?.addDependency(this),this._error}get isPending(){const t=f.current;return t?.addDependency(this),(this.flags&m)!==0}get isResolved(){const t=f.current;return t?.addDependency(this),(this.flags&d)!==0}invalidate(){this.flags|=z,this._markDirty()}dispose(){(this.flags&H)===0&&(this._deps.disposeAll(),this._slots!=null&&this._slots.clear(),this.flags=H|E|C,this._error=null,this._value=void 0,this._hotIndex=-1)}[Symbol.dispose](){this.dispose()}addDependency(t){const s=this._trackEpoch;if(t._lastSeenEpoch===s)return;t._lastSeenEpoch=s;const e=this._trackCount++,i=this._deps,r=i.getAt(e);if(r!=null&&r.node===t)r.version=t.version;else if(!i.claimExisting(t,e)){const n=new G(t,t.version,t.subscribe(this));i.insertNew(e,n)}(t.flags&F)!==0&&(i.hasComputeds=!0)}_recompute(){if(this.isRecomputing)return;this.flags=(this.flags|y)&~z,this._trackEpoch=Y(),this._trackCount=0,this._deps.prepareTracking(),this._hotIndex=-1;let t=!1;try{const s=f.run(this,this._fn);this._deps.truncateFrom(this._trackCount),this._deps.seal(),t=!0,_t(s)?this._handleAsyncComputation(s):this._finalizeResolution(s)}catch(s){if(!t)try{this._deps.truncateFrom(this._trackCount)}catch{}this._handleError(s,_.COMPUTED_COMPUTATION_FAILED,!0)}finally{this._trackEpoch=T.UNINITIALIZED,this._trackCount=0,this.flags&=~y}}_handleAsyncComputation(t){this.flags=(this.flags|m)&~(C|E|d|v),this._notifySubscribers(void 0,void 0),this._asyncRetryCount=0,this._promiseId=(this._promiseId+1)%J.MAX_PROMISE_ID;const s=this._promiseId;t.then(e=>{if(s===this._promiseId){if(this._isDirty()){const i=ut();return this._lastDriftEpoch!==i&&(this._lastDriftEpoch=i,this._asyncRetryCount=0),this._asyncRetryCount++<this._maxAsyncRetries?this._markDirty():this._handleError(new S(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`),_.COMPUTED_ASYNC_COMPUTATION_FAILED)}this._finalizeResolution(e),this._notifySubscribers(e,void 0)}},e=>s===this._promiseId&&this._handleError(e,_.COMPUTED_ASYNC_COMPUTATION_FAILED))}_handleError(t,s,e=!1){const i=N(t,S,s);if(!e&&!this.isRejected&&(this.version=Q(this.version)),this._error=i,this.flags=this.flags&~(C|E|m|d)|v|R,this._onError)try{this._onError(i)}catch(r){console.error(_.CALLBACK_ERROR_IN_ERROR_HANDLER,r)}if(e)throw i;this._notifySubscribers(void 0,void 0)}_finalizeResolution(t){const s=this.flags;((s&d)===0||!this._equal(this._value,t))&&(this.version=Q(this.version)),this._value=t,this._error=null,this.flags=(s|d)&~(C|E|m|v|R)}execute(){this._markDirty()}_markDirty(){const t=this.flags;(t&(y|E))===0&&(this.flags=t|E,this._notifySubscribers(void 0,void 0))}_isDirty(){const t=this._deps;return t.hasComputeds?this._deepDirtyCheck():t.isDirtyFast()}_deepDirtyCheck(){const t=this._deps,s=f.current;f.current=null;try{const e=t.size;for(let i=0;i<e;i++){const r=t.getAt(i);if(r==null)continue;const n=r.node;if((n.flags&F)!==0)try{n.value}catch{}if(n.version!==r.version)return this._hotIndex=i,!0}return this._hotIndex=-1,!1}finally{f.current=s}}};function Ft(t,s={}){return new Rt(t,s)}var wt=class extends k{constructor(t,s={}){super(),this[ht]=!0,this._cleanup=null,this._deps=new ct,this._currentEpoch=T.UNINITIALIZED,this._lastFlushEpoch=T.UNINITIALIZED,this._fn=t,this._onError=s.onError??null,this._sync=s.sync??!1,this._maxExecutions=s.maxExecutionsPerSecond??p.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=s.maxExecutionsPerFlush??p.MAX_EXECUTIONS_PER_EFFECT,this._executionsInEpoch=0,this._executionCount=0,this._windowStart=0,this._windowCount=0,this._execId=0,this._trackCount=0,this._sync?this._notifyCallback=()=>this.execute():this._notifyCallback=()=>O.schedule(this),P.attachDebugInfo(this,"effect",this.id)}run(){if(this.isDisposed)throw new I(_.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.isDisposed||(this.flags|=D.DISPOSED,this._execCleanup(),this._deps?.disposeAll())}[Symbol.dispose](){this.dispose()}addDependency(t){if((this.flags&D.EXECUTING)===0)return;const s=this._currentEpoch;if(t._lastSeenEpoch===s)return;t._lastSeenEpoch=s;const e=this._trackCount++,i=this._deps;let r;switch(e){case 0:r=i._s0;break;case 1:r=i._s1;break;case 2:r=i._s2;break;case 3:r=i._s3;break;default:r=i.getAt(e)}r!=null&&r.node===t?r.version=t.version:i.claimExisting(t,e)||this._insertNewDependency(t,e),t.isComputed&&(i.hasComputeds=!0)}_insertNewDependency(t,s){let e;try{const i=t.subscribe(this._notifyCallback);e=new G(t,t.version,i)}catch(i){const r=N(i,I,_.EFFECT_EXECUTION_FAILED);if(console.error(r),this._onError)try{this._onError(r)}catch{}e=new G(t,t.version,void 0)}this._deps.insertNew(s,e)}execute(t=!1){const s=this.flags;if((s&(D.DISPOSED|D.EXECUTING))!==0)return;const e=this._deps;if(!t&&e.size>0&&!this._isDirty())return;this._checkInfiniteLoops(),this.flags=s|D.EXECUTING,this._execCleanup(),this._currentEpoch=Y(),this._trackCount=0,e.prepareTracking(),this._hotIndex=-1;let i=!1;try{const r=f.run(this,this._fn);e.truncateFrom(this._trackCount),e.seal(),i=!0,_t(r)?this._handleAsyncResult(r):this._cleanup=typeof r=="function"?r:null}catch(r){if(!i)try{e.truncateFrom(this._trackCount)}catch{}this._handleExecutionError(r),this._cleanup=null}finally{this.flags&=~D.EXECUTING}}_isDirty(){const t=this._deps;return t.hasComputeds?this._deepDirtyCheck():t.isDirtyFast()}_handleAsyncResult(t){const s=++this._execId;t.then(e=>{if(s!==this._execId||this.isDisposed){if(typeof e=="function")try{e()}catch(i){this._handleExecutionError(i,_.EFFECT_CLEANUP_FAILED)}return}typeof e=="function"&&(this._cleanup=e)},e=>s===this._execId&&this._handleExecutionError(e))}_deepDirtyCheck(){const t=f.current;f.current=null;const s=this._deps;try{const e=s.size;for(let i=0;i<e;i++){const r=s.getAt(i);if(r==null)continue;const n=r.node;if(n.isComputed&&this._tryPullComputed(n),n.version!==r.version)return this._hotIndex=i,!0}return!1}finally{f.current=t}}_tryPullComputed(t){try{t.value}catch{}}_execCleanup(){const t=this._cleanup;if(t!=null){this._cleanup=null;try{t()}catch(s){this._handleExecutionError(s,_.EFFECT_CLEANUP_FAILED)}}}_checkInfiniteLoops(){const t=ut();this._lastFlushEpoch!==t&&(this._lastFlushEpoch=t,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError("per-effect"),vt()>p.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError("global"),this._executionCount++}_checkFrequencyLimit(){if(!Number.isFinite(this._maxExecutions))return;const t=Date.now();if(t-this._windowStart>=V.EFFECT_FREQUENCY_WINDOW){this._windowStart=t,this._windowCount=1;return}if(++this._windowCount>this._maxExecutions){const s=new I(_.EFFECT_FREQUENCY_LIMIT_EXCEEDED);throw this.dispose(),this._handleExecutionError(s),s}}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&D.EXECUTING)!==0}_throwInfiniteLoopError(t){const s=new I(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${$}`);throw this.dispose(),console.error(s),s}_handleExecutionError(t,s=_.EFFECT_EXECUTION_FAILED){const e=N(t,I,s);if(console.error(e),this._onError)try{this._onError(e)}catch(i){console.error(N(i,I,_.CALLBACK_ERROR_IN_ERROR_HANDLER))}}};function Ut(t,s={}){if(typeof t!="function")throw new I(_.EFFECT_MUST_BE_FUNCTION);const e=new wt(t,s);return e.execute(),e}var Lt=Symbol.for("atom-effect/atom"),Pt=Symbol.for("atom-effect/writable");function q(t,s,e,i){if(e===s.length)return i;const r=s[e],n=t!=null&&typeof t=="object"?t:{},o=n[r],u=q(o,s,e+1,i);if(Object.is(o,u))return t;if(Array.isArray(n)){const l=n.slice(),h=Number.parseInt(r,10);return Number.isNaN(h)?l[r]=u:l[h]=u,l}return{...n,[r]:u}}function b(t,s){let e=t;const i=s.length;for(let r=0;r<i;r++){if(e==null)return;e=e[s[r]]}return e}function W(t,s){const e=s.includes(".")?s.split("."):[s],i=new Set,r=()=>{i.forEach(n=>n()),i.clear()};return{get value(){return b(t.value,e)},set value(n){const o=t.peek(),u=q(o,e,0,n);u!==o&&(t.value=u)},peek:()=>b(t.peek(),e),subscribe(n){const o=t.subscribe((u,l)=>{const h=b(u,e),c=b(l,e);Object.is(h,c)||n(h,c)});return i.add(o),()=>{o(),i.delete(o)}},subscriberCount:()=>i.size,dispose:r,[Symbol.dispose]:r,[Lt]:!0,[Pt]:!0}}var Mt=(t,s)=>W(t,s),xt=t=>s=>W(t,s);function Bt(t){if(typeof t!="function")throw new TypeError(_.BATCH_CALLBACK_MUST_BE_FUNCTION);const s=O;s.startBatch();try{return t()}finally{s.endBatch()}}exports.AsyncState=A;exports.AtomError=g;exports.ComputedError=S;exports.DEBUG_CONFIG=V;exports.DEBUG_RUNTIME=P;exports.EffectError=I;exports.SCHEDULER_CONFIG=p;exports.SchedulerError=w;exports.atom=yt;exports.atomLens=W;exports.batch=Bt;exports.composeLens=Mt;exports.computed=Ft;exports.effect=Ut;exports.getPathValue=b;exports.isAtom=At;exports.isComputed=bt;exports.isEffect=Ot;exports.lensFor=xt;exports.scheduler=O;exports.setDeepValue=q;exports.untracked=Tt;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var u={DISPOSED:1,IS_COMPUTED:2,DIRTY:256,RECOMPUTING:512,HAS_ERROR:1024,FORCE_COMPUTE:2048,IDLE:65536,PENDING:1<<17,RESOLVED:1<<18,REJECTED:1<<19,ATOM_SYNC:1<<24,ATOM_NOTIFICATION_SCHEDULED:1<<25,EFFECT_EXECUTING:1<<28},Mt=Object.freeze({ASYNC_STATE:u.IDLE|u.PENDING|u.RESOLVED|u.REJECTED,COMPUTED_DIRTY_MASK:u.DIRTY|u.RECOMPUTING|u.FORCE_COMPUTE}),F=Object.freeze({IDLE:"idle",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"}),m=Object.freeze({DISPOSED:u.DISPOSED,EXECUTING:u.EFFECT_EXECUTING}),Y=Object.freeze({DISPOSED:u.DISPOSED,IS_COMPUTED:u.IS_COMPUTED,DIRTY:u.DIRTY,IDLE:u.IDLE,PENDING:u.PENDING,RESOLVED:u.RESOLVED,REJECTED:u.REJECTED,RECOMPUTING:u.RECOMPUTING,HAS_ERROR:u.HAS_ERROR,FORCE_COMPUTE:u.FORCE_COMPUTE}),f=Object.freeze({DISPOSED:u.DISPOSED,SYNC:u.ATOM_SYNC,NOTIFICATION_SCHEDULED:u.ATOM_NOTIFICATION_SCHEDULED}),p=Object.freeze({MAX_EXECUTIONS_PER_SECOND:1e3,MAX_EXECUTIONS_PER_EFFECT:100,MAX_EXECUTIONS_PER_FLUSH:1e4,MAX_FLUSH_ITERATIONS:1e3,MIN_FLUSH_ITERATIONS:10,BATCH_QUEUE_SHRINK_THRESHOLD:1e3}),B=1073741823,z=Object.freeze({WARN_INFINITE_LOOP:!0,EFFECT_FREQUENCY_WINDOW:1e3,LOOP_THRESHOLD:100}),at=Object.freeze({MAX_PROMISE_ID:B}),P=Object.freeze({UNINITIALIZED:-1,MIN:1}),ht=!1;try{ht=!!(typeof globalThis<"u"&&globalThis.__ATOM_DEBUG__||typeof sessionStorage<"u"&&sessionStorage.getItem("__ATOM_DEBUG__")==="true")}catch{}var _=(typeof process<"u"&&process.env,typeof __DEV__<"u"&&!!__DEV__||ht),it=Object.freeze([]),I=class V extends Error{constructor(e,s=null,i=!0,n){super(e),this.cause=s,this.recoverable=i,this.code=n,this.name="AtomError",Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}getChain(){if(this.cause===null||this.cause===void 0)return[this];const e=[this],s=new Set([this]);let i=this.cause;for(;i!=null;){const n=s.has(i);if(e.push(i),n)break;if(s.add(i),i instanceof V)i=i.cause;else if(i instanceof Error&&"cause"in i)i=i.cause;else break}return e}toJSON(e=new Set){if(e.has(this))return{name:this.name,message:"[Circular Reference]",recoverable:this.recoverable,code:this.code};e.add(this);let s=this.cause;return this.cause instanceof V?s=this.cause.toJSON(e):this.cause instanceof Error&&(s={name:this.cause.name,message:this.cause.message,stack:this.cause.stack,cause:this.cause.cause}),{name:this.name,message:this.message,code:this.code,recoverable:this.recoverable,stack:this.stack,cause:s}}static format(e,s,i){return`${e} (${s}): ${i}`}},N=class extends I{constructor(...t){super(...t),this.name="ComputedError"}},S=class extends I{constructor(t,e=null,s=!1,i){super(t,e,s,i),this.name="EffectError"}},w=class extends I{constructor(t,e=null,s=!1,i){super(t,e,s,i),this.name="SchedulerError"}},h={COMPUTED_MUST_BE_FUNCTION:"Computed target must be a function",COMPUTED_ASYNC_PENDING_NO_DEFAULT:"Async computation pending with no default value",COMPUTED_COMPUTATION_FAILED:"Computation execution failed",COMPUTED_ASYNC_COMPUTATION_FAILED:"Async computation execution failed",COMPUTED_CIRCULAR_DEPENDENCY:"Circular dependency detected",COMPUTED_DISPOSED:"Attempted to access disposed computed",ATOM_SUBSCRIBER_MUST_BE_FUNCTION:"Subscriber must be a function or Subscriber object",ATOM_INDIVIDUAL_SUBSCRIBER_FAILED:"Subscriber execution failed",EFFECT_MUST_BE_FUNCTION:"Effect target must be a function",EFFECT_EXECUTION_FAILED:"Effect execution failed",EFFECT_CLEANUP_FAILED:"Effect cleanup failed",EFFECT_DISPOSED:"Attempted to run disposed effect",SCHEDULER_FLUSH_OVERFLOW:(t,e)=>`Maximum flush iterations (${t}) exceeded. ${e} jobs dropped. Possible infinite loop.`,CALLBACK_ERROR_IN_ERROR_HANDLER:"Exception encountered in onError handler",EFFECT_FREQUENCY_LIMIT_EXCEEDED:"Effect executed too frequently within 1 second. Suspected infinite loop.",SCHEDULER_CALLBACK_MUST_BE_FUNCTION:"Scheduler callback must be a function",SCHEDULER_END_BATCH_WITHOUT_START:"endBatch() called without matching startBatch(). Ignoring.",BATCH_CALLBACK_MUST_BE_FUNCTION:"Batch callback must be a function"};function b(t,e,s){if(t instanceof I)return new e(I.format(t.name,s,t.message),t,t.recoverable,t.code);if(t instanceof Error){const i=t.name||t.constructor.name||"Error";return new e(I.format(i,s,t.message),t)}return new e(I.format("Unexpected error",s,String(t)),t)}var nt=Symbol("AtomEffect.DebugName"),ft=Symbol("AtomEffect.Id"),rt=Symbol("AtomEffect.Type"),H=Symbol("AtomEffect.NoDefaultValue"),Et="[Atom Effect]",dt=class{constructor(){this.enabled=!0,this.warnInfiniteLoop=z.WARN_INFINITE_LOOP,this._updateCounts=new Map,this._nodeRegistry=new Map,this._threshold=z.LOOP_THRESHOLD,this._cleanupScheduled=!1,this.warn=(t,e)=>{this.enabled&&t&&console.warn(`${Et} ${e}`)},this.registerNode=t=>{this._nodeRegistry.set(t.id,new WeakRef(t))},this.attachDebugInfo=(t,e,s,i)=>{this.enabled&&(Object.defineProperties(t,{[nt]:{value:i??`${e}_${s}`,configurable:!0},[ft]:{value:s,configurable:!0},[rt]:{value:e,configurable:!0}}),this.registerNode(t))},this.trackUpdate=(t,e)=>{if(!this.enabled||!this.warnInfiniteLoop)return;const s=this._updateCounts,i=(s.get(t)??0)+1;i>this._threshold?this.warn(!0,`Infinite loop detected for ${e??`dependency ${t}`}. Over ${this._threshold} updates in a single execution scope.`):s.set(t,i),this._cleanupScheduled||(this._cleanupScheduled=!0,Promise.resolve().then(()=>{this._updateCounts.clear(),this._cleanupScheduled=!1}))},this.dumpGraph=()=>{const t=[];for(const[e,s]of this._nodeRegistry){const i=s.deref();i?t.push({id:e,name:this.getDebugName(i),type:this.getDebugType(i),updateCount:this._updateCounts.get(e)??0}):(this._nodeRegistry.delete(e),this._updateCounts.delete(e))}return t},this.getDebugName=t=>{if(t)return t[nt]},this.getDebugType=t=>{if(t)return t[rt]}}},pt={enabled:!1,warnInfiniteLoop:!1,warn:()=>{},registerNode:()=>{},attachDebugInfo:()=>{},trackUpdate:()=>{},dumpGraph:()=>[],getDebugName:()=>{},getDebugType:()=>{}},d=_?new dt:pt,It=1,Ct=()=>It++|0,ct=class{constructor(){this._s0=null,this._s1=null,this._s2=null,this._s3=null,this._count=0,this._actualCount=0,this._overflow=null,this._freeIndices=null}_rawWrite(t,e){if(t<4)t===0?this._s0=e:t===1?this._s1=e:t===2?this._s2=e:this._s3=e;else{this._overflow===null&&(this._overflow=[]);const s=this._overflow,i=t-4;s[i]=e}}_rawAdd(t){if(this._s0===null)return this._s0=t,0;if(this._s1===null)return this._s1=t,1;if(this._s2===null)return this._s2=t,2;if(this._s3===null)return this._s3=t,3;this._overflow===null&&(this._overflow=[]);const e=this._overflow,s=this._freeIndices;if(s!==null&&s.length>0){const i=s.pop();return e[i]=t,i+4}return e.push(t),4+e.length-1}_rawSwap(t,e){if(t===e)return;const s=this.getAt(t),i=this.getAt(e);this._rawWrite(t,i),this._rawWrite(e,s)}get size(){return this._actualCount}get physicalSize(){return this._count}getAt(t){return t<4?t===0?this._s0:t===1?this._s1:t===2?this._s2:this._s3:this._overflow?.[t-4]??null}setAt(t,e){const s=this.getAt(t);s!==e&&(this._rawWrite(t,e),s===null?this._actualCount++:e===null&&this._actualCount--,e!==null&&t>=this._count?this._count=t+1:e===null&&this._shrinkPhysicalSizeFrom(t))}_shrinkPhysicalSizeFrom(t){if(t===this._count-1)for(this._count--;this._count>0&&this.getAt(this._count-1)==null;)this._count--}truncateFrom(t){t<=3&&(t<=0&&this._s0!==null&&(this._onItemRemoved(this._s0),this._s0=null,this._actualCount--),t<=1&&this._s1!==null&&(this._onItemRemoved(this._s1),this._s1=null,this._actualCount--),t<=2&&this._s2!==null&&(this._onItemRemoved(this._s2),this._s2=null,this._actualCount--),t<=3&&this._s3!==null&&(this._onItemRemoved(this._s3),this._s3=null,this._actualCount--));const e=this._overflow;if(e!==null){const s=t>4?t-4:0,i=e.length;for(let n=s;n<i;n++){const r=e[n];r!=null&&(this._onItemRemoved(r),e[n]=null,this._actualCount--)}t<=4?this._overflow=null:e.length=t-4}this._count=t,this._actualCount<0&&(this._actualCount=0),this._freeIndices=null}_onItemRemoved(t){}add(t){const e=this._rawAdd(t);return e>=this._count&&(this._count=e+1),this._actualCount++,e}remove(t){let e=-1;if(this._s0===t)e=0;else if(this._s1===t)e=1;else if(this._s2===t)e=2;else if(this._s3===t)e=3;else{const s=this._overflow;s!==null&&(e=s.indexOf(t),e!==-1&&(e+=4))}return e!==-1?(this._rawWrite(e,null),this._shrinkPhysicalSizeFrom(e),this._actualCount--,e>=4&&(this._freeIndices===null&&(this._freeIndices=[]),this._freeIndices.push(e-4)),!0):!1}has(t){if(this._actualCount===0)return!1;if(this._s0===t||this._s1===t||this._s2===t||this._s3===t)return!0;const e=this._overflow;return e!==null?e.indexOf(t)!==-1:!1}forEach(t){const e=this._actualCount;if(e===0)return;if(e===this._count){this._s0!=null&&t(this._s0),this._s1!=null&&t(this._s1),this._s2!=null&&t(this._s2),this._s3!=null&&t(this._s3);const n=this._overflow;if(n!==null)for(let r=0,o=n.length;r<o;r++){const c=n[r];c!=null&&t(c)}return}let s=0;const i=this._count;for(let n=0;n<i;n++){const r=this.getAt(n);if(r!=null&&(t(r),++s>=e))break}}compact(){if(this._actualCount===this._count)return;let t=0;const e=this._count;for(let s=0;s<e;s++){const i=this.getAt(s);i!=null&&(s!==t&&(this._rawWrite(t,i),this._rawWrite(s,null)),t++)}this._count=this._actualCount,this._overflow!==null&&(t<=4?this._overflow=null:this._overflow.length=t-4),this._freeIndices=null}clear(){this._s0=this._s1=this._s2=this._s3=null,this._count=0,this._actualCount=0,this._overflow=null,this._freeIndices=null}dispose(){this.clear()}},lt=class extends ct{constructor(...t){super(...t),this._map=null,this._SCAN_THRESHOLD=32,this.hasComputeds=!1}prepareTracking(){this.hasComputeds=!1}_onItemRemoved(t){t.unsub?.()}setAt(t,e){const s=this.getAt(t);super.setAt(t,e),this._map!==null&&(s?.unsub&&this._map.delete(s.node),e?.unsub&&this._map.set(e.node,t))}claimExisting(t,e){const s=this._count;if(s<=e)return!1;const i=this.getAt(e);if(i&&i.node===t&&i.unsub)return i.version=t.version,!0;if(this._map!==null||s-e>this._SCAN_THRESHOLD)return this._claimViaMap(t,e);for(let n=e+1;n<s;n++){const r=this.getAt(n);if(r&&r.node===t&&r.unsub)return r.version=t.version,this._rawSwap(n,e),!0}return!1}_claimViaMap(t,e){this._map===null&&(this._map=this._initMap());const s=this._map,i=s.get(t);if(i===void 0||i<e)return!1;const n=this.getAt(i);if(n==null||!n.unsub)return!1;if(n.version=t.version,i!==e){const r=this.getAt(e);this._rawSwap(i,e),s.set(t,e),r?.unsub&&s.set(r.node,i)}return!0}_initMap(){const t=new Map;for(let e=0;e<this._count;e++){const s=this.getAt(e);s?.unsub&&t.set(s.node,e)}return t}insertNew(t,e){const s=this.getAt(t);if(s!==null){const i=this._rawAdd(s);i>=this._count&&(this._count=i+1),this._map!==null&&s.unsub&&this._map.set(s.node,i)}this._rawWrite(t,e),t>=this._count&&(this._count=t+1),this._actualCount++,this._map!==null&&e.unsub&&this._map.set(e.node,t)}add(t){const e=super.add(t);return this._map!==null&&t.unsub&&this._map.set(t.node,e),e}remove(t){throw new Error("remove() prohibited")}compact(){}truncateFrom(t){super.truncateFrom(t),this._map!==null&&(this._map=null)}disposeAll(){this.truncateFrom(0),this.hasComputeds=!1}},M=Symbol.for("atom-effect/brand"),C={Atom:1,Writable:2,Computed:4,Effect:8};function q(t,e){if(!t)return!1;const s=typeof t;return(s==="object"||s==="function")&&!!((t[M]??0)&e)}function gt(t){return q(t,C.Atom)}function Dt(t){return q(t,C.Computed)}function St(t){return q(t,C.Effect)}function $(t){if(t instanceof Promise)return!0;if(!t)return!1;const e=typeof t;return(e==="object"||e==="function")&&typeof t.then=="function"}var j=class{constructor(t,e,s=void 0){this.node=t,this.version=e,this.unsub=s}},mt=class{constructor(t=void 0,e=void 0){this.fn=t,this.sub=e}notify(t,e){L(()=>{const s=this.fn;s!==void 0&&s(t,e);const i=this.sub;i!==void 0&&i.execute()})}},Tt=class{constructor(){this.current=null}run(t,e){if(this.current===t)return e();const s=this.current;this.current=t;try{const i=e();return _&&d.warn($(i),'Detected Promise returned within tracking context. Dependencies accessed after "await" will NOT be tracked. Consider using synchronous tracking before the async boundary.'),i}finally{this.current=s}}},l=new Tt;function L(t){const e=l,s=e.current;if(s===null)return t();e.current=null;try{return t()}finally{e.current=s}}var K=class{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=P.UNINITIALIZED,this._nextEpoch=void 0,this._notifying=0,this._hotIndex=-1,this._slots=null,this._deps=null,this.id=Ct()&B}get isDisposed(){return(this.flags&Y.DISPOSED)!==0}get isComputed(){return(this.flags&Y.IS_COMPUTED)!==0}get hasError(){return!1}subscribe(t){const e=typeof t=="function";if(!e&&(!t||typeof t.execute!="function"))throw b(new TypeError("Invalid subscriber"),I,h.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);let s=this._slots;s||(s=new ct,this._slots=s);let i=!1;if(s._s0!=null&&(e?s._s0.fn===t:s._s0.sub===t))i=!0;else if(s._s1!=null&&(e?s._s1.fn===t:s._s1.sub===t))i=!0;else if(s._s2!=null&&(e?s._s2.fn===t:s._s2.sub===t))i=!0;else if(s._s3!=null&&(e?s._s3.fn===t:s._s3.sub===t))i=!0;else{const r=s._overflow;if(r!=null)for(let o=0,c=r.length;o<c;o++){const a=r[o];if(a!=null&&(e?a.fn===t:a.sub===t)){i=!0;break}}}if(i)return _&&console.warn(`[atom-effect] Duplicate subscription ignored on node ${this.id}`),()=>{};const n=new mt(e?t:void 0,e?void 0:t);return s.add(n),()=>this._unsubscribe(n)}_unsubscribe(t){const e=this._slots;e&&(e.remove(t),this._notifying===0&&e.compact())}subscriberCount(){const t=this._slots;return t===null?0:t.size}_notifySubscribers(t,e){const s=this._slots;if(!(s===null||s.size===0)){this._notifying++;try{let i=s._s0;if(i!=null)try{i.notify(t,e)}catch(r){this._logNotifyError(r)}if(i=s._s1,i!=null)try{i.notify(t,e)}catch(r){this._logNotifyError(r)}if(i=s._s2,i!=null)try{i.notify(t,e)}catch(r){this._logNotifyError(r)}if(i=s._s3,i!=null)try{i.notify(t,e)}catch(r){this._logNotifyError(r)}const n=s._overflow;if(n!=null)for(let r=0,o=n.length;r<o;r++){const c=n[r];if(c!=null)try{c.notify(t,e)}catch(a){this._logNotifyError(a)}}}finally{--this._notifying===0&&s.compact()}}}_logNotifyError(t){console.error(b(t,I,h.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}_isDirty(){const t=this._deps;if(t===null||t.size===0)return!1;const e=this._hotIndex;if(e!==-1){const s=t.getAt(e);if(s!=null&&s.node.version!==s.version)return!0}return this._deepDirtyCheck()}},G=0;function J(){const t=G+1&B;return G=t===0?1:t,G}function W(t){const e=t+1&B;return e===0?1:e}var Z=0,k=!1,_t=0;function vt(){return _t}function ot(){return k?(_&&console.warn("startFlush() called during flush - ignored"),!1):(k=!0,_t=J(),Z=0,!0)}function ut(){k=!1}function Ot(){if(!k)return 0;const t=++Z;if(t<=p.MAX_EXECUTIONS_PER_FLUSH)return t;throw new Error(`[atom-effect] Infinite loop detected: flush execution count exceeded ${p.MAX_EXECUTIONS_PER_FLUSH}`)}var Nt=class{constructor(){this._queueBuffer=[[],[]],this._bufferIndex=0,this._size=0,this._epoch=0,this._isProcessing=!1,this._isFlushingSync=!1,this._batchDepth=0,this._batchQueue=[],this._batchQueueSize=0,this._maxFlushIterations=p.MAX_FLUSH_ITERATIONS,this.onOverflow=null,this._boundRunLoop=this._runLoop.bind(this)}get queueSize(){return this._size+this._batchQueueSize}get isBatching(){return this._batchDepth>0}schedule(t){if(_&&typeof t!="function"&&(!t||typeof t.execute!="function"))throw new w(h.SCHEDULER_CALLBACK_MUST_BE_FUNCTION);const e=this._epoch;if(t._nextEpoch===e)return;if(t._nextEpoch=e,this._batchDepth>0||this._isFlushingSync){this._batchQueue[this._batchQueueSize++]=t;return}const s=this._queueBuffer[this._bufferIndex];s[this._size++]=t,this._isProcessing||this._flush()}_flush(){this._isProcessing||this._size===0||(this._isProcessing=!0,queueMicrotask(this._boundRunLoop))}_runLoop(){try{if(this._size===0&&this._batchQueueSize===0)return;const t=ot();this._drainQueue(),t&&ut()}finally{this._isProcessing=!1}}_flushSync(){if(this._size===0&&this._batchQueueSize===0)return;const t=this._isFlushingSync;this._isFlushingSync=!0;const e=ot();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=t,e&&ut()}}_mergeBatchQueue(){const t=this._batchQueueSize;if(t===0)return;this._epoch=this._epoch+1|0;const e=this._epoch,s=this._batchQueue,i=this._queueBuffer[this._bufferIndex];let n=this._size;for(let r=0;r<t;r++){const o=s[r];o._nextEpoch!==e&&(o._nextEpoch=e,i[n++]=o),s[r]=void 0}this._size=n,this._batchQueueSize=0,s.length>p.BATCH_QUEUE_SHRINK_THRESHOLD&&(s.length=0)}_drainQueue(){let t=0;for(;this._size>0||this._batchQueueSize>0;){if(++t>this._maxFlushIterations){this._handleFlushOverflow();return}this._batchQueueSize>0&&this._mergeBatchQueue(),this._size>0&&this._processQueue()}}_processQueue(){const t=this._bufferIndex,e=this._queueBuffer[t],s=this._size;this._bufferIndex=t^1,this._size=0,this._epoch=this._epoch+1|0;for(let i=0;i<s;i++){const n=e[i];e[i]=void 0;try{typeof n=="function"?n():n.execute()}catch(r){console.error(new w("Error occurred during scheduler execution",r))}}}_handleFlushOverflow(){const t=this._size+this._batchQueueSize;console.error(new w(h.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations,t))),this._size=0,this._queueBuffer[0].length=0,this._queueBuffer[1].length=0,this._batchQueueSize=0,this._batchQueue.length=0;const e=this.onOverflow;if(e)try{e(t)}catch{}}startBatch(){this._batchDepth++}endBatch(){if(this._batchDepth===0){_&&console.warn(h.SCHEDULER_END_BATCH_WITHOUT_START);return}--this._batchDepth===0&&(this._isFlushingSync||this._flushSync())}setMaxFlushIterations(t){if(t<p.MIN_FLUSH_ITERATIONS)throw new w(`Max iterations must be at least ${p.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=t}},v=new Nt;function bt(t){if(_&&typeof t!="function")throw new TypeError(h.BATCH_CALLBACK_MUST_BE_FUNCTION);v.startBatch();try{return t()}finally{v.endBatch()}}var At=class extends K{constructor(t,e){super(),this[M]=C.Atom|C.Writable,this._value=t,this._equal=e.equal??Object.is,e.sync&&(this.flags|=f.SYNC),d.attachDebugInfo(this,"atom",this.id,e.name)}get isNotificationScheduled(){return(this.flags&f.NOTIFICATION_SCHEDULED)!==0}get isSync(){return(this.flags&f.SYNC)!==0}get value(){const t=l.current;return t?.addDependency(this),this._value}set value(t){const e=this._value;if(this._equal(e,t)||(this._value=t,this.version=W(this.version),d.trackUpdate(this.id,d.getDebugName(this)),(this.flags&f.NOTIFICATION_SCHEDULED)!==0))return;const s=this._slots;s==null||s.size===0||(this._pendingOldValue=e,this.flags|=f.NOTIFICATION_SCHEDULED,(this.flags&f.SYNC)!==0&&!v.isBatching?this._notifying===0&&this._flushNotifications():v.schedule(this))}execute(){this._flushNotifications()}_flushNotifications(){const t=f.NOTIFICATION_SCHEDULED,e=f.DISPOSED,s=f.SYNC;for(;(this.flags&(t|e))===t;){const i=this._pendingOldValue;if(this._pendingOldValue=void 0,this.flags&=~t,this._equal(this._value,i)||this._notifySubscribers(this._value,i),(this.flags&s)===0||v.isBatching)break}}peek(){return this._value}dispose(){const t=this.flags;(t&f.DISPOSED)===0&&(this._slots?.clear(),this.flags=t|f.DISPOSED,this._value=void 0,this._pendingOldValue=void 0,this._equal=Object.is)}_deepDirtyCheck(){return!1}[Symbol.dispose](){this.dispose()}};function yt(t,e={}){return new At(t,e)}var{IDLE:D,DIRTY:E,PENDING:O,RESOLVED:g,REJECTED:T,HAS_ERROR:x,RECOMPUTING:y,DISPOSED:X,IS_COMPUTED:R,FORCE_COMPUTE:Q}=Y,Rt=class extends K{constructor(t,e={}){if(typeof t!="function")throw new N(h.COMPUTED_MUST_BE_FUNCTION);if(super(),this[M]=C.Atom|C.Computed,this._error=null,this._promiseId=0,this._deps=new lt,this._trackEpoch=P.UNINITIALIZED,this._trackCount=0,this._value=void 0,this.flags=R|E|D,this._equal=e.equal??Object.is,this._fn=t,this._defaultValue="defaultValue"in e?e.defaultValue:H,this._onError=e.onError??null,d.attachDebugInfo(this,"computed",this.id,e.name),e.lazy===!1)try{this._recompute()}catch{}}get isDirty(){return(this.flags&E)!==0}get isRejected(){return(this.flags&T)!==0}get isRecomputing(){return(this.flags&y)!==0}get _hasErrorInternal(){return(this.flags&x)!==0}_track(){l.current?.addDependency(this)}get value(){const t=l.current;t?.addDependency(this);let e=this.flags;if((e&(g|E|D))===g)return this._value;if((e&X)!==0)throw new N(h.COMPUTED_DISPOSED);if((e&y)!==0){const n=this._defaultValue;if(n!==H)return n;throw new N(h.COMPUTED_CIRCULAR_DEPENDENCY)}if((e&(E|D))!==0){const n=this._deps;if((e&D)===0&&(e&Q)===0&&n.size>0&&!this._isDirty()?e=this.flags&=~E:(this._recompute(),e=this.flags),(e&g)!==0)return this._value}const s=this._defaultValue,i=s!==H;if((e&O)!==0){if(i)return s;throw new N(h.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if((e&T)!==0){if(i)return s;throw this._error}return this._value}peek(){return this._value}get state(){const t=l.current;t?.addDependency(this);const e=this.flags;return(e&g)!==0?F.RESOLVED:(e&O)!==0?F.PENDING:(e&T)!==0?F.REJECTED:F.IDLE}get hasError(){const t=l.current;if(t?.addDependency(this),(this.flags&(T|x))!==0)return!0;const e=this._deps;return e.hasComputeds?L(()=>{const s=e.size;for(let i=0;i<s;i++)if(e.getAt(i)?.node.hasError)return!0;return!1}):!1}get isValid(){return!this.hasError}get errors(){const t=l.current;t?.addDependency(this);const e=this._error,s=this._deps;if(!s.hasComputeds)return e==null?it:Object.freeze([e]);const i=[];return e!=null&&i.push(e),L(()=>{const n=s.size;for(let r=0;r<n;r++){const o=s.getAt(r)?.node;o!=null&&(o.flags&R)!==0&&this._accumulateErrors(o,i)}}),i.length===0?it:Object.freeze(i)}_accumulateErrors(t,e){const s=t._error;s!=null&&!e.includes(s)&&e.push(s);const i=t._deps;if(!i.hasComputeds)return;const n=i.size;for(let r=0;r<n;r++){const o=i.getAt(r)?.node;o!=null&&(o.flags&R)!==0&&this._accumulateErrors(o,e)}}get lastError(){const t=l.current;return t?.addDependency(this),this._error}get isPending(){const t=l.current;return t?.addDependency(this),(this.flags&O)!==0}get isResolved(){const t=l.current;return t?.addDependency(this),(this.flags&g)!==0}invalidate(){this.flags|=Q,this._markDirty()}dispose(){(this.flags&X)===0&&(this._deps.disposeAll(),this._slots!=null&&this._slots.clear(),this.flags=X|E|D,this._error=null,this._value=void 0,this._hotIndex=-1)}[Symbol.dispose](){this.dispose()}addDependency(t){const e=this._trackEpoch;if(t._lastSeenEpoch===e)return;t._lastSeenEpoch=e;const s=this._trackCount++,i=this._deps,n=i.getAt(s);if(n!=null&&n.node===t)n.version=t.version;else if(!i.claimExisting(t,s)){const r=new j(t,t.version,t.subscribe(this));i.insertNew(s,r)}(t.flags&R)!==0&&(i.hasComputeds=!0)}_recompute(){if(this.isRecomputing)return;this.flags=(this.flags|y)&~Q,this._trackEpoch=J(),this._trackCount=0,this._deps.prepareTracking(),this._hotIndex=-1;let t=!1;try{const e=l.run(this,this._fn);this._deps.truncateFrom(this._trackCount),t=!0,$(e)?this._handleAsyncComputation(e):this._finalizeResolution(e)}catch(e){if(!t)try{this._deps.truncateFrom(this._trackCount)}catch(s){_&&console.warn("[atom-effect] _commitDeps failed during error recovery:",s)}this._handleError(e,h.COMPUTED_COMPUTATION_FAILED,!0)}finally{this._trackEpoch=P.UNINITIALIZED,this._trackCount=0,this.flags&=~y}}_handleAsyncComputation(t){this.flags=(this.flags|O)&~(D|E|g|T),this._notifySubscribers(void 0,void 0),this._promiseId=(this._promiseId+1)%at.MAX_PROMISE_ID;const e=this._promiseId;t.then(s=>{if(e===this._promiseId){if(this._isDirty())return this._markDirty();this._finalizeResolution(s),this._notifySubscribers(s,void 0)}},s=>e===this._promiseId&&this._handleError(s,h.COMPUTED_ASYNC_COMPUTATION_FAILED))}_handleError(t,e,s=!1){const i=b(t,N,e);if((!this.isRejected||this._error!==i)&&(this.version=W(this.version)),this._error=i,this.flags=this.flags&~(D|E|O|g)|T|x,this._onError)try{this._onError(i)}catch(n){console.error(h.CALLBACK_ERROR_IN_ERROR_HANDLER,n)}if(this._notifySubscribers(void 0,void 0),s)throw i}_finalizeResolution(t){const e=this.flags;((e&g)===0||!this._equal(this._value,t))&&(this.version=W(this.version)),this._value=t,this._error=null,this.flags=(e|g)&~(D|E|O|T|x)}execute(){this._markDirty()}_markDirty(){const t=this.flags;(t&(y|E))===0&&(this.flags=t|E,d.trackUpdate(this.id,d.getDebugName(this)),this._notifySubscribers(void 0,void 0))}_deepDirtyCheck(){const t=this._deps;return L(()=>{const e=t.size;for(let s=0;s<e;s++){const i=t.getAt(s);if(i==null)continue;const n=i.node;if((n.flags&R)!==0)try{n.value}catch{_&&console.warn(`[atom-effect] Dependency #${n.id} threw during dirty check`)}if(n.version!==i.version)return this._hotIndex=s,!0}return this._hotIndex=-1,!1})}};function Ft(t,e={}){return new Rt(t,e)}var wt=class extends K{constructor(t,e={}){super(),this[M]=C.Effect,this._cleanup=null,this._deps=new lt,this._currentEpoch=P.UNINITIALIZED,this._lastFlushEpoch=P.UNINITIALIZED,this._fn=t,this._onError=e.onError??null,this._sync=e.sync??!1,this._maxExecutions=e.maxExecutionsPerSecond??p.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=e.maxExecutionsPerFlush??p.MAX_EXECUTIONS_PER_EFFECT,this._executionsInEpoch=0,this._executionCount=0,this._windowStart=0,this._windowCount=0,this._execId=0,this._trackCount=0,this._sync?this._notifyCallback=()=>this.execute():this._notifyCallback=()=>v.schedule(this),d.attachDebugInfo(this,"effect",this.id,e.name)}run(){if(this.isDisposed)throw new S(h.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.isDisposed||(this.flags|=m.DISPOSED,this._execCleanup(),this._deps?.disposeAll())}[Symbol.dispose](){this.dispose()}addDependency(t){if((this.flags&m.EXECUTING)===0)return;const e=this._currentEpoch;if(t._lastSeenEpoch===e)return;t._lastSeenEpoch=e;const s=this._trackCount++,i=this._deps;let n;switch(s){case 0:n=i._s0;break;case 1:n=i._s1;break;case 2:n=i._s2;break;case 3:n=i._s3;break;default:n=i.getAt(s)}n!=null&&n.node===t?n.version=t.version:i.claimExisting(t,s)||this._insertNewDependency(t,s),t.isComputed&&(i.hasComputeds=!0)}_insertNewDependency(t,e){let s;try{const i=t.subscribe(this._notifyCallback);s=new j(t,t.version,i)}catch(i){const n=b(i,S,h.EFFECT_EXECUTION_FAILED);if(console.error(n),this._onError)try{this._onError(n)}catch{}s=new j(t,t.version,void 0)}this._deps.insertNew(e,s)}execute(t=!1){const e=this.flags;if((e&(m.DISPOSED|m.EXECUTING))!==0)return;const s=this._deps;if(!t&&s.size>0&&!this._isDirty())return;this._checkInfiniteLoops(),d.trackUpdate(this.id,d.getDebugName(this)),this.flags=e|m.EXECUTING,this._execCleanup(),this._currentEpoch=J(),this._trackCount=0,s.prepareTracking(),this._hotIndex=-1;let i=!1;try{const n=l.run(this,this._fn);s.truncateFrom(this._trackCount),i=!0,$(n)?this._handleAsyncResult(n):this._cleanup=typeof n=="function"?n:null}catch(n){if(!i)try{s.truncateFrom(this._trackCount)}catch(r){_&&console.warn("[atom-effect] _commitDeps failed during error recovery:",r)}this._handleExecutionError(n),this._cleanup=null}finally{this.flags&=~m.EXECUTING}}_handleAsyncResult(t){const e=++this._execId;t.then(s=>{if(e!==this._execId||this.isDisposed){if(typeof s=="function")try{s()}catch(i){this._handleExecutionError(i,h.EFFECT_CLEANUP_FAILED)}return}typeof s=="function"&&(this._cleanup=s)},s=>e===this._execId&&this._handleExecutionError(s))}_deepDirtyCheck(){const t=l.current;l.current=null;const e=this._deps;try{const s=e.size;for(let i=0;i<s;i++){const n=e.getAt(i);if(n==null)continue;const r=n.node;if(r.isComputed&&this._tryPullComputed(r),r.version!==n.version)return this._hotIndex=i,!0}return!1}finally{l.current=t}}_tryPullComputed(t){try{t.value}catch{_&&console.warn(`[atom-effect] Dependency #${t.id} threw during dirty check`)}}_execCleanup(){const t=this._cleanup;if(t!=null){this._cleanup=null;try{t()}catch(e){this._handleExecutionError(e,h.EFFECT_CLEANUP_FAILED)}}}_checkInfiniteLoops(){const t=vt();this._lastFlushEpoch!==t&&(this._lastFlushEpoch=t,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError("per-effect"),Ot()>p.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError("global"),this._executionCount++,_&&this._checkFrequencyLimit()}_checkFrequencyLimit(){if(!Number.isFinite(this._maxExecutions))return;const t=Date.now();if(t-this._windowStart>=z.EFFECT_FREQUENCY_WINDOW){this._windowStart=t,this._windowCount=1;return}if(++this._windowCount>this._maxExecutions){const e=new S(h.EFFECT_FREQUENCY_LIMIT_EXCEEDED);throw this.dispose(),this._handleExecutionError(e),e}}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&m.EXECUTING)!==0}_throwInfiniteLoopError(t){const e=new S(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Z}`);throw this.dispose(),console.error(e),e}_handleExecutionError(t,e=h.EFFECT_EXECUTION_FAILED){const s=b(t,S,e);if(console.error(s),this._onError)try{this._onError(s)}catch(i){console.error(b(i,S,h.CALLBACK_ERROR_IN_ERROR_HANDLER))}}};function Ut(t,e={}){if(typeof t!="function")throw new S(h.EFFECT_MUST_BE_FUNCTION);const s=new wt(t,e);return s.execute(),s}function tt(t,e,s,i){if(s===e.length)return i;const n=e[s],r=t!=null&&typeof t=="object"?t:{},o=r[n],c=tt(o,e,s+1,i);if(Object.is(o,c))return t;if(Array.isArray(r)){const a=r.slice(),A=Number.parseInt(n,10);return Number.isNaN(A)?a[n]=c:a[A]=c,a}return{...r,[n]:c}}function U(t,e){let s=t;const i=e.length;for(let n=0;n<i;n++){if(s==null)return;s=s[e[n]]}return s}function et(t,e){const s=e.includes(".")?e.split("."):[e],i=new Set,n=()=>{i.forEach(r=>r()),i.clear()};return{get value(){return U(t.value,s)},set value(r){const o=t.peek(),c=tt(o,s,0,r);c!==o&&(t.value=c)},peek:()=>U(t.peek(),s),subscribe(r){const o=t.subscribe((c,a)=>{const A=U(c,s),st=U(a,s);Object.is(A,st)||r(A,st)});return i.add(o),()=>{o(),i.delete(o)}},subscriberCount:()=>i.size,dispose:n,[Symbol.dispose]:n,[M]:C.Atom|C.Writable}}var Lt=(t,e)=>et(t,e),Pt=t=>e=>et(t,e);exports.AsyncState=F;exports.AtomError=I;exports.ComputedError=N;exports.DEBUG_CONFIG=z;exports.EffectError=S;exports.SCHEDULER_CONFIG=p;exports.SchedulerError=w;exports.atom=yt;exports.atomLens=et;exports.batch=bt;exports.composeLens=Lt;exports.computed=Ft;exports.effect=Ut;exports.getPathValue=U;exports.globalScheduler=v;exports.isAtom=gt;exports.isComputed=Dt;exports.isEffect=St;exports.lensFor=Pt;exports.runtimeDebug=d;exports.setDeepValue=tt;exports.untracked=L;
|
|
2
2
|
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|