@deijose/nix-js 1.1.3 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/nix/async.d.ts +60 -6
- package/dist/lib/nix/index.d.ts +2 -2
- package/dist/lib/nix/router.d.ts +28 -2
- package/dist/lib/nix-js.cjs +8 -8
- package/dist/lib/nix-js.js +8 -8
- package/package.json +1 -1
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet, createErrorBoundary, transition, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, createQuery, invalidateQueries, provide, inject, createInjectionKey, useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
|
-
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, PortalOutlet, ErrorFallback, TransitionOptions, TransitionContent, Store, StoreSignals, Router, RouteRecord, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute, SuspenseOptions, QueryOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
|
1
|
+
export { Signal, signal, effect, computed, batch, watch, untrack, nextTick, html, repeat, ref, showWhen, portal, createPortalOutlet, portalOutlet, provideOutlet, injectOutlet, createErrorBoundary, transition, mount, NixComponent, createStore, createRouter, RouterView, Link, useRouter, suspend, lazy, createQuery, invalidateQueries, clearQueryCache, setQueryCacheTime, provide, inject, createInjectionKey, useField, createForm, required, minLength, maxLength, email, pattern, min, max, createValidator, validators, extendValidators, } from "./nix";
|
|
2
|
+
export type { WatchOptions, NixTemplate, NixMountHandle, KeyedList, NixRef, PortalOutlet, ErrorFallback, TransitionOptions, TransitionContent, Store, StoreSignals, Router, RouteRecord, RouterOptions, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute, SuspenseOptions, QueryOptions, InjectionKey, Validator, FieldState, FieldErrors, FormState, FormOptions, ValidatorsBase, NixChildren, } from "./nix";
|
package/dist/lib/nix/async.d.ts
CHANGED
|
@@ -10,7 +10,31 @@ export interface SuspenseOptions {
|
|
|
10
10
|
resetOnRefresh?: boolean;
|
|
11
11
|
/** Signal that triggers a re-fetch when its value changes. DOM is reused. */
|
|
12
12
|
invalidate?: Signal<unknown>;
|
|
13
|
+
/**
|
|
14
|
+
* Optional cache key. When provided, resolved data is cached globally
|
|
15
|
+
* so that subsequent mounts with the same key render cached data instantly,
|
|
16
|
+
* similar to `createQuery` caching behaviour.
|
|
17
|
+
*/
|
|
18
|
+
cacheKey?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Time in milliseconds that cached data is considered fresh.
|
|
21
|
+
* While fresh, no background refetch happens on mount.
|
|
22
|
+
* Only used when `cacheKey` is set.
|
|
23
|
+
* @default 0 (always stale — refetch in background on every mount)
|
|
24
|
+
*/
|
|
25
|
+
staleTime?: number;
|
|
13
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Clear the query cache.
|
|
29
|
+
* - Call with no arguments to clear **all** cached data.
|
|
30
|
+
* - Pass a specific `key` to clear only that entry.
|
|
31
|
+
*/
|
|
32
|
+
export declare function clearQueryCache(key?: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Set the global cache time (how long unused entries persist).
|
|
35
|
+
* @param ms Time in milliseconds. Pass `Infinity` to keep entries forever.
|
|
36
|
+
*/
|
|
37
|
+
export declare function setQueryCacheTime(ms: number): void;
|
|
14
38
|
/**
|
|
15
39
|
* Runs an async function and renders based on its state (pending/resolved/error).
|
|
16
40
|
* Equivalent to the Suspense pattern in other frameworks.
|
|
@@ -21,9 +45,18 @@ export interface SuspenseOptions {
|
|
|
21
45
|
* suspend(() => fetchData(), render, { invalidate: refresh });
|
|
22
46
|
* // later: refresh.update(n => n + 1);
|
|
23
47
|
* ```
|
|
48
|
+
*
|
|
49
|
+
* Pass `cacheKey` to enable caching — subsequent mounts render cached data
|
|
50
|
+
* instantly without a loading spinner:
|
|
51
|
+
* ```ts
|
|
52
|
+
* suspend(() => fetchProfile(), render, { cacheKey: "profile" });
|
|
53
|
+
* ```
|
|
24
54
|
*/
|
|
25
55
|
export declare function suspend<T>(asyncFn: () => Promise<T>, renderFn: (data: T) => NixTemplate | NixComponent, options?: SuspenseOptions): NixComponent;
|
|
26
|
-
/**
|
|
56
|
+
/**
|
|
57
|
+
* Force all active `createQuery()` instances with the given key to re-fetch.
|
|
58
|
+
* Also clears the cached data for this key so subsequent mounts will refetch.
|
|
59
|
+
*/
|
|
27
60
|
export declare function invalidateQueries(key: string): void;
|
|
28
61
|
export interface QueryOptions {
|
|
29
62
|
/** Template shown while the promise is pending. */
|
|
@@ -32,16 +65,37 @@ export interface QueryOptions {
|
|
|
32
65
|
errorFallback?: (err: unknown) => NixTemplate;
|
|
33
66
|
/** If `true`, shows fallback during re-fetches instead of stale content. */
|
|
34
67
|
resetOnRefresh?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Time in ms that cached data is considered fresh.
|
|
70
|
+
* While fresh, mounting the query will **not** refetch — it renders cached
|
|
71
|
+
* data instantly. Set to `Infinity` to never auto-refetch.
|
|
72
|
+
* @default 0 (always stale — background refetch on every mount)
|
|
73
|
+
*/
|
|
74
|
+
staleTime?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Controls whether a background refetch happens when the component mounts.
|
|
77
|
+
* - `"always"` — always refetch on mount (default; stale data shown instantly
|
|
78
|
+
* while the refetch runs in the background).
|
|
79
|
+
* - `"stale"` — refetch only if cached data has exceeded `staleTime`.
|
|
80
|
+
* - `false` — never refetch on mount; only manual `invalidateQueries()` refetches.
|
|
81
|
+
* @default "always"
|
|
82
|
+
*/
|
|
83
|
+
refetchOnMount?: "always" | "stale" | false;
|
|
35
84
|
}
|
|
36
85
|
/**
|
|
37
|
-
* Key-based async data fetching with
|
|
86
|
+
* Key-based async data fetching with **built-in caching** and global
|
|
87
|
+
* cache invalidation, similar to React Query / TanStack Query.
|
|
88
|
+
*
|
|
89
|
+
* Cached data is stored globally by `key`. When a component using
|
|
90
|
+
* `createQuery` mounts:
|
|
91
|
+
* 1. If cached data exists, it is rendered **immediately** (no loading spinner).
|
|
92
|
+
* 2. A background refetch runs (unless the data is still "fresh" per `staleTime`).
|
|
93
|
+
* 3. When the refetch resolves, the UI updates seamlessly.
|
|
38
94
|
*
|
|
39
95
|
* ```ts
|
|
40
|
-
* createQuery("reservations", () => api.getAll(),
|
|
41
|
-
* renderFn: (data) => html`...`,
|
|
42
|
-
* });
|
|
96
|
+
* createQuery("reservations", () => api.getAll(), (data) => html`...`);
|
|
43
97
|
*
|
|
44
|
-
* // After a mutation —
|
|
98
|
+
* // After a mutation — clears cache & all active instances re-fetch:
|
|
45
99
|
* invalidateQueries("reservations");
|
|
46
100
|
* ```
|
|
47
101
|
*/
|
package/dist/lib/nix/index.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export type { NixChildren } from "./lifecycle";
|
|
|
8
8
|
export { createStore } from "./store";
|
|
9
9
|
export type { Store, StoreSignals } from "./store";
|
|
10
10
|
export { createRouter, RouterView, Link, useRouter } from "./router";
|
|
11
|
-
export type { Router, RouteRecord, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute } from "./router";
|
|
12
|
-
export { suspend, lazy, createQuery, invalidateQueries } from "./async";
|
|
11
|
+
export type { Router, RouteRecord, RouterOptions, NavigationGuard, NavigationGuardResult, AfterEachHook, ResolvedRoute } from "./router";
|
|
12
|
+
export { suspend, lazy, createQuery, invalidateQueries, clearQueryCache, setQueryCacheTime } from "./async";
|
|
13
13
|
export type { SuspenseOptions, QueryOptions } from "./async";
|
|
14
14
|
export { provide, inject, createInjectionKey } from "./context";
|
|
15
15
|
export type { InjectionKey } from "./context";
|
package/dist/lib/nix/router.d.ts
CHANGED
|
@@ -35,13 +35,36 @@ export interface ResolvedRoute {
|
|
|
35
35
|
/** The matched route record, or `undefined` if no match. */
|
|
36
36
|
route: RouteRecord | undefined;
|
|
37
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Options for `createRouter()`.
|
|
40
|
+
*/
|
|
41
|
+
export interface RouterOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Base path for the application.
|
|
44
|
+
* Useful when deploying under a sub-path (e.g. GitHub Pages).
|
|
45
|
+
*
|
|
46
|
+
* If omitted, the router auto-detects the base from the `<base href>` tag
|
|
47
|
+
* that tools like Vite inject when you set `base` in your config.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // vite.config.ts sets base: "/my-app/"
|
|
51
|
+
* // No need to pass base — auto-detected from <base href>
|
|
52
|
+
* createRouter(routes);
|
|
53
|
+
*
|
|
54
|
+
* // Or pass it explicitly:
|
|
55
|
+
* createRouter(routes, { base: "/my-app/" });
|
|
56
|
+
*/
|
|
57
|
+
base?: string;
|
|
58
|
+
}
|
|
38
59
|
export interface Router {
|
|
39
|
-
/** Signal with the current active pathname. */
|
|
60
|
+
/** Signal with the current active pathname (without the base prefix). */
|
|
40
61
|
readonly current: Signal<string>;
|
|
41
62
|
/** Signal with the extracted dynamic route params. */
|
|
42
63
|
readonly params: Signal<Record<string, string>>;
|
|
43
64
|
/** Signal with the URL query params. */
|
|
44
65
|
readonly query: Signal<Record<string, string>>;
|
|
66
|
+
/** The resolved base path used by the router. */
|
|
67
|
+
readonly base: string;
|
|
45
68
|
/** Navigate to a new path via `pushState`. Guards run before committing. */
|
|
46
69
|
navigate(path: string, query?: Record<string, string | number | boolean | null | undefined>): void;
|
|
47
70
|
/** Navigate via `replaceState` (no new history entry). Guards still run. */
|
|
@@ -66,8 +89,11 @@ export interface Router {
|
|
|
66
89
|
/**
|
|
67
90
|
* Creates the History API router and sets it as the active singleton.
|
|
68
91
|
* In production the server must serve `index.html` for all non-file routes.
|
|
92
|
+
*
|
|
93
|
+
* @param routes The route tree.
|
|
94
|
+
* @param options Optional configuration — use `base` for sub-path deployments.
|
|
69
95
|
*/
|
|
70
|
-
export declare function createRouter(routes: RouteRecord[]): Router;
|
|
96
|
+
export declare function createRouter(routes: RouteRecord[], options?: RouterOptions): Router;
|
|
71
97
|
/** Returns the active router singleton. */
|
|
72
98
|
export declare function useRouter(): Router;
|
|
73
99
|
/**
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=[],n=null,r=[],i=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,u=!0,a=!1,s=m(()=>{let e=i();if(u){if(u=!1,o&&!a){let n=e;_(()=>t(n,void 0)),l&&(a=!0,Promise.resolve().then(s))}r=e}else if(!a){let n=e,o=r;r=e,_(()=>t(n,o)),l&&(a=!0,Promise.resolve().then(s))}});return()=>{a=!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)}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,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 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(n,r){let o;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)){let t,n;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}var A=S("nix:portal-outlet");function oe(e){O(A,e)}function se(){return k(A)}function ce(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("nix-eb");n.insertBefore(l,r);let i,u=null,a=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||x(t)?t:t(e);if(x(o)){let e,t;T();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{E()}try{let e=o.onMount?.();"function"==typeof e&&(t=e)}catch{}u=()=>{try{o.onUnmount?.()}catch{}t?.(),e()}}else u=o._render(n,r)};o(e=>{a||(a=!0,c?(u?.(),u=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)}u=e.render()._render(n,r)}finally{E()}if(!a)try{let t=e.onMount?.(),n=u;u=()=>{try{e.onUnmount?.()}catch{}if("function"==typeof t)try{t()}catch{}n?.()}}catch(t){if(!e.onError)throw t;e.onError(t)}}else u=e._render(n,r)}catch(e){a=!0,u?.(),u=null,i=e,f=!0}finally{s(),c=!0}return f&&(u?.(),u=null,d(i)),()=>{u?.(),l.remove()}}}}function le(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 j(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(j(r.transitionDuration||"0"),j(r.animationDuration||"0")),l=o>0?o+100:t>0?t:0;if(l<=0)return void n();let i,u=t=>{t.target===e&&(clearTimeout(i),e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n())};e.addEventListener("transitionend",u),e.addEventListener("animationend",u),i=setTimeout(()=>{e.removeEventListener("transitionend",u),e.removeEventListener("animationend",u),n()},l)})}function ue(e,t={}){let n=le(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("nix-t");r.insertBefore(l,o);let i=null,u=null,a=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){if(x(e)){let t,n=e;T();try{try{n.onInit?.()}catch{}t=n.render()}finally{E()}let l,i=t._render(r,o);try{l=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof l)try{l()}catch{}i()}}return e._render(r,o)}let d=(e,r=!1)=>{a++,u&&=(u(),null),i=f(e);let o=c();if(o&&(!s||t.appear)&&!r){let e=a;(async()=>{t.onBeforeEnter?.(o),o.classList.add(n.enterFrom,n.enterActive),o.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===e&&(o.classList.remove(n.enterFrom),o.classList.add(n.enterTo),await M(o,t.duration),a===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=++a;u=e??null,(async()=>{t.onBeforeLeave?.(r),r.classList.add(n.leaveFrom,n.leaveActive),r.getBoundingClientRect(),await new Promise(e=>requestAnimationFrame(()=>e())),a===o&&(r.classList.remove(n.leaveFrom),r.classList.add(n.leaveTo),await M(r,t.duration),a===o&&(r.classList.remove(n.leaveActive,n.leaveTo),t.onAfterLeave?.(r),u?.(),u=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&&(a++,u?.(),u=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{a++,h?.(),i?.(),u?.(),i=null,u=null,l.remove()}}}}function de(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 fe(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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function pe(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function me(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 he(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ge(e,t,n){let r=[],o=[],l=me(e),i=he(e);for(let e=0;e<t.length;e++){let u=t[e],a=n[e];if("event"===u.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=a,s=u.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===u.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){a.el=n,r.push(()=>{a.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof a){let n=m(()=>{let n=!!a(),r="show"===o?n:!n;null===t&&(t=e.style.display||""),e.style.display=r?t:"none"});r.push(n)}else("show"===o?a:!a)||(n.style.display="none");continue}let l=("value"===o||"checked"===o||"selected"===o)&&o in n;if("function"==typeof a){let e=m(()=>{let e=a();l?n[o]=e??"":null==e||!1===e?n.removeAttribute(o):n.setAttribute(o,String(e))});r.push(e)}else l?n[o]=a??"":null!=a&&!1!==a&&n.setAttribute(o,String(a));continue}let s=l.get(e);if(!s)continue;if("function"!=typeof a){if(x(a)){let e,n,l=a;T();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(N(a)){let e=a._render(s.parentNode,s);r.push(e)}else if(Array.isArray(a))for(let e of a)if(x(e)){let n,l;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else N(e)?e._render(s.parentNode,s):null!=e&&!1!==e&&s.parentNode.insertBefore(document.createTextNode(String(e)),s);else null!=a&&!1!==a&&s.parentNode.insertBefore(document.createTextNode(String(a)),s);continue}let c=null,f=null,d=null,p=w(),h=m(()=>{let e=a();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(N(e))f=e._render(s.parentNode,s);else if(x(e)){let t,n,r=e;D(p,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}f=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(pe(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("nix-ke"),u=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(u,n);let a,s=e.renderFn(i,r);if(x(s)){let r,o;D(p,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}a=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else a=s._render(t,n);d.set(l,{start:u,end:n,cleanup:a}),o=u}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(N(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 P(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=de(r);n.push(o),r+="__nix__"}let o=fe(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:u,postMountHooks:a}=ge(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return a.forEach(e=>e()),()=>{u.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function _e(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 ve(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 F=null,I=null;function L(){if(!F)throw Error("[Nix] No active router. Call createRouter() first.");return F}function R(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function z(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 ye(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 be(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function B(e,t="",n=[]){let r=[];for(let o of e){let e=be(t,o.path),l=[...n,o.component],i=ye(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...B(o.children,e,l))}return r}function xe(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 Se(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function V(e,t){let n,r={},o=-1;for(let l of t){let t=xe(e,l);if(null===t)continue;let i=Se(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function Ce(e){function t(){return window.location.pathname||"/"}let n=t(),r=B(e),o=V(n,r),l=p(n),i=p(o?.params??{}),u=p(R(window.location.search)),a=[],s=[],c=0;function f(e,t,n,r,o){let l=[...a];n&&l.push(n);let i=++c;if(0===l.length)return void r();let u=0;!function n(a){if(i!==c)return;if(!1===a)return void o?.();if("string"==typeof a)return void(a===e?r():y(a));if(u>=l.length)return void r();let s=l[u++](e,t);s instanceof Promise?s.then(n):n(s)}(void 0)}let d=!1;function h(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:R(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}}I&&=(I(),null);let m=()=>{let e=t(),n=l.value,o=u.value,a=V(e,r),c=R(window.location.search);f(e,n,a?.route.beforeEnter,()=>{i.value=a?.params??{},u.value=c,l.value=e;for(let t of s)try{t(e,n)}catch{}},()=>{history.pushState(null,"",n+z(o))})};function v(e,t,n,r,o){i.value=r?.params??{},u.value=t,l.value=e;let a=e+z(t);o?history.replaceState(null,"",a):history.pushState(null,"",a);for(let t of s)try{t(e,n)}catch{}}function y(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,u=V(n,r);f(n,i,u?.route.beforeEnter,()=>v(n,o,i,u,!1))}window.addEventListener("popstate",m),I=()=>window.removeEventListener("popstate",m);let x={current:l,params:i,query:u,navigate:y,replace:function(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,u=V(n,r);f(n,i,u?.route.beforeEnter,()=>v(n,o,i,u,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=l.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=V(t,r);if(!n)return{matched:!1,params:{},route:void 0};let o=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===o)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return a.push(e),()=>{let t=a.indexOf(e);-1!==t&&a.splice(t,1)}},afterEach:function(e){return s.push(e),()=>{let t=s.indexOf(e);-1!==t&&s.splice(t,1)}},routes:e,_flat:r,_guards:a};return F&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),F=x,queueMicrotask(()=>{d||f(n,"",V(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=V("/",r);l.value="/",i.value=e?.params??{},u.value={}})}),x}function we(){return L()}var Te=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return P`<div class="router-view">${()=>{let t=L(),n=V(t.current.value,t._flat);return n?e>=n.route.chain.length?P`<span></span>`:n.route.chain[e]():P`<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)}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,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 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(n,r){let o;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)){let t,n;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}var oe=S("nix:portal-outlet");function se(e){O(oe,e)}function ce(){return k(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(n,r){let l=document.createComment("nix-eb");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);if(x(o)){let e,t;T();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{E()}try{let e=o.onMount?.();"function"==typeof e&&(t=e)}catch{}a=()=>{try{o.onUnmount?.()}catch{}t?.(),e()}}else a=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 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 A(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function j(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(A(r.transitionDuration||"0"),A(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 n=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(r,o){let l=document.createComment("nix-t");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){if(x(e)){let t,n=e;T();try{try{n.onInit?.()}catch{}t=n.render()}finally{E()}let l,i=t._render(r,o);try{l=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof l)try{l()}catch{}i()}}return 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 j(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 j(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 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 M(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,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 ge(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function _e(e,t,n){let r=[],o=[],l=he(e),i=ge(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=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)){let e,n,l=u;T();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(M(u)){let e=u._render(s.parentNode,s);r.push(e)}else if(Array.isArray(u))for(let e of u)if(x(e)){let n,l;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else M(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(M(e))f=e._render(s.parentNode,s);else if(x(e)){let t,n,r=e;D(p,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}f=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(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("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(x(s)){let r,o;D(p,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);d.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(M(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 N(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=fe(r);n.push(o),r+="__nix__"}let o=pe(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=_e(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function ve(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 ye(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 P=null,F=null;function I(){if(!P)throw Error("[Nix] No active router. Call createRouter() first.");return P}function L(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function R(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 be(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 xe(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function z(e,t="",n=[]){let r=[];for(let o of e){let e=xe(t,o.path),l=[...n,o.component],i=be(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...z(o.children,e,l))}return r}function Se(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 Ce(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function B(e,t){let n,r={},o=-1;for(let l of t){let t=Se(e,l);if(null===t)continue;let i=Ce(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function V(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function we(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return V(new URL(t,window.location.origin).pathname)}catch{return V(t)}}function Te(e,t){let n=null==t?.base?we():V(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=z(e),a=B(l,i),u=p(l),s=p(a?.params??{}),c=p(L(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?{}:L(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}}F&&=(F(),null);let x=()=>{let e=r(),t=u.value,n=c.value,l=B(e,i),a=L(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)+R(n))})};function g(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+R(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=B(n,i);m(n,o,l?.route.beforeEnter,()=>g(n,r,o,l,!1))}window.addEventListener("popstate",x),F=()=>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=B(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=B(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 P&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),P=b,queueMicrotask(()=>{v||m(l,"",B(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=B("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),b}function Ee(){return I()}var De=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return N`<div class="router-view">${()=>{let t=I(),n=B(t.current.value,t._flat);return n?e>=n.route.chain.length?N`<span></span>`:n.route.chain[e]():N`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
4
|
-
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${
|
|
3
|
+
</div>`}}</div>`}},Oe=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return N`<a
|
|
4
|
+
href=${(I()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
5
|
+
style=${()=>I().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(),I().navigate(e)}}
|
|
7
|
+
>${t}</a>`}};function ke(){return N`
|
|
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 Ae(e){return N`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}function W(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1,invalidate:i}=n,
|
|
21
|
+
`}var H=new Map,je=3e5,U=null,W=je;function Me(){null===U&&(U=setInterval(()=>{let e=Date.now();for(let[t,n]of H)n.subscribers<=0&&e-n.fetchedAt>W&&H.delete(t);0===H.size&&null!==U&&(clearInterval(U),U=null)},6e4))}function G(e){return H.get(e)}function K(e,t){let n=H.get(e);H.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Me()}function q(e){let t=H.get(e);t&&t.subscribers++}function J(e){let t=H.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Y(e,t){let n=H.get(e);return!!n&&Date.now()-n.fetchedAt<t}function Ne(e){void 0===e?H.clear():H.delete(e)}function Pe(e){W=e}function X(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1,invalidate:i,cacheKey:a,staleTime:u=0}=n,s=r??ke(),c=o??Ae;return new class extends b{_state;_disposeWatcher;constructor(){super();let e=a?G(a):void 0;this._state=p(e?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){a&&q(a);let e=a?G(a):void 0;if(e&&Y(a,u)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=m(()=>{i.value,e?e=!1:(a&&H.delete(a),this._run())})}return()=>{this._disposeWatcher?.(),a&&J(a)}}_run(){(l||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{a&&K(a,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return N`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Z=new Map;function Fe(e){H.delete(e);let t=Z.get(e);if(t)for(let e of t)e()}function Ie(e,t,n,r={}){let{fallback:o,errorFallback:l,resetOnRefresh:i=!1,staleTime:a=0,refetchOnMount:u="always"}=r,s=o??ke(),c=l??Ae;return new class extends b{_state;constructor(){super();let t=G(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),q(e);let r=G(e),o=Y(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),J(e)}}_run(){(i||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){t().then(t=>{K(e,t),this._state.value={status:"resolved",data:t}},e=>{this._state.value={status:"error",error:e}})}render(){return N`<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 Le(e,t){let n=null;return()=>n?new n:X(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function Re(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function ze(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function Q(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function $(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function Be(e="Invalid email"){return $(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Ve(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function He(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Ue(e){return e}const We={required:Re,minLength:ze,maxLength:Q,email:Be,pattern:$,min:Ve,max:He};function Ge(e,t){return{...e,...t}}function Ke(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 qe(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=Ke(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=Oe,exports.NixComponent=b,exports.RouterView=De,exports.Signal=f,exports.batch=g,exports.clearQueryCache=Ne,exports.computed=h,exports.createErrorBoundary=le,exports.createForm=qe,exports.createInjectionKey=S,exports.createPortalOutlet=re,exports.createQuery=Ie,exports.createRouter=Te,exports.createStore=ye,exports.createValidator=Ue,exports.effect=m,exports.email=Be,exports.extendValidators=Ge,exports.html=N,exports.inject=k,exports.injectOutlet=ce,exports.invalidateQueries=Fe,exports.lazy=Le,exports.max=He,exports.maxLength=Q,exports.min=Ve,exports.minLength=ze,exports.mount=ve,exports.nextTick=y,exports.pattern=$,exports.portal=ae,exports.portalOutlet=ie,exports.provide=O,exports.provideOutlet=se,exports.ref=ee,exports.repeat=ne,exports.required=Re,exports.setQueryCacheTime=Pe,exports.showWhen=te,exports.signal=p,exports.suspend=X,exports.transition=de,exports.untrack=_,exports.useField=Ke,exports.useRouter=Ee,exports.validators=We,exports.watch=v;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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(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)}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,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 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(n,r){let o;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)){let t,n;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}var A=S("nix:portal-outlet");function oe(e){O(A,e)}function se(){return k(A)}function ce(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("nix-eb");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);if(x(o)){let e,t;T();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{E()}try{let e=o.onMount?.();"function"==typeof e&&(t=e)}catch{}a=()=>{try{o.onUnmount?.()}catch{}t?.(),e()}}else a=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 le(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 j(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function M(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(j(r.transitionDuration||"0"),j(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 ue(e,t={}){let n=le(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("nix-t");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){if(x(e)){let t,n=e;T();try{try{n.onInit?.()}catch{}t=n.render()}finally{E()}let l,i=t._render(r,o);try{l=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof l)try{l()}catch{}i()}}return 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 de(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 fe(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 N(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function pe(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function me(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 he(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function ge(e,t,n){let r=[],o=[],l=me(e),i=he(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=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)){let e,n,l=u;T();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(N(u)){let e=u._render(s.parentNode,s);r.push(e)}else if(Array.isArray(u))for(let e of u)if(x(e)){let n,l;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else N(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(N(e))f=e._render(s.parentNode,s);else if(x(e)){let t,n,r=e;D(p,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}f=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(pe(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("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(x(s)){let r,o;D(p,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);d.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(N(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 P(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=de(r);n.push(o),r+="__nix__"}let o=fe(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=ge(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function _e(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 ve(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 F=null,I=null;function L(){if(!F)throw Error("[Nix] No active router. Call createRouter() first.");return F}function R(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function z(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 ye(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 be(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function B(e,t="",n=[]){let r=[];for(let o of e){let e=be(t,o.path),l=[...n,o.component],i=ye(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...B(o.children,e,l))}return r}function xe(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 Se(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function V(e,t){let n,r={},o=-1;for(let l of t){let t=xe(e,l);if(null===t)continue;let i=Se(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function Ce(e){function t(){return window.location.pathname||"/"}let n=t(),r=B(e),o=V(n,r),l=p(n),i=p(o?.params??{}),a=p(R(window.location.search)),u=[],s=[],c=0;function f(e,t,n,r,o){let l=[...u];n&&l.push(n);let i=++c;if(0===l.length)return void r();let a=0;!function n(u){if(i!==c)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():y(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 d=!1;function h(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:R(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}}I&&=(I(),null);let m=()=>{let e=t(),n=l.value,o=a.value,u=V(e,r),c=R(window.location.search);f(e,n,u?.route.beforeEnter,()=>{i.value=u?.params??{},a.value=c,l.value=e;for(let t of s)try{t(e,n)}catch{}},()=>{history.pushState(null,"",n+z(o))})};function v(e,t,n,r,o){i.value=r?.params??{},a.value=t,l.value=e;let u=e+z(t);o?history.replaceState(null,"",u):history.pushState(null,"",u);for(let t of s)try{t(e,n)}catch{}}function y(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,a=V(n,r);f(n,i,a?.route.beforeEnter,()=>v(n,o,i,a,!1))}window.addEventListener("popstate",m),I=()=>window.removeEventListener("popstate",m);let g={current:l,params:i,query:a,navigate:y,replace:function(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,a=V(n,r);f(n,i,a?.route.beforeEnter,()=>v(n,o,i,a,!0))},back:function(){history.back()},forward:function(){history.forward()},go:function(e){history.go(e)},isActive:function(e,t=!0){let n=l.value;return t?n===e:n===e||n.startsWith(e.endsWith("/")?e:e+"/")},resolve:function(t){let n=V(t,r);if(!n)return{matched:!1,params:{},route:void 0};let o=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===o)return n;if(n.children){let t=e(n.children);if(t)return t}}}(e)}},beforeEach:function(e){return u.push(e),()=>{let t=u.indexOf(e);-1!==t&&u.splice(t,1)}},afterEach:function(e){return s.push(e),()=>{let t=s.indexOf(e);-1!==t&&s.splice(t,1)}},routes:e,_flat:r,_guards:u};return F&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),F=g,queueMicrotask(()=>{d||f(n,"",V(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=V("/",r);l.value="/",i.value=e?.params??{},a.value={}})}),g}function we(){return L()}var Te=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return P`<div class="router-view">${()=>{let t=L(),n=V(t.current.value,t._flat);return n?e>=n.route.chain.length?P`<span></span>`:n.route.chain[e]():P`<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(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)}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,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 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(n,r){let o;if(o="string"==typeof t?document.querySelector(t)??document.body:t instanceof Element?t:"__isPortalOutlet"in t?t._container??document.body:t.el??document.body,x(e)){let t,n;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{E()}try{let t=e.onMount?.();"function"==typeof t&&(n=t)}catch(t){if(!e.onError)throw t;e.onError(t)}return()=>{try{e.onUnmount?.()}catch{}try{n?.()}catch{}t()}}return e._render(o,null)}}}var oe=S("nix:portal-outlet");function se(e){O(oe,e)}function ce(){return k(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(n,r){let l=document.createComment("nix-eb");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);if(x(o)){let e,t;T();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{E()}try{let e=o.onMount?.();"function"==typeof e&&(t=e)}catch{}a=()=>{try{o.onUnmount?.()}catch{}t?.(),e()}}else a=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 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 A(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function j(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(A(r.transitionDuration||"0"),A(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 n=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(r,o){let l=document.createComment("nix-t");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){if(x(e)){let t,n=e;T();try{try{n.onInit?.()}catch{}t=n.render()}finally{E()}let l,i=t._render(r,o);try{l=n.onMount?.()}catch{}return()=>{try{n.onUnmount?.()}catch{}if("function"==typeof l)try{l()}catch{}i()}}return 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 j(o,t.duration),u===e&&(o.classList.remove(n.enterActive,n.enterTo),t.onAfterEnter?.(o)))})().catch(()=>{})}s=!1},h=()=>{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 j(r,t.duration),u===o&&(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,o=null===e;r&&!o?d(e):!r&&o?h():!r&&!o&&(u++,a?.(),a=null,i?.(),i=null,d(e,!0)),n=e}),s=!1}return()=>{u++,p?.(),i?.(),a?.(),i=null,a=null,l.remove()}}}}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 M(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,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 ge(e){let t=new Map;return e.querySelectorAll("*").forEach(e=>{let n=Array.from(e.attributes);for(let r of n){let n=r.name.match(/^data-nix-e-(\d+)$/);n?(t.set(parseInt(n[1]),{el:e,type:"event",name:r.value}),e.removeAttribute(r.name)):(n=r.name.match(/^data-nix-a-(\d+)$/),n&&(t.set(parseInt(n[1]),{el:e,type:"attr",name:r.value}),e.removeAttribute(r.name)))}}),t}function _e(e,t,n){let r=[],o=[],l=he(e),i=ge(e);for(let e=0;e<t.length;e++){let a=t[e],u=n[e];if("event"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t,l=u,s=a.modifiers,c={};s.includes("once")&&(c.once=!0),s.includes("capture")&&(c.capture=!0),s.includes("passive")&&(c.passive=!0);let f={enter:"Enter",escape:"Escape",space:" ",tab:"Tab",delete:"Delete",backspace:"Backspace",up:"ArrowUp",down:"ArrowDown",left:"ArrowLeft",right:"ArrowRight"},d=e=>{if(s.includes("prevent")&&e.preventDefault(),s.includes("stop")&&e.stopPropagation(),!s.includes("self")||e.target===e.currentTarget){if("key"in e){let t=e;for(let e of s){let n=f[e];if(void 0!==n&&t.key!==n||!f[e]&&1===e.length&&t.key.toLowerCase()!==e)return}}l(e)}};n.addEventListener(o,d,c),r.push(()=>n.removeEventListener(o,d,c));continue}if("attr"===a.type){let t=i.get(e);if(!t)continue;let{el:n,name:o}=t;if("ref"===o){u.el=n,r.push(()=>{u.el=null});continue}if("show"===o||"hide"===o){let e=n,t=null;if("function"==typeof u){let n=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)){let e,n,l=u;T();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let e=l.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!l.onError)throw e;l.onError(e)}}),r.push(()=>{try{l.onUnmount?.()}catch{}try{n?.()}catch{}e()})}else if(M(u)){let e=u._render(s.parentNode,s);r.push(e)}else if(Array.isArray(u))for(let e of u)if(x(e)){let n,l;T();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{E()}o.push(()=>{try{let t=e.onMount?.();"function"==typeof t&&(l=t)}catch(t){if(!e.onError)throw t;e.onError(t)}}),r.push(()=>{try{e.onUnmount?.()}catch{}try{l?.()}catch{}n()})}else M(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(M(e))f=e._render(s.parentNode,s);else if(x(e)){let t,n,r=e;D(h,()=>{try{r.onInit?.()}catch(e){if(!r.onError)throw e;r.onError(e)}t=r.render()._render(s.parentNode,s)});try{let e=r.onMount?.();"function"==typeof e&&(n=e)}catch(e){if(!r.onError)throw e;r.onError(e)}f=()=>{try{r.onUnmount?.()}catch{}try{n?.()}catch{}t()}}else if(me(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("nix-ke"),a=document.createComment("nix-ks");t.insertBefore(n,o),t.insertBefore(a,n);let u,s=e.renderFn(i,r);if(x(s)){let r,o;D(h,()=>{try{s.onInit?.()}catch(e){if(!s.onError)throw e;s.onError(e)}r=s.render()._render(t,n)});try{let e=s.onMount?.();"function"==typeof e&&(o=e)}catch(e){if(!s.onError)throw e;s.onError(e)}u=()=>{try{s.onUnmount?.()}catch{}try{o?.()}catch{}r()}}else u=s._render(t,n);d.set(l,{start:a,end:n,cleanup:u}),o=a}}}else if(Array.isArray(e)){let t=[];for(let n of e)if(x(n)){try{n.onInit?.()}catch(e){if(!n.onError)throw e;n.onError(e)}let r,o=n.render()._render(s.parentNode,s);try{let e=n.onMount?.();"function"==typeof e&&(r=e)}catch(e){if(!n.onError)throw e;n.onError(e)}t.push(()=>{try{n.onUnmount?.()}catch{}try{r?.()}catch{}o()})}else if(M(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:o}}function N(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=fe(r);n.push(o),r+="__nix__"}let o=pe(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=_e(i,n,t),s=document.createComment("nix-scope");e.insertBefore(s,r);let c=i.firstChild;for(;c;){let t=c.nextSibling;e.insertBefore(c,r),c=t}return u.forEach(e=>e()),()=>{a.forEach(e=>e());let e=s.nextSibling;for(;e&&e!==r;){let t=e.nextSibling;e.parentNode?.removeChild(e),e=t}s.parentNode?.removeChild(s)}}return{__isNixTemplate:!0,_render:l,mount(e){let t="string"==typeof e?document.querySelector(e):e;if(!t)throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);let n=l(t,null);return{unmount(){n()}}}}}function ve(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 ye(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 P=null,F=null;function I(){if(!P)throw Error("[Nix] No active router. Call createRouter() first.");return P}function L(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function R(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 be(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 xe(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function z(e,t="",n=[]){let r=[];for(let o of e){let e=xe(t,o.path),l=[...n,o.component],i=be(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...z(o.children,e,l))}return r}function Se(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 Ce(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function B(e,t){let n,r={},o=-1;for(let l of t){let t=Se(e,l);if(null===t)continue;let i=Ce(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function V(e){let t=e.trim();return t&&"/"!==t?(t.startsWith("/")||(t="/"+t),t.endsWith("/")&&(t=t.slice(0,-1)),t):""}function we(){if(typeof document>"u")return"";let e=document.querySelector("base");if(!e)return"";let t=e.getAttribute("href")||"";try{return V(new URL(t,window.location.origin).pathname)}catch{return V(t)}}function Te(e,t){let n=null==t?.base?we():V(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=z(e),a=B(l,i),u=p(l),s=p(a?.params??{}),c=p(L(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():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 v=!1;function y(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:L(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}}F&&=(F(),null);let g=()=>{let e=r(),t=u.value,n=c.value,l=B(e,i),a=L(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)+R(n))})};function _(e,t,n,r,l){s.value=r?.params??{},c.value=t,u.value=e;let i=o(e)+R(t);l?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),o=u.value,l=B(n,i);m(n,o,l?.route.beforeEnter,()=>_(n,r,o,l,!1))}window.addEventListener("popstate",g),F=()=>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),o=u.value,l=B(n,i);m(n,o,l?.route.beforeEnter,()=>_(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=B(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 P&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),P=x,queueMicrotask(()=>{v||m(l,"",B(l,i)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"",o("/"));let e=B("/",i);u.value="/",s.value=e?.params??{},c.value={}})}),x}function Ee(){return I()}var De=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return N`<div class="router-view">${()=>{let t=I(),n=B(t.current.value,t._flat);return n?e>=n.route.chain.length?N`<span></span>`:n.route.chain[e]():N`<div style="color:#f87171;padding:16px 0">
|
|
2
2
|
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
-
</div>`}}</div>`}},
|
|
4
|
-
href=${e}
|
|
5
|
-
style=${()=>
|
|
6
|
-
@click=${t=>{t.preventDefault(),
|
|
7
|
-
>${
|
|
3
|
+
</div>`}}</div>`}},Oe=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to,t=this._label;return N`<a
|
|
4
|
+
href=${(I()._base||"")+(e.startsWith("/")?e:"/"+e)}
|
|
5
|
+
style=${()=>I().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(),I().navigate(e)}}
|
|
7
|
+
>${t}</a>`}};function ke(){return N`
|
|
8
8
|
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
9
9
|
<span class="nix-spinner" style="
|
|
10
10
|
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
@@ -14,8 +14,8 @@ var e=null,t=[],n=null,r=[],i=null,a=[];function o(e){a.push(i),i=e}function s()
|
|
|
14
14
|
Loading…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
|
-
`}function
|
|
17
|
+
`}function Ae(e){return N`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`}function W(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1,invalidate:i}=n,
|
|
21
|
+
`}var H=new Map,je=3e5,U=null,W=je;function Me(){null===U&&(U=setInterval(()=>{let e=Date.now();for(let[t,n]of H)n.subscribers<=0&&e-n.fetchedAt>W&&H.delete(t);0===H.size&&null!==U&&(clearInterval(U),U=null)},6e4))}function G(e){return H.get(e)}function K(e,t){let n=H.get(e);H.set(e,{data:t,fetchedAt:Date.now(),subscribers:n?.subscribers??0}),Me()}function q(e){let t=H.get(e);t&&t.subscribers++}function J(e){let t=H.get(e);t&&(t.subscribers=Math.max(0,t.subscribers-1))}function Y(e,t){let n=H.get(e);return!!n&&Date.now()-n.fetchedAt<t}function Ne(e){void 0===e?H.clear():H.delete(e)}function Pe(e){W=e}function X(e,t,n={}){let{fallback:r,errorFallback:o,resetOnRefresh:l=!1,invalidate:i,cacheKey:a,staleTime:u=0}=n,s=r??ke(),c=o??Ae;return new class extends b{_state;_disposeWatcher;constructor(){super();let e=a?G(a):void 0;this._state=p(e?{status:"resolved",data:e.data}:{status:"pending"})}onMount(){a&&q(a);let e=a?G(a):void 0;if(e&&Y(a,u)||(e?this._fetch():this._run()),i){let e=!0;this._disposeWatcher=m(()=>{i.value,e?e=!1:(a&&H.delete(a),this._run())})}return()=>{this._disposeWatcher?.(),a&&J(a)}}_run(){(l||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){e().then(e=>{a&&K(a,e),this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return N`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?s:"error"===e.status?c(e.error):t(e.data)}}</div>`}}}var Z=new Map;function Fe(e){H.delete(e);let t=Z.get(e);if(t)for(let e of t)e()}function Ie(e,t,n,r={}){let{fallback:o,errorFallback:l,resetOnRefresh:i=!1,staleTime:a=0,refetchOnMount:u="always"}=r,s=o??ke(),c=l??Ae;return new class extends b{_state;constructor(){super();let t=G(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),q(e);let r=G(e),o=Y(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),J(e)}}_run(){(i||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),this._fetch()}_fetch(){t().then(t=>{K(e,t),this._state.value={status:"resolved",data:t}},e=>{this._state.value={status:"error",error:e}})}render(){return N`<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 Le(e,t){let n=null;return()=>n?new n:X(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function Re(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function ze(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function Q(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function $(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function Be(e="Invalid email"){return $(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Ve(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function He(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Ue(e){return e}const We={required:Re,minLength:ze,maxLength:Q,email:Be,pattern:$,min:Ve,max:He};function Ge(e,t){return{...e,...t}}function Ke(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 qe(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=Ke(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}}export{Oe as Link,b as NixComponent,De as RouterView,f as Signal,g as batch,Ne as clearQueryCache,h as computed,le as createErrorBoundary,qe as createForm,S as createInjectionKey,re as createPortalOutlet,Ie as createQuery,Te as createRouter,ye as createStore,Ue as createValidator,m as effect,Be as email,Ge as extendValidators,N as html,k as inject,ce as injectOutlet,Fe as invalidateQueries,Le as lazy,He as max,Q as maxLength,Ve as min,ze as minLength,ve as mount,y as nextTick,$ as pattern,ae as portal,ie as portalOutlet,O as provide,se as provideOutlet,ee as ref,ne as repeat,Re as required,Pe as setQueryCacheTime,te as showWhen,p as signal,X as suspend,de as transition,_ as untrack,Ke as useField,Ee as useRouter,We as validators,v as watch};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deijose/nix-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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-c2yq.vercel.app/",
|