@deijose/nix-js 0.5.0 → 0.6.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/dist/lib/index.d.ts +2 -2
- package/dist/lib/nix/index.d.ts +2 -2
- package/dist/lib/nix/template.d.ts +107 -1
- package/dist/lib/nix-js.cjs +7 -7
- package/dist/lib/nix-js.js +7 -7
- package/package.json +1 -1
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, 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
|
-
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, Store, StoreSignals, Router, RouteRecord, SuspenseOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
|
1
|
+
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet, 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
|
+
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, PortalOutlet, Store, StoreSignals, Router, RouteRecord, SuspenseOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
package/dist/lib/nix/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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, portal } from "./template";
|
|
4
|
-
export type { NixTemplate, NixMountHandle, KeyedList, NixRef } from "./template";
|
|
3
|
+
export { html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet } from "./template";
|
|
4
|
+
export type { NixTemplate, NixMountHandle, KeyedList, NixRef, PortalOutlet } from "./template";
|
|
5
5
|
export { mount } from "./component";
|
|
6
6
|
export { NixComponent } from "./lifecycle";
|
|
7
7
|
export type { NixChildren } from "./lifecycle";
|
|
@@ -137,5 +137,111 @@ export declare function repeat<T>(items: T[], keyFn: (item: T, index: number) =>
|
|
|
137
137
|
* portal(html`<Tooltip />`, document.getElementById("tooltip-layer")!)
|
|
138
138
|
* ```
|
|
139
139
|
*/
|
|
140
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Opaque token created by `createPortalOutlet()`.
|
|
142
|
+
*
|
|
143
|
+
* Pass it to `portalOutlet()` to declare the DOM anchor where portals targeting
|
|
144
|
+
* this outlet will render, and to `portal(content, outlet)` as the target.
|
|
145
|
+
*
|
|
146
|
+
* @see createPortalOutlet
|
|
147
|
+
* @see portalOutlet
|
|
148
|
+
*/
|
|
149
|
+
export interface PortalOutlet {
|
|
150
|
+
readonly __isPortalOutlet: true;
|
|
151
|
+
/** @internal — resolved DOM container; set when `portalOutlet()` is mounted */
|
|
152
|
+
_container: Element | null;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Creates a `PortalOutlet` token — a lightweight, typed anchor point that
|
|
156
|
+
* decouples *where* a portal renders from direct DOM access.
|
|
157
|
+
* No CSS selectors, no `document.querySelector`, no manual element references.
|
|
158
|
+
*
|
|
159
|
+
* ### Workflow
|
|
160
|
+
* 1. Create the token at module or component scope.
|
|
161
|
+
* 2. Place `${portalOutlet(outlet)}` in your layout template to declare the anchor.
|
|
162
|
+
* 3. From any child: `portal(content, outlet)` renders into that anchor.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const modalOutlet = createPortalOutlet();
|
|
167
|
+
*
|
|
168
|
+
* // Layout:
|
|
169
|
+
* html`
|
|
170
|
+
* <main>${mainContent}</main>
|
|
171
|
+
* ${portalOutlet(modalOutlet)}
|
|
172
|
+
* `
|
|
173
|
+
*
|
|
174
|
+
* // Child (any depth):
|
|
175
|
+
* html`${() => show.value ? portal(html\`<Modal />\`, modalOutlet) : null}`
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
export declare function createPortalOutlet(): PortalOutlet;
|
|
179
|
+
/**
|
|
180
|
+
* Declares the DOM anchor for a `PortalOutlet` inside a template.
|
|
181
|
+
* Creates a `<div data-nix-outlet>` at this position; portals targeting
|
|
182
|
+
* `outlet` will render their content as children of that div.
|
|
183
|
+
*
|
|
184
|
+
* The anchor's lifecycle follows its parent template — when the parent
|
|
185
|
+
* unmounts, the outlet div and any portals inside it are cleaned up.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* mount(html`
|
|
190
|
+
* <div class="app">
|
|
191
|
+
* <main>${mainContent}</main>
|
|
192
|
+
* ${portalOutlet(modalOutlet)}
|
|
193
|
+
* </div>
|
|
194
|
+
* `, document.body);
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
export declare function portalOutlet(outlet: PortalOutlet): NixTemplate;
|
|
198
|
+
export declare function portal(content: NixTemplate | NixComponent, target?: Element | string | PortalOutlet | NixRef<Element>): NixTemplate;
|
|
199
|
+
/**
|
|
200
|
+
* Provides a `PortalOutlet` to descendant components via the inject system.
|
|
201
|
+
* Must be called inside `onInit()` of a `NixComponent`.
|
|
202
|
+
*
|
|
203
|
+
* Eliminates prop drilling: any descendant can call `injectOutlet()` to
|
|
204
|
+
* obtain the outlet without it being passed through every layer.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* class AppLayout extends NixComponent {
|
|
209
|
+
* private outlet = createPortalOutlet();
|
|
210
|
+
* onInit() { provideOutlet(this.outlet); }
|
|
211
|
+
* render() {
|
|
212
|
+
* return html`
|
|
213
|
+
* <main>...</main>
|
|
214
|
+
* ${portalOutlet(this.outlet)}
|
|
215
|
+
* `;
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
export declare function provideOutlet(outlet: PortalOutlet): void;
|
|
221
|
+
/**
|
|
222
|
+
* Injects the nearest `PortalOutlet` provided by an ancestor component.
|
|
223
|
+
* Returns `undefined` if no ancestor has called `provideOutlet()`.
|
|
224
|
+
*
|
|
225
|
+
* Use `portal(content, injectOutlet())` to render into the ancestor's outlet
|
|
226
|
+
* with no CSS selectors, no `document.querySelector`, and no prop drilling.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* class ToastButton extends NixComponent {
|
|
231
|
+
* private outlet: PortalOutlet | undefined;
|
|
232
|
+
* private active = signal(false);
|
|
233
|
+
* onInit() { this.outlet = injectOutlet(); }
|
|
234
|
+
* render() {
|
|
235
|
+
* return html`
|
|
236
|
+
* <button @click=${() => { this.active.value = true; }}>Notify</button>
|
|
237
|
+
* ${() => this.active.value
|
|
238
|
+
* ? portal(html\`<div class="toast">Done!</div>\`, this.outlet)
|
|
239
|
+
* : null
|
|
240
|
+
* }
|
|
241
|
+
* `;
|
|
242
|
+
* }
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export declare function injectOutlet(): PortalOutlet | undefined;
|
|
141
247
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): NixTemplate;
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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">
|
|
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,u=()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(u)),i=new Set,t.push(e),r.push(n),e=u,n=i;try{l=o()}finally{e=t.pop()||null,n=r.pop()||null}};return u(),()=>{"function"==typeof l&&l(),i.forEach(e=>e._removeSub(u)),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,u=e instanceof o?()=>e.value:e,a=!0,s=!1,f=c(()=>{let e=u();if(a){if(a=!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 w(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function te(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function ne(){return{__isPortalOutlet:!0,_container:null}}function T(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 E(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;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,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)}}}var D=g("nix:portal-outlet");function re(e){x(D,e)}function O(){return S(D)}function k(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 A(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 j(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ie(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function ae(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 oe(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 se(e,t,n){let r=[],o=[],l=ae(e),i=oe(e);for(let e=0;e<t.length;e++){let u=t[e],a=n[e];if("event"===u.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=a,s=u.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"===u.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){a.el=n,r.push(()=>{a.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof a){let n=c(()=>{let n=!!a(),r="show"===o?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===o?a:!a)||(n.style.display="none");continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof a){let e=c(()=>{let e=a();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=a??"":null!=a&&!1!==a&&n.setAttribute(o,String(a));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof a){if(h(a)){let e,n,l=a;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(j(a))a._render(s.parentNode,s);else if(Array.isArray(a))for(let e of a)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 j(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=a&&!1!==a&&s.parentNode.insertBefore(document.createTextNode(String(a)),s);continue}let f=null,d=null,p=null,m=ee(),x=c(()=>{let e=a();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(j(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(ie(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"),u=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(u,n);let a,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)}a=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else a=s._render(t,n);p.set(l,{start:u,end:n,cleanup:a}),o=u}}}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(j(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 M(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=k(r);n.push(o),r+="__nix__"}let o=A(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:u,postMountHooks:a}=se(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 a.forEach(e=>e()),()=>{u.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 ce(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 N(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 P=null;function F(){if(!P)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return P}function I(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function L(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 R(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 z(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function B(e,t="",n=[]){let r=[];for(let o of e){let e=z(t,o.path),l=[...n,o.component],i=R(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...B(o.children,e,l))}return r}function V(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 H(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},o=-1;for(let l of t){let t=V(e,l);if(null===t)continue;let i=H(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function W(e){function t(){return window.location.pathname||"/"}let n=t(),r=B(e),o=U(n,r),l=s(n),i=s(o?.params??{}),u=s(I(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=U(e,r)?.params??{},u.value=I(window.location.search),l.value=e});let a={current:l,params:i,query:u,navigate:function(e,t){let n=e.indexOf("?"),o=-1===n?e:e.slice(0,n),a=-1===n?{}:I(e.slice(n)),s=t?{...a,...t}:a,c={};for(let[e,t]of Object.entries(s))null!=t&&!1!==t&&(c[e]=String(t));i.value=U(o,r)?.params??{},u.value=c,l.value=o;let f=o+L(c);history.pushState(null,"",f)},routes:e,_flat:r};return P=a,a}function le(){return F()}var ue=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return M`<div class="router-view">${()=>{let t=F(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?M`<span></span>`:n.route.chain[e]():M`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
3
|
+
</div>`}}</div>`}},de=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return M`<a
|
|
4
4
|
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${this._label}</a>`}};function
|
|
5
|
+
style=${()=>F().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
|
+
@click=${t=>{t.preventDefault(),F().navigate(e)}}
|
|
7
|
+
>${this._label}</a>`}};function G(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1}=n,i=r??M`
|
|
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 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=
|
|
|
14
14
|
Cargando…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`,
|
|
17
|
+
`,u=o??(e=>M`
|
|
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
|
|
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 M`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?u(e.error):t(e.data)}}</div>`}}}function fe(e,t){let n=null;return()=>n?new n:G(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 pe(e){return e}const me={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function he(e,t){return{...e,...t}}function $(e,t=[]){let n=s(e),r=s(!1),o=s(!1),i=s(null),u=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 a(t){return"boolean"==typeof e?t.checked:"number"==typeof e?Number(t.value):t.value}return{value:n,error:u,touched:r,dirty:o,onInput:e=>{n.value=a(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 ge(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}),u=l(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function a(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:i,dirty:u,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 a(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:a}}exports.Link=de,exports.NixComponent=m,exports.RouterView=ue,exports.Signal=o,exports.batch=u,exports.computed=l,exports.createForm=ge,exports.createInjectionKey=g,exports.createPortalOutlet=ne,exports.createRouter=W,exports.createStore=N,exports.createValidator=pe,exports.effect=c,exports.email=X,exports.extendValidators=he,exports.html=M,exports.inject=S,exports.injectOutlet=O,exports.lazy=fe,exports.max=Q,exports.maxLength=J,exports.min=Z,exports.minLength=q,exports.mount=ce,exports.nextTick=p,exports.pattern=Y,exports.portal=E,exports.portalOutlet=T,exports.provide=x,exports.provideOutlet=re,exports.ref=C,exports.repeat=te,exports.required=K,exports.showWhen=w,exports.signal=s,exports.suspend=G,exports.untrack=d,exports.useField=$,exports.useRouter=le,exports.validators=me,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(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">
|
|
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 w(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function te(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function ne(){return{__isPortalOutlet:!0,_container:null}}function T(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 E(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;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,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)}}}var D=g("nix:portal-outlet");function re(e){x(D,e)}function O(){return S(D)}function k(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 A(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 j(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ie(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function ae(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 oe(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 se(e,t,n){let r=[],o=[],l=ae(e),i=oe(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(j(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 j(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(),_=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(j(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(ie(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(j(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(_(),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 M(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=k(r);n.push(o),r+="__nix__"}let o=A(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=se(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 ce(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 N(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 P=null;function F(){if(!P)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return P}function I(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function L(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 R(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 z(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function B(e,t="",n=[]){let r=[];for(let o of e){let e=z(t,o.path),l=[...n,o.component],i=R(e);r.push({fullPath:e,segments:i,chain:l}),o.children?.length&&r.push(...B(o.children,e,l))}return r}function V(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 H(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},o=-1;for(let l of t){let t=V(e,l);if(null===t)continue;let i=H(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function W(e){function t(){return window.location.pathname||"/"}let n=t(),r=B(e),o=U(n,r),l=s(n),i=s(o?.params??{}),a=s(I(window.location.search));window.addEventListener("popstate",()=>{let e=t();i.value=U(e,r)?.params??{},a.value=I(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?{}:I(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=U(o,r)?.params??{},a.value=c,l.value=o;let f=o+L(c);history.pushState(null,"",f)},routes:e,_flat:r};return P=u,u}function le(){return F()}var ue=class extends m{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return M`<div class="router-view">${()=>{let t=F(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?M`<span></span>`:n.route.chain[e]():M`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
3
|
+
</div>`}}</div>`}},de=class extends m{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return M`<a
|
|
4
4
|
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${this._label}</a>`}};function
|
|
5
|
+
style=${()=>F().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
|
+
@click=${t=>{t.preventDefault(),F().navigate(e)}}
|
|
7
|
+
>${this._label}</a>`}};function G(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1}=n,i=r??M`
|
|
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=o??(e=>
|
|
17
|
+
`,a=o??(e=>M`
|
|
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
|
|
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 M`<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 fe(e,t){let n=null;return()=>n?new n:G(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 pe(e){return e}const me={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function he(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 ge(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{de as Link,m as NixComponent,ue as RouterView,o as Signal,u as batch,l as computed,ge as createForm,g as createInjectionKey,ne as createPortalOutlet,W as createRouter,N as createStore,pe as createValidator,c as effect,X as email,he as extendValidators,M as html,S as inject,O as injectOutlet,fe as lazy,Q as max,J as maxLength,Z as min,q as minLength,ce as mount,p as nextTick,Y as pattern,E as portal,T as portalOutlet,x as provide,re as provideOutlet,C as ref,te as repeat,K as required,w as showWhen,s as signal,G as suspend,d as untrack,$ as useField,le as useRouter,me as validators,f as watch};
|
package/package.json
CHANGED