@but212/atom-effect-jquery 0.22.0 → 0.22.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,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.0"></script>
20
+ <script src="https://cdn.jsdelivr.net/npm/@but212/atom-effect-jquery@0.22.1"></script>
21
21
  ```
22
22
 
23
23
  ### Usage
@@ -1,2 +1,2 @@
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},Me={WARN_INFINITE_LOOP:!0},Jt={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:Number.MAX_SAFE_INTEGER-1},ut=1073741823,Fe=typeof process<"u"&&process.env&&!1||!1,Be=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 He=Symbol("AtomEffect.DebugName"),Ge=Symbol("AtomEffect.Type"),Ot=Symbol("AtomEffect.NoDefaultValue"),ht={enabled:Fe,warnInfiniteLoop:Me.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?.[He],getDebugType:e=>e?.[Ge]};let je=1;const ze=()=>je++;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=ze()&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 At=0;const Dt=()=>(At=At+1&ut||1,At),Ut=e=>e+1&ut;let Lt=0,lt=!1,ne=0;const Ve=()=>ne;function ie(){return lt?!1:(lt=!0,ne=Dt(),Lt=0,!0)}const re=()=>{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=ie();this._drainQueue(),t&&re()}finally{this._isProcessing=!1,this._size>0&&!this._isBatching&&this._flush()}}_flushSync(){this._isFlushingSync=!0;const t=ie();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,t&&re()}}_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"),oe=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 ce;class $e extends se{constructor(t,s){super(),this._pendingOldValue=void 0,this._notifyTask=()=>this._flushNotifications(),this._subscribers=[],this[ce]=!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)}[(ce=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 ae(e){return e!==null&&typeof e=="object"&&oe in e}function ue(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}var he,le;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[le]=!0,this[he]=!0,this._error=null,this._promiseId=0,this._subscribers=[],this._links=O,this._asyncStartAggregateVersion=0,this._asyncRetryCount=0,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 Be;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}[(le=wt,he=oe,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=Dt(),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,ue(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)return 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 fe;class Ze extends ee{constructor(t,s={}){super(),this[fe]=!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)}[(fe=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=Dt();let n=!1;try{const i=w.run(this,this._fn);this._links=s,n=!0,ue(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=Ve();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 A=n[S];A!==void 0&&f<(e[A]??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={},de=600,ys=`${de/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 _e;function Ss(){if(_e?.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),_e=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)},de))});Gt.set(e,n)}function Ee(e,t){return ft(e,t)}Object.defineProperty(Ee,"debug",{enumerable:!0,configurable:!0,get(){return l.enabled},set(e){l.enabled=e}});function pe(){return new Promise(e=>setTimeout(e,0))}const Rs={atom:Ee,computed:rt,effect:H,batch:Pt,untracked:x,isAtom:dt,isComputed:ae,isReactive:xt,nextTick:pe};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 me(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 ge=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]=ge(n))}),t}function As(e){const t={};return Object.keys(e).forEach(s=>{const n=e[s];t[s]=n?It.get(n)??n:void 0}),t}function Ie(){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]=ge(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]=As(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 Ds(){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 A=o.length;S!==null&&T!==null&&this.el.setSelectionRange(Math.min(S,A),Math.min(T,A))}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 ye=new Map;function ks(e){let t=ye.get(e);return t!==void 0||(t=e.includes("-")?e.replace(/-./g,s=>s[1].toUpperCase()):e,ye.set(e,t)),t}const Ce=new WeakMap;function Ps(e){let t=Ce.get(e);return t||(t=rt(()=>Ft(e.value)),Ce.set(e,t)),t}function N(e){return{$el:c(e),el:e,trackCleanup:t=>p.trackCleanup(e,t)}}function be(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 Se(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 Te(e,t){Object.entries(t).forEach(([s,n])=>{X(e.el,n,i=>{e.el.classList.toggle(s,!!i)},`class.${s}`)})}function Re(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 Oe(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 ve(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 Ne(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(){be(N(this),e,t)})},c.fn.atomHtml=function(e){return this.each(function(){Se(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(){Te(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(){Re(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(){Oe(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(){ve(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(){Ne(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&&be(t,e.text),e.html!==void 0&&Se(t,e.html),e.class!==void 0&&Te(t,e.class),e.css!==void 0&&Re(t,e.css),e.attr!==void 0&&Oe(t,e.attr),e.prop!==void 0&&ve(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&&Ne(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,A)=>T[s];return this.each(function(){const T=c(this),A=Mt(this),m=new Map,I=new Set;let j=[],P=null;const $=(D,R)=>{const K=()=>{zt?.isDisposed||(R.$el.remove(),I.delete(D),l.log("list",`${A} removed item:`,D))};if(f){const z=f(R.$el);z instanceof Promise?z.then(K,K):K()}else K()},Ue=(D,R)=>{m.delete(D),I.add(D),$(D,R)};let zt;zt=H(()=>{const D=e.value,R=D.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)||Ue(u,a)}),j=[];return}l.log("list",`${A} 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=D[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 Le="<!--sep-->",St=bt.length,we=new Array(St),Xt=[];for(let a=0;a<St;a++){const u=n(qt[a],Qt[a]);we[a]=u,typeof u=="string"&&Xt.push(u)}let Tt=null;if(Xt.length>0){const a=Xt.join(Le);Tt=Ft(a).split(Le)}let ke=0;for(let a=0;a<St;a++){const u=we[a],_=c(typeof u=="string"?Tt[ke++]: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)&&Ue(a,u);const Pe=gs(Ct);let $t=Pe.length-1,xe=null;const Kt=j.length===0;if(Kt&&Tt!==null&&ke===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=D[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=D[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=D[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&&Pe[$t]===u?$t--:Fs(h.$el,xe,T),o&&M&&o(h.$el),xe=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 De(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}`;De(null,s),this.previousUrl=s}else{const s=`#${t}`;window.location.hash=s,this.previousUrl=s}}restoreUrl(){this.isHistoryMode?De(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,A={...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?{...A,url:T}:{...A,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(()=>{Ie(),me(document.body)}),E.default=c,E.atom=ft,E.batch=Pt,E.computed=rt,E.disableAutoCleanup=vs,E.disablejQueryOverrides=Ds,E.effect=H,E.enableAutoCleanup=me,E.enablejQueryOverrides=Ie,E.isAtom=dt,E.isComputed=ae,E.isReactive=xt,E.nextTick=pe,E.registry=p,E.untracked=x,Object.defineProperties(E,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
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"}})}));
2
2
  //# sourceMappingURL=atom-effect-jquery.min.js.map