@manyducks.co/dolla 2.0.0-alpha.22 → 2.0.0-alpha.23

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