@manyducks.co/dolla 2.0.0-alpha.35 → 2.0.0-alpha.36
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 +2 -13
- package/dist/core/_signals_new.d.ts +130 -0
- package/dist/core/context.d.ts +1 -52
- package/dist/core/dolla.d.ts +3 -3
- package/dist/core/nodes/dynamic.d.ts +5 -5
- package/dist/core/nodes/html.d.ts +11 -15
- package/dist/core/nodes/list.d.ts +9 -15
- package/dist/core/nodes/outlet.d.ts +6 -6
- package/dist/core/nodes/portal.d.ts +2 -2
- package/dist/core/nodes/view.d.ts +17 -34
- package/dist/core/ref.d.ts +0 -17
- package/dist/core/store.d.ts +10 -16
- package/dist/core/symbols.d.ts +0 -1
- package/dist/index.js +652 -693
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/{markup-BWJWLvDF.js → markup-ILMFXzoo.js} +433 -625
- package/dist/markup-ILMFXzoo.js.map +1 -0
- package/dist/typeChecking.d.ts +0 -96
- package/dist/utils.d.ts +4 -1
- package/docs/views.md +0 -86
- package/notes/context-routes.md +56 -0
- package/notes/elimination.md +33 -0
- package/package.json +2 -4
- package/dist/markup-BWJWLvDF.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,262 +1,261 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var zt = Object.defineProperty;
|
|
2
|
+
var $t = (i) => {
|
|
3
3
|
throw TypeError(i);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var a = (i,
|
|
8
|
-
var
|
|
9
|
-
set _(
|
|
10
|
-
d(i,
|
|
5
|
+
var Bt = (i, t, e) => t in i ? zt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
6
|
+
var w = (i, t, e) => Bt(i, typeof t != "symbol" ? t + "" : t, e), mt = (i, t, e) => t.has(i) || $t("Cannot " + e);
|
|
7
|
+
var a = (i, t, e) => (mt(i, t, "read from private field"), e ? e.call(i) : t.get(i)), u = (i, t, e) => t.has(i) ? $t("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, e), d = (i, t, e, s) => (mt(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e), f = (i, t, e) => (mt(i, t, "access private method"), e);
|
|
8
|
+
var Rt = (i, t, e, s) => ({
|
|
9
|
+
set _(r) {
|
|
10
|
+
d(i, t, r, e);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
|
-
return a(i,
|
|
13
|
+
return a(i, t, s);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
function
|
|
19
|
-
|
|
16
|
+
import { a as Ft, b as Kt, i as B, I as Ot, c as Ut, d as U, g as E, s as _t, e as Qt, f as M, h as V, P as jt, j as Jt, t as St, k as Mt, l as Xt, m as xt, S as Yt, n as Tt, o as Nt, p as Zt, V as te, q as ee, r as se, u as ne, v as re } from "./markup-ILMFXzoo.js";
|
|
17
|
+
import { w as Ue, B as je, y as Ce, A as De, x as Ie, z as Ve } from "./markup-ILMFXzoo.js";
|
|
18
|
+
function Ne(i) {
|
|
19
|
+
return () => {
|
|
20
20
|
if (arguments.length === 1)
|
|
21
21
|
i = arguments[0];
|
|
22
22
|
else if (arguments.length > 1)
|
|
23
23
|
throw new Error(`Too many arguments. Expected 0 or 1. Got: ${arguments.length}`);
|
|
24
24
|
return i;
|
|
25
|
-
}
|
|
26
|
-
return e[Je] = !0, e;
|
|
25
|
+
};
|
|
27
26
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
27
|
+
function Q(i) {
|
|
28
|
+
return Ft(i, "Expected `path` to be a string. Got type: %t, value: %v"), i.split("/").map((t) => t.trim()).filter((t) => t !== "");
|
|
30
29
|
}
|
|
31
|
-
function
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
(
|
|
30
|
+
function G(i) {
|
|
31
|
+
var e;
|
|
32
|
+
Kt(
|
|
33
|
+
(s) => B(s == null ? void 0 : s.toString),
|
|
35
34
|
i,
|
|
36
35
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
37
|
-
), i = i.filter((
|
|
38
|
-
let
|
|
39
|
-
if (
|
|
40
|
-
for (const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
return
|
|
36
|
+
), i = i.filter((s) => s).flatMap(String);
|
|
37
|
+
let t = (e = i.shift()) == null ? void 0 : e.toString();
|
|
38
|
+
if (t) {
|
|
39
|
+
for (const s of i.map((r) => r.toString()))
|
|
40
|
+
s.startsWith(".") ? t = ct(t, s) : t[t.length - 1] !== "/" ? s[0] !== "/" ? t += "/" + s : t += s : s[0] === "/" ? t += s.slice(1) : t += s;
|
|
41
|
+
t && t !== "/" && t.endsWith("/") && (t = t.slice(0, t.length - 1));
|
|
42
|
+
}
|
|
43
|
+
return t ?? "";
|
|
45
44
|
}
|
|
46
|
-
function
|
|
47
|
-
if (
|
|
48
|
-
return
|
|
49
|
-
let
|
|
45
|
+
function ct(i, t) {
|
|
46
|
+
if (Ft(i, "Expected `base` to be a string. Got type: %t, value: %v"), t == null && (t = i, i = ""), t.startsWith("/"))
|
|
47
|
+
return t;
|
|
48
|
+
let e = i;
|
|
50
49
|
for (; ; )
|
|
51
|
-
if (
|
|
52
|
-
for (let
|
|
53
|
-
if (
|
|
54
|
-
|
|
50
|
+
if (t.startsWith("..")) {
|
|
51
|
+
for (let s = e.length; s > 0; --s)
|
|
52
|
+
if (e[s] === "/" || s === 0) {
|
|
53
|
+
e = e.slice(0, s), t = t.replace(/^\.\.\/?/, "");
|
|
55
54
|
break;
|
|
56
55
|
}
|
|
57
|
-
} else if (
|
|
58
|
-
|
|
56
|
+
} else if (t.startsWith("."))
|
|
57
|
+
t = t.replace(/^\.\/?/, "");
|
|
59
58
|
else
|
|
60
59
|
break;
|
|
61
|
-
return
|
|
60
|
+
return G([e, t]);
|
|
62
61
|
}
|
|
63
|
-
function
|
|
62
|
+
function ae(i) {
|
|
64
63
|
if (!i) return {};
|
|
65
64
|
i.startsWith("?") && (i = i.slice(1));
|
|
66
|
-
const
|
|
67
|
-
const [
|
|
68
|
-
return
|
|
65
|
+
const t = i.split("&").filter((e) => e.trim() !== "").map((e) => {
|
|
66
|
+
const [s, r] = e.split("=").map((n) => n.trim());
|
|
67
|
+
return r.toLowerCase() === "true" ? [s, !0] : r.toLowerCase() === "false" ? [s, !1] : isNaN(Number(r)) ? [s, r] : [s, Number(r)];
|
|
69
68
|
});
|
|
70
|
-
return Object.fromEntries(
|
|
69
|
+
return Object.fromEntries(t);
|
|
71
70
|
}
|
|
72
|
-
function
|
|
71
|
+
function Ct(i, t, e = {}) {
|
|
73
72
|
var o;
|
|
74
|
-
const [
|
|
75
|
-
|
|
76
|
-
const { fragments: l } =
|
|
77
|
-
if (!(((o = l[l.length - 1]) == null ? void 0 : o.type) === 3) && l.length !==
|
|
78
|
-
continue
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
if (
|
|
83
|
-
continue
|
|
84
|
-
switch (
|
|
73
|
+
const [s, r] = t.split("?"), n = Q(s);
|
|
74
|
+
t: for (const c of i) {
|
|
75
|
+
const { fragments: l } = c;
|
|
76
|
+
if (!(((o = l[l.length - 1]) == null ? void 0 : o.type) === 3) && l.length !== n.length || e.willMatch && !e.willMatch(c))
|
|
77
|
+
continue t;
|
|
78
|
+
const v = [];
|
|
79
|
+
e: for (let h = 0; h < l.length; h++) {
|
|
80
|
+
const x = n[h], $ = l[h];
|
|
81
|
+
if (x == null && $.type !== 3)
|
|
82
|
+
continue t;
|
|
83
|
+
switch ($.type) {
|
|
85
84
|
case 1:
|
|
86
|
-
if (
|
|
87
|
-
|
|
85
|
+
if ($.name.toLowerCase() === x.toLowerCase()) {
|
|
86
|
+
v.push($);
|
|
88
87
|
break;
|
|
89
88
|
} else
|
|
90
|
-
continue
|
|
89
|
+
continue t;
|
|
91
90
|
case 2:
|
|
92
|
-
|
|
91
|
+
v.push({ ...$, value: x });
|
|
93
92
|
break;
|
|
94
93
|
case 3:
|
|
95
|
-
|
|
96
|
-
break
|
|
94
|
+
v.push({ ...$, value: n.slice(h).join("/") });
|
|
95
|
+
break e;
|
|
97
96
|
case 4:
|
|
98
|
-
if (isNaN(Number(
|
|
99
|
-
continue
|
|
100
|
-
|
|
97
|
+
if (isNaN(Number(x)))
|
|
98
|
+
continue t;
|
|
99
|
+
v.push({ ...$, value: Number(x) });
|
|
101
100
|
break;
|
|
102
101
|
default:
|
|
103
|
-
throw new Error(`Unknown fragment type: ${
|
|
102
|
+
throw new Error(`Unknown fragment type: ${$.type}`);
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
const
|
|
107
|
-
for (const
|
|
108
|
-
|
|
105
|
+
const k = {};
|
|
106
|
+
for (const h of v)
|
|
107
|
+
h.type === 2 && (k[h.name] = decodeURIComponent(h.value)), h.type === 4 && (k[h.name] = h.value), h.type === 3 && (k.wildcard = "/" + decodeURIComponent(h.value));
|
|
109
108
|
return {
|
|
110
|
-
path: "/" +
|
|
111
|
-
pattern: "/" + l.map((
|
|
112
|
-
params:
|
|
113
|
-
query:
|
|
114
|
-
meta:
|
|
109
|
+
path: "/" + v.map((h) => h.value).join("/"),
|
|
110
|
+
pattern: "/" + l.map((h) => h.type === 2 ? `{${h.name}}` : h.type === 4 ? `{#${h.name}}` : h.name).join("/"),
|
|
111
|
+
params: k,
|
|
112
|
+
query: ae(r),
|
|
113
|
+
meta: c.meta
|
|
115
114
|
};
|
|
116
115
|
}
|
|
117
116
|
}
|
|
118
|
-
function
|
|
119
|
-
const
|
|
117
|
+
function ie(i) {
|
|
118
|
+
const t = [], e = [], s = [], r = [];
|
|
120
119
|
for (const o of i) {
|
|
121
|
-
const { fragments:
|
|
122
|
-
|
|
120
|
+
const { fragments: c } = o;
|
|
121
|
+
c.some(
|
|
123
122
|
(l) => l.type === 3
|
|
124
123
|
/* Wildcard */
|
|
125
|
-
) ?
|
|
124
|
+
) ? r.push(o) : c.some(
|
|
126
125
|
(l) => l.type === 4
|
|
127
126
|
/* NumericParam */
|
|
128
|
-
) ?
|
|
127
|
+
) ? e.push(o) : c.some(
|
|
129
128
|
(l) => l.type === 2
|
|
130
129
|
/* Param */
|
|
131
|
-
) ?
|
|
130
|
+
) ? s.push(o) : t.push(o);
|
|
132
131
|
}
|
|
133
|
-
const
|
|
134
|
-
return
|
|
132
|
+
const n = (o, c) => o.fragments.length > c.fragments.length ? -1 : 1;
|
|
133
|
+
return t.sort(n), e.sort(n), s.sort(n), r.sort(n), [...t, ...e, ...s, ...r];
|
|
135
134
|
}
|
|
136
|
-
function
|
|
137
|
-
const
|
|
138
|
-
for (let
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
if (
|
|
135
|
+
function oe(i) {
|
|
136
|
+
const t = Q(i), e = [];
|
|
137
|
+
for (let s = 0; s < t.length; s++) {
|
|
138
|
+
const r = t[s];
|
|
139
|
+
if (r === "*") {
|
|
140
|
+
if (s !== t.length - 1)
|
|
142
141
|
throw new Error(`Wildcard must be at the end of a pattern. Received: ${i}`);
|
|
143
|
-
|
|
142
|
+
e.push({
|
|
144
143
|
type: 3,
|
|
145
144
|
name: "*",
|
|
146
145
|
value: null
|
|
147
146
|
});
|
|
148
|
-
} else
|
|
149
|
-
type:
|
|
150
|
-
name:
|
|
147
|
+
} else r.at(0) === "{" && r.at(-1) === "}" ? e.push({
|
|
148
|
+
type: r[1] === "#" ? 4 : 2,
|
|
149
|
+
name: r[1] === "#" ? r.slice(2, -1) : r.slice(1, -1),
|
|
151
150
|
value: null
|
|
152
|
-
}) :
|
|
151
|
+
}) : e.push({
|
|
153
152
|
type: 1,
|
|
154
|
-
name:
|
|
155
|
-
value:
|
|
153
|
+
name: r,
|
|
154
|
+
value: r
|
|
156
155
|
});
|
|
157
156
|
}
|
|
158
|
-
return
|
|
157
|
+
return e;
|
|
159
158
|
}
|
|
160
|
-
function
|
|
161
|
-
return new
|
|
159
|
+
function Pe(i) {
|
|
160
|
+
return new he(i);
|
|
162
161
|
}
|
|
163
|
-
const
|
|
164
|
-
function
|
|
165
|
-
return (i == null ? void 0 : i[
|
|
162
|
+
const Dt = Symbol.for("DollaRouterMountMethod"), It = Symbol.for("DollaRouterUnmountMethod");
|
|
163
|
+
function pt(i) {
|
|
164
|
+
return (i == null ? void 0 : i[Ot]) === !0;
|
|
166
165
|
}
|
|
167
|
-
async function
|
|
168
|
-
return i[
|
|
166
|
+
async function le(i, t) {
|
|
167
|
+
return i[Dt](t);
|
|
169
168
|
}
|
|
170
|
-
async function
|
|
171
|
-
return i[
|
|
169
|
+
async function ce(i) {
|
|
170
|
+
return i[It]();
|
|
172
171
|
}
|
|
173
|
-
var
|
|
174
|
-
class
|
|
175
|
-
constructor(
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
172
|
+
var Lt, W, S, ht, T, A, J, j, C, N, m, wt, Vt, qt, K, Gt, gt, yt;
|
|
173
|
+
class he {
|
|
174
|
+
constructor(t) {
|
|
175
|
+
u(this, m);
|
|
176
|
+
w(this, Lt, !0);
|
|
177
|
+
u(this, W);
|
|
178
|
+
u(this, S);
|
|
179
|
+
u(this, ht, 0);
|
|
180
|
+
u(this, T, []);
|
|
181
|
+
u(this, A, []);
|
|
182
|
+
u(this, J, !1);
|
|
184
183
|
/**
|
|
185
184
|
* Use hash routing when true. Configured in router options.
|
|
186
185
|
*/
|
|
187
|
-
|
|
186
|
+
u(this, j, !1);
|
|
188
187
|
// Callbacks that need to be called on unmount.
|
|
189
|
-
|
|
188
|
+
u(this, C, []);
|
|
190
189
|
/**
|
|
191
190
|
* The current match object.
|
|
192
191
|
*/
|
|
193
|
-
|
|
192
|
+
u(this, N, Ut());
|
|
194
193
|
/**
|
|
195
194
|
* The currently matched route pattern, if any.
|
|
196
195
|
*/
|
|
197
|
-
|
|
198
|
-
var
|
|
199
|
-
return (
|
|
196
|
+
w(this, "pattern", U(() => {
|
|
197
|
+
var t;
|
|
198
|
+
return (t = E(a(this, N))) == null ? void 0 : t.pattern;
|
|
200
199
|
}));
|
|
201
200
|
/**
|
|
202
201
|
* The current URL path.
|
|
203
202
|
*/
|
|
204
|
-
|
|
205
|
-
var
|
|
206
|
-
return ((
|
|
203
|
+
w(this, "path", U(() => {
|
|
204
|
+
var t;
|
|
205
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.path) ?? window.location.pathname;
|
|
207
206
|
}));
|
|
208
207
|
/**
|
|
209
208
|
* The current named path params.
|
|
210
209
|
*/
|
|
211
|
-
|
|
212
|
-
var
|
|
213
|
-
return ((
|
|
214
|
-
}, { equals:
|
|
210
|
+
w(this, "params", U(() => {
|
|
211
|
+
var t;
|
|
212
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.params) ?? {};
|
|
213
|
+
}, { equals: _t }));
|
|
215
214
|
/**
|
|
216
215
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
217
216
|
*/
|
|
218
|
-
|
|
219
|
-
var
|
|
220
|
-
return ((
|
|
221
|
-
}, { equals:
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
pattern:
|
|
225
|
-
meta:
|
|
226
|
-
fragments:
|
|
217
|
+
w(this, "query", U(() => {
|
|
218
|
+
var t;
|
|
219
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.query) ?? {};
|
|
220
|
+
}, { equals: _t }));
|
|
221
|
+
Qt(t, "Options must be an object. Got: %t"), t.hash && d(this, j, !0), d(this, A, ie(
|
|
222
|
+
t.routes.flatMap((e) => f(this, m, yt).call(this, e)).map((e) => ({
|
|
223
|
+
pattern: e.pattern,
|
|
224
|
+
meta: e.meta,
|
|
225
|
+
fragments: oe(e.pattern)
|
|
227
226
|
}))
|
|
228
|
-
)),
|
|
227
|
+
)), pe(a(this, A));
|
|
229
228
|
}
|
|
230
|
-
async [(
|
|
231
|
-
d(this,
|
|
232
|
-
const
|
|
233
|
-
f(this, m,
|
|
229
|
+
async [(Lt = Ot, Dt)](t) {
|
|
230
|
+
d(this, W, t), d(this, S, t.createLogger("Dolla.router"));
|
|
231
|
+
const e = () => {
|
|
232
|
+
f(this, m, K).call(this);
|
|
234
233
|
};
|
|
235
|
-
window.addEventListener("popstate",
|
|
236
|
-
const
|
|
237
|
-
a(this,
|
|
238
|
-
|
|
239
|
-
let
|
|
240
|
-
a(this,
|
|
234
|
+
window.addEventListener("popstate", e), a(this, C).push(() => window.removeEventListener("popstate", e));
|
|
235
|
+
const s = t.getRootElement();
|
|
236
|
+
a(this, C).push(
|
|
237
|
+
de(s, (r) => {
|
|
238
|
+
let n = r.getAttribute("href");
|
|
239
|
+
a(this, S).info("intercepted click on <a> tag", r), /^https?:\/\/|^\//.test(n) || (n = G([window.location.pathname, n])), f(this, m, wt).call(this, n);
|
|
241
240
|
})
|
|
242
|
-
), a(this,
|
|
241
|
+
), a(this, S).info("will intercept clicks on <a> tags within root element", s), d(this, J, !0), await f(this, m, K).call(this);
|
|
243
242
|
}
|
|
244
|
-
async [
|
|
245
|
-
for (const
|
|
246
|
-
|
|
247
|
-
d(this,
|
|
243
|
+
async [It]() {
|
|
244
|
+
for (const t of a(this, C))
|
|
245
|
+
t();
|
|
246
|
+
d(this, C, []);
|
|
248
247
|
}
|
|
249
248
|
/**
|
|
250
249
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
251
250
|
*/
|
|
252
|
-
back(
|
|
253
|
-
window.history.go(-
|
|
251
|
+
back(t = 1) {
|
|
252
|
+
window.history.go(-t);
|
|
254
253
|
}
|
|
255
254
|
/**
|
|
256
255
|
* Navigate forward. Pass a number of steps to hit the forward button that many times.
|
|
257
256
|
*/
|
|
258
|
-
forward(
|
|
259
|
-
window.history.go(
|
|
257
|
+
forward(t = 1) {
|
|
258
|
+
window.history.go(t);
|
|
260
259
|
}
|
|
261
260
|
/**
|
|
262
261
|
* Navigates to another route.
|
|
@@ -265,186 +264,186 @@ class ft {
|
|
|
265
264
|
* router.go("/login"); // navigate to `/login`
|
|
266
265
|
* router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
267
266
|
*/
|
|
268
|
-
go(
|
|
269
|
-
if (a(this,
|
|
267
|
+
go(t, e = {}) {
|
|
268
|
+
if (a(this, W) == null)
|
|
270
269
|
throw new Error("Routa methods won't work until you register it: Dolla.use(Routa, { /* ...options */ })");
|
|
271
|
-
let
|
|
272
|
-
Array.isArray(
|
|
270
|
+
let s;
|
|
271
|
+
Array.isArray(t) ? s = G(t) : s = t.toString(), s = ct(window.location.pathname, s), e.preserveQuery && (s += window.location.search), e.replace ? f(this, m, Vt).call(this, s) : f(this, m, wt).call(this, s);
|
|
273
272
|
}
|
|
274
273
|
}
|
|
275
|
-
|
|
276
|
-
var
|
|
277
|
-
(
|
|
278
|
-
},
|
|
279
|
-
var
|
|
280
|
-
(
|
|
281
|
-
},
|
|
282
|
-
return a(this,
|
|
283
|
-
},
|
|
284
|
-
var
|
|
285
|
-
const
|
|
274
|
+
W = new WeakMap(), S = new WeakMap(), ht = new WeakMap(), T = new WeakMap(), A = new WeakMap(), J = new WeakMap(), j = new WeakMap(), C = new WeakMap(), N = new WeakMap(), m = new WeakSet(), wt = function(t, e) {
|
|
275
|
+
var s;
|
|
276
|
+
(s = a(this, S)) == null || s.info("(push)", t), window.history.pushState(e, "", a(this, j) ? "/#" + t : t), f(this, m, K).call(this, t);
|
|
277
|
+
}, Vt = function(t, e) {
|
|
278
|
+
var s;
|
|
279
|
+
(s = a(this, S)) == null || s.info("(replace)", t), window.history.replaceState(e, "", a(this, j) ? "/#" + t : t), f(this, m, K).call(this, t);
|
|
280
|
+
}, qt = function() {
|
|
281
|
+
return a(this, j) ? new URL(window.location.hash.slice(1), window.location.origin) : new URL(window.location.pathname, window.location.origin);
|
|
282
|
+
}, K = async function(t) {
|
|
283
|
+
var c;
|
|
284
|
+
const e = a(this, S), s = (c = a(this, W)) == null ? void 0 : c.getRootView(), r = t ? new URL(t, window.location.origin) : f(this, m, qt).call(this), { match: n, journey: o } = await f(this, m, gt).call(this, r);
|
|
286
285
|
for (const l of o)
|
|
287
286
|
switch (l.kind) {
|
|
288
287
|
case "match":
|
|
289
|
-
|
|
288
|
+
e == null || e.info(`📍 ${l.message}`);
|
|
290
289
|
break;
|
|
291
290
|
case "redirect":
|
|
292
|
-
|
|
291
|
+
e == null || e.info(`↩️ ${l.message}`);
|
|
293
292
|
break;
|
|
294
293
|
case "miss":
|
|
295
|
-
|
|
294
|
+
e == null || e.info(`💀 ${l.message}`);
|
|
296
295
|
break;
|
|
297
296
|
}
|
|
298
|
-
if (
|
|
297
|
+
if (n) {
|
|
299
298
|
const l = this.pattern.value;
|
|
300
|
-
a(this,
|
|
299
|
+
a(this, N).value = n, s && n.pattern !== l && f(this, m, Gt).call(this, s, n);
|
|
301
300
|
} else
|
|
302
|
-
a(this,
|
|
303
|
-
return { match:
|
|
301
|
+
a(this, J) && e.crash(new we(`Failed to match route '${r.pathname}'`));
|
|
302
|
+
return { match: n, journey: o };
|
|
304
303
|
}, /**
|
|
305
304
|
* Takes a matched route and mounts it.
|
|
306
305
|
*/
|
|
307
|
-
|
|
308
|
-
const
|
|
309
|
-
for (let
|
|
310
|
-
const
|
|
311
|
-
if ((o == null ? void 0 : o.id) !==
|
|
312
|
-
d(this,
|
|
313
|
-
const
|
|
314
|
-
a(this,
|
|
306
|
+
Gt = function(t, e) {
|
|
307
|
+
const s = e.meta.layers;
|
|
308
|
+
for (let r = 0; r < s.length; r++) {
|
|
309
|
+
const n = s[r], o = a(this, T)[r];
|
|
310
|
+
if ((o == null ? void 0 : o.id) !== n.id) {
|
|
311
|
+
d(this, T, a(this, T).slice(0, r)), o == null || o.view.unmount();
|
|
312
|
+
const c = a(this, T).at(-1), p = ((c == null ? void 0 : c.view) ?? t).setChildView(n.view);
|
|
313
|
+
a(this, T).push({ id: n.id, view: p });
|
|
315
314
|
}
|
|
316
315
|
}
|
|
317
|
-
},
|
|
318
|
-
const
|
|
319
|
-
if (!
|
|
316
|
+
}, gt = async function(t, e = []) {
|
|
317
|
+
const s = Ct(a(this, A), t.pathname);
|
|
318
|
+
if (!s)
|
|
320
319
|
return {
|
|
321
320
|
match: null,
|
|
322
|
-
journey: [...
|
|
321
|
+
journey: [...e, { kind: "miss", message: `no match for '${t.pathname}'` }]
|
|
323
322
|
};
|
|
324
|
-
let
|
|
325
|
-
if (
|
|
323
|
+
let r = s.meta.redirect;
|
|
324
|
+
if (s.meta.beforeMatch && await s.meta.beforeMatch({
|
|
326
325
|
// TODO: Allow setting context variables from here? Would apply to the context of the matched view.
|
|
327
|
-
redirect: (
|
|
328
|
-
|
|
326
|
+
redirect: (n) => {
|
|
327
|
+
r = n;
|
|
329
328
|
}
|
|
330
|
-
}),
|
|
331
|
-
let
|
|
332
|
-
if (
|
|
333
|
-
|
|
334
|
-
else if (
|
|
329
|
+
}), r != null) {
|
|
330
|
+
let n;
|
|
331
|
+
if (M(r))
|
|
332
|
+
n = me(r, s.params);
|
|
333
|
+
else if (B(r)) {
|
|
335
334
|
const o = {
|
|
336
|
-
path:
|
|
337
|
-
pattern:
|
|
338
|
-
params:
|
|
339
|
-
query:
|
|
335
|
+
path: s.path,
|
|
336
|
+
pattern: s.pattern,
|
|
337
|
+
params: s.params,
|
|
338
|
+
query: s.query
|
|
340
339
|
};
|
|
341
|
-
if (
|
|
340
|
+
if (n = await r(o), !M(n))
|
|
342
341
|
throw new Error("Redirect function must return a path to redirect to.");
|
|
343
|
-
|
|
342
|
+
n.startsWith("/") || (n = ct(s.path, n));
|
|
344
343
|
} else
|
|
345
344
|
throw new TypeError("Redirect must either be a path string or a function.");
|
|
346
|
-
return f(this, m,
|
|
347
|
-
...
|
|
348
|
-
{ kind: "redirect", message: `redirecting '${
|
|
345
|
+
return f(this, m, gt).call(this, new URL(n, window.location.origin), [
|
|
346
|
+
...e,
|
|
347
|
+
{ kind: "redirect", message: `redirecting '${s.path}' -> '${n}'` }
|
|
349
348
|
]);
|
|
350
349
|
} else
|
|
351
|
-
return { match:
|
|
350
|
+
return { match: s, journey: [...e, { kind: "match", message: `matched route '${s.path}'` }] };
|
|
352
351
|
}, /**
|
|
353
352
|
* Parses a route definition object into a set of matchable routes.
|
|
354
353
|
*
|
|
355
354
|
* @param route - Route config object.
|
|
356
355
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
357
356
|
*/
|
|
358
|
-
|
|
359
|
-
if (!
|
|
360
|
-
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${
|
|
361
|
-
if (
|
|
357
|
+
yt = function(t, e = [], s = []) {
|
|
358
|
+
if (!V(t) || !M(t.path))
|
|
359
|
+
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${t}`);
|
|
360
|
+
if (t.redirect && t.routes)
|
|
362
361
|
throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
|
|
363
|
-
if (
|
|
362
|
+
if (t.redirect && t.view)
|
|
364
363
|
throw new Error("Route cannot have both a 'redirect' and a 'view'.");
|
|
365
|
-
if (!
|
|
364
|
+
if (!t.view && !t.routes && !t.redirect)
|
|
366
365
|
throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
|
|
367
|
-
let
|
|
368
|
-
for (const l of
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
let l =
|
|
374
|
-
return
|
|
375
|
-
pattern: "/" +
|
|
366
|
+
let r = [];
|
|
367
|
+
for (const l of e)
|
|
368
|
+
r.push(...Q(l.path));
|
|
369
|
+
r.push(...Q(t.path)), r[r.length - 1] === "*" && r.pop();
|
|
370
|
+
const n = [];
|
|
371
|
+
if (t.redirect) {
|
|
372
|
+
let l = t.redirect;
|
|
373
|
+
return M(l) && (l = ct(G(r), l), l.startsWith("/") || (l = "/" + l)), n.push({
|
|
374
|
+
pattern: "/" + G([...r, ...Q(t.path)]),
|
|
376
375
|
meta: {
|
|
377
376
|
redirect: l
|
|
378
377
|
}
|
|
379
|
-
}),
|
|
380
|
-
}
|
|
381
|
-
let o =
|
|
382
|
-
if (
|
|
383
|
-
o =
|
|
384
|
-
else if (
|
|
385
|
-
throw new TypeError(`Route '${
|
|
386
|
-
const
|
|
387
|
-
if (
|
|
388
|
-
for (const l of
|
|
389
|
-
|
|
378
|
+
}), n;
|
|
379
|
+
}
|
|
380
|
+
let o = jt;
|
|
381
|
+
if (B(t.view))
|
|
382
|
+
o = t.view;
|
|
383
|
+
else if (t.view)
|
|
384
|
+
throw new TypeError(`Route '${t.path}' expected a view function or undefined. Got: ${t.view}`);
|
|
385
|
+
const c = { id: Rt(this, ht)._++, view: o };
|
|
386
|
+
if (t.routes)
|
|
387
|
+
for (const l of t.routes)
|
|
388
|
+
n.push(...f(this, m, yt).call(this, l, [...e, t], [...s, c]));
|
|
390
389
|
else
|
|
391
|
-
|
|
392
|
-
pattern: parent ?
|
|
390
|
+
n.push({
|
|
391
|
+
pattern: parent ? G([...e.map((l) => l.path), t.path]) : t.path,
|
|
393
392
|
meta: {
|
|
394
|
-
pattern:
|
|
395
|
-
layers: [...
|
|
396
|
-
beforeMatch:
|
|
393
|
+
pattern: t.path,
|
|
394
|
+
layers: [...s, c],
|
|
395
|
+
beforeMatch: t.beforeMatch
|
|
397
396
|
}
|
|
398
397
|
});
|
|
399
|
-
return
|
|
398
|
+
return n;
|
|
400
399
|
};
|
|
401
|
-
const
|
|
402
|
-
function
|
|
403
|
-
function
|
|
404
|
-
return !
|
|
400
|
+
const ue = /(noopener|noreferrer) (noopener|noreferrer)/, fe = /^[\w-_]+:/;
|
|
401
|
+
function de(i, t, e = window) {
|
|
402
|
+
function s(n) {
|
|
403
|
+
return !n || n === i ? null : n.localName !== "a" || n.href === void 0 ? s(n.parentNode) : n;
|
|
405
404
|
}
|
|
406
|
-
function n
|
|
407
|
-
if (
|
|
405
|
+
function r(n) {
|
|
406
|
+
if (n.button && n.button !== 0 || n.ctrlKey || n.metaKey || n.altKey || n.shiftKey || n.defaultPrevented)
|
|
408
407
|
return;
|
|
409
|
-
const o =
|
|
410
|
-
o && (
|
|
408
|
+
const o = s(n.target);
|
|
409
|
+
o && (e.location.protocol !== o.protocol || e.location.hostname !== o.hostname || e.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" && ue.test(o.getAttribute("rel")) || fe.test(o.getAttribute("href")) || (n.preventDefault(), t(o)));
|
|
411
410
|
}
|
|
412
|
-
return i.addEventListener("click",
|
|
413
|
-
i.removeEventListener("click",
|
|
411
|
+
return i.addEventListener("click", r), function() {
|
|
412
|
+
i.removeEventListener("click", r);
|
|
414
413
|
};
|
|
415
414
|
}
|
|
416
|
-
function
|
|
417
|
-
for (const
|
|
418
|
-
const
|
|
419
|
-
i = i.replace(`{${
|
|
415
|
+
function me(i, t) {
|
|
416
|
+
for (const e in t) {
|
|
417
|
+
const s = t[e].toString();
|
|
418
|
+
i = i.replace(`{${e}}`, s).replace(`{#${e}}`, s);
|
|
420
419
|
}
|
|
421
420
|
return i;
|
|
422
421
|
}
|
|
423
|
-
function
|
|
424
|
-
for (const
|
|
425
|
-
if (
|
|
426
|
-
let
|
|
427
|
-
if (!
|
|
428
|
-
if (
|
|
429
|
-
willMatch(
|
|
430
|
-
return
|
|
422
|
+
function pe(i) {
|
|
423
|
+
for (const t of i)
|
|
424
|
+
if (t.meta.redirect) {
|
|
425
|
+
let e;
|
|
426
|
+
if (!B(t.meta.redirect)) if (M(t.meta.redirect)) {
|
|
427
|
+
if (e = t.meta.redirect, !Ct(i, e, {
|
|
428
|
+
willMatch(r) {
|
|
429
|
+
return r !== t;
|
|
431
430
|
}
|
|
432
431
|
}))
|
|
433
|
-
throw new Error(`Found a redirect to an undefined URL. From '${
|
|
432
|
+
throw new Error(`Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`);
|
|
434
433
|
} else
|
|
435
|
-
throw new TypeError(`Expected a string or redirect function. Got: ${
|
|
434
|
+
throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
|
|
436
435
|
}
|
|
437
436
|
}
|
|
438
|
-
class
|
|
437
|
+
class we extends Error {
|
|
439
438
|
}
|
|
440
|
-
var
|
|
441
|
-
class
|
|
439
|
+
var D, ut, R, _;
|
|
440
|
+
class ge {
|
|
442
441
|
// #dolla: Dolla;
|
|
443
442
|
// #logger: Logger;
|
|
444
443
|
constructor() {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
444
|
+
u(this, R);
|
|
445
|
+
u(this, D, []);
|
|
446
|
+
u(this, ut, ye());
|
|
448
447
|
}
|
|
449
448
|
/**
|
|
450
449
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -452,312 +451,312 @@ class bt {
|
|
|
452
451
|
*
|
|
453
452
|
* @param middleware - A middleware function that will intercept requests.
|
|
454
453
|
*/
|
|
455
|
-
use(
|
|
456
|
-
return a(this,
|
|
457
|
-
a(this,
|
|
454
|
+
use(t) {
|
|
455
|
+
return a(this, D).push(t), () => {
|
|
456
|
+
a(this, D).splice(a(this, D).indexOf(t), 1);
|
|
458
457
|
};
|
|
459
458
|
}
|
|
460
|
-
async get(
|
|
461
|
-
return f(this,
|
|
459
|
+
async get(t, e) {
|
|
460
|
+
return f(this, R, _).call(this, "get", t, e);
|
|
462
461
|
}
|
|
463
|
-
async put(
|
|
464
|
-
return f(this,
|
|
462
|
+
async put(t, e) {
|
|
463
|
+
return f(this, R, _).call(this, "put", t, e);
|
|
465
464
|
}
|
|
466
|
-
async patch(
|
|
467
|
-
return f(this,
|
|
465
|
+
async patch(t, e) {
|
|
466
|
+
return f(this, R, _).call(this, "patch", t, e);
|
|
468
467
|
}
|
|
469
|
-
async post(
|
|
470
|
-
return f(this,
|
|
468
|
+
async post(t, e) {
|
|
469
|
+
return f(this, R, _).call(this, "post", t, e);
|
|
471
470
|
}
|
|
472
|
-
async delete(
|
|
473
|
-
return f(this,
|
|
471
|
+
async delete(t, e) {
|
|
472
|
+
return f(this, R, _).call(this, "delete", t, e);
|
|
474
473
|
}
|
|
475
|
-
async head(
|
|
476
|
-
return f(this,
|
|
474
|
+
async head(t, e) {
|
|
475
|
+
return f(this, R, _).call(this, "head", t, e);
|
|
477
476
|
}
|
|
478
|
-
async options(
|
|
479
|
-
return f(this,
|
|
477
|
+
async options(t, e) {
|
|
478
|
+
return f(this, R, _).call(this, "options", t, e);
|
|
480
479
|
}
|
|
481
|
-
async trace(
|
|
482
|
-
return f(this,
|
|
480
|
+
async trace(t, e) {
|
|
481
|
+
return f(this, R, _).call(this, "trace", t, e);
|
|
483
482
|
}
|
|
484
483
|
}
|
|
485
|
-
|
|
486
|
-
return new
|
|
487
|
-
...
|
|
488
|
-
method:
|
|
489
|
-
uri:
|
|
490
|
-
middleware: a(this,
|
|
491
|
-
fetch: a(this,
|
|
484
|
+
D = new WeakMap(), ut = new WeakMap(), R = new WeakSet(), _ = async function(t, e, s) {
|
|
485
|
+
return new Ee({
|
|
486
|
+
...s,
|
|
487
|
+
method: t,
|
|
488
|
+
uri: e,
|
|
489
|
+
middleware: a(this, D),
|
|
490
|
+
fetch: a(this, ut)
|
|
492
491
|
}).fetch();
|
|
493
492
|
};
|
|
494
|
-
function
|
|
493
|
+
function ye() {
|
|
495
494
|
if (typeof window < "u" && window.fetch)
|
|
496
495
|
return window.fetch.bind(window);
|
|
497
496
|
if (typeof global < "u" && global.fetch)
|
|
498
497
|
return global.fetch.bind(global);
|
|
499
498
|
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
500
499
|
}
|
|
501
|
-
class
|
|
502
|
-
constructor(
|
|
503
|
-
const { status:
|
|
504
|
-
super(
|
|
505
|
-
|
|
506
|
-
this.response =
|
|
500
|
+
class be extends Error {
|
|
501
|
+
constructor(e) {
|
|
502
|
+
const { status: s, statusText: r, method: n, url: o } = e, c = `${s} ${r}: Request failed (${n.toUpperCase()} ${o.toString()})`;
|
|
503
|
+
super(c);
|
|
504
|
+
w(this, "response");
|
|
505
|
+
this.response = e;
|
|
507
506
|
}
|
|
508
507
|
}
|
|
509
|
-
class
|
|
510
|
-
constructor(
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
this.method =
|
|
508
|
+
class ve {
|
|
509
|
+
constructor(t) {
|
|
510
|
+
w(this, "method");
|
|
511
|
+
w(this, "url");
|
|
512
|
+
w(this, "headers", new Headers());
|
|
513
|
+
w(this, "body");
|
|
514
|
+
this.method = t.method, this.body = t.body, t.uri.startsWith("http") ? this.url = new URL(t.uri) : this.url = new URL(t.uri, window.location.origin), this._applyHeaders(t.headers), this._applyQueryParams(t.query);
|
|
516
515
|
}
|
|
517
516
|
get isSameOrigin() {
|
|
518
517
|
return this.url.origin === window.location.origin;
|
|
519
518
|
}
|
|
520
|
-
_applyHeaders(
|
|
521
|
-
if (
|
|
522
|
-
if (
|
|
523
|
-
|
|
524
|
-
this.headers.set(
|
|
519
|
+
_applyHeaders(t) {
|
|
520
|
+
if (t != null)
|
|
521
|
+
if (t instanceof Map || t instanceof Headers)
|
|
522
|
+
t.forEach((e, s) => {
|
|
523
|
+
this.headers.set(s, e);
|
|
525
524
|
});
|
|
526
|
-
else if (
|
|
527
|
-
for (const
|
|
528
|
-
const
|
|
529
|
-
|
|
525
|
+
else if (V(t))
|
|
526
|
+
for (const e in t) {
|
|
527
|
+
const s = t[e];
|
|
528
|
+
s instanceof Date ? this.headers.set(e, s.toISOString()) : s != null && this.headers.set(e, String(s));
|
|
530
529
|
}
|
|
531
530
|
else
|
|
532
|
-
throw new TypeError(`Unknown headers type. Got: ${
|
|
531
|
+
throw new TypeError(`Unknown headers type. Got: ${t}`);
|
|
533
532
|
}
|
|
534
|
-
_applyQueryParams(
|
|
535
|
-
if (
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
this.url.searchParams.set(
|
|
533
|
+
_applyQueryParams(t) {
|
|
534
|
+
if (t != null)
|
|
535
|
+
if (t instanceof Map || t instanceof URLSearchParams)
|
|
536
|
+
t.forEach((e, s) => {
|
|
537
|
+
this.url.searchParams.set(s, e);
|
|
539
538
|
});
|
|
540
|
-
else if (
|
|
541
|
-
for (const
|
|
542
|
-
const
|
|
543
|
-
|
|
539
|
+
else if (V(t))
|
|
540
|
+
for (const e in t) {
|
|
541
|
+
const s = t[e];
|
|
542
|
+
s instanceof Date ? this.url.searchParams.set(e, s.toISOString()) : s != null && this.url.searchParams.set(e, String(s));
|
|
544
543
|
}
|
|
545
544
|
else
|
|
546
|
-
throw new TypeError(`Unknown query params type. Got: ${
|
|
545
|
+
throw new TypeError(`Unknown query params type. Got: ${t}`);
|
|
547
546
|
}
|
|
548
547
|
}
|
|
549
|
-
class
|
|
550
|
-
constructor(
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this._middleware =
|
|
548
|
+
class Ee {
|
|
549
|
+
constructor(t) {
|
|
550
|
+
w(this, "_middleware");
|
|
551
|
+
w(this, "_fetch");
|
|
552
|
+
w(this, "_request");
|
|
553
|
+
w(this, "_response");
|
|
554
|
+
this._middleware = t.middleware, this._fetch = t.fetch, this._request = new ve(t);
|
|
556
555
|
}
|
|
557
556
|
async fetch() {
|
|
558
557
|
if (this._middleware.length > 0) {
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
return async () =>
|
|
558
|
+
const t = (e = 0) => {
|
|
559
|
+
const s = this._middleware[e], r = this._middleware[e + 1] ? t(e + 1) : this._handler.bind(this);
|
|
560
|
+
return async () => s(this._request, async () => (await r(), this._response));
|
|
562
561
|
};
|
|
563
|
-
await
|
|
562
|
+
await t()();
|
|
564
563
|
} else
|
|
565
564
|
await this._handler();
|
|
566
565
|
if (this._response.status < 200 || this._response.status >= 400)
|
|
567
|
-
throw new
|
|
566
|
+
throw new be(this._response);
|
|
568
567
|
return this._response;
|
|
569
568
|
}
|
|
570
569
|
// This is the function that performs the actual request after the final middleware.
|
|
571
570
|
async _handler() {
|
|
572
|
-
let
|
|
573
|
-
const
|
|
574
|
-
!
|
|
575
|
-
const
|
|
576
|
-
method:
|
|
577
|
-
headers:
|
|
578
|
-
body:
|
|
579
|
-
}),
|
|
580
|
-
let
|
|
581
|
-
|
|
582
|
-
method:
|
|
583
|
-
url:
|
|
584
|
-
status:
|
|
585
|
-
statusText:
|
|
586
|
-
headers:
|
|
587
|
-
body:
|
|
571
|
+
let t;
|
|
572
|
+
const e = this._request;
|
|
573
|
+
!e.headers.has("content-type") && V(e.body) ? (e.headers.set("content-type", "application/json"), t = JSON.stringify(e.body)) : t = e.body;
|
|
574
|
+
const s = await this._fetch(e.url.toString(), {
|
|
575
|
+
method: e.method,
|
|
576
|
+
headers: e.headers,
|
|
577
|
+
body: t
|
|
578
|
+
}), r = s.headers.get("content-type");
|
|
579
|
+
let n;
|
|
580
|
+
r != null && r.includes("application/json") ? n = await s.json() : r != null && r.includes("application/x-www-form-urlencoded") ? n = await s.formData() : n = await s.text(), this._response = {
|
|
581
|
+
method: e.method,
|
|
582
|
+
url: e.url,
|
|
583
|
+
status: s.status,
|
|
584
|
+
statusText: s.statusText,
|
|
585
|
+
headers: s.headers,
|
|
586
|
+
body: n
|
|
588
587
|
};
|
|
589
588
|
}
|
|
590
589
|
}
|
|
591
|
-
var
|
|
592
|
-
class
|
|
593
|
-
constructor(
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
this.config =
|
|
590
|
+
var ft, H, q, bt, Wt;
|
|
591
|
+
class ke {
|
|
592
|
+
constructor(t, e) {
|
|
593
|
+
u(this, q);
|
|
594
|
+
w(this, "dolla");
|
|
595
|
+
w(this, "config");
|
|
596
|
+
u(this, ft, !1);
|
|
597
|
+
u(this, H, /* @__PURE__ */ new Map());
|
|
598
|
+
this.config = t, this.dolla = e;
|
|
600
599
|
}
|
|
601
600
|
async load() {
|
|
602
|
-
let
|
|
603
|
-
if (!a(this,
|
|
604
|
-
if (
|
|
605
|
-
|
|
606
|
-
else if (
|
|
607
|
-
if (
|
|
608
|
-
throw new Error(`Fetch function did not return an object of language strings: ${
|
|
609
|
-
} else if (
|
|
610
|
-
const
|
|
611
|
-
if (
|
|
612
|
-
const
|
|
613
|
-
if (
|
|
614
|
-
|
|
601
|
+
let t;
|
|
602
|
+
if (!a(this, ft)) {
|
|
603
|
+
if (V(this.config.strings))
|
|
604
|
+
t = this.config.strings;
|
|
605
|
+
else if (B(this.config.fetch)) {
|
|
606
|
+
if (t = await this.config.fetch(), !V(t))
|
|
607
|
+
throw new Error(`Fetch function did not return an object of language strings: ${t}`);
|
|
608
|
+
} else if (M(this.config.path)) {
|
|
609
|
+
const e = await fetch(this.config.path);
|
|
610
|
+
if (e.ok) {
|
|
611
|
+
const s = await e.json();
|
|
612
|
+
if (V(s))
|
|
613
|
+
t = s;
|
|
615
614
|
else
|
|
616
615
|
throw new Error(
|
|
617
|
-
`Language path '${this.config.path}' did not return an object of language strings: ${
|
|
616
|
+
`Language path '${this.config.path}' did not return an object of language strings: ${s}`
|
|
618
617
|
);
|
|
619
618
|
} else
|
|
620
619
|
throw new Error("HTTP request failed.");
|
|
621
620
|
}
|
|
622
621
|
}
|
|
623
|
-
if (
|
|
624
|
-
const
|
|
625
|
-
for (const
|
|
626
|
-
a(this,
|
|
622
|
+
if (t) {
|
|
623
|
+
const e = f(this, q, bt).call(this, t);
|
|
624
|
+
for (const s of e)
|
|
625
|
+
a(this, H).set(s[0], s[1]);
|
|
627
626
|
} else
|
|
628
627
|
throw new Error("Language could not be loaded.");
|
|
629
628
|
}
|
|
630
|
-
getTemplate(
|
|
631
|
-
return a(this,
|
|
632
|
-
segments: [{ type: 0, text: `[MISSING: ${
|
|
629
|
+
getTemplate(t) {
|
|
630
|
+
return a(this, H).get(t) ?? {
|
|
631
|
+
segments: [{ type: 0, text: `[MISSING: ${t}]` }]
|
|
633
632
|
};
|
|
634
633
|
}
|
|
635
|
-
hasTemplate(
|
|
636
|
-
return a(this,
|
|
634
|
+
hasTemplate(t) {
|
|
635
|
+
return a(this, H).has(t);
|
|
637
636
|
}
|
|
638
637
|
}
|
|
639
|
-
|
|
640
|
-
const
|
|
641
|
-
for (const
|
|
642
|
-
switch (
|
|
638
|
+
ft = new WeakMap(), H = new WeakMap(), q = new WeakSet(), bt = function(t, e = []) {
|
|
639
|
+
const s = [];
|
|
640
|
+
for (const r in t)
|
|
641
|
+
switch (St(t[r])) {
|
|
643
642
|
case "string":
|
|
644
|
-
|
|
643
|
+
s.push([[...e, r].join("."), f(this, q, Wt).call(this, t[r])]);
|
|
645
644
|
break;
|
|
646
645
|
case "object":
|
|
647
|
-
|
|
646
|
+
s.push(...f(this, q, bt).call(this, t[r], [...e, r]));
|
|
648
647
|
break;
|
|
649
648
|
default:
|
|
650
649
|
throw new Error(
|
|
651
|
-
`Expected to find a string or object at ${[...
|
|
650
|
+
`Expected to find a string or object at ${[...e, r].join(".")}. Got: ${St(t[r])}`
|
|
652
651
|
);
|
|
653
652
|
}
|
|
654
|
-
return
|
|
655
|
-
},
|
|
656
|
-
let
|
|
657
|
-
((
|
|
658
|
-
|
|
659
|
-
})(
|
|
660
|
-
const
|
|
653
|
+
return s;
|
|
654
|
+
}, Wt = function(t) {
|
|
655
|
+
let e;
|
|
656
|
+
((h) => {
|
|
657
|
+
h[h.Static = 0] = "Static", h[h.ValueName = 1] = "ValueName", h[h.FormatName = 2] = "FormatName", h[h.FormatOptionName = 3] = "FormatOptionName", h[h.FormatOptionValue = 4] = "FormatOptionValue", h[h.FormatOptionEnd = 5] = "FormatOptionEnd";
|
|
658
|
+
})(e || (e = {}));
|
|
659
|
+
const s = {
|
|
661
660
|
segments: []
|
|
662
661
|
};
|
|
663
|
-
let
|
|
664
|
-
const
|
|
665
|
-
|
|
662
|
+
let r = "", n = 0, o = 0, c, l, p;
|
|
663
|
+
const v = () => {
|
|
664
|
+
c = {
|
|
666
665
|
type: 1,
|
|
667
666
|
name: "",
|
|
668
667
|
formats: []
|
|
669
668
|
};
|
|
670
|
-
},
|
|
669
|
+
}, k = () => {
|
|
671
670
|
l = {
|
|
672
671
|
name: "",
|
|
673
672
|
options: {}
|
|
674
673
|
};
|
|
675
674
|
};
|
|
676
|
-
for (;
|
|
677
|
-
if (o !== 0 &&
|
|
678
|
-
|
|
675
|
+
for (; n < t.length; ) {
|
|
676
|
+
if (o !== 0 && t[n] === " ") {
|
|
677
|
+
n++;
|
|
679
678
|
continue;
|
|
680
679
|
}
|
|
681
680
|
switch (o) {
|
|
682
681
|
case 0:
|
|
683
|
-
|
|
682
|
+
t[n] === "{" && t[n + 1] === "{" ? (o = 1, n += 2, r.length > 0 && (s.segments.push({ type: 0, text: r }), r = ""), v()) : (r += t[n], n++);
|
|
684
683
|
break;
|
|
685
684
|
case 1:
|
|
686
|
-
|
|
685
|
+
t[n] === "|" ? (o = 2, n += 1, c.name = r, r = "", k()) : t[n] === "}" && t[n + 1] === "}" ? (o = 0, n += 2, c.name = r, r = "", s.segments.push(c)) : (r += t[n], n++);
|
|
687
686
|
break;
|
|
688
687
|
case 2:
|
|
689
|
-
|
|
688
|
+
t[n] === "(" ? (o = 3, n += 1, l.name = r, r = "") : t[n] === "}" && t[n + 1] === "}" ? (o = 0, n += 2, c.formats.push(l), s.segments.push(c)) : (r += t[n], n++);
|
|
690
689
|
break;
|
|
691
690
|
case 3:
|
|
692
|
-
|
|
691
|
+
t[n] === ")" || (t[n] === ":" ? (o = 4, n += 1, p = r, r = "") : t[n] === "}" && t[n + 1] === "}" || (r += t[n], n++));
|
|
693
692
|
break;
|
|
694
693
|
case 4:
|
|
695
|
-
|
|
694
|
+
t[n] === ")" ? (o = 5, n += 1, l.options[p] = r, r = "", c.formats.push(l)) : t[n] === "," ? (o = 3, n += 1, l.options[p] = r, r = "") : t[n] === "}" && t[n + 1] === "}" || (r += t[n], n++);
|
|
696
695
|
break;
|
|
697
696
|
case 5:
|
|
698
|
-
|
|
697
|
+
t[n] === "|" ? (o = 2, n += 1, k()) : t[n] === "}" && t[n + 1] === "}" && (o = 0, n += 2, s.segments.push(c));
|
|
699
698
|
break;
|
|
700
699
|
}
|
|
701
700
|
}
|
|
702
|
-
return o === 0 &&
|
|
701
|
+
return o === 0 && r.length > 0 && s.segments.push({ type: 0, text: r }), s;
|
|
703
702
|
};
|
|
704
|
-
var
|
|
705
|
-
class
|
|
706
|
-
constructor(
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
d(this,
|
|
716
|
-
a(this,
|
|
703
|
+
var X, P, g, Y, Z, tt, b, y, At, vt, Et, kt, Ht;
|
|
704
|
+
class $e {
|
|
705
|
+
constructor(t) {
|
|
706
|
+
u(this, y);
|
|
707
|
+
u(this, X);
|
|
708
|
+
u(this, P);
|
|
709
|
+
u(this, g, /* @__PURE__ */ new Map());
|
|
710
|
+
u(this, Y, []);
|
|
711
|
+
u(this, Z, /* @__PURE__ */ new Map());
|
|
712
|
+
u(this, tt, "auto");
|
|
713
|
+
u(this, b, Ut(""));
|
|
714
|
+
d(this, X, t), d(this, P, t.createLogger("Dolla.i18n")), this.addFormat("number", (e, s, r) => f(this, y, vt).call(this, Number(s), r)), this.addFormat("datetime", (e, s, r) => f(this, y, Et).call(this, s, r)), this.addFormat("list", (e, s, r) => f(this, y, kt).call(this, s, r)), t.beforeMount(async () => {
|
|
715
|
+
a(this, g).size > 0 && await this.setLocale(a(this, tt));
|
|
717
716
|
});
|
|
718
717
|
}
|
|
719
718
|
get locale() {
|
|
720
|
-
return a(this,
|
|
719
|
+
return a(this, b);
|
|
721
720
|
}
|
|
722
721
|
get locales() {
|
|
723
|
-
return [...a(this,
|
|
724
|
-
}
|
|
725
|
-
setup(
|
|
726
|
-
if (
|
|
727
|
-
a(this,
|
|
728
|
-
}),
|
|
729
|
-
if (!
|
|
730
|
-
throw new Error(`Initial locale '${
|
|
731
|
-
d(this,
|
|
722
|
+
return [...a(this, g).keys()];
|
|
723
|
+
}
|
|
724
|
+
setup(t) {
|
|
725
|
+
if (t.translations.forEach((e) => {
|
|
726
|
+
a(this, g).set(e.locale, new ke(e, a(this, X)));
|
|
727
|
+
}), t.locale && t.locale !== "auto") {
|
|
728
|
+
if (!t.translations.some((s) => s.locale === t.locale))
|
|
729
|
+
throw new Error(`Initial locale '${t.locale}' is not registered in the locales array.`);
|
|
730
|
+
d(this, tt, t.locale);
|
|
732
731
|
}
|
|
733
|
-
a(this,
|
|
734
|
-
`${a(this,
|
|
732
|
+
a(this, P).info(
|
|
733
|
+
`${a(this, g).size} language${a(this, g).size === 1 ? "" : "s"} supported: '${[...a(this, g).keys()].join("', '")}'`
|
|
735
734
|
);
|
|
736
735
|
}
|
|
737
|
-
async setLocale(
|
|
738
|
-
var
|
|
739
|
-
let
|
|
740
|
-
if (
|
|
741
|
-
let
|
|
736
|
+
async setLocale(t) {
|
|
737
|
+
var r;
|
|
738
|
+
let e;
|
|
739
|
+
if (t === "auto") {
|
|
740
|
+
let n = [];
|
|
742
741
|
if (typeof navigator < "u") {
|
|
743
742
|
const o = navigator;
|
|
744
|
-
((
|
|
743
|
+
((r = o.languages) == null ? void 0 : r.length) > 0 ? n.push(...o.languages) : o.language ? n.push(o.language) : o.browserLanguage ? n.push(o.browserLanguage) : o.userLanguage && n.push(o.userLanguage);
|
|
745
744
|
}
|
|
746
|
-
for (const o of
|
|
747
|
-
a(this,
|
|
745
|
+
for (const o of n)
|
|
746
|
+
a(this, g).has(o) && (e = o);
|
|
748
747
|
} else
|
|
749
|
-
a(this,
|
|
750
|
-
if (
|
|
751
|
-
const
|
|
752
|
-
|
|
748
|
+
a(this, g).has(t) && (e = t);
|
|
749
|
+
if (e == null) {
|
|
750
|
+
const n = a(this, g).keys().next().value;
|
|
751
|
+
n && (e = n);
|
|
753
752
|
}
|
|
754
|
-
if (!
|
|
755
|
-
throw new Error(`Locale '${
|
|
756
|
-
const
|
|
753
|
+
if (!e || !a(this, g).has(e))
|
|
754
|
+
throw new Error(`Locale '${t}' has no translation.`);
|
|
755
|
+
const s = a(this, g).get(e);
|
|
757
756
|
try {
|
|
758
|
-
await
|
|
759
|
-
} catch (
|
|
760
|
-
|
|
757
|
+
await s.load(), d(this, Y, []), a(this, b).value = e, a(this, P).info("set language to " + e);
|
|
758
|
+
} catch (n) {
|
|
759
|
+
n instanceof Error && a(this, P).crash(n);
|
|
761
760
|
}
|
|
762
761
|
}
|
|
763
762
|
/**
|
|
@@ -769,16 +768,16 @@ class _t {
|
|
|
769
768
|
* @example
|
|
770
769
|
* const $value = t("your.key.here", { count: 5 });
|
|
771
770
|
*/
|
|
772
|
-
t(
|
|
771
|
+
t(t, e) {
|
|
773
772
|
if (this === void 0)
|
|
774
773
|
throw new Error(
|
|
775
774
|
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
776
775
|
);
|
|
777
|
-
return
|
|
778
|
-
const
|
|
779
|
-
for (const
|
|
780
|
-
r
|
|
781
|
-
return f(this,
|
|
776
|
+
return U(() => {
|
|
777
|
+
const s = {};
|
|
778
|
+
for (const r in e)
|
|
779
|
+
s[r] = E(e[r]);
|
|
780
|
+
return f(this, y, At).call(this, E(a(this, b)), t, s);
|
|
782
781
|
});
|
|
783
782
|
}
|
|
784
783
|
/**
|
|
@@ -795,8 +794,8 @@ class _t {
|
|
|
795
794
|
*
|
|
796
795
|
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
797
796
|
*/
|
|
798
|
-
addFormat(
|
|
799
|
-
a(this,
|
|
797
|
+
addFormat(t, e) {
|
|
798
|
+
a(this, Z).set(t, e);
|
|
800
799
|
}
|
|
801
800
|
/**
|
|
802
801
|
* Creates an `Intl.Collator` configured for the current locale.
|
|
@@ -804,16 +803,16 @@ class _t {
|
|
|
804
803
|
*
|
|
805
804
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
806
805
|
*/
|
|
807
|
-
collator(
|
|
808
|
-
return new Intl.Collator(a(this,
|
|
806
|
+
collator(t) {
|
|
807
|
+
return new Intl.Collator(a(this, b).value, t);
|
|
809
808
|
}
|
|
810
809
|
/**
|
|
811
810
|
* Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
812
811
|
*
|
|
813
812
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
814
813
|
*/
|
|
815
|
-
number(
|
|
816
|
-
return
|
|
814
|
+
number(t, e) {
|
|
815
|
+
return U(() => (E(a(this, b)), f(this, y, vt).call(this, E(t), e)));
|
|
817
816
|
}
|
|
818
817
|
/**
|
|
819
818
|
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -824,8 +823,8 @@ class _t {
|
|
|
824
823
|
* const date = new Date();
|
|
825
824
|
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
826
825
|
*/
|
|
827
|
-
dateTime(
|
|
828
|
-
return
|
|
826
|
+
dateTime(t, e) {
|
|
827
|
+
return U(() => (E(a(this, b)), f(this, y, Et).call(this, E(t), e)));
|
|
829
828
|
}
|
|
830
829
|
/**
|
|
831
830
|
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
@@ -836,69 +835,69 @@ class _t {
|
|
|
836
835
|
* const list = new Date();
|
|
837
836
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
838
837
|
*/
|
|
839
|
-
list(
|
|
840
|
-
return
|
|
838
|
+
list(t, e) {
|
|
839
|
+
return U(() => (E(a(this, b)), f(this, y, kt).call(this, E(t), e)));
|
|
841
840
|
}
|
|
842
841
|
}
|
|
843
|
-
|
|
842
|
+
X = new WeakMap(), P = new WeakMap(), g = new WeakMap(), Y = new WeakMap(), Z = new WeakMap(), tt = new WeakMap(), b = new WeakMap(), y = new WeakSet(), At = function(t, e, s) {
|
|
844
843
|
var l;
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
const
|
|
848
|
-
if (
|
|
849
|
-
if (
|
|
850
|
-
const
|
|
851
|
-
|
|
844
|
+
const r = f(this, y, Ht).call(this, e, s);
|
|
845
|
+
if (r) return r;
|
|
846
|
+
const n = a(this, g).get(t);
|
|
847
|
+
if (s.context != null && (e += "_" + s.context), s.count != null)
|
|
848
|
+
if (s.ordinal) {
|
|
849
|
+
const p = `${e}_ordinal_(=${s.count})`;
|
|
850
|
+
n.hasTemplate(p) ? e = p : e += "_ordinal_" + new Intl.PluralRules(t, { type: "ordinal" }).select(s.count);
|
|
852
851
|
} else {
|
|
853
|
-
const
|
|
854
|
-
|
|
852
|
+
const p = `${e}_(=${s.count})`;
|
|
853
|
+
n.hasTemplate(p) ? e = p : e += "_" + new Intl.PluralRules(t).select(s.count);
|
|
855
854
|
}
|
|
856
|
-
const o =
|
|
857
|
-
let
|
|
858
|
-
for (const
|
|
859
|
-
if (
|
|
860
|
-
|
|
861
|
-
else if (
|
|
862
|
-
let
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
for (const
|
|
866
|
-
const
|
|
867
|
-
if (
|
|
868
|
-
const
|
|
869
|
-
`Failed to load format '${
|
|
855
|
+
const o = n.getTemplate(e);
|
|
856
|
+
let c = "";
|
|
857
|
+
for (const p of o.segments)
|
|
858
|
+
if (p.type === 0)
|
|
859
|
+
c += p.text;
|
|
860
|
+
else if (p.type === 1) {
|
|
861
|
+
let v = Re(s, p.name);
|
|
862
|
+
const k = ((l = s.formatOverrides) == null ? void 0 : l[p.name]) ?? [...p.formats];
|
|
863
|
+
p.name === "count" && k.length === 0 && k.push({ name: "number", options: {} });
|
|
864
|
+
for (const h of k) {
|
|
865
|
+
const x = a(this, Z).get(h.name);
|
|
866
|
+
if (x == null) {
|
|
867
|
+
const $ = new Error(
|
|
868
|
+
`Failed to load format '${h.name}' when processing '${e}', template: ${o}`
|
|
870
869
|
);
|
|
871
|
-
throw a(this,
|
|
870
|
+
throw a(this, P).crash($), $;
|
|
872
871
|
}
|
|
873
|
-
|
|
872
|
+
v = x(t, v, h.options);
|
|
874
873
|
}
|
|
875
|
-
|
|
874
|
+
c += v;
|
|
876
875
|
}
|
|
877
|
-
return
|
|
878
|
-
},
|
|
879
|
-
return new Intl.NumberFormat(a(this,
|
|
880
|
-
},
|
|
881
|
-
return new Intl.DateTimeFormat(a(this,
|
|
882
|
-
},
|
|
883
|
-
return new Intl.ListFormat(a(this,
|
|
876
|
+
return c;
|
|
877
|
+
}, vt = function(t, e) {
|
|
878
|
+
return new Intl.NumberFormat(a(this, b).value, e).format(t);
|
|
879
|
+
}, Et = function(t, e) {
|
|
880
|
+
return new Intl.DateTimeFormat(a(this, b).value, e).format(M(t) ? new Date(t) : t);
|
|
881
|
+
}, kt = function(t, e) {
|
|
882
|
+
return new Intl.ListFormat(a(this, b).value, e).format(t);
|
|
884
883
|
}, // relativeTime(): State<string> {
|
|
885
884
|
// }
|
|
886
|
-
|
|
887
|
-
for (const
|
|
888
|
-
if (
|
|
889
|
-
return
|
|
885
|
+
Ht = function(t, e) {
|
|
886
|
+
for (const s of a(this, Y))
|
|
887
|
+
if (s[0] === t && Jt(s[1], e))
|
|
888
|
+
return s[2];
|
|
890
889
|
};
|
|
891
|
-
function
|
|
892
|
-
const
|
|
893
|
-
let
|
|
894
|
-
for (;
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
return
|
|
890
|
+
function Re(i, t) {
|
|
891
|
+
const e = String(t).split(/[\.\[\]]/).filter((r) => r.trim() !== "");
|
|
892
|
+
let s = i;
|
|
893
|
+
for (; e.length > 0; ) {
|
|
894
|
+
const r = e.shift();
|
|
895
|
+
s != null ? s = s[r] : s = void 0;
|
|
896
|
+
}
|
|
897
|
+
return s;
|
|
899
898
|
}
|
|
900
|
-
function
|
|
901
|
-
return
|
|
899
|
+
function _e(i) {
|
|
900
|
+
return Mt`
|
|
902
901
|
<div
|
|
903
902
|
style=${{
|
|
904
903
|
backgroundColor: "#880000",
|
|
@@ -912,7 +911,7 @@ function Mt(i) {
|
|
|
912
911
|
<h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
|
|
913
912
|
<p style=${{ marginBottom: "0.25rem" }}>
|
|
914
913
|
<span style=${{ fontFamily: "monospace" }}>${i.loggerName}</span>
|
|
915
|
-
${
|
|
914
|
+
${Xt(i.uid, Mt`<span style=${{ fontFamily: "monospace", opacity: 0.5 }}> [uid: ${i.uid}]</span>`)}
|
|
916
915
|
${" "}says:
|
|
917
916
|
</p>
|
|
918
917
|
<blockquote
|
|
@@ -944,40 +943,38 @@ function Mt(i) {
|
|
|
944
943
|
</div>
|
|
945
944
|
`;
|
|
946
945
|
}
|
|
947
|
-
var L,
|
|
948
|
-
class
|
|
946
|
+
var L, et, F, I, st, z, nt, rt, at, it, O, ot, lt, dt;
|
|
947
|
+
class Se {
|
|
949
948
|
constructor() {
|
|
950
949
|
// TODO: Take these off the global Dolla object.
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
950
|
+
w(this, "http");
|
|
951
|
+
w(this, "i18n");
|
|
952
|
+
u(this, L, !1);
|
|
953
|
+
u(this, et, "production");
|
|
954
|
+
u(this, F);
|
|
955
|
+
u(this, I);
|
|
956
|
+
u(this, st, _e);
|
|
957
|
+
u(this, z);
|
|
958
|
+
u(this, nt, []);
|
|
959
|
+
u(this, rt, []);
|
|
960
|
+
u(this, at, []);
|
|
961
|
+
u(this, it, []);
|
|
962
|
+
u(this, O, {
|
|
964
963
|
root: this,
|
|
965
|
-
data: {},
|
|
966
|
-
emitter: new tt(),
|
|
967
964
|
stores: /* @__PURE__ */ new Map(),
|
|
968
965
|
viewName: "Dolla"
|
|
969
966
|
});
|
|
970
|
-
|
|
967
|
+
u(this, ot, {
|
|
971
968
|
info: "development",
|
|
972
969
|
log: "development",
|
|
973
970
|
warn: "development",
|
|
974
971
|
error: !0
|
|
975
972
|
});
|
|
976
|
-
|
|
973
|
+
u(this, lt, xt("*,-Dolla.*"));
|
|
977
974
|
// Registration functions for modules.
|
|
978
975
|
// All modules will be registered before mount.
|
|
979
|
-
|
|
980
|
-
this.http = new
|
|
976
|
+
u(this, dt, []);
|
|
977
|
+
this.http = new ge(), this.i18n = new $e(this);
|
|
981
978
|
}
|
|
982
979
|
/**
|
|
983
980
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
@@ -990,235 +987,197 @@ class xt {
|
|
|
990
987
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
991
988
|
*/
|
|
992
989
|
getEnv() {
|
|
993
|
-
return a(this,
|
|
990
|
+
return a(this, et);
|
|
994
991
|
}
|
|
995
992
|
/**
|
|
996
993
|
* Sets the environment that this app is running in.
|
|
997
994
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
998
995
|
*/
|
|
999
|
-
setEnv(
|
|
1000
|
-
d(this,
|
|
996
|
+
setEnv(t) {
|
|
997
|
+
d(this, et, t);
|
|
1001
998
|
}
|
|
1002
999
|
/**
|
|
1003
1000
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1004
1001
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1005
1002
|
*/
|
|
1006
|
-
setCrashView(
|
|
1007
|
-
d(this,
|
|
1003
|
+
setCrashView(t) {
|
|
1004
|
+
d(this, st, t);
|
|
1008
1005
|
}
|
|
1009
1006
|
/**
|
|
1010
1007
|
* Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
|
|
1011
1008
|
*/
|
|
1012
1009
|
getRootElement() {
|
|
1013
|
-
return a(this,
|
|
1010
|
+
return a(this, F);
|
|
1014
1011
|
}
|
|
1015
1012
|
/**
|
|
1016
1013
|
* Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
|
|
1017
1014
|
*/
|
|
1018
1015
|
getRootView() {
|
|
1019
|
-
return a(this,
|
|
1016
|
+
return a(this, I);
|
|
1020
1017
|
}
|
|
1021
|
-
provide(
|
|
1022
|
-
const
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
1018
|
+
provide(t, e) {
|
|
1019
|
+
const s = new Yt(t, e);
|
|
1020
|
+
if (s.attach(a(this, O)))
|
|
1021
|
+
return s.value;
|
|
1025
1022
|
{
|
|
1026
|
-
let
|
|
1027
|
-
return console.warn(`An instance of ${
|
|
1023
|
+
let n = t.name ? `'${t.name}'` : "this store";
|
|
1024
|
+
return console.warn(`An instance of ${n} was already attached to this context.`), this.get(t);
|
|
1028
1025
|
}
|
|
1029
1026
|
}
|
|
1030
1027
|
/**
|
|
1031
1028
|
* Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
1032
1029
|
*/
|
|
1033
|
-
get(
|
|
1034
|
-
if (
|
|
1035
|
-
const
|
|
1036
|
-
if (
|
|
1037
|
-
throw new
|
|
1038
|
-
return
|
|
1030
|
+
get(t) {
|
|
1031
|
+
if (B(t)) {
|
|
1032
|
+
const e = a(this, O).stores.get(t);
|
|
1033
|
+
if (e == null)
|
|
1034
|
+
throw new Tt("Store not found on this context.");
|
|
1035
|
+
return e.value;
|
|
1039
1036
|
} else
|
|
1040
|
-
throw new
|
|
1037
|
+
throw new Tt("Invalid store.");
|
|
1041
1038
|
}
|
|
1042
|
-
async mount(
|
|
1039
|
+
async mount(t, e) {
|
|
1043
1040
|
if (a(this, L))
|
|
1044
1041
|
throw new Error("Dolla is already mounted.");
|
|
1045
|
-
if (
|
|
1046
|
-
const
|
|
1047
|
-
|
|
1042
|
+
if (M(t)) {
|
|
1043
|
+
const n = document.querySelector(t);
|
|
1044
|
+
Nt(HTMLElement, n, `Selector '${t}' did not match any element.`), d(this, F, n);
|
|
1048
1045
|
} else
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
const
|
|
1052
|
-
d(this,
|
|
1053
|
-
for (const
|
|
1054
|
-
|
|
1055
|
-
for (const
|
|
1056
|
-
|
|
1046
|
+
Nt(HTMLElement, t, "Expected an HTML element or a selector string. Got type: %t, value: %v"), d(this, F, t);
|
|
1047
|
+
pt(e) && d(this, z, e);
|
|
1048
|
+
const s = pt(e) ? jt : e, r = Zt(s);
|
|
1049
|
+
d(this, I, this.constructView(r.type, r.props)), await Promise.all(a(this, dt).map((n) => n())), pt(e) && await le(e, this), await Promise.all(a(this, nt).map((n) => n())), a(this, I).mount(a(this, F)), d(this, L, !0);
|
|
1050
|
+
for (const n of a(this, O).stores.values())
|
|
1051
|
+
n.handleMount();
|
|
1052
|
+
for (const n of a(this, rt))
|
|
1053
|
+
n();
|
|
1057
1054
|
}
|
|
1058
1055
|
async unmount() {
|
|
1059
|
-
var
|
|
1056
|
+
var t;
|
|
1060
1057
|
if (a(this, L)) {
|
|
1061
|
-
await Promise.all(a(this,
|
|
1062
|
-
for (const
|
|
1063
|
-
|
|
1058
|
+
await Promise.all(a(this, at).map((e) => e())), (t = a(this, I)) == null || t.unmount(!1), a(this, z) && await ce(a(this, z)), d(this, L, !1);
|
|
1059
|
+
for (const e of a(this, it))
|
|
1060
|
+
e();
|
|
1064
1061
|
}
|
|
1065
1062
|
}
|
|
1066
1063
|
/**
|
|
1067
1064
|
* Registers a `callback` to run after `Dolla.mount` is called, before the app is mounted. If `callback` returns a Promise,
|
|
1068
1065
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1069
1066
|
*/
|
|
1070
|
-
beforeMount(
|
|
1071
|
-
a(this,
|
|
1067
|
+
beforeMount(t) {
|
|
1068
|
+
a(this, nt).push(t);
|
|
1072
1069
|
}
|
|
1073
1070
|
/**
|
|
1074
1071
|
* Registers a `callback` to run after the app is mounted.
|
|
1075
1072
|
*/
|
|
1076
|
-
onMount(
|
|
1077
|
-
a(this,
|
|
1073
|
+
onMount(t) {
|
|
1074
|
+
a(this, rt).push(t);
|
|
1078
1075
|
}
|
|
1079
1076
|
/**
|
|
1080
1077
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1081
1078
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1082
1079
|
*/
|
|
1083
|
-
beforeUnmount(
|
|
1084
|
-
a(this,
|
|
1080
|
+
beforeUnmount(t) {
|
|
1081
|
+
a(this, at).push(t);
|
|
1085
1082
|
}
|
|
1086
1083
|
/**
|
|
1087
1084
|
* Registers a `callback` to run after the app is unmounted.
|
|
1088
1085
|
*/
|
|
1089
|
-
onUnmount(
|
|
1090
|
-
a(this,
|
|
1086
|
+
onUnmount(t) {
|
|
1087
|
+
a(this, it).push(t);
|
|
1091
1088
|
}
|
|
1092
1089
|
/**
|
|
1093
1090
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
1094
1091
|
*/
|
|
1095
|
-
setLoggles(
|
|
1096
|
-
for (const
|
|
1097
|
-
const
|
|
1098
|
-
|
|
1092
|
+
setLoggles(t) {
|
|
1093
|
+
for (const e in t) {
|
|
1094
|
+
const s = t[e];
|
|
1095
|
+
s && (a(this, ot)[e] = s);
|
|
1099
1096
|
}
|
|
1100
1097
|
}
|
|
1101
|
-
setLogFilter(
|
|
1102
|
-
d(this,
|
|
1103
|
-
}
|
|
1104
|
-
createLogger(
|
|
1105
|
-
const
|
|
1098
|
+
setLogFilter(t) {
|
|
1099
|
+
d(this, lt, xt(t));
|
|
1100
|
+
}
|
|
1101
|
+
createLogger(t, e) {
|
|
1102
|
+
const s = (e == null ? void 0 : e.console) ?? Me(), r = this, n = a(this, ot), o = (c) => {
|
|
1103
|
+
if (n[c] === !1 || M(n[c]) && n[c] !== r.getEnv() || !a(this, lt).call(this, t))
|
|
1104
|
+
return ne;
|
|
1105
|
+
{
|
|
1106
|
+
let l = `%c${t}`;
|
|
1107
|
+
return e != null && e.uid ? l += ` %c[uid: %c${e.uid}%c]` : l += "%c%c%c", s[c].bind(
|
|
1108
|
+
s,
|
|
1109
|
+
l,
|
|
1110
|
+
`color:${re(l)};font-weight:bold`,
|
|
1111
|
+
"color:#777",
|
|
1112
|
+
"color:#aaa",
|
|
1113
|
+
"color:#777"
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1106
1117
|
return {
|
|
1107
|
-
setName(
|
|
1108
|
-
return
|
|
1118
|
+
setName(c) {
|
|
1119
|
+
return t = c, this;
|
|
1109
1120
|
},
|
|
1110
1121
|
get info() {
|
|
1111
|
-
|
|
1112
|
-
if (a(n, g).info === !1 || k(a(n, g).info) && a(n, g).info !== n.getEnv() || !a(s = n, j).call(s, e))
|
|
1113
|
-
return ce;
|
|
1114
|
-
{
|
|
1115
|
-
let o = `%c${e}`;
|
|
1116
|
-
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.info.bind(
|
|
1117
|
-
r,
|
|
1118
|
-
o,
|
|
1119
|
-
`color:${he(o)};font-weight:bold`,
|
|
1120
|
-
"color:#777",
|
|
1121
|
-
"color:#aaa",
|
|
1122
|
-
"color:#777"
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1122
|
+
return o("info");
|
|
1125
1123
|
},
|
|
1126
1124
|
get log() {
|
|
1127
|
-
|
|
1128
|
-
if (a(n, g).log === !1 || k(a(n, g).log) && a(n, g).log !== n.getEnv() || !a(s = n, j).call(s, e))
|
|
1129
|
-
return ce;
|
|
1130
|
-
{
|
|
1131
|
-
let o = `%c${e}`;
|
|
1132
|
-
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.log.bind(
|
|
1133
|
-
r,
|
|
1134
|
-
o,
|
|
1135
|
-
`color:${he(o)};font-weight:bold`,
|
|
1136
|
-
"color:#777",
|
|
1137
|
-
"color:#aaa",
|
|
1138
|
-
"color:#777"
|
|
1139
|
-
);
|
|
1140
|
-
}
|
|
1125
|
+
return o("log");
|
|
1141
1126
|
},
|
|
1142
1127
|
get warn() {
|
|
1143
|
-
|
|
1144
|
-
if (a(n, g).warn === !1 || k(a(n, g).warn) && a(n, g).warn !== n.getEnv() || !a(s = n, j).call(s, e))
|
|
1145
|
-
return ce;
|
|
1146
|
-
{
|
|
1147
|
-
let o = `%c${e}`;
|
|
1148
|
-
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.warn.bind(
|
|
1149
|
-
r,
|
|
1150
|
-
o,
|
|
1151
|
-
`color:${he(o)};font-weight:bold`,
|
|
1152
|
-
"color:#777",
|
|
1153
|
-
"color:#aaa",
|
|
1154
|
-
"color:#777"
|
|
1155
|
-
);
|
|
1156
|
-
}
|
|
1128
|
+
return o("warn");
|
|
1157
1129
|
},
|
|
1158
1130
|
get error() {
|
|
1159
|
-
|
|
1160
|
-
if (a(n, g).error === !1 || k(a(n, g).error) && a(n, g).error !== n.getEnv() || !a(s = n, j).call(s, e))
|
|
1161
|
-
return ce;
|
|
1162
|
-
{
|
|
1163
|
-
let o = `%c${e}`;
|
|
1164
|
-
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.error.bind(
|
|
1165
|
-
r,
|
|
1166
|
-
o,
|
|
1167
|
-
`color:${he(o)};font-weight:bold`,
|
|
1168
|
-
"color:#777",
|
|
1169
|
-
"color:#aaa",
|
|
1170
|
-
"color:#777"
|
|
1171
|
-
);
|
|
1172
|
-
}
|
|
1131
|
+
return o("error");
|
|
1173
1132
|
},
|
|
1174
|
-
crash(
|
|
1175
|
-
|
|
1176
|
-
error:
|
|
1177
|
-
loggerName:
|
|
1178
|
-
uid:
|
|
1179
|
-
}).mount(a(
|
|
1133
|
+
crash(c) {
|
|
1134
|
+
r.isMounted && (r.unmount(), r.constructView(a(r, st), {
|
|
1135
|
+
error: c,
|
|
1136
|
+
loggerName: t,
|
|
1137
|
+
uid: e == null ? void 0 : e.uid
|
|
1138
|
+
}).mount(a(r, F)));
|
|
1180
1139
|
}
|
|
1181
1140
|
};
|
|
1182
1141
|
}
|
|
1183
1142
|
/**
|
|
1184
1143
|
*
|
|
1185
1144
|
*/
|
|
1186
|
-
constructView(
|
|
1187
|
-
return new
|
|
1145
|
+
constructView(t, e, s = []) {
|
|
1146
|
+
return new te(a(this, O), t, e, s);
|
|
1188
1147
|
}
|
|
1189
1148
|
/**
|
|
1190
1149
|
*
|
|
1191
1150
|
*/
|
|
1192
|
-
constructMarkup(
|
|
1193
|
-
return
|
|
1151
|
+
constructMarkup(t) {
|
|
1152
|
+
return ee(se(a(this, O), t));
|
|
1194
1153
|
}
|
|
1195
1154
|
}
|
|
1196
|
-
L = new WeakMap(),
|
|
1197
|
-
function
|
|
1155
|
+
L = new WeakMap(), et = new WeakMap(), F = new WeakMap(), I = new WeakMap(), st = new WeakMap(), z = new WeakMap(), nt = new WeakMap(), rt = new WeakMap(), at = new WeakMap(), it = new WeakMap(), O = new WeakMap(), ot = new WeakMap(), lt = new WeakMap(), dt = new WeakMap();
|
|
1156
|
+
function Me() {
|
|
1198
1157
|
if (typeof window < "u" && window.console)
|
|
1199
1158
|
return window.console;
|
|
1200
1159
|
if (typeof global < "u" && global.console)
|
|
1201
1160
|
return global.console;
|
|
1202
1161
|
}
|
|
1203
|
-
const
|
|
1162
|
+
const Pt = new Se(), Le = Pt.i18n.t.bind(Pt.i18n);
|
|
1204
1163
|
export {
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1164
|
+
Ut as atom,
|
|
1165
|
+
U as compose,
|
|
1166
|
+
Xt as cond,
|
|
1167
|
+
Zt as createMarkup,
|
|
1168
|
+
Pe as createRouter,
|
|
1169
|
+
Jt as deepEqual,
|
|
1170
|
+
Pt as default,
|
|
1171
|
+
Ue as effect,
|
|
1213
1172
|
E as get,
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1173
|
+
Mt as html,
|
|
1174
|
+
je as list,
|
|
1175
|
+
Ce as peek,
|
|
1176
|
+
De as portal,
|
|
1177
|
+
Ne as ref,
|
|
1178
|
+
Ie as set,
|
|
1179
|
+
_t as shallowEqual,
|
|
1180
|
+
Ve as strictEqual,
|
|
1181
|
+
Le as t
|
|
1223
1182
|
};
|
|
1224
1183
|
//# sourceMappingURL=index.js.map
|