@manyducks.co/dolla 2.0.0-alpha.22 → 2.0.0-alpha.24
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 +32 -22
- package/dist/core/dolla.d.ts +19 -3
- package/dist/core/markup.d.ts +5 -5
- package/dist/core/nodes/cond.d.ts +4 -2
- package/dist/core/nodes/html.d.ts +4 -0
- package/dist/core/nodes/observer.d.ts +4 -1
- package/dist/core/nodes/outlet.d.ts +10 -14
- package/dist/core/nodes/portal.d.ts +3 -1
- package/dist/core/nodes/repeat.d.ts +5 -3
- package/dist/core/nodes/text.d.ts +2 -0
- package/dist/core/{view.d.ts → nodes/view.d.ts} +8 -6
- package/dist/core/state.d.ts +3 -4
- package/dist/core/symbols.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +599 -555
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +3 -3
- package/dist/jsx-runtime.js +2 -2
- package/dist/modules/http.d.ts +2 -0
- package/dist/modules/i18n.d.ts +1 -1
- package/dist/modules/router.d.ts +15 -24
- package/dist/{passthrough-CrReqVVB.js → passthrough-BeKX_qRr.js} +553 -542
- package/dist/passthrough-BeKX_qRr.js.map +1 -0
- package/dist/typeChecking.d.ts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/views/passthrough.d.ts +1 -1
- package/docs/http.md +16 -0
- package/docs/router.md +19 -0
- package/docs/setup.md +22 -0
- package/docs/states.md +85 -2
- package/index.d.ts +2 -2
- package/notes/TODO.md +6 -0
- package/notes/scratch.md +7 -7
- package/package.json +1 -2
- package/vite.config.js +0 -10
- package/dist/passthrough-CrReqVVB.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var nt = Object.defineProperty;
|
|
2
|
+
var Ae = (o) => {
|
|
3
3
|
throw TypeError(o);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var a = (o, e, t) => (
|
|
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 a(o, e,
|
|
13
|
+
return a(o, e, r);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import { h as
|
|
17
|
-
import { B as
|
|
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-BeKX_qRr.js";
|
|
17
|
+
import { B as Ht, D as Kt, E as Qt, C as Jt } from "./passthrough-BeKX_qRr.js";
|
|
18
|
+
function bt(o) {
|
|
19
|
+
return Ie`
|
|
20
20
|
<div
|
|
21
21
|
style=${{
|
|
22
22
|
backgroundColor: "#880000",
|
|
@@ -30,7 +30,7 @@ function yt(o) {
|
|
|
30
30
|
<h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
|
|
31
31
|
<p style=${{ marginBottom: "0.25rem" }}>
|
|
32
32
|
<span style=${{ fontFamily: "monospace" }}>${o.loggerName}</span>
|
|
33
|
-
${
|
|
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
|
|
@@ -62,80 +62,83 @@ function yt(o) {
|
|
|
62
62
|
</div>
|
|
63
63
|
`;
|
|
64
64
|
}
|
|
65
|
-
var
|
|
66
|
-
class
|
|
65
|
+
var re, K, N, V, A, Q, Re, M, se, q, Ne, ve;
|
|
66
|
+
class $t {
|
|
67
67
|
constructor(e) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
l(this, q);
|
|
69
|
+
l(this, re);
|
|
70
|
+
l(this, K);
|
|
71
71
|
// Keys ensure only the most recent callback queued with a certain key
|
|
72
72
|
// will be called, keeping DOM operations to a minimum.
|
|
73
|
-
|
|
73
|
+
l(this, N, /* @__PURE__ */ new Map());
|
|
74
74
|
// All unkeyed writes are run on every batch.
|
|
75
|
-
|
|
75
|
+
l(this, V, []);
|
|
76
76
|
// All read callbacks are run before updates on every batch.
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
l(this, A, []);
|
|
78
|
+
l(this, Q, !1);
|
|
79
79
|
// When true, batches that would exceed 16ms will be split and deferred to a rAF.
|
|
80
80
|
// This may not be desirable, because while it does prevent hitching it sometimes leaves
|
|
81
81
|
// the state partially rendered for a brief second and certain elements can be seen to update after the fact.
|
|
82
82
|
// But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
87
|
}
|
|
88
88
|
/**
|
|
89
89
|
* Queues a callback that runs before the next batch of writes.
|
|
90
90
|
*/
|
|
91
91
|
read(e) {
|
|
92
|
-
a(this, A).push(e), d(this,
|
|
92
|
+
a(this, A).push(e), d(this, q, Ne).call(this);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* Queues a callback to run in the next render batch.
|
|
96
96
|
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
97
97
|
*/
|
|
98
98
|
write(e, t) {
|
|
99
|
-
t ? a(this,
|
|
99
|
+
t ? a(this, N).set(t, e) : a(this, V).push(e), d(this, q, Ne).call(this);
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
|
-
|
|
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
103
|
if (!a(this, Q)) {
|
|
104
|
-
|
|
105
|
-
const e = a(this,
|
|
104
|
+
g(this, Q, !0);
|
|
105
|
+
const e = a(this, re).getEnv() === "development";
|
|
106
106
|
queueMicrotask(() => {
|
|
107
|
-
d(this,
|
|
107
|
+
d(this, q, ve).call(this, e);
|
|
108
108
|
});
|
|
109
109
|
}
|
|
110
|
-
},
|
|
110
|
+
}, ve = function(e = !1) {
|
|
111
111
|
const t = performance.now();
|
|
112
|
-
let s = 0;
|
|
113
|
-
const n = a(this, A).length + a(this, P).size + a(this, C).length;
|
|
114
112
|
let r = 0;
|
|
115
|
-
const
|
|
116
|
-
|
|
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
117
|
), requestAnimationFrame(() => {
|
|
118
|
-
d(this,
|
|
119
|
-
}), !0) : !1), f = [...a(this,
|
|
120
|
-
let
|
|
121
|
-
for (;
|
|
122
|
-
if (
|
|
123
|
-
for ([
|
|
124
|
-
if (
|
|
125
|
-
for (;
|
|
126
|
-
if (
|
|
127
|
-
e && a(this, K)[
|
|
128
|
-
`${
|
|
129
|
-
),
|
|
130
|
-
d(this,
|
|
131
|
-
}) :
|
|
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
132
|
};
|
|
133
|
-
var
|
|
134
|
-
class
|
|
135
|
-
constructor() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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"));
|
|
139
142
|
}
|
|
140
143
|
/**
|
|
141
144
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -144,65 +147,66 @@ class $t {
|
|
|
144
147
|
* @param middleware - A middleware function that will intercept requests.
|
|
145
148
|
*/
|
|
146
149
|
use(e) {
|
|
147
|
-
return a(this,
|
|
148
|
-
a(this,
|
|
150
|
+
return a(this, I).push(e), () => {
|
|
151
|
+
a(this, I).splice(a(this, I).indexOf(e), 1);
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
154
|
async get(e, t) {
|
|
152
|
-
return d(this,
|
|
155
|
+
return d(this, S, L).call(this, "get", e, t);
|
|
153
156
|
}
|
|
154
157
|
async put(e, t) {
|
|
155
|
-
return d(this,
|
|
158
|
+
return d(this, S, L).call(this, "put", e, t);
|
|
156
159
|
}
|
|
157
160
|
async patch(e, t) {
|
|
158
|
-
return d(this,
|
|
161
|
+
return d(this, S, L).call(this, "patch", e, t);
|
|
159
162
|
}
|
|
160
163
|
async post(e, t) {
|
|
161
|
-
return d(this,
|
|
164
|
+
return d(this, S, L).call(this, "post", e, t);
|
|
162
165
|
}
|
|
163
166
|
async delete(e, t) {
|
|
164
|
-
return d(this,
|
|
167
|
+
return d(this, S, L).call(this, "delete", e, t);
|
|
165
168
|
}
|
|
166
169
|
async head(e, t) {
|
|
167
|
-
return d(this,
|
|
170
|
+
return d(this, S, L).call(this, "head", e, t);
|
|
168
171
|
}
|
|
169
172
|
async options(e, t) {
|
|
170
|
-
return d(this,
|
|
173
|
+
return d(this, S, L).call(this, "options", e, t);
|
|
171
174
|
}
|
|
172
175
|
async trace(e, t) {
|
|
173
|
-
return d(this,
|
|
176
|
+
return d(this, S, L).call(this, "trace", e, t);
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
|
-
|
|
177
|
-
return
|
|
178
|
-
...
|
|
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({
|
|
181
|
+
...r,
|
|
179
182
|
method: e,
|
|
180
183
|
uri: t,
|
|
181
|
-
middleware: a(this,
|
|
182
|
-
fetch: a(this,
|
|
184
|
+
middleware: a(this, I),
|
|
185
|
+
fetch: a(this, Se),
|
|
186
|
+
logger: a(this, ne)
|
|
183
187
|
});
|
|
184
188
|
};
|
|
185
|
-
function
|
|
189
|
+
function Et() {
|
|
186
190
|
if (typeof window < "u" && window.fetch)
|
|
187
191
|
return window.fetch.bind(window);
|
|
188
192
|
if (typeof global < "u" && global.fetch)
|
|
189
193
|
return global.fetch.bind(global);
|
|
190
194
|
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
191
195
|
}
|
|
192
|
-
class
|
|
196
|
+
class kt extends Error {
|
|
193
197
|
constructor(t) {
|
|
194
|
-
const { status:
|
|
198
|
+
const { status: r, statusText: n, method: s, uri: i } = t, f = `${r} ${n}: Request failed (${s.toUpperCase()} ${i})`;
|
|
195
199
|
super(f);
|
|
196
|
-
|
|
200
|
+
p(this, "response");
|
|
197
201
|
this.response = t;
|
|
198
202
|
}
|
|
199
203
|
}
|
|
200
|
-
async function
|
|
201
|
-
const { headers: e, query: t, fetch:
|
|
204
|
+
async function Rt(o) {
|
|
205
|
+
const { headers: e, query: t, fetch: r, middleware: n, logger: s } = o, i = {
|
|
202
206
|
method: o.method,
|
|
203
207
|
uri: o.uri,
|
|
204
208
|
get sameOrigin() {
|
|
205
|
-
return !
|
|
209
|
+
return !i.uri.startsWith("http");
|
|
206
210
|
},
|
|
207
211
|
query: new URLSearchParams(),
|
|
208
212
|
headers: new Headers(),
|
|
@@ -210,93 +214,94 @@ async function kt(o) {
|
|
|
210
214
|
};
|
|
211
215
|
if (e)
|
|
212
216
|
if (e instanceof Map || e instanceof Headers)
|
|
213
|
-
e.forEach((
|
|
214
|
-
|
|
217
|
+
e.forEach((u, m) => {
|
|
218
|
+
i.headers.set(m, u);
|
|
215
219
|
});
|
|
216
220
|
else if (e != null && typeof e == "object" && !Array.isArray(e))
|
|
217
|
-
for (const
|
|
218
|
-
const
|
|
219
|
-
|
|
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));
|
|
220
224
|
}
|
|
221
225
|
else
|
|
222
226
|
throw new TypeError(`Unknown headers type. Got: ${e}`);
|
|
223
227
|
if (t)
|
|
224
228
|
if (t instanceof Map || t instanceof URLSearchParams)
|
|
225
|
-
t.forEach((
|
|
226
|
-
|
|
229
|
+
t.forEach((u, m) => {
|
|
230
|
+
i.query.set(m, u);
|
|
227
231
|
});
|
|
228
232
|
else if (t != null && typeof t == "object" && !Array.isArray(t))
|
|
229
|
-
for (const
|
|
230
|
-
const
|
|
231
|
-
|
|
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));
|
|
232
236
|
}
|
|
233
237
|
else
|
|
234
238
|
throw new TypeError(`Unknown query params type. Got: ${t}`);
|
|
235
|
-
let
|
|
236
|
-
const
|
|
237
|
-
const
|
|
238
|
-
let
|
|
239
|
-
!
|
|
240
|
-
const
|
|
241
|
-
method:
|
|
242
|
-
headers:
|
|
243
|
-
body:
|
|
244
|
-
}),
|
|
245
|
-
let
|
|
246
|
-
y != null && y.includes("application/json") ?
|
|
247
|
-
method:
|
|
248
|
-
uri:
|
|
249
|
-
status:
|
|
250
|
-
statusText:
|
|
251
|
-
headers:
|
|
252
|
-
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
|
|
253
257
|
};
|
|
254
258
|
};
|
|
255
259
|
if (n.length > 0) {
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
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));
|
|
259
263
|
};
|
|
260
|
-
await
|
|
264
|
+
await u()();
|
|
261
265
|
} else
|
|
262
|
-
await
|
|
263
|
-
if (
|
|
264
|
-
throw new
|
|
265
|
-
return
|
|
266
|
+
await c();
|
|
267
|
+
if (f.status < 200 || f.status >= 400)
|
|
268
|
+
throw new kt(f);
|
|
269
|
+
return f;
|
|
266
270
|
}
|
|
267
|
-
var Me, J,
|
|
271
|
+
var Me, J, z, Pe, Xe;
|
|
268
272
|
class St {
|
|
269
273
|
constructor(e, t) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
l(this, z);
|
|
275
|
+
p(this, "dolla");
|
|
276
|
+
p(this, "config");
|
|
277
|
+
l(this, Me, !1);
|
|
278
|
+
l(this, J, /* @__PURE__ */ new Map());
|
|
275
279
|
this.config = e, this.dolla = t;
|
|
276
280
|
}
|
|
277
281
|
async load() {
|
|
278
282
|
let e;
|
|
279
283
|
if (!a(this, Me)) {
|
|
280
|
-
if (
|
|
281
|
-
if (e = await this.config.fetch(), !
|
|
284
|
+
if (te(this.config.fetch)) {
|
|
285
|
+
if (e = await this.config.fetch(), !ke(e))
|
|
282
286
|
throw new Error(`Fetch function did not return an object of language strings: ${e}`);
|
|
283
|
-
} else if (
|
|
284
|
-
const t = await
|
|
285
|
-
if (t.
|
|
286
|
-
|
|
287
|
-
|
|
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;
|
|
288
293
|
else
|
|
289
294
|
throw new Error(
|
|
290
|
-
`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}`
|
|
291
296
|
);
|
|
292
|
-
else
|
|
297
|
+
} else
|
|
293
298
|
throw new Error("HTTP request failed.");
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
301
|
if (e) {
|
|
297
|
-
const t = d(this,
|
|
298
|
-
for (const
|
|
299
|
-
a(this, J).set(
|
|
302
|
+
const t = d(this, z, Pe).call(this, e);
|
|
303
|
+
for (const r of t)
|
|
304
|
+
a(this, J).set(r[0], r[1]);
|
|
300
305
|
} else
|
|
301
306
|
throw new Error("Language could not be loaded.");
|
|
302
307
|
}
|
|
@@ -309,128 +314,128 @@ class St {
|
|
|
309
314
|
return a(this, J).has(e);
|
|
310
315
|
}
|
|
311
316
|
}
|
|
312
|
-
Me = new WeakMap(), J = new WeakMap(),
|
|
313
|
-
const
|
|
317
|
+
Me = new WeakMap(), J = new WeakMap(), z = new WeakSet(), Pe = function(e, t = []) {
|
|
318
|
+
const r = [];
|
|
314
319
|
for (const n in e)
|
|
315
|
-
switch (
|
|
320
|
+
switch (We(e[n])) {
|
|
316
321
|
case "string":
|
|
317
|
-
|
|
322
|
+
r.push([[...t, n].join("."), d(this, z, Xe).call(this, e[n])]);
|
|
318
323
|
break;
|
|
319
324
|
case "object":
|
|
320
|
-
|
|
325
|
+
r.push(...d(this, z, Pe).call(this, e[n], [...t, n]));
|
|
321
326
|
break;
|
|
322
327
|
default:
|
|
323
328
|
throw new Error(
|
|
324
|
-
`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])}`
|
|
325
330
|
);
|
|
326
331
|
}
|
|
327
|
-
return
|
|
328
|
-
},
|
|
332
|
+
return r;
|
|
333
|
+
}, Xe = function(e) {
|
|
329
334
|
let t;
|
|
330
|
-
((
|
|
331
|
-
|
|
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";
|
|
332
337
|
})(t || (t = {}));
|
|
333
|
-
const
|
|
338
|
+
const r = {
|
|
334
339
|
segments: []
|
|
335
340
|
};
|
|
336
|
-
let n = "",
|
|
337
|
-
const
|
|
341
|
+
let n = "", s = 0, i = 0, f, c, u;
|
|
342
|
+
const m = () => {
|
|
338
343
|
f = {
|
|
339
344
|
type: 1,
|
|
340
345
|
name: "",
|
|
341
346
|
formats: []
|
|
342
347
|
};
|
|
343
|
-
},
|
|
344
|
-
|
|
348
|
+
}, b = () => {
|
|
349
|
+
c = {
|
|
345
350
|
name: "",
|
|
346
351
|
options: {}
|
|
347
352
|
};
|
|
348
353
|
};
|
|
349
|
-
for (;
|
|
350
|
-
if (i !== 0 && e[
|
|
351
|
-
|
|
354
|
+
for (; s < e.length; ) {
|
|
355
|
+
if (i !== 0 && e[s] === " ") {
|
|
356
|
+
s++;
|
|
352
357
|
continue;
|
|
353
358
|
}
|
|
354
359
|
switch (i) {
|
|
355
360
|
case 0:
|
|
356
|
-
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++);
|
|
357
362
|
break;
|
|
358
363
|
case 1:
|
|
359
|
-
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++);
|
|
360
365
|
break;
|
|
361
366
|
case 2:
|
|
362
|
-
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++);
|
|
363
368
|
break;
|
|
364
369
|
case 3:
|
|
365
|
-
e[
|
|
370
|
+
e[s] === ")" || (e[s] === ":" ? (i = 4, s += 1, u = n, n = "") : e[s] === "}" && e[s + 1] === "}" || (n += e[s], s++));
|
|
366
371
|
break;
|
|
367
372
|
case 4:
|
|
368
|
-
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++);
|
|
369
374
|
break;
|
|
370
375
|
case 5:
|
|
371
|
-
e[
|
|
376
|
+
e[s] === "|" ? (i = 2, s += 1, b()) : e[s] === "}" && e[s + 1] === "}" && (i = 0, s += 2, r.segments.push(f));
|
|
372
377
|
break;
|
|
373
378
|
}
|
|
374
379
|
}
|
|
375
|
-
return i === 0 && n.length > 0 &&
|
|
380
|
+
return i === 0 && n.length > 0 && r.segments.push({ type: 0, text: n }), r;
|
|
376
381
|
};
|
|
377
|
-
var ae,
|
|
378
|
-
class
|
|
382
|
+
var ae, P, v, ie, oe, le, ce, E, Ye, De, Te, Oe, Ze;
|
|
383
|
+
class Lt {
|
|
379
384
|
constructor(e) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
const [t,
|
|
391
|
-
this.$locale = t,
|
|
392
|
-
a(this,
|
|
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));
|
|
393
398
|
});
|
|
394
399
|
}
|
|
395
400
|
get locales() {
|
|
396
|
-
return [...a(this,
|
|
401
|
+
return [...a(this, v).keys()];
|
|
397
402
|
}
|
|
398
403
|
setup(e) {
|
|
399
404
|
if (e.translations.forEach((t) => {
|
|
400
|
-
a(this,
|
|
405
|
+
a(this, v).set(t.locale, new St(t, a(this, ae)));
|
|
401
406
|
}), e.locale && e.locale !== "auto") {
|
|
402
|
-
if (!e.translations.some((
|
|
407
|
+
if (!e.translations.some((r) => r.locale === e.locale))
|
|
403
408
|
throw new Error(`Initial locale '${e.locale}' is not registered in the locales array.`);
|
|
404
|
-
|
|
409
|
+
g(this, le, e.locale);
|
|
405
410
|
}
|
|
406
|
-
a(this,
|
|
407
|
-
`${a(this,
|
|
411
|
+
a(this, P).info(
|
|
412
|
+
`${a(this, v).size} language${a(this, v).size === 1 ? "" : "s"} supported: '${[...a(this, v).keys()].join("', '")}'`
|
|
408
413
|
);
|
|
409
414
|
}
|
|
410
415
|
async setLocale(e) {
|
|
411
416
|
var n;
|
|
412
417
|
let t;
|
|
413
418
|
if (e === "auto") {
|
|
414
|
-
let
|
|
415
|
-
if (typeof navigator
|
|
419
|
+
let s = [];
|
|
420
|
+
if (typeof navigator < "u") {
|
|
416
421
|
const i = navigator;
|
|
417
|
-
((n = i.languages) == null ? void 0 : n.length) > 0 ?
|
|
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);
|
|
418
423
|
}
|
|
419
|
-
for (const i of
|
|
420
|
-
a(this,
|
|
424
|
+
for (const i of s)
|
|
425
|
+
a(this, v).has(i) && (t = i);
|
|
421
426
|
} else
|
|
422
|
-
a(this,
|
|
427
|
+
a(this, v).has(e) && (t = e);
|
|
423
428
|
if (t == null) {
|
|
424
|
-
const
|
|
425
|
-
|
|
429
|
+
const s = a(this, v).keys().next().value;
|
|
430
|
+
s && (t = s);
|
|
426
431
|
}
|
|
427
|
-
if (!t || !a(this,
|
|
432
|
+
if (!t || !a(this, v).has(t))
|
|
428
433
|
throw new Error(`Locale '${e}' has no translation.`);
|
|
429
|
-
const
|
|
434
|
+
const r = a(this, v).get(t);
|
|
430
435
|
try {
|
|
431
|
-
await
|
|
432
|
-
} catch (
|
|
433
|
-
|
|
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);
|
|
434
439
|
}
|
|
435
440
|
}
|
|
436
441
|
/**
|
|
@@ -447,16 +452,16 @@ class Rt {
|
|
|
447
452
|
throw new Error(
|
|
448
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"'`
|
|
449
454
|
);
|
|
450
|
-
let
|
|
451
|
-
for (const
|
|
452
|
-
|
|
453
|
-
return
|
|
454
|
-
if (
|
|
455
|
+
let r = [], n = [];
|
|
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)
|
|
455
460
|
return "[NO LOCALE SET]";
|
|
456
461
|
const f = {};
|
|
457
|
-
for (let
|
|
458
|
-
f[
|
|
459
|
-
return d(this,
|
|
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);
|
|
460
465
|
});
|
|
461
466
|
}
|
|
462
467
|
/**
|
|
@@ -491,7 +496,7 @@ class Rt {
|
|
|
491
496
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
492
497
|
*/
|
|
493
498
|
number(e, t) {
|
|
494
|
-
return
|
|
499
|
+
return F([this.$locale, e], (r, n) => d(this, E, De).call(this, n, t));
|
|
495
500
|
}
|
|
496
501
|
/**
|
|
497
502
|
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -503,7 +508,7 @@ class Rt {
|
|
|
503
508
|
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
504
509
|
*/
|
|
505
510
|
dateTime(e, t) {
|
|
506
|
-
return
|
|
511
|
+
return F([this.$locale, e], (r, n) => d(this, E, Te).call(this, n, t));
|
|
507
512
|
}
|
|
508
513
|
/**
|
|
509
514
|
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
@@ -515,182 +520,180 @@ class Rt {
|
|
|
515
520
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
516
521
|
*/
|
|
517
522
|
list(e, t) {
|
|
518
|
-
return
|
|
523
|
+
return F([this.$locale, e], (r, n) => d(this, E, Oe).call(this, n, t));
|
|
519
524
|
}
|
|
520
525
|
}
|
|
521
|
-
ae = new WeakMap(),
|
|
522
|
-
var
|
|
523
|
-
const n = d(this,
|
|
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);
|
|
524
529
|
if (n) return n;
|
|
525
|
-
const
|
|
526
|
-
if (
|
|
527
|
-
if (
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
+
const s = a(this, v).get(e);
|
|
531
|
+
if (r.context != null && (t += "_" + r.context), r.count != null)
|
|
532
|
+
if (r.ordinal) {
|
|
533
|
+
const u = `${t}_ordinal_(=${r.count})`;
|
|
534
|
+
s.hasTemplate(u) ? t = u : t += "_ordinal_" + new Intl.PluralRules(e, { type: "ordinal" }).select(r.count);
|
|
530
535
|
} else {
|
|
531
|
-
const
|
|
532
|
-
|
|
536
|
+
const u = `${t}_(=${r.count})`;
|
|
537
|
+
s.hasTemplate(u) ? t = u : t += "_" + new Intl.PluralRules(e).select(r.count);
|
|
533
538
|
}
|
|
534
|
-
const i =
|
|
539
|
+
const i = s.getTemplate(t);
|
|
535
540
|
let f = "";
|
|
536
|
-
for (const
|
|
537
|
-
if (
|
|
538
|
-
f +=
|
|
539
|
-
else if (
|
|
540
|
-
let
|
|
541
|
-
const
|
|
542
|
-
|
|
543
|
-
for (const
|
|
544
|
-
const
|
|
545
|
-
if (
|
|
546
|
-
const
|
|
547
|
-
`Failed to load format '${
|
|
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}`
|
|
548
553
|
);
|
|
549
|
-
throw a(this,
|
|
554
|
+
throw a(this, P).crash(y), y;
|
|
550
555
|
}
|
|
551
|
-
|
|
556
|
+
m = R(e, m, h.options);
|
|
552
557
|
}
|
|
553
|
-
f +=
|
|
558
|
+
f += m;
|
|
554
559
|
}
|
|
555
560
|
return f;
|
|
556
561
|
}, De = function(e, t) {
|
|
557
562
|
return new Intl.NumberFormat(this.$locale.get(), t).format(e);
|
|
563
|
+
}, Te = function(e, t) {
|
|
564
|
+
return new Intl.DateTimeFormat(this.$locale.get(), t).format(k(e) ? new Date(e) : e);
|
|
558
565
|
}, Oe = function(e, t) {
|
|
559
|
-
return new Intl.DateTimeFormat(this.$locale.get(), t).format(
|
|
560
|
-
typeof e == "string" ? new Date(e) : e
|
|
561
|
-
);
|
|
562
|
-
}, je = function(e, t) {
|
|
563
566
|
return new Intl.ListFormat(this.$locale.get(), t).format(e);
|
|
564
567
|
}, // relativeTime(): State<string> {
|
|
565
568
|
// }
|
|
566
|
-
|
|
567
|
-
for (const
|
|
568
|
-
if (
|
|
569
|
-
return
|
|
569
|
+
Ze = function(e, t) {
|
|
570
|
+
for (const r of a(this, ie))
|
|
571
|
+
if (r[0] === e && ot(r[1], t))
|
|
572
|
+
return r[2];
|
|
570
573
|
};
|
|
571
|
-
function
|
|
574
|
+
function Mt(o, e) {
|
|
572
575
|
const t = String(e).split(/[\.\[\]]/).filter((n) => n.trim() !== "");
|
|
573
|
-
let
|
|
576
|
+
let r = o;
|
|
574
577
|
for (; t.length > 0; ) {
|
|
575
578
|
const n = t.shift();
|
|
576
|
-
|
|
579
|
+
r != null ? r = r[n] : r = void 0;
|
|
577
580
|
}
|
|
578
|
-
return
|
|
581
|
+
return r;
|
|
579
582
|
}
|
|
580
|
-
function
|
|
581
|
-
return
|
|
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 !== "");
|
|
582
585
|
}
|
|
583
|
-
function
|
|
586
|
+
function H(o) {
|
|
584
587
|
var t;
|
|
585
|
-
|
|
586
|
-
(
|
|
588
|
+
lt(
|
|
589
|
+
(r) => te(r == null ? void 0 : r.toString),
|
|
587
590
|
o,
|
|
588
591
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
589
|
-
), o = o.filter((
|
|
592
|
+
), o = o.filter((r) => r).flatMap(String);
|
|
590
593
|
let e = (t = o.shift()) == null ? void 0 : t.toString();
|
|
591
594
|
if (e) {
|
|
592
|
-
for (const
|
|
593
|
-
|
|
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;
|
|
594
597
|
e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
|
|
595
598
|
}
|
|
596
599
|
return e ?? "";
|
|
597
600
|
}
|
|
598
|
-
function
|
|
599
|
-
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("/"))
|
|
600
603
|
return e;
|
|
601
604
|
let t = o;
|
|
602
605
|
for (; ; )
|
|
603
606
|
if (e.startsWith("..")) {
|
|
604
|
-
for (let
|
|
605
|
-
if (t[
|
|
606
|
-
t = t.slice(0,
|
|
607
|
+
for (let r = t.length; r > 0; --r)
|
|
608
|
+
if (t[r] === "/" || r === 0) {
|
|
609
|
+
t = t.slice(0, r), e = e.replace(/^\.\.\/?/, "");
|
|
607
610
|
break;
|
|
608
611
|
}
|
|
609
612
|
} else if (e.startsWith("."))
|
|
610
613
|
e = e.replace(/^\.\/?/, "");
|
|
611
614
|
else
|
|
612
615
|
break;
|
|
613
|
-
return
|
|
616
|
+
return H([t, e]);
|
|
614
617
|
}
|
|
615
|
-
function
|
|
618
|
+
function xt(o) {
|
|
616
619
|
if (!o) return {};
|
|
617
620
|
o.startsWith("?") && (o = o.slice(1));
|
|
618
621
|
const e = o.split("&").filter((t) => t.trim() !== "").map((t) => {
|
|
619
|
-
const [
|
|
620
|
-
return n.toLowerCase() === "true" ? [
|
|
622
|
+
const [r, n] = t.split("=").map((s) => s.trim());
|
|
623
|
+
return n.toLowerCase() === "true" ? [r, !0] : n.toLowerCase() === "false" ? [r, !1] : isNaN(Number(n)) ? [r, n] : [r, Number(n)];
|
|
621
624
|
});
|
|
622
625
|
return Object.fromEntries(e);
|
|
623
626
|
}
|
|
624
|
-
function
|
|
627
|
+
function et(o, e, t = {}) {
|
|
625
628
|
var i;
|
|
626
|
-
const [
|
|
629
|
+
const [r, n] = e.split("?"), s = ee(r);
|
|
627
630
|
e: for (const f of o) {
|
|
628
|
-
const { fragments:
|
|
629
|
-
if (!(((i =
|
|
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))
|
|
630
633
|
continue e;
|
|
631
|
-
const
|
|
632
|
-
t: for (let
|
|
633
|
-
const
|
|
634
|
-
if (
|
|
634
|
+
const m = [];
|
|
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)
|
|
635
638
|
continue e;
|
|
636
|
-
switch (
|
|
639
|
+
switch (y.type) {
|
|
637
640
|
case 1:
|
|
638
|
-
if (
|
|
639
|
-
|
|
641
|
+
if (y.name.toLowerCase() === R.toLowerCase()) {
|
|
642
|
+
m.push(y);
|
|
640
643
|
break;
|
|
641
644
|
} else
|
|
642
645
|
continue e;
|
|
643
646
|
case 2:
|
|
644
|
-
|
|
647
|
+
m.push({ ...y, value: R });
|
|
645
648
|
break;
|
|
646
649
|
case 3:
|
|
647
|
-
|
|
650
|
+
m.push({ ...y, value: s.slice(h).join("/") });
|
|
648
651
|
break t;
|
|
649
652
|
case 4:
|
|
650
|
-
if (isNaN(Number(
|
|
653
|
+
if (isNaN(Number(R)))
|
|
651
654
|
continue e;
|
|
652
|
-
|
|
655
|
+
m.push({ ...y, value: Number(R) });
|
|
653
656
|
break;
|
|
654
657
|
default:
|
|
655
|
-
throw new Error(`Unknown fragment type: ${
|
|
658
|
+
throw new Error(`Unknown fragment type: ${y.type}`);
|
|
656
659
|
}
|
|
657
660
|
}
|
|
658
|
-
const
|
|
659
|
-
for (const
|
|
660
|
-
|
|
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));
|
|
661
664
|
return {
|
|
662
|
-
path: "/" +
|
|
663
|
-
pattern: "/" +
|
|
664
|
-
params:
|
|
665
|
-
query:
|
|
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),
|
|
666
669
|
meta: f.meta
|
|
667
670
|
};
|
|
668
671
|
}
|
|
669
672
|
}
|
|
670
|
-
function
|
|
671
|
-
const e = [], t = [],
|
|
673
|
+
function Ft(o) {
|
|
674
|
+
const e = [], t = [], r = [], n = [];
|
|
672
675
|
for (const i of o) {
|
|
673
676
|
const { fragments: f } = i;
|
|
674
677
|
f.some(
|
|
675
|
-
(
|
|
678
|
+
(c) => c.type === 3
|
|
676
679
|
/* Wildcard */
|
|
677
680
|
) ? n.push(i) : f.some(
|
|
678
|
-
(
|
|
681
|
+
(c) => c.type === 4
|
|
679
682
|
/* NumericParam */
|
|
680
683
|
) ? t.push(i) : f.some(
|
|
681
|
-
(
|
|
684
|
+
(c) => c.type === 2
|
|
682
685
|
/* Param */
|
|
683
|
-
) ?
|
|
686
|
+
) ? r.push(i) : e.push(i);
|
|
684
687
|
}
|
|
685
|
-
const
|
|
686
|
-
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];
|
|
687
690
|
}
|
|
688
|
-
function
|
|
689
|
-
const e =
|
|
690
|
-
for (let
|
|
691
|
-
const n = e[
|
|
691
|
+
function qt(o) {
|
|
692
|
+
const e = ee(o), t = [];
|
|
693
|
+
for (let r = 0; r < e.length; r++) {
|
|
694
|
+
const n = e[r];
|
|
692
695
|
if (n === "*") {
|
|
693
|
-
if (
|
|
696
|
+
if (r !== e.length - 1)
|
|
694
697
|
throw new Error(`Wildcard must be at the end of a pattern. Received: ${o}`);
|
|
695
698
|
t.push({
|
|
696
699
|
type: 3,
|
|
@@ -709,94 +712,71 @@ function xt(o) {
|
|
|
709
712
|
}
|
|
710
713
|
return t;
|
|
711
714
|
}
|
|
712
|
-
var
|
|
713
|
-
class
|
|
714
|
-
constructor(e
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
c(this, N, []);
|
|
722
|
-
c(this, ue);
|
|
723
|
-
c(this, V, []);
|
|
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
724
|
/**
|
|
725
725
|
* Use hash routing when true. Configured in router options.
|
|
726
726
|
*/
|
|
727
|
-
|
|
727
|
+
l(this, _, !1);
|
|
728
728
|
// Callbacks that need to be called on unmount.
|
|
729
|
-
|
|
729
|
+
l(this, G, []);
|
|
730
|
+
/**
|
|
731
|
+
* The current match object.
|
|
732
|
+
*/
|
|
733
|
+
l(this, T);
|
|
734
|
+
l(this, he);
|
|
730
735
|
/**
|
|
731
736
|
* The currently matched route pattern, if any.
|
|
732
737
|
*/
|
|
733
|
-
|
|
734
|
-
c(this, X);
|
|
738
|
+
p(this, "$pattern");
|
|
735
739
|
/**
|
|
736
740
|
* The current URL path.
|
|
737
741
|
*/
|
|
738
|
-
|
|
739
|
-
c(this, Y);
|
|
742
|
+
p(this, "$path");
|
|
740
743
|
/**
|
|
741
744
|
* The current named path params.
|
|
742
745
|
*/
|
|
743
|
-
|
|
744
|
-
c(this, Z);
|
|
746
|
+
p(this, "$params");
|
|
745
747
|
/**
|
|
746
748
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
747
749
|
*/
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
Ce(typeof window > "u" ? "" : window.location.search ?? ""),
|
|
753
|
-
{ equals: Ge }
|
|
754
|
-
);
|
|
755
|
-
this.$pattern = s, m(this, X, n), this.$path = r, m(this, Y, i), this.$params = f, m(this, Z, l), this.$query = h, m(this, fe, w), e.beforeMount(() => {
|
|
756
|
-
const p = () => {
|
|
757
|
-
d(this, b, te).call(this);
|
|
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);
|
|
758
754
|
};
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
755
|
+
window.addEventListener("popstate", t), a(this, G).push(() => window.removeEventListener("popstate", t));
|
|
756
|
+
const r = e.getRootElement();
|
|
757
|
+
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);
|
|
763
761
|
})
|
|
764
|
-
), a(this,
|
|
762
|
+
), a(this, x).info("will intercept clicks on <a> tags within root element", r), await d(this, w, Z).call(this);
|
|
765
763
|
}), e.onUnmount(() => {
|
|
766
|
-
for (const
|
|
767
|
-
|
|
768
|
-
|
|
764
|
+
for (const t of a(this, G))
|
|
765
|
+
t();
|
|
766
|
+
g(this, G, []);
|
|
769
767
|
});
|
|
770
768
|
}
|
|
771
|
-
setup(e) {
|
|
772
|
-
|
|
773
|
-
a(this,
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
}
|
|
778
|
-
e.hash && m(this, W, !0), m(this, V, Mt(
|
|
779
|
-
e.routes.flatMap((t) => d(this, b, Ue).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) => ({
|
|
780
775
|
pattern: t.pattern,
|
|
781
776
|
meta: t.meta,
|
|
782
|
-
fragments:
|
|
777
|
+
fragments: qt(t.pattern)
|
|
783
778
|
}))
|
|
784
|
-
));
|
|
785
|
-
for (const t of a(this, V))
|
|
786
|
-
if (t.meta.redirect) {
|
|
787
|
-
let s;
|
|
788
|
-
if (!Ie(t.meta.redirect)) if (F(t.meta.redirect)) {
|
|
789
|
-
if (s = t.meta.redirect, !Ke(a(this, V), s, {
|
|
790
|
-
willMatch(r) {
|
|
791
|
-
return r !== t;
|
|
792
|
-
}
|
|
793
|
-
}))
|
|
794
|
-
throw new Error(
|
|
795
|
-
`Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`
|
|
796
|
-
);
|
|
797
|
-
} else
|
|
798
|
-
throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
|
|
799
|
-
}
|
|
779
|
+
)), jt(a(this, X));
|
|
800
780
|
}
|
|
801
781
|
/**
|
|
802
782
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
@@ -818,59 +798,84 @@ class Ft {
|
|
|
818
798
|
* Dolla.router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
819
799
|
*/
|
|
820
800
|
go(e, t = {}) {
|
|
821
|
-
|
|
822
|
-
|
|
801
|
+
if (a(this, W) == null)
|
|
802
|
+
throw new Error("Routa methods won't work until you register it: Dolla.use(Routa, { /* ...options */ })");
|
|
803
|
+
let 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);
|
|
823
805
|
}
|
|
824
806
|
}
|
|
825
|
-
|
|
826
|
-
a(this,
|
|
827
|
-
},
|
|
828
|
-
a(this,
|
|
829
|
-
},
|
|
830
|
-
return a(this,
|
|
831
|
-
},
|
|
832
|
-
const t = e ? new URL(e, window.location.origin) : d(this,
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
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;
|
|
826
|
+
}
|
|
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
|
+
return { match: n, journey: s };
|
|
833
|
+
}, Ce = async function(e, t = []) {
|
|
834
|
+
const r = et(a(this, X), e.pathname);
|
|
835
|
+
if (!r)
|
|
836
|
+
return {
|
|
837
|
+
match: null,
|
|
838
|
+
journey: [...t, { kind: "miss", message: `no match for '${e.pathname}'` }]
|
|
839
|
+
};
|
|
840
|
+
let n = r.meta.redirect;
|
|
841
|
+
if (r.meta.beforeMatch && await r.meta.beforeMatch({
|
|
843
842
|
// TODO: Allow setting context variables from here? Would apply to the context of the matched view.
|
|
844
|
-
redirect: (
|
|
845
|
-
n =
|
|
843
|
+
redirect: (s) => {
|
|
844
|
+
n = s;
|
|
846
845
|
}
|
|
847
|
-
}), n != null)
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
const
|
|
853
|
-
path:
|
|
854
|
-
pattern:
|
|
855
|
-
params:
|
|
856
|
-
query:
|
|
846
|
+
}), n != null) {
|
|
847
|
+
let s;
|
|
848
|
+
if (k(n))
|
|
849
|
+
s = Ot(n, r.params);
|
|
850
|
+
else if (te(n)) {
|
|
851
|
+
const i = {
|
|
852
|
+
path: r.path,
|
|
853
|
+
pattern: r.pattern,
|
|
854
|
+
params: r.params,
|
|
855
|
+
query: r.query
|
|
857
856
|
};
|
|
858
|
-
|
|
859
|
-
if (typeof i != "string")
|
|
857
|
+
if (s = await n(i), !k(s))
|
|
860
858
|
throw new Error("Redirect function must return a path to redirect to.");
|
|
861
|
-
|
|
859
|
+
s.startsWith("/") || (s = Ee(r.path, s));
|
|
862
860
|
} else
|
|
863
861
|
throw new TypeError("Redirect must either be a path string or a function.");
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
862
|
+
return d(this, w, Ce).call(this, new URL(s, window.location.origin), [
|
|
863
|
+
...t,
|
|
864
|
+
{ kind: "redirect", message: `redirecting '${r.path}' -> '${s}'` }
|
|
865
|
+
]);
|
|
866
|
+
} else
|
|
867
|
+
return { match: r, journey: [...t, { kind: "match", message: `matched route '${r.path}'` }] };
|
|
868
|
+
}, /**
|
|
869
|
+
* Takes a matched route and mounts it.
|
|
870
|
+
*/
|
|
871
|
+
st = function(e) {
|
|
872
|
+
const t = e.meta.layers;
|
|
873
|
+
for (let r = 0; r < t.length; r++) {
|
|
874
|
+
const n = t[r], s = a(this, D)[r];
|
|
875
|
+
if ((s == null ? void 0 : s.id) !== n.id) {
|
|
876
|
+
g(this, D, a(this, D).slice(0, r)), s == null || s.node.unmount();
|
|
877
|
+
const i = a(this, D).at(-1), c = ((i == null ? void 0 : i.node) ?? a(this, W).getRootView()).setChildView(n.view);
|
|
878
|
+
a(this, D).push({ id: n.id, node: c });
|
|
874
879
|
}
|
|
875
880
|
}
|
|
876
881
|
}, /**
|
|
@@ -879,8 +884,8 @@ he = new WeakMap(), S = new WeakMap(), I = new WeakMap(), xe = new WeakMap(), N
|
|
|
879
884
|
* @param route - Route config object.
|
|
880
885
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
881
886
|
*/
|
|
882
|
-
Ue = function(e, t = [],
|
|
883
|
-
if (!(
|
|
887
|
+
Ue = function(e, t = [], r = []) {
|
|
888
|
+
if (!ke(e) || !k(e.path))
|
|
884
889
|
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
|
|
885
890
|
if (e.redirect && e.routes)
|
|
886
891
|
throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
|
|
@@ -889,172 +894,205 @@ Ue = function(e, t = [], s = []) {
|
|
|
889
894
|
if (!e.view && !e.routes && !e.redirect)
|
|
890
895
|
throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
|
|
891
896
|
let n = [];
|
|
892
|
-
for (const
|
|
893
|
-
n.push(...
|
|
894
|
-
n.push(...
|
|
895
|
-
const
|
|
897
|
+
for (const c of t)
|
|
898
|
+
n.push(...ee(c.path));
|
|
899
|
+
n.push(...ee(e.path)), n[n.length - 1] === "*" && n.pop();
|
|
900
|
+
const s = [];
|
|
896
901
|
if (e.redirect) {
|
|
897
|
-
let
|
|
898
|
-
return
|
|
899
|
-
pattern: "/" +
|
|
902
|
+
let c = e.redirect;
|
|
903
|
+
return k(c) && (c = Ee(H(n), c), c.startsWith("/") || (c = "/" + c)), s.push({
|
|
904
|
+
pattern: "/" + H([...n, ...ee(e.path)]),
|
|
900
905
|
meta: {
|
|
901
|
-
redirect:
|
|
906
|
+
redirect: c
|
|
902
907
|
}
|
|
903
|
-
}),
|
|
908
|
+
}), s;
|
|
904
909
|
}
|
|
905
|
-
let i =
|
|
906
|
-
if (
|
|
910
|
+
let i = Je;
|
|
911
|
+
if (te(e.view))
|
|
907
912
|
i = e.view;
|
|
908
913
|
else if (e.view)
|
|
909
914
|
throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
|
|
910
|
-
const f = { id:
|
|
915
|
+
const f = { id: Y(this, xe)._++, view: i };
|
|
911
916
|
if (e.routes)
|
|
912
|
-
for (const
|
|
913
|
-
|
|
917
|
+
for (const c of e.routes)
|
|
918
|
+
s.push(...d(this, w, Ue).call(this, c, [...t, e], [...r, f]));
|
|
914
919
|
else
|
|
915
|
-
|
|
916
|
-
pattern: parent ?
|
|
920
|
+
s.push({
|
|
921
|
+
pattern: parent ? H([...t.map((c) => c.path), e.path]) : e.path,
|
|
917
922
|
meta: {
|
|
918
923
|
pattern: e.path,
|
|
919
|
-
layers: [...
|
|
924
|
+
layers: [...r, f],
|
|
920
925
|
beforeMatch: e.beforeMatch
|
|
921
926
|
}
|
|
922
927
|
});
|
|
923
|
-
return
|
|
928
|
+
return s;
|
|
924
929
|
};
|
|
925
|
-
const Pt = /(noopener|noreferrer) (noopener|noreferrer)/,
|
|
926
|
-
function
|
|
927
|
-
function s
|
|
928
|
-
return !
|
|
930
|
+
const Pt = /(noopener|noreferrer) (noopener|noreferrer)/, Dt = /^[\w-_]+:/;
|
|
931
|
+
function Tt(o, e, t = window) {
|
|
932
|
+
function r(s) {
|
|
933
|
+
return !s || s === o ? null : s.localName !== "a" || s.href === void 0 ? r(s.parentNode) : s;
|
|
929
934
|
}
|
|
930
|
-
function n(
|
|
931
|
-
if (
|
|
935
|
+
function n(s) {
|
|
936
|
+
if (s.button && s.button !== 0 || s.ctrlKey || s.metaKey || s.altKey || s.shiftKey || s.defaultPrevented)
|
|
932
937
|
return;
|
|
933
|
-
const i = s
|
|
934
|
-
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")) ||
|
|
938
|
+
const i = r(s.target);
|
|
939
|
+
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)));
|
|
935
940
|
}
|
|
936
941
|
return o.addEventListener("click", n), function() {
|
|
937
942
|
o.removeEventListener("click", n);
|
|
938
943
|
};
|
|
939
944
|
}
|
|
940
|
-
function
|
|
945
|
+
function Ot(o, e) {
|
|
941
946
|
for (const t in e) {
|
|
942
|
-
const
|
|
943
|
-
o = o.replace(`{${t}}`,
|
|
947
|
+
const r = e[t].toString();
|
|
948
|
+
o = o.replace(`{${t}}`, r).replace(`{#${t}}`, r);
|
|
944
949
|
}
|
|
945
950
|
return o;
|
|
946
951
|
}
|
|
947
|
-
|
|
948
|
-
|
|
952
|
+
function jt(o) {
|
|
953
|
+
for (const e of o)
|
|
954
|
+
if (e.meta.redirect) {
|
|
955
|
+
let t;
|
|
956
|
+
if (!te(e.meta.redirect)) if (k(e.meta.redirect)) {
|
|
957
|
+
if (t = e.meta.redirect, !et(o, t, {
|
|
958
|
+
willMatch(n) {
|
|
959
|
+
return n !== e;
|
|
960
|
+
}
|
|
961
|
+
}))
|
|
962
|
+
throw new Error(`Found a redirect to an undefined URL. From '${e.pattern}' to '${e.meta.redirect}'`);
|
|
963
|
+
} else
|
|
964
|
+
throw new TypeError(`Expected a string or redirect function. Got: ${e.meta.redirect}`);
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
class Ct extends Error {
|
|
968
|
+
}
|
|
969
|
+
var O, ue, j, B, fe, de, me, ge, pe, we, C, $, U, Fe;
|
|
970
|
+
class Ut {
|
|
949
971
|
constructor() {
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
972
|
+
p(this, "batch");
|
|
973
|
+
p(this, "http");
|
|
974
|
+
p(this, "i18n");
|
|
975
|
+
p(this, "router");
|
|
976
|
+
l(this, O, !1);
|
|
977
|
+
l(this, ue, "production");
|
|
978
|
+
l(this, j);
|
|
979
|
+
l(this, B);
|
|
980
|
+
l(this, fe, bt);
|
|
981
|
+
l(this, de, Be());
|
|
982
|
+
l(this, me, []);
|
|
983
|
+
l(this, ge, []);
|
|
984
|
+
l(this, pe, []);
|
|
985
|
+
l(this, we, []);
|
|
986
|
+
l(this, C, {
|
|
965
987
|
root: this,
|
|
966
988
|
data: {}
|
|
967
989
|
});
|
|
968
|
-
|
|
990
|
+
l(this, $, {
|
|
969
991
|
info: "development",
|
|
970
992
|
log: "development",
|
|
971
993
|
warn: "development",
|
|
972
994
|
error: !0
|
|
973
995
|
});
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
},
|
|
990
|
-
get rootView() {
|
|
991
|
-
return a(e, G);
|
|
992
|
-
}
|
|
993
|
-
});
|
|
996
|
+
l(this, U, ze("*,-dolla/*"));
|
|
997
|
+
// Registration functions for modules.
|
|
998
|
+
// All modules will be registered before mount.
|
|
999
|
+
l(this, Fe, []);
|
|
1000
|
+
p(this, "watch", a(this, de).watch);
|
|
1001
|
+
p(this, "createState", Ve);
|
|
1002
|
+
p(this, "createSettableState", ct);
|
|
1003
|
+
p(this, "toSettableState", ht);
|
|
1004
|
+
p(this, "toState", ut);
|
|
1005
|
+
p(this, "valueOf", ft);
|
|
1006
|
+
p(this, "derive", F);
|
|
1007
|
+
p(this, "createWatcher", Be);
|
|
1008
|
+
p(this, "createRef", dt);
|
|
1009
|
+
p(this, "isRef", mt);
|
|
1010
|
+
this.batch = new $t(this), this.http = new vt(this), this.i18n = new Lt(this), this.router = new Nt(this);
|
|
994
1011
|
}
|
|
995
1012
|
/**
|
|
996
1013
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
997
1014
|
*/
|
|
998
1015
|
get isMounted() {
|
|
999
|
-
return a(this,
|
|
1016
|
+
return a(this, O);
|
|
1000
1017
|
}
|
|
1001
1018
|
/**
|
|
1002
1019
|
* Get the current environment that this app is running in.
|
|
1003
1020
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1004
1021
|
*/
|
|
1005
1022
|
getEnv() {
|
|
1006
|
-
return a(this,
|
|
1023
|
+
return a(this, ue);
|
|
1007
1024
|
}
|
|
1008
1025
|
/**
|
|
1009
1026
|
* Sets the environment that this app is running in.
|
|
1010
1027
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1011
1028
|
*/
|
|
1012
1029
|
setEnv(e) {
|
|
1013
|
-
|
|
1030
|
+
g(this, ue, e);
|
|
1014
1031
|
}
|
|
1015
1032
|
/**
|
|
1016
1033
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1017
1034
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1018
1035
|
*/
|
|
1019
1036
|
setCrashView(e) {
|
|
1020
|
-
|
|
1037
|
+
g(this, fe, e);
|
|
1021
1038
|
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
|
|
1041
|
+
*/
|
|
1042
|
+
getRootElement() {
|
|
1043
|
+
return a(this, j);
|
|
1044
|
+
}
|
|
1045
|
+
/**
|
|
1046
|
+
* Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
|
|
1047
|
+
*/
|
|
1048
|
+
getRootView() {
|
|
1049
|
+
return a(this, B);
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Registers a Dolla module.
|
|
1053
|
+
*/
|
|
1054
|
+
// use<O>(module: DollaModule<O>, options: O) {
|
|
1055
|
+
// this.#modules.push(async () => {
|
|
1056
|
+
// return module.register({ root: this, options });
|
|
1057
|
+
// });
|
|
1058
|
+
// return this;
|
|
1059
|
+
// }
|
|
1022
1060
|
/**
|
|
1023
1061
|
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
1024
1062
|
*/
|
|
1025
1063
|
set(e, t) {
|
|
1026
|
-
return a(this,
|
|
1064
|
+
return a(this, C).data[e] = t, t;
|
|
1027
1065
|
}
|
|
1028
1066
|
/**
|
|
1029
1067
|
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
1030
1068
|
*/
|
|
1031
1069
|
get(e) {
|
|
1032
|
-
return a(this,
|
|
1070
|
+
return a(this, C).data[e] ?? null;
|
|
1033
1071
|
}
|
|
1034
1072
|
/**
|
|
1035
1073
|
* Returns an object of all context variables stored at the app level.
|
|
1036
1074
|
*/
|
|
1037
1075
|
getAll() {
|
|
1038
|
-
return { ...a(this,
|
|
1076
|
+
return { ...a(this, C).data };
|
|
1039
1077
|
}
|
|
1040
1078
|
async mount(e, t) {
|
|
1041
|
-
if (a(this,
|
|
1079
|
+
if (a(this, O))
|
|
1042
1080
|
throw new Error("Dolla is already mounted.");
|
|
1043
|
-
if (
|
|
1081
|
+
if (k(e)) {
|
|
1044
1082
|
const n = document.querySelector(e);
|
|
1045
|
-
He(HTMLElement, n, `Selector '${e}' did not match any element.`),
|
|
1083
|
+
He(HTMLElement, n, `Selector '${e}' did not match any element.`), g(this, j, n);
|
|
1046
1084
|
} else
|
|
1047
|
-
He(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"),
|
|
1048
|
-
const
|
|
1049
|
-
|
|
1050
|
-
for (const n of a(this,
|
|
1085
|
+
He(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), g(this, j, e);
|
|
1086
|
+
const r = gt(t ?? Je);
|
|
1087
|
+
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);
|
|
1088
|
+
for (const n of a(this, ge))
|
|
1051
1089
|
n();
|
|
1052
1090
|
}
|
|
1053
1091
|
async unmount() {
|
|
1054
1092
|
var e;
|
|
1055
|
-
if (a(this,
|
|
1056
|
-
await Promise.all(a(this,
|
|
1057
|
-
for (const t of a(this,
|
|
1093
|
+
if (a(this, O)) {
|
|
1094
|
+
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);
|
|
1095
|
+
for (const t of a(this, we))
|
|
1058
1096
|
t();
|
|
1059
1097
|
}
|
|
1060
1098
|
}
|
|
@@ -1063,55 +1101,55 @@ class Dt {
|
|
|
1063
1101
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1064
1102
|
*/
|
|
1065
1103
|
beforeMount(e) {
|
|
1066
|
-
a(this,
|
|
1104
|
+
a(this, me).push(e);
|
|
1067
1105
|
}
|
|
1068
1106
|
/**
|
|
1069
1107
|
* Registers a `callback` to run after the app is mounted.
|
|
1070
1108
|
*/
|
|
1071
1109
|
onMount(e) {
|
|
1072
|
-
a(this,
|
|
1110
|
+
a(this, ge).push(e);
|
|
1073
1111
|
}
|
|
1074
1112
|
/**
|
|
1075
1113
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1076
1114
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1077
1115
|
*/
|
|
1078
1116
|
beforeUnmount(e) {
|
|
1079
|
-
a(this,
|
|
1117
|
+
a(this, pe).push(e);
|
|
1080
1118
|
}
|
|
1081
1119
|
/**
|
|
1082
1120
|
* Registers a `callback` to run after the app is unmounted.
|
|
1083
1121
|
*/
|
|
1084
1122
|
onUnmount(e) {
|
|
1085
|
-
a(this,
|
|
1123
|
+
a(this, we).push(e);
|
|
1086
1124
|
}
|
|
1087
1125
|
/**
|
|
1088
1126
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
1089
1127
|
*/
|
|
1090
1128
|
setLoggles(e) {
|
|
1091
1129
|
for (const t in e) {
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1130
|
+
const r = e[t];
|
|
1131
|
+
r && (a(this, $)[t] = r);
|
|
1094
1132
|
}
|
|
1095
1133
|
}
|
|
1096
1134
|
setLogFilter(e) {
|
|
1097
|
-
|
|
1135
|
+
g(this, U, ze(e));
|
|
1098
1136
|
}
|
|
1099
1137
|
createLogger(e, t) {
|
|
1100
|
-
const
|
|
1138
|
+
const r = (t == null ? void 0 : t.console) ?? Vt(), n = this;
|
|
1101
1139
|
return {
|
|
1102
|
-
setName(
|
|
1103
|
-
return e =
|
|
1140
|
+
setName(s) {
|
|
1141
|
+
return e = s, this;
|
|
1104
1142
|
},
|
|
1105
1143
|
get info() {
|
|
1106
|
-
var
|
|
1107
|
-
if (a(n,
|
|
1108
|
-
return
|
|
1144
|
+
var s;
|
|
1145
|
+
if (a(n, $).info === !1 || k(a(n, $).info) && a(n, $).info !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1146
|
+
return be;
|
|
1109
1147
|
{
|
|
1110
1148
|
let i = `%c${e}`;
|
|
1111
|
-
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c",
|
|
1112
|
-
|
|
1149
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.info.bind(
|
|
1150
|
+
r,
|
|
1113
1151
|
i,
|
|
1114
|
-
`color:${
|
|
1152
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1115
1153
|
"color:#777",
|
|
1116
1154
|
"color:#aaa",
|
|
1117
1155
|
"color:#777"
|
|
@@ -1119,15 +1157,15 @@ class Dt {
|
|
|
1119
1157
|
}
|
|
1120
1158
|
},
|
|
1121
1159
|
get log() {
|
|
1122
|
-
var
|
|
1123
|
-
if (a(n,
|
|
1124
|
-
return
|
|
1160
|
+
var s;
|
|
1161
|
+
if (a(n, $).log === !1 || k(a(n, $).log) && a(n, $).log !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1162
|
+
return be;
|
|
1125
1163
|
{
|
|
1126
1164
|
let i = `%c${e}`;
|
|
1127
|
-
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c",
|
|
1128
|
-
|
|
1165
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.log.bind(
|
|
1166
|
+
r,
|
|
1129
1167
|
i,
|
|
1130
|
-
`color:${
|
|
1168
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1131
1169
|
"color:#777",
|
|
1132
1170
|
"color:#aaa",
|
|
1133
1171
|
"color:#777"
|
|
@@ -1135,15 +1173,15 @@ class Dt {
|
|
|
1135
1173
|
}
|
|
1136
1174
|
},
|
|
1137
1175
|
get warn() {
|
|
1138
|
-
var
|
|
1139
|
-
if (a(n,
|
|
1140
|
-
return
|
|
1176
|
+
var s;
|
|
1177
|
+
if (a(n, $).warn === !1 || k(a(n, $).warn) && a(n, $).warn !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1178
|
+
return be;
|
|
1141
1179
|
{
|
|
1142
1180
|
let i = `%c${e}`;
|
|
1143
|
-
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c",
|
|
1144
|
-
|
|
1181
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.warn.bind(
|
|
1182
|
+
r,
|
|
1145
1183
|
i,
|
|
1146
|
-
`color:${
|
|
1184
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1147
1185
|
"color:#777",
|
|
1148
1186
|
"color:#aaa",
|
|
1149
1187
|
"color:#777"
|
|
@@ -1151,72 +1189,78 @@ class Dt {
|
|
|
1151
1189
|
}
|
|
1152
1190
|
},
|
|
1153
1191
|
get error() {
|
|
1154
|
-
var
|
|
1155
|
-
if (a(n,
|
|
1156
|
-
return
|
|
1192
|
+
var s;
|
|
1193
|
+
if (a(n, $).error === !1 || k(a(n, $).error) && a(n, $).error !== n.getEnv() || !a(s = n, U).call(s, e))
|
|
1194
|
+
return be;
|
|
1157
1195
|
{
|
|
1158
1196
|
let i = `%c${e}`;
|
|
1159
|
-
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c",
|
|
1160
|
-
|
|
1197
|
+
return t != null && t.uid ? i += ` %c[uid: %c${t.uid}%c]` : i += "%c%c%c", r.error.bind(
|
|
1198
|
+
r,
|
|
1161
1199
|
i,
|
|
1162
|
-
`color:${
|
|
1200
|
+
`color:${$e(i)};font-weight:bold`,
|
|
1163
1201
|
"color:#777",
|
|
1164
1202
|
"color:#aaa",
|
|
1165
1203
|
"color:#777"
|
|
1166
1204
|
);
|
|
1167
1205
|
}
|
|
1168
1206
|
},
|
|
1169
|
-
crash(
|
|
1170
|
-
throw n.isMounted && (n.unmount(), n.constructView(a(n,
|
|
1171
|
-
error:
|
|
1207
|
+
crash(s) {
|
|
1208
|
+
throw n.isMounted && (n.unmount(), n.constructView(a(n, fe), {
|
|
1209
|
+
error: s,
|
|
1172
1210
|
loggerName: e,
|
|
1173
1211
|
uid: t == null ? void 0 : t.uid
|
|
1174
|
-
}).mount(a(n,
|
|
1212
|
+
}).mount(a(n, j))), s;
|
|
1175
1213
|
}
|
|
1176
1214
|
};
|
|
1177
1215
|
}
|
|
1178
1216
|
/**
|
|
1179
1217
|
*
|
|
1180
1218
|
*/
|
|
1181
|
-
constructView(e, t,
|
|
1182
|
-
return new pt(a(this,
|
|
1219
|
+
constructView(e, t, r = []) {
|
|
1220
|
+
return new pt(a(this, C), e, t, r);
|
|
1183
1221
|
}
|
|
1184
1222
|
/**
|
|
1185
1223
|
*
|
|
1186
1224
|
*/
|
|
1187
1225
|
constructMarkup(e) {
|
|
1188
|
-
return
|
|
1226
|
+
return wt(yt(a(this, C), e));
|
|
1189
1227
|
}
|
|
1190
1228
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1229
|
+
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();
|
|
1230
|
+
function Vt() {
|
|
1231
|
+
if (typeof window < "u" && window.console)
|
|
1232
|
+
return window.console;
|
|
1233
|
+
if (typeof global < "u" && global.console)
|
|
1234
|
+
return global.console;
|
|
1235
|
+
}
|
|
1236
|
+
const Ke = new Ut(), Wt = Ke.i18n.t.bind(Ke.i18n);
|
|
1237
|
+
function _t(o) {
|
|
1194
1238
|
typeof window < "u" && (window.DOLLA_DEV_DEBUG = o);
|
|
1195
1239
|
}
|
|
1196
|
-
function
|
|
1240
|
+
function Gt() {
|
|
1197
1241
|
return typeof window < "u" ? window.DOLLA_DEV_DEBUG === !0 : !1;
|
|
1198
1242
|
}
|
|
1199
1243
|
export {
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1244
|
+
it as cond,
|
|
1245
|
+
gt as createMarkup,
|
|
1246
|
+
dt as createRef,
|
|
1247
|
+
ct as createSettableState,
|
|
1248
|
+
Ht as createSetter,
|
|
1249
|
+
Ve as createState,
|
|
1250
|
+
ot as deepEqual,
|
|
1251
|
+
Ke as default,
|
|
1252
|
+
F as derive,
|
|
1253
|
+
Gt as getDevDebug,
|
|
1254
|
+
Ie as html,
|
|
1255
|
+
mt as isRef,
|
|
1256
|
+
Kt as portal,
|
|
1257
|
+
Qt as repeat,
|
|
1258
|
+
_t as setDevDebug,
|
|
1259
|
+
_e as shallowEqual,
|
|
1260
|
+
Jt as strictEqual,
|
|
1261
|
+
Wt as t,
|
|
1262
|
+
ht as toSettableState,
|
|
1263
|
+
ut as toState,
|
|
1264
|
+
ft as valueOf
|
|
1221
1265
|
};
|
|
1222
1266
|
//# sourceMappingURL=index.js.map
|