@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 +4 -1
- package/dist/atom-effect-jquery.min.js +3 -3
- package/dist/atom-effect-jquery.min.js.map +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.mjs +2374 -2416
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("jquery"),ct={IDLE:"idle",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"},w={DISPOSED:1,EXECUTING:8},Zt={DISPOSED:1,IS_COMPUTED:2,DIRTY:8,IDLE:16,PENDING:32,RESOLVED:64,REJECTED:128,RECOMPUTING:256,HAS_ERROR:512},M={DISPOSED:1,SYNC:8,NOTIFICATION_SCHEDULED:16},V={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},be={WARN_INFINITE_LOOP:!0},Mt={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:Number.MAX_SAFE_INTEGER-1},Q={UNINITIALIZED:-1},It=1073741823,Re=typeof process<"u"&&process.env&&!1||!1,ve=Object.freeze([]);function Ft(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 ut{constructor(t,e,s=void 0){this.node=t,this.version=e,this.unsub=s}}class De{constructor(t,e){this.fn=t,this.sub=e}notify(t,e){this.fn?this.fn(t,e):this.sub&&this.sub.execute()}}class W extends Error{constructor(t,e=null,s=!0){super(t),this.cause=e,this.recoverable=s,this.name="AtomError"}}class z extends W{constructor(t,e=null){super(t,e,!0),this.name="ComputedError"}}class q extends W{constructor(t,e=null){super(t,e,!1),this.name="EffectError"}}class Tt extends W{constructor(t,e=null){super(t,e,!1),this.name="SchedulerError"}}const R={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"},Oe=Symbol("AtomEffect.DebugName"),Le=Symbol("AtomEffect.Type"),St=Symbol("AtomEffect.NoDefaultValue"),kt={enabled:Re,warnInfiniteLoop:be.WARN_INFINITE_LOOP,warn(n,t){},attachDebugInfo(n,t,e){},getDebugName:n=>n?.[Oe],getDebugType:n=>n?.[Le]};let ke=1;const Ae=()=>ke++;function Y(n,t,e){if(n instanceof W)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 Jt{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=Q.UNINITIALIZED,this.id=Ae()&It}}class te extends Jt{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"),W,R.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 De(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,W,R.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}}let Nt=0;const At=()=>(Nt=Nt+1&It||1,Nt),Ot=n=>n+1&It;let Ut=0,ft=!1,ee=0;const se=()=>ee;function Bt(){return ft?!1:(ft=!0,ee=At(),Ut=0,!0)}const Gt=()=>{ft=!1},Ue=()=>ft?++Ut:0;class we{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=V.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=Bt();this._drainQueue(),t&&Gt()}finally{this._isProcessing=!1,this._size>0&&!this._isBatching&&this._flush()}}_flushSync(){this._isFlushingSync=!0;const t=Bt();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,t&&Gt()}}_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>V.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(R.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<V.MIN_FLUSH_ITERATIONS)throw new Tt(`Max flush iterations must be at least ${V.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=t}}const ot=new we,wt=Symbol.for("atom-effect/atom"),ne=Symbol.for("atom-effect/computed"),xe=Symbol.for("atom-effect/effect"),$e=Symbol.for("atom-effect/writable"),$={current:null,run(n,t){const e=this.current;this.current=n;try{return t()}finally{this.current=e}}};function P(n){const t=$.current;if(t===null)return n();$.current=null;try{return n()}finally{$.current=t}}var Ht,jt;class Pe extends te{constructor(t,e){super(),this._pendingOldValue=void 0,this._subscribers=[],this[jt]=!0,this[Ht]=!0,this._value=t,e&&(this.flags|=M.SYNC),kt.attachDebugInfo(this,"atom",this.id)}get value(){return $.current?.addDependency(this),this._value}set value(t){const e=this._value;if(Object.is(e,t))return;this._value=t,this.version=Ot(this.version);const s=this.flags;if(!(this._subscribers.length===0||s&M.NOTIFICATION_SCHEDULED)){if(this._pendingOldValue=e,this.flags=s|M.NOTIFICATION_SCHEDULED,s&M.SYNC&&!ot.isBatching){this._flushNotifications();return}ot.schedule(this)}}execute(){this._flushNotifications()}_flushNotifications(){const t=this.flags;if(!(t&M.NOTIFICATION_SCHEDULED)||t&M.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&M.DISPOSED||(this._subscribers.length=0,this.flags|=M.DISPOSED,this._value=void 0,this._pendingOldValue=void 0)}[(jt=wt,Ht=$e,Symbol.dispose)](){this.dispose()}}function dt(n,t={}){return new Pe(n,t.sync??!1)}class Me{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 L=Object.freeze([]),F=new Me;function yt(n){return n!==null&&typeof n=="object"&&wt in n}function ie(n){return n!==null&&typeof n=="object"&&ne in n}function oe(n){return n!==null&&typeof n=="object"&&typeof n.then=="function"}var Vt,zt;const{IDLE:at,DIRTY:K,PENDING:ht,RESOLVED:j,REJECTED:it,HAS_ERROR:lt,RECOMPUTING:tt,DISPOSED:bt,IS_COMPUTED:Fe}=Zt;function Be(n){return n&j?ct.RESOLVED:n&ht?ct.PENDING:n&it?ct.REJECTED:ct.IDLE}class Ge extends te{constructor(t,e={}){if(typeof t!="function")throw new z(R.COMPUTED_MUST_BE_FUNCTION);super(),this[zt]=!0,this[Vt]=!0,this._error=null,this._promiseId=0,this._subscribers=[],this._links=L,this._asyncStartAggregateVersion=0,this._asyncRetryCount=0,this._lastDriftEpoch=Q.UNINITIALIZED,this._trackEpoch=Q.UNINITIALIZED,this._trackLinks=L,this._trackCount=0,this._value=void 0,this.flags=Fe|K|at,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??Mt.MAX_ASYNC_RETRIES)&It,kt.attachDebugInfo(this,"computed",this.id),e.lazy===!1)try{this._recompute()}catch{}}_track(){$.current?.addDependency(this)}get value(){this._track();const t=this.flags;if((t&(j|K|at))===j)return this._value;if(t&bt)throw new z(R.COMPUTED_DISPOSED);if(t&tt){if(this._defaultValue!==St)return this._defaultValue;throw new z(R.COMPUTED_CIRCULAR_DEPENDENCY)}if(t&(K|at)&&(this._recompute(),this.flags&j))return this._value;const e=this._defaultValue,s=e!==St;if(this.flags&ht){if(s)return e;throw new z(R.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if(this.flags&it){if(s)return e;throw this._error}return this._value}peek(){return this._value}get state(){return this._track(),Be(this.flags)}get hasError(){return this._track(),this.flags&(it|lt)?!0:this._links.some(t=>t?.node?.flags<)}get isValid(){return!this.hasError}get errors(){if(this._track(),!this.hasError)return ve;const t=[];return this._error&&t.push(this._error),this._links.forEach(e=>{const s=e.node;s.flags<&&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&ht)!==0}get isResolved(){return this._track(),(this.flags&j)!==0}invalidate(){this._markDirty()}dispose(){if(this.flags&bt)return;const t=this._links;t!==L&&(t.forEach(e=>e.unsub?.()),F.release(t),this._links=L),this._subscribers.length=0,this.flags=bt|K|at,this._error=null,this._value=void 0}[(zt=wt,Vt=ne,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=F.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 ut(t,t.version):this._trackLinks.push(new ut(t,t.version)),this._trackCount++}}_recompute(){if(this.flags&tt)return;this.flags|=tt;const t=this._links;this._trackEpoch=At(),this._trackLinks=t,this._trackCount=0;let e=!1;try{const s=$.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,Ft(this._trackLinks,t,this),this._links=this._trackLinks,e=!0;oe(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,Ft(this._trackLinks,t,this),this._links=this._trackLinks,e=!0}catch{}this._handleError(s,R.COMPUTED_COMPUTATION_FAILED,!0)}finally{e?this._links!==t&&t!==L&&F.release(t):this._trackLinks!==t&&this._trackLinks!==L&&F.release(this._trackLinks),this._trackEpoch=Q.UNINITIALIZED,this._trackLinks=L,this._trackCount=0,this.flags&=~tt}}_handleAsyncComputation(t){this.flags=(this.flags|ht)&-217,this._notifySubscribers(void 0,void 0),this._asyncStartAggregateVersion=this._captureVersionSnapshot(),this._asyncRetryCount=0,this._promiseId=(this._promiseId+1)%Mt.MAX_PROMISE_ID;const e=this._promiseId;t.then(s=>{if(e===this._promiseId){if(this._captureVersionSnapshot()!==this._asyncStartAggregateVersion){const i=se();return this._lastDriftEpoch!==i&&(this._lastDriftEpoch=i,this._asyncRetryCount=0),this._asyncRetryCount++<this._maxAsyncRetries?this._markDirty():this._handleError(new z(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`),R.COMPUTED_ASYNC_COMPUTATION_FAILED)}this._finalizeResolution(s),this._notifySubscribers(s,void 0)}},s=>e===this._promiseId&&this._handleError(s,R.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,z,e);if(!s&&!(this.flags&it)&&(this.version=Ot(this.version)),this._error=i,this.flags=this.flags&-121|it|lt,this._onError)try{this._onError(i)}catch(o){console.error(R.CALLBACK_ERROR_IN_ERROR_HANDLER,o)}if(s)throw i;this._notifySubscribers(void 0,void 0)}_finalizeResolution(t){(!(this.flags&j)||!this._equal(this._value,t))&&(this.version=Ot(this.version)),this._value=t,this._error=null,this.flags=(this.flags|j)&-697}execute(){this._markDirty()}_markDirty(){this.flags&(tt|K)||(this.flags|=K,this._notifySubscribers(void 0,void 0))}}function rt(n,t={}){return new Ge(n,t)}var Kt;class He extends Jt{constructor(t,e={}){super(),this[Kt]=!0,this._cleanup=null,this._links=L,this._nextLinks=null,this._prevLinks=L,this._currentEpoch=Q.UNINITIALIZED,this._lastFlushEpoch=Q.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??V.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=e.maxExecutionsPerFlush??V.MAX_EXECUTIONS_PER_EFFECT,this._sync?this._notifyCallback=()=>this.execute():this._notifyCallback=()=>ot.schedule(this),kt.attachDebugInfo(this,"effect",this.id)}run(){if(this.flags&w.DISPOSED)throw new q(R.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.flags&w.DISPOSED||(this.flags|=w.DISPOSED,this._execCleanup(),this._unsubLinks(this._links),this._links!==L&&F.release(this._links),this._links=L,this._prevLinks=L)}[(Kt=xe,Symbol.dispose)](){this.dispose()}addDependency(t){if(!(this.flags&w.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=F.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 ut(t,t.version,r)}catch(r){const c=Y(r,q,R.EFFECT_EXECUTION_FAILED);if(console.error(c),this._onError)try{this._onError(c)}catch{}i[this._trackCount]=new ut(t,t.version,void 0)}this._trackCount++}execute(t=!1){if(this.flags&(w.DISPOSED|w.EXECUTING)||!t&&this._links.length>0&&!this._isDirty())return;this._checkInfiniteLoops(),this.flags|=w.EXECUTING,this._execCleanup(),this._prevLinks=this._links,this._nextLinks=this._links,this._currentEpoch=At(),this._trackCount=0;let e=!1;try{const s=$.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,oe(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&w.DISPOSED){if(typeof s=="function")try{s()}catch(i){this._handleExecutionError(i,R.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=L,t?s!==e&&e!==L&&(e.forEach(i=>i?.unsub?.()),F.release(e)):s!==e&&s!==L&&s&&(this._unsubLinks(s),F.release(s))}_unsubLinks(t){t.forEach(e=>e?.unsub?.())}_isDirty(){const t=this._links,e=$.current;$.current=null;try{return t.some(s=>{const i=s.node;if(i.flags&Zt.IS_COMPUTED)try{i.value}catch{return!0}return i.version!==s.version})}finally{$.current=e}}_execCleanup(){if(this._cleanup){try{this._cleanup()}catch(t){this._handleExecutionError(t,R.EFFECT_CLEANUP_FAILED)}this._cleanup=null}}_checkInfiniteLoops(){const t=se();this._lastFlushEpoch!==t&&(this._lastFlushEpoch=t,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError("per-effect"),Ue()>V.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError("global"),this._executionCount++}get isDisposed(){return(this.flags&w.DISPOSED)!==0}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&w.EXECUTING)!==0}_throwInfiniteLoopError(t){const e=new q(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${Ut}`);throw this.dispose(),console.error(e),e}_handleExecutionError(t,e=R.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,R.CALLBACK_ERROR_IN_ERROR_HANDLER))}}}function B(n,t={}){if(typeof n!="function")throw new q(R.EFFECT_MUST_BE_FUNCTION);const e=new He(n,t);return e.execute(),e}function xt(n){if(typeof n!="function")throw new TypeError(R.BATCH_CALLBACK_MUST_BE_FUNCTION);ot.startBatch();try{return n()}finally{ot.endBatch()}}const E={ROUTE:"[atom-route]",BINDING:"[atom-binding]",LIST:"[atom-list]",MOUNT:"[atom-mount]"},et=Object.freeze({mode:"hash",basePath:"",autoBindLinks:!1,activeClass:"active"}),je={EVENT:"input"},re={HIGHLIGHT_DURATION_MS:500},Ve=new Set(["input","select","textarea"]),ze=new Set(["src","href","action","formaction","data","poster","background","cite","longdesc","profile","usemap","classid","codebase","xlink:href"]),Ke=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 $t(n){return yt(n)}function X(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 Z=Object.prototype.hasOwnProperty;function qe(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(!Z.call(o,c)||i[c]!==o[c])return!1}return!0}function Xe(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 l=0,u=i-1;for(;l<u;){const y=l+u>>>1,p=s[y];p!==void 0&&(n[p]??-1)<c?l=y+1:u=y}const _=s[l];_!==void 0&&c<(n[_]??Number.MAX_SAFE_INTEGER)&&(l>0&&(e[r]=s[l-1]??-1),s[l]=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},Ye=`${re.HIGHLIGHT_DURATION_MS/1e3}s`;function We(){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 qt=We();const d={get enabled(){if(typeof window<"u"){const n=window.__ATOM_DEBUG__;if(typeof n=="boolean")return n}return qt},set enabled(n){qt=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: ${X(i)}.${e} =`,s),Je(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)}},Lt="atom-debug-highlight",Xt="data-atom-debug";let st;function Ze(){if((st instanceof HTMLStyleElement?st:st?.deref())?.isConnected||document.querySelector(`style[${Xt}]`))return;const t=document.createElement("style");t.setAttribute(Xt,""),t.textContent=`.${Lt}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline ${Ye} ease-out}`,document.head.appendChild(t),typeof WeakRef<"u"?st=new WeakRef(t):st=t}const Rt=new WeakMap,vt=new WeakMap;function Je(n){if(!d.enabled||!n.isConnected)return;Ze();const t=vt.get(n);t!==void 0&&cancelAnimationFrame(t);const e=Rt.get(n);e!==void 0&&clearTimeout(e);const s=requestAnimationFrame(()=>{vt.delete(n),n.isConnected&&(n.classList.add(Lt),Rt.set(n,setTimeout(()=>{n.isConnected&&n.classList.remove(Lt),Rt.delete(n)},re.HIGHLIGHT_DURATION_MS)))});vt.set(n,s)}function ce(n,t){return dt(n,t)}Object.defineProperty(ce,"debug",{enumerable:!0,configurable:!0,get(){return d.enabled},set(n){d.enabled=n}});function ae(){return new Promise(n=>setTimeout(n,0))}const ts={atom:ce,computed:rt,effect:B,batch:xt,untracked:P,isAtom:yt,isComputed:ie,isReactive:$t,nextTick:ae};h.extend(ts);const H="_aes-bound";class es{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(H)),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(H),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(H),d.enabled){const s=t.nodeType===1?X(t):t.nodeName||"Node";d.cleanup(E.BINDING,s)}if(e.componentCleanup)try{e.componentCleanup()}catch(s){const i=t.nodeType===1?X(t):"Node";d.error(E.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?X(t):"Node";d.error(E.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?X(t):"Node";d.error(E.BINDING,S.BINDING.CLEANUP_ERROR(c),r)}}}cleanupDescendants(t){const e="getElementsByClassName"in t&&typeof t.getElementsByClassName=="function"?t.getElementsByClassName(H):t.querySelectorAll(`.${H}`);for(let s=e.length-1;s>=0;s--){const i=e[s];i&&(this.records.has(i)?this.cleanup(i):(i.classList.remove(H),d.enabled&&d.warn(E.BINDING,`${H} class found on unregistered element:`,i)))}}cleanupTree(t){(t.nodeType===1||t.nodeType===11)&&this.cleanupDescendants(t),this.cleanup(t)}}const b=new es,_t=new Map;function le(n){if(_t.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}),_t.set(n,t)}function ss(){_t.forEach(n=>n.disconnect()),_t.clear()}function G(n,t,e,s){if($t(t)){const i=t;b.trackEffect(n,B(()=>{const o=i.value;P(()=>{try{e(o)}catch(r){d.error(E.BINDING,S.BINDING.UPDATER_ERROR(s),r);return}d.enabled&&d.domUpdated(E.BINDING,n,s,o)})},{name:s}))}else P(()=>{try{e(t)}catch(i){d.error(E.BINDING,S.BINDING.UPDATER_ERROR(s,!0),i);return}d.enabled&&d.domUpdated(E.BINDING,n,s,t)})}const pt=Symbol("atom-effect-internal"),Et=new WeakMap;let x=null;const he=n=>{if(n[pt])return n;let t=Et.get(n);return t||(t=function(...e){return xt(()=>n.apply(this,e))},t[pt]=!0,Et.set(n,t)),t};function ns(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]=he(c))}return t}function is(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?Et.get(c)??c:void 0}return t}function ue(){if(x!==null)return;x={on:h.fn.on,off:h.fn.off,remove:h.fn.remove,empty:h.fn.empty,detach:h.fn.detach};const n=x;h.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},h.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},h.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},h.fn.on=function(...t){const e=t[0];if(e&&typeof e=="object")t[0]=ns(e);else{const i=t.length-1;i>=0&&typeof t[i]=="function"&&(t[i]=he(t[i]))}const s=n.on.apply(this,t);return s!==void 0?s:this},h.fn.off=function(...t){const e=t[0];if(e&&typeof e=="object")t[0]=is(e);else{const i=t.length-1;if(i>=0&&typeof t[i]=="function"){const o=t[i];t[i]=Et.get(o)??o}}const s=n.off.apply(this,t);return s!==void 0?s:this}}function os(){x!==null&&(h.fn.on=x.on,h.fn.off=x.off,h.fn.remove=x.remove,h.fn.empty=x.empty,h.fn.detach=x.detach,x=null)}var O=(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))(O||{});let rs=0;function nt(n){n[pt]=!0}class cs{constructor(t,e,s){this.flags=0,this.timeoutId=void 0,this.handleCompositionStart=()=>{this.flags|=O.Composing},this.handleCompositionEnd=()=>{this.flags&=~O.Composing,this.handleInput()},this.handleFocus=()=>{this.flags|=O.Focused},this.handleBlur=()=>{this.flags&=~O.Focused;const c=!!(this.flags&O.Composing);this.flags&=~O.Composing,this.flushPendingDebounce(),c&&this.timeoutId===void 0&&this.syncAtomFromDom(),this.normalizeDomValue()},this.syncDomFromAtom=()=>{const c=this.atom.value;P(()=>{const a=this.format(c);let l;if(this.isMultipleSelect?l=this.$el.val()||[]:l=this.el.value,this.equal(l,c))return;const u=!!(this.flags&O.Focused);if(u)try{const _=this.isMultipleSelect?l:this.parse(this.el.value);if(this.equal(_,c))return}catch{}this.flags|=O.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 p=a.length;_!==null&&y!==null&&this.el.setSelectionRange(_<p?_:p,y<p?y:p)}catch{this.el.value=a}else this.el.value=a;d.enabled&&d.domUpdated(E.BINDING,this.$el,"val",a)}finally{this.flags&=~O.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-${++rs}`;const i=s.debounce??0,o=s.event??je.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((l,u)=>Object.is(l,a[u])):!1,i>0?this.handleInput=()=>{this.flags&O.Composing||(clearTimeout(this.timeoutId),this.timeoutId=setTimeout(()=>this.syncAtomFromDom(),i))}:this.handleInput=()=>{this.flags&O.Composing||this.syncAtomFromDom()},nt(this.handleFocus),nt(this.handleBlur),nt(this.handleCompositionStart),nt(this.handleCompositionEnd),nt(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&O.Busy)){this.flags|=O.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(E.BINDING,S.BINDING.PARSE_ERROR(t instanceof Error?t.message:String(t)),t)}finally{this.flags&=~O.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 as(n,t,e){const s=new cs(n,t,e);return{fx:B(s.syncDomFromAtom),cleanup:s.cleanup}}const ls=new Set(["href","src","action","formaction","xlink:href","data","poster","background","cite","longdesc","profile","usemap","classid","codebase"]),hs=/^\s*(?:javascript|vbscript)\s*:/i,us=/(?: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,fs=/url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i,ds=/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,_s=/&#x([0-9a-f]+);?|&#([0-9]+);?/gi,ps={colon:":",Tab:" ",NewLine:`
|
|
2
|
-
`},Es=/&(colon|Tab|NewLine);/g,ms=/<\?[\s\S]*?\?>/g,gs=/(<(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,Is=/(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,ys=/data\s*:\s*(?:text\/(?:html|javascript|vbscript|xml)|application\/(?:javascript|xhtml\+xml|xml|x-shockwave-flash)|image\/svg\+xml)/gi,Cs=/\bon\w+\s*=/gim,Ts=new RegExp(us.source,"gim");function mt(n){let t=String(n??"");t=t.replace(ds,""),t=t.replace(_s,(s,i,o)=>String.fromCodePoint(i?parseInt(i,16):parseInt(o,10))),t=t.replace(Es,(s,i)=>ps[i]??""),t=t.replace(ms,"");let e;do e=t,t=t.replace(gs,"");while(t!==e);return t=t.replace(Is,"data-unsafe-protocol:"),t=t.replace(ys,"data-unsafe-protocol:"),t=t.replace(Cs,"data-unsafe-attr="),t=t.replace(Ts,"data-unsafe-css:"),t}function fe(n,t){return ls.has(n.toLowerCase())?hs.test(t):!1}function Ss(n){return n.toLowerCase().includes("url(")?fs.test(n):!1}const Qt=new Map;function Ns(n){let t=Qt.get(n);return t!==void 0||(t=n.includes("-")?n.replace(/-./g,e=>e[1].toUpperCase()):n,Qt.set(n,t)),t}const Yt=new WeakMap;function bs(n){let t=Yt.get(n);return t||(t=rt(()=>mt(n.value)),Yt.set(n,t)),t}function A(n){return{$el:h(n),el:n,trackCleanup:t=>b.trackCleanup(n,t)}}function de(n,t,e){const s=n.el;G(s,t,i=>{const o=e?e(i):typeof i=="string"?i:String(i??"");s.textContent!==o&&(s.textContent=o)},"text")}function _e(n,t){const e=n.el,s=yt(t)?bs(t):t;G(e,s,i=>{e.innerHTML!==i&&(b.cleanupDescendants(e),e.innerHTML=i)},"html")}function pe(n,t){for(const e in t)if(Z.call(t,e)){const s=t[e],i=e.trim().split(/\s+/).filter(Boolean);i.length>1?G(n.el,s,o=>{o?n.el.classList.add(...i):n.el.classList.remove(...i)},`class.${e}`):i.length===1&&G(n.el,s,o=>{n.el.classList.toggle(i[0],!!o)},`class.${e}`)}}function Ee(n,t){const e=n.el,s=e.style;for(const i in t)if(Z.call(t,i)){const o=t[i],r=Ns(i),[c,a]=Array.isArray(o)?o:[o,""];G(e,c,l=>{const u=a?String(l)+a:String(l);Ss(u)||(s[r]=u)},`css.${i}`)}}function me(n,t){const e=n.el;for(const s in t)if(Z.call(t,s)){const i=s.toLowerCase();if(i.startsWith("on")){console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`);continue}const o=i.startsWith("aria-");G(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(fe(s,c)){console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`);return}e.getAttribute(s)!==c&&e.setAttribute(s,c)},`attr.${s}`)}}function ge(n,t){const e=n.el;for(const s in t)if(Z.call(t,s)){const i=s.toLowerCase();if(i.startsWith("on")){console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_EVENT_HANDLER(s)}`);continue}if(Ke.has(s)){console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_PROP(s)}`);continue}const o=ze.has(i);G(n.el,t[s],r=>{if(o&&typeof r=="string"&&fe(s,r)){console.warn(`${E.BINDING} ${S.SECURITY.BLOCKED_PROTOCOL(s)}`);return}e[s]!==r&&(e[s]=r)},`prop.${s}`)}}function gt(n,t,e){const s=n.el,i=e?"hide":"show",o=s.style.display,r=o==="none"?"":o;G(s,t,c=>{s.style.display=e!==!!c?r:"none"},i)}function Ie(n,t,e={}){const s=n.el.tagName.toLowerCase();if(!Ve.has(s)){console.warn(`${E.BINDING} ${S.BINDING.INVALID_INPUT_ELEMENT(s)}`);return}const{fx:i,cleanup:o}=as(n.$el,t,e);b.trackEffect(n.el,i),n.trackCleanup(o)}function ye(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?h(e.form):h(document)).find(`input[type="radio"][name="${a}"]`).not(e).trigger("change.atomRadioSync")}};o[pt]=!0,s.on("change change.atomRadioSync",o),n.trackCleanup(()=>s.off("change change.atomRadioSync",o));const r=B(()=>{const c=!!t.value;P(()=>{e.checked!==c&&(e.checked=c,d.enabled&&d.domUpdated(E.BINDING,s,"checked",c))})});b.trackEffect(e,r)}function Rs(n,t){const e=n.$el;e.on(t),n.trackCleanup(()=>e.off(t))}function vs(n,t,e){const s=n.$el;s.on(t,e),n.trackCleanup(()=>s.off(t,e))}function Ce(n){b.cleanupTree(n)}function k(n){d.enabled&&d.log(E.BINDING,`Skipping non-Element node (nodeType=${n})`)}h.fn.atomText=function(n,t){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?de(A(i),n,t):k(i.nodeType)}return this};h.fn.atomHtml=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?_e(A(s),n):k(s.nodeType)}return this};h.fn.atomClass=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${E.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?pe(A(o),e):k(o.nodeType)}return this};h.fn.atomCss=function(n,t,e){if(typeof n=="string"&&t===void 0)return console.warn(`${E.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?Ee(A(r),s):k(r.nodeType)}return this};h.fn.atomAttr=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${E.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?me(A(o),e):k(o.nodeType)}return this};h.fn.atomProp=function(n,t){if(typeof n=="string"&&t===void 0)return console.warn(`${E.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?ge(A(o),e):k(o.nodeType)}return this};h.fn.atomShow=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?gt(A(s),n,!1):k(s.nodeType)}return this};h.fn.atomHide=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?gt(A(s),n,!0):k(s.nodeType)}return this};h.fn.atomVal=function(n,t={}){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?Ie(A(i),n,t):k(i.nodeType)}return this};h.fn.atomChecked=function(n){for(let t=0,e=this.length;t<e;t++){const s=this[t];s.nodeType===1?ye(A(s),n):k(s.nodeType)}return this};h.fn.atomOn=function(n,t){for(let e=0,s=this.length;e<s;e++){const i=this[e];i.nodeType===1?vs(A(i),n,t):k(i.nodeType)}return this};h.fn.atomBind=function(n){const{text:t,html:e,class:s,css:i,attr:o,prop:r,show:c,hide:a,val:l,checked:u,on:_}=n,y=l===void 0?null:Array.isArray(l)?{atom:l[0],opts:l[1]}:{atom:l,opts:void 0};for(let p=0,v=this.length;p<v;p++){const C=this[p];if(C.nodeType!==1){k(C.nodeType);continue}const T=A(C);t!==void 0&&de(T,t),e!==void 0&&_e(T,e),s!==void 0&&pe(T,s),i!==void 0&&Ee(T,i),o!==void 0&&me(T,o),r!==void 0&&ge(T,r),c!==void 0&>(T,c,!1),a!==void 0&>(T,a,!0),y!==null&&Ie(T,y.atom,y.opts),u!==void 0&&ye(T,u),_!==void 0&&Rs(T,_)}return this};h.fn.atomUnbind=function(){for(let n=0,t=this.length;n<t;n++){const e=this[n];e.nodeType===1?Ce(e):k(e.nodeType)}return this};const Dt=new WeakMap;let Ds=0;function Os(n,t,e){t?.isConnected?n.insertBefore(t):n.appendTo(e)}function Ls(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 ks{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(E.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 As(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"?mt(s):s;n.$emptyEl=h(r).appendTo(e)}const{oldKeys:i,itemMap:o}=n;for(let r=0,c=i.length;r<c;r++){const a=i[r],l=o.get(a);l&&n.removeItem(a,l)}i.length=0}function Us(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 l=new Array(e),u=new Set,_=new Int32Array(e),y=[],p=[],v=[];for(let C=0;C<e;C++){const T=t[C],f=s(T,C);if(l[C]=f,u.has(f)){d.warn(E.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),p.push(T),v.push(C),_[C]=-1;continue}const m=I.item;!i&&m!==T&&!qe(m,T)&&(y.push(f),p.push(T),v.push(C)),_[C]=c.has(f)?-1:a.get(f)??-1}return{newKeys:l,newKeySet:u,newIndices:_,trKeys:y,trItems:p,trIdxs:v}}function ws(n,t,e,s){const{trKeys:i,trItems:o,trIdxs:r}=t,c=i.length,a=n.itemMap,l=e.render,u=new Array(c),_=[];let y=0;for(let f=0;f<c;f++){const I=l(o[f],r[f]);u[f]=I,typeof I=="string"&&(_.push(I),y++)}let p=null;const v=_.length;if(v===1)p=[mt(_[0])];else if(v>1){const I=`<template data-atom-sep="${(Ds++).toString(36)}"></template>`;p=mt(_.join(I)).split(I)}if(s&&p!==null&&y===c&&!e.bind&&!e.onAdd&&!e.onRemove&&!e.events)return p;let T=0;for(let f=0;f<c;f++){const I=u[f],m=h(typeof I=="string"?p[T++]:I),N=i[f],g=a.get(N);if(!g){a.set(N,{$el:m,item:null,state:"new"});continue}const D=g.$el[0];D&&b.cleanupTree(D),g.$el.replaceWith(m),g.$el=m,g.state="replaced"}return null}function xs(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 $s(n,t,e,s,i,o,r){const{bind:c,update:a,onAdd:l}=o,{newKeys:u,newIndices:_}=e,y=t.length,p=n.oldKeys.length===0,v=Xe(_);let C=v.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 N=u[m],g=t[m],D=s.children[I++];if(D){const U=h(D);T.set(N,{$el:U,item:g,state:void 0}),f.delete(N),d.enabled&&d.domUpdated(E.LIST,U,"list.add",g)}}return}if(p){const I=document.createDocumentFragment();for(let m=y-1;m>=0;m--){const N=u[m],g=T.get(N);if(!g)continue;const D=g.$el;for(let U=D.length-1;U>=0;U--)I.insertBefore(D[U],I.firstChild)}s.appendChild(I)}else{let I=null;for(let m=y-1;m>=0;m--){const N=u[m],g=T.get(N);g&&(C>=0&&v[C]===m?C--:Os(g.$el,I,i),I=g.$el[0]??null)}}for(let I=0;I<y;I++){const m=u[I],N=t[I],g=T.get(m);if(!g)continue;const D=g.state;g.item=N,g.state=void 0,Ls(D,g,N,I,c,a),D==="new"&&(l&&l(g.$el),f.delete(m),d.enabled&&d.domUpdated(E.LIST,g.$el,"list.add",N))}}function Ps(n,t){const{newKeys:e,newKeySet:s}=t,i=e.length,{oldKeys:o,itemMap:r,elToKey:c,keyToIndex:a}=n;for(let l=0,u=o.length;l<u;l++){const _=o[l];s.has(_)||a.delete(_)}for(let l=0;l<i;l++){const u=e[l],_=r.get(u);if(_){for(let y=0;y<_.$el.length;y++){const p=_.$el[y];p&&c.set(p,u)}a.set(u,l)}}}h.fn.atomList=function(n,t){const{key:e,bind:s,update:i,onAdd:o,onRemove:r,empty:c,events:a}=t,l=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 p=this[_],v=h(p);v.off(".atomList");const C=Dt.get(p);C&&(C.fx.dispose(),C.ctx.dispose());const T=X(p),f=new ks(v,T,r),I=B(()=>{const m=n.value,N=m.length;P(()=>{if(As(f,N,v,c),N===0)return;d.log(E.LIST,`${T} updating with ${N} items`);const g=Us(f,m,N,l,i),D=f.oldKeys.length===0,U=ws(f,g,t,D);xs(f,g.newKeySet),$s(f,m,g,p,v,u,U),a&&Ps(f,g),f.oldKeys=g.newKeys})});if(f.fx=I,a)for(const m in a){if(!Z.call(a,m))continue;const N=a[m],g=m.indexOf(" "),D=g===-1?m:m.slice(0,g),U=g===-1?null:m.slice(g+1).trim(),Te=U||"> *",Se=function(Ne){let J=this;for(;J&&J!==p;){const Ct=f.elToKey.get(J);if(Ct!==void 0){const Pt=f.itemMap.get(Ct);Pt&&N.call(this,Pt.item,f.keyToIndex.get(Ct)??-1,Ne);return}J=J.parentElement}};v.on(`${D}.atomList`,Te,Se)}b.trackEffect(p,I),Dt.set(p,{fx:I,ctx:f}),b.trackCleanup(p,()=>{f.dispose(),Dt.delete(p)})}return this};const Ms=Object.freeze({});h.fn.atomMount=function(n,t){const e=t??Ms;for(let s=0,i=this.length;s<i;s++){const o=this[s];if(!o)continue;b.cleanupTree(o);const r=h(o);let c;try{c=P(()=>n(r,e))}catch(a){d.error(E.MOUNT,S.MOUNT.ERROR(n.name),a);continue}typeof c=="function"&&b.setComponentCleanup(o,c)}return this};h.fn.atomUnmount=function(){for(let n=0,t=this.length;n<t;n++){const e=this[n];e&&Ce(e)}return this};function Wt(n,t){try{return history.pushState(n,"",t),!0}catch(e){return d.warn(E.ROUTE,"PushState failed (likely file:// protocol or security restriction). UI will update, but URL will not.",e),!1}}class Fs{constructor(t){this.isDestroyed=!1,this.previousRoute="",this.cleanups=[],this.templateCache=new Map,this.config={...t,mode:t.mode??et.mode,basePath:t.basePath??et.basePath,autoBindLinks:t.autoBindLinks??et.autoBindLinks,activeClass:t.activeClass??et.activeClass},this.isHistoryMode=this.config.mode==="history",this.$target=h(this.config.target),this.normalizedBasePath=this.config.basePath?.replace(/\/$/,"")||"",this.activeClass=this.config.activeClass??et.activeClass,this.previousUrl=this.isHistoryMode?window.location.pathname+window.location.search:window.location.hash,this.currentRouteAtom=dt(this.getRouteName()),this.currentRoute=this.currentRouteAtom,this.queryParamsAtom=dt(this.getQueryParams()),this.queryParams=rt(()=>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=B(()=>{const s=this.currentRouteAtom.value;P(()=>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(E.ROUTE,S.ROUTE.MALFORMED_URI(t))}return s}setUrl(t){if(this.isHistoryMode){const e=`${this.normalizedBasePath}/${t}`;Wt(null,e),this.previousUrl=e}else{const e=`#${t}`;window.location.hash=e,this.previousUrl=e}}restoreUrl(){this.isHistoryMode?Wt(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(E.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(E.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(E.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)};h(document).on("click","[data-route]",t),this.cleanups.push(()=>{h(document).off("click","[data-route]",t)});const e=this.activeClass,s=B(()=>{const i=this.currentRouteAtom.value;P(()=>{const o=document.querySelectorAll("[data-route]");for(let r=0,c=o.length;r<c;r++){const a=o[r],l=a.dataset.route,u=i===l;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(E.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(E.ROUTE,"Cleanup error during destroy:",i)}this.templateCache.clear()}}function Bs(n){return new Fs(n)}h.extend({route:Bs});class Gs{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=h.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=h.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 l=this.onErrorFn;if(l)try{l(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}}h.extend({atomFetch(n,t){const e=new Gs(n,t),s=!(t.eager??!0),i=rt(e.execute,{defaultValue:t.defaultValue,lazy:s});return Object.assign(i,{abort:()=>e.abort()})}});h(()=>{ue(),le(document.body)});exports.default=h;exports.atom=dt;exports.batch=xt;exports.computed=rt;exports.disableAutoCleanup=ss;exports.disablejQueryOverrides=os;exports.effect=B;exports.enableAutoCleanup=le;exports.enablejQueryOverrides=ue;exports.isAtom=yt;exports.isComputed=ie;exports.isReactive=$t;exports.nextTick=ae;exports.registry=b;exports.untracked=P;
|
|
3
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`jquery`);c=s(c);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};c.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:c.default.fn.on,off:c.default.fn.off,remove:c.default.fn.remove,empty:c.default.fn.empty,detach:c.default.fn.detach};let e=J;c.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},c.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},c.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},c.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},c.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&&(c.default.fn.on=J.on,c.default.fn.off=J.off,c.default.fn.remove=J.remove,c.default.fn.empty=J.empty,c.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,t,n={}){let r=e.el.tagName.toLowerCase();if(!ze.has(r)){console.warn(`${H.BINDING} ${W.BINDING.INVALID_INPUT_ELEMENT(r)}`);return}let{fx:i,cleanup:a}=vt((0,c.default)(e.el),t,n);q.trackEffect(e.el,i),e.trackCleanup(a)}function Zt(e,t){let n=e.el,r=(0,c.default)(n),i=n.type===`radio`,a=()=>{let e=n.checked;if(t.peek()!==e&&(t.value=e,i&&e&&n.name)){let e=n.name.replace(/"/g,`\\"`);(n.form?(0,c.default)(n.form):(0,c.default)(document)).find(`input[type="radio"][name="${e}"]`).not(n).trigger(`change.atomRadioSync`)}};a[lt]=!0,r.on(`change change.atomRadioSync`,a),e.trackCleanup(()=>r.off(`change change.atomRadioSync`,a));let o=z(()=>{let e=!!t.value;k(()=>{n.checked!==e&&(n.checked=e,G.enabled&&G.domUpdated(H.BINDING,n,`checked`,e))})});q.trackEffect(n,o)}function Qt(e,t){let n=(0,c.default)(e.el);n.on(t),e.trackCleanup(()=>n.off(t))}function $t(e,t,n){let r=(0,c.default)(e.el);r.on(t,n),e.trackCleanup(()=>r.off(t,n))}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}c.default.fn.atomText=function(e,t){return Z(this,n=>Ut(n,e,t))},c.default.fn.atomHtml=function(e){return Z(this,t=>Wt(t,e))},c.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))},c.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))},c.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))},c.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))},c.default.fn.atomShow=function(e){return Z(this,t=>Yt(t,e,!1))},c.default.fn.atomHide=function(e){return Z(this,t=>Yt(t,e,!0))},c.default.fn.atomVal=function(e,t={}){return Z(this,n=>Xt(n,e,t))},c.default.fn.atomChecked=function(e){return Z(this,t=>Zt(t,e))},c.default.fn.atomOn=function(e,t){return Z(this,n=>$t(n,e,t))},c.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)})},c.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,c.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,t,n,r){if(e.$emptyEl&&t>0&&(e.$emptyEl.remove(),e.$emptyEl=null),t!==0)return;let{oldKeys:i,oldNodes:a,onRemove:o}=e;if(o)for(let t=0,n=i.length;t<n;t++){let n=i[t],r=a[t];r&&e.removeItem(n,$(r))}else{for(let t=0,n=i.length;t<n;t++)e.removingKeys.delete(i[t]);n.empty()}r&&!e.$emptyEl&&(e.$emptyEl=(0,c.default)(typeof r==`string`?Ft(r):r).appendTo(n)),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,t,n){let{trKeys:r,trItems:i,trIdxs:a,newNodes:o,newStates:s}=e,l=r.length,u=t.render,d=Array(l),f=[],p=0;for(let e=0;e<l;e++){let t=u(i[e],a[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(n&&m&&p===l&&!t.bind&&!t.onAdd&&!t.onRemove&&!t.events)return m;let g=0;for(let e=0;e<l;e++){let t=d[e],n=typeof t==`string`?(0,c.default)(m[g++]):(0,c.default)(t),i=a[e],l=s[i],u=r[e],f=String(u);for(let e=0,t=n.length;e<t;e++){let t=n[e];t instanceof Element&&t.setAttribute(`data-atom-key`,f)}if(l===2){let e=o[i];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(n)}}o[i]=n.length===1?n[0]:n}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,t,n,r,i,a){let{bind:o,update:s,onAdd:l}=i,{newKeys:u,newItems:d,newNodes:f,newStates:p,newIndices:m}=t,h=u.length,g=e.oldKeys.length===0;if(a!==null){n.innerHTML=a.join(``);let t=n.firstElementChild;for(let n=0;n<h&&t;n++){let r=u[n];t.setAttribute(`data-atom-key`,String(r)),f[n]=t,p[n]=0,e.removingKeys.delete(r),G.enabled&&G.domUpdated(H.LIST,(0,c.default)(t),`list.add`,d[n]),t=t.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])}n.appendChild(e)}else{let e=null,t=2147483647;for(let n=h-1;n>=0;n--){let i=m[n],a=f[n];i!==-1&&i<t?t=i:on($(a),e,r),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?s?.(i,a,t):o?.(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])}}}}c.default.fn.atomList=function(e,t){let{key:n,bind:r,update:i,onAdd:a,onRemove:o,empty:s,events:l,isEqual:u}=t,d=typeof n==`function`?n:(e,t)=>e[n],f={bind:r,update:i,onAdd:a,onRemove:o,events:l};for(let n=0,r=this.length;n<r;n++){let r=this[n],a=(0,c.default)(r);a.off(`.atomList`);let p=tn.get(r);p&&(p.fx.dispose(),p.ctx.dispose());let m=B(r),h=new sn(a,m,o),g=z(()=>{let n=e.value,o=n.length;k(()=>{if(cn(h,o,a,s),o===0)return;G.log(H.LIST,`${m} updating with ${o} items`);let e=ln(h,n,o,d,i,u),c=un(e,t,h.oldKeys.length===0);if(dn(h,e),fn(h,e,r,a,f,c),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())||`> *`;a.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(r,g),tn.set(r,{fx:g,ctx:h}),q.trackCleanup(r,()=>{h.dispose(),tn.delete(r)})}return this};var pn=Object.freeze({});c.default.fn.atomMount=function(e,t){let n=t??pn;for(let t=0,r=this.length;t<r;t++){let r=this[t];if(!r)continue;q.cleanupTree(r);let i=(0,c.default)(r),a;try{a=k(()=>e(i,n))}catch(t){G.error(H.MOUNT,W.MOUNT.ERROR(e.name),t);continue}typeof a==`function`&&q.setComponentCleanup(r,a)}return this},c.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,c.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,c.default)(document).on(`click`,`[data-route]`,e),this.cleanups.push(()=>{(0,c.default)(document).off(`click`,`[data-route]`,e)});let t=this.activeClass,n=[],r=z(()=>{let e=this.currentRouteAtom.value;k(()=>{for(let e=0,r=n.length;e<r;e++){let r=n[e];r.classList.remove(t),r.removeAttribute(`aria-current`)}try{let r=e.replace(/"/g,`\\"`),i=document.querySelectorAll(`[data-route="${r}"]`),a=i.length,o=Array(a);for(let e=0;e<a;e++){let n=i[e];n.classList.add(t),n.setAttribute(`aria-current`,`page`),o[e]=n}n=o}catch{n=[]}})});this.cleanups.push(()=>r.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)}c.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,t=this.ajaxOptionsFn?this.ajaxOptionsFn():{},n=c.default.extend(!0,{},this.staticOptions,t);n.success=void 0,n.error=void 0,n.complete=void 0,n.url=this.isStaticUrl?this.staticUrl:this.getUrl();let r=c.default.ajax(n);e.onabort=()=>r.abort(),e.aborted&&r.abort();let i;try{i=await r}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 a=this.transformFn;if(a)try{return a(i)}catch(e){let t=this.onErrorFn;if(t)try{t(e)}catch{}throw e}return i}};c.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,c.default)(()=>{mt(),st(document.body)});var vn=c.default;exports.atom=Te,exports.batch=Pe,exports.computed=R,exports.default=vn,exports.disableAutoCleanup=ct,exports.disablejQueryOverrides=ht,exports.effect=z,exports.enableAutoCleanup=st,exports.enablejQueryOverrides=mt,exports.isAtom=A,exports.isComputed=De,exports.isReactive=Fe,exports.nextTick=$e,exports.registry=q,exports.untracked=k;
|
|
3
|
+
//# sourceMappingURL=index.cjs.map
|