@manyducks.co/dolla 2.0.0-alpha.21 → 2.0.0-alpha.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{modules/render.d.ts → core/batch.d.ts} +4 -1
- package/dist/{modules → core}/dolla.d.ts +25 -9
- package/dist/{markup.d.ts → core/markup.d.ts} +6 -6
- package/dist/{nodes → core/nodes}/cond.d.ts +4 -2
- package/dist/{nodes → core/nodes}/html.d.ts +2 -0
- package/dist/{nodes → core/nodes}/observer.d.ts +4 -1
- package/dist/core/nodes/outlet.d.ts +18 -0
- package/dist/{nodes → core/nodes}/portal.d.ts +4 -2
- package/dist/{nodes → core/nodes}/repeat.d.ts +5 -3
- package/dist/{nodes → core/nodes}/text.d.ts +2 -0
- package/dist/{view.d.ts → core/nodes/view.d.ts} +8 -6
- package/dist/{state.d.ts → core/state.d.ts} +3 -4
- package/dist/core/symbols.d.ts +5 -0
- package/dist/index.d.ts +9 -8
- package/dist/index.js +670 -1038
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +2 -2
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +3 -3
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/modules/http.d.ts +2 -0
- package/dist/modules/i18n.d.ts +2 -2
- package/dist/modules/router.d.ts +27 -48
- package/dist/{passthrough-6Lrg96Id.js → passthrough-C9975ULD.js} +636 -576
- package/dist/passthrough-C9975ULD.js.map +1 -0
- package/dist/typeChecking.d.ts +2 -2
- package/dist/types.d.ts +2 -2
- package/dist/utils.d.ts +14 -1
- package/dist/views/default-crash-view.d.ts +1 -1
- package/dist/views/passthrough.d.ts +2 -2
- package/docs/http.md +16 -0
- package/docs/router.md +19 -0
- package/index.d.ts +2 -2
- package/notes/TODO.md +6 -0
- package/notes/scratch.md +2 -2
- package/package.json +3 -6
- package/vite.config.js +0 -10
- package/dist/nodes/outlet.d.ts +0 -22
- package/dist/passthrough-6Lrg96Id.js.map +0 -1
- /package/dist/{routing.d.ts → modules/router.utils.d.ts} +0 -0
- /package/dist/{routing.test.d.ts → modules/router.utils.test.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var nt = Object.defineProperty;
|
|
2
|
+
var Ae = (o) => {
|
|
3
|
+
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
5
|
+
var at = (o, e, t) => e in o ? nt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
|
|
6
|
+
var p = (o, e, t) => at(o, typeof e != "symbol" ? e + "" : e, t), qe = (o, e, t) => e.has(o) || Ae("Cannot " + t);
|
|
7
|
+
var a = (o, e, t) => (qe(o, e, "read from private field"), t ? t.call(o) : e.get(o)), l = (o, e, t) => e.has(o) ? Ae("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), g = (o, e, t, r) => (qe(o, e, "write to private field"), r ? r.call(o, t) : e.set(o, t), t), d = (o, e, t) => (qe(o, e, "access private method"), t);
|
|
8
|
+
var Y = (o, e, t, r) => ({
|
|
9
9
|
set _(n) {
|
|
10
|
-
|
|
10
|
+
g(o, e, n, t);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
|
-
return
|
|
13
|
+
return a(o, e, r);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import { h as
|
|
17
|
-
import {
|
|
18
|
-
function
|
|
19
|
-
return
|
|
16
|
+
import { h as Ie, c as it, i as ke, a as Ve, d as F, b as k, e as ot, f as te, t as We, g as Qe, j as lt, s as _e, k as Ge, P as Je, l as Be, m as ze, n as ct, o as ht, p as ut, v as ft, q as dt, r as mt, u as He, w as gt, x as be, y as $e, V as pt, z as wt, A as yt } from "./passthrough-C9975ULD.js";
|
|
17
|
+
import { B as Ht, D as Kt, E as Qt, C as Jt } from "./passthrough-C9975ULD.js";
|
|
18
|
+
function bt(o) {
|
|
19
|
+
return Ie`
|
|
20
20
|
<div
|
|
21
21
|
style=${{
|
|
22
22
|
backgroundColor: "#880000",
|
|
@@ -29,8 +29,8 @@ function Gt(i) {
|
|
|
29
29
|
>
|
|
30
30
|
<h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
|
|
31
31
|
<p style=${{ marginBottom: "0.25rem" }}>
|
|
32
|
-
<span style=${{ fontFamily: "monospace" }}>${
|
|
33
|
-
${
|
|
32
|
+
<span style=${{ fontFamily: "monospace" }}>${o.loggerName}</span>
|
|
33
|
+
${it(o.uid, Ie`<span style=${{ fontFamily: "monospace", opacity: 0.5 }}> [uid: ${o.uid}]</span>`)}
|
|
34
34
|
${" "}says:
|
|
35
35
|
</p>
|
|
36
36
|
<blockquote
|
|
@@ -53,21 +53,92 @@ function Gt(i) {
|
|
|
53
53
|
fontWeight: "bold"
|
|
54
54
|
}}
|
|
55
55
|
>
|
|
56
|
-
${
|
|
56
|
+
${o.error.name}
|
|
57
57
|
</span>
|
|
58
|
-
${
|
|
58
|
+
${o.error.message}
|
|
59
59
|
</blockquote>
|
|
60
60
|
|
|
61
61
|
<p>Please see the browser console for details.</p>
|
|
62
62
|
</div>
|
|
63
63
|
`;
|
|
64
64
|
}
|
|
65
|
-
var
|
|
66
|
-
class
|
|
67
|
-
constructor() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
65
|
+
var re, K, N, V, A, Q, Re, M, se, q, Ne, ve;
|
|
66
|
+
class $t {
|
|
67
|
+
constructor(e) {
|
|
68
|
+
l(this, q);
|
|
69
|
+
l(this, re);
|
|
70
|
+
l(this, K);
|
|
71
|
+
// Keys ensure only the most recent callback queued with a certain key
|
|
72
|
+
// will be called, keeping DOM operations to a minimum.
|
|
73
|
+
l(this, N, /* @__PURE__ */ new Map());
|
|
74
|
+
// All unkeyed writes are run on every batch.
|
|
75
|
+
l(this, V, []);
|
|
76
|
+
// All read callbacks are run before updates on every batch.
|
|
77
|
+
l(this, A, []);
|
|
78
|
+
l(this, Q, !1);
|
|
79
|
+
// When true, batches that would exceed 16ms will be split and deferred to a rAF.
|
|
80
|
+
// This may not be desirable, because while it does prevent hitching it sometimes leaves
|
|
81
|
+
// the state partially rendered for a brief second and certain elements can be seen to update after the fact.
|
|
82
|
+
// But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
|
|
83
|
+
l(this, Re, !0);
|
|
84
|
+
l(this, M, 0);
|
|
85
|
+
l(this, se, new Intl.NumberFormat("en-US", { maximumFractionDigits: 2, minimumFractionDigits: 0 }));
|
|
86
|
+
g(this, re, e), g(this, K, e.createLogger("dolla/render"));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Queues a callback that runs before the next batch of writes.
|
|
90
|
+
*/
|
|
91
|
+
read(e) {
|
|
92
|
+
a(this, A).push(e), d(this, q, Ne).call(this);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Queues a callback to run in the next render batch.
|
|
96
|
+
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
97
|
+
*/
|
|
98
|
+
write(e, t) {
|
|
99
|
+
t ? a(this, N).set(t, e) : a(this, V).push(e), d(this, q, Ne).call(this);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
re = new WeakMap(), K = new WeakMap(), N = new WeakMap(), V = new WeakMap(), A = new WeakMap(), Q = new WeakMap(), Re = new WeakMap(), M = new WeakMap(), se = new WeakMap(), q = new WeakSet(), Ne = function() {
|
|
103
|
+
if (!a(this, Q)) {
|
|
104
|
+
g(this, Q, !0);
|
|
105
|
+
const e = a(this, re).getEnv() === "development";
|
|
106
|
+
queueMicrotask(() => {
|
|
107
|
+
d(this, q, ve).call(this, e);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, ve = function(e = !1) {
|
|
111
|
+
const t = performance.now();
|
|
112
|
+
let r = 0;
|
|
113
|
+
const n = a(this, A).length + a(this, N).size + a(this, V).length;
|
|
114
|
+
let s = 0;
|
|
115
|
+
const i = () => (s++, r = performance.now() - t, a(this, Re) && r > 12 && s < n ? (Y(this, M)._++, e && a(this, K).warn(
|
|
116
|
+
`⚠️ Deferring batch to next frame. Performed ${s} of ${n} batched operation${s === 1 ? "" : "s"} in ${a(this, se).format(r)}ms (deferral ${a(this, M)}).`
|
|
117
|
+
), requestAnimationFrame(() => {
|
|
118
|
+
d(this, q, ve).call(this, e);
|
|
119
|
+
}), !0) : !1), f = [...a(this, N).entries()];
|
|
120
|
+
let c, u;
|
|
121
|
+
for (; u = a(this, A).shift(); )
|
|
122
|
+
if (u(), i()) return;
|
|
123
|
+
for ([c, u] of f)
|
|
124
|
+
if (u(), a(this, N).delete(c), i()) return;
|
|
125
|
+
for (; u = a(this, V).shift(); )
|
|
126
|
+
if (u(), i()) return;
|
|
127
|
+
e && a(this, K)[r > 16 ? "warn" : "info"](
|
|
128
|
+
`${r > 16 ? "⚠️ (>=16ms) " : ""}Executed ${s} operation${s === 1 ? "" : "s"} in ${a(this, se).format(r)}ms${a(this, M) > 0 ? ` (after ${a(this, M)} deferral${a(this, M) === 1 ? "" : "s"})` : ""}.`
|
|
129
|
+
), g(this, M, 0), a(this, A).length || a(this, N).size || a(this, V).length ? queueMicrotask(() => {
|
|
130
|
+
d(this, q, ve).call(this, e);
|
|
131
|
+
}) : g(this, Q, !1);
|
|
132
|
+
};
|
|
133
|
+
var I, Se, Le, ne, S, L;
|
|
134
|
+
class vt {
|
|
135
|
+
constructor(e) {
|
|
136
|
+
l(this, S);
|
|
137
|
+
l(this, I, []);
|
|
138
|
+
l(this, Se, Et());
|
|
139
|
+
l(this, Le);
|
|
140
|
+
l(this, ne);
|
|
141
|
+
g(this, Le, e), g(this, ne, e.createLogger("dolla/http"));
|
|
71
142
|
}
|
|
72
143
|
/**
|
|
73
144
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -76,323 +147,295 @@ class zt {
|
|
|
76
147
|
* @param middleware - A middleware function that will intercept requests.
|
|
77
148
|
*/
|
|
78
149
|
use(e) {
|
|
79
|
-
return
|
|
80
|
-
|
|
150
|
+
return a(this, I).push(e), () => {
|
|
151
|
+
a(this, I).splice(a(this, I).indexOf(e), 1);
|
|
81
152
|
};
|
|
82
153
|
}
|
|
83
154
|
async get(e, t) {
|
|
84
|
-
return
|
|
155
|
+
return d(this, S, L).call(this, "get", e, t);
|
|
85
156
|
}
|
|
86
157
|
async put(e, t) {
|
|
87
|
-
return
|
|
158
|
+
return d(this, S, L).call(this, "put", e, t);
|
|
88
159
|
}
|
|
89
160
|
async patch(e, t) {
|
|
90
|
-
return
|
|
161
|
+
return d(this, S, L).call(this, "patch", e, t);
|
|
91
162
|
}
|
|
92
163
|
async post(e, t) {
|
|
93
|
-
return
|
|
164
|
+
return d(this, S, L).call(this, "post", e, t);
|
|
94
165
|
}
|
|
95
166
|
async delete(e, t) {
|
|
96
|
-
return
|
|
167
|
+
return d(this, S, L).call(this, "delete", e, t);
|
|
97
168
|
}
|
|
98
169
|
async head(e, t) {
|
|
99
|
-
return
|
|
170
|
+
return d(this, S, L).call(this, "head", e, t);
|
|
100
171
|
}
|
|
101
172
|
async options(e, t) {
|
|
102
|
-
return
|
|
173
|
+
return d(this, S, L).call(this, "options", e, t);
|
|
103
174
|
}
|
|
104
175
|
async trace(e, t) {
|
|
105
|
-
return
|
|
176
|
+
return d(this, S, L).call(this, "trace", e, t);
|
|
106
177
|
}
|
|
107
178
|
}
|
|
108
|
-
|
|
109
|
-
return
|
|
179
|
+
I = new WeakMap(), Se = new WeakMap(), Le = new WeakMap(), ne = new WeakMap(), S = new WeakSet(), L = async function(e, t, r) {
|
|
180
|
+
return Rt({
|
|
110
181
|
...r,
|
|
111
182
|
method: e,
|
|
112
183
|
uri: t,
|
|
113
|
-
middleware:
|
|
114
|
-
fetch:
|
|
184
|
+
middleware: a(this, I),
|
|
185
|
+
fetch: a(this, Se),
|
|
186
|
+
logger: a(this, ne)
|
|
115
187
|
});
|
|
116
188
|
};
|
|
117
|
-
function
|
|
189
|
+
function Et() {
|
|
118
190
|
if (typeof window < "u" && window.fetch)
|
|
119
191
|
return window.fetch.bind(window);
|
|
120
192
|
if (typeof global < "u" && global.fetch)
|
|
121
193
|
return global.fetch.bind(global);
|
|
122
194
|
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
123
195
|
}
|
|
124
|
-
class
|
|
196
|
+
class kt extends Error {
|
|
125
197
|
constructor(t) {
|
|
126
|
-
const { status: r, statusText: n, method:
|
|
127
|
-
super(
|
|
128
|
-
|
|
198
|
+
const { status: r, statusText: n, method: s, uri: i } = t, f = `${r} ${n}: Request failed (${s.toUpperCase()} ${i})`;
|
|
199
|
+
super(f);
|
|
200
|
+
p(this, "response");
|
|
129
201
|
this.response = t;
|
|
130
202
|
}
|
|
131
203
|
}
|
|
132
|
-
async function
|
|
133
|
-
const { headers: e, query: t, fetch: r, middleware: n } =
|
|
134
|
-
method:
|
|
135
|
-
uri:
|
|
204
|
+
async function Rt(o) {
|
|
205
|
+
const { headers: e, query: t, fetch: r, middleware: n, logger: s } = o, i = {
|
|
206
|
+
method: o.method,
|
|
207
|
+
uri: o.uri,
|
|
136
208
|
get sameOrigin() {
|
|
137
|
-
return !
|
|
209
|
+
return !i.uri.startsWith("http");
|
|
138
210
|
},
|
|
139
211
|
query: new URLSearchParams(),
|
|
140
212
|
headers: new Headers(),
|
|
141
|
-
body:
|
|
213
|
+
body: o.body
|
|
142
214
|
};
|
|
143
215
|
if (e)
|
|
144
216
|
if (e instanceof Map || e instanceof Headers)
|
|
145
|
-
e.forEach((
|
|
146
|
-
|
|
217
|
+
e.forEach((u, m) => {
|
|
218
|
+
i.headers.set(m, u);
|
|
147
219
|
});
|
|
148
220
|
else if (e != null && typeof e == "object" && !Array.isArray(e))
|
|
149
|
-
for (const
|
|
150
|
-
const
|
|
151
|
-
|
|
221
|
+
for (const u in e) {
|
|
222
|
+
const m = e[u];
|
|
223
|
+
m instanceof Date ? i.headers.set(u, m.toISOString()) : m != null && i.headers.set(u, String(m));
|
|
152
224
|
}
|
|
153
225
|
else
|
|
154
226
|
throw new TypeError(`Unknown headers type. Got: ${e}`);
|
|
155
227
|
if (t)
|
|
156
228
|
if (t instanceof Map || t instanceof URLSearchParams)
|
|
157
|
-
t.forEach((
|
|
158
|
-
|
|
229
|
+
t.forEach((u, m) => {
|
|
230
|
+
i.query.set(m, u);
|
|
159
231
|
});
|
|
160
232
|
else if (t != null && typeof t == "object" && !Array.isArray(t))
|
|
161
|
-
for (const
|
|
162
|
-
const
|
|
163
|
-
|
|
233
|
+
for (const u in t) {
|
|
234
|
+
const m = t[u];
|
|
235
|
+
m instanceof Date ? i.query.set(u, m.toISOString()) : m != null && i.query.set(u, String(m));
|
|
164
236
|
}
|
|
165
237
|
else
|
|
166
238
|
throw new TypeError(`Unknown query params type. Got: ${t}`);
|
|
167
|
-
let
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
let
|
|
171
|
-
!
|
|
172
|
-
const
|
|
173
|
-
method:
|
|
174
|
-
headers:
|
|
175
|
-
body:
|
|
176
|
-
}),
|
|
177
|
-
let
|
|
178
|
-
y != null && y.includes("application/json") ?
|
|
179
|
-
method:
|
|
180
|
-
uri:
|
|
181
|
-
status:
|
|
182
|
-
statusText:
|
|
183
|
-
headers:
|
|
184
|
-
body:
|
|
239
|
+
let f;
|
|
240
|
+
const c = async () => {
|
|
241
|
+
const u = i.query.toString(), m = u.length > 0 ? i.uri + "?" + u : i.uri;
|
|
242
|
+
let b;
|
|
243
|
+
!i.headers.has("content-type") && ke(i.body) ? (i.headers.set("content-type", "application/json"), b = JSON.stringify(i.body)) : b = i.body;
|
|
244
|
+
const h = await r(m, {
|
|
245
|
+
method: i.method,
|
|
246
|
+
headers: i.headers,
|
|
247
|
+
body: b
|
|
248
|
+
}), R = Object.fromEntries(h.headers.entries()), y = R["content-type"];
|
|
249
|
+
let ye;
|
|
250
|
+
y != null && y.includes("application/json") ? ye = await h.json() : y != null && y.includes("application/x-www-form-urlencoded") ? ye = await h.formData() : ye = await h.text(), f = {
|
|
251
|
+
method: i.method,
|
|
252
|
+
uri: i.uri,
|
|
253
|
+
status: h.status,
|
|
254
|
+
statusText: h.statusText,
|
|
255
|
+
headers: R,
|
|
256
|
+
body: ye
|
|
185
257
|
};
|
|
186
258
|
};
|
|
187
259
|
if (n.length > 0) {
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
return async () =>
|
|
260
|
+
const u = (m = 0) => {
|
|
261
|
+
const b = n[m], h = n[m + 1] ? u(m + 1) : c;
|
|
262
|
+
return async () => b(i, async () => (await h(), f));
|
|
191
263
|
};
|
|
192
|
-
await
|
|
264
|
+
await u()();
|
|
193
265
|
} else
|
|
194
|
-
await
|
|
195
|
-
if (
|
|
196
|
-
throw new
|
|
197
|
-
return
|
|
198
|
-
}
|
|
199
|
-
var tt, bt;
|
|
200
|
-
function Yt() {
|
|
201
|
-
return bt || (bt = 1, tt = function i(e, t) {
|
|
202
|
-
if (e === t) return !0;
|
|
203
|
-
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
204
|
-
if (e.constructor !== t.constructor) return !1;
|
|
205
|
-
var r, n, a;
|
|
206
|
-
if (Array.isArray(e)) {
|
|
207
|
-
if (r = e.length, r != t.length) return !1;
|
|
208
|
-
for (n = r; n-- !== 0; )
|
|
209
|
-
if (!i(e[n], t[n])) return !1;
|
|
210
|
-
return !0;
|
|
211
|
-
}
|
|
212
|
-
if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
|
|
213
|
-
if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
|
|
214
|
-
if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
|
|
215
|
-
if (a = Object.keys(e), r = a.length, r !== Object.keys(t).length) return !1;
|
|
216
|
-
for (n = r; n-- !== 0; )
|
|
217
|
-
if (!Object.prototype.hasOwnProperty.call(t, a[n])) return !1;
|
|
218
|
-
for (n = r; n-- !== 0; ) {
|
|
219
|
-
var o = a[n];
|
|
220
|
-
if (!i(e[o], t[o])) return !1;
|
|
221
|
-
}
|
|
222
|
-
return !0;
|
|
223
|
-
}
|
|
224
|
-
return e !== e && t !== t;
|
|
225
|
-
}), tt;
|
|
266
|
+
await c();
|
|
267
|
+
if (f.status < 200 || f.status >= 400)
|
|
268
|
+
throw new kt(f);
|
|
269
|
+
return f;
|
|
226
270
|
}
|
|
227
|
-
var
|
|
228
|
-
|
|
229
|
-
var Je, le, ne, at, Pt;
|
|
230
|
-
class er {
|
|
271
|
+
var Me, J, z, Pe, Xe;
|
|
272
|
+
class St {
|
|
231
273
|
constructor(e, t) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
274
|
+
l(this, z);
|
|
275
|
+
p(this, "dolla");
|
|
276
|
+
p(this, "config");
|
|
277
|
+
l(this, Me, !1);
|
|
278
|
+
l(this, J, /* @__PURE__ */ new Map());
|
|
237
279
|
this.config = e, this.dolla = t;
|
|
238
280
|
}
|
|
239
281
|
async load() {
|
|
240
282
|
let e;
|
|
241
|
-
if (!
|
|
242
|
-
if (
|
|
243
|
-
if (e = await this.config.fetch(), !
|
|
283
|
+
if (!a(this, Me)) {
|
|
284
|
+
if (te(this.config.fetch)) {
|
|
285
|
+
if (e = await this.config.fetch(), !ke(e))
|
|
244
286
|
throw new Error(`Fetch function did not return an object of language strings: ${e}`);
|
|
245
|
-
} else if (
|
|
246
|
-
const t = await
|
|
247
|
-
if (t.
|
|
248
|
-
|
|
249
|
-
|
|
287
|
+
} else if (k(this.config.path)) {
|
|
288
|
+
const t = await fetch(this.config.path);
|
|
289
|
+
if (t.ok) {
|
|
290
|
+
const r = await t.json();
|
|
291
|
+
if (ke(r))
|
|
292
|
+
e = r;
|
|
250
293
|
else
|
|
251
294
|
throw new Error(
|
|
252
|
-
`Language path '${this.config.path}' did not return an object of language strings: ${
|
|
295
|
+
`Language path '${this.config.path}' did not return an object of language strings: ${r}`
|
|
253
296
|
);
|
|
254
|
-
else
|
|
297
|
+
} else
|
|
255
298
|
throw new Error("HTTP request failed.");
|
|
256
299
|
}
|
|
257
300
|
}
|
|
258
301
|
if (e) {
|
|
259
|
-
const t =
|
|
302
|
+
const t = d(this, z, Pe).call(this, e);
|
|
260
303
|
for (const r of t)
|
|
261
|
-
|
|
304
|
+
a(this, J).set(r[0], r[1]);
|
|
262
305
|
} else
|
|
263
306
|
throw new Error("Language could not be loaded.");
|
|
264
307
|
}
|
|
265
308
|
getTemplate(e) {
|
|
266
|
-
return
|
|
309
|
+
return a(this, J).get(e) ?? {
|
|
267
310
|
segments: [{ type: 0, text: `[MISSING: ${e}]` }]
|
|
268
311
|
};
|
|
269
312
|
}
|
|
270
313
|
hasTemplate(e) {
|
|
271
|
-
return
|
|
314
|
+
return a(this, J).has(e);
|
|
272
315
|
}
|
|
273
316
|
}
|
|
274
|
-
|
|
317
|
+
Me = new WeakMap(), J = new WeakMap(), z = new WeakSet(), Pe = function(e, t = []) {
|
|
275
318
|
const r = [];
|
|
276
319
|
for (const n in e)
|
|
277
|
-
switch (
|
|
320
|
+
switch (We(e[n])) {
|
|
278
321
|
case "string":
|
|
279
|
-
r.push([[...t, n].join("."),
|
|
322
|
+
r.push([[...t, n].join("."), d(this, z, Xe).call(this, e[n])]);
|
|
280
323
|
break;
|
|
281
324
|
case "object":
|
|
282
|
-
r.push(...
|
|
325
|
+
r.push(...d(this, z, Pe).call(this, e[n], [...t, n]));
|
|
283
326
|
break;
|
|
284
327
|
default:
|
|
285
328
|
throw new Error(
|
|
286
|
-
`Expected to find a string or object at ${[...t, n].join(".")}. Got: ${
|
|
329
|
+
`Expected to find a string or object at ${[...t, n].join(".")}. Got: ${We(e[n])}`
|
|
287
330
|
);
|
|
288
331
|
}
|
|
289
332
|
return r;
|
|
290
|
-
},
|
|
333
|
+
}, Xe = function(e) {
|
|
291
334
|
let t;
|
|
292
|
-
((
|
|
293
|
-
|
|
335
|
+
((h) => {
|
|
336
|
+
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";
|
|
294
337
|
})(t || (t = {}));
|
|
295
338
|
const r = {
|
|
296
339
|
segments: []
|
|
297
340
|
};
|
|
298
|
-
let n = "",
|
|
341
|
+
let n = "", s = 0, i = 0, f, c, u;
|
|
299
342
|
const m = () => {
|
|
300
|
-
|
|
343
|
+
f = {
|
|
301
344
|
type: 1,
|
|
302
345
|
name: "",
|
|
303
346
|
formats: []
|
|
304
347
|
};
|
|
305
|
-
},
|
|
306
|
-
|
|
348
|
+
}, b = () => {
|
|
349
|
+
c = {
|
|
307
350
|
name: "",
|
|
308
351
|
options: {}
|
|
309
352
|
};
|
|
310
353
|
};
|
|
311
|
-
for (;
|
|
312
|
-
if (
|
|
313
|
-
|
|
354
|
+
for (; s < e.length; ) {
|
|
355
|
+
if (i !== 0 && e[s] === " ") {
|
|
356
|
+
s++;
|
|
314
357
|
continue;
|
|
315
358
|
}
|
|
316
|
-
switch (
|
|
359
|
+
switch (i) {
|
|
317
360
|
case 0:
|
|
318
|
-
e[
|
|
361
|
+
e[s] === "{" && e[s + 1] === "{" ? (i = 1, s += 2, n.length > 0 && (r.segments.push({ type: 0, text: n }), n = ""), m()) : (n += e[s], s++);
|
|
319
362
|
break;
|
|
320
363
|
case 1:
|
|
321
|
-
e[
|
|
364
|
+
e[s] === "|" ? (i = 2, s += 1, f.name = n, n = "", b()) : e[s] === "}" && e[s + 1] === "}" ? (i = 0, s += 2, f.name = n, n = "", r.segments.push(f)) : (n += e[s], s++);
|
|
322
365
|
break;
|
|
323
366
|
case 2:
|
|
324
|
-
e[
|
|
367
|
+
e[s] === "(" ? (i = 3, s += 1, c.name = n, n = "") : e[s] === "}" && e[s + 1] === "}" ? (i = 0, s += 2, f.formats.push(c), r.segments.push(f)) : (n += e[s], s++);
|
|
325
368
|
break;
|
|
326
369
|
case 3:
|
|
327
|
-
e[
|
|
370
|
+
e[s] === ")" || (e[s] === ":" ? (i = 4, s += 1, u = n, n = "") : e[s] === "}" && e[s + 1] === "}" || (n += e[s], s++));
|
|
328
371
|
break;
|
|
329
372
|
case 4:
|
|
330
|
-
e[
|
|
373
|
+
e[s] === ")" ? (i = 5, s += 1, c.options[u] = n, n = "", f.formats.push(c)) : e[s] === "," ? (i = 3, s += 1, c.options[u] = n, n = "") : e[s] === "}" && e[s + 1] === "}" || (n += e[s], s++);
|
|
331
374
|
break;
|
|
332
375
|
case 5:
|
|
333
|
-
e[
|
|
376
|
+
e[s] === "|" ? (i = 2, s += 1, b()) : e[s] === "}" && e[s + 1] === "}" && (i = 0, s += 2, r.segments.push(f));
|
|
334
377
|
break;
|
|
335
378
|
}
|
|
336
379
|
}
|
|
337
|
-
return
|
|
380
|
+
return i === 0 && n.length > 0 && r.segments.push({ type: 0, text: n }), r;
|
|
338
381
|
};
|
|
339
|
-
var
|
|
340
|
-
class
|
|
382
|
+
var ae, P, v, ie, oe, le, ce, E, Ye, De, Te, Oe, Ze;
|
|
383
|
+
class Lt {
|
|
341
384
|
constructor(e) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const [t, r] =
|
|
353
|
-
this.$locale = t,
|
|
354
|
-
|
|
385
|
+
l(this, E);
|
|
386
|
+
l(this, ae);
|
|
387
|
+
l(this, P);
|
|
388
|
+
l(this, v, /* @__PURE__ */ new Map());
|
|
389
|
+
l(this, ie, []);
|
|
390
|
+
l(this, oe, /* @__PURE__ */ new Map());
|
|
391
|
+
l(this, le, "auto");
|
|
392
|
+
p(this, "$locale");
|
|
393
|
+
l(this, ce);
|
|
394
|
+
g(this, ae, e), g(this, P, e.createLogger("dolla/i18n"));
|
|
395
|
+
const [t, r] = Ve();
|
|
396
|
+
this.$locale = t, g(this, ce, r), this.addFormat("number", (n, s, i) => d(this, E, De).call(this, Number(s), i)), this.addFormat("datetime", (n, s, i) => d(this, E, Te).call(this, s, i)), this.addFormat("list", (n, s, i) => d(this, E, Oe).call(this, s, i)), e.beforeMount(async () => {
|
|
397
|
+
a(this, v).size > 0 && await this.setLocale(a(this, le));
|
|
355
398
|
});
|
|
356
399
|
}
|
|
357
400
|
get locales() {
|
|
358
|
-
return [...
|
|
401
|
+
return [...a(this, v).keys()];
|
|
359
402
|
}
|
|
360
403
|
setup(e) {
|
|
361
404
|
if (e.translations.forEach((t) => {
|
|
362
|
-
|
|
405
|
+
a(this, v).set(t.locale, new St(t, a(this, ae)));
|
|
363
406
|
}), e.locale && e.locale !== "auto") {
|
|
364
407
|
if (!e.translations.some((r) => r.locale === e.locale))
|
|
365
408
|
throw new Error(`Initial locale '${e.locale}' is not registered in the locales array.`);
|
|
366
|
-
|
|
409
|
+
g(this, le, e.locale);
|
|
367
410
|
}
|
|
368
|
-
|
|
369
|
-
`${
|
|
411
|
+
a(this, P).info(
|
|
412
|
+
`${a(this, v).size} language${a(this, v).size === 1 ? "" : "s"} supported: '${[...a(this, v).keys()].join("', '")}'`
|
|
370
413
|
);
|
|
371
414
|
}
|
|
372
415
|
async setLocale(e) {
|
|
373
416
|
var n;
|
|
374
417
|
let t;
|
|
375
418
|
if (e === "auto") {
|
|
376
|
-
let
|
|
377
|
-
if (typeof navigator
|
|
378
|
-
const
|
|
379
|
-
((n =
|
|
419
|
+
let s = [];
|
|
420
|
+
if (typeof navigator < "u") {
|
|
421
|
+
const i = navigator;
|
|
422
|
+
((n = i.languages) == null ? void 0 : n.length) > 0 ? s.push(...i.languages) : i.language ? s.push(i.language) : i.browserLanguage ? s.push(i.browserLanguage) : i.userLanguage && s.push(i.userLanguage);
|
|
380
423
|
}
|
|
381
|
-
for (const
|
|
382
|
-
|
|
424
|
+
for (const i of s)
|
|
425
|
+
a(this, v).has(i) && (t = i);
|
|
383
426
|
} else
|
|
384
|
-
|
|
427
|
+
a(this, v).has(e) && (t = e);
|
|
385
428
|
if (t == null) {
|
|
386
|
-
const
|
|
387
|
-
|
|
429
|
+
const s = a(this, v).keys().next().value;
|
|
430
|
+
s && (t = s);
|
|
388
431
|
}
|
|
389
|
-
if (!t || !
|
|
432
|
+
if (!t || !a(this, v).has(t))
|
|
390
433
|
throw new Error(`Locale '${e}' has no translation.`);
|
|
391
|
-
const r =
|
|
434
|
+
const r = a(this, v).get(t);
|
|
392
435
|
try {
|
|
393
|
-
await r.load(),
|
|
394
|
-
} catch (
|
|
395
|
-
|
|
436
|
+
await r.load(), g(this, ie, []), a(this, ce).call(this, t), a(this, P).info("set language to " + t);
|
|
437
|
+
} catch (s) {
|
|
438
|
+
s instanceof Error && a(this, P).crash(s);
|
|
396
439
|
}
|
|
397
440
|
}
|
|
398
441
|
/**
|
|
@@ -410,15 +453,15 @@ class tr {
|
|
|
410
453
|
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
411
454
|
);
|
|
412
455
|
let r = [], n = [];
|
|
413
|
-
for (const
|
|
414
|
-
r.push(
|
|
415
|
-
return
|
|
416
|
-
if (
|
|
456
|
+
for (const s in t)
|
|
457
|
+
r.push(s), n.push(t[s]);
|
|
458
|
+
return F([this.$locale, ...n], (s, ...i) => {
|
|
459
|
+
if (s == null)
|
|
417
460
|
return "[NO LOCALE SET]";
|
|
418
|
-
const
|
|
419
|
-
for (let
|
|
420
|
-
|
|
421
|
-
return
|
|
461
|
+
const f = {};
|
|
462
|
+
for (let c = 0; c < i.length; c++)
|
|
463
|
+
f[r[c]] = i[c];
|
|
464
|
+
return d(this, E, Ye).call(this, s, e, f);
|
|
422
465
|
});
|
|
423
466
|
}
|
|
424
467
|
/**
|
|
@@ -436,7 +479,7 @@ class tr {
|
|
|
436
479
|
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
437
480
|
*/
|
|
438
481
|
addFormat(e, t) {
|
|
439
|
-
|
|
482
|
+
a(this, oe).set(e, t);
|
|
440
483
|
}
|
|
441
484
|
/**
|
|
442
485
|
* Creates an `Intl.Collator` configured for the current locale.
|
|
@@ -453,7 +496,7 @@ class tr {
|
|
|
453
496
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
454
497
|
*/
|
|
455
498
|
number(e, t) {
|
|
456
|
-
return
|
|
499
|
+
return F([this.$locale, e], (r, n) => d(this, E, De).call(this, n, t));
|
|
457
500
|
}
|
|
458
501
|
/**
|
|
459
502
|
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -465,7 +508,7 @@ class tr {
|
|
|
465
508
|
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
466
509
|
*/
|
|
467
510
|
dateTime(e, t) {
|
|
468
|
-
return
|
|
511
|
+
return F([this.$locale, e], (r, n) => d(this, E, Te).call(this, n, t));
|
|
469
512
|
}
|
|
470
513
|
/**
|
|
471
514
|
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -477,513 +520,88 @@ class tr {
|
|
|
477
520
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
478
521
|
*/
|
|
479
522
|
list(e, t) {
|
|
480
|
-
return
|
|
523
|
+
return F([this.$locale, e], (r, n) => d(this, E, Oe).call(this, n, t));
|
|
481
524
|
}
|
|
482
525
|
}
|
|
483
|
-
|
|
484
|
-
var
|
|
485
|
-
const n =
|
|
526
|
+
ae = new WeakMap(), P = new WeakMap(), v = new WeakMap(), ie = new WeakMap(), oe = new WeakMap(), le = new WeakMap(), ce = new WeakMap(), E = new WeakSet(), Ye = function(e, t, r) {
|
|
527
|
+
var c;
|
|
528
|
+
const n = d(this, E, Ze).call(this, t, r);
|
|
486
529
|
if (n) return n;
|
|
487
|
-
const
|
|
530
|
+
const s = a(this, v).get(e);
|
|
488
531
|
if (r.context != null && (t += "_" + r.context), r.count != null)
|
|
489
532
|
if (r.ordinal) {
|
|
490
|
-
const
|
|
491
|
-
|
|
533
|
+
const u = `${t}_ordinal_(=${r.count})`;
|
|
534
|
+
s.hasTemplate(u) ? t = u : t += "_ordinal_" + new Intl.PluralRules(e, { type: "ordinal" }).select(r.count);
|
|
492
535
|
} else {
|
|
493
|
-
const
|
|
494
|
-
|
|
536
|
+
const u = `${t}_(=${r.count})`;
|
|
537
|
+
s.hasTemplate(u) ? t = u : t += "_" + new Intl.PluralRules(e).select(r.count);
|
|
495
538
|
}
|
|
496
|
-
const
|
|
497
|
-
let
|
|
498
|
-
for (const
|
|
499
|
-
if (
|
|
500
|
-
|
|
501
|
-
else if (
|
|
502
|
-
let m =
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
for (const
|
|
506
|
-
const
|
|
507
|
-
if (
|
|
508
|
-
const
|
|
509
|
-
`Failed to load format '${
|
|
539
|
+
const i = s.getTemplate(t);
|
|
540
|
+
let f = "";
|
|
541
|
+
for (const u of i.segments)
|
|
542
|
+
if (u.type === 0)
|
|
543
|
+
f += u.text;
|
|
544
|
+
else if (u.type === 1) {
|
|
545
|
+
let m = Mt(r, u.name);
|
|
546
|
+
const b = ((c = r.formatOverrides) == null ? void 0 : c[u.name]) ?? [...u.formats];
|
|
547
|
+
u.name === "count" && b.length === 0 && b.push({ name: "number", options: {} });
|
|
548
|
+
for (const h of b) {
|
|
549
|
+
const R = a(this, oe).get(h.name);
|
|
550
|
+
if (R == null) {
|
|
551
|
+
const y = new Error(
|
|
552
|
+
`Failed to load format '${h.name}' when processing '${t}', template: ${i}`
|
|
510
553
|
);
|
|
511
|
-
throw
|
|
554
|
+
throw a(this, P).crash(y), y;
|
|
512
555
|
}
|
|
513
|
-
m =
|
|
556
|
+
m = R(e, m, h.options);
|
|
514
557
|
}
|
|
515
|
-
|
|
558
|
+
f += m;
|
|
516
559
|
}
|
|
517
|
-
return
|
|
518
|
-
},
|
|
560
|
+
return f;
|
|
561
|
+
}, De = function(e, t) {
|
|
519
562
|
return new Intl.NumberFormat(this.$locale.get(), t).format(e);
|
|
520
|
-
},
|
|
521
|
-
return new Intl.DateTimeFormat(this.$locale.get(), t).format(
|
|
522
|
-
|
|
523
|
-
);
|
|
524
|
-
}, ot = function(e, t) {
|
|
563
|
+
}, Te = function(e, t) {
|
|
564
|
+
return new Intl.DateTimeFormat(this.$locale.get(), t).format(k(e) ? new Date(e) : e);
|
|
565
|
+
}, Oe = function(e, t) {
|
|
525
566
|
return new Intl.ListFormat(this.$locale.get(), t).format(e);
|
|
526
567
|
}, // relativeTime(): State<string> {
|
|
527
568
|
// }
|
|
528
|
-
|
|
529
|
-
for (const r of
|
|
530
|
-
if (r[0] === e &&
|
|
569
|
+
Ze = function(e, t) {
|
|
570
|
+
for (const r of a(this, ie))
|
|
571
|
+
if (r[0] === e && ot(r[1], t))
|
|
531
572
|
return r[2];
|
|
532
573
|
};
|
|
533
|
-
function
|
|
574
|
+
function Mt(o, e) {
|
|
534
575
|
const t = String(e).split(/[\.\[\]]/).filter((n) => n.trim() !== "");
|
|
535
|
-
let r =
|
|
576
|
+
let r = o;
|
|
536
577
|
for (; t.length > 0; ) {
|
|
537
578
|
const n = t.shift();
|
|
538
579
|
r != null ? r = r[n] : r = void 0;
|
|
539
580
|
}
|
|
540
581
|
return r;
|
|
541
582
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
constructor(e) {
|
|
545
|
-
h(this, _);
|
|
546
|
-
h(this, xe);
|
|
547
|
-
h(this, ce);
|
|
548
|
-
// Keys ensure only the most recent callback queued with a certain key
|
|
549
|
-
// will be called, keeping DOM operations to a minimum.
|
|
550
|
-
h(this, U, /* @__PURE__ */ new Map());
|
|
551
|
-
// All unkeyed writes are run on every batch.
|
|
552
|
-
h(this, Y, []);
|
|
553
|
-
// All read callbacks are run before updates on every batch.
|
|
554
|
-
h(this, X, []);
|
|
555
|
-
h(this, ue, !1);
|
|
556
|
-
// When true, batches that would exceed 16ms will be split and deferred to a rAF.
|
|
557
|
-
// This may not be desirable, because while it does prevent hitching it sometimes leaves
|
|
558
|
-
// the state partially rendered for a brief second and certain elements can be seen to update after the fact.
|
|
559
|
-
// But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
|
|
560
|
-
h(this, Ye, !0);
|
|
561
|
-
h(this, A, 0);
|
|
562
|
-
h(this, Oe, new Intl.NumberFormat("en-US", { maximumFractionDigits: 2, minimumFractionDigits: 0 }));
|
|
563
|
-
b(this, xe, e), b(this, ce, e.createLogger("dolla/render"));
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Queues a callback that runs before the next batch of writes.
|
|
567
|
-
*/
|
|
568
|
-
read(e) {
|
|
569
|
-
s(this, X).push(e), v(this, _, lt).call(this);
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Queues a callback to run in the next render batch.
|
|
573
|
-
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
574
|
-
*/
|
|
575
|
-
write(e, t) {
|
|
576
|
-
t ? s(this, U).set(t, e) : s(this, Y).push(e), v(this, _, lt).call(this);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
xe = new WeakMap(), ce = new WeakMap(), U = new WeakMap(), Y = new WeakMap(), X = new WeakMap(), ue = new WeakMap(), Ye = new WeakMap(), A = new WeakMap(), Oe = new WeakMap(), _ = new WeakSet(), lt = function() {
|
|
580
|
-
if (!s(this, ue)) {
|
|
581
|
-
b(this, ue, !0);
|
|
582
|
-
const e = s(this, xe).getEnv() === "development";
|
|
583
|
-
queueMicrotask(() => {
|
|
584
|
-
v(this, _, Ie).call(this, e);
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
}, Ie = function(e = !1) {
|
|
588
|
-
const t = performance.now();
|
|
589
|
-
let r = 0;
|
|
590
|
-
const n = s(this, X).length + s(this, U).size + s(this, Y).length;
|
|
591
|
-
let a = 0;
|
|
592
|
-
const o = () => (a++, r = performance.now() - t, s(this, Ye) && r > 12 && a < n ? (et(this, A)._++, e && s(this, ce).warn(
|
|
593
|
-
`⚠️ Deferring batch to next frame. Performed ${a} of ${n} batched operation${a === 1 ? "" : "s"} in ${s(this, Oe).format(r)}ms (deferral ${s(this, A)}).`
|
|
594
|
-
), requestAnimationFrame(() => {
|
|
595
|
-
v(this, _, Ie).call(this, e);
|
|
596
|
-
}), !0) : !1), p = [...s(this, U).entries()];
|
|
597
|
-
let l;
|
|
598
|
-
for (; l = s(this, X).shift(); )
|
|
599
|
-
if (l(), o()) return;
|
|
600
|
-
for (const [f, m] of p)
|
|
601
|
-
if (m(), s(this, U).delete(f), o()) return;
|
|
602
|
-
for (; l = s(this, Y).shift(); )
|
|
603
|
-
if (l(), o()) return;
|
|
604
|
-
e && s(this, ce)[r > 16 ? "warn" : "info"](
|
|
605
|
-
`${r > 16 ? "⚠️ (>=16ms) " : ""}Executed ${a} operation${a === 1 ? "" : "s"} in ${s(this, Oe).format(r)}ms${s(this, A) > 0 ? ` (after ${s(this, A)} deferral${s(this, A) === 1 ? "" : "s"})` : ""}.`
|
|
606
|
-
), b(this, A, 0), s(this, X).length || s(this, U).size || s(this, Y).length ? queueMicrotask(() => {
|
|
607
|
-
v(this, _, Ie).call(this, e);
|
|
608
|
-
}) : b(this, ue, !1);
|
|
609
|
-
};
|
|
610
|
-
function pe() {
|
|
611
|
-
return pe = Object.assign ? Object.assign.bind() : function(i) {
|
|
612
|
-
for (var e = 1; e < arguments.length; e++) {
|
|
613
|
-
var t = arguments[e];
|
|
614
|
-
for (var r in t) ({}).hasOwnProperty.call(t, r) && (i[r] = t[r]);
|
|
615
|
-
}
|
|
616
|
-
return i;
|
|
617
|
-
}, pe.apply(null, arguments);
|
|
618
|
-
}
|
|
619
|
-
var M;
|
|
620
|
-
(function(i) {
|
|
621
|
-
i.Pop = "POP", i.Push = "PUSH", i.Replace = "REPLACE";
|
|
622
|
-
})(M || (M = {}));
|
|
623
|
-
var Be = process.env.NODE_ENV !== "production" ? function(i) {
|
|
624
|
-
return Object.freeze(i);
|
|
625
|
-
} : function(i) {
|
|
626
|
-
return i;
|
|
627
|
-
};
|
|
628
|
-
function Ue(i, e) {
|
|
629
|
-
if (!i) {
|
|
630
|
-
typeof console < "u" && console.warn(e);
|
|
631
|
-
try {
|
|
632
|
-
throw new Error(e);
|
|
633
|
-
} catch {
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
var Ge = "beforeunload", ar = "hashchange", Lt = "popstate";
|
|
638
|
-
function sr(i) {
|
|
639
|
-
i === void 0 && (i = {});
|
|
640
|
-
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
641
|
-
function a() {
|
|
642
|
-
var w = r.location, c = w.pathname, d = w.search, $ = w.hash, E = n.state || {};
|
|
643
|
-
return [E.idx, Be({
|
|
644
|
-
pathname: c,
|
|
645
|
-
search: d,
|
|
646
|
-
hash: $,
|
|
647
|
-
state: E.usr || null,
|
|
648
|
-
key: E.key || "default"
|
|
649
|
-
})];
|
|
650
|
-
}
|
|
651
|
-
var o = null;
|
|
652
|
-
function p() {
|
|
653
|
-
if (o)
|
|
654
|
-
y.call(o), o = null;
|
|
655
|
-
else {
|
|
656
|
-
var w = M.Pop, c = a(), d = c[0], $ = c[1];
|
|
657
|
-
if (y.length)
|
|
658
|
-
if (d != null) {
|
|
659
|
-
var E = m - d;
|
|
660
|
-
E && (o = {
|
|
661
|
-
action: w,
|
|
662
|
-
location: $,
|
|
663
|
-
retry: function() {
|
|
664
|
-
C(E * -1);
|
|
665
|
-
}
|
|
666
|
-
}, C(E));
|
|
667
|
-
} else
|
|
668
|
-
process.env.NODE_ENV !== "production" && Ue(
|
|
669
|
-
!1,
|
|
670
|
-
// TODO: Write up a doc that explains our blocking strategy in
|
|
671
|
-
// detail and link to it here so people can understand better what
|
|
672
|
-
// is going on and how to avoid it.
|
|
673
|
-
"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
|
|
674
|
-
);
|
|
675
|
-
else
|
|
676
|
-
ae(w);
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
r.addEventListener(Lt, p);
|
|
680
|
-
var l = M.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
681
|
-
m == null && (m = 0, n.replaceState(pe({}, n.state, {
|
|
682
|
-
idx: m
|
|
683
|
-
}), ""));
|
|
684
|
-
function k(w) {
|
|
685
|
-
return typeof w == "string" ? w : He(w);
|
|
686
|
-
}
|
|
687
|
-
function me(w, c) {
|
|
688
|
-
return c === void 0 && (c = null), Be(pe({
|
|
689
|
-
pathname: g.pathname,
|
|
690
|
-
hash: "",
|
|
691
|
-
search: ""
|
|
692
|
-
}, typeof w == "string" ? ct(w) : w, {
|
|
693
|
-
state: c,
|
|
694
|
-
key: Rt()
|
|
695
|
-
}));
|
|
696
|
-
}
|
|
697
|
-
function ge(w, c) {
|
|
698
|
-
return [{
|
|
699
|
-
usr: w.state,
|
|
700
|
-
key: w.key,
|
|
701
|
-
idx: c
|
|
702
|
-
}, k(w)];
|
|
703
|
-
}
|
|
704
|
-
function we(w, c, d) {
|
|
705
|
-
return !y.length || (y.call({
|
|
706
|
-
action: w,
|
|
707
|
-
location: c,
|
|
708
|
-
retry: d
|
|
709
|
-
}), !1);
|
|
710
|
-
}
|
|
711
|
-
function ae(w) {
|
|
712
|
-
l = w;
|
|
713
|
-
var c = a();
|
|
714
|
-
m = c[0], g = c[1], u.call({
|
|
715
|
-
action: l,
|
|
716
|
-
location: g
|
|
717
|
-
});
|
|
718
|
-
}
|
|
719
|
-
function se(w, c) {
|
|
720
|
-
var d = M.Push, $ = me(w, c);
|
|
721
|
-
function E() {
|
|
722
|
-
se(w, c);
|
|
723
|
-
}
|
|
724
|
-
if (we(d, $, E)) {
|
|
725
|
-
var x = ge($, m + 1), D = x[0], T = x[1];
|
|
726
|
-
try {
|
|
727
|
-
n.pushState(D, "", T);
|
|
728
|
-
} catch {
|
|
729
|
-
r.location.assign(T);
|
|
730
|
-
}
|
|
731
|
-
ae(d);
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
function ye(w, c) {
|
|
735
|
-
var d = M.Replace, $ = me(w, c);
|
|
736
|
-
function E() {
|
|
737
|
-
ye(w, c);
|
|
738
|
-
}
|
|
739
|
-
if (we(d, $, E)) {
|
|
740
|
-
var x = ge($, m), D = x[0], T = x[1];
|
|
741
|
-
n.replaceState(D, "", T), ae(d);
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
function C(w) {
|
|
745
|
-
n.go(w);
|
|
746
|
-
}
|
|
747
|
-
var Q = {
|
|
748
|
-
get action() {
|
|
749
|
-
return l;
|
|
750
|
-
},
|
|
751
|
-
get location() {
|
|
752
|
-
return g;
|
|
753
|
-
},
|
|
754
|
-
createHref: k,
|
|
755
|
-
push: se,
|
|
756
|
-
replace: ye,
|
|
757
|
-
go: C,
|
|
758
|
-
back: function() {
|
|
759
|
-
C(-1);
|
|
760
|
-
},
|
|
761
|
-
forward: function() {
|
|
762
|
-
C(1);
|
|
763
|
-
},
|
|
764
|
-
listen: function(c) {
|
|
765
|
-
return u.push(c);
|
|
766
|
-
},
|
|
767
|
-
block: function(c) {
|
|
768
|
-
var d = y.push(c);
|
|
769
|
-
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
770
|
-
d(), y.length || r.removeEventListener(Ge, ze);
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
return Q;
|
|
775
|
-
}
|
|
776
|
-
function ir(i) {
|
|
777
|
-
i === void 0 && (i = {});
|
|
778
|
-
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
779
|
-
function a() {
|
|
780
|
-
var c = ct(r.location.hash.substr(1)), d = c.pathname, $ = d === void 0 ? "/" : d, E = c.search, x = E === void 0 ? "" : E, D = c.hash, T = D === void 0 ? "" : D, q = n.state || {};
|
|
781
|
-
return [q.idx, Be({
|
|
782
|
-
pathname: $,
|
|
783
|
-
search: x,
|
|
784
|
-
hash: T,
|
|
785
|
-
state: q.usr || null,
|
|
786
|
-
key: q.key || "default"
|
|
787
|
-
})];
|
|
788
|
-
}
|
|
789
|
-
var o = null;
|
|
790
|
-
function p() {
|
|
791
|
-
if (o)
|
|
792
|
-
y.call(o), o = null;
|
|
793
|
-
else {
|
|
794
|
-
var c = M.Pop, d = a(), $ = d[0], E = d[1];
|
|
795
|
-
if (y.length)
|
|
796
|
-
if ($ != null) {
|
|
797
|
-
var x = m - $;
|
|
798
|
-
x && (o = {
|
|
799
|
-
action: c,
|
|
800
|
-
location: E,
|
|
801
|
-
retry: function() {
|
|
802
|
-
Q(x * -1);
|
|
803
|
-
}
|
|
804
|
-
}, Q(x));
|
|
805
|
-
} else
|
|
806
|
-
process.env.NODE_ENV !== "production" && Ue(
|
|
807
|
-
!1,
|
|
808
|
-
// TODO: Write up a doc that explains our blocking strategy in
|
|
809
|
-
// detail and link to it here so people can understand better
|
|
810
|
-
// what is going on and how to avoid it.
|
|
811
|
-
"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
|
|
812
|
-
);
|
|
813
|
-
else
|
|
814
|
-
se(c);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
r.addEventListener(Lt, p), r.addEventListener(ar, function() {
|
|
818
|
-
var c = a(), d = c[1];
|
|
819
|
-
He(d) !== He(g) && p();
|
|
820
|
-
});
|
|
821
|
-
var l = M.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
822
|
-
m == null && (m = 0, n.replaceState(pe({}, n.state, {
|
|
823
|
-
idx: m
|
|
824
|
-
}), ""));
|
|
825
|
-
function k() {
|
|
826
|
-
var c = document.querySelector("base"), d = "";
|
|
827
|
-
if (c && c.getAttribute("href")) {
|
|
828
|
-
var $ = r.location.href, E = $.indexOf("#");
|
|
829
|
-
d = E === -1 ? $ : $.slice(0, E);
|
|
830
|
-
}
|
|
831
|
-
return d;
|
|
832
|
-
}
|
|
833
|
-
function me(c) {
|
|
834
|
-
return k() + "#" + (typeof c == "string" ? c : He(c));
|
|
835
|
-
}
|
|
836
|
-
function ge(c, d) {
|
|
837
|
-
return d === void 0 && (d = null), Be(pe({
|
|
838
|
-
pathname: g.pathname,
|
|
839
|
-
hash: "",
|
|
840
|
-
search: ""
|
|
841
|
-
}, typeof c == "string" ? ct(c) : c, {
|
|
842
|
-
state: d,
|
|
843
|
-
key: Rt()
|
|
844
|
-
}));
|
|
845
|
-
}
|
|
846
|
-
function we(c, d) {
|
|
847
|
-
return [{
|
|
848
|
-
usr: c.state,
|
|
849
|
-
key: c.key,
|
|
850
|
-
idx: d
|
|
851
|
-
}, me(c)];
|
|
852
|
-
}
|
|
853
|
-
function ae(c, d, $) {
|
|
854
|
-
return !y.length || (y.call({
|
|
855
|
-
action: c,
|
|
856
|
-
location: d,
|
|
857
|
-
retry: $
|
|
858
|
-
}), !1);
|
|
859
|
-
}
|
|
860
|
-
function se(c) {
|
|
861
|
-
l = c;
|
|
862
|
-
var d = a();
|
|
863
|
-
m = d[0], g = d[1], u.call({
|
|
864
|
-
action: l,
|
|
865
|
-
location: g
|
|
866
|
-
});
|
|
867
|
-
}
|
|
868
|
-
function ye(c, d) {
|
|
869
|
-
var $ = M.Push, E = ge(c, d);
|
|
870
|
-
function x() {
|
|
871
|
-
ye(c, d);
|
|
872
|
-
}
|
|
873
|
-
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.push(" + JSON.stringify(c) + ")"), ae($, E, x)) {
|
|
874
|
-
var D = we(E, m + 1), T = D[0], q = D[1];
|
|
875
|
-
try {
|
|
876
|
-
n.pushState(T, "", q);
|
|
877
|
-
} catch {
|
|
878
|
-
r.location.assign(q);
|
|
879
|
-
}
|
|
880
|
-
se($);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
function C(c, d) {
|
|
884
|
-
var $ = M.Replace, E = ge(c, d);
|
|
885
|
-
function x() {
|
|
886
|
-
C(c, d);
|
|
887
|
-
}
|
|
888
|
-
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(c) + ")"), ae($, E, x)) {
|
|
889
|
-
var D = we(E, m), T = D[0], q = D[1];
|
|
890
|
-
n.replaceState(T, "", q), se($);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
function Q(c) {
|
|
894
|
-
n.go(c);
|
|
895
|
-
}
|
|
896
|
-
var w = {
|
|
897
|
-
get action() {
|
|
898
|
-
return l;
|
|
899
|
-
},
|
|
900
|
-
get location() {
|
|
901
|
-
return g;
|
|
902
|
-
},
|
|
903
|
-
createHref: me,
|
|
904
|
-
push: ye,
|
|
905
|
-
replace: C,
|
|
906
|
-
go: Q,
|
|
907
|
-
back: function() {
|
|
908
|
-
Q(-1);
|
|
909
|
-
},
|
|
910
|
-
forward: function() {
|
|
911
|
-
Q(1);
|
|
912
|
-
},
|
|
913
|
-
listen: function(d) {
|
|
914
|
-
return u.push(d);
|
|
915
|
-
},
|
|
916
|
-
block: function(d) {
|
|
917
|
-
var $ = y.push(d);
|
|
918
|
-
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
919
|
-
$(), y.length || r.removeEventListener(Ge, ze);
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
return w;
|
|
924
|
-
}
|
|
925
|
-
function ze(i) {
|
|
926
|
-
i.preventDefault(), i.returnValue = "";
|
|
927
|
-
}
|
|
928
|
-
function Ke() {
|
|
929
|
-
var i = [];
|
|
930
|
-
return {
|
|
931
|
-
get length() {
|
|
932
|
-
return i.length;
|
|
933
|
-
},
|
|
934
|
-
push: function(t) {
|
|
935
|
-
return i.push(t), function() {
|
|
936
|
-
i = i.filter(function(r) {
|
|
937
|
-
return r !== t;
|
|
938
|
-
});
|
|
939
|
-
};
|
|
940
|
-
},
|
|
941
|
-
call: function(t) {
|
|
942
|
-
i.forEach(function(r) {
|
|
943
|
-
return r && r(t);
|
|
944
|
-
});
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
|
-
}
|
|
948
|
-
function Rt() {
|
|
949
|
-
return Math.random().toString(36).substr(2, 8);
|
|
950
|
-
}
|
|
951
|
-
function He(i) {
|
|
952
|
-
var e = i.pathname, t = e === void 0 ? "/" : e, r = i.search, n = r === void 0 ? "" : r, a = i.hash, o = a === void 0 ? "" : a;
|
|
953
|
-
return n && n !== "?" && (t += n.charAt(0) === "?" ? n : "?" + n), o && o !== "#" && (t += o.charAt(0) === "#" ? o : "#" + o), t;
|
|
583
|
+
function ee(o) {
|
|
584
|
+
return Qe(o, "Expected `path` to be a string. Got type: %t, value: %v"), o.split("/").map((e) => e.trim()).filter((e) => e !== "");
|
|
954
585
|
}
|
|
955
|
-
function
|
|
956
|
-
var e = {};
|
|
957
|
-
if (i) {
|
|
958
|
-
var t = i.indexOf("#");
|
|
959
|
-
t >= 0 && (e.hash = i.substr(t), i = i.substr(0, t));
|
|
960
|
-
var r = i.indexOf("?");
|
|
961
|
-
r >= 0 && (e.search = i.substr(r), i = i.substr(0, r)), i && (e.pathname = i);
|
|
962
|
-
}
|
|
963
|
-
return e;
|
|
964
|
-
}
|
|
965
|
-
function ve(i) {
|
|
966
|
-
return kt(i, "Expected `path` to be a string. Got type: %t, value: %v"), i.split("/").map((e) => e.trim()).filter((e) => e !== "");
|
|
967
|
-
}
|
|
968
|
-
function ie(i) {
|
|
586
|
+
function H(o) {
|
|
969
587
|
var t;
|
|
970
|
-
|
|
971
|
-
(r) =>
|
|
972
|
-
|
|
588
|
+
lt(
|
|
589
|
+
(r) => te(r == null ? void 0 : r.toString),
|
|
590
|
+
o,
|
|
973
591
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
974
|
-
),
|
|
975
|
-
let e = (t =
|
|
592
|
+
), o = o.filter((r) => r).flatMap(String);
|
|
593
|
+
let e = (t = o.shift()) == null ? void 0 : t.toString();
|
|
976
594
|
if (e) {
|
|
977
|
-
for (const r of
|
|
978
|
-
r.startsWith(".") ? e =
|
|
595
|
+
for (const r of o.map((n) => n.toString()))
|
|
596
|
+
r.startsWith(".") ? e = Ee(e, r) : e[e.length - 1] !== "/" ? r[0] !== "/" ? e += "/" + r : e += r : r[0] === "/" ? e += r.slice(1) : e += r;
|
|
979
597
|
e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
|
|
980
598
|
}
|
|
981
599
|
return e ?? "";
|
|
982
600
|
}
|
|
983
|
-
function
|
|
984
|
-
if (
|
|
601
|
+
function Ee(o, e) {
|
|
602
|
+
if (Qe(o, "Expected `base` to be a string. Got type: %t, value: %v"), e == null && (e = o, o = ""), e.startsWith("/"))
|
|
985
603
|
return e;
|
|
986
|
-
let t =
|
|
604
|
+
let t = o;
|
|
987
605
|
for (; ; )
|
|
988
606
|
if (e.startsWith("..")) {
|
|
989
607
|
for (let r = t.length; r > 0; --r)
|
|
@@ -995,88 +613,88 @@ function We(i, e) {
|
|
|
995
613
|
e = e.replace(/^\.\/?/, "");
|
|
996
614
|
else
|
|
997
615
|
break;
|
|
998
|
-
return
|
|
616
|
+
return H([t, e]);
|
|
999
617
|
}
|
|
1000
|
-
function
|
|
1001
|
-
if (!
|
|
1002
|
-
|
|
1003
|
-
const e =
|
|
1004
|
-
const [r, n] = t.split("=").map((
|
|
618
|
+
function xt(o) {
|
|
619
|
+
if (!o) return {};
|
|
620
|
+
o.startsWith("?") && (o = o.slice(1));
|
|
621
|
+
const e = o.split("&").filter((t) => t.trim() !== "").map((t) => {
|
|
622
|
+
const [r, n] = t.split("=").map((s) => s.trim());
|
|
1005
623
|
return n.toLowerCase() === "true" ? [r, !0] : n.toLowerCase() === "false" ? [r, !1] : isNaN(Number(n)) ? [r, n] : [r, Number(n)];
|
|
1006
624
|
});
|
|
1007
625
|
return Object.fromEntries(e);
|
|
1008
626
|
}
|
|
1009
|
-
function
|
|
1010
|
-
var
|
|
1011
|
-
const [r, n] = e.split("?"),
|
|
1012
|
-
e: for (const
|
|
1013
|
-
const { fragments:
|
|
1014
|
-
if (!(((
|
|
627
|
+
function et(o, e, t = {}) {
|
|
628
|
+
var i;
|
|
629
|
+
const [r, n] = e.split("?"), s = ee(r);
|
|
630
|
+
e: for (const f of o) {
|
|
631
|
+
const { fragments: c } = f;
|
|
632
|
+
if (!(((i = c[c.length - 1]) == null ? void 0 : i.type) === 3) && c.length !== s.length || t.willMatch && !t.willMatch(f))
|
|
1015
633
|
continue e;
|
|
1016
634
|
const m = [];
|
|
1017
|
-
t: for (let
|
|
1018
|
-
const
|
|
1019
|
-
if (
|
|
635
|
+
t: for (let h = 0; h < c.length; h++) {
|
|
636
|
+
const R = s[h], y = c[h];
|
|
637
|
+
if (R == null && y.type !== 3)
|
|
1020
638
|
continue e;
|
|
1021
|
-
switch (
|
|
639
|
+
switch (y.type) {
|
|
1022
640
|
case 1:
|
|
1023
|
-
if (
|
|
1024
|
-
m.push(
|
|
641
|
+
if (y.name.toLowerCase() === R.toLowerCase()) {
|
|
642
|
+
m.push(y);
|
|
1025
643
|
break;
|
|
1026
644
|
} else
|
|
1027
645
|
continue e;
|
|
1028
646
|
case 2:
|
|
1029
|
-
m.push({ ...
|
|
647
|
+
m.push({ ...y, value: R });
|
|
1030
648
|
break;
|
|
1031
649
|
case 3:
|
|
1032
|
-
m.push({ ...
|
|
650
|
+
m.push({ ...y, value: s.slice(h).join("/") });
|
|
1033
651
|
break t;
|
|
1034
652
|
case 4:
|
|
1035
|
-
if (isNaN(Number(
|
|
653
|
+
if (isNaN(Number(R)))
|
|
1036
654
|
continue e;
|
|
1037
|
-
m.push({ ...
|
|
655
|
+
m.push({ ...y, value: Number(R) });
|
|
1038
656
|
break;
|
|
1039
657
|
default:
|
|
1040
|
-
throw new Error(`Unknown fragment type: ${
|
|
658
|
+
throw new Error(`Unknown fragment type: ${y.type}`);
|
|
1041
659
|
}
|
|
1042
660
|
}
|
|
1043
|
-
const
|
|
1044
|
-
for (const
|
|
1045
|
-
|
|
661
|
+
const b = {};
|
|
662
|
+
for (const h of m)
|
|
663
|
+
h.type === 2 && (b[h.name] = decodeURIComponent(h.value)), h.type === 4 && (b[h.name] = h.value), h.type === 3 && (b.wildcard = "/" + decodeURIComponent(h.value));
|
|
1046
664
|
return {
|
|
1047
|
-
path: "/" + m.map((
|
|
1048
|
-
pattern: "/" +
|
|
1049
|
-
params:
|
|
1050
|
-
query:
|
|
1051
|
-
meta:
|
|
665
|
+
path: "/" + m.map((h) => h.value).join("/"),
|
|
666
|
+
pattern: "/" + c.map((h) => h.type === 2 ? `{${h.name}}` : h.type === 4 ? `{#${h.name}}` : h.name).join("/"),
|
|
667
|
+
params: b,
|
|
668
|
+
query: xt(n),
|
|
669
|
+
meta: f.meta
|
|
1052
670
|
};
|
|
1053
671
|
}
|
|
1054
672
|
}
|
|
1055
|
-
function
|
|
673
|
+
function Ft(o) {
|
|
1056
674
|
const e = [], t = [], r = [], n = [];
|
|
1057
|
-
for (const
|
|
1058
|
-
const { fragments:
|
|
1059
|
-
|
|
1060
|
-
(
|
|
675
|
+
for (const i of o) {
|
|
676
|
+
const { fragments: f } = i;
|
|
677
|
+
f.some(
|
|
678
|
+
(c) => c.type === 3
|
|
1061
679
|
/* Wildcard */
|
|
1062
|
-
) ? n.push(
|
|
1063
|
-
(
|
|
680
|
+
) ? n.push(i) : f.some(
|
|
681
|
+
(c) => c.type === 4
|
|
1064
682
|
/* NumericParam */
|
|
1065
|
-
) ? t.push(
|
|
1066
|
-
(
|
|
683
|
+
) ? t.push(i) : f.some(
|
|
684
|
+
(c) => c.type === 2
|
|
1067
685
|
/* Param */
|
|
1068
|
-
) ? r.push(
|
|
686
|
+
) ? r.push(i) : e.push(i);
|
|
1069
687
|
}
|
|
1070
|
-
const
|
|
1071
|
-
return e.sort(
|
|
688
|
+
const s = (i, f) => i.fragments.length > f.fragments.length ? -1 : 1;
|
|
689
|
+
return e.sort(s), t.sort(s), r.sort(s), n.sort(s), [...e, ...t, ...r, ...n];
|
|
1072
690
|
}
|
|
1073
|
-
function
|
|
1074
|
-
const e =
|
|
691
|
+
function qt(o) {
|
|
692
|
+
const e = ee(o), t = [];
|
|
1075
693
|
for (let r = 0; r < e.length; r++) {
|
|
1076
694
|
const n = e[r];
|
|
1077
695
|
if (n === "*") {
|
|
1078
696
|
if (r !== e.length - 1)
|
|
1079
|
-
throw new Error(`Wildcard must be at the end of a pattern. Received: ${
|
|
697
|
+
throw new Error(`Wildcard must be at the end of a pattern. Received: ${o}`);
|
|
1080
698
|
t.push({
|
|
1081
699
|
type: 3,
|
|
1082
700
|
name: "*",
|
|
@@ -1094,105 +712,83 @@ function lr(i) {
|
|
|
1094
712
|
}
|
|
1095
713
|
return t;
|
|
1096
714
|
}
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
h(this, N);
|
|
1111
|
-
h(this, Z);
|
|
1112
|
-
h(this, Re, nt());
|
|
1113
|
-
h(this, S);
|
|
1114
|
-
h(this, Xe, 0);
|
|
1115
|
-
h(this, H, []);
|
|
1116
|
-
h(this, De);
|
|
1117
|
-
h(this, ee, []);
|
|
715
|
+
var W, x, xe, D, X, _, G, T, he, w, je, tt, rt, Z, Ce, st, Ue;
|
|
716
|
+
class Nt {
|
|
717
|
+
constructor(e) {
|
|
718
|
+
l(this, w);
|
|
719
|
+
l(this, W);
|
|
720
|
+
l(this, x);
|
|
721
|
+
l(this, xe, 0);
|
|
722
|
+
l(this, D, []);
|
|
723
|
+
l(this, X, []);
|
|
724
|
+
/**
|
|
725
|
+
* Use hash routing when true. Configured in router options.
|
|
726
|
+
*/
|
|
727
|
+
l(this, _, !1);
|
|
1118
728
|
// Callbacks that need to be called on unmount.
|
|
1119
|
-
|
|
729
|
+
l(this, G, []);
|
|
730
|
+
/**
|
|
731
|
+
* The current match object.
|
|
732
|
+
*/
|
|
733
|
+
l(this, T);
|
|
734
|
+
l(this, he);
|
|
1120
735
|
/**
|
|
1121
736
|
* The currently matched route pattern, if any.
|
|
1122
737
|
*/
|
|
1123
|
-
|
|
1124
|
-
h(this, he);
|
|
738
|
+
p(this, "$pattern");
|
|
1125
739
|
/**
|
|
1126
740
|
* The current URL path.
|
|
1127
741
|
*/
|
|
1128
|
-
|
|
1129
|
-
h(this, fe);
|
|
742
|
+
p(this, "$path");
|
|
1130
743
|
/**
|
|
1131
744
|
* The current named path params.
|
|
1132
745
|
*/
|
|
1133
|
-
|
|
1134
|
-
h(this, de);
|
|
746
|
+
p(this, "$params");
|
|
1135
747
|
/**
|
|
1136
748
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
1137
749
|
*/
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
u.set(k, String(g[k]));
|
|
1150
|
-
const y = "?" + u.toString();
|
|
1151
|
-
y != s(this, S).location.search && s(this, S).replace({
|
|
1152
|
-
pathname: s(this, S).location.pathname,
|
|
1153
|
-
search: y
|
|
1154
|
-
});
|
|
1155
|
-
}), s(this, te).push(s(this, S).listen(v(this, K, ft).bind(this))), v(this, K, ft).call(this, s(this, S)), s(this, te).push(
|
|
1156
|
-
fr(s(this, Z).rootElement, (g) => {
|
|
1157
|
-
let u = g.getAttribute("href");
|
|
1158
|
-
s(this, N).info("Intercepted link click", g, u), /^https?:\/\/|^\//.test(u) || (u = ie([s(this, S).location.pathname, u])), s(this, S).push(u);
|
|
750
|
+
p(this, "$query");
|
|
751
|
+
g(this, W, e), g(this, x, e.createLogger("dolla/router")), [Y(this, T)._, Y(this, he)._] = Ve(), this.$pattern = F([a(this, T)], (t) => t == null ? void 0 : t.pattern), this.$path = F([a(this, T)], (t) => (t == null ? void 0 : t.path) ?? window.location.pathname), this.$params = F([a(this, T)], (t) => (t == null ? void 0 : t.params) ?? {}, { equals: _e }), this.$query = F([a(this, T)], (t) => (t == null ? void 0 : t.query) ?? {}, { equals: _e }), e.beforeMount(async () => {
|
|
752
|
+
const t = () => {
|
|
753
|
+
d(this, w, Z).call(this);
|
|
754
|
+
};
|
|
755
|
+
window.addEventListener("popstate", t), a(this, G).push(() => window.removeEventListener("popstate", t));
|
|
756
|
+
const r = e.getRootElement();
|
|
757
|
+
return a(this, G).push(
|
|
758
|
+
Tt(r, (n) => {
|
|
759
|
+
let s = n.getAttribute("href");
|
|
760
|
+
a(this, x).info("intercepted click on <a> tag", n), /^https?:\/\/|^\//.test(s) || (s = H([window.location.pathname, s])), d(this, w, je).call(this, s);
|
|
1159
761
|
})
|
|
1160
|
-
),
|
|
762
|
+
), a(this, x).info("will intercept clicks on <a> tags within root element", r), d(this, w, Z).call(this);
|
|
1161
763
|
}), e.onUnmount(() => {
|
|
1162
|
-
for (
|
|
1163
|
-
|
|
1164
|
-
|
|
764
|
+
for (const t of a(this, G))
|
|
765
|
+
t();
|
|
766
|
+
g(this, G, []);
|
|
1165
767
|
});
|
|
1166
768
|
}
|
|
1167
|
-
setup(e) {
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
}
|
|
1174
|
-
e.style === "hash" ? b(this, S, ir()) : b(this, S, sr()), b(this, ee, or(
|
|
1175
|
-
e.routes.flatMap((t) => v(this, K, ht).call(this, t)).map((t) => ({
|
|
769
|
+
async setup(e) {
|
|
770
|
+
Ge(e != null, "Options object must not be null. Got: %t"), Ge(
|
|
771
|
+
!a(this, W).isMounted,
|
|
772
|
+
"Dolla is already mounted. Dolla.router.setup() must be called before Dolla.mount()."
|
|
773
|
+
), e.hash && g(this, _, !0), g(this, X, Ft(
|
|
774
|
+
e.routes.flatMap((t) => d(this, w, Ue).call(this, t)).map((t) => ({
|
|
1176
775
|
pattern: t.pattern,
|
|
1177
776
|
meta: t.meta,
|
|
1178
|
-
fragments:
|
|
777
|
+
fragments: qt(t.pattern)
|
|
1179
778
|
}))
|
|
1180
|
-
));
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
} else
|
|
1194
|
-
throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
|
|
1195
|
-
}
|
|
779
|
+
)), jt(a(this, X));
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
783
|
+
*/
|
|
784
|
+
back(e = 1) {
|
|
785
|
+
window.history.go(-e);
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Navigate forward. Pass a number of steps to hit the forward button that many times.
|
|
789
|
+
*/
|
|
790
|
+
forward(e = 1) {
|
|
791
|
+
window.history.go(e);
|
|
1196
792
|
}
|
|
1197
793
|
/**
|
|
1198
794
|
* Navigates to another route.
|
|
@@ -1202,54 +798,93 @@ class cr {
|
|
|
1202
798
|
* Dolla.router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
1203
799
|
*/
|
|
1204
800
|
go(e, t = {}) {
|
|
1205
|
-
if (
|
|
1206
|
-
|
|
1207
|
-
new Error(
|
|
1208
|
-
"Router.go was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1209
|
-
)
|
|
1210
|
-
);
|
|
1211
|
-
return;
|
|
1212
|
-
}
|
|
801
|
+
if (a(this, W) == null)
|
|
802
|
+
throw new Error("Routa methods won't work until you register it: Dolla.use(Routa, { /* ...options */ })");
|
|
1213
803
|
let r;
|
|
1214
|
-
Array.isArray(e) ? r =
|
|
804
|
+
Array.isArray(e) ? r = H(e) : r = e.toString(), r = Ee(window.location.pathname, r), t.preserveQuery && (r += window.location.search), t.replace ? d(this, w, tt).call(this, r) : d(this, w, je).call(this, r);
|
|
1215
805
|
}
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
806
|
+
}
|
|
807
|
+
W = new WeakMap(), x = new WeakMap(), xe = new WeakMap(), D = new WeakMap(), X = new WeakMap(), _ = new WeakMap(), G = new WeakMap(), T = new WeakMap(), he = new WeakMap(), w = new WeakSet(), je = function(e, t) {
|
|
808
|
+
a(this, x).info("(push)", e), window.history.pushState(t, "", a(this, _) ? "/#" + e : e), d(this, w, Z).call(this, e);
|
|
809
|
+
}, tt = function(e, t) {
|
|
810
|
+
a(this, x).info("(replace)", e), window.history.replaceState(t, "", a(this, _) ? "/#" + e : e), d(this, w, Z).call(this, e);
|
|
811
|
+
}, rt = function() {
|
|
812
|
+
return a(this, _) ? new URL(window.location.hash.slice(1), window.location.origin) : new URL(window.location.pathname, window.location.origin);
|
|
813
|
+
}, Z = async function(e) {
|
|
814
|
+
const t = a(this, x), r = e ? new URL(e, window.location.origin) : d(this, w, rt).call(this), { match: n, journey: s } = await d(this, w, Ce).call(this, r);
|
|
815
|
+
for (const i of s)
|
|
816
|
+
switch (i.kind) {
|
|
817
|
+
case "match":
|
|
818
|
+
t.info(`📍 ${i.message}`);
|
|
819
|
+
break;
|
|
820
|
+
case "redirect":
|
|
821
|
+
t.info(`↩️ ${i.message}`);
|
|
822
|
+
break;
|
|
823
|
+
case "miss":
|
|
824
|
+
t.info(`💀 ${i.message}`);
|
|
825
|
+
break;
|
|
1227
826
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
827
|
+
if (n) {
|
|
828
|
+
const i = this.$pattern.get();
|
|
829
|
+
a(this, he).call(this, n), n.pattern !== i && d(this, w, st).call(this, n);
|
|
830
|
+
} else
|
|
831
|
+
t.crash(new Ct(`Failed to match route '${r.pathname}'`));
|
|
832
|
+
}, Ce = async function(e, t = []) {
|
|
833
|
+
const r = et(a(this, X), e.pathname);
|
|
834
|
+
if (!r)
|
|
835
|
+
return {
|
|
836
|
+
match: null,
|
|
837
|
+
journey: [...t, { kind: "miss", message: `no match for '${e.pathname}'` }]
|
|
838
|
+
};
|
|
839
|
+
let n = r.meta.redirect;
|
|
840
|
+
if (r.meta.beforeMatch && await r.meta.beforeMatch({
|
|
841
|
+
// TODO: Allow setting context variables from here? Would apply to the context of the matched view.
|
|
842
|
+
redirect: (s) => {
|
|
843
|
+
n = s;
|
|
844
|
+
}
|
|
845
|
+
}), n != null) {
|
|
846
|
+
let s;
|
|
847
|
+
if (k(n))
|
|
848
|
+
s = Ot(n, r.params);
|
|
849
|
+
else if (te(n)) {
|
|
850
|
+
const i = {
|
|
851
|
+
path: r.path,
|
|
852
|
+
pattern: r.pattern,
|
|
853
|
+
params: r.params,
|
|
854
|
+
query: r.query
|
|
855
|
+
};
|
|
856
|
+
if (s = await n(i), !k(s))
|
|
857
|
+
throw new Error("Redirect function must return a path to redirect to.");
|
|
858
|
+
s.startsWith("/") || (s = Ee(r.path, s));
|
|
859
|
+
} else
|
|
860
|
+
throw new TypeError("Redirect must either be a path string or a function.");
|
|
861
|
+
return d(this, w, Ce).call(this, new URL(s, window.location.origin), [
|
|
862
|
+
...t,
|
|
863
|
+
{ kind: "redirect", message: `redirecting '${r.path}' -> '${s}'` }
|
|
864
|
+
]);
|
|
865
|
+
} else
|
|
866
|
+
return { match: r, journey: [...t, { kind: "match", message: `matched route '${r.path}'` }] };
|
|
867
|
+
}, /**
|
|
868
|
+
* Takes a matched route and mounts it.
|
|
869
|
+
*/
|
|
870
|
+
st = function(e) {
|
|
871
|
+
const t = e.meta.layers;
|
|
872
|
+
for (let r = 0; r < t.length; r++) {
|
|
873
|
+
const n = t[r], s = a(this, D)[r];
|
|
874
|
+
if ((s == null ? void 0 : s.id) !== n.id) {
|
|
875
|
+
g(this, D, a(this, D).slice(0, r)), s == null || s.node.unmount();
|
|
876
|
+
const i = a(this, D).at(-1), c = ((i == null ? void 0 : i.node) ?? a(this, W).getRootView()).setChildView(n.view);
|
|
877
|
+
a(this, D).push({ id: n.id, node: c });
|
|
1241
878
|
}
|
|
1242
|
-
s(this, S).go(e);
|
|
1243
879
|
}
|
|
1244
|
-
}
|
|
1245
|
-
Le = new WeakMap(), N = new WeakMap(), Z = new WeakMap(), Re = new WeakMap(), S = new WeakMap(), Xe = new WeakMap(), H = new WeakMap(), De = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), he = new WeakMap(), fe = new WeakMap(), de = new WeakMap(), Ne = new WeakMap(), K = new WeakSet(), /**
|
|
880
|
+
}, /**
|
|
1246
881
|
* Parses a route definition object into a set of matchable routes.
|
|
1247
882
|
*
|
|
1248
883
|
* @param route - Route config object.
|
|
1249
884
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
1250
885
|
*/
|
|
1251
|
-
|
|
1252
|
-
if (!(
|
|
886
|
+
Ue = function(e, t = [], r = []) {
|
|
887
|
+
if (!ke(e) || !k(e.path))
|
|
1253
888
|
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
|
|
1254
889
|
if (e.redirect && e.routes)
|
|
1255
890
|
throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
|
|
@@ -1258,217 +893,205 @@ ht = function(e, t = [], r = []) {
|
|
|
1258
893
|
if (!e.view && !e.routes && !e.redirect)
|
|
1259
894
|
throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
|
|
1260
895
|
let n = [];
|
|
1261
|
-
for (const
|
|
1262
|
-
n.push(...
|
|
1263
|
-
n.push(...
|
|
1264
|
-
const
|
|
896
|
+
for (const c of t)
|
|
897
|
+
n.push(...ee(c.path));
|
|
898
|
+
n.push(...ee(e.path)), n[n.length - 1] === "*" && n.pop();
|
|
899
|
+
const s = [];
|
|
1265
900
|
if (e.redirect) {
|
|
1266
|
-
let
|
|
1267
|
-
return
|
|
1268
|
-
pattern: "/" +
|
|
901
|
+
let c = e.redirect;
|
|
902
|
+
return k(c) && (c = Ee(H(n), c), c.startsWith("/") || (c = "/" + c)), s.push({
|
|
903
|
+
pattern: "/" + H([...n, ...ee(e.path)]),
|
|
1269
904
|
meta: {
|
|
1270
|
-
redirect:
|
|
905
|
+
redirect: c
|
|
1271
906
|
}
|
|
1272
|
-
}),
|
|
907
|
+
}), s;
|
|
1273
908
|
}
|
|
1274
|
-
let
|
|
1275
|
-
if (
|
|
1276
|
-
|
|
909
|
+
let i = Je;
|
|
910
|
+
if (te(e.view))
|
|
911
|
+
i = e.view;
|
|
1277
912
|
else if (e.view)
|
|
1278
913
|
throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
|
|
1279
|
-
const
|
|
914
|
+
const f = { id: Y(this, xe)._++, view: i };
|
|
1280
915
|
if (e.routes)
|
|
1281
|
-
for (const
|
|
1282
|
-
|
|
916
|
+
for (const c of e.routes)
|
|
917
|
+
s.push(...d(this, w, Ue).call(this, c, [...t, e], [...r, f]));
|
|
1283
918
|
else
|
|
1284
|
-
|
|
1285
|
-
pattern: parent ?
|
|
919
|
+
s.push({
|
|
920
|
+
pattern: parent ? H([...t.map((c) => c.path), e.path]) : e.path,
|
|
1286
921
|
meta: {
|
|
1287
922
|
pattern: e.path,
|
|
1288
|
-
layers: [...r,
|
|
923
|
+
layers: [...r, f],
|
|
1289
924
|
beforeMatch: e.beforeMatch
|
|
1290
925
|
}
|
|
1291
926
|
});
|
|
1292
|
-
return
|
|
1293
|
-
}, ft = async function({ location: e }) {
|
|
1294
|
-
e.search !== s(this, De) && (b(this, De, e.search), s(this, Ne).call(this, ut(e.search)));
|
|
1295
|
-
const t = vt(s(this, ee), e.pathname);
|
|
1296
|
-
if (!t) {
|
|
1297
|
-
s(this, he).call(this, null), s(this, fe).call(this, e.pathname), s(this, de).call(this, {
|
|
1298
|
-
wildcard: e.pathname
|
|
1299
|
-
});
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
if (t.meta.beforeMatch && await t.meta.beforeMatch({
|
|
1303
|
-
// TODO: Allow setting context variables from here.
|
|
1304
|
-
redirect: (r) => {
|
|
1305
|
-
throw new Error("Redirect not yet implemented.");
|
|
1306
|
-
}
|
|
1307
|
-
}), t.meta.redirect != null)
|
|
1308
|
-
if (typeof t.meta.redirect == "string") {
|
|
1309
|
-
const r = dr(t.meta.redirect, t.params);
|
|
1310
|
-
s(this, N).info(`↩️ redirecting from '${t.path}' to '${r}'`), s(this, S).replace(r);
|
|
1311
|
-
} else if (typeof t.meta.redirect == "function") {
|
|
1312
|
-
const r = {
|
|
1313
|
-
path: t.path,
|
|
1314
|
-
pattern: t.pattern,
|
|
1315
|
-
params: t.params,
|
|
1316
|
-
query: t.query
|
|
1317
|
-
};
|
|
1318
|
-
let n = await t.meta.redirect(r);
|
|
1319
|
-
if (typeof n != "string")
|
|
1320
|
-
throw new Error("Redirect function must return a path to redirect to.");
|
|
1321
|
-
n.startsWith("/") || (n = We(t.path, n)), s(this, N).info(`Redirecting to: '${n}'`), s(this, S).replace(n);
|
|
1322
|
-
} else
|
|
1323
|
-
throw new TypeError("Redirect must either be a path string or a function.");
|
|
1324
|
-
else if (s(this, N).info(`📍 navigating to '${t.path}'`), s(this, fe).call(this, t.path), s(this, de).call(this, t.params), t.pattern !== this.$pattern.get()) {
|
|
1325
|
-
s(this, he).call(this, t.pattern);
|
|
1326
|
-
const r = t.meta.layers;
|
|
1327
|
-
for (let n = 0; n < r.length; n++) {
|
|
1328
|
-
const a = r[n], o = s(this, H)[n];
|
|
1329
|
-
if ((o == null ? void 0 : o.id) !== a.id) {
|
|
1330
|
-
b(this, H, s(this, H).slice(0, n));
|
|
1331
|
-
const p = s(this, H).at(-1);
|
|
1332
|
-
o && o.node.isMounted && o.node.unmount(!1);
|
|
1333
|
-
let l;
|
|
1334
|
-
p ? l = p.node.setChildView(a.view) : l = s(this, Z).rootView.setChildView(a.view), s(this, H).push({ id: a.id, node: l });
|
|
1335
|
-
}
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
927
|
+
return s;
|
|
1338
928
|
};
|
|
1339
|
-
const
|
|
1340
|
-
function
|
|
1341
|
-
function r(
|
|
1342
|
-
return !
|
|
929
|
+
const Pt = /(noopener|noreferrer) (noopener|noreferrer)/, Dt = /^[\w-_]+:/;
|
|
930
|
+
function Tt(o, e, t = window) {
|
|
931
|
+
function r(s) {
|
|
932
|
+
return !s || s === o ? null : s.localName !== "a" || s.href === void 0 ? r(s.parentNode) : s;
|
|
1343
933
|
}
|
|
1344
|
-
function n(
|
|
1345
|
-
if (
|
|
934
|
+
function n(s) {
|
|
935
|
+
if (s.button && s.button !== 0 || s.ctrlKey || s.metaKey || s.altKey || s.shiftKey || s.defaultPrevented)
|
|
1346
936
|
return;
|
|
1347
|
-
const
|
|
1348
|
-
|
|
937
|
+
const i = r(s.target);
|
|
938
|
+
i && (t.location.protocol !== i.protocol || t.location.hostname !== i.hostname || t.location.port !== i.port || i.hasAttribute("data-router-ignore") || i.hasAttribute("download") || i.getAttribute("target") === "_blank" && Pt.test(i.getAttribute("rel")) || Dt.test(i.getAttribute("href")) || (s.preventDefault(), e(i)));
|
|
1349
939
|
}
|
|
1350
|
-
return
|
|
1351
|
-
|
|
940
|
+
return o.addEventListener("click", n), function() {
|
|
941
|
+
o.removeEventListener("click", n);
|
|
1352
942
|
};
|
|
1353
943
|
}
|
|
1354
|
-
function
|
|
944
|
+
function Ot(o, e) {
|
|
1355
945
|
for (const t in e) {
|
|
1356
946
|
const r = e[t].toString();
|
|
1357
|
-
|
|
947
|
+
o = o.replace(`{${t}}`, r).replace(`{#${t}}`, r);
|
|
1358
948
|
}
|
|
1359
|
-
return
|
|
949
|
+
return o;
|
|
950
|
+
}
|
|
951
|
+
function jt(o) {
|
|
952
|
+
for (const e of o)
|
|
953
|
+
if (e.meta.redirect) {
|
|
954
|
+
let t;
|
|
955
|
+
if (!te(e.meta.redirect)) if (k(e.meta.redirect)) {
|
|
956
|
+
if (t = e.meta.redirect, !et(o, t, {
|
|
957
|
+
willMatch(n) {
|
|
958
|
+
return n !== e;
|
|
959
|
+
}
|
|
960
|
+
}))
|
|
961
|
+
throw new Error(`Found a redirect to an undefined URL. From '${e.pattern}' to '${e.meta.redirect}'`);
|
|
962
|
+
} else
|
|
963
|
+
throw new TypeError(`Expected a string or redirect function. Got: ${e.meta.redirect}`);
|
|
964
|
+
}
|
|
1360
965
|
}
|
|
1361
|
-
|
|
1362
|
-
|
|
966
|
+
class Ct extends Error {
|
|
967
|
+
}
|
|
968
|
+
var O, ue, j, B, fe, de, me, ge, pe, we, C, $, U, Fe;
|
|
969
|
+
class Ut {
|
|
1363
970
|
constructor() {
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
971
|
+
p(this, "batch");
|
|
972
|
+
p(this, "http");
|
|
973
|
+
p(this, "i18n");
|
|
974
|
+
p(this, "router");
|
|
975
|
+
l(this, O, !1);
|
|
976
|
+
l(this, ue, "production");
|
|
977
|
+
l(this, j);
|
|
978
|
+
l(this, B);
|
|
979
|
+
l(this, fe, bt);
|
|
980
|
+
l(this, de, Be());
|
|
981
|
+
l(this, me, []);
|
|
982
|
+
l(this, ge, []);
|
|
983
|
+
l(this, pe, []);
|
|
984
|
+
l(this, we, []);
|
|
985
|
+
l(this, C, {
|
|
1379
986
|
root: this,
|
|
1380
987
|
data: {}
|
|
1381
988
|
});
|
|
1382
|
-
|
|
989
|
+
l(this, $, {
|
|
1383
990
|
info: "development",
|
|
1384
991
|
log: "development",
|
|
1385
992
|
warn: "development",
|
|
1386
993
|
error: !0
|
|
1387
994
|
});
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
this
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
},
|
|
1404
|
-
get rootView() {
|
|
1405
|
-
return s(e, re);
|
|
1406
|
-
}
|
|
1407
|
-
});
|
|
995
|
+
l(this, U, ze("*,-dolla/*"));
|
|
996
|
+
// Registration functions for modules.
|
|
997
|
+
// All modules will be registered before mount.
|
|
998
|
+
l(this, Fe, []);
|
|
999
|
+
p(this, "watch", a(this, de).watch);
|
|
1000
|
+
p(this, "createState", Ve);
|
|
1001
|
+
p(this, "createSettableState", ct);
|
|
1002
|
+
p(this, "toSettableState", ht);
|
|
1003
|
+
p(this, "toState", ut);
|
|
1004
|
+
p(this, "valueOf", ft);
|
|
1005
|
+
p(this, "derive", F);
|
|
1006
|
+
p(this, "createWatcher", Be);
|
|
1007
|
+
p(this, "createRef", dt);
|
|
1008
|
+
p(this, "isRef", mt);
|
|
1009
|
+
this.batch = new $t(this), this.http = new vt(this), this.i18n = new Lt(this), this.router = new Nt(this);
|
|
1408
1010
|
}
|
|
1409
1011
|
/**
|
|
1410
1012
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
1411
1013
|
*/
|
|
1412
1014
|
get isMounted() {
|
|
1413
|
-
return
|
|
1015
|
+
return a(this, O);
|
|
1414
1016
|
}
|
|
1415
1017
|
/**
|
|
1416
1018
|
* Get the current environment that this app is running in.
|
|
1417
1019
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1418
1020
|
*/
|
|
1419
1021
|
getEnv() {
|
|
1420
|
-
return
|
|
1022
|
+
return a(this, ue);
|
|
1421
1023
|
}
|
|
1422
1024
|
/**
|
|
1423
1025
|
* Sets the environment that this app is running in.
|
|
1424
1026
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1425
1027
|
*/
|
|
1426
1028
|
setEnv(e) {
|
|
1427
|
-
|
|
1029
|
+
g(this, ue, e);
|
|
1428
1030
|
}
|
|
1429
1031
|
/**
|
|
1430
1032
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1431
1033
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1432
1034
|
*/
|
|
1433
1035
|
setCrashView(e) {
|
|
1434
|
-
|
|
1036
|
+
g(this, fe, e);
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
|
|
1040
|
+
*/
|
|
1041
|
+
getRootElement() {
|
|
1042
|
+
return a(this, j);
|
|
1435
1043
|
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
|
|
1046
|
+
*/
|
|
1047
|
+
getRootView() {
|
|
1048
|
+
return a(this, B);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Registers a Dolla module.
|
|
1052
|
+
*/
|
|
1053
|
+
// use<O>(module: DollaModule<O>, options: O) {
|
|
1054
|
+
// this.#modules.push(async () => {
|
|
1055
|
+
// return module.register({ root: this, options });
|
|
1056
|
+
// });
|
|
1057
|
+
// return this;
|
|
1058
|
+
// }
|
|
1436
1059
|
/**
|
|
1437
1060
|
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
1438
1061
|
*/
|
|
1439
1062
|
set(e, t) {
|
|
1440
|
-
return
|
|
1063
|
+
return a(this, C).data[e] = t, t;
|
|
1441
1064
|
}
|
|
1442
1065
|
/**
|
|
1443
1066
|
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
1444
1067
|
*/
|
|
1445
1068
|
get(e) {
|
|
1446
|
-
return
|
|
1069
|
+
return a(this, C).data[e] ?? null;
|
|
1447
1070
|
}
|
|
1448
1071
|
/**
|
|
1449
1072
|
* Returns an object of all context variables stored at the app level.
|
|
1450
1073
|
*/
|
|
1451
1074
|
getAll() {
|
|
1452
|
-
return { ...
|
|
1075
|
+
return { ...a(this, C).data };
|
|
1453
1076
|
}
|
|
1454
1077
|
async mount(e, t) {
|
|
1455
|
-
if (
|
|
1078
|
+
if (a(this, O))
|
|
1456
1079
|
throw new Error("Dolla is already mounted.");
|
|
1457
|
-
if (
|
|
1080
|
+
if (k(e)) {
|
|
1458
1081
|
const n = document.querySelector(e);
|
|
1459
|
-
|
|
1082
|
+
He(HTMLElement, n, `Selector '${e}' did not match any element.`), g(this, j, n);
|
|
1460
1083
|
} else
|
|
1461
|
-
|
|
1462
|
-
const r =
|
|
1463
|
-
|
|
1464
|
-
for (const n of
|
|
1084
|
+
He(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), g(this, j, e);
|
|
1085
|
+
const r = gt(t ?? Je);
|
|
1086
|
+
g(this, B, this.constructView(r.type, r.props)), await Promise.all(a(this, Fe).map((n) => n())), await Promise.all(a(this, me).map((n) => n())), a(this, B).mount(a(this, j)), g(this, O, !0);
|
|
1087
|
+
for (const n of a(this, ge))
|
|
1465
1088
|
n();
|
|
1466
1089
|
}
|
|
1467
1090
|
async unmount() {
|
|
1468
1091
|
var e;
|
|
1469
|
-
if (
|
|
1470
|
-
await Promise.all(
|
|
1471
|
-
for (const t of
|
|
1092
|
+
if (a(this, O)) {
|
|
1093
|
+
await Promise.all(a(this, pe).map((t) => t())), (e = a(this, B)) == null || e.unmount(!1), a(this, de).stopAll(), g(this, O, !1);
|
|
1094
|
+
for (const t of a(this, we))
|
|
1472
1095
|
t();
|
|
1473
1096
|
}
|
|
1474
1097
|
}
|
|
@@ -1477,26 +1100,26 @@ class pr {
|
|
|
1477
1100
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1478
1101
|
*/
|
|
1479
1102
|
beforeMount(e) {
|
|
1480
|
-
|
|
1103
|
+
a(this, me).push(e);
|
|
1481
1104
|
}
|
|
1482
1105
|
/**
|
|
1483
1106
|
* Registers a `callback` to run after the app is mounted.
|
|
1484
1107
|
*/
|
|
1485
1108
|
onMount(e) {
|
|
1486
|
-
|
|
1109
|
+
a(this, ge).push(e);
|
|
1487
1110
|
}
|
|
1488
1111
|
/**
|
|
1489
1112
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1490
1113
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1491
1114
|
*/
|
|
1492
1115
|
beforeUnmount(e) {
|
|
1493
|
-
|
|
1116
|
+
a(this, pe).push(e);
|
|
1494
1117
|
}
|
|
1495
1118
|
/**
|
|
1496
1119
|
* Registers a `callback` to run after the app is unmounted.
|
|
1497
1120
|
*/
|
|
1498
1121
|
onUnmount(e) {
|
|
1499
|
-
|
|
1122
|
+
a(this, we).push(e);
|
|
1500
1123
|
}
|
|
1501
1124
|
/**
|
|
1502
1125
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
@@ -1504,28 +1127,28 @@ class pr {
|
|
|
1504
1127
|
setLoggles(e) {
|
|
1505
1128
|
for (const t in e) {
|
|
1506
1129
|
const r = e[t];
|
|
1507
|
-
r && (
|
|
1130
|
+
r && (a(this, $)[t] = r);
|
|
1508
1131
|
}
|
|
1509
1132
|
}
|
|
1510
1133
|
setLogFilter(e) {
|
|
1511
|
-
|
|
1134
|
+
g(this, U, ze(e));
|
|
1512
1135
|
}
|
|
1513
1136
|
createLogger(e, t) {
|
|
1514
|
-
const r = (t == null ? void 0 : t.console) ??
|
|
1137
|
+
const r = (t == null ? void 0 : t.console) ?? Vt(), n = this;
|
|
1515
1138
|
return {
|
|
1516
|
-
setName(
|
|
1517
|
-
return e =
|
|
1139
|
+
setName(s) {
|
|
1140
|
+
return e = s, this;
|
|
1518
1141
|
},
|
|
1519
1142
|
get info() {
|
|
1520
|
-
var
|
|
1521
|
-
if (
|
|
1522
|
-
return
|
|
1143
|
+
var s;
|
|
1144
|
+
if (a(n, $).info === !1 || k(a(n, $).info) && a(n, $).info !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1145
|
+
return be;
|
|
1523
1146
|
{
|
|
1524
|
-
let
|
|
1525
|
-
return t != null && t.uid ?
|
|
1147
|
+
let i = `%c${e}`;
|
|
1148
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.info.bind(
|
|
1526
1149
|
r,
|
|
1527
|
-
|
|
1528
|
-
`color:${
|
|
1150
|
+
i,
|
|
1151
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1529
1152
|
"color:#777",
|
|
1530
1153
|
"color:#aaa",
|
|
1531
1154
|
"color:#777"
|
|
@@ -1533,15 +1156,15 @@ class pr {
|
|
|
1533
1156
|
}
|
|
1534
1157
|
},
|
|
1535
1158
|
get log() {
|
|
1536
|
-
var
|
|
1537
|
-
if (
|
|
1538
|
-
return
|
|
1159
|
+
var s;
|
|
1160
|
+
if (a(n, $).log === !1 || k(a(n, $).log) && a(n, $).log !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1161
|
+
return be;
|
|
1539
1162
|
{
|
|
1540
|
-
let
|
|
1541
|
-
return t != null && t.uid ?
|
|
1163
|
+
let i = `%c${e}`;
|
|
1164
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.log.bind(
|
|
1542
1165
|
r,
|
|
1543
|
-
|
|
1544
|
-
`color:${
|
|
1166
|
+
i,
|
|
1167
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1545
1168
|
"color:#777",
|
|
1546
1169
|
"color:#aaa",
|
|
1547
1170
|
"color:#777"
|
|
@@ -1549,15 +1172,15 @@ class pr {
|
|
|
1549
1172
|
}
|
|
1550
1173
|
},
|
|
1551
1174
|
get warn() {
|
|
1552
|
-
var
|
|
1553
|
-
if (
|
|
1554
|
-
return
|
|
1175
|
+
var s;
|
|
1176
|
+
if (a(n, $).warn === !1 || k(a(n, $).warn) && a(n, $).warn !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1177
|
+
return be;
|
|
1555
1178
|
{
|
|
1556
|
-
let
|
|
1557
|
-
return t != null && t.uid ?
|
|
1179
|
+
let i = `%c${e}`;
|
|
1180
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.warn.bind(
|
|
1558
1181
|
r,
|
|
1559
|
-
|
|
1560
|
-
`color:${
|
|
1182
|
+
i,
|
|
1183
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1561
1184
|
"color:#777",
|
|
1562
1185
|
"color:#aaa",
|
|
1563
1186
|
"color:#777"
|
|
@@ -1565,27 +1188,27 @@ class pr {
|
|
|
1565
1188
|
}
|
|
1566
1189
|
},
|
|
1567
1190
|
get error() {
|
|
1568
|
-
var
|
|
1569
|
-
if (
|
|
1570
|
-
return
|
|
1191
|
+
var s;
|
|
1192
|
+
if (a(n, $).error === !1 || k(a(n, $).error) && a(n, $).error !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1193
|
+
return be;
|
|
1571
1194
|
{
|
|
1572
|
-
let
|
|
1573
|
-
return t != null && t.uid ?
|
|
1195
|
+
let i = `%c${e}`;
|
|
1196
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.error.bind(
|
|
1574
1197
|
r,
|
|
1575
|
-
|
|
1576
|
-
`color:${
|
|
1198
|
+
i,
|
|
1199
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1577
1200
|
"color:#777",
|
|
1578
1201
|
"color:#aaa",
|
|
1579
1202
|
"color:#777"
|
|
1580
1203
|
);
|
|
1581
1204
|
}
|
|
1582
1205
|
},
|
|
1583
|
-
crash(
|
|
1584
|
-
throw n.isMounted && (n.unmount(), n.constructView(
|
|
1585
|
-
error:
|
|
1206
|
+
crash(s) {
|
|
1207
|
+
throw n.isMounted && (n.unmount(), n.constructView(a(n, fe), {
|
|
1208
|
+
error: s,
|
|
1586
1209
|
loggerName: e,
|
|
1587
1210
|
uid: t == null ? void 0 : t.uid
|
|
1588
|
-
}).mount(
|
|
1211
|
+
}).mount(a(n, j))), s;
|
|
1589
1212
|
}
|
|
1590
1213
|
};
|
|
1591
1214
|
}
|
|
@@ -1593,41 +1216,50 @@ class pr {
|
|
|
1593
1216
|
*
|
|
1594
1217
|
*/
|
|
1595
1218
|
constructView(e, t, r = []) {
|
|
1596
|
-
return new
|
|
1219
|
+
return new pt(a(this, C), e, t, r);
|
|
1597
1220
|
}
|
|
1598
1221
|
/**
|
|
1599
1222
|
*
|
|
1600
1223
|
*/
|
|
1601
1224
|
constructMarkup(e) {
|
|
1602
|
-
return
|
|
1225
|
+
return wt(yt(a(this, C), e));
|
|
1603
1226
|
}
|
|
1604
1227
|
}
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1228
|
+
O = new WeakMap(), ue = new WeakMap(), j = new WeakMap(), B = new WeakMap(), fe = new WeakMap(), de = new WeakMap(), me = new WeakMap(), ge = new WeakMap(), pe = new WeakMap(), we = new WeakMap(), C = new WeakMap(), $ = new WeakMap(), U = new WeakMap(), Fe = new WeakMap();
|
|
1229
|
+
function Vt() {
|
|
1230
|
+
if (typeof window < "u" && window.console)
|
|
1231
|
+
return window.console;
|
|
1232
|
+
if (typeof global < "u" && global.console)
|
|
1233
|
+
return global.console;
|
|
1234
|
+
}
|
|
1235
|
+
const Ke = new Ut(), Wt = Ke.i18n.t.bind(Ke.i18n);
|
|
1236
|
+
function _t(o) {
|
|
1237
|
+
typeof window < "u" && (window.DOLLA_DEV_DEBUG = o);
|
|
1609
1238
|
}
|
|
1610
|
-
function
|
|
1239
|
+
function Gt() {
|
|
1611
1240
|
return typeof window < "u" ? window.DOLLA_DEV_DEBUG === !0 : !1;
|
|
1612
1241
|
}
|
|
1613
1242
|
export {
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1243
|
+
it as cond,
|
|
1244
|
+
gt as createMarkup,
|
|
1245
|
+
dt as createRef,
|
|
1246
|
+
ct as createSettableState,
|
|
1247
|
+
Ht as createSetter,
|
|
1248
|
+
Ve as createState,
|
|
1249
|
+
ot as deepEqual,
|
|
1250
|
+
Ke as default,
|
|
1251
|
+
F as derive,
|
|
1252
|
+
Gt as getDevDebug,
|
|
1253
|
+
Ie as html,
|
|
1254
|
+
mt as isRef,
|
|
1255
|
+
Kt as portal,
|
|
1256
|
+
Qt as repeat,
|
|
1257
|
+
_t as setDevDebug,
|
|
1258
|
+
_e as shallowEqual,
|
|
1259
|
+
Jt as strictEqual,
|
|
1260
|
+
Wt as t,
|
|
1261
|
+
ht as toSettableState,
|
|
1262
|
+
ut as toState,
|
|
1263
|
+
ft as valueOf
|
|
1632
1264
|
};
|
|
1633
1265
|
//# sourceMappingURL=index.js.map
|