@manyducks.co/dolla 2.0.0-alpha.34 → 2.0.0-alpha.36

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