@elurjs/core 3.5.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/LICENSE +21 -0
- package/README.md +157 -0
- package/dist/lib/async.cjs +16 -0
- package/dist/lib/async.js +123 -0
- package/dist/lib/component.cjs +2 -0
- package/dist/lib/component.js +66 -0
- package/dist/lib/context.cjs +2 -0
- package/dist/lib/context.js +52 -0
- package/dist/lib/devtools.cjs +59 -0
- package/dist/lib/devtools.js +419 -0
- package/dist/lib/elur/async.cjs +16 -0
- package/dist/lib/elur/async.cjs.map +1 -0
- package/dist/lib/elur/async.d.cts +32 -0
- package/dist/lib/elur/async.d.ts +32 -0
- package/dist/lib/elur/async.js +123 -0
- package/dist/lib/elur/async.js.map +1 -0
- package/dist/lib/elur/component.cjs +2 -0
- package/dist/lib/elur/component.cjs.map +1 -0
- package/dist/lib/elur/component.d.cts +17 -0
- package/dist/lib/elur/component.d.ts +17 -0
- package/dist/lib/elur/component.js +66 -0
- package/dist/lib/elur/component.js.map +1 -0
- package/dist/lib/elur/context.cjs +2 -0
- package/dist/lib/elur/context.cjs.map +1 -0
- package/dist/lib/elur/context.d.cts +29 -0
- package/dist/lib/elur/context.d.ts +29 -0
- package/dist/lib/elur/context.js +52 -0
- package/dist/lib/elur/context.js.map +1 -0
- package/dist/lib/elur/devtools.cjs +59 -0
- package/dist/lib/elur/devtools.cjs.map +1 -0
- package/dist/lib/elur/devtools.d.cts +24 -0
- package/dist/lib/elur/devtools.d.ts +24 -0
- package/dist/lib/elur/devtools.js +419 -0
- package/dist/lib/elur/devtools.js.map +1 -0
- package/dist/lib/elur/form.cjs +2 -0
- package/dist/lib/elur/form.cjs.map +1 -0
- package/dist/lib/elur/form.d.cts +283 -0
- package/dist/lib/elur/form.d.ts +283 -0
- package/dist/lib/elur/form.js +315 -0
- package/dist/lib/elur/form.js.map +1 -0
- package/dist/lib/elur/hydrate/index.cjs +2 -0
- package/dist/lib/elur/hydrate/index.cjs.map +1 -0
- package/dist/lib/elur/hydrate/index.d.cts +13 -0
- package/dist/lib/elur/hydrate/index.d.ts +13 -0
- package/dist/lib/elur/hydrate/index.js +410 -0
- package/dist/lib/elur/hydrate/index.js.map +1 -0
- package/dist/lib/elur/index.d.cts +19 -0
- package/dist/lib/elur/index.d.ts +19 -0
- package/dist/lib/elur/lifecycle.cjs +2 -0
- package/dist/lib/elur/lifecycle.cjs.map +1 -0
- package/dist/lib/elur/lifecycle.d.cts +45 -0
- package/dist/lib/elur/lifecycle.d.ts +45 -0
- package/dist/lib/elur/lifecycle.js +39 -0
- package/dist/lib/elur/lifecycle.js.map +1 -0
- package/dist/lib/elur/plugins.cjs +2 -0
- package/dist/lib/elur/plugins.cjs.map +1 -0
- package/dist/lib/elur/plugins.d.cts +48 -0
- package/dist/lib/elur/plugins.d.ts +48 -0
- package/dist/lib/elur/plugins.js +59 -0
- package/dist/lib/elur/plugins.js.map +1 -0
- package/dist/lib/elur/reactivity.cjs +2 -0
- package/dist/lib/elur/reactivity.cjs.map +1 -0
- package/dist/lib/elur/reactivity.d.cts +60 -0
- package/dist/lib/elur/reactivity.d.ts +60 -0
- package/dist/lib/elur/reactivity.js +188 -0
- package/dist/lib/elur/reactivity.js.map +1 -0
- package/dist/lib/elur/router.cjs +12 -0
- package/dist/lib/elur/router.cjs.map +1 -0
- package/dist/lib/elur/router.d.cts +137 -0
- package/dist/lib/elur/router.d.ts +137 -0
- package/dist/lib/elur/router.js +513 -0
- package/dist/lib/elur/router.js.map +1 -0
- package/dist/lib/elur/server/index.cjs +2 -0
- package/dist/lib/elur/server/index.cjs.map +1 -0
- package/dist/lib/elur/server/index.d.cts +44 -0
- package/dist/lib/elur/server/index.d.ts +44 -0
- package/dist/lib/elur/server/index.js +307 -0
- package/dist/lib/elur/server/index.js.map +1 -0
- package/dist/lib/elur/store.cjs +2 -0
- package/dist/lib/elur/store.cjs.map +1 -0
- package/dist/lib/elur/store.d.cts +137 -0
- package/dist/lib/elur/store.d.ts +137 -0
- package/dist/lib/elur/store.js +143 -0
- package/dist/lib/elur/store.js.map +1 -0
- package/dist/lib/elur/template/bindings.cjs +2 -0
- package/dist/lib/elur/template/bindings.cjs.map +1 -0
- package/dist/lib/elur/template/bindings.d.cts +40 -0
- package/dist/lib/elur/template/bindings.d.ts +40 -0
- package/dist/lib/elur/template/bindings.js +214 -0
- package/dist/lib/elur/template/bindings.js.map +1 -0
- package/dist/lib/elur/template/dom-write.cjs +2 -0
- package/dist/lib/elur/template/dom-write.cjs.map +1 -0
- package/dist/lib/elur/template/dom-write.d.cts +5 -0
- package/dist/lib/elur/template/dom-write.d.ts +5 -0
- package/dist/lib/elur/template/dom-write.js +16 -0
- package/dist/lib/elur/template/dom-write.js.map +1 -0
- package/dist/lib/elur/template/error-boundary.cjs +2 -0
- package/dist/lib/elur/template/error-boundary.cjs.map +1 -0
- package/dist/lib/elur/template/error-boundary.d.cts +7 -0
- package/dist/lib/elur/template/error-boundary.d.ts +7 -0
- package/dist/lib/elur/template/error-boundary.js +90 -0
- package/dist/lib/elur/template/error-boundary.js.map +1 -0
- package/dist/lib/elur/template/html.cjs +2 -0
- package/dist/lib/elur/template/html.cjs.map +1 -0
- package/dist/lib/elur/template/html.d.cts +8 -0
- package/dist/lib/elur/template/html.d.ts +8 -0
- package/dist/lib/elur/template/html.js +104 -0
- package/dist/lib/elur/template/html.js.map +1 -0
- package/dist/lib/elur/template/index.cjs +1 -0
- package/dist/lib/elur/template/index.d.cts +15 -0
- package/dist/lib/elur/template/index.d.ts +15 -0
- package/dist/lib/elur/template/index.js +13 -0
- package/dist/lib/elur/template/keyed-diff.cjs +2 -0
- package/dist/lib/elur/template/keyed-diff.cjs.map +1 -0
- package/dist/lib/elur/template/keyed-diff.d.cts +32 -0
- package/dist/lib/elur/template/keyed-diff.d.ts +32 -0
- package/dist/lib/elur/template/keyed-diff.js +100 -0
- package/dist/lib/elur/template/keyed-diff.js.map +1 -0
- package/dist/lib/elur/template/keyed.cjs +2 -0
- package/dist/lib/elur/template/keyed.cjs.map +1 -0
- package/dist/lib/elur/template/keyed.d.cts +27 -0
- package/dist/lib/elur/template/keyed.d.ts +27 -0
- package/dist/lib/elur/template/keyed.js +52 -0
- package/dist/lib/elur/template/keyed.js.map +1 -0
- package/dist/lib/elur/template/mount-helpers.cjs +2 -0
- package/dist/lib/elur/template/mount-helpers.cjs.map +1 -0
- package/dist/lib/elur/template/mount-helpers.d.cts +29 -0
- package/dist/lib/elur/template/mount-helpers.d.ts +29 -0
- package/dist/lib/elur/template/mount-helpers.js +132 -0
- package/dist/lib/elur/template/mount-helpers.js.map +1 -0
- package/dist/lib/elur/template/node-binding.cjs +2 -0
- package/dist/lib/elur/template/node-binding.cjs.map +1 -0
- package/dist/lib/elur/template/node-binding.d.cts +6 -0
- package/dist/lib/elur/template/node-binding.d.ts +6 -0
- package/dist/lib/elur/template/node-binding.js +95 -0
- package/dist/lib/elur/template/node-binding.js.map +1 -0
- package/dist/lib/elur/template/portal.cjs +2 -0
- package/dist/lib/elur/template/portal.cjs.map +1 -0
- package/dist/lib/elur/template/portal.d.cts +19 -0
- package/dist/lib/elur/template/portal.d.ts +19 -0
- package/dist/lib/elur/template/portal.js +49 -0
- package/dist/lib/elur/template/portal.js.map +1 -0
- package/dist/lib/elur/template/raw.cjs +2 -0
- package/dist/lib/elur/template/raw.cjs.map +1 -0
- package/dist/lib/elur/template/raw.d.cts +9 -0
- package/dist/lib/elur/template/raw.d.ts +9 -0
- package/dist/lib/elur/template/raw.js +29 -0
- package/dist/lib/elur/template/raw.js.map +1 -0
- package/dist/lib/elur/template/sanitize.cjs +2 -0
- package/dist/lib/elur/template/sanitize.cjs.map +1 -0
- package/dist/lib/elur/template/sanitize.d.cts +16 -0
- package/dist/lib/elur/template/sanitize.d.ts +16 -0
- package/dist/lib/elur/template/sanitize.js +29 -0
- package/dist/lib/elur/template/sanitize.js.map +1 -0
- package/dist/lib/elur/template/transitions.cjs +2 -0
- package/dist/lib/elur/template/transitions.cjs.map +1 -0
- package/dist/lib/elur/template/transitions.d.cts +43 -0
- package/dist/lib/elur/template/transitions.d.ts +43 -0
- package/dist/lib/elur/template/transitions.js +96 -0
- package/dist/lib/elur/template/transitions.js.map +1 -0
- package/dist/lib/elur/template/types.cjs +2 -0
- package/dist/lib/elur/template/types.cjs.map +1 -0
- package/dist/lib/elur/template/types.d.cts +114 -0
- package/dist/lib/elur/template/types.d.ts +114 -0
- package/dist/lib/elur/template/types.js +23 -0
- package/dist/lib/elur/template/types.js.map +1 -0
- package/dist/lib/elur.cjs +1 -0
- package/dist/lib/elur.js +18 -0
- package/dist/lib/form.cjs +2 -0
- package/dist/lib/form.js +315 -0
- package/dist/lib/hydrate.cjs +2 -0
- package/dist/lib/hydrate.js +410 -0
- package/dist/lib/index.cjs +1 -0
- package/dist/lib/index.d.cts +2 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +18 -0
- package/dist/lib/lifecycle.cjs +2 -0
- package/dist/lib/lifecycle.js +39 -0
- package/dist/lib/plugins.cjs +2 -0
- package/dist/lib/plugins.js +59 -0
- package/dist/lib/router.cjs +12 -0
- package/dist/lib/router.js +513 -0
- package/dist/lib/server.cjs +2 -0
- package/dist/lib/server.js +307 -0
- package/dist/lib/signals.cjs +2 -0
- package/dist/lib/signals.js +188 -0
- package/dist/lib/store.cjs +2 -0
- package/dist/lib/store.js +143 -0
- package/dist/lib/template.cjs +1 -0
- package/dist/lib/template.js +13 -0
- package/package.json +216 -0
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { signal as e } from "./signals.js";
|
|
2
|
+
import { ElurComponent as t } from "./lifecycle.js";
|
|
3
|
+
import { createInjectionKey as n, inject as r } from "./context.js";
|
|
4
|
+
import { html as i } from "./elur/template/html.js";
|
|
5
|
+
//#region src/elur/router.ts
|
|
6
|
+
var a = n("elur:router"), o = null, s = null, c = [], l = "__elur_scroll", u = "__elur_pos";
|
|
7
|
+
function d() {
|
|
8
|
+
if (!o) throw Error("[elur] No active router. Call createRouter() first, or instantiate an outlet that auto-bootstraps one (e.g. IonRouterOutlet).");
|
|
9
|
+
return o;
|
|
10
|
+
}
|
|
11
|
+
function f() {
|
|
12
|
+
return o !== null;
|
|
13
|
+
}
|
|
14
|
+
function p() {
|
|
15
|
+
return {
|
|
16
|
+
left: window.scrollX ?? window.pageXOffset ?? 0,
|
|
17
|
+
top: window.scrollY ?? window.pageYOffset ?? 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function ee(e) {
|
|
21
|
+
if (!e || typeof e != "object") return null;
|
|
22
|
+
let t = e[l];
|
|
23
|
+
if (!t || typeof t != "object") return null;
|
|
24
|
+
let n = t.left, r = t.top;
|
|
25
|
+
return typeof n != "number" || typeof r != "number" ? null : {
|
|
26
|
+
left: n,
|
|
27
|
+
top: r
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function m(e) {
|
|
31
|
+
if (!e || typeof e != "object") return null;
|
|
32
|
+
let t = e[u];
|
|
33
|
+
return typeof t == "number" ? t : null;
|
|
34
|
+
}
|
|
35
|
+
function h(e, t, n) {
|
|
36
|
+
let r = e && typeof e == "object" ? { ...e } : {};
|
|
37
|
+
return r[l] = {
|
|
38
|
+
left: t.left,
|
|
39
|
+
top: t.top
|
|
40
|
+
}, r[u] = n, r;
|
|
41
|
+
}
|
|
42
|
+
function g(e) {
|
|
43
|
+
let t = {};
|
|
44
|
+
return new URLSearchParams(e).forEach((e, n) => {
|
|
45
|
+
t[n] = e;
|
|
46
|
+
}), t;
|
|
47
|
+
}
|
|
48
|
+
function _(e) {
|
|
49
|
+
let t = new URLSearchParams();
|
|
50
|
+
for (let [n, r] of Object.entries(e)) r != null && r !== !1 && t.set(n, String(r));
|
|
51
|
+
let n = t.toString();
|
|
52
|
+
return n ? "?" + n : "";
|
|
53
|
+
}
|
|
54
|
+
function v(e) {
|
|
55
|
+
return e === "*" ? [{ kind: "wildcard" }] : e.split("/").filter(Boolean).map((e) => e === "*" ? { kind: "wildcard" } : e.startsWith(":") ? {
|
|
56
|
+
kind: "param",
|
|
57
|
+
name: e.slice(1)
|
|
58
|
+
} : {
|
|
59
|
+
kind: "literal",
|
|
60
|
+
value: e
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
function y(e, t) {
|
|
64
|
+
return t === "*" ? e === "" ? "*" : e + "/*" : (e + (t.startsWith("/") ? t : "/" + t)).replace(/\/+/g, "/") || "/";
|
|
65
|
+
}
|
|
66
|
+
function b(e, t = "", n = []) {
|
|
67
|
+
let r = [];
|
|
68
|
+
for (let i of e) {
|
|
69
|
+
let e = y(t, i.path), a = [...n, i.component], o = v(e);
|
|
70
|
+
r.push({
|
|
71
|
+
fullPath: e,
|
|
72
|
+
segments: o,
|
|
73
|
+
chain: a,
|
|
74
|
+
name: i.name,
|
|
75
|
+
meta: i.meta,
|
|
76
|
+
beforeEnter: i.beforeEnter,
|
|
77
|
+
record: i
|
|
78
|
+
}), i.children?.length && r.push(...b(i.children, e, a));
|
|
79
|
+
}
|
|
80
|
+
return r;
|
|
81
|
+
}
|
|
82
|
+
function x(e, t) {
|
|
83
|
+
let n = e.split("/").filter(Boolean), r = t.segments;
|
|
84
|
+
if (r.length === 1 && r[0].kind === "wildcard") return {};
|
|
85
|
+
let i = r.length > 0 && r[r.length - 1].kind === "wildcard", a = i ? r.slice(0, -1) : r;
|
|
86
|
+
if (i) {
|
|
87
|
+
if (n.length < a.length) return null;
|
|
88
|
+
} else if (n.length !== a.length) return null;
|
|
89
|
+
let o = {};
|
|
90
|
+
for (let e = 0; e < a.length; e++) {
|
|
91
|
+
let t = a[e];
|
|
92
|
+
if (t.kind === "literal") {
|
|
93
|
+
if (n[e] !== t.value) return null;
|
|
94
|
+
} else if (t.kind === "param") try {
|
|
95
|
+
o[t.name] = decodeURIComponent(n[e] ?? "");
|
|
96
|
+
} catch {
|
|
97
|
+
o[t.name] = n[e] ?? "";
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return o;
|
|
101
|
+
}
|
|
102
|
+
function S(e) {
|
|
103
|
+
return e.segments.reduce((e, t) => t.kind === "literal" ? e + 2 : t.kind === "param" ? e + 1 : e, 0);
|
|
104
|
+
}
|
|
105
|
+
function C(e, t) {
|
|
106
|
+
let n, r = {}, i = -1;
|
|
107
|
+
for (let a of t) {
|
|
108
|
+
let t = x(e, a);
|
|
109
|
+
if (t === null) continue;
|
|
110
|
+
let o = S(a);
|
|
111
|
+
o > i && (n = a, r = t, i = o);
|
|
112
|
+
}
|
|
113
|
+
return n ? {
|
|
114
|
+
route: n,
|
|
115
|
+
params: r
|
|
116
|
+
} : void 0;
|
|
117
|
+
}
|
|
118
|
+
function w(e) {
|
|
119
|
+
let t = e.trim();
|
|
120
|
+
return !t || t === "/" ? "" : (t.startsWith("/") || (t = "/" + t), t.endsWith("/") && (t = t.slice(0, -1)), t);
|
|
121
|
+
}
|
|
122
|
+
function T() {
|
|
123
|
+
if (typeof document > "u") return "";
|
|
124
|
+
let e = document.querySelector("base");
|
|
125
|
+
if (!e) return "";
|
|
126
|
+
let t = e.getAttribute("href") || "";
|
|
127
|
+
try {
|
|
128
|
+
return w(new URL(t, window.location.origin).pathname);
|
|
129
|
+
} catch {
|
|
130
|
+
return w(t);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function te(e) {
|
|
134
|
+
return e === !1 ? { allow: !1 } : e === !0 || e == null ? { allow: !0 } : typeof e == "string" ? {
|
|
135
|
+
allow: !1,
|
|
136
|
+
redirect: e
|
|
137
|
+
} : typeof e == "object" && "redirect" in e && typeof e.redirect == "string" ? {
|
|
138
|
+
allow: !1,
|
|
139
|
+
redirect: e.redirect
|
|
140
|
+
} : { allow: !0 };
|
|
141
|
+
}
|
|
142
|
+
function E(t, n) {
|
|
143
|
+
let r = n?.base == null ? T() : w(n.base), i = n?.mode ?? "history", a = i === "hash", c = n?.scrollBehavior, l = /* @__PURE__ */ new Map(), u = !1;
|
|
144
|
+
function d(e) {
|
|
145
|
+
return e ? e.startsWith("/") ? e : "/" + e : "/";
|
|
146
|
+
}
|
|
147
|
+
function f(e) {
|
|
148
|
+
let t = d(e || "/");
|
|
149
|
+
if (r && t.startsWith(r)) {
|
|
150
|
+
let e = t.slice(r.length);
|
|
151
|
+
return e === "" ? "/" : d(e);
|
|
152
|
+
}
|
|
153
|
+
return t;
|
|
154
|
+
}
|
|
155
|
+
function v(e) {
|
|
156
|
+
let t = d(e);
|
|
157
|
+
return r ? (r + t).replace(/\/+/g, "/") || "/" : t;
|
|
158
|
+
}
|
|
159
|
+
function y() {
|
|
160
|
+
let e = window.location.hash || "";
|
|
161
|
+
if (e.startsWith("#") && (e = e.slice(1)), !e) return {
|
|
162
|
+
pathname: "/",
|
|
163
|
+
search: ""
|
|
164
|
+
};
|
|
165
|
+
e.startsWith("/") || (e = "/" + e);
|
|
166
|
+
let t = e.indexOf("?"), n = t === -1 ? e : e.slice(0, t), r = t === -1 ? "" : e.slice(t);
|
|
167
|
+
return {
|
|
168
|
+
pathname: f(n),
|
|
169
|
+
search: r
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
function x() {
|
|
173
|
+
return a ? y() : {
|
|
174
|
+
pathname: f(window.location.pathname || "/"),
|
|
175
|
+
search: window.location.search || ""
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
function S(e, t) {
|
|
179
|
+
let n = v(e) + _(t);
|
|
180
|
+
return a ? "#" + n : n;
|
|
181
|
+
}
|
|
182
|
+
function E(e, t) {
|
|
183
|
+
return d(e) + _(t);
|
|
184
|
+
}
|
|
185
|
+
let D = x(), O = D.pathname, k = g(D.search), A = b(t), j = /* @__PURE__ */ new Map();
|
|
186
|
+
for (let e of A) e.name && (j.has(e.name) && console.warn(`[Elur Router] Duplicate route name: "${e.name}"`), j.set(e.name, e));
|
|
187
|
+
let M = C(O, A), N = e(O), P = e(M?.params ?? {}), F = e(k), I = m(history.state) ?? 0, L = e({
|
|
188
|
+
action: "initial",
|
|
189
|
+
direction: "none"
|
|
190
|
+
}), R = e(I > 0);
|
|
191
|
+
a ? l.set(E(O, k), p()) : history.replaceState(h(history.state, p(), I), "");
|
|
192
|
+
function z(e) {
|
|
193
|
+
window.scrollTo(e.left, e.top);
|
|
194
|
+
}
|
|
195
|
+
function B(e, t, n) {
|
|
196
|
+
if (c) {
|
|
197
|
+
let r = c(e, t, n);
|
|
198
|
+
if (!r) return;
|
|
199
|
+
z(r);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
z(n ?? {
|
|
203
|
+
left: 0,
|
|
204
|
+
top: 0
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
function ne(e, t) {
|
|
208
|
+
let n = p();
|
|
209
|
+
if (a) {
|
|
210
|
+
l.set(E(e, t), n);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
history.replaceState(h(history.state, n, I), "");
|
|
214
|
+
}
|
|
215
|
+
let V = [], H = [], U = 0;
|
|
216
|
+
function W(e, t, n, r, i) {
|
|
217
|
+
let a = [...V];
|
|
218
|
+
n && a.push(n);
|
|
219
|
+
let o = ++U;
|
|
220
|
+
if (a.length === 0) {
|
|
221
|
+
r();
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
let s = 0;
|
|
225
|
+
function c(n) {
|
|
226
|
+
if (o !== U) return;
|
|
227
|
+
let l = te(n);
|
|
228
|
+
if (!l.allow) {
|
|
229
|
+
if (l.redirect && l.redirect !== e) {
|
|
230
|
+
Z(l.redirect);
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (l.redirect === e) {
|
|
234
|
+
r();
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
i?.();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (s >= a.length) {
|
|
241
|
+
r();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
let u = a[s++](e, t);
|
|
245
|
+
if (u instanceof Promise) {
|
|
246
|
+
u.then(c);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
c(u);
|
|
250
|
+
}
|
|
251
|
+
c(void 0);
|
|
252
|
+
}
|
|
253
|
+
let G = !1;
|
|
254
|
+
function K(e, t) {
|
|
255
|
+
let n = e.indexOf("?"), r = d((n === -1 ? e : e.slice(0, n)) || "/"), i = n === -1 ? {} : g(e.slice(n)), a = t ? {
|
|
256
|
+
...i,
|
|
257
|
+
...t
|
|
258
|
+
} : i, o = {};
|
|
259
|
+
for (let [e, t] of Object.entries(a)) t != null && t !== !1 && (o[e] = String(t));
|
|
260
|
+
return {
|
|
261
|
+
pathname: r,
|
|
262
|
+
stringQuery: o
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function re(e) {
|
|
266
|
+
let t = j.get(e.name);
|
|
267
|
+
if (!t) throw Error(`[Elur Router] No route with name "${e.name}"`);
|
|
268
|
+
return "/" + t.segments.map((t) => {
|
|
269
|
+
if (t.kind === "literal") return t.value;
|
|
270
|
+
if (t.kind === "wildcard") return "";
|
|
271
|
+
let n = e.params?.[t.name];
|
|
272
|
+
if (n == null) throw Error(`[Elur Router] Missing param "${t.name}" for route "${e.name}"`);
|
|
273
|
+
return encodeURIComponent(String(n));
|
|
274
|
+
}).filter(Boolean).join("/");
|
|
275
|
+
}
|
|
276
|
+
function q(e, t) {
|
|
277
|
+
return typeof e == "string" ? K(e, t?.query) : K(re(e), {
|
|
278
|
+
...e.query ?? {},
|
|
279
|
+
...t?.query ?? {}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
s &&= (s(), null);
|
|
283
|
+
let J = (e, t, n, r, i) => {
|
|
284
|
+
let a = N.value, o = { ...F.value }, s = C(e, A), c = "none";
|
|
285
|
+
r != null && (r < I ? c = "back" : r > I && (c = "forward")), W(e, a, s?.route.beforeEnter, () => {
|
|
286
|
+
r != null && (I = r);
|
|
287
|
+
let i = X;
|
|
288
|
+
X = void 0, L.value = {
|
|
289
|
+
action: "pop",
|
|
290
|
+
direction: c,
|
|
291
|
+
animation: i
|
|
292
|
+
}, P.value = s?.params ?? {}, F.value = t, N.value = e, R.value = I > 0, B(e, a, n);
|
|
293
|
+
for (let t of H) try {
|
|
294
|
+
t(e, a);
|
|
295
|
+
} catch {}
|
|
296
|
+
}, () => i(a, o));
|
|
297
|
+
};
|
|
298
|
+
if (a) {
|
|
299
|
+
let e = () => {
|
|
300
|
+
if (u) {
|
|
301
|
+
u = !1;
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
let e = x(), t = g(e.search), n = l.get(E(e.pathname, t)) ?? null;
|
|
305
|
+
J(e.pathname, t, n, null, (e, t) => {
|
|
306
|
+
u = !0, window.location.hash = S(e, t).slice(1), queueMicrotask(() => {
|
|
307
|
+
u = !1;
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
window.addEventListener("hashchange", e), s = () => window.removeEventListener("hashchange", e);
|
|
312
|
+
} else {
|
|
313
|
+
let e = (e) => {
|
|
314
|
+
let t = x(), n = g(t.search), r = ee(e.state ?? history.state), i = m(e.state ?? history.state);
|
|
315
|
+
J(t.pathname, n, r, i, (e, t) => {
|
|
316
|
+
history.pushState(h({}, p(), I), "", S(e, t));
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
window.addEventListener("popstate", e), s = () => window.removeEventListener("popstate", e);
|
|
320
|
+
}
|
|
321
|
+
function Y(e, t, n, r, i, o, s) {
|
|
322
|
+
s || (ne(n, r), I += 1), L.value = o, P.value = i?.params ?? {}, F.value = t, N.value = e, R.value = I > 0;
|
|
323
|
+
let c = S(e, t);
|
|
324
|
+
if (a) l.set(E(e, t), {
|
|
325
|
+
left: 0,
|
|
326
|
+
top: 0
|
|
327
|
+
}), s ? history.replaceState(history.state, "", c) : (u = !0, window.location.hash = c.slice(1), queueMicrotask(() => {
|
|
328
|
+
u = !1;
|
|
329
|
+
}));
|
|
330
|
+
else {
|
|
331
|
+
let e = h({}, {
|
|
332
|
+
left: 0,
|
|
333
|
+
top: 0
|
|
334
|
+
}, I);
|
|
335
|
+
s ? history.replaceState(e, "", c) : history.pushState(e, "", c);
|
|
336
|
+
}
|
|
337
|
+
B(e, n, null);
|
|
338
|
+
for (let t of H) try {
|
|
339
|
+
t(e, n);
|
|
340
|
+
} catch {}
|
|
341
|
+
}
|
|
342
|
+
let X;
|
|
343
|
+
function Z(e, t) {
|
|
344
|
+
G = !0;
|
|
345
|
+
let { pathname: n, stringQuery: r } = q(e, t), i = N.value, a = { ...F.value }, o = C(n, A), s = {
|
|
346
|
+
action: "push",
|
|
347
|
+
direction: t?.direction ?? "forward",
|
|
348
|
+
animation: t?.animation
|
|
349
|
+
};
|
|
350
|
+
W(n, i, o?.route.beforeEnter, () => Y(n, r, i, a, o, s, !1));
|
|
351
|
+
}
|
|
352
|
+
function ie(e, t) {
|
|
353
|
+
G = !0;
|
|
354
|
+
let { pathname: n, stringQuery: r } = q(e, t), i = N.value, a = { ...F.value }, o = C(n, A), s = {
|
|
355
|
+
action: "replace",
|
|
356
|
+
direction: t?.direction ?? "root",
|
|
357
|
+
animation: t?.animation
|
|
358
|
+
};
|
|
359
|
+
W(n, i, o?.route.beforeEnter, () => Y(n, r, i, a, o, s, !0));
|
|
360
|
+
}
|
|
361
|
+
function ae(e) {
|
|
362
|
+
e !== void 0 && (X = e), history.back();
|
|
363
|
+
}
|
|
364
|
+
function oe(e) {
|
|
365
|
+
e !== void 0 && (X = e), history.forward();
|
|
366
|
+
}
|
|
367
|
+
function se(e) {
|
|
368
|
+
history.go(e);
|
|
369
|
+
}
|
|
370
|
+
function Q(e, t = !0) {
|
|
371
|
+
let n = N.value;
|
|
372
|
+
return t ? n === e : n === e || n.startsWith(e.endsWith("/") ? e : e + "/");
|
|
373
|
+
}
|
|
374
|
+
function ce(e) {
|
|
375
|
+
let t = C(e, A);
|
|
376
|
+
return t ? {
|
|
377
|
+
matched: !0,
|
|
378
|
+
params: t.params,
|
|
379
|
+
route: t.route.record
|
|
380
|
+
} : {
|
|
381
|
+
matched: !1,
|
|
382
|
+
params: {},
|
|
383
|
+
route: void 0
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function le(e) {
|
|
387
|
+
return V.push(e), () => {
|
|
388
|
+
let t = V.indexOf(e);
|
|
389
|
+
t !== -1 && V.splice(t, 1);
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function ue(e) {
|
|
393
|
+
return H.push(e), () => {
|
|
394
|
+
let t = H.indexOf(e);
|
|
395
|
+
t !== -1 && H.splice(t, 1);
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
let $ = {
|
|
399
|
+
current: N,
|
|
400
|
+
params: P,
|
|
401
|
+
query: F,
|
|
402
|
+
intent: L,
|
|
403
|
+
canGoBack: R,
|
|
404
|
+
base: r || "/",
|
|
405
|
+
navigate: Z,
|
|
406
|
+
replace: ie,
|
|
407
|
+
back: ae,
|
|
408
|
+
forward: oe,
|
|
409
|
+
go: se,
|
|
410
|
+
isActive: Q,
|
|
411
|
+
resolve: ce,
|
|
412
|
+
beforeEach: le,
|
|
413
|
+
afterEach: ue,
|
|
414
|
+
routes: t,
|
|
415
|
+
_flat: A,
|
|
416
|
+
_guards: V,
|
|
417
|
+
_base: r,
|
|
418
|
+
_mode: i
|
|
419
|
+
};
|
|
420
|
+
return o && console.warn("[elur] A router already exists. The previous router is being replaced. Only one router instance should be active at a time."), o = $, queueMicrotask(() => {
|
|
421
|
+
G || W(O, "", C(O, A)?.route.beforeEnter, () => {}, () => {
|
|
422
|
+
let e = S("/", {});
|
|
423
|
+
a ? (l.set(E("/", {}), {
|
|
424
|
+
left: 0,
|
|
425
|
+
top: 0
|
|
426
|
+
}), history.replaceState(history.state, "", e)) : history.replaceState(h({}, {
|
|
427
|
+
left: 0,
|
|
428
|
+
top: 0
|
|
429
|
+
}, I), "", e);
|
|
430
|
+
let t = C("/", A);
|
|
431
|
+
L.value = {
|
|
432
|
+
action: "replace",
|
|
433
|
+
direction: "root"
|
|
434
|
+
}, N.value = "/", P.value = t?.params ?? {}, F.value = {}, R.value = I > 0, B("/", O, null);
|
|
435
|
+
});
|
|
436
|
+
}), $;
|
|
437
|
+
}
|
|
438
|
+
function D() {
|
|
439
|
+
return r(a) || d();
|
|
440
|
+
}
|
|
441
|
+
function O() {
|
|
442
|
+
s &&= (s(), null), o = null, c.length = 0;
|
|
443
|
+
}
|
|
444
|
+
var k = class extends t {
|
|
445
|
+
_depth;
|
|
446
|
+
_router;
|
|
447
|
+
constructor(e = 0, t) {
|
|
448
|
+
super(), this._depth = e, this._router = t;
|
|
449
|
+
}
|
|
450
|
+
render() {
|
|
451
|
+
let e = this._depth, t = this._router;
|
|
452
|
+
return i`<div class="router-view">${() => {
|
|
453
|
+
let n = t ?? D(), r = C(n.current.value, n._flat);
|
|
454
|
+
if (!r) return i`
|
|
455
|
+
<div style="color:#f87171;padding:16px 0">
|
|
456
|
+
404 — Route not found: <strong>${n.current.value}</strong>
|
|
457
|
+
</div>
|
|
458
|
+
`;
|
|
459
|
+
if (e >= r.route.chain.length) return i`
|
|
460
|
+
<span></span>
|
|
461
|
+
`;
|
|
462
|
+
let a = r.route.chain[e];
|
|
463
|
+
return a ? a() : i`
|
|
464
|
+
<span></span>
|
|
465
|
+
`;
|
|
466
|
+
}}</div>`;
|
|
467
|
+
}
|
|
468
|
+
}, A = class extends t {
|
|
469
|
+
_to;
|
|
470
|
+
_label;
|
|
471
|
+
_router;
|
|
472
|
+
constructor(e, t, n) {
|
|
473
|
+
super(), this._to = e, this._label = t, this._router = n;
|
|
474
|
+
}
|
|
475
|
+
render() {
|
|
476
|
+
let e = this._to, t = this._label, n = this._router ?? D(), r = e.startsWith("/") ? e : "/" + e, a = (n._base ? n._base + r : r).replace(/\/+/g, "/");
|
|
477
|
+
return i`
|
|
478
|
+
<a href=${n._mode === "hash" ? "#" + a : a} style=${() => n.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"} @click=${(t) => {
|
|
479
|
+
t.preventDefault(), n.navigate(e);
|
|
480
|
+
}}>${t}</a>
|
|
481
|
+
`;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
function j(e) {
|
|
485
|
+
let t = c.indexOf(e);
|
|
486
|
+
t >= 0 && c.splice(t, 1), c.push(e);
|
|
487
|
+
}
|
|
488
|
+
function M(e) {
|
|
489
|
+
let t = c.indexOf(e);
|
|
490
|
+
t >= 0 && c.splice(t, 1);
|
|
491
|
+
}
|
|
492
|
+
function N() {
|
|
493
|
+
let e = c.length ? c[c.length - 1] : o;
|
|
494
|
+
if (!e) return null;
|
|
495
|
+
let t = e, n = t.current.value, r = C(n, t._flat), i = r?.route.beforeEnter, a = t._guards.map((e, t) => e.name || `beforeEach#${t + 1}`);
|
|
496
|
+
return i && a.push(i.name || "beforeEnter"), {
|
|
497
|
+
mode: t._mode,
|
|
498
|
+
base: t._base || "/",
|
|
499
|
+
currentPath: n,
|
|
500
|
+
params: { ...t.params.value },
|
|
501
|
+
query: { ...t.query.value },
|
|
502
|
+
matchedPath: r?.route.fullPath ?? null,
|
|
503
|
+
activeGuards: {
|
|
504
|
+
globalCount: t._guards.length,
|
|
505
|
+
hasRouteGuard: !!i,
|
|
506
|
+
names: a
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
//#endregion
|
|
511
|
+
export { A as Link, a as RouterKey, k as RouterView, N as _debugGetRouterInternal, j as _debugRegisterRouter, M as _debugUnregisterRouter, f as _hasActiveRouter, O as _resetRouter, E as createRouter, D as elurRouter };
|
|
512
|
+
|
|
513
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./elur/template/types.cjs`),t=require(`./lifecycle.cjs`),n=require(`./context.cjs`),r=require(`./elur/template/keyed.cjs`),i=require(`./elur/template/sanitize.cjs`);let a=require(`node:async_hooks`);var o=e.isElurTemplate,s=e.isKeyedList,c=new a.AsyncLocalStorage;n._setContextScopeResolver(()=>c.getStore());function l(e={}){let t=new AbortController,n={markers:e.markers===`hydration`,context:e.context,onError:e.onError},r=e=>Promise.resolve(c.run([],e));return{signal:t.signal,async render(e,i){let a={...n,markers:i?.markers??n.markers,signal:t.signal},o=``;return await r(()=>(async()=>{for await(let t of p(e,a))o+=t.value})()),o},renderToChunks(e,r){return u(e,{...n,markers:r?.markers??n.markers,signal:t.signal})},abort(e){t.abort(e)}}}function u(e,t){return{async*[Symbol.asyncIterator](){let n=[],r=[],i=!1,a,o=()=>{r.shift()?.()},s=c.run([],async()=>{try{for await(let r of p(e,t))n.push(r),o()}catch(e){a=e}finally{i=!0,o()}});for(;;){for(;n.length===0&&!i;)await new Promise(e=>r.push(e));if(n.length===0)break;let e=n.shift();e&&(yield e)}if(a)throw a;yield{type:`done`,value:``,index:-1},await s}}}async function d(e,t={}){let n={markers:t.markers===`hydration`,signal:t.signal,context:t.context,onError:t.onError},r=``;return await Promise.resolve(c.run([],async()=>{for await(let t of p(e,n))r+=t.value})),r}function f(e,t={}){return u(e,{markers:t.markers===`hydration`,signal:t.signal,context:t.context,onError:t.onError})}async function*p(n,i){if(_(i),n instanceof Promise){yield*p(await n,i);return}if(!(n==null||n===!1||n===!0)){if(typeof n==`string`||typeof n==`number`||typeof n==`bigint`){yield{type:`markup`,value:b(String(n)),index:-1};return}if(Array.isArray(n)){let e=await Promise.all(n.map(e=>v(e)));_(i);for(let t of e)i.markers&&(yield{type:`markup`,value:`<!--elur-ai-->`,index:-1}),yield*p(t,i),i.markers&&(yield{type:`markup`,value:`<!--elur-aiend-->`,index:-1});return}if((typeof n==`object`||typeof n==`function`)&&n!==null){let t=n[e.ELUR_RENDER_PROTOCOL];if(t?.renderServer){let e=await t.renderServer({markers:i.markers,signal:i.signal,context:i.context,render:(e,t)=>g(e,{...i,markers:t?.markers??i.markers})});_(i),yield{type:`markup`,value:e,index:-1};return}}if(t.isElurComponent(n)){yield*m(n,i);return}if(s(n)){if(!i.markers){yield{type:`markup`,value:(await Promise.all(n.items.map((e,t)=>g(n.renderFn(e,t),i)))).join(``),index:-1};return}let e=new Set;for(let t=0;t<n.items.length;t++){let a=n.items[t],o=r.normalizeRepeatKey(n.keyFn(a,t),t),s=r.serializeRepeatKey(o);e.has(s)&&console.warn(`[elur] repeat(): duplicate key "${o}" during server render. Keys must be unique; entries after the first will leak during hydration.`),e.add(s),yield{type:`markup`,value:`<!--elur-ki:${s}-->`,index:-1},yield*p(n.renderFn(a,t),i),yield{type:`markup`,value:`<!--elur-ke-->`,index:-1}}return}if(o(n)){let t=n[e.ELUR_TEMPLATE_DESCRIPTOR];if(!t)throw TypeError(`[elur] Template does not support server rendering`);yield*h(t,i);return}yield{type:`markup`,value:b(String(n)),index:-1}}}async function*m(e,t){n._pushComponentContext();let r={index:-1,context:`component`,cause:void 0,component:e._debugName};try{try{e.onInit?.(),e.onServerRender?.()}catch(t){if(e.onError)e.onError(t);else throw t}try{yield*p(e.render(),t)}catch(t){if(e.onError){e.onError(t);return}throw t}}catch(e){throw t.onError?.(e,{...r,cause:e}),e}finally{n._popComponentContext()}}async function*h(e,t){let n=new Uint8Array(e.strings.length);for(let r=0;r<e.strings.length;r++){if(t.signal?.aborted)throw t.signal.reason??new DOMException(`Render aborted`,`AbortError`);let a=e.strings[r];if(n[r]===1&&(a[0]===`"`||a[0]===`'`)&&(a=a.slice(1)),r>=e.contexts.length){yield{type:`markup`,value:a,index:r};continue}let o=e.contexts[r],s=e.values[r];if(o.type===`node`){yield{type:`markup`,value:a,index:r},t.markers&&(yield{type:`boundary-start`,value:`<!--elur-${r}-->`,index:r});try{let e=await v(s);_(t),yield*p(e,t)}catch(e){throw t.onError?.(e,{index:r,context:`node`,cause:e}),e}t.markers&&(yield{type:`boundary-end`,value:`<!--elur-end-${r}-->`,index:r});continue}let c=y(o),l=a.slice(0,-c);if(o.hadOpenQuote&&(n[r+1]=1),o.type===`event`){t.markers?yield{type:`markup`,value:`${l}${/\s$/.test(l)?``:` `}data-elur-e-${r}="${x(o.eventName)}"`,index:r}:yield{type:`markup`,value:l.replace(/\s+$/,``),index:r};continue}yield{type:`markup`,value:l,index:r};let u=await v(s);if(_(t),o.attrName!==`ref`&&u!=null&&u!==!1){let e=o.url?i.sanitizeUrl(String(u)):String(u);yield{type:`markup`,value:`${/\s$/.test(l)?``:` `}${o.attrName}="${x(e)}"`,index:r}}t.markers&&(yield{type:`markup`,value:` data-elur-a-${r}="${x(o.attrName)}"`,index:r})}}async function g(e,t){let n=``;for await(let r of p(e,t))n+=r.value;return n}function _(e){if(e.signal?.aborted)throw e.signal.reason??new DOMException(`Render aborted`,`AbortError`)}async function v(e){let t=typeof e==`function`?e():e;return t instanceof Promise?await t:t}function y(e){return e.type===`event`?`@${e.modifiers.length?`${e.eventName}.${e.modifiers.join(`.`)}`:e.eventName}=`.length+ +!!e.hadOpenQuote:`${e.attrName}=`.length+ +!!e.hadOpenQuote}function b(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`)}function x(e){return b(e).replace(/"/g,`"`)}exports.createServerRenderScope=l,exports.renderToChunks=f,exports.renderToString=d;
|
|
2
|
+
//# sourceMappingURL=server.cjs.map
|