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