@manyducks.co/dolla 2.0.0-alpha.51 → 2.0.0-alpha.53

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