@but212/atom-effect-jquery 0.21.2 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("jquery"),dt={IDLE:"idle",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"},P={DISPOSED:1,EXECUTING:8},ee={DISPOSED:1,IS_COMPUTED:2,DIRTY:8,IDLE:16,PENDING:32,RESOLVED:64,REJECTED:128,RECOMPUTING:256,HAS_ERROR:512},j={DISPOSED:1,SYNC:8,NOTIFICATION_SCHEDULED:16},Y={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},Te={WARN_INFINITE_LOOP:!0},Vt={MAX_ASYNC_RETRIES:3,MAX_PROMISE_ID:Number.MAX_SAFE_INTEGER-1},Ft=1073741823,De=typeof process<"u"&&process.env&&!1||!1,Oe=Object.freeze([]);class st extends Error{constructor(t,n=null,s=!0){super(t),this.cause=n,this.recoverable=s,this.name="AtomError"}}class K extends st{constructor(t,n=null){super(t,n,!0),this.name="ComputedError"}}class et extends st{constructor(t,n=null){super(t,n,!1),this.name="EffectError"}}class At extends st{constructor(t,n=null){super(t,n,!1),this.name="SchedulerError"}}const ve=Symbol("AtomEffect.DebugName"),Ae=Symbol("AtomEffect.Type"),Lt=Symbol("AtomEffect.NoDefaultValue"),Dt={enabled:De,warnInfiniteLoop:Te.WARN_INFINITE_LOOP,warn(e,t){},checkCircular(e,t){if(e===t)throw new K("Direct circular dependency detected")},attachDebugInfo(e,t,n){},getDebugName:e=>e?.[ve],getDebugType:e=>e?.[Ae]};let Le=1;const Ne=()=>Le++;function ne(e,t,n){if(typeof t=="function"){const i=t;for(let o=0,r=n.length;o<r;o++){const c=n[o];if(c&&c.fn===i)return}n.push(new Ut(i,void 0));return}if("addDependency"in t){t.addDependency(e);return}const s=t;for(let i=0,o=n.length;i<o;i++){const r=n[i];if(r&&r.sub===s)return}n.push(new Ut(void 0,s))}function zt(e,t,n){const s=new Map;for(let i=0,o=t.length;i<o;i++){const r=t[i];r?.unsub&&s.set(r.node,r.unsub)}for(let i=0,o=e.length;i<o;i++){const r=e[i];if(!r)continue;const c=r.node,u=s.get(c);u!==void 0?(r.unsub=u,s.delete(c)):(Dt.checkCircular(c,n),r.unsub=c.subscribe(n))}for(const i of s.values())i()}class wt{constructor(t,n,s=void 0){this.node=t,this.version=n,this.unsub=s}}class Ut{constructor(t,n){this.fn=t,this.sub=n}}const D={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 nt(e,t,n){if(e instanceof st)return e;const s=e instanceof Error,i=s?e.message:String(e),o=s?e:void 0,r=`${s?e.constructor.name:"Unexpected error"} (${n}): ${i}`;return new t(r,o)}class se{constructor(){this.flags=0,this.version=0,this._lastSeenEpoch=-1,this.id=Ne()&Ft}}class ie extends se{subscribe(t){const n=typeof t=="function";if(!n&&(!t||typeof t.execute!="function"))throw nt(new TypeError("Invalid subscriber"),st,D.ATOM_SUBSCRIBER_MUST_BE_FUNCTION);const s=this._subscribers;for(let o=0,r=s.length;o<r;o++){const c=s[o];if(c&&(n?c.fn===t:c.sub===t))return()=>{}}const i=new Ut(n?t:void 0,n?void 0:t);return s.push(i),()=>this._unsubscribe(i)}_unsubscribe(t){const n=this._subscribers,s=n.indexOf(t);if(s===-1)return;const i=n.pop();s<n.length&&i&&(n[s]=i)}subscriberCount(){return this._subscribers.length}_notifySubscribers(t,n){if(this._subscribers.length===0)return;const s=this._subscribers.slice(0),i=s.length;for(let o=0;o<i;o++){const r=s[o];if(r)try{r.fn?r.fn(t,n):r.sub&&r.sub.execute()}catch(c){this._handleNotifyError(c)}}}_handleNotifyError(t){console.error(nt(t,st,D.ATOM_INDIVIDUAL_SUBSCRIBER_FAILED))}}let Nt=0;const Mt=()=>(Nt=Nt+1&Ft||1,Nt),xt=e=>e+1&Ft;let $t=0,It=!1,oe=0;const ke=()=>oe;function qt(){return It?!1:(It=!0,oe=Mt(),$t=0,!0)}const Xt=()=>{It=!1},Re=()=>It?++$t: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=Y.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=qt();this._drainQueue(),t&&Xt()}finally{this._isProcessing=!1,this._size>0&&!this._isBatching&&this._flush()}}_flushSync(){this._isFlushingSync=!0;const t=qt();try{this._mergeBatchQueue(),this._drainQueue()}finally{this._isFlushingSync=!1,t&&Xt()}}_mergeBatchQueue(){if(this._batchQueueSize===0)return;const t=++this._epoch,n=this._batchQueue,s=this._queueBuffer[this._bufferIndex];let i=this._size;for(let o=0;o<this._batchQueueSize;o++){const r=n[o];r._nextEpoch!==t&&(r._nextEpoch=t,s[i++]=r)}this._size=i,this._batchQueueSize=0,n.length>Y.BATCH_QUEUE_SHRINK_THRESHOLD&&(n.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,n=this._queueBuffer[t],s=this._size;this._bufferIndex=t^1,this._size=0,this._epoch++;for(let i=0;i<s;i++)try{n[i]()}catch(o){console.error(new At("Error occurred during scheduler execution",o))}n.length=0}_handleFlushOverflow(){const t=this._size+this._batchQueueSize;if(console.error(new At(D.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<Y.MIN_FLUSH_ITERATIONS)throw new At(`Max flush iterations must be at least ${Y.MIN_FLUSH_ITERATIONS}`);this._maxFlushIterations=t}}const lt=new we,Bt=Symbol.for("atom-effect/atom"),re=Symbol.for("atom-effect/computed"),Ue=Symbol.for("atom-effect/effect"),F={current:null,run(e,t){const n=this.current;this.current=e;try{return t()}finally{this.current=n}}};function ce(e){const t=F.current;if(t===null)return e();F.current=null;try{return e()}finally{F.current=t}}var Gt;class xe extends ie{constructor(t,n){super(),this._pendingOldValue=void 0,this._notifyTask=()=>this._flushNotifications(),this._subscribers=[],this[Gt]=!0,this._value=t,n&&(this.flags|=j.SYNC),Dt.attachDebugInfo(this,"atom",this.id)}get value(){const t=F.current;return t&&ne(this,t,this._subscribers),this._value}set value(t){const n=this._value;if(Object.is(n,t))return;this._value=t,this.version=xt(this.version);const s=this.flags;if(!(this._subscribers.length===0||s&j.NOTIFICATION_SCHEDULED)){if(this._pendingOldValue=n,this.flags=s|j.NOTIFICATION_SCHEDULED,s&j.SYNC&&!lt.isBatching){this._flushNotifications();return}lt.schedule(this._notifyTask)}}_flushNotifications(){const t=this.flags;if(!(t&j.NOTIFICATION_SCHEDULED)||t&j.DISPOSED)return;const n=this._pendingOldValue;this._pendingOldValue=void 0,this.flags&=-17,this._notifySubscribers(this._value,n)}peek(){return this._value}dispose(){this.flags&j.DISPOSED||(this._subscribers.length=0,this.flags|=j.DISPOSED,this._value=void 0,this._pendingOldValue=void 0)}[(Gt=Bt,Symbol.dispose)](){this.dispose()}}function jt(e,t={}){return new xe(e,t.sync??!1)}class Pe{constructor(t=50,n=256,s=!1){this.limit=t,this.capacity=n,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,n){if(!(n&&t===n)){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:n,rejected:s}=this.stats,i=t-n-(s.frozen+s.tooLarge+s.poolFull);return{acquired:t,released:n,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 R=Object.freeze([]),H=new Pe;function ue(e){return e!==null&&typeof e=="object"&&Bt in e}function ae(e){return e!==null&&typeof e=="object"&&re in e}function le(e){return e!==null&&typeof e=="object"&&typeof e.then=="function"}var Kt,Qt;const{IDLE:_t,DIRTY:tt,PENDING:bt,RESOLVED:Q,REJECTED:ut,HAS_ERROR:Et,RECOMPUTING:ct,DISPOSED:kt,IS_COMPUTED:Fe}=ee;function Me(e){return e&Q?dt.RESOLVED:e&bt?dt.PENDING:e&ut?dt.REJECTED:dt.IDLE}class $e extends ie{constructor(t,n={}){if(typeof t!="function")throw new K(D.COMPUTED_MUST_BE_FUNCTION);super(),this[Qt]=!0,this[Kt]=!0,this._error=null,this._promiseId=0,this._subscribers=[],this._links=R,this._asyncStartAggregateVersion=0,this._asyncRetryCount=0,this._trackEpoch=-1,this._trackLinks=R,this._trackCount=0,this._value=void 0,this.flags=Fe|tt|_t,this._equal=n.equal??Object.is,this._fn=t,this._defaultValue="defaultValue"in n?n.defaultValue:Lt,this._onError=n.onError??null;const s=n.maxAsyncRetries;if(this._maxAsyncRetries=s!=null&&s>=0?s:Vt.MAX_ASYNC_RETRIES,Dt.attachDebugInfo(this,"computed",this.id),n.lazy===!1)try{this._recompute()}catch{}}_track(){const t=F.current;t&&ne(this,t,this._subscribers)}get value(){this._track();const t=this.flags;if((t&(Q|tt|_t))===Q)return this._value;if(t&kt)throw new K(D.COMPUTED_DISPOSED);if(t&ct){if(this._defaultValue!==Lt)return this._defaultValue;throw new K(D.COMPUTED_CIRCULAR_DEPENDENCY)}if(t&(tt|_t)&&(this._recompute(),this.flags&Q))return this._value;const n=this._defaultValue,s=n!==Lt;if(this.flags&bt){if(s)return n;throw new K(D.COMPUTED_ASYNC_PENDING_NO_DEFAULT)}if(this.flags&ut){if(s)return n;throw this._error}return this._value}peek(){return this._value}get state(){return this._track(),Me(this.flags)}get hasError(){if(this._track(),this.flags&(ut|Et))return!0;const t=this._links;for(let n=0,s=t.length;n<s;n++){const i=t[n]?.node;if(i&&i.flags&Et)return!0}return!1}get isValid(){return!this.hasError}get errors(){if(this._track(),!this.hasError)return Oe;const t=[];this._error&&t.push(this._error);const n=this._links;for(let s=0,i=n.length;s<i;s++){const o=n[s].node;if(o.flags&Et){const r=o.errors;if(r.length>0)for(let c=0;c<r.length;c++){const u=r[c];u&&t.indexOf(u)===-1&&t.push(u)}}}return Object.freeze(t)}get lastError(){return this._track(),this._error}get isPending(){return this._track(),(this.flags&bt)!==0}get isResolved(){return this._track(),(this.flags&Q)!==0}invalidate(){this._markDirty()}dispose(){if(this.flags&kt)return;const t=this._links;if(t!==R){for(let n=0,s=t.length;n<s;n++)t[n].unsub?.();H.release(t),this._links=R}this._subscribers.length=0,this.flags=kt|tt|_t,this._error=null,this._value=void 0}[(Qt=Bt,Kt=re,Symbol.dispose)](){this.dispose()}addDependency(t){if(t._lastSeenEpoch!==this._trackEpoch){if(t._lastSeenEpoch=this._trackEpoch,this._trackCount<this._trackLinks.length){const n=this._trackLinks[this._trackCount];n.node=t,n.version=t.version}else this._trackLinks.push(new wt(t,t.version));this._trackCount++}}_recompute(){if(this.flags&ct)return;this.flags|=ct;const t=this._links;this._trackEpoch=Mt(),this._trackLinks=H.acquire(),this._trackCount=0;let n=!1;try{const s=F.run(this,this._fn);this._trackLinks.length=this._trackCount,zt(this._trackLinks,t,this),this._links=this._trackLinks,n=!0,le(s)?this._handleAsyncComputation(s):this._finalizeResolution(s)}catch(s){if(!n)try{this._trackLinks.length=this._trackCount,zt(this._trackLinks,t,this),this._links=this._trackLinks,n=!0}catch{}this._handleError(s,D.COMPUTED_COMPUTATION_FAILED,!0)}finally{n&&t!==R?H.release(t):n||H.release(this._trackLinks),this._trackEpoch=-1,this._trackLinks=R,this._trackCount=0,this.flags&=~ct}}_handleAsyncComputation(t){this.flags=(this.flags|bt)&-217,this._notifySubscribers(void 0,void 0),this._asyncStartAggregateVersion=this._captureVersionSnapshot(),this._asyncRetryCount=0,this._promiseId=(this._promiseId+1)%Vt.MAX_PROMISE_ID;const n=this._promiseId;t.then(s=>{if(n===this._promiseId){if(this._captureVersionSnapshot()!==this._asyncStartAggregateVersion)return this._asyncRetryCount++<this._maxAsyncRetries?this._markDirty():this._handleError(new K(`Async drift threshold exceeded after ${this._maxAsyncRetries} retries.`),D.COMPUTED_ASYNC_COMPUTATION_FAILED);this._finalizeResolution(s),this._notifySubscribers(s,void 0)}},s=>n===this._promiseId&&this._handleError(s,D.COMPUTED_ASYNC_COMPUTATION_FAILED))}_captureVersionSnapshot(){let t=0;const n=this._links;for(let s=0,i=n.length;s<i;s++)t=(t<<5)-t+n[s].node.version|0;return t}_handleError(t,n,s=!1){const i=nt(t,K,n);if(!s&&!(this.flags&ut)&&(this.version=xt(this.version)),this._error=i,this.flags=this.flags&-121|ut|Et,this._onError)try{this._onError(i)}catch(o){console.error(D.CALLBACK_ERROR_IN_ERROR_HANDLER,o)}if(s)throw i;this._notifySubscribers(void 0,void 0)}_finalizeResolution(t){(!(this.flags&Q)||!this._equal(this._value,t))&&(this.version=xt(this.version)),this._value=t,this._error=null,this.flags=(this.flags|Q)&-697}execute(){this._markDirty()}_markDirty(){this.flags&(ct|tt)||(this.flags|=tt,this._notifySubscribers(void 0,void 0))}}function Ht(e,t={}){return new $e(e,t)}var Yt;class Be extends se{constructor(t,n={}){super(),this[Yt]=!0,this._cleanup=null,this._links=R,this._nextLinks=null,this._prevLinks=R,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=n.onError??null,this._sync=n.sync??!1,this._maxExecutions=n.maxExecutionsPerSecond??Y.MAX_EXECUTIONS_PER_SECOND,this._maxExecutionsPerFlush=n.maxExecutionsPerFlush??Y.MAX_EXECUTIONS_PER_EFFECT,this._sync?(this._executeTask=void 0,this._notifyCallback=()=>this.execute()):(this._executeTask=()=>this.execute(),this._notifyCallback=()=>lt.schedule(this._executeTask)),Dt.attachDebugInfo(this,"effect",this.id)}run(){if(this.flags&P.DISPOSED)throw new et(D.EFFECT_DISPOSED);this.execute(!0)}dispose(){this.flags&P.DISPOSED||(this.flags|=P.DISPOSED,this._execCleanup(),this._unsubLinks(this._links),this._links!==R&&H.release(this._links),this._links=R,this._prevLinks=R)}[(Yt=Ue,Symbol.dispose)](){this.dispose()}addDependency(t){if(!(this.flags&P.EXECUTING))return;const n=this._currentEpoch;if(t._lastSeenEpoch===n)return;t._lastSeenEpoch=n;const s=this._nextLinks,i=this._prevLinks;for(let o=0,r=i.length;o<r;o++){const c=i[o];if(c&&c.node===t&&c.unsub){c.version=t.version,s.push(c),i[o]=null;return}}try{const o=t.subscribe(this._notifyCallback);s.push(new wt(t,t.version,o))}catch(o){const r=nt(o,et,D.EFFECT_EXECUTION_FAILED);if(console.error(r),this._onError)try{this._onError(r)}catch{}s.push(new wt(t,t.version,void 0))}}execute(t=!1){if(this.flags&(P.DISPOSED|P.EXECUTING)||!t&&this._links.length>0&&!this._isDirty())return;this._checkInfiniteLoops(),this.flags|=P.EXECUTING,this._execCleanup(),this._prevLinks=this._links;const n=H.acquire();this._nextLinks=n,this._currentEpoch=Mt();let s=!1;try{const i=F.run(this,this._fn);this._links=n,s=!0,le(i)?this._handleAsyncResult(i):this._cleanup=typeof i=="function"?i:null}catch(i){this._links=n,s=!0,this._handleExecutionError(i),this._cleanup=null}finally{this._finalizeDependencies(s,this._prevLinks,n),this.flags&=-9}}_handleAsyncResult(t){const n=++this._execId;t.then(s=>{if(n!==this._execId||this.flags&P.DISPOSED){if(typeof s=="function")try{s()}catch(i){this._handleExecutionError(i,D.EFFECT_CLEANUP_FAILED)}return}typeof s=="function"&&(this._cleanup=s)},s=>n===this._execId&&this._handleExecutionError(s))}_finalizeDependencies(t,n,s){if(this._nextLinks=null,this._prevLinks=R,t){for(let i=0,o=n.length;i<o;i++){const r=n[i];r&&r.unsub?.()}n!==R&&H.release(n)}else this._unsubLinks(s),H.release(s)}_unsubLinks(t){for(let n=0,s=t.length;n<s;n++)t[n]?.unsub?.()}_isDirty(){const t=this._links,n=F.current;F.current=null;try{for(let s=0,i=t.length;s<i;s++){const o=t[s],r=o.node;if(r.flags&ee.IS_COMPUTED)try{r.value}catch{return!0}if(r.version!==o.version)return!0}return!1}finally{F.current=n}}_execCleanup(){if(this._cleanup){try{this._cleanup()}catch(t){this._handleExecutionError(t,D.EFFECT_CLEANUP_FAILED)}this._cleanup=null}}_checkInfiniteLoops(){const t=ke();this._lastFlushEpoch!==t&&(this._lastFlushEpoch=t,this._executionsInEpoch=0),++this._executionsInEpoch>this._maxExecutionsPerFlush&&this._throwInfiniteLoopError("per-effect"),Re()>Y.MAX_EXECUTIONS_PER_FLUSH&&this._throwInfiniteLoopError("global"),this._executionCount++}get isDisposed(){return(this.flags&P.DISPOSED)!==0}get executionCount(){return this._executionCount}get isExecuting(){return(this.flags&P.EXECUTING)!==0}_throwInfiniteLoopError(t){const n=new et(`Infinite loop detected (${t}): effect executed ${this._executionsInEpoch} times in current flush. Total executions in flush: ${$t}`);throw this.dispose(),console.error(n),n}_handleExecutionError(t,n=D.EFFECT_EXECUTION_FAILED){const s=nt(t,et,n);if(console.error(s),this._onError)try{this._onError(s)}catch(i){console.error(nt(i,et,D.CALLBACK_ERROR_IN_ERROR_HANDLER))}}}function V(e,t={}){if(typeof e!="function")throw new et(D.EFFECT_MUST_BE_FUNCTION);const n=new Be(e,t);return n.execute(),n}function Ot(e){if(typeof e!="function")throw new TypeError("Batch callback must be a function");lt.startBatch();try{return e()}finally{lt.endBatch()}}function he(e){return ue(e)||ae(e)}function vt(e){if(!e)return"unknown";const t="jquery"in e?e[0]:e;if(!t)return"unknown";const n=t.id;if(n&&typeof n=="string")return`#${n}`;const s=t.tagName.toLowerCase(),i=t.classList;if(i&&i.length>0){let o=s;for(let r=0,c=i.length;r<c;r++){const u=i[r];u&&(o+=`.${u}`)}return o}return s}function yt(e){let t=String(e??"");t=t.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g,""),t=t.replace(/<\?[\s\S]*?\?>/g,"");const n=/(<(script|iframe|object|embed|base|meta|applet|noscript)\b[^>]*>([\s\S]*?)<\/\2>|<(script|iframe|object|embed|base|meta|applet|noscript)\b[^>]*\/?>)/gim;let s;do s=t,t=t.replace(n,"");while(t!==s);const i=/(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;t=t.replace(i,"data-unsafe-protocol:");const o=/data\s*:\s*(?:text\/html|application\/javascript|text\/javascript|text\/vbscript|text\/xml|application\/xhtml\+xml)/gim;return t=t.replace(o,"data-unsafe-protocol:"),t=t.replace(/\bon\w+\s*=/gim,"data-unsafe-attr="),t=t.replace(/expression\s*\(/gim,"data-unsafe-css(").replace(/behavior\s*:/gim,"data-unsafe-css:"),t}const je=new Set(["href","src","action","formaction","xlink:href","data","poster","srcset","background","cite","longdesc","profile","usemap","classid","codebase"]),He=/^\s*(?:javascript|vbscript)\s*:/i;function Ve(e,t){return je.has(e.toLowerCase())?He.test(t):!1}function ze(e){return e.toLowerCase().includes("url(")?/url\s*\(\s*(?:["']?\s*)?(?:javascript|vbscript)\s*:/i.test(e):!1}function qe(e,t){if(e===t)return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;const n=Object.keys(e),s=Object.keys(t);if(n.length!==s.length)return!1;const i=t;for(let o=0;o<n.length;o++){const r=n[o];if(e[r]!==i[r])return!1}return!0}function Xe(e){const t=e.length;if(t===0)return new Int32Array(0);const n=new Int32Array(t),s=new Int32Array(t);let i=0;for(let r=0;r<t;r++){const c=e[r];if(c===void 0||c===-1)continue;const u=i>0?s[i-1]:void 0;if(i===0||u!==void 0&&(e[u]??-1)<c){n[r]=u??-1,s[i++]=r;continue}let h=0,E=i-1;for(;h<E;){const y=h+E>>>1,A=s[y];A!==void 0&&(e[A]??-1)<c?h=y+1:E=y}const S=s[h];S!==void 0&&c<(e[S]??Number.MAX_SAFE_INTEGER)&&(h>0&&(n[r]=s[h-1]??-1),s[h]=r)}const o=new Int32Array(i);if(i>0){let r=s[i-1];for(let c=i-1;c>=0&&r!==void 0&&r!==-1;c--)o[c]=r,r=n[r]}return o}function Ge(){if(typeof window<"u"){const e=window.__ATOM_DEBUG__;if(typeof e=="boolean")return e}return!1}let G=Ge();const b={get enabled(){return G},set enabled(e){G=e},log(e,...t){G&&console.log(`[atom-effect-jquery] ${e}:`,...t)},atomChanged(e,t,n){G&&console.log(`[atom-effect-jquery] Atom "${e??"anonymous"}" changed:`,t,"→",n)},domUpdated(e,t,n){G&&(console.log(`[atom-effect-jquery] DOM updated: ${vt(e)}.${t} =`,n),Qe(e))},cleanup(e){G&&console.log(`[atom-effect-jquery] Cleanup: ${e}`)},warn(...e){G&&console.warn("[atom-effect-jquery]",...e)}},Pt="atom-debug-highlight";let Wt=!1;function Ke(){if(Wt)return;Wt=!0;const e=document.createElement("style");e.textContent=`.${Pt}{outline:2px solid rgba(255,68,68,0.8);outline-offset:1px;transition:outline 0.5s ease-out}`,document.head.appendChild(e)}const Rt=new WeakMap;function Qe(e){const t="jquery"in e?e[0]:e;if(!t||!t.isConnected)return;Ke();const n=Rt.get(t);n&&clearTimeout(n),t.classList.add(Pt),Rt.set(t,setTimeout(()=>{t.classList.remove(Pt),Rt.delete(t)},600))}function fe(e,t={}){return jt(e,t)}Object.defineProperty(fe,"debug",{get(){return b.enabled},set(e){b.enabled=e}});function Ye(){return new Promise(e=>setTimeout(e,0))}l.extend({atom:fe,computed:Ht,effect:V,batch:Ot,untracked:ce,isAtom:ue,isComputed:ae,isReactive:he,nextTick:Ye});const We="_aes-bound",W={ROUTE:"[$.route]",BIND:"[atomBind]",LIST:"[atomList]"},pt={MODE:"hash",ACTIVE_CLASS:"active",BASE_PATH:"",AUTO_BIND_LINKS:!1},Je={EVENT:"input"},Ze=["innerHTML","outerHTML"],it={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_VALUE:e=>`Blocked dangerous value in "${e}" property.`,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}>.`,DUPLICATE_KEY:(e,t)=>`Duplicate key "${e}" at index ${t}.`},gt=We;class tn{constructor(){this.records=new WeakMap,this.boundElements=new WeakSet,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 n=this.records.get(t);return n||(n={},this.records.set(t,n),this.boundElements.has(t)||(this.boundElements.add(t),t.classList.add(gt))),n}trackEffect(t,n){const s=this._getOrCreateRecord(t);s.effects??=[],s.effects.push(n)}trackCleanup(t,n){const s=this._getOrCreateRecord(t);s.cleanups??=[],s.cleanups.push(n)}hasBind(t){return this.boundElements.has(t)}cleanup(t){if(!this.boundElements.delete(t))return;const n=this.records.get(t);if(!n)return;this.records.delete(t),this.preservedNodes.delete(t),this.ignoredNodes.delete(t),t.classList.remove(gt),b.enabled&&b.cleanup(vt(t));const s=n.effects;if(s)for(let o=0,r=s.length;o<r;o++)try{s[o]?.dispose()}catch(c){b.warn("Effect dispose error:",c)}const i=n.cleanups;if(i)for(let o=0,r=i.length;o<r;o++)try{i[o]?.()}catch(c){b.warn("Cleanup error:",c)}}cleanupDescendants(t){const n=t.querySelectorAll(`.${gt}`);for(let s=0,i=n.length;s<i;s++){const o=n[s];o&&this.boundElements.has(o)?this.cleanup(o):o&&o.classList.remove(gt)}}cleanupTree(t){this.cleanupDescendants(t),this.cleanup(t)}}const m=new tn;let at=null;function de(e=document.body){at||(at=new MutationObserver(t=>{for(let n=0,s=t.length;n<s;n++){const i=t[n]?.removedNodes;if(!i)continue;const o=i.length;if(o!==0)for(let r=0;r<o;r++){const c=i[r];c.nodeType===1&&(c.isConnected||m.isKept(c)||m.isIgnored(c)||m.cleanupTree(c))}}}),at.observe(e,{childList:!0,subtree:!0}))}function en(){at?.disconnect(),at=null}function z(e,t,n,s){he(t)?m.trackEffect(e,V(()=>{const i=t.value;n(i),b.domUpdated(l(e),s,i)})):(n(t),b.enabled&&b.domUpdated(l(e),s,t))}var O=(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))(O||{});function _e(){return{timeoutId:null,flags:0}}function nn(e,t,n={}){const{debounce:s,event:i=Je.EVENT,parse:o=I=>I,format:r=I=>String(I??""),equal:c=Object.is}=n,u=_e(),h=e[0],E=()=>{if(!(u.flags&O.Busy)){u.flags|=O.SyncingToAtom;try{const I=h.value,C=o(I);c(t.value,C)||(t.value=C)}finally{u.flags&=~O.SyncingToAtom}}},S=()=>{u.timeoutId&&(clearTimeout(u.timeoutId),u.timeoutId=null,E()),u.flags&=~O.Focused;const I=r(t.value);h.value!==I&&(h.value=I)},y=()=>{u.flags&O.Busy||(s?(u.timeoutId&&clearTimeout(u.timeoutId),u.timeoutId=setTimeout(E,s)):E())},A={compositionstart:()=>{u.flags|=O.Composing},compositionend:()=>{u.flags&=~O.Composing,E()},focus:()=>{u.flags|=O.Focused},blur:S,[i]:y,change:y};return e.on(A),{effect:()=>{const I=t.value,C=r(I),k=h.value;if(k!==C&&!(u.flags&O.Focused&&c(o(k),I))){u.flags|=O.SyncingToDom;try{if(u.flags&O.Focused){const{selectionStart:J,selectionEnd:ot}=h;h.value=C;const B=C.length;h.setSelectionRange(Math.min(J??0,B),Math.min(ot??0,B))}else h.value=C;b.domUpdated(e,"val",C)}finally{u.flags&=~O.SyncingToDom}}},cleanup:()=>{e.off(A),u.timeoutId&&clearTimeout(u.timeoutId)}}}const Jt=Object.create(null);function sn(e){let t=Jt[e];return t||(t=e.includes("-")?e.replace(/-./g,n=>n[1].toUpperCase()):e,Jt[e]=t,t)}function M(e){let t=null;return{get $el(){return t||(t=l(e)),t},el:e,trackCleanup:n=>m.trackCleanup(e,n)}}function on(e,t){const n=e.el;z(n,t,s=>{const i=typeof s=="string"?s:String(s??"");n.textContent!==i&&(n.textContent=i)},"text")}function Ee(e,t){const n=e.el;z(n,t,s=>{const i=String(s??""),o=yt(i);o!==i&&console.warn(`${W.BIND} ${it.UNSAFE_CONTENT}`),n.innerHTML!==o&&(n.innerHTML=o)},"html")}function pe(e,t){for(const n in t)z(e.el,t[n],s=>{e.el.classList.toggle(n,!!s)},`class.${n}`)}function ge(e,t){const n=e.el,s=n.style;for(const i in t){const o=t[i];if(o===void 0)continue;const r=sn(i),c=Array.isArray(o),u=c?o[0]:o,h=c?o[1]:"";z(n,u,E=>{const S=h?`${E}${h}`:String(E);if(ze(S)){console.warn(`${W.BIND} ${it.BLOCKED_DANGEROUS_VALUE(i)}`);return}s[r]=S},`css.${i}`)}}function me(e,t){const n=e.el;for(const s in t){const i=s.charCodeAt(0);if((i===111||i===79)&&(s.charCodeAt(1)===110||s.charCodeAt(1)===78)){console.warn(`${W.BIND} ${it.BLOCKED_EVENT_HANDLER(s)}`);continue}z(n,t[s],o=>{if(o==null||o===!1){n.removeAttribute(s);return}const r=o===!0?s:String(o);if(Ve(s,r)){console.warn(`${W.BIND} ${it.BLOCKED_PROTOCOL(s)}`);return}n.getAttribute(s)!==r&&n.setAttribute(s,r)},`attr.${s}`)}}function be(e,t){const n=e.el;for(const s in t){if(Ze.includes(s)){console.warn(`${W.BIND} ${it.BLOCKED_DANGEROUS_PROP(s)}`);continue}z(e.el,t[s],i=>{n[s]!==i&&(n[s]=i)},`prop.${s}`)}}function Ct(e,t,n,s){const i=e.el;z(i,t,o=>{const r=n?!o:!!o;i.style.display=r?"":"none",b.enabled&&b.domUpdated(i,s,o)},s)}function ye(e,t){const n=e.el.tagName.toLowerCase();if(n!=="input"&&n!=="select"&&n!=="textarea"){console.warn(`[atomBind] Val binding used on non-input element <${n}>.`);return}const s=Array.isArray(t),{effect:i,cleanup:o}=nn(e.$el,s?t[0]:t,s?t[1]:{});m.trackEffect(e.el,V(i)),e.trackCleanup(o)}function Se(e,t){const n=e.el,s=e.$el,i=_e(),o=()=>{if(i.flags&O.Busy)return;const c=n.checked;t.value!==c&&(t.value=c)};s.on("change",o),e.trackCleanup(()=>s.off("change",o));const r=V(()=>{i.flags|=O.SyncingToDom;const c=!!t.value;n.checked!==c&&(n.checked=c,b.enabled&&b.domUpdated(s,"checked",c)),i.flags&=~O.SyncingToDom});m.trackEffect(n,r)}function rn(e,t){for(const n in t){const s=t[n];if(typeof s!="function")continue;const i=o=>{Ot(()=>s.call(e.el,l.Event(o.type,{originalEvent:o})))};e.el.addEventListener(n,i),e.trackCleanup(()=>e.el.removeEventListener(n,i))}}l.fn.atomBind=function(e){return this.each(function(){const t=M(this);e.text!==void 0&&on(t,e.text),e.html!==void 0&&Ee(t,e.html),e.class&&pe(t,e.class),e.css&&ge(t,e.css),e.attr&&me(t,e.attr),e.prop&&be(t,e.prop),e.show!==void 0&&Ct(t,e.show,!1,"show"),e.hide!==void 0&&Ct(t,e.hide,!0,"hide"),e.val!==void 0&&ye(t,e.val),e.checked!==void 0&&Se(t,e.checked),e.on&&rn(t,e.on)})};l.fn.atomText=function(e,t){return this.each(function(){const n=l(this);z(this,e,t?i=>n.text(t(i)):i=>n.text(String(i??"")),"text")})};l.fn.atomHtml=function(e){return this.each(function(){Ee(M(this),e)})};l.fn.atomClass=function(e,t){return this.each(function(){pe(M(this),{[e]:t})})};l.fn.atomCss=function(e,t,n){return this.each(function(){ge(M(this),{[e]:n?[t,n]:t})})};l.fn.atomAttr=function(e,t){return this.each(function(){me(M(this),{[e]:t})})};l.fn.atomProp=function(e,t){return this.each(function(){be(M(this),{[e]:t})})};l.fn.atomShow=function(e){return this.each(function(){Ct(M(this),e,!1,"show")})};l.fn.atomHide=function(e){return this.each(function(){Ct(M(this),e,!0,"hide")})};l.fn.atomVal=function(e,t={}){return this.each(function(){ye(M(this),t&&Object.keys(t).length>0?[e,t]:e)})};l.fn.atomChecked=function(e){return this.each(function(){Se(M(this),e)})};l.fn.atomOn=function(e,t){return this.each(function(){const n=l(this);n.on(e,t),m.trackCleanup(this,()=>n.off(e,t))})};l.fn.atomUnbind=function(){return this.each(function(){m.cleanupTree(this)})};l.fn.atomList=function(e,t){const{key:n,render:s,bind:i,update:o,onAdd:r,onRemove:c,empty:u}=t,h=typeof n=="function"?n:(E,S)=>E[n];return this.each(function(){const E=l(this),S=vt(this),y=new Map,A=new Set;let L=[],N=null;const I=V(()=>{const C=e.value,k=C.length;if(k===0){if(u&&!N){const d=typeof u=="string"?yt(u):u;N=l(d).appendTo(E)}}else N&&(N.remove(),N=null);if(k===0&&y.size===0){L=[];return}b.log("list",`${S} updating with ${k} items`);const J=new Map,ot=L.length;for(let d=0;d<ot;d++)J.set(L[d],d);const B=new Array(k),rt=new Set,ht=new Int32Array(k);for(let d=0;d<k;d++){const U=C[d],g=h(U,d);rt.has(g)&&console.warn(`${W.LIST} ${it.DUPLICATE_KEY(g,d)}`),B[d]=g,rt.add(g),ht[d]=J.get(g)??-1}if(y.size>0)for(const[d,U]of y){if(rt.has(d)||A.has(d))continue;const g=()=>{U.$el.remove(),U.$el[0]&&m.cleanup(U.$el[0]),A.delete(d),b.log("list",`${S} removed item:`,d)};if(y.delete(d),A.add(d),c){const T=c(U.$el);T instanceof Promise?T.then(g):g()}else g()}if(k===0){L=[];return}const ft=Xe(ht);let x=ft.length-1,w=null;for(let d=k-1;d>=0;d--){const U=B[d],g=C[d],T=y.get(U);if(T){const $=T.item;T.item=g;const Z=T.$el[0];if(!Z)continue;if(o)o(T.$el,g,d),b.domUpdated(T.$el,"list.update",g);else if($!==g&&!qe($,g)){const a=s(g,d),_=typeof a=="string"?yt(a):a,p=l(_),f=w===Z;T.$el.replaceWith(p),T.$el=p,i&&i(p,g,d),b.domUpdated(p,"list.render",g),f&&(w=p[0]||null)}if(x>=0&&ft[x]===d)x--;else{const a=T.$el[0];w?.isConnected?w!==a&&T.$el.insertBefore(w):T.$el.appendTo(E)}w=T.$el[0]||null}else{const $=s(g,d),Z=typeof $=="string"?yt($):$,a=l(Z);y.set(U,{$el:a,item:g}),w?.isConnected?a.insertBefore(w):a.appendTo(E),i&&i(a,g,d),r&&r(a),b.domUpdated(a,"list.add",g),w=a[0]||null}}L=B});m.trackEffect(this,I),m.trackCleanup(this,()=>{y.clear(),A.clear(),L=[],N?.remove()})})};const St=new WeakMap;l.fn.atomMount=function(e,t={}){return this.each(function(){const n=vt(this),s=St.get(this);s&&(b.log("mount",`${n} unmounting existing component`),s()),b.log("mount",`${n} mounting component`);let i;try{i=e(l(this),t)}catch(r){console.error("[atom-effect-jquery] Mount error:",r);return}const o=()=>{if(St.delete(this)){if(b.log("mount",`${n} full cleanup`),typeof i=="function")try{i()}catch(r){console.error("[atom-effect-jquery] Cleanup error:",r)}m.cleanupTree(this)}};St.set(this,o),m.trackCleanup(this,o)})};l.fn.atomUnmount=function(){return this.each(function(){const e=St.get(this);e&&e()})};const mt=W.ROUTE;function cn(e){const{target:t,default:n,routes:s,notFound:i,mode:o=pt.MODE,basePath:r=pt.BASE_PATH,autoBindLinks:c=pt.AUTO_BIND_LINKS,activeClass:u=pt.ACTIVE_CLASS,beforeTransition:h,afterTransition:E}=e,S=o==="history";let y=!1,A=null,L=S?window.location.pathname+window.location.search:window.location.hash;const N=[],I=new Set,C=l(t),k=()=>{if(S){let f=window.location.pathname;return r&&f.startsWith(r)&&(f=f.substring(r.length)),f.replace(/^\//,"")||n}const a=window.location.hash,_=a.indexOf("?");return(_===-1?a.substring(1):a.substring(1,_))||n},J=()=>{let a;if(S){if(a=window.location.search.substring(1),!a)return{}}else{const f=window.location.hash,v=f.indexOf("?");if(v===-1)return{};a=f.substring(v+1)}const _=new URLSearchParams(a),p=Object.fromEntries(_);if(a.includes("%"))try{decodeURIComponent(a)}catch{console.warn(`${mt} Malformed URI component: ${a}`)}return p},ot=a=>{if(S){const _=`${r.replace(/\/$/,"")}/${a}`;history.pushState(null,"",_),L=_}else{const _=`#${a}`;L=_,window.location.hash=_}},B=()=>{S?history.replaceState(null,"",L):window.location.hash=L},rt=()=>S?window.location.pathname+window.location.search:window.location.hash,ht=a=>{let _=s[a];return!_&&i&&(_=s[i]),_||(console.warn(`${mt} Route "${a}" not found and no notFound route configured`),null)},ft=a=>{const _=document.querySelector(a);if(!_?.content)return console.warn(`${mt} Template "${a}" not found`),!1;const p=_.content.cloneNode(!0);return C.append(p),!0},x=jt(k()),w=a=>{if(y)return;const _=C[0];if(!_){console.warn(`${mt} Target element "${t}" not found`);return}const p=ht(a);if(!p)return;const f=J();h&&h(A||a,a),C.empty();let v=f;if(p.onEnter){const q=p.onEnter(f);q!==void 0&&(v={...f,...q})}p.render?p.render(_,a,v):p.template&&ft(p.template),E&&E(A||a,a),A=a},d=a=>{if(y)return;const _=x.value,p=s[_];if(p?.onLeave&&p.onLeave()===!1)return;const f=a||n;ot(f),x.value=f},U=()=>{if(y)return;const a=rt();if(a===L)return;const _=k(),p=x.value;if(p!==_){const f=s[p];if(f?.onLeave&&f.onLeave()===!1){B();return}x.value=_}else w(_);L=a},g=()=>{if(!c)return;const a=f=>{f.preventDefault();const v=f.currentTarget.dataset.route;v!=null&&d(v)};l(document).on("click","[data-route]",a),N.push(()=>{l(document).off("click","[data-route]",a)});const _=f=>{if(I.has(f))return;const v=f.dataset.route;I.add(f);const q=V(()=>{const X=x.value===v;f.classList.toggle(u,X),X?f.setAttribute("aria-current","page"):f.removeAttribute("aria-current")});m.trackEffect(f,q),m.trackCleanup(f,()=>{I.delete(f)})};for(const f of document.querySelectorAll("[data-route]"))_(f);const p=new MutationObserver(f=>{for(const v of f)v.type==="childList"&&v.addedNodes.forEach(q=>{if(q.nodeType===1){const X=q;X.matches?.("[data-route]")&&_(X),X.querySelectorAll&&X.querySelectorAll("[data-route]").forEach(Ce=>_(Ce))}})});p.observe(document.body,{childList:!0,subtree:!0}),N.push(()=>p.disconnect())},T=()=>{y||(y=!0,N.forEach(a=>a()),N.length=0,I.forEach(a=>m.cleanup(a)),I.clear())},$=S?"popstate":"hashchange";window.addEventListener($,U),N.push(()=>window.removeEventListener($,U));const Z=V(()=>{w(x.value)});return N.push(()=>Z.dispose()),g(),C[0]&&m.trackCleanup(C[0],T),{currentRoute:x,navigate:d,destroy:T}}l.extend({route:cn});function un(e,t){const{defaultValue:n,transform:s,method:i,headers:o,ajaxOptions:r}=t,c=typeof e=="function"?e:()=>e;return Ht(async()=>{const u=c(),h=await l.ajax({...r,url:u,method:i,headers:o});return s?s(h):h},{defaultValue:n,lazy:!1})}l.extend({atomFetch:un});const Tt=new WeakMap;let Zt=!1;const te=e=>{let t=Tt.get(e);return t||(t=function(...n){return Ot(()=>e.apply(this,n))},Tt.set(e,t)),t};function Ie(){if(Zt)return;Zt=!0;const e=l.fn.on,t=l.fn.off,n=l.fn.remove,s=l.fn.empty,i=l.fn.detach;l.fn.remove=function(o){const r=o?this.filter(o):this;for(let c=0,u=r.length;c<u;c++){const h=r[c];h&&(m.cleanupTree(h),m.markIgnored(h))}return n.call(this,o)},l.fn.empty=function(){for(let o=0,r=this.length;o<r;o++){const c=this[o];c&&m.cleanupDescendants(c)}return s.call(this)},l.fn.detach=function(o){const r=o?this.filter(o):this;for(let c=0,u=r.length;c<u;c++){const h=r[c];h&&m.keep(h)}return i.call(this,o)},l.fn.on=function(...o){const r=o[0];if(r&&typeof r=="object"){const c=r,u={};for(const h in c){const E=c[h];E&&(u[h]=te(E))}o[0]=u}else for(let c=o.length-1;c>=0;c--)if(typeof o[c]=="function"){o[c]=te(o[c]);break}return e.apply(this,o)},l.fn.off=function(...o){const r=o[0];if(r&&typeof r=="object"){const c=r,u={};for(const h in c){const E=c[h];E&&(u[h]=Tt.get(E)||E)}o[0]=u}else for(let c=o.length-1;c>=0;c--)if(typeof o[c]=="function"){o[c]=Tt.get(o[c])||o[c];break}return t.apply(this,o)}}l(()=>{Ie(),de(document.body)});exports.default=l;exports.atom=jt;exports.batch=Ot;exports.computed=Ht;exports.disableAutoCleanup=en;exports.effect=V;exports.enableAutoCleanup=de;exports.enablejQueryOverrides=Ie;exports.registry=m;exports.untracked=ce;
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;
2
2
  //# sourceMappingURL=index.cjs.map