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