@deijose/nix-js 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/nix/index.d.ts +1 -1
- package/dist/lib/nix/template.d.ts +45 -0
- package/dist/lib/nix-js.cjs +2 -2
- package/dist/lib/nix-js.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -203,6 +203,38 @@ const panel = document.getElementById("panel") as HTMLElement;
|
|
|
203
203
|
effect(() => showWhen(panel, isOpen.value));
|
|
204
204
|
```
|
|
205
205
|
|
|
206
|
+
### Portal
|
|
207
|
+
|
|
208
|
+
Render a template into `document.body` (or any target) — escaping
|
|
209
|
+
`overflow: hidden` and stacking contexts. Ideal for modals, tooltips, toasts.
|
|
210
|
+
The portal is cleaned up automatically when its parent unmounts.
|
|
211
|
+
|
|
212
|
+
```typescript
|
|
213
|
+
import { signal, portal, html } from "@deijose/nix-js";
|
|
214
|
+
|
|
215
|
+
const isOpen = signal(false);
|
|
216
|
+
|
|
217
|
+
html`
|
|
218
|
+
<button @click=${() => { isOpen.value = true; }}>Open modal</button>
|
|
219
|
+
|
|
220
|
+
${() => isOpen.value
|
|
221
|
+
? portal(html`
|
|
222
|
+
<div class="overlay" @click=${() => { isOpen.value = false; }}>
|
|
223
|
+
<div class="modal" @click.stop=${() => {}}>
|
|
224
|
+
<h2>Hello!</h2>
|
|
225
|
+
<button @click=${() => { isOpen.value = false; }}>Close</button>
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
`) // renders into document.body by default
|
|
229
|
+
: null
|
|
230
|
+
}
|
|
231
|
+
`
|
|
232
|
+
|
|
233
|
+
// Custom target:
|
|
234
|
+
portal(html`<div class="toast">Saved!</div>`, "#toast-root")
|
|
235
|
+
portal(html`<Tooltip />`, document.getElementById("tooltip-layer")!)
|
|
236
|
+
```
|
|
237
|
+
|
|
206
238
|
### Dependency injection
|
|
207
239
|
|
|
208
240
|
```typescript
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, provide, inject, createInjectionKey, useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
1
|
+
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, provide, inject, createInjectionKey, useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
2
|
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, Store, StoreSignals, Router, RouteRecord, SuspenseOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
package/dist/lib/nix/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick } from "./reactivity";
|
|
2
2
|
export type { WatchOptions } from "./reactivity";
|
|
3
|
-
export { html, repeat, ref, showWhen } from "./template";
|
|
3
|
+
export { html, repeat, ref, showWhen, portal } from "./template";
|
|
4
4
|
export type { NixTemplate, NixMountHandle, KeyedList, NixRef } from "./template";
|
|
5
5
|
export { mount } from "./component";
|
|
6
6
|
export { NixComponent } from "./lifecycle";
|
|
@@ -93,4 +93,49 @@ export interface KeyedList<T = unknown> {
|
|
|
93
93
|
* )}
|
|
94
94
|
*/
|
|
95
95
|
export declare function repeat<T>(items: T[], keyFn: (item: T, index: number) => string | number, renderFn: (item: T, index: number) => NixTemplate | NixComponent): KeyedList<T>;
|
|
96
|
+
/**
|
|
97
|
+
* Renders `content` into `target` instead of the current position in the tree.
|
|
98
|
+
* The portal is cleaned up automatically when the parent template is unmounted.
|
|
99
|
+
*
|
|
100
|
+
* Use this to render modals, tooltips, notifications, or dropdowns outside of
|
|
101
|
+
* your component tree — typically into `document.body` — so they are not clipped
|
|
102
|
+
* by `overflow: hidden` or buried under other stacking contexts.
|
|
103
|
+
*
|
|
104
|
+
* The portal returns a `NixTemplate`, so it works as a node value anywhere in
|
|
105
|
+
* a template, including inside reactive conditionals: the portal is
|
|
106
|
+
* mounted/unmounted together with whatever controls its condition.
|
|
107
|
+
*
|
|
108
|
+
* @param content Template or component to render inside the portal.
|
|
109
|
+
* @param target CSS selector or `Element` to render into. Defaults to `document.body`.
|
|
110
|
+
*
|
|
111
|
+
* @example Reactive modal
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { signal, portal, html } from "@deijose/nix-js";
|
|
114
|
+
*
|
|
115
|
+
* const isOpen = signal(false);
|
|
116
|
+
*
|
|
117
|
+
* html`
|
|
118
|
+
* <button @click=${() => { isOpen.value = true; }}>Open</button>
|
|
119
|
+
*
|
|
120
|
+
* ${() => isOpen.value
|
|
121
|
+
* ? portal(html`
|
|
122
|
+
* <div class="overlay" @click=${() => { isOpen.value = false; }}>
|
|
123
|
+
* <div class="modal" @click.stop=${() => {}}>
|
|
124
|
+
* <h2>Hello from a portal!</h2>
|
|
125
|
+
* <button @click=${() => { isOpen.value = false; }}>Close</button>
|
|
126
|
+
* </div>
|
|
127
|
+
* </div>
|
|
128
|
+
* `)
|
|
129
|
+
* : null
|
|
130
|
+
* }
|
|
131
|
+
* `
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @example Custom target
|
|
135
|
+
* ```typescript
|
|
136
|
+
* portal(html`<div class="toast">Saved!</div>`, "#toast-root")
|
|
137
|
+
* portal(html`<Tooltip />`, document.getElementById("tooltip-layer")!)
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export declare function portal(content: NixTemplate | NixComponent, target?: Element | string): NixTemplate;
|
|
96
141
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): NixTemplate;
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=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 h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function ee(){return[..._]}function v(){_.push(new Map)}function y(){_.pop()}function b(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function x(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function S(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function C(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function T(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function E(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function re(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function D(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function O(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ie(e,t,n){let r=[],o=[],l=D(e),i=O(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=c(()=>{let n=!!u(),r="show"===o?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===o?u:!u)||(n.style.display="none");continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof u){let e=c(()=>{let e=u();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=u??"":null!=u&&!1!==u&&n.setAttribute(o,String(u));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,l=u;v();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(E(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,l;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else E(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=ee(),x=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(E(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;b(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(re(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,o;b(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);p.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(E(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(x(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function k(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=w(r);n.push(o),r+="__nix__"}let o=T(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ie(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function ae(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function oe(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var A=null;function j(){if(!A)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return A}function M(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function N(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function P(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 F(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function I(e,t="",n=[]){let r=[];for(let o of e){let e=F(t,o.path),l=[...n,o.component],i=P(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...I(o.children,e,l))}return r}function L(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function R(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function z(e,t){let n,r={},o=-1;for(let l of t){let t=L(e,l);if(null===t)continue;let i=R(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function B(e){function t(){return window.location.pathname||"/"}let n=t(),r=I(e),o=z(n,r),l=s(n),i=s(o?.params??{}),a=s(M(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=z(e,r)?.params??{},a.value=M(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),u=-1===n?{}:M(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=z(o,r)?.params??{},a.value=c,l.value=o;let f=o+N(c);history.pushState(null,"",f)},routes:e,_flat:r};return A=u,u}function V(){return j()}var H=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return k`<div class="router-view">${()=>{let t=j(),n=z(t.current.value,t._flat);return n?e>=n.route.chain.length?k`<span></span>`:n.route.chain[e]():k`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=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 h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function ee(){return[..._]}function v(){_.push(new Map)}function y(){_.pop()}function b(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function x(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function S(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function C(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(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="string"==typeof t?document.querySelector(t)??document.body:t;if(h(e)){let t,n;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}function T(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function re(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function E(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function D(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function O(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function ie(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ae(e,t,n){let r=[],o=[],l=O(e),i=ie(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=c(()=>{let n=!!u(),r="show"===o?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===o?u:!u)||(n.style.display="none");continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof u){let e=c(()=>{let e=u();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=u??"":null!=u&&!1!==u&&n.setAttribute(o,String(u));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,l=u;v();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(E(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,l;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else E(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=ee(),x=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(E(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;b(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(D(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,o;b(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);p.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(E(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(x(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function k(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=T(r);n.push(o),r+="__nix__"}let o=re(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ae(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function oe(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function se(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var A=null;function j(){if(!A)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return A}function M(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function N(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function P(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 F(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function I(e,t="",n=[]){let r=[];for(let o of e){let e=F(t,o.path),l=[...n,o.component],i=P(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...I(o.children,e,l))}return r}function L(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function R(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function z(e,t){let n,r={},o=-1;for(let l of t){let t=L(e,l);if(null===t)continue;let i=R(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function B(e){function t(){return window.location.pathname||"/"}let n=t(),r=I(e),o=z(n,r),l=s(n),i=s(o?.params??{}),a=s(M(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=z(e,r)?.params??{},a.value=M(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),u=-1===n?{}:M(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=z(o,r)?.params??{},a.value=c,l.value=o;let f=o+N(c);history.pushState(null,"",f)},routes:e,_flat:r};return A=u,u}function V(){return j()}var H=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return k`<div class="router-view">${()=>{let t=j(),n=z(t.current.value,t._flat);return n?e>=n.route.chain.length?k`<span></span>`:n.route.chain[e]():k`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},U=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return k`<a
|
|
4
4
|
href=${e}
|
|
@@ -18,4 +18,4 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=
|
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return k`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function G(e,t){let n=null;return()=>n?new n:W(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function K(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function q(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function J(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Y(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function X(e="Invalid email"){return Y(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Z(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function
|
|
21
|
+
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return k`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function G(e,t){let n=null;return()=>n?new n:W(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function K(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function q(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function J(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Y(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function X(e="Invalid email"){return Y(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Z(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function ce(e){return e}const le={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function ue(e,t){return{...e,...t}}function $(e,t=[]){let n=s(e),r=s(!1),o=s(!1),i=s(null),a=l(()=>{if(i.value)return i.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function u(t){return"boolean"==typeof e?t.checked:"number"==typeof e?Number(t.value):t.value}return{value:n,error:a,touched:r,dirty:o,onInput:e=>{n.value=u(e.target),o.value=!0,i.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,i.value=null},_setExternalError:function(e){i.value=e,e&&(r.value=!0)}}}function de(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=$(e[r],o)}let r=l(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=l(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),i=l(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),a=l(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function u(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:i,dirty:a,handleSubmit:function(e){return o=>{o.preventDefault();for(let e in n)n[e].touched.value=!0;let l=r.value;if(t.validate){let e=t.validate(l);if(e){let t={},n=!1;for(let r in e){let o=e[r],l=Array.isArray(o)?o[0]??null:o??null;l&&(t[r]=l,n=!0)}if(n)return void u(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:u}}exports.Link=U,exports.NixComponent=m,exports.RouterView=H,exports.Signal=o,exports.batch=u,exports.computed=l,exports.createForm=de,exports.createInjectionKey=g,exports.createRouter=B,exports.createStore=se,exports.createValidator=ce,exports.effect=c,exports.email=X,exports.extendValidators=ue,exports.html=k,exports.inject=S,exports.lazy=G,exports.max=Q,exports.maxLength=J,exports.min=Z,exports.minLength=q,exports.mount=oe,exports.nextTick=p,exports.pattern=Y,exports.portal=w,exports.provide=x,exports.ref=C,exports.repeat=ne,exports.required=K,exports.showWhen=te,exports.signal=s,exports.suspend=W,exports.untrack=d,exports.useField=$,exports.useRouter=V,exports.validators=le,exports.watch=f;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(l){let o,i=new Set,a=()=>{"function"==typeof o&&o(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{o=l()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof o&&o(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,l=n;e=null,n=null;try{return t()}finally{e=r,n=l}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,l=r;r=e,d(()=>t(n,l)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=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 h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function ee(){return[..._]}function v(){_.push(new Map)}function y(){_.pop()}function b(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function x(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function S(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function C(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),l=r.match(/@([\w:.-]+)=["']?$/);if(l){let e=l[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}}let o=r.match(/([\w:.-]+)=["']?$/);return o?{type:"attr",attrName:o[1],hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}:{type:"node"}}function T(e,t){let n=Array(e.length).fill(0),r="";for(let l=0;l<e.length;l++){let o=e[l];if(1===n[l]&&('"'===o[0]||"'"===o[0])&&(o=o.slice(1)),l<t.length){let e=t[l];if("node"===e.type)r+=o+`\x3c!--nix-${l}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-e-${l}="${e.eventName}"`,e.hadOpenQuote&&(n[l+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=o.slice(0,-t)+` data-nix-a-${l}="${e.attrName}"`,e.hadOpenQuote&&(n[l+1]=1)}}else r+=o}return r}function E(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function re(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function D(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function O(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ie(e,t,n){let r=[],l=[],o=D(e),i=O(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:l}=t,o=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}o(e)}};n.addEventListener(l,d,c),r.push(()=>n.removeEventListener(l,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:l}=t;if("ref"===l){u.el=n,r.push(()=>{u.el=null});continue}if("show"===l||"hide"===l){let e=n,t=null;if("function"==typeof u){let n=c(()=>{let n=!!u(),r="show"===l?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===l?u:!u)||(n.style.display="none");continue}let o=("value"===l||"checked"===l||"selected"===l)&&l in n;if("function"==typeof u){let e=c(()=>{let e=u();o?n[l]=e??"":null==e||!1===e?n.removeAttribute(l):n.setAttribute(l,String(e))});r.push(e)}else o?n[l]=u??"":null!=u&&!1!==u&&n.setAttribute(l,String(u));continue}let s=o.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,o=u;v();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(s.parentNode,s)}finally{y()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r.push(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(E(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,o;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{y()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else E(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=ee(),g=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(E(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;b(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(re(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let l=s;for(let r=n.length-1;r>=0;r--){let o=n[r],i=e.items[r];if(p.has(o)){let e=p.get(o);if(e.end.nextSibling!==l){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,l)}l=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,l),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,l;b(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(l=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{l?.()}catch{}r()}}else u=s._render(t,n);p.set(o,{start:a,end:n,cleanup:u}),l=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,l=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}l()})}else if(E(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:l}}function k(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let l=w(r);n.push(l),r+="__nix__"}let l=T(e,n);function o(e,r){let o=document.createElement("template");o.innerHTML=l;let i=o.content,{disposes:a,postMountHooks:u}=ie(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:o,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=o(t,null);return{unmount(){n()}}}}}function ae(e,t){if(h(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function oe(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let l=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(l,e)}return l}var A=null;function j(){if(!A)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return A}function M(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function N(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function P(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 F(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function I(e,t="",n=[]){let r=[];for(let l of e){let e=F(t,l.path),o=[...n,l.component],i=P(e);r.push({fullPath:e,segments:i,chain:o}),l.children?.length&&r.push(...I(l.children,e,o))}return r}function L(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let l=r.length>0&&"wildcard"===r[r.length-1].kind,o=l?r.slice(0,-1):r;if(l){if(n.length<o.length)return null}else if(n.length!==o.length)return null;let i={};for(let e=0;e<o.length;e++){let t=o[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function R(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function z(e,t){let n,r={},l=-1;for(let o of t){let t=L(e,o);if(null===t)continue;let i=R(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function B(e){function t(){return window.location.pathname||"/"}let n=t(),r=I(e),l=z(n,r),o=s(n),i=s(l?.params??{}),a=s(M(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=z(e,r)?.params??{},a.value=M(window.location.search),o.value=e});let u={current:o,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),l=-1===n?e:e.slice(0,n),u=-1===n?{}:M(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=z(l,r)?.params??{},a.value=c,o.value=l;let f=l+N(c);history.pushState(null,"",f)},routes:e,_flat:r};return A=u,u}function V(){return j()}var H=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return k`<div class="router-view">${()=>{let t=j(),n=z(t.current.value,t._flat);return n?e>=n.route.chain.length?k`<span></span>`:n.route.chain[e]():k`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return e&&(this._subs.add(e),n?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=[...this._subs];i>0?e.forEach(e=>a.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function s(e){return new o(e)}function c(o){let l,i=new Set,a=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i=new Set,t.push(e),r.push(n),e=a,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return a(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(a)),i.clear()}}function l(e){let t=new o(void 0);return c(()=>{t.value=e()}),t}function u(e){i++;try{e()}finally{if(0===--i){let e=[...a];a.clear(),e.forEach(e=>e())}}}function d(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function f(e,t,n={}){let r,{immediate:l=!1,once:i=!1}=n,a=e instanceof o?()=>e.value:e,u=!0,s=!1,f=c(()=>{let e=a();if(u){if(u=!1,l&&!s){let n=e;d(()=>t(n,void 0)),i&&(s=!0,Promise.resolve().then(f))}r=e}else if(!s){let n=e,o=r;r=e,d(()=>t(n,o)),i&&(s=!0,Promise.resolve().then(f))}});return()=>{s=!0,f()}}function p(e){return e?Promise.resolve().then(e):Promise.resolve()}var m=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 h(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function g(e){return Symbol(e)}var _=[];function ee(){return[..._]}function v(){_.push(new Map)}function y(){_.pop()}function b(e,t){let n=_.splice(0);e.forEach(e=>_.push(e)),_.push(new Map);try{return t()}finally{_.splice(0),n.forEach(e=>_.push(e))}}function x(e,t){let n=_[_.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function S(e){for(let t=_.length-1;t>=0;t--)if(_[t].has(e))return _[t].get(e)}function C(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function w(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="string"==typeof t?document.querySelector(t)??document.body:t;if(h(e)){let t,n;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}function T(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function re(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function E(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function D(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function O(e){let t,n=new Map,r=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT);for(;t=r.nextNode();){let e=t,r=e.nodeValue?.match(/^nix-(\d+)$/);r&&n.set(parseInt(r[1]),e)}return n}function ie(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ae(e,t,n){let r=[],o=[],l=O(e),i=ie(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=c(()=>{let n=!!u(),r="show"===o?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===o?u:!u)||(n.style.display="none");continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof u){let e=c(()=>{let e=u();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=u??"":null!=u&&!1!==u&&n.setAttribute(o,String(u));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof u){if(h(u)){let e,n,l=u;v();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(E(u))u._render(s.parentNode,s);else if(Array.isArray(u))for(let e of u)if(h(e)){let n,l;v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{y()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else E(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=u&&!1!==u&&s.parentNode.insertBefore(document.createTextNode(String(u)),s);continue}let f=null,d=null,p=null,m=ee(),g=c(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return d&&=(d(),null),void(f?f.nodeValue=String(e):(f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)));if(f&&=(f.parentNode?.removeChild(f),null),d&&=(d(),null),null!=e&&!1!==e)if(E(e))d=e._render(s.parentNode,s);else if(h(e)){let t,n,r=e;b(m,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}d=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(D(e)){p||=new Map;let t=s.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n);for(let[e,n]of p)if(!r.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),p.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(p.has(l)){let e=p.get(l);if(e.end.nextSibling!==o){let n=[],r=e.start;for(;n.push(r),r!==e.end;)r=r.nextSibling;for(let e of n)t.insertBefore(e,o)}o=e.start}else{let n=document.createComment("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(h(s)){let r,o;b(m,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);p.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(h(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(E(n))t.push(n._render(s.parentNode,s));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));s.parentNode.insertBefore(e,s),t.push(()=>e.parentNode?.removeChild(e))}d=()=>t.forEach(e=>e())}else f=document.createTextNode(String(e)),s.parentNode.insertBefore(f,s)});r.push(()=>{if(g(),d&&=(d(),null),f&&=(f.parentNode?.removeChild(f),null),p){for(let e of p.values())e.cleanup();p=null}})}return{disposes:r,postMountHooks:o}}function k(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=T(r);n.push(o),r+="__nix__"}let o=re(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ae(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function oe(e,t){if(h(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);v();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{y()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function se(e,t){let n={};for(let t of Object.keys(e))n[t]=s(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);Object.assign(o,e)}return o}var A=null;function j(){if(!A)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return A}function M(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function N(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function P(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 F(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function I(e,t="",n=[]){let r=[];for(let o of e){let e=F(t,o.path),l=[...n,o.component],i=P(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...I(o.children,e,l))}return r}function L(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else"param"===t.kind&&(i[t.name]=decodeURIComponent(n[e]??""))}return i}function R(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function z(e,t){let n,r={},o=-1;for(let l of t){let t=L(e,l);if(null===t)continue;let i=R(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function B(e){function t(){return window.location.pathname||"/"}let n=t(),r=I(e),o=z(n,r),l=s(n),i=s(o?.params??{}),a=s(M(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=z(e,r)?.params??{},a.value=M(window.location.search),l.value=e});let u={current:l,params:i,query:a,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),u=-1===n?{}:M(e.slice(n)),s=t?{...u,...t}:u,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=z(o,r)?.params??{},a.value=c,l.value=o;let f=o+N(c);history.pushState(null,"",f)},routes:e,_flat:r};return A=u,u}function V(){return j()}var H=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return k`<div class="router-view">${()=>{let t=j(),n=z(t.current.value,t._flat);return n?e>=n.route.chain.length?k`<span></span>`:n.route.chain[e]():k`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},U=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return k`<a
|
|
4
4
|
href=${e}
|
|
5
5
|
style=${()=>j().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(),j().navigate(e)}}
|
|
7
|
-
>${this._label}</a>`}};function W(e,t,n={}){let{fallback:r,errorFallback:
|
|
7
|
+
>${this._label}</a>`}};function W(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1}=n,i=r??k`
|
|
8
8
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
9
9
|
<span class="nix-spinner" style="
|
|
10
10
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -14,8 +14,8 @@ var e=null,t=[],n=null,r=[],i=0,a=new Set,o=class{_value;_subs=new Set;construct
|
|
|
14
14
|
Cargando…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`,a=
|
|
17
|
+
`,a=o??(e=>k`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(
|
|
21
|
+
`);return new class extends m{_state=s({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.value.status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return k`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function G(e,t){let n=null;return()=>n?new n:W(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function K(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function q(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function J(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Y(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function X(e="Invalid email"){return Y(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Z(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function ce(e){return e}const le={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function ue(e,t){return{...e,...t}}function $(e,t=[]){let n=s(e),r=s(!1),o=s(!1),i=s(null),a=l(()=>{if(i.value)return i.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function u(t){return"boolean"==typeof e?t.checked:"number"==typeof e?Number(t.value):t.value}return{value:n,error:a,touched:r,dirty:o,onInput:e=>{n.value=u(e.target),o.value=!0,i.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,i.value=null},_setExternalError:function(e){i.value=e,e&&(r.value=!0)}}}function de(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=$(e[r],o)}let r=l(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=l(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),i=l(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),a=l(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function u(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:i,dirty:a,handleSubmit:function(e){return o=>{o.preventDefault();for(let e in n)n[e].touched.value=!0;let l=r.value;if(t.validate){let e=t.validate(l);if(e){let t={},n=!1;for(let r in e){let o=e[r],l=Array.isArray(o)?o[0]??null:o??null;l&&(t[r]=l,n=!0)}if(n)return void u(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:u}}export{U as Link,m as NixComponent,H as RouterView,o as Signal,u as batch,l as computed,de as createForm,g as createInjectionKey,B as createRouter,se as createStore,ce as createValidator,c as effect,X as email,ue as extendValidators,k as html,S as inject,G as lazy,Q as max,J as maxLength,Z as min,q as minLength,oe as mount,p as nextTick,Y as pattern,w as portal,x as provide,C as ref,ne as repeat,K as required,te as showWhen,s as signal,W as suspend,d as untrack,$ as useField,V as useRouter,le as validators,f as watch};
|
package/package.json
CHANGED