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