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