@manyducks.co/dolla 2.0.0-alpha.26 → 2.0.0-alpha.28

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