@deijose/nix-js 1.8.0 → 1.8.1
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 +3 -2
- package/dist/lib/nix-js.cjs +2 -2
- package/dist/lib/nix-js.js +2 -2
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@deijose/nix-js)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[]()
|
|
6
|
+
[]()
|
|
6
7
|
[]()
|
|
7
8
|
[]()
|
|
8
9
|
[](https://nix-js.dev/)
|
|
@@ -12,7 +13,7 @@ A lightweight, fully reactive micro-framework for building modern web UIs — no
|
|
|
12
13
|
**[→ Documentation & Live Demo](https://nix-js.dev/)**
|
|
13
14
|
|
|
14
15
|
```
|
|
15
|
-
~24 KB minified · ~
|
|
16
|
+
~24 KB minified · ~10 KB gzipped · zero dependencies · TypeScript-first · ES2022
|
|
16
17
|
```
|
|
17
18
|
|
|
18
19
|
## Installation
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=[],t=[],n=null,r=null,i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=[],d=100,f=0,p=[],m=0,h=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return n&&(this._subs.add(n),r?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){if(c>0){for(let e of this._subs)l.has(e)||(l.add(e),u.push(e));return}let e=m,t=0;for(let n of this._subs)p[e+t++]=n;m=e+t;try{for(let n=0;n<t;n++){let t=p[e+n];p[e+n]=null,t?.()}}finally{m=e}}dispose(){this._subs.clear()}};function g(e){return new h(e)}function _(l){let o,u=!1,a=new Set,s=new Set,c=i,p=()=>{if(u)return;"function"==typeof o&&o();let i=a;a=s,s=i,s.clear();let h=e.length>0?e.pop():{effect:null,deps:null};if(h.effect=n,h.deps=r,t.push(h),n=p,r=s,++f>d){f=0;let l=t.pop();throw n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l),Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).")}try{o=l()}catch(e){if(!c)throw e;c(e)}finally{f--;let l=t.pop();n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l);for(let e of a)s.has(e)||e._removeSub(p)}};return p(),()=>{u=!0,"function"==typeof o&&o();for(let e of s)e._removeSub(p);s.clear(),a.clear()}}function v(e){let t=new h(void 0),n=_(()=>{t.value=e()}),r=t.dispose;return t.dispose=()=>{n(),r.call(t)},t}function y(e){c++;try{e()}finally{if(0===--c&&u.length>0){let e=u.length;for(let t=0;t<e;t++)u[t]();u.length=0,l.clear()}}}function b(e){let t=n,l=r;n=null,r=null;try{return e()}finally{n=t,r=l}}function x(e,t,n={}){let r,{immediate:l=!1,once:o=!1}=n,i=e instanceof h?()=>e.value:e,u=!0,a=!1,s=_(()=>{let e=i();if(u){if(u=!1,l&&!a){let n=e;b(()=>t(n,void 0)),o&&(a=!0,Promise.resolve().then(s))}r=e}else if(!a){let n=e,l=r;r=e,b(()=>t(n,l)),o&&(a=!0,Promise.resolve().then(s))}});return()=>{a=!0,s()}}function ee(e){return e?Promise.resolve().then(e):Promise.resolve()}function te(){return{el:null}}const S={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function C(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ne(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function re(){return[...D]}function O(){D.push(new Map)}function k(){D.pop()}function ie(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function ae(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function oe(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function se(e,t,n){let r,l;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function ce(e,t,n){let r,l;O();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function A(e,t,n,r){let l,o;ie(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}l()}}function le(e,t,n,r,l){let o,i;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)}finally{k()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}o()})}function ue(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function de(e){let t,n,r,l,o,i=e.slice(),u=[0],a=e.length;for(t=0;t<a;t++){let a=e[t];if(0!==a){if(n=u[u.length-1],e[n]<a){i[t]=n,u.push(t);continue}for(r=0,l=u.length-1;r<l;)o=r+l>>1,e[u[o]]<a?r=o+1:l=o;a<e[u[r]]&&(r>0&&(i[t]=u[r-1]),u[r]=t)}}for(r=u.length,l=u[r-1];r-- >0;)u[r]=l,l=i[l];return u}var j=new Set,M=!1;function N(e){j.add(e),M||(M=!0,queueMicrotask(()=>{for(let e of j)e();j.clear(),M=!1}))}function fe(e,t,n,r){if("function"!=typeof t){if(T(t))le(t,e.parentNode,e,r,n);else if(C(t))n.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let l of t)T(l)?le(l,e.parentNode,e,r,n):C(l)?l._render(e.parentNode,e):null!=l&&!1!==l&&e.parentNode.insertBefore(document.createTextNode(String(l)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let l=null,o=null,i=null,u=[],a=null,s=re(),c=!1,f="",d=!0,p=_(()=>{let n=t();if("string"==typeof n||"number"==typeof n){f=String(n);let t=()=>{c=!1,o&&=(o(),null),l?l.nodeValue=f:(l=document.createTextNode(f),e.parentNode.insertBefore(l,e))};return void(d?(d=!1,t()):c||(c=!0,N(t)))}if(c=!1,d=!1,l&&=(l.parentNode?.removeChild(l),null),o&&=(o(),null),null!=n&&!1!==n)if(C(n))o=n._render(e.parentNode,e);else if(T(n))o=A(n,e.parentNode,e,s);else if(ne(n)){i||(i=new Map,a=document.createTextNode(""),e.parentNode.insertBefore(a,e));let t=e.parentNode,r=n.items.map((e,t)=>n.keyFn(e,t)),l=new Set(r),o=!1;if(i.size>0)for(let e of i.keys())if(l.has(e)){o=!0;break}if(!o){if(i.size>0){let t=document.createRange();t.setStartAfter(a),t.setEndBefore(e),t.deleteContents();for(let e of i.values())e.cleanup();i.clear()}if(r.length>0){let l=document.createDocumentFragment();y(()=>{for(let e=0;e<r.length;e++){let t=r[e],o=n.items[e],u=document.createTextNode(""),a=document.createTextNode("");l.appendChild(u),l.appendChild(a);let c=n.renderFn(o,e),f=T(c)?A(c,l,a,s):c._render(l,a);i?.set(t,{start:u,end:a,cleanup:f})}}),t.insertBefore(l,e)}return void(u=r)}let c=new Map;for(let e=0;e<r.length;e++)c.set(r[e],e);let f=new Int32Array(r.length),d=!1,p=0;for(let e=0;e<u.length;e++){let t=u[e],n=c.get(t);if(void 0===n){let e=i.get(t);e.cleanup();let n=e.start;for(;n;){let t=n===e.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!t)break;n=t}i.delete(t)}else f[n]=e+1,n>=p?p=n:d=!0}let h=d?de(f):[],v=h.length-1,m=e;for(let e=r.length-1;e>=0;e--){let l=r[e];if(0===f[e]){let r=n.items[e],o=document.createTextNode(""),u=document.createTextNode(""),a=document.createDocumentFragment();a.appendChild(o),a.appendChild(u);let c=n.renderFn(r,e),f=T(c)?A(c,a,u,s):c._render(a,u);i.set(l,{start:o,end:u,cleanup:f}),t.insertBefore(a,m),m=o}else{let n=i.get(l);if(d)if(v<0||e!==h[v]){let e=n.start;for(;e;){let r=e===n.end?null:e.nextSibling;if(t.insertBefore(e,m),!r)break;e=r}}else v--;m=n.start}}u=r}else if(Array.isArray(n)){let t=[];for(let r of n)if(T(r))t.push(se(r,e.parentNode,e));else if(C(r))t.push(r._render(e.parentNode,e));else if(null!=r&&!1!==r){let n=document.createTextNode(String(r));e.parentNode.insertBefore(n,e),t.push(()=>n.parentNode?.removeChild(n))}o=()=>t.forEach(e=>e())}else l=document.createTextNode(String(n)),e.parentNode.insertBefore(l,e)});n.push(()=>{if(p(),o&&=(o(),null),l&&=(l.parentNode?.removeChild(l),null),i){for(let e of i.values())e.cleanup();i=null,a=null}})}function pe(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function me(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),l=r.lastIndexOf("=");if(-1===l)return{type:"node"};let o=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=l-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let u=r.slice(i,l);if("@"===u[0]){let e=u.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o}}return{type:"attr",attrName:u,hadOpenQuote:o}}var he={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},ge=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),P=new Set;function _e(e,t,n){let r=e.target,l=e.stopPropagation,o=!1;for(e.stopPropagation=()=>{o=!0,l.call(e)};r&&r!==document;){let l=r[t];if(l){let t=r[n];if(t){if(t.includes("prevent")&&e.preventDefault(),t.includes("stop")&&e.stopPropagation(),t.includes("self")&&e.target!==r){r=r.parentNode;continue}if("key"in e){let n=e,l=!0;for(let e of t){let t=he[e];if(void 0!==t&&n.key!==t){l=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){l=!1;break}}if(!l){r=r.parentNode;continue}}}if(l(e),o)break}r=r.parentNode}e.stopPropagation=l}var ve=new Map;function ye(e,t,n,r){let l=[],o=[],i=Array(t.length),u=-1;for(let e=0;e<t.length;e++)r[e]&&r[e].nodeIndex>u&&(u=r[e].nodeIndex);let a=Array(u+1);if(a[0]=e,u>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=u&&(t=n.nextNode());)a[r++]=t}for(let e=0;e<t.length;e++){let t=r[e];i[e]=t?a[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let u=t[e],a=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===u.type){let e=s.name,t=a,n=u.modifiers;if(!ge.has(e)||n.includes("capture")||n.includes("once")){let r={once:n.includes("once"),capture:n.includes("capture"),passive:n.includes("passive")},o=e=>{n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),(!n.includes("self")||e.target===e.currentTarget)&&t(e)};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r))}else{if(!P.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>_e(e,t,n);ve.set(e,r),document.addEventListener(e,r),P.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;c[r]=t,n.length>0&&(c[o]=n),l.push(()=>{c[r]=null,c[o]=null})}continue}if("attr"===u.type){let e=s.name,t=c;if("ref"===e){a.el=t,l.push(()=>{a.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof a){let t=!1,o=!1,i=!0,u=_(()=>{o=!!a();let l=()=>{t=!1;let l="show"===e?o:!o;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"};i?(i=!1,l()):t||(t=!0,N(l))});l.push(u)}else("show"===e?a:!a)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof a){let r,o=!1,i=!0,u=_(()=>{r=a();let l=()=>{o=!1;let l=r;n?t[e]=l??"":null==l||!1===l?t.removeAttribute(e):t.setAttribute(e,String(l))};i?(i=!1,l()):o||(o=!0,N(l))});l.push(u)}else n?t[e]=a??"":null!=a&&!1!==a&&t.setAttribute(e,String(a));continue}let f=c;if(!f)continue;let d=document.createTextNode("");f.parentNode.replaceChild(d,f),fe(d,a,l,o)}return{disposes:l,postMountHooks:o}}function be(e,t){let n=new Uint8Array(e.length),r="";for(let l=0;l<e.length;l++){let o=e[l];if(1===n[l]&&('"'===o[0]||"'"===o[0])&&(o=o.slice(1)),l<t.length){let e=t[l];if("node"===e.type)r+=o+`\x3c!--nix-${l}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-e-${l}="${e.eventName}"`,e.hadOpenQuote&&(n[l+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-a-${l}="${e.attrName}"`,e.hadOpenQuote&&(n[l+1]=1)}}else r+=o}return r}var F=new WeakMap;function I(e,...t){let n=F.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(me(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=be(e,t);let o,i=Array(t.length).fill(null),u=l.content,a=document.createTreeWalker(u,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),s=0;for(;o=a.nextNode();)if(s++,8===o.nodeType){let e=o.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:s})}}else if(1===o.nodeType){let e=o,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],l=r.name;if(l.startsWith("data-nix-e-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l));continue}if(l.startsWith("data-nix-a-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l))}}}n={contexts:t,tpl:l,pathMap:i},F.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:u,postMountHooks:a}=ye(i,r,t,o),s=document.createTextNode("");return e.insertBefore(s,n),e.insertBefore(i,n),a.forEach(e=>e()),()=>{for(let e=u.length-1;e>=0;e--)u[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function xe(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function L(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function R(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(L(r.transitionDuration||"0"),L(r.animationDuration||"0")),o=l>0?l+100:t;if(o<=0)return void n();let i,u=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n())};e.addEventListener("transitionend",u),e.addEventListener("animationend",u),i=setTimeout(()=>{e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n()},o)})}function Se(e,t={}){let n=xe(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,l){let o=document.createComment(S.TRANSITION);r.insertBefore(o,l);let i=null,u=null,a=0,s=!0,c=()=>{let e=o.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return T(e)?ce(e,r,l):e._render(r,l)}let d=(e,r=!1)=>{a++,u&&=(u(),null),i=f(e);let l=c();if(l&&(!s||t.appear)&&!r){let e=a;(async()=>{t.onBeforeEnter?.(l),l.classList.add(n.enterFrom,n.enterActive),l.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===e&&(l.classList.remove(n.enterFrom),l.classList.add(n.enterTo),await R(l,t.duration),a===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let l=++a;u=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===l&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await R(r,t.duration),a===l&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),u?.(),u=null))})().catch(()=>{})},h=null;if("function"!=typeof e||T(e))d(e);else{let t=e,n=null;h=_(()=>{let e=t(),r=null===n,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(a++,u?.(),u=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{a++,h?.(),i?.(),u?.(),i=null,u=null,o.remove()}}}}function Ce(){return{__isPortalOutlet:!0,_container:null}}function we(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function Te(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)?se(e,l,null):e._render(l,null)}}}var z=E("nix:portal-outlet");function Ee(e){ae(z,e)}function De(){return oe(z)}function Oe(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(S.ERROR_BOUNDARY);n.insertBefore(l,r);let i,u=null,a=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||T(t)?t:t(e);u=T(o)?ce(o,n,r):o._render(n,r)};o(e=>{a||(a=!0,c?(u?.(),u=null,d(e)):(i=e,f=!0))});try{if(T(e)){O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}u=e.render()._render(n,r)}finally{k()}if(!a)try{let t=e.onMount?.(),n=u;u=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else u=e._render(n,r)}catch(e){a=!0,u?.(),u=null,i=e,f=!0}finally{s(),c=!0}return f&&(u?.(),u=null,d(i)),()=>{u?.(),l.remove()}}}}function ke(e,t){if(T(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: container not found: ${t}`);O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function Ae(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=g(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var B=null,V=null;function H(){if(!B)throw Error("[Nix] No active router. Call createRouter() first.");return B}function U(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function je(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function Me(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Ne(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Pe(e,t="",n=[]){let r=[];for(let l of e){let e=Ne(t,l.path),o=[...n,l.component],i=Me(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...Pe(l.children,e,o))}return r}function Fe(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let l=r.length>0&&"wildcard"===r[r.length-1].kind,o=l?r.slice(0,-1):r;if(l){if(n.length<o.length)return null}else if(n.length!==o.length)return null;let i={};for(let e=0;e<o.length;e++){let t=o[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Ie(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},l=-1;for(let o of t){let t=Fe(e,o);if(null===t)continue;let i=Ie(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function G(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Le(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return G(new URL(t,window.location.origin).pathname)}catch{return G(t)}}function Re(e,t){let n=null==t?.base?Le():G(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function l(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let o=r(),i=Pe(e),u=W(o,i),a=g(o),s=g(u?.params??{}),c=g(U(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,l){let o=[...f];n&&o.push(n);let i=++p;if(0===o.length)return void r();let u=0;!function n(a){if(i!==p)return;if(!1===a)return void l?.();if("string"==typeof a)return void(a===e?r():_(a));if(u>=o.length)return void r();let s=o[u++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function m(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),l=-1===n?{}:U(e.slice(n)),o=t?{...l,...t}:l,i={};for(let[e,t]of Object.entries(o))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}V&&=(V(),null);let y=()=>{let e=r(),t=a.value,n=c.value,o=W(e,i),u=U(window.location.search);h(e,t,o?.route.beforeEnter,()=>{s.value=o?.params??{},c.value=u,a.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",l(t)+je(n))})};function x(e,t,n,r,o){s.value=r?.params??{},c.value=t,a.value=e;let i=l(e)+je(t);o?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function _(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=a.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>x(n,r,l,o,!1))}window.addEventListener("popstate",y),V=()=>window.removeEventListener("popstate",y);let b={current:a,params:s,query:c,base:n||"/",navigate:_,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=a.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>x(n,r,l,o,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=a.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=W(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return B&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),B=b,queueMicrotask(()=>{v||h(o,"",W(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=W("/",i);a.value="/",s.value=e?.params??{},c.value={}})}),b}function ze(){return H()}var Be=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=H(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=[],t=[],n=null,r=null,i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=[],d=100,f=0,p=[],m=0,h=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return n&&(this._subs.add(n),r?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){if(c>0){for(let e of this._subs)l.has(e)||(l.add(e),u.push(e));return}let e=m,t=0;for(let n of this._subs)p[e+t++]=n;m=e+t;try{for(let n=0;n<t;n++){let t=p[e+n];p[e+n]=null,t?.()}}finally{m=e}}dispose(){this._subs.clear()}};function g(e){return new h(e)}function _(l){let o,u=!1,a=new Set,s=new Set,c=i,p=()=>{if(u)return;"function"==typeof o&&o();let i=a;a=s,s=i,s.clear();let h=e.length>0?e.pop():{effect:null,deps:null};if(h.effect=n,h.deps=r,t.push(h),n=p,r=s,++f>d){f=0;let l=t.pop();throw n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l),Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).")}try{o=l()}catch(e){if(!c)throw e;c(e)}finally{f--;let l=t.pop();n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l);for(let e of a)s.has(e)||e._removeSub(p)}};return p(),()=>{u=!0,"function"==typeof o&&o();for(let e of s)e._removeSub(p);s.clear(),a.clear()}}function v(e){let t=new h(void 0),n=_(()=>{t.value=e()}),r=t.dispose;return t.dispose=()=>{n(),r.call(t)},t}function y(e){c++;try{e()}finally{if(0===--c&&u.length>0){let e=u.length;for(let t=0;t<e;t++)u[t]();u.length=0,l.clear()}}}function b(e){let t=n,l=r;n=null,r=null;try{return e()}finally{n=t,r=l}}function x(e,t,n={}){let r,{immediate:l=!1,once:o=!1}=n,i=e instanceof h?()=>e.value:e,u=!0,a=!1,s=_(()=>{let e=i();if(u){if(u=!1,l&&!a){let n=e;b(()=>t(n,void 0)),o&&(a=!0,Promise.resolve().then(s))}r=e}else if(!a){let n=e,l=r;r=e,b(()=>t(n,l)),o&&(a=!0,Promise.resolve().then(s))}});return()=>{a=!0,s()}}function ee(e){return e?Promise.resolve().then(e):Promise.resolve()}function te(){return{el:null}}var S={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function C(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ne(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function re(){return[...D]}function O(){D.push(new Map)}function k(){D.pop()}function ie(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function ae(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function oe(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function se(e,t,n){let r,l;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function ce(e,t,n){let r,l;O();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function A(e,t,n,r){let l,o;ie(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}l()}}function le(e,t,n,r,l){let o,i;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)}finally{k()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}o()})}function ue(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function de(e){let t,n,r,l,o,i=e.slice(),u=[0],a=e.length;for(t=0;t<a;t++){let a=e[t];if(0!==a){if(n=u[u.length-1],e[n]<a){i[t]=n,u.push(t);continue}for(r=0,l=u.length-1;r<l;)o=r+l>>1,e[u[o]]<a?r=o+1:l=o;a<e[u[r]]&&(r>0&&(i[t]=u[r-1]),u[r]=t)}}for(r=u.length,l=u[r-1];r-- >0;)u[r]=l,l=i[l];return u}var j=new Set,M=!1;function N(e){j.add(e),M||(M=!0,queueMicrotask(()=>{for(let e of j)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}j.clear(),M=!1}))}function fe(e,t,n,r){if("function"!=typeof t){if(T(t))le(t,e.parentNode,e,r,n);else if(C(t))n.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let l of t)T(l)?le(l,e.parentNode,e,r,n):C(l)?l._render(e.parentNode,e):null!=l&&!1!==l&&e.parentNode.insertBefore(document.createTextNode(String(l)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let l=null,o=null,i=null,u=[],a=null,s=re(),c=!1,f="",d=!0,p=_(()=>{let n=t();if("string"==typeof n||"number"==typeof n){f=String(n);let t=()=>{c=!1,o&&=(o(),null),l?l.nodeValue=f:(l=document.createTextNode(f),e.parentNode.insertBefore(l,e))};return void(d?(d=!1,t()):c||(c=!0,N(t)))}if(c=!1,d=!1,l&&=(l.parentNode?.removeChild(l),null),o&&=(o(),null),null!=n&&!1!==n)if(C(n))o=n._render(e.parentNode,e);else if(T(n))o=A(n,e.parentNode,e,s);else if(ne(n)){i||(i=new Map,a=document.createTextNode(""),e.parentNode.insertBefore(a,e));let t=e.parentNode,r=n.items.map((e,t)=>n.keyFn(e,t)),l=new Set(r),o=!1;if(i.size>0)for(let e of i.keys())if(l.has(e)){o=!0;break}if(!o){if(i.size>0){let t=document.createRange();t.setStartAfter(a),t.setEndBefore(e),t.deleteContents();for(let e of i.values())e.cleanup();i.clear()}if(r.length>0){let l=document.createDocumentFragment();y(()=>{for(let e=0;e<r.length;e++){let t=r[e],o=n.items[e],u=document.createTextNode(""),a=document.createTextNode("");l.appendChild(u),l.appendChild(a);let c=n.renderFn(o,e),f=T(c)?A(c,l,a,s):c._render(l,a);i?.set(t,{start:u,end:a,cleanup:f})}}),t.insertBefore(l,e)}return void(u=r)}let c=new Map;for(let e=0;e<r.length;e++)c.set(r[e],e);let f=new Int32Array(r.length),d=!1,p=0;for(let e=0;e<u.length;e++){let t=u[e],n=c.get(t);if(void 0===n){let e=i.get(t);e.cleanup();let n=e.start;for(;n;){let t=n===e.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!t)break;n=t}i.delete(t)}else f[n]=e+1,n>=p?p=n:d=!0}let h=d?de(f):[],v=h.length-1,m=e;for(let e=r.length-1;e>=0;e--){let l=r[e];if(0===f[e]){let r=n.items[e],o=document.createTextNode(""),u=document.createTextNode(""),a=document.createDocumentFragment();a.appendChild(o),a.appendChild(u);let c=n.renderFn(r,e),f=T(c)?A(c,a,u,s):c._render(a,u);i.set(l,{start:o,end:u,cleanup:f}),t.insertBefore(a,m),m=o}else{let n=i.get(l);if(d)if(v<0||e!==h[v]){let e=n.start;for(;e;){let r=e===n.end?null:e.nextSibling;if(t.insertBefore(e,m),!r)break;e=r}}else v--;m=n.start}}u=r}else if(Array.isArray(n)){let t=[];for(let r of n)if(T(r))t.push(se(r,e.parentNode,e));else if(C(r))t.push(r._render(e.parentNode,e));else if(null!=r&&!1!==r){let n=document.createTextNode(String(r));e.parentNode.insertBefore(n,e),t.push(()=>n.parentNode?.removeChild(n))}o=()=>t.forEach(e=>e())}else l=document.createTextNode(String(n)),e.parentNode.insertBefore(l,e)});n.push(()=>{if(p(),o&&=(o(),null),l&&=(l.parentNode?.removeChild(l),null),i){for(let e of i.values())e.cleanup();i=null,a=null}})}function pe(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function me(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),l=r.lastIndexOf("=");if(-1===l)return{type:"node"};let o=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=l-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let u=r.slice(i,l);if("@"===u[0]){let e=u.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o}}return{type:"attr",attrName:u,hadOpenQuote:o}}var he={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},ge=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),P=new Set;function _e(e,t,n){let r=e.target,l=e.stopPropagation,o=!1;for(e.stopPropagation=()=>{o=!0,l.call(e)};r&&r!==document;){let l=r[t];if(l){let t=r[n];if(t){if(t.includes("prevent")&&e.preventDefault(),t.includes("stop")&&e.stopPropagation(),t.includes("self")&&e.target!==r){r=r.parentNode;continue}if("key"in e){let n=e,l=!0;for(let e of t){let t=he[e];if(void 0!==t&&n.key!==t){l=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){l=!1;break}}if(!l){r=r.parentNode;continue}}}if(l(e),o)break}r=r.parentNode}e.stopPropagation=l}var ve=new Map;function ye(e,t,n,r){let l=[],o=[],i=Array(t.length),u=-1;for(let e=0;e<t.length;e++)r[e]&&r[e].nodeIndex>u&&(u=r[e].nodeIndex);let a=Array(u+1);if(a[0]=e,u>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=u&&(t=n.nextNode());)a[r++]=t}for(let e=0;e<t.length;e++){let t=r[e];i[e]=t?a[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let u=t[e],a=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===u.type){let e=s.name,t=a,n=u.modifiers;if(!ge.has(e)||n.includes("capture")||n.includes("once")){let r={once:n.includes("once"),capture:n.includes("capture"),passive:n.includes("passive")},o=e=>{n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),(!n.includes("self")||e.target===e.currentTarget)&&t(e)};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r))}else{if(!P.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>_e(e,t,n);ve.set(e,r),document.addEventListener(e,r),P.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;c[r]=t,n.length>0&&(c[o]=n),l.push(()=>{c[r]=null,c[o]=null})}continue}if("attr"===u.type){let e=s.name,t=c;if("ref"===e){a.el=t,l.push(()=>{a.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof a){let t=!1,o=!1,i=!0,u=_(()=>{o=!!a();let l=()=>{t=!1;let l="show"===e?o:!o;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"};i?(i=!1,l()):t||(t=!0,N(l))});l.push(u)}else("show"===e?a:!a)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof a){let r,o=!1,i=!0,u=_(()=>{r=a();let l=()=>{o=!1;let l=r;n?t[e]=l??"":null==l||!1===l?t.removeAttribute(e):t.setAttribute(e,String(l))};i?(i=!1,l()):o||(o=!0,N(l))});l.push(u)}else n?t[e]=a??"":null!=a&&!1!==a&&t.setAttribute(e,String(a));continue}let f=c;if(!f)continue;let d=document.createTextNode("");f.parentNode.replaceChild(d,f),fe(d,a,l,o)}return{disposes:l,postMountHooks:o}}function be(e,t){let n=new Uint8Array(e.length),r="";for(let l=0;l<e.length;l++){let o=e[l];if(1===n[l]&&('"'===o[0]||"'"===o[0])&&(o=o.slice(1)),l<t.length){let e=t[l];if("node"===e.type)r+=o+`\x3c!--nix-${l}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+ +!!e.hadOpenQuote;r+=o.slice(0,-t)+` data-nix-e-${l}="${e.eventName}"`,e.hadOpenQuote&&(n[l+1]=1)}else{let t=`${e.attrName}=`.length+ +!!e.hadOpenQuote;r+=o.slice(0,-t)+` data-nix-a-${l}="${e.attrName}"`,e.hadOpenQuote&&(n[l+1]=1)}}else r+=o}return r}var F=new WeakMap;function I(e,...t){let n=F.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(me(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=be(e,t);let o,i=Array(t.length).fill(null),u=l.content,a=document.createTreeWalker(u,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),s=0;for(;o=a.nextNode();)if(s++,8===o.nodeType){let e=o.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:s})}}else if(1===o.nodeType){let e=o,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],l=r.name;if(l.startsWith("data-nix-e-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l));continue}if(l.startsWith("data-nix-a-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l))}}}n={contexts:t,tpl:l,pathMap:i},F.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:u,postMountHooks:a}=ye(i,r,t,o),s=document.createTextNode(""),c=document.createTextNode("");return e.insertBefore(s,n),e.insertBefore(i,n),e.insertBefore(c,n),a.forEach(e=>e()),()=>{for(let e=u.length-1;e>=0;e--)u[e]();let e=s.nextSibling;for(;e&&e!==c;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s),c.parentNode?.removeChild(c)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function xe(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function L(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function R(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(L(r.transitionDuration||"0"),L(r.animationDuration||"0")),o=l>0?l+100:t;if(o<=0)return void n();let i,u=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n())};e.addEventListener("transitionend",u),e.addEventListener("animationend",u),i=setTimeout(()=>{e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n()},o)})}function Se(e,t={}){let n=xe(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,l){let o=document.createComment(S.TRANSITION);r.insertBefore(o,l);let i=null,u=null,a=0,s=!0,c=()=>{let e=o.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return T(e)?ce(e,r,l):e._render(r,l)}let d=(e,r=!1)=>{a++,u&&=(u(),null),i=f(e);let l=c();if(l&&(!s||t.appear)&&!r){let e=a;(async()=>{t.onBeforeEnter?.(l),l.classList.add(n.enterFrom,n.enterActive),l.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===e&&(l.classList.remove(n.enterFrom),l.classList.add(n.enterTo),await R(l,t.duration),a===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let l=++a;u=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===l&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await R(r,t.duration),a===l&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),u?.(),u=null))})().catch(()=>{})},h=null;if("function"!=typeof e||T(e))d(e);else{let t=e,n=null;h=_(()=>{let e=t(),r=null===n,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(a++,u?.(),u=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{a++,h?.(),i?.(),u?.(),i=null,u=null,o.remove()}}}}function Ce(){return{__isPortalOutlet:!0,_container:null}}function we(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function Te(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)?se(e,l,null):e._render(l,null)}}}var z=E("nix:portal-outlet");function Ee(e){ae(z,e)}function De(){return oe(z)}function Oe(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(S.ERROR_BOUNDARY);n.insertBefore(l,r);let i,u=null,a=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||T(t)?t:t(e);u=T(o)?ce(o,n,r):o._render(n,r)};o(e=>{a||(a=!0,c?(u?.(),u=null,d(e)):(i=e,f=!0))});try{if(T(e)){O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}u=e.render()._render(n,r)}finally{k()}if(!a)try{let t=e.onMount?.(),n=u;u=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else u=e._render(n,r)}catch(e){a=!0,u?.(),u=null,i=e,f=!0}finally{s(),c=!0}return f&&(u?.(),u=null,d(i)),()=>{u?.(),l.remove()}}}}function ke(e,t){if(T(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: container not found: ${t}`);O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function Ae(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=g(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var B=null,V=null;function H(){if(!B)throw Error("[Nix] No active router. Call createRouter() first.");return B}function U(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function je(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function Me(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Ne(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Pe(e,t="",n=[]){let r=[];for(let l of e){let e=Ne(t,l.path),o=[...n,l.component],i=Me(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...Pe(l.children,e,o))}return r}function Fe(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let l=r.length>0&&"wildcard"===r[r.length-1].kind,o=l?r.slice(0,-1):r;if(l){if(n.length<o.length)return null}else if(n.length!==o.length)return null;let i={};for(let e=0;e<o.length;e++){let t=o[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Ie(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},l=-1;for(let o of t){let t=Fe(e,o);if(null===t)continue;let i=Ie(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function G(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Le(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return G(new URL(t,window.location.origin).pathname)}catch{return G(t)}}function Re(e,t){let n=null==t?.base?Le():G(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function l(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let o=r(),i=Pe(e),u=W(o,i),a=g(o),s=g(u?.params??{}),c=g(U(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,l){let o=[...f];n&&o.push(n);let i=++p;if(0===o.length)return void r();let u=0;!function n(a){if(i!==p)return;if(!1===a)return void l?.();if("string"==typeof a)return void(a===e?r():_(a));if(u>=o.length)return void r();let s=o[u++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function m(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),l=-1===n?{}:U(e.slice(n)),o=t?{...l,...t}:l,i={};for(let[e,t]of Object.entries(o))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}V&&=(V(),null);let y=()=>{let e=r(),t=a.value,n=c.value,o=W(e,i),u=U(window.location.search);h(e,t,o?.route.beforeEnter,()=>{s.value=o?.params??{},c.value=u,a.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",l(t)+je(n))})};function x(e,t,n,r,o){s.value=r?.params??{},c.value=t,a.value=e;let i=l(e)+je(t);o?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function _(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=a.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>x(n,r,l,o,!1))}window.addEventListener("popstate",y),V=()=>window.removeEventListener("popstate",y);let b={current:a,params:s,query:c,base:n||"/",navigate:_,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=a.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>x(n,r,l,o,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=a.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=W(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return B&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),B=b,queueMicrotask(()=>{v||h(o,"",W(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=W("/",i);a.value="/",s.value=e?.params??{},c.value={}})}),b}function ze(){return H()}var Be=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=H(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Ve=class extends w{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return I`<a
|
|
4
4
|
href=${(H()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
@@ -18,4 +18,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=[],t=[]
|
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}var K=new Map,We=3e5,q=null,Ge=We;function Ke(){null===q&&(q=setInterval(()=>{let e=Date.now();for(let[t,n]of K)n.subscribers<=0&&e-n.fetchedAt>Ge&&K.delete(t);0===K.size&&null!==q&&(clearInterval(q),q=null)},6e4))}function J(e){
|
|
21
|
+
`}var K=new Map,We=3e5,q=null,Ge=We;function Ke(){null===q&&(q=setInterval(()=>{let e=Date.now();for(let[t,n]of K)n.subscribers<=0&&e-n.fetchedAt>Ge&&K.delete(t);0===K.size&&null!==q&&(clearInterval(q),q=null)},6e4))}function J(e){let t=K.get(e);if(t&&t.fetchedAt>0)return t}function qe(e,t){let n=K.get(e);K.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Ke()}function Je(e){let t=K.get(e);t?t.subscribers++:K.set(e,{fetchedAt:0,subscribers:1})}function Ye(e){let t=K.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Xe(e,t){let n=K.get(e);return!!n&&Date.now()-n.fetchedAt<t}function Ze(e){void 0===e?(K.clear(),null!==q&&(clearInterval(q),q=null)):K.delete(e)}function Qe(e){Ge=e}function $e(e,t,n={}){let{fallback:r,errorFallback:l,resetOnRefresh:o=!1,invalidate:i,cacheKey:u,staleTime:a=0}=n,s=r??He(),c=l??Ue;return new class extends w{_state;_disposeWatcher;constructor(){super();let e=u?J(u):void 0;this._state=g(e&&void 0!==e.data?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){u&&Je(u);let e=u?J(u):void 0;if(e&&Xe(u,a)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=_(()=>{i.value,e?e=!1:(u&&K.delete(u),this._run())})}return()=>{this._disposeWatcher?.(),u&&Ye(u)}}_run(){(o||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{u&&qe(u,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return I`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Y=new Map,et=new FinalizationRegistry(({key:e,ref:t})=>{let n=Y.get(e);n&&(n.delete(t),0===n.size&&Y.delete(e))});function tt(e){K.delete(e);let t=Y.get(e);if(t){for(let e of t){let n=e.deref();n?n():t.delete(e)}0===t.size&&Y.delete(e)}}function nt(e,t,n={}){let{staleTime:r=0,refetchOnMount:l="always"}=n,o=J(e),i=g(o?"success":"pending"),u=g(o?.data),a=g(void 0),s=()=>{t().then(t=>{qe(e,t),u.value=t,a.value=void 0,i.value="success"},e=>{a.value=e,i.value="error"})},c=()=>{"pending"===i.peek()&&(u.value=void 0,a.value=void 0),s()};Y.has(e)||Y.set(e,new Set);let f=Y.get(e),d=new WeakRef(c);f.add(d),et.register(c,{key:e,ref:d});let p=Xe(e,r);return o?!1===l||"stale"===l&&p||"always"===l&&p&&r>0||s():c(),{status:i,data:u,error:a,refetch:()=>{K.delete(e),c()}}}function rt(e,t){let n=null;return()=>n?new n:$e(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function it(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function X(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function at(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Z(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function ot(e="Invalid email"){return Z(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function st(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function ct(e){return e}var lt={required:it,minLength:X,maxLength:at,email:ot,pattern:Z,min:st,max:Q};function ut(e,t){return{...e,...t}}function $(e,t=[],n="blur"){let r=g(e),l=g(!1),o=g(!1),i=g(null),u=g(!1),a=v(()=>{if(i.value)return i.value;if(!("input"===n?o.value||l.value:"submit"===n?u.value:l.value))return null;for(let e of t){let t=e(r.value);if(t)return t}return null});function s(t){if(!t||!("value"in t))return e;let n=t;return"boolean"==typeof e?n.checked:"number"==typeof e?Number(n.value):n.value}return{value:r,error:a,touched:l,dirty:o,onInput:e=>{r.value=s(e.target),o.value=!0,i.value=null},onBlur:()=>{l.value=!0},reset:function(){r.value=e,l.value=!1,o.value=!1,i.value=null,u.value=!1},_setExternalError:function(e){i.value=e,e&&(l.value=!0)},_forceVisible:function(){l.value=!0,u.value=!0},_dispose:function(){a.dispose()}}}function dt(e,t={},n="blur"){function r(e){let r={};for(let l in e){let o=t[l]??[];r[l]=$(e[l],o,n)}return r}let l=g(e.map(r)),o=v(()=>l.value.length);return{fields:l,append:function(e){l.value=[...l.value,r(e)]},remove:function(e){let t=l.value;if(!(e<0||e>=t.length)){for(let n in t[e])t[e][n]._dispose();l.value=t.filter((t,n)=>n!==e)}},move:function(e,t){let n=[...l.value];if(e<0||e>=n.length||t<0||t>=n.length||e===t)return;let[r]=n.splice(e,1);n.splice(t,0,r),l.value=n},replace:function(e,t){let n=[...l.value];if(!(e<0||e>=n.length)){for(let t in n[e])n[e][t]._dispose();n[e]=r(t),l.value=n}},length:o,reset:function(){for(let e of l.value)for(let t in e)e[t]._dispose();l.value=e.map(r)},_dispose:function(){for(let e of l.value)for(let t in e)e[t]._dispose();o.dispose()}}}function ft(e,t={}){let n=t.validateOn??"blur",r={};for(let l in e){let o=t.validators?.[l]??[];r[l]=$(e[l],o,n)}let l=g(!1),o=g(0),i=v(()=>{let e={};for(let t in r)e[t]=r[t].value.value;return e}),u=v(()=>{let e={};for(let t in r){let n=r[t].error.value;n&&(e[t]=n)}return e}),a=v(()=>{for(let e in r)if(r[e].error.value)return!1;return!0}),s=v(()=>{for(let e in r)if(r[e].dirty.value)return!0;return!1}),c=v(()=>{for(let e in r)if(r[e].touched.value)return!0;return!1});function f(e){for(let t in e)r[t]?._setExternalError(e[t]??null)}return{fields:r,values:i,errors:u,valid:a,dirty:s,touched:c,isSubmitting:l,submitCount:o,handleSubmit:function(e){return n=>{n.preventDefault(),o.value++;for(let e in r)r[e]._forceVisible();let u=i.value;if(t.validate){let e=t.validate(u);if(e){let t={},n=!1;for(let r in e){let l=e[r],o=Array.isArray(l)?l[0]??null:l??null;o&&(t[r]=o,n=!0)}if(n)return void f(t)}}for(let e in r)if(r[e].error.value)return;let a=e(u);a instanceof Promise&&(l.value=!0,a.finally(()=>{l.value=!1}).catch(()=>{}))}},reset:function(){for(let e in r)r[e].reset();l.value=!1,o.value=0},setErrors:f,dispose:function(){i.dispose(),u.dispose(),a.dispose(),s.dispose(),c.dispose();for(let e in r)r[e]._dispose()}}}exports.Link=Ve,exports.NixComponent=w,exports.RouterView=Be,exports.Signal=h,exports.batch=y,exports.clearQueryCache=Ze,exports.computed=v,exports.createErrorBoundary=Oe,exports.createForm=ft,exports.createInjectionKey=E,exports.createPortalOutlet=Ce,exports.createQuery=nt,exports.createRouter=Re,exports.createStore=Ae,exports.createValidator=ct,exports.effect=_,exports.email=ot,exports.extendValidators=ut,exports.html=I,exports.inject=oe,exports.injectOutlet=De,exports.invalidateQueries=tt,exports.lazy=rt,exports.max=Q,exports.maxLength=at,exports.min=st,exports.minLength=X,exports.mount=ke,exports.nextTick=ee,exports.pattern=Z,exports.portal=Te,exports.portalOutlet=we,exports.provide=ae,exports.provideOutlet=Ee,exports.ref=te,exports.repeat=ue,exports.required=it,exports.setQueryCacheTime=Qe,exports.showWhen=pe,exports.signal=g,exports.suspend=$e,exports.transition=Se,exports.untrack=b,exports.useField=$,exports.useFieldArray=dt,exports.useRouter=ze,exports.validators=lt,exports.watch=x;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=[],t=[],n=null,r=null,i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=[],d=100,f=0,p=[],m=0,h=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return n&&(this._subs.add(n),r?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){if(c>0){for(let e of this._subs)l.has(e)||(l.add(e),u.push(e));return}let e=m,t=0;for(let n of this._subs)p[e+t++]=n;m=e+t;try{for(let n=0;n<t;n++){let t=p[e+n];p[e+n]=null,t?.()}}finally{m=e}}dispose(){this._subs.clear()}};function g(e){return new h(e)}function _(l){let o,a=!1,u=new Set,s=new Set,c=i,p=()=>{if(a)return;"function"==typeof o&&o();let i=u;u=s,s=i,s.clear();let h=e.length>0?e.pop():{effect:null,deps:null};if(h.effect=n,h.deps=r,t.push(h),n=p,r=s,++f>d){f=0;let l=t.pop();throw n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l),Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).")}try{o=l()}catch(e){if(!c)throw e;c(e)}finally{f--;let l=t.pop();n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l);for(let e of u)s.has(e)||e._removeSub(p)}};return p(),()=>{a=!0,"function"==typeof o&&o();for(let e of s)e._removeSub(p);s.clear(),u.clear()}}function v(e){let t=new h(void 0),n=_(()=>{t.value=e()}),r=t.dispose;return t.dispose=()=>{n(),r.call(t)},t}function y(e){c++;try{e()}finally{if(0===--c&&u.length>0){let e=u.length;for(let t=0;t<e;t++)u[t]();u.length=0,l.clear()}}}function b(e){let t=n,l=r;n=null,r=null;try{return e()}finally{n=t,r=l}}function x(e,t,n={}){let r,{immediate:l=!1,once:o=!1}=n,i=e instanceof h?()=>e.value:e,a=!0,u=!1,s=_(()=>{let e=i();if(a){if(a=!1,l&&!u){let n=e;b(()=>t(n,void 0)),o&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,l=r;r=e,b(()=>t(n,l)),o&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function ee(e){return e?Promise.resolve().then(e):Promise.resolve()}function te(){return{el:null}}const S={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function C(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ne(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function re(){return[...D]}function O(){D.push(new Map)}function k(){D.pop()}function ie(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function ae(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function oe(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function se(e,t,n){let r,l;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function ce(e,t,n){let r,l;O();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function A(e,t,n,r){let l,o;ie(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}l()}}function le(e,t,n,r,l){let o,i;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)}finally{k()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}o()})}function ue(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function de(e){let t,n,r,l,o,i=e.slice(),a=[0],u=e.length;for(t=0;t<u;t++){let u=e[t];if(0!==u){if(n=a[a.length-1],e[n]<u){i[t]=n,a.push(t);continue}for(r=0,l=a.length-1;r<l;)o=r+l>>1,e[a[o]]<u?r=o+1:l=o;u<e[a[r]]&&(r>0&&(i[t]=a[r-1]),a[r]=t)}}for(r=a.length,l=a[r-1];r-- >0;)a[r]=l,l=i[l];return a}var j=new Set,M=!1;function N(e){j.add(e),M||(M=!0,queueMicrotask(()=>{for(let e of j)e();j.clear(),M=!1}))}function fe(e,t,n,r){if("function"!=typeof t){if(T(t))le(t,e.parentNode,e,r,n);else if(C(t))n.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let l of t)T(l)?le(l,e.parentNode,e,r,n):C(l)?l._render(e.parentNode,e):null!=l&&!1!==l&&e.parentNode.insertBefore(document.createTextNode(String(l)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let l=null,o=null,i=null,a=[],u=null,s=re(),c=!1,f="",d=!0,p=_(()=>{let n=t();if("string"==typeof n||"number"==typeof n){f=String(n);let t=()=>{c=!1,o&&=(o(),null),l?l.nodeValue=f:(l=document.createTextNode(f),e.parentNode.insertBefore(l,e))};return void(d?(d=!1,t()):c||(c=!0,N(t)))}if(c=!1,d=!1,l&&=(l.parentNode?.removeChild(l),null),o&&=(o(),null),null!=n&&!1!==n)if(C(n))o=n._render(e.parentNode,e);else if(T(n))o=A(n,e.parentNode,e,s);else if(ne(n)){i||(i=new Map,u=document.createTextNode(""),e.parentNode.insertBefore(u,e));let t=e.parentNode,r=n.items.map((e,t)=>n.keyFn(e,t)),l=new Set(r),o=!1;if(i.size>0)for(let e of i.keys())if(l.has(e)){o=!0;break}if(!o){if(i.size>0){let t=document.createRange();t.setStartAfter(u),t.setEndBefore(e),t.deleteContents();for(let e of i.values())e.cleanup();i.clear()}if(r.length>0){let l=document.createDocumentFragment();y(()=>{for(let e=0;e<r.length;e++){let t=r[e],o=n.items[e],a=document.createTextNode(""),u=document.createTextNode("");l.appendChild(a),l.appendChild(u);let c=n.renderFn(o,e),f=T(c)?A(c,l,u,s):c._render(l,u);i?.set(t,{start:a,end:u,cleanup:f})}}),t.insertBefore(l,e)}return void(a=r)}let c=new Map;for(let e=0;e<r.length;e++)c.set(r[e],e);let f=new Int32Array(r.length),d=!1,p=0;for(let e=0;e<a.length;e++){let t=a[e],n=c.get(t);if(void 0===n){let e=i.get(t);e.cleanup();let n=e.start;for(;n;){let t=n===e.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!t)break;n=t}i.delete(t)}else f[n]=e+1,n>=p?p=n:d=!0}let h=d?de(f):[],v=h.length-1,m=e;for(let e=r.length-1;e>=0;e--){let l=r[e];if(0===f[e]){let r=n.items[e],o=document.createTextNode(""),a=document.createTextNode(""),u=document.createDocumentFragment();u.appendChild(o),u.appendChild(a);let c=n.renderFn(r,e),f=T(c)?A(c,u,a,s):c._render(u,a);i.set(l,{start:o,end:a,cleanup:f}),t.insertBefore(u,m),m=o}else{let n=i.get(l);if(d)if(v<0||e!==h[v]){let e=n.start;for(;e;){let r=e===n.end?null:e.nextSibling;if(t.insertBefore(e,m),!r)break;e=r}}else v--;m=n.start}}a=r}else if(Array.isArray(n)){let t=[];for(let r of n)if(T(r))t.push(se(r,e.parentNode,e));else if(C(r))t.push(r._render(e.parentNode,e));else if(null!=r&&!1!==r){let n=document.createTextNode(String(r));e.parentNode.insertBefore(n,e),t.push(()=>n.parentNode?.removeChild(n))}o=()=>t.forEach(e=>e())}else l=document.createTextNode(String(n)),e.parentNode.insertBefore(l,e)});n.push(()=>{if(p(),o&&=(o(),null),l&&=(l.parentNode?.removeChild(l),null),i){for(let e of i.values())e.cleanup();i=null,u=null}})}function pe(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function me(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),l=r.lastIndexOf("=");if(-1===l)return{type:"node"};let o=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=l-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let a=r.slice(i,l);if("@"===a[0]){let e=a.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o}}return{type:"attr",attrName:a,hadOpenQuote:o}}var he={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},ge=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),P=new Set;function _e(e,t,n){let r=e.target,l=e.stopPropagation,o=!1;for(e.stopPropagation=()=>{o=!0,l.call(e)};r&&r!==document;){let l=r[t];if(l){let t=r[n];if(t){if(t.includes("prevent")&&e.preventDefault(),t.includes("stop")&&e.stopPropagation(),t.includes("self")&&e.target!==r){r=r.parentNode;continue}if("key"in e){let n=e,l=!0;for(let e of t){let t=he[e];if(void 0!==t&&n.key!==t){l=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){l=!1;break}}if(!l){r=r.parentNode;continue}}}if(l(e),o)break}r=r.parentNode}e.stopPropagation=l}var ve=new Map;function ye(e,t,n,r){let l=[],o=[],i=Array(t.length),a=-1;for(let e=0;e<t.length;e++)r[e]&&r[e].nodeIndex>a&&(a=r[e].nodeIndex);let u=Array(a+1);if(u[0]=e,a>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=a&&(t=n.nextNode());)u[r++]=t}for(let e=0;e<t.length;e++){let t=r[e];i[e]=t?u[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers;if(!ge.has(e)||n.includes("capture")||n.includes("once")){let r={once:n.includes("once"),capture:n.includes("capture"),passive:n.includes("passive")},o=e=>{n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),(!n.includes("self")||e.target===e.currentTarget)&&t(e)};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r))}else{if(!P.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>_e(e,t,n);ve.set(e,r),document.addEventListener(e,r),P.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;c[r]=t,n.length>0&&(c[o]=n),l.push(()=>{c[r]=null,c[o]=null})}continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,l.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=!1,o=!1,i=!0,a=_(()=>{o=!!u();let l=()=>{t=!1;let l="show"===e?o:!o;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"};i?(i=!1,l()):t||(t=!0,N(l))});l.push(a)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r,o=!1,i=!0,a=_(()=>{r=u();let l=()=>{o=!1;let l=r;n?t[e]=l??"":null==l||!1===l?t.removeAttribute(e):t.setAttribute(e,String(l))};i?(i=!1,l()):o||(o=!0,N(l))});l.push(a)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;let d=document.createTextNode("");f.parentNode.replaceChild(d,f),fe(d,u,l,o)}return{disposes:l,postMountHooks:o}}function be(e,t){let n=new Uint8Array(e.length),r="";for(let l=0;l<e.length;l++){let o=e[l];if(1===n[l]&&('"'===o[0]||"'"===o[0])&&(o=o.slice(1)),l<t.length){let e=t[l];if("node"===e.type)r+=o+`\x3c!--nix-${l}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-e-${l}="${e.eventName}"`,e.hadOpenQuote&&(n[l+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-a-${l}="${e.attrName}"`,e.hadOpenQuote&&(n[l+1]=1)}}else r+=o}return r}var F=new WeakMap;function I(e,...t){let n=F.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(me(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=be(e,t);let o,i=Array(t.length).fill(null),a=l.content,u=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),s=0;for(;o=u.nextNode();)if(s++,8===o.nodeType){let e=o.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:s})}}else if(1===o.nodeType){let e=o,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],l=r.name;if(l.startsWith("data-nix-e-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l));continue}if(l.startsWith("data-nix-a-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l))}}}n={contexts:t,tpl:l,pathMap:i},F.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:a,postMountHooks:u}=ye(i,r,t,o),s=document.createTextNode("");return e.insertBefore(s,n),e.insertBefore(i,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function xe(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function L(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function R(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(L(r.transitionDuration||"0"),L(r.animationDuration||"0")),o=l>0?l+100:t;if(o<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},o)})}function Se(e,t={}){let n=xe(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,l){let o=document.createComment(S.TRANSITION);r.insertBefore(o,l);let i=null,a=null,u=0,s=!0,c=()=>{let e=o.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return T(e)?ce(e,r,l):e._render(r,l)}let d=(e,r=!1)=>{u++,a&&=(a(),null),i=f(e);let l=c();if(l&&(!s||t.appear)&&!r){let e=u;(async()=>{t.onBeforeEnter?.(l),l.classList.add(n.enterFrom,n.enterActive),l.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===e&&(l.classList.remove(n.enterFrom),l.classList.add(n.enterTo),await R(l,t.duration),u===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let l=++u;a=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===l&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await R(r,t.duration),u===l&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),a?.(),a=null))})().catch(()=>{})},h=null;if("function"!=typeof e||T(e))d(e);else{let t=e,n=null;h=_(()=>{let e=t(),r=null===n,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,h?.(),i?.(),a?.(),i=null,a=null,o.remove()}}}}function Ce(){return{__isPortalOutlet:!0,_container:null}}function we(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function Te(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)?se(e,l,null):e._render(l,null)}}}var z=E("nix:portal-outlet");function Ee(e){ae(z,e)}function De(){return oe(z)}function Oe(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(S.ERROR_BOUNDARY);n.insertBefore(l,r);let i,a=null,u=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||T(t)?t:t(e);a=T(o)?ce(o,n,r):o._render(n,r)};o(e=>{u||(u=!0,c?(a?.(),a=null,d(e)):(i=e,f=!0))});try{if(T(e)){O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(n,r)}finally{k()}if(!u)try{let t=e.onMount?.(),n=a;a=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else a=e._render(n,r)}catch(e){u=!0,a?.(),a=null,i=e,f=!0}finally{s(),c=!0}return f&&(a?.(),a=null,d(i)),()=>{a?.(),l.remove()}}}}function ke(e,t){if(T(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: container not found: ${t}`);O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function Ae(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=g(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var B=null,V=null;function H(){if(!B)throw Error("[Nix] No active router. Call createRouter() first.");return B}function U(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function je(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function Me(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Ne(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Pe(e,t="",n=[]){let r=[];for(let l of e){let e=Ne(t,l.path),o=[...n,l.component],i=Me(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...Pe(l.children,e,o))}return r}function Fe(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let l=r.length>0&&"wildcard"===r[r.length-1].kind,o=l?r.slice(0,-1):r;if(l){if(n.length<o.length)return null}else if(n.length!==o.length)return null;let i={};for(let e=0;e<o.length;e++){let t=o[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Ie(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},l=-1;for(let o of t){let t=Fe(e,o);if(null===t)continue;let i=Ie(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function G(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Le(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return G(new URL(t,window.location.origin).pathname)}catch{return G(t)}}function Re(e,t){let n=null==t?.base?Le():G(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function l(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let o=r(),i=Pe(e),a=W(o,i),u=g(o),s=g(a?.params??{}),c=g(U(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,l){let o=[...f];n&&o.push(n);let i=++p;if(0===o.length)return void r();let a=0;!function n(u){if(i!==p)return;if(!1===u)return void l?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=o.length)return void r();let s=o[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function m(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),l=-1===n?{}:U(e.slice(n)),o=t?{...l,...t}:l,i={};for(let[e,t]of Object.entries(o))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}V&&=(V(),null);let y=()=>{let e=r(),t=u.value,n=c.value,o=W(e,i),a=U(window.location.search);h(e,t,o?.route.beforeEnter,()=>{s.value=o?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",l(t)+je(n))})};function _(e,t,n,r,o){s.value=r?.params??{},c.value=t,u.value=e;let i=l(e)+je(t);o?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=u.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!1))}window.addEventListener("popstate",y),V=()=>window.removeEventListener("popstate",y);let x={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=u.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=W(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return B&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),B=x,queueMicrotask(()=>{v||h(o,"",W(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=W("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function ze(){return H()}var Be=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=H(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
var e=[],t=[],n=null,r=null,i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=[],d=100,f=0,p=[],m=0,h=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return n&&(this._subs.add(n),r?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){if(c>0){for(let e of this._subs)l.has(e)||(l.add(e),u.push(e));return}let e=m,t=0;for(let n of this._subs)p[e+t++]=n;m=e+t;try{for(let n=0;n<t;n++){let t=p[e+n];p[e+n]=null,t?.()}}finally{m=e}}dispose(){this._subs.clear()}};function g(e){return new h(e)}function _(l){let o,a=!1,u=new Set,s=new Set,c=i,p=()=>{if(a)return;"function"==typeof o&&o();let i=u;u=s,s=i,s.clear();let h=e.length>0?e.pop():{effect:null,deps:null};if(h.effect=n,h.deps=r,t.push(h),n=p,r=s,++f>d){f=0;let l=t.pop();throw n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l),Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).")}try{o=l()}catch(e){if(!c)throw e;c(e)}finally{f--;let l=t.pop();n=l.effect,r=l.deps,l.effect=null,l.deps=null,e.push(l);for(let e of u)s.has(e)||e._removeSub(p)}};return p(),()=>{a=!0,"function"==typeof o&&o();for(let e of s)e._removeSub(p);s.clear(),u.clear()}}function v(e){let t=new h(void 0),n=_(()=>{t.value=e()}),r=t.dispose;return t.dispose=()=>{n(),r.call(t)},t}function y(e){c++;try{e()}finally{if(0===--c&&u.length>0){let e=u.length;for(let t=0;t<e;t++)u[t]();u.length=0,l.clear()}}}function b(e){let t=n,l=r;n=null,r=null;try{return e()}finally{n=t,r=l}}function x(e,t,n={}){let r,{immediate:l=!1,once:o=!1}=n,i=e instanceof h?()=>e.value:e,a=!0,u=!1,s=_(()=>{let e=i();if(a){if(a=!1,l&&!u){let n=e;b(()=>t(n,void 0)),o&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,l=r;r=e,b(()=>t(n,l)),o&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function ee(e){return e?Promise.resolve().then(e):Promise.resolve()}function te(){return{el:null}}var S={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function C(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ne(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function re(){return[...D]}function O(){D.push(new Map)}function k(){D.pop()}function ie(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function ae(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function oe(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function se(e,t,n){let r,l;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function ce(e,t,n){let r,l;O();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function A(e,t,n,r){let l,o;ie(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}l()}}function le(e,t,n,r,l){let o,i;O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)}finally{k()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}o()})}function ue(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function de(e){let t,n,r,l,o,i=e.slice(),a=[0],u=e.length;for(t=0;t<u;t++){let u=e[t];if(0!==u){if(n=a[a.length-1],e[n]<u){i[t]=n,a.push(t);continue}for(r=0,l=a.length-1;r<l;)o=r+l>>1,e[a[o]]<u?r=o+1:l=o;u<e[a[r]]&&(r>0&&(i[t]=a[r-1]),a[r]=t)}}for(r=a.length,l=a[r-1];r-- >0;)a[r]=l,l=i[l];return a}var j=new Set,M=!1;function N(e){j.add(e),M||(M=!0,queueMicrotask(()=>{for(let e of j)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}j.clear(),M=!1}))}function fe(e,t,n,r){if("function"!=typeof t){if(T(t))le(t,e.parentNode,e,r,n);else if(C(t))n.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let l of t)T(l)?le(l,e.parentNode,e,r,n):C(l)?l._render(e.parentNode,e):null!=l&&!1!==l&&e.parentNode.insertBefore(document.createTextNode(String(l)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let l=null,o=null,i=null,a=[],u=null,s=re(),c=!1,f="",d=!0,p=_(()=>{let n=t();if("string"==typeof n||"number"==typeof n){f=String(n);let t=()=>{c=!1,o&&=(o(),null),l?l.nodeValue=f:(l=document.createTextNode(f),e.parentNode.insertBefore(l,e))};return void(d?(d=!1,t()):c||(c=!0,N(t)))}if(c=!1,d=!1,l&&=(l.parentNode?.removeChild(l),null),o&&=(o(),null),null!=n&&!1!==n)if(C(n))o=n._render(e.parentNode,e);else if(T(n))o=A(n,e.parentNode,e,s);else if(ne(n)){i||(i=new Map,u=document.createTextNode(""),e.parentNode.insertBefore(u,e));let t=e.parentNode,r=n.items.map((e,t)=>n.keyFn(e,t)),l=new Set(r),o=!1;if(i.size>0)for(let e of i.keys())if(l.has(e)){o=!0;break}if(!o){if(i.size>0){let t=document.createRange();t.setStartAfter(u),t.setEndBefore(e),t.deleteContents();for(let e of i.values())e.cleanup();i.clear()}if(r.length>0){let l=document.createDocumentFragment();y(()=>{for(let e=0;e<r.length;e++){let t=r[e],o=n.items[e],a=document.createTextNode(""),u=document.createTextNode("");l.appendChild(a),l.appendChild(u);let c=n.renderFn(o,e),f=T(c)?A(c,l,u,s):c._render(l,u);i?.set(t,{start:a,end:u,cleanup:f})}}),t.insertBefore(l,e)}return void(a=r)}let c=new Map;for(let e=0;e<r.length;e++)c.set(r[e],e);let f=new Int32Array(r.length),d=!1,p=0;for(let e=0;e<a.length;e++){let t=a[e],n=c.get(t);if(void 0===n){let e=i.get(t);e.cleanup();let n=e.start;for(;n;){let t=n===e.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!t)break;n=t}i.delete(t)}else f[n]=e+1,n>=p?p=n:d=!0}let h=d?de(f):[],v=h.length-1,m=e;for(let e=r.length-1;e>=0;e--){let l=r[e];if(0===f[e]){let r=n.items[e],o=document.createTextNode(""),a=document.createTextNode(""),u=document.createDocumentFragment();u.appendChild(o),u.appendChild(a);let c=n.renderFn(r,e),f=T(c)?A(c,u,a,s):c._render(u,a);i.set(l,{start:o,end:a,cleanup:f}),t.insertBefore(u,m),m=o}else{let n=i.get(l);if(d)if(v<0||e!==h[v]){let e=n.start;for(;e;){let r=e===n.end?null:e.nextSibling;if(t.insertBefore(e,m),!r)break;e=r}}else v--;m=n.start}}a=r}else if(Array.isArray(n)){let t=[];for(let r of n)if(T(r))t.push(se(r,e.parentNode,e));else if(C(r))t.push(r._render(e.parentNode,e));else if(null!=r&&!1!==r){let n=document.createTextNode(String(r));e.parentNode.insertBefore(n,e),t.push(()=>n.parentNode?.removeChild(n))}o=()=>t.forEach(e=>e())}else l=document.createTextNode(String(n)),e.parentNode.insertBefore(l,e)});n.push(()=>{if(p(),o&&=(o(),null),l&&=(l.parentNode?.removeChild(l),null),i){for(let e of i.values())e.cleanup();i=null,u=null}})}function pe(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function me(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),l=r.lastIndexOf("=");if(-1===l)return{type:"node"};let o=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=l-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let a=r.slice(i,l);if("@"===a[0]){let e=a.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o}}return{type:"attr",attrName:a,hadOpenQuote:o}}var he={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},ge=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),P=new Set;function _e(e,t,n){let r=e.target,l=e.stopPropagation,o=!1;for(e.stopPropagation=()=>{o=!0,l.call(e)};r&&r!==document;){let l=r[t];if(l){let t=r[n];if(t){if(t.includes("prevent")&&e.preventDefault(),t.includes("stop")&&e.stopPropagation(),t.includes("self")&&e.target!==r){r=r.parentNode;continue}if("key"in e){let n=e,l=!0;for(let e of t){let t=he[e];if(void 0!==t&&n.key!==t){l=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){l=!1;break}}if(!l){r=r.parentNode;continue}}}if(l(e),o)break}r=r.parentNode}e.stopPropagation=l}var ve=new Map;function ye(e,t,n,r){let l=[],o=[],i=Array(t.length),a=-1;for(let e=0;e<t.length;e++)r[e]&&r[e].nodeIndex>a&&(a=r[e].nodeIndex);let u=Array(a+1);if(u[0]=e,a>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=a&&(t=n.nextNode());)u[r++]=t}for(let e=0;e<t.length;e++){let t=r[e];i[e]=t?u[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers;if(!ge.has(e)||n.includes("capture")||n.includes("once")){let r={once:n.includes("once"),capture:n.includes("capture"),passive:n.includes("passive")},o=e=>{n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),(!n.includes("self")||e.target===e.currentTarget)&&t(e)};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r))}else{if(!P.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>_e(e,t,n);ve.set(e,r),document.addEventListener(e,r),P.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;c[r]=t,n.length>0&&(c[o]=n),l.push(()=>{c[r]=null,c[o]=null})}continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,l.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=!1,o=!1,i=!0,a=_(()=>{o=!!u();let l=()=>{t=!1;let l="show"===e?o:!o;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"};i?(i=!1,l()):t||(t=!0,N(l))});l.push(a)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r,o=!1,i=!0,a=_(()=>{r=u();let l=()=>{o=!1;let l=r;n?t[e]=l??"":null==l||!1===l?t.removeAttribute(e):t.setAttribute(e,String(l))};i?(i=!1,l()):o||(o=!0,N(l))});l.push(a)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;let d=document.createTextNode("");f.parentNode.replaceChild(d,f),fe(d,u,l,o)}return{disposes:l,postMountHooks:o}}function be(e,t){let n=new Uint8Array(e.length),r="";for(let l=0;l<e.length;l++){let o=e[l];if(1===n[l]&&('"'===o[0]||"'"===o[0])&&(o=o.slice(1)),l<t.length){let e=t[l];if("node"===e.type)r+=o+`\x3c!--nix-${l}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+ +!!e.hadOpenQuote;r+=o.slice(0,-t)+` data-nix-e-${l}="${e.eventName}"`,e.hadOpenQuote&&(n[l+1]=1)}else{let t=`${e.attrName}=`.length+ +!!e.hadOpenQuote;r+=o.slice(0,-t)+` data-nix-a-${l}="${e.attrName}"`,e.hadOpenQuote&&(n[l+1]=1)}}else r+=o}return r}var F=new WeakMap;function I(e,...t){let n=F.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(me(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=be(e,t);let o,i=Array(t.length).fill(null),a=l.content,u=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),s=0;for(;o=u.nextNode();)if(s++,8===o.nodeType){let e=o.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:s})}}else if(1===o.nodeType){let e=o,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],l=r.name;if(l.startsWith("data-nix-e-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l));continue}if(l.startsWith("data-nix-a-")){let t=parseInt(l.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(l))}}}n={contexts:t,tpl:l,pathMap:i},F.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:a,postMountHooks:u}=ye(i,r,t,o),s=document.createTextNode(""),c=document.createTextNode("");return e.insertBefore(s,n),e.insertBefore(i,n),e.insertBefore(c,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==c;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s),c.parentNode?.removeChild(c)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function xe(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function L(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function R(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(L(r.transitionDuration||"0"),L(r.animationDuration||"0")),o=l>0?l+100:t;if(o<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},o)})}function Se(e,t={}){let n=xe(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,l){let o=document.createComment(S.TRANSITION);r.insertBefore(o,l);let i=null,a=null,u=0,s=!0,c=()=>{let e=o.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return T(e)?ce(e,r,l):e._render(r,l)}let d=(e,r=!1)=>{u++,a&&=(a(),null),i=f(e);let l=c();if(l&&(!s||t.appear)&&!r){let e=u;(async()=>{t.onBeforeEnter?.(l),l.classList.add(n.enterFrom,n.enterActive),l.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===e&&(l.classList.remove(n.enterFrom),l.classList.add(n.enterTo),await R(l,t.duration),u===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let l=++u;a=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===l&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await R(r,t.duration),u===l&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),a?.(),a=null))})().catch(()=>{})},h=null;if("function"!=typeof e||T(e))d(e);else{let t=e,n=null;h=_(()=>{let e=t(),r=null===n,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,h?.(),i?.(),a?.(),i=null,a=null,o.remove()}}}}function Ce(){return{__isPortalOutlet:!0,_container:null}}function we(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function Te(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)?se(e,l,null):e._render(l,null)}}}var z=E("nix:portal-outlet");function Ee(e){ae(z,e)}function De(){return oe(z)}function Oe(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(S.ERROR_BOUNDARY);n.insertBefore(l,r);let i,a=null,u=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||T(t)?t:t(e);a=T(o)?ce(o,n,r):o._render(n,r)};o(e=>{u||(u=!0,c?(a?.(),a=null,d(e)):(i=e,f=!0))});try{if(T(e)){O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(n,r)}finally{k()}if(!u)try{let t=e.onMount?.(),n=a;a=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else a=e._render(n,r)}catch(e){u=!0,a?.(),a=null,i=e,f=!0}finally{s(),c=!0}return f&&(a?.(),a=null,d(i)),()=>{a?.(),l.remove()}}}}function ke(e,t){if(T(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: container not found: ${t}`);O();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{k()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function Ae(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=g(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var B=null,V=null;function H(){if(!B)throw Error("[Nix] No active router. Call createRouter() first.");return B}function U(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function je(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function Me(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Ne(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Pe(e,t="",n=[]){let r=[];for(let l of e){let e=Ne(t,l.path),o=[...n,l.component],i=Me(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...Pe(l.children,e,o))}return r}function Fe(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let l=r.length>0&&"wildcard"===r[r.length-1].kind,o=l?r.slice(0,-1):r;if(l){if(n.length<o.length)return null}else if(n.length!==o.length)return null;let i={};for(let e=0;e<o.length;e++){let t=o[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Ie(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},l=-1;for(let o of t){let t=Fe(e,o);if(null===t)continue;let i=Ie(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function G(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Le(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return G(new URL(t,window.location.origin).pathname)}catch{return G(t)}}function Re(e,t){let n=null==t?.base?Le():G(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function l(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let o=r(),i=Pe(e),a=W(o,i),u=g(o),s=g(a?.params??{}),c=g(U(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,l){let o=[...f];n&&o.push(n);let i=++p;if(0===o.length)return void r();let a=0;!function n(u){if(i!==p)return;if(!1===u)return void l?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=o.length)return void r();let s=o[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function m(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),l=-1===n?{}:U(e.slice(n)),o=t?{...l,...t}:l,i={};for(let[e,t]of Object.entries(o))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}V&&=(V(),null);let y=()=>{let e=r(),t=u.value,n=c.value,o=W(e,i),a=U(window.location.search);h(e,t,o?.route.beforeEnter,()=>{s.value=o?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",l(t)+je(n))})};function _(e,t,n,r,o){s.value=r?.params??{},c.value=t,u.value=e;let i=l(e)+je(t);o?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=u.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!1))}window.addEventListener("popstate",y),V=()=>window.removeEventListener("popstate",y);let x={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=m(e,t),l=u.value,o=W(n,i);h(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=W(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return B&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),B=x,queueMicrotask(()=>{v||h(o,"",W(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=W("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function ze(){return H()}var Be=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=H(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Ve=class extends w{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return I`<a
|
|
4
4
|
href=${(H()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
@@ -18,4 +18,4 @@ var e=[],t=[],n=null,r=null,i=null,a=[];function o(e){a.push(i),i=e}function s()
|
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}var K=new Map,We=3e5,q=null,Ge=We;function Ke(){null===q&&(q=setInterval(()=>{let e=Date.now();for(let[t,n]of K)n.subscribers<=0&&e-n.fetchedAt>Ge&&K.delete(t);0===K.size&&null!==q&&(clearInterval(q),q=null)},6e4))}function J(e){
|
|
21
|
+
`}var K=new Map,We=3e5,q=null,Ge=We;function Ke(){null===q&&(q=setInterval(()=>{let e=Date.now();for(let[t,n]of K)n.subscribers<=0&&e-n.fetchedAt>Ge&&K.delete(t);0===K.size&&null!==q&&(clearInterval(q),q=null)},6e4))}function J(e){let t=K.get(e);if(t&&t.fetchedAt>0)return t}function qe(e,t){let n=K.get(e);K.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Ke()}function Je(e){let t=K.get(e);t?t.subscribers++:K.set(e,{fetchedAt:0,subscribers:1})}function Ye(e){let t=K.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Xe(e,t){let n=K.get(e);return!!n&&Date.now()-n.fetchedAt<t}function Ze(e){void 0===e?(K.clear(),null!==q&&(clearInterval(q),q=null)):K.delete(e)}function Qe(e){Ge=e}function $e(e,t,n={}){let{fallback:r,errorFallback:l,resetOnRefresh:o=!1,invalidate:i,cacheKey:a,staleTime:u=0}=n,s=r??He(),c=l??Ue;return new class extends w{_state;_disposeWatcher;constructor(){super();let e=a?J(a):void 0;this._state=g(e&&void 0!==e.data?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){a&&Je(a);let e=a?J(a):void 0;if(e&&Xe(a,u)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=_(()=>{i.value,e?e=!1:(a&&K.delete(a),this._run())})}return()=>{this._disposeWatcher?.(),a&&Ye(a)}}_run(){(o||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{a&&qe(a,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return I`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Y=new Map,et=new FinalizationRegistry(({key:e,ref:t})=>{let n=Y.get(e);n&&(n.delete(t),0===n.size&&Y.delete(e))});function tt(e){K.delete(e);let t=Y.get(e);if(t){for(let e of t){let n=e.deref();n?n():t.delete(e)}0===t.size&&Y.delete(e)}}function nt(e,t,n={}){let{staleTime:r=0,refetchOnMount:l="always"}=n,o=J(e),i=g(o?"success":"pending"),a=g(o?.data),u=g(void 0),s=()=>{t().then(t=>{qe(e,t),a.value=t,u.value=void 0,i.value="success"},e=>{u.value=e,i.value="error"})},c=()=>{"pending"===i.peek()&&(a.value=void 0,u.value=void 0),s()};Y.has(e)||Y.set(e,new Set);let f=Y.get(e),d=new WeakRef(c);f.add(d),et.register(c,{key:e,ref:d});let p=Xe(e,r);return o?!1===l||"stale"===l&&p||"always"===l&&p&&r>0||s():c(),{status:i,data:a,error:u,refetch:()=>{K.delete(e),c()}}}function rt(e,t){let n=null;return()=>n?new n:$e(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function it(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function X(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function at(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Z(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function ot(e="Invalid email"){return Z(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function st(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function ct(e){return e}var lt={required:it,minLength:X,maxLength:at,email:ot,pattern:Z,min:st,max:Q};function ut(e,t){return{...e,...t}}function $(e,t=[],n="blur"){let r=g(e),l=g(!1),o=g(!1),i=g(null),a=g(!1),u=v(()=>{if(i.value)return i.value;if(!("input"===n?o.value||l.value:"submit"===n?a.value:l.value))return null;for(let e of t){let t=e(r.value);if(t)return t}return null});function s(t){if(!t||!("value"in t))return e;let n=t;return"boolean"==typeof e?n.checked:"number"==typeof e?Number(n.value):n.value}return{value:r,error:u,touched:l,dirty:o,onInput:e=>{r.value=s(e.target),o.value=!0,i.value=null},onBlur:()=>{l.value=!0},reset:function(){r.value=e,l.value=!1,o.value=!1,i.value=null,a.value=!1},_setExternalError:function(e){i.value=e,e&&(l.value=!0)},_forceVisible:function(){l.value=!0,a.value=!0},_dispose:function(){u.dispose()}}}function dt(e,t={},n="blur"){function r(e){let r={};for(let l in e){let o=t[l]??[];r[l]=$(e[l],o,n)}return r}let l=g(e.map(r)),o=v(()=>l.value.length);return{fields:l,append:function(e){l.value=[...l.value,r(e)]},remove:function(e){let t=l.value;if(!(e<0||e>=t.length)){for(let n in t[e])t[e][n]._dispose();l.value=t.filter((t,n)=>n!==e)}},move:function(e,t){let n=[...l.value];if(e<0||e>=n.length||t<0||t>=n.length||e===t)return;let[r]=n.splice(e,1);n.splice(t,0,r),l.value=n},replace:function(e,t){let n=[...l.value];if(!(e<0||e>=n.length)){for(let t in n[e])n[e][t]._dispose();n[e]=r(t),l.value=n}},length:o,reset:function(){for(let e of l.value)for(let t in e)e[t]._dispose();l.value=e.map(r)},_dispose:function(){for(let e of l.value)for(let t in e)e[t]._dispose();o.dispose()}}}function ft(e,t={}){let n=t.validateOn??"blur",r={};for(let l in e){let o=t.validators?.[l]??[];r[l]=$(e[l],o,n)}let l=g(!1),o=g(0),i=v(()=>{let e={};for(let t in r)e[t]=r[t].value.value;return e}),a=v(()=>{let e={};for(let t in r){let n=r[t].error.value;n&&(e[t]=n)}return e}),u=v(()=>{for(let e in r)if(r[e].error.value)return!1;return!0}),s=v(()=>{for(let e in r)if(r[e].dirty.value)return!0;return!1}),c=v(()=>{for(let e in r)if(r[e].touched.value)return!0;return!1});function f(e){for(let t in e)r[t]?._setExternalError(e[t]??null)}return{fields:r,values:i,errors:a,valid:u,dirty:s,touched:c,isSubmitting:l,submitCount:o,handleSubmit:function(e){return n=>{n.preventDefault(),o.value++;for(let e in r)r[e]._forceVisible();let a=i.value;if(t.validate){let e=t.validate(a);if(e){let t={},n=!1;for(let r in e){let l=e[r],o=Array.isArray(l)?l[0]??null:l??null;o&&(t[r]=o,n=!0)}if(n)return void f(t)}}for(let e in r)if(r[e].error.value)return;let u=e(a);u instanceof Promise&&(l.value=!0,u.finally(()=>{l.value=!1}).catch(()=>{}))}},reset:function(){for(let e in r)r[e].reset();l.value=!1,o.value=0},setErrors:f,dispose:function(){i.dispose(),a.dispose(),u.dispose(),s.dispose(),c.dispose();for(let e in r)r[e]._dispose()}}}export{Ve as Link,w as NixComponent,Be as RouterView,h as Signal,y as batch,Ze as clearQueryCache,v as computed,Oe as createErrorBoundary,ft as createForm,E as createInjectionKey,Ce as createPortalOutlet,nt as createQuery,Re as createRouter,Ae as createStore,ct as createValidator,_ as effect,ot as email,ut as extendValidators,I as html,oe as inject,De as injectOutlet,tt as invalidateQueries,rt as lazy,Q as max,at as maxLength,st as min,X as minLength,ke as mount,ee as nextTick,Z as pattern,Te as portal,we as portalOutlet,ae as provide,Ee as provideOutlet,te as ref,ue as repeat,it as required,Qe as setQueryCacheTime,pe as showWhen,g as signal,$e as suspend,Se as transition,b as untrack,$ as useField,dt as useFieldArray,ze as useRouter,lt as validators,x as watch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "A lightweight, fully reactive micro-framework — no virtual DOM, no compiler, just signals and tagged templates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Deiver Vasquez",
|
|
@@ -51,10 +51,12 @@
|
|
|
51
51
|
"build:lib": "vite build --config vite.lib.config.ts && tsc --project tsconfig.lib.json && terser dist/lib/nix-js.js -c -m -o dist/lib/nix-js.js && terser dist/lib/nix-js.cjs -c -m -o dist/lib/nix-js.cjs",
|
|
52
52
|
"typecheck": "tsc --noEmit",
|
|
53
53
|
"test": "vitest run",
|
|
54
|
+
"coverage": "vitest run --coverage",
|
|
54
55
|
"prepublishOnly": "bun run build:lib && cp README.md .readme-full.md && cp .readme-npm.md README.md",
|
|
55
56
|
"postpublish": "mv .readme-full.md README.md"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
59
|
+
"@vitest/coverage-v8": "^4.1.3",
|
|
58
60
|
"happy-dom": "^20.8.3",
|
|
59
61
|
"terser": "^5.46.0",
|
|
60
62
|
"typescript": "~5.9.3",
|