@deijose/nix-js 1.9.4 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/lib/async.cjs +3 -3
- package/dist/lib/async.js +3 -3
- package/dist/lib/component.cjs +1 -0
- package/dist/lib/component.js +1 -0
- package/dist/lib/context.cjs +1 -0
- package/dist/lib/context.js +1 -0
- package/dist/lib/lifecycle.cjs +1 -0
- package/dist/lib/lifecycle.js +1 -0
- package/dist/lib/nix-js.cjs +1 -1
- package/dist/lib/nix-js.js +1 -1
- package/dist/lib/router.cjs +3 -3
- package/dist/lib/router.js +4 -4
- package/dist/lib/template.cjs +1 -1
- package/dist/lib/template.js +1 -1
- package/dist/lib/template2.cjs +1 -1
- package/dist/lib/template2.js +1 -1
- package/package.json +16 -1
package/README.md
CHANGED
|
@@ -33,6 +33,9 @@ import { createStore } from "@deijose/nix-js/store";
|
|
|
33
33
|
import { createForm } from "@deijose/nix-js/form";
|
|
34
34
|
import { suspend, lazy } from "@deijose/nix-js/async";
|
|
35
35
|
import { html, repeat, transition } from "@deijose/nix-js/template";
|
|
36
|
+
import { mount } from "@deijose/nix-js/component";
|
|
37
|
+
import { NixComponent } from "@deijose/nix-js/lifecycle";
|
|
38
|
+
import { provide, inject, createInjectionKey } from "@deijose/nix-js/context";
|
|
36
39
|
```
|
|
37
40
|
|
|
38
41
|
This is optional: `import { ... } from "@deijose/nix-js"` remains fully supported.
|
package/dist/lib/async.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs");function
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./lifecycle.cjs");function r(){return t.l`
|
|
2
2
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
3
3
|
<span class="nix-spinner" style="
|
|
4
4
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -8,8 +8,8 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=requi
|
|
|
8
8
|
Loading…
|
|
9
9
|
</span>
|
|
10
10
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
11
|
-
`}function
|
|
11
|
+
`}function i(e){return t.l`
|
|
12
12
|
<span style="color:#f87171;font-size:13px">
|
|
13
13
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
14
14
|
</span>
|
|
15
|
-
`}var
|
|
15
|
+
`}var a=new Map,o=3e5,s=null,c=o;function l(){null===s&&(s=setInterval(()=>{let e=Date.now();for(let[t,s]of a)s.subscribers<=0&&e-s.fetchedAt>c&&a.delete(t);0===a.size&&null!==s&&(clearInterval(s),s=null)},6e4))}function u(e){let t=a.get(e);if(t&&t.fetchedAt>0)return t}function d(e,t){let s=a.get(e);a.set(e,{data:t,fetchedAt:Date.now(),subscribers:s?.subscribers??0}),l()}function f(e){let t=a.get(e);t?t.subscribers++:a.set(e,{fetchedAt:0,subscribers:1})}function p(e){let t=a.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function m(e,t){let s=a.get(e);return!!s&&Date.now()-s.fetchedAt<t}function h(s,l,o={}){let{fallback:c,errorFallback:h,resetOnRefresh:b=!1,invalidate:g,cacheKey:v,staleTime:x=0}=o,y=c??r(),_=h??i;class w extends n.NixComponent{_state;_disposeWatcher;constructor(){super();let t=v?u(v):void 0;this._state=e.signal(t&&void 0!==t.data?{status:"resolved",data:t.data}:{status:"pending"})}onMount(){v&&f(v);let t=v?u(v):void 0;if(t&&m(v,x)||(t?this._fetch():this._run()),g){let t=!0;this._disposeWatcher=e.effect(()=>{g.value,t?t=!1:(v&&a.delete(v),this._run())})}return()=>{this._disposeWatcher?.(),v&&p(v)}}_run(){(b||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){s().then(e=>{v&&d(v,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return t.l`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?y:"error"===e.status?_(e.error):l(e.data)}}</div>`}}return new w}function g(e,t){let s=null;return()=>s?new s:h(async()=>(s=(await e()).default,s),e=>new e,{fallback:t})}exports.lazy=g,exports.suspend=h;
|
package/dist/lib/async.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{effect as e,signal as t}from"./signals.js";import{
|
|
1
|
+
import{effect as e,signal as t}from"./signals.js";import{l as n}from"./template2.js";import{NixComponent as r}from"./lifecycle.js";function i(){return n`
|
|
2
2
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
3
3
|
<span class="nix-spinner" style="
|
|
4
4
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -8,8 +8,8 @@ import{effect as e,signal as t}from"./signals.js";import{_ as n,l as r}from"./te
|
|
|
8
8
|
Loading…
|
|
9
9
|
</span>
|
|
10
10
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
11
|
-
`}function a(e){return
|
|
11
|
+
`}function a(e){return n`
|
|
12
12
|
<span style="color:#f87171;font-size:13px">
|
|
13
13
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
14
14
|
</span>
|
|
15
|
-
`}var o=new Map,s=3e5,c=null,l=s;function u(){null===c&&(c=setInterval(()=>{let e=Date.now();for(let[t,s]of o)s.subscribers<=0&&e-s.fetchedAt>l&&o.delete(t);0===o.size&&null!==c&&(clearInterval(c),c=null)},6e4))}function d(e){let t=o.get(e);if(t&&t.fetchedAt>0)return t}function f(e,t){let s=o.get(e);o.set(e,{data:t,fetchedAt:Date.now(),subscribers:s?.subscribers??0}),u()}function p(e){let t=o.get(e);t?t.subscribers++:o.set(e,{fetchedAt:0,subscribers:1})}function m(e){let t=o.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function h(e,t){let s=o.get(e);return!!s&&Date.now()-s.fetchedAt<t}function g(s,l,
|
|
15
|
+
`}var o=new Map,s=3e5,c=null,l=s;function u(){null===c&&(c=setInterval(()=>{let e=Date.now();for(let[t,s]of o)s.subscribers<=0&&e-s.fetchedAt>l&&o.delete(t);0===o.size&&null!==c&&(clearInterval(c),c=null)},6e4))}function d(e){let t=o.get(e);if(t&&t.fetchedAt>0)return t}function f(e,t){let s=o.get(e);o.set(e,{data:t,fetchedAt:Date.now(),subscribers:s?.subscribers??0}),u()}function p(e){let t=o.get(e);t?t.subscribers++:o.set(e,{fetchedAt:0,subscribers:1})}function m(e){let t=o.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function h(e,t){let s=o.get(e);return!!s&&Date.now()-s.fetchedAt<t}function g(s,l,c={}){let{fallback:u,errorFallback:b,resetOnRefresh:g=!1,invalidate:_,cacheKey:v,staleTime:x=0}=c,y=u??i(),w=b??a;return new class extends r{_state;_disposeWatcher;constructor(){super();let e=v?d(v):void 0;this._state=t(e&&void 0!==e.data?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){v&&p(v);let t=v?d(v):void 0;if(t&&h(v,x)||(t?this._fetch():this._run()),_){let t=!0;this._disposeWatcher=e(()=>{_.value,t?t=!1:(v&&o.delete(v),this._run())})}return()=>{this._disposeWatcher?.(),v&&m(v)}}_run(){(g||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){s().then(e=>{v&&f(v,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return n`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?y:"error"===e.status?w(e.error):l(e.data)}}</div>`}}}function _(e,t){let s=null;return()=>s?new s:g(async()=>(s=(await e()).default,s),e=>new e,{fallback:t})}export{_ as lazy,g as suspend};
|
|
@@ -0,0 +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 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 e,c,l=r(u);t._pushComponentContext();try{i?.router&&t.provide(n.RouterKey,i.router);try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(l,null)}finally{t._popComponentContext()}try{let t=o.onMount?.();"function"==typeof t&&(c=t)}catch(t){if(!o.onError)throw t;o.onError(t)}return{unmount(){try{o.onUnmount?.()}catch{}try{c?.()}catch{}e()}}}if(!i?.router)return o.mount(u);let c,l=r(u);t._pushComponentContext();try{t.provide(n.RouterKey,i.router),c=o._render(l,null)}finally{t._popComponentContext()}return{unmount(){c()}}}exports.mount=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isNixComponent as e}from"./lifecycle.js";import{_popComponentContext as t,_pushComponentContext as n,provide as r}from"./context.js";import{RouterKey as i}from"./router.js";function a(r){let t="string"==typeof r?document.querySelector(r):r;if(!t)throw Error(`[Nix] mount: container not found: ${r}`);return t}function o(o,u,c){if(e(o)){let e,f,m=a(u);n();try{c?.router&&r(i,c.router);try{o.onInit?.()}catch(r){if(!o.onError)throw r;o.onError(r)}e=o.render()._render(m,null)}finally{t()}try{let r=o.onMount?.();"function"==typeof r&&(f=r)}catch(r){if(!o.onError)throw r;o.onError(r)}return{unmount(){try{o.onUnmount?.()}catch{}try{f?.()}catch{}e()}}}if(!c?.router)return o.mount(u);let f,m=a(u);n();try{r(i,c.router),f=o._render(m,null)}finally{t()}return{unmount(){f()}}}export{o as mount};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(t){return Symbol(t)}Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=[];function n(){return[...t]}function r(){t.push(new Map)}function i(){t.pop()}function a(e,n){let o=t.splice(0);e.forEach(e=>t.push(e)),t.push(new Map);try{return n()}finally{t.splice(0),o.forEach(e=>t.push(e))}}function o(e,n){let o=t[t.length-1];if(!o)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");o.set(e,n)}function s(e,n){for(let n=t.length-1;n>=0;n--)if(t[n].has(e))return t[n].get(e);return n}exports._captureContextSnapshot=n,exports._popComponentContext=i,exports._pushComponentContext=r,exports._withComponentContext=a,exports.createInjectionKey=e,exports.inject=s,exports.provide=o;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(t){return Symbol(t)}var t=[];function n(){return[...t]}function r(){t.push(new Map)}function i(){t.pop()}function a(n,e){let o=t.splice(0);n.forEach(n=>t.push(n)),t.push(new Map);try{return e()}finally{t.splice(0),o.forEach(n=>t.push(n))}}function o(n,e){let o=t[t.length-1];if(!o)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");o.set(n,e)}function s(n,e){for(let e=t.length-1;e>=0;e--)if(t[e].has(n))return t[e].get(n);return e}export{n as _captureContextSnapshot,i as _popComponentContext,r as _pushComponentContext,a as _withComponentContext,e as createInjectionKey,s as inject,o as provide};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=class{__isNixComponent=!0;children;_slots=new Map;setChildren(t){return this.children=t,this}setSlot(t,e){return this._slots.set(t,e),this}slot(t){return this._slots.get(t)}};function t(t){return"object"==typeof t&&!!t&&!0===t.__isNixComponent}exports.NixComponent=e,exports.isNixComponent=t;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class{__isNixComponent=!0;children;_slots=new Map;setChildren(t){return this.children=t,this}setSlot(t,s){return this._slots.set(t,s),this}slot(t){return this._slots.get(t)}};function t(t){return"object"==typeof t&&!!t&&!0===t.__isNixComponent}export{e as NixComponent,t as isNixComponent};
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs"),n=require("./
|
|
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"),i=require("./router.cjs"),a=require("./component.cjs"),o=require("./store.cjs"),s=require("./async.cjs"),c=require("./form.cjs");exports.Link=i.Link,exports.NixComponent=n.NixComponent,exports.RouterKey=i.RouterKey,exports.RouterView=i.RouterView,exports.Signal=e.Signal,exports.batch=e.batch,exports.computed=e.computed,exports.createErrorBoundary=t.t,exports.createForm=c.createForm,exports.createInjectionKey=r.createInjectionKey,exports.createPortalOutlet=t.n,exports.createRouter=i.createRouter,exports.createStore=o.createStore,exports.createValidator=c.createValidator,exports.effect=e.effect,exports.email=c.email,exports.extendValidators=c.extendValidators,exports.html=t.l,exports.inject=r.inject,exports.injectOutlet=t.r,exports.lazy=s.lazy,exports.max=c.max,exports.maxLength=c.maxLength,exports.min=c.min,exports.minLength=c.minLength,exports.mount=a.mount,exports.nextTick=e.nextTick,exports.pattern=c.pattern,exports.portal=t.i,exports.portalOutlet=t.a,exports.provide=r.provide,exports.provideOutlet=t.o,exports.ref=t.h,exports.repeat=t.d,exports.required=c.required,exports.showWhen=t.u,exports.signal=e.signal,exports.suspend=s.suspend,exports.transition=t.s,exports.untrack=e.untrack,exports.useField=c.useField,exports.useFieldArray=c.useFieldArray,exports.useRouter=i.useRouter,exports.validators=c.validators,exports.watch=e.watch;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Signal as e,batch as t,computed as n,effect as r,nextTick as i,signal as a,untrack as o,watch as s}from"./signals.js";import{
|
|
1
|
+
import{Signal as e,batch as t,computed as n,effect as r,nextTick as i,signal as a,untrack as o,watch as s}from"./signals.js";import{a as c,d as l,h as u,i as d,l as f,n as p,o as m,r as h,s as g,t as _,u as v}from"./template2.js";import{NixComponent as y}from"./lifecycle.js";import{createInjectionKey as b,inject as x,provide as S}from"./context.js";import{Link as C,RouterKey as w,RouterView as T,createRouter as E,useRouter as D}from"./router.js";import{mount as O}from"./component.js";import{createStore as k}from"./store.js";import{lazy as A,suspend as j}from"./async.js";import{createForm as M,createValidator as N,email as P,extendValidators as F,max as I,maxLength as L,min as R,minLength as z,pattern as B,required as V,useField as H,useFieldArray as U,validators as W}from"./form.js";export{C as Link,y as NixComponent,w as RouterKey,T as RouterView,e as Signal,t as batch,n as computed,_ as createErrorBoundary,M as createForm,b as createInjectionKey,p as createPortalOutlet,E as createRouter,k as createStore,N as createValidator,r as effect,P as email,F as extendValidators,f as html,x as inject,h as injectOutlet,A as lazy,I as max,L as maxLength,R as min,z as minLength,O as mount,i as nextTick,B as pattern,d as portal,c as portalOutlet,S as provide,m as provideOutlet,u as ref,l as repeat,V as required,v as showWhen,a as signal,j as suspend,g as transition,o as untrack,H as useField,U as useFieldArray,D as useRouter,W as validators,s as watch};
|
package/dist/lib/router.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./signals.cjs"),t=require("./template2.cjs");var
|
|
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";function c(){if(!a)throw Error("[Nix] No active router. Call createRouter() first.");return a}function l(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function u(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 d(e,t){let r=e&&"object"==typeof e?{...e}:{};return r[s]={left:t.left,top:t.top},r}function f(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function p(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 m(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 h(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function g(e,t="",r=[]){let n=[];for(let o of e){let e=h(t,o.path),i=[...r,o.component],a=m(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(...g(o.children,e,i))}return n}function _(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 v(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function y(e,t){let r,n={},o=-1;for(let i of t){let t=_(e,i);if(null===t)continue;let a=v(i);a>o&&(r=i,n=t,o=a)}return r?{route:r,params:n}:void 0}function b(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function x(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return b(new URL(t,window.location.origin).pathname)}catch{return b(t)}}function S(t,r){let n=null==r?.base?x():b(r.base),i=r?.mode??"history",s="hash"===i,c=r?.scrollBehavior,h=new Map,m=!1;function v(e){return e?e.startsWith("/")?e:"/"+e:"/"}function w(e){let t=v(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":v(e)}return t}function _(){return s?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 k(e,t){let r=function(e){let t=v(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+p(t);return s?"#"+r:r}function S(e,t){return v(e)+p(t)}let E=_(),R=E.pathname,j=f(E.search),W=g(t),q=new Map;for(let e of W)e.name&&(q.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),q.set(e.name,e));let O=y(R,W),$=e.signal(R),C=e.signal(O?.params??{}),N=e.signal(j);function L(e){window.scrollTo(e.left,e.top)}function M(e,t,r){if(c){let n=c(e,t,r);if(!1===n||null==n)return;return void L(n)}L(r??{left:0,top:0})}s?h.set(S(R,j),l()):history.replaceState(d(history.state,l()),"");let P=[],T=[],U=0;function B(e,t,r,n,o){let i=[...P];r&&i.push(r);let a=++U;if(0===i.length)return void n();let l=0;!function r(u){if(a!==U)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?n():X(u));if(l>=i.length)return void n();let s=i[l++](e,t);s instanceof Promise?s.then(r):r(s)}(void 0)}let A=!1;function I(e,t){let r=e.indexOf("?"),n=v((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:f(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 Q(e,t){return"string"==typeof e?I(e,t):I(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??{}})}o&&=(o(),null);let D=(e,t,r,n)=>{let o=$.value,i={...N.value},a=y(e,W);B(e,o,a?.route.beforeEnter,()=>{C.value=a?.params??{},N.value=t,$.value=e,M(e,o,r);for(let t of T)try{t(e,o)}catch{}},()=>n(o,i))};if(s){let e=()=>{if(m)return void(m=!1);let e=_(),t=f(e.search),r=h.get(S(e.pathname,t))??null;D(e.pathname,t,r,(e,t)=>{m=!0,window.location.hash=k(e,t).slice(1),queueMicrotask(()=>{m=!1})})};window.addEventListener("hashchange",e),o=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=_(),r=f(t.search),n=u(e.state??history.state);D(t.pathname,r,n,(e,t)=>{history.pushState(d({},l()),"",k(e,t))})};window.addEventListener("popstate",e),o=()=>window.removeEventListener("popstate",e)}function K(e,t,r,n,o,i){i||function(e,t){let r=l();s?h.set(S(e,t),r):history.replaceState(d(history.state,r),"")}(r,n),C.value=o?.params??{},N.value=t,$.value=e;let a=k(e,t);if(s)h.set(S(e,t),{left:0,top:0}),i?history.replaceState(history.state,"",a):(m=!0,window.location.hash=a.slice(1),queueMicrotask(()=>{m=!1}));else{let e=d({},{left:0,top:0});i?history.replaceState(e,"",a):history.pushState(e,"",a)}M(e,r,null);for(let t of T)try{t(e,r)}catch{}}function X(e,t){A=!0;let{pathname:r,stringQuery:n}=Q(e,t),o=$.value,i={...N.value},a=y(r,W);B(r,o,a?.route.beforeEnter,()=>K(r,n,o,i,a,!1))}let Y={current:$,params:C,query:N,base:n||"/",navigate:X,replace:function(e,t){A=!0;let{pathname:r,stringQuery:n}=Q(e,t),o=$.value,i={...N.value},a=y(r,W);B(r,o,a?.route.beforeEnter,()=>K(r,n,o,i,a,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=$.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=y(e,W);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return P.push(e),()=>{let t=P.indexOf(e);-1!==t&&P.splice(t,1)}},afterEach:function(e){return T.push(e),()=>{let t=T.indexOf(e);-1!==t&&T.splice(t,1)}},routes:t,_flat:W,_guards:P,_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=Y,queueMicrotask(()=>{A||B(R,"",y(R,W)?.route.beforeEnter,()=>{},()=>{let e=k("/",{});s?(h.set(S("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(d({},{left:0,top:0}),"",e);let t=y("/",W);$.value="/",C.value=t?.params??{},N.value={},M("/",R,null)})}),Y}function C(){return r.inject(i)||c()}function w(){o&&=(o(),null),a=null}var T=class extends n.NixComponent{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return t.l`<div class="router-view">${()=>{let r=C(),n=y(r.current.value,r._flat);return n?e>=n.route.chain.length?t.l`<span></span>`:n.route.chain[e]():t.l`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${r.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
3
|
+
</div>`}}</div>`}},E=class extends n.NixComponent{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,r=this._label,n=C(),o=e.startsWith("/")?e:"/"+e,i=(n._base?n._base+o:o).replace(/\/+/g,"/");return t.l`<a
|
|
4
4
|
href=${"hash"===n._mode?"#"+i:i}
|
|
5
5
|
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"}
|
|
6
6
|
@click=${t=>{t.preventDefault(),n.navigate(e)}}
|
|
7
|
-
>${r}</a>`}};exports.Link=
|
|
7
|
+
>${r}</a>`}};exports.Link=E,exports.RouterKey=i,exports.RouterView=T,exports._resetRouter=w,exports.createRouter=S,exports.useRouter=C;
|
package/dist/lib/router.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{signal as e}from"./signals.js";import{
|
|
2
|
-
404 — Route not found: <strong>${
|
|
3
|
-
</div>`}}</div>`}},D=class extends
|
|
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";function l(){if(!o)throw Error("[Nix] No active router. Call createRouter() first.");return o}function u(){return{left:window.scrollX??window.pageXOffset??0,top:window.scrollY??window.pageYOffset??0}}function d(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 f(e,t){let r=e&&"object"==typeof e?{...e}:{};return r[c]={left:t.left,top:t.top},r}function p(e){let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t}function m(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 h(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 g(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function _(e,t="",r=[]){let n=[];for(let o of e){let e=g(t,o.path),a=[...r,o.component],i=h(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(..._(o.children,e,a))}return n}function v(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 y(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function b(e,t){let r,n={},o=-1;for(let a of t){let t=v(e,a);if(null===t)continue;let i=y(a);i>o&&(r=a,n=t,o=i)}return r?{route:r,params:n}:void 0}function x(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function S(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return x(new URL(t,window.location.origin).pathname)}catch{return x(t)}}function C(t,r){let n=null==r?.base?S():x(r.base),a=r?.mode??"history",i="hash"===a,l=r?.scrollBehavior,c=new Map,h=!1;function g(e){return e?e.startsWith("/")?e:"/"+e:"/"}function v(e){let t=g(e||"/");if(n&&t.startsWith(n)){let e=t.slice(n.length);return""===e?"/":g(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 y(e,t){let r=function(e){let t=g(e);return n?(n+t).replace(/\/+/g,"/")||"/":t}(e)+m(t);return i?"#"+r:r}function k(e,t){return g(e)+m(t)}let E=w(),R=E.pathname,j=p(E.search),W=_(t),$=new Map;for(let e of W)e.name&&($.has(e.name)&&console.warn(`[Nix Router] Duplicate route name: "${e.name}"`),$.set(e.name,e));let O=b(R,W),L=e(R),N=e(O?.params??{}),q=e(j);function C(e){window.scrollTo(e.left,e.top)}function M(e,t,r){if(l){let n=l(e,t,r);if(!1===n||null==n)return;return void C(n)}C(r??{left:0,top:0})}i?c.set(k(R,j),u()):history.replaceState(f(history.state,u()),"");let U=[],B=[],D=0;function P(e,t,r,n,o){let a=[...U];r&&a.push(r);let i=++D;if(0===a.length)return void n();let l=0;!function r(u){if(i!==D)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?n():X(u));if(l>=a.length)return void n();let s=a[l++](e,t);s instanceof Promise?s.then(r):r(s)}(void 0)}let T=!1;function A(e,t){let r=e.indexOf("?"),n=g((-1===r?e:e.slice(0,r))||"/"),o=-1===r?{}:p(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 I(e,t){return"string"==typeof e?A(e,t):A(function(e){let t=$.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??{}})}s&&=(s(),null);let Q=(e,t,r,n)=>{let o=L.value,a={...q.value},i=b(e,W);P(e,o,i?.route.beforeEnter,()=>{N.value=i?.params??{},q.value=t,L.value=e,M(e,o,r);for(let t of B)try{t(e,o)}catch{}},()=>n(o,a))};if(i){let e=()=>{if(h)return void(h=!1);let e=w(),t=p(e.search),r=c.get(k(e.pathname,t))??null;Q(e.pathname,t,r,(e,t)=>{h=!0,window.location.hash=y(e,t).slice(1),queueMicrotask(()=>{h=!1})})};window.addEventListener("hashchange",e),s=()=>window.removeEventListener("hashchange",e)}else{let e=e=>{let t=w(),r=p(t.search),n=d(e.state??history.state);Q(t.pathname,r,n,(e,t)=>{history.pushState(f({},u()),"",y(e,t))})};window.addEventListener("popstate",e),s=()=>window.removeEventListener("popstate",e)}function K(e,t,r,n,o,a){a||function(e,t){let r=u();i?c.set(k(e,t),r):history.replaceState(f(history.state,r),"")}(r,n),N.value=o?.params??{},q.value=t,L.value=e;let l=y(e,t);if(i)c.set(k(e,t),{left:0,top:0}),a?history.replaceState(history.state,"",l):(h=!0,window.location.hash=l.slice(1),queueMicrotask(()=>{h=!1}));else{let e=f({},{left:0,top:0});a?history.replaceState(e,"",l):history.pushState(e,"",l)}M(e,r,null);for(let t of B)try{t(e,r)}catch{}}function X(e,t){T=!0;let{pathname:r,stringQuery:n}=I(e,t),o=L.value,a={...q.value},i=b(r,W);P(r,o,i?.route.beforeEnter,()=>K(r,n,o,a,i,!1))}let Y={current:L,params:N,query:q,base:n||"/",navigate:X,replace:function(e,t){T=!0;let{pathname:r,stringQuery:n}=I(e,t),o=L.value,a={...q.value},i=b(r,W);P(r,o,i?.route.beforeEnter,()=>K(r,n,o,a,i,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let r=L.value;return t?r===e:r===e||r.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(e){let t=b(e,W);return t?{matched:!0,params:t.params,route:t.route.record}:{matched:!1,params:{},route:void 0}},beforeEach:function(e){return U.push(e),()=>{let t=U.indexOf(e);-1!==t&&U.splice(t,1)}},afterEach:function(e){return B.push(e),()=>{let t=B.indexOf(e);-1!==t&&B.splice(t,1)}},routes:t,_flat:W,_guards:U,_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=Y,queueMicrotask(()=>{T||P(R,"",b(R,W)?.route.beforeEnter,()=>{},()=>{let e=y("/",{});i?(c.set(k("/",{}),{left:0,top:0}),history.replaceState(history.state,"",e)):history.replaceState(f({},{left:0,top:0}),"",e);let t=b("/",W);L.value="/",N.value=t?.params??{},q.value={},M("/",R,null)})}),Y}function w(){return i(a)||l()}function T(){s&&=(s(),null),o=null}var E=class extends n{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return t`<div class="router-view">${()=>{let r=w(),n=b(r.current.value,r._flat);return n?e>=n.route.chain.length?t`<span></span>`:n.route.chain[e]():t`<div style="color:#f87171;padding:16px 0">
|
|
2
|
+
404 — Route not found: <strong>${r.current.value}</strong>
|
|
3
|
+
</div>`}}</div>`}},D=class extends n{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,r=this._label,n=w(),o=e.startsWith("/")?e:"/"+e,a=(n._base?n._base+o:o).replace(/\/+/g,"/");return t`<a
|
|
4
4
|
href=${"hash"===n._mode?"#"+a:a}
|
|
5
5
|
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"}
|
|
6
6
|
@click=${t=>{t.preventDefault(),n.navigate(e)}}
|
|
7
|
-
>${
|
|
7
|
+
>${r}</a>`}};export{D as Link,a as RouterKey,E as RouterView,T as _resetRouter,C as createRouter,w as useRouter};
|
package/dist/lib/template.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./template2.cjs");exports.COMMENT=e.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./template2.cjs");exports.COMMENT=e.f,exports.buildHTML=e.c,exports.createErrorBoundary=e.t,exports.createPortalOutlet=e.n,exports.html=e.l,exports.injectOutlet=e.r,exports.isKeyedList=e.p,exports.isNixTemplate=e.m,exports.portal=e.i,exports.portalOutlet=e.a,exports.provideOutlet=e.o,exports.ref=e.h,exports.repeat=e.d,exports.showWhen=e.u,exports.transition=e.s;
|
package/dist/lib/template.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as e,c as t,d as n,f as r,h as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./template2.js";export{r as COMMENT,t as buildHTML,p as createErrorBoundary,c as createPortalOutlet,o as html,d as injectOutlet,u as isKeyedList,s as isNixTemplate,a as portal,e as portalOutlet,l as provideOutlet,i as ref,n as repeat,m as showWhen,f as transition};
|
package/dist/lib/template2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./signals.cjs");function t(){return{el:null}}var n={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function r(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function i(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var a=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function o(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function s(e){return Symbol(e)}var c=[];function l(){return[...c]}function u(){c.push(new Map)}function d(){c.pop()}function f(e,t){let n=c.splice(0);e.forEach(e=>c.push(e)),c.push(new Map);try{return t()}finally{c.splice(0),n.forEach(e=>c.push(e))}}function p(e,t){let n=c[c.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function m(e,t){for(let t=c.length-1;t>=0;t--)if(c[t].has(e))return c[t].get(e);return t}function h(e,t,n){let r,o;u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{d()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function g(e,t,n){let r,o;u();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{d()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function _(e,t,n,r){let o,l;f(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)});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{}o()}}function v(e,t,n,r,o){let l,i;u();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)}finally{d()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),o.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}l()})}function y(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function b(e){let t,n,r,o,l,i=e.slice(),u=[0],a=e.length;for(t=0;t<a;t++){let a=e[t];if(0!==a){if(n=u[u.length-1],e[n]<a){i[t]=n,u.push(t);continue}for(r=0,o=u.length-1;r<o;)l=r+o>>1,e[u[l]]<a?r=l+1:o=l;a<e[u[r]]&&(r>0&&(i[t]=u[r-1]),u[r]=t)}}for(r=u.length,o=u[r-1];r-- >0;)u[r]=o,o=i[o];return u}var x=new Set,S=!1;function C(e){x.add(e),S||(S=!0,queueMicrotask(()=>{for(let e of x)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}x.clear(),S=!1}))}function w(t,n,u,a){if("function"!=typeof n){if(o(n))v(n,t.parentNode,t,a,u);else if(r(n))u.push(n._render(t.parentNode,t));else if(Array.isArray(n))for(let e of n)o(e)?v(e,t.parentNode,t,a,u):r(e)?e._render(t.parentNode,t):null!=e&&!1!==e&&t.parentNode.insertBefore(document.createTextNode(String(e)),t);else null!=n&&!1!==n&&t.parentNode.insertBefore(document.createTextNode(String(n)),t);return}let c=null,s=null,d=null,f=[],p=null,m=l(),y=!1,g="",x=!0,N=e.effect(()=>{let l=n();if("string"==typeof l||"number"==typeof l){g=String(l);let e=()=>{y=!1,s&&=(s(),null),c?c.nodeValue=g:(c=document.createTextNode(g),t.parentNode.insertBefore(c,t))};return void(x?(x=!1,e()):y||(y=!0,C(e)))}if(y=!1,x=!1,c&&=(c.parentNode?.removeChild(c),null),s&&=(s(),null),null!=l&&!1!==l)if(r(l))s=l._render(t.parentNode,t);else if(o(l))s=_(l,t.parentNode,t,m);else if(i(l)){d||(d=new Map,p=document.createTextNode(""),t.parentNode.insertBefore(p,t));let n=t.parentNode,r=l.items.map((e,t)=>l.keyFn(e,t)),i=new Set(r),u=!1;if(d.size>0)for(let e of d.keys())if(i.has(e)){u=!0;break}if(!u){if(d.size>0){let e=document.createRange();e.setStartAfter(p),e.setEndBefore(t),e.deleteContents();for(let e of d.values())e.cleanup();d.clear()}if(r.length>0){let i=document.createDocumentFragment();e.batch(()=>{for(let e=0;e<r.length;e++){let t=r[e],n=l.items[e],u=document.createTextNode(""),a=document.createTextNode("");i.appendChild(u),i.appendChild(a);let c=l.renderFn(n,e),s=o(c)?_(c,i,a,m):c._render(i,a);d?.set(t,{start:u,end:a,cleanup:s})}}),n.insertBefore(i,t)}return void(f=r)}let a=new Map;for(let e=0;e<r.length;e++)a.set(r[e],e);let c=new Int32Array(r.length),s=!1,h=0;for(let e=0;e<f.length;e++){let t=f[e],n=a.get(t);if(void 0===n){let e=d.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}d.delete(t)}else c[n]=e+1,n>=h?h=n:s=!0}let y=s?b(c):[],g=y.length-1,v=t;for(let e=r.length-1;e>=0;e--){let t=r[e];if(0===c[e]){let r=l.items[e],i=document.createTextNode(""),u=document.createTextNode(""),a=document.createDocumentFragment();a.appendChild(i),a.appendChild(u);let c=l.renderFn(r,e),s=o(c)?_(c,a,u,m):c._render(a,u);d.set(t,{start:i,end:u,cleanup:s}),n.insertBefore(a,v),v=i}else{let r=d.get(t);if(s)if(g<0||e!==y[g]){let e=r.start;for(;e;){let t=e===r.end?null:e.nextSibling;if(n.insertBefore(e,v),!t)break;e=t}}else g--;v=r.start}}f=r}else if(Array.isArray(l)){let e=[];for(let n of l)if(o(n))e.push(h(n,t.parentNode,t));else if(r(n))e.push(n._render(t.parentNode,t));else if(null!=n&&!1!==n){let r=document.createTextNode(String(n));t.parentNode.insertBefore(r,t),e.push(()=>r.parentNode?.removeChild(r))}s=()=>e.forEach(e=>e())}else c=document.createTextNode(String(l)),t.parentNode.insertBefore(c,t)});u.push(()=>{if(N(),s&&=(s(),null),c&&=(c.parentNode?.removeChild(c),null),d){for(let e of d.values())e.cleanup();d=null,p=null}})}function T(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function E(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 u=r.slice(i,o);if("@"===u[0]){let e=u.slice(1).split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:l}}return{type:"attr",attrName:u,hadOpenQuote:l}}var D={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},O=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),k=new Set;function A(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=D[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 j=new Map;function M(t,n,r,o){let l=[],i=[],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(!O.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(!k.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>A(e,t,n);j.set(e,r),document.addEventListener(e,r),k.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"===a.type){let t=s.name,n=d;if("ref"===t){c.el=n,l.push(()=>{c.el=null});continue}if("show"===t||"hide"===t){let r=n,o=null;if("function"==typeof c){let n=!1,i=!1,u=!0,a=e.effect(()=>{i=!!c();let e=()=>{n=!1;let e="show"===t?i:!i;null===o&&(o=r.style.display||""),r.style.display=e?o:"none"};u?(u=!1,e()):n||(n=!0,C(e))});l.push(a)}else("show"===t?c:!c)||(r.style.display="none");continue}let r=("value"===t||"checked"===t||"selected"===t)&&t in n;if("function"==typeof c){let o,i=!1,u=!0,a=e.effect(()=>{o=c();let e=()=>{i=!1;let e=o;r?n[t]=e??"":null==e||!1===e?n.removeAttribute(t):n.setAttribute(t,String(e))};u?(u=!1,e()):i||(i=!0,C(e))});l.push(a)}else r?n[t]=c??"":null!=c&&!1!==c&&n.setAttribute(t,String(c));continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),w(p,c,l,i)}return{disposes:l,postMountHooks:i}}function N(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 P=new WeakMap;function F(e,...t){let n=P.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(E(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=N(e,t);let l,i=Array(t.length).fill(null),u=o.content,a=document.createTreeWalker(u,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),c=0;for(;l=a.nextNode();)if(c++,8===l.nodeType){let e=l.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:c})}}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:c,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:c,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:i},P.set(e,n)}let{contexts:r,tpl:o,pathMap:l}=n;function i(e,n){let i=o.content.cloneNode(!0),{disposes:u,postMountHooks:a}=M(i,r,t,l),c=document.createTextNode(""),s=document.createTextNode("");return e.insertBefore(c,n),e.insertBefore(i,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: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 I(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function L(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function R(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(L(r.transitionDuration||"0"),L(r.animationDuration||"0")),l=o>0?o+100:t;if(l<=0)return void n();let i,u=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n())};e.addEventListener("transitionend",u),e.addEventListener("animationend",u),i=setTimeout(()=>{e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n()},l)})}function z(t,r={}){let l=I(r);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(i,u){let a=document.createComment(n.TRANSITION);i.insertBefore(a,u);let c=null,s=null,d=0,f=!0,p=()=>{let e=a.nextSibling;for(;e&&e!==u;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};let m=(e,t=!1)=>{d++,s&&=(s(),null),c=function(e){return o(e)?g(e,i,u):e._render(i,u)}(e);let n=p();if(n&&(!f||r.appear)&&!t){let e=d;(async()=>{r.onBeforeEnter?.(n),n.classList.add(l.enterFrom,l.enterActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),d===e&&(n.classList.remove(l.enterFrom),n.classList.add(l.enterTo),await R(n,r.duration),d===e&&(n.classList.remove(l.enterActive,l.enterTo),r.onAfterEnter?.(n)))})().catch(()=>{})}f=!1},h=()=>{let e=c;c=null;let t=p();if(!t)return void e?.();let n=++d;s=e??null,(async()=>{r.onBeforeLeave?.(t),t.classList.add(l.leaveFrom,l.leaveActive),t.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),d===n&&(t.classList.remove(l.leaveFrom),t.classList.add(l.leaveTo),await R(t,r.duration),d===n&&(t.classList.remove(l.leaveActive,l.leaveTo),r.onAfterLeave?.(t),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof t||o(t))m(t);else{let n=t,r=null;y=e.effect(()=>{let e=n(),t=null===r,o=null===e;t&&!o?m(e):!t&&o?h():!t&&!o&&(d++,s?.(),s=null,c?.(),c=null,m(e,!0)),r=e}),f=!1}return()=>{d++,y?.(),c?.(),s?.(),c=null,s=null,a.remove()}}}}function B(){return{__isPortalOutlet:!0,_container:null}}function V(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 H(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,o(e)?h(e,l,null):e._render(l,null)}}}var U=s("nix:portal-outlet");function W(e){p(U,e)}function G(){return m(U)}function K(t,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,i){let a=document.createComment(n.ERROR_BOUNDARY);l.insertBefore(a,i);let c,s=null,f=!1,p=!1,m=!1,h=e=>{let t=a.parentNode,n="function"!=typeof r||o(r)?r:r(e);s=o(n)?g(n,t,i):n._render(t,i)};e._pushErrorHandler(e=>{f||(f=!0,p?(s?.(),s=null,h(e)):(c=e,m=!0))});try{if(o(t)){u();try{try{t.onInit?.()}catch(e){if(!t.onError)throw e;t.onError(e)}s=t.render()._render(l,i)}finally{d()}if(!f)try{let e=t.onMount?.(),n=s;s=()=>{try{t.onUnmount?.()}catch{}if("function"==typeof e)try{e()}catch{}n?.()}}catch(e){if(!t.onError)throw e;t.onError(e)}}else s=t._render(l,i)}catch(e){f=!0,s?.(),s=null,c=e,m=!0}finally{e._popErrorHandler(),p=!0}return m&&(s?.(),s=null,h(c)),()=>{s?.(),a.remove()}}}}Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return V}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return n}});
|
|
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,t,r){let o,l;n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,r)}finally{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{}o()}}function c(e,t,r){let o,l;n._pushComponentContext();try{try{e.onInit?.()}catch{}o=e.render()._render(t,r)}finally{n._popComponentContext()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}o()}}function l(e,t,r,o){let l,i;n._withComponentContext(o,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,r)});try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}l()}}function u(e,t,r,o,l){let i,a;n._pushComponentContext();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}i=e.render()._render(t,r)}finally{n._popComponentContext()}o.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{}i()})}function d(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function f(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 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=[],N=null,g=n._captureContextSnapshot(),v=!1,_="",b=!0,E=e.effect(()=>{let n=i();if("string"==typeof n||"number"==typeof n){_=String(n);let e=()=>{v=!1,m&&=(m(),null),p?p.nodeValue=_:(p=document.createTextNode(_),r.parentNode.insertBefore(p,r))};return void(b?(b=!1,e()):v||(v=!0,h(e)))}if(v=!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,g);else if(o(n)){y||(y=new Map,N=document.createTextNode(""),r.parentNode.insertBefore(N,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(N),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,g):s._render(a,c);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,v=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,g):s._render(c,u);y.set(r,{start:a,end:u,cleanup:d}),o.insertBefore(c,v),v=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,v),!n)break;e=n}}else h--;v=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,N=null}})}function _(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function v(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}}var y={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},b=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),x=new Set;function S(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=y[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 C=new Map;function w(t,n,r,o){let l=[],i=[],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(!b.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(!x.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>S(e,t,n);C.set(e,r),document.addEventListener(e,r),x.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 t=s.name,n=d;if("ref"===t){c.el=n,l.push(()=>{c.el=null});continue}if("show"===t||"hide"===t){let r=n,o=null;if("function"==typeof c){let n=!1,i=!1,a=!0,u=e.effect(()=>{i=!!c();let e=()=>{n=!1;let e="show"===t?i:!i;null===o&&(o=r.style.display||""),r.style.display=e?o:"none"};a?(a=!1,e()):n||(n=!0,h(e))});l.push(u)}else("show"===t?c:!c)||(r.style.display="none");continue}let r=("value"===t||"checked"===t||"selected"===t)&&t in n;if("function"==typeof c){let o,i=!1,a=!0,u=e.effect(()=>{o=c();let e=()=>{i=!1;let e=o;r?n[t]=e??"":null==e||!1===e?n.removeAttribute(t):n.setAttribute(t,String(e))};a?(a=!1,e()):i||(i=!0,h(e))});l.push(u)}else r?n[t]=c??"":null!=c&&!1!==c&&n.setAttribute(t,String(c));continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),g(p,c,l,i)}return{disposes:l,postMountHooks:i}}function T(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 E=new WeakMap;function D(e,...t){let n=E.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(v(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=T(e,t);let l,i=Array(t.length).fill(null),a=o.content,u=document.createTreeWalker(a,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT),c=0;for(;l=u.nextNode();)if(c++,8===l.nodeType){let e=l.nodeValue;if(e&&e.startsWith("nix-")){let t=parseInt(e.slice(4),10);isNaN(t)||(i[t]={nodeIndex:c})}}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:c,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:c,name:r.value},e.removeAttribute(o))}}}n={contexts:t,tpl:o,pathMap:i},E.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}=w(i,r,t,l),c=document.createTextNode(""),s=document.createTextNode("");return e.insertBefore(c,n),e.insertBefore(i,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: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 O(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 k(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function A(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(k(r.transitionDuration||"0"),k(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 j(n,r={}){let o=O(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 A(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 A(t,r.duration),f===n&&(t.classList.remove(o.leaveActive,o.leaveTo),r.onAfterLeave?.(t),d?.(),d=null))})().catch(()=>{})},N=null;if("function"!=typeof n||t.isNixComponent(n))y(n);else{let t=n,r=null;N=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++,N?.(),s?.(),d?.(),s=null,d=null,u.remove()}}}}function M(){return{__isPortalOutlet:!0,_container:null}}function N(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 P(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 l;return l="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,l,null):e._render(l,null)}}}var F=n.createInjectionKey("nix:portal-outlet");function I(e){n.provide(F,e)}function L(){return n.inject(F)}function R(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=e=>{let n=u.parentNode,r="function"!=typeof o||t.isNixComponent(o)?o:o(e);d=t.isNixComponent(r)?c(r,n,a):r._render(n,a)};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,"a",{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return _}});
|
package/dist/lib/template2.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_popErrorHandler as e,_pushErrorHandler as t,batch as n,effect as r}from"./signals.js";function i(){return{el:null}}var a={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function o(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function s(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}var c=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function l(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function u(e){return Symbol(e)}var d=[];function f(){return[...d]}function p(){d.push(new Map)}function m(){d.pop()}function h(e,t){let n=d.splice(0);e.forEach(e=>d.push(e)),d.push(new Map);try{return t()}finally{d.splice(0),n.forEach(e=>d.push(e))}}function g(e,t){let n=d[d.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function _(e,t){for(let t=d.length-1;t>=0;t--)if(d[t].has(e))return d[t].get(e);return t}function v(e,t,n){let r,o;p();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{m()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function y(e,t,n){let r,o;p();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{m()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function b(e,t,n,r){let o,l;h(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)});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{}o()}}function x(e,t,n,r,o){let l,i;p();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)}finally{m()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),o.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}l()})}function S(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function C(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 w=new Set,T=!1;function E(e){w.add(e),T||(T=!0,queueMicrotask(()=>{for(let e of w)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}w.clear(),T=!1}))}function D(e,t,i,a){if("function"!=typeof t){if(l(t))x(t,e.parentNode,e,a,i);else if(o(t))i.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let n of t)l(n)?x(n,e.parentNode,e,a,i):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 u=null,d=null,c=null,p=[],m=null,h=f(),y=!1,N="",_=!0,g=r(()=>{let r=t();if("string"==typeof r||"number"==typeof r){N=String(r);let t=()=>{y=!1,d&&=(d(),null),u?u.nodeValue=N:(u=document.createTextNode(N),e.parentNode.insertBefore(u,e))};return void(_?(_=!1,t()):y||(y=!0,E(t)))}if(y=!1,_=!1,u&&=(u.parentNode?.removeChild(u),null),d&&=(d(),null),null!=r&&!1!==r)if(o(r))d=r._render(e.parentNode,e);else if(l(r))d=b(r,e.parentNode,e,h);else if(s(r)){c||(c=new Map,m=document.createTextNode(""),e.parentNode.insertBefore(m,e));let t=e.parentNode,o=r.items.map((e,t)=>r.keyFn(e,t)),i=new Set(o),a=!1;if(c.size>0)for(let e of c.keys())if(i.has(e)){a=!0;break}if(!a){if(c.size>0){let t=document.createRange();t.setStartAfter(m),t.setEndBefore(e),t.deleteContents();for(let e of c.values())e.cleanup();c.clear()}if(o.length>0){let i=document.createDocumentFragment();n(()=>{for(let e=0;e<o.length;e++){let t=o[e],n=r.items[e],a=document.createTextNode(""),u=document.createTextNode("");i.appendChild(a),i.appendChild(u);let s=r.renderFn(n,e),d=l(s)?b(s,i,u,h):s._render(i,u);c?.set(t,{start:a,end:u,cleanup:d})}}),t.insertBefore(i,e)}return void(p=o)}let u=new Map;for(let e=0;e<o.length;e++)u.set(o[e],e);let s=new Int32Array(o.length),d=!1,f=0;for(let e=0;e<p.length;e++){let t=p[e],n=u.get(t);if(void 0===n){let e=c.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}c.delete(t)}else s[n]=e+1,n>=f?f=n:d=!0}let y=d?C(s):[],v=y.length-1,N=e;for(let e=o.length-1;e>=0;e--){let n=o[e];if(0===s[e]){let o=r.items[e],i=document.createTextNode(""),a=document.createTextNode(""),u=document.createDocumentFragment();u.appendChild(i),u.appendChild(a);let s=r.renderFn(o,e),d=l(s)?b(s,u,a,h):s._render(u,a);c.set(n,{start:i,end:a,cleanup:d}),t.insertBefore(u,N),N=i}else{let r=c.get(n);if(d)if(v<0||e!==y[v]){let e=r.start;for(;e;){let n=e===r.end?null:e.nextSibling;if(t.insertBefore(e,N),!n)break;e=n}}else v--;N=r.start}}p=o}else if(Array.isArray(r)){let t=[];for(let n of r)if(l(n))t.push(v(n,e.parentNode,e));else if(o(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))}d=()=>t.forEach(e=>e())}else u=document.createTextNode(String(r)),e.parentNode.insertBefore(u,e)});i.push(()=>{if(g(),d&&=(d(),null),u&&=(u.parentNode?.removeChild(u),null),c){for(let e of c.values())e.cleanup();c=null,m=null}})}function O(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function k(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}}var A={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},j=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),M=new Set;function N(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=A[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 P=new Map;function F(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],d=o[e];if(!d)continue;let c=a[e];if("event"===u.type){let e=d.name,t=s,n=u.modifiers;if(!j.has(e)||n.includes("capture")||n.includes("once")){let r={once:n.includes("once"),capture:n.includes("capture"),passive:n.includes("passive")},o=e=>{n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),(!n.includes("self")||e.target===e.currentTarget)&&t(e)};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r))}else{if(!M.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>N(e,t,n);P.set(e,r),document.addEventListener(e,r),M.add(e)}let r=`__nix_${e}`,o=`__nix_${e}_mods`;c[r]=t,n.length>0&&(c[o]=n),l.push(()=>{c[r]=null,c[o]=null})}continue}if("attr"===u.type){let e=d.name,t=c;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,E(r))});l.push(u)}else("show"===e?s:!s)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof s){let o,i=!1,a=!0,u=r(()=>{o=s();let r=()=>{i=!1;let r=o;n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))};a?(a=!1,r()):i||(i=!0,E(r))});l.push(u)}else n?t[e]=s??"":null!=s&&!1!==s&&t.setAttribute(e,String(s));continue}let f=c;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),D(p,s,l,i)}return{disposes:l,postMountHooks:i}}function I(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 L=new WeakMap;function R(e,...t){let n=L.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(k(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=I(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},L.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}=F(i,r,t,l),s=document.createTextNode(""),d=document.createTextNode("");return e.insertBefore(s,n),e.insertBefore(i,n),e.insertBefore(d,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==d;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s),d.parentNode?.removeChild(d)}}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 z(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 B(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function V(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(B(r.transitionDuration||"0"),B(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 H(e,t={}){let n=z(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,i){let u=document.createComment(a.TRANSITION);o.insertBefore(u,i);let s=null,d=null,c=0,f=!0,p=()=>{let e=u.nextSibling;for(;e&&e!==i;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function m(e){return l(e)?y(e,o,i):e._render(o,i)}let h=(e,r=!1)=>{c++,d&&=(d(),null),s=m(e);let o=p();if(o&&(!f||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 V(o,t.duration),c===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},v=()=>{let e=s;s=null;let r=p();if(!r)return void e?.();let o=++c;d=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 V(r,t.duration),c===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),d?.(),d=null))})().catch(()=>{})},N=null;if("function"!=typeof e||l(e))h(e);else{let t=e,n=null;N=r(()=>{let e=t(),r=null===n,o=null===e;r&&!o?h(e):!r&&o?v():!r&&!o&&(c++,d?.(),d=null,s?.(),s=null,h(e,!0)),n=e}),f=!1}return()=>{c++,N?.(),s?.(),d?.(),s=null,d=null,u.remove()}}}}function U(){return{__isPortalOutlet:!0,_container:null}}function W(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 G(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,l(e)?v(e,o,null):e._render(o,null)}}}var K=u("nix:portal-outlet");function q(e){g(K,e)}function J(){return _(K)}function Y(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 u=document.createComment(a.ERROR_BOUNDARY);o.insertBefore(u,i);let s,d=null,c=!1,f=!1,h=!1,v=e=>{let t=u.parentNode,n="function"!=typeof r||l(r)?r:r(e);d=l(n)?y(n,t,i):n._render(t,i)};t(e=>{c||(c=!0,f?(d?.(),d=null,v(e)):(s=e,h=!0))});try{if(l(n)){p();try{try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}d=n.render()._render(o,i)}finally{m()}if(!c)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){c=!0,d?.(),d=null,s=e,h=!0}finally{e(),f=!0}return h&&(d?.(),d=null,v(s)),()=>{d?.(),u.remove()}}}}export{i as S,c as _,W as a,s as b,I as c,S as d,m as f,g,_ as h,G as i,R as l,u as m,U as n,q as o,p,J as r,H as s,Y as t,O as u,l as v,o as x,a as y};
|
|
1
|
+
import{_popErrorHandler as e,_pushErrorHandler as t,batch as n,effect as r}from"./signals.js";import{isNixComponent as i}from"./lifecycle.js";import{_captureContextSnapshot as a,_popComponentContext as o,_pushComponentContext as s,_withComponentContext as c,createInjectionKey as l,inject as u,provide as d}from"./context.js";function f(){return{el:null}}var p={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function m(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function h(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function g(e,t,n){let r,l;s();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{o()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function _(e,t,n){let r,l;s();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{o()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function v(e,t,n,r){let o,l;c(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)});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{}o()}}function y(e,t,n,r,l){let i,a;s();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}i=e.render()._render(t,n)}finally{o()}r.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{}i()})}function b(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function x(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 S=new Set,C=!1;function w(e){S.add(e),C||(C=!0,queueMicrotask(()=>{for(let e of S)try{e()}catch(e){console.error("[Nix.js] Error in DOM write task:",e)}S.clear(),C=!1}))}function T(e,t,o,l){if("function"!=typeof t){if(i(t))y(t,e.parentNode,e,l,o);else if(m(t))o.push(t._render(e.parentNode,e));else if(Array.isArray(t))for(let n of t)i(n)?y(n,e.parentNode,e,l,o):m(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 u=null,s=null,c=null,d=[],f=null,p=a(),N=!1,_="",E=!0,T=r(()=>{let r=t();if("string"==typeof r||"number"==typeof r){_=String(r);let t=()=>{N=!1,s&&=(s(),null),u?u.nodeValue=_:(u=document.createTextNode(_),e.parentNode.insertBefore(u,e))};return void(E?(E=!1,t()):N||(N=!0,w(t)))}if(N=!1,E=!1,u&&=(u.parentNode?.removeChild(u),null),s&&=(s(),null),null!=r&&!1!==r)if(m(r))s=r._render(e.parentNode,e);else if(i(r))s=v(r,e.parentNode,e,p);else if(h(r)){c||(c=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),a=!1;if(c.size>0)for(let e of c.keys())if(l.has(e)){a=!0;break}if(!a){if(c.size>0){let t=document.createRange();t.setStartAfter(f),t.setEndBefore(e),t.deleteContents();for(let e of c.values())e.cleanup();c.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],a=document.createTextNode(""),u=document.createTextNode("");l.appendChild(a),l.appendChild(u);let s=r.renderFn(n,e),d=i(s)?v(s,l,u,p):s._render(l,u);c?.set(t,{start:a,end:u,cleanup:d})}}),t.insertBefore(l,e)}return void(d=o)}let u=new Map;for(let e=0;e<o.length;e++)u.set(o[e],e);let s=new Int32Array(o.length),m=!1,h=0;for(let e=0;e<d.length;e++){let t=d[e],n=u.get(t);if(void 0===n){let e=c.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}c.delete(t)}else s[n]=e+1,n>=h?h=n:m=!0}let y=m?x(s):[],N=y.length-1,_=e;for(let e=o.length-1;e>=0;e--){let n=o[e];if(0===s[e]){let o=r.items[e],l=document.createTextNode(""),a=document.createTextNode(""),u=document.createDocumentFragment();u.appendChild(l),u.appendChild(a);let s=r.renderFn(o,e),d=i(s)?v(s,u,a,p):s._render(u,a);c.set(n,{start:l,end:a,cleanup:d}),t.insertBefore(u,_),_=l}else{let r=c.get(n);if(m)if(N<0||e!==y[N]){let e=r.start;for(;e;){let n=e===r.end?null:e.nextSibling;if(t.insertBefore(e,_),!n)break;e=n}}else N--;_=r.start}}d=o}else if(Array.isArray(r)){let t=[];for(let n of r)if(i(n))t.push(g(n,e.parentNode,e));else if(m(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))}s=()=>t.forEach(e=>e())}else u=document.createTextNode(String(r)),e.parentNode.insertBefore(u,e)});o.push(()=>{if(T(),s&&=(s(),null),u&&=(u.parentNode?.removeChild(u),null),c){for(let e of c.values())e.cleanup();c=null,f=null}})}function E(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function D(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}}var O={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},k=new Set(["click","dblclick","mousedown","mouseup","keydown","keyup","input","change","submit"]),A=new Set;function j(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=O[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 M=new Map;function N(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(!k.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(!A.has(e)){let t=`__nix_${e}`,n=`__nix_${e}_mods`,r=e=>j(e,t,n);M.set(e,r),document.addEventListener(e,r),A.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,w(r))});l.push(u)}else("show"===e?s:!s)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof s){let o,i=!1,a=!0,u=r(()=>{o=s();let r=()=>{i=!1;let r=o;n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))};a?(a=!1,r()):i||(i=!0,w(r))});l.push(u)}else n?t[e]=s??"":null!=s&&!1!==s&&t.setAttribute(e,String(s));continue}let f=d;if(!f)continue;let p=document.createTextNode("");f.parentNode.replaceChild(p,f),T(p,s,l,i)}return{disposes:l,postMountHooks:i}}function P(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 F=new WeakMap;function I(e,...t){let n=F.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(D(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=P(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},F.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}=N(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 L(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 R(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function z(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(R(r.transitionDuration||"0"),R(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 B(e,t={}){let n=L(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 a=document.createComment(p.TRANSITION);o.insertBefore(a,l);let u=null,s=null,c=0,d=!0,f=()=>{let e=a.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function m(e){return i(e)?_(e,o,l):e._render(o,l)}let h=(e,r=!1)=>{c++,s&&=(s(),null),u=m(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 z(o,t.duration),c===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}d=!1},y=()=>{let e=u;u=null;let r=f();if(!r)return void e?.();let o=++c;s=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 z(r,t.duration),c===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),s?.(),s=null))})().catch(()=>{})},v=null;if("function"!=typeof e||i(e))h(e);else{let t=e,n=null;v=r(()=>{let e=t(),r=null===n,o=null===e;r&&!o?h(e):!r&&o?y():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,h(e,!0)),n=e}),d=!1}return()=>{c++,v?.(),u?.(),s?.(),u=null,s=null,a.remove()}}}}function V(){return{__isPortalOutlet:!0,_container:null}}function H(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 U(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,i(e)?g(e,o,null):e._render(o,null)}}}var W=l("nix:portal-outlet");function G(e){d(W,e)}function K(){return u(W)}function q(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(l,a){let u=document.createComment(p.ERROR_BOUNDARY);l.insertBefore(u,a);let c,d=null,f=!1,m=!1,h=!1,y=e=>{let t=u.parentNode,n="function"!=typeof r||i(r)?r:r(e);d=i(n)?_(n,t,a):n._render(t,a)};t(e=>{f||(f=!0,m?(d?.(),d=null,y(e)):(c=e,h=!0))});try{if(i(n)){s();try{try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}d=n.render()._render(l,a)}finally{o()}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(l,a)}catch(e){f=!0,d?.(),d=null,c=e,h=!0}finally{e(),m=!0}return h&&(d?.(),d=null,y(c)),()=>{d?.(),u.remove()}}}}export{H as a,P as c,b as d,p as f,f as h,U as i,I as l,m,V as n,G as o,h as p,K as r,B as s,q as t,E as u};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.5",
|
|
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",
|
|
@@ -55,6 +55,21 @@
|
|
|
55
55
|
"types": "./dist/lib/nix/template/index.d.ts",
|
|
56
56
|
"import": "./dist/lib/template.js",
|
|
57
57
|
"require": "./dist/lib/template.cjs"
|
|
58
|
+
},
|
|
59
|
+
"./component": {
|
|
60
|
+
"types": "./dist/lib/nix/component.d.ts",
|
|
61
|
+
"import": "./dist/lib/component.js",
|
|
62
|
+
"require": "./dist/lib/component.cjs"
|
|
63
|
+
},
|
|
64
|
+
"./context": {
|
|
65
|
+
"types": "./dist/lib/nix/context.d.ts",
|
|
66
|
+
"import": "./dist/lib/context.js",
|
|
67
|
+
"require": "./dist/lib/context.cjs"
|
|
68
|
+
},
|
|
69
|
+
"./lifecycle": {
|
|
70
|
+
"types": "./dist/lib/nix/lifecycle.d.ts",
|
|
71
|
+
"import": "./dist/lib/lifecycle.js",
|
|
72
|
+
"require": "./dist/lib/lifecycle.cjs"
|
|
58
73
|
}
|
|
59
74
|
},
|
|
60
75
|
"main": "./dist/lib/nix-js.cjs",
|