@manyducks.co/dolla 2.0.0-alpha.6 → 2.0.0-alpha.61

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