@manyducks.co/dolla 2.0.0 → 3.1.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 (112) hide show
  1. package/README.md +133 -284
  2. package/dist/context-B5blupD2.js +363 -0
  3. package/dist/context-B5blupD2.js.map +1 -0
  4. package/dist/core/context.d.ts +29 -144
  5. package/dist/core/debug.d.ts +19 -0
  6. package/dist/core/index.d.ts +15 -16
  7. package/dist/core/markup/helpers.d.ts +34 -0
  8. package/dist/core/markup/html.d.ts +3 -0
  9. package/dist/core/{nodes → markup/nodes}/dom.d.ts +5 -4
  10. package/dist/core/markup/nodes/dynamic.d.ts +16 -0
  11. package/dist/core/markup/nodes/element.d.ts +14 -0
  12. package/dist/core/markup/nodes/portal.d.ts +15 -0
  13. package/dist/core/markup/nodes/repeat.d.ts +21 -0
  14. package/dist/core/markup/nodes/view.d.ts +17 -0
  15. package/dist/core/markup/scheduler.d.ts +1 -0
  16. package/dist/core/markup/types.d.ts +62 -0
  17. package/dist/core/markup/utils.d.ts +22 -0
  18. package/dist/core/ref.d.ts +6 -12
  19. package/dist/core/root.d.ts +36 -0
  20. package/dist/core/signals.d.ts +46 -76
  21. package/dist/core/symbols.d.ts +2 -0
  22. package/dist/core-JHktdqjt.js +242 -0
  23. package/dist/core-JHktdqjt.js.map +1 -0
  24. package/dist/http/index.d.ts +21 -33
  25. package/dist/http.js +89 -149
  26. package/dist/http.js.map +1 -1
  27. package/dist/index.js +4 -174
  28. package/dist/jsx-dev-runtime.d.ts +4 -3
  29. package/dist/jsx-dev-runtime.js +12 -9
  30. package/dist/jsx-dev-runtime.js.map +1 -1
  31. package/dist/jsx-runtime.d.ts +5 -4
  32. package/dist/jsx-runtime.js +17 -12
  33. package/dist/jsx-runtime.js.map +1 -1
  34. package/dist/router/index.d.ts +4 -3
  35. package/dist/router/router.d.ts +19 -162
  36. package/dist/router/store.d.ts +12 -0
  37. package/dist/router/types.d.ts +152 -0
  38. package/dist/router/utils.d.ts +99 -0
  39. package/dist/router/utils.test.d.ts +1 -0
  40. package/dist/router.js +428 -5
  41. package/dist/router.js.map +1 -1
  42. package/dist/signals-CMJPGr_M.js +354 -0
  43. package/dist/signals-CMJPGr_M.js.map +1 -0
  44. package/dist/translate/index.d.ts +82 -0
  45. package/dist/translate.js +125 -0
  46. package/dist/translate.js.map +1 -0
  47. package/dist/types.d.ts +21 -39
  48. package/dist/utils.d.ts +41 -29
  49. package/dist/utils.test.d.ts +1 -0
  50. package/dist/virtual/index.d.ts +1 -0
  51. package/dist/virtual/list.d.ts +53 -0
  52. package/package.json +19 -16
  53. package/dist/core/app.d.ts +0 -24
  54. package/dist/core/env.d.ts +0 -3
  55. package/dist/core/hooks.d.ts +0 -70
  56. package/dist/core/logger.d.ts +0 -42
  57. package/dist/core/logger.test.d.ts +0 -0
  58. package/dist/core/markup.d.ts +0 -82
  59. package/dist/core/markup.test.d.ts +0 -0
  60. package/dist/core/nodes/_markup.d.ts +0 -36
  61. package/dist/core/nodes/dynamic.d.ts +0 -22
  62. package/dist/core/nodes/element.d.ts +0 -27
  63. package/dist/core/nodes/portal.d.ts +0 -18
  64. package/dist/core/nodes/repeat.d.ts +0 -27
  65. package/dist/core/nodes/view.d.ts +0 -25
  66. package/dist/core/views/default-crash-view.d.ts +0 -25
  67. package/dist/core/views/for.d.ts +0 -21
  68. package/dist/core/views/fragment.d.ts +0 -7
  69. package/dist/core/views/portal.d.ts +0 -16
  70. package/dist/core/views/show.d.ts +0 -25
  71. package/dist/fragment-BahD_BJA.js +0 -7
  72. package/dist/fragment-BahD_BJA.js.map +0 -1
  73. package/dist/i18n/index.d.ts +0 -134
  74. package/dist/i18n.js +0 -309
  75. package/dist/i18n.js.map +0 -1
  76. package/dist/index-DRJlxs-Q.js +0 -535
  77. package/dist/index-DRJlxs-Q.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/logger-Aqi9m1CF.js +0 -565
  80. package/dist/logger-Aqi9m1CF.js.map +0 -1
  81. package/dist/markup-8jNhoqDe.js +0 -1089
  82. package/dist/markup-8jNhoqDe.js.map +0 -1
  83. package/dist/router/hooks.d.ts +0 -2
  84. package/dist/router/router.utils.d.ts +0 -93
  85. package/dist/typeChecking-5kmX0ulW.js +0 -65
  86. package/dist/typeChecking-5kmX0ulW.js.map +0 -1
  87. package/dist/typeChecking.d.ts +0 -95
  88. package/docs/buildless.md +0 -132
  89. package/docs/components.md +0 -238
  90. package/docs/hooks.md +0 -356
  91. package/docs/http.md +0 -178
  92. package/docs/i18n.md +0 -220
  93. package/docs/index.md +0 -10
  94. package/docs/markup.md +0 -136
  95. package/docs/mixins.md +0 -176
  96. package/docs/ref.md +0 -77
  97. package/docs/router.md +0 -281
  98. package/docs/setup.md +0 -137
  99. package/docs/signals.md +0 -262
  100. package/docs/stores.md +0 -113
  101. package/docs/views.md +0 -356
  102. package/notes/atomic.md +0 -452
  103. package/notes/elimination.md +0 -33
  104. package/notes/observable.md +0 -180
  105. package/notes/scratch.md +0 -565
  106. package/notes/splitting.md +0 -5
  107. package/notes/views.md +0 -195
  108. package/vite.config.js +0 -22
  109. /package/dist/core/{hooks.test.d.ts → markup/html.test.d.ts} +0 -0
  110. /package/dist/core/{ref.test.d.ts → markup/utils.test.d.ts} +0 -0
  111. /package/dist/router/{router.utils.test.d.ts → matcher.test.d.ts} +0 -0
  112. /package/dist/{typeChecking.test.d.ts → router/router.test.d.ts} +0 -0
@@ -0,0 +1,152 @@
1
+ import type { Setter, Getter, MarkupNode, Renderable, View } from "../core";
2
+ import type { Context } from "../core/context";
3
+ import type { Match } from "./utils";
4
+ export type Stringable = {
5
+ toString(): string;
6
+ };
7
+ export type LazyLoader<Props = any> = () => Promise<{
8
+ default: View<Props>;
9
+ } | View<Props>>;
10
+ export interface LazyView<Props = any> {
11
+ _lazy: true;
12
+ load: LazyLoader<Props>;
13
+ }
14
+ export interface Route<Data = any> {
15
+ /**
16
+ * The path or path fragment to match.
17
+ */
18
+ path: string;
19
+ /**
20
+ * Path to redirect to when this route is matched, or a callback function that returns such path.
21
+ */
22
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
23
+ preload?: (match: Match) => Data | Promise<Data>;
24
+ /**
25
+ * View to display when this route is matched.
26
+ */
27
+ view?: View<{
28
+ data?: Data;
29
+ children: Renderable;
30
+ }> | LazyView<{
31
+ data?: Data;
32
+ children: Renderable;
33
+ }>;
34
+ errorView?: View<{
35
+ error: Error;
36
+ }>;
37
+ /**
38
+ * Subroutes.
39
+ */
40
+ routes?: Route[];
41
+ /**
42
+ * Arbitrary data you'd like to store on this route.
43
+ * This object is accessible via `match.meta` on the `$router` API while the route is active.
44
+ *
45
+ * In the case of nested routes, data from all layers will be merged into a single data object.
46
+ */
47
+ meta?: Record<string | symbol, any>;
48
+ }
49
+ export interface RouteLayer {
50
+ id: string;
51
+ pattern: string;
52
+ view: View<any> | LazyView<any>;
53
+ errorView?: View<{
54
+ error: Error;
55
+ }>;
56
+ preload?: (match: Match) => any | Promise<any>;
57
+ }
58
+ /**
59
+ * An active route layer whose markup has been initialized into a view.
60
+ */
61
+ export interface ActiveLayer {
62
+ id: string;
63
+ key: string;
64
+ node: MarkupNode;
65
+ context: Context;
66
+ slot: Getter<MarkupNode | undefined>;
67
+ setSlot: Setter<MarkupNode | undefined>;
68
+ }
69
+ /**
70
+ * A log for a single step in the route resolution process.
71
+ */
72
+ export interface JourneyStep {
73
+ kind: "match" | "redirect" | "miss";
74
+ message: string;
75
+ }
76
+ export interface NavigateOptions {
77
+ /**
78
+ * Preserve existing query params (if any) when navigating. Defaults to false.
79
+ * If true, all existing query params are preserved and merged with new ones.
80
+ * If an array of strings is passed only those keys will be preserved, then merged with any new ones.
81
+ */
82
+ preserveQuery?: boolean | string[];
83
+ }
84
+ export interface RouterOptions {
85
+ routes: Route[];
86
+ /**
87
+ * When true, the router will construct routes like "https://www.example.com/#/sub/route" which work without any backend intervention.
88
+ */
89
+ hash?: boolean;
90
+ /**
91
+ * Persist query params between pages when navigating. Pass an array to specify a list of params that will be preserved.
92
+ * By default all query params are cleared when navigating to a new URL (equivalent to `false`).
93
+ */
94
+ preserveQuery?: boolean | string[];
95
+ }
96
+ export interface Router {
97
+ /**
98
+ * The current path as it is displayed in the URL bar (e.g. `/users/123/edit`).
99
+ */
100
+ path: Getter<string>;
101
+ /**
102
+ * The route pattern that was matched (e.g. `/users/{#id}/edit`), or undefined if no route is currently matched.
103
+ */
104
+ pattern: Getter<string | undefined>;
105
+ /**
106
+ * The extracted route parameters from the path. (e.g. `{ id: "123" }`)
107
+ */
108
+ params: Getter<Record<string, string>>;
109
+ /**
110
+ * The current query params.
111
+ */
112
+ query: Getter<Record<string, string>>;
113
+ /**
114
+ * The contents of the `meta` fields of all matched route layers.
115
+ */
116
+ meta: Getter<Record<string, string>>;
117
+ /**
118
+ * Represents the loading progress of the current navigation from 0 to 1.
119
+ * Returns 0 when no navigation is pending.
120
+ */
121
+ progress: Getter<number>;
122
+ /**
123
+ * Update query params without changing the route.
124
+ */
125
+ setQuery(params: Record<string, Stringable>): Record<string, string>;
126
+ /**
127
+ * Go back in the page history. Equivalent to hitting the back button.
128
+ * Steps is the number of times to hit the back button. The default is 1.
129
+ */
130
+ back(steps?: number): void;
131
+ /**
132
+ * Go forward in the page history. Equivalent to hitting the forward button.
133
+ * Steps is the number of times to hit the forward button. The default is 1.
134
+ */
135
+ forward(steps?: number): void;
136
+ /**
137
+ * Push a new route into the page history and navigate to it.
138
+ */
139
+ push(path: string): void;
140
+ /**
141
+ * Replace the current route in the page history and navigate to it.
142
+ */
143
+ replace(path: string): void;
144
+ /**
145
+ * Prevents attempted navigations if the condition returns true.
146
+ */
147
+ block(guard: () => boolean | Promise<boolean>): () => void;
148
+ /**
149
+ * Contains `true` when the current route matches `path`.
150
+ */
151
+ isActive(path: string, exact?: boolean): Getter<boolean>;
152
+ }
@@ -0,0 +1,99 @@
1
+ import type { JourneyStep, Route, RouteLayer, Stringable } from "./types.js";
2
+ export interface Match {
3
+ /**
4
+ * The path string that triggered this match.
5
+ */
6
+ path: string;
7
+ /**
8
+ * The pattern satisfied by `path`.
9
+ */
10
+ pattern: string;
11
+ /**
12
+ * Named params as parsed from `path`.
13
+ */
14
+ params: Record<string, string>;
15
+ /**
16
+ * Query params as parsed from `path`.
17
+ */
18
+ query: Record<string, string>;
19
+ /**
20
+ * Freeform data you wish to store with this route.
21
+ * Merged `data` from all matched layers are available on the router's `match.meta`.
22
+ */
23
+ meta: Record<any, any>;
24
+ }
25
+ export interface RouteMatch extends Match {
26
+ layers: RouteLayer[];
27
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
28
+ }
29
+ export type RoutePayload = {
30
+ pattern: string;
31
+ meta: Record<any, any>;
32
+ layers?: RouteLayer[];
33
+ redirect?: string | ((match: Match) => string) | ((match: Match) => Promise<string>);
34
+ };
35
+ export type RouteMatchOptions = {
36
+ willMatch?: (route: RoutePayload) => boolean;
37
+ };
38
+ /**
39
+ * Separates a URL path into multiple fragments.
40
+ *
41
+ * @param path - A path string (e.g. `"/api/users/5"`)
42
+ * @returns an array of fragments (e.g. `["api", "users", "5"]`)
43
+ */
44
+ export declare function splitPath(path: string): string[];
45
+ /**
46
+ * Joins multiple URL path fragments into a single string.
47
+ *
48
+ * @param parts - One or more URL fragments (e.g. `["api", "users", 5]`)
49
+ * @returns a joined path (e.g. `"api/users/5"`)
50
+ */
51
+ export declare function joinPath(parts: {
52
+ toString(): string;
53
+ }[]): string;
54
+ export declare function resolvePath(base: string, part?: string | null): string;
55
+ export declare function parseQueryParams(query: string): Record<string, string>;
56
+ export declare function mergeQueryParams(previous: Record<string, string>, current: Record<string, Stringable>, preserve?: boolean | string[]): URLSearchParams;
57
+ export declare class RouteNode {
58
+ staticChildren: Map<string, RouteNode>;
59
+ numericChild: RouteNode | null;
60
+ paramChild: RouteNode | null;
61
+ wildcardChild: RouteNode | null;
62
+ route?: RoutePayload;
63
+ paramName?: string;
64
+ numericName?: string;
65
+ }
66
+ export declare function buildRouteTree(routes: Route[]): RouteNode;
67
+ export declare function matchRoute(rootNode: RouteNode, url: string, options?: RouteMatchOptions): RouteMatch | undefined;
68
+ export interface ResolvedRoute {
69
+ match?: RouteMatch;
70
+ journey: JourneyStep[];
71
+ }
72
+ /**
73
+ * Takes a URL and finds a match, following redirects.
74
+ */
75
+ export declare function resolveRoute(rootNode: RouteNode, path: string, journey?: JourneyStep[]): Promise<ResolvedRoute>;
76
+ /**
77
+ * Intercepts links within the root node.
78
+ *
79
+ * This is adapted from https://github.com/choojs/nanohref/blob/master/index.js
80
+ *
81
+ * @param root - Element under which to intercept link clicks
82
+ * @param callback - Function to call when a click event is intercepted
83
+ * @param _window - (optional) Override for global window object
84
+ */
85
+ export declare function catchLinks(root: Element, callback: (href: string, anchor: HTMLAnchorElement) => void, _window?: Window & typeof globalThis): () => void;
86
+ export declare function expandOptionalPaths(path: string): string[];
87
+ /**
88
+ * Replace route pattern param placeholders with real matched values.
89
+ */
90
+ export declare function replaceParams(path: string, params: Record<string, string | number>): string;
91
+ export interface HistoryAdapter {
92
+ getPath(): string;
93
+ getSearch(): string;
94
+ getKey(): string;
95
+ getIndex(): number;
96
+ push(url: string): void;
97
+ replace(url: string): void;
98
+ }
99
+ export declare function createHistoryAdapter(useHash: boolean): HistoryAdapter;
@@ -0,0 +1 @@
1
+ export {};
package/dist/router.js CHANGED
@@ -1,6 +1,429 @@
1
- import { c as o, u as t } from "./index-DRJlxs-Q.js";
2
- export {
3
- o as createRouter,
4
- t as useRouter
1
+ import { a as e, c as t, f as n, h as r, l as i, n as a, p as o, r as s, t as c, u as l } from "./signals-CMJPGr_M.js";
2
+ import { a as u, b as d, d as f, i as p, l as m, m as h, n as g, p as _, s as v, t as y, v as b } from "./context-B5blupD2.js";
3
+ import { c as x } from "./core-JHktdqjt.js";
4
+ //#region src/router/utils.ts
5
+ function S(e) {
6
+ return e.split("/").map((e) => e.trim()).filter(Boolean);
7
+ }
8
+ function C(e) {
9
+ let t = e.map((e) => e.toString()).filter(Boolean).join("/");
10
+ if (!t) return "";
11
+ let n = t.startsWith("/"), r = t.split("/"), i = [];
12
+ for (let e of r) e === "" || e === "." || (e === ".." ? i.length > 0 && i[i.length - 1] !== ".." ? i.pop() : n || i.push("..") : i.push(e));
13
+ let a = i.join("/");
14
+ return n && (a = "/" + a), a || (n ? "/" : "");
15
+ }
16
+ function w(e, t = null) {
17
+ return t ?? (t = e, e = ""), t.startsWith("/") ? C([t]) : C([e, t]);
18
+ }
19
+ function T(e) {
20
+ return Object.fromEntries(new URLSearchParams(e));
21
+ }
22
+ function E(e, t, n) {
23
+ let r = {};
24
+ if (n === !0) Object.assign(r, e);
25
+ else if (i(n)) for (let t of n) t in e && (r[t] = e[t]);
26
+ return Object.assign(r, t), new URLSearchParams(r);
27
+ }
28
+ var D = class {
29
+ staticChildren = /* @__PURE__ */ new Map();
30
+ numericChild = null;
31
+ paramChild = null;
32
+ wildcardChild = null;
33
+ route;
34
+ paramName;
35
+ numericName;
5
36
  };
6
- //# sourceMappingURL=router.js.map
37
+ function O(e) {
38
+ let i = new D(), a = [];
39
+ function s(e, t) {
40
+ let n = S(e), r = i;
41
+ for (let e of n) if (e === "*") r = r.wildcardChild ??= new D();
42
+ else if (e.charCodeAt(0) === 123) e.charCodeAt(1) === 35 ? (r = r.numericChild ??= new D(), r.numericName = e.slice(2, -1)) : (r = r.paramChild ??= new D(), r.paramName = e.slice(1, -1));
43
+ else {
44
+ let t = e.toLowerCase(), n = r.staticChildren.get(t);
45
+ n || r.staticChildren.set(t, n = new D()), r = n;
46
+ }
47
+ r.route = t;
48
+ }
49
+ function c(e, i = [], u = []) {
50
+ t(n(e) && o(e.path), "Invalid route object");
51
+ let d = i.map((e) => e.path), f = i.at(-1), p = f && e.meta ? {
52
+ ...f.meta,
53
+ ...e.meta
54
+ } : e.meta || {}, m = d.length ? C([...d, e.path]) : e.path, h = M(m);
55
+ if (e.redirect) {
56
+ t(!e.routes && !e.view, "Route cannot mix redirect with view/routes");
57
+ let n = e.redirect;
58
+ o(n) && (n = w(C(d), n), n.startsWith("/") || (n = "/" + n));
59
+ for (let e of h) {
60
+ let t = {
61
+ pattern: e,
62
+ meta: p,
63
+ redirect: n
64
+ };
65
+ s(e, t), o(n) && a.push(t);
66
+ }
67
+ return;
68
+ }
69
+ t(e.view || e.routes, "Route must have view, redirect, or routes");
70
+ let g = e.view || ((e) => e.children);
71
+ if (!l(g) && !g._lazy) throw TypeError(`Expected view function for ${e.path}`);
72
+ if (e.routes) {
73
+ let t = {
74
+ id: r(),
75
+ pattern: m,
76
+ view: g,
77
+ preload: e.preload,
78
+ errorView: e.errorView
79
+ };
80
+ for (let n of e.routes) c(n, [...i, e], [...u, t]);
81
+ } else for (let t of h) {
82
+ let n = {
83
+ id: r(),
84
+ pattern: t,
85
+ view: g,
86
+ preload: e.preload,
87
+ errorView: e.errorView
88
+ };
89
+ s(t, {
90
+ pattern: t,
91
+ meta: p,
92
+ layers: [...u, n]
93
+ });
94
+ }
95
+ }
96
+ for (let t of e) c(t);
97
+ for (let e of a) t(k(i, e.redirect, { willMatch: (t) => t !== e }), `Dead redirect: ${e.pattern} -> ${e.redirect}`);
98
+ return i;
99
+ }
100
+ function k(e, t, n = {}) {
101
+ let [r, i] = t.split("?"), a = S(r), o = {};
102
+ function s(e, t) {
103
+ if (t === a.length) return e.route && (!n.willMatch || n.willMatch(e.route)) ? {
104
+ path: r || "/",
105
+ pattern: e.route.pattern,
106
+ params: { ...o },
107
+ query: T(i || ""),
108
+ meta: e.route.meta,
109
+ layers: e.route.layers ?? [],
110
+ redirect: e.route.redirect
111
+ } : e.wildcardChild && e.wildcardChild.route && (!n.willMatch || n.willMatch(e.wildcardChild.route)) ? {
112
+ path: r || "/",
113
+ pattern: e.wildcardChild.route.pattern,
114
+ params: {
115
+ ...o,
116
+ wildcard: "/"
117
+ },
118
+ query: T(i || ""),
119
+ meta: e.wildcardChild.route.meta,
120
+ layers: e.wildcardChild.route.layers ?? [],
121
+ redirect: e.wildcardChild.route.redirect
122
+ } : void 0;
123
+ let c = a[t], l = c.toLowerCase(), u = e.staticChildren.get(l);
124
+ if (u) {
125
+ let e = s(u, t + 1);
126
+ if (e) return e;
127
+ }
128
+ if (e.numericChild && !isNaN(Number(c))) {
129
+ o[e.numericChild.numericName] = c;
130
+ let n = s(e.numericChild, t + 1);
131
+ if (n) return n;
132
+ delete o[e.numericChild.numericName];
133
+ }
134
+ if (e.paramChild) {
135
+ o[e.paramChild.paramName] = decodeURIComponent(c);
136
+ let n = s(e.paramChild, t + 1);
137
+ if (n) return n;
138
+ delete o[e.paramChild.paramName];
139
+ }
140
+ if (e.wildcardChild && e.wildcardChild.route && (!n.willMatch || n.willMatch(e.wildcardChild.route))) return {
141
+ path: r || "/",
142
+ pattern: e.wildcardChild.route.pattern,
143
+ params: {
144
+ ...o,
145
+ wildcard: "/" + a.slice(t).map(decodeURIComponent).join("/")
146
+ },
147
+ query: T(i || ""),
148
+ meta: e.wildcardChild.route.meta,
149
+ layers: e.wildcardChild.route.layers ?? [],
150
+ redirect: e.wildcardChild.route.redirect
151
+ };
152
+ }
153
+ return s(e, 0);
154
+ }
155
+ async function A(e, n, r = []) {
156
+ let i = k(e, n);
157
+ if (!i) return { journey: [...r, {
158
+ kind: "miss",
159
+ message: `no match for '${n}'`
160
+ }] };
161
+ if (i.redirect != null) {
162
+ let n = i.redirect;
163
+ return o(n) ? n = N(n, i.params) : (n = await n(i), t(o(n), "Redirect function must return a path."), n.startsWith("/") || (n = w(i.path, n))), A(e, n, [...r, {
164
+ kind: "redirect",
165
+ message: `redirecting '${i.path}' -> '${n}'`
166
+ }]);
167
+ }
168
+ return {
169
+ match: i,
170
+ journey: [...r, {
171
+ kind: "match",
172
+ message: `matched route '${i.path}'`
173
+ }]
174
+ };
175
+ }
176
+ function j(e, t, n = window) {
177
+ function r(r) {
178
+ if (r.button && r.button !== 0 || r.ctrlKey || r.metaKey || r.altKey || r.shiftKey || r.defaultPrevented) return;
179
+ let i = r.target.closest("a");
180
+ if (!i || !e.contains(i)) return;
181
+ let a = i.getAttribute("href");
182
+ a && (n.location.protocol !== i.protocol || n.location.hostname !== i.hostname || n.location.port !== i.port || i.hasAttribute("data-router-ignore") || i.hasAttribute("download") || i.getAttribute("target") === "_blank" || /^[\w-_]+:/.test(a) || (r.preventDefault(), t(a, i)));
183
+ }
184
+ return e.addEventListener("click", r), () => e.removeEventListener("click", r);
185
+ }
186
+ function M(e) {
187
+ let t = S(e), n = [[]];
188
+ for (let e of t) {
189
+ let t = e.endsWith("?}"), r = t ? e.replace("?", "") : e;
190
+ if (t) {
191
+ let e = n.map((e) => [...e, r]);
192
+ n.push(...e);
193
+ } else for (let e of n) e.push(r);
194
+ }
195
+ return n.map((e) => "/" + e.join("/")).map((e) => e === "/" ? e : e.replace(/\/$/, ""));
196
+ }
197
+ function N(e, t) {
198
+ for (let n in t) {
199
+ let r = String(t[n]);
200
+ e = e.replace(`{${n}}`, r).replace(`{#${n}}`, r).replace(`{${n}?}`, r).replace(`{#${n}?}`, r);
201
+ }
202
+ return e = e.replace(/\{#?[a-zA-Z0-9_]+\?\}/g, ""), e = e.replace(/\/+/g, "/"), e.length > 1 && e.endsWith("/") && (e = e.slice(0, -1)), e;
203
+ }
204
+ function P(e) {
205
+ let t = window.history.state?.index || 0;
206
+ window.history.state?.index === void 0 && window.history.replaceState({
207
+ ...window.history.state,
208
+ key: Date.now().toString(),
209
+ index: t
210
+ }, "");
211
+ let n = e ? () => window.location.hash.slice(1).split("?")[0] || "/" : () => window.location.pathname, i = e ? () => {
212
+ let e = window.location.hash, t = e.indexOf("?");
213
+ return t === -1 ? "" : e.slice(t);
214
+ } : () => window.location.search, a = () => window.history.state?.key || "root";
215
+ return {
216
+ getPath: n,
217
+ getSearch: i,
218
+ getKey: a,
219
+ getIndex: () => window.history.state?.index || 0,
220
+ push: (n) => {
221
+ t++;
222
+ let i = e ? "/#" : "";
223
+ window.history.pushState({
224
+ key: r(),
225
+ index: t
226
+ }, "", i + n);
227
+ },
228
+ replace: (n) => {
229
+ let r = e ? "/#" : "";
230
+ window.history.replaceState({
231
+ key: a(),
232
+ index: t
233
+ }, "", r + n);
234
+ }
235
+ };
236
+ }
237
+ //#endregion
238
+ //#region src/router/store.ts
239
+ function F({ currentMatch: t, setCurrentMatch: n, progress: r, history: i, updateRoute: o, guards: s }) {
240
+ this.name = "dolla:router";
241
+ let c = x(this);
242
+ async function l(e, t) {
243
+ for (let e of s) if (await e()) return;
244
+ c.info(`đŸ—ēī¸ navigating to '${e}'${t ? " (replace)" : ""}`);
245
+ let n = w(i.getPath(), e);
246
+ t ? i.replace(n) : i.push(n), o();
247
+ }
248
+ return {
249
+ path: a(() => t().path),
250
+ pattern: a(() => t().pattern),
251
+ params: a(() => t().params),
252
+ query: a(() => t().query),
253
+ meta: a(() => t().meta),
254
+ progress: r,
255
+ setQuery(r) {
256
+ let a = e(t), o = E(a.query, r, !0), s = Object.fromEntries(o);
257
+ n({
258
+ ...a,
259
+ query: s
260
+ });
261
+ let c = o.size ? "?" + o.toString() : "";
262
+ return i.replace(a.path + c), s;
263
+ },
264
+ back: (e = 1) => window.history.go(-e),
265
+ forward: (e = 1) => window.history.go(e),
266
+ push: (e) => l(e, !1),
267
+ replace: (e) => l(e, !0),
268
+ block: (e) => (s.add(e), () => s.delete(e)),
269
+ isActive(e, n = !1) {
270
+ let r = e === "/" ? "/" : e.replace(/\/$/, ""), i = r === "/" ? "/" : r + "/";
271
+ return a(() => {
272
+ let e = t().path, a = e === "/" ? "/" : e.replace(/\/$/, "");
273
+ return n ? a === r : a === r || a.startsWith(i);
274
+ });
275
+ }
276
+ };
277
+ }
278
+ //#endregion
279
+ //#region src/router/router.ts
280
+ var I = Symbol();
281
+ function L(e) {
282
+ return {
283
+ _lazy: !0,
284
+ load: e
285
+ };
286
+ }
287
+ function R(t) {
288
+ return function(n) {
289
+ "scrollRestoration" in window.history && (window.history.scrollRestoration = "manual");
290
+ let r = P(!!t.hash), i = /* @__PURE__ */ new Map(), a = r.getKey(), [o, l] = s({
291
+ path: r.getPath(),
292
+ pattern: "",
293
+ params: {},
294
+ query: Object.fromEntries(new URLSearchParams(r.getSearch())),
295
+ meta: {}
296
+ }), [u, S] = s(0), C = O(t.routes), w = /* @__PURE__ */ new Set(), T = g(n);
297
+ T.name = "dolla:router";
298
+ let D = x(T), [k, M] = s();
299
+ n[I] = k;
300
+ let L = {
301
+ context: n,
302
+ slot: k,
303
+ setSlot: M
304
+ }, R = [];
305
+ async function z(u) {
306
+ i.set(a, window.scrollY);
307
+ let p = u ?? r.getPath(), { match: m, journey: g } = await A(C, p);
308
+ if (n[b]) for (let e = 0; e < g.length; e++) {
309
+ let t = g[e], n = `(update ${e + 1}/${g.length})`;
310
+ t.kind === "match" ? D.info(`📍 ${n} ${t.message}`) : t.kind === "redirect" ? D.info(`â†Šī¸ ${n} ${t.message}`) : D.info(`💀 ${n} ${t.message}`);
311
+ }
312
+ if (!m) throw Error(`Failed to match route '${p}'`);
313
+ let { layers: _, params: v } = m, y = [], x = 0;
314
+ for (let e = 0; e < _.length; e++) {
315
+ let t = `${_[e].id}:${N(_[e].pattern, v)}`;
316
+ y.push(t), x === e && R[e]?.key === t && x++;
317
+ }
318
+ let w = [], T = [];
319
+ for (let e = x; e < _.length; e++) {
320
+ let t = _[e];
321
+ t.preload && w.push(Promise.resolve(t.preload(m)).then((t) => {
322
+ T[e - x] = t;
323
+ }));
324
+ let n = t.view;
325
+ n._lazy && w.push(n.load().then((e) => {
326
+ t.view = e.default ?? e;
327
+ }));
328
+ }
329
+ let O = null, k = -1;
330
+ if (w.length > 0) {
331
+ S(.1);
332
+ let e = 0, t = .8 / w.length;
333
+ w.forEach((n) => n.then(() => S(.1 + ++e * t)).catch(() => {}));
334
+ try {
335
+ await Promise.all(w);
336
+ } catch (e) {
337
+ if (S(0), e instanceof B) return V.replace(e.redirectPath);
338
+ O = e instanceof Error ? e : Error(String(e)), k = x;
339
+ }
340
+ }
341
+ let j = E(e(o).query, m.query, t.preserveQuery), M = j.toString(), P = m.path + (M ? `?${M}` : "");
342
+ P !== r.getPath() + r.getSearch() && r.replace(P), c(() => {
343
+ if (l({
344
+ ...m,
345
+ query: Object.fromEntries(j)
346
+ }), !(x === _.length && R.length === _.length)) {
347
+ R[x] && (R[x].node.unmount(), R.length = x);
348
+ for (let e = x; e < _.length; e++) {
349
+ let t = _[e], n = R[e - 1] ?? L, [r, i] = s(), a = t.view, o = {
350
+ data: T[e - x],
351
+ children: h(d, { args: [r] })
352
+ };
353
+ if (O && e === k) {
354
+ if (!t.errorView) throw O;
355
+ a = t.errorView, o = { error: O };
356
+ }
357
+ let c = new f(n.context, a, o);
358
+ if (n.setSlot(c), R.push({
359
+ id: t.id,
360
+ key: y[e],
361
+ node: c,
362
+ context: c.context,
363
+ slot: r,
364
+ setSlot: i
365
+ }), O && e === k) break;
366
+ }
367
+ }
368
+ }), S(0), requestAnimationFrame(() => {
369
+ window.scrollTo(0, i.get(r.getKey()) ?? 0), a = r.getKey();
370
+ });
371
+ }
372
+ let V = y(n, F, {
373
+ currentMatch: o,
374
+ setCurrentMatch: l,
375
+ progress: u,
376
+ history: r,
377
+ updateRoute: z,
378
+ guards: w
379
+ });
380
+ m(n, () => {
381
+ let e = !1, t = !1, i = r.getIndex(), a = _(window, "popstate", async () => {
382
+ if (e) {
383
+ e = !1;
384
+ return;
385
+ }
386
+ if (t) {
387
+ t = !1, i = r.getIndex(), z();
388
+ return;
389
+ }
390
+ let n = r.getIndex(), a = i - n;
391
+ if (w.size > 0) {
392
+ e = !0, window.history.go(a);
393
+ let n = !1;
394
+ for (let e of w) if (await e()) {
395
+ n = !0;
396
+ break;
397
+ }
398
+ n || (t = !0, window.history.go(-a));
399
+ return;
400
+ }
401
+ i = n, z();
402
+ }), o = _(window, "beforeunload", (e) => {
403
+ w.size > 0 && (e.preventDefault(), e.returnValue = "");
404
+ }), s = j(p(n), V.push);
405
+ v(n, () => {
406
+ a(), o(), s();
407
+ }), z();
408
+ });
409
+ };
410
+ }
411
+ function z() {
412
+ this.name = "dolla:router";
413
+ let e = this[I];
414
+ return t(e != null, "Router plugin not found on root."), new d(this, e);
415
+ }
416
+ var B = class extends Error {
417
+ constructor(e) {
418
+ super(`Redirecting to ${e}`), this.redirectPath = e, this.name = "RedirectError";
419
+ }
420
+ };
421
+ //#endregion
422
+ //#region src/router/index.ts
423
+ function V(e) {
424
+ return u(e, F);
425
+ }
426
+ //#endregion
427
+ export { z as Outlet, B as RedirectError, R as createRouterPlugin, V as getRouter, L as lazy };
428
+
429
+ //# sourceMappingURL=router.js.map