@deijose/nix-js 2.5.2 → 2.5.4

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.
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./lifecycle.cjs"),t=require("./context.cjs"),n=require("./router.cjs");function r(t){let o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);return o}function i(o,u,i){if(e.isNixComponent(o)){let c=r(u);e._debugComponentMountStart(o),t._pushComponentContext();let p,l=()=>{},f=!1;try{i?.router&&t.provide(n.RouterKey,i.router);try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}try{l=o.render()._render(c,null)}catch(t){if(!o.onError)throw t;o.onError(t),l=()=>{},f=!0}}finally{e._debugComponentMountEnd(o),t._popComponentContext()}if(!f)try{let t=o.onMount?.();"function"==typeof t&&(p=t)}catch(t){if(!o.onError)throw t;o.onError(t)}return{unmount(){try{o.onUnmount?.()}catch{}try{p?.()}catch{}l(),e._debugComponentUnmount(o)}}}if(!i?.router)return o.mount(u);let c,p=r(u);t._pushComponentContext();try{t.provide(n.RouterKey,i.router),c=o._render(p,null)}finally{t._popComponentContext()}return{unmount(){c()}}}exports.mount=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./lifecycle.cjs"),t=require("./context.cjs"),n=require("./router.cjs");function r(t){let r="string"==typeof t?document.querySelector(t):t;if(!r)throw Error(`[Nix] mount: container not found: ${t}`);return r}function i(o,u,i){if(e.isNixComponent(o)){let c=r(u);e._debugComponentMountStart(o),t._pushComponentContext();let p,l=()=>{},d=!1;try{i?.router&&(t.provide(n.RouterKey,i.router),n._debugRegisterRouter(i.router));try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}try{l=o.render()._render(c,null)}catch(t){if(!o.onError)throw t;o.onError(t),l=()=>{},d=!0}}finally{e._debugComponentMountEnd(o),t._popComponentContext()}if(!d)try{let t=o.onMount?.();"function"==typeof t&&(p=t)}catch(t){if(!o.onError)throw t;o.onError(t)}return{unmount(){try{o.onUnmount?.()}catch{}try{p?.()}catch{}l(),i?.router&&n._debugUnregisterRouter(i.router),e._debugComponentUnmount(o)}}}if(!i?.router)return o.mount(u);let c,p=r(u);t._pushComponentContext();try{t.provide(n.RouterKey,i.router),n._debugRegisterRouter(i.router),c=o._render(p,null)}finally{t._popComponentContext()}return{unmount(){c(),n._debugUnregisterRouter(i.router)}}}exports.mount=i;
@@ -1 +1 @@
1
- import{_debugComponentMountEnd as e,_debugComponentMountStart as t,_debugComponentUnmount as n,isNixComponent as r}from"./lifecycle.js";import{_popComponentContext as i,_pushComponentContext as a,provide as o}from"./context.js";import{RouterKey as s}from"./router.js";function c(o){let r="string"==typeof o?document.querySelector(o):o;if(!r)throw Error(`[Nix] mount: container not found: ${o}`);return r}function l(u,m,f){if(r(u)){let r=c(m);t(u),a();let l,p=()=>{},y=!1;try{f?.router&&o(s,f.router);try{u.onInit?.()}catch(o){if(!u.onError)throw o;u.onError(o)}try{p=u.render()._render(r,null)}catch(o){if(!u.onError)throw o;u.onError(o),p=()=>{},y=!0}}finally{e(u),i()}if(!y)try{let o=u.onMount?.();"function"==typeof o&&(l=o)}catch(o){if(!u.onError)throw o;u.onError(o)}return{unmount(){try{u.onUnmount?.()}catch{}try{l?.()}catch{}p(),n(u)}}}if(!f?.router)return u.mount(m);let l,p=c(m);a();try{o(s,f.router),l=u._render(p,null)}finally{i()}return{unmount(){l()}}}export{l as mount};
1
+ import{_debugComponentMountEnd as e,_debugComponentMountStart as t,_debugComponentUnmount as n,isNixComponent as r}from"./lifecycle.js";import{_popComponentContext as i,_pushComponentContext as a,provide as o}from"./context.js";import{RouterKey as s,_debugRegisterRouter as c,_debugUnregisterRouter as l}from"./router.js";function u(r){let t="string"==typeof r?document.querySelector(r):r;if(!t)throw Error(`[Nix] mount: container not found: ${r}`);return t}function d(m,f,p){if(r(m)){let r=u(f);t(m),a();let d,y=()=>{},h=!1;try{p?.router&&(o(s,p.router),c(p.router));try{m.onInit?.()}catch(r){if(!m.onError)throw r;m.onError(r)}try{y=m.render()._render(r,null)}catch(r){if(!m.onError)throw r;m.onError(r),y=()=>{},h=!0}}finally{e(m),i()}if(!h)try{let r=m.onMount?.();"function"==typeof r&&(d=r)}catch(r){if(!m.onError)throw r;m.onError(r)}return{unmount(){try{m.onUnmount?.()}catch{}try{d?.()}catch{}y(),p?.router&&l(p.router),n(m)}}}if(!p?.router)return m.mount(f);let d,y=u(f);a();try{o(s,p.router),c(p.router),d=m._render(y,null)}finally{i()}return{unmount(){d(),l(p.router)}}}export{d as mount};
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./lifecycle.cjs"),n=require("./router.cjs");var r={enabled:!1,activeTab:"signals",renderedTab:null,refreshId:null,root:null,panel:null,content:null,dispose:null,renderKeys:{signals:"",components:"",router:""},scrollMemo:{signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}}},i=new Set,a=new WeakMap,o=1,s=new WeakMap,c=new Map,l=[],u=1;function d(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function f(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function p(e,t){let n=a.get(e);if(n)return n;let r=Date.now(),l={id:o++,createdAt:r,lastUpdated:r,history:[{at:r,value:t}]};return a.set(e,l),i.add(d(e)),l}function m(){let e=[];for(let t of Array.from(i)){let n=t.deref();if(!n){i.delete(t);continue}let o=a.get(n);if(!o)continue;let r=n._subs?.size??0;e.push({id:o.id,value:n.peek(),subscriberCount:r,createdAt:o.createdAt,lastUpdated:o.lastUpdated,history:o.history.slice()})}return e.sort((e,t)=>t.lastUpdated-e.lastUpdated),e}function h(e){let t=e._debugName;if(t&&t.trim())return t;let n=e.constructor;return n?.name&&n.name.trim()?n.name:"AnonymousComponent"}function g(e){let t=e._slots;return t instanceof Map?Array.from(t.keys()).map(e=>String(e)):[]}function _(e){let t={};for(let n of Object.keys(e)){if("__isNixComponent"===n||"children"===n||"_debugName"===n||n.startsWith("_"))continue;let o=e[n];"function"!=typeof o&&(t[n]=o)}return t}function v(e){if(!e)return[];if("*"===e)return["*"];let t=e.split("/").filter(Boolean),n=[],o="";for(let e of t)o+="/"+e,n.push(o);return n.length>0?n:["/"]}function y(){let e=[];for(let[t,n]of c){let o=n.ref.deref();o?(n.debugName=h(o),n.hasDefaultSlot=null!=o.children,n.slotNames=g(o),n.props=_(o),e.push({id:n.id,parentId:n.parentId,debugName:n.debugName,mountedAt:n.mountedAt,hasDefaultSlot:n.hasDefaultSlot,slotNames:[...n.slotNames],props:{...n.props}})):c.delete(t)}return e.sort((e,t)=>e.id-t.id),e}function b(e){let t=[e];for(;t.length>0;){let e=t.pop();for(let[n,o]of c)o.parentId===e&&t.push(n);c.delete(e)}}function x(){i.clear(),a=new WeakMap,o=1,s=new WeakMap,c.clear(),l.length=0,u=1}function S(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||null==e)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function C(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}function w(e,t=90){let n=S(e);return n.length<=t?n:n.slice(0,t-1)+"…"}function T(e){if(!e)return"-";let t=Date.now()-e;return t<1e3?`${t}ms ago`:t<6e4?`${Math.floor(t/1e3)}s ago`:`${Math.floor(t/6e4)}m ago`}function E(e){let t=m(),n=`${t.length}:${t.map(e=>`${e.id}-${e.lastUpdated}-${e.subscriberCount}`).join("|")}`;if("signals"===r.renderedTab&&r.renderKeys.signals===n)return;r.renderKeys.signals=n,r.renderedTab="signals";let o=t.map(e=>{let t=S(e.value),n=w(e.value,120);return`<tr data-nix-devtools-signal-id="${e.id}">\n <td style="padding:6px 8px;white-space:nowrap;">${e.id}</td>\n <td style="padding:6px 8px;max-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;" title="${C(t)}">${C(n)}</td>\n <td>${e.subscriberCount}</td>\n <td>${T(e.lastUpdated)}</td>\n </tr>`}).join("");e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Signals</strong>\n <span style="opacity:.8">${t.length} active</span>\n </div>\n <div data-nix-devtools-scroll="signals" style="max-height:260px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n <table style="width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed;">\n <thead>\n <tr style="background:#1f1f24;">\n <th style="text-align:left;padding:6px 8px;width:42px;">ID</th>\n <th style="text-align:left;padding:6px 8px;">Value</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">Subs</th>\n <th style="text-align:left;padding:6px 8px;width:84px;">Updated</th>\n </tr>\n </thead>\n <tbody>${o}</tbody>\n </table>\n </div>\n <p style="margin:8px 0 0 0;font-size:11px;opacity:.75;">Click a row to log full history in console.</p>\n `;for(let n of e.querySelectorAll("tr[data-nix-devtools-signal-id]"))n.style.cursor="pointer",n.addEventListener("click",()=>{let e=Number(n.dataset.nixDevtoolsSignalId),o=t.find(t=>t.id===e);o&&(console.group(`[Nix DevTools] Signal #${o.id}`),console.log("Current value:",o.value),console.log("Subscribers:",o.subscriberCount),console.table(o.history.map(e=>({at:new Date(e.at).toISOString(),value:e.value}))),console.groupEnd())})}function D(e){let t=new Map,n=[];for(let n of e)t.set(n.id,{...n,children:[]});for(let e of t.values()){if(null==e.parentId){n.push(e);continue}let o=t.get(e.parentId);o?o.children.push(e):n.push(e)}return n}function O(e,t){let n=10+14*t,o=Object.keys(e.props).length>0?S(e.props):"{}",r=e.slotNames.length>0?e.slotNames.join(", "):"none";return`<div style="padding:6px 8px 6px ${n}px;border-bottom:1px solid #24242b;">\n <div><strong>${C(e.debugName)}</strong> <span style="opacity:.7">#${e.id}</span></div>\n <div style="font-size:11px;opacity:.8;">slots: ${r} | default-slot: ${e.hasDefaultSlot?"yes":"no"}</div>\n <div style="font-size:11px;opacity:.8;">props: ${C(w(o,180))}</div>\n </div>`+e.children.map(e=>O(e,t+1)).join("")}function k(e){let t=y(),o=n._debugGetRouterInternal(),l=`${o?`${o.currentPath}|${o.matchedPath??""}`:"no-router"}:${t.length}:${t.map(e=>`${e.id}-${e.parentId}-${e.debugName}-${e.hasDefaultSlot}-${e.slotNames.join(",")}-${S(e.props)}`).join("|")}`;if("components"===r.renderedTab&&r.renderKeys.components===l)return;r.renderKeys.components=l,r.renderedTab="components";let a=D(t);e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Component Tree</strong>\n <span style="opacity:.8">${t.length} mounted</span>\n </div>\n <div style="font-size:11px;opacity:.82;margin-bottom:8px;display:flex;gap:8px;flex-wrap:wrap;">\n <span><b>current:</b> ${C(o?.currentPath??"-")}</span>\n <span><b>matched:</b> ${C(o?.matchedPath??"none")}</span>\n </div>\n <div data-nix-devtools-scroll="components" style="max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n ${a.length>0?a.map(e=>O(e,0)).join(""):"<div style='padding:10px;opacity:.75'>No mounted components tracked. Enable devtools before your first mount() to capture initial tree.</div>"}\n </div>\n `}function A(e){let t=n._debugGetRouterInternal(),o=t?`${t.mode}|${t.base}|${t.currentPath}|${JSON.stringify(t.params)}|${JSON.stringify(t.query)}|${t.matchedPath}|${t.activeGuards.names.join(",")}`:"none";if("router"===r.renderedTab&&r.renderKeys.router===o)return;if(r.renderKeys.router=o,r.renderedTab="router",!t)return void(e.innerHTML='\n <strong>Router State</strong>\n <div style="margin-top:8px;opacity:.75">No active Nix router instance. Ensure your app uses createRouter()/RouterView from @deijose/nix-js/router.</div>\n ');let l=v(t.matchedPath);e.innerHTML=`\n <strong>Router State</strong>\n <div data-nix-devtools-scroll="router" style="margin-top:8px;font-size:12px;line-height:1.55;max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;padding:8px;">\n <div><b>mode</b>: ${t.mode}</div>\n <div><b>base</b>: ${t.base}</div>\n <div><b>current</b>: ${C(t.currentPath)}</div>\n <div><b>params</b>: ${C(S(t.params))}</div>\n <div><b>query</b>: ${C(S(t.query))}</div>\n <div><b>matched</b>: ${C(t.matchedPath??"none")}</div>\n <div><b>matched chain</b>: ${l.length>0?C(l.join(" -> ")):"none"}</div>\n <div><b>guards</b>: ${t.activeGuards.names.length>0?C(t.activeGuards.names.join(", ")):"none"}</div>\n </div>\n `}function j(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);t&&(r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft})}function M(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);if(!t)return;let n=r.scrollMemo[e];t.scrollTop=n.top,t.scrollLeft=n.left,"1"!==t.dataset.nixDevtoolsScrollBound&&(t.addEventListener("scroll",()=>{r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft}},{passive:!0}),t.dataset.nixDevtoolsScrollBound="1")}function N(e=!1){if(!r.content)return;let t=r.activeTab;return e||j(t),"signals"===r.activeTab?(E(r.content),void M("signals")):"components"===r.activeTab?(k(r.content),void M("components")):(A(r.content),void M("router"))}function P(){if(r.panel)for(let e of r.panel.querySelectorAll("button[data-nix-devtools-tab]")){let t=e.dataset.nixDevtoolsTab===r.activeTab;e.style.background=t?"#2d4c7a":"#1f1f24"}}function F(e){let t=document.createElement("div");t.setAttribute("data-nix-devtools-root",""),t.style.position="fixed",t.style.zIndex="2147483647",t.style.bottom="16px",t.style.right="bottom-right"===e.position?"16px":"auto",t.style.left="bottom-left"===e.position?"16px":"auto",t.style.fontFamily="ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif";let n=document.createElement("button");n.type="button",n.textContent="Nix DevTools",n.setAttribute("data-nix-devtools-button",""),n.style.background="#111827",n.style.color="#f9fafb",n.style.border="1px solid #374151",n.style.borderRadius="999px",n.style.padding="8px 12px",n.style.cursor="pointer",n.style.boxShadow="0 6px 18px rgba(0,0,0,.3)";let o=document.createElement("div");o.setAttribute("data-nix-devtools-panel",""),o.style.marginTop="8px",o.style.width="460px",o.style.maxWidth="min(92vw, 460px)",o.style.background="#15151b",o.style.color="#e5e7eb",o.style.border="1px solid #2f2f35",o.style.borderRadius="12px",o.style.padding="10px",o.style.display="none",o.style.boxShadow="0 14px 28px rgba(0,0,0,.35)";let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginBottom="10px";let a=document.createElement("div");a.setAttribute("data-nix-devtools-content","");let s=(e,t)=>{let n=document.createElement("button");return n.type="button",n.textContent=t,n.setAttribute("data-nix-devtools-tab",e),n.style.border="1px solid #353543",n.style.borderRadius="8px",n.style.padding="6px 9px",n.style.background="#1f1f24",n.style.color="#d1d5db",n.style.cursor="pointer",n.addEventListener("click",()=>{r.activeTab=e,P(),N(!0)}),n};l.appendChild(s("signals","Signals")),l.appendChild(s("components","Components")),l.appendChild(s("router","Router")),n.addEventListener("click",()=>{o.style.display="none"===o.style.display?"block":"none","block"===o.style.display&&(P(),N(!0))}),o.appendChild(l),o.appendChild(a),t.appendChild(n),t.appendChild(o),document.body.appendChild(t),r.root=t,r.panel=o,r.content=a}function I(){r.enabled&&(r.enabled=!1,null!=r.refreshId&&(clearInterval(r.refreshId),r.refreshId=null),e._setSignalDebugHooks(null),t._setComponentDebugHooks(null),x(),r.root?.parentNode&&r.root.parentNode.removeChild(r.root),r.root=null,r.panel=null,r.content=null,r.dispose=null,r.renderedTab=null,r.renderKeys={signals:"",components:"",router:""},r.scrollMemo={signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}})}function L(n={}){if(typeof document>"u")return{disable:()=>{}};if(r.enabled&&r.dispose)return{disable:r.dispose};let o=Math.max(100,n.refreshMs??350),a=Math.max(1,n.historyLimit??50),i=n.position??"bottom-right";r.enabled=!0,r.activeTab="signals",e._setSignalDebugHooks({onCreate(e,t){p(e,t)},onWrite(e,t){let n=p(e,t),o=Date.now();n.lastUpdated=o,n.history.push({at:o,value:t}),n.history.length>a&&n.history.splice(0,n.history.length-a)}}),t._setComponentDebugHooks({onMountStart(e){let t=s.get(e);t??(t=u++,s.set(e,t));let n=l.length>0?l[l.length-1]:null;c.set(t,{id:t,parentId:n,debugName:h(e),mountedAt:Date.now(),hasDefaultSlot:null!=e.children,slotNames:g(e),props:_(e),ref:f(e)}),l.push(t)},onMountEnd(e){let t=s.get(e);if(null==t)return;let n=c.get(t);if(n&&(n.debugName=h(e),n.hasDefaultSlot=null!=e.children,n.slotNames=g(e),n.props=_(e)),l[l.length-1]===t)return void l.pop();let o=l.lastIndexOf(t);o>=0&&l.splice(o,1)},onUnmount(e){let t=s.get(e);if(null==t)return;b(t);let n=l.lastIndexOf(t);n>=0&&l.splice(n,1)}}),F({position:i}),r.refreshId=setInterval(()=>{"block"===r.panel?.style.display&&N()},o),n.initiallyOpen&&r.panel&&(r.panel.style.display="block",P(),N(!0));let d=()=>I();return r.dispose=d,{disable:d}}exports.disableDevTools=I,exports.enableDevTools=L;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./lifecycle.cjs"),n=require("./router.cjs");var r={enabled:!1,activeTab:"signals",renderedTab:null,refreshId:null,root:null,panel:null,content:null,dispose:null,renderKeys:{signals:"",components:"",router:""},scrollMemo:{signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}}},i=new Set,a=new WeakMap,o=1,s=50,c=new WeakMap,l=new Map,u=[],d=1;function f(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function p(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function m(e){e.history.length>s&&e.history.splice(0,e.history.length-s)}function h(e,t){let n=a.get(e);if(n)return m(n),n;let r=Date.now(),l={id:o++,createdAt:r,lastUpdated:r,history:[{at:r,value:t}]};return a.set(e,l),i.add(f(e)),l}function g(){let e=[];for(let t of Array.from(i)){let n=t.deref();if(!n){i.delete(t);continue}let o=a.get(n);if(!o)continue;let r=n._subs?.size??0;e.push({id:o.id,value:n.peek(),subscriberCount:r,createdAt:o.createdAt,lastUpdated:o.lastUpdated,history:o.history.slice()})}return e.sort((e,t)=>t.lastUpdated-e.lastUpdated),e}function _(e){let t=e._debugName;if(t&&t.trim())return t;let n=e.constructor;return n?.name&&n.name.trim()?n.name:"AnonymousComponent"}function v(e){let t=e._slots;return t instanceof Map?Array.from(t.keys()).map(e=>String(e)):[]}function y(e){let t={};for(let n of Object.keys(e)){if("__isNixComponent"===n||"children"===n||"_debugName"===n||n.startsWith("_"))continue;let o=e[n];"function"!=typeof o&&(t[n]=o)}return t}function b(e){if(!e)return[];if("*"===e)return["*"];let t=e.split("/").filter(Boolean),n=[],o="";for(let e of t)o+="/"+e,n.push(o);return n.length>0?n:["/"]}function x(){let e=[];for(let[t,n]of l){let o=n.ref.deref();o?(n.debugName=_(o),n.hasDefaultSlot=null!=o.children,n.slotNames=v(o),n.props=y(o),e.push({id:n.id,parentId:n.parentId,debugName:n.debugName,mountedAt:n.mountedAt,hasDefaultSlot:n.hasDefaultSlot,slotNames:[...n.slotNames],props:{...n.props}})):l.delete(t)}return e.sort((e,t)=>e.id-t.id),e}function S(e){let t=[e];for(;t.length>0;){let e=t.pop();for(let[n,o]of l)o.parentId===e&&t.push(n);l.delete(e)}}function C(){i.clear(),a=new WeakMap,o=1,c=new WeakMap,l.clear(),u.length=0,d=1}function w(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||null==e)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function T(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}function E(e,t=90){let n=w(e);return n.length<=t?n:n.slice(0,t-1)+"…"}function D(e){if(!e)return"-";let t=Date.now()-e;return t<1e3?`${t}ms ago`:t<6e4?`${Math.floor(t/1e3)}s ago`:`${Math.floor(t/6e4)}m ago`}function O(e){let t=g(),n=`${t.length}:${t.map(e=>`${e.id}-${e.lastUpdated}-${e.subscriberCount}`).join("|")}`;if("signals"===r.renderedTab&&r.renderKeys.signals===n)return;r.renderKeys.signals=n,r.renderedTab="signals";let o=t.map(e=>{let t=w(e.value),n=E(e.value,120);return`<tr data-nix-devtools-signal-id="${e.id}">\n <td style="padding:6px 8px;white-space:nowrap;">${e.id}</td>\n <td style="padding:6px 8px;max-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;" title="${T(t)}">${T(n)}</td>\n <td>${e.subscriberCount}</td>\n <td data-nix-devtools-history-count="${e.history.length}">${e.history.length}</td>\n <td>${D(e.lastUpdated)}</td>\n </tr>`}).join("");e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Signals</strong>\n <span style="opacity:.8">${t.length} active</span>\n </div>\n <div data-nix-devtools-scroll="signals" style="max-height:260px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n <table style="width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed;">\n <thead>\n <tr style="background:#1f1f24;">\n <th style="text-align:left;padding:6px 8px;width:42px;">ID</th>\n <th style="text-align:left;padding:6px 8px;">Value</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">Subs</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">History</th>\n <th style="text-align:left;padding:6px 8px;width:84px;">Updated</th>\n </tr>\n </thead>\n <tbody>${o}</tbody>\n </table>\n </div>\n <p style="margin:8px 0 0 0;font-size:11px;opacity:.75;">Click a row to log full history in console.</p>\n `;for(let n of e.querySelectorAll("tr[data-nix-devtools-signal-id]"))n.style.cursor="pointer",n.addEventListener("click",()=>{let e=Number(n.dataset.nixDevtoolsSignalId),o=t.find(t=>t.id===e);o&&(console.group(`[Nix DevTools] Signal #${o.id}`),console.log("Current value:",o.value),console.log("Subscribers:",o.subscriberCount),console.table(o.history.map(e=>({at:new Date(e.at).toISOString(),value:e.value}))),console.groupEnd())})}function k(e){let t=new Map,n=[];for(let n of e)t.set(n.id,{...n,children:[]});for(let e of t.values()){if(null==e.parentId){n.push(e);continue}let o=t.get(e.parentId);o?o.children.push(e):n.push(e)}return n}function A(e,t){let n=10+14*t,o=Object.keys(e.props).length>0?w(e.props):"{}",r=e.slotNames.length>0?e.slotNames.join(", "):"none";return`<div style="padding:6px 8px 6px ${n}px;border-bottom:1px solid #24242b;">\n <div><strong>${T(e.debugName)}</strong> <span style="opacity:.7">#${e.id}</span></div>\n <div style="font-size:11px;opacity:.8;">slots: ${r} | default-slot: ${e.hasDefaultSlot?"yes":"no"}</div>\n <div style="font-size:11px;opacity:.8;">props: ${T(E(o,180))}</div>\n </div>`+e.children.map(e=>A(e,t+1)).join("")}function j(e){let t=x(),o=n._debugGetRouterInternal(),l=`${o?`${o.currentPath}|${o.matchedPath??""}`:"no-router"}:${t.length}:${t.map(e=>`${e.id}-${e.parentId}-${e.debugName}-${e.hasDefaultSlot}-${e.slotNames.join(",")}-${w(e.props)}`).join("|")}`;if("components"===r.renderedTab&&r.renderKeys.components===l)return;r.renderKeys.components=l,r.renderedTab="components";let a=k(t);e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Component Tree</strong>\n <span style="opacity:.8">${t.length} mounted</span>\n </div>\n <div style="font-size:11px;opacity:.82;margin-bottom:8px;display:flex;gap:8px;flex-wrap:wrap;">\n <span><b>current:</b> ${T(o?.currentPath??"-")}</span>\n <span><b>matched:</b> ${T(o?.matchedPath??"none")}</span>\n </div>\n <div data-nix-devtools-scroll="components" style="max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n ${a.length>0?a.map(e=>A(e,0)).join(""):"<div style='padding:10px;opacity:.75'>No mounted components tracked. Enable devtools before your first mount() to capture initial tree.</div>"}\n </div>\n `}function M(e){let t=n._debugGetRouterInternal(),o=t?`${t.mode}|${t.base}|${t.currentPath}|${JSON.stringify(t.params)}|${JSON.stringify(t.query)}|${t.matchedPath}|${t.activeGuards.names.join(",")}`:"none";if("router"===r.renderedTab&&r.renderKeys.router===o)return;if(r.renderKeys.router=o,r.renderedTab="router",!t)return void(e.innerHTML='\n <strong>Router State</strong>\n <div style="margin-top:8px;opacity:.75">No active Nix router instance. Ensure your app uses createRouter()/RouterView from @deijose/nix-js/router.</div>\n ');let l=b(t.matchedPath);e.innerHTML=`\n <strong>Router State</strong>\n <div data-nix-devtools-scroll="router" style="margin-top:8px;font-size:12px;line-height:1.55;max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;padding:8px;">\n <div><b>mode</b>: ${t.mode}</div>\n <div><b>base</b>: ${t.base}</div>\n <div><b>current</b>: ${T(t.currentPath)}</div>\n <div><b>params</b>: ${T(w(t.params))}</div>\n <div><b>query</b>: ${T(w(t.query))}</div>\n <div><b>matched</b>: ${T(t.matchedPath??"none")}</div>\n <div><b>matched chain</b>: ${l.length>0?T(l.join(" -> ")):"none"}</div>\n <div><b>guards</b>: ${t.activeGuards.names.length>0?T(t.activeGuards.names.join(", ")):"none"}</div>\n </div>\n `}function N(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);t&&(r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft})}function P(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);if(!t)return;let n=r.scrollMemo[e];t.scrollTop=n.top,t.scrollLeft=n.left,"1"!==t.dataset.nixDevtoolsScrollBound&&(t.addEventListener("scroll",()=>{r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft}},{passive:!0}),t.dataset.nixDevtoolsScrollBound="1")}function F(e=!1){if(!r.content)return;let t=r.activeTab;return e||N(t),"signals"===r.activeTab?(O(r.content),void P("signals")):"components"===r.activeTab?(j(r.content),void P("components")):(M(r.content),void P("router"))}function I(){if(r.panel)for(let e of r.panel.querySelectorAll("button[data-nix-devtools-tab]")){let t=e.dataset.nixDevtoolsTab===r.activeTab;e.style.background=t?"#2d4c7a":"#1f1f24"}}function L(e){let t=document.createElement("div");t.setAttribute("data-nix-devtools-root",""),t.style.position="fixed",t.style.zIndex="2147483647",t.style.bottom="16px",t.style.right="bottom-right"===e.position?"16px":"auto",t.style.left="bottom-left"===e.position?"16px":"auto",t.style.fontFamily="ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif";let n=document.createElement("button");n.type="button",n.textContent="Nix DevTools",n.setAttribute("data-nix-devtools-button",""),n.style.background="#111827",n.style.color="#f9fafb",n.style.border="1px solid #374151",n.style.borderRadius="999px",n.style.padding="8px 12px",n.style.cursor="pointer",n.style.boxShadow="0 6px 18px rgba(0,0,0,.3)";let o=document.createElement("div");o.setAttribute("data-nix-devtools-panel",""),o.style.marginTop="8px",o.style.width="460px",o.style.maxWidth="min(92vw, 460px)",o.style.background="#15151b",o.style.color="#e5e7eb",o.style.border="1px solid #2f2f35",o.style.borderRadius="12px",o.style.padding="10px",o.style.display="none",o.style.boxShadow="0 14px 28px rgba(0,0,0,.35)";let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginBottom="10px";let a=document.createElement("div");a.setAttribute("data-nix-devtools-content","");let s=(e,t)=>{let n=document.createElement("button");return n.type="button",n.textContent=t,n.setAttribute("data-nix-devtools-tab",e),n.style.border="1px solid #353543",n.style.borderRadius="8px",n.style.padding="6px 9px",n.style.background="#1f1f24",n.style.color="#d1d5db",n.style.cursor="pointer",n.addEventListener("click",()=>{r.activeTab=e,I(),F(!0)}),n};l.appendChild(s("signals","Signals")),l.appendChild(s("components","Components")),l.appendChild(s("router","Router")),n.addEventListener("click",()=>{o.style.display="none"===o.style.display?"block":"none","block"===o.style.display&&(I(),F(!0))}),o.appendChild(l),o.appendChild(a),t.appendChild(n),t.appendChild(o),document.body.appendChild(t),r.root=t,r.panel=o,r.content=a}function R(){r.enabled&&(r.enabled=!1,null!=r.refreshId&&(clearInterval(r.refreshId),r.refreshId=null),e._setSignalDebugHooks(null),t._setComponentDebugHooks(null),C(),r.root?.parentNode&&r.root.parentNode.removeChild(r.root),r.root=null,r.panel=null,r.content=null,r.dispose=null,r.renderedTab=null,r.renderKeys={signals:"",components:"",router:""},r.scrollMemo={signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}})}function z(n={}){if(typeof document>"u")return{disable:()=>{}};if(r.enabled&&r.dispose)return{disable:r.dispose};let o=Math.max(100,n.refreshMs??350);s=Math.max(1,n.historyLimit??50);let f=n.position??"bottom-right";r.enabled=!0,r.activeTab="signals";for(let e of Array.from(i)){let t=e.deref();if(!t){i.delete(e);continue}let n=a.get(t);n&&m(n)}e._setSignalDebugHooks({onCreate(e,t){h(e,t)},onWrite(e,t){let n=h(e,t),o=Date.now();n.lastUpdated=o,n.history.push({at:o,value:t}),m(n)}}),t._setComponentDebugHooks({onMountStart(e){let t=c.get(e);t??(t=d++,c.set(e,t));let n=u.length>0?u[u.length-1]:null;l.set(t,{id:t,parentId:n,debugName:_(e),mountedAt:Date.now(),hasDefaultSlot:null!=e.children,slotNames:v(e),props:y(e),ref:p(e)}),u.push(t)},onMountEnd(e){let t=c.get(e);if(null==t)return;let n=l.get(t);if(n&&(n.debugName=_(e),n.hasDefaultSlot=null!=e.children,n.slotNames=v(e),n.props=y(e)),u[u.length-1]===t)return void u.pop();let o=u.lastIndexOf(t);o>=0&&u.splice(o,1)},onUnmount(e){let t=c.get(e);if(null==t)return;S(t);let n=u.lastIndexOf(t);n>=0&&u.splice(n,1)}}),L({position:f}),r.refreshId=setInterval(()=>{"block"===r.panel?.style.display&&F()},o),n.initiallyOpen&&r.panel&&(r.panel.style.display="block",I(),F(!0));let b=()=>R();return r.dispose=b,{disable:b}}exports._listSignals=g,exports.disableDevTools=R,exports.enableDevTools=z;
@@ -1 +1 @@
1
- import{_setSignalDebugHooks as e}from"./signals.js";import{_setComponentDebugHooks as t}from"./lifecycle.js";import{_debugGetRouterInternal as n}from"./router.js";var r={enabled:!1,activeTab:"signals",renderedTab:null,refreshId:null,root:null,panel:null,content:null,dispose:null,renderKeys:{signals:"",components:"",router:""},scrollMemo:{signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}}},i=new Set,a=new WeakMap,o=1,s=new WeakMap,c=new Map,l=[],u=1;function d(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function f(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function p(e,t){let n=a.get(e);if(n)return n;let r=Date.now(),l={id:o++,createdAt:r,lastUpdated:r,history:[{at:r,value:t}]};return a.set(e,l),i.add(d(e)),l}function m(){let e=[];for(let t of Array.from(i)){let n=t.deref();if(!n){i.delete(t);continue}let o=a.get(n);if(!o)continue;let r=n._subs?.size??0;e.push({id:o.id,value:n.peek(),subscriberCount:r,createdAt:o.createdAt,lastUpdated:o.lastUpdated,history:o.history.slice()})}return e.sort((e,t)=>t.lastUpdated-e.lastUpdated),e}function h(e){let t=e._debugName;if(t&&t.trim())return t;let n=e.constructor;return n?.name&&n.name.trim()?n.name:"AnonymousComponent"}function g(e){let t=e._slots;return t instanceof Map?Array.from(t.keys()).map(e=>String(e)):[]}function _(e){let t={};for(let n of Object.keys(e)){if("__isNixComponent"===n||"children"===n||"_debugName"===n||n.startsWith("_"))continue;let o=e[n];"function"!=typeof o&&(t[n]=o)}return t}function v(e){if(!e)return[];if("*"===e)return["*"];let t=e.split("/").filter(Boolean),n=[],o="";for(let e of t)o+="/"+e,n.push(o);return n.length>0?n:["/"]}function y(){let e=[];for(let[t,n]of c){let o=n.ref.deref();o?(n.debugName=h(o),n.hasDefaultSlot=null!=o.children,n.slotNames=g(o),n.props=_(o),e.push({id:n.id,parentId:n.parentId,debugName:n.debugName,mountedAt:n.mountedAt,hasDefaultSlot:n.hasDefaultSlot,slotNames:[...n.slotNames],props:{...n.props}})):c.delete(t)}return e.sort((e,t)=>e.id-t.id),e}function b(e){let t=[e];for(;t.length>0;){let e=t.pop();for(let[n,o]of c)o.parentId===e&&t.push(n);c.delete(e)}}function x(){i.clear(),a=new WeakMap,o=1,s=new WeakMap,c.clear(),l.length=0,u=1}function S(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||null==e)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function C(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}function w(e,t=90){let n=S(e);return n.length<=t?n:n.slice(0,t-1)+"…"}function T(e){if(!e)return"-";let t=Date.now()-e;return t<1e3?`${t}ms ago`:t<6e4?`${Math.floor(t/1e3)}s ago`:`${Math.floor(t/6e4)}m ago`}function E(e){let t=m(),n=`${t.length}:${t.map(e=>`${e.id}-${e.lastUpdated}-${e.subscriberCount}`).join("|")}`;if("signals"===r.renderedTab&&r.renderKeys.signals===n)return;r.renderKeys.signals=n,r.renderedTab="signals";let o=t.map(e=>{let t=S(e.value),n=w(e.value,120);return`<tr data-nix-devtools-signal-id="${e.id}">\n <td style="padding:6px 8px;white-space:nowrap;">${e.id}</td>\n <td style="padding:6px 8px;max-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;" title="${C(t)}">${C(n)}</td>\n <td>${e.subscriberCount}</td>\n <td>${T(e.lastUpdated)}</td>\n </tr>`}).join("");e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Signals</strong>\n <span style="opacity:.8">${t.length} active</span>\n </div>\n <div data-nix-devtools-scroll="signals" style="max-height:260px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n <table style="width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed;">\n <thead>\n <tr style="background:#1f1f24;">\n <th style="text-align:left;padding:6px 8px;width:42px;">ID</th>\n <th style="text-align:left;padding:6px 8px;">Value</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">Subs</th>\n <th style="text-align:left;padding:6px 8px;width:84px;">Updated</th>\n </tr>\n </thead>\n <tbody>${o}</tbody>\n </table>\n </div>\n <p style="margin:8px 0 0 0;font-size:11px;opacity:.75;">Click a row to log full history in console.</p>\n `;for(let n of e.querySelectorAll("tr[data-nix-devtools-signal-id]"))n.style.cursor="pointer",n.addEventListener("click",()=>{let e=Number(n.dataset.nixDevtoolsSignalId),o=t.find(t=>t.id===e);o&&(console.group(`[Nix DevTools] Signal #${o.id}`),console.log("Current value:",o.value),console.log("Subscribers:",o.subscriberCount),console.table(o.history.map(e=>({at:new Date(e.at).toISOString(),value:e.value}))),console.groupEnd())})}function D(e){let t=new Map,n=[];for(let n of e)t.set(n.id,{...n,children:[]});for(let e of t.values()){if(null==e.parentId){n.push(e);continue}let o=t.get(e.parentId);o?o.children.push(e):n.push(e)}return n}function O(e,t){let n=10+14*t,o=Object.keys(e.props).length>0?S(e.props):"{}",r=e.slotNames.length>0?e.slotNames.join(", "):"none";return`<div style="padding:6px 8px 6px ${n}px;border-bottom:1px solid #24242b;">\n <div><strong>${C(e.debugName)}</strong> <span style="opacity:.7">#${e.id}</span></div>\n <div style="font-size:11px;opacity:.8;">slots: ${r} | default-slot: ${e.hasDefaultSlot?"yes":"no"}</div>\n <div style="font-size:11px;opacity:.8;">props: ${C(w(o,180))}</div>\n </div>`+e.children.map(e=>O(e,t+1)).join("")}function k(e){let t=y(),o=n(),l=`${o?`${o.currentPath}|${o.matchedPath??""}`:"no-router"}:${t.length}:${t.map(e=>`${e.id}-${e.parentId}-${e.debugName}-${e.hasDefaultSlot}-${e.slotNames.join(",")}-${S(e.props)}`).join("|")}`;if("components"===r.renderedTab&&r.renderKeys.components===l)return;r.renderKeys.components=l,r.renderedTab="components";let a=D(t);e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Component Tree</strong>\n <span style="opacity:.8">${t.length} mounted</span>\n </div>\n <div style="font-size:11px;opacity:.82;margin-bottom:8px;display:flex;gap:8px;flex-wrap:wrap;">\n <span><b>current:</b> ${C(o?.currentPath??"-")}</span>\n <span><b>matched:</b> ${C(o?.matchedPath??"none")}</span>\n </div>\n <div data-nix-devtools-scroll="components" style="max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n ${a.length>0?a.map(e=>O(e,0)).join(""):"<div style='padding:10px;opacity:.75'>No mounted components tracked. Enable devtools before your first mount() to capture initial tree.</div>"}\n </div>\n `}function A(e){let t=n(),o=t?`${t.mode}|${t.base}|${t.currentPath}|${JSON.stringify(t.params)}|${JSON.stringify(t.query)}|${t.matchedPath}|${t.activeGuards.names.join(",")}`:"none";if("router"===r.renderedTab&&r.renderKeys.router===o)return;if(r.renderKeys.router=o,r.renderedTab="router",!t)return void(e.innerHTML='\n <strong>Router State</strong>\n <div style="margin-top:8px;opacity:.75">No active Nix router instance. Ensure your app uses createRouter()/RouterView from @deijose/nix-js/router.</div>\n ');let l=v(t.matchedPath);e.innerHTML=`\n <strong>Router State</strong>\n <div data-nix-devtools-scroll="router" style="margin-top:8px;font-size:12px;line-height:1.55;max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;padding:8px;">\n <div><b>mode</b>: ${t.mode}</div>\n <div><b>base</b>: ${t.base}</div>\n <div><b>current</b>: ${C(t.currentPath)}</div>\n <div><b>params</b>: ${C(S(t.params))}</div>\n <div><b>query</b>: ${C(S(t.query))}</div>\n <div><b>matched</b>: ${C(t.matchedPath??"none")}</div>\n <div><b>matched chain</b>: ${l.length>0?C(l.join(" -> ")):"none"}</div>\n <div><b>guards</b>: ${t.activeGuards.names.length>0?C(t.activeGuards.names.join(", ")):"none"}</div>\n </div>\n `}function j(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);t&&(r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft})}function M(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);if(!t)return;let n=r.scrollMemo[e];t.scrollTop=n.top,t.scrollLeft=n.left,"1"!==t.dataset.nixDevtoolsScrollBound&&(t.addEventListener("scroll",()=>{r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft}},{passive:!0}),t.dataset.nixDevtoolsScrollBound="1")}function N(e=!1){if(!r.content)return;let t=r.activeTab;return e||j(t),"signals"===r.activeTab?(E(r.content),void M("signals")):"components"===r.activeTab?(k(r.content),void M("components")):(A(r.content),void M("router"))}function P(){if(r.panel)for(let e of r.panel.querySelectorAll("button[data-nix-devtools-tab]")){let t=e.dataset.nixDevtoolsTab===r.activeTab;e.style.background=t?"#2d4c7a":"#1f1f24"}}function F(e){let t=document.createElement("div");t.setAttribute("data-nix-devtools-root",""),t.style.position="fixed",t.style.zIndex="2147483647",t.style.bottom="16px",t.style.right="bottom-right"===e.position?"16px":"auto",t.style.left="bottom-left"===e.position?"16px":"auto",t.style.fontFamily="ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif";let n=document.createElement("button");n.type="button",n.textContent="Nix DevTools",n.setAttribute("data-nix-devtools-button",""),n.style.background="#111827",n.style.color="#f9fafb",n.style.border="1px solid #374151",n.style.borderRadius="999px",n.style.padding="8px 12px",n.style.cursor="pointer",n.style.boxShadow="0 6px 18px rgba(0,0,0,.3)";let o=document.createElement("div");o.setAttribute("data-nix-devtools-panel",""),o.style.marginTop="8px",o.style.width="460px",o.style.maxWidth="min(92vw, 460px)",o.style.background="#15151b",o.style.color="#e5e7eb",o.style.border="1px solid #2f2f35",o.style.borderRadius="12px",o.style.padding="10px",o.style.display="none",o.style.boxShadow="0 14px 28px rgba(0,0,0,.35)";let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginBottom="10px";let a=document.createElement("div");a.setAttribute("data-nix-devtools-content","");let s=(e,t)=>{let n=document.createElement("button");return n.type="button",n.textContent=t,n.setAttribute("data-nix-devtools-tab",e),n.style.border="1px solid #353543",n.style.borderRadius="8px",n.style.padding="6px 9px",n.style.background="#1f1f24",n.style.color="#d1d5db",n.style.cursor="pointer",n.addEventListener("click",()=>{r.activeTab=e,P(),N(!0)}),n};l.appendChild(s("signals","Signals")),l.appendChild(s("components","Components")),l.appendChild(s("router","Router")),n.addEventListener("click",()=>{o.style.display="none"===o.style.display?"block":"none","block"===o.style.display&&(P(),N(!0))}),o.appendChild(l),o.appendChild(a),t.appendChild(n),t.appendChild(o),document.body.appendChild(t),r.root=t,r.panel=o,r.content=a}function I(){r.enabled&&(r.enabled=!1,null!=r.refreshId&&(clearInterval(r.refreshId),r.refreshId=null),e(null),t(null),x(),r.root?.parentNode&&r.root.parentNode.removeChild(r.root),r.root=null,r.panel=null,r.content=null,r.dispose=null,r.renderedTab=null,r.renderKeys={signals:"",components:"",router:""},r.scrollMemo={signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}})}function L(n={}){if(typeof document>"u")return{disable:()=>{}};if(r.enabled&&r.dispose)return{disable:r.dispose};let o=Math.max(100,n.refreshMs??350),a=Math.max(1,n.historyLimit??50),i=n.position??"bottom-right";r.enabled=!0,r.activeTab="signals",e({onCreate(e,t){p(e,t)},onWrite(e,t){let n=p(e,t),o=Date.now();n.lastUpdated=o,n.history.push({at:o,value:t}),n.history.length>a&&n.history.splice(0,n.history.length-a)}}),t({onMountStart(e){let t=s.get(e);t??(t=u++,s.set(e,t));let n=l.length>0?l[l.length-1]:null;c.set(t,{id:t,parentId:n,debugName:h(e),mountedAt:Date.now(),hasDefaultSlot:null!=e.children,slotNames:g(e),props:_(e),ref:f(e)}),l.push(t)},onMountEnd(e){let t=s.get(e);if(null==t)return;let n=c.get(t);if(n&&(n.debugName=h(e),n.hasDefaultSlot=null!=e.children,n.slotNames=g(e),n.props=_(e)),l[l.length-1]===t)return void l.pop();let o=l.lastIndexOf(t);o>=0&&l.splice(o,1)},onUnmount(e){let t=s.get(e);if(null==t)return;b(t);let n=l.lastIndexOf(t);n>=0&&l.splice(n,1)}}),F({position:i}),r.refreshId=setInterval(()=>{"block"===r.panel?.style.display&&N()},o),n.initiallyOpen&&r.panel&&(r.panel.style.display="block",P(),N(!0));let d=()=>I();return r.dispose=d,{disable:d}}export{I as disableDevTools,L as enableDevTools};
1
+ import{_setSignalDebugHooks as e}from"./signals.js";import{_setComponentDebugHooks as t}from"./lifecycle.js";import{_debugGetRouterInternal as n}from"./router.js";var r={enabled:!1,activeTab:"signals",renderedTab:null,refreshId:null,root:null,panel:null,content:null,dispose:null,renderKeys:{signals:"",components:"",router:""},scrollMemo:{signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}}},i=new Set,a=new WeakMap,o=1,s=50,c=new WeakMap,l=new Map,u=[],d=1;function f(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function p(e){return typeof WeakRef<"u"?new WeakRef(e):{deref:()=>e}}function m(e){e.history.length>s&&e.history.splice(0,e.history.length-s)}function h(e,t){let n=a.get(e);if(n)return m(n),n;let r=Date.now(),l={id:o++,createdAt:r,lastUpdated:r,history:[{at:r,value:t}]};return a.set(e,l),i.add(f(e)),l}function g(){let e=[];for(let t of Array.from(i)){let n=t.deref();if(!n){i.delete(t);continue}let o=a.get(n);if(!o)continue;let r=n._subs?.size??0;e.push({id:o.id,value:n.peek(),subscriberCount:r,createdAt:o.createdAt,lastUpdated:o.lastUpdated,history:o.history.slice()})}return e.sort((e,t)=>t.lastUpdated-e.lastUpdated),e}function _(e){let t=e._debugName;if(t&&t.trim())return t;let n=e.constructor;return n?.name&&n.name.trim()?n.name:"AnonymousComponent"}function v(e){let t=e._slots;return t instanceof Map?Array.from(t.keys()).map(e=>String(e)):[]}function y(e){let t={};for(let n of Object.keys(e)){if("__isNixComponent"===n||"children"===n||"_debugName"===n||n.startsWith("_"))continue;let o=e[n];"function"!=typeof o&&(t[n]=o)}return t}function b(e){if(!e)return[];if("*"===e)return["*"];let t=e.split("/").filter(Boolean),n=[],o="";for(let e of t)o+="/"+e,n.push(o);return n.length>0?n:["/"]}function x(){let e=[];for(let[t,n]of l){let o=n.ref.deref();o?(n.debugName=_(o),n.hasDefaultSlot=null!=o.children,n.slotNames=v(o),n.props=y(o),e.push({id:n.id,parentId:n.parentId,debugName:n.debugName,mountedAt:n.mountedAt,hasDefaultSlot:n.hasDefaultSlot,slotNames:[...n.slotNames],props:{...n.props}})):l.delete(t)}return e.sort((e,t)=>e.id-t.id),e}function S(e){let t=[e];for(;t.length>0;){let e=t.pop();for(let[n,o]of l)o.parentId===e&&t.push(n);l.delete(e)}}function C(){i.clear(),a=new WeakMap,o=1,c=new WeakMap,l.clear(),u.length=0,d=1}function w(e){if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||null==e)return String(e);try{return JSON.stringify(e)}catch{return Object.prototype.toString.call(e)}}function T(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\"/g,"&quot;").replace(/'/g,"&#39;")}function E(e,t=90){let n=w(e);return n.length<=t?n:n.slice(0,t-1)+"…"}function D(e){if(!e)return"-";let t=Date.now()-e;return t<1e3?`${t}ms ago`:t<6e4?`${Math.floor(t/1e3)}s ago`:`${Math.floor(t/6e4)}m ago`}function O(e){let t=g(),n=`${t.length}:${t.map(e=>`${e.id}-${e.lastUpdated}-${e.subscriberCount}`).join("|")}`;if("signals"===r.renderedTab&&r.renderKeys.signals===n)return;r.renderKeys.signals=n,r.renderedTab="signals";let o=t.map(e=>{let t=w(e.value),n=E(e.value,120);return`<tr data-nix-devtools-signal-id="${e.id}">\n <td style="padding:6px 8px;white-space:nowrap;">${e.id}</td>\n <td style="padding:6px 8px;max-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-family:ui-monospace, SFMono-Regular, Menlo, monospace;" title="${T(t)}">${T(n)}</td>\n <td>${e.subscriberCount}</td>\n <td data-nix-devtools-history-count="${e.history.length}">${e.history.length}</td>\n <td>${D(e.lastUpdated)}</td>\n </tr>`}).join("");e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Signals</strong>\n <span style="opacity:.8">${t.length} active</span>\n </div>\n <div data-nix-devtools-scroll="signals" style="max-height:260px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n <table style="width:100%;border-collapse:collapse;font-size:12px;table-layout:fixed;">\n <thead>\n <tr style="background:#1f1f24;">\n <th style="text-align:left;padding:6px 8px;width:42px;">ID</th>\n <th style="text-align:left;padding:6px 8px;">Value</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">Subs</th>\n <th style="text-align:left;padding:6px 8px;width:50px;">History</th>\n <th style="text-align:left;padding:6px 8px;width:84px;">Updated</th>\n </tr>\n </thead>\n <tbody>${o}</tbody>\n </table>\n </div>\n <p style="margin:8px 0 0 0;font-size:11px;opacity:.75;">Click a row to log full history in console.</p>\n `;for(let n of e.querySelectorAll("tr[data-nix-devtools-signal-id]"))n.style.cursor="pointer",n.addEventListener("click",()=>{let e=Number(n.dataset.nixDevtoolsSignalId),o=t.find(t=>t.id===e);o&&(console.group(`[Nix DevTools] Signal #${o.id}`),console.log("Current value:",o.value),console.log("Subscribers:",o.subscriberCount),console.table(o.history.map(e=>({at:new Date(e.at).toISOString(),value:e.value}))),console.groupEnd())})}function k(e){let t=new Map,n=[];for(let n of e)t.set(n.id,{...n,children:[]});for(let e of t.values()){if(null==e.parentId){n.push(e);continue}let o=t.get(e.parentId);o?o.children.push(e):n.push(e)}return n}function A(e,t){let n=10+14*t,o=Object.keys(e.props).length>0?w(e.props):"{}",r=e.slotNames.length>0?e.slotNames.join(", "):"none";return`<div style="padding:6px 8px 6px ${n}px;border-bottom:1px solid #24242b;">\n <div><strong>${T(e.debugName)}</strong> <span style="opacity:.7">#${e.id}</span></div>\n <div style="font-size:11px;opacity:.8;">slots: ${r} | default-slot: ${e.hasDefaultSlot?"yes":"no"}</div>\n <div style="font-size:11px;opacity:.8;">props: ${T(E(o,180))}</div>\n </div>`+e.children.map(e=>A(e,t+1)).join("")}function j(e){let t=x(),o=n(),l=`${o?`${o.currentPath}|${o.matchedPath??""}`:"no-router"}:${t.length}:${t.map(e=>`${e.id}-${e.parentId}-${e.debugName}-${e.hasDefaultSlot}-${e.slotNames.join(",")}-${w(e.props)}`).join("|")}`;if("components"===r.renderedTab&&r.renderKeys.components===l)return;r.renderKeys.components=l,r.renderedTab="components";let a=k(t);e.innerHTML=`\n <div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px;">\n <strong>Component Tree</strong>\n <span style="opacity:.8">${t.length} mounted</span>\n </div>\n <div style="font-size:11px;opacity:.82;margin-bottom:8px;display:flex;gap:8px;flex-wrap:wrap;">\n <span><b>current:</b> ${T(o?.currentPath??"-")}</span>\n <span><b>matched:</b> ${T(o?.matchedPath??"none")}</span>\n </div>\n <div data-nix-devtools-scroll="components" style="max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;">\n ${a.length>0?a.map(e=>A(e,0)).join(""):"<div style='padding:10px;opacity:.75'>No mounted components tracked. Enable devtools before your first mount() to capture initial tree.</div>"}\n </div>\n `}function M(e){let t=n(),o=t?`${t.mode}|${t.base}|${t.currentPath}|${JSON.stringify(t.params)}|${JSON.stringify(t.query)}|${t.matchedPath}|${t.activeGuards.names.join(",")}`:"none";if("router"===r.renderedTab&&r.renderKeys.router===o)return;if(r.renderKeys.router=o,r.renderedTab="router",!t)return void(e.innerHTML='\n <strong>Router State</strong>\n <div style="margin-top:8px;opacity:.75">No active Nix router instance. Ensure your app uses createRouter()/RouterView from @deijose/nix-js/router.</div>\n ');let l=b(t.matchedPath);e.innerHTML=`\n <strong>Router State</strong>\n <div data-nix-devtools-scroll="router" style="margin-top:8px;font-size:12px;line-height:1.55;max-height:280px;overflow:auto;overscroll-behavior:contain;border:1px solid #2f2f35;border-radius:8px;padding:8px;">\n <div><b>mode</b>: ${t.mode}</div>\n <div><b>base</b>: ${t.base}</div>\n <div><b>current</b>: ${T(t.currentPath)}</div>\n <div><b>params</b>: ${T(w(t.params))}</div>\n <div><b>query</b>: ${T(w(t.query))}</div>\n <div><b>matched</b>: ${T(t.matchedPath??"none")}</div>\n <div><b>matched chain</b>: ${l.length>0?T(l.join(" -> ")):"none"}</div>\n <div><b>guards</b>: ${t.activeGuards.names.length>0?T(t.activeGuards.names.join(", ")):"none"}</div>\n </div>\n `}function N(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);t&&(r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft})}function P(e){if(!r.content)return;let t=r.content.querySelector(`[data-nix-devtools-scroll='${e}']`);if(!t)return;let n=r.scrollMemo[e];t.scrollTop=n.top,t.scrollLeft=n.left,"1"!==t.dataset.nixDevtoolsScrollBound&&(t.addEventListener("scroll",()=>{r.scrollMemo[e]={top:t.scrollTop,left:t.scrollLeft}},{passive:!0}),t.dataset.nixDevtoolsScrollBound="1")}function F(e=!1){if(!r.content)return;let t=r.activeTab;return e||N(t),"signals"===r.activeTab?(O(r.content),void P("signals")):"components"===r.activeTab?(j(r.content),void P("components")):(M(r.content),void P("router"))}function I(){if(r.panel)for(let e of r.panel.querySelectorAll("button[data-nix-devtools-tab]")){let t=e.dataset.nixDevtoolsTab===r.activeTab;e.style.background=t?"#2d4c7a":"#1f1f24"}}function L(e){let t=document.createElement("div");t.setAttribute("data-nix-devtools-root",""),t.style.position="fixed",t.style.zIndex="2147483647",t.style.bottom="16px",t.style.right="bottom-right"===e.position?"16px":"auto",t.style.left="bottom-left"===e.position?"16px":"auto",t.style.fontFamily="ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif";let n=document.createElement("button");n.type="button",n.textContent="Nix DevTools",n.setAttribute("data-nix-devtools-button",""),n.style.background="#111827",n.style.color="#f9fafb",n.style.border="1px solid #374151",n.style.borderRadius="999px",n.style.padding="8px 12px",n.style.cursor="pointer",n.style.boxShadow="0 6px 18px rgba(0,0,0,.3)";let o=document.createElement("div");o.setAttribute("data-nix-devtools-panel",""),o.style.marginTop="8px",o.style.width="460px",o.style.maxWidth="min(92vw, 460px)",o.style.background="#15151b",o.style.color="#e5e7eb",o.style.border="1px solid #2f2f35",o.style.borderRadius="12px",o.style.padding="10px",o.style.display="none",o.style.boxShadow="0 14px 28px rgba(0,0,0,.35)";let l=document.createElement("div");l.style.display="flex",l.style.gap="6px",l.style.marginBottom="10px";let a=document.createElement("div");a.setAttribute("data-nix-devtools-content","");let s=(e,t)=>{let n=document.createElement("button");return n.type="button",n.textContent=t,n.setAttribute("data-nix-devtools-tab",e),n.style.border="1px solid #353543",n.style.borderRadius="8px",n.style.padding="6px 9px",n.style.background="#1f1f24",n.style.color="#d1d5db",n.style.cursor="pointer",n.addEventListener("click",()=>{r.activeTab=e,I(),F(!0)}),n};l.appendChild(s("signals","Signals")),l.appendChild(s("components","Components")),l.appendChild(s("router","Router")),n.addEventListener("click",()=>{o.style.display="none"===o.style.display?"block":"none","block"===o.style.display&&(I(),F(!0))}),o.appendChild(l),o.appendChild(a),t.appendChild(n),t.appendChild(o),document.body.appendChild(t),r.root=t,r.panel=o,r.content=a}function R(){r.enabled&&(r.enabled=!1,null!=r.refreshId&&(clearInterval(r.refreshId),r.refreshId=null),e(null),t(null),C(),r.root?.parentNode&&r.root.parentNode.removeChild(r.root),r.root=null,r.panel=null,r.content=null,r.dispose=null,r.renderedTab=null,r.renderKeys={signals:"",components:"",router:""},r.scrollMemo={signals:{top:0,left:0},components:{top:0,left:0},router:{top:0,left:0}})}function z(n={}){if(typeof document>"u")return{disable:()=>{}};if(r.enabled&&r.dispose)return{disable:r.dispose};let o=Math.max(100,n.refreshMs??350);s=Math.max(1,n.historyLimit??50);let f=n.position??"bottom-right";r.enabled=!0,r.activeTab="signals";for(let e of Array.from(i)){let t=e.deref();if(!t){i.delete(e);continue}let n=a.get(t);n&&m(n)}e({onCreate(e,t){h(e,t)},onWrite(e,t){let n=h(e,t),o=Date.now();n.lastUpdated=o,n.history.push({at:o,value:t}),m(n)}}),t({onMountStart(e){let t=c.get(e);t??(t=d++,c.set(e,t));let n=u.length>0?u[u.length-1]:null;l.set(t,{id:t,parentId:n,debugName:_(e),mountedAt:Date.now(),hasDefaultSlot:null!=e.children,slotNames:v(e),props:y(e),ref:p(e)}),u.push(t)},onMountEnd(e){let t=c.get(e);if(null==t)return;let n=l.get(t);if(n&&(n.debugName=_(e),n.hasDefaultSlot=null!=e.children,n.slotNames=v(e),n.props=y(e)),u[u.length-1]===t)return void u.pop();let o=u.lastIndexOf(t);o>=0&&u.splice(o,1)},onUnmount(e){let t=c.get(e);if(null==t)return;S(t);let n=u.lastIndexOf(t);n>=0&&u.splice(n,1)}}),L({position:f}),r.refreshId=setInterval(()=>{"block"===r.panel?.style.display&&F()},o),n.initiallyOpen&&r.panel&&(r.panel.style.display="block",I(),F(!0));let b=()=>R();return r.dispose=b,{disable:b}}export{g as _listSignals,R as disableDevTools,z as enableDevTools};
@@ -4,7 +4,21 @@ export interface DevToolsOptions {
4
4
  initiallyOpen?: boolean;
5
5
  position?: "bottom-right" | "bottom-left";
6
6
  }
7
+ interface _SignalSnapshot {
8
+ id: number;
9
+ value: unknown;
10
+ subscriberCount: number;
11
+ createdAt: number;
12
+ lastUpdated: number;
13
+ history: Array<{
14
+ at: number;
15
+ value: unknown;
16
+ }>;
17
+ }
18
+ /** @internal Exported for testing. */
19
+ export declare function _listSignals(): _SignalSnapshot[];
7
20
  export declare function disableDevTools(): void;
8
21
  export declare function enableDevTools(options?: DevToolsOptions): {
9
22
  disable: () => void;
10
23
  };
24
+ export {};
@@ -130,4 +130,8 @@ export interface _RouterDebugInternal {
130
130
  names: string[];
131
131
  };
132
132
  }
133
+ /** @internal Register a router that was injected via mount({ router }). */
134
+ export declare function _debugRegisterRouter(router: Router): void;
135
+ /** @internal Unregister a router when its mount point is unmounted. */
136
+ export declare function _debugUnregisterRouter(router: Router): void;
133
137
  export declare function _debugGetRouterInternal(): _RouterDebugInternal | null;
@@ -1,11 +1,11 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./lifecycle.cjs"),r=require("./context.cjs");var i=r.createInjectionKey("nix:router"),a=null,o=null,s="__nix_scroll",c="__nix_pos";function l(){if(!a)throw Error("[Nix] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).");return a}function u(){return null!==a}function d(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||"object"!=typeof e)return null;let t=e[s];if(!t||"object"!=typeof t)return null;let r=t.left,n=t.top;return"number"!=typeof r||"number"!=typeof n?null:{left:r,top:n}}function f(e){if(!e||"object"!=typeof e)return null;let t=e[c];return"number"==typeof t?t:null}function p(e,t,r){let n=e&&"object"==typeof e?{...e}:{};return n[s]={left:t.left,top:t.top},n[c]=r,n}function m(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function h(e){let t=new URLSearchParams;for(let[r,n]of Object.entries(e))null!=n&&!1!==n&&t.set(r,String(n));let r=t.toString();return r?"?"+r:""}function g(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 _(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function v(e,t="",r=[]){let n=[];for(let o of e){let e=_(t,o.path),a=[...r,o.component],i=g(e);n.push({fullPath:e,segments:i,chain:a,name:o.name,meta:o.meta,beforeEnter:o.beforeEnter,record:o}),o.children?.length&&n.push(...v(o.children,e,a))}return n}function y(e,t){let r=e.split("/").filter(Boolean),n=t.segments;if(1===n.length&&"wildcard"===n[0].kind)return{};let o=n.length>0&&"wildcard"===n[n.length-1].kind,a=o?n.slice(0,-1):n;if(o){if(r.length<a.length)return null}else if(r.length!==a.length)return null;let i={};for(let e=0;e<a.length;e++){let t=a[e];if("literal"===t.kind){if(r[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(r[e]??"")}catch{i[t.name]=r[e]??""}}return i}function b(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function x(e,t){let r,n={},o=-1;for(let a of t){let t=y(e,a);if(null===t)continue;let i=b(a);i>o&&(r=a,n=t,o=i)}return r?{route:r,params:n}:void 0}function S(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function te(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return S(new URL(t,window.location.origin).pathname)}catch{return S(t)}}function C(e){return!1===e?{allow:!1}:!0===e||null==e?{allow:!0}:"string"==typeof e?{allow:!1,redirect:e}:"object"==typeof e&&"redirect"in e&&"string"==typeof e.redirect?{allow:!1,redirect:e.redirect}:{allow:!0}}function w(t,r){let n=null==r?.base?te():S(r.base),i=r?.mode??"history",l="hash"===i,u=r?.scrollBehavior,s=new Map,c=!1;function g(e){return e?e.startsWith("/")?e:"/"+e:"/"}function w(e){let t=g(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":g(e)}return t}function y(){return l?function(){let e=window.location.hash||"";if(e.startsWith("#")&&(e=e.slice(1)),!e)return{pathname:"/",search:""};e.startsWith("/")||(e="/"+e);let t=e.indexOf("?"),r=-1===t?e:e.slice(0,t),n=-1===t?"":e.slice(t);return{pathname:w(r),search:n}}():{pathname:w(window.location.pathname||"/"),search:window.location.search||""}}function b(e,t){let r=function(e){let t=g(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+h(t);return l?"#"+r:r}function _(e,t){return g(e)+h(t)}let k=y(),E=k.pathname,R=m(k.search),j=v(t),q=new Map;for(let e of j)e.name&&(q.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),q.set(e.name,e));let O=x(E,j),W=e.signal(E),$=e.signal(O?.params??{}),N=e.signal(R),L=f(history.state)??0,P=e.signal({action:"initial",direction:"none"}),M=e.signal(L>0);function T(e){window.scrollTo(e.left,e.top)}function B(e,t,r){if(u){let n=u(e,t,r);if(!n)return;return void T(n)}T(r??{left:0,top:0})}l?s.set(_(E,R),d()):history.replaceState(p(history.state,d(),L),"");let I=[],U=[],A=0;function D(e,t,r,n,o){let a=[...I];r&&a.push(r);let i=++A;if(0===a.length)return void n();let l=0;!function r(u){if(i!==A)return;let s=C(u);if(!s.allow)return s.redirect&&s.redirect!==e?void z(s.redirect):s.redirect===e?void n():void o?.();if(l>=a.length)return void n();let c=a[l++](e,t);c instanceof Promise?c.then(r):r(c)}(void 0)}let G=!1;function Q(e,t){let r=e.indexOf("?"),n=g((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:m(e.slice(r)),a=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(a))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:n,stringQuery:i}}function K(e,t){return"string"==typeof e?Q(e,t?.query):Q(function(e){let t=q.get(e.name);if(!t)throw Error(`[Nix Router] No route with name "${e.name}"`);return"/"+t.segments.map(t=>{if("literal"===t.kind)return t.value;if("wildcard"===t.kind)return"";let r=e.params?.[t.name];if(null==r)throw Error(`[Nix Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(r))}).filter(Boolean).join("/")}(e),{...e.query??{},...t?.query??{}})}o&&=(o(),null);let X,Y=(e,t,r,n,o)=>{let a=W.value,i={...N.value},l=x(e,j),u="none";null!=n&&(n<L?u="back":n>L&&(u="forward")),D(e,a,l?.route.beforeEnter,()=>{null!=n&&(L=n);let o=X;X=void 0,P.value={action:"pop",direction:u,animation:o},$.value=l?.params??{},N.value=t,W.value=e,M.value=L>0,B(e,a,r);for(let t of U)try{t(e,a)}catch{}},()=>o(a,i))};if(l){let e=()=>{if(c)return void(c=!1);let e=y(),t=m(e.search),r=s.get(_(e.pathname,t))??null;Y(e.pathname,t,r,null,(e,t)=>{c=!0,window.location.hash=b(e,t).slice(1),queueMicrotask(()=>{c=!1})})};window.addEventListener("hashchange",e),o=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=y(),r=m(t.search),n=ee(e.state??history.state),o=f(e.state??history.state);Y(t.pathname,r,n,o,(e,t)=>{history.pushState(p({},d(),L),"",b(e,t))})};window.addEventListener("popstate",e),o=()=>window.removeEventListener("popstate",e)}function V(e,t,r,n,o,a,i){i||(function(e,t){let r=d();l?s.set(_(e,t),r):history.replaceState(p(history.state,r,L),"")}(r,n),L+=1),P.value=a,$.value=o?.params??{},N.value=t,W.value=e,M.value=L>0;let u=b(e,t);if(l)s.set(_(e,t),{left:0,top:0}),i?history.replaceState(history.state,"",u):(c=!0,window.location.hash=u.slice(1),queueMicrotask(()=>{c=!1}));else{let e=p({},{left:0,top:0},L);i?history.replaceState(e,"",u):history.pushState(e,"",u)}B(e,r,null);for(let t of U)try{t(e,r)}catch{}}function z(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,a={...N.value},i=x(r,j),l={action:"push",direction:t?.direction??"forward",animation:t?.animation};D(r,o,i?.route.beforeEnter,()=>V(r,n,o,a,i,l,!1))}let F={current:W,params:$,query:N,intent:P,canGoBack:M,base:n||"/",navigate:z,replace:function(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,a={...N.value},i=x(r,j),l={action:"replace",direction:t?.direction??"root",animation:t?.animation};D(r,o,i?.route.beforeEnter,()=>V(r,n,o,a,i,l,!0))},back:function(e){void 0!==e&&(X=e),history.back()},forward:function(e){void 0!==e&&(X=e),history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=W.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=x(e,j);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return I.push(e),()=>{let t=I.indexOf(e);-1!==t&&I.splice(t,1)}},afterEach:function(e){return U.push(e),()=>{let t=U.indexOf(e);-1!==t&&U.splice(t,1)}},routes:t,_flat:j,_guards:I,_base:n,_mode:i};return a&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),a=F,queueMicrotask(()=>{G||D(E,"",x(E,j)?.route.beforeEnter,()=>{},()=>{let e=b("/",{});l?(s.set(_("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(p({},{left:0,top:0},L),"",e);let t=x("/",j);P.value={action:"replace",direction:"root"},W.value="/",$.value=t?.params??{},N.value={},M.value=L>0,B("/",E,null)})}),F}function T(){return r.inject(i)||l()}function E(){o&&=(o(),null),a=null}var D=class extends n.NixComponent{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,r=this._router;return t.l`<div class="router-view">${()=>{let n=r??T(),o=x(n.current.value,n._flat);if(!o)return t.l`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./lifecycle.cjs"),r=require("./context.cjs");var i=r.createInjectionKey("nix:router"),a=null,o=null,s=[],c="__nix_scroll",l="__nix_pos";function u(){if(!a)throw Error("[Nix] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).");return a}function d(){return null!==a}function f(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||"object"!=typeof e)return null;let t=e[c];if(!t||"object"!=typeof t)return null;let r=t.left,n=t.top;return"number"!=typeof r||"number"!=typeof n?null:{left:r,top:n}}function p(e){if(!e||"object"!=typeof e)return null;let t=e[l];return"number"==typeof t?t:null}function m(e,t,r){let n=e&&"object"==typeof e?{...e}:{};return n[c]={left:t.left,top:t.top},n[l]=r,n}function h(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function g(e){let t=new URLSearchParams;for(let[r,n]of Object.entries(e))null!=n&&!1!==n&&t.set(r,String(n));let r=t.toString();return r?"?"+r:""}function _(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 v(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function y(e,t="",r=[]){let n=[];for(let o of e){let e=v(t,o.path),i=[...r,o.component],a=_(e);n.push({fullPath:e,segments:a,chain:i,name:o.name,meta:o.meta,beforeEnter:o.beforeEnter,record:o}),o.children?.length&&n.push(...y(o.children,e,i))}return n}function b(e,t){let r=e.split("/").filter(Boolean),n=t.segments;if(1===n.length&&"wildcard"===n[0].kind)return{};let o=n.length>0&&"wildcard"===n[n.length-1].kind,i=o?n.slice(0,-1):n;if(o){if(r.length<i.length)return null}else if(r.length!==i.length)return null;let a={};for(let e=0;e<i.length;e++){let t=i[e];if("literal"===t.kind){if(r[e]!==t.value)return null}else if("param"===t.kind)try{a[t.name]=decodeURIComponent(r[e]??"")}catch{a[t.name]=r[e]??""}}return a}function x(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function S(e,t){let r,n={},o=-1;for(let i of t){let t=b(e,i);if(null===t)continue;let a=x(i);a>o&&(r=i,n=t,o=a)}return r?{route:r,params:n}:void 0}function C(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function w(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return C(new URL(t,window.location.origin).pathname)}catch{return C(t)}}function te(e){return!1===e?{allow:!1}:!0===e||null==e?{allow:!0}:"string"==typeof e?{allow:!1,redirect:e}:"object"==typeof e&&"redirect"in e&&"string"==typeof e.redirect?{allow:!1,redirect:e.redirect}:{allow:!0}}function T(t,r){let n=null==r?.base?w():C(r.base),i=r?.mode??"history",l="hash"===i,u=r?.scrollBehavior,s=new Map,c=!1;function d(e){return e?e.startsWith("/")?e:"/"+e:"/"}function v(e){let t=d(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":d(e)}return t}function b(){return l?function(){let e=window.location.hash||"";if(e.startsWith("#")&&(e=e.slice(1)),!e)return{pathname:"/",search:""};e.startsWith("/")||(e="/"+e);let t=e.indexOf("?"),r=-1===t?e:e.slice(0,t),n=-1===t?"":e.slice(t);return{pathname:v(r),search:n}}():{pathname:v(window.location.pathname||"/"),search:window.location.search||""}}function x(e,t){let r=function(e){let t=d(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+g(t);return l?"#"+r:r}function _(e,t){return d(e)+g(t)}let k=b(),E=k.pathname,R=h(k.search),j=y(t),O=new Map;for(let e of j)e.name&&(O.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),O.set(e.name,e));let q=S(E,j),W=e.signal(E),$=e.signal(q?.params??{}),M=e.signal(R),N=p(history.state)??0,L=e.signal({action:"initial",direction:"none"}),P=e.signal(N>0);function A(e){window.scrollTo(e.left,e.top)}function U(e,t,r){if(u){let n=u(e,t,r);if(!n)return;return void A(n)}A(r??{left:0,top:0})}l?s.set(_(E,R),f()):history.replaceState(m(history.state,f(),N),"");let B=[],I=[],T=0;function D(e,t,r,n,o){let i=[...B];r&&i.push(r);let a=++T;if(0===i.length)return void n();let l=0;!function r(u){if(a!==T)return;let s=te(u);if(!s.allow)return s.redirect&&s.redirect!==e?void z(s.redirect):s.redirect===e?void n():void o?.();if(l>=i.length)return void n();let c=i[l++](e,t);c instanceof Promise?c.then(r):r(c)}(void 0)}let G=!1;function Q(e,t){let r=e.indexOf("?"),n=d((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:h(e.slice(r)),i=t?{...o,...t}:o,a={};for(let[e,t]of Object.entries(i))null!=t&&!1!==t&&(a[e]=String(t));return{pathname:n,stringQuery:a}}function K(e,t){return"string"==typeof e?Q(e,t?.query):Q(function(e){let t=O.get(e.name);if(!t)throw Error(`[Nix Router] No route with name "${e.name}"`);return"/"+t.segments.map(t=>{if("literal"===t.kind)return t.value;if("wildcard"===t.kind)return"";let r=e.params?.[t.name];if(null==r)throw Error(`[Nix Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(r))}).filter(Boolean).join("/")}(e),{...e.query??{},...t?.query??{}})}o&&=(o(),null);let X,Y=(e,t,r,n,o)=>{let i=W.value,a={...M.value},l=S(e,j),u="none";null!=n&&(n<N?u="back":n>N&&(u="forward")),D(e,i,l?.route.beforeEnter,()=>{null!=n&&(N=n);let o=X;X=void 0,L.value={action:"pop",direction:u,animation:o},$.value=l?.params??{},M.value=t,W.value=e,P.value=N>0,U(e,i,r);for(let t of I)try{t(e,i)}catch{}},()=>o(i,a))};if(l){let e=()=>{if(c)return void(c=!1);let e=b(),t=h(e.search),r=s.get(_(e.pathname,t))??null;Y(e.pathname,t,r,null,(e,t)=>{c=!0,window.location.hash=x(e,t).slice(1),queueMicrotask(()=>{c=!1})})};window.addEventListener("hashchange",e),o=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=b(),r=h(t.search),n=ee(e.state??history.state),o=p(e.state??history.state);Y(t.pathname,r,n,o,(e,t)=>{history.pushState(m({},f(),N),"",x(e,t))})};window.addEventListener("popstate",e),o=()=>window.removeEventListener("popstate",e)}function V(e,t,r,n,o,i,a){a||(function(e,t){let r=f();l?s.set(_(e,t),r):history.replaceState(m(history.state,r,N),"")}(r,n),N+=1),L.value=i,$.value=o?.params??{},M.value=t,W.value=e,P.value=N>0;let u=x(e,t);if(l)s.set(_(e,t),{left:0,top:0}),a?history.replaceState(history.state,"",u):(c=!0,window.location.hash=u.slice(1),queueMicrotask(()=>{c=!1}));else{let e=m({},{left:0,top:0},N);a?history.replaceState(e,"",u):history.pushState(e,"",u)}U(e,r,null);for(let t of I)try{t(e,r)}catch{}}function z(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,i={...M.value},a=S(r,j),l={action:"push",direction:t?.direction??"forward",animation:t?.animation};D(r,o,a?.route.beforeEnter,()=>V(r,n,o,i,a,l,!1))}let F={current:W,params:$,query:M,intent:L,canGoBack:P,base:n||"/",navigate:z,replace:function(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,i={...M.value},a=S(r,j),l={action:"replace",direction:t?.direction??"root",animation:t?.animation};D(r,o,a?.route.beforeEnter,()=>V(r,n,o,i,a,l,!0))},back:function(e){void 0!==e&&(X=e),history.back()},forward:function(e){void 0!==e&&(X=e),history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=W.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=S(e,j);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return B.push(e),()=>{let t=B.indexOf(e);-1!==t&&B.splice(t,1)}},afterEach:function(e){return I.push(e),()=>{let t=I.indexOf(e);-1!==t&&I.splice(t,1)}},routes:t,_flat:j,_guards:B,_base:n,_mode:i};return a&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),a=F,queueMicrotask(()=>{G||D(E,"",S(E,j)?.route.beforeEnter,()=>{},()=>{let e=x("/",{});l?(s.set(_("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(m({},{left:0,top:0},N),"",e);let t=S("/",j);L.value={action:"replace",direction:"root"},W.value="/",$.value=t?.params??{},M.value={},P.value=N>0,U("/",E,null)})}),F}function E(){return r.inject(i)||u()}function D(){o&&=(o(),null),a=null,s.length=0}var O=class extends n.NixComponent{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,r=this._router;return t.l`<div class="router-view">${()=>{let n=r??E(),o=S(n.current.value,n._flat);if(!o)return t.l`
2
2
  <div style="color:#f87171;padding:16px 0">
3
3
  404 — Route not found: <strong>${n.current.value}</strong>
4
4
  </div>
5
5
  `;if(e>=o.route.chain.length)return t.l`
6
6
  <span></span>
7
- `;let a=o.route.chain[e];return a?a():t.l`
7
+ `;let i=o.route.chain[e];return i?i():t.l`
8
8
  <span></span>
9
- `}}</div>`}},O=class extends n.NixComponent{_to;_label;_router;constructor(e,t,r){super(),this._to=e,this._label=t,this._router=r}render(){let e=this._to,r=this._label,n=this._router??T(),o=e.startsWith("/")?e:"/"+e,a=(n._base?n._base+o:o).replace(/\/+/g,"/");return t.l`
10
- <a href=${"hash"===n._mode?"#"+a:a} style=${()=>n.current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"} @click=${t=>{t.preventDefault(),n.navigate(e)}}>${r}</a>
11
- `}};function k(){if(!a)return null;let e=a.current.value,t=x(e,a._flat),r=t?.route.beforeEnter,n=a._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return r&&n.push(r.name||"beforeEnter"),{mode:a._mode,base:a._base||"/",currentPath:e,params:{...a.params.value},query:{...a.query.value},matchedPath:t?.route.fullPath??null,activeGuards:{globalCount:a._guards.length,hasRouteGuard:!!r,names:n}}}exports.Link=O,exports.RouterKey=i,exports.RouterView=D,exports._debugGetRouterInternal=k,exports._hasActiveRouter=u,exports._resetRouter=E,exports.createRouter=w,exports.nixRouter=T;
9
+ `}}</div>`}},k=class extends n.NixComponent{_to;_label;_router;constructor(e,t,r){super(),this._to=e,this._label=t,this._router=r}render(){let e=this._to,r=this._label,n=this._router??E(),o=e.startsWith("/")?e:"/"+e,i=(n._base?n._base+o:o).replace(/\/+/g,"/");return t.l`
10
+ <a href=${"hash"===n._mode?"#"+i:i} style=${()=>n.current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"} @click=${t=>{t.preventDefault(),n.navigate(e)}}>${r}</a>
11
+ `}};function A(e){let t=s.indexOf(e);t>=0&&s.splice(t,1),s.push(e)}function j(e){let t=s.indexOf(e);t>=0&&s.splice(t,1)}function M(){let e=s.length?s[s.length-1]:a;if(!e)return null;let t=e,r=t.current.value,n=S(r,t._flat),o=n?.route.beforeEnter,i=t._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return o&&i.push(o.name||"beforeEnter"),{mode:t._mode,base:t._base||"/",currentPath:r,params:{...t.params.value},query:{...t.query.value},matchedPath:n?.route.fullPath??null,activeGuards:{globalCount:t._guards.length,hasRouteGuard:!!o,names:i}}}exports.Link=k,exports.RouterKey=i,exports.RouterView=O,exports._debugGetRouterInternal=M,exports._debugRegisterRouter=A,exports._debugUnregisterRouter=j,exports._hasActiveRouter=d,exports._resetRouter=D,exports.createRouter=T,exports.nixRouter=E;
@@ -1,4 +1,4 @@
1
- import{signal as e}from"./signals.js";import{l as t}from"./template2.js";import{NixComponent as n}from"./lifecycle.js";import{createInjectionKey as r,inject as i}from"./context.js";var a=r("nix:router"),o=null,s=null,c="__nix_scroll",l="__nix_pos";function u(){if(!o)throw Error("[Nix] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).");return o}function d(){return null!==o}function f(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||"object"!=typeof e)return null;let t=e[c];if(!t||"object"!=typeof t)return null;let r=t.left,n=t.top;return"number"!=typeof r||"number"!=typeof n?null:{left:r,top:n}}function p(e){if(!e||"object"!=typeof e)return null;let t=e[l];return"number"==typeof t?t:null}function m(e,t,r){let n=e&&"object"==typeof e?{...e}:{};return n[c]={left:t.left,top:t.top},n[l]=r,n}function h(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function g(e){let t=new URLSearchParams;for(let[r,n]of Object.entries(e))null!=n&&!1!==n&&t.set(r,String(n));let r=t.toString();return r?"?"+r:""}function _(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 v(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function y(e,t="",r=[]){let n=[];for(let o of e){let e=v(t,o.path),a=[...r,o.component],i=_(e);n.push({fullPath:e,segments:i,chain:a,name:o.name,meta:o.meta,beforeEnter:o.beforeEnter,record:o}),o.children?.length&&n.push(...y(o.children,e,a))}return n}function b(e,t){let r=e.split("/").filter(Boolean),n=t.segments;if(1===n.length&&"wildcard"===n[0].kind)return{};let o=n.length>0&&"wildcard"===n[n.length-1].kind,a=o?n.slice(0,-1):n;if(o){if(r.length<a.length)return null}else if(r.length!==a.length)return null;let i={};for(let e=0;e<a.length;e++){let t=a[e];if("literal"===t.kind){if(r[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(r[e]??"")}catch{i[t.name]=r[e]??""}}return i}function x(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function S(e,t){let r,n={},o=-1;for(let a of t){let t=b(e,a);if(null===t)continue;let i=x(a);i>o&&(r=a,n=t,o=i)}return r?{route:r,params:n}:void 0}function C(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function te(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return C(new URL(t,window.location.origin).pathname)}catch{return C(t)}}function ne(e){return!1===e?{allow:!1}:!0===e||null==e?{allow:!0}:"string"==typeof e?{allow:!1,redirect:e}:"object"==typeof e&&"redirect"in e&&"string"==typeof e.redirect?{allow:!1,redirect:e.redirect}:{allow:!0}}function w(t,r){let n=null==r?.base?te():C(r.base),a=r?.mode??"history",i="hash"===a,l=r?.scrollBehavior,u=new Map,c=!1;function d(e){return e?e.startsWith("/")?e:"/"+e:"/"}function v(e){let t=d(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":d(e)}return t}function w(){return i?function(){let e=window.location.hash||"";if(e.startsWith("#")&&(e=e.slice(1)),!e)return{pathname:"/",search:""};e.startsWith("/")||(e="/"+e);let t=e.indexOf("?"),r=-1===t?e:e.slice(0,t),n=-1===t?"":e.slice(t);return{pathname:v(r),search:n}}():{pathname:v(window.location.pathname||"/"),search:window.location.search||""}}function b(e,t){let r=function(e){let t=d(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+g(t);return i?"#"+r:r}function _(e,t){return d(e)+g(t)}let x=w(),k=x.pathname,E=h(x.search),R=y(t),j=new Map;for(let e of R)e.name&&(j.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),j.set(e.name,e));let O=S(k,R),W=e(k),$=e(O?.params??{}),q=e(E),L=p(history.state)??0,N=e({action:"initial",direction:"none"}),P=e(L>0);function M(e){window.scrollTo(e.left,e.top)}function T(e,t,r){if(l){let n=l(e,t,r);if(!n)return;return void M(n)}M(r??{left:0,top:0})}i?u.set(_(k,E),f()):history.replaceState(m(history.state,f(),L),"");let B=[],I=[],U=0;function A(e,t,r,n,o){let a=[...B];r&&a.push(r);let i=++U;if(0===a.length)return void n();let l=0;!function r(u){if(i!==U)return;let s=ne(u);if(!s.allow)return s.redirect&&s.redirect!==e?void V(s.redirect):s.redirect===e?void n():void o?.();if(l>=a.length)return void n();let c=a[l++](e,t);c instanceof Promise?c.then(r):r(c)}(void 0)}let D=!1;function G(e,t){let r=e.indexOf("?"),n=d((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:h(e.slice(r)),a=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(a))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:n,stringQuery:i}}function Q(e,t){return"string"==typeof e?G(e,t?.query):G(function(e){let t=j.get(e.name);if(!t)throw Error(`[Nix Router] No route with name "${e.name}"`);return"/"+t.segments.map(t=>{if("literal"===t.kind)return t.value;if("wildcard"===t.kind)return"";let r=e.params?.[t.name];if(null==r)throw Error(`[Nix Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(r))}).filter(Boolean).join("/")}(e),{...e.query??{},...t?.query??{}})}s&&=(s(),null);let K,X=(e,t,r,n,o)=>{let a=W.value,i={...q.value},l=S(e,R),u="none";null!=n&&(n<L?u="back":n>L&&(u="forward")),A(e,a,l?.route.beforeEnter,()=>{null!=n&&(L=n);let o=K;K=void 0,N.value={action:"pop",direction:u,animation:o},$.value=l?.params??{},q.value=t,W.value=e,P.value=L>0,T(e,a,r);for(let t of I)try{t(e,a)}catch{}},()=>o(a,i))};if(i){let e=()=>{if(c)return void(c=!1);let e=w(),t=h(e.search),r=u.get(_(e.pathname,t))??null;X(e.pathname,t,r,null,(e,t)=>{c=!0,window.location.hash=b(e,t).slice(1),queueMicrotask(()=>{c=!1})})};window.addEventListener("hashchange",e),s=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=w(),r=h(t.search),n=ee(e.state??history.state),o=p(e.state??history.state);X(t.pathname,r,n,o,(e,t)=>{history.pushState(m({},f(),L),"",b(e,t))})};window.addEventListener("popstate",e),s=()=>window.removeEventListener("popstate",e)}function Y(e,t,r,n,o,a,l){l||(function(e,t){let r=f();i?u.set(_(e,t),r):history.replaceState(m(history.state,r,L),"")}(r,n),L+=1),N.value=a,$.value=o?.params??{},q.value=t,W.value=e,P.value=L>0;let s=b(e,t);if(i)u.set(_(e,t),{left:0,top:0}),l?history.replaceState(history.state,"",s):(c=!0,window.location.hash=s.slice(1),queueMicrotask(()=>{c=!1}));else{let e=m({},{left:0,top:0},L);l?history.replaceState(e,"",s):history.pushState(e,"",s)}T(e,r,null);for(let t of I)try{t(e,r)}catch{}}function V(e,t){D=!0;let{pathname:r,stringQuery:n}=Q(e,t),o=W.value,a={...q.value},i=S(r,R),l={action:"push",direction:t?.direction??"forward",animation:t?.animation};A(r,o,i?.route.beforeEnter,()=>Y(r,n,o,a,i,l,!1))}let z={current:W,params:$,query:q,intent:N,canGoBack:P,base:n||"/",navigate:V,replace:function(e,t){D=!0;let{pathname:r,stringQuery:n}=Q(e,t),o=W.value,a={...q.value},i=S(r,R),l={action:"replace",direction:t?.direction??"root",animation:t?.animation};A(r,o,i?.route.beforeEnter,()=>Y(r,n,o,a,i,l,!0))},back:function(e){void 0!==e&&(K=e),history.back()},forward:function(e){void 0!==e&&(K=e),history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=W.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=S(e,R);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return B.push(e),()=>{let t=B.indexOf(e);-1!==t&&B.splice(t,1)}},afterEach:function(e){return I.push(e),()=>{let t=I.indexOf(e);-1!==t&&I.splice(t,1)}},routes:t,_flat:R,_guards:B,_base:n,_mode:a};return o&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),o=z,queueMicrotask(()=>{D||A(k,"",S(k,R)?.route.beforeEnter,()=>{},()=>{let e=b("/",{});i?(u.set(_("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(m({},{left:0,top:0},L),"",e);let t=S("/",R);N.value={action:"replace",direction:"root"},W.value="/",$.value=t?.params??{},q.value={},P.value=L>0,T("/",k,null)})}),z}function T(){return i(a)||u()}function E(){s&&=(s(),null),o=null}var D=class extends n{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,r=this._router;return t`<div class="router-view">${()=>{let n=r??T(),o=S(n.current.value,n._flat);if(!o)return t`
1
+ import{signal as e}from"./signals.js";import{l as t}from"./template2.js";import{NixComponent as n}from"./lifecycle.js";import{createInjectionKey as r,inject as i}from"./context.js";var a=r("nix:router"),o=null,s=null,c=[],l="__nix_scroll",u="__nix_pos";function d(){if(!o)throw Error("[Nix] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).");return o}function f(){return null!==o}function p(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function ee(e){if(!e||"object"!=typeof e)return null;let t=e[l];if(!t||"object"!=typeof t)return null;let r=t.left,n=t.top;return"number"!=typeof r||"number"!=typeof n?null:{left:r,top:n}}function m(e){if(!e||"object"!=typeof e)return null;let t=e[u];return"number"==typeof t?t:null}function h(e,t,r){let n=e&&"object"==typeof e?{...e}:{};return n[l]={left:t.left,top:t.top},n[u]=r,n}function g(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function _(e){let t=new URLSearchParams;for(let[r,n]of Object.entries(e))null!=n&&!1!==n&&t.set(r,String(n));let r=t.toString();return r?"?"+r:""}function v(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 y(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function b(e,t="",r=[]){let n=[];for(let o of e){let e=y(t,o.path),a=[...r,o.component],i=v(e);n.push({fullPath:e,segments:i,chain:a,name:o.name,meta:o.meta,beforeEnter:o.beforeEnter,record:o}),o.children?.length&&n.push(...b(o.children,e,a))}return n}function x(e,t){let r=e.split("/").filter(Boolean),n=t.segments;if(1===n.length&&"wildcard"===n[0].kind)return{};let o=n.length>0&&"wildcard"===n[n.length-1].kind,a=o?n.slice(0,-1):n;if(o){if(r.length<a.length)return null}else if(r.length!==a.length)return null;let i={};for(let e=0;e<a.length;e++){let t=a[e];if("literal"===t.kind){if(r[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(r[e]??"")}catch{i[t.name]=r[e]??""}}return i}function S(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function C(e,t){let r,n={},o=-1;for(let a of t){let t=x(e,a);if(null===t)continue;let i=S(a);i>o&&(r=a,n=t,o=i)}return r?{route:r,params:n}:void 0}function w(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function T(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return w(new URL(t,window.location.origin).pathname)}catch{return w(t)}}function te(e){return!1===e?{allow:!1}:!0===e||null==e?{allow:!0}:"string"==typeof e?{allow:!1,redirect:e}:"object"==typeof e&&"redirect"in e&&"string"==typeof e.redirect?{allow:!1,redirect:e.redirect}:{allow:!0}}function E(t,r){let n=null==r?.base?T():w(r.base),a=r?.mode??"history",i="hash"===a,l=r?.scrollBehavior,u=new Map,c=!1;function f(e){return e?e.startsWith("/")?e:"/"+e:"/"}function d(e){let t=f(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":f(e)}return t}function v(){return i?function(){let e=window.location.hash||"";if(e.startsWith("#")&&(e=e.slice(1)),!e)return{pathname:"/",search:""};e.startsWith("/")||(e="/"+e);let t=e.indexOf("?"),r=-1===t?e:e.slice(0,t),n=-1===t?"":e.slice(t);return{pathname:d(r),search:n}}():{pathname:d(window.location.pathname||"/"),search:window.location.search||""}}function y(e,t){let r=function(e){let t=f(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+_(t);return i?"#"+r:r}function x(e,t){return f(e)+_(t)}let k=v(),R=k.pathname,E=g(k.search),S=b(t),j=new Map;for(let e of S)e.name&&(j.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),j.set(e.name,e));let O=C(R,S),W=e(R),$=e(O?.params??{}),q=e(E),N=m(history.state)??0,L=e({action:"initial",direction:"none"}),M=e(N>0);function P(e){window.scrollTo(e.left,e.top)}function A(e,t,r){if(l){let n=l(e,t,r);if(!n)return;return void P(n)}P(r??{left:0,top:0})}i?u.set(x(R,E),p()):history.replaceState(h(history.state,p(),N),"");let D=[],U=[],B=0;function I(e,t,r,n,o){let a=[...D];r&&a.push(r);let i=++B;if(0===a.length)return void n();let l=0;!function r(u){if(i!==B)return;let s=te(u);if(!s.allow)return s.redirect&&s.redirect!==e?void z(s.redirect):s.redirect===e?void n():void o?.();if(l>=a.length)return void n();let c=a[l++](e,t);c instanceof Promise?c.then(r):r(c)}(void 0)}let G=!1;function Q(e,t){let r=e.indexOf("?"),n=f((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:g(e.slice(r)),a=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(a))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:n,stringQuery:i}}function K(e,t){return"string"==typeof e?Q(e,t?.query):Q(function(e){let t=j.get(e.name);if(!t)throw Error(`[Nix Router] No route with name "${e.name}"`);return"/"+t.segments.map(t=>{if("literal"===t.kind)return t.value;if("wildcard"===t.kind)return"";let r=e.params?.[t.name];if(null==r)throw Error(`[Nix Router] Missing param "${t.name}" for route "${e.name}"`);return encodeURIComponent(String(r))}).filter(Boolean).join("/")}(e),{...e.query??{},...t?.query??{}})}s&&=(s(),null);let X,Y=(e,t,r,n,o)=>{let a=W.value,i={...q.value},l=C(e,S),u="none";null!=n&&(n<N?u="back":n>N&&(u="forward")),I(e,a,l?.route.beforeEnter,()=>{null!=n&&(N=n);let o=X;X=void 0,L.value={action:"pop",direction:u,animation:o},$.value=l?.params??{},q.value=t,W.value=e,M.value=N>0,A(e,a,r);for(let t of U)try{t(e,a)}catch{}},()=>o(a,i))};if(i){let e=()=>{if(c)return void(c=!1);let e=v(),t=g(e.search),r=u.get(x(e.pathname,t))??null;Y(e.pathname,t,r,null,(e,t)=>{c=!0,window.location.hash=y(e,t).slice(1),queueMicrotask(()=>{c=!1})})};window.addEventListener("hashchange",e),s=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=v(),r=g(t.search),n=ee(e.state??history.state),o=m(e.state??history.state);Y(t.pathname,r,n,o,(e,t)=>{history.pushState(h({},p(),N),"",y(e,t))})};window.addEventListener("popstate",e),s=()=>window.removeEventListener("popstate",e)}function V(e,t,r,n,o,a,l){l||(function(e,t){let r=p();i?u.set(x(e,t),r):history.replaceState(h(history.state,r,N),"")}(r,n),N+=1),L.value=a,$.value=o?.params??{},q.value=t,W.value=e,M.value=N>0;let s=y(e,t);if(i)u.set(x(e,t),{left:0,top:0}),l?history.replaceState(history.state,"",s):(c=!0,window.location.hash=s.slice(1),queueMicrotask(()=>{c=!1}));else{let e=h({},{left:0,top:0},N);l?history.replaceState(e,"",s):history.pushState(e,"",s)}A(e,r,null);for(let t of U)try{t(e,r)}catch{}}function z(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,a={...q.value},i=C(r,S),l={action:"push",direction:t?.direction??"forward",animation:t?.animation};I(r,o,i?.route.beforeEnter,()=>V(r,n,o,a,i,l,!1))}let F={current:W,params:$,query:q,intent:L,canGoBack:M,base:n||"/",navigate:z,replace:function(e,t){G=!0;let{pathname:r,stringQuery:n}=K(e,t),o=W.value,a={...q.value},i=C(r,S),l={action:"replace",direction:t?.direction??"root",animation:t?.animation};I(r,o,i?.route.beforeEnter,()=>V(r,n,o,a,i,l,!0))},back:function(e){void 0!==e&&(X=e),history.back()},forward:function(e){void 0!==e&&(X=e),history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=W.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=C(e,S);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return D.push(e),()=>{let t=D.indexOf(e);-1!==t&&D.splice(t,1)}},afterEach:function(e){return U.push(e),()=>{let t=U.indexOf(e);-1!==t&&U.splice(t,1)}},routes:t,_flat:S,_guards:D,_base:n,_mode:a};return o&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),o=F,queueMicrotask(()=>{G||I(R,"",C(R,S)?.route.beforeEnter,()=>{},()=>{let e=y("/",{});i?(u.set(x("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(h({},{left:0,top:0},N),"",e);let t=C("/",S);L.value={action:"replace",direction:"root"},W.value="/",$.value=t?.params??{},q.value={},M.value=N>0,A("/",R,null)})}),F}function D(){return i(a)||d()}function O(){s&&=(s(),null),o=null,c.length=0}var k=class extends n{_depth;_router;constructor(e=0,t){super(),this._depth=e,this._router=t}render(){let e=this._depth,r=this._router;return t`<div class="router-view">${()=>{let n=r??D(),o=C(n.current.value,n._flat);if(!o)return t`
2
2
  <div style="color:#f87171;padding:16px 0">
3
3
  404 — Route not found: <strong>${n.current.value}</strong>
4
4
  </div>
@@ -6,6 +6,6 @@ import{signal as e}from"./signals.js";import{l as t}from"./template2.js";import{
6
6
  <span></span>
7
7
  `;let a=o.route.chain[e];return a?a():t`
8
8
  <span></span>
9
- `}}</div>`}},O=class extends n{_to;_label;_router;constructor(e,t,r){super(),this._to=e,this._label=t,this._router=r}render(){let e=this._to,r=this._label,n=this._router??T(),o=e.startsWith("/")?e:"/"+e,a=(n._base?n._base+o:o).replace(/\/+/g,"/");return t`
9
+ `}}</div>`}},A=class extends n{_to;_label;_router;constructor(e,t,r){super(),this._to=e,this._label=t,this._router=r}render(){let e=this._to,r=this._label,n=this._router??D(),o=e.startsWith("/")?e:"/"+e,a=(n._base?n._base+o:o).replace(/\/+/g,"/");return t`
10
10
  <a href=${"hash"===n._mode?"#"+a:a} style=${()=>n.current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"} @click=${t=>{t.preventDefault(),n.navigate(e)}}>${r}</a>
11
- `}};function k(){if(!o)return null;let e=o.current.value,t=S(e,o._flat),r=t?.route.beforeEnter,n=o._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return r&&n.push(r.name||"beforeEnter"),{mode:o._mode,base:o._base||"/",currentPath:e,params:{...o.params.value},query:{...o.query.value},matchedPath:t?.route.fullPath??null,activeGuards:{globalCount:o._guards.length,hasRouteGuard:!!r,names:n}}}export{O as Link,a as RouterKey,D as RouterView,k as _debugGetRouterInternal,d as _hasActiveRouter,E as _resetRouter,w as createRouter,T as nixRouter};
11
+ `}};function j(e){let t=c.indexOf(e);t>=0&&c.splice(t,1),c.push(e)}function M(e){let t=c.indexOf(e);t>=0&&c.splice(t,1)}function N(){let e=c.length?c[c.length-1]:o;if(!e)return null;let t=e,r=t.current.value,n=C(r,t._flat),a=n?.route.beforeEnter,i=t._guards.map((e,t)=>e.name||`beforeEach#${t+1}`);return a&&i.push(a.name||"beforeEnter"),{mode:t._mode,base:t._base||"/",currentPath:r,params:{...t.params.value},query:{...t.query.value},matchedPath:n?.route.fullPath??null,activeGuards:{globalCount:t._guards.length,hasRouteGuard:!!a,names:i}}}export{A as Link,a as RouterKey,k as RouterView,N as _debugGetRouterInternal,j as _debugRegisterRouter,M as _debugUnregisterRouter,f as _hasActiveRouter,O as _resetRouter,E as createRouter,D as nixRouter};
@@ -1 +1 @@
1
- const e=require("./signals.cjs"),t=require("./lifecycle.cjs"),n=require("./context.cjs");function r(){return{el:null}}var i={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function a(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function o(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function s(e,r,o){let i,l;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}i=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}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{}i(),t._debugComponentUnmount(e)}}function c(e,r,o){let i,l;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch{}i=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}i(),t._debugComponentUnmount(e)}}function l(e,r,o,i){let l,u;t._debugComponentMountStart(e);try{n._withComponentContext(i,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(r,o)})}finally{t._debugComponentMountEnd(e)}try{let t=e.onMount?.();"function"==typeof t&&(u=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{u?.()}catch{}l(),t._debugComponentUnmount(e)}}function u(e,r,o,i,l){let u,a;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}u=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}i.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(a=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{a?.()}catch{}u(),t._debugComponentUnmount(e)})}function d(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function f(e){let t,n,r,o,i,l=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){l[t]=n,u.push(t);continue}for(r=0,o=u.length-1;r<o;)i=r+o>>1,e[u[i]]<a?r=i+1:o=i;a<e[u[r]]&&(r>0&&(l[t]=u[r-1]),u[r]=t)}}for(r=u.length,o=u[r-1];r-- >0;)u[r]=o,o=l[o];return u}var p=new Set,m=!1;function h(e){p.add(e),m||(m=!0,queueMicrotask(()=>{for(let e of p)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}p.clear(),m=!1}))}function g(r,i,c,d){if("function"!=typeof i){if(t.isNixComponent(i))u(i,r.parentNode,r,d,c);else if(a(i))c.push(i._render(r.parentNode,r));else if(Array.isArray(i))for(let e of i)t.isNixComponent(e)?u(e,r.parentNode,r,d,c):a(e)?e._render(r.parentNode,r):null!=e&&!1!==e&&r.parentNode.insertBefore(document.createTextNode(String(e)),r);else null!=i&&!1!==i&&r.parentNode.insertBefore(document.createTextNode(String(i)),r);return}let p=null,m=null,y=null,g=[],x=null,v=n._captureContextSnapshot(),_=!1,N="",b=!0,C=e.effect(()=>{let n=i();if("string"==typeof n||"number"==typeof n){N=String(n);let e=()=>{_=!1,m&&=(m(),null),p?p.nodeValue=N:(p=document.createTextNode(N),r.parentNode.insertBefore(p,r))};return void(b?(b=!1,e()):_||(_=!0,h(e)))}if(_=!1,b=!1,p&&=(p.parentNode?.removeChild(p),null),m&&=(m(),null),null!=n&&!1!==n)if(a(n))m=n._render(r.parentNode,r);else if(t.isNixComponent(n))m=l(n,r.parentNode,r,v);else if(o(n)){y||(y=new Map,x=document.createTextNode(""),r.parentNode.insertBefore(x,r));let o=r.parentNode,i=n.items.map((e,t)=>n.keyFn(e,t)),u=new Set(i),a=!1;if(y.size>0)for(let e of y.keys())if(u.has(e)){a=!0;break}if(!a){if(y.size>0){let e=document.createRange();e.setStartAfter(x),e.setEndBefore(r),e.deleteContents();for(let e of y.values())e.cleanup();y.clear()}if(i.length>0){let u=document.createDocumentFragment();e.batch(()=>{for(let e=0;e<i.length;e++){let r=i[e],o=n.items[e],a=document.createTextNode(""),c=document.createTextNode("");u.appendChild(a),u.appendChild(c);let s=n.renderFn(o,e),d=t.isNixComponent(s)?l(s,u,c,v):s._render(u,c);y.has(r)&&console.warn(`[Nix] repeat(): duplicate key "${r}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),y?.set(r,{start:a,end:c,cleanup:d})}}),o.insertBefore(u,r)}return void(g=i)}let c=new Map;for(let e=0;e<i.length;e++)c.set(i[e],e);let s=new Int32Array(i.length),d=!1,p=0;for(let e=0;e<g.length;e++){let t=g[e],n=c.get(t);if(void 0===n){let e=y.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}y.delete(t)}else s[n]=e+1,n>=p?p=n:d=!0}let m=d?f(s):[],h=m.length-1,_=r;for(let e=i.length-1;e>=0;e--){let r=i[e];if(0===s[e]){let i=n.items[e],u=document.createTextNode(""),a=document.createTextNode(""),c=document.createDocumentFragment();c.appendChild(u),c.appendChild(a);let s=n.renderFn(i,e),d=t.isNixComponent(s)?l(s,c,a,v):s._render(c,a);y.has(r)&&console.warn(`[Nix] repeat(): duplicate key "${r}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),y.set(r,{start:u,end:a,cleanup:d}),o.insertBefore(c,_),_=u}else{let t=y.get(r);if(d)if(h<0||e!==m[h]){let e=t.start;for(;e;){let n=e===t.end?null:e.nextSibling;if(o.insertBefore(e,_),!n)break;e=n}}else h--;_=t.start}}g=i}else if(Array.isArray(n)){let e=[];for(let o of n)if(t.isNixComponent(o))e.push(s(o,r.parentNode,r));else if(a(o))e.push(o._render(r.parentNode,r));else if(null!=o&&!1!==o){let t=document.createTextNode(String(o));r.parentNode.insertBefore(t,r),e.push(()=>t.parentNode?.removeChild(t))}m=()=>e.forEach(e=>e())}else p=document.createTextNode(String(n)),r.parentNode.insertBefore(p,r)});c.push(()=>{if(C(),m&&=(m(),null),p&&=(p.parentNode?.removeChild(p),null),y){for(let e of y.values())e.cleanup();y=null,x=null}})}var _=new Set(["href","src","action","formaction","xlink:href","poster","background","cite","ping","data"]);function v(e){return _.has(e.toLowerCase())}function y(e){let t=e.toLowerCase();return t.startsWith("on")||"srcdoc"===t}var b=/[\u0000-\u001F\u007F-\u009F\u2028\u2029\uFEFF]/g,x=/^(?:javascript|vbscript|livescript|mocha|data):/i,S=/^data:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|vnd\.microsoft\.icon)[;,]/i;function C(e){let t=e.replace(b,"").trim();return x.test(t)?/^data:/i.test(t)&&S.test(t)?e:(console.warn(`[Nix] Blocked attribute URL with unsafe scheme: "${t.slice(0,48)}${t.length>48?"…":""}"`),""):e}function w(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function T(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.lastIndexOf("=");if(-1===o)return{type:"node"};let i=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],l=o-1;for(;l>=0&&/\S/.test(r[l]);)l--;l++;let u=r.slice(l,o);if("@"===u[0]){let e=u.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:i}}return{type:"attr",attrName:u,hadOpenQuote:i,url:v(u),executable:y(u)}}var E={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},D=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),O=new Set;function k(e,t,n){let r=e.target,o=e.stopPropagation,i=!1;for(e.stopPropagation=()=>{i=!0,o.call(e)};r&&r!==document;){let o=r[t];if(o){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,o=!0;for(let e of t){let t=E[e];if(void 0!==t&&n.key!==t){o=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){o=!1;break}}if(!o){r=r.parentNode;continue}}}if(o(e),i)break}r=r.parentNode}e.stopPropagation=o}var A=new Map;function j(t,n,r,o){let i=[],l=[],u=Array(n.length),a=-1;for(let e=0;e<n.length;e++)o[e]&&o[e].nodeIndex>a&&(a=o[e].nodeIndex);let c=Array(a+1);if(c[0]=t,a>0){let e,n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=a&&(e=n.nextNode());)c[r++]=e}for(let e=0;e<n.length;e++){let t=o[e];u[e]=t?c[t.nodeIndex]:null}for(let t=0;t<n.length;t++){let a=n[t],c=r[t],s=o[t];if(!s)continue;let d=u[t];if("event"===a.type){let e=s.name,t=c,n=a.modifiers;if(!D.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)};d.addEventListener(e,o,r),i.push(()=>d.removeEventListener(e,o,r))}else{if(!O.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>k(e,t,n);A.set(e,r),document.addEventListener(e,r),O.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;d[r]=t,n.length>0&&(d[o]=n),i.push(()=>{d[r]=null,d[o]=null})}continue}if("attr"===a.type){let t=s.name,n=d;if("ref"===t){c.el=n,i.push(()=>{c.el=null});continue}if("show"===t||"hide"===t){let r=n,o=null;if("function"==typeof c){let n=!1,l=!1,u=!0,a=e.effect(()=>{l=!!c();let e=()=>{n=!1;let e="show"===t?l:!l;null===o&&(o=r.style.display||""),r.style.display=e?o:"none"};u?(u=!1,e()):n||(n=!0,h(e))});i.push(a)}else("show"===t?c:!c)||(r.style.display="none");continue}(a.executable??y(t))&&console.warn(`[Nix] Dynamic binding on executable attribute "${t}". Use @event for handlers; avoid binding untrusted values here.`);let r=a.url??v(t),o=("value"===t||"checked"===t||"selected"===t)&&t in n;if("function"==typeof c){let l,u=!1,a=!0,s=e.effect(()=>{l=c();let e=()=>{u=!1;let e=l;if(o)n[t]=e??"";else if(null==e||!1===e)n.removeAttribute(t);else{let o=String(e);n.setAttribute(t,r?C(o):o)}};a?(a=!1,e()):u||(u=!0,h(e))});i.push(s)}else if(o)n[t]=c??"";else if(null!=c&&!1!==c){let e=String(c);n.setAttribute(t,r?C(e):e)}continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),g(p,c,i,l)}return{disposes:i,postMountHooks:l}}function M(e,t){let n=new Uint8Array(e.length),r="";for(let o=0;o<e.length;o++){let i=e[o];if(1===n[o]&&('"'===i[0]||"'"===i[0])&&(i=i.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=i+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+ +!!e.hadOpenQuote;r+=i.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+ +!!e.hadOpenQuote;r+=i.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=i}return r}var N=new WeakMap;function P(e,...t){let n=N.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(T(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=M(e,t);let i,l=Array(t.length).fill(null),u=o.content,a=document.createTreeWalker(u,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),c=0;for(;i=a.nextNode();)if(c++,8===i.nodeType){let e=i.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(l[t]={nodeIndex:c})}}else if(1===i.nodeType){let e=i,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],o=r.name;if(o.startsWith("data-nix-e-")){let t=parseInt(o.slice(11),10);isNaN(t)||(l[t]={nodeIndex:c,name:r.value},e.removeAttribute(o));continue}if(o.startsWith("data-nix-a-")){let t=parseInt(o.slice(11),10);isNaN(t)||(l[t]={nodeIndex:c,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:l},N.set(e,n)}let{contexts:r,tpl:o,pathMap:i}=n;function l(e,n){let l=o.content.cloneNode(!0),{disposes:u,postMountHooks:a}=j(l,r,t,i),c=document.createTextNode(""),s=document.createTextNode("");return e.insertBefore(c,n),e.insertBefore(l,n),e.insertBefore(s,n),a.forEach(e=>e()),()=>{for(let e=u.length-1;e>=0;e--)u[e]();let e=c.nextSibling;for(;e&&e!==s;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}c.parentNode?.removeChild(c),s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function F(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 I(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function L(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(I(r.transitionDuration||"0"),I(r.animationDuration||"0")),i=o>0?o+100:t;if(i<=0)return void n();let l,u=t=>{t.target===e&&(clearTimeout(l),e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n())};e.addEventListener("transitionend",u),e.addEventListener("animationend",u),l=setTimeout(()=>{e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n()},i)})}function R(n,r={}){let o=F(r);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(l,u){let a=document.createComment(i.TRANSITION);l.insertBefore(a,u);let s=null,d=null,f=0,p=!0,m=()=>{let e=a.nextSibling;for(;e&&e!==u;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function h(e){return t.isNixComponent(e)?c(e,l,u):e._render(l,u)}let y=(e,t=!1)=>{f++,d&&=(d(),null),s=h(e);let n=m();if(n&&(!p||r.appear)&&!t){let e=f;(async()=>{r.onBeforeEnter?.(n),n.classList.add(o.enterFrom,o.enterActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),f===e&&(n.classList.remove(o.enterFrom),n.classList.add(o.enterTo),await L(n,r.duration),f===e&&(n.classList.remove(o.enterActive,o.enterTo),r.onAfterEnter?.(n)))})().catch(()=>{})}p=!1},g=()=>{let e=s;s=null;let t=m();if(!t)return void e?.();let n=++f;d=e??null,(async()=>{r.onBeforeLeave?.(t),t.classList.add(o.leaveFrom,o.leaveActive),t.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),f===n&&(t.classList.remove(o.leaveFrom),t.classList.add(o.leaveTo),await L(t,r.duration),f===n&&(t.classList.remove(o.leaveActive,o.leaveTo),r.onAfterLeave?.(t),d?.(),d=null))})().catch(()=>{})},x=null;if("function"!=typeof n||t.isNixComponent(n))y(n);else{let t=n,r=null;x=e.effect(()=>{let e=t(),n=null===r,o=null===e;n&&!o?y(e):!n&&o?g():!n&&!o&&(f++,d?.(),d=null,s?.(),s=null,y(e,!0)),r=e}),p=!1}return()=>{f++,x?.(),s?.(),d?.(),s=null,d=null,a.remove()}}}}function z(){return{__isPortalOutlet:!0,_container:null}}function B(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 V(e,n=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 i;return i="string"==typeof n?document.querySelector(n)??document.body:n instanceof Element?n:"__isPortalOutlet"in n?n._container??document.body:n.el??document.body,t.isNixComponent(e)?s(e,i,null):e._render(i,null)}}}var H=n.createInjectionKey("nix:portal-outlet");function U(e){n.provide(H,e)}function W(){return n.inject(H)}function G(r,o){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(l,u){let a=document.createComment(i.ERROR_BOUNDARY);l.insertBefore(a,u);let s,d=null,f=!1,p=!1,m=!1,h=e=>{let n=a.parentNode,r="function"!=typeof o||t.isNixComponent(o)?o:o(e);d=t.isNixComponent(r)?c(r,n,u):r._render(n,u)};e._pushErrorHandler(e=>{f||(f=!0,p?(d?.(),d=null,h(e)):(s=e,m=!0))});try{if(t.isNixComponent(r)){n._pushComponentContext();try{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}d=r.render()._render(l,u)}finally{n._popComponentContext()}if(!f)try{let e=r.onMount?.(),t=d;d=()=>{try{r.onUnmount?.()}catch{}if("function"==typeof e)try{e()}catch{}t?.()}}catch(e){if(!r.onError)throw e;r.onError(e)}}else d=r._render(l,u)}catch(e){f=!0,d?.(),d=null,s=e,m=!0}finally{e._popErrorHandler(),p=!0}return m&&(d?.(),d=null,h(s)),()=>{d?.(),a.remove()}}}}Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return r}});
1
+ const e=require("./signals.cjs"),t=require("./lifecycle.cjs"),n=require("./context.cjs");function r(){return{el:null}}var i={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function a(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function o(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function s(e,r,o){let i,l;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}i=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}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{}i(),t._debugComponentUnmount(e)}}function c(e,r,o){let i,l;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch{}i=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}i(),t._debugComponentUnmount(e)}}function l(e,r,o,i){let l,a;t._debugComponentMountStart(e);try{n._withComponentContext(i,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(r,o)})}finally{t._debugComponentMountEnd(e)}try{let t=e.onMount?.();"function"==typeof t&&(a=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{a?.()}catch{}l(),t._debugComponentUnmount(e)}}function u(e,r,o,i,l){let a,u;t._debugComponentMountStart(e),n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(r,o)}finally{t._debugComponentMountEnd(e),n._popComponentContext()}i.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(u=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{u?.()}catch{}a(),t._debugComponentUnmount(e)})}function d(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function f(e){let t,n,r,o,i,l=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){l[t]=n,a.push(t);continue}for(r=0,o=a.length-1;r<o;)i=r+o>>1,e[a[i]]<u?r=i+1:o=i;u<e[a[r]]&&(r>0&&(l[t]=a[r-1]),a[r]=t)}}for(r=a.length,o=a[r-1];r-- >0;)a[r]=o,o=l[o];return a}var p=new Set,m=!1;function h(e){p.add(e),m||(m=!0,queueMicrotask(()=>{for(let e of p)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}p.clear(),m=!1}))}function g(r,i,c,d){if("function"!=typeof i){if(t.isNixComponent(i))u(i,r.parentNode,r,d,c);else if(a(i))c.push(i._render(r.parentNode,r));else if(Array.isArray(i))for(let e of i)t.isNixComponent(e)?u(e,r.parentNode,r,d,c):a(e)?e._render(r.parentNode,r):null!=e&&!1!==e&&r.parentNode.insertBefore(document.createTextNode(String(e)),r);else null!=i&&!1!==i&&r.parentNode.insertBefore(document.createTextNode(String(i)),r);return}let p=null,m=null,y=null,x=[],g=null,v=n._captureContextSnapshot(),b=!1,N="",_=!0,E=e.effect(()=>{let n=i();if("string"==typeof n||"number"==typeof n){N=String(n);let e=()=>{b=!1,m&&=(m(),null),p?p.nodeValue=N:(p=document.createTextNode(N),r.parentNode.insertBefore(p,r))};return void(_?(_=!1,e()):b||(b=!0,h(e)))}if(b=!1,_=!1,p&&=(p.parentNode?.removeChild(p),null),m&&=(m(),null),null!=n&&!1!==n)if(a(n))m=n._render(r.parentNode,r);else if(t.isNixComponent(n))m=l(n,r.parentNode,r,v);else if(o(n)){y||(y=new Map,g=document.createTextNode(""),r.parentNode.insertBefore(g,r));let o=r.parentNode,i=n.items.map((e,t)=>n.keyFn(e,t)),a=new Set(i),u=!1;if(y.size>0)for(let e of y.keys())if(a.has(e)){u=!0;break}if(!u){if(y.size>0){let e=document.createRange();e.setStartAfter(g),e.setEndBefore(r),e.deleteContents();for(let e of y.values())e.cleanup();y.clear()}if(i.length>0){let a=document.createDocumentFragment();e.batch(()=>{for(let e=0;e<i.length;e++){let r=i[e],o=n.items[e],u=document.createTextNode(""),c=document.createTextNode("");a.appendChild(u),a.appendChild(c);let s=n.renderFn(o,e),d=t.isNixComponent(s)?l(s,a,c,v):s._render(a,c);y.has(r)&&console.warn(`[Nix] repeat(): duplicate key "${r}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),y?.set(r,{start:u,end:c,cleanup:d})}}),o.insertBefore(a,r)}return void(x=i)}let c=new Map;for(let e=0;e<i.length;e++)c.set(i[e],e);let s=new Int32Array(i.length),d=!1,p=0;for(let e=0;e<x.length;e++){let t=x[e],n=c.get(t);if(void 0===n){let e=y.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}y.delete(t)}else s[n]=e+1,n>=p?p=n:d=!0}let m=d?f(s):[],h=m.length-1,b=r;for(let e=i.length-1;e>=0;e--){let r=i[e];if(0===s[e]){let i=n.items[e],a=document.createTextNode(""),u=document.createTextNode(""),c=document.createDocumentFragment();c.appendChild(a),c.appendChild(u);let s=n.renderFn(i,e),d=t.isNixComponent(s)?l(s,c,u,v):s._render(c,u);y.has(r)&&console.warn(`[Nix] repeat(): duplicate key "${r}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),y.set(r,{start:a,end:u,cleanup:d}),o.insertBefore(c,b),b=a}else{let t=y.get(r);if(d)if(h<0||e!==m[h]){let e=t.start;for(;e;){let n=e===t.end?null:e.nextSibling;if(o.insertBefore(e,b),!n)break;e=n}}else h--;b=t.start}}x=i}else if(Array.isArray(n)){let e=[];for(let o of n)if(t.isNixComponent(o))e.push(s(o,r.parentNode,r));else if(a(o))e.push(o._render(r.parentNode,r));else if(null!=o&&!1!==o){let t=document.createTextNode(String(o));r.parentNode.insertBefore(t,r),e.push(()=>t.parentNode?.removeChild(t))}m=()=>e.forEach(e=>e())}else p=document.createTextNode(String(n)),r.parentNode.insertBefore(p,r)});c.push(()=>{if(E(),m&&=(m(),null),p&&=(p.parentNode?.removeChild(p),null),y){for(let e of y.values())e.cleanup();y=null,g=null}})}var _=new Set(["href","src","action","formaction","xlink:href","poster","background","cite","ping","data"]);function v(e){return _.has(e.toLowerCase())}function y(e){let t=e.toLowerCase();return t.startsWith("on")||"srcdoc"===t}var b=/[\u0000-\u001F\u007F-\u009F\u2028\u2029\uFEFF]/g,x=/^(?:javascript|vbscript|livescript|mocha|data):/i,S=/^data:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|vnd\.microsoft\.icon)[;,]/i;function C(e){let t=e.replace(b,"").trim();return x.test(t)?/^data:/i.test(t)&&S.test(t)?e:(console.warn(`[Nix] Blocked attribute URL with unsafe scheme: "${t.slice(0,48)}${t.length>48?"…":""}"`),""):e}function w(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function T(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.lastIndexOf("=");if(-1===o)return{type:"node"};let i=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],l=o-1;for(;l>=0&&/\S/.test(r[l]);)l--;l++;let a=r.slice(l,o);if("@"===a[0]){let e=a.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:i}}return{type:"attr",attrName:a,hadOpenQuote:i,url:v(a),executable:y(a)}}var E={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},D=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),O=new Set;function k(e,t,n){let r=e.target,o=e.stopPropagation,i=!1;for(e.stopPropagation=()=>{i=!0,o.call(e)};r&&r!==document;){let o=r[t];if(o){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,o=!0;for(let e of t){let t=E[e];if(void 0!==t&&n.key!==t){o=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){o=!1;break}}if(!o){r=r.parentNode;continue}}}if(o(e),i)break}r=r.parentNode}e.stopPropagation=o}var A=new Map;function j(t,n,r,o){let i=[],l=[],a=Array(n.length),u=-1;for(let e=0;e<n.length;e++)o[e]&&o[e].nodeIndex>u&&(u=o[e].nodeIndex);let c=Array(u+1);if(c[0]=t,u>0){let e,n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=u&&(e=n.nextNode());)c[r++]=e}for(let e=0;e<n.length;e++){let t=o[e];a[e]=t?c[t.nodeIndex]:null}for(let t=0;t<n.length;t++){let u=n[t],c=r[t],s=o[t];if(!s)continue;let d=a[t];if("event"===u.type){let e=s.name,t=c,n=u.modifiers;if(!D.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)};d.addEventListener(e,o,r),i.push(()=>d.removeEventListener(e,o,r))}else{if(!O.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>k(e,t,n);A.set(e,r),document.addEventListener(e,r),O.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;d[r]=t,n.length>0&&(d[o]=n),i.push(()=>{d[r]=null,d[o]=null})}continue}if("attr"===u.type){let t=s.name,n=d;if("ref"===t){c.el=n,i.push(()=>{c.el=null});continue}if("show"===t||"hide"===t){let r=n,o=null;if("function"==typeof c){let n=!1,l=!1,a=!0,u=e.effect(()=>{l=!!c();let e=()=>{n=!1;let e="show"===t?l:!l;null===o&&(o=r.style.display||""),r.style.display=e?o:"none"};a?(a=!1,e()):n||(n=!0,h(e))});i.push(u)}else("show"===t?c:!c)||(r.style.display="none");continue}(u.executable??y(t))&&console.warn(`[Nix] Dynamic binding on executable attribute "${t}". Use @event for handlers; avoid binding untrusted values here.`);let r=u.url??v(t),o=("value"===t||"checked"===t||"selected"===t)&&t in n;if("function"==typeof c){let l,a=!1,u=!0,s=e.effect(()=>{l=c();let e=()=>{a=!1;let e=l;if(o)n[t]=e??"";else if(null==e||!1===e)n.removeAttribute(t);else{let o=String(e);n.setAttribute(t,r?C(o):o)}};u?(u=!1,e()):a||(a=!0,h(e))});i.push(s)}else if(o)n[t]=c??"";else if(null!=c&&!1!==c){let e=String(c);n.setAttribute(t,r?C(e):e)}continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),g(p,c,i,l)}return{disposes:i,postMountHooks:l}}function M(e,t){let n=new Uint8Array(e.length),r="";for(let o=0;o<e.length;o++){let i=e[o];if(1===n[o]&&('"'===i[0]||"'"===i[0])&&(i=i.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=i+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+ +!!e.hadOpenQuote;r+=i.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+ +!!e.hadOpenQuote;r+=i.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=i}return r}var N=new WeakMap;function P(e,...t){let n=N.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(T(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=M(e,t);let i,l=Array(t.length).fill(null),a=o.content,u=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),c=0;for(;i=u.nextNode();)if(c++,8===i.nodeType){let e=i.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(l[t]={nodeIndex:c})}}else if(1===i.nodeType){let e=i,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],o=r.name;if(o.startsWith("data-nix-e-")){let t=parseInt(o.slice(11),10);isNaN(t)||(l[t]={nodeIndex:c,name:r.value},e.removeAttribute(o));continue}if(o.startsWith("data-nix-a-")){let t=parseInt(o.slice(11),10);isNaN(t)||(l[t]={nodeIndex:c,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:l},N.set(e,n)}let{contexts:r,tpl:o,pathMap:i}=n;function l(e,n){let l=o.content.cloneNode(!0),{disposes:a,postMountHooks:u}=j(l,r,t,i),c=document.createTextNode(""),s=document.createTextNode("");return e.insertBefore(c,n),e.insertBefore(l,n),e.insertBefore(s,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=c.nextSibling;for(;e&&e!==s;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}c.parentNode?.removeChild(c),s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function F(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 I(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function L(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(I(r.transitionDuration||"0"),I(r.animationDuration||"0")),i=o>0?o+100:t;if(i<=0)return void n();let l,a=t=>{t.target===e&&(clearTimeout(l),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),l=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},i)})}function R(n,r={}){let o=F(r);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(l,a){let u=document.createComment(i.TRANSITION);l.insertBefore(u,a);let s=null,d=null,f=0,p=!0,m=()=>{let e=u.nextSibling;for(;e&&e!==a;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function h(e){return t.isNixComponent(e)?c(e,l,a):e._render(l,a)}let y=(e,t=!1)=>{f++,d&&=(d(),null),s=h(e);let n=m();if(n&&(!p||r.appear)&&!t){let e=f;(async()=>{r.onBeforeEnter?.(n),n.classList.add(o.enterFrom,o.enterActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),f===e&&(n.classList.remove(o.enterFrom),n.classList.add(o.enterTo),await L(n,r.duration),f===e&&(n.classList.remove(o.enterActive,o.enterTo),r.onAfterEnter?.(n)))})().catch(()=>{})}p=!1},x=()=>{let e=s;s=null;let t=m();if(!t)return void e?.();let n=++f;d=e??null,(async()=>{r.onBeforeLeave?.(t),t.classList.add(o.leaveFrom,o.leaveActive),t.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),f===n&&(t.classList.remove(o.leaveFrom),t.classList.add(o.leaveTo),await L(t,r.duration),f===n&&(t.classList.remove(o.leaveActive,o.leaveTo),r.onAfterLeave?.(t),d?.(),d=null))})().catch(()=>{})},g=null;if("function"!=typeof n||t.isNixComponent(n))y(n);else{let t=n,r=null;g=e.effect(()=>{let e=t(),n=null===r,o=null===e;n&&!o?y(e):!n&&o?x():!n&&!o&&(f++,d?.(),d=null,s?.(),s=null,y(e,!0)),r=e}),p=!1}return()=>{f++,g?.(),s?.(),d?.(),s=null,d=null,u.remove()}}}}function z(){return{__isPortalOutlet:!0,_container:null}}function B(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 V(e,n=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 i;return i="string"==typeof n?document.querySelector(n)??document.body:n instanceof Element?n:"__isPortalOutlet"in n?n._container??document.body:n.el??document.body,t.isNixComponent(e)?s(e,i,null):e._render(i,null)}}}var H=n.createInjectionKey("nix:portal-outlet");function U(e){n.provide(H,e)}function W(){return n.inject(H)}function G(r,o){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(l,a){let u=document.createComment(i.ERROR_BOUNDARY);l.insertBefore(u,a);let s,d=null,f=!1,p=!1,m=!1,h=n=>{let r,i=u.parentNode;if(i){try{r="function"!=typeof o||t.isNixComponent(o)?o:o(n)}catch(e){return console.error("[Nix] Error boundary fallback threw while producing the fallback UI:",e),void(d=x(i,a))}e._pushErrorHandler(y);try{d=t.isNixComponent(r)?c(r,i,a):r._render(i,a)}catch(e){console.error("[Nix] Error boundary fallback threw during render:",e),d?.(),d=x(i,a)}finally{e._popErrorHandler()}}},y=e=>{console.error("[Nix] Error boundary fallback threw during a reactive update:",e),d?.(),d=null;let t=u.parentNode;t&&(d=x(t,a))},x=(e,t)=>{let n=document.createElement("div");return n.setAttribute("data-nix-error-boundary","fallback-failed"),n.textContent="[Nix] Error boundary fallback failed to render.",e.insertBefore(n,t),()=>n.remove()};e._pushErrorHandler(e=>{f||(f=!0,p?(d?.(),d=null,h(e)):(s=e,m=!0))});try{if(t.isNixComponent(r)){n._pushComponentContext();try{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}d=r.render()._render(l,a)}finally{n._popComponentContext()}if(!f)try{let e=r.onMount?.(),t=d;d=()=>{try{r.onUnmount?.()}catch{}if("function"==typeof e)try{e()}catch{}t?.()}}catch(e){if(!r.onError)throw e;r.onError(e)}}else d=r._render(l,a)}catch(e){f=!0,d?.(),d=null,s=e,m=!0}finally{e._popErrorHandler(),p=!0}return m&&(d?.(),d=null,h(s)),()=>{d?.(),u.remove()}}}}Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return r}});
@@ -1 +1 @@
1
- import{_popErrorHandler as e,_pushErrorHandler as t,batch as n,effect as r}from"./signals.js";import{_debugComponentMountEnd as i,_debugComponentMountStart as a,_debugComponentUnmount as o,isNixComponent as s}from"./lifecycle.js";import{_captureContextSnapshot as c,_popComponentContext as l,_pushComponentContext as u,_withComponentContext as d,createInjectionKey as f,inject as p,provide as m}from"./context.js";function h(){return{el:null}}var g={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function _(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function v(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function y(e,t,n){let r,s;a(e),u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{i(e),l()}try{let t=e.onMount?.();"function"==typeof t&&(s=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{s?.()}catch{}r(),o(e)}}function b(e,t,n){let r,s;a(e),u();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{i(e),l()}try{let t=e.onMount?.();"function"==typeof t&&(s=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{s?.()}catch{}r(),o(e)}}function x(e,t,n,r){let l,s;a(e);try{d(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)})}finally{i(e)}try{let t=e.onMount?.();"function"==typeof t&&(s=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{s?.()}catch{}l(),o(e)}}function S(e,t,n,r,s){let c,d;a(e),u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}c=e.render()._render(t,n)}finally{i(e),l()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(d=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),s.push(()=>{try{e.onUnmount?.()}catch{}try{d?.()}catch{}c(),o(e)})}function C(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(e){let t,n,r,o,l,i=e.slice(),a=[0],s=e.length;for(t=0;t<s;t++){let s=e[t];if(0!==s){if(n=a[a.length-1],e[n]<s){i[t]=n,a.push(t);continue}for(r=0,o=a.length-1;r<o;)l=r+o>>1,e[a[l]]<s?r=l+1:o=l;s<e[a[r]]&&(r>0&&(i[t]=a[r-1]),a[r]=t)}}for(r=a.length,o=a[r-1];r-- >0;)a[r]=o,o=i[o];return a}var T=new Set,E=!1;function D(e){T.add(e),E||(E=!0,queueMicrotask(()=>{for(let e of T)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}T.clear(),E=!1}))}function O(e,t,o,l){if("function"!=typeof t){if(s(t))S(t,e.parentNode,e,l,o);else if(_(t))o.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let n of t)s(n)?S(n,e.parentNode,e,l,o):_(n)?n._render(e.parentNode,e):null!=n&&!1!==n&&e.parentNode.insertBefore(document.createTextNode(String(n)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let i=null,a=null,u=null,d=[],f=null,p=c(),m=!1,h="",g=!0,N=r(()=>{let r=t();if("string"==typeof r||"number"==typeof r){h=String(r);let t=()=>{m=!1,a&&=(a(),null),i?i.nodeValue=h:(i=document.createTextNode(h),e.parentNode.insertBefore(i,e))};return void(g?(g=!1,t()):m||(m=!0,D(t)))}if(m=!1,g=!1,i&&=(i.parentNode?.removeChild(i),null),a&&=(a(),null),null!=r&&!1!==r)if(_(r))a=r._render(e.parentNode,e);else if(s(r))a=x(r,e.parentNode,e,p);else if(v(r)){u||(u=new Map,f=document.createTextNode(""),e.parentNode.insertBefore(f,e));let t=e.parentNode,o=r.items.map((e,t)=>r.keyFn(e,t)),l=new Set(o),i=!1;if(u.size>0)for(let e of u.keys())if(l.has(e)){i=!0;break}if(!i){if(u.size>0){let t=document.createRange();t.setStartAfter(f),t.setEndBefore(e),t.deleteContents();for(let e of u.values())e.cleanup();u.clear()}if(o.length>0){let l=document.createDocumentFragment();n(()=>{for(let e=0;e<o.length;e++){let t=o[e],n=r.items[e],i=document.createTextNode(""),a=document.createTextNode("");l.appendChild(i),l.appendChild(a);let c=r.renderFn(n,e),d=s(c)?x(c,l,a,p):c._render(l,a);u.has(t)&&console.warn(`[Nix] repeat(): duplicate key "${t}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),u?.set(t,{start:i,end:a,cleanup:d})}}),t.insertBefore(l,e)}return void(d=o)}let a=new Map;for(let e=0;e<o.length;e++)a.set(o[e],e);let c=new Int32Array(o.length),m=!1,h=0;for(let e=0;e<d.length;e++){let t=d[e],n=a.get(t);if(void 0===n){let e=u.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}u.delete(t)}else c[n]=e+1,n>=h?h=n:m=!0}let y=m?w(c):[],v=y.length-1,g=e;for(let e=o.length-1;e>=0;e--){let n=o[e];if(0===c[e]){let o=r.items[e],l=document.createTextNode(""),i=document.createTextNode(""),a=document.createDocumentFragment();a.appendChild(l),a.appendChild(i);let c=r.renderFn(o,e),d=s(c)?x(c,a,i,p):c._render(a,i);u.has(n)&&console.warn(`[Nix] repeat(): duplicate key "${n}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),u.set(n,{start:l,end:i,cleanup:d}),t.insertBefore(a,g),g=l}else{let r=u.get(n);if(m)if(v<0||e!==y[v]){let e=r.start;for(;e;){let n=e===r.end?null:e.nextSibling;if(t.insertBefore(e,g),!n)break;e=n}}else v--;g=r.start}}d=o}else if(Array.isArray(r)){let t=[];for(let n of r)if(s(n))t.push(y(n,e.parentNode,e));else if(_(n))t.push(n._render(e.parentNode,e));else if(null!=n&&!1!==n){let r=document.createTextNode(String(n));e.parentNode.insertBefore(r,e),t.push(()=>r.parentNode?.removeChild(r))}a=()=>t.forEach(e=>e())}else i=document.createTextNode(String(r)),e.parentNode.insertBefore(i,e)});o.push(()=>{if(N(),a&&=(a(),null),i&&=(i.parentNode?.removeChild(i),null),u){for(let e of u.values())e.cleanup();u=null,f=null}})}var k=new Set(["href","src","action","formaction","xlink:href","poster","background","cite","ping","data"]);function A(e){return k.has(e.toLowerCase())}function j(e){let t=e.toLowerCase();return t.startsWith("on")||"srcdoc"===t}var M=/[\u0000-\u001F\u007F-\u009F\u2028\u2029\uFEFF]/g,N=/^(?:javascript|vbscript|livescript|mocha|data):/i,P=/^data:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|vnd\.microsoft\.icon)[;,]/i;function F(e){let t=e.replace(M,"").trim();return N.test(t)?/^data:/i.test(t)&&P.test(t)?e:(console.warn(`[Nix] Blocked attribute URL with unsafe scheme: "${t.slice(0,48)}${t.length>48?"…":""}"`),""):e}function I(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function L(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.lastIndexOf("=");if(-1===o)return{type:"node"};let l=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=o-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let a=r.slice(i,o);if("@"===a[0]){let e=a.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:l}}return{type:"attr",attrName:a,hadOpenQuote:l,url:A(a),executable:j(a)}}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},z=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),B=new Set;function V(e,t,n){let r=e.target,o=e.stopPropagation,l=!1;for(e.stopPropagation=()=>{l=!0,o.call(e)};r&&r!==document;){let o=r[t];if(o){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,o=!0;for(let e of t){let t=R[e];if(void 0!==t&&n.key!==t){o=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){o=!1;break}}if(!o){r=r.parentNode;continue}}}if(o(e),l)break}r=r.parentNode}e.stopPropagation=o}var H=new Map;function U(e,t,n,o){let l=[],i=[],a=Array(t.length),s=-1;for(let e=0;e<t.length;e++)o[e]&&o[e].nodeIndex>s&&(s=o[e].nodeIndex);let u=Array(s+1);if(u[0]=e,s>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=s&&(t=n.nextNode());)u[r++]=t}for(let e=0;e<t.length;e++){let t=o[e];a[e]=t?u[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let s=t[e],u=n[e],c=o[e];if(!c)continue;let d=a[e];if("event"===s.type){let e=c.name,t=u,n=s.modifiers;if(!z.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)};d.addEventListener(e,o,r),l.push(()=>d.removeEventListener(e,o,r))}else{if(!B.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>V(e,t,n);H.set(e,r),document.addEventListener(e,r),B.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;d[r]=t,n.length>0&&(d[o]=n),l.push(()=>{d[r]=null,d[o]=null})}continue}if("attr"===s.type){let e=c.name,t=d;if("ref"===e){u.el=t,l.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,o=null;if("function"==typeof u){let t=!1,i=!1,a=!0,s=r(()=>{i=!!u();let r=()=>{t=!1;let r="show"===e?i:!i;null===o&&(o=n.style.display||""),n.style.display=r?o:"none"};a?(a=!1,r()):t||(t=!0,D(r))});l.push(s)}else("show"===e?u:!u)||(n.style.display="none");continue}(s.executable??j(e))&&console.warn(`[Nix] Dynamic binding on executable attribute "${e}". Use @event for handlers; avoid binding untrusted values here.`);let n=s.url??A(e),o=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let i,a=!1,s=!0,c=r(()=>{i=u();let r=()=>{a=!1;let r=i;if(o)t[e]=r??"";else if(null==r||!1===r)t.removeAttribute(e);else{let o=String(r);t.setAttribute(e,n?F(o):o)}};s?(s=!1,r()):a||(a=!0,D(r))});l.push(c)}else if(o)t[e]=u??"";else if(null!=u&&!1!==u){let r=String(u);t.setAttribute(e,n?F(r):r)}continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),O(p,u,l,i)}return{disposes:l,postMountHooks:i}}function W(e,t){let n=new Uint8Array(e.length),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;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;r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}var G=new WeakMap;function K(e,...t){let n=G.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(L(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=W(e,t);let l,i=Array(t.length).fill(null),a=o.content,s=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),u=0;for(;l=s.nextNode();)if(u++,8===l.nodeType){let e=l.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:u})}}else if(1===l.nodeType){let e=l,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],o=r.name;if(o.startsWith("data-nix-e-")){let t=parseInt(o.slice(11),10);isNaN(t)||(i[t]={nodeIndex:u,name:r.value},e.removeAttribute(o));continue}if(o.startsWith("data-nix-a-")){let t=parseInt(o.slice(11),10);isNaN(t)||(i[t]={nodeIndex:u,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:i},G.set(e,n)}let{contexts:r,tpl:o,pathMap:l}=n;function i(e,n){let i=o.content.cloneNode(!0),{disposes:a,postMountHooks:s}=U(i,r,t,l),u=document.createTextNode(""),c=document.createTextNode("");return e.insertBefore(u,n),e.insertBefore(i,n),e.insertBefore(c,n),s.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=u.nextSibling;for(;e&&e!==c;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}u.parentNode?.removeChild(u),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 q(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 J(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function Y(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(J(r.transitionDuration||"0"),J(r.animationDuration||"0")),l=o>0?o+100:t;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 X(e,t={}){let n=q(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=document.createComment(g.TRANSITION);o.insertBefore(i,l);let a=null,u=null,c=0,d=!0,f=()=>{let e=i.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function p(e){return s(e)?b(e,o,l):e._render(o,l)}let m=(e,r=!1)=>{c++,u&&=(u(),null),a=p(e);let o=f();if(o&&(!d||t.appear)&&!r){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(n.enterFrom,n.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(n.enterFrom),o.classList.add(n.enterTo),await Y(o,t.duration),c===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}d=!1},h=()=>{let e=a;a=null;let r=f();if(!r)return void e?.();let o=++c;u=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await Y(r,t.duration),c===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),u?.(),u=null))})().catch(()=>{})},y=null;if("function"!=typeof e||s(e))m(e);else{let t=e,n=null;y=r(()=>{let e=t(),r=null===n,o=null===e;r&&!o?m(e):!r&&o?h():!r&&!o&&(c++,u?.(),u=null,a?.(),a=null,m(e,!0)),n=e}),d=!1}return()=>{c++,y?.(),a?.(),u?.(),a=null,u=null,i.remove()}}}}function Z(){return{__isPortalOutlet:!0,_container:null}}function Q(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 ee(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 o;return o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,s(e)?y(e,o,null):e._render(o,null)}}}var $=f("nix:portal-outlet");function te(e){m($,e)}function ne(){return p($)}function re(n,r){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,i){let a=document.createComment(g.ERROR_BOUNDARY);o.insertBefore(a,i);let c,d=null,f=!1,p=!1,m=!1,h=e=>{let t=a.parentNode,n="function"!=typeof r||s(r)?r:r(e);d=s(n)?b(n,t,i):n._render(t,i)};t(e=>{f||(f=!0,p?(d?.(),d=null,h(e)):(c=e,m=!0))});try{if(s(n)){u();try{try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}d=n.render()._render(o,i)}finally{l()}if(!f)try{let e=n.onMount?.(),t=d;d=()=>{try{n.onUnmount?.()}catch{}if("function"==typeof e)try{e()}catch{}t?.()}}catch(e){if(!n.onError)throw e;n.onError(e)}}else d=n._render(o,i)}catch(e){f=!0,d?.(),d=null,c=e,m=!0}finally{e(),p=!0}return m&&(d?.(),d=null,h(c)),()=>{d?.(),a.remove()}}}}export{_,Q as a,W as c,j as d,A as f,v as g,g as h,ee as i,K as l,C as m,Z as n,te as o,F as p,ne as r,X as s,re as t,I as u,h as v};
1
+ import{_popErrorHandler as e,_pushErrorHandler as t,batch as n,effect as r}from"./signals.js";import{_debugComponentMountEnd as i,_debugComponentMountStart as a,_debugComponentUnmount as o,isNixComponent as s}from"./lifecycle.js";import{_captureContextSnapshot as c,_popComponentContext as l,_pushComponentContext as u,_withComponentContext as d,createInjectionKey as f,inject as p,provide as m}from"./context.js";function h(){return{el:null}}var g={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function _(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function v(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function y(e,t,n){let r,s;a(e),u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{i(e),l()}try{let t=e.onMount?.();"function"==typeof t&&(s=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{s?.()}catch{}r(),o(e)}}function b(e,t,n){let r,s;a(e),u();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{i(e),l()}try{let t=e.onMount?.();"function"==typeof t&&(s=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{s?.()}catch{}r(),o(e)}}function x(e,t,n,r){let l,u;a(e);try{d(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)})}finally{i(e)}try{let t=e.onMount?.();"function"==typeof t&&(u=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{u?.()}catch{}l(),o(e)}}function S(e,t,n,r,s){let c,d;a(e),u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}c=e.render()._render(t,n)}finally{i(e),l()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(d=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),s.push(()=>{try{e.onUnmount?.()}catch{}try{d?.()}catch{}c(),o(e)})}function C(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(e){let t,n,r,o,l,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,o=a.length-1;r<o;)l=r+o>>1,e[a[l]]<u?r=l+1:o=l;u<e[a[r]]&&(r>0&&(i[t]=a[r-1]),a[r]=t)}}for(r=a.length,o=a[r-1];r-- >0;)a[r]=o,o=i[o];return a}var T=new Set,E=!1;function D(e){T.add(e),E||(E=!0,queueMicrotask(()=>{for(let e of T)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}T.clear(),E=!1}))}function O(e,t,o,l){if("function"!=typeof t){if(s(t))S(t,e.parentNode,e,l,o);else if(_(t))o.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let n of t)s(n)?S(n,e.parentNode,e,l,o):_(n)?n._render(e.parentNode,e):null!=n&&!1!==n&&e.parentNode.insertBefore(document.createTextNode(String(n)),e);else null!=t&&!1!==t&&e.parentNode.insertBefore(document.createTextNode(String(t)),e);return}let i=null,a=null,u=null,d=[],f=null,p=c(),m=!1,h="",g=!0,N=r(()=>{let r=t();if("string"==typeof r||"number"==typeof r){h=String(r);let t=()=>{m=!1,a&&=(a(),null),i?i.nodeValue=h:(i=document.createTextNode(h),e.parentNode.insertBefore(i,e))};return void(g?(g=!1,t()):m||(m=!0,D(t)))}if(m=!1,g=!1,i&&=(i.parentNode?.removeChild(i),null),a&&=(a(),null),null!=r&&!1!==r)if(_(r))a=r._render(e.parentNode,e);else if(s(r))a=x(r,e.parentNode,e,p);else if(v(r)){u||(u=new Map,f=document.createTextNode(""),e.parentNode.insertBefore(f,e));let t=e.parentNode,o=r.items.map((e,t)=>r.keyFn(e,t)),l=new Set(o),i=!1;if(u.size>0)for(let e of u.keys())if(l.has(e)){i=!0;break}if(!i){if(u.size>0){let t=document.createRange();t.setStartAfter(f),t.setEndBefore(e),t.deleteContents();for(let e of u.values())e.cleanup();u.clear()}if(o.length>0){let l=document.createDocumentFragment();n(()=>{for(let e=0;e<o.length;e++){let t=o[e],n=r.items[e],i=document.createTextNode(""),a=document.createTextNode("");l.appendChild(i),l.appendChild(a);let c=r.renderFn(n,e),d=s(c)?x(c,l,a,p):c._render(l,a);u.has(t)&&console.warn(`[Nix] repeat(): duplicate key "${t}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),u?.set(t,{start:i,end:a,cleanup:d})}}),t.insertBefore(l,e)}return void(d=o)}let a=new Map;for(let e=0;e<o.length;e++)a.set(o[e],e);let c=new Int32Array(o.length),m=!1,h=0;for(let e=0;e<d.length;e++){let t=d[e],n=a.get(t);if(void 0===n){let e=u.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}u.delete(t)}else c[n]=e+1,n>=h?h=n:m=!0}let y=m?w(c):[],v=y.length-1,g=e;for(let e=o.length-1;e>=0;e--){let n=o[e];if(0===c[e]){let o=r.items[e],l=document.createTextNode(""),i=document.createTextNode(""),a=document.createDocumentFragment();a.appendChild(l),a.appendChild(i);let c=r.renderFn(o,e),d=s(c)?x(c,a,i,p):c._render(a,i);u.has(n)&&console.warn(`[Nix] repeat(): duplicate key "${n}". Keys must be unique; the previous entry leaks (orphaned nodes + live effects).`),u.set(n,{start:l,end:i,cleanup:d}),t.insertBefore(a,g),g=l}else{let r=u.get(n);if(m)if(v<0||e!==y[v]){let e=r.start;for(;e;){let n=e===r.end?null:e.nextSibling;if(t.insertBefore(e,g),!n)break;e=n}}else v--;g=r.start}}d=o}else if(Array.isArray(r)){let t=[];for(let n of r)if(s(n))t.push(y(n,e.parentNode,e));else if(_(n))t.push(n._render(e.parentNode,e));else if(null!=n&&!1!==n){let r=document.createTextNode(String(n));e.parentNode.insertBefore(r,e),t.push(()=>r.parentNode?.removeChild(r))}a=()=>t.forEach(e=>e())}else i=document.createTextNode(String(r)),e.parentNode.insertBefore(i,e)});o.push(()=>{if(N(),a&&=(a(),null),i&&=(i.parentNode?.removeChild(i),null),u){for(let e of u.values())e.cleanup();u=null,f=null}})}var k=new Set(["href","src","action","formaction","xlink:href","poster","background","cite","ping","data"]);function A(e){return k.has(e.toLowerCase())}function j(e){let t=e.toLowerCase();return t.startsWith("on")||"srcdoc"===t}var M=/[\u0000-\u001F\u007F-\u009F\u2028\u2029\uFEFF]/g,N=/^(?:javascript|vbscript|livescript|mocha|data):/i,P=/^data:image\/(?:png|jpe?g|gif|webp|avif|bmp|x-icon|vnd\.microsoft\.icon)[;,]/i;function F(e){let t=e.replace(M,"").trim();return N.test(t)?/^data:/i.test(t)&&P.test(t)?e:(console.warn(`[Nix] Blocked attribute URL with unsafe scheme: "${t.slice(0,48)}${t.length>48?"…":""}"`),""):e}function I(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function L(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.lastIndexOf("=");if(-1===o)return{type:"node"};let l=r.endsWith('"')||r.endsWith("'")||'"'===r[r.length-1]||"'"===r[r.length-1],i=o-1;for(;i>=0&&/\S/.test(r[i]);)i--;i++;let a=r.slice(i,o);if("@"===a[0]){let e=a.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:l}}return{type:"attr",attrName:a,hadOpenQuote:l,url:A(a),executable:j(a)}}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},z=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),B=new Set;function V(e,t,n){let r=e.target,o=e.stopPropagation,l=!1;for(e.stopPropagation=()=>{l=!0,o.call(e)};r&&r!==document;){let o=r[t];if(o){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,o=!0;for(let e of t){let t=R[e];if(void 0!==t&&n.key!==t){o=!1;break}if(!t&&1===e.length&&n.key.toLowerCase()!==e){o=!1;break}}if(!o){r=r.parentNode;continue}}}if(o(e),l)break}r=r.parentNode}e.stopPropagation=o}var H=new Map;function U(e,t,n,o){let l=[],i=[],a=Array(t.length),u=-1;for(let e=0;e<t.length;e++)o[e]&&o[e].nodeIndex>u&&(u=o[e].nodeIndex);let s=Array(u+1);if(s[0]=e,u>0){let t,n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),r=1;for(;r<=u&&(t=n.nextNode());)s[r++]=t}for(let e=0;e<t.length;e++){let t=o[e];a[e]=t?s[t.nodeIndex]:null}for(let e=0;e<t.length;e++){let u=t[e],s=n[e],c=o[e];if(!c)continue;let d=a[e];if("event"===u.type){let e=c.name,t=s,n=u.modifiers;if(!z.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)};d.addEventListener(e,o,r),l.push(()=>d.removeEventListener(e,o,r))}else{if(!B.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>V(e,t,n);H.set(e,r),document.addEventListener(e,r),B.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;d[r]=t,n.length>0&&(d[o]=n),l.push(()=>{d[r]=null,d[o]=null})}continue}if("attr"===u.type){let e=c.name,t=d;if("ref"===e){s.el=t,l.push(()=>{s.el=null});continue}if("show"===e||"hide"===e){let n=t,o=null;if("function"==typeof s){let t=!1,i=!1,a=!0,u=r(()=>{i=!!s();let r=()=>{t=!1;let r="show"===e?i:!i;null===o&&(o=n.style.display||""),n.style.display=r?o:"none"};a?(a=!1,r()):t||(t=!0,D(r))});l.push(u)}else("show"===e?s:!s)||(n.style.display="none");continue}(u.executable??j(e))&&console.warn(`[Nix] Dynamic binding on executable attribute "${e}". Use @event for handlers; avoid binding untrusted values here.`);let n=u.url??A(e),o=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof s){let i,a=!1,u=!0,c=r(()=>{i=s();let r=()=>{a=!1;let r=i;if(o)t[e]=r??"";else if(null==r||!1===r)t.removeAttribute(e);else{let o=String(r);t.setAttribute(e,n?F(o):o)}};u?(u=!1,r()):a||(a=!0,D(r))});l.push(c)}else if(o)t[e]=s??"";else if(null!=s&&!1!==s){let r=String(s);t.setAttribute(e,n?F(r):r)}continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),O(p,s,l,i)}return{disposes:l,postMountHooks:i}}function W(e,t){let n=new Uint8Array(e.length),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;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;r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}var G=new WeakMap;function K(e,...t){let n=G.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(L(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=W(e,t);let l,i=Array(t.length).fill(null),a=o.content,u=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),s=0;for(;l=u.nextNode();)if(s++,8===l.nodeType){let e=l.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:s})}}else if(1===l.nodeType){let e=l,t=Array.from(e.attributes);for(let n=0;n<t.length;n++){let r=t[n],o=r.name;if(o.startsWith("data-nix-e-")){let t=parseInt(o.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(o));continue}if(o.startsWith("data-nix-a-")){let t=parseInt(o.slice(11),10);isNaN(t)||(i[t]={nodeIndex:s,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:i},G.set(e,n)}let{contexts:r,tpl:o,pathMap:l}=n;function i(e,n){let i=o.content.cloneNode(!0),{disposes:a,postMountHooks:u}=U(i,r,t,l),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 q(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 J(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function Y(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(J(r.transitionDuration||"0"),J(r.animationDuration||"0")),l=o>0?o+100:t;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 X(e,t={}){let n=q(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=document.createComment(g.TRANSITION);o.insertBefore(i,l);let a=null,u=null,c=0,d=!0,f=()=>{let e=i.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function p(e){return s(e)?b(e,o,l):e._render(o,l)}let m=(e,r=!1)=>{c++,u&&=(u(),null),a=p(e);let o=f();if(o&&(!d||t.appear)&&!r){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(n.enterFrom,n.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(n.enterFrom),o.classList.add(n.enterTo),await Y(o,t.duration),c===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}d=!1},h=()=>{let e=a;a=null;let r=f();if(!r)return void e?.();let o=++c;u=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await Y(r,t.duration),c===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),u?.(),u=null))})().catch(()=>{})},y=null;if("function"!=typeof e||s(e))m(e);else{let t=e,n=null;y=r(()=>{let e=t(),r=null===n,o=null===e;r&&!o?m(e):!r&&o?h():!r&&!o&&(c++,u?.(),u=null,a?.(),a=null,m(e,!0)),n=e}),d=!1}return()=>{c++,y?.(),a?.(),u?.(),a=null,u=null,i.remove()}}}}function Z(){return{__isPortalOutlet:!0,_container:null}}function Q(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 ee(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 o;return o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,s(e)?y(e,o,null):e._render(o,null)}}}var $=f("nix:portal-outlet");function te(e){m($,e)}function ne(){return p($)}function re(n,r){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,i){let a=document.createComment(g.ERROR_BOUNDARY);o.insertBefore(a,i);let c,d=null,f=!1,p=!1,m=!1,h=n=>{let o,l=a.parentNode;if(l){try{o="function"!=typeof r||s(r)?r:r(n)}catch(e){return console.error("[Nix] Error boundary fallback threw while producing the fallback UI:",e),void(d=v(l,i))}t(y);try{d=s(o)?b(o,l,i):o._render(l,i)}catch(e){console.error("[Nix] Error boundary fallback threw during render:",e),d?.(),d=v(l,i)}finally{e()}}},y=e=>{console.error("[Nix] Error boundary fallback threw during a reactive update:",e),d?.(),d=null;let t=a.parentNode;t&&(d=v(t,i))},v=(e,t)=>{let n=document.createElement("div");return n.setAttribute("data-nix-error-boundary","fallback-failed"),n.textContent="[Nix] Error boundary fallback failed to render.",e.insertBefore(n,t),()=>n.remove()};t(e=>{f||(f=!0,p?(d?.(),d=null,h(e)):(c=e,m=!0))});try{if(s(n)){u();try{try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}d=n.render()._render(o,i)}finally{l()}if(!f)try{let e=n.onMount?.(),t=d;d=()=>{try{n.onUnmount?.()}catch{}if("function"==typeof e)try{e()}catch{}t?.()}}catch(e){if(!n.onError)throw e;n.onError(e)}}else d=n._render(o,i)}catch(e){f=!0,d?.(),d=null,c=e,m=!0}finally{e(),p=!0}return m&&(d?.(),d=null,h(c)),()=>{d?.(),a.remove()}}}}export{_,Q as a,W as c,j as d,A as f,v as g,g as h,ee as i,K as l,C as m,Z as n,te as o,F as p,ne as r,X as s,re as t,I as u,h as v};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deijose/nix-js",
3
- "version": "2.5.2",
3
+ "version": "2.5.4",
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",
@@ -1,116 +0,0 @@
1
- import type { NixComponent } from "./lifecycle";
2
- export interface NixTemplate {
3
- readonly __isNixTemplate: true;
4
- /** Mounts the template into a container element (public / root API). */
5
- mount(container: Element | string): NixMountHandle;
6
- /** @internal Renders before `before` node (or appends to `parent`). Returns cleanup. */
7
- _render(parent: Node, before: Node | null): () => void;
8
- }
9
- export interface NixMountHandle {
10
- unmount(): void;
11
- }
12
- /** Direct reference to a DOM element, assigned on mount and cleared on unmount. */
13
- export interface NixRef<T extends Element = Element> {
14
- el: T | null;
15
- }
16
- /** Creates an empty `NixRef`. Use as `ref` attribute value in templates. */
17
- export declare function ref<T extends Element = Element>(): NixRef<T>;
18
- /** Toggles element visibility via `display: none` without unmounting. */
19
- export declare function showWhen(el: HTMLElement, condition: boolean): void;
20
- /** Keyed list result for efficient DOM diffing via `repeat()`. */
21
- export interface KeyedList<T = unknown> {
22
- readonly __isKeyedList: true;
23
- readonly items: T[];
24
- readonly keyFn: (item: T, index: number) => string | number;
25
- readonly renderFn: (item: T, index: number) => NixTemplate | NixComponent;
26
- }
27
- /**
28
- * Creates a keyed list for efficient DOM reconciliation.
29
- * Use instead of `.map()` when the list changes frequently.
30
- */
31
- export declare function repeat<T>(items: T[], keyFn: (item: T, index: number) => string | number, renderFn: (item: T, index: number) => NixTemplate | NixComponent): KeyedList<T>;
32
- /**
33
- * Renders `content` into `target` instead of the current tree position.
34
- * Useful for modals, tooltips, and overlays that must escape overflow clipping.
35
- * Returns a NixTemplate — works inside reactive conditionals.
36
- *
37
- * @param content Template or component to render.
38
- * @param target CSS selector, Element, PortalOutlet, or NixRef. Defaults to `document.body`.
39
- */
40
- /** Opaque token for a named portal target. */
41
- export interface PortalOutlet {
42
- readonly __isPortalOutlet: true;
43
- /** @internal */
44
- _container: Element | null;
45
- }
46
- /** Creates a PortalOutlet token for decoupled portal targeting. */
47
- export declare function createPortalOutlet(): PortalOutlet;
48
- /** Declares the DOM anchor for a PortalOutlet inside a template. */
49
- export declare function portalOutlet(outlet: PortalOutlet): NixTemplate;
50
- export declare function portal(content: NixTemplate | NixComponent, target?: Element | string | PortalOutlet | NixRef<Element>): NixTemplate;
51
- /** Provides a PortalOutlet to descendant components via dependency injection. */
52
- export declare function provideOutlet(outlet: PortalOutlet): void;
53
- /** Injects the nearest PortalOutlet provided by an ancestor. */
54
- export declare function injectOutlet(): PortalOutlet | undefined;
55
- /** Fallback: a static template/component, or a factory receiving the error. */
56
- export type ErrorFallback = NixTemplate | NixComponent | ((err: unknown) => NixTemplate | NixComponent);
57
- /**
58
- * Wraps `content` in an error boundary. If rendering or a reactive update
59
- * throws, the boundary tears down the broken subtree and renders `fallback`.
60
- */
61
- export declare function createErrorBoundary(content: NixTemplate | NixComponent, fallback: ErrorFallback): NixTemplate;
62
- /**
63
- * Options for `transition()`. All class-name overrides are optional — by
64
- * default they are derived from `name` (default `"nix"`).
65
- *
66
- * | phase | from class | active class | to class |
67
- * |--------------|-------------------|---------------------|-----------------|
68
- * | enter | `{n}-enter-from` | `{n}-enter-active` | `{n}-enter-to` |
69
- * | leave | `{n}-leave-from` | `{n}-leave-active` | `{n}-leave-to` |
70
- */
71
- export interface TransitionOptions {
72
- /**
73
- * Prefix for all generated CSS classes. Default `"nix"`.
74
- * e.g. `name: "fade"` generates `.fade-enter-from`, `.fade-leave-to`, …
75
- */
76
- name?: string;
77
- /** Override the enter-from class individually. */
78
- enterFrom?: string;
79
- /** Override the enter-active class individually. */
80
- enterActive?: string;
81
- /** Override the enter-to class individually. */
82
- enterTo?: string;
83
- /** Override the leave-from class individually. */
84
- leaveFrom?: string;
85
- /** Override the leave-active class individually. */
86
- leaveActive?: string;
87
- /** Override the leave-to class individually. */
88
- leaveTo?: string;
89
- /**
90
- * When `true` the enter transition also plays on the very first render
91
- * (similar to Vue's `appear`). Default `false`.
92
- */
93
- appear?: boolean;
94
- /**
95
- * Fallback duration in **milliseconds** used when no `transition-duration`
96
- * or `animation-duration` is found on the element via `getComputedStyle`.
97
- */
98
- duration?: number;
99
- /** Called synchronously right before the enter classes are added. */
100
- onBeforeEnter?: (el: Element) => void;
101
- /** Called after the enter transition has fully completed. */
102
- onAfterEnter?: (el: Element) => void;
103
- /** Called synchronously right before the leave classes are added. */
104
- onBeforeLeave?: (el: Element) => void;
105
- /** Called after the leave transition has fully completed and the DOM is removed. */
106
- onAfterLeave?: (el: Element) => void;
107
- }
108
- /** Content that can be wrapped with `transition()`. */
109
- export type TransitionContent = NixTemplate | NixComponent | (() => NixTemplate | NixComponent | null);
110
- /**
111
- * Wraps content with CSS class-based enter/leave transitions.
112
- * Static content plays enter on mount (only with `appear: true`).
113
- * Reactive `() => Template | null` auto-animates enter/leave on toggle.
114
- */
115
- export declare function transition(content: TransitionContent, options?: TransitionOptions): NixTemplate;
116
- export declare function html(strings: TemplateStringsArray, ...values: unknown[]): NixTemplate;