@deijose/nix-js 1.5.1-beta.0 → 1.5.1-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/nix-js.cjs +1 -1
- package/dist/lib/nix-js.js +1 -1
- package/package.json +1 -1
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.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(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}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 O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(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 M(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 N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(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,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(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(r,o){let l,i=n();return i.run(()=>{let n;if(n="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)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(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(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,p=!1,h=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,h(e)):(a=e,p=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,p=!0}finally{d(),f=!0}p&&(s?.(),s=null,h(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(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 P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=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()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function p(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let h=(e,n=!1)=>{c++,s&&=(s(),null),u=p(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))h(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?h(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,h(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let p=null,h=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return h&&=(h(),null),void(p?p.nodeValue=String(e):(p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)));if(p&&=(p.parentNode?.removeChild(p),null),h&&=(h(),null),null!=e&&!1!==e)if(I(e))h=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}h=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}h=()=>{for(let e=0;e<t.length;e++)t[e]()}}else p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)}),r(()=>{if(h&&=(h(),null),p&&=(p.parentNode?.removeChild(p),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=Array.from(n.childNodes);e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{u.stop();for(let e=0;e<c.length;e++)c[e].parentNode?.removeChild(c[e])}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}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 be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(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 xe(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 Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[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 Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(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 o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++p;if(0===l.length)return void r();let a=0;!function n(u){if(i!==p)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():x(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);h(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function x(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let b={current:u,params:s,query:c,base:n||"/",navigate:x,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!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=K(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 V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=b,queueMicrotask(()=>{m||h(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.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(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}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 O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(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 M(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 N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(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,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(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(r,o){let l,i=n();return i.run(()=>{let n;if(n="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)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(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(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,p=!1,h=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,h(e)):(a=e,p=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,p=!0}finally{d(),f=!0}p&&(s?.(),s=null,h(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(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 P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=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()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function p(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let h=(e,n=!1)=>{c++,s&&=(s(),null),u=p(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))h(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?h(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,h(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let p=null,h=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return h&&=(h(),null),void(p?p.nodeValue=String(e):(p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)));if(p&&=(p.parentNode?.removeChild(p),null),h&&=(h(),null),null!=e&&!1!==e)if(I(e))h=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}h=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}h=()=>{for(let e=0;e<t.length;e++)t[e]()}}else p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)}),r(()=>{if(h&&=(h(),null),p&&=(p.parentNode?.removeChild(p),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=document.createComment("nix-s"),f=document.createComment("nix-e");n.insertBefore(c,n.firstChild),n.appendChild(f),e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{if(u.stop(),c.parentNode){let e=document.createRange();e.setStartBefore(c),e.setEndAfter(f),e.deleteContents()}}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}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 be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(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 xe(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 Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[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 Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(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 o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++p;if(0===l.length)return void r();let a=0;!function n(u){if(i!==p)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():x(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);h(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function x(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let b={current:u,params:s,query:c,base:n||"/",navigate:x,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!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=K(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 V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=b,queueMicrotask(()=>{m||h(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Ae=class extends w{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return B`<a
|
|
4
4
|
href=${(U()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var e=null,t=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.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(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}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 O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(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 M(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 N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(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,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(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(r,o){let l,i=n();return i.run(()=>{let n;if(n="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)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(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(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,h=!1,p=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,p(e)):(a=e,h=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,h=!0}finally{d(),f=!0}h&&(s?.(),s=null,p(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(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 P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=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()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function h(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let p=(e,n=!1)=>{c++,s&&=(s(),null),u=h(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))p(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?p(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,p(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let h=null,p=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(h?h.nodeValue=String(e):(h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)));if(h&&=(h.parentNode?.removeChild(h),null),p&&=(p(),null),null!=e&&!1!==e)if(I(e))p=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}p=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}p=()=>{for(let e=0;e<t.length;e++)t[e]()}}else h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)}),r(()=>{if(p&&=(p(),null),h&&=(h.parentNode?.removeChild(h),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=Array.from(n.childNodes);e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{u.stop();for(let e=0;e<c.length;e++)c[e].parentNode?.removeChild(c[e])}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}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 be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(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 xe(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 Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[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 Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(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 o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],h=0;function p(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++h;if(0===l.length)return void r();let a=0;!function n(u){if(i!==h)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);p(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let w={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!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=K(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 V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=w,queueMicrotask(()=>{m||p(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),w}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
var e=null,t=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.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(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}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 O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(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 M(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 N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(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,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(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(r,o){let l,i=n();return i.run(()=>{let n;if(n="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)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(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(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,h=!1,p=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,p(e)):(a=e,h=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,h=!0}finally{d(),f=!0}h&&(s?.(),s=null,p(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(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 P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=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()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function h(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let p=(e,n=!1)=>{c++,s&&=(s(),null),u=h(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))p(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?p(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,p(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let h=null,p=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(h?h.nodeValue=String(e):(h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)));if(h&&=(h.parentNode?.removeChild(h),null),p&&=(p(),null),null!=e&&!1!==e)if(I(e))p=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}p=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}p=()=>{for(let e=0;e<t.length;e++)t[e]()}}else h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)}),r(()=>{if(p&&=(p(),null),h&&=(h.parentNode?.removeChild(h),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=document.createComment("nix-s"),f=document.createComment("nix-e");n.insertBefore(c,n.firstChild),n.appendChild(f),e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{if(u.stop(),c.parentNode){let e=document.createRange();e.setStartBefore(c),e.setEndAfter(f),e.deleteContents()}}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}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 be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(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 xe(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 Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[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 Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(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 o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],h=0;function p(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++h;if(0===l.length)return void r();let a=0;!function n(u){if(i!==h)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);p(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let w={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!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=K(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 V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=w,queueMicrotask(()=>{m||p(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),w}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Ae=class extends w{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return B`<a
|
|
4
4
|
href=${(U()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.5.1-beta.
|
|
3
|
+
"version": "1.5.1-beta.2",
|
|
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
|
"homepage": "https://nix-js-landing.vercel.app/",
|