@but212/atom-effect-jquery 0.23.0 → 0.24.1

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/README.md CHANGED
@@ -17,7 +17,10 @@ npm install @but212/atom-effect-jquery jquery
17
17
  ### CDN
18
18
 
19
19
  ```html
20
- <script src="https://cdn.jsdelivr.net/npm/@but212/atom-effect-jquery@0.23.0"></script>
20
+ <!-- jquery -->
21
+ <script src="https://code.jquery.com/jquery-4.0.0.min.js"></script>
22
+ <!-- atom-effect-jquery -->
23
+ <script src="https://cdn.jsdelivr.net/npm/@but212/atom-effect-jquery@0.24.1"></script>
21
24
  ```
22
25
 
23
26
  ### Usage
@@ -1,3 +1,3 @@
1
- (function(N,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("jquery")):typeof define=="function"&&define.amd?define(["exports","jquery"],l):(N=typeof globalThis<"u"?globalThis:N||self,l(N.AtomEffectJQuery={},N.jQuery))})(this,(function(N,l){"use strict";const at={IDLE:"idle",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"},P={DISPOSED:1,EXECUTING:8},Ft={DISPOSED:1,IS_COMPUTED:2,DIRTY:8,IDLE:16,PENDING:32,RESOLVED:64,REJECTED:128,RECOMPUTING:256,HAS_ERROR:512},B={DISPOSED:1,SYNC:8,NOTIFICATION_SCHEDULED:16},$={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},Se={WARN_INFINITE_LOOP:!0},Bt={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:Number.MAX_SAFE_INTEGER-1},K={UNINITIALIZED:-1},lt=1073741823,Ne=typeof process<"u"&&process.env&&!1||!1,be=Object.freeze([]);function Gt(n,t,e){const s=new Map;for(let i=0;i<t.length;i++){const o=t[i];o?.unsub&&s.set(o.node,o.unsub)}for(let i=0;i<n.length;i++){const o=n[i];if(!o)continue;const r=o.node,c=s.get(r);c!==void 0?(o.unsub=c,s.delete(r)):o.unsub||(o.unsub=r.subscribe(e))}for(const i of s.values())i()}class ht{constructor(t,e,s=void 0){this.node=t,this.version=e,this.unsub=s}}class Re{constructor(t,e){this.fn=t,this.sub=e}notify(t,e){this.fn?this.fn(t,e):this.sub&&this.sub.execute()}}class q extends Error{constructor(t,e=null,s=!0){super(t),this.cause=e,this.recoverable=s,this.name="AtomError"}}class X extends q{constructor(t,e=null){super(t,e,!0),this.name="ComputedError"}}class Q extends q{constructor(t,e=null){super(t,e,!1),this.name="EffectError"}}class Tt extends q{constructor(t,e=null){super(t,e,!1),this.name="SchedulerError"}}const v={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:(n,t)=>`Maximum flush iterations (${n}) exceeded. ${t} 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"},ve=Symbol("AtomEffect.DebugName"),De=Symbol("AtomEffect.Type"),St=Symbol("AtomEffect.NoDefaultValue"),Nt={enabled:Ne,warnInfiniteLoop:Se.WARN_INFINITE_LOOP,warn(n,t){},attachDebugInfo(n,t,e){},getDebugName:n=>n?.[ve],getDebugType:n=>n?.[De]};let Oe=1;const Le=()=>Oe++;function Y(n,t,e){if(n instanceof q)return n;const s=n instanceof Error,i=s?n.message:String(n),o=s?n:void 0,r=`${s?n.constructor.name:"Unexpected error"} (${e}): ${i}`;return new t(r,o)}class Ht{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=K.UNINITIALIZED,this.id=Le()&lt}}class jt extends Ht{constructor(){super(...arguments),this._notifying=0}subscribe(t){const e=typeof t=="function";if(!e&&(!t||typeof t.execute!="function"))throw Y(new TypeError("Invalid subscriber"),q,v.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);const s=this._subscribers,i=s.length;let o=!1;for(let c=0;c<i;c++){const a=s[c];if(a!=null&&(e?a.fn===t:a.sub===t)){o=!0;break}}if(o)return()=>{};const r=new Re(e?t:void 0,e?void 0:t);return s.push(r),()=>this._unsubscribe(r)}_unsubscribe(t){const e=this._subscribers;let s=-1;for(let o=0;o<e.length;o++)if(e[o]===t){s=o;break}if(s===-1)return;if(this._notifying>0){e[s]=null;return}const i=e.pop();s<e.length&&i!==void 0&&(e[s]=i)}subscriberCount(){let t=0;const e=this._subscribers;for(let s=0;s<e.length;s++)e[s]!=null&&t++;return t}_notifySubscribers(t,e){const s=this._subscribers,i=s.length;if(i!==0){this._notifying++;try{for(let o=0;o<i;o++){const r=s[o];if(r!=null)try{r.notify(t,e)}catch(c){this._handleNotifyError(c)}}}finally{this._notifying--,this._notifying===0&&this._cleanupTombstones()}}}_cleanupTombstones(){const t=this._subscribers;let e=0;for(;e<t.length;)if(t[e]===null){const s=t.pop();e<t.length&&s!==void 0&&(t[e]=s)}else e++}_handleNotifyError(t){console.error(Y(t,q,v.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}}let bt=0;const Rt=()=>(bt=bt+1&lt||1,bt),vt=n=>n+1&lt;let Dt=0,ut=!1,$t=0;const Vt=()=>$t;function zt(){return ut?!1:(ut=!0,$t=Rt(),Dt=0,!0)}const Kt=()=>{ut=!1},ke=()=>ut?++Dt:0;class Ae{constructor(){this._queueBuffer=[[],[]],this._bufferIndex=0,this._size=0,this._epoch=0,this._isProcessing=!1,this._isBatching=!1,this._isFlushingSync=!1,this._batchDepth=0,this._batchQueue=[],this._batchQueueSize=0,this._maxFlushIterations=$.MAX_FLUSH_ITERATIONS,this.onOverflow=null,this._boundRunLoop=this._runLoop.bind(this)}get phase(){return this._isProcessing||this._isFlushingSync?2:this._isBatching?1:0}get queueSize(){return this._size}get isBatching(){return this._isBatching}schedule(t){if(t._nextEpoch!==this._epoch){if(t._nextEpoch=this._epoch,this._isBatching||this._isFlushingSync){this._batchQueue[this._batchQueueSize++]=t;return}this._queueBuffer[this._bufferIndex][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=zt();this._drainQueue(),t&&Kt()}finally{this._isProcessing=!1,this._size>0&&!this._isBatching&&this._flush()}}_flushSync(){this._isFlushingSync=!0;const t=zt();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,t&&Kt()}}_mergeBatchQueue(){if(this._batchQueueSize===0)return;const t=++this._epoch,e=this._batchQueue,s=this._queueBuffer[this._bufferIndex];let i=this._size;e.slice(0,this._batchQueueSize).forEach(o=>{o._nextEpoch!==t&&(o._nextEpoch=t,s[i++]=o)}),this._size=i,this._batchQueueSize=0,e.length>$.BATCH_QUEUE_SHRINK_THRESHOLD&&(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,e=this._queueBuffer[t],s=this._size;this._bufferIndex=t^1,this._size=0,this._epoch++;for(let i=0;i<s;i++)try{const o=e[i];typeof o=="function"?o():o.execute()}catch(o){console.error(new Tt("Error occurred during scheduler execution",o))}e.length=0}_handleFlushOverflow(){const t=this._size+this._batchQueueSize;if(console.error(new Tt(v.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations,t))),this._size=0,this._queueBuffer[this._bufferIndex].length=0,this._batchQueueSize=0,this.onOverflow)try{this.onOverflow(t)}catch{}}startBatch(){this._batchDepth++,this._isBatching=!0}endBatch(){this._batchDepth!==0&&--this._batchDepth===0&&(this._flushSync(),this._isBatching=!1)}setMaxFlushIterations(t){if(t<$.MIN_FLUSH_ITERATIONS)throw new Tt(`Max flush iterations must be at least ${$.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=t}}const tt=new Ae,Ot=Symbol.for("atom-effect/atom"),qt=Symbol.for("atom-effect/computed"),Ue=Symbol.for("atom-effect/effect"),we=Symbol.for("atom-effect/writable"),x={current:null,run(n,t){const e=this.current;this.current=n;try{return t()}finally{this.current=e}}};function M(n){const t=x.current;if(t===null)return n();x.current=null;try{return n()}finally{x.current=t}}var Xt,Qt;class Pe extends jt{constructor(t,e){super(),this._pendingOldValue=void 0,this._subscribers=[],this[Qt]=!0,this[Xt]=!0,this._value=t,e&&(this.flags|=B.SYNC),Nt.attachDebugInfo(this,"atom",this.id)}get value(){return x.current?.addDependency(this),this._value}set value(t){const e=this._value;if(Object.is(e,t))return;this._value=t,this.version=vt(this.version);const s=this.flags;if(!(this._subscribers.length===0||s&B.NOTIFICATION_SCHEDULED)){if(this._pendingOldValue=e,this.flags=s|B.NOTIFICATION_SCHEDULED,s&B.SYNC&&!tt.isBatching){this._flushNotifications();return}tt.schedule(this)}}execute(){this._flushNotifications()}_flushNotifications(){const t=this.flags;if(!(t&B.NOTIFICATION_SCHEDULED)||t&B.DISPOSED)return;const e=this._pendingOldValue;this._pendingOldValue=void 0,this.flags&=-17,this._notifySubscribers(this._value,e)}peek(){return this._value}dispose(){this.flags&B.DISPOSED||(this._subscribers.length=0,this.flags|=B.DISPOSED,this._value=void 0,this._pendingOldValue=void 0)}[(Qt=Ot,Xt=we,Symbol.dispose)](){this.dispose()}}function ft(n,t={}){return new Pe(n,t.sync??!1)}class xe{constructor(t=50,e=256,s=!1){this.limit=t,this.capacity=e,this.pool=[],this.stats=null,this.stats=s?{acquired:0,released:0,rejected:{frozen:0,tooLarge:0,poolFull:0}}:null}acquire(){return this.stats&&this.stats.acquired++,this.pool.pop()??[]}release(t,e){if(!(e&&t===e)){if(t.length>this.capacity){this.stats&&this.stats.rejected.tooLarge++;return}if(this.pool.length>=this.limit){this.stats&&this.stats.rejected.poolFull++;return}if(Object.isFrozen(t)){this.stats&&this.stats.rejected.frozen++;return}t.length=0,this.pool.push(t),this.stats&&this.stats.released++}}getStats(){if(!this.stats)return null;const{acquired:t,released:e,rejected:s}=this.stats,i=t-e-(s.frozen+s.tooLarge+s.poolFull);return{acquired:t,released:e,rejected:{...s},leaked:i,poolSize:this.pool.length}}reset(){this.pool.length=0,this.stats&&(this.stats={acquired:0,released:0,rejected:{frozen:0,tooLarge:0,poolFull:0}})}}const O=Object.freeze([]),G=new xe;function dt(n){return n!==null&&typeof n=="object"&&Ot in n}function Yt(n){return n!==null&&typeof n=="object"&&qt in n}function Wt(n){return n!==null&&typeof n=="object"&&typeof n.then=="function"}var Zt,Jt;const{IDLE:_t,DIRTY:W,PENDING:pt,RESOLVED:V,REJECTED:et,HAS_ERROR:Et,RECOMPUTING:st,DISPOSED:Lt,IS_COMPUTED:Me}=Ft;function Fe(n){return n&V?at.RESOLVED:n&pt?at.PENDING:n&et?at.REJECTED:at.IDLE}class Be extends jt{constructor(t,e={}){if(typeof t!="function")throw new X(v.COMPUTED_MUST_BE_FUNCTION);super(),this[Jt]=!0,this[Zt]=!0,this._error=null,this._promiseId=0,this._subscribers=[],this._links=O,this._asyncStartAggregateVersion=0,this._asyncRetryCount=0,this._lastDriftEpoch=K.UNINITIALIZED,this._trackEpoch=K.UNINITIALIZED,this._trackLinks=O,this._trackCount=0,this._value=void 0,this.flags=Me|W|_t,this._equal=e.equal??Object.is,this._fn=t,this._defaultValue="defaultValue"in e?e.defaultValue:St,this._onError=e.onError??null;const s=e.maxAsyncRetries;if(this._maxAsyncRetries=(s??Bt.MAX_ASYNC_RETRIES)&lt,Nt.attachDebugInfo(this,"computed",this.id),e.lazy===!1)try{this._recompute()}catch{}}_track(){x.current?.addDependency(this)}get value(){this._track();const t=this.flags;if((t&(V|W|_t))===V)return this._value;if(t&Lt)throw new X(v.COMPUTED_DISPOSED);if(t&st){if(this._defaultValue!==St)return this._defaultValue;throw new X(v.COMPUTED_CIRCULAR_DEPENDENCY)}if(t&(W|_t)&&(this._recompute(),this.flags&V))return this._value;const e=this._defaultValue,s=e!==St;if(this.flags&pt){if(s)return e;throw new X(v.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if(this.flags&et){if(s)return e;throw this._error}return this._value}peek(){return this._value}get state(){return this._track(),Fe(this.flags)}get hasError(){return this._track(),this.flags&(et|Et)?!0:this._links.some(t=>t?.node?.flags&Et)}get isValid(){return!this.hasError}get errors(){if(this._track(),!this.hasError)return be;const t=[];return this._error&&t.push(this._error),this._links.forEach(e=>{const s=e.node;s.flags&Et&&s.errors.forEach(i=>{i&&!t.includes(i)&&t.push(i)})}),Object.freeze(t)}get lastError(){return this._track(),this._error}get isPending(){return this._track(),(this.flags&pt)!==0}get isResolved(){return this._track(),(this.flags&V)!==0}invalidate(){this._markDirty()}dispose(){if(this.flags&Lt)return;const t=this._links;t!==O&&(t.forEach(e=>e.unsub?.()),G.release(t),this._links=O),this._subscribers.length=0,this.flags=Lt|W|_t,this._error=null,this._value=void 0}[(Jt=Ot,Zt=qt,Symbol.dispose)](){this.dispose()}addDependency(t){if(t._lastSeenEpoch!==this._trackEpoch){if(t._lastSeenEpoch=this._trackEpoch,this._trackLinks===this._links&&this._trackCount<this._links.length&&this._links[this._trackCount].node===t){this._links[this._trackCount].version=t.version,this._trackCount++;return}if(this._trackLinks===this._links){const e=G.acquire();for(let s=0;s<this._trackCount;s++)e[s]=this._links[s];this._trackLinks=e}this._trackCount<this._trackLinks.length?this._trackLinks[this._trackCount]=new ht(t,t.version):this._trackLinks.push(new ht(t,t.version)),this._trackCount++}}_recompute(){if(this.flags&st)return;this.flags|=st;const t=this._links;this._trackEpoch=Rt(),this._trackLinks=t,this._trackCount=0;let e=!1;try{const s=x.run(this,this._fn);if(this._trackLinks===t)if(this._trackCount===t.length)e=!0;else{for(let i=this._trackCount;i<t.length;i++)t[i].unsub?.();t.length=this._trackCount,e=!0}else this._trackLinks.length=this._trackCount,Gt(this._trackLinks,t,this),this._links=this._trackLinks,e=!0;Wt(s)?this._handleAsyncComputation(s):this._finalizeResolution(s)}catch(s){if(!e)try{if(this._trackLinks===t){for(let i=this._trackCount;i<t.length;i++)t[i].unsub?.();t.length=this._trackCount,e=!0}else this._trackLinks.length=this._trackCount,Gt(this._trackLinks,t,this),this._links=this._trackLinks,e=!0}catch{}this._handleError(s,v.COMPUTED_COMPUTATION_FAILED,!0)}finally{e?this._links!==t&&t!==O&&G.release(t):this._trackLinks!==t&&this._trackLinks!==O&&G.release(this._trackLinks),this._trackEpoch=K.UNINITIALIZED,this._trackLinks=O,this._trackCount=0,this.flags&=~st}}_handleAsyncComputation(t){this.flags=(this.flags|pt)&-217,this._notifySubscribers(void 0,void 0),this._asyncStartAggregateVersion=this._captureVersionSnapshot(),this._asyncRetryCount=0,this._promiseId=(this._promiseId+1)%Bt.MAX_PROMISE_ID;const e=this._promiseId;t.then(s=>{if(e===this._promiseId){if(this._captureVersionSnapshot()!==this._asyncStartAggregateVersion){const i=Vt();return this._lastDriftEpoch!==i&&(this._lastDriftEpoch=i,this._asyncRetryCount=0),this._asyncRetryCount++<this._maxAsyncRetries?this._markDirty():this._handleError(new X(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`),v.COMPUTED_ASYNC_COMPUTATION_FAILED)}this._finalizeResolution(s),this._notifySubscribers(s,void 0)}},s=>e===this._promiseId&&this._handleError(s,v.COMPUTED_ASYNC_COMPUTATION_FAILED))}_captureVersionSnapshot(){let t=0;const e=this._links;for(let s=0,i=e.length;s<i;s++)t=(t<<5)-t+e[s].node.version|0;return t}_handleError(t,e,s=!1){const i=Y(t,X,e);if(!s&&!(this.flags&et)&&(this.version=vt(this.version)),this._error=i,this.flags=this.flags&-121|et|Et,this._onError)try{this._onError(i)}catch(o){console.error(v.CALLBACK_ERROR_IN_ERROR_HANDLER,o)}if(s)throw i;this._notifySubscribers(void 0,void 0)}_finalizeResolution(t){(!(this.flags&V)||!this._equal(this._value,t))&&(this.version=vt(this.version)),this._value=t,this._error=null,this.flags=(this.flags|V)&-697}execute(){this._markDirty()}_markDirty(){this.flags&(st|W)||(this.flags|=W,this._notifySubscribers(void 0,void 0))}}function nt(n,t={}){return new Be(n,t)}var te;class Ge extends Ht{constructor(t,e={}){super(),this[te]=!0,this._cleanup=null,this._links=O,this._nextLinks=null,this._prevLinks=O,this._currentEpoch=K.UNINITIALIZED,this._lastFlushEpoch=K.UNINITIALIZED,this._executionsInEpoch=0,this._executionCount=0,this._windowStart=0,this._windowCount=0,this._execId=0,this._trackCount=0,this._fn=t,this._onError=e.onError??null,this._sync=e.sync??!1,this._maxExecutions=e.maxExecutionsPerSecond??$.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=e.maxExecutionsPerFlush??$.MAX_EXECUTIONS_PER_EFFECT,this._sync?this._notifyCallback=()=>this.execute():this._notifyCallback=()=>tt.schedule(this),Nt.attachDebugInfo(this,"effect",this.id)}run(){if(this.flags&P.DISPOSED)throw new Q(v.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.flags&P.DISPOSED||(this.flags|=P.DISPOSED,this._execCleanup(),this._unsubLinks(this._links),this._links!==O&&G.release(this._links),this._links=O,this._prevLinks=O)}[(te=Ue,Symbol.dispose)](){this.dispose()}addDependency(t){if(!(this.flags&P.EXECUTING))return;const e=this._currentEpoch;if(t._lastSeenEpoch===e)return;t._lastSeenEpoch=e;const s=this._prevLinks;if(this._nextLinks===s&&this._trackCount<s.length&&s[this._trackCount].node===t){s[this._trackCount].version=t.version,this._trackCount++;return}if(this._nextLinks===s){const r=G.acquire();for(let c=0;c<this._trackCount;c++)r[c]=s[c];this._nextLinks=r}const i=this._nextLinks;let o=-1;for(let r=this._trackCount;r<s.length;r++){const c=s[r];if(c&&c.node===t&&c.unsub){o=r;break}}if(o!==-1){const r=s[o];r.version=t.version,i[this._trackCount]=r,s[o]=null}else try{const r=t.subscribe(this._notifyCallback);i[this._trackCount]=new ht(t,t.version,r)}catch(r){const c=Y(r,Q,v.EFFECT_EXECUTION_FAILED);if(console.error(c),this._onError)try{this._onError(c)}catch{}i[this._trackCount]=new ht(t,t.version,void 0)}this._trackCount++}execute(t=!1){if(this.flags&(P.DISPOSED|P.EXECUTING)||!t&&this._links.length>0&&!this._isDirty())return;this._checkInfiniteLoops(),this.flags|=P.EXECUTING,this._execCleanup(),this._prevLinks=this._links,this._nextLinks=this._links,this._currentEpoch=Rt(),this._trackCount=0;let e=!1;try{const s=x.run(this,this._fn);if(this._nextLinks===this._prevLinks)if(this._trackCount===this._prevLinks.length)e=!0;else{for(let i=this._trackCount;i<this._prevLinks.length;i++)this._prevLinks[i]?.unsub?.();this._prevLinks.length=this._trackCount,e=!0}else this._nextLinks.length=this._trackCount,e=!0;this._links=this._nextLinks,Wt(s)?this._handleAsyncResult(s):this._cleanup=typeof s=="function"?s:null}catch(s){if(!e)if(this._nextLinks===this._prevLinks){for(let i=this._trackCount;i<this._prevLinks.length;i++)this._prevLinks[i]?.unsub?.();this._prevLinks.length=this._trackCount,e=!0}else this._nextLinks.length=this._trackCount,e=!0;this._links=this._nextLinks,this._handleExecutionError(s),this._cleanup=null}finally{this._finalizeDependencies(e,this._prevLinks,this._nextLinks),this.flags&=-9}}_handleAsyncResult(t){const e=++this._execId;t.then(s=>{if(e!==this._execId||this.flags&P.DISPOSED){if(typeof s=="function")try{s()}catch(i){this._handleExecutionError(i,v.EFFECT_CLEANUP_FAILED)}return}typeof s=="function"&&(this._cleanup=s)},s=>e===this._execId&&this._handleExecutionError(s))}_finalizeDependencies(t,e,s){this._nextLinks=null,this._prevLinks=O,t?s!==e&&e!==O&&(e.forEach(i=>i?.unsub?.()),G.release(e)):s!==e&&s!==O&&s&&(this._unsubLinks(s),G.release(s))}_unsubLinks(t){t.forEach(e=>e?.unsub?.())}_isDirty(){const t=this._links,e=x.current;x.current=null;try{return t.some(s=>{const i=s.node;if(i.flags&Ft.IS_COMPUTED)try{i.value}catch{return!0}return i.version!==s.version})}finally{x.current=e}}_execCleanup(){if(this._cleanup){try{this._cleanup()}catch(t){this._handleExecutionError(t,v.EFFECT_CLEANUP_FAILED)}this._cleanup=null}}_checkInfiniteLoops(){const t=Vt();this._lastFlushEpoch!==t&&(this._lastFlushEpoch=t,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError("per-effect"),ke()>$.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError("global"),this._executionCount++}get isDisposed(){return(this.flags&P.DISPOSED)!==0}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&P.EXECUTING)!==0}_throwInfiniteLoopError(t){const e=new Q(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Dt}`);throw this.dispose(),console.error(e),e}_handleExecutionError(t,e=v.EFFECT_EXECUTION_FAILED){const s=Y(t,Q,e);if(console.error(s),this._onError)try{this._onError(s)}catch(i){console.error(Y(i,Q,v.CALLBACK_ERROR_IN_ERROR_HANDLER))}}}function H(n,t={}){if(typeof n!="function")throw new Q(v.EFFECT_MUST_BE_FUNCTION);const e=new Ge(n,t);return e.execute(),e}function kt(n){if(typeof n!="function")throw new TypeError(v.BATCH_CALLBACK_MUST_BE_FUNCTION);tt.startBatch();try{return n()}finally{tt.endBatch()}}const p={ROUTE:"[atom-route]",BINDING:"[atom-binding]",LIST:"[atom-list]",MOUNT:"[atom-mount]"},it=Object.freeze({mode:"hash",basePath:"",autoBindLinks:!1,activeClass:"active"}),He={EVENT:"input"},ee={HIGHLIGHT_DURATION_MS:500},je=new Set(["input","select","textarea"]),$e=new Set(["src","href","action","formaction","data","poster","background","cite","longdesc","profile","usemap","classid","codebase","xlink:href"]),Ve=new Set(["innerHTML","outerHTML","srcdoc","__proto__","constructor","prototype"]),S={ROUTE:{NOT_FOUND:n=>`Route "${n}" not found and no notFound route configured`,TEMPLATE_NOT_FOUND:n=>`Template "${n}" not found`,TARGET_NOT_FOUND:n=>`Target element "${n}" not found`,MALFORMED_URI:n=>`Malformed URI component: ${n}`},SECURITY:{UNSAFE_CONTENT:()=>"Unsafe content neutralized during sanitization.",BLOCKED_CSS_VALUE:n=>`Blocked dangerous value in CSS style property "${n}".`,BLOCKED_EVENT_HANDLER:n=>`Blocked setting dangerous event handler attribute/property "${n}".`,BLOCKED_PROTOCOL:n=>`Blocked dangerous protocol in "${n}".`,BLOCKED_PROP:n=>`Blocked setting dangerous property "${n}". Use html binding for sanitized HTML.`},BINDING:{INVALID_INPUT_ELEMENT:n=>`Val binding used on non-input element <${n}>.`,MISSING_SOURCE:n=>`[${n}] source is required when prop/name is a string.`,MISSING_CONDITION:n=>`[${n}] condition is required when className is a string.`,UPDATER_ERROR:(n,t)=>`Updater threw in binding "${n}"${t?" (static)":""}`,CLEANUP_ERROR:n=>`Binding cleanup error${n?`: ${n}`:""}`,PARSE_ERROR:n=>`parse() threw during DOM→Atom sync${n?`: ${n}`:""}`},LIST:{DUPLICATE_KEY:(n,t,e)=>`Duplicate key "${n}" at index ${t} in atomList <${e}>.`},MOUNT:{ERROR:n=>`Mount error${n?` in component <${n}>`:""}`,CLEANUP_ERROR:n=>`Cleanup error${n?` in component <${n}>`:""}`},CORE:{EFFECT_DISPOSE_ERROR:n=>`Effect dispose error${n?`: ${n}`:""}`}};function At(n){return dt(n)}function Z(n){const t=n.tagName.toLowerCase();if(n.id)return`${t}#${n.id}`;const e=n.classList,s=e.length;if(s===0)return t;let i=t;for(let o=0;o<s;o++)i+=`.${e[o]}`;return i}const J=Object.prototype.hasOwnProperty;function ze(n,t){if(n===t)return!0;if(n===null||t===null||typeof n!="object"||typeof t!="object")return!1;const e=Object.keys(n),s=Object.keys(t);if(e.length!==s.length)return!1;const i=n,o=t;for(let r=0;r<e.length;r++){const c=e[r];if(!J.call(o,c)||i[c]!==o[c])return!1}return!0}function Ke(n){const t=n.length;if(t===0)return new Int32Array(0);const e=new Int32Array(t).fill(-1),s=new Int32Array(t);let i=0;for(let r=0;r<t;r++){const c=n[r];if(c===void 0||c===-1)continue;const a=i>0?s[i-1]:void 0;if(i===0||a!==void 0&&(n[a]??-1)<c){e[r]=a??-1,s[i++]=r;continue}let h=0,u=i-1;for(;h<u;){const y=h+u>>>1,E=s[y];E!==void 0&&(n[E]??-1)<c?h=y+1:u=y}const _=s[h];_!==void 0&&c<(n[_]??Number.MAX_SAFE_INTEGER)&&(h>0&&(e[r]=s[h-1]??-1),s[h]=r)}const o=new Int32Array(i);if(i>0){let r=s[i-1];for(let c=i-1;c>=0&&r!==void 0&&r!==-1;c--)o[c]=r,r=e[r]}return o}const qe={BASE_URL:"/",DEV:!1,MODE:"production",PROD:!0,SSR:!1},Xe=`${ee.HIGHLIGHT_DURATION_MS/1e3}s`;function Qe(){if(typeof window<"u"){const n=window.__ATOM_DEBUG__;if(typeof n=="boolean")return n}try{if(qe?.VITE_ATOM_DEBUG==="true")return!0}catch{}try{if(globalThis.process?.env?.VITE_ATOM_DEBUG==="true")return!0}catch{}return!1}let se=Qe();const d={get enabled(){if(typeof window<"u"){const n=window.__ATOM_DEBUG__;if(typeof n=="boolean")return n}return se},set enabled(n){se=n},log(n,...t){this.enabled&&console.log(`${n}`,...t)},atomChanged(n,t,e,s){this.enabled&&console.log(`${n} Atom "${t??"anonymous"}" changed:`,e,"→",s)},domUpdated(n,t,e,s){if(!this.enabled)return;const i=t instanceof Element?t:t[0];i&&(console.log(`${n} DOM updated: ${Z(i)}.${e} =`,s),We(i))},cleanup(n,t){this.enabled&&console.log(`${n} Cleanup: ${t}`)},warn(n,t,...e){console.warn(`${n} ${t}`,...e)},error(n,t,e){console.error(`${n} ${t}`,e)}},Ut="atom-debug-highlight",ne="data-atom-debug";let ot;function Ye(){if((ot instanceof HTMLStyleElement?ot:ot?.deref())?.isConnected||document.querySelector(`style[${ne}]`))return;const t=document.createElement("style");t.setAttribute(ne,""),t.textContent=`.${Ut}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Xe} ease-out}`,document.head.appendChild(t),typeof WeakRef<"u"?ot=new WeakRef(t):ot=t}const wt=new WeakMap,Pt=new WeakMap;function We(n){if(!d.enabled||!n.isConnected)return;Ye();const t=Pt.get(n);t!==void 0&&cancelAnimationFrame(t);const e=wt.get(n);e!==void 0&&clearTimeout(e);const s=requestAnimationFrame(()=>{Pt.delete(n),n.isConnected&&(n.classList.add(Ut),wt.set(n,setTimeout(()=>{n.isConnected&&n.classList.remove(Ut),wt.delete(n)},ee.HIGHLIGHT_DURATION_MS)))});Pt.set(n,s)}function ie(n,t){return ft(n,t)}Object.defineProperty(ie,"debug",{enumerable:!0,configurable:!0,get(){return d.enabled},set(n){d.enabled=n}});function oe(){return new Promise(n=>setTimeout(n,0))}const Ze={atom:ie,computed:nt,effect:H,batch:kt,untracked:M,isAtom:dt,isComputed:Yt,isReactive:At,nextTick:oe};l.extend(Ze);const z="_aes-bound";class Je{constructor(){this.records=new WeakMap,this.preservedNodes=new WeakSet,this.ignoredNodes=new WeakSet}keep(t){this.preservedNodes.add(t)}isKept(t){return this.preservedNodes.has(t)}markIgnored(t){this.ignoredNodes.add(t)}isIgnored(t){return this.ignoredNodes.has(t)}getOrCreateRecord(t){let e=this.records.get(t);return e||(e={effects:void 0,cleanups:void 0,componentCleanup:void 0},this.records.set(t,e),t.classList.add(z)),e}trackEffect(t,e){const s=this.getOrCreateRecord(t);s.effects??=[],s.effects.push(e)}trackCleanup(t,e){const s=this.getOrCreateRecord(t);s.cleanups??=[],s.cleanups.push(e)}setComponentCleanup(t,e){const s=this.getOrCreateRecord(t);s.componentCleanup=e}hasBind(t){return this.records.has(t)}cleanup(t){const e=this.records.get(t);if(!e){t.nodeType===1&&t.classList.remove(z),this.preservedNodes.delete(t),this.ignoredNodes.delete(t);return}if(this.records.delete(t),this.preservedNodes.delete(t),this.ignoredNodes.delete(t),t.nodeType===1&&t.classList.remove(z),d.enabled){const s=t.nodeType===1?Z(t):t.nodeName||"Node";d.cleanup(p.BINDING,s)}if(e.componentCleanup)try{e.componentCleanup()}catch(s){const i=t.nodeType===1?Z(t):"Node";d.error(p.MOUNT,S.MOUNT.CLEANUP_ERROR(i),s)}if(e.effects){const s=e.effects;for(let i=0,o=s.length;i<o;i++)try{s[i].dispose()}catch(r){const c=t.nodeType===1?Z(t):"Node";d.error(p.BINDING,S.CORE.EFFECT_DISPOSE_ERROR(c),r)}}if(e.cleanups){const s=e.cleanups;for(let i=0,o=s.length;i<o;i++)try{s[i]()}catch(r){const c=t.nodeType===1?Z(t):"Node";d.error(p.BINDING,S.BINDING.CLEANUP_ERROR(c),r)}}}cleanupDescendants(t){const e="getElementsByClassName"in t&&typeof t.getElementsByClassName=="function"?t.getElementsByClassName(z):t.querySelectorAll(`.${z}`);for(let s=e.length-1;s>=0;s--){const i=e[s];i&&(this.records.has(i)?this.cleanup(i):(i.classList.remove(z),d.enabled&&d.warn(p.BINDING,`${z} class found on unregistered element:`,i)))}}cleanupTree(t){(t.nodeType===1||t.nodeType===11)&&this.cleanupDescendants(t),this.cleanup(t)}}const b=new Je,mt=new Map;function re(n){if(mt.has(n))return;const t=new MutationObserver(e=>{for(let s=0,i=e.length;s<i;s++){const o=e[s].removedNodes;for(let r=0,c=o.length;r<c;r++){const a=o[r];a.nodeType===1&&(a.isConnected||b.isKept(a)||b.isIgnored(a)||b.cleanupTree(a))}}});t.observe(n,{childList:!0,subtree:!0}),mt.set(n,t)}function ts(){mt.forEach(n=>n.disconnect()),mt.clear()}function j(n,t,e,s){if(At(t)){const i=t;b.trackEffect(n,H(()=>{const o=i.value;M(()=>{try{e(o)}catch(r){d.error(p.BINDING,S.BINDING.UPDATER_ERROR(s),r);return}d.enabled&&d.domUpdated(p.BINDING,n,s,o)})},{name:s}))}else M(()=>{try{e(t)}catch(i){d.error(p.BINDING,S.BINDING.UPDATER_ERROR(s,!0),i);return}d.enabled&&d.domUpdated(p.BINDING,n,s,t)})}const gt=Symbol("atom-effect-internal"),It=new WeakMap;let F=null;const ce=n=>{if(n[gt])return n;let t=It.get(n);return t||(t=function(...e){return kt(()=>n.apply(this,e))},t[gt]=!0,It.set(n,t)),t};function es(n){const t={},e=Object.entries(n);for(let s=0,i=e.length;s<i;s++){const o=e[s],r=o[0],c=o[1];c&&(t[r]=ce(c))}return t}function ss(n){const t={},e=Object.entries(n);for(let s=0,i=e.length;s<i;s++){const o=e[s],r=o[0],c=o[1];t[r]=c?It.get(c)??c:void 0}return t}function ae(){if(F!==null)return;F={on:l.fn.on,off:l.fn.off,remove:l.fn.remove,empty:l.fn.empty,detach:l.fn.detach};const n=F;l.fn.remove=function(t){const e=t?this.filter(t):this;for(let i=0,o=e.length;i<o;i++){const r=e[i];r&&(b.markIgnored(r),b.cleanupTree(r))}const s=n.remove.call(this,t);return s!==void 0?s:this},l.fn.empty=function(){for(let e=0,s=this.length;e<s;e++){const i=this[e];i?.hasChildNodes()&&b.cleanupDescendants(i)}const t=n.empty.call(this);return t!==void 0?t:this},l.fn.detach=function(t){const e=t?this.filter(t):this;for(let i=0,o=e.length;i<o;i++){const r=e[i];r&&b.keep(r)}const s=n.detach.call(this,t);return s!==void 0?s:this},l.fn.on=function(...t){const e=t[0];if(e&&typeof e=="object")t[0]=es(e);else{const i=t.length-1;i>=0&&typeof t[i]=="function"&&(t[i]=ce(t[i]))}const s=n.on.apply(this,t);return s!==void 0?s:this},l.fn.off=function(...t){const e=t[0];if(e&&typeof e=="object")t[0]=ss(e);else{const i=t.length-1;if(i>=0&&typeof t[i]=="function"){const o=t[i];t[i]=It.get(o)??o}}const s=n.off.apply(this,t);return s!==void 0?s:this}}function ns(){F!==null&&(l.fn.on=F.on,l.fn.off=F.off,l.fn.remove=F.remove,l.fn.empty=F.empty,l.fn.detach=F.detach,F=null)}var L=(n=>(n[n.None=0]="None",n[n.Focused=1]="Focused",n[n.Composing=2]="Composing",n[n.SyncingToAtom=4]="SyncingToAtom",n[n.SyncingToDom=8]="SyncingToDom",n[n.Busy=14]="Busy",n))(L||{});let is=0;function rt(n){n[gt]=!0}class os{constructor(t,e,s){this.flags=0,this.timeoutId=void 0,this.handleCompositionStart=()=>{this.flags|=L.Composing},this.handleCompositionEnd=()=>{this.flags&=~L.Composing,this.handleInput()},this.handleFocus=()=>{this.flags|=L.Focused},this.handleBlur=()=>{this.flags&=~L.Focused;const c=!!(this.flags&L.Composing);this.flags&=~L.Composing,this.flushPendingDebounce(),c&&this.timeoutId===void 0&&this.syncAtomFromDom(),this.normalizeDomValue()},this.syncDomFromAtom=()=>{const c=this.atom.value;M(()=>{const a=this.format(c);let h;if(this.isMultipleSelect?h=this.$el.val()||[]:h=this.el.value,this.equal(h,c))return;const u=!!(this.flags&L.Focused);if(u)try{const _=this.isMultipleSelect?h:this.parse(this.el.value);if(this.equal(_,c))return}catch{}this.flags|=L.SyncingToDom;try{if(this.isMultipleSelect)this.$el.val(c);else if(u&&(this.el instanceof HTMLInputElement||this.el instanceof HTMLTextAreaElement))try{const _=this.el.selectionStart,y=this.el.selectionEnd;this.el.value=a;const E=a.length;_!==null&&y!==null&&this.el.setSelectionRange(_<E?_:E,y<E?y:E)}catch{this.el.value=a}else this.el.value=a;d.enabled&&d.domUpdated(p.BINDING,this.$el,"val",a)}finally{this.flags&=~L.SyncingToDom}})},this.cleanup=()=>{this.$el.off(this.ns),clearTimeout(this.timeoutId),this.timeoutId=void 0},this.$el=t,this.el=t[0],this.atom=e,this.isMultipleSelect=this.el.tagName==="SELECT"&&this.el.multiple,this.ns=`.atomBind-${++is}`;const i=s.debounce??0,o=s.event??He.EVENT;this.parse=s.parse??(c=>c),this.format=s.format??(c=>this.isMultipleSelect?(Array.isArray(c)?c:c?[String(c)]:[]).join(","):String(c??""));const r=s.equal??Object.is;this.equal=(c,a)=>r(c,a)?!0:Array.isArray(c)&&Array.isArray(a)?c.length===a.length&&c.every((h,u)=>Object.is(h,a[u])):!1,i>0?this.handleInput=()=>{this.flags&L.Composing||(clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>this.syncAtomFromDom(),i))}:this.handleInput=()=>{this.flags&L.Composing||this.syncAtomFromDom()},rt(this.handleFocus),rt(this.handleBlur),rt(this.handleCompositionStart),rt(this.handleCompositionEnd),rt(this.handleInput),this.bindEvents(o)}flushPendingDebounce(){this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0,this.syncAtomFromDom())}normalizeDomValue(){const t=this.format(this.atom.peek());if(this.isMultipleSelect){const e=this.$el.val()||[],s=Array.isArray(this.atom.peek())?this.atom.peek():[];this.equal(e,s)||this.$el.val(s)}else this.el.value!==t&&(this.el.value=t)}syncAtomFromDom(){if(!(this.flags&L.Busy)){this.flags|=L.SyncingToAtom;try{let t;this.isMultipleSelect?t=this.$el.val()||[]:t=this.el.value;const e=this.parse(t);this.equal(this.atom.peek(),e)||(this.atom.value=e)}catch(t){d.warn(p.BINDING,S.BINDING.PARSE_ERROR(t instanceof Error?t.message:String(t)),t)}finally{this.flags&=~L.SyncingToAtom}}}bindEvents(t){const e=this.ns,s=t.trim().split(/\s+/).map(i=>`${i}${e}`).join(" ");this.$el.on(`focus${e}`,this.handleFocus).on(`blur${e}`,this.handleBlur).on(`compositionstart${e}`,this.handleCompositionStart).on(`compositionend${e}`,this.handleCompositionEnd).on(s,this.handleInput)}}function rs(n,t,e){const s=new os(n,t,e);return{fx:H(s.syncDomFromAtom),cleanup:s.cleanup}}const cs=new Set(["href","src","action","formaction","xlink:href","data","poster","background","cite","longdesc","profile","usemap","classid","codebase"]),as=/^\s*(?:javascript|vbscript)\s*:/i,ls=/(?:expression\s*\(|behavior\s*:|-moz-binding\s*:|(?:\\[0-9a-f]{1,6}\s*|[\s\x00-\x20/'"])*(?:j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t|v\s*b\s*s\s*c\s*r\s*i\s*p\s*t|d\s*a\s*t\s*a)\s*:(?!image\/))/i,hs=/url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i,us=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,fs=/&#x([0-9a-f]+);?|&#([0-9]+);?/gi,ds={colon:":",Tab:" ",NewLine:`
2
- `},_s=/&(colon|Tab|NewLine);/g,ps=/<\?[\s\S]*?\?>/g,Es=/(<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*>([\s\S]*?)<\/\2>|<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*\/?>)/gi,ms=/(j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t|v\s*b\s*s\s*c\s*r\s*i\s*p\s*t)\s*:/gi,gs=/data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi,Is=/\bon\w+\s*=/gim,ys=new RegExp(ls.source,"gim");function yt(n){let t=String(n??"");t=t.replace(us,""),t=t.replace(fs,(s,i,o)=>String.fromCodePoint(i?parseInt(i,16):parseInt(o,10))),t=t.replace(_s,(s,i)=>ds[i]??""),t=t.replace(ps,"");let e;do e=t,t=t.replace(Es,"");while(t!==e);return t=t.replace(ms,"data-unsafe-protocol:"),t=t.replace(gs,"data-unsafe-protocol:"),t=t.replace(Is,"data-unsafe-attr="),t=t.replace(ys,"data-unsafe-css:"),t}function le(n,t){return cs.has(n.toLowerCase())?as.test(t):!1}function Cs(n){return n.toLowerCase().includes("url(")?hs.test(n):!1}const he=new Map;function Ts(n){let t=he.get(n);return t!==void 0||(t=n.includes("-")?n.replace(/-./g,e=>e[1].toUpperCase()):n,he.set(n,t)),t}const ue=new WeakMap;function Ss(n){let t=ue.get(n);return t||(t=nt(()=>yt(n.value)),ue.set(n,t)),t}function U(n){return{$el:l(n),el:n,trackCleanup:t=>b.trackCleanup(n,t)}}function fe(n,t,e){const s=n.el;j(s,t,i=>{const o=e?e(i):typeof i=="string"?i:String(i??"");s.textContent!==o&&(s.textContent=o)},"text")}function de(n,t){const e=n.el,s=dt(t)?Ss(t):t;j(e,s,i=>{e.innerHTML!==i&&(b.cleanupDescendants(e),e.innerHTML=i)},"html")}function _e(n,t){for(const e in t)if(J.call(t,e)){const s=t[e],i=e.trim().split(/\s+/).filter(Boolean);i.length>1?j(n.el,s,o=>{o?n.el.classList.add(...i):n.el.classList.remove(...i)},`class.${e}`):i.length===1&&j(n.el,s,o=>{n.el.classList.toggle(i[0],!!o)},`class.${e}`)}}function pe(n,t){const e=n.el,s=e.style;for(const i in t)if(J.call(t,i)){const o=t[i],r=Ts(i),[c,a]=Array.isArray(o)?o:[o,""];j(e,c,h=>{const u=a?String(h)+a:String(h);Cs(u)||(s[r]=u)},`css.${i}`)}}function Ee(n,t){const e=n.el;for(const s in t)if(J.call(t,s)){const i=s.toLowerCase();if(i.startsWith("on")){console.warn(`${p.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`);continue}const o=i.startsWith("aria-");j(e,t[s],r=>{if(r==null){e.removeAttribute(s);return}if(r===!1&&!o){e.removeAttribute(s);return}const c=r===!0?o?"true":s:String(r);if(le(s,c)){console.warn(`${p.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`);return}e.getAttribute(s)!==c&&e.setAttribute(s,c)},`attr.${s}`)}}function me(n,t){const e=n.el;for(const s in t)if(J.call(t,s)){const i=s.toLowerCase();if(i.startsWith("on")){console.warn(`${p.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`);continue}if(Ve.has(s)){console.warn(`${p.BINDING} ${S.SECURITY.BLOCKED_PROP(s)}`);continue}const o=$e.has(i);j(n.el,t[s],r=>{if(o&&typeof r=="string"&&le(s,r)){console.warn(`${p.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`);return}e[s]!==r&&(e[s]=r)},`prop.${s}`)}}function Ct(n,t,e){const s=n.el,i=e?"hide":"show",o=s.style.display,r=o==="none"?"":o;j(s,t,c=>{s.style.display=e!==!!c?r:"none"},i)}function ge(n,t,e={}){const s=n.el.tagName.toLowerCase();if(!je.has(s)){console.warn(`${p.BINDING} ${S.BINDING.INVALID_INPUT_ELEMENT(s)}`);return}const{fx:i,cleanup:o}=rs(n.$el,t,e);b.trackEffect(n.el,i),n.trackCleanup(o)}function Ie(n,t){const e=n.el,s=n.$el,i=e.type==="radio",o=()=>{const c=e.checked;if(t.value!==c&&(t.value=c,i&&c&&e.name)){const a=e.name.replace(/"/g,'\\"');(e.form?l(e.form):l(document)).find(`input[type="radio"][name="${a}"]`).not(e).trigger("change.atomRadioSync")}};o[gt]=!0,s.on("change change.atomRadioSync",o),n.trackCleanup(()=>s.off("change change.atomRadioSync",o));const r=H(()=>{const c=!!t.value;M(()=>{e.checked!==c&&(e.checked=c,d.enabled&&d.domUpdated(p.BINDING,s,"checked",c))})});b.trackEffect(e,r)}function Ns(n,t){const e=n.$el;e.on(t),n.trackCleanup(()=>e.off(t))}function bs(n,t,e){const s=n.$el;s.on(t,e),n.trackCleanup(()=>s.off(t,e))}function ye(n){b.cleanupTree(n)}function A(n){d.enabled&&d.log(p.BINDING,`Skipping non-Element node (nodeType=${n})`)}l.fn.atomText=function(n,t){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?fe(U(i),n,t):A(i.nodeType)}return this},l.fn.atomHtml=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?de(U(s),n):A(s.nodeType)}return this},l.fn.atomClass=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${p.BINDING} ${S.BINDING.MISSING_CONDITION("atomClass")}`),this;const e=typeof n=="string"?{[n]:t}:n;for(let s=0,i=this.length;s<i;s++){const o=this[s];o.nodeType===1?_e(U(o),e):A(o.nodeType)}return this},l.fn.atomCss=function(n,t,e){if(typeof n=="string"&&t===void 0)return console.warn(`${p.BINDING} ${S.BINDING.MISSING_SOURCE("atomCss")}`),this;const s=typeof n=="string"?{[n]:e?[t,e]:t}:n;for(let i=0,o=this.length;i<o;i++){const r=this[i];r.nodeType===1?pe(U(r),s):A(r.nodeType)}return this},l.fn.atomAttr=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${p.BINDING} ${S.BINDING.MISSING_SOURCE("atomAttr")}`),this;const e=typeof n=="string"?{[n]:t}:n;for(let s=0,i=this.length;s<i;s++){const o=this[s];o.nodeType===1?Ee(U(o),e):A(o.nodeType)}return this},l.fn.atomProp=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${p.BINDING} ${S.BINDING.MISSING_SOURCE("atomProp")}`),this;const e=typeof n=="string"?{[n]:t}:n;for(let s=0,i=this.length;s<i;s++){const o=this[s];o.nodeType===1?me(U(o),e):A(o.nodeType)}return this},l.fn.atomShow=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?Ct(U(s),n,!1):A(s.nodeType)}return this},l.fn.atomHide=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?Ct(U(s),n,!0):A(s.nodeType)}return this},l.fn.atomVal=function(n,t={}){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?ge(U(i),n,t):A(i.nodeType)}return this},l.fn.atomChecked=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?Ie(U(s),n):A(s.nodeType)}return this},l.fn.atomOn=function(n,t){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?bs(U(i),n,t):A(i.nodeType)}return this},l.fn.atomBind=function(n){const{text:t,html:e,class:s,css:i,attr:o,prop:r,show:c,hide:a,val:h,checked:u,on:_}=n,y=h===void 0?null:Array.isArray(h)?{atom:h[0],opts:h[1]}:{atom:h,opts:void 0};for(let E=0,D=this.length;E<D;E++){const C=this[E];if(C.nodeType!==1){A(C.nodeType);continue}const T=U(C);t!==void 0&&fe(T,t),e!==void 0&&de(T,e),s!==void 0&&_e(T,s),i!==void 0&&pe(T,i),o!==void 0&&Ee(T,o),r!==void 0&&me(T,r),c!==void 0&&Ct(T,c,!1),a!==void 0&&Ct(T,a,!0),y!==null&&ge(T,y.atom,y.opts),u!==void 0&&Ie(T,u),_!==void 0&&Ns(T,_)}return this},l.fn.atomUnbind=function(){for(let n=0,t=this.length;n<t;n++){const e=this[n];e.nodeType===1?ye(e):A(e.nodeType)}return this};const xt=new WeakMap;let Rs=0;function vs(n,t,e){t?.isConnected?n.insertBefore(t):n.appendTo(e)}function Ds(n,t,e,s,i,o){t.$el[0]&&(n===void 0?o&&o(t.$el,e,s):i&&i(t.$el,e,s))}class Os{constructor(t,e,s){this.$container=t,this.containerSelector=e,this.onRemove=s,this.itemMap=new Map,this.removingKeys=new Set,this.oldKeys=[],this.$emptyEl=null,this.elToKey=new WeakMap,this.keyToIndex=new Map}scheduleRemoval(t,e){const s=()=>{this.fx?.isDisposed||(e.$el.remove(),this.removingKeys.delete(t),d.log(p.LIST,`${this.containerSelector} removed item:`,t))};if(!this.onRemove){s();return}const i=this.onRemove(e.$el);i instanceof Promise?i.then(s,s):s()}removeItem(t,e){for(let s=0;s<e.$el.length;s++){const i=e.$el[s];i&&this.elToKey.delete(i)}this.itemMap.delete(t),this.removingKeys.add(t),this.scheduleRemoval(t,e)}dispose(){this.itemMap.clear(),this.removingKeys.clear(),this.oldKeys.length=0,this.keyToIndex.clear(),this.$emptyEl?.remove(),this.$container.off(".atomList")}}function Ls(n,t,e,s){if(n.$emptyEl&&t>0&&(n.$emptyEl.remove(),n.$emptyEl=null),t!==0)return;if(s&&!n.$emptyEl){const r=typeof s=="string"?yt(s):s;n.$emptyEl=l(r).appendTo(e)}const{oldKeys:i,itemMap:o}=n;for(let r=0,c=i.length;r<c;r++){const a=i[r],h=o.get(a);h&&n.removeItem(a,h)}i.length=0}function ks(n,t,e,s,i){const{oldKeys:o,itemMap:r,removingKeys:c}=n,a=new Map;for(let C=0,T=o.length;C<T;C++)a.set(o[C],C);const h=new Array(e),u=new Set,_=new Int32Array(e),y=[],E=[],D=[];for(let C=0;C<e;C++){const T=t[C],f=s(T,C);if(h[C]=f,u.has(f)){d.warn(p.LIST,S.LIST.DUPLICATE_KEY(f,C,n.containerSelector)),_[C]=-1;continue}u.add(f);const I=r.get(f);if(!I){y.push(f),E.push(T),D.push(C),_[C]=-1;continue}const m=I.item;!i&&m!==T&&!ze(m,T)&&(y.push(f),E.push(T),D.push(C)),_[C]=c.has(f)?-1:a.get(f)??-1}return{newKeys:h,newKeySet:u,newIndices:_,trKeys:y,trItems:E,trIdxs:D}}function As(n,t,e,s){const{trKeys:i,trItems:o,trIdxs:r}=t,c=i.length,a=n.itemMap,h=e.render,u=new Array(c),_=[];let y=0;for(let f=0;f<c;f++){const I=h(o[f],r[f]);u[f]=I,typeof I=="string"&&(_.push(I),y++)}let E=null;const D=_.length;if(D===1)E=[yt(_[0])];else if(D>1){const I=`<template data-atom-sep="${(Rs++).toString(36)}"></template>`;E=yt(_.join(I)).split(I)}if(s&&E!==null&&y===c&&!e.bind&&!e.onAdd&&!e.onRemove&&!e.events)return E;let T=0;for(let f=0;f<c;f++){const I=u[f],m=l(typeof I=="string"?E[T++]:I),R=i[f],g=a.get(R);if(!g){a.set(R,{$el:m,item:null,state:"new"});continue}const k=g.$el[0];k&&b.cleanupTree(k),g.$el.replaceWith(m),g.$el=m,g.state="replaced"}return null}function Us(n,t){const{oldKeys:e,itemMap:s}=n;for(let i=0,o=e.length;i<o;i++){const r=e[i];if(t.has(r))continue;const c=s.get(r);c&&n.removeItem(r,c)}}function ws(n,t,e,s,i,o,r){const{bind:c,update:a,onAdd:h}=o,{newKeys:u,newIndices:_}=e,y=t.length,E=n.oldKeys.length===0,D=Ke(_);let C=D.length-1;const{itemMap:T,removingKeys:f}=n;if(r!==null){s.innerHTML=r.join("");let I=0;for(let m=0;m<y;m++){const R=u[m],g=t[m],k=s.children[I++];if(k){const w=l(k);T.set(R,{$el:w,item:g,state:void 0}),f.delete(R),d.enabled&&d.domUpdated(p.LIST,w,"list.add",g)}}return}if(E){const I=document.createDocumentFragment();for(let m=y-1;m>=0;m--){const R=u[m],g=T.get(R);if(!g)continue;const k=g.$el;for(let w=k.length-1;w>=0;w--)I.insertBefore(k[w],I.firstChild)}s.appendChild(I)}else{let I=null;for(let m=y-1;m>=0;m--){const R=u[m],g=T.get(R);g&&(C>=0&&D[C]===m?C--:vs(g.$el,I,i),I=g.$el[0]??null)}}for(let I=0;I<y;I++){const m=u[I],R=t[I],g=T.get(m);if(!g)continue;const k=g.state;g.item=R,g.state=void 0,Ds(k,g,R,I,c,a),k==="new"&&(h&&h(g.$el),f.delete(m),d.enabled&&d.domUpdated(p.LIST,g.$el,"list.add",R))}}function Ps(n,t){const{newKeys:e,newKeySet:s}=t,i=e.length,{oldKeys:o,itemMap:r,elToKey:c,keyToIndex:a}=n;for(let h=0,u=o.length;h<u;h++){const _=o[h];s.has(_)||a.delete(_)}for(let h=0;h<i;h++){const u=e[h],_=r.get(u);if(_){for(let y=0;y<_.$el.length;y++){const E=_.$el[y];E&&c.set(E,u)}a.set(u,h)}}}l.fn.atomList=function(n,t){const{key:e,bind:s,update:i,onAdd:o,onRemove:r,empty:c,events:a}=t,h=typeof e=="function"?e:(_,y)=>_[e],u={bind:s,update:i,onAdd:o,onRemove:r,events:a};for(let _=0,y=this.length;_<y;_++){const E=this[_],D=l(E);D.off(".atomList");const C=xt.get(E);C&&(C.fx.dispose(),C.ctx.dispose());const T=Z(E),f=new Os(D,T,r),I=H(()=>{const m=n.value,R=m.length;M(()=>{if(Ls(f,R,D,c),R===0)return;d.log(p.LIST,`${T} updating with ${R} items`);const g=ks(f,m,R,h,i),k=f.oldKeys.length===0,w=As(f,g,t,k);Us(f,g.newKeySet),ws(f,m,g,E,D,u,w),a&&Ps(f,g),f.oldKeys=g.newKeys})});if(f.fx=I,a)for(const m in a){if(!J.call(a,m))continue;const R=a[m],g=m.indexOf(" "),k=g===-1?m:m.slice(0,g),w=g===-1?null:m.slice(g+1).trim(),Gs=w||"> *",Hs=function(js){let ct=this;for(;ct&&ct!==E;){const Mt=f.elToKey.get(ct);if(Mt!==void 0){const Te=f.itemMap.get(Mt);Te&&R.call(this,Te.item,f.keyToIndex.get(Mt)??-1,js);return}ct=ct.parentElement}};D.on(`${k}.atomList`,Gs,Hs)}b.trackEffect(E,I),xt.set(E,{fx:I,ctx:f}),b.trackCleanup(E,()=>{f.dispose(),xt.delete(E)})}return this};const xs=Object.freeze({});l.fn.atomMount=function(n,t){const e=t??xs;for(let s=0,i=this.length;s<i;s++){const o=this[s];if(!o)continue;b.cleanupTree(o);const r=l(o);let c;try{c=M(()=>n(r,e))}catch(a){d.error(p.MOUNT,S.MOUNT.ERROR(n.name),a);continue}typeof c=="function"&&b.setComponentCleanup(o,c)}return this},l.fn.atomUnmount=function(){for(let n=0,t=this.length;n<t;n++){const e=this[n];e&&ye(e)}return this};function Ce(n,t){try{return history.pushState(n,"",t),!0}catch(e){return d.warn(p.ROUTE,"PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.",e),!1}}class Ms{constructor(t){this.isDestroyed=!1,this.previousRoute="",this.cleanups=[],this.templateCache=new Map,this.config={...t,mode:t.mode??it.mode,basePath:t.basePath??it.basePath,autoBindLinks:t.autoBindLinks??it.autoBindLinks,activeClass:t.activeClass??it.activeClass},this.isHistoryMode=this.config.mode==="history",this.$target=l(this.config.target),this.normalizedBasePath=this.config.basePath?.replace(/\/$/,"")||"",this.activeClass=this.config.activeClass??it.activeClass,this.previousUrl=this.isHistoryMode?window.location.pathname+window.location.search:window.location.hash,this.currentRouteAtom=ft(this.getRouteName()),this.currentRoute=this.currentRouteAtom,this.queryParamsAtom=ft(this.getQueryParams()),this.queryParams=nt(()=>this.queryParamsAtom.value),this.handleUrlChange=this.handleUrlChange.bind(this),this.destroy=this.destroy.bind(this),this.init()}init(){const t=this.isHistoryMode?"popstate":"hashchange";window.addEventListener(t,this.handleUrlChange),this.cleanups.push(()=>window.removeEventListener(t,this.handleUrlChange));const e=H(()=>{const s=this.currentRouteAtom.value;M(()=>this.renderRoute(s))});this.cleanups.push(()=>e.dispose()),this.setupAutoBindLinks(),this.$target[0]&&b.trackCleanup(this.$target[0],this.destroy)}getRouteName(){const{default:t}=this.config;if(this.isHistoryMode){let o=window.location.pathname;return this.normalizedBasePath&&o.startsWith(this.normalizedBasePath)&&(o=o.substring(this.normalizedBasePath.length)),o.charCodeAt(0)===47&&(o=o.slice(1)),o||t}const e=window.location.hash,s=e.indexOf("?");return(s===-1?e.substring(1):e.substring(1,s))||t}getQueryParams(){let t;if(this.isHistoryMode){if(t=window.location.search.substring(1),!t)return{}}else{const i=window.location.hash,o=i.indexOf("?");if(o===-1)return{};t=i.substring(o+1)}const e=new URLSearchParams(t),s=Object.fromEntries(e);if(t.includes("%"))try{decodeURIComponent(t)}catch{d.warn(p.ROUTE,S.ROUTE.MALFORMED_URI(t))}return s}setUrl(t){if(this.isHistoryMode){const e=`${this.normalizedBasePath}/${t}`;Ce(null,e),this.previousUrl=e}else{const e=`#${t}`;window.location.hash=e,this.previousUrl=e}}restoreUrl(){this.isHistoryMode?Ce(null,this.previousUrl):window.location.hash=this.previousUrl}getCurrentUrl(){return this.isHistoryMode?window.location.pathname+window.location.search:window.location.hash}getRouteConfig(t){const{routes:e,notFound:s}=this.config;let i=e[t];return!i&&s&&(i=e[s]),i||(d.warn(p.ROUTE,S.ROUTE.NOT_FOUND(t)),null)}renderTemplate(t){let e=this.templateCache.get(t);if(!e){const i=document.querySelector(t);if(!i||!(i instanceof HTMLTemplateElement))return d.warn(p.ROUTE,S.ROUTE.TEMPLATE_NOT_FOUND(t)),!1;e=i,this.templateCache.set(t,e)}const s=e.content.cloneNode(!0);return this.$target.append(s),!0}renderRoute(t){if(this.isDestroyed)return;const e=this.$target[0];if(!e){d.warn(p.ROUTE,S.ROUTE.TARGET_NOT_FOUND(this.config.target));return}const s=this.getRouteConfig(t);if(!s)return;const i=this.getQueryParams(),o=this.previousRoute;this.config.beforeTransition&&this.config.beforeTransition(o,t),this.$target.empty();let r=i;if(s.onEnter){const c=s.onEnter(i);c!==void 0&&(r={...i,...c})}s.render?s.render(e,t,r):s.template&&this.renderTemplate(s.template)&&s.onMount&&s.onMount(this.$target.children()),this.config.afterTransition&&this.config.afterTransition(o,t),this.previousRoute=t}handleUrlChange(){if(this.isDestroyed)return;const t=this.getCurrentUrl();if(t===this.previousUrl)return;const e=this.getRouteName(),s=this.currentRouteAtom.peek(),i=this.getQueryParams();if(s!==e){const o=this.config.routes[s];if(o?.onLeave&&o.onLeave()===!1){this.restoreUrl();return}this.currentRouteAtom.value=e,this.queryParamsAtom.value=i}else{this.queryParamsAtom.value=i;const o=this.config.routes[s];o?.onParamsChange?o.onParamsChange(i):this.renderRoute(e)}this.previousUrl=t}setupAutoBindLinks(){if(!this.config.autoBindLinks)return;const t=i=>{i.preventDefault();const o=i.currentTarget.dataset.route;o!=null&&this.navigate(o)};l(document).on("click","[data-route]",t),this.cleanups.push(()=>{l(document).off("click","[data-route]",t)});const e=this.activeClass,s=H(()=>{const i=this.currentRouteAtom.value;M(()=>{const o=document.querySelectorAll("[data-route]");for(let r=0,c=o.length;r<c;r++){const a=o[r],h=a.dataset.route,u=i===h;a.classList.toggle(e,u),u?a.setAttribute("aria-current","page"):a.removeAttribute("aria-current")}})});this.cleanups.push(()=>s.dispose())}navigate(t){if(this.isDestroyed)return;const e=this.currentRouteAtom.peek(),s=this.config.routes[e];if(s?.onLeave&&s.onLeave()===!1)return;const i=t||this.config.default;if(!i){d.warn(p.ROUTE,"navigate() called with empty routeName and no default configured.");return}this.setUrl(i),this.queryParamsAtom.value={},this.currentRouteAtom.value=i}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;const t=this.cleanups;this.cleanups=[];for(let e=0,s=t.length;e<s;e++)try{t[e]()}catch(i){d.warn(p.ROUTE,"Cleanup error during destroy:",i)}this.templateCache.clear()}}function Fs(n){return new Ms(n)}l.extend({route:Fs});class Bs{constructor(t,e){this.abortController=null,this.isStaticUrl=typeof t=="string",this.isStaticUrl?this.staticUrl=t:this.getUrl=t,typeof e.ajaxOptions=="function"?(this.ajaxOptionsFn=e.ajaxOptions,this.staticOptions={}):this.staticOptions={...e.ajaxOptions},e.method!==void 0&&(this.staticOptions.method=e.method),e.headers!==void 0&&(this.staticOptions.headers={...this.staticOptions.headers,...e.headers}),this.transformFn=e.transform,this.onErrorFn=e.onError,this.execute=this.execute.bind(this)}abort(){this.abortController?.abort()}async execute(){this.abortController?.abort(),this.abortController=new AbortController;const t=this.abortController.signal,e=this.ajaxOptionsFn?this.ajaxOptionsFn():{},s=l.extend(!0,{},this.staticOptions,e);s.success=void 0,s.error=void 0,s.complete=void 0,s.url=this.isStaticUrl?this.staticUrl:this.getUrl();const i=l.ajax(s);t.onabort=()=>i.abort(),t.aborted&&i.abort();let o;try{o=await i}catch(c){if(t.aborted){const u=new Error("AbortError");throw u.name="AbortError",u}let a;if(c&&typeof c.readyState<"u"){const u=c;a=new Error(`Network Error: ${u.statusText||"Unknown"} (${u.status})`),a.jqXHR=u}else a=c instanceof Error?c:new Error(String(c??"Unknown network error"));const h=this.onErrorFn;if(h)try{h(a)}catch{}throw a}finally{t.onabort=null,this.abortController?.signal===t&&(this.abortController=null)}const r=this.transformFn;if(r)try{return r(o)}catch(c){const a=this.onErrorFn;if(a)try{a(c)}catch{}throw c}return o}}l.extend({atomFetch(n,t){const e=new Bs(n,t),s=!(t.eager??!0),i=nt(e.execute,{defaultValue:t.defaultValue,lazy:s});return Object.assign(i,{abort:()=>e.abort()})}}),l(()=>{ae(),re(document.body)}),N.default=l,N.atom=ft,N.batch=kt,N.computed=nt,N.disableAutoCleanup=ts,N.disablejQueryOverrides=ns,N.effect=H,N.enableAutoCleanup=re,N.enablejQueryOverrides=ae,N.isAtom=dt,N.isComputed=Yt,N.isReactive=At,N.nextTick=oe,N.registry=b,N.untracked=M,Object.defineProperties(N,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
3
- //# sourceMappingURL=atom-effect-jquery.min.js.map
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`jquery`)):typeof define==`function`&&define.amd?define([`exports`,`jquery`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.AtomEffectJQuery={},e.jQuery))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=Object.create,r=Object.defineProperty,i=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,o=Object.getPrototypeOf,s=Object.prototype.hasOwnProperty,c=(e,t,n,o)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=a(t),l=0,u=c.length,d;l<u;l++)d=c[l],!s.call(e,d)&&d!==n&&r(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(o=i(t,d))||o.enumerable});return e};t=((e,t,i)=>(i=e==null?{}:n(o(e)),c(t||!e||!e.__esModule?r(i,`default`,{value:e,enumerable:!0}):i,e)))(t);var l={IDLE:`idle`,PENDING:`pending`,RESOLVED:`resolved`,REJECTED:`rejected`},u={DISPOSED:1,EXECUTING:8},d={DISPOSED:1,IS_COMPUTED:2,DIRTY:8,IDLE:16,PENDING:32,RESOLVED:64,REJECTED:128,RECOMPUTING:256,HAS_ERROR:512,FORCE_COMPUTE:1024},f={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},m={WARN_INFINITE_LOOP:!0,EFFECT_FREQUENCY_WINDOW:1e3},h={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:2**53-1-1},g={UNINITIALIZED:-1,MIN:1},_=1073741823,v={VERSION_BITS:16};typeof process<`u`&&process.env;var y=Object.freeze([]),b=class{constructor(e,t,n=void 0){this.node=e,this.version=t,this.unsub=n}},x=class{constructor(e,t){this.fn=e,this.sub=t}notify(e,t){this.fn?this.fn(e,t):this.sub&&this.sub.execute()}},S=class extends Error{constructor(e,t=null,n=!0){super(e),this.cause=t,this.recoverable=n,this.name=`AtomError`}},C=class extends S{constructor(e,t=null){super(e,t,!0),this.name=`ComputedError`}},w=class extends S{constructor(e,t=null){super(e,t,!1),this.name=`EffectError`}},ee=class extends S{constructor(e,t=null){super(e,t,!1),this.name=`SchedulerError`}},T={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:(e,t)=>`Maximum flush iterations (${e}) exceeded. ${t} 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`},te=class{constructor(){this._s0=null,this._s1=null,this._s2=null,this._s3=null,this._count=0,this._epoch=g.UNINITIALIZED,this._overflow=null}get size(){return this._count}getAt(e){switch(e){case 0:return this._s0;case 1:return this._s1;case 2:return this._s2;case 3:return this._s3;default:{let t=this._overflow;if(t!==null&&e>=4){let n=e-4;if(n<t.length)return t[n]??null}return null}}}setAt(e,t){switch(e){case 0:this._s0=t;break;case 1:this._s1=t;break;case 2:this._s2=t;break;case 3:this._s3=t;break;default:{this._overflow??=[];let n=this._overflow;n[e-4]=t}}e>=this._count&&(this._count=e+1)}truncateFrom(e){let t=this._count;if(e>=t)return;if(e<=3)switch(e){case 0:{let e=this._s0;e!=null&&(this._onItemRemoved(e),this._s0=null)}case 1:{let e=this._s1;e!=null&&(this._onItemRemoved(e),this._s1=null)}case 2:{let e=this._s2;e!=null&&(this._onItemRemoved(e),this._s2=null)}case 3:{let e=this._s3;e!=null&&(this._onItemRemoved(e),this._s3=null)}}let n=this._overflow;if(n!==null&&t>4){let t=e>4?e-4:0,r=n.length;for(let e=t;e<r;e++){let t=n[e];t!=null&&(this._onItemRemoved(t),n[e]=null)}e<=4?(n.length=0,this._overflow=null):n.length=e-4}this._count=e}_onItemRemoved(e){}add(e){if(this._s0===null){this._s0=e,this._count++;return}if(this._s1===null){this._s1=e,this._count++;return}if(this._s2===null){this._s2=e,this._count++;return}if(this._s3===null){this._s3=e,this._count++;return}if(this._overflow===null)this._overflow=[e];else{let t=this._overflow;for(let n=0,r=t.length;n<r;n++)if(t[n]===null){t[n]=e,this._count++;return}t.push(e)}this._count++}remove(e){if(this._s0===e)return this._s0=null,this._count--,!0;if(this._s1===e)return this._s1=null,this._count--,!0;if(this._s2===e)return this._s2=null,this._count--,!0;if(this._s3===e)return this._s3=null,this._count--,!0;let t=this._overflow;if(t==null)return!1;for(let n=0,r=t.length;n<r;n++)if(t[n]===e)return t[n]=null,this._count--,!0;return!1}has(e){let t=this._count;if(t===0)return!1;if(this._s0===e||this._s1===e||this._s2===e||this._s3===e)return!0;if(t<=4)return!1;let n=this._overflow;if(n!=null){let r=0;this._s0!=null&&r++,this._s1!=null&&r++,this._s2!=null&&r++,this._s3!=null&&r++;for(let i=0,a=n.length;i<a;i++){let a=n[i];if(a!=null){if(a===e)return!0;if(++r===t)break}}}return!1}forEach(e){let t=this._count;if(t===0)return;let n=this._s0;n!=null&&e(n);let r=this._s1;r!=null&&e(r);let i=this._s2;i!=null&&e(i);let a=this._s3;if(a!=null&&e(a),t<=4)return;let o=this._overflow;if(o!=null){let s=0;n!=null&&s++,r!=null&&s++,i!=null&&s++,a!=null&&s++;for(let n=0,r=o.length;n<r;n++){let r=o[n];if(r!=null&&(e(r),++s===t))return}}}forEachIndexed(e){let t=this._count;if(t===0)return 0;let n=0,r=this._s0;r!=null&&(e(r),n++);let i=this._s1;i!=null&&(e(i),n++);let a=this._s2;a!=null&&(e(a),n++);let o=this._s3;if(o!=null&&(e(o),n++),t<=4||n===t)return n;let s=this._overflow;if(s!=null)for(let r=0,i=s.length;r<i;r++){let i=s[r];if(i!=null&&(e(i),++n===t))break}return n}compact(){let e=this._overflow;if(e===null||e.length===0)return;let t=0;for(;t<e.length;)if(e[t]===null){let n=e.pop();t<e.length&&n!=null&&(e[t]=n)}else t++;e.length===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)}dispose(){this.clear()}},ne=Symbol(`AtomEffect.DebugName`),re=Symbol(`AtomEffect.Type`),ie=Symbol(`AtomEffect.NoDefaultValue`),ae={enabled:!1,warnInfiniteLoop:m.WARN_INFINITE_LOOP,warn(e,t){},attachDebugInfo(e,t,n){},getDebugName:e=>e?.[ne],getDebugType:e=>e?.[re]},oe=1,se=()=>oe++;function E(e,t,n){if(e instanceof S)return e;let r=e instanceof Error,i=r?e.message:String(e),a=r?e:void 0;return new t(`${r?e.constructor.name:`Unexpected error`} (${n}): ${i}`,a)}var ce=class{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=g.UNINITIALIZED,this._notifying=0,this._hotIndex=-1,this._slots=null,this._deps=null,this.id=se()&_}subscribe(e){let t=typeof e==`function`;if(!t&&(!e||typeof e.execute!=`function`))throw E(TypeError(`Invalid subscriber`),S,T.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);let n=this._slots;n||(n=new te,this._slots=n);let r=!1;if(n.forEach(n=>{(t?n.fn===e:n.sub===e)&&(r=!0)}),r)return()=>{};let i=new x(t?e:void 0,t?void 0:e);return n.add(i),()=>this._unsubscribe(i)}_unsubscribe(e){if(this._slots){if(this._notifying>0){this._slots.remove(e);return}this._slots.remove(e),this._slots.compact()}}subscriberCount(){return this._slots?this._slots.size:0}_notifySubscribers(e,t){let n=this._slots;if(!(!n||n.size===0)){this._notifying++;try{n.forEach(n=>{try{n.notify(e,t)}catch(e){console.error(E(e,S,T.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}})}finally{this._notifying--,this._notifying===0&&n.compact()}}}_isDirty(){let e=this._deps;if(!e||e.size===0)return!1;if(this._hotIndex!==-1){let t=e.getAt(this._hotIndex);if(t!=null&&t.node.version!==t.version)return!0}return!e.hasComputeds&&!e.isDirtyFast()?!1:this._deepDirtyCheck()}},le=0,ue=()=>(le=le+1&1073741823||1,le),de=e=>e+1&_,fe=0,pe=!1,me=0,he=()=>me;function ge(){return pe?!1:(pe=!0,me=ue(),fe=0,!0)}var _e=()=>{pe=!1},ve=()=>pe?++fe:0,ye=(function(e){return e[e.IDLE=0]=`IDLE`,e[e.BATCHING=1]=`BATCHING`,e[e.FLUSHING=2]=`FLUSHING`,e})({}),D=new class{constructor(){this._queueBuffer=[[],[]],this._bufferIndex=0,this._size=0,this._epoch=0,this._isProcessing=!1,this._isBatching=!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 phase(){return this._isProcessing||this._isFlushingSync?ye.FLUSHING:this._isBatching?ye.BATCHING:ye.IDLE}get queueSize(){return this._size}get isBatching(){return this._isBatching}schedule(e){if(e._nextEpoch!==this._epoch){if(e._nextEpoch=this._epoch,this._isBatching||this._isFlushingSync){this._batchQueue[this._batchQueueSize++]=e;return}this._queueBuffer[this._bufferIndex][this._size++]=e,this._isProcessing||this._flush()}}_flush(){this._isProcessing||this._size===0||(this._isProcessing=!0,queueMicrotask(this._boundRunLoop))}_runLoop(){try{if(this._size===0)return;let e=ge();this._drainQueue(),e&&_e()}finally{this._isProcessing=!1,this._size>0&&!this._isBatching&&this._flush()}}_flushSync(){this._isFlushingSync=!0;let e=ge();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,e&&_e()}}_mergeBatchQueue(){if(this._batchQueueSize===0)return;let e=++this._epoch,t=this._batchQueue,n=this._queueBuffer[this._bufferIndex],r=this._size;for(let i=0;i<this._batchQueueSize;i++){let a=t[i];a._nextEpoch!==e&&(a._nextEpoch=e,n[r++]=a)}this._size=r,this._batchQueueSize=0,t.length=0}_drainQueue(){let e=0;for(;this._size>0;){if(++e>this._maxFlushIterations){this._handleFlushOverflow();return}this._processQueue(),this._mergeBatchQueue()}}_processQueue(){let e=this._bufferIndex,t=this._queueBuffer[e],n=this._size;this._bufferIndex=e^1,this._size=0,this._epoch++;for(let e=0;e<n;e++)try{let n=t[e];typeof n==`function`?n():n.execute()}catch(e){console.error(new ee(`Error occurred during scheduler execution`,e))}t.length=0}_handleFlushOverflow(){let e=this._size+this._batchQueueSize;if(console.error(new ee(T.SCHEDULER_FLUSH_OVERFLOW(this._maxFlushIterations,e))),this._size=0,this._queueBuffer[this._bufferIndex].length=0,this._batchQueueSize=0,this.onOverflow)try{this.onOverflow(e)}catch{}}startBatch(){this._batchDepth++,this._isBatching=!0}endBatch(){this._batchDepth!==0&&--this._batchDepth===0&&(this._flushSync(),this._isBatching=!1)}setMaxFlushIterations(e){if(e<p.MIN_FLUSH_ITERATIONS)throw new ee(`Max flush iterations must be at least ${p.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=e}},be=Symbol.for(`atom-effect/atom`),xe=Symbol.for(`atom-effect/computed`),Se=Symbol.for(`atom-effect/effect`),Ce=Symbol.for(`atom-effect/writable`),O={current:null,run(e,t){let n=this.current;this.current=e;try{return t()}finally{this.current=n}}};function k(e){let t=O.current;if(t===null)return e();O.current=null;try{return e()}finally{O.current=t}}var we=class extends ce{constructor(e,t){super(),this[be]=!0,this[Ce]=!0,this._value=e,this._pendingOldValue=void 0,t&&(this.flags|=f.SYNC),ae.attachDebugInfo(this,`atom`,this.id)}get value(){return O.current?.addDependency(this),this._value}set value(e){let t=this._value;if(Object.is(t,e))return;this._value=e,this.version=de(this.version);let n=this._slots,r=this.flags;if(n==null||n.size===0||r&f.NOTIFICATION_SCHEDULED)return;this._pendingOldValue=t;let i=r|f.NOTIFICATION_SCHEDULED;if(this.flags=i,(i&f.SYNC)!==0&&!D.isBatching){this._flushNotifications();return}D.schedule(this)}execute(){this._flushNotifications()}_flushNotifications(){let e=this.flags;if(!(e&f.NOTIFICATION_SCHEDULED)||e&f.DISPOSED)return;let t=this._pendingOldValue;this._pendingOldValue=void 0,this.flags&=~f.NOTIFICATION_SCHEDULED,this._notifySubscribers(this._value,t)}peek(){return this._value}dispose(){this.flags&f.DISPOSED||(this._slots?.clear(),this.flags|=f.DISPOSED,this._value=void 0,this._pendingOldValue=void 0)}_deepDirtyCheck(){return!1}[Symbol.dispose](){this.dispose()}};function Te(e,t={}){return new we(e,t.sync??!1)}var Ee=class extends te{constructor(){super(),this._map=null,this._SCAN_THRESHOLD=32,this.hasComputeds=!1,this._depsHash=0,this._map=null,this.hasComputeds=!1,this._depsHash=0}prepareTracking(){this.hasComputeds=!1}_onItemRemoved(e){let t=e.unsub;t&&t()}claimExisting(e,t){let n=this._count;if(t>=n)return!1;let r=n-t;if(this._map!==null||r>this._SCAN_THRESHOLD)return this._claimViaMap(e,t);if(t<4)switch(t){case 0:{let t=this._s0;if(t&&t.node===e&&t.unsub)return t.version=e.version,!0}case 1:if(n>1){let n=this._s1;if(n&&n.node===e&&n.unsub)return n.version=e.version,t!==1&&(this._s1=this._s0,this._s0=n),!0}case 2:if(n>2){let n=this._s2;if(n&&n.node===e&&n.unsub){if(n.version=e.version,t!==2){let e=t===0?this._s0:this._s1;t===0?this._s0=n:this._s1=n,this._s2=e}return!0}}case 3:if(n>3){let n=this._s3;if(n&&n.node===e&&n.unsub){if(n.version=e.version,t!==3){let e;t===0?(e=this._s0,this._s0=n):t===1?(e=this._s1,this._s1=n):(e=this._s2,this._s2=n),this._s3=e}return!0}}}let i=t>4?t:4,a=this._overflow;if(a)for(let n=i-4,r=a.length;n<r;n++){let r=a[n];if(r&&r.node===e&&r.unsub)return r.version=e.version,this._swapGeneral(n+4,t,r),!0}return!1}_claimViaMap(e,t){if(this._map===null){this._map=new Map;let e=this._count;t<4&&(t<=0&&this._s0?.unsub&&this._map.set(this._s0.node,0),t<=1&&this._s1?.unsub&&this._map.set(this._s1.node,1),t<=2&&this._s2?.unsub&&this._map.set(this._s2.node,2),t<=3&&this._s3?.unsub&&this._map.set(this._s3.node,3));let n=this._overflow;if(n&&e>4){let e=t>4?t:4;for(let t=e-4,r=n.length;t<r;t++){let e=n[t];e?.unsub&&this._map.set(e.node,t+4)}}}let n=this._map.get(e);if(n===void 0||n<t)return!1;let r=this.getAt(n);if(r==null||!r.unsub)return!1;if(r.version=e.version,n!==t){let i=this.getAt(t);this.setAt(t,r),this.setAt(n,i),i?.unsub&&this._map.set(i.node,n),this._map.set(e,t)}return!0}_swapInline(e,t,n){let r=this.getAt(t);this.setAt(t,n),this.setAt(e,r)}_swapGeneral(e,t,n){if(e===t)return;let r=this.getAt(t);if(this.setAt(t,n),e===0)this._s0=r;else if(e===1)this._s1=r;else if(e===2)this._s2=r;else if(e===3)this._s3=r;else{let t=this._overflow;t[e-4]=r}}insertNew(e,t){let n=this._count;if(e<n){let t=this.getAt(e);t!=null&&(this.add(t),this._map!==null&&t.unsub&&this._map.set(t.node,this._count-1))}if(e===0)this._s0=t;else if(e===1)this._s1=t;else if(e===2)this._s2=t;else if(e===3)this._s3=t;else{let n=this._overflow;n||(n=[],this._overflow=n),n[e-4]=t}e>=n&&(this._count=e+1)}truncateFrom(e){e>=this._count||(super.truncateFrom(e),this._map!==null&&(this._map.clear(),this._map=null))}seal(){let e=this._count,t=v.VERSION_BITS,n=0;switch(e){case 0:this._depsHash=0;return;case 1:{let e=this._s0;n=n+(e.version<<t)+e.node.id|0;break}case 2:{let e=this._s0,r=this._s1;n=n+(e.version<<t)+e.node.id|0,n=n+(r.version<<t)+r.node.id|0;break}case 3:{let e=this._s0,r=this._s1,i=this._s2;n=n+(e.version<<t)+e.node.id|0,n=n+(r.version<<t)+r.node.id|0,n=n+(i.version<<t)+i.node.id|0;break}default:{let r=this._s0,i=this._s1,a=this._s2,o=this._s3;if(n=n+(r.version<<t)+r.node.id|0,n=n+(i.version<<t)+i.node.id|0,n=n+(a.version<<t)+a.node.id|0,n=n+(o.version<<t)+o.node.id|0,e>4){let e=this._overflow;for(let r=0,i=e.length;r<i;r++){let i=e[r];n=n+(i.version<<t)+i.node.id|0}}}}this._depsHash=n}isDirtyFast(){let e=this._count,t=v.VERSION_BITS,n=0;switch(e){case 0:return!1;case 1:{let e=this._s0.node;n=n+(e.version<<t)+e.id|0;break}case 2:{let e=this._s0.node,r=this._s1.node;n=n+(e.version<<t)+e.id|0,n=n+(r.version<<t)+r.id|0;break}case 3:{let e=this._s0.node,r=this._s1.node,i=this._s2.node;n=n+(e.version<<t)+e.id|0,n=n+(r.version<<t)+r.id|0,n=n+(i.version<<t)+i.id|0;break}default:{let r=this._s0.node,i=this._s1.node,a=this._s2.node,o=this._s3.node;if(n=n+(r.version<<t)+r.id|0,n=n+(i.version<<t)+i.id|0,n=n+(a.version<<t)+a.id|0,n=n+(o.version<<t)+o.id|0,e>4){let e=this._overflow;for(let r=0,i=e.length;r<i;r++){let i=e[r].node;n=n+(i.version<<t)+i.id|0}}}}return n!==this._depsHash}disposeAll(){this._count>0&&this.truncateFrom(0),this.hasComputeds=!1,this._map!==null&&(this._map.clear(),this._map=null)}remove(e){throw Error(`remove() is strictly prohibited in DepSlotBuffer to preserve sequential cache paths.`)}compact(){}};function A(e){return typeof e==`object`&&!!e&&be in e}function De(e){return typeof e==`object`&&!!e&&xe in e}function Oe(e){return typeof e==`object`&&!!e&&typeof e.then==`function`}var{IDLE:j,DIRTY:M,PENDING:N,RESOLVED:P,REJECTED:F,HAS_ERROR:I,RECOMPUTING:L,DISPOSED:ke,IS_COMPUTED:Ae,FORCE_COMPUTE:je}=d,Me=class extends ce{constructor(e,t={}){if(typeof e!=`function`)throw new C(T.COMPUTED_MUST_BE_FUNCTION);if(super(),this[be]=!0,this[xe]=!0,this._error=null,this._promiseId=0,this._deps=new Ee,this._asyncRetryCount=0,this._lastDriftEpoch=g.UNINITIALIZED,this._trackEpoch=g.UNINITIALIZED,this._trackCount=0,this._value=void 0,this.flags=Ae|M|j,this._equal=t.equal??Object.is,this._fn=e,this._defaultValue=`defaultValue`in t?t.defaultValue:ie,this._onError=t.onError??null,this._maxAsyncRetries=(t.maxAsyncRetries??h.MAX_ASYNC_RETRIES)&_,ae.attachDebugInfo(this,`computed`,this.id),t.lazy===!1)try{this._recompute()}catch{}}_track(){O.current?.addDependency(this)}get value(){this._track();let e=this.flags;if((e&(P|M|j))===P)return this._value;if(e&ke)throw new C(T.COMPUTED_DISPOSED);if(e&L){if(this._defaultValue!==ie)return this._defaultValue;throw new C(T.COMPUTED_CIRCULAR_DEPENDENCY)}if(e&(M|j)&&((e&j)===0&&(e&je)===0&&this._deps.size>0&&!this._isDirty()?this.flags&=~M:this._recompute(),this.flags&P))return this._value;let t=this._defaultValue,n=t!==ie;if(this.flags&N){if(n)return t;throw new C(T.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if(this.flags&F){if(n)return t;throw this._error}return this._value}peek(){return this._value}get state(){this._track();let e=this.flags;return e&P?l.RESOLVED:e&N?l.PENDING:e&F?l.REJECTED:l.IDLE}get hasError(){if(this._track(),this.flags&(F|I))return!0;let e=this._deps;if(!e.hasComputeds)return!1;let t=e.size;for(let n=0;n<t;n++){let t=e.getAt(n);if(t!=null&&t.node.flags&I)return!0}return!1}get isValid(){return!this.hasError}get errors(){this._track();let e=[];this._error&&e.push(this._error);let t=this._deps;if(!t.hasComputeds)return e.length===0?y:Object.freeze(e);let n=t.size;for(let r=0;r<n;r++){let n=t.getAt(r);if(n==null)continue;let i=n.node;i.flags&I&&this._collectErrorsFromDep(i,e)}return e.length===0?y:Object.freeze(e)}_collectErrorsFromDep(e,t){let n=e.errors,r=n.length;for(let e=0;e<r;e++){let r=n[e];r!=null&&!t.includes(r)&&t.push(r)}}get lastError(){return this._track(),this._error}get isPending(){return this._track(),(this.flags&N)!==0}get isResolved(){return this._track(),(this.flags&P)!==0}invalidate(){this.flags|=je,this._markDirty()}dispose(){this.flags&ke||(this._deps.disposeAll(),this._slots?.clear(),this.flags=ke|M|j,this._error=null,this._value=void 0,this._hotIndex=-1)}[Symbol.dispose](){this.dispose()}addDependency(e){if(e._lastSeenEpoch===this._trackEpoch)return;e._lastSeenEpoch=this._trackEpoch;let t=this._trackCount,n=this._deps.getAt(t);if(n!=null&&n.node===e)n.version=e.version;else if(!this._deps.claimExisting(e,t)){let n=new b(e,e.version,e.subscribe(this));this._deps.insertNew(t,n)}e.flags&Ae&&(this._deps.hasComputeds=!0),this._trackCount=t+1}_recompute(){if(this.flags&L)return;this.flags=(this.flags|L)&~je,this._trackEpoch=ue(),this._trackCount=0,this._deps.prepareTracking(),this._hotIndex=-1;let e=!1;try{let t=O.run(this,this._fn);this._deps.truncateFrom(this._trackCount),this._deps.seal(),e=!0,Oe(t)?this._handleAsyncComputation(t):this._finalizeResolution(t)}catch(t){if(!e)try{this._deps.truncateFrom(this._trackCount)}catch{}this._handleError(t,T.COMPUTED_COMPUTATION_FAILED,!0)}finally{this._trackEpoch=g.UNINITIALIZED,this._trackCount=0,this.flags&=~L}}_handleAsyncComputation(e){this.flags=(this.flags|N)&~(j|M|P|F),this._notifySubscribers(void 0,void 0),this._asyncRetryCount=0,this._promiseId=(this._promiseId+1)%h.MAX_PROMISE_ID;let t=this._promiseId;e.then(e=>{if(t===this._promiseId){if(this._isDirty()){let e=he();return this._lastDriftEpoch!==e&&(this._lastDriftEpoch=e,this._asyncRetryCount=0),this._asyncRetryCount++<this._maxAsyncRetries?this._markDirty():this._handleError(new C(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`),T.COMPUTED_ASYNC_COMPUTATION_FAILED)}this._finalizeResolution(e),this._notifySubscribers(e,void 0)}},e=>t===this._promiseId&&this._handleError(e,T.COMPUTED_ASYNC_COMPUTATION_FAILED))}_handleError(e,t,n=!1){let r=E(e,C,t);if(!n&&!(this.flags&F)&&(this.version=de(this.version)),this._error=r,this.flags=this.flags&~(j|M|N|P)|F|I,this._onError)try{this._onError(r)}catch(e){console.error(T.CALLBACK_ERROR_IN_ERROR_HANDLER,e)}if(n)throw r;this._notifySubscribers(void 0,void 0)}_finalizeResolution(e){(!(this.flags&P)||!this._equal(this._value,e))&&(this.version=de(this.version)),this._value=e,this._error=null,this.flags=(this.flags|P)&~(j|M|N|F|I)}execute(){this._markDirty()}_markDirty(){this.flags&(L|M)||(this.flags|=M,this._notifySubscribers(void 0,void 0))}_isDirty(){let e=this._deps;return e.hasComputeds?this._deepDirtyCheck():e.isDirtyFast()}_deepDirtyCheck(){let e=this._deps,t=O.current;O.current=null;try{let t=e.size;for(let n=0;n<t;n++){let t=e.getAt(n);if(t==null)continue;let r=t.node;if(r.flags&Ae)try{r.value}catch{}if(r.version!==t.version)return this._hotIndex=n,!0}return this._hotIndex=-1,!1}finally{O.current=t}}};function R(e,t={}){return new Me(e,t)}var Ne=class extends ce{constructor(e,t={}){super(),this[Se]=!0,this._cleanup=null,this._deps=new Ee,this._currentEpoch=g.UNINITIALIZED,this._lastFlushEpoch=g.UNINITIALIZED,this._fn=e,this._onError=t.onError??null,this._sync=t.sync??!1,this._maxExecutions=t.maxExecutionsPerSecond??p.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=t.maxExecutionsPerFlush??p.MAX_EXECUTIONS_PER_EFFECT,this._cleanup=null,this._deps=new Ee,this._currentEpoch=g.UNINITIALIZED,this._lastFlushEpoch=g.UNINITIALIZED,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=()=>D.schedule(this),ae.attachDebugInfo(this,`effect`,this.id)}run(){if(this.flags&u.DISPOSED)throw new w(T.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.flags&u.DISPOSED||(this.flags|=u.DISPOSED,this._execCleanup(),this._deps?.disposeAll())}[Symbol.dispose](){this.dispose()}addDependency(e){if(!(this.flags&u.EXECUTING))return;let t=this._currentEpoch;if(e._lastSeenEpoch===t)return;e._lastSeenEpoch=t;let n=this._trackCount,r=this._deps,i;i=n===0?r._s0:n===1?r._s1:n===2?r._s2:n===3?r._s3:r.getAt(n),i!=null&&i.node===e?i.version=e.version:r.claimExisting(e,n)||this._insertNewDependency(e,n),e.flags&d.IS_COMPUTED&&(r.hasComputeds=!0),this._trackCount=n+1}_insertNewDependency(e,t){let n;try{let t=e.subscribe(this._notifyCallback);n=new b(e,e.version,t)}catch(t){let r=E(t,w,T.EFFECT_EXECUTION_FAILED);if(console.error(r),this._onError)try{this._onError(r)}catch{}n=new b(e,e.version,void 0)}this._deps.insertNew(t,n)}execute(e=!1){if(this.flags&(u.DISPOSED|u.EXECUTING))return;let t=this._deps;if(!e&&t.size>0&&!this._isDirty())return;this._checkInfiniteLoops(),this.flags|=u.EXECUTING,this._execCleanup(),this._currentEpoch=ue(),this._trackCount=0,t.prepareTracking(),this._hotIndex=-1;let n=!1;try{let e=O.run(this,this._fn);t.truncateFrom(this._trackCount),t.seal(),n=!0,Oe(e)?this._handleAsyncResult(e):this._cleanup=typeof e==`function`?e:null}catch(e){if(!n)try{t.truncateFrom(this._trackCount)}catch{}this._handleExecutionError(e),this._cleanup=null}finally{this.flags&=~u.EXECUTING}}_isDirty(){let e=this._deps;return e.hasComputeds?this._deepDirtyCheck():e.isDirtyFast()}_handleAsyncResult(e){let t=++this._execId;e.then(e=>{if(t!==this._execId||this.flags&u.DISPOSED){if(typeof e==`function`)try{e()}catch(e){this._handleExecutionError(e,T.EFFECT_CLEANUP_FAILED)}return}typeof e==`function`&&(this._cleanup=e)},e=>t===this._execId&&this._handleExecutionError(e))}_deepDirtyCheck(){let e=O.current;O.current=null;let t=this._deps;try{let e=t.size;for(let n=0;n<e;n++){let e=t.getAt(n);if(e==null)continue;let r=e.node;if(r.flags&d.IS_COMPUTED&&this._tryPullComputed(r),r.version!==e.version)return this._hotIndex=n,!0}return!1}finally{O.current=e}}_tryPullComputed(e){try{e.value}catch{}}_execCleanup(){if(this._cleanup){try{this._cleanup()}catch(e){this._handleExecutionError(e,T.EFFECT_CLEANUP_FAILED)}this._cleanup=null}}_checkInfiniteLoops(){let e=he();this._lastFlushEpoch!==e&&(this._lastFlushEpoch=e,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError(`per-effect`),ve()>p.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError(`global`),this._executionCount++}_checkFrequencyLimit(){if(!Number.isFinite(this._maxExecutions))return;let e=Date.now();if(e-this._windowStart>=m.EFFECT_FREQUENCY_WINDOW){this._windowStart=e,this._windowCount=1;return}if(++this._windowCount>this._maxExecutions){let e=new w(T.EFFECT_FREQUENCY_LIMIT_EXCEEDED);throw this.dispose(),this._handleExecutionError(e),e}}get isDisposed(){return(this.flags&u.DISPOSED)!==0}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&u.EXECUTING)!==0}_throwInfiniteLoopError(e){let t=new w(`Infinite loop detected (${e}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${fe}`);throw this.dispose(),console.error(t),t}_handleExecutionError(e,t=T.EFFECT_EXECUTION_FAILED){let n=E(e,w,t);if(console.error(n),this._onError)try{this._onError(n)}catch(e){console.error(E(e,w,T.CALLBACK_ERROR_IN_ERROR_HANDLER))}}};function z(e,t={}){if(typeof e!=`function`)throw new w(T.EFFECT_MUST_BE_FUNCTION);let n=new Ne(e,t);return n.execute(),n}function Pe(e){if(typeof e!=`function`)throw TypeError(T.BATCH_CALLBACK_MUST_BE_FUNCTION);D.startBatch();try{return e()}finally{D.endBatch()}}function Fe(e){return A(e)}function B(e){let t=e.tagName.toLowerCase();if(e.id)return`${t}#${e.id}`;let n=e.classList,r=n.length;if(r===0)return t;let i=t;for(let e=0;e<r;e++)i+=`.${n[e]}`;return i}var V=Object.prototype.hasOwnProperty;function Ie(e,t){if(e===t)return!0;if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;let i=e,a=t;for(let e=0;e<n.length;e++){let t=n[e];if(!V.call(a,t)||i[t]!==a[t])return!1}return!0}var H={ROUTE:`[atom-route]`,BINDING:`[atom-binding]`,LIST:`[atom-list]`,MOUNT:`[atom-mount]`},U=Object.freeze({mode:`hash`,basePath:``,autoBindLinks:!1,activeClass:`active`}),Le={EVENT:`input`,DEBOUNCE:0},Re={HIGHLIGHT_DURATION_MS:500},ze=new Set([`input`,`select`,`textarea`]),Be=new Set([`src`,`href`,`action`,`formaction`,`data`,`poster`,`background`,`cite`,`longdesc`,`profile`,`usemap`,`classid`,`codebase`,`xlink:href`]),Ve=new Set([`innerHTML`,`outerHTML`,`srcdoc`,`__proto__`,`constructor`,`prototype`]),W={ROUTE:{NOT_FOUND:e=>`Route "${e}" not found and no notFound route configured`,TEMPLATE_NOT_FOUND:e=>`Template "${e}" not found`,TARGET_NOT_FOUND:e=>`Target element "${e}" not found`,MALFORMED_URI:e=>`Malformed URI component: ${e}`},SECURITY:{UNSAFE_CONTENT:()=>`Unsafe content neutralized during sanitization.`,BLOCKED_CSS_VALUE:e=>`Blocked dangerous value in CSS style property "${e}".`,BLOCKED_EVENT_HANDLER:e=>`Blocked setting dangerous event handler attribute/property "${e}".`,BLOCKED_PROTOCOL:e=>`Blocked dangerous protocol in "${e}".`,BLOCKED_PROP:e=>`Blocked setting dangerous property "${e}". Use html binding for sanitized HTML.`},BINDING:{INVALID_INPUT_ELEMENT:e=>`Val binding used on non-input element <${e}>.`,MISSING_SOURCE:e=>`[${e}] source is required when prop/name is a string.`,MISSING_CONDITION:e=>`[${e}] condition is required when className is a string.`,UPDATER_ERROR:(e,t)=>`Updater threw in binding "${e}"${t?` (static)`:``}`,CLEANUP_ERROR:e=>`Binding cleanup error${e?`: ${e}`:``}`,PARSE_ERROR:e=>`parse() threw during DOM→Atom sync${e?`: ${e}`:``}`},LIST:{DUPLICATE_KEY:(e,t,n)=>`Duplicate key "${e}" at index ${t} in atomList <${n}>.`},MOUNT:{ERROR:e=>`Mount error${e?` in component <${e}>`:``}`,CLEANUP_ERROR:e=>`Cleanup error${e?` in component <${e}>`:``}`},CORE:{EFFECT_DISPOSE_ERROR:e=>`Effect dispose error${e?`: ${e}`:``}`}},He=`${Re.HIGHLIGHT_DURATION_MS/1e3}s`;function Ue(){if(typeof window<`u`){let e=window.__ATOM_DEBUG__;if(typeof e==`boolean`)return e}try{if(globalThis.process?.env?.VITE_ATOM_DEBUG===`true`)return!0}catch{}return!1}var We=Ue(),G={get enabled(){if(typeof window<`u`){let e=window.__ATOM_DEBUG__;if(typeof e==`boolean`)return e}return We},set enabled(e){We=e},log(e,...t){this.enabled&&console.log(`${e}`,...t)},atomChanged(e,t,n,r){this.enabled&&console.log(`${e} Atom "${t??`anonymous`}" changed:`,n,`→`,r)},domUpdated(e,t,n,r){if(!this.enabled)return;let i=t instanceof Element?t:t[0];i&&(console.log(`${e} DOM updated: ${B(i)}.${n} =`,r),Ze(i))},cleanup(e,t){this.enabled&&console.log(`${e} Cleanup: ${t}`)},warn(e,t,...n){console.warn(`${e} ${t}`,...n)},error(e,t,n){console.error(`${e} ${t}`,n)}},Ge=`atom-debug-highlight`,Ke=`data-atom-debug`,qe;function Je(){if((qe instanceof HTMLStyleElement?qe:qe?.deref())?.isConnected||document.querySelector(`style[${Ke}]`))return;let e=document.createElement(`style`);e.setAttribute(Ke,``),e.textContent=`.${Ge}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${He} ease-out}`,document.head.appendChild(e),qe=typeof WeakRef<`u`?new WeakRef(e):e}var Ye=new WeakMap,Xe=new WeakMap;function Ze(e){if(!G.enabled||!e.isConnected)return;Je();let t=Xe.get(e);t!==void 0&&cancelAnimationFrame(t);let n=Ye.get(e);n!==void 0&&clearTimeout(n);let r=requestAnimationFrame(()=>{Xe.delete(e),e.isConnected&&(e.classList.add(Ge),Ye.set(e,setTimeout(()=>{e.isConnected&&e.classList.remove(Ge),Ye.delete(e)},Re.HIGHLIGHT_DURATION_MS)))});Xe.set(e,r)}function Qe(e,t){return Te(e,t)}Object.defineProperty(Qe,`debug`,{enumerable:!0,configurable:!0,get(){return G.enabled},set(e){G.enabled=e}});function $e(){return new Promise(e=>setTimeout(e,0))}var et={atom:Qe,computed:R,effect:z,batch:Pe,untracked:k,isAtom:A,isComputed:De,isReactive:Fe,nextTick:$e};t.default.extend(et);var tt=class{constructor(e=50,t=256){this.limit=e,this.capacity=t,this.pool=[]}acquire(){return this.pool.pop()??[]}release(e){e.length>this.capacity||this.pool.length>=this.limit||Object.isFrozen(e)||(e.length=0,this.pool.push(e))}reset(){this.pool.length=0}},nt=class{constructor(e,t,n=64){this.factory=e,this.reset=t,this.limit=n,this.pool=[]}acquire(){return this.pool.pop()??this.factory()}release(e){this.pool.length>=this.limit||(this.reset(e),this.pool.push(e))}drain(){this.pool.length=0}get size(){return this.pool.length}},rt=new tt,it=new tt,at=new nt(()=>({effects:void 0,cleanups:void 0,componentCleanup:void 0}),e=>{e.effects=void 0,e.cleanups=void 0,e.componentCleanup=void 0},128),K=`_aes-bound`,q=new class{constructor(){this.records=new WeakMap,this.preservedNodes=new WeakSet,this.ignoredNodes=new WeakSet}keep(e){this.preservedNodes.add(e)}isKept(e){return this.preservedNodes.has(e)}markIgnored(e){this.ignoredNodes.add(e)}isIgnored(e){return this.ignoredNodes.has(e)}getOrCreateRecord(e){let t=this.records.get(e);return t||(t=at.acquire(),this.records.set(e,t),e.classList.add(K)),t}trackEffect(e,t){let n=this.getOrCreateRecord(e);n.effects??=rt.acquire(),n.effects.push(t)}trackCleanup(e,t){let n=this.getOrCreateRecord(e);n.cleanups??=it.acquire(),n.cleanups.push(t)}setComponentCleanup(e,t){let n=this.getOrCreateRecord(e);n.componentCleanup=t}hasBind(e){return this.records.has(e)}cleanup(e){let t=this.records.get(e);if(!t){e.nodeType===1&&e.classList.remove(K),this.preservedNodes.delete(e),this.ignoredNodes.delete(e);return}if(this.records.delete(e),this.preservedNodes.delete(e),this.ignoredNodes.delete(e),e.nodeType===1&&e.classList.remove(K),G.enabled){let t=e.nodeType===1?B(e):e.nodeName||`Node`;G.cleanup(H.BINDING,t)}if(t.componentCleanup)try{t.componentCleanup()}catch(t){let n=e.nodeType===1?B(e):`Node`;G.error(H.MOUNT,W.MOUNT.CLEANUP_ERROR(n),t)}if(t.effects){let n=t.effects;for(let t=0,r=n.length;t<r;t++)try{n[t].dispose()}catch(t){let n=e.nodeType===1?B(e):`Node`;G.error(H.BINDING,W.CORE.EFFECT_DISPOSE_ERROR(n),t)}rt.release(n),t.effects=void 0}if(t.cleanups){let n=t.cleanups;for(let t=0,r=n.length;t<r;t++)try{n[t]()}catch(t){let n=e.nodeType===1?B(e):`Node`;G.error(H.BINDING,W.BINDING.CLEANUP_ERROR(n),t)}it.release(n),t.cleanups=void 0}at.release(t)}cleanupDescendants(e){let t=`getElementsByClassName`in e&&typeof e.getElementsByClassName==`function`?e.getElementsByClassName(K):e.querySelectorAll(`.${K}`);for(let e=t.length-1;e>=0;e--){let n=t[e];n&&(this.records.has(n)?this.cleanup(n):(n.classList.remove(K),G.enabled&&G.warn(H.BINDING,`${K} class found on unregistered element:`,n)))}}cleanupTree(e){(e.nodeType===1||e.nodeType===11)&&this.cleanupDescendants(e),this.cleanup(e)}},ot=new Map;function st(e){if(ot.has(e))return;let t=new MutationObserver(e=>{for(let t=0,n=e.length;t<n;t++){let n=e[t].removedNodes;for(let e=0,t=n.length;e<t;e++){let t=n[e];t.nodeType===1&&(t.isConnected||q.isKept(t)||q.isIgnored(t)||q.cleanupTree(t))}}});t.observe(e,{childList:!0,subtree:!0}),ot.set(e,t)}function ct(){ot.forEach(e=>e.disconnect()),ot.clear()}var lt=Symbol(`atom-effect-internal`),ut=new WeakMap,J=null,dt=e=>{if(e[lt])return e;let t=ut.get(e);return t||(t=function(...t){return Pe(()=>e.apply(this,t))},t[lt]=!0,ut.set(e,t)),t};function ft(e){let t={},n=Object.entries(e);for(let e=0,r=n.length;e<r;e++){let r=n[e],i=r[0],a=r[1];a&&(t[i]=dt(a))}return t}function pt(e){let t={},n=Object.entries(e);for(let e=0,r=n.length;e<r;e++){let r=n[e],i=r[0],a=r[1];t[i]=a?ut.get(a)??a:void 0}return t}function mt(){if(J!==null)return;J={on:t.default.fn.on,off:t.default.fn.off,remove:t.default.fn.remove,empty:t.default.fn.empty,detach:t.default.fn.detach};let e=J;t.default.fn.remove=function(t){let n=t?this.filter(t):this;for(let e=0,t=n.length;e<t;e++){let t=n[e];t&&(q.markIgnored(t),q.cleanupTree(t))}let r=e.remove.call(this,t);return r===void 0?this:r},t.default.fn.empty=function(){for(let e=0,t=this.length;e<t;e++){let t=this[e];t?.hasChildNodes()&&q.cleanupDescendants(t)}let t=e.empty.call(this);return t===void 0?this:t},t.default.fn.detach=function(t){let n=t?this.filter(t):this;for(let e=0,t=n.length;e<t;e++){let t=n[e];t&&q.keep(t)}let r=e.detach.call(this,t);return r===void 0?this:r},t.default.fn.on=function(...t){let n=t[0];if(n&&typeof n==`object`)t[0]=ft(n);else{let e=t.length-1;e>=0&&typeof t[e]==`function`&&(t[e]=dt(t[e]))}let r=e.on.apply(this,t);return r===void 0?this:r},t.default.fn.off=function(...t){let n=t[0];if(n&&typeof n==`object`)t[0]=pt(n);else{let e=t.length-1;if(e>=0&&typeof t[e]==`function`){let n=t[e];t[e]=ut.get(n)??n}}let r=e.off.apply(this,t);return r===void 0?this:r}}function ht(){J!==null&&(t.default.fn.on=J.on,t.default.fn.off=J.off,t.default.fn.remove=J.remove,t.default.fn.empty=J.empty,t.default.fn.detach=J.detach,J=null)}var Y=function(e){return e[e.None=0]=`None`,e[e.Focused=1]=`Focused`,e[e.Composing=2]=`Composing`,e[e.SyncingToAtom=4]=`SyncingToAtom`,e[e.SyncingToDom=8]=`SyncingToDom`,e[e.Busy=14]=`Busy`,e}({}),gt=0;function X(e){e[lt]=!0}var _t=class{constructor(e,t,n){this.flags=0,this.timeoutId=void 0,this.handleCompositionStart=()=>{this.flags|=Y.Composing},this.handleCompositionEnd=()=>{this.flags&=~Y.Composing,this.handleInput()},this.handleFocus=()=>{this.flags|=Y.Focused},this.handleBlur=()=>{this.flags&=~Y.Focused;let e=!!(this.flags&Y.Composing);this.flags&=~Y.Composing,this.flushPendingDebounce(),e&&this.timeoutId===void 0&&this.syncAtomFromDom(),this.normalizeDomValue()},this.syncDomFromAtom=()=>{let e=this.atom.value;k(()=>{let t=this.format(e),n;if(n=this.isMultipleSelect?this.$el.val()||[]:this.el.value,this.equal(n,e))return;let r=!!(this.flags&Y.Focused);if(r)try{let t=this.isMultipleSelect?n:this.parse(this.el.value);if(this.equal(t,e))return}catch{}this.flags|=Y.SyncingToDom;try{if(this.isMultipleSelect)this.$el.val(e);else if(r&&(this.el instanceof HTMLInputElement||this.el instanceof HTMLTextAreaElement))try{let e=this.el.selectionStart,n=this.el.selectionEnd;this.el.value=t;let r=t.length;e!==null&&n!==null&&this.el.setSelectionRange(e<r?e:r,n<r?n:r)}catch{this.el.value=t}else this.el.value=t;G.enabled&&G.domUpdated(H.BINDING,this.$el,`val`,t)}finally{this.flags&=~Y.SyncingToDom}})},this.cleanup=()=>{this.$el.off(this.ns),clearTimeout(this.timeoutId),this.timeoutId=void 0},this.$el=e,this.el=e[0],this.atom=t,this.isMultipleSelect=this.el.tagName===`SELECT`&&this.el.multiple,this.ns=`.atomBind-${++gt}`;let r=n.debounce??0,i=n.event??Le.EVENT;this.parse=n.parse??(e=>e),this.format=n.format??(e=>this.isMultipleSelect?(Array.isArray(e)?e:e?[String(e)]:[]).join(`,`):String(e??``));let a=n.equal??Object.is;this.equal=(e,t)=>a(e,t)?!0:Array.isArray(e)&&Array.isArray(t)?e.length===t.length&&e.every((e,n)=>Object.is(e,t[n])):!1,r>0?this.handleInput=()=>{this.flags&Y.Composing||(clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>this.syncAtomFromDom(),r))}:this.handleInput=()=>{this.flags&Y.Composing||this.syncAtomFromDom()},X(this.handleFocus),X(this.handleBlur),X(this.handleCompositionStart),X(this.handleCompositionEnd),X(this.handleInput),this.bindEvents(i)}flushPendingDebounce(){this.timeoutId!==void 0&&(clearTimeout(this.timeoutId),this.timeoutId=void 0,this.syncAtomFromDom())}normalizeDomValue(){let e=this.format(this.atom.peek());if(this.isMultipleSelect){let e=this.$el.val()||[],t=Array.isArray(this.atom.peek())?this.atom.peek():[];this.equal(e,t)||this.$el.val(t)}else this.el.value!==e&&(this.el.value=e)}syncAtomFromDom(){if(!(this.flags&Y.Busy)){this.flags|=Y.SyncingToAtom;try{let e;e=this.isMultipleSelect?this.$el.val()||[]:this.el.value;let t=this.parse(e);this.equal(this.atom.peek(),t)||(this.atom.value=t)}catch(e){G.warn(H.BINDING,W.BINDING.PARSE_ERROR(e instanceof Error?e.message:String(e)),e)}finally{this.flags&=~Y.SyncingToAtom}}}bindEvents(e){let t=this.ns,n=e.trim().split(/\s+/).map(e=>`${e}${t}`).join(` `);this.$el.on(`focus${t}`,this.handleFocus).on(`blur${t}`,this.handleBlur).on(`compositionstart${t}`,this.handleCompositionStart).on(`compositionend${t}`,this.handleCompositionEnd).on(n,this.handleInput)}};function vt(e,t,n){let r=new _t(e,t,n);return{fx:z(r.syncDomFromAtom),cleanup:r.cleanup}}function yt(e,t,n,r){if(Fe(t)){let i=t;q.trackEffect(e,z(()=>{let t=i.value;k(()=>{try{n(t)}catch(e){G.error(H.BINDING,W.BINDING.UPDATER_ERROR(r),e);return}G.enabled&&G.domUpdated(H.BINDING,e,r,t)})},{name:r}))}else k(()=>{try{n(t)}catch(e){G.error(H.BINDING,W.BINDING.UPDATER_ERROR(r,!0),e);return}G.enabled&&G.domUpdated(H.BINDING,e,r,t)})}function bt(e,t,n,r){let i=Object.keys(t),a=[],o={};for(let e=0;e<i.length;e++){let n=i[e],r=t[n];Fe(r)?a.push(n):o[n]=r}a.length>0?q.trackEffect(e,z(()=>{let i={...o};for(let e=0;e<a.length;e++){let n=a[e];i[n]=t[n].value}k(()=>{try{n(i)}catch(e){G.error(H.BINDING,W.BINDING.UPDATER_ERROR(r),e);return}G.enabled&&G.domUpdated(H.BINDING,e,r,i)})},{name:r})):k(()=>{try{n(o)}catch(e){G.error(H.BINDING,W.BINDING.UPDATER_ERROR(r,!0),e);return}G.enabled&&G.domUpdated(H.BINDING,e,r,o)})}var xt=new Set([`href`,`src`,`action`,`formaction`,`xlink:href`,`data`,`poster`,`background`,`cite`,`longdesc`,`profile`,`usemap`,`classid`,`codebase`]),St=/^\s*(?:javascript|vbscript)\s*:/i,Ct=/(?:expression\s*\(|behavior\s*:|-moz-binding\s*:|(?:\\[0-9a-f]{1,6}\s*|[\s\x00-\x20/'"])*(?:j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t|v\s*b\s*s\s*c\s*r\s*i\s*p\s*t|d\s*a\s*t\s*a)\s*:(?!image\/))/i,wt=/url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i,Tt=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,Et=/&#x([0-9a-f]+);?|&#([0-9]+);?/gi,Dt={colon:`:`,Tab:` `,NewLine:`
2
+ `},Ot=/&(colon|Tab|NewLine);/g,kt=/<\?[\s\S]*?\?>/g,At=/(<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*>([\s\S]*?)<\/\2>|<(script|iframe|object|embed|base|meta|applet|noscript|form|style|link)\b[^>]*\/?>)/gi,jt=/(j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t|v\s*b\s*s\s*c\s*r\s*i\s*p\s*t)\s*:/gi,Mt=/data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi,Nt=/\bon\w+\s*=/gim,Pt=new RegExp(Ct.source,`gim`);function Ft(e){let t=String(e??``);t=t.replace(Tt,``),t=t.replace(Et,(e,t,n)=>String.fromCodePoint(t?parseInt(t,16):parseInt(n,10))),t=t.replace(Ot,(e,t)=>Dt[t]??``),t=t.replace(kt,``);let n;do n=t,t=t.replace(At,``);while(t!==n);return t=t.replace(jt,`data-unsafe-protocol:`),t=t.replace(Mt,`data-unsafe-protocol:`),t=t.replace(Nt,`data-unsafe-attr=`),t=t.replace(Pt,`data-unsafe-css:`),t}function It(e,t){return xt.has(e.toLowerCase())?St.test(t):!1}function Lt(e){return e.toLowerCase().includes(`url(`)?wt.test(e):!1}var Rt=new Map;function zt(e){let t=Rt.get(e);return t===void 0?(t=e.includes(`-`)?e.replace(/-./g,e=>e[1].toUpperCase()):e,Rt.set(e,t),t):t}var Bt=new WeakMap;function Vt(e){let t=Bt.get(e);return t||(t=R(()=>Ft(e.value)),Bt.set(e,t)),t}function Ht(e){return{el:e,trackCleanup:t=>q.trackCleanup(e,t)}}function Ut(e,t,n){let r=e.el;yt(r,t,e=>{let t=n?n(e):typeof e==`string`?e:String(e??``);r.textContent!==t&&(r.textContent=t)},`text`)}function Wt(e,t){let n=e.el;yt(n,A(t)?Vt(t):t,e=>{n.innerHTML!==e&&(q.cleanupDescendants(n),n.innerHTML=e)},`html`)}function Gt(e,t){let n=e.el;bt(n,t,e=>{for(let t in e){let r=e[t],i=t.trim().split(/\s+/).filter(Boolean);r?n.classList.add(...i):n.classList.remove(...i)}},`class`)}function Kt(e,t){let n=e.el,r=n.style;q.trackEffect(n,z(()=>{for(let e in t)if(V.call(t,e)){let n=t[e],i=zt(e),[a,o]=Array.isArray(n)?n:[n,``],s=A(a)?a.value:a;k(()=>{let e=o?String(s)+o:String(s);Lt(e)||r[i]!==e&&(r[i]=e)})}},{name:`css`}))}function qt(e,t){let n=e.el,r={};for(let e in t)if(V.call(t,e)){if(e.toLowerCase().startsWith(`on`)){console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_EVENT_HANDLER(e)}`);continue}r[e]=t[e]}bt(n,r,e=>{for(let t in e){let r=e[t],i=t.toLowerCase().startsWith(`aria-`);if(r==null||r===!1&&!i){n.removeAttribute(t);continue}let a=r===!0?i?`true`:t:String(r);if(It(t,a)){console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_PROTOCOL(t)}`);continue}n.getAttribute(t)!==a&&n.setAttribute(t,a)}},`attr`)}function Jt(e,t){let n=e.el,r={};for(let e in t)if(V.call(t,e)){if(e.toLowerCase().startsWith(`on`)){console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_EVENT_HANDLER(e)}`);continue}if(Ve.has(e)){console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_PROP(e)}`);continue}r[e]=t[e]}bt(e.el,r,e=>{for(let t in e){let r=e[t],i=t.toLowerCase();if(Be.has(i)&&typeof r==`string`&&It(t,r)){console.warn(`${H.BINDING} ${W.SECURITY.BLOCKED_PROTOCOL(t)}`);continue}n[t]!==r&&(n[t]=r)}},`prop`)}function Yt(e,t,n){let r=e.el,i=n?`hide`:`show`,a=r.style.display,o=a===`none`?``:a;yt(r,t,e=>{let t=n===!!e?`none`:o;r.style.display!==t&&(r.style.display=t)},i)}function Xt(e,n,r={}){let i=e.el.tagName.toLowerCase();if(!ze.has(i)){console.warn(`${H.BINDING} ${W.BINDING.INVALID_INPUT_ELEMENT(i)}`);return}let{fx:a,cleanup:o}=vt((0,t.default)(e.el),n,r);q.trackEffect(e.el,a),e.trackCleanup(o)}function Zt(e,n){let r=e.el,i=(0,t.default)(r),a=r.type===`radio`,o=()=>{let e=r.checked;if(n.peek()!==e&&(n.value=e,a&&e&&r.name)){let e=r.name.replace(/"/g,`\\"`);(r.form?(0,t.default)(r.form):(0,t.default)(document)).find(`input[type="radio"][name="${e}"]`).not(r).trigger(`change.atomRadioSync`)}};o[lt]=!0,i.on(`change change.atomRadioSync`,o),e.trackCleanup(()=>i.off(`change change.atomRadioSync`,o));let s=z(()=>{let e=!!n.value;k(()=>{r.checked!==e&&(r.checked=e,G.enabled&&G.domUpdated(H.BINDING,r,`checked`,e))})});q.trackEffect(r,s)}function Qt(e,n){let r=(0,t.default)(e.el);r.on(n),e.trackCleanup(()=>r.off(n))}function $t(e,n,r){let i=(0,t.default)(e.el);i.on(n,r),e.trackCleanup(()=>i.off(n,r))}function en(e){q.cleanupTree(e)}function Z(e,t){for(let n=0,r=e.length;n<r;n++){let r=e[n];r.nodeType===1?t(Ht(r),r):G.enabled&&G.log(H.BINDING,`Skipping non-Element node (nodeType=${r.nodeType})`)}return e}t.default.fn.atomText=function(e,t){return Z(this,n=>Ut(n,e,t))},t.default.fn.atomHtml=function(e){return Z(this,t=>Wt(t,e))},t.default.fn.atomClass=function(e,t){if(typeof e==`string`&&t===void 0)return console.warn(`${H.BINDING} ${W.BINDING.MISSING_CONDITION(`atomClass`)}`),this;let n=typeof e==`string`?{[e]:t}:e;return Z(this,e=>Gt(e,n))},t.default.fn.atomCss=function(e,t,n){if(typeof e==`string`&&t===void 0)return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE(`atomCss`)}`),this;let r=typeof e==`string`?{[e]:n?[t,n]:t}:e;return Z(this,e=>Kt(e,r))},t.default.fn.atomAttr=function(e,t){if(typeof e==`string`&&t===void 0)return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE(`atomAttr`)}`),this;let n=typeof e==`string`?{[e]:t}:e;return Z(this,e=>qt(e,n))},t.default.fn.atomProp=function(e,t){if(typeof e==`string`&&t===void 0)return console.warn(`${H.BINDING} ${W.BINDING.MISSING_SOURCE(`atomProp`)}`),this;let n=typeof e==`string`?{[e]:t}:e;return Z(this,e=>Jt(e,n))},t.default.fn.atomShow=function(e){return Z(this,t=>Yt(t,e,!1))},t.default.fn.atomHide=function(e){return Z(this,t=>Yt(t,e,!0))},t.default.fn.atomVal=function(e,t={}){return Z(this,n=>Xt(n,e,t))},t.default.fn.atomChecked=function(e){return Z(this,t=>Zt(t,e))},t.default.fn.atomOn=function(e,t){return Z(this,n=>$t(n,e,t))},t.default.fn.atomBind=function(e){let{text:t,html:n,class:r,css:i,attr:a,prop:o,show:s,hide:c,val:l,checked:u,on:d}=e,f=l===void 0?null:Array.isArray(l)?{atom:l[0],opts:l[1]}:{atom:l,opts:void 0};return Z(this,e=>{t!==void 0&&Ut(e,t),n!==void 0&&Wt(e,n),r!==void 0&&Gt(e,r),i!==void 0&&Kt(e,i),a!==void 0&&qt(e,a),o!==void 0&&Jt(e,o),s!==void 0&&Yt(e,s,!1),c!==void 0&&Yt(e,c,!0),f!==null&&Xt(e,f.atom,f.opts),u!==void 0&&Zt(e,u),d!==void 0&&Qt(e,d)})},t.default.fn.atomUnbind=function(){for(let e=0,t=this.length;e<t;e++){let t=this[e];t.nodeType===1&&en(t)}return this};var tn=new WeakMap,nn=0,rn=new nt(()=>new Map,e=>e.clear()),an=new nt(()=>new Set,e=>e.clear()),Q=new tt(100,1024);function on(e,t,n){t?.isConnected?e.insertBefore(t):e.appendTo(n)}function $(e){return e instanceof Element?(0,t.default)(e):e}var sn=class{constructor(e,t,n){this.$container=e,this.containerSelector=t,this.onRemove=n,this.oldKeys=[],this.oldItems=[],this.oldNodes=[],this.removingKeys=new Set,this.$emptyEl=null,this.keyToIndex=new Map,this.statesBuffer=new Uint8Array(256),this.indicesBuffer=new Int32Array(256)}scheduleRemoval(e,t){let n=()=>{this.fx?.isDisposed||(t.remove(),this.removingKeys.delete(e),G.log(H.LIST,`${this.containerSelector} removed item:`,e))};if(!this.onRemove){n();return}let r=this.onRemove(t);r instanceof Promise?r.then(n,n):n()}removeItem(e,t){for(let e=0;e<t.length;e++){let n=t[e];n instanceof Element&&n.removeAttribute(`data-atom-key`)}this.removingKeys.add(e),this.scheduleRemoval(e,t)}dispose(){this.removingKeys.clear(),this.oldKeys.length=0,this.oldItems.length=0,this.oldNodes.length=0,this.keyToIndex.clear(),this.$emptyEl?.remove(),this.$container.off(`.atomList`);let e=new Uint8Array,t=new Int32Array;this.statesBuffer=e,this.indicesBuffer=t}ensureBuffers(e){this.statesBuffer.length<e&&(this.statesBuffer=new Uint8Array(Math.max(e,this.statesBuffer.length*2))),this.indicesBuffer.length<e&&(this.indicesBuffer=new Int32Array(Math.max(e,this.indicesBuffer.length*2)))}};function cn(e,n,r,i){if(e.$emptyEl&&n>0&&(e.$emptyEl.remove(),e.$emptyEl=null),n!==0)return;let{oldKeys:a,oldNodes:o,onRemove:s}=e;if(s)for(let t=0,n=a.length;t<n;t++){let n=a[t],r=o[t];r&&e.removeItem(n,$(r))}else{for(let t=0,n=a.length;t<n;t++)e.removingKeys.delete(a[t]);r.empty()}i&&!e.$emptyEl&&(e.$emptyEl=(0,t.default)(typeof i==`string`?Ft(i):i).appendTo(r)),Q.release(e.oldKeys),Q.release(e.oldItems),Q.release(e.oldNodes),e.oldKeys=[],e.oldItems=[],e.oldNodes=[]}function ln(e,t,n,r,i,a){let{oldKeys:o,oldItems:s,oldNodes:c,removingKeys:l,keyToIndex:u}=e,d=o.length,f=0,p=d-1,m=n-1;for(;f<=p&&f<=m;){let e=t[f],n=r(e,f);if(o[f]!==n)break;let i=s[f];if(!(a?a(i,e):Ie(i,e)))break;u.set(n,f),f++}for(;p>=f&&m>=f;){let e=t[m],n=r(e,m);if(o[p]!==n)break;let i=s[p];if(!(a?a(i,e):Ie(i,e)))break;u.set(n,m),p--,m--}let h=rn.acquire();for(let e=f;e<=p;e++)h.set(o[e],e);let g=Q.acquire();g.length=n;let _=an.acquire();e.ensureBuffers(n);let v=Q.acquire();v.length=n;let y=Q.acquire();y.length=n;let b=e.statesBuffer,x=e.indicesBuffer,S=Q.acquire(),C=Q.acquire(),w=Q.acquire();for(let e=0;e<f;e++)g[e]=o[e],v[e]=t[e],y[e]=c[e],b[e]=3,x[e]=e;for(let e=d-1,r=n-1;r>m;r--,e--)g[r]=o[e],v[r]=t[r],y[r]=c[e],b[r]=3,x[r]=e;for(let n=f;n<=m;n++){let o=t[n],d=r(o,n);if(g[n]=d,v[n]=o,u.set(d,n),_.has(d)){G.warn(H.LIST,W.LIST.DUPLICATE_KEY(d,n,e.containerSelector)),x[n]=-1;continue}_.add(d);let f=h.get(d);if(f===void 0){S.push(d),C.push(o),w.push(n),x[n]=-1,b[n]=1;continue}let p=s[f];y[n]=c[f];let m=a?a(p,o):Ie(p,o);!i&&p!==o&&!m?(S.push(d),C.push(o),w.push(n),b[n]=2):b[n]=0,x[n]=l.has(d)?-1:f}return rn.release(h),{newKeys:g,newKeySet:_,newItems:v,newNodes:y,newStates:b,newIndices:x,trKeys:S,trItems:C,trIdxs:w,startIndex:f,oldEndIndex:p,newEndIndex:m}}function un(e,n,r){let{trKeys:i,trItems:a,trIdxs:o,newNodes:s,newStates:c}=e,l=i.length,u=n.render,d=Array(l),f=[],p=0;for(let e=0;e<l;e++){let t=u(a[e],o[e]);d[e]=t,typeof t==`string`&&(f.push(t),p++)}let m=null,h=f.length;if(h>0)if(h===1)m=[Ft(f[0])];else{let e=`<template data-atom-sep="${(nn++).toString(36)}"></template>`;m=Ft(f.join(e)).split(e)}if(r&&m&&p===l&&!n.bind&&!n.onAdd&&!n.onRemove&&!n.events)return m;let g=0;for(let e=0;e<l;e++){let n=d[e],r=typeof n==`string`?(0,t.default)(m[g++]):(0,t.default)(n),a=o[e],l=c[a],u=i[e],f=String(u);for(let e=0,t=r.length;e<t;e++){let t=r[e];t instanceof Element&&t.setAttribute(`data-atom-key`,f)}if(l===2){let e=s[a];if(e){let t=$(e);for(let e=0,n=t.length;e<n;e++){let n=t[e];n&&q.cleanupTree(n)}t.replaceWith(r)}}s[a]=r.length===1?r[0]:r}return null}function dn(e,t){let{startIndex:n,oldEndIndex:r,newKeySet:i}=t,{oldKeys:a,oldNodes:o}=e;for(let t=n;t<=r;t++){let n=a[t];if(i.has(n))continue;let r=o[t];r&&e.removeItem(n,$(r))}}function fn(e,n,r,i,a,o){let{bind:s,update:c,onAdd:l}=a,{newKeys:u,newItems:d,newNodes:f,newStates:p,newIndices:m}=n,h=u.length,g=e.oldKeys.length===0;if(o!==null){r.innerHTML=o.join(``);let n=r.firstElementChild;for(let r=0;r<h&&n;r++){let i=u[r];n.setAttribute(`data-atom-key`,String(i)),f[r]=n,p[r]=0,e.removingKeys.delete(i),G.enabled&&G.domUpdated(H.LIST,(0,t.default)(n),`list.add`,d[r]),n=n.nextElementSibling}return}if(g){let e=document.createDocumentFragment();for(let t=0;t<h;t++){let n=f[t];if(n instanceof Element)e.appendChild(n);else for(let t=0;t<n.length;t++)e.appendChild(n[t])}r.appendChild(e)}else{let e=null,t=2147483647;for(let n=h-1;n>=0;n--){let r=m[n],a=f[n];r!==-1&&r<t?t=r:on($(a),e,i),e=a instanceof Element?a:a[0]??null}}for(let t=0;t<h;t++){let n=f[t],r=p[t];if(r!==3){let i=$(n),a=d[t];if(r===0?c?.(i,a,t):s?.(i,a,t),r===1){l?.(i);let n=u[t];e.removingKeys.delete(n),G.enabled&&G.domUpdated(H.LIST,i,`list.add`,d[t])}}}}t.default.fn.atomList=function(e,n){let{key:r,bind:i,update:a,onAdd:o,onRemove:s,empty:c,events:l,isEqual:u}=n,d=typeof r==`function`?r:(e,t)=>e[r],f={bind:i,update:a,onAdd:o,onRemove:s,events:l};for(let r=0,i=this.length;r<i;r++){let i=this[r],o=(0,t.default)(i);o.off(`.atomList`);let p=tn.get(i);p&&(p.fx.dispose(),p.ctx.dispose());let m=B(i),h=new sn(o,m,s),g=z(()=>{let t=e.value,r=t.length;k(()=>{if(cn(h,r,o,c),r===0)return;G.log(H.LIST,`${m} updating with ${r} items`);let e=ln(h,t,r,d,a,u),s=un(e,n,h.oldKeys.length===0);if(dn(h,e),fn(h,e,i,o,f,s),l){let{startIndex:t,oldEndIndex:n,newKeySet:r}=e;for(let e=t;e<=n;e++){let t=h.oldKeys[e];r.has(t)||h.keyToIndex.delete(t)}}Q.release(h.oldKeys),Q.release(h.oldItems),Q.release(h.oldNodes),h.oldKeys=e.newKeys,h.oldItems=e.newItems,h.oldNodes=e.newNodes,an.release(e.newKeySet),Q.release(e.trKeys),Q.release(e.trItems),Q.release(e.trIdxs)})});if(h.fx=g,l)for(let e in l){if(!V.call(l,e))continue;let t=l[e],n=e.indexOf(` `),r=n===-1?e:e.slice(0,n),i=(n===-1?null:e.slice(n+1).trim())||`> *`;o.on(`${r}.atomList`,i,function(e){let n=e.target.closest?.(`[data-atom-key]`);if(!n)return;let r=n.getAttribute(`data-atom-key`);if(r===null)return;let i=r;if(!h.keyToIndex.has(r)){let e=Number(r);!Number.isNaN(e)&&h.keyToIndex.has(e)&&(i=e)}let a=h.keyToIndex.get(i);a!==void 0&&t.call(n,h.oldItems[a],a,e)})}q.trackEffect(i,g),tn.set(i,{fx:g,ctx:h}),q.trackCleanup(i,()=>{h.dispose(),tn.delete(i)})}return this};var pn=Object.freeze({});t.default.fn.atomMount=function(e,n){let r=n??pn;for(let n=0,i=this.length;n<i;n++){let i=this[n];if(!i)continue;q.cleanupTree(i);let a=(0,t.default)(i),o;try{o=k(()=>e(a,r))}catch(t){G.error(H.MOUNT,W.MOUNT.ERROR(e.name),t);continue}typeof o==`function`&&q.setComponentCleanup(i,o)}return this},t.default.fn.atomUnmount=function(){for(let e=0,t=this.length;e<t;e++){let t=this[e];t&&en(t)}return this};function mn(e,t){try{return history.pushState(e,``,t),!0}catch(e){return G.warn(H.ROUTE,`PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.`,e),!1}}var hn=class{constructor(e){this.isDestroyed=!1,this.previousRoute=``,this.cleanups=[],this.templateCache=new Map,this.routeCleanups=[],this.lastRawQuery=``,this.cachedParams={},this.config={...e,mode:e.mode??U.mode,basePath:e.basePath??U.basePath,autoBindLinks:e.autoBindLinks??U.autoBindLinks,activeClass:e.activeClass??U.activeClass},this.isHistoryMode=this.config.mode===`history`,this.$target=(0,t.default)(this.config.target),this.normalizedBasePath=this.config.basePath?.replace(/\/$/,``)||``,this.activeClass=this.config.activeClass??U.activeClass,this.previousUrl=this.isHistoryMode?window.location.pathname+window.location.search:window.location.hash,this.currentRouteAtom=Te(this.getRouteName()),this.currentRoute=this.currentRouteAtom,this.queryParamsAtom=Te(this.getQueryParams()),this.queryParams=R(()=>this.queryParamsAtom.value),this.handleUrlChange=this.handleUrlChange.bind(this),this.destroy=this.destroy.bind(this),this.init()}init(){let e=this.isHistoryMode?`popstate`:`hashchange`;window.addEventListener(e,this.handleUrlChange),this.cleanups.push(()=>window.removeEventListener(e,this.handleUrlChange));let t=z(()=>{let e=this.currentRouteAtom.value;k(()=>{let e=this.routeCleanups;for(let t=0,n=e.length;t<n;t++)try{e[t]()}catch(e){G.warn(H.ROUTE,`Cleanup error during route transition:`,e)}e.length=0}),this.renderRoute(e)});this.cleanups.push(()=>t.dispose()),this.setupAutoBindLinks(),this.$target[0]&&q.trackCleanup(this.$target[0],this.destroy)}getRouteName(){let e=this.config.default;if(this.isHistoryMode){let t=window.location.pathname,n=0,r=this.normalizedBasePath;return r&&t.startsWith(r)&&(n=r.length),t.charCodeAt(n)===47&&n++,(n===0?t:t.substring(n))||e}let t=window.location.hash;if(t.length<=1)return e;let n=t.indexOf(`?`);return(n===-1?t.substring(1):t.substring(1,n))||e}getQueryParams(){let e=``;if(this.isHistoryMode)e=window.location.search.substring(1);else{let t=window.location.hash,n=t.indexOf(`?`);n!==-1&&(e=t.substring(n+1))}if(e===this.lastRawQuery)return this.cachedParams;let t={};e&&new URLSearchParams(e).forEach((e,n)=>{t[n]=e});let n=!1,r=this.cachedParams,i=Object.keys(r),a=Object.keys(t);if(i.length!==a.length)n=!0;else for(let e=0,i=a.length;e<i;e++){let i=a[e];if(r[i]!==t[i]){n=!0;break}}return n&&(this.cachedParams=t),this.lastRawQuery=e,e.includes(`%`),this.cachedParams}setUrl(e){if(this.isHistoryMode){let t=`${this.normalizedBasePath}/${e}`;mn(null,t),this.previousUrl=t}else{let t=`#${e}`;window.location.hash=t,this.previousUrl=t}}restoreUrl(){this.isHistoryMode?mn(null,this.previousUrl):window.location.hash=this.previousUrl}getCurrentUrl(){return this.isHistoryMode?window.location.pathname+window.location.search:window.location.hash}getRouteConfig(e){let{routes:t,notFound:n}=this.config,r=t[e];return!r&&n&&(r=t[n]),r||(G.warn(H.ROUTE,W.ROUTE.NOT_FOUND(e)),null)}renderTemplate(e){let t=this.templateCache.get(e);if(!t){let n=document.querySelector(e);if(!n||!(n instanceof HTMLTemplateElement))return G.warn(H.ROUTE,W.ROUTE.TEMPLATE_NOT_FOUND(e)),!1;t=n,this.templateCache.set(e,t)}let n=t.content.cloneNode(!0);return this.$target.append(n),!0}renderRoute(e){if(this.isDestroyed)return;let t=this.$target[0];if(!t){G.warn(H.ROUTE,W.ROUTE.TARGET_NOT_FOUND(this.config.target));return}let n=this.getRouteConfig(e);if(!n)return;let r=this.getQueryParams(),i=this.previousRoute,{beforeTransition:a,afterTransition:o}=this.config;a&&k(()=>a(i,e)),this.$target.empty();let s=r,{onEnter:c}=n;if(c){let e=k(()=>c(r,this));e!==void 0&&(s={...r,...e})}let l=e=>{this.routeCleanups.push(e)};n.render?n.render(t,e,s,l,this):n.template&&this.renderTemplate(n.template)&&n.onMount&&n.onMount(this.$target.children(),l,this),o&&k(()=>o(i,e)),this.previousRoute=e}handleUrlChange(){if(this.isDestroyed)return;let e=this.getCurrentUrl();if(e===this.previousUrl)return;let t=this.getRouteName(),n=this.currentRouteAtom.peek(),r=this.getQueryParams();if(n!==t){let e=this.config.routes[n];if(e?.onLeave&&k(()=>e.onLeave(this))===!1){this.restoreUrl();return}this.currentRouteAtom.value=t,this.queryParamsAtom.value=r}else this.queryParamsAtom.value=r;this.previousUrl=e}setupAutoBindLinks(){if(!this.config.autoBindLinks)return;let e=e=>{e.preventDefault();let t=e.currentTarget.dataset.route;t!=null&&this.navigate(t)};(0,t.default)(document).on(`click`,`[data-route]`,e),this.cleanups.push(()=>{(0,t.default)(document).off(`click`,`[data-route]`,e)});let n=this.activeClass,r=[],i=z(()=>{let e=this.currentRouteAtom.value;k(()=>{for(let e=0,t=r.length;e<t;e++){let t=r[e];t.classList.remove(n),t.removeAttribute(`aria-current`)}try{let t=e.replace(/"/g,`\\"`),i=document.querySelectorAll(`[data-route="${t}"]`),a=i.length,o=Array(a);for(let e=0;e<a;e++){let t=i[e];t.classList.add(n),t.setAttribute(`aria-current`,`page`),o[e]=t}r=o}catch{r=[]}})});this.cleanups.push(()=>i.dispose())}navigate(e){if(this.isDestroyed)return;let t=this.currentRouteAtom.peek(),n=this.config.routes[t];if(n?.onLeave&&n.onLeave(this)===!1)return;let r=e||this.config.default;if(!r){G.warn(H.ROUTE,`navigate() called with empty routeName and no default configured.`);return}this.setUrl(r),this.queryParamsAtom.value={},this.currentRouteAtom.value=r}destroy(){if(this.isDestroyed)return;this.isDestroyed=!0;let e=this.cleanups;this.cleanups=[];for(let t=0,n=e.length;t<n;t++)try{e[t]()}catch(e){G.warn(H.ROUTE,`Cleanup error during destroy:`,e)}this.templateCache.clear()}};function gn(e){return new hn(e)}t.default.extend({route:gn});var _n=class{constructor(e,t){this.abortController=null,this.isStaticUrl=typeof e==`string`,this.isStaticUrl?this.staticUrl=e:this.getUrl=e,typeof t.ajaxOptions==`function`?(this.ajaxOptionsFn=t.ajaxOptions,this.staticOptions={}):this.staticOptions={...t.ajaxOptions},t.method!==void 0&&(this.staticOptions.method=t.method),t.headers!==void 0&&(this.staticOptions.headers={...this.staticOptions.headers,...t.headers}),this.transformFn=t.transform,this.onErrorFn=t.onError,this.execute=this.execute.bind(this)}abort(){this.abortController?.abort()}async execute(){this.abortController?.abort(),this.abortController=new AbortController;let e=this.abortController.signal,n=this.ajaxOptionsFn?this.ajaxOptionsFn():{},r=t.default.extend(!0,{},this.staticOptions,n);r.success=void 0,r.error=void 0,r.complete=void 0,r.url=this.isStaticUrl?this.staticUrl:this.getUrl();let i=t.default.ajax(r);e.onabort=()=>i.abort(),e.aborted&&i.abort();let a;try{a=await i}catch(t){if(e.aborted){let e=Error(`AbortError`);throw e.name=`AbortError`,e}let n;if(t&&t.readyState!==void 0){let e=t;n=Error(`Network Error: ${e.statusText||`Unknown`} (${e.status})`),n.jqXHR=e}else n=t instanceof Error?t:Error(String(t??`Unknown network error`));let r=this.onErrorFn;if(r)try{r(n)}catch{}throw n}finally{e.onabort=null,this.abortController?.signal===e&&(this.abortController=null)}let o=this.transformFn;if(o)try{return o(a)}catch(e){let t=this.onErrorFn;if(t)try{t(e)}catch{}throw e}return a}};t.default.extend({atomFetch(e,t){let n=new _n(e,t),r=!(t.eager??!0),i=R(n.execute,{defaultValue:t.defaultValue,lazy:r});return Object.assign(i,{abort:()=>n.abort()})}}),(0,t.default)(()=>{mt(),st(document.body)});var vn=t.default;e.atom=Te,e.batch=Pe,e.computed=R,e.default=vn,e.disableAutoCleanup=ct,e.disablejQueryOverrides=ht,e.effect=z,e.enableAutoCleanup=st,e.enablejQueryOverrides=mt,e.isAtom=A,e.isComputed=De,e.isReactive=Fe,e.nextTick=$e,e.registry=q,e.untracked=k});
3
+ //# sourceMappingURL=atom-effect-jquery.min.js.map