@deijose/nix-js 1.7.2-beta.4 → 1.7.2-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/nix/template.d.ts +0 -55
- package/dist/lib/nix-js.cjs +1 -1
- package/dist/lib/nix-js.js +1 -1
- package/package.json +1 -1
|
@@ -29,88 +29,33 @@ 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
|
-
*/
|
|
40
|
-
/** Opaque token for a named portal target. */
|
|
41
32
|
export interface PortalOutlet {
|
|
42
33
|
readonly __isPortalOutlet: true;
|
|
43
34
|
/** @internal */
|
|
44
35
|
_container: Element | null;
|
|
45
36
|
}
|
|
46
|
-
/** Creates a PortalOutlet token for decoupled portal targeting. */
|
|
47
37
|
export declare function createPortalOutlet(): PortalOutlet;
|
|
48
|
-
/** Declares the DOM anchor for a PortalOutlet inside a template. */
|
|
49
38
|
export declare function portalOutlet(outlet: PortalOutlet): NixTemplate;
|
|
50
39
|
export declare function portal(content: NixTemplate | NixComponent, target?: Element | string | PortalOutlet | NixRef<Element>): NixTemplate;
|
|
51
|
-
/** Provides a PortalOutlet to descendant components via dependency injection. */
|
|
52
40
|
export declare function provideOutlet(outlet: PortalOutlet): void;
|
|
53
|
-
/** Injects the nearest PortalOutlet provided by an ancestor. */
|
|
54
41
|
export declare function injectOutlet(): PortalOutlet | undefined;
|
|
55
|
-
/** Fallback: a static template/component, or a factory receiving the error. */
|
|
56
42
|
export type ErrorFallback = NixTemplate | NixComponent | ((err: unknown) => NixTemplate | NixComponent);
|
|
57
|
-
/**
|
|
58
|
-
* Wraps `content` in an error boundary. If rendering or a reactive update
|
|
59
|
-
* throws, the boundary tears down the broken subtree and renders `fallback`.
|
|
60
|
-
*/
|
|
61
43
|
export declare function createErrorBoundary(content: NixTemplate | NixComponent, fallback: ErrorFallback): NixTemplate;
|
|
62
|
-
/**
|
|
63
|
-
* Options for `transition()`. All class-name overrides are optional — by
|
|
64
|
-
* default they are derived from `name` (default `"nix"`).
|
|
65
|
-
*
|
|
66
|
-
* | phase | from class | active class | to class |
|
|
67
|
-
* |--------------|-------------------|---------------------|-----------------|
|
|
68
|
-
* | enter | `{n}-enter-from` | `{n}-enter-active` | `{n}-enter-to` |
|
|
69
|
-
* | leave | `{n}-leave-from` | `{n}-leave-active` | `{n}-leave-to` |
|
|
70
|
-
*/
|
|
71
44
|
export interface TransitionOptions {
|
|
72
|
-
/**
|
|
73
|
-
* Prefix for all generated CSS classes. Default `"nix"`.
|
|
74
|
-
* e.g. `name: "fade"` generates `.fade-enter-from`, `.fade-leave-to`, …
|
|
75
|
-
*/
|
|
76
45
|
name?: string;
|
|
77
|
-
/** Override the enter-from class individually. */
|
|
78
46
|
enterFrom?: string;
|
|
79
|
-
/** Override the enter-active class individually. */
|
|
80
47
|
enterActive?: string;
|
|
81
|
-
/** Override the enter-to class individually. */
|
|
82
48
|
enterTo?: string;
|
|
83
|
-
/** Override the leave-from class individually. */
|
|
84
49
|
leaveFrom?: string;
|
|
85
|
-
/** Override the leave-active class individually. */
|
|
86
50
|
leaveActive?: string;
|
|
87
|
-
/** Override the leave-to class individually. */
|
|
88
51
|
leaveTo?: string;
|
|
89
|
-
/**
|
|
90
|
-
* When `true` the enter transition also plays on the very first render
|
|
91
|
-
* (similar to Vue's `appear`). Default `false`.
|
|
92
|
-
*/
|
|
93
52
|
appear?: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Fallback duration in **milliseconds** used when no `transition-duration`
|
|
96
|
-
* or `animation-duration` is found on the element via `getComputedStyle`.
|
|
97
|
-
*/
|
|
98
53
|
duration?: number;
|
|
99
|
-
/** Called synchronously right before the enter classes are added. */
|
|
100
54
|
onBeforeEnter?: (el: Element) => void;
|
|
101
|
-
/** Called after the enter transition has fully completed. */
|
|
102
55
|
onAfterEnter?: (el: Element) => void;
|
|
103
|
-
/** Called synchronously right before the leave classes are added. */
|
|
104
56
|
onBeforeLeave?: (el: Element) => void;
|
|
105
|
-
/** Called after the leave transition has fully completed and the DOM is removed. */
|
|
106
57
|
onAfterLeave?: (el: Element) => void;
|
|
107
58
|
}
|
|
108
|
-
/** Content that can be wrapped with `transition()`. */
|
|
109
59
|
export type TransitionContent = NixTemplate | NixComponent | (() => NixTemplate | NixComponent | null);
|
|
110
|
-
/**
|
|
111
|
-
* Wraps content with CSS class-based enter/leave transitions.
|
|
112
|
-
* Static content plays enter on mount (only with `appear: true`).
|
|
113
|
-
* Reactive `() => Template | null` auto-animates enter/leave on toggle.
|
|
114
|
-
*/
|
|
115
60
|
export declare function transition(content: TransitionContent, options?: TransitionOptions): NixTemplate;
|
|
116
61
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): NixTemplate;
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=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=!1,s=new Set,c=i,f=()=>{if(!a){if("function"==typeof l&&l(),s.forEach(e=>e._removeSub(f)),s=new Set,t.push(e),r.push(n),e=f,n=s,++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(!c)throw e;c(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}}};return f(),()=>{a=!0,"function"==typeof l&&l(),s.forEach(e=>e._removeSub(f)),s.clear()}}function h(e){let t=new f(void 0),n=m(()=>{t.value=e()}),r=t.dispose.bind(t);return t.dispose=()=>{n(),r()},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 ee(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 D(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 O(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var k={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function A(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 ie(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 j(e,t,n,r){let o,l;ee(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 ae(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 oe(){return{__isPortalOutlet:!0,_container:null}}function se(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 ce(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)?A(e,o,null):e._render(o,null)}}}var le=S("nix:portal-outlet");function ue(e){D(le,e)}function de(){return O(le)}function fe(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(k.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)?ie(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 pe(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 me(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(me(r.transitionDuration||"0"),me(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 he(e,t={}){let n=pe(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(k.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)?ie(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 M(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 M(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 ge(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 _e(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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ve(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function P(e,t){let n=[],r=t;for(;r&&r!==e;){let e=r.parentNode,t=0,o=e.firstChild;for(;o&&o!==r;)t++,o=o.nextSibling;n.unshift(t),r=e}return n}function ye(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e],o=n.firstChild;for(let e=0;e<r;e++)o=o.nextSibling;n=o}return n}var F={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function be(e,t,n,r){let o=[],l=[],i=Array(t.length);for(let n=0;n<t.length;n++){let t=r[n];i[n]=t?ye(e,t.path):null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers,r={};n.includes("once")&&(r.once=!0),n.includes("capture")&&(r.capture=!0),n.includes("passive")&&(r.passive=!0);let l=e=>{if(n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),!n.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of n){let n=F[e];if(void 0!==n&&t.key!==n||!F[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}t(e)}};c.addEventListener(e,l,r),o.push(()=>c.removeEventListener(e,l,r));continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,o.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=m(()=>{let t=!!u(),o="show"===e?t:!t;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"});o.push(t)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r=m(()=>{let r=u();n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))});o.push(r)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;if("function"!=typeof u){if(x(u))ae(u,f.parentNode,f,l,o);else if(N(u)){let e=u._render(f.parentNode,f);o.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?ae(e,f.parentNode,f,l,o):N(e)?e._render(f.parentNode,f):null!=e&&!1!==e&&f.parentNode.insertBefore(document.createTextNode(String(e)),f);else null!=u&&!1!==u&&f.parentNode.insertBefore(document.createTextNode(String(u)),f);continue}let d=null,p=null,h=null,v=null,y=w(),g=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(d?d.nodeValue=String(e):(d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)));if(d&&=(d.parentNode?.removeChild(d),null),p&&=(p(),null),null!=e&&!1!==e)if(N(e))p=e._render(f.parentNode,f);else if(x(e))p=j(e,f.parentNode,f,y);else if(ve(e)){h||(h=new Map,v=document.createComment(k.KEYED_ZONE),f.parentNode.insertBefore(v,f));let t=f.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n),o=!1;if(h.size>0)for(let e of h.keys())if(r.has(e)){o=!0;break}if(!o){if(h.size>0){let e=document.createRange();e.setStartAfter(v),e.setEndBefore(f),e.deleteContents();for(let e of h.values())e.cleanup();h.clear()}if(n.length>0){let r=document.createDocumentFragment();for(let t=0;t<n.length;t++){let o=n[t],l=e.items[t],i=document.createComment(k.KEYED_START),a=document.createComment(k.KEYED_END);r.appendChild(i);let u=e.renderFn(l,t),s=x(u)?j(u,r,null,y):u._render(r,null);r.appendChild(a),h.set(o,{start:i,end:a,cleanup:s})}t.insertBefore(r,f)}return}for(let[e,t]of h.entries())if(!r.has(e)){t.cleanup();let n=t.start;for(;n;){let e=n===t.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!e)break;n=e}h.delete(e)}let l=f;for(let r=n.length-1;r>=0;r--){let o=n[r];if(h.has(o)){let e=h.get(o);if(e.end.nextSibling!==l){let n=e.start;for(;n;){let r=n===e.end?null:n.nextSibling;if(t.insertBefore(n,l),!r)break;n=r}}l=e.start}else{let o=r;for(;o>0&&!h.has(n[o-1]);)o--;let i=document.createDocumentFragment(),a=[];for(let t=o;t<=r;t++){let r=n[t],o=e.items[t],l=document.createComment(k.KEYED_START),u=document.createComment(k.KEYED_END);i.appendChild(l);let s=e.renderFn(o,t),c=x(s)?j(s,i,null,y):s._render(i,null);i.appendChild(u),a.push({key:r,start:l,end:u,cleanup:c})}t.insertBefore(i,l);for(let e of a)h.set(e.key,e);l=a[0].start,r=o}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(A(n,f.parentNode,f));else if(N(n))t.push(n._render(f.parentNode,f));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));f.parentNode.insertBefore(e,f),t.push(()=>e.parentNode?.removeChild(e))}p=()=>t.forEach(e=>e())}else d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)});o.push(()=>{if(g(),p&&=(p(),null),d&&=(d.parentNode?.removeChild(d),null),h){for(let e of h.values())e.cleanup();h=null,v=null}})}return{disposes:o,postMountHooks:l}}var xe=new WeakMap;function I(e,...t){let n=xe.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(ge(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=_e(e,t);let l,i=Array(t.length).fill(null),a=o.content,u=document.createTreeWalker(a,NodeFilter.SHOW_COMMENT);for(;l=u.nextNode();){let e=l,t=e.nodeValue?.match(/^nix-(\d+)$/);if(t){let n=parseInt(t[1]);i[n]={path:P(a,e)}}}a.querySelectorAll("*").forEach(e=>{let t=Array.from(e.attributes);for(let n of t){let t=n.name.match(/^data-nix-e-(\d+)$/);if(t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name);continue}if(t=n.name.match(/^data-nix-a-(\d+)$/),t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name)}}}),n={contexts:t,tpl:o,pathMap:i},xe.set(e,n)}let{contexts:r,tpl:o,pathMap:l}=n;function i(e,n){let i=o.content.cloneNode(!0),{disposes:a,postMountHooks:u}=be(i,r,t,l),s=document.createComment(k.SCOPE);return e.insertBefore(s,n),e.insertBefore(i,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function Se(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 Ce(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=p(e[t])}let o=n;let l=Object.assign(Object.create(null),o,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(l,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(o);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):l[t]=e[t]}return l}var L=null,R=null;function z(){if(!L)throw Error("[Nix] No active router. Call createRouter() first.");return L}function B(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function V(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 we(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 Te(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let o of e){let e=Te(t,o.path),l=[...n,o.component],i=we(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...H(o.children,e,l))}return r}function Ee(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 De(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},o=-1;for(let l of t){let t=Ee(e,l);if(null===t)continue;let i=De(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function W(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Oe(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return W(new URL(t,window.location.origin).pathname)}catch{return W(t)}}function ke(e,t){let n=null==t?.base?Oe():W(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=H(e),a=U(l,i),u=p(l),s=p(a?.params??{}),c=p(B(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?{}:B(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}}R&&=(R(),null);let x=()=>{let e=r(),t=u.value,n=c.value,l=U(e,i),a=B(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)+V(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+V(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=U(n,i);m(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",x),R=()=>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=U(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=U(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 L&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),L=b,queueMicrotask(()=>{v||m(l,"",U(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=U("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Ae(){return z()}var je=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=z(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<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=!1,s=new Set,c=i,f=()=>{if(!a){if("function"==typeof l&&l(),s.forEach(e=>e._removeSub(f)),s=new Set,t.push(e),r.push(n),e=f,n=s,++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(!c)throw e;c(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}}};return f(),()=>{a=!0,"function"==typeof l&&l(),s.forEach(e=>e._removeSub(f)),s.clear()}}function h(e){let t=new f(void 0),n=m(()=>{t.value=e()}),r=t.dispose.bind(t);return t.dispose=()=>{n(),r()},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 ee(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 D(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 O(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var k={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function A(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 ie(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 j(e,t,n,r){let o,l;ee(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 ae(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 oe(){return{__isPortalOutlet:!0,_container:null}}function se(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 ce(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)?A(e,o,null):e._render(o,null)}}}var le=S("nix:portal-outlet");function ue(e){D(le,e)}function de(){return O(le)}function fe(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(k.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)?ie(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 pe(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 me(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(me(r.transitionDuration||"0"),me(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 he(e,t={}){let n=pe(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(k.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)?ie(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 M(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 M(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 ge(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 _e(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+"";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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ve(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function P(e,t){let n=[],r=t;for(;r&&r!==e;){let e=r.parentNode,t=0,o=e.firstChild;for(;o&&o!==r;)t++,o=o.nextSibling;n.unshift(t),r=e}return n}function ye(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e],o=n.firstChild;for(let e=0;e<r;e++)o=o.nextSibling;n=o}return n}var F={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function be(e,t,n,r){let o=[],l=[],i=Array(t.length);for(let n=0;n<t.length;n++){let t=r[n];i[n]=t?ye(e,t.path):null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers,r={};n.includes("once")&&(r.once=!0),n.includes("capture")&&(r.capture=!0),n.includes("passive")&&(r.passive=!0);let l=e=>{if(n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),!n.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of n){let n=F[e];if(void 0!==n&&t.key!==n||!F[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}t(e)}};c.addEventListener(e,l,r),o.push(()=>c.removeEventListener(e,l,r));continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,o.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=m(()=>{let t=!!u(),o="show"===e?t:!t;null===r&&(r=n.style.display||""),n.style.display=o?r:"none"});o.push(t)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r=m(()=>{let r=u();n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))});o.push(r)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;if("function"!=typeof u){if(x(u))ae(u,f.parentNode,f,l,o);else if(N(u)){let e=u._render(f.parentNode,f);o.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?ae(e,f.parentNode,f,l,o):N(e)?e._render(f.parentNode,f):null!=e&&!1!==e&&f.parentNode.insertBefore(document.createTextNode(String(e)),f);else null!=u&&!1!==u&&f.parentNode.insertBefore(document.createTextNode(String(u)),f);continue}let d=null,p=null,h=null,v=null,y=w(),g=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(d?d.nodeValue=String(e):(d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)));if(d&&=(d.parentNode?.removeChild(d),null),p&&=(p(),null),null!=e&&!1!==e)if(N(e))p=e._render(f.parentNode,f);else if(x(e))p=j(e,f.parentNode,f,y);else if(ve(e)){h||(h=new Map,v=document.createComment(k.KEYED_ZONE),f.parentNode.insertBefore(v,f));let t=f.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n),o=!1;if(h.size>0)for(let e of h.keys())if(r.has(e)){o=!0;break}if(!o){if(h.size>0){let e=v.nextSibling;for(;e&&e!==f;){let n=e.nextSibling;t.removeChild(e),e=n}for(let e of h.values())e.cleanup();h.clear()}if(n.length>0){let r=document.createDocumentFragment();for(let t=0;t<n.length;t++){let o=n[t],l=e.items[t],i=document.createComment(k.KEYED_START),a=document.createComment(k.KEYED_END);r.appendChild(i);let u=e.renderFn(l,t),s=x(u)?j(u,r,null,y):u._render(r,null);r.appendChild(a),h.set(o,{start:i,end:a,cleanup:s})}t.insertBefore(r,f)}return}for(let[e,t]of h.entries())if(!r.has(e)){let n=t.start;for(;n;){let e=n===t.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!e)break;n=e}t.cleanup(),h.delete(e)}let l=f;for(let r=n.length-1;r>=0;r--){let o=n[r];if(h.has(o)){let e=h.get(o);if(e.end.nextSibling!==l){let n=e.start;for(;n;){let r=n===e.end?null:n.nextSibling;if(t.insertBefore(n,l),!r)break;n=r}}l=e.start}else{let o=r;for(;o>0&&!h.has(n[o-1]);)o--;let i=document.createDocumentFragment(),a=[];for(let t=o;t<=r;t++){let r=n[t],o=e.items[t],l=document.createComment(k.KEYED_START),u=document.createComment(k.KEYED_END);i.appendChild(l);let s=e.renderFn(o,t),c=x(s)?j(s,i,null,y):s._render(i,null);i.appendChild(u),a.push({key:r,start:l,end:u,cleanup:c})}t.insertBefore(i,l);for(let e of a)h.set(e.key,e);l=a[0].start,r=o}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(A(n,f.parentNode,f));else if(N(n))t.push(n._render(f.parentNode,f));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));f.parentNode.insertBefore(e,f),t.push(()=>e.parentNode?.removeChild(e))}p=()=>t.forEach(e=>e())}else d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)});o.push(()=>{if(g(),p&&=(p(),null),d&&=(d.parentNode?.removeChild(d),null),h){for(let e of h.values())e.cleanup();h=null,v=null}})}return{disposes:o,postMountHooks:l}}var xe=new WeakMap;function I(e,...t){let n=xe.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(ge(r)),r+="__nix__";let o=document.createElement("template");o.innerHTML=_e(e,t);let l,i=Array(t.length).fill(null),a=o.content,u=document.createTreeWalker(a,NodeFilter.SHOW_COMMENT);for(;l=u.nextNode();){let e=l,t=e.nodeValue?.match(/^nix-(\d+)$/);if(t){let n=parseInt(t[1]);i[n]={path:P(a,e)}}}a.querySelectorAll("*").forEach(e=>{let t=Array.from(e.attributes);for(let n of t){let t=n.name.match(/^data-nix-e-(\d+)$/);if(t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name);continue}if(t=n.name.match(/^data-nix-a-(\d+)$/),t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name)}}}),n={contexts:t,tpl:o,pathMap:i},xe.set(e,n)}let{contexts:r,tpl:o,pathMap:l}=n;function i(e,n){let i=o.content.cloneNode(!0),{disposes:a,postMountHooks:u}=be(i,r,t,l),s=document.createComment(k.SCOPE);return e.insertBefore(s,n),e.insertBefore(i,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function Se(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 Ce(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=p(e[t])}let o=n;let l=Object.assign(Object.create(null),o,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(l,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(o);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):l[t]=e[t]}return l}var L=null,R=null;function z(){if(!L)throw Error("[Nix] No active router. Call createRouter() first.");return L}function B(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function V(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 we(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 Te(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let o of e){let e=Te(t,o.path),l=[...n,o.component],i=we(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...H(o.children,e,l))}return r}function Ee(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 De(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},o=-1;for(let l of t){let t=Ee(e,l);if(null===t)continue;let i=De(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function W(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Oe(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return W(new URL(t,window.location.origin).pathname)}catch{return W(t)}}function ke(e,t){let n=null==t?.base?Oe():W(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=H(e),a=U(l,i),u=p(l),s=p(a?.params??{}),c=p(B(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?{}:B(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}}R&&=(R(),null);let x=()=>{let e=r(),t=u.value,n=c.value,l=U(e,i),a=B(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)+V(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+V(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=U(n,i);m(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",x),R=()=>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=U(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=U(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 L&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),L=b,queueMicrotask(()=>{v||m(l,"",U(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=U("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Ae(){return z()}var je=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=z(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Me=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return I`<a
|
|
4
4
|
href=${(z()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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=!1,s=new Set,c=i,f=()=>{if(!a){if("function"==typeof o&&o(),s.forEach(e=>e._removeSub(f)),s=new Set,t.push(e),r.push(n),e=f,n=s,++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(!c)throw e;c(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}}};return f(),()=>{a=!0,"function"==typeof o&&o(),s.forEach(e=>e._removeSub(f)),s.clear()}}function h(e){let t=new f(void 0),n=m(()=>{t.value=e()}),r=t.dispose.bind(t);return t.dispose=()=>{n(),r()},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 ee(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 D(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 O(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var k={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function A(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 ie(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 j(e,t,n,r){let l,o;ee(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 ae(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 oe(){return{__isPortalOutlet:!0,_container:null}}function se(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 ce(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)?A(e,l,null):e._render(l,null)}}}var le=S("nix:portal-outlet");function ue(e){D(le,e)}function de(){return O(le)}function fe(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(k.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)?ie(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 pe(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 me(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(me(r.transitionDuration||"0"),me(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 he(e,t={}){let n=pe(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(k.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)?ie(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 M(l,t.duration),u===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{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 M(r,t.duration),u===l&&(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,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,h?.(),i?.(),a?.(),i=null,a=null,o.remove()}}}}function ge(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 _e(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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ve(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function P(e,t){let n=[],r=t;for(;r&&r!==e;){let e=r.parentNode,t=0,l=e.firstChild;for(;l&&l!==r;)t++,l=l.nextSibling;n.unshift(t),r=e}return n}function ye(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e],l=n.firstChild;for(let e=0;e<r;e++)l=l.nextSibling;n=l}return n}var F={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function be(e,t,n,r){let l=[],o=[],i=Array(t.length);for(let n=0;n<t.length;n++){let t=r[n];i[n]=t?ye(e,t.path):null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers,r={};n.includes("once")&&(r.once=!0),n.includes("capture")&&(r.capture=!0),n.includes("passive")&&(r.passive=!0);let o=e=>{if(n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),!n.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of n){let n=F[e];if(void 0!==n&&t.key!==n||!F[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}t(e)}};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r));continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,l.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=m(()=>{let t=!!u(),l="show"===e?t:!t;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"});l.push(t)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r=m(()=>{let r=u();n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))});l.push(r)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;if("function"!=typeof u){if(x(u))ae(u,f.parentNode,f,o,l);else if(N(u)){let e=u._render(f.parentNode,f);l.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?ae(e,f.parentNode,f,o,l):N(e)?e._render(f.parentNode,f):null!=e&&!1!==e&&f.parentNode.insertBefore(document.createTextNode(String(e)),f);else null!=u&&!1!==u&&f.parentNode.insertBefore(document.createTextNode(String(u)),f);continue}let d=null,p=null,h=null,v=null,y=w(),g=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(d?d.nodeValue=String(e):(d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)));if(d&&=(d.parentNode?.removeChild(d),null),p&&=(p(),null),null!=e&&!1!==e)if(N(e))p=e._render(f.parentNode,f);else if(x(e))p=j(e,f.parentNode,f,y);else if(ve(e)){h||(h=new Map,v=document.createComment(k.KEYED_ZONE),f.parentNode.insertBefore(v,f));let t=f.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n),l=!1;if(h.size>0)for(let e of h.keys())if(r.has(e)){l=!0;break}if(!l){if(h.size>0){let e=document.createRange();e.setStartAfter(v),e.setEndBefore(f),e.deleteContents();for(let e of h.values())e.cleanup();h.clear()}if(n.length>0){let r=document.createDocumentFragment();for(let t=0;t<n.length;t++){let l=n[t],o=e.items[t],i=document.createComment(k.KEYED_START),a=document.createComment(k.KEYED_END);r.appendChild(i);let u=e.renderFn(o,t),s=x(u)?j(u,r,null,y):u._render(r,null);r.appendChild(a),h.set(l,{start:i,end:a,cleanup:s})}t.insertBefore(r,f)}return}for(let[e,t]of h.entries())if(!r.has(e)){t.cleanup();let n=t.start;for(;n;){let e=n===t.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!e)break;n=e}h.delete(e)}let o=f;for(let r=n.length-1;r>=0;r--){let l=n[r];if(h.has(l)){let e=h.get(l);if(e.end.nextSibling!==o){let n=e.start;for(;n;){let r=n===e.end?null:n.nextSibling;if(t.insertBefore(n,o),!r)break;n=r}}o=e.start}else{let l=r;for(;l>0&&!h.has(n[l-1]);)l--;let i=document.createDocumentFragment(),a=[];for(let t=l;t<=r;t++){let r=n[t],l=e.items[t],o=document.createComment(k.KEYED_START),u=document.createComment(k.KEYED_END);i.appendChild(o);let s=e.renderFn(l,t),c=x(s)?j(s,i,null,y):s._render(i,null);i.appendChild(u),a.push({key:r,start:o,end:u,cleanup:c})}t.insertBefore(i,o);for(let e of a)h.set(e.key,e);o=a[0].start,r=l}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(A(n,f.parentNode,f));else if(N(n))t.push(n._render(f.parentNode,f));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));f.parentNode.insertBefore(e,f),t.push(()=>e.parentNode?.removeChild(e))}p=()=>t.forEach(e=>e())}else d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)});l.push(()=>{if(g(),p&&=(p(),null),d&&=(d.parentNode?.removeChild(d),null),h){for(let e of h.values())e.cleanup();h=null,v=null}})}return{disposes:l,postMountHooks:o}}var xe=new WeakMap;function I(e,...t){let n=xe.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(ge(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=_e(e,t);let o,i=Array(t.length).fill(null),a=l.content,u=document.createTreeWalker(a,NodeFilter.SHOW_COMMENT);for(;o=u.nextNode();){let e=o,t=e.nodeValue?.match(/^nix-(\d+)$/);if(t){let n=parseInt(t[1]);i[n]={path:P(a,e)}}}a.querySelectorAll("*").forEach(e=>{let t=Array.from(e.attributes);for(let n of t){let t=n.name.match(/^data-nix-e-(\d+)$/);if(t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name);continue}if(t=n.name.match(/^data-nix-a-(\d+)$/),t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name)}}}),n={contexts:t,tpl:l,pathMap:i},xe.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:a,postMountHooks:u}=be(i,r,t,o),s=document.createComment(k.SCOPE);return e.insertBefore(s,n),e.insertBefore(i,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function Se(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 Ce(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=p(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var L=null,R=null;function z(){if(!L)throw Error("[Nix] No active router. Call createRouter() first.");return L}function B(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function V(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 we(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 Te(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let l of e){let e=Te(t,l.path),o=[...n,l.component],i=we(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...H(l.children,e,o))}return r}function Ee(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 De(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},l=-1;for(let o of t){let t=Ee(e,o);if(null===t)continue;let i=De(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function W(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Oe(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return W(new URL(t,window.location.origin).pathname)}catch{return W(t)}}function ke(e,t){let n=null==t?.base?Oe():W(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=H(e),a=U(o,i),u=p(o),s=p(a?.params??{}),c=p(B(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?{}:B(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}}R&&=(R(),null);let g=()=>{let e=r(),t=u.value,n=c.value,o=U(e,i),a=B(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)+V(n))})};function _(e,t,n,r,o){s.value=r?.params??{},c.value=t,u.value=e;let i=l(e)+V(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=U(n,i);m(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!1))}window.addEventListener("popstate",g),R=()=>window.removeEventListener("popstate",g);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=U(n,i);m(n,l,o?.route.beforeEnter,()=>_(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=U(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 L&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),L=x,queueMicrotask(()=>{v||m(o,"",U(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=U("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function Ae(){return z()}var je=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=z(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<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=!1,s=new Set,c=i,f=()=>{if(!a){if("function"==typeof o&&o(),s.forEach(e=>e._removeSub(f)),s=new Set,t.push(e),r.push(n),e=f,n=s,++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(!c)throw e;c(e)}finally{d--,e=t.pop()||null,n=r.pop()||null}}};return f(),()=>{a=!0,"function"==typeof o&&o(),s.forEach(e=>e._removeSub(f)),s.clear()}}function h(e){let t=new f(void 0),n=m(()=>{t.value=e()}),r=t.dispose.bind(t);return t.dispose=()=>{n(),r()},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 ee(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 D(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 O(e){for(let t=C.length-1;t>=0;t--)if(C[t].has(e))return C[t].get(e)}var k={SCOPE:"nix-scope",ERROR_BOUNDARY:"nix-eb",TRANSITION:"nix-t",KEYED_START:"nix-ks",KEYED_END:"nix-ke",KEYED_ZONE:"nix-kz"};function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function A(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 ie(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 j(e,t,n,r){let l,o;ee(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 ae(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 oe(){return{__isPortalOutlet:!0,_container:null}}function se(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 ce(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)?A(e,l,null):e._render(l,null)}}}var le=S("nix:portal-outlet");function ue(e){D(le,e)}function de(){return O(le)}function fe(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(k.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)?ie(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 pe(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 me(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e.trim())||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),l=1e3*Math.max(me(r.transitionDuration||"0"),me(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 he(e,t={}){let n=pe(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(k.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)?ie(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 M(l,t.duration),u===e&&(l.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(l)))})().catch(()=>{})}s=!1},p=()=>{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 M(r,t.duration),u===l&&(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,l=null===e;r&&!l?d(e):!r&&l?p():!r&&!l&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,h?.(),i?.(),a?.(),i=null,a=null,o.remove()}}}}function ge(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 _e(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+"";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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function ve(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function P(e,t){let n=[],r=t;for(;r&&r!==e;){let e=r.parentNode,t=0,l=e.firstChild;for(;l&&l!==r;)t++,l=l.nextSibling;n.unshift(t),r=e}return n}function ye(e,t){let n=e;for(let e=0;e<t.length;e++){let r=t[e],l=n.firstChild;for(let e=0;e<r;e++)l=l.nextSibling;n=l}return n}var F={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"};function be(e,t,n,r){let l=[],o=[],i=Array(t.length);for(let n=0;n<t.length;n++){let t=r[n];i[n]=t?ye(e,t.path):null}for(let e=0;e<t.length;e++){let a=t[e],u=n[e],s=r[e];if(!s)continue;let c=i[e];if("event"===a.type){let e=s.name,t=u,n=a.modifiers,r={};n.includes("once")&&(r.once=!0),n.includes("capture")&&(r.capture=!0),n.includes("passive")&&(r.passive=!0);let o=e=>{if(n.includes("prevent")&&e.preventDefault(),n.includes("stop")&&e.stopPropagation(),!n.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of n){let n=F[e];if(void 0!==n&&t.key!==n||!F[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}t(e)}};c.addEventListener(e,o,r),l.push(()=>c.removeEventListener(e,o,r));continue}if("attr"===a.type){let e=s.name,t=c;if("ref"===e){u.el=t,l.push(()=>{u.el=null});continue}if("show"===e||"hide"===e){let n=t,r=null;if("function"==typeof u){let t=m(()=>{let t=!!u(),l="show"===e?t:!t;null===r&&(r=n.style.display||""),n.style.display=l?r:"none"});l.push(t)}else("show"===e?u:!u)||(n.style.display="none");continue}let n=("value"===e||"checked"===e||"selected"===e)&&e in t;if("function"==typeof u){let r=m(()=>{let r=u();n?t[e]=r??"":null==r||!1===r?t.removeAttribute(e):t.setAttribute(e,String(r))});l.push(r)}else n?t[e]=u??"":null!=u&&!1!==u&&t.setAttribute(e,String(u));continue}let f=c;if(!f)continue;if("function"!=typeof u){if(x(u))ae(u,f.parentNode,f,o,l);else if(N(u)){let e=u._render(f.parentNode,f);l.push(e)}else if(Array.isArray(u))for(let e of u)x(e)?ae(e,f.parentNode,f,o,l):N(e)?e._render(f.parentNode,f):null!=e&&!1!==e&&f.parentNode.insertBefore(document.createTextNode(String(e)),f);else null!=u&&!1!==u&&f.parentNode.insertBefore(document.createTextNode(String(u)),f);continue}let d=null,p=null,h=null,v=null,y=w(),g=m(()=>{let e=u();if("string"==typeof e||"number"==typeof e)return p&&=(p(),null),void(d?d.nodeValue=String(e):(d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)));if(d&&=(d.parentNode?.removeChild(d),null),p&&=(p(),null),null!=e&&!1!==e)if(N(e))p=e._render(f.parentNode,f);else if(x(e))p=j(e,f.parentNode,f,y);else if(ve(e)){h||(h=new Map,v=document.createComment(k.KEYED_ZONE),f.parentNode.insertBefore(v,f));let t=f.parentNode,n=e.items.map((t,n)=>e.keyFn(t,n)),r=new Set(n),l=!1;if(h.size>0)for(let e of h.keys())if(r.has(e)){l=!0;break}if(!l){if(h.size>0){let e=v.nextSibling;for(;e&&e!==f;){let n=e.nextSibling;t.removeChild(e),e=n}for(let e of h.values())e.cleanup();h.clear()}if(n.length>0){let r=document.createDocumentFragment();for(let t=0;t<n.length;t++){let l=n[t],o=e.items[t],i=document.createComment(k.KEYED_START),a=document.createComment(k.KEYED_END);r.appendChild(i);let u=e.renderFn(o,t),s=x(u)?j(u,r,null,y):u._render(r,null);r.appendChild(a),h.set(l,{start:i,end:a,cleanup:s})}t.insertBefore(r,f)}return}for(let[e,t]of h.entries())if(!r.has(e)){let n=t.start;for(;n;){let e=n===t.end?null:n.nextSibling;if(n.parentNode?.removeChild(n),!e)break;n=e}t.cleanup(),h.delete(e)}let o=f;for(let r=n.length-1;r>=0;r--){let l=n[r];if(h.has(l)){let e=h.get(l);if(e.end.nextSibling!==o){let n=e.start;for(;n;){let r=n===e.end?null:n.nextSibling;if(t.insertBefore(n,o),!r)break;n=r}}o=e.start}else{let l=r;for(;l>0&&!h.has(n[l-1]);)l--;let i=document.createDocumentFragment(),a=[];for(let t=l;t<=r;t++){let r=n[t],l=e.items[t],o=document.createComment(k.KEYED_START),u=document.createComment(k.KEYED_END);i.appendChild(o);let s=e.renderFn(l,t),c=x(s)?j(s,i,null,y):s._render(i,null);i.appendChild(u),a.push({key:r,start:o,end:u,cleanup:c})}t.insertBefore(i,o);for(let e of a)h.set(e.key,e);o=a[0].start,r=l}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n))t.push(A(n,f.parentNode,f));else if(N(n))t.push(n._render(f.parentNode,f));else if(null!=n&&!1!==n){let e=document.createTextNode(String(n));f.parentNode.insertBefore(e,f),t.push(()=>e.parentNode?.removeChild(e))}p=()=>t.forEach(e=>e())}else d=document.createTextNode(String(e)),f.parentNode.insertBefore(d,f)});l.push(()=>{if(g(),p&&=(p(),null),d&&=(d.parentNode?.removeChild(d),null),h){for(let e of h.values())e.cleanup();h=null,v=null}})}return{disposes:l,postMountHooks:o}}var xe=new WeakMap;function I(e,...t){let n=xe.get(e);if(!n){let t=[],r="";for(let n=0;n<e.length-1;n++)r+=e[n],t.push(ge(r)),r+="__nix__";let l=document.createElement("template");l.innerHTML=_e(e,t);let o,i=Array(t.length).fill(null),a=l.content,u=document.createTreeWalker(a,NodeFilter.SHOW_COMMENT);for(;o=u.nextNode();){let e=o,t=e.nodeValue?.match(/^nix-(\d+)$/);if(t){let n=parseInt(t[1]);i[n]={path:P(a,e)}}}a.querySelectorAll("*").forEach(e=>{let t=Array.from(e.attributes);for(let n of t){let t=n.name.match(/^data-nix-e-(\d+)$/);if(t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name);continue}if(t=n.name.match(/^data-nix-a-(\d+)$/),t){let r=parseInt(t[1]);i[r]={path:P(a,e),name:n.value},e.removeAttribute(n.name)}}}),n={contexts:t,tpl:l,pathMap:i},xe.set(e,n)}let{contexts:r,tpl:l,pathMap:o}=n;function i(e,n){let i=l.content.cloneNode(!0),{disposes:a,postMountHooks:u}=be(i,r,t,o),s=document.createComment(k.SCOPE);return e.insertBefore(s,n),e.insertBefore(i,n),u.forEach(e=>e()),()=>{for(let e=a.length-1;e>=0;e--)a[e]();let e=s.nextSibling;for(;e&&e!==n;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:i,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=i(t,null);return{unmount(){n()}}}}}function Se(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 Ce(e,t){let n={},r=new Set(["$reset","$patch","$state"]);for(let t of Object.keys(e)){if(r.has(t))throw Error(`[Nix] Store key "${t}" is reserved.`);n[t]=p(e[t])}let l=n;let o=Object.assign(Object.create(null),l,{$reset:function(){for(let t of Object.keys(e))n[t].value=e[t]},$patch:function(e){for(let t of Object.keys(e))t in n&&(n[t].value=e[t])}});if(Object.defineProperty(o,"$state",{get(){let e={};for(let t in n)e[t]=n[t].value;return e},enumerable:!0,configurable:!1}),t){let e=t(l);for(let t of Object.keys(e))r.has(t)?console.warn(`[Nix] Store action name "${t}" is reserved and will be ignored.`):o[t]=e[t]}return o}var L=null,R=null;function z(){if(!L)throw Error("[Nix] No active router. Call createRouter() first.");return L}function B(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function V(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 we(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 Te(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function H(e,t="",n=[]){let r=[];for(let l of e){let e=Te(t,l.path),o=[...n,l.component],i=we(e);r.push({fullPath:e,segments:i,chain:o,beforeEnter:l.beforeEnter}),l.children?.length&&r.push(...H(l.children,e,o))}return r}function Ee(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 De(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function U(e,t){let n,r={},l=-1;for(let o of t){let t=Ee(e,o);if(null===t)continue;let i=De(o);i>l&&(n=o,r=t,l=i)}return n?{route:n,params:r}:void 0}function W(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function Oe(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return W(new URL(t,window.location.origin).pathname)}catch{return W(t)}}function ke(e,t){let n=null==t?.base?Oe():W(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=H(e),a=U(o,i),u=p(o),s=p(a?.params??{}),c=p(B(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?{}:B(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}}R&&=(R(),null);let g=()=>{let e=r(),t=u.value,n=c.value,o=U(e,i),a=B(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)+V(n))})};function _(e,t,n,r,o){s.value=r?.params??{},c.value=t,u.value=e;let i=l(e)+V(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=U(n,i);m(n,l,o?.route.beforeEnter,()=>_(n,r,l,o,!1))}window.addEventListener("popstate",g),R=()=>window.removeEventListener("popstate",g);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=U(n,i);m(n,l,o?.route.beforeEnter,()=>_(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=U(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 L&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),L=x,queueMicrotask(()=>{v||m(o,"",U(o,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",l("/"));let e=U("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function Ae(){return z()}var je=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return I`<div class="router-view">${()=>{let t=z(),n=U(t.current.value,t._flat);return n?e>=n.route.chain.length?I`<span></span>`:n.route.chain[e]():I`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
3
|
</div>`}}</div>`}},Me=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return I`<a
|
|
4
4
|
href=${(z()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.7.2-beta.
|
|
3
|
+
"version": "1.7.2-beta.5",
|
|
4
4
|
"description": "A lightweight, fully reactive micro-framework — no virtual DOM, no compiler, just signals and tagged templates.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://nix-js-landing.vercel.app/",
|