@manyducks.co/dolla 1.0.1 → 2.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +47 -23
  2. package/build.js +5 -5
  3. package/dist/fragment-s33qZBzz.js +1241 -0
  4. package/dist/fragment-s33qZBzz.js.map +1 -0
  5. package/dist/index.d.ts +42 -0
  6. package/dist/index.js +1308 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/jsx-dev-runtime.d.ts +2 -0
  9. package/dist/jsx-dev-runtime.js +17 -0
  10. package/dist/jsx-dev-runtime.js.map +1 -0
  11. package/{lib/jsx → dist}/jsx-runtime.d.ts +3 -4
  12. package/dist/jsx-runtime.js +20 -0
  13. package/dist/jsx-runtime.js.map +1 -0
  14. package/{lib → dist}/markup.d.ts +12 -13
  15. package/dist/modules/dolla.d.ts +87 -0
  16. package/dist/modules/http.d.ts +57 -0
  17. package/dist/modules/language.d.ts +41 -0
  18. package/{lib/stores → dist/modules}/render.d.ts +5 -6
  19. package/{lib/stores → dist/modules}/router.d.ts +37 -39
  20. package/{lib → dist}/nodes/cond.d.ts +1 -4
  21. package/{lib → dist}/nodes/html.d.ts +2 -5
  22. package/{lib → dist}/nodes/observer.d.ts +2 -5
  23. package/{lib → dist}/nodes/outlet.d.ts +1 -4
  24. package/{lib → dist}/nodes/portal.d.ts +1 -3
  25. package/{lib → dist}/nodes/repeat.d.ts +2 -5
  26. package/{lib → dist}/nodes/text.d.ts +1 -1
  27. package/{lib → dist}/signals.d.ts +37 -54
  28. package/{lib → dist}/types.d.ts +0 -8
  29. package/{lib → dist}/utils.d.ts +10 -0
  30. package/dist/view.d.ts +44 -0
  31. package/dist/views/default-crash-page.d.ts +8 -0
  32. package/notes/scratch.md +120 -0
  33. package/package.json +11 -12
  34. package/vite.config.js +27 -0
  35. package/lib/app.d.ts +0 -83
  36. package/lib/classes/CrashCollector.d.ts +0 -30
  37. package/lib/classes/DebugHub.d.ts +0 -61
  38. package/lib/classes/EventEmitter.d.ts +0 -44
  39. package/lib/index.d.ts +0 -21
  40. package/lib/index.js +0 -4176
  41. package/lib/index.js.map +0 -7
  42. package/lib/jsx/jsx-dev-runtime.d.ts +0 -3
  43. package/lib/jsx/jsx-dev-runtime.js +0 -20
  44. package/lib/jsx/jsx-dev-runtime.js.map +0 -7
  45. package/lib/jsx/jsx-runtime.js +0 -22
  46. package/lib/jsx/jsx-runtime.js.map +0 -7
  47. package/lib/signals.test.d.ts +0 -1
  48. package/lib/spring.d.ts +0 -0
  49. package/lib/state.d.ts +0 -103
  50. package/lib/store.d.ts +0 -59
  51. package/lib/stores/dialog.d.ts +0 -32
  52. package/lib/stores/document.d.ts +0 -11
  53. package/lib/stores/http.d.ts +0 -60
  54. package/lib/stores/language.d.ts +0 -36
  55. package/lib/testing/classes/MockHTTP.d.ts +0 -10
  56. package/lib/testing/index.d.ts +0 -4
  57. package/lib/testing/makeMockDOMNode.d.ts +0 -10
  58. package/lib/testing/makeMockFetch._test.d.ts +0 -1
  59. package/lib/testing/makeMockFetch.d.ts +0 -36
  60. package/lib/testing/makeMockFetch.test.d.ts +0 -1
  61. package/lib/testing/makeMockFetch.test_skip.d.ts +0 -1
  62. package/lib/testing/stores/dialog.d.ts +0 -6
  63. package/lib/testing/stores/http.d.ts +0 -13
  64. package/lib/testing/stores/page.d.ts +0 -7
  65. package/lib/testing/stores/router.d.ts +0 -12
  66. package/lib/testing/wrapStore._test.d.ts +0 -1
  67. package/lib/testing/wrapStore.d.ts +0 -8
  68. package/lib/testing/wrapStore.test.d.ts +0 -1
  69. package/lib/testing/wrapStore.test_skip.d.ts +0 -1
  70. package/lib/testing/wrapView.d.ts +0 -0
  71. package/lib/view.d.ts +0 -88
  72. package/lib/views/default-crash-page.d.ts +0 -7
  73. package/lib/views/store-scope.d.ts +0 -13
  74. /package/{lib → dist}/routing.d.ts +0 -0
  75. /package/{lib → dist}/routing.test.d.ts +0 -0
  76. /package/{lib → dist}/typeChecking.d.ts +0 -0
  77. /package/{lib → dist}/views/default-view.d.ts +0 -0
  78. /package/{lib → dist}/views/fragment.d.ts +0 -0
package/dist/index.js ADDED
@@ -0,0 +1,1308 @@
1
+ var yt = Object.defineProperty;
2
+ var et = (r) => {
3
+ throw TypeError(r);
4
+ };
5
+ var wt = (r, e, t) => e in r ? yt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
6
+ var k = (r, e, t) => wt(r, typeof e != "symbol" ? e + "" : e, t), Ie = (r, e, t) => e.has(r) || et("Cannot " + t);
7
+ var s = (r, e, t) => (Ie(r, e, "read from private field"), t ? t.call(r) : e.get(r)), f = (r, e, t) => e.has(r) ? et("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t), w = (r, e, t, n) => (Ie(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t), P = (r, e, t) => (Ie(r, e, "access private method"), t);
8
+ var tt = (r, e, t, n) => ({
9
+ set _(i) {
10
+ w(r, e, i, t);
11
+ },
12
+ get _() {
13
+ return s(r, e, n);
14
+ }
15
+ });
16
+ import { i as ze, s as Ge, a as bt, d as Be, b as vt, c as Ze, e as H, f as Q, g as ct, h as $t, w as lt, j as Qe, r as Et, k as Lt, l as nt, m as kt, t as St, n as Pt, o as Rt, p as xt, q as rt, u as at, v as Mt, x as Ne, y as Te } from "./fragment-s33qZBzz.js";
17
+ import { F as dn, A as gn, z as pn, C as mn, B as yn } from "./fragment-s33qZBzz.js";
18
+ function ht(r, e) {
19
+ return e.outlet();
20
+ }
21
+ var K, Ve, T, q;
22
+ class Ot {
23
+ constructor() {
24
+ f(this, T);
25
+ f(this, K, []);
26
+ f(this, Ve, Nt());
27
+ }
28
+ /**
29
+ * Adds a new middleware that will apply to subsequent requests.
30
+ * Returns a function to remove this middleware.
31
+ *
32
+ * @param middleware - A middleware function that will intercept requests.
33
+ */
34
+ use(e) {
35
+ return s(this, K).push(e), () => {
36
+ s(this, K).splice(s(this, K).indexOf(e), 1);
37
+ };
38
+ }
39
+ async get(e, t) {
40
+ return P(this, T, q).call(this, "get", e, t);
41
+ }
42
+ async put(e, t) {
43
+ return P(this, T, q).call(this, "put", e, t);
44
+ }
45
+ async patch(e, t) {
46
+ return P(this, T, q).call(this, "patch", e, t);
47
+ }
48
+ async post(e, t) {
49
+ return P(this, T, q).call(this, "post", e, t);
50
+ }
51
+ async delete(e, t) {
52
+ return P(this, T, q).call(this, "delete", e, t);
53
+ }
54
+ async head(e, t) {
55
+ return P(this, T, q).call(this, "head", e, t);
56
+ }
57
+ async options(e, t) {
58
+ return P(this, T, q).call(this, "options", e, t);
59
+ }
60
+ async trace(e, t) {
61
+ return P(this, T, q).call(this, "trace", e, t);
62
+ }
63
+ }
64
+ K = new WeakMap(), Ve = new WeakMap(), T = new WeakSet(), q = async function(e, t, n) {
65
+ return At({
66
+ ...n,
67
+ method: e,
68
+ uri: t,
69
+ middleware: s(this, K),
70
+ fetch: s(this, Ve)
71
+ });
72
+ };
73
+ function Nt() {
74
+ if (typeof window < "u" && window.fetch)
75
+ return window.fetch.bind(window);
76
+ if (typeof global < "u" && global.fetch)
77
+ return global.fetch.bind(global);
78
+ throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
79
+ }
80
+ class Tt extends Error {
81
+ constructor(t) {
82
+ const { status: n, statusText: i, method: a, uri: o } = t, d = `${n} ${i}: Request failed (${a.toUpperCase()} ${o})`;
83
+ super(d);
84
+ k(this, "response");
85
+ this.response = t;
86
+ }
87
+ }
88
+ async function At(r) {
89
+ const { headers: e, query: t, fetch: n, middleware: i } = r, a = {
90
+ method: r.method,
91
+ uri: r.uri,
92
+ get sameOrigin() {
93
+ return !a.uri.startsWith("http");
94
+ },
95
+ query: new URLSearchParams(),
96
+ headers: new Headers(),
97
+ body: r.body
98
+ };
99
+ if (e)
100
+ if (e instanceof Map || e instanceof Headers)
101
+ e.forEach((c, h) => {
102
+ a.headers.set(h, c);
103
+ });
104
+ else if (e != null && typeof e == "object" && !Array.isArray(e))
105
+ for (const c in e) {
106
+ const h = e[c];
107
+ h instanceof Date ? a.headers.set(c, h.toISOString()) : h != null && a.headers.set(c, String(h));
108
+ }
109
+ else
110
+ throw new TypeError(`Unknown headers type. Got: ${e}`);
111
+ if (t)
112
+ if (t instanceof Map || t instanceof URLSearchParams)
113
+ t.forEach((c, h) => {
114
+ a.query.set(h, c);
115
+ });
116
+ else if (t != null && typeof t == "object" && !Array.isArray(t))
117
+ for (const c in t) {
118
+ const h = t[c];
119
+ h instanceof Date ? a.query.set(c, h.toISOString()) : h != null && a.query.set(c, String(h));
120
+ }
121
+ else
122
+ throw new TypeError(`Unknown query params type. Got: ${t}`);
123
+ let o;
124
+ const d = async () => {
125
+ const c = a.query.toString(), h = c.length > 0 ? a.uri + "?" + c : a.uri;
126
+ let y;
127
+ !a.headers.has("content-type") && ze(a.body) ? (a.headers.set("content-type", "application/json"), y = JSON.stringify(a.body)) : y = a.body;
128
+ const b = await n(h, {
129
+ method: a.method,
130
+ headers: a.headers,
131
+ body: y
132
+ }), g = Object.fromEntries(b.headers.entries()), p = g["content-type"];
133
+ let $;
134
+ p != null && p.includes("application/json") ? $ = await b.json() : p != null && p.includes("application/x-www-form-urlencoded") ? $ = await b.formData() : $ = await b.text(), o = {
135
+ method: a.method,
136
+ uri: a.uri,
137
+ status: b.status,
138
+ statusText: b.statusText,
139
+ headers: g,
140
+ body: $
141
+ };
142
+ };
143
+ if (i.length > 0) {
144
+ const c = (h = 0) => {
145
+ const y = i[h], b = i[h + 1] ? c(h + 1) : d;
146
+ return async () => y(a, async () => (await b(), o));
147
+ };
148
+ await c()();
149
+ } else
150
+ await d();
151
+ if (o.status < 200 || o.status >= 400)
152
+ throw new Tt(o);
153
+ return o;
154
+ }
155
+ class jt {
156
+ constructor(e, t) {
157
+ k(this, "dolla");
158
+ k(this, "config");
159
+ k(this, "strings");
160
+ this.config = e, this.dolla = t;
161
+ }
162
+ async load() {
163
+ if (this.strings == null) {
164
+ if (Ze(this.config.fetch)) {
165
+ const e = await this.config.fetch();
166
+ if (ze(e))
167
+ this.strings = e;
168
+ else
169
+ throw new Error(`Fetch function did not return an object of language strings: ${e}`);
170
+ } else if (H(this.config.path)) {
171
+ const e = await this.dolla.http.get(this.config.path);
172
+ if (e.status >= 200 && e.status < 300)
173
+ if (ze(e.body))
174
+ this.strings = e.body;
175
+ else
176
+ throw new Error(
177
+ `Language path '${this.config.path}' did not return an object of language strings: ${e.body}`
178
+ );
179
+ else
180
+ throw new Error("HTTP request failed.");
181
+ }
182
+ }
183
+ if (this.strings == null)
184
+ throw new Error("Language could not be loaded.");
185
+ return this.strings;
186
+ }
187
+ }
188
+ var we, J, M, ie, be, ve, oe, $e, Fe, ut;
189
+ class Ct {
190
+ constructor(e) {
191
+ f(this, Fe);
192
+ f(this, we);
193
+ f(this, J);
194
+ f(this, M, /* @__PURE__ */ new Map());
195
+ f(this, ie, []);
196
+ f(this, be, "auto");
197
+ k(this, "$current");
198
+ f(this, ve);
199
+ f(this, oe);
200
+ f(this, $e);
201
+ w(this, we, e), w(this, J, e.createLogger("dolla/language"));
202
+ const [t, n] = Q(), [i, a] = Q();
203
+ this.$current = t, w(this, ve, n), w(this, oe, i), w(this, $e, a), e.beforeMount(async () => {
204
+ s(this, M).size > 0 && await this.setLanguage(s(this, be));
205
+ });
206
+ }
207
+ get supportedLanguages() {
208
+ return [...s(this, M).keys()];
209
+ }
210
+ setup(e) {
211
+ if (e.languages.forEach((t) => {
212
+ s(this, M).set(t.name, new jt(t, s(this, we)));
213
+ }), e.initialLanguage && e.initialLanguage !== "auto") {
214
+ if (!e.languages.some((n) => n.name === e.initialLanguage))
215
+ throw new Error(`Initial language '${e.initialLanguage}' has no registered translation.`);
216
+ w(this, be, e.initialLanguage);
217
+ }
218
+ s(this, J).info(
219
+ `${s(this, M).size} language${s(this, M).size === 1 ? "" : "s"} supported: '${[...s(this, M).keys()].join("', '")}'`
220
+ );
221
+ }
222
+ async setLanguage(e) {
223
+ var i;
224
+ let t;
225
+ if (e === "auto") {
226
+ let a = [];
227
+ if (typeof navigator == "object") {
228
+ const o = navigator;
229
+ ((i = o.languages) == null ? void 0 : i.length) > 0 ? a.push(...o.languages) : o.language ? a.push(o.language) : o.browserLanguage ? a.push(o.browserLanguage) : o.userLanguage && a.push(o.userLanguage);
230
+ }
231
+ for (const o of a)
232
+ s(this, M).has(o) && (t = o);
233
+ } else
234
+ s(this, M).has(e) && (t = e);
235
+ if (t == null) {
236
+ const a = s(this, M).keys().next().value;
237
+ a && (t = a);
238
+ }
239
+ if (!t || !s(this, M).has(t))
240
+ throw new Error(`Language '${e}' is not configured for this app.`);
241
+ const n = s(this, M).get(t);
242
+ try {
243
+ const a = await n.load();
244
+ s(this, $e).call(this, a), s(this, ve).call(this, t), s(this, J).info("set language to " + t);
245
+ } catch (a) {
246
+ a instanceof Error && s(this, J).crash(a);
247
+ }
248
+ }
249
+ /**
250
+ * Returns a Signal containing the value at `key`.
251
+
252
+ * @param key - Key to the translated value.
253
+ * @param values - A map of {{placeholder}} names and the values to replace them with.
254
+ */
255
+ t(e, t) {
256
+ if (this === void 0)
257
+ throw new Error(
258
+ `The 't' function cannot be destructured. If you need a standalone version you can import it from the package like so: 'import { t } from "@manyducks.co/dolla"'`
259
+ );
260
+ if (!this.$current.get())
261
+ return Ut;
262
+ const n = P(this, Fe, ut).call(this, e, t);
263
+ if (n)
264
+ return n;
265
+ if (t) {
266
+ const a = {};
267
+ for (const [d, c] of Object.entries(t))
268
+ bt(c) && (a[d] = c);
269
+ const o = Object.entries(a);
270
+ if (o.length > 0) {
271
+ const d = o.map((h) => h[1]), c = Be([s(this, oe), ...d], (h, ...y) => {
272
+ const b = y.map(($, N) => o[N]), g = {
273
+ ...t
274
+ };
275
+ for (let $ = 0; $ < b.length; $++) {
276
+ const N = b[$][0];
277
+ g[N] = y[$];
278
+ }
279
+ const p = it(h, e) || `[NO TRANSLATION: ${e}]`;
280
+ return st(p, g);
281
+ });
282
+ return s(this, ie).push([e, t, c]), c;
283
+ }
284
+ }
285
+ const i = Be([s(this, oe)], (a) => {
286
+ let o = it(a, e) || `[NO TRANSLATION: ${e}]`;
287
+ return t && (o = st(o, t)), o;
288
+ });
289
+ return s(this, ie).push([e, t, i]), i;
290
+ }
291
+ }
292
+ we = new WeakMap(), J = new WeakMap(), M = new WeakMap(), ie = new WeakMap(), be = new WeakMap(), ve = new WeakMap(), oe = new WeakMap(), $e = new WeakMap(), Fe = new WeakSet(), ut = function(e, t) {
293
+ for (const n of s(this, ie))
294
+ if (n[0] === e && vt(n[1], t))
295
+ return n[2];
296
+ };
297
+ const Ut = Ge("[NO LANGUAGE SET]");
298
+ function st(r, e) {
299
+ for (const t in e)
300
+ r = r.replace(`{{${t}}}`, String(e[t]));
301
+ return r;
302
+ }
303
+ function it(r, e) {
304
+ const t = String(e).split(/[\.\[\]]/).filter((i) => i.trim() !== "");
305
+ let n = r;
306
+ for (; t.length > 0; ) {
307
+ const i = t.shift();
308
+ n != null ? n = n[i] : n = void 0;
309
+ }
310
+ return n;
311
+ }
312
+ var Y, Ee, V, F, ce, _, le, Ae;
313
+ class qt {
314
+ constructor(e) {
315
+ f(this, le);
316
+ f(this, Y);
317
+ f(this, Ee);
318
+ // Keyed updates ensure only the most recent callback queued with a certain key
319
+ // will be called, keeping DOM operations to a minimum.
320
+ f(this, V, /* @__PURE__ */ new Map());
321
+ // All unkeyed updates are run on every batch.
322
+ f(this, F, []);
323
+ f(this, ce, []);
324
+ f(this, _, !1);
325
+ w(this, Y, e), w(this, Ee, e.createLogger("dolla/render"));
326
+ }
327
+ /**
328
+ * Queues a callback to run in the next render batch.
329
+ * Running your DOM mutations in update callbacks reduces layout thrashing.
330
+ * Returns a Promise that resolves once the callback has run.
331
+ */
332
+ update(e, t) {
333
+ return new Promise((n) => {
334
+ t ? s(this, V).set(t, () => {
335
+ e(), n();
336
+ }) : s(this, F).push(() => {
337
+ e(), n();
338
+ }), !s(this, _) && s(this, Y).isMounted && (w(this, _, !0), P(this, le, Ae).call(this));
339
+ });
340
+ }
341
+ /**
342
+ * Queues a callback that reads DOM information to run after the next render batch,
343
+ * ensuring all writes have been performed before reading.
344
+ * Returns a Promise that resolves once the callback has run.
345
+ */
346
+ async read(e) {
347
+ return new Promise((t) => {
348
+ s(this, ce).push(() => {
349
+ e(), t();
350
+ }), !s(this, _) && s(this, Y).isMounted && (w(this, _, !0), P(this, le, Ae).call(this));
351
+ });
352
+ }
353
+ }
354
+ Y = new WeakMap(), Ee = new WeakMap(), V = new WeakMap(), F = new WeakMap(), ce = new WeakMap(), _ = new WeakMap(), le = new WeakSet(), Ae = function() {
355
+ const e = s(this, V).size + s(this, F).length;
356
+ if ((!s(this, Y).isMounted || e === 0) && w(this, _, !1), !s(this, _)) {
357
+ for (const t of s(this, ce))
358
+ t();
359
+ w(this, ce, []);
360
+ return;
361
+ }
362
+ requestAnimationFrame(() => {
363
+ s(this, Ee).info(`Batching ${s(this, V).size + s(this, F).length} queued DOM update(s).`);
364
+ for (const t of s(this, V).values())
365
+ t();
366
+ s(this, V).clear();
367
+ for (const t of s(this, F))
368
+ t();
369
+ w(this, F, []), P(this, le, Ae).call(this);
370
+ });
371
+ };
372
+ function de() {
373
+ return de = Object.assign || function(r) {
374
+ for (var e = 1; e < arguments.length; e++) {
375
+ var t = arguments[e];
376
+ for (var n in t)
377
+ Object.prototype.hasOwnProperty.call(t, n) && (r[n] = t[n]);
378
+ }
379
+ return r;
380
+ }, de.apply(this, arguments);
381
+ }
382
+ var C;
383
+ (function(r) {
384
+ r.Pop = "POP", r.Push = "PUSH", r.Replace = "REPLACE";
385
+ })(C || (C = {}));
386
+ var qe = process.env.NODE_ENV !== "production" ? function(r) {
387
+ return Object.freeze(r);
388
+ } : function(r) {
389
+ return r;
390
+ };
391
+ function je(r, e) {
392
+ if (!r) {
393
+ typeof console < "u" && console.warn(e);
394
+ try {
395
+ throw new Error(e);
396
+ } catch {
397
+ }
398
+ }
399
+ }
400
+ var _e = "beforeunload", _t = "hashchange", ft = "popstate";
401
+ function Dt(r) {
402
+ r === void 0 && (r = {});
403
+ var e = r, t = e.window, n = t === void 0 ? document.defaultView : t, i = n.history;
404
+ function a() {
405
+ var m = n.location, l = m.pathname, u = m.search, v = m.hash, E = i.state || {};
406
+ return [E.idx, qe({
407
+ pathname: l,
408
+ search: u,
409
+ hash: v,
410
+ state: E.usr || null,
411
+ key: E.key || "default"
412
+ })];
413
+ }
414
+ var o = null;
415
+ function d() {
416
+ if (o)
417
+ p.call(o), o = null;
418
+ else {
419
+ var m = C.Pop, l = a(), u = l[0], v = l[1];
420
+ if (p.length)
421
+ if (u != null) {
422
+ var E = y - u;
423
+ E && (o = {
424
+ action: m,
425
+ location: v,
426
+ retry: function() {
427
+ D(E * -1);
428
+ }
429
+ }, D(E));
430
+ } else
431
+ process.env.NODE_ENV !== "production" && je(
432
+ !1,
433
+ // TODO: Write up a doc that explains our blocking strategy in
434
+ // detail and link to it here so people can understand better what
435
+ // is going on and how to avoid it.
436
+ "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
437
+ );
438
+ else
439
+ re(m);
440
+ }
441
+ }
442
+ n.addEventListener(ft, d);
443
+ var c = C.Pop, h = a(), y = h[0], b = h[1], g = He(), p = He();
444
+ y == null && (y = 0, i.replaceState(de({}, i.state, {
445
+ idx: y
446
+ }), ""));
447
+ function $(m) {
448
+ return typeof m == "string" ? m : Ce(m);
449
+ }
450
+ function N(m, l) {
451
+ return l === void 0 && (l = null), qe(de({
452
+ pathname: b.pathname,
453
+ hash: "",
454
+ search: ""
455
+ }, typeof m == "string" ? Ke(m) : m, {
456
+ state: l,
457
+ key: dt()
458
+ }));
459
+ }
460
+ function ge(m, l) {
461
+ return [{
462
+ usr: m.state,
463
+ key: m.key,
464
+ idx: l
465
+ }, $(m)];
466
+ }
467
+ function pe(m, l, u) {
468
+ return !p.length || (p.call({
469
+ action: m,
470
+ location: l,
471
+ retry: u
472
+ }), !1);
473
+ }
474
+ function re(m) {
475
+ c = m;
476
+ var l = a();
477
+ y = l[0], b = l[1], g.call({
478
+ action: c,
479
+ location: b
480
+ });
481
+ }
482
+ function ae(m, l) {
483
+ var u = C.Push, v = N(m, l);
484
+ function E() {
485
+ ae(m, l);
486
+ }
487
+ if (pe(u, v, E)) {
488
+ var R = ge(v, y + 1), O = R[0], A = R[1];
489
+ try {
490
+ i.pushState(O, "", A);
491
+ } catch {
492
+ n.location.assign(A);
493
+ }
494
+ re(u);
495
+ }
496
+ }
497
+ function me(m, l) {
498
+ var u = C.Replace, v = N(m, l);
499
+ function E() {
500
+ me(m, l);
501
+ }
502
+ if (pe(u, v, E)) {
503
+ var R = ge(v, y), O = R[0], A = R[1];
504
+ i.replaceState(O, "", A), re(u);
505
+ }
506
+ }
507
+ function D(m) {
508
+ i.go(m);
509
+ }
510
+ var B = {
511
+ get action() {
512
+ return c;
513
+ },
514
+ get location() {
515
+ return b;
516
+ },
517
+ createHref: $,
518
+ push: ae,
519
+ replace: me,
520
+ go: D,
521
+ back: function() {
522
+ D(-1);
523
+ },
524
+ forward: function() {
525
+ D(1);
526
+ },
527
+ listen: function(l) {
528
+ return g.push(l);
529
+ },
530
+ block: function(l) {
531
+ var u = p.push(l);
532
+ return p.length === 1 && n.addEventListener(_e, De), function() {
533
+ u(), p.length || n.removeEventListener(_e, De);
534
+ };
535
+ }
536
+ };
537
+ return B;
538
+ }
539
+ function Ht(r) {
540
+ r === void 0 && (r = {});
541
+ var e = r, t = e.window, n = t === void 0 ? document.defaultView : t, i = n.history;
542
+ function a() {
543
+ var l = Ke(n.location.hash.substr(1)), u = l.pathname, v = u === void 0 ? "/" : u, E = l.search, R = E === void 0 ? "" : E, O = l.hash, A = O === void 0 ? "" : O, U = i.state || {};
544
+ return [U.idx, qe({
545
+ pathname: v,
546
+ search: R,
547
+ hash: A,
548
+ state: U.usr || null,
549
+ key: U.key || "default"
550
+ })];
551
+ }
552
+ var o = null;
553
+ function d() {
554
+ if (o)
555
+ p.call(o), o = null;
556
+ else {
557
+ var l = C.Pop, u = a(), v = u[0], E = u[1];
558
+ if (p.length)
559
+ if (v != null) {
560
+ var R = y - v;
561
+ R && (o = {
562
+ action: l,
563
+ location: E,
564
+ retry: function() {
565
+ B(R * -1);
566
+ }
567
+ }, B(R));
568
+ } else
569
+ process.env.NODE_ENV !== "production" && je(
570
+ !1,
571
+ // TODO: Write up a doc that explains our blocking strategy in
572
+ // detail and link to it here so people can understand better
573
+ // what is going on and how to avoid it.
574
+ "You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
575
+ );
576
+ else
577
+ ae(l);
578
+ }
579
+ }
580
+ n.addEventListener(ft, d), n.addEventListener(_t, function() {
581
+ var l = a(), u = l[1];
582
+ Ce(u) !== Ce(b) && d();
583
+ });
584
+ var c = C.Pop, h = a(), y = h[0], b = h[1], g = He(), p = He();
585
+ y == null && (y = 0, i.replaceState(de({}, i.state, {
586
+ idx: y
587
+ }), ""));
588
+ function $() {
589
+ var l = document.querySelector("base"), u = "";
590
+ if (l && l.getAttribute("href")) {
591
+ var v = n.location.href, E = v.indexOf("#");
592
+ u = E === -1 ? v : v.slice(0, E);
593
+ }
594
+ return u;
595
+ }
596
+ function N(l) {
597
+ return $() + "#" + (typeof l == "string" ? l : Ce(l));
598
+ }
599
+ function ge(l, u) {
600
+ return u === void 0 && (u = null), qe(de({
601
+ pathname: b.pathname,
602
+ hash: "",
603
+ search: ""
604
+ }, typeof l == "string" ? Ke(l) : l, {
605
+ state: u,
606
+ key: dt()
607
+ }));
608
+ }
609
+ function pe(l, u) {
610
+ return [{
611
+ usr: l.state,
612
+ key: l.key,
613
+ idx: u
614
+ }, N(l)];
615
+ }
616
+ function re(l, u, v) {
617
+ return !p.length || (p.call({
618
+ action: l,
619
+ location: u,
620
+ retry: v
621
+ }), !1);
622
+ }
623
+ function ae(l) {
624
+ c = l;
625
+ var u = a();
626
+ y = u[0], b = u[1], g.call({
627
+ action: c,
628
+ location: b
629
+ });
630
+ }
631
+ function me(l, u) {
632
+ var v = C.Push, E = ge(l, u);
633
+ function R() {
634
+ me(l, u);
635
+ }
636
+ if (process.env.NODE_ENV !== "production" && je(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.push(" + JSON.stringify(l) + ")"), re(v, E, R)) {
637
+ var O = pe(E, y + 1), A = O[0], U = O[1];
638
+ try {
639
+ i.pushState(A, "", U);
640
+ } catch {
641
+ n.location.assign(U);
642
+ }
643
+ ae(v);
644
+ }
645
+ }
646
+ function D(l, u) {
647
+ var v = C.Replace, E = ge(l, u);
648
+ function R() {
649
+ D(l, u);
650
+ }
651
+ if (process.env.NODE_ENV !== "production" && je(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(l) + ")"), re(v, E, R)) {
652
+ var O = pe(E, y), A = O[0], U = O[1];
653
+ i.replaceState(A, "", U), ae(v);
654
+ }
655
+ }
656
+ function B(l) {
657
+ i.go(l);
658
+ }
659
+ var m = {
660
+ get action() {
661
+ return c;
662
+ },
663
+ get location() {
664
+ return b;
665
+ },
666
+ createHref: N,
667
+ push: me,
668
+ replace: D,
669
+ go: B,
670
+ back: function() {
671
+ B(-1);
672
+ },
673
+ forward: function() {
674
+ B(1);
675
+ },
676
+ listen: function(u) {
677
+ return g.push(u);
678
+ },
679
+ block: function(u) {
680
+ var v = p.push(u);
681
+ return p.length === 1 && n.addEventListener(_e, De), function() {
682
+ v(), p.length || n.removeEventListener(_e, De);
683
+ };
684
+ }
685
+ };
686
+ return m;
687
+ }
688
+ function De(r) {
689
+ r.preventDefault(), r.returnValue = "";
690
+ }
691
+ function He() {
692
+ var r = [];
693
+ return {
694
+ get length() {
695
+ return r.length;
696
+ },
697
+ push: function(t) {
698
+ return r.push(t), function() {
699
+ r = r.filter(function(n) {
700
+ return n !== t;
701
+ });
702
+ };
703
+ },
704
+ call: function(t) {
705
+ r.forEach(function(n) {
706
+ return n && n(t);
707
+ });
708
+ }
709
+ };
710
+ }
711
+ function dt() {
712
+ return Math.random().toString(36).substr(2, 8);
713
+ }
714
+ function Ce(r) {
715
+ var e = r.pathname, t = e === void 0 ? "/" : e, n = r.search, i = n === void 0 ? "" : n, a = r.hash, o = a === void 0 ? "" : a;
716
+ return i && i !== "?" && (t += i.charAt(0) === "?" ? i : "?" + i), o && o !== "#" && (t += o.charAt(0) === "#" ? o : "#" + o), t;
717
+ }
718
+ function Ke(r) {
719
+ var e = {};
720
+ if (r) {
721
+ var t = r.indexOf("#");
722
+ t >= 0 && (e.hash = r.substr(t), r = r.substr(0, t));
723
+ var n = r.indexOf("?");
724
+ n >= 0 && (e.search = r.substr(n), r = r.substr(0, n)), r && (e.pathname = r);
725
+ }
726
+ return e;
727
+ }
728
+ function ye(r) {
729
+ return ct(r, "Expected `path` to be a string. Got type: %t, value: %v"), r.split("/").map((e) => e.trim()).filter((e) => e !== "");
730
+ }
731
+ function se(r) {
732
+ var t;
733
+ $t(
734
+ (n) => Ze(n == null ? void 0 : n.toString),
735
+ r,
736
+ "Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
737
+ ), r = r.filter((n) => n).flatMap(String);
738
+ let e = (t = r.shift()) == null ? void 0 : t.toString();
739
+ if (e) {
740
+ for (const n of r.map((i) => i.toString()))
741
+ n.startsWith(".") ? e = Ue(e, n) : e[e.length - 1] !== "/" ? n[0] !== "/" ? e += "/" + n : e += n : n[0] === "/" ? e += n.slice(1) : e += n;
742
+ e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
743
+ }
744
+ return e ?? "";
745
+ }
746
+ function Ue(r, e) {
747
+ if (ct(r, "Expected `base` to be a string. Got type: %t, value: %v"), e == null && (e = r, r = ""), e.startsWith("/"))
748
+ return e;
749
+ let t = r;
750
+ for (; ; )
751
+ if (e.startsWith("..")) {
752
+ for (let n = t.length; n > 0; --n)
753
+ if (t[n] === "/" || n === 0) {
754
+ t = t.slice(0, n), e = e.replace(/^\.\.\/?/, "");
755
+ break;
756
+ }
757
+ } else if (e.startsWith("."))
758
+ e = e.replace(/^\.\/?/, "");
759
+ else
760
+ break;
761
+ return se([t, e]);
762
+ }
763
+ function Je(r) {
764
+ if (!r) return {};
765
+ r.startsWith("?") && (r = r.slice(1));
766
+ const e = r.split("&").filter((t) => t.trim() !== "").map((t) => {
767
+ const [n, i] = t.split("=").map((a) => a.trim());
768
+ return i.toLowerCase() === "true" ? [n, !0] : i.toLowerCase() === "false" ? [n, !1] : isNaN(Number(i)) ? [n, i] : [n, Number(i)];
769
+ });
770
+ return Object.fromEntries(e);
771
+ }
772
+ function ot(r, e, t = {}) {
773
+ var o;
774
+ const [n, i] = e.split("?"), a = ye(n);
775
+ e: for (const d of r) {
776
+ const { fragments: c } = d;
777
+ if (!(((o = c[c.length - 1]) == null ? void 0 : o.type) === 3) && c.length !== a.length || t.willMatch && !t.willMatch(d))
778
+ continue e;
779
+ const y = [];
780
+ t: for (let g = 0; g < c.length; g++) {
781
+ const p = a[g], $ = c[g];
782
+ if (p == null && $.type !== 3)
783
+ continue e;
784
+ switch ($.type) {
785
+ case 1:
786
+ if ($.name.toLowerCase() === p.toLowerCase()) {
787
+ y.push($);
788
+ break;
789
+ } else
790
+ continue e;
791
+ case 2:
792
+ y.push({ ...$, value: p });
793
+ break;
794
+ case 3:
795
+ y.push({ ...$, value: a.slice(g).join("/") });
796
+ break t;
797
+ case 4:
798
+ if (isNaN(Number(p)))
799
+ continue e;
800
+ y.push({ ...$, value: Number(p) });
801
+ break;
802
+ default:
803
+ throw new Error(`Unknown fragment type: ${$.type}`);
804
+ }
805
+ }
806
+ const b = /* @__PURE__ */ Object.create(null);
807
+ for (const g of y)
808
+ g.type === 2 && (b[g.name] = decodeURIComponent(g.value)), g.type === 4 && (b[g.name] = g.value), g.type === 3 && (b.wildcard = "/" + decodeURIComponent(g.value));
809
+ return {
810
+ path: "/" + y.map((g) => g.value).join("/"),
811
+ pattern: "/" + c.map((g) => g.type === 2 ? `{${g.name}}` : g.type === 4 ? `{#${g.name}}` : g.name).join("/"),
812
+ params: b,
813
+ query: Je(i),
814
+ meta: d.meta
815
+ };
816
+ }
817
+ }
818
+ function Vt(r) {
819
+ const e = [], t = [], n = [], i = [];
820
+ for (const o of r) {
821
+ const { fragments: d } = o;
822
+ d.some(
823
+ (c) => c.type === 3
824
+ /* Wildcard */
825
+ ) ? i.push(o) : d.some(
826
+ (c) => c.type === 4
827
+ /* NumericParam */
828
+ ) ? t.push(o) : d.some(
829
+ (c) => c.type === 2
830
+ /* Param */
831
+ ) ? n.push(o) : e.push(o);
832
+ }
833
+ const a = (o, d) => o.fragments.length > d.fragments.length ? -1 : 1;
834
+ return e.sort(a), t.sort(a), n.sort(a), i.sort(a), [...e, ...t, ...n, ...i];
835
+ }
836
+ function Ft(r) {
837
+ const e = ye(r), t = [];
838
+ for (let n = 0; n < e.length; n++) {
839
+ const i = e[n];
840
+ if (i === "*") {
841
+ if (n !== e.length - 1)
842
+ throw new Error(`Wildcard must be at the end of a pattern. Received: ${r}`);
843
+ t.push({
844
+ type: 3,
845
+ name: "*",
846
+ value: null
847
+ });
848
+ } else i.at(0) === "{" && i.at(-1) === "}" ? t.push({
849
+ type: i[1] === "#" ? 4 : 2,
850
+ name: i[1] === "#" ? i.slice(2, -1) : i.slice(1, -1),
851
+ value: null
852
+ }) : t.push({
853
+ type: 1,
854
+ name: i,
855
+ value: i
856
+ });
857
+ }
858
+ return t;
859
+ }
860
+ var gt = /* @__PURE__ */ ((r) => (r.hash = "hash", r.path = "path", r))(gt || {}), Le, j, X, S, We, W, ke, Z, ee, he, ue, fe, Se, G, Ye, Xe;
861
+ class pt {
862
+ constructor(e, t) {
863
+ f(this, G);
864
+ f(this, Le);
865
+ f(this, j);
866
+ f(this, X);
867
+ f(this, S, Dt());
868
+ f(this, We, 0);
869
+ f(this, W, []);
870
+ f(this, ke);
871
+ f(this, Z, []);
872
+ f(this, ee);
873
+ /**
874
+ * The currently matched route pattern, if any.
875
+ */
876
+ k(this, "$pattern");
877
+ f(this, he);
878
+ /**
879
+ * The current URL path.
880
+ */
881
+ k(this, "$path");
882
+ f(this, ue);
883
+ /**
884
+ * The current named path params.
885
+ */
886
+ k(this, "$params");
887
+ f(this, fe);
888
+ /**
889
+ * The current query params. Changes to this object will be reflected in the URL.
890
+ */
891
+ k(this, "$query");
892
+ f(this, Se);
893
+ w(this, Le, e), w(this, j, e.createLogger("dolla/router")), w(this, X, t);
894
+ const [n, i] = Q(null), [a, o] = Q(""), [d, c] = Q({}), [h, y] = Q(Je(window.location.search));
895
+ this.$pattern = n, w(this, he, i), this.$path = a, w(this, ue, o), this.$params = d, w(this, fe, c), this.$query = h, w(this, Se, y), e.beforeMount(() => {
896
+ w(this, ee, lt([h], (g) => {
897
+ const p = new URLSearchParams();
898
+ for (const N in g)
899
+ p.set(N, String(g[N]));
900
+ const $ = "?" + p.toString();
901
+ $ != s(this, S).location.search && s(this, S).replace({
902
+ pathname: s(this, S).location.pathname,
903
+ search: $
904
+ });
905
+ }));
906
+ const b = (g) => {
907
+ P(this, G, Xe).call(this, g);
908
+ };
909
+ s(this, S).listen(b), P(this, G, Xe).call(this, s(this, S)), s(this, j).info("Intercepting <a> clicks within root element:", s(this, X).rootElement), mt(s(this, X).rootElement, (g) => {
910
+ let p = g.getAttribute("href");
911
+ s(this, j).info("Intercepted link click", g, p), /^https?:\/\/|^\//.test(p) || (p = se([s(this, S).location.pathname, p])), s(this, S).push(p);
912
+ });
913
+ }), e.onUnmount(() => {
914
+ s(this, ee) && (s(this, ee).call(this), w(this, ee, void 0));
915
+ });
916
+ }
917
+ setup(e) {
918
+ e.style === "hash" && w(this, S, Ht()), w(this, Z, Vt(
919
+ e.routes.flatMap((t) => P(this, G, Ye).call(this, t)).map((t) => ({
920
+ pattern: t.pattern,
921
+ meta: t.meta,
922
+ fragments: Ft(t.pattern)
923
+ }))
924
+ ));
925
+ for (const t of s(this, Z))
926
+ if (t.meta.redirect) {
927
+ let n;
928
+ if (!Ze(t.meta.redirect)) if (H(t.meta.redirect)) {
929
+ if (n = t.meta.redirect, !ot(s(this, Z), n, {
930
+ willMatch(a) {
931
+ return a !== t;
932
+ }
933
+ }))
934
+ throw new Error(
935
+ `Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`
936
+ );
937
+ } else
938
+ throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
939
+ }
940
+ }
941
+ /**
942
+ * Navigates to another route.
943
+ *
944
+ * @example
945
+ * navigate("/login"); // navigate to `/login`
946
+ * navigate(["/users", 215], { replace: true }); // replace current history entry with `/users/215`
947
+ */
948
+ go(e, t = {}) {
949
+ let n;
950
+ Array.isArray(e) ? n = se(e) : n = e.toString(), n = Ue(s(this, S).location.pathname, n), t.preserveQuery && (n += s(this, S).location.search), t.replace ? s(this, S).replace(n) : s(this, S).push(n);
951
+ }
952
+ /**
953
+ * Navigate backward. Pass a number of steps to hit the back button that many times.
954
+ */
955
+ back(e = 1) {
956
+ s(this, S).go(-e);
957
+ }
958
+ /**
959
+ * Navigate forward. Pass a number of steps to hit the forward button that many times.
960
+ */
961
+ forward(e = 1) {
962
+ s(this, S).go(e);
963
+ }
964
+ }
965
+ Le = new WeakMap(), j = new WeakMap(), X = new WeakMap(), S = new WeakMap(), We = new WeakMap(), W = new WeakMap(), ke = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), he = new WeakMap(), ue = new WeakMap(), fe = new WeakMap(), Se = new WeakMap(), G = new WeakSet(), /**
966
+ * Parses a route definition object into a set of matchable routes.
967
+ *
968
+ * @param route - Route config object.
969
+ * @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
970
+ */
971
+ Ye = function(e, t = [], n = []) {
972
+ if (!(typeof e == "object" && !Array.isArray(e)) || typeof e.path != "string")
973
+ throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
974
+ if (e.redirect && e.routes)
975
+ throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
976
+ if (e.redirect && e.view)
977
+ throw new Error("Route cannot have both a 'redirect' and a 'view'.");
978
+ if (!e.view && !e.routes && !e.redirect)
979
+ throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
980
+ let i = [];
981
+ for (const h of t)
982
+ i.push(...ye(h.path));
983
+ i.push(...ye(e.path)), i[i.length - 1] === "*" && i.pop();
984
+ const a = [];
985
+ if (e.redirect) {
986
+ let h = e.redirect;
987
+ return H(h) && (h = Ue(se(i), h), h.startsWith("/") || (h = "/" + h)), a.push({
988
+ pattern: "/" + se([...i, ...ye(e.path)]),
989
+ meta: {
990
+ redirect: h
991
+ }
992
+ }), a;
993
+ }
994
+ let o = ht;
995
+ if (typeof e.view == "function")
996
+ o = e.view;
997
+ else if (e.view)
998
+ throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
999
+ const d = Qe(o), c = { id: tt(this, We)._++, markup: d };
1000
+ if (e.routes)
1001
+ for (const h of e.routes)
1002
+ a.push(...P(this, G, Ye).call(this, h, [...t, e], [...n, c]));
1003
+ else
1004
+ a.push({
1005
+ pattern: parent ? se([...t.map((h) => h.path), e.path]) : e.path,
1006
+ meta: {
1007
+ pattern: e.path,
1008
+ layers: [...n, c],
1009
+ beforeMatch: e.beforeMatch
1010
+ }
1011
+ });
1012
+ return a;
1013
+ }, Xe = async function({ location: e }) {
1014
+ e.search !== s(this, ke) && (w(this, ke, e.search), s(this, Se).call(this, Je(e.search)));
1015
+ const t = ot(s(this, Z), e.pathname);
1016
+ if (!t) {
1017
+ s(this, he).call(this, null), s(this, ue).call(this, e.pathname), s(this, fe).call(this, {
1018
+ wildcard: e.pathname
1019
+ });
1020
+ return;
1021
+ }
1022
+ if (t.meta.beforeMatch && await t.meta.beforeMatch({
1023
+ redirect: (n) => {
1024
+ throw new Error("Redirect not yet implemented.");
1025
+ }
1026
+ }), s(this, j).info(`Matched route: '${t.pattern}' ('${t.path}')`), t.meta.redirect != null)
1027
+ if (typeof t.meta.redirect == "string") {
1028
+ const n = zt(t.meta.redirect, t.params);
1029
+ s(this, j).info(`Redirecting to: '${n}'`), s(this, S).replace(n);
1030
+ } else if (typeof t.meta.redirect == "function") {
1031
+ const n = {
1032
+ path: t.path,
1033
+ pattern: t.pattern,
1034
+ params: t.params,
1035
+ query: t.query
1036
+ };
1037
+ let i = await t.meta.redirect(n);
1038
+ if (typeof i != "string")
1039
+ throw new Error("Redirect function must return a path to redirect to.");
1040
+ i.startsWith("/") || (i = Ue(t.path, i)), s(this, j).info(`Redirecting to: '${i}'`), s(this, S).replace(i);
1041
+ } else
1042
+ throw new TypeError("Redirect must either be a path string or a function.");
1043
+ else if (s(this, ue).call(this, t.path), s(this, fe).call(this, t.params), t.pattern !== this.$pattern.get()) {
1044
+ s(this, he).call(this, t.pattern);
1045
+ const n = t.meta.layers;
1046
+ for (let i = 0; i < n.length; i++) {
1047
+ const a = n[i], o = s(this, W)[i];
1048
+ if ((o == null ? void 0 : o.id) !== a.id) {
1049
+ s(this, j).info(`Replacing layer @${i} (active ID: ${o == null ? void 0 : o.id}, matched ID: ${a.id})`), w(this, W, s(this, W).slice(0, i));
1050
+ const d = s(this, W).at(-1), c = {
1051
+ dolla: s(this, Le)
1052
+ }, h = Et(a.markup, c), y = Lt(h);
1053
+ o && o.handle.connected && o.handle.disconnect(), d ? d.handle.setChildren(h) : s(this, X).rootView.setChildren(h), s(this, W).push({ id: a.id, handle: y });
1054
+ }
1055
+ }
1056
+ }
1057
+ };
1058
+ const Wt = /(noopener|noreferrer) (noopener|noreferrer)/, It = /^[\w-_]+:/;
1059
+ function mt(r, e, t = window) {
1060
+ function n(a) {
1061
+ return !a || a === r ? null : a.localName !== "a" || a.href === void 0 ? n(a.parentNode) : a;
1062
+ }
1063
+ function i(a) {
1064
+ if (a.button && a.button !== 0 || a.ctrlKey || a.metaKey || a.altKey || a.shiftKey || a.defaultPrevented)
1065
+ return;
1066
+ const o = n(a.target);
1067
+ o && (t.location.protocol !== o.protocol || t.location.hostname !== o.hostname || t.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" && Wt.test(o.getAttribute("rel")) || It.test(o.getAttribute("href")) || (a.preventDefault(), e(o)));
1068
+ }
1069
+ return r.addEventListener("click", i), function() {
1070
+ r.removeEventListener("click", i);
1071
+ };
1072
+ }
1073
+ function zt(r, e) {
1074
+ for (const t in e) {
1075
+ const n = e[t].toString();
1076
+ r = r.replace(`{${t}}`, n).replace(`{#${t}}`, n);
1077
+ }
1078
+ return r;
1079
+ }
1080
+ const Jt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1081
+ __proto__: null,
1082
+ Router: pt,
1083
+ RoutingStyle: gt,
1084
+ catchLinks: mt
1085
+ }, Symbol.toStringTag, { value: "Module" }));
1086
+ var I, Pe, te, ne, Re, xe, Me, Oe, x, z;
1087
+ class Gt {
1088
+ constructor() {
1089
+ f(this, I, !1);
1090
+ f(this, Pe, "production");
1091
+ f(this, te);
1092
+ f(this, ne);
1093
+ k(this, "http");
1094
+ k(this, "language");
1095
+ k(this, "render");
1096
+ k(this, "router");
1097
+ f(this, Re, []);
1098
+ f(this, xe, []);
1099
+ f(this, Me, []);
1100
+ f(this, Oe, []);
1101
+ f(this, x, {
1102
+ info: "development",
1103
+ log: "development",
1104
+ warn: "development",
1105
+ error: !0
1106
+ });
1107
+ f(this, z, nt("*,-dolla/*"));
1108
+ k(this, "createSignal", Q);
1109
+ k(this, "createSettableSignal", kt);
1110
+ k(this, "toSettableSignal", St);
1111
+ k(this, "signalify", Ge);
1112
+ k(this, "designalify", Pt);
1113
+ k(this, "derive", Be);
1114
+ k(this, "watch", lt);
1115
+ k(this, "createRef", Rt);
1116
+ k(this, "isRef", xt);
1117
+ const e = this;
1118
+ this.http = new Ot(), this.language = new Ct(this), this.render = new qt(this), this.router = new pt(this, {
1119
+ get rootElement() {
1120
+ return s(e, te);
1121
+ },
1122
+ get rootView() {
1123
+ return s(e, ne);
1124
+ }
1125
+ });
1126
+ }
1127
+ get isMounted() {
1128
+ return s(this, I);
1129
+ }
1130
+ get env() {
1131
+ return s(this, Pe);
1132
+ }
1133
+ set env(e) {
1134
+ w(this, Pe, e);
1135
+ }
1136
+ async mount(e, t) {
1137
+ if (s(this, I))
1138
+ throw new Error("Dolla is already mounted.");
1139
+ if (H(e)) {
1140
+ const a = document.querySelector(e);
1141
+ rt(HTMLElement, a, `Selector '${e}' did not match any element.`), w(this, te, a);
1142
+ } else
1143
+ rt(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), w(this, te, e);
1144
+ let n;
1145
+ t ? n = Qe(t) : n = Qe(ht), w(this, ne, at({ dolla: this }, n.type, n.props)), await Promise.all(s(this, Re).map((a) => a())), s(this, ne).connect(s(this, te)), w(this, I, !0);
1146
+ for (const a of s(this, xe))
1147
+ a();
1148
+ }
1149
+ async unmount() {
1150
+ var e;
1151
+ if (s(this, I)) {
1152
+ await Promise.all(s(this, Me).map((t) => t())), (e = s(this, ne)) == null || e.disconnect(), w(this, I, !1);
1153
+ for (const t of s(this, Oe))
1154
+ t();
1155
+ }
1156
+ }
1157
+ /**
1158
+ * Registers a `callback` to run after `Dolla.mount` is called, before the app is mounted. If `callback` returns a Promise,
1159
+ * it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
1160
+ */
1161
+ beforeMount(e) {
1162
+ s(this, Re).push(e);
1163
+ }
1164
+ /**
1165
+ * Registers a `callback` to run after the app is mounted.
1166
+ */
1167
+ onMount(e) {
1168
+ s(this, xe).push(e);
1169
+ }
1170
+ /**
1171
+ * Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
1172
+ * it will be awaited before unmounting finishes. Use this to perform cleanup.
1173
+ */
1174
+ beforeUnmount(e) {
1175
+ s(this, Me).push(e);
1176
+ }
1177
+ /**
1178
+ * Registers a `callback` to run after the app is unmounted.
1179
+ */
1180
+ onUnmount(e) {
1181
+ s(this, Oe).push(e);
1182
+ }
1183
+ /**
1184
+ * Update log level settings. Values that are not passed will remain unchanged.
1185
+ */
1186
+ setLoggles(e) {
1187
+ for (const t in e) {
1188
+ const n = e[t];
1189
+ n && (s(this, x)[t] = n);
1190
+ }
1191
+ }
1192
+ setLogFilter(e) {
1193
+ w(this, z, nt(e));
1194
+ }
1195
+ createLogger(e, t) {
1196
+ const n = Ge(e), i = (t == null ? void 0 : t.console) ?? Mt(), a = this;
1197
+ return {
1198
+ get info() {
1199
+ var d;
1200
+ const o = n.get();
1201
+ if (s(a, x).info === !1 || H(s(a, x).info) && s(a, x).info !== a.env || !s(d = a, z).call(d, o))
1202
+ return Ne;
1203
+ {
1204
+ let c = `%c${o}`;
1205
+ return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.info.bind(
1206
+ i,
1207
+ c,
1208
+ `color:${Te(c)};font-weight:bold`,
1209
+ "color:#777",
1210
+ "color:#aaa",
1211
+ "color:#777"
1212
+ );
1213
+ }
1214
+ },
1215
+ get log() {
1216
+ var d;
1217
+ const o = n.get();
1218
+ if (s(a, x).log === !1 || H(s(a, x).log) && s(a, x).log !== a.env || !s(d = a, z).call(d, o))
1219
+ return Ne;
1220
+ {
1221
+ let c = `%c${o}`;
1222
+ return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.log.bind(
1223
+ i,
1224
+ c,
1225
+ `color:${Te(c)};font-weight:bold`,
1226
+ "color:#777",
1227
+ "color:#aaa",
1228
+ "color:#777"
1229
+ );
1230
+ }
1231
+ },
1232
+ get warn() {
1233
+ var d;
1234
+ const o = n.get();
1235
+ if (s(a, x).warn === !1 || H(s(a, x).warn) && s(a, x).warn !== a.env || !s(d = a, z).call(d, o))
1236
+ return Ne;
1237
+ {
1238
+ let c = `%c${o}`;
1239
+ return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.warn.bind(
1240
+ i,
1241
+ c,
1242
+ `color:${Te(c)};font-weight:bold`,
1243
+ "color:#777",
1244
+ "color:#aaa",
1245
+ "color:#777"
1246
+ );
1247
+ }
1248
+ },
1249
+ get error() {
1250
+ var d;
1251
+ const o = n.get();
1252
+ if (s(a, x).error === !1 || H(s(a, x).error) && s(a, x).error !== a.env || !s(d = a, z).call(d, o))
1253
+ return Ne;
1254
+ {
1255
+ let c = `%c${o}`;
1256
+ return t != null && t.uid ? c += ` %c[uid: %c${t.uid}%c]` : c += "%c%c%c", i.error.bind(
1257
+ i,
1258
+ c,
1259
+ `color:${Te(c)};font-weight:bold`,
1260
+ "color:#777",
1261
+ "color:#aaa",
1262
+ "color:#777"
1263
+ );
1264
+ }
1265
+ },
1266
+ crash(o) {
1267
+ }
1268
+ };
1269
+ }
1270
+ constructView(e, t, n = []) {
1271
+ return at({ dolla: this }, e, t, n);
1272
+ }
1273
+ }
1274
+ I = new WeakMap(), Pe = new WeakMap(), te = new WeakMap(), ne = new WeakMap(), Re = new WeakMap(), xe = new WeakMap(), Me = new WeakMap(), Oe = new WeakMap(), x = new WeakMap(), z = new WeakMap();
1275
+ const L = new Gt(), Yt = L.beforeMount.bind(L), Xt = L.onMount.bind(L), Zt = L.beforeUnmount.bind(L), en = L.onUnmount.bind(L), tn = L.mount.bind(L), nn = L.unmount.bind(L), rn = L.http, an = L.render, sn = L.createLogger.bind(L), on = L.setLogFilter.bind(L), cn = L.setLoggles.bind(L), ln = L.language.t.bind(L.language), hn = L.constructView.bind(L);
1276
+ export {
1277
+ dn as Fragment,
1278
+ Yt as beforeMount,
1279
+ Zt as beforeUnmount,
1280
+ gn as cond,
1281
+ hn as constructView,
1282
+ sn as createLogger,
1283
+ Rt as createRef,
1284
+ kt as createSettableSignal,
1285
+ Q as createSignal,
1286
+ pn as createSignalSetter,
1287
+ L as default,
1288
+ Be as derive,
1289
+ Pt as designalify,
1290
+ rn as http,
1291
+ xt as isRef,
1292
+ Qe as m,
1293
+ tn as mount,
1294
+ Xt as onMount,
1295
+ en as onUnmount,
1296
+ mn as portal,
1297
+ an as render,
1298
+ yn as repeat,
1299
+ Jt as router,
1300
+ on as setLogFilter,
1301
+ cn as setLogges,
1302
+ Ge as signalify,
1303
+ ln as t,
1304
+ St as toSettableSignal,
1305
+ nn as unmount,
1306
+ lt as watch
1307
+ };
1308
+ //# sourceMappingURL=index.js.map