@but212/atom-effect-jquery 0.22.0 → 0.22.2

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