@manyducks.co/dolla 2.0.0-alpha.46 → 2.0.0-alpha.47

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