@deijose/nix-js 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -279
- package/dist/lib/nix/async.d.ts +8 -54
- package/dist/lib/nix/context.d.ts +11 -45
- package/dist/lib/nix/form.d.ts +6 -129
- package/dist/lib/nix/index.d.ts +1 -1
- package/dist/lib/nix/lifecycle.d.ts +13 -107
- package/dist/lib/nix/reactivity.d.ts +16 -88
- package/dist/lib/nix/router.d.ts +45 -121
- package/dist/lib/nix/store.d.ts +5 -30
- package/dist/lib/nix/template.d.ts +25 -289
- package/dist/lib/nix-js.cjs +5 -5
- package/dist/lib/nix-js.js +5 -5
- package/package.json +1 -1
|
@@ -1,76 +1,23 @@
|
|
|
1
1
|
import type { NixComponent } from "./lifecycle";
|
|
2
2
|
export interface NixTemplate {
|
|
3
3
|
readonly __isNixTemplate: true;
|
|
4
|
-
/**
|
|
4
|
+
/** Mounts the template into a container element (public / root API). */
|
|
5
5
|
mount(container: Element | string): NixMountHandle;
|
|
6
|
-
/**
|
|
7
|
-
* @internal — Renderiza el template antes del nodo `before` (o al final
|
|
8
|
-
* de `parent` si `before` es null). Retorna una función de limpieza.
|
|
9
|
-
*/
|
|
6
|
+
/** @internal Renders before `before` node (or appends to `parent`). Returns cleanup. */
|
|
10
7
|
_render(parent: Node, before: Node | null): () => void;
|
|
11
8
|
}
|
|
12
9
|
export interface NixMountHandle {
|
|
13
10
|
unmount(): void;
|
|
14
11
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Contenedor para una referencia directa a un elemento DOM.
|
|
17
|
-
* Se asigna automáticamente cuando el template se monta y se limpia al
|
|
18
|
-
* desmontarse.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* const inputRef = ref<HTMLInputElement>();
|
|
22
|
-
* html`<input ref=${inputRef} />`
|
|
23
|
-
* // después del mount:
|
|
24
|
-
* inputRef.el?.focus();
|
|
25
|
-
*/
|
|
12
|
+
/** Direct reference to a DOM element, assigned on mount and cleared on unmount. */
|
|
26
13
|
export interface NixRef<T extends Element = Element> {
|
|
27
14
|
el: T | null;
|
|
28
15
|
}
|
|
29
|
-
/**
|
|
30
|
-
* Crea un objeto `NixRef` vacío.
|
|
31
|
-
* Pásalo como valor del atributo especial `ref` en un template para que
|
|
32
|
-
* Nix.js rellene automáticamente `ref.el` con el elemento real del DOM.
|
|
33
|
-
*/
|
|
16
|
+
/** Creates an empty `NixRef`. Use as `ref` attribute value in templates. */
|
|
34
17
|
export declare function ref<T extends Element = Element>(): NixRef<T>;
|
|
35
|
-
/**
|
|
36
|
-
* Toggles the visibility of an element **without unmounting it** from the DOM
|
|
37
|
-
* (sets `style.display = "none"` when hidden, restores it when visible).
|
|
38
|
-
*
|
|
39
|
-
* Use the `show` or `hide` attribute bindings inside templates — or call
|
|
40
|
-
* this helper directly for imperative use outside of templates.
|
|
41
|
-
*
|
|
42
|
-
* ### Template usage
|
|
43
|
-
* ```html
|
|
44
|
-
* <!-- show: element is visible when condition is truthy -->
|
|
45
|
-
* <div show=${() => isVisible.value}>...</div>
|
|
46
|
-
*
|
|
47
|
-
* <!-- hide: element is hidden when condition is truthy (inverse of show) -->
|
|
48
|
-
* <div hide=${() => isLoading.value}>Submit</div>
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* ### Difference from conditional rendering
|
|
52
|
-
* | | `show` / `hide` | conditional (`() => condition ? html\`…\` : null`) |
|
|
53
|
-
* |---|---|---|
|
|
54
|
-
* | DOM node kept | ✅ always | ❌ destroyed when hidden |
|
|
55
|
-
* | Lifecycle hooks | not called on toggle | called on every toggle |
|
|
56
|
-
* | Use when | hiding/showing frequently | rarely shown alternatives |
|
|
57
|
-
*
|
|
58
|
-
* ### Imperative usage (outside a template)
|
|
59
|
-
* ```typescript
|
|
60
|
-
* import { showWhen } from "@deijose/nix-js";
|
|
61
|
-
* import { effect } from "@deijose/nix-js";
|
|
62
|
-
*
|
|
63
|
-
* const el = document.getElementById("my-panel")!;
|
|
64
|
-
* // Reactively controlled:
|
|
65
|
-
* effect(() => showWhen(el, isVisible.value));
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
18
|
+
/** Toggles element visibility via `display: none` without unmounting. */
|
|
68
19
|
export declare function showWhen(el: HTMLElement, condition: boolean): void;
|
|
69
|
-
/**
|
|
70
|
-
* Resultado de `repeat()` — lista con keys para diffing eficiente.
|
|
71
|
-
* El template engine lo reconoce y solo añade/mueve/elimina los nodos
|
|
72
|
-
* que realmente cambiaron, preservando el DOM de los items estables.
|
|
73
|
-
*/
|
|
20
|
+
/** Keyed list result for efficient DOM diffing via `repeat()`. */
|
|
74
21
|
export interface KeyedList<T = unknown> {
|
|
75
22
|
readonly __isKeyedList: true;
|
|
76
23
|
readonly items: T[];
|
|
@@ -78,227 +25,38 @@ export interface KeyedList<T = unknown> {
|
|
|
78
25
|
readonly renderFn: (item: T, index: number) => NixTemplate | NixComponent;
|
|
79
26
|
}
|
|
80
27
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param items Array reactivo de datos
|
|
85
|
-
* @param keyFn Devuelve una clave única por item (p.ej. `item => item.id`)
|
|
86
|
-
* @param renderFn Devuelve el template/componente para cada item
|
|
87
|
-
*
|
|
88
|
-
* @example
|
|
89
|
-
* ${() => repeat(
|
|
90
|
-
* users.value,
|
|
91
|
-
* u => u.id,
|
|
92
|
-
* u => html`<li>${u.name}</li>`
|
|
93
|
-
* )}
|
|
28
|
+
* Creates a keyed list for efficient DOM reconciliation.
|
|
29
|
+
* Use instead of `.map()` when the list changes frequently.
|
|
94
30
|
*/
|
|
95
31
|
export declare function repeat<T>(items: T[], keyFn: (item: T, index: number) => string | number, renderFn: (item: T, index: number) => NixTemplate | NixComponent): KeyedList<T>;
|
|
96
32
|
/**
|
|
97
|
-
* Renders `content` into `target` instead of the current position
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* Use this to render modals, tooltips, notifications, or dropdowns outside of
|
|
101
|
-
* your component tree — typically into `document.body` — so they are not clipped
|
|
102
|
-
* by `overflow: hidden` or buried under other stacking contexts.
|
|
103
|
-
*
|
|
104
|
-
* The portal returns a `NixTemplate`, so it works as a node value anywhere in
|
|
105
|
-
* a template, including inside reactive conditionals: the portal is
|
|
106
|
-
* mounted/unmounted together with whatever controls its condition.
|
|
107
|
-
*
|
|
108
|
-
* @param content Template or component to render inside the portal.
|
|
109
|
-
* @param target CSS selector or `Element` to render into. Defaults to `document.body`.
|
|
110
|
-
*
|
|
111
|
-
* @example Reactive modal
|
|
112
|
-
* ```typescript
|
|
113
|
-
* import { signal, portal, html } from "@deijose/nix-js";
|
|
114
|
-
*
|
|
115
|
-
* const isOpen = signal(false);
|
|
33
|
+
* Renders `content` into `target` instead of the current tree position.
|
|
34
|
+
* Useful for modals, tooltips, and overlays that must escape overflow clipping.
|
|
35
|
+
* Returns a NixTemplate — works inside reactive conditionals.
|
|
116
36
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* ${() => isOpen.value
|
|
121
|
-
* ? portal(html`
|
|
122
|
-
* <div class="overlay" @click=${() => { isOpen.value = false; }}>
|
|
123
|
-
* <div class="modal" @click.stop=${() => {}}>
|
|
124
|
-
* <h2>Hello from a portal!</h2>
|
|
125
|
-
* <button @click=${() => { isOpen.value = false; }}>Close</button>
|
|
126
|
-
* </div>
|
|
127
|
-
* </div>
|
|
128
|
-
* `)
|
|
129
|
-
* : null
|
|
130
|
-
* }
|
|
131
|
-
* `
|
|
132
|
-
* ```
|
|
133
|
-
*
|
|
134
|
-
* @example Custom target
|
|
135
|
-
* ```typescript
|
|
136
|
-
* portal(html`<div class="toast">Saved!</div>`, "#toast-root")
|
|
137
|
-
* portal(html`<Tooltip />`, document.getElementById("tooltip-layer")!)
|
|
138
|
-
* ```
|
|
139
|
-
*/
|
|
140
|
-
/**
|
|
141
|
-
* Opaque token created by `createPortalOutlet()`.
|
|
142
|
-
*
|
|
143
|
-
* Pass it to `portalOutlet()` to declare the DOM anchor where portals targeting
|
|
144
|
-
* this outlet will render, and to `portal(content, outlet)` as the target.
|
|
145
|
-
*
|
|
146
|
-
* @see createPortalOutlet
|
|
147
|
-
* @see portalOutlet
|
|
37
|
+
* @param content Template or component to render.
|
|
38
|
+
* @param target CSS selector, Element, PortalOutlet, or NixRef. Defaults to `document.body`.
|
|
148
39
|
*/
|
|
40
|
+
/** Opaque token for a named portal target. */
|
|
149
41
|
export interface PortalOutlet {
|
|
150
42
|
readonly __isPortalOutlet: true;
|
|
151
|
-
/** @internal
|
|
43
|
+
/** @internal */
|
|
152
44
|
_container: Element | null;
|
|
153
45
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates a `PortalOutlet` token — a lightweight, typed anchor point that
|
|
156
|
-
* decouples *where* a portal renders from direct DOM access.
|
|
157
|
-
* No CSS selectors, no `document.querySelector`, no manual element references.
|
|
158
|
-
*
|
|
159
|
-
* ### Workflow
|
|
160
|
-
* 1. Create the token at module or component scope.
|
|
161
|
-
* 2. Place `${portalOutlet(outlet)}` in your layout template to declare the anchor.
|
|
162
|
-
* 3. From any child: `portal(content, outlet)` renders into that anchor.
|
|
163
|
-
*
|
|
164
|
-
* @example
|
|
165
|
-
* ```typescript
|
|
166
|
-
* const modalOutlet = createPortalOutlet();
|
|
167
|
-
*
|
|
168
|
-
* // Layout:
|
|
169
|
-
* html`
|
|
170
|
-
* <main>${mainContent}</main>
|
|
171
|
-
* ${portalOutlet(modalOutlet)}
|
|
172
|
-
* `
|
|
173
|
-
*
|
|
174
|
-
* // Child (any depth):
|
|
175
|
-
* html`${() => show.value ? portal(html\`<Modal />\`, modalOutlet) : null}`
|
|
176
|
-
* ```
|
|
177
|
-
*/
|
|
46
|
+
/** Creates a PortalOutlet token for decoupled portal targeting. */
|
|
178
47
|
export declare function createPortalOutlet(): PortalOutlet;
|
|
179
|
-
/**
|
|
180
|
-
* Declares the DOM anchor for a `PortalOutlet` inside a template.
|
|
181
|
-
* Creates a `<div data-nix-outlet>` at this position; portals targeting
|
|
182
|
-
* `outlet` will render their content as children of that div.
|
|
183
|
-
*
|
|
184
|
-
* The anchor's lifecycle follows its parent template — when the parent
|
|
185
|
-
* unmounts, the outlet div and any portals inside it are cleaned up.
|
|
186
|
-
*
|
|
187
|
-
* @example
|
|
188
|
-
* ```typescript
|
|
189
|
-
* mount(html`
|
|
190
|
-
* <div class="app">
|
|
191
|
-
* <main>${mainContent}</main>
|
|
192
|
-
* ${portalOutlet(modalOutlet)}
|
|
193
|
-
* </div>
|
|
194
|
-
* `, document.body);
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
48
|
+
/** Declares the DOM anchor for a PortalOutlet inside a template. */
|
|
197
49
|
export declare function portalOutlet(outlet: PortalOutlet): NixTemplate;
|
|
198
50
|
export declare function portal(content: NixTemplate | NixComponent, target?: Element | string | PortalOutlet | NixRef<Element>): NixTemplate;
|
|
199
|
-
/**
|
|
200
|
-
* Provides a `PortalOutlet` to descendant components via the inject system.
|
|
201
|
-
* Must be called inside `onInit()` of a `NixComponent`.
|
|
202
|
-
*
|
|
203
|
-
* Eliminates prop drilling: any descendant can call `injectOutlet()` to
|
|
204
|
-
* obtain the outlet without it being passed through every layer.
|
|
205
|
-
*
|
|
206
|
-
* @example
|
|
207
|
-
* ```typescript
|
|
208
|
-
* class AppLayout extends NixComponent {
|
|
209
|
-
* private outlet = createPortalOutlet();
|
|
210
|
-
* onInit() { provideOutlet(this.outlet); }
|
|
211
|
-
* render() {
|
|
212
|
-
* return html`
|
|
213
|
-
* <main>...</main>
|
|
214
|
-
* ${portalOutlet(this.outlet)}
|
|
215
|
-
* `;
|
|
216
|
-
* }
|
|
217
|
-
* }
|
|
218
|
-
* ```
|
|
219
|
-
*/
|
|
51
|
+
/** Provides a PortalOutlet to descendant components via dependency injection. */
|
|
220
52
|
export declare function provideOutlet(outlet: PortalOutlet): void;
|
|
221
|
-
/**
|
|
222
|
-
* Injects the nearest `PortalOutlet` provided by an ancestor component.
|
|
223
|
-
* Returns `undefined` if no ancestor has called `provideOutlet()`.
|
|
224
|
-
*
|
|
225
|
-
* Use `portal(content, injectOutlet())` to render into the ancestor's outlet
|
|
226
|
-
* with no CSS selectors, no `document.querySelector`, and no prop drilling.
|
|
227
|
-
*
|
|
228
|
-
* @example
|
|
229
|
-
* ```typescript
|
|
230
|
-
* class ToastButton extends NixComponent {
|
|
231
|
-
* private outlet: PortalOutlet | undefined;
|
|
232
|
-
* private active = signal(false);
|
|
233
|
-
* onInit() { this.outlet = injectOutlet(); }
|
|
234
|
-
* render() {
|
|
235
|
-
* return html`
|
|
236
|
-
* <button @click=${() => { this.active.value = true; }}>Notify</button>
|
|
237
|
-
* ${() => this.active.value
|
|
238
|
-
* ? portal(html\`<div class="toast">Done!</div>\`, this.outlet)
|
|
239
|
-
* : null
|
|
240
|
-
* }
|
|
241
|
-
* `;
|
|
242
|
-
* }
|
|
243
|
-
* }
|
|
244
|
-
* ```
|
|
245
|
-
*/
|
|
53
|
+
/** Injects the nearest PortalOutlet provided by an ancestor. */
|
|
246
54
|
export declare function injectOutlet(): PortalOutlet | undefined;
|
|
247
|
-
/**
|
|
248
|
-
* Fallback value for `createErrorBoundary()`:
|
|
249
|
-
* - A static `NixTemplate` or `NixComponent` — always render this on error.
|
|
250
|
-
* - A function `(err) => NixTemplate | NixComponent` — render based on the error.
|
|
251
|
-
*/
|
|
55
|
+
/** Fallback: a static template/component, or a factory receiving the error. */
|
|
252
56
|
export type ErrorFallback = NixTemplate | NixComponent | ((err: unknown) => NixTemplate | NixComponent);
|
|
253
57
|
/**
|
|
254
|
-
* Wraps `content` in an error boundary. If
|
|
255
|
-
*
|
|
256
|
-
* boundary automatically:
|
|
257
|
-
* 1. Tears down the broken subtree (effects, event listeners, DOM).
|
|
258
|
-
* 2. Renders `fallback` in its place — without crashing the rest of the app.
|
|
259
|
-
*
|
|
260
|
-
* Errors caught:
|
|
261
|
-
* - `onInit()` / `render()` throws in any `NixComponent` inside `content`
|
|
262
|
-
* - Throws inside `html\`\`` binding expressions during initial render
|
|
263
|
-
* - Reactive re-renders: effects created inside `content` that throw when
|
|
264
|
-
* a signal changes
|
|
265
|
-
*
|
|
266
|
-
* Not caught (same as React):
|
|
267
|
-
* - Event handler throws (wrap those with your own try/catch)
|
|
268
|
-
* - Async code (Promises, `setTimeout`, etc.)
|
|
269
|
-
* - Errors thrown inside `fallback` itself (propagate to the parent boundary)
|
|
270
|
-
*
|
|
271
|
-
* @example Basic usage
|
|
272
|
-
* ```typescript
|
|
273
|
-
* import { createErrorBoundary, html, signal } from "@deijose/nix-js";
|
|
274
|
-
*
|
|
275
|
-
* mount(
|
|
276
|
-
* createErrorBoundary(
|
|
277
|
-
* new MyWidget(),
|
|
278
|
-
* (err) => html`<div class="error">Widget failed: ${String(err)}</div>`
|
|
279
|
-
* ),
|
|
280
|
-
* "#app"
|
|
281
|
-
* );
|
|
282
|
-
* ```
|
|
283
|
-
*
|
|
284
|
-
* @example Static fallback
|
|
285
|
-
* ```typescript
|
|
286
|
-
* createErrorBoundary(
|
|
287
|
-
* html`${() => riskyValue.value}`,
|
|
288
|
-
* html`<p>Something went wrong.</p>`
|
|
289
|
-
* )
|
|
290
|
-
* ```
|
|
291
|
-
*
|
|
292
|
-
* @example Nested boundaries (inner catches first)
|
|
293
|
-
* ```typescript
|
|
294
|
-
* createErrorBoundary(
|
|
295
|
-
* html`
|
|
296
|
-
* <header>...</header>
|
|
297
|
-
* ${createErrorBoundary(new RiskyWidget(), html`<p>Widget error</p>`)}
|
|
298
|
-
* `,
|
|
299
|
-
* html`<p>App-level error</p>`
|
|
300
|
-
* )
|
|
301
|
-
* ```
|
|
58
|
+
* Wraps `content` in an error boundary. If rendering or a reactive update
|
|
59
|
+
* throws, the boundary tears down the broken subtree and renders `fallback`.
|
|
302
60
|
*/
|
|
303
61
|
export declare function createErrorBoundary(content: NixTemplate | NixComponent, fallback: ErrorFallback): NixTemplate;
|
|
304
62
|
/**
|
|
@@ -350,31 +108,9 @@ export interface TransitionOptions {
|
|
|
350
108
|
/** Content that can be wrapped with `transition()`. */
|
|
351
109
|
export type TransitionContent = NixTemplate | NixComponent | (() => NixTemplate | NixComponent | null);
|
|
352
110
|
/**
|
|
353
|
-
* Wraps
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* on mount (only if `appear: true`; otherwise instant), and cleans up
|
|
357
|
-
* immediately on unmount without a leave transition.
|
|
358
|
-
*
|
|
359
|
-
* **Reactive conditional** `() => Template | null`: plays the enter
|
|
360
|
-
* transition when the expression goes from `null` → value, and the leave
|
|
361
|
-
* transition when it goes from value → `null`. An in-progress leave is
|
|
362
|
-
* cancelled and the DOM is removed synchronously when new content enters.
|
|
363
|
-
*
|
|
364
|
-
* @example
|
|
365
|
-
* ```css
|
|
366
|
-
* .fade-enter-active, .fade-leave-active { transition: opacity 0.3s ease; }
|
|
367
|
-
* .fade-enter-from, .fade-leave-to { opacity: 0; }
|
|
368
|
-
* ```
|
|
369
|
-
* ```typescript
|
|
370
|
-
* const show = signal(true);
|
|
371
|
-
*
|
|
372
|
-
* // Reactive — full enter + leave
|
|
373
|
-
* transition(() => show.value ? html`<p>Hello</p>` : null, { name: "fade" })
|
|
374
|
-
*
|
|
375
|
-
* // Static — only enter (if appear: true)
|
|
376
|
-
* transition(html`<span>Always here</span>`, { name: "slide", appear: true })
|
|
377
|
-
* ```
|
|
111
|
+
* Wraps content with CSS class-based enter/leave transitions.
|
|
112
|
+
* Static content plays enter on mount (only with `appear: true`).
|
|
113
|
+
* Reactive `() => Template | null` auto-animates enter/leave on toggle.
|
|
378
114
|
*/
|
|
379
115
|
export declare function transition(content: TransitionContent, options?: TransitionOptions): NixTemplate;
|
|
380
116
|
export declare function html(strings: TemplateStringsArray, ...values: unknown[]): NixTemplate;
|
package/dist/lib/nix-js.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 ee(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 v(e){return e?Promise.resolve().then(e):Promise.resolve()}var y=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 b(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function x(e){return Symbol(e)}var S=[];function C(){return[...S]}function w(){S.push(new Map)}function T(){S.pop()}function E(e,t){let n=S.splice(0);e.forEach(e=>S.push(e)),S.push(new Map);try{return t()}finally{S.splice(0),n.forEach(e=>S.push(e))}}function D(e,t){let n=S[S.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function O(e){for(let t=S.length-1;t>=0;t--)if(S[t].has(e))return S[t].get(e)}function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function ie(){return{__isPortalOutlet:!0,_container:null}}function ae(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function oe(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let o;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,b(e)){let t,n;w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{T()}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 k=x("nix:portal-outlet");function se(e){D(k,e)}function ce(){return O(k)}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,u=null,a=!1,c=!1,f=!1,d=e=>{let n=l.parentNode,o="function"!=typeof t||b(t)?t:t(e);if(b(o)){let e,t;w();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{T()}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(b(e)){w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}u=e.render()._render(n,r)}finally{T()}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 A(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=A(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(b(e)){let t,n=e;w();try{try{n.onInit?.()}catch{}t=n.render()}finally{T()}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||b(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 P(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(b(a)){let e,n,l=a;w();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{T()}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(b(e)){let n,l;w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{T()}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=C(),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(b(e)){let t,n,r=e;E(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(b(s)){let r,o;E(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(b(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 F(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}=P(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 I(e,t){if(b(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{T()}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 L(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 R=null,z=null;function B(){if(!R)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return R}function V(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function H(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 ge(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 _e(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function U(e,t="",n=[]){let r=[];for(let o of e){let e=_e(t,o.path),l=[...n,o.component],i=ge(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...U(o.children,e,l))}return r}function ve(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 ye(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},o=-1;for(let l of t){let t=ve(e,l);if(null===t)continue;let i=ye(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function be(e){function t(){return window.location.pathname||"/"}let n=t(),r=U(e),o=W(n,r),l=p(n),i=p(o?.params??{}),u=p(V(window.location.search)),a=[],s=0;function c(e,t,n,r,o){let l=[...a];n&&l.push(n);let i=++s;if(0===l.length)return void r();let u=0;!function n(a){if(i!==s)return;if(!1===a)return void o?.();if("string"==typeof a)return void(a===e?r():h(a));if(u>=l.length)return void r();let c=l[u++](e,t);c instanceof Promise?c.then(n):n(c)}(void 0)}let f=!1;z&&=(z(),null);let d=()=>{let e=t(),n=l.value,o=u.value,a=W(e,r),s=V(window.location.search);c(e,n,a?.route.beforeEnter,()=>{i.value=a?.params??{},u.value=s,l.value=e},()=>{history.pushState(null,"",n+H(o))})};function h(e,t){f=!0;let{pathname:n,stringQuery:o}=function(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:V(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}}(e,t),a=l.value,s=W(n,r);c(n,a,s?.route.beforeEnter,()=>{i.value=s?.params??{},u.value=o,l.value=n,history.pushState(null,"",n+H(o))})}window.addEventListener("popstate",d),z=()=>window.removeEventListener("popstate",d);let m={current:l,params:i,query:u,navigate:h,beforeEach:function(e){return a.push(e),()=>{let t=a.indexOf(e);-1!==t&&a.splice(t,1)}},routes:e,_flat:r,_guards:a};return R&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),R=m,queueMicrotask(()=>{f||c(n,"",W(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=W("/",r);l.value="/",i.value=e?.params??{},u.value={}})}),m}function xe(){return B()}var Se=class extends y{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return F`<div class="router-view">${()=>{let t=B(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?F`<span></span>`:n.route.chain[e]():F`<div style="color:#f87171;padding:16px 0">
|
|
2
|
-
404 —
|
|
3
|
-
</div>`}}</div>`}},Ce=class extends
|
|
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 A(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 ie(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 j=S("nix:portal-outlet");function ae(e){O(j,e)}function oe(){return k(j)}function se(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 ce(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 M(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function N(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(M(r.transitionDuration||"0"),M(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 le(e,t={}){let n=ce(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 N(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 N(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 ue(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 de(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 P(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function fe(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function pe(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 me(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 he(e,t,n){let r=[],o=[],l=pe(e),i=me(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(P(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 P(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(P(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(fe(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(P(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 F(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=ue(r);n.push(o),r+="__nix__"}let o=de(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:u,postMountHooks:a}=he(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 I(e,t){if(x(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${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 L(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 R=null,z=null;function B(){if(!R)throw Error("[Nix] No active router. Call createRouter() first.");return R}function V(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function H(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 ge(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 _e(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function U(e,t="",n=[]){let r=[];for(let o of e){let e=_e(t,o.path),l=[...n,o.component],i=ge(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...U(o.children,e,l))}return r}function ve(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 ye(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},o=-1;for(let l of t){let t=ve(e,l);if(null===t)continue;let i=ye(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function be(e){function t(){return window.location.pathname||"/"}let n=t(),r=U(e),o=W(n,r),l=p(n),i=p(o?.params??{}),u=p(V(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():v(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?{}:V(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}}z&&=(z(),null);let m=()=>{let e=t(),n=l.value,o=u.value,a=W(e,r),c=V(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+H(o))})};function y(e,t,n,r,o){i.value=r?.params??{},u.value=t,l.value=e;let a=e+H(t);o?history.replaceState(null,"",a):history.pushState(null,"",a);for(let t of s)try{t(e,n)}catch{}}function v(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,u=W(n,r);f(n,i,u?.route.beforeEnter,()=>y(n,o,i,u,!1))}window.addEventListener("popstate",m),z=()=>window.removeEventListener("popstate",m);let x={current:l,params:i,query:u,navigate:v,replace:function(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,u=W(n,r);f(n,i,u?.route.beforeEnter,()=>y(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=W(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 R&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),R=x,queueMicrotask(()=>{d||f(n,"",W(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=W("/",r);l.value="/",i.value=e?.params??{},u.value={}})}),x}function xe(){return B()}var Se=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return F`<div class="router-view">${()=>{let t=B(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?F`<span></span>`:n.route.chain[e]():F`<div style="color:#f87171;padding:16px 0">
|
|
2
|
+
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
+
</div>`}}</div>`}},Ce=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return F`<a
|
|
4
4
|
href=${e}
|
|
5
5
|
style=${()=>B().current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"}
|
|
6
6
|
@click=${t=>{t.preventDefault(),B().navigate(e)}}
|
|
@@ -11,11 +11,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=null,t=
|
|
|
11
11
|
border:2px solid #38bdf840;border-top-color:#38bdf8;
|
|
12
12
|
animation:nix-spin .7s linear infinite
|
|
13
13
|
"></span>
|
|
14
|
-
|
|
14
|
+
Loading…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
17
|
`,u=o??(e=>F`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends
|
|
21
|
+
`);return new class extends b{_state=p({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return F`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?u(e.error):t(e.data)}}</div>`}}}function we(e,t){let n=null;return()=>n?new n:G(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function K(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function q(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function J(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Y(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function X(e="Invalid email"){return Y(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Z(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Te(e){return e}const Ee={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function De(e,t){return{...e,...t}}function $(e,t=[]){let n=p(e),r=p(!1),o=p(!1),l=p(null),i=h(()=>{if(l.value)return l.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function u(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=u(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 Oe(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=$(e[r],o)}let r=h(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=h(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),l=h(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),i=h(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function u(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 u(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:u}}exports.Link=Ce,exports.NixComponent=b,exports.RouterView=Se,exports.Signal=f,exports.batch=g,exports.computed=h,exports.createErrorBoundary=se,exports.createForm=Oe,exports.createInjectionKey=S,exports.createPortalOutlet=re,exports.createRouter=be,exports.createStore=L,exports.createValidator=Te,exports.effect=m,exports.email=X,exports.extendValidators=De,exports.html=F,exports.inject=k,exports.injectOutlet=oe,exports.lazy=we,exports.max=Q,exports.maxLength=J,exports.min=Z,exports.minLength=q,exports.mount=I,exports.nextTick=y,exports.pattern=Y,exports.portal=ie,exports.portalOutlet=A,exports.provide=O,exports.provideOutlet=ae,exports.ref=ee,exports.repeat=ne,exports.required=K,exports.showWhen=te,exports.signal=p,exports.suspend=G,exports.transition=le,exports.untrack=_,exports.useField=$,exports.useRouter=xe,exports.validators=Ee,exports.watch=v;
|
package/dist/lib/nix-js.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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 ee(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 v(e){return e?Promise.resolve().then(e):Promise.resolve()}var y=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 b(e){return"object"==typeof e&&!!e&&!0===e.__isNixComponent}function x(e){return Symbol(e)}var S=[];function C(){return[...S]}function w(){S.push(new Map)}function T(){S.pop()}function E(e,t){let n=S.splice(0);e.forEach(e=>S.push(e)),S.push(new Map);try{return t()}finally{S.splice(0),n.forEach(e=>S.push(e))}}function D(e,t){let n=S[S.length-1];if(!n)throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");n.set(e,t)}function O(e){for(let t=S.length-1;t>=0;t--)if(S[t].has(e))return S[t].get(e)}function te(){return{el:null}}function ne(e,t){t?"none"===e.style.display&&(e.style.display=""):"none"!==e.style.display&&(e.style.display="none")}function re(e,t,n){return{__isKeyedList:!0,items:e,keyFn:t,renderFn:n}}function ie(){return{__isPortalOutlet:!0,_container:null}}function ae(e){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(t,n){let r=document.createElement("div");return r.setAttribute("data-nix-outlet",""),e._container=r,t.insertBefore(r,n),()=>{e._container=null,r.remove()}}}}function oe(e,t=document.body){return{__isNixTemplate:!0,mount(e){let t="string"==typeof e?document.querySelector(e)??document.body:e;return{unmount:this._render(t,null)}},_render(n,r){let o;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,b(e)){let t,n;w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}t=e.render()._render(o,null)}finally{T()}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 k=x("nix:portal-outlet");function se(e){D(k,e)}function ce(){return O(k)}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||b(t)?t:t(e);if(b(o)){let e,t;w();try{try{o.onInit?.()}catch{}e=o.render()._render(n,r)}finally{T()}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(b(e)){w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}a=e.render()._render(n,r)}finally{T()}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 A(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=A(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(b(e)){let t,n=e;w();try{try{n.onInit?.()}catch{}t=n.render()}finally{T()}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||b(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 P(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(b(u)){let e,n,l=u;w();try{try{l.onInit?.()}catch(t){if(!l.onError)throw t;l.onError(t)}e=l.render()._render(s.parentNode,s)}finally{T()}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(b(e)){let n,l;w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(s.parentNode,s)}finally{T()}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=C(),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(b(e)){let t,n,r=e;E(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(b(s)){let r,o;E(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(b(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 F(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}=P(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 I(e,t){if(b(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);w();try{try{e.onInit?.()}catch(t){if(!e.onError)throw t;e.onError(t)}n=e.render()._render(o,null)}finally{T()}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 L(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 R=null,z=null;function B(){if(!R)throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");return R}function V(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function H(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 ge(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 _e(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function U(e,t="",n=[]){let r=[];for(let o of e){let e=_e(t,o.path),l=[...n,o.component],i=ge(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...U(o.children,e,l))}return r}function ve(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 ye(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},o=-1;for(let l of t){let t=ve(e,l);if(null===t)continue;let i=ye(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function be(e){function t(){return window.location.pathname||"/"}let n=t(),r=U(e),o=W(n,r),l=p(n),i=p(o?.params??{}),a=p(V(window.location.search)),u=[],s=0;function c(e,t,n,r,o){let l=[...u];n&&l.push(n);let i=++s;if(0===l.length)return void r();let a=0;!function n(u){if(i!==s)return;if(!1===u)return void o?.();if("string"==typeof u)return void(u===e?r():h(u));if(a>=l.length)return void r();let c=l[a++](e,t);c instanceof Promise?c.then(n):n(c)}(void 0)}let f=!1;z&&=(z(),null);let d=()=>{let e=t(),n=l.value,o=a.value,u=W(e,r),s=V(window.location.search);c(e,n,u?.route.beforeEnter,()=>{i.value=u?.params??{},a.value=s,l.value=e},()=>{history.pushState(null,"",n+H(o))})};function h(e,t){f=!0;let{pathname:n,stringQuery:o}=function(e,t){let n=e.indexOf("?"),r=-1===n?e:e.slice(0,n),o=-1===n?{}:V(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}}(e,t),u=l.value,s=W(n,r);c(n,u,s?.route.beforeEnter,()=>{i.value=s?.params??{},a.value=o,l.value=n,history.pushState(null,"",n+H(o))})}window.addEventListener("popstate",d),z=()=>window.removeEventListener("popstate",d);let m={current:l,params:i,query:a,navigate:h,beforeEach:function(e){return u.push(e),()=>{let t=u.indexOf(e);-1!==t&&u.splice(t,1)}},routes:e,_flat:r,_guards:u};return R&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),R=m,queueMicrotask(()=>{f||c(n,"",W(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=W("/",r);l.value="/",i.value=e?.params??{},a.value={}})}),m}function xe(){return B()}var Se=class extends y{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return F`<div class="router-view">${()=>{let t=B(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?F`<span></span>`:n.route.chain[e]():F`<div style="color:#f87171;padding:16px 0">
|
|
2
|
-
404 —
|
|
3
|
-
</div>`}}</div>`}},Ce=class extends
|
|
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 A(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 ie(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 j=S("nix:portal-outlet");function ae(e){O(j,e)}function oe(){return k(j)}function se(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 ce(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 M(e){return Math.max(0,...e.split(",").map(e=>parseFloat(e)||0))}function N(e,t=0){return new Promise(n=>{let r=getComputedStyle(e),o=1e3*Math.max(M(r.transitionDuration||"0"),M(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 le(e,t={}){let n=ce(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 N(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 N(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 ue(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 de(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 P(e){return"object"==typeof e&&!!e&&!0===e.__isNixTemplate}function fe(e){return"object"==typeof e&&!!e&&!0===e.__isKeyedList}function pe(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 me(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 he(e,t,n){let r=[],o=[],l=pe(e),i=me(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(P(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 P(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(P(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(fe(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(P(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 F(e,...t){let n=[],r="";for(let t=0;t<e.length-1;t++){r+=e[t];let o=ue(r);n.push(o),r+="__nix__"}let o=de(e,n);function l(e,r){let l=document.createElement("template");l.innerHTML=o;let i=l.content,{disposes:a,postMountHooks:u}=he(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 I(e,t){if(x(e)){let n,r,o="string"==typeof t?document.querySelector(t):t;if(!o)throw Error(`[Nix] mount: contenedor no encontrado: ${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 L(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 R=null,z=null;function B(){if(!R)throw Error("[Nix] No active router. Call createRouter() first.");return R}function V(e){let t={};return new URLSearchParams(e).forEach((e,n)=>{t[n]=e}),t}function H(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 ge(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 _e(e,t){return"*"===t?""===e?"*":e+"/*":(e+(t.startsWith("/")?t:"/"+t)).replace(/\/+/g,"/")||"/"}function U(e,t="",n=[]){let r=[];for(let o of e){let e=_e(t,o.path),l=[...n,o.component],i=ge(e);r.push({fullPath:e,segments:i,chain:l,beforeEnter:o.beforeEnter}),o.children?.length&&r.push(...U(o.children,e,l))}return r}function ve(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 ye(e){return e.segments.reduce((e,t)=>"literal"===t.kind?e+2:"param"===t.kind?e+1:e,0)}function W(e,t){let n,r={},o=-1;for(let l of t){let t=ve(e,l);if(null===t)continue;let i=ye(l);i>o&&(n=l,r=t,o=i)}return n?{route:n,params:r}:void 0}function be(e){function t(){return window.location.pathname||"/"}let n=t(),r=U(e),o=W(n,r),l=p(n),i=p(o?.params??{}),a=p(V(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():v(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?{}:V(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}}z&&=(z(),null);let m=()=>{let e=t(),n=l.value,o=a.value,u=W(e,r),c=V(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+H(o))})};function y(e,t,n,r,o){i.value=r?.params??{},a.value=t,l.value=e;let u=e+H(t);o?history.replaceState(null,"",u):history.pushState(null,"",u);for(let t of s)try{t(e,n)}catch{}}function v(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,a=W(n,r);f(n,i,a?.route.beforeEnter,()=>y(n,o,i,a,!1))}window.addEventListener("popstate",m),z=()=>window.removeEventListener("popstate",m);let g={current:l,params:i,query:a,navigate:v,replace:function(e,t){d=!0;let{pathname:n,stringQuery:o}=h(e,t),i=l.value,a=W(n,r);f(n,i,a?.route.beforeEnter,()=>y(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=W(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 R&&console.warn("[Nix] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."),R=g,queueMicrotask(()=>{d||f(n,"",W(n,r)?.route.beforeEnter,()=>{},()=>{history.replaceState(null,"","/");let e=W("/",r);l.value="/",i.value=e?.params??{},a.value={}})}),g}function xe(){return B()}var Se=class extends b{_depth;constructor(e=0){super(),this._depth=e}render(){let e=this._depth;return F`<div class="router-view">${()=>{let t=B(),n=W(t.current.value,t._flat);return n?e>=n.route.chain.length?F`<span></span>`:n.route.chain[e]():F`<div style="color:#f87171;padding:16px 0">
|
|
2
|
+
404 — Route not found: <strong>${t.current.value}</strong>
|
|
3
|
+
</div>`}}</div>`}},Ce=class extends b{_to;_label;constructor(e,t){super(),this._to=e,this._label=t}render(){let e=this._to;return F`<a
|
|
4
4
|
href=${e}
|
|
5
5
|
style=${()=>B().current.value===e?"color:#38bdf8;font-weight:700;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px;background:#0c2a3a":"color:#a3a3a3;text-decoration:none;cursor:pointer;padding:4px 10px;border-radius:4px"}
|
|
6
6
|
@click=${t=>{t.preventDefault(),B().navigate(e)}}
|
|
@@ -11,11 +11,11 @@ var e=null,t=[],n=null,r=[],i=null,a=[];function o(e){a.push(i),i=e}function s()
|
|
|
11
11
|
border:2px solid #38bdf840;border-top-color:#38bdf8;
|
|
12
12
|
animation:nix-spin .7s linear infinite
|
|
13
13
|
"></span>
|
|
14
|
-
|
|
14
|
+
Loading…
|
|
15
15
|
</span>
|
|
16
16
|
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
17
17
|
`,a=o??(e=>F`
|
|
18
18
|
<span style="color:#f87171;font-size:13px">
|
|
19
19
|
⚠ ${e instanceof Error?e.message:String(e)}
|
|
20
20
|
</span>
|
|
21
|
-
`);return new class extends
|
|
21
|
+
`);return new class extends b{_state=p({status:"pending"});onMount(){this._run()}_run(){(l||"pending"===this._state.peek().status)&&(this._state.value={status:"pending"}),e().then(e=>{this._state.value={status:"resolved",data:e}},e=>{this._state.value={status:"error",error:e}})}render(){return F`<div class="nix-suspense" style="display:contents">${()=>{let e=this._state.value;return"pending"===e.status?i:"error"===e.status?a(e.error):t(e.data)}}</div>`}}}function we(e,t){let n=null;return()=>n?new n:G(async()=>(n=(await e()).default,n),e=>new e,{fallback:t})}function K(e="Required"){return t=>null==t||""===t||Array.isArray(t)&&0===t.length?e:null}function q(e,t){return n=>"string"==typeof n&&n.length<e?t??`Minimum ${e} characters`:null}function J(e,t){return n=>"string"==typeof n&&n.length>e?t??`Maximum ${e} characters`:null}function Y(e,t="Invalid format"){return n=>"string"!=typeof n||e.test(n)?null:t}function X(e="Invalid email"){return Y(/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e)}function Z(e,t){return n=>"number"==typeof n&&n<e?t??`Minimum value is ${e}`:null}function Q(e,t){return n=>"number"==typeof n&&n>e?t??`Maximum value is ${e}`:null}function Te(e){return e}const Ee={required:K,minLength:q,maxLength:J,email:X,pattern:Y,min:Z,max:Q};function De(e,t){return{...e,...t}}function $(e,t=[]){let n=p(e),r=p(!1),o=p(!1),l=p(null),i=h(()=>{if(l.value)return l.value;if(!r.value&&!o.value)return null;for(let e of t){let t=e(n.value);if(t)return t}return null});function a(t){if(!t||!("value"in t))return e;let n=t;return"boolean"==typeof e?n.checked:"number"==typeof e?Number(n.value):n.value}return{value:n,error:i,touched:r,dirty:o,onInput:e=>{n.value=a(e.target),o.value=!0,l.value=null},onBlur:()=>{r.value=!0},reset:function(){n.value=e,r.value=!1,o.value=!1,l.value=null},_setExternalError:function(e){l.value=e,e&&(r.value=!0)}}}function Oe(e,t={}){let n={};for(let r in e){let o=t.validators?.[r]??[];n[r]=$(e[r],o)}let r=h(()=>{let e={};for(let t in n)e[t]=n[t].value.value;return e}),o=h(()=>{let e={};for(let t in n){let r=n[t].error.value;r&&(e[t]=r)}return e}),l=h(()=>{for(let e in n)if(n[e].error.value)return!1;return!0}),i=h(()=>{for(let e in n)if(n[e].dirty.value)return!0;return!1});function a(e){for(let t in e)n[t]?._setExternalError(e[t]??null)}return{fields:n,values:r,errors:o,valid:l,dirty:i,handleSubmit:function(e){return o=>{o.preventDefault();for(let e in n)n[e].touched.value=!0;let l=r.value;if(t.validate){let e=t.validate(l);if(e){let t={},n=!1;for(let r in e){let o=e[r],l=Array.isArray(o)?o[0]??null:o??null;l&&(t[r]=l,n=!0)}if(n)return void a(t)}}for(let e in n)if(n[e].error.value)return;e(l)}},reset:function(){for(let e in n)n[e].reset()},setErrors:a}}export{Ce as Link,b as NixComponent,Se as RouterView,f as Signal,g as batch,h as computed,se as createErrorBoundary,Oe as createForm,S as createInjectionKey,re as createPortalOutlet,be as createRouter,L as createStore,Te as createValidator,m as effect,X as email,De as extendValidators,F as html,k as inject,oe as injectOutlet,we as lazy,Q as max,J as maxLength,Z as min,q as minLength,I as mount,y as nextTick,Y as pattern,ie as portal,A as portalOutlet,O as provide,ae as provideOutlet,ee as ref,ne as repeat,K as required,te as showWhen,p as signal,G as suspend,le as transition,_ as untrack,$ as useField,xe as useRouter,Ee as validators,v as watch};
|