@deijose/nix-js 1.5.1-beta.4 → 1.5.3-beta.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/nix/reactivity.d.ts +0 -15
- package/dist/lib/nix/template.d.ts +45 -5
- package/dist/lib/nix-js.cjs +8 -8
- package/dist/lib/nix-js.js +8 -8
- package/package.json +1 -1
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
export declare class EffectScope {
|
|
2
|
-
private active;
|
|
3
|
-
private effects;
|
|
4
|
-
private cleanups;
|
|
5
|
-
private parent;
|
|
6
|
-
private scopes;
|
|
7
|
-
constructor(detached?: boolean);
|
|
8
|
-
run<T>(fn: () => T): T | undefined;
|
|
9
|
-
onDispose(fn: () => void): void;
|
|
10
|
-
stop(fromParent?: boolean): void;
|
|
11
|
-
/** @internal */
|
|
12
|
-
_addEffect(dispose: () => void): void;
|
|
13
|
-
}
|
|
14
|
-
export declare function effectScope(detached?: boolean): EffectScope;
|
|
15
|
-
export declare function onScopeDispose(fn: () => void): void;
|
|
16
1
|
/**
|
|
17
2
|
* @internal — Register an error boundary handler. All `effect()` calls made
|
|
18
3
|
* synchronously while this handler is active will capture it. When those
|
|
@@ -29,6 +29,14 @@ export interface KeyedList<T = unknown> {
|
|
|
29
29
|
* Use instead of `.map()` when the list changes frequently.
|
|
30
30
|
*/
|
|
31
31
|
export declare function repeat<T>(items: T[], keyFn: (item: T, index: number) => string | number, renderFn: (item: T, index: number) => NixTemplate | NixComponent): KeyedList<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Renders `content` into `target` instead of the current tree position.
|
|
34
|
+
* Useful for modals, tooltips, and overlays that must escape overflow clipping.
|
|
35
|
+
* Returns a NixTemplate — works inside reactive conditionals.
|
|
36
|
+
*
|
|
37
|
+
* @param content Template or component to render.
|
|
38
|
+
* @param target CSS selector, Element, PortalOutlet, or NixRef. Defaults to `document.body`.
|
|
39
|
+
*/
|
|
32
40
|
/** Opaque token for a named portal target. */
|
|
33
41
|
export interface PortalOutlet {
|
|
34
42
|
readonly __isPortalOutlet: true;
|
|
@@ -51,26 +59,58 @@ export type ErrorFallback = NixTemplate | NixComponent | ((err: unknown) => NixT
|
|
|
51
59
|
* throws, the boundary tears down the broken subtree and renders `fallback`.
|
|
52
60
|
*/
|
|
53
61
|
export declare function createErrorBoundary(content: NixTemplate | NixComponent, fallback: ErrorFallback): NixTemplate;
|
|
62
|
+
/**
|
|
63
|
+
* Options for `transition()`. All class-name overrides are optional — by
|
|
64
|
+
* default they are derived from `name` (default `"nix"`).
|
|
65
|
+
*
|
|
66
|
+
* | phase | from class | active class | to class |
|
|
67
|
+
* |--------------|-------------------|---------------------|-----------------|
|
|
68
|
+
* | enter | `{n}-enter-from` | `{n}-enter-active` | `{n}-enter-to` |
|
|
69
|
+
* | leave | `{n}-leave-from` | `{n}-leave-active` | `{n}-leave-to` |
|
|
70
|
+
*/
|
|
54
71
|
export interface TransitionOptions {
|
|
72
|
+
/**
|
|
73
|
+
* Prefix for all generated CSS classes. Default `"nix"`.
|
|
74
|
+
* e.g. `name: "fade"` generates `.fade-enter-from`, `.fade-leave-to`, …
|
|
75
|
+
*/
|
|
55
76
|
name?: string;
|
|
77
|
+
/** Override the enter-from class individually. */
|
|
56
78
|
enterFrom?: string;
|
|
79
|
+
/** Override the enter-active class individually. */
|
|
57
80
|
enterActive?: string;
|
|
81
|
+
/** Override the enter-to class individually. */
|
|
58
82
|
enterTo?: string;
|
|
83
|
+
/** Override the leave-from class individually. */
|
|
59
84
|
leaveFrom?: string;
|
|
85
|
+
/** Override the leave-active class individually. */
|
|
60
86
|
leaveActive?: string;
|
|
87
|
+
/** Override the leave-to class individually. */
|
|
61
88
|
leaveTo?: string;
|
|
89
|
+
/**
|
|
90
|
+
* When `true` the enter transition also plays on the very first render
|
|
91
|
+
* (similar to Vue's `appear`). Default `false`.
|
|
92
|
+
*/
|
|
62
93
|
appear?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Fallback duration in **milliseconds** used when no `transition-duration`
|
|
96
|
+
* or `animation-duration` is found on the element via `getComputedStyle`.
|
|
97
|
+
*/
|
|
63
98
|
duration?: number;
|
|
99
|
+
/** Called synchronously right before the enter classes are added. */
|
|
64
100
|
onBeforeEnter?: (el: Element) => void;
|
|
101
|
+
/** Called after the enter transition has fully completed. */
|
|
65
102
|
onAfterEnter?: (el: Element) => void;
|
|
103
|
+
/** Called synchronously right before the leave classes are added. */
|
|
66
104
|
onBeforeLeave?: (el: Element) => void;
|
|
105
|
+
/** Called after the leave transition has fully completed and the DOM is removed. */
|
|
67
106
|
onAfterLeave?: (el: Element) => void;
|
|
68
107
|
}
|
|
108
|
+
/** Content that can be wrapped with `transition()`. */
|
|
69
109
|
export type TransitionContent = NixTemplate | NixComponent | (() => NixTemplate | NixComponent | null);
|
|
110
|
+
/**
|
|
111
|
+
* Wraps content with CSS class-based enter/leave transitions.
|
|
112
|
+
* Static content plays enter on mount (only with `appear: true`).
|
|
113
|
+
* Reactive `() => Template | null` auto-animates enter/leave on toggle.
|
|
114
|
+
*/
|
|
70
115
|
export declare function transition(content: TransitionContent, options?: TransitionOptions): NixTemplate;
|
|
71
|
-
export interface DOMPath {
|
|
72
|
-
indices: number[];
|
|
73
|
-
type: "node" | "event" | "attr";
|
|
74
|
-
name?: string;
|
|
75
|
-
}
|
|
76
116
|
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=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function M(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,o){let l,i=n();return i.run(()=>{let n;if(n="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,p=!1,h=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,h(e)):(a=e,p=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,p=!0}finally{d(),f=!0}p&&(s?.(),s=null,h(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function p(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let h=(e,n=!1)=>{c++,s&&=(s(),null),u=p(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))h(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?h(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,h(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let p=null,h=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return h&&=(h(),null),void(p?p.nodeValue=String(e):(p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)));if(p&&=(p.parentNode?.removeChild(p),null),h&&=(h(),null),null!=e&&!1!==e)if(I(e))h=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}h=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}h=()=>{for(let e=0;e<t.length;e++)t[e]()}}else p=document.createTextNode(String(e)),d.parentNode.insertBefore(p,d)}),r(()=>{if(h&&=(h(),null),p&&=(p.parentNode?.removeChild(p),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=document.createComment("nix-s");e.insertBefore(c,r),e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{u.stop();let e=c.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}c.parentNode?.removeChild(c)}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function xe(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],p=0;function h(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++p;if(0===l.length)return void r();let a=0;!function n(u){if(i!==p)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():x(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);h(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function x(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let b={current:u,params:s,query:c,base:n||"/",navigate:x,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);h(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=K(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=b,queueMicrotask(()=>{m||h(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=100,d=0,f=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];c>0?e.forEach(e=>l.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function p(e){return new f(e)}function m(o){let l,a=new Set,s=i,c=()=>{if("function"==typeof l&&l(),a.forEach(e=>e._removeSub(c)),a=new Set,t.push(e),r.push(n),e=c,n=a,++d>u)throw d=0,e=t.pop()||null,n=r.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{l=o()}catch(e){if(!s)throw e;s(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}};return c(),()=>{"function"==typeof l&&l(),a.forEach(e=>e._removeSub(c)),a.clear()}}function h(e){let t=new f(void 0);return m(()=>{t.value=e()}),t}function g(e){c++;try{e()}finally{if(0===--c){let e=[...l];l.clear(),e.forEach(e=>e())}}}function _(t){let r=e,o=n;e=null,n=null;try{return t()}finally{e=r,n=o}}function v(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof f?()=>e.value:e,a=!0,u=!1,s=m(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;_(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,_(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function y(e){return e?Promise.resolve().then(e):Promise.resolve()}var b=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 x(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function S(e){return Symbol(e)}var C=[];function w(){return[...C]}function T(){C.push(new Map)}function E(){C.pop()}function D(e,t){let n=C.splice(0);e.forEach(e=>C.push(e)),C.push(new Map);try{return t()}finally{C.splice(0),n.forEach(e=>C.push(e))}}function O(e,t){let n=C[C.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function k(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var A={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke"};function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function j(e,t,n){let r,o;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function M(e,t,n){let r,o;T();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}r()}}function N(e,t,n,r){let o,l;D(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}o()}}function re(e,t,n,r,o){let l,i;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)}finally{E()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),o.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}l()})}function ie(){return{__isPortalOutlet:!0,_container:null}}function ae(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 oe(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let o;return o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)?j(e,o,null):e._render(o,null)}}}var se=S("nix:portal-outlet");function ce(e){O(se,e)}function le(){return k(se)}function ue(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(A.ERROR_BOUNDARY);n.insertBefore(l,r);let i,a=null,u=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||x(t)?t:t(e);a=x(o)?M(o,n,r):o._render(n,r)};o(e=>{u||(u=!0,c?(a?.(),a=null,d(e)):(i=e,f=!0))});try{if(x(e)){T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(n,r)}finally{E()}if(!u)try{let t=e.onMount?.(),n=a;a=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else a=e._render(n,r)}catch(e){u=!0,a?.(),a=null,i=e,f=!0}finally{s(),c=!0}return f&&(a?.(),a=null,d(i)),()=>{a?.(),l.remove()}}}}function de(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t;if(l<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},l)})}function fe(e,t={}){let n=de(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,o){let l=document.createComment(A.TRANSITION);r.insertBefore(l,o);let i=null,a=null,u=0,s=!0,c=()=>{let e=l.nextSibling;for(;e&&e!==o;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return x(e)?M(e,r,o):e._render(r,o)}let d=(e,r=!1)=>{u++,a&&=(a(),null),i=f(e);let o=c();if(o&&(!s||t.appear)&&!r){let e=u;(async()=>{t.onBeforeEnter?.(o),o.classList.add(n.enterFrom,n.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===e&&(o.classList.remove(n.enterFrom),o.classList.add(n.enterTo),await F(o,t.duration),u===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}s=!1},p=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let o=++u;a=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===o&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await F(r,t.duration),u===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),a?.(),a=null))})().catch(()=>{})},h=null;if("function"!=typeof e||x(e))d(e);else{let t=e,n=null;h=m(()=>{let e=t(),r=null===n,o=null===e;r&&!o?d(e):!r&&o?p():!r&&!o&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,h?.(),i?.(),a?.(),i=null,a=null,l.remove()}}}}function pe(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 me(e,t){let n=new Set,r="";for(let o=0;o<e.length;o++){let l=e[o];if(n.has(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.add(o+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.add(o+1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function he(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function ge(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 _e(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}var L={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n){let r=[],o=[],l=ge(e),i=_e(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=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=L[e];if(void 0!==n&&t.key!==n||!L[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,f,c),r.push(()=>n.removeEventListener(o,f,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=m(()=>{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=m(()=>{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(x(u))re(u,s.parentNode,s,o,r);else if(I(u)){let e=u._render(s.parentNode,s);r.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?re(e,s.parentNode,s,o,r):I(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 c=null,f=null,d=null,p=w(),h=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return f&&=(f(),null),void(c?c.nodeValue=String(e):(c=document.createTextNode(String(e)),s.parentNode.insertBefore(c,s)));if(c&&=(c.parentNode?.removeChild(c),null),f&&=(f(),null),null!=e&&!1!==e)if(I(e))f=e._render(s.parentNode,s);else if(x(e))f=N(e,s.parentNode,s,p);else if(he(e)){d||=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 d)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),d.delete(e)}let o=s;for(let r=n.length-1;r>=0;r--){let l=n[r],i=e.items[r];if(d.has(l)){let e=d.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(A.KEYED_END),a=document.createComment(A.KEYED_START);t.insertBefore(n,o),t.insertBefore(a,n);let u=e.renderFn(i,r),s=x(u)?N(u,t,n,p):u._render(t,n);d.set(l,{start:a,end:n,cleanup:s}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(j(n,s.parentNode,s));else if(I(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))}f=()=>t.forEach(e=>e())}else c=document.createTextNode(String(e)),s.parentNode.insertBefore(c,s)});r.push(()=>{if(h(),f&&=(f(),null),c&&=(c.parentNode?.removeChild(c),null),d){for(let e of d.values())e.cleanup();d=null}})}return{disposes:r,postMountHooks:o}}function R(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=pe(r);n.push(o),r+="__nix__"}let o=me(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ve(i,n,t),s=document.createComment(A.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 ye(e,t){if(x(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function be(e,t){let n={};for(let t of Object.keys(e))n[t]=p(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var z=null,B=null;function V(){if(!z)throw Error("[Nix] No active router. Call createRouter() first.");return z}function H(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function U(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function xe(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function W(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...W(o.children,e,l))}return r}function Ce(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function we(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function G(e,t){let n,r={},o=-1;for(let l of t){let t=Ce(e,l);if(null===t)continue;let i=we(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function K(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Te(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return K(new URL(t,window.location.origin).pathname)}catch{return K(t)}}function Ee(e,t){let n=null==t?.base?Te():K(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=W(e),a=G(l,i),u=p(l),s=p(a?.params??{}),c=p(H(window.location.search)),f=[],d=[],h=0;function m(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++h;if(0===l.length)return void r();let a=0;!function n(u){if(i!==h)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():_(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function y(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:H(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}B&&=(B(),null);let x=()=>{let e=r(),t=u.value,n=c.value,l=G(e,i),a=H(window.location.search);m(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+U(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+U(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function _(e,t){v=!0;let{pathname:n,stringQuery:r}=y(e,t),o=u.value,l=G(n,i);m(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",x),B=()=>window.removeEventListener("popstate",x);let b={current:u,params:s,query:c,base:n||"/",navigate:_,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=y(e,t),o=u.value,l=G(n,i);m(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=G(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return z&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),z=b,queueMicrotask(()=>{v||m(l,"",G(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=G("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function De(){return V()}var Oe=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return R`<div class="router-view">${()=>{let t=V(),n=G(t.current.value,t._flat);return n?e>=n.route.chain.length?R`<span></span>`:n.route.chain[e]():R`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
4
|
-
href=${(
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${t}</a>`}};function
|
|
3
|
+
</div>`}}</div>`}},ke=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return R`<a
|
|
4
|
+
href=${(V()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
5
|
+
style=${()=>V().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(),V().navigate(e)}}
|
|
7
|
+
>${t}</a>`}};function Ae(){return R`
|
|
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
|
Loading…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`}function
|
|
17
|
+
`}function je(e){return R`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}var
|
|
21
|
+
`}var q=new Map,Me=3e5,J=null,Ne=Me;function Pe(){null===J&&(J=setInterval(()=>{let e=Date.now();for(let[t,n]of q)n.subscribers<=0&&e-n.fetchedAt>Ne&&q.delete(t);0===q.size&&null!==J&&(clearInterval(J),J=null)},6e4))}function Y(e){return q.get(e)}function Fe(e,t){let n=q.get(e);q.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Pe()}function Ie(e){let t=q.get(e);t&&t.subscribers++}function Le(e){let t=q.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Re(e,t){let n=q.get(e);return!!n&&Date.now()-n.fetchedAt<t}function ze(e){void 0===e?q.clear():q.delete(e)}function Be(e){Ne=e}function X(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1,invalidate:i,cacheKey:a,staleTime:u=0}=n,s=r??Ae(),c=o??je;return new class extends b{_state;_disposeWatcher;constructor(){super();let e=a?Y(a):void 0;this._state=p(e?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){a&&Ie(a);let e=a?Y(a):void 0;if(e&&Re(a,u)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=m(()=>{i.value,e?e=!1:(a&&q.delete(a),this._run())})}return()=>{this._disposeWatcher?.(),a&&Le(a)}}_run(){(l||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{a&&Fe(a,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return R`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Z=new Map;function Ve(e){q.delete(e);let t=Z.get(e);if(t)for(let e of t)e()}function He(e,t,n,r={}){let{fallback:o,errorFallback:l,resetOnRefresh:i=!1,staleTime:a=0,refetchOnMount:u="always"}=r,s=o??Ae(),c=l??je;return new class extends b{_state;constructor(){super();let t=Y(e);this._state=p(t?{status:"resolved",data:t.data}:{status:"pending"})}onMount(){Z.has(e)||Z.set(e,new Set);let t=Z.get(e),n=()=>this._run();t.add(n),Ie(e);let r=Y(e),o=Re(e,a);return r?!1===u||"stale"===u&&o||"always"===u&&o&&a>0||this._fetch():this._run(),()=>{t.delete(n),0===t.size&&Z.delete(e),Le(e)}}_run(){(i||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){t().then(t=>{Fe(e,t),this._state.value={status:"resolved",data:t}},e=>{this._state.value={status:"error",error:e}})}render(){return R`<div class="nix-query" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):n(e.data)}}</div>`}}}function Ue(e,t){let n=null;return()=>n?new n:X(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function We(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function Ge(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function Ke(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Q(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function qe(e="Invalid email"){return Q(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Je(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Ye(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Xe(e){return e}const Ze={required:We,minLength:Ge,maxLength:Ke,email:qe,pattern:Q,min:Je,max:Ye};function Qe(e,t){return{...e,...t}}function $(e,t=[]){let n=p(e),r=p(!1),o=p(!1),l=p(null),i=h(()=>{if(l.value)return l.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){if(!t||!("value"in t))return e;let n=t;return"boolean"==typeof e?n.checked:"number"==typeof e?Number(n.value):n.value}return{value:n,error:i,touched:r,dirty:o,onInput:e=>{n.value=a(e.target),o.value=!0,l.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,l.value=null},_setExternalError:function(e){l.value=e,e&&(r.value=!0)}}}function $e(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=$(e[r],o)}let r=h(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=h(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),l=h(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),i=h(()=>{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:l,dirty:i,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=ke,exports.NixComponent=b,exports.RouterView=Oe,exports.Signal=f,exports.batch=g,exports.clearQueryCache=ze,exports.computed=h,exports.createErrorBoundary=ue,exports.createForm=$e,exports.createInjectionKey=S,exports.createPortalOutlet=ie,exports.createQuery=He,exports.createRouter=Ee,exports.createStore=be,exports.createValidator=Xe,exports.effect=m,exports.email=qe,exports.extendValidators=Qe,exports.html=R,exports.inject=k,exports.injectOutlet=le,exports.invalidateQueries=Ve,exports.lazy=Ue,exports.max=Ye,exports.maxLength=Ke,exports.min=Je,exports.minLength=Ge,exports.mount=ye,exports.nextTick=y,exports.pattern=Q,exports.portal=oe,exports.portalOutlet=ae,exports.provide=O,exports.provideOutlet=ce,exports.ref=ee,exports.repeat=ne,exports.required=We,exports.setQueryCacheTime=Be,exports.showWhen=te,exports.signal=p,exports.suspend=X,exports.transition=fe,exports.untrack=_,exports.useField=$,exports.useRouter=De,exports.validators=Ze,exports.watch=v;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var e=null,t=class{active=!0;effects=[];cleanups=[];parent=null;scopes;constructor(t=!1){!t&&e&&(this.parent=e,(e.scopes||=new Set).add(this))}run(t){if(this.active){let n=e;e=this;try{return t()}finally{e=n}}}onDispose(e){this.active&&this.cleanups.push(e)}stop(e=!1){if(this.active){let t,n;for(t=0,n=this.effects.length;t<n;t++)this.effects[t]();for(t=0,n=this.cleanups.length;t<n;t++)this.cleanups[t]();if(this.scopes)for(let e of this.scopes)e.stop(!0);!e&&this.parent&&this.parent.scopes&&this.parent.scopes.delete(this),this.active=!1}}_addEffect(e){this.active&&this.effects.push(e)}};function n(e=!1){return new t(e)}function r(t){e&&e.onDispose(t)}var i=null,a=[],o=null,s=[],c=null,l=[];function u(e){l.push(c),c=e}function d(){c=l.pop()??null}var f=0,p=new Set,m=100,h=0,g=class{_value;_subs=new Set;constructor(e){this._value=e}get value(){return i&&(this._subs.add(i),o?.add(this)),this._value}set value(e){Object.is(this._value,e)||(this._value=e,this._notify())}update(e){this.value=e(this._value)}peek(){return this._value}_removeSub(e){this._subs.delete(e)}_notify(){let e=Array.from(this._subs);if(f>0)for(let t=0;t<e.length;t++)p.add(e[t]);else for(let t=0;t<e.length;t++)e[t]()}dispose(){this._subs.clear()}};function _(e){return new g(e)}function v(t){let n,r=new Set,l=c,u=()=>{if("function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r=new Set,a.push(i),s.push(o),i=u,o=r,++h>m)throw h=0,i=a.pop()||null,o=s.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{n=t()}catch(e){if(!l)throw e;l(e)}finally{h--,i=a.pop()||null,o=s.pop()||null}};u();let f=()=>{"function"==typeof n&&n(),r.forEach(e=>e._removeSub(u)),r.clear()};return e&&e._addEffect(f),f}function y(e){let t=new g(void 0);return v(()=>{t.value=e()}),t}function b(e){f++;try{e()}finally{if(0===--f){let e=Array.from(p);p.clear();for(let t=0;t<e.length;t++)e[t]()}}}function x(e){let t=i,n=o;i=null,o=null;try{return e()}finally{i=t,o=n}}function S(e,t,n={}){let r,{immediate:o=!1,once:l=!1}=n,i=e instanceof g?()=>e.value:e,a=!0,u=!1,s=v(()=>{let e=i();if(a){if(a=!1,o&&!u){let n=e;x(()=>t(n,void 0)),l&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,o=r;r=e,x(()=>t(n,o)),l&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function C(e){return e?Promise.resolve().then(e):Promise.resolve()}var w=class{__isNixComponent=!0;children;_slots=new Map;setChildren(e){return this.children=e,this}setSlot(e,t){return this._slots.set(e,t),this}slot(e){return this._slots.get(e)}};function T(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function E(e){return Symbol(e)}var D=[];function O(){return[...D]}function k(){D.push(new Map)}function A(){D.pop()}function j(e,t){let n=D.splice(0);e.forEach(e=>D.push(e)),D.push(new Map);try{return t()}finally{D.splice(0),n.forEach(e=>D.push(e))}}function M(e,t){let n=D[D.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function N(e){for(let t=D.length-1;t>=0;t--)if(D[t].has(e))return D[t].get(e)}function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function re(){return{__isPortalOutlet:!0,_container:null}}function ie(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,r){let o,l=n();return l.run(()=>{let n=document.createElement("div");n.setAttribute("data-nix-outlet",""),e._container=n,t.insertBefore(n,r),o=()=>{e._container=null,n.remove(),l.stop()}}),o}}}function ae(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,o){let l,i=n();return i.run(()=>{let n;if(n="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,T(e)){let t,r;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(n,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}l=()=>{try{e.onUnmount?.()}catch{}try{r?.()}catch{}t(),i.stop()}}else{let t=e._render(n,null);l=()=>{t(),i.stop()}}}),l}}}var oe=E("nix:portal-outlet");function se(e){M(oe,e)}function ce(){return N(oe)}function le(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,o){let l,i=n();return i.run(()=>{let n=document.createComment("nix-eb");r.insertBefore(n,o);let a,s=null,c=!1,f=!1,h=!1,p=e=>{let r=n.parentNode,l="function"!=typeof t||T(t)?t:t(e);if(T(l)){let e,t;k();try{try{l.onInit?.()}catch{}e=l.render()._render(r,o)}finally{A()}try{let e=l.onMount?.();"function"==typeof e&&(t=e)}catch{}s=()=>{try{l.onUnmount?.()}catch{}t?.(),e()}}else s=l._render(r,o)};u(e=>{c||(c=!0,f?(s?.(),s=null,p(e)):(a=e,h=!0))});try{if(T(e)){k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}s=e.render()._render(r,o)}finally{A()}if(!c)try{let t=e.onMount?.(),n=s;s=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else s=e._render(r,o)}catch(e){c=!0,s?.(),s=null,a=e,h=!0}finally{d(),f=!0}h&&(s?.(),s=null,p(a)),l=()=>{s?.(),n.remove(),i.stop()}}),l}}}function ue(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},l)})}function de(e,t={}){let r=ue(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(o,l){let i,a=n();return a.run(()=>{let n=document.createComment("nix-t");o.insertBefore(n,l);let u=null,s=null,c=0,f=!0,d=()=>{let e=n.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function h(e){if(T(e)){let t,n=e;k();try{try{n.onInit?.()}catch{}t=n.render()}finally{A()}let r,i=t._render(o,l);try{r=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof r)try{r()}catch{}i()}}return e._render(o,l)}let p=(e,n=!1)=>{c++,s&&=(s(),null),u=h(e);let o=d();if(o&&(!f||t.appear)&&!n){let e=c;(async()=>{t.onBeforeEnter?.(o),o.classList.add(r.enterFrom,r.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===e&&(o.classList.remove(r.enterFrom),o.classList.add(r.enterTo),await F(o,t.duration),c===e&&(o.classList.remove(r.enterActive,r.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}f=!1},m=()=>{let e=u;u=null;let n=d();if(!n)return void e?.();let o=++c;s=e??null,(async()=>{t.onBeforeLeave?.(n),n.classList.add(r.leaveFrom,r.leaveActive),n.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),c===o&&(n.classList.remove(r.leaveFrom),n.classList.add(r.leaveTo),await F(n,t.duration),c===o&&(n.classList.remove(r.leaveActive,r.leaveTo),t.onAfterLeave?.(n),s?.(),s=null))})().catch(()=>{})},y=null;if("function"!=typeof e||T(e))p(e);else{let t=e,n=null;y=v(()=>{let e=t(),r=null===n,o=null===e;r&&!o?p(e):!r&&o?m():!r&&!o&&(c++,s?.(),s=null,u?.(),u=null,p(e,!0)),n=e}),f=!1}i=()=>{c++,y?.(),u?.(),s?.(),u=null,s=null,n.remove(),a.stop()}}),i}}}function fe(e){let t=e.lastIndexOf(">"),n=e.lastIndexOf("<");if(n<=t)return{type:"node"};let r=e.slice(n+1),o=r.match(/@([\w:.-]+)=["']?$/);if(o){let e=o[1].split(".");return{type:"event",eventName:e[0],modifiers:e.slice(1),hadOpenQuote:o[0].endsWith('"')||o[0].endsWith("'")}}let l=r.match(/([\w:.-]+)=["']?$/);return l?{type:"attr",attrName:l[1],hadOpenQuote:l[0].endsWith('"')||l[0].endsWith("'")}:{type:"node"}}function pe(e,t){let n=Array(e.length).fill(0),r="";for(let o=0;o<e.length;o++){let l=e[o];if(1===n[o]&&('"'===l[0]||"'"===l[0])&&(l=l.slice(1)),o<t.length){let e=t[o];if("node"===e.type)r+=l+`\x3c!--nix-${o}--\x3e`;else if("event"===e.type){let t=`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(".")}`:e.eventName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-e-${o}="${e.eventName}"`,e.hadOpenQuote&&(n[o+1]=1)}else{let t=`${e.attrName}=`.length+(e.hadOpenQuote?1:0);r+=l.slice(0,-t)+` data-nix-a-${o}="${e.attrName}"`,e.hadOpenQuote&&(n[o+1]=1)}}else r+=l}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function me(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function he(e){let t=new Map,n=[e];for(;n.length;){let e=n.pop().childNodes;for(let r=0;r<e.length;r++)t.set(e[r],r),n.push(e[r])}return t}function L(e,t,n){let r=[],o=e;for(;o&&o!==t;)r.push(n.get(o)??0),o=o.parentNode;return r.reverse()}function ge(e){let t,n=new Map,r=he(e),o=document.createTreeWalker(e,NodeFilter.SHOW_COMMENT|NodeFilter.SHOW_ELEMENT),l=[];for(;t=o.nextNode();)if(t.nodeType===Node.COMMENT_NODE){let o=(t.nodeValue||"").match(/^nix-(\d+)$/);o&&n.set(parseInt(o[1]),{indices:L(t,e,r),type:"node"})}else if(t.nodeType===Node.ELEMENT_NODE){let o=t,i=o.attributes;for(let t=0;t<i.length;t++){let a=i[t],u=a.name.match(/^data-nix-e-(\d+)$/);u?(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"event",name:a.value}),l.push([o,a.name])):(u=a.name.match(/^data-nix-a-(\d+)$/),u&&(n.set(parseInt(u[1]),{indices:L(o,e,r),type:"attr",name:a.value}),l.push([o,a.name])))}}for(let e=0;e<l.length;e++)l[e][0].removeAttribute(l[e][1]);return n}function _e(e,t){let n=e;for(let e=0;e<t.length;e++){if(!n)return null;n=n.childNodes[t[e]]??null}return n??null}var R={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n,o){let l=[],i=O();for(let a=0;a<t.length;a++){let u=t[a],s=n[a],c=o.get(a);if(!c)continue;let f=_e(e,c.indices);if(!f)continue;if("event"===u.type&&"event"===c.type){let e=f,t=c.name,n=s,o=u.modifiers,l={};o.includes("once")&&(l.once=!0),o.includes("capture")&&(l.capture=!0),o.includes("passive")&&(l.passive=!0);let i=e=>{if(o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),!o.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of o){let n=R[e];if(void 0!==n&&t.key!==n||!R[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}n(e)}};e.addEventListener(t,i,l),r(()=>e.removeEventListener(t,i,l));continue}if("attr"===u.type&&"attr"===c.type){let e=f,t=c.name;if("ref"===t){s.el=e,r(()=>{s.el=null});continue}if("show"===t||"hide"===t){let n=e,r=null;"function"==typeof s?v(()=>{let e=!!s(),o="show"===t?e:!e;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"}):("show"===t?s:!s)||(e.style.display="none");continue}let n=("value"===t||"checked"===t||"selected"===t)&&t in e;"function"==typeof s?v(()=>{let r=s();n?e[t]=r??"":null==r||!1===r?e.removeAttribute(t):e.setAttribute(t,String(r))}):n?e[t]=s??"":null!=s&&!1!==s&&e.setAttribute(t,String(s));continue}if("node"!==c.type)continue;let d=f;if("function"!=typeof s){if(T(s)){let e,n,o=s;k();try{try{o.onInit?.()}catch(t){if(!o.onError)throw t;o.onError(t)}e=o.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let e=o.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!o.onError)throw e;o.onError(e)}}),r(()=>{try{o.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(I(s))r(s._render(d.parentNode,d));else if(Array.isArray(s))for(let e of s)if(T(e)){let n,o;k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(d.parentNode,d)}finally{A()}l.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r(()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}n()})}else I(e)?e._render(d.parentNode,d):null!=e&&!1!==e&&d.parentNode.insertBefore(document.createTextNode(String(e)),d);else null!=s&&!1!==s&&d.parentNode.insertBefore(document.createTextNode(String(s)),d);continue}let h=null,p=null,m=null,y=!1;v(()=>{let e=s();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(h?h.nodeValue=String(e):(h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)));if(h&&=(h.parentNode?.removeChild(h),null),p&&=(p(),null),null!=e&&!1!==e)if(I(e))p=e._render(d.parentNode,d);else if(T(e)){let t,n,r=e;j(i,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(d.parentNode,d)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}p=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(e)){m||=new Map;let t=d.parentNode,n=e.items.length,r=Array(n),o=new Set;for(let t=0;t<n;t++){let n=e.keyFn(e.items[t],t);r[t]=n,o.add(n)}if(0===n&&m.size>0){let e=Array(m.size),t=0,n=null,r=null;for(let o of m.values())e[t++]=o.cleanup,n||=o.start,r=o.end;if(n&&r){let e=document.createRange();e.setStartBefore(n),e.setEndAfter(r),e.deleteContents()}m.clear();for(let t=0;t<e.length;t++)e[t]();return}for(let[e,n]of m)if(!o.has(e)){n.cleanup();let r=n.start;for(;r!==n.end;){let e=r.nextSibling;t.removeChild(r),r=e}t.removeChild(n.end),m.delete(e)}let l=d;for(let n=r.length-1;n>=0;n--){let o=r[n],a=e.items[n];if(m.has(o)){let e=m.get(o);if(e.end.nextSibling!==l){let n=document.createDocumentFragment(),r=e.start;for(;;){let t=r.nextSibling;if(n.appendChild(r),r===e.end)break;r=t}t.insertBefore(n,l)}l=e.start}else{let r=document.createComment("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(r,l),t.insertBefore(u,r);let s,c=e.renderFn(a,n);if(T(c)){let n,o;j(i,()=>{try{c.onInit?.()}catch(e){if(!c.onError)throw e;c.onError(e)}n=c.render()._render(t,r)});try{let e=c.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!c.onError)throw e;c.onError(e)}s=()=>{try{c.onUnmount?.()}catch{}try{o?.()}catch{}n()}}else s=c._render(t,r);m.set(o,{start:u,end:r,cleanup:s}),l=u}}}else if(Array.isArray(e)){!y&&e.length>10&&(y=!0,console.warn("[Nix] Rendering array without keys. Consider using repeat() for better performance."));let t=[];for(let n of e)if(T(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(d.parentNode,d);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(I(n))t.push(n._render(d.parentNode,d));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));d.parentNode.insertBefore(e,d),t.push(()=>e.parentNode?.removeChild(e))}p=()=>{for(let e=0;e<t.length;e++)t[e]()}}else h=document.createTextNode(String(e)),d.parentNode.insertBefore(h,d)}),r(()=>{if(p&&=(p(),null),h&&=(h.parentNode?.removeChild(h),null),m){for(let e of m.values())e.cleanup();m=null}})}return{postMountHooks:l}}var z=new WeakMap;function B(e,...t){let r=z.get(e);if(!r){let t=[],n="";for(let r=0;r<e.length-1;r++){n+=e[r];let o=fe(n);t.push(o),n+="__nix__"}let o=pe(e,t),l=document.createElement("template");l.innerHTML=o,r={tpl:l,contexts:t,bindingPaths:ge(l.content)},z.set(e,r)}let{tpl:o,contexts:l,bindingPaths:i}=r;function a(e,r){let a,u=n();return u.run(()=>{let n=o.content.cloneNode(!0),{postMountHooks:s}=ve(n,l,t,i),c=document.createComment("nix-s");e.insertBefore(c,r),e.insertBefore(n,r);for(let e=0;e<s.length;e++)s[e]();a=()=>{u.stop();let e=c.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}c.parentNode?.removeChild(c)}}),a}return{__isNixTemplate:!0,_render:a,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=a(t,null);return{unmount(){n()}}}}}function ye(e,t){if(T(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: container not found: ${t}`);k();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{A()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function be(e,t){let n={};for(let t of Object.keys(e))n[t]=_(e[t]);let r=n;let o=Object.assign(Object.create(null),r,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]}});if(t){let e=t(r);for(let t of Object.keys(e))"$reset"!==t?o[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return o}var V=null,H=null;function U(){if(!V)throw Error("[Nix] No active router. Call createRouter() first.");return V}function W(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function G(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function xe(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function Ce(e,t="",n=[]){let r=[];for(let o of e){let e=Se(t,o.path),l=[...n,o.component],i=xe(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...Ce(o.children,e,l))}return r}function we(e,t){let n=e.split("/").filter(Boolean),r=t.segments;if(1===r.length&&"wildcard"===r[0].kind)return{};let o=r.length>0&&"wildcard"===r[r.length-1].kind,l=o?r.slice(0,-1):r;if(o){if(n.length<l.length)return null}else if(n.length!==l.length)return null;let i={};for(let e=0;e<l.length;e++){let t=l[e];if("literal"===t.kind){if(n[e]!==t.value)return null}else if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function Te(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function K(e,t){let n,r={},o=-1;for(let l of t){let t=we(e,l);if(null===t)continue;let i=Te(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function q(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Ee(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return q(new URL(t,window.location.origin).pathname)}catch{return q(t)}}function De(e,t){let n=null==t?.base?Ee():q(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function o(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let l=r(),i=Ce(e),a=K(l,i),u=_(l),s=_(a?.params??{}),c=_(W(window.location.search)),f=[],d=[],h=0;function p(e,t,n,r,o){let l=[...f];n&&l.push(n);let i=++h;if(0===l.length)return void r();let a=0;!function n(u){if(i!==h)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=l.length)return void r();let s=l[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let m=!1;function v(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:W(e.slice(n)),l=t?{...o,...t}:o,i={};for(let[e,t]of Object.entries(l))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}H&&=(H(),null);let y=()=>{let e=r(),t=u.value,n=c.value,l=K(e,i),a=W(window.location.search);p(e,t,l?.route.beforeEnter,()=>{s.value=l?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",o(t)+G(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+G(t);l?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",y),H=()=>window.removeEventListener("popstate",y);let w={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){m=!0;let{pathname:n,stringQuery:r}=v(e,t),o=u.value,l=K(n,i);p(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=K(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return V&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),V=w,queueMicrotask(()=>{m||p(l,"",K(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=K("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),w}function Oe(){return U()}var ke=class extends w{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return B`<div class="router-view">${()=>{let t=U(),n=K(t.current.value,t._flat);return n?e>=n.route.chain.length?B`<span></span>`:n.route.chain[e]():B`<div style="color:#f87171;padding:16px 0">
|
|
1
|
+
var e=null,t=[],n=null,r=[],i=null,a=[];function o(e){a.push(i),i=e}function s(){i=a.pop()??null}var c=0,l=new Set,u=100,d=0,f=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];c>0?e.forEach(e=>l.add(e)):e.forEach(e=>e())}dispose(){this._subs.clear()}};function p(e){return new f(e)}function m(l){let o,a=new Set,s=i,c=()=>{if("function"==typeof o&&o(),a.forEach(e=>e._removeSub(c)),a=new Set,t.push(e),r.push(n),e=c,n=a,++d>u)throw d=0,e=t.pop()||null,n=r.pop()||null,Error("[Nix] Maximum effect re-execution depth exceeded (possible infinite loop).");try{o=l()}catch(e){if(!s)throw e;s(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}};return c(),()=>{"function"==typeof o&&o(),a.forEach(e=>e._removeSub(c)),a.clear()}}function h(e){let t=new f(void 0);return m(()=>{t.value=e()}),t}function g(e){c++;try{e()}finally{if(0===--c){let e=[...l];l.clear(),e.forEach(e=>e())}}}function _(t){let r=e,l=n;e=null,n=null;try{return t()}finally{e=r,n=l}}function v(e,t,n={}){let r,{immediate:l=!1,once:o=!1}=n,i=e instanceof f?()=>e.value:e,a=!0,u=!1,s=m(()=>{let e=i();if(a){if(a=!1,l&&!u){let n=e;_(()=>t(n,void 0)),o&&(u=!0,Promise.resolve().then(s))}r=e}else if(!u){let n=e,l=r;r=e,_(()=>t(n,l)),o&&(u=!0,Promise.resolve().then(s))}});return()=>{u=!0,s()}}function y(e){return e?Promise.resolve().then(e):Promise.resolve()}var b=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 x(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function S(e){return Symbol(e)}var C=[];function w(){return[...C]}function T(){C.push(new Map)}function E(){C.pop()}function D(e,t){let n=C.splice(0);e.forEach(e=>C.push(e)),C.push(new Map);try{return t()}finally{C.splice(0),n.forEach(e=>C.push(e))}}function O(e,t){let n=C[C.length-1];if(!n)throw Error("[Nix] provide() must be called inside onInit() of a NixComponent.");n.set(e,t)}function k(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var A={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke"};function ee(){return{el:null}}function te(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function ne(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function j(e,t,n){let r,l;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}r=e.render()._render(t,n)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function M(e,t,n){let r,l;T();try{try{e.onInit?.()}catch{}r=e.render()._render(t,n)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch{}return()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}r()}}function N(e,t,n,r){let l,o;D(r,()=>{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}l=e.render()._render(t,n)});try{let t=e.onMount?.();"function"==typeof t&&(o=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{o?.()}catch{}l()}}function re(e,t,n,r,l){let o,i;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}o=e.render()._render(t,n)}finally{E()}r.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(i=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),l.push(()=>{try{e.onUnmount?.()}catch{}try{i?.()}catch{}o()})}function ie(){return{__isPortalOutlet:!0,_container:null}}function ae(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 oe(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l;return l="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)?j(e,l,null):e._render(l,null)}}}var se=S("nix:portal-outlet");function ce(e){O(se,e)}function le(){return k(se)}function ue(e,t){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let l=document.createComment(A.ERROR_BOUNDARY);n.insertBefore(l,r);let i,a=null,u=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||x(t)?t:t(e);a=x(o)?M(o,n,r):o._render(n,r)};o(e=>{u||(u=!0,c?(a?.(),a=null,d(e)):(i=e,f=!0))});try{if(x(e)){T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(n,r)}finally{E()}if(!u)try{let t=e.onMount?.(),n=a;a=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else a=e._render(n,r)}catch(e){u=!0,a?.(),a=null,i=e,f=!0}finally{s(),c=!0}return f&&(a?.(),a=null,d(i)),()=>{a?.(),l.remove()}}}}function de(e){let t=e.name??"nix";return{enterFrom:e.enterFrom??`${t}-enter-from`,enterActive:e.enterActive??`${t}-enter-active`,enterTo:e.enterTo??`${t}-enter-to`,leaveFrom:e.leaveFrom??`${t}-leave-from`,leaveActive:e.leaveActive??`${t}-leave-active`,leaveTo:e.leaveTo??`${t}-leave-to`}}function P(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function F(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(P(r.transitionDuration||"0"),P(r.animationDuration||"0")),o=l>0?l+100:t;if(o<=0)return void n();let i,a=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n())};e.addEventListener("transitionend",a),e.addEventListener("animationend",a),i=setTimeout(()=>{e.removeEventListener("transitionend",a),e.removeEventListener("animationend",a),n()},o)})}function fe(e,t={}){let n=de(t);return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(r,l){let o=document.createComment(A.TRANSITION);r.insertBefore(o,l);let i=null,a=null,u=0,s=!0,c=()=>{let e=o.nextSibling;for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE)return e;e=e.nextSibling}return null};function f(e){return x(e)?M(e,r,l):e._render(r,l)}let d=(e,r=!1)=>{u++,a&&=(a(),null),i=f(e);let l=c();if(l&&(!s||t.appear)&&!r){let e=u;(async()=>{t.onBeforeEnter?.(l),l.classList.add(n.enterFrom,n.enterActive),l.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===e&&(l.classList.remove(n.enterFrom),l.classList.add(n.enterTo),await F(l,t.duration),u===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},h=()=>{let e=i;i=null;let r=c();if(!r)return void e?.();let l=++u;a=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),u===l&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await F(r,t.duration),u===l&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),a?.(),a=null))})().catch(()=>{})},p=null;if("function"!=typeof e||x(e))d(e);else{let t=e,n=null;p=m(()=>{let e=t(),r=null===n,l=null===e;r&&!l?d(e):!r&&l?h():!r&&!l&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,p?.(),i?.(),a?.(),i=null,a=null,o.remove()}}}}function pe(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 me(e,t){let n=new Set,r="";for(let l=0;l<e.length;l++){let o=e[l];if(n.has(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.add(l+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.add(l+1)}}else r+=o}return r}function I(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function he(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function ge(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 _e(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}var L={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function ve(e,t,n){let r=[],l=[],o=ge(e),i=_e(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=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=L[e];if(void 0!==n&&t.key!==n||!L[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}o(e)}};n.addEventListener(l,f,c),r.push(()=>n.removeEventListener(l,f,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=m(()=>{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=m(()=>{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(x(u))re(u,s.parentNode,s,l,r);else if(I(u)){let e=u._render(s.parentNode,s);r.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?re(e,s.parentNode,s,l,r):I(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 c=null,f=null,d=null,h=w(),p=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return f&&=(f(),null),void(c?c.nodeValue=String(e):(c=document.createTextNode(String(e)),s.parentNode.insertBefore(c,s)));if(c&&=(c.parentNode?.removeChild(c),null),f&&=(f(),null),null!=e&&!1!==e)if(I(e))f=e._render(s.parentNode,s);else if(x(e))f=N(e,s.parentNode,s,h);else if(he(e)){d||=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 d)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),d.delete(e)}let l=s;for(let r=n.length-1;r>=0;r--){let o=n[r],i=e.items[r];if(d.has(o)){let e=d.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(A.KEYED_END),a=document.createComment(A.KEYED_START);t.insertBefore(n,l),t.insertBefore(a,n);let u=e.renderFn(i,r),s=x(u)?N(u,t,n,h):u._render(t,n);d.set(o,{start:a,end:n,cleanup:s}),l=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(j(n,s.parentNode,s));else if(I(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))}f=()=>t.forEach(e=>e())}else c=document.createTextNode(String(e)),s.parentNode.insertBefore(c,s)});r.push(()=>{if(p(),f&&=(f(),null),c&&=(c.parentNode?.removeChild(c),null),d){for(let e of d.values())e.cleanup();d=null}})}return{disposes:r,postMountHooks:l}}function R(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let l=pe(r);n.push(l),r+="__nix__"}let l=me(e,n);function o(e,r){let o=document.createElement("template");o.innerHTML=l;let i=o.content,{disposes:a,postMountHooks:u}=ve(i,n,t),s=document.createComment(A.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 ye(e,t){if(x(e)){let n,r,l="string"==typeof t?document.querySelector(t):t;if(!l)throw Error(`[Nix] mount: container not found: ${t}`);T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(l,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(r=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return{unmount(){try{e.onUnmount?.()}catch{}try{r?.()}catch{}n()}}}return e.mount(t)}function be(e,t){let n={};for(let t of Object.keys(e))n[t]=p(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);for(let t of Object.keys(e))"$reset"!==t?l[t]=e[t]:console.warn('[Nix] Store action name "$reset" is reserved and will be ignored.')}return l}var z=null,B=null;function V(){if(!z)throw Error("[Nix] No active router. Call createRouter() first.");return z}function H(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function U(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))null!=r&&!1!==r&&t.set(n,String(r));let n=t.toString();return n?"?"+n:""}function xe(e){return"*"===e?[{kind:"wildcard"}]:e.split("/").filter(Boolean).map(e=>"*"===e?{kind:"wildcard"}:e.startsWith(":")?{kind:"param",name:e.slice(1)}:{kind:"literal",value:e})}function Se(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function W(e,t="",n=[]){let r=[];for(let l of e){let e=Se(t,l.path),o=[...n,l.component],i=xe(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...W(l.children,e,o))}return r}function Ce(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 if("param"===t.kind)try{i[t.name]=decodeURIComponent(n[e]??"")}catch{i[t.name]=n[e]??""}}return i}function we(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function G(e,t){let n,r={},l=-1;for(let o of t){let t=Ce(e,o);if(null===t)continue;let i=we(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function K(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Te(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return K(new URL(t,window.location.origin).pathname)}catch{return K(t)}}function Ee(e,t){let n=null==t?.base?Te():K(t.base);function r(){let e=window.location.pathname||"/";if(n&&e.startsWith(n)){let t=e.slice(n.length);return""===t?"/":t}return e}function l(e){return n?n+(e.startsWith("/")?e:"/"+e):e}let o=r(),i=W(e),a=G(o,i),u=p(o),s=p(a?.params??{}),c=p(H(window.location.search)),f=[],d=[],h=0;function m(e,t,n,r,l){let o=[...f];n&&o.push(n);let i=++h;if(0===o.length)return void r();let a=0;!function n(u){if(i!==h)return;if(!1===u)return void l?.();if("string"==typeof u)return void(u===e?r():b(u));if(a>=o.length)return void r();let s=o[a++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let v=!1;function y(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),l=-1===n?{}:H(e.slice(n)),o=t?{...l,...t}:l,i={};for(let[e,t]of Object.entries(o))null!=t&&!1!==t&&(i[e]=String(t));return{pathname:r,stringQuery:i}}B&&=(B(),null);let _=()=>{let e=r(),t=u.value,n=c.value,o=G(e,i),a=H(window.location.search);m(e,t,o?.route.beforeEnter,()=>{s.value=o?.params??{},c.value=a,u.value=e;for(let n of d)try{n(e,t)}catch{}},()=>{history.pushState(null,"",l(t)+U(n))})};function g(e,t,n,r,o){s.value=r?.params??{},c.value=t,u.value=e;let i=l(e)+U(t);o?history.replaceState(null,"",i):history.pushState(null,"",i);for(let t of d)try{t(e,n)}catch{}}function b(e,t){v=!0;let{pathname:n,stringQuery:r}=y(e,t),l=u.value,o=G(n,i);m(n,l,o?.route.beforeEnter,()=>g(n,r,l,o,!1))}window.addEventListener("popstate",_),B=()=>window.removeEventListener("popstate",_);let x={current:u,params:s,query:c,base:n||"/",navigate:b,replace:function(e,t){v=!0;let{pathname:n,stringQuery:r}=y(e,t),l=u.value,o=G(n,i);m(n,l,o?.route.beforeEnter,()=>g(n,r,l,o,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=u.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=G(t,i);if(!n)return{matched:!1,params:{},route:void 0};let r=n.route.chain[n.route.chain.length-1];return{matched:!0,params:n.params,route:function e(t){for(let n of t){if(n.component===r)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return f.push(e),()=>{let t=f.indexOf(e);-1!==t&&f.splice(t,1)}},afterEach:function(e){return d.push(e),()=>{let t=d.indexOf(e);-1!==t&&d.splice(t,1)}},routes:e,_flat:i,_guards:f,_base:n};return z&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),z=x,queueMicrotask(()=>{v||m(o,"",G(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=G("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function De(){return V()}var Oe=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return R`<div class="router-view">${()=>{let t=V(),n=G(t.current.value,t._flat);return n?e>=n.route.chain.length?R`<span></span>`:n.route.chain[e]():R`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
4
|
-
href=${(
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${t}</a>`}};function
|
|
3
|
+
</div>`}}</div>`}},ke=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return R`<a
|
|
4
|
+
href=${(V()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
5
|
+
style=${()=>V().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(),V().navigate(e)}}
|
|
7
|
+
>${t}</a>`}};function Ae(){return R`
|
|
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=class{active=!0;effects=[];cleanups=[];parent=null;scopes;construct
|
|
|
14
14
|
Loading…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`}function
|
|
17
|
+
`}function je(e){return R`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}var
|
|
21
|
+
`}var q=new Map,Me=3e5,J=null,Ne=Me;function Pe(){null===J&&(J=setInterval(()=>{let e=Date.now();for(let[t,n]of q)n.subscribers<=0&&e-n.fetchedAt>Ne&&q.delete(t);0===q.size&&null!==J&&(clearInterval(J),J=null)},6e4))}function Y(e){return q.get(e)}function Fe(e,t){let n=q.get(e);q.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Pe()}function Ie(e){let t=q.get(e);t&&t.subscribers++}function Le(e){let t=q.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Re(e,t){let n=q.get(e);return!!n&&Date.now()-n.fetchedAt<t}function ze(e){void 0===e?q.clear():q.delete(e)}function Be(e){Ne=e}function X(e,t,n={}){let{fallback:r,errorFallback:l,resetOnRefresh:o=!1,invalidate:i,cacheKey:a,staleTime:u=0}=n,s=r??Ae(),c=l??je;return new class extends b{_state;_disposeWatcher;constructor(){super();let e=a?Y(a):void 0;this._state=p(e?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){a&&Ie(a);let e=a?Y(a):void 0;if(e&&Re(a,u)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=m(()=>{i.value,e?e=!1:(a&&q.delete(a),this._run())})}return()=>{this._disposeWatcher?.(),a&&Le(a)}}_run(){(o||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{a&&Fe(a,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return R`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Z=new Map;function Ve(e){q.delete(e);let t=Z.get(e);if(t)for(let e of t)e()}function He(e,t,n,r={}){let{fallback:l,errorFallback:o,resetOnRefresh:i=!1,staleTime:a=0,refetchOnMount:u="always"}=r,s=l??Ae(),c=o??je;return new class extends b{_state;constructor(){super();let t=Y(e);this._state=p(t?{status:"resolved",data:t.data}:{status:"pending"})}onMount(){Z.has(e)||Z.set(e,new Set);let t=Z.get(e),n=()=>this._run();t.add(n),Ie(e);let r=Y(e),l=Re(e,a);return r?!1===u||"stale"===u&&l||"always"===u&&l&&a>0||this._fetch():this._run(),()=>{t.delete(n),0===t.size&&Z.delete(e),Le(e)}}_run(){(i||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){t().then(t=>{Fe(e,t),this._state.value={status:"resolved",data:t}},e=>{this._state.value={status:"error",error:e}})}render(){return R`<div class="nix-query" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):n(e.data)}}</div>`}}}function Ue(e,t){let n=null;return()=>n?new n:X(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function We(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function Ge(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function Ke(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Q(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function qe(e="Invalid email"){return Q(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Je(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Ye(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Xe(e){return e}const Ze={required:We,minLength:Ge,maxLength:Ke,email:qe,pattern:Q,min:Je,max:Ye};function Qe(e,t){return{...e,...t}}function $(e,t=[]){let n=p(e),r=p(!1),l=p(!1),o=p(null),i=h(()=>{if(o.value)return o.value;if(!r.value&&!l.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function a(t){if(!t||!("value"in t))return e;let n=t;return"boolean"==typeof e?n.checked:"number"==typeof e?Number(n.value):n.value}return{value:n,error:i,touched:r,dirty:l,onInput:e=>{n.value=a(e.target),l.value=!0,o.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,l.value=!1,o.value=null},_setExternalError:function(e){o.value=e,e&&(r.value=!0)}}}function $e(e,t={}){let n={};for(let r in e){let l=t.validators?.[r]??[];n[r]=$(e[r],l)}let r=h(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),l=h(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),o=h(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),i=h(()=>{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:l,valid:o,dirty:i,handleSubmit:function(e){return l=>{l.preventDefault();for(let e in n)n[e].touched.value=!0;let o=r.value;if(t.validate){let e=t.validate(o);if(e){let t={},n=!1;for(let r in e){let l=e[r],o=Array.isArray(l)?l[0]??null:l??null;o&&(t[r]=o,n=!0)}if(n)return void a(t)}}for(let e in n)if(n[e].error.value)return;e(o)}},reset:function(){for(let e in n)n[e].reset()},setErrors:a}}export{ke as Link,b as NixComponent,Oe as RouterView,f as Signal,g as batch,ze as clearQueryCache,h as computed,ue as createErrorBoundary,$e as createForm,S as createInjectionKey,ie as createPortalOutlet,He as createQuery,Ee as createRouter,be as createStore,Xe as createValidator,m as effect,qe as email,Qe as extendValidators,R as html,k as inject,le as injectOutlet,Ve as invalidateQueries,Ue as lazy,Ye as max,Ke as maxLength,Je as min,Ge as minLength,ye as mount,y as nextTick,Q as pattern,oe as portal,ae as portalOutlet,O as provide,ce as provideOutlet,ee as ref,ne as repeat,We as required,Be as setQueryCacheTime,te as showWhen,p as signal,X as suspend,fe as transition,_ as untrack,$ as useField,De as useRouter,Ze as validators,v as watch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.3-beta.0",
|
|
4
4
|
"description": "A lightweight, fully reactive micro-framework — no virtual DOM, no compiler, just signals and tagged templates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://nix-js-landing.vercel.app/",
|