@deijose/nix-js 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1024 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/nix/async.d.ts +69 -0
- package/dist/lib/nix/component.d.ts +13 -0
- package/dist/lib/nix/context.d.ts +61 -0
- package/dist/lib/nix/index.d.ts +14 -0
- package/dist/lib/nix/lifecycle.d.ts +70 -0
- package/dist/lib/nix/reactivity.d.ts +116 -0
- package/dist/lib/nix/router.d.ts +115 -0
- package/dist/lib/nix/store.d.ts +40 -0
- package/dist/lib/nix/template.d.ts +62 -0
- package/dist/lib/nix-js.cjs +22 -0
- package/dist/lib/nix-js.js +764 -0
- package/package.json +62 -0
- package/src/index.ts +61 -0
- package/src/nix/async.ts +164 -0
- package/src/nix/component.ts +76 -0
- package/src/nix/context.ts +142 -0
- package/src/nix/index.ts +14 -0
- package/src/nix/lifecycle.ts +112 -0
- package/src/nix/reactivity.ts +308 -0
- package/src/nix/router.ts +393 -0
- package/src/nix/store.ts +117 -0
- package/src/nix/template.ts +793 -0
|
@@ -0,0 +1,764 @@
|
|
|
1
|
+
var e = null, t = [], n = null, r = [], i = 0, a = new Set(), o = class {
|
|
2
|
+
_value;
|
|
3
|
+
_subs = new Set();
|
|
4
|
+
constructor(e) {
|
|
5
|
+
this._value = e;
|
|
6
|
+
}
|
|
7
|
+
get value() {
|
|
8
|
+
return e && (this._subs.add(e), n?.add(this)), this._value;
|
|
9
|
+
}
|
|
10
|
+
set value(e) {
|
|
11
|
+
Object.is(this._value, e) || (this._value = e, this._notify());
|
|
12
|
+
}
|
|
13
|
+
update(e) {
|
|
14
|
+
this.value = e(this._value);
|
|
15
|
+
}
|
|
16
|
+
peek() {
|
|
17
|
+
return this._value;
|
|
18
|
+
}
|
|
19
|
+
_removeSub(e) {
|
|
20
|
+
this._subs.delete(e);
|
|
21
|
+
}
|
|
22
|
+
_notify() {
|
|
23
|
+
let e = [...this._subs];
|
|
24
|
+
i > 0 ? e.forEach((e) => a.add(e)) : e.forEach((e) => e());
|
|
25
|
+
}
|
|
26
|
+
dispose() {
|
|
27
|
+
this._subs.clear();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
function s(e) {
|
|
31
|
+
return new o(e);
|
|
32
|
+
}
|
|
33
|
+
function c(i) {
|
|
34
|
+
let a, o = new Set(), s = () => {
|
|
35
|
+
typeof a == "function" && a(), o.forEach((e) => e._removeSub(s)), o = new Set(), t.push(e), r.push(n), e = s, n = o;
|
|
36
|
+
try {
|
|
37
|
+
a = i();
|
|
38
|
+
} finally {
|
|
39
|
+
e = t.pop() || null, n = r.pop() || null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
return s(), () => {
|
|
43
|
+
typeof a == "function" && a(), o.forEach((e) => e._removeSub(s)), o.clear();
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function l(e) {
|
|
47
|
+
let t = new o(void 0);
|
|
48
|
+
return c(() => {
|
|
49
|
+
t.value = e();
|
|
50
|
+
}), t;
|
|
51
|
+
}
|
|
52
|
+
function u(e) {
|
|
53
|
+
i++;
|
|
54
|
+
try {
|
|
55
|
+
e();
|
|
56
|
+
} finally {
|
|
57
|
+
if (i--, i === 0) {
|
|
58
|
+
let e = [...a];
|
|
59
|
+
a.clear(), e.forEach((e) => e());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function d(t) {
|
|
64
|
+
let r = e, i = n;
|
|
65
|
+
e = null, n = null;
|
|
66
|
+
try {
|
|
67
|
+
return t();
|
|
68
|
+
} finally {
|
|
69
|
+
e = r, n = i;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function f(e, t, n = {}) {
|
|
73
|
+
let { immediate: r = !1, once: i = !1 } = n, a = e instanceof o ? () => e.value : e, s, l = !0, u = !1, f = c(() => {
|
|
74
|
+
let e = a();
|
|
75
|
+
if (l) {
|
|
76
|
+
if (l = !1, r && !u) {
|
|
77
|
+
let n = e;
|
|
78
|
+
d(() => t(n, void 0)), i && (u = !0, Promise.resolve().then(f));
|
|
79
|
+
}
|
|
80
|
+
s = e;
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (!u) {
|
|
84
|
+
let n = e, r = s;
|
|
85
|
+
s = e, d(() => t(n, r)), i && (u = !0, Promise.resolve().then(f));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
return () => {
|
|
89
|
+
u = !0, f();
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function p(e) {
|
|
93
|
+
return e ? Promise.resolve().then(e) : Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
var m = class {
|
|
96
|
+
__isNixComponent = !0;
|
|
97
|
+
};
|
|
98
|
+
function h(e) {
|
|
99
|
+
return typeof e == "object" && !!e && e.__isNixComponent === !0;
|
|
100
|
+
}
|
|
101
|
+
function g(e) {
|
|
102
|
+
return Symbol(e);
|
|
103
|
+
}
|
|
104
|
+
var _ = [];
|
|
105
|
+
function v() {
|
|
106
|
+
return [..._];
|
|
107
|
+
}
|
|
108
|
+
function y() {
|
|
109
|
+
_.push(new Map());
|
|
110
|
+
}
|
|
111
|
+
function b() {
|
|
112
|
+
_.pop();
|
|
113
|
+
}
|
|
114
|
+
function x(e, t) {
|
|
115
|
+
let n = _.splice(0);
|
|
116
|
+
e.forEach((e) => _.push(e)), _.push(new Map());
|
|
117
|
+
try {
|
|
118
|
+
return t();
|
|
119
|
+
} finally {
|
|
120
|
+
_.splice(0), n.forEach((e) => _.push(e));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function S(e, t) {
|
|
124
|
+
let n = _[_.length - 1];
|
|
125
|
+
if (!n) throw Error("[Nix] provide() debe llamarse dentro de onInit() de un NixComponent.");
|
|
126
|
+
n.set(e, t);
|
|
127
|
+
}
|
|
128
|
+
function C(e) {
|
|
129
|
+
for (let t = _.length - 1; t >= 0; t--) if (_[t].has(e)) return _[t].get(e);
|
|
130
|
+
}
|
|
131
|
+
function w() {
|
|
132
|
+
return { el: null };
|
|
133
|
+
}
|
|
134
|
+
function T(e, t, n) {
|
|
135
|
+
return {
|
|
136
|
+
__isKeyedList: !0,
|
|
137
|
+
items: e,
|
|
138
|
+
keyFn: t,
|
|
139
|
+
renderFn: n
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function E(e) {
|
|
143
|
+
let t = e.lastIndexOf(">"), n = e.lastIndexOf("<");
|
|
144
|
+
if (n <= t) return { type: "node" };
|
|
145
|
+
let r = e.slice(n + 1), i = r.match(/@([\w:.-]+)=["']?$/);
|
|
146
|
+
if (i) {
|
|
147
|
+
let e = i[1].split(".");
|
|
148
|
+
return {
|
|
149
|
+
type: "event",
|
|
150
|
+
eventName: e[0],
|
|
151
|
+
modifiers: e.slice(1),
|
|
152
|
+
hadOpenQuote: i[0].endsWith("\"") || i[0].endsWith("'")
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
let a = r.match(/([\w:.-]+)=["']?$/);
|
|
156
|
+
return a ? {
|
|
157
|
+
type: "attr",
|
|
158
|
+
attrName: a[1],
|
|
159
|
+
hadOpenQuote: a[0].endsWith("\"") || a[0].endsWith("'")
|
|
160
|
+
} : { type: "node" };
|
|
161
|
+
}
|
|
162
|
+
function D(e, t) {
|
|
163
|
+
let n = Array(e.length).fill(0), r = "";
|
|
164
|
+
for (let i = 0; i < e.length; i++) {
|
|
165
|
+
let a = e[i];
|
|
166
|
+
if (n[i] === 1 && (a[0] === "\"" || a[0] === "'") && (a = a.slice(1)), i < t.length) {
|
|
167
|
+
let e = t[i];
|
|
168
|
+
if (e.type === "node") r += a + `<!--nix-${i}-->`;
|
|
169
|
+
else if (e.type === "event") {
|
|
170
|
+
let t = `@${e.modifiers.length ? `${e.eventName}.${e.modifiers.join(".")}` : e.eventName}=`.length + (e.hadOpenQuote ? 1 : 0);
|
|
171
|
+
r += a.slice(0, -t) + ` data-nix-e-${i}="${e.eventName}"`, e.hadOpenQuote && (n[i + 1] = 1);
|
|
172
|
+
} else {
|
|
173
|
+
let t = `${e.attrName}=`.length + (e.hadOpenQuote ? 1 : 0);
|
|
174
|
+
r += a.slice(0, -t) + ` data-nix-a-${i}="${e.attrName}"`, e.hadOpenQuote && (n[i + 1] = 1);
|
|
175
|
+
}
|
|
176
|
+
} else r += a;
|
|
177
|
+
}
|
|
178
|
+
return r;
|
|
179
|
+
}
|
|
180
|
+
function O(e) {
|
|
181
|
+
return typeof e == "object" && !!e && e.__isNixTemplate === !0;
|
|
182
|
+
}
|
|
183
|
+
function k(e) {
|
|
184
|
+
return typeof e == "object" && !!e && e.__isKeyedList === !0;
|
|
185
|
+
}
|
|
186
|
+
function A(e) {
|
|
187
|
+
let t = new Map(), n = document.createTreeWalker(e, NodeFilter.SHOW_COMMENT), r;
|
|
188
|
+
for (; r = n.nextNode();) {
|
|
189
|
+
let e = r, n = e.nodeValue?.match(/^nix-(\d+)$/);
|
|
190
|
+
n && t.set(parseInt(n[1]), e);
|
|
191
|
+
}
|
|
192
|
+
return t;
|
|
193
|
+
}
|
|
194
|
+
function j(e) {
|
|
195
|
+
let t = new Map();
|
|
196
|
+
return e.querySelectorAll("*").forEach((e) => {
|
|
197
|
+
let n = Array.from(e.attributes);
|
|
198
|
+
for (let r of n) {
|
|
199
|
+
let n = r.name.match(/^data-nix-e-(\d+)$/);
|
|
200
|
+
if (n) {
|
|
201
|
+
t.set(parseInt(n[1]), {
|
|
202
|
+
el: e,
|
|
203
|
+
type: "event",
|
|
204
|
+
name: r.value
|
|
205
|
+
}), e.removeAttribute(r.name);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
n = r.name.match(/^data-nix-a-(\d+)$/), n && (t.set(parseInt(n[1]), {
|
|
209
|
+
el: e,
|
|
210
|
+
type: "attr",
|
|
211
|
+
name: r.value
|
|
212
|
+
}), e.removeAttribute(r.name));
|
|
213
|
+
}
|
|
214
|
+
}), t;
|
|
215
|
+
}
|
|
216
|
+
function M(e, t, n) {
|
|
217
|
+
let r = [], i = [], a = A(e), o = j(e);
|
|
218
|
+
for (let e = 0; e < t.length; e++) {
|
|
219
|
+
let s = t[e], l = n[e];
|
|
220
|
+
if (s.type === "event") {
|
|
221
|
+
let t = o.get(e);
|
|
222
|
+
if (!t) continue;
|
|
223
|
+
let { el: n, name: i } = t, a = l, c = s.modifiers, u = {};
|
|
224
|
+
c.includes("once") && (u.once = !0), c.includes("capture") && (u.capture = !0), c.includes("passive") && (u.passive = !0);
|
|
225
|
+
let d = {
|
|
226
|
+
enter: "Enter",
|
|
227
|
+
escape: "Escape",
|
|
228
|
+
space: " ",
|
|
229
|
+
tab: "Tab",
|
|
230
|
+
delete: "Delete",
|
|
231
|
+
backspace: "Backspace",
|
|
232
|
+
up: "ArrowUp",
|
|
233
|
+
down: "ArrowDown",
|
|
234
|
+
left: "ArrowLeft",
|
|
235
|
+
right: "ArrowRight"
|
|
236
|
+
}, f = (e) => {
|
|
237
|
+
if (c.includes("prevent") && e.preventDefault(), c.includes("stop") && e.stopPropagation(), !(c.includes("self") && e.target !== e.currentTarget)) {
|
|
238
|
+
if ("key" in e) {
|
|
239
|
+
let t = e;
|
|
240
|
+
for (let e of c) {
|
|
241
|
+
let n = d[e];
|
|
242
|
+
if (n !== void 0 && t.key !== n || !d[e] && e.length === 1 && t.key.toLowerCase() !== e) return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
a(e);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
n.addEventListener(i, f, u), r.push(() => n.removeEventListener(i, f, u));
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
if (s.type === "attr") {
|
|
252
|
+
let t = o.get(e);
|
|
253
|
+
if (!t) continue;
|
|
254
|
+
let { el: n, name: i } = t;
|
|
255
|
+
if (i === "ref") {
|
|
256
|
+
l.el = n, r.push(() => {
|
|
257
|
+
l.el = null;
|
|
258
|
+
});
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (typeof l == "function") {
|
|
262
|
+
let e = c(() => {
|
|
263
|
+
let e = l();
|
|
264
|
+
e == null || e === !1 ? n.removeAttribute(i) : n.setAttribute(i, String(e));
|
|
265
|
+
});
|
|
266
|
+
r.push(e);
|
|
267
|
+
} else l != null && l !== !1 && n.setAttribute(i, String(l));
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
let u = a.get(e);
|
|
271
|
+
if (!u) continue;
|
|
272
|
+
if (typeof l != "function") {
|
|
273
|
+
if (h(l)) {
|
|
274
|
+
let e = l;
|
|
275
|
+
y();
|
|
276
|
+
let t;
|
|
277
|
+
try {
|
|
278
|
+
try {
|
|
279
|
+
e.onInit?.();
|
|
280
|
+
} catch (t) {
|
|
281
|
+
if (e.onError) e.onError(t);
|
|
282
|
+
else throw t;
|
|
283
|
+
}
|
|
284
|
+
t = e.render()._render(u.parentNode, u);
|
|
285
|
+
} finally {
|
|
286
|
+
b();
|
|
287
|
+
}
|
|
288
|
+
let n;
|
|
289
|
+
i.push(() => {
|
|
290
|
+
try {
|
|
291
|
+
let t = e.onMount?.();
|
|
292
|
+
typeof t == "function" && (n = t);
|
|
293
|
+
} catch (t) {
|
|
294
|
+
if (e.onError) e.onError(t);
|
|
295
|
+
else throw t;
|
|
296
|
+
}
|
|
297
|
+
}), r.push(() => {
|
|
298
|
+
try {
|
|
299
|
+
e.onUnmount?.();
|
|
300
|
+
} catch {}
|
|
301
|
+
try {
|
|
302
|
+
n?.();
|
|
303
|
+
} catch {}
|
|
304
|
+
t();
|
|
305
|
+
});
|
|
306
|
+
} else if (O(l)) l._render(u.parentNode, u);
|
|
307
|
+
else if (Array.isArray(l)) for (let e of l) if (h(e)) {
|
|
308
|
+
let t;
|
|
309
|
+
y();
|
|
310
|
+
try {
|
|
311
|
+
try {
|
|
312
|
+
e.onInit?.();
|
|
313
|
+
} catch (t) {
|
|
314
|
+
if (e.onError) e.onError(t);
|
|
315
|
+
else throw t;
|
|
316
|
+
}
|
|
317
|
+
t = e.render()._render(u.parentNode, u);
|
|
318
|
+
} finally {
|
|
319
|
+
b();
|
|
320
|
+
}
|
|
321
|
+
let n;
|
|
322
|
+
i.push(() => {
|
|
323
|
+
try {
|
|
324
|
+
let t = e.onMount?.();
|
|
325
|
+
typeof t == "function" && (n = t);
|
|
326
|
+
} catch (t) {
|
|
327
|
+
if (e.onError) e.onError(t);
|
|
328
|
+
else throw t;
|
|
329
|
+
}
|
|
330
|
+
}), r.push(() => {
|
|
331
|
+
try {
|
|
332
|
+
e.onUnmount?.();
|
|
333
|
+
} catch {}
|
|
334
|
+
try {
|
|
335
|
+
n?.();
|
|
336
|
+
} catch {}
|
|
337
|
+
t();
|
|
338
|
+
});
|
|
339
|
+
} else O(e) ? e._render(u.parentNode, u) : e != null && e !== !1 && u.parentNode.insertBefore(document.createTextNode(String(e)), u);
|
|
340
|
+
else l != null && l !== !1 && u.parentNode.insertBefore(document.createTextNode(String(l)), u);
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
let d = null, f = null, p = null, m = v(), g = c(() => {
|
|
344
|
+
let e = l();
|
|
345
|
+
if (typeof e == "string" || typeof e == "number") {
|
|
346
|
+
f &&= (f(), null), d ? d.nodeValue = String(e) : (d = document.createTextNode(String(e)), u.parentNode.insertBefore(d, u));
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (d &&= (d.parentNode?.removeChild(d), null), f &&= (f(), null), !(e == null || e === !1)) if (O(e)) f = e._render(u.parentNode, u);
|
|
350
|
+
else if (h(e)) {
|
|
351
|
+
let t = e, n;
|
|
352
|
+
x(m, () => {
|
|
353
|
+
try {
|
|
354
|
+
t.onInit?.();
|
|
355
|
+
} catch (e) {
|
|
356
|
+
if (t.onError) t.onError(e);
|
|
357
|
+
else throw e;
|
|
358
|
+
}
|
|
359
|
+
n = t.render()._render(u.parentNode, u);
|
|
360
|
+
});
|
|
361
|
+
let r;
|
|
362
|
+
try {
|
|
363
|
+
let e = t.onMount?.();
|
|
364
|
+
typeof e == "function" && (r = e);
|
|
365
|
+
} catch (e) {
|
|
366
|
+
if (t.onError) t.onError(e);
|
|
367
|
+
else throw e;
|
|
368
|
+
}
|
|
369
|
+
f = () => {
|
|
370
|
+
try {
|
|
371
|
+
t.onUnmount?.();
|
|
372
|
+
} catch {}
|
|
373
|
+
try {
|
|
374
|
+
r?.();
|
|
375
|
+
} catch {}
|
|
376
|
+
n();
|
|
377
|
+
};
|
|
378
|
+
} else if (k(e)) {
|
|
379
|
+
p ||= new Map();
|
|
380
|
+
let t = u.parentNode, n = e.items.map((t, n) => e.keyFn(t, n)), r = new Set(n);
|
|
381
|
+
for (let [e, n] of p) if (!r.has(e)) {
|
|
382
|
+
n.cleanup();
|
|
383
|
+
let r = n.start;
|
|
384
|
+
for (; r !== n.end;) {
|
|
385
|
+
let e = r.nextSibling;
|
|
386
|
+
t.removeChild(r), r = e;
|
|
387
|
+
}
|
|
388
|
+
t.removeChild(n.end), p.delete(e);
|
|
389
|
+
}
|
|
390
|
+
let i = u;
|
|
391
|
+
for (let r = n.length - 1; r >= 0; r--) {
|
|
392
|
+
let a = n[r], o = e.items[r];
|
|
393
|
+
if (p.has(a)) {
|
|
394
|
+
let e = p.get(a);
|
|
395
|
+
if (e.end.nextSibling !== i) {
|
|
396
|
+
let n = [], r = e.start;
|
|
397
|
+
for (; n.push(r), r !== e.end;) r = r.nextSibling;
|
|
398
|
+
for (let e of n) t.insertBefore(e, i);
|
|
399
|
+
}
|
|
400
|
+
i = e.start;
|
|
401
|
+
} else {
|
|
402
|
+
let n = document.createComment("nix-ke"), s = document.createComment("nix-ks");
|
|
403
|
+
t.insertBefore(n, i), t.insertBefore(s, n);
|
|
404
|
+
let c, l = e.renderFn(o, r);
|
|
405
|
+
if (h(l)) {
|
|
406
|
+
let e;
|
|
407
|
+
x(m, () => {
|
|
408
|
+
try {
|
|
409
|
+
l.onInit?.();
|
|
410
|
+
} catch (e) {
|
|
411
|
+
if (l.onError) l.onError(e);
|
|
412
|
+
else throw e;
|
|
413
|
+
}
|
|
414
|
+
e = l.render()._render(t, n);
|
|
415
|
+
});
|
|
416
|
+
let r;
|
|
417
|
+
try {
|
|
418
|
+
let e = l.onMount?.();
|
|
419
|
+
typeof e == "function" && (r = e);
|
|
420
|
+
} catch (e) {
|
|
421
|
+
if (l.onError) l.onError(e);
|
|
422
|
+
else throw e;
|
|
423
|
+
}
|
|
424
|
+
c = () => {
|
|
425
|
+
try {
|
|
426
|
+
l.onUnmount?.();
|
|
427
|
+
} catch {}
|
|
428
|
+
try {
|
|
429
|
+
r?.();
|
|
430
|
+
} catch {}
|
|
431
|
+
e();
|
|
432
|
+
};
|
|
433
|
+
} else c = l._render(t, n);
|
|
434
|
+
p.set(a, {
|
|
435
|
+
start: s,
|
|
436
|
+
end: n,
|
|
437
|
+
cleanup: c
|
|
438
|
+
}), i = s;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
} else if (Array.isArray(e)) {
|
|
442
|
+
let t = [];
|
|
443
|
+
for (let n of e) if (h(n)) {
|
|
444
|
+
try {
|
|
445
|
+
n.onInit?.();
|
|
446
|
+
} catch (e) {
|
|
447
|
+
if (n.onError) n.onError(e);
|
|
448
|
+
else throw e;
|
|
449
|
+
}
|
|
450
|
+
let e = n.render()._render(u.parentNode, u), r;
|
|
451
|
+
try {
|
|
452
|
+
let e = n.onMount?.();
|
|
453
|
+
typeof e == "function" && (r = e);
|
|
454
|
+
} catch (e) {
|
|
455
|
+
if (n.onError) n.onError(e);
|
|
456
|
+
else throw e;
|
|
457
|
+
}
|
|
458
|
+
t.push(() => {
|
|
459
|
+
try {
|
|
460
|
+
n.onUnmount?.();
|
|
461
|
+
} catch {}
|
|
462
|
+
try {
|
|
463
|
+
r?.();
|
|
464
|
+
} catch {}
|
|
465
|
+
e();
|
|
466
|
+
});
|
|
467
|
+
} else if (O(n)) t.push(n._render(u.parentNode, u));
|
|
468
|
+
else if (n != null && n !== !1) {
|
|
469
|
+
let e = document.createTextNode(String(n));
|
|
470
|
+
u.parentNode.insertBefore(e, u), t.push(() => e.parentNode?.removeChild(e));
|
|
471
|
+
}
|
|
472
|
+
f = () => t.forEach((e) => e());
|
|
473
|
+
} else d = document.createTextNode(String(e)), u.parentNode.insertBefore(d, u);
|
|
474
|
+
});
|
|
475
|
+
r.push(() => {
|
|
476
|
+
if (g(), f &&= (f(), null), d &&= (d.parentNode?.removeChild(d), null), p) {
|
|
477
|
+
for (let e of p.values()) e.cleanup();
|
|
478
|
+
p = null;
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
disposes: r,
|
|
484
|
+
postMountHooks: i
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
function N(e, ...t) {
|
|
488
|
+
let n = [], r = "";
|
|
489
|
+
for (let t = 0; t < e.length - 1; t++) {
|
|
490
|
+
r += e[t];
|
|
491
|
+
let i = E(r);
|
|
492
|
+
n.push(i), r += "__nix__";
|
|
493
|
+
}
|
|
494
|
+
let i = D(e, n);
|
|
495
|
+
function a(e, r) {
|
|
496
|
+
let a = document.createElement("template");
|
|
497
|
+
a.innerHTML = i;
|
|
498
|
+
let o = a.content, { disposes: s, postMountHooks: c } = M(o, n, t), l = document.createComment("nix-scope");
|
|
499
|
+
e.insertBefore(l, r);
|
|
500
|
+
let u = o.firstChild;
|
|
501
|
+
for (; u;) {
|
|
502
|
+
let t = u.nextSibling;
|
|
503
|
+
e.insertBefore(u, r), u = t;
|
|
504
|
+
}
|
|
505
|
+
return c.forEach((e) => e()), () => {
|
|
506
|
+
s.forEach((e) => e());
|
|
507
|
+
let e = l.nextSibling;
|
|
508
|
+
for (; e && e !== r;) {
|
|
509
|
+
let t = e.nextSibling;
|
|
510
|
+
e.parentNode?.removeChild(e), e = t;
|
|
511
|
+
}
|
|
512
|
+
l.parentNode?.removeChild(l);
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
return {
|
|
516
|
+
__isNixTemplate: !0,
|
|
517
|
+
_render: a,
|
|
518
|
+
mount(e) {
|
|
519
|
+
let t = typeof e == "string" ? document.querySelector(e) : e;
|
|
520
|
+
if (!t) throw Error(`[Nix] mount: contenedor no encontrado: ${e}`);
|
|
521
|
+
let n = a(t, null);
|
|
522
|
+
return { unmount() {
|
|
523
|
+
n();
|
|
524
|
+
} };
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function P(e, t) {
|
|
529
|
+
if (h(e)) {
|
|
530
|
+
let n = typeof t == "string" ? document.querySelector(t) : t;
|
|
531
|
+
if (!n) throw Error(`[Nix] mount: contenedor no encontrado: ${t}`);
|
|
532
|
+
y();
|
|
533
|
+
let r;
|
|
534
|
+
try {
|
|
535
|
+
try {
|
|
536
|
+
e.onInit?.();
|
|
537
|
+
} catch (t) {
|
|
538
|
+
if (e.onError) e.onError(t);
|
|
539
|
+
else throw t;
|
|
540
|
+
}
|
|
541
|
+
r = e.render()._render(n, null);
|
|
542
|
+
} finally {
|
|
543
|
+
b();
|
|
544
|
+
}
|
|
545
|
+
let i;
|
|
546
|
+
try {
|
|
547
|
+
let t = e.onMount?.();
|
|
548
|
+
typeof t == "function" && (i = t);
|
|
549
|
+
} catch (t) {
|
|
550
|
+
if (e.onError) e.onError(t);
|
|
551
|
+
else throw t;
|
|
552
|
+
}
|
|
553
|
+
return { unmount() {
|
|
554
|
+
try {
|
|
555
|
+
e.onUnmount?.();
|
|
556
|
+
} catch {}
|
|
557
|
+
try {
|
|
558
|
+
i?.();
|
|
559
|
+
} catch {}
|
|
560
|
+
r();
|
|
561
|
+
} };
|
|
562
|
+
}
|
|
563
|
+
return e.mount(t);
|
|
564
|
+
}
|
|
565
|
+
function F(e, t) {
|
|
566
|
+
let n = {};
|
|
567
|
+
for (let t of Object.keys(e)) n[t] = s(e[t]);
|
|
568
|
+
let r = n;
|
|
569
|
+
function i() {
|
|
570
|
+
for (let t of Object.keys(e)) n[t].value = e[t];
|
|
571
|
+
}
|
|
572
|
+
let a = Object.assign(Object.create(null), r, { $reset: i });
|
|
573
|
+
if (t) {
|
|
574
|
+
let e = t(r);
|
|
575
|
+
Object.assign(a, e);
|
|
576
|
+
}
|
|
577
|
+
return a;
|
|
578
|
+
}
|
|
579
|
+
var I = null;
|
|
580
|
+
function L() {
|
|
581
|
+
if (!I) throw Error("[Nix] No hay router activo. Llama a createRouter() antes.");
|
|
582
|
+
return I;
|
|
583
|
+
}
|
|
584
|
+
function R(e) {
|
|
585
|
+
let t = {};
|
|
586
|
+
return new URLSearchParams(e).forEach((e, n) => {
|
|
587
|
+
t[n] = e;
|
|
588
|
+
}), t;
|
|
589
|
+
}
|
|
590
|
+
function z(e) {
|
|
591
|
+
let t = new URLSearchParams();
|
|
592
|
+
for (let [n, r] of Object.entries(e)) r != null && r !== !1 && t.set(n, String(r));
|
|
593
|
+
let n = t.toString();
|
|
594
|
+
return n ? "?" + n : "";
|
|
595
|
+
}
|
|
596
|
+
function B(e) {
|
|
597
|
+
return e === "*" ? [{ kind: "wildcard" }] : e.split("/").filter(Boolean).map((e) => e === "*" ? { kind: "wildcard" } : e.startsWith(":") ? {
|
|
598
|
+
kind: "param",
|
|
599
|
+
name: e.slice(1)
|
|
600
|
+
} : {
|
|
601
|
+
kind: "literal",
|
|
602
|
+
value: e
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
function V(e, t) {
|
|
606
|
+
return t === "*" ? e === "" ? "*" : e + "/*" : (e + (t.startsWith("/") ? t : "/" + t)).replace(/\/+/g, "/") || "/";
|
|
607
|
+
}
|
|
608
|
+
function H(e, t = "", n = []) {
|
|
609
|
+
let r = [];
|
|
610
|
+
for (let i of e) {
|
|
611
|
+
let e = V(t, i.path), a = [...n, i.component], o = B(e);
|
|
612
|
+
r.push({
|
|
613
|
+
fullPath: e,
|
|
614
|
+
segments: o,
|
|
615
|
+
chain: a
|
|
616
|
+
}), i.children?.length && r.push(...H(i.children, e, a));
|
|
617
|
+
}
|
|
618
|
+
return r;
|
|
619
|
+
}
|
|
620
|
+
function U(e, t) {
|
|
621
|
+
let n = e.split("/").filter(Boolean), r = t.segments;
|
|
622
|
+
if (r.length === 1 && r[0].kind === "wildcard") return {};
|
|
623
|
+
let i = r.length > 0 && r[r.length - 1].kind === "wildcard", a = i ? r.slice(0, -1) : r;
|
|
624
|
+
if (i) {
|
|
625
|
+
if (n.length < a.length) return null;
|
|
626
|
+
} else if (n.length !== a.length) return null;
|
|
627
|
+
let o = {};
|
|
628
|
+
for (let e = 0; e < a.length; e++) {
|
|
629
|
+
let t = a[e];
|
|
630
|
+
if (t.kind === "literal") {
|
|
631
|
+
if (n[e] !== t.value) return null;
|
|
632
|
+
} else t.kind === "param" && (o[t.name] = decodeURIComponent(n[e] ?? ""));
|
|
633
|
+
}
|
|
634
|
+
return o;
|
|
635
|
+
}
|
|
636
|
+
function W(e) {
|
|
637
|
+
return e.segments.reduce((e, t) => t.kind === "literal" ? e + 2 : t.kind === "param" ? e + 1 : e, 0);
|
|
638
|
+
}
|
|
639
|
+
function G(e, t) {
|
|
640
|
+
let n, r = {}, i = -1;
|
|
641
|
+
for (let a of t) {
|
|
642
|
+
let t = U(e, a);
|
|
643
|
+
if (t === null) continue;
|
|
644
|
+
let o = W(a);
|
|
645
|
+
o > i && (n = a, r = t, i = o);
|
|
646
|
+
}
|
|
647
|
+
return n ? {
|
|
648
|
+
route: n,
|
|
649
|
+
params: r
|
|
650
|
+
} : void 0;
|
|
651
|
+
}
|
|
652
|
+
function K(e) {
|
|
653
|
+
function t() {
|
|
654
|
+
return window.location.pathname || "/";
|
|
655
|
+
}
|
|
656
|
+
let n = t(), r = H(e), i = G(n, r), a = s(n), o = s(i?.params ?? {}), c = s(R(window.location.search));
|
|
657
|
+
window.addEventListener("popstate", () => {
|
|
658
|
+
let e = t();
|
|
659
|
+
o.value = G(e, r)?.params ?? {}, c.value = R(window.location.search), a.value = e;
|
|
660
|
+
});
|
|
661
|
+
function l(e, t) {
|
|
662
|
+
let n = e.indexOf("?"), i = n === -1 ? e : e.slice(0, n), s = n === -1 ? {} : R(e.slice(n)), l = t ? {
|
|
663
|
+
...s,
|
|
664
|
+
...t
|
|
665
|
+
} : s, u = {};
|
|
666
|
+
for (let [e, t] of Object.entries(l)) t != null && t !== !1 && (u[e] = String(t));
|
|
667
|
+
o.value = G(i, r)?.params ?? {}, c.value = u, a.value = i;
|
|
668
|
+
let d = i + z(u);
|
|
669
|
+
history.pushState(null, "", d);
|
|
670
|
+
}
|
|
671
|
+
let u = {
|
|
672
|
+
current: a,
|
|
673
|
+
params: o,
|
|
674
|
+
query: c,
|
|
675
|
+
navigate: l,
|
|
676
|
+
routes: e,
|
|
677
|
+
_flat: r
|
|
678
|
+
};
|
|
679
|
+
return I = u, u;
|
|
680
|
+
}
|
|
681
|
+
function q() {
|
|
682
|
+
return L();
|
|
683
|
+
}
|
|
684
|
+
var J = class extends m {
|
|
685
|
+
_depth;
|
|
686
|
+
constructor(e = 0) {
|
|
687
|
+
super(), this._depth = e;
|
|
688
|
+
}
|
|
689
|
+
render() {
|
|
690
|
+
let e = this._depth;
|
|
691
|
+
return N`<div class="router-view">${() => {
|
|
692
|
+
let t = L(), n = G(t.current.value, t._flat);
|
|
693
|
+
return n ? e >= n.route.chain.length ? N`<span></span>` : n.route.chain[e]() : N`<div style="color:#f87171;padding:16px 0">
|
|
694
|
+
404 — Ruta no encontrada: <strong>${t.current.value}</strong>
|
|
695
|
+
</div>`;
|
|
696
|
+
}}</div>`;
|
|
697
|
+
}
|
|
698
|
+
}, Y = class extends m {
|
|
699
|
+
_to;
|
|
700
|
+
_label;
|
|
701
|
+
constructor(e, t) {
|
|
702
|
+
super(), this._to = e, this._label = t;
|
|
703
|
+
}
|
|
704
|
+
render() {
|
|
705
|
+
let e = this._to;
|
|
706
|
+
return N`<a
|
|
707
|
+
href=${e}
|
|
708
|
+
style=${() => L().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"}
|
|
709
|
+
@click=${(t) => {
|
|
710
|
+
t.preventDefault(), L().navigate(e);
|
|
711
|
+
}}
|
|
712
|
+
>${this._label}</a>`;
|
|
713
|
+
}
|
|
714
|
+
};
|
|
715
|
+
function X(e, t, n = {}) {
|
|
716
|
+
let { fallback: r, errorFallback: i, resetOnRefresh: a = !1 } = n, o = r ?? N`
|
|
717
|
+
<span style="color:#52525b;font-size:13px;display:inline-flex;align-items:center;gap:6px">
|
|
718
|
+
<span class="nix-spinner" style="
|
|
719
|
+
display:inline-block;width:14px;height:14px;border-radius:50%;
|
|
720
|
+
border:2px solid #38bdf840;border-top-color:#38bdf8;
|
|
721
|
+
animation:nix-spin .7s linear infinite
|
|
722
|
+
"></span>
|
|
723
|
+
Cargando…
|
|
724
|
+
</span>
|
|
725
|
+
<style>@keyframes nix-spin{to{transform:rotate(360deg)}}</style>
|
|
726
|
+
`, c = i ?? ((e) => N`
|
|
727
|
+
<span style="color:#f87171;font-size:13px">
|
|
728
|
+
⚠ ${e instanceof Error ? e.message : String(e)}
|
|
729
|
+
</span>
|
|
730
|
+
`);
|
|
731
|
+
class l extends m {
|
|
732
|
+
_state = s({ status: "pending" });
|
|
733
|
+
onMount() {
|
|
734
|
+
this._run();
|
|
735
|
+
}
|
|
736
|
+
_run() {
|
|
737
|
+
(a || this._state.value.status === "pending") && (this._state.value = { status: "pending" }), e().then((e) => {
|
|
738
|
+
this._state.value = {
|
|
739
|
+
status: "resolved",
|
|
740
|
+
data: e
|
|
741
|
+
};
|
|
742
|
+
}, (e) => {
|
|
743
|
+
this._state.value = {
|
|
744
|
+
status: "error",
|
|
745
|
+
error: e
|
|
746
|
+
};
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
render() {
|
|
750
|
+
return N`<div class="nix-suspense" style="display:contents">${() => {
|
|
751
|
+
let e = this._state.value;
|
|
752
|
+
return e.status === "pending" ? o : e.status === "error" ? c(e.error) : t(e.data);
|
|
753
|
+
}}</div>`;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
return new l();
|
|
757
|
+
}
|
|
758
|
+
function Z(e, t) {
|
|
759
|
+
let n = null;
|
|
760
|
+
return () => n ? new n() : X(async () => (n = (await e()).default, n), (e) => new e(), { fallback: t });
|
|
761
|
+
}
|
|
762
|
+
export { Y as Link, m as NixComponent, J as RouterView, o as Signal, u as batch, l as computed, g as createInjectionKey, K as createRouter, F as createStore, c as effect, N as html, C as inject, Z as lazy, P as mount, p as nextTick, S as provide, w as ref, T as repeat, s as signal, X as suspend, d as untrack, q as useRouter, f as watch };
|
|
763
|
+
|
|
764
|
+
//# sourceMappingURL=nix-js.js.map
|