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