@but212/atom-effect-jquery 0.22.1 → 0.23.0

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