@sigil-dev/grimoire 0.8.6 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "module": "index.ts",
4
4
  "type": "module",
5
5
  "private": false,
6
- "version": "0.8.6",
6
+ "version": "0.9.1",
7
7
  "exports": {
8
8
  ".": "./index.ts",
9
9
  "./server": "./server.ts",
@@ -30,16 +30,14 @@
30
30
  "@babel/plugin-syntax-typescript": "^8.0.0-rc.6",
31
31
  "@babel/preset-typescript": "^8.0.0-rc.6",
32
32
  "@babel/types": "^8.0.0-rc.6",
33
+ "@sigil-dev/compiler": "0.9.1",
34
+ "@sigil-dev/runtime": "0.9.1",
33
35
  "vite": "^8.0.16"
34
36
  },
35
37
  "peerDependencies": {
36
- "@sigil-dev/compiler": "0.8.6",
37
- "@sigil-dev/runtime": "0.8.6",
38
38
  "typescript": "^5"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/bun": "latest",
42
- "@sigil-dev/compiler": "0.8.6",
43
- "@sigil-dev/runtime": "0.8.6"
41
+ "@types/bun": "latest"
44
42
  }
45
43
  }
package/server.ts CHANGED
@@ -4,6 +4,11 @@ export { createServer } from "./src/server";
4
4
  export { buildProject } from "./src/server/build";
5
5
  export { parseCookies } from "./src/server/cookie-utils";
6
6
  export { startCoordinator } from "./src/server/coordinator.ts";
7
+ export {
8
+ createWaiter,
9
+ listenForKeys,
10
+ stopListening,
11
+ } from "./src/server/interactive.ts";
7
12
  export {
8
13
  runDeserializeLocals,
9
14
  runRouteRequest,
@@ -12,4 +17,3 @@ export {
12
17
  } from "./src/server/plugins";
13
18
  export type { TypegenConfig } from "./src/typegen";
14
19
  export { generateTypes } from "./src/typegen";
15
- export {createWaiter, listenForKeys, stopListening} from "./src/server/interactive.ts"
@@ -0,0 +1,13 @@
1
+ const routeDeps = new Map<string, Set<string>>();
2
+ let _collecting: Set<string> | null = null;
3
+
4
+ export function startCollecting(): void { _collecting = new Set(); }
5
+ export function stopCollecting(pattern: string): void {
6
+ if (_collecting) routeDeps.set(pattern, _collecting);
7
+ _collecting = null;
8
+ }
9
+ export function depends(key: string): void { _collecting?.add(key); }
10
+ export function hasDep(pattern: string, key: string): boolean {
11
+ return routeDeps.get(pattern)?.has(key) ?? false;
12
+ }
13
+ export function clearDeps(pattern: string): void { routeDeps.delete(pattern); }
@@ -9,6 +9,7 @@ export function collectHead(): (string | Node)[] {
9
9
  }
10
10
 
11
11
  export function applyHead(): void {
12
+ //biome-ignore lint: ChildNode.remove() returns void??? sure typescript
12
13
  document.querySelectorAll("[data-sigil-head]").forEach((el) => el.remove());
13
14
  for (const el of headElements) {
14
15
  if (el instanceof Node) {
@@ -1,9 +1,43 @@
1
- import { popHydrationNodes, pushHydrationNodes } from "@sigil-dev/runtime";
2
- import { withEffectScope } from "./scope";
1
+ import {popHydrationNodes, pushHydrationNodes} from "@sigil-dev/runtime";
2
+ import {withEffectScope} from "./scope";
3
+
4
+ // ── Dependency tracking ──────────────────────────────────────────────────────
5
+ const routeDeps = new Map<string, Set<string>>(); // pattern → dep keys
6
+ let _collectingDeps: Set<string> | null = null;
7
+
8
+ /**
9
+ * Call from inside a load() function to register a dependency key.
10
+ * When invalidate(key) is called, any route that depends on that key
11
+ * will refetch if it's the current route.
12
+ */
13
+ export function depends(key: string): void {
14
+ _collectingDeps?.add(key);
15
+ }
16
+
17
+ async function refetchCurrent(): Promise<void> {
18
+ if (!lastState) return;
19
+ await navigate(location.pathname, true); // true = replace, no pushState
20
+ }
21
+
22
+ export async function invalidate(...keys: string[]): Promise<void> {
23
+ const current = lastState?.pattern;
24
+ if (!current) return;
25
+ const deps = routeDeps.get(current);
26
+ if (!deps) return;
27
+ if (keys.some(k => deps.has(k))) await refetchCurrent();
28
+ }
29
+
30
+ export async function invalidateAll(): Promise<void> {
31
+ await refetchCurrent();
32
+ }
3
33
 
4
34
  let routeMap: Record<
5
- string,
6
- ((props: any) => any) & { load?: (ctx: any) => Promise<any> }
35
+ string,
36
+ ((props: any) => any) & {
37
+ load?: (ctx: any) => Promise<any>;
38
+ loading?: () => any;
39
+ error?: (props: { error: unknown }) => any;
40
+ }
7
41
  > = {};
8
42
  let layoutList: { path: string; component: (props: any) => any }[] = [];
9
43
  let disposeCurrentPage: (() => void) | null = null;
@@ -20,272 +54,318 @@ let afterNavigateCb: ((url: URL) => void) | null = null;
20
54
  // (globalThis as any).__grimoire_navigate__ = navigate;
21
55
 
22
56
  export async function hmrRerender(): Promise<void> {
23
- if (!lastState) {
24
- location.reload();
25
- return;
26
- }
27
- disposeCurrentPage?.();
28
- pushHydrationNodes([]);
29
- let rootNode: any;
30
- disposeCurrentPage = withEffectScope(() => {
31
- rootNode = buildRouteTree(lastState!);
32
- });
33
- popHydrationNodes();
34
- document.getElementById("grimoire-root")?.replaceChildren(rootNode);
57
+ if (!lastState) {
58
+ location.reload();
59
+ return;
60
+ }
61
+ disposeCurrentPage?.();
62
+ pushHydrationNodes([]);
63
+ let rootNode: any;
64
+ disposeCurrentPage = withEffectScope(() => {
65
+ rootNode = buildRouteTree(lastState!);
66
+ });
67
+ popHydrationNodes();
68
+ document.getElementById("grimoire-root")?.replaceChildren(rootNode);
35
69
  }
36
70
 
37
71
  // (globalThis as any).__grimoire_rerender__ = hmrRerender;
38
72
 
39
73
  export function beforeNavigate(cb: (url: URL) => boolean | undefined): void {
40
- beforeNavigateCb = cb;
74
+ beforeNavigateCb = cb;
41
75
  }
42
76
 
43
77
  export function onNavigate(cb: (url: URL) => void): void {
44
- onNavigateCb = cb;
78
+ onNavigateCb = cb;
45
79
  }
46
80
 
47
81
  export function afterNavigate(cb: (url: URL) => void): void {
48
- afterNavigateCb = cb;
82
+ afterNavigateCb = cb;
49
83
  }
50
84
 
51
85
  // C2: Scroll restoration
52
86
  const scrollPositions = new Map<string, number>();
53
87
 
54
88
  function saveScrollPosition(): void {
55
- scrollPositions.set(currentPath, window.scrollY);
89
+ scrollPositions.set(currentPath, window.scrollY);
56
90
  }
57
91
 
58
92
  function restoreScrollPosition(path: string): void {
59
- const saved = scrollPositions.get(path);
60
- if (saved !== undefined) {
61
- requestAnimationFrame(() => window.scrollTo(0, saved));
62
- } else {
63
- requestAnimationFrame(() => window.scrollTo(0, 0));
64
- }
93
+ const saved = scrollPositions.get(path);
94
+ if (saved !== undefined) {
95
+ requestAnimationFrame(() => window.scrollTo(0, saved));
96
+ } else {
97
+ requestAnimationFrame(() => window.scrollTo(0, 0));
98
+ }
65
99
  }
66
100
 
67
101
  // C3: Preloading
68
102
  let preloadTimer: Timer | null = null;
69
103
 
70
104
  function setupPreload(): void {
71
- document.addEventListener("mouseover", (e) => {
72
- const a = (e.target as Element).closest("a");
73
- if (!a) return;
74
- const href = a.getAttribute("href");
75
- if (!href) return;
76
- if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href)) return;
77
-
78
- const preloadData = a.hasAttribute("data-sigil-preload-data");
79
- const preloadCode = a.hasAttribute("data-sigil-preload-code");
80
- if (!preloadData && !preloadCode) return;
81
-
82
- if (preloadTimer) clearTimeout(preloadTimer);
83
- preloadTimer = setTimeout(() => {
84
- if (preloadCode) {
85
- const link = document.createElement("link");
86
- link.rel = "prefetch";
87
- link.href = href;
88
- document.head.appendChild(link);
89
- }
90
- if (preloadData) {
91
- fetch(href, {
92
- headers: { "x-grimoire-navigate": "1" },
93
- priority: "low",
94
- }).catch(() => {});
95
- }
96
- }, 80);
97
- });
98
-
99
- document.addEventListener("mouseout", (e) => {
100
- const a = (e.target as Element).closest("a");
101
- if (!a) return;
102
- if (preloadTimer) clearTimeout(preloadTimer);
103
- });
105
+ document.addEventListener("mouseover", (e) => {
106
+ const a = (e.target as Element).closest("a");
107
+ if (!a) return;
108
+ const href = a.getAttribute("href");
109
+ if (!href) return;
110
+ if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href)) return;
111
+
112
+ const preloadData = a.hasAttribute("data-sigil-preload-data");
113
+ const preloadCode = a.hasAttribute("data-sigil-preload-code");
114
+ if (!preloadData && !preloadCode) return;
115
+
116
+ if (preloadTimer) clearTimeout(preloadTimer);
117
+ preloadTimer = setTimeout(() => {
118
+ if (preloadCode) {
119
+ const link = document.createElement("link");
120
+ link.rel = "prefetch";
121
+ link.href = href;
122
+ document.head.appendChild(link);
123
+ }
124
+ if (preloadData) {
125
+ fetch(href, {
126
+ headers: {"x-grimoire-navigate": "1"},
127
+ priority: "low",
128
+ }).catch(() => {
129
+ });
130
+ }
131
+ }, 80);
132
+ });
133
+
134
+ document.addEventListener("mouseout", (e) => {
135
+ const a = (e.target as Element).closest("a");
136
+ if (!a) return;
137
+ if (preloadTimer) clearTimeout(preloadTimer);
138
+ });
104
139
  }
105
140
 
106
141
  let lastState: {
107
- data: any;
108
- layoutData: any[];
109
- params: any;
110
- pattern: string;
142
+ data: any;
143
+ layoutData: any[];
144
+ params: any;
145
+ pattern: string;
111
146
  } | null = null;
112
147
 
113
148
  function buildRouteTree(state: typeof lastState): any {
114
- const { data, layoutData, params, pattern } = state!;
115
- const Page = routeMap[pattern];
116
- if (!Page) throw new Error(`no component for pattern ${pattern}`);
117
-
118
- const matchedLayouts = layoutList
119
- .filter(
120
- (l) =>
121
- l.path === "/" ||
122
- pattern === l.path ||
123
- pattern.startsWith(`${l.path}/`),
124
- )
125
- .sort((a, b) => a.path.length - b.path.length);
126
-
127
- let renderFn = () => {
128
- const pageNode = Page({ data, params });
129
- const pageDiv = document.createElement("div");
130
- pageDiv.id = "grimoire-page";
131
- pageDiv.appendChild(pageNode);
132
- return pageDiv;
133
- };
134
-
135
- for (let i = matchedLayouts.length - 1; i >= 0; i--) {
136
- const LayoutComponent = matchedLayouts[i].component;
137
- const innerRender = renderFn;
138
- const currentLayoutData = layoutData?.[i];
139
- renderFn = () => {
140
- const childNode = innerRender();
141
- return LayoutComponent({
142
- data: currentLayoutData,
143
- params,
144
- children: childNode,
145
- });
146
- };
147
- }
148
-
149
- return renderFn();
149
+ const {data, layoutData, params, pattern} = state!;
150
+ const Page = routeMap[pattern];
151
+ if (!Page) throw new Error(`no component for pattern ${pattern}`);
152
+
153
+ const matchedLayouts = layoutList
154
+ .filter(
155
+ (l) =>
156
+ l.path === "/" ||
157
+ pattern === l.path ||
158
+ pattern.startsWith(`${l.path}/`),
159
+ )
160
+ .sort((a, b) => a.path.length - b.path.length);
161
+
162
+ let renderFn = () => {
163
+ const pageNode = Page({data, params});
164
+ const pageDiv = document.createElement("div");
165
+ pageDiv.id = "grimoire-page";
166
+ pageDiv.appendChild(pageNode);
167
+ return pageDiv;
168
+ };
169
+
170
+ for (let i = matchedLayouts.length - 1; i >= 0; i--) {
171
+ const LayoutComponent = matchedLayouts[i].component;
172
+ const innerRender = renderFn;
173
+ const currentLayoutData = layoutData?.[i];
174
+ renderFn = () => {
175
+ const childNode = innerRender();
176
+ return LayoutComponent({
177
+ data: currentLayoutData,
178
+ params,
179
+ children: childNode,
180
+ });
181
+ };
182
+ }
183
+
184
+ return renderFn();
185
+ }
186
+
187
+ function matchClientPattern(pattern: string, pathname: string): boolean {
188
+ // haha pp and ph
189
+ const pp = pattern.split("/").filter(Boolean);
190
+ const ph = pathname.split("/").filter(Boolean);
191
+ let pi = 0, pj = 0;
192
+ while (pi < pp.length) {
193
+ if (pp[pi]!.startsWith("*")) return true;
194
+ if (pj >= ph.length) return false;
195
+ if (!pp[pi]!.startsWith(":") && pp[pi] !== ph[pj]) return false;
196
+ pi++;
197
+ pj++;
198
+ }
199
+ return pj === ph.length;
200
+ }
201
+
202
+ function findPattern(pathname: string): string | null {
203
+ for (const pattern of Object.keys(routeMap)) {
204
+ if (matchClientPattern(pattern, pathname)) return pattern;
205
+ }
206
+ return null;
150
207
  }
151
208
 
152
- export async function navigate(path: string) {
153
- const url = new URL(path, location.origin);
154
-
155
- if (beforeNavigateCb) {
156
- const shouldProceed = beforeNavigateCb(url);
157
- if (shouldProceed === false) return;
158
- }
159
- onNavigateCb?.(url);
160
- saveScrollPosition();
161
-
162
- const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
163
- const contentType = res.headers.get("content-type") ?? "";
164
- if (!contentType.includes("application/json")) {
165
- window.location.href = path;
166
- return;
167
- }
168
- const json = await res.json();
169
- const { data, layoutData, params, pattern, head } = json;
170
- const Page = routeMap[pattern];
171
- if (!Page) {
172
- window.location.href = path;
173
- return;
174
- }
175
-
176
- let mergedData = data;
177
- if (Page.load) {
178
- try {
179
- const clientData = await Page.load({
180
- params,
181
- url,
182
- request: new Request(url),
183
- });
184
- mergedData = { ...clientData, ...data };
185
- } catch (e: any) {
186
- if (e?.location) {
187
- window.location.href = e.location;
188
- return;
189
- }
190
- console.error("[grimoire] universal load error:", e);
191
- }
192
- }
193
-
194
- // track state for HMR rerender
195
- lastState = { data: mergedData, layoutData, params, pattern };
196
- (globalThis as any).__grimoire_current_pattern__ = pattern;
197
-
198
- disposeCurrentPage?.();
199
- disposeCurrentPage = null;
200
- pushHydrationNodes([]);
201
- let rootNode: any;
202
- disposeCurrentPage = withEffectScope(() => {
203
- try {
204
- rootNode = buildRouteTree(lastState!);
205
- } catch (e) {
206
- console.error(e);
207
- }
208
- });
209
- popHydrationNodes();
210
-
211
- updateHead(head);
212
- document.title = head?.title ?? document.title;
213
- document.getElementById("grimoire-root")?.replaceChildren(rootNode);
214
- currentPath = path;
215
- history.pushState(null, "", path);
216
- restoreScrollPosition(path);
217
- afterNavigateCb?.(url);
209
+ export async function navigate(path: string, replace = false) {
210
+ const url = new URL(path, location.origin);
211
+
212
+ if (beforeNavigateCb) {
213
+ const shouldProceed = beforeNavigateCb(url);
214
+ if (shouldProceed === false) return;
215
+ }
216
+ onNavigateCb?.(url);
217
+ saveScrollPosition();
218
+
219
+ // load the loading immediately
220
+ const destPattern = findPattern(url.pathname);
221
+ const DestPage = destPattern ? routeMap[destPattern] : null;
222
+ if (DestPage?.loading) {
223
+ disposeCurrentPage?.();
224
+ disposeCurrentPage = null;
225
+ pushHydrationNodes([]);
226
+ let loadingNode: any;
227
+ disposeCurrentPage = withEffectScope(() => {
228
+ loadingNode = (DestPage as any).loading();
229
+ });
230
+ popHydrationNodes();
231
+ // replace only grimoire-page, keeps layout stable during transition
232
+ const pageEl = document.getElementById("grimoire-page");
233
+ if (pageEl) pageEl.replaceChildren(loadingNode);
234
+ else document.getElementById("grimoire-root")?.replaceChildren(loadingNode);
235
+ }
236
+
237
+ const res = await fetch(path, {headers: {"x-grimoire-navigate": "1"}});
238
+ const contentType = res.headers.get("content-type") ?? "";
239
+ if (!contentType.includes("application/json")) {
240
+ window.location.href = path;
241
+ return;
242
+ }
243
+ const json = await res.json();
244
+ const {data, layoutData, params, pattern, head} = json;
245
+ const Page = routeMap[pattern];
246
+ if (!Page) {
247
+ window.location.href = path;
248
+ return;
249
+ }
250
+
251
+ let mergedData = data;
252
+ if (Page.load) {
253
+ try {
254
+ _collectingDeps = new Set()
255
+ const clientData = await Page.load({
256
+ params,
257
+ url,
258
+ request: new Request(url),
259
+ });
260
+ routeDeps.set(pattern, _collectingDeps);
261
+ _collectingDeps = null;
262
+ mergedData = {...clientData, ...data};
263
+ } catch (e: any) {
264
+ _collectingDeps = null;
265
+ if (e?.location) {
266
+ window.location.href = e.location;
267
+ return;
268
+ }
269
+ console.error("[grimoire] universal load error:", e);
270
+ }
271
+ }
272
+
273
+ // track state for HMR rerender
274
+ lastState = {data: mergedData, layoutData, params, pattern};
275
+ (globalThis as any).__grimoire_current_pattern__ = pattern;
276
+
277
+ disposeCurrentPage?.();
278
+ disposeCurrentPage = null;
279
+ pushHydrationNodes([]);
280
+ let rootNode: any;
281
+ disposeCurrentPage = withEffectScope(() => {
282
+ try {
283
+ rootNode = buildRouteTree(lastState!);
284
+ } catch (e) {
285
+ console.error(e);
286
+ }
287
+ });
288
+ popHydrationNodes();
289
+
290
+ updateHead(head);
291
+ document.title = head?.title ?? document.title;
292
+ document.getElementById("grimoire-root")?.replaceChildren(rootNode);
293
+ currentPath = path;
294
+
295
+ history[replace ? "replaceState" : "pushState"](null, "", path);
296
+ restoreScrollPosition(path);
297
+ afterNavigateCb?.(url);
218
298
  }
219
299
 
220
300
  export function initRouter(
221
- routes: Record<
222
- string,
223
- ((props: any) => any) & { load?: (ctx: any) => Promise<any> }
224
- >,
225
- layouts: any[],
226
- initialDispose?: () => void,
301
+ routes: Record<
302
+ string,
303
+ ((props: any) => any) & { load?: (ctx: any) => Promise<any> }
304
+ >,
305
+ layouts: any[],
306
+ initialDispose?: () => void,
227
307
  ) {
228
- routeMap = routes;
229
- layoutList = layouts;
230
- disposeCurrentPage = initialDispose ?? null;
231
- currentPath = location.pathname;
232
-
233
- // set initial HMR state from SSR
234
- const stateEl = document.getElementById("__grimoire_state__");
235
- if (stateEl) {
236
- const state = JSON.parse(stateEl.textContent!);
237
- lastState = {
238
- data: state.data,
239
- layoutData: state.layoutData,
240
- params: state.params,
241
- pattern: state.pattern,
242
- };
243
- (globalThis as any).__grimoire_current_pattern__ = state.pattern;
244
- (globalThis as any).__grimoire_routes__ = routeMap;
245
- (globalThis as any).__grimoire_rerender__ = hmrRerender;
246
- (globalThis as any).__grimoire_navigate__ = (path: string) =>
247
- navigate(path);
248
- }
249
-
250
- saveScrollPosition();
251
- document.addEventListener("click", handleClick);
252
- window.addEventListener("popstate", () => {
253
- if (location.pathname !== currentPath) {
254
- saveScrollPosition();
255
- currentPath = location.pathname;
256
- navigate(location.pathname);
257
- }
258
- });
259
- setupPreload();
308
+ routeMap = routes;
309
+ layoutList = layouts;
310
+ disposeCurrentPage = initialDispose ?? null;
311
+ currentPath = location.pathname;
312
+
313
+ // set initial HMR state from SSR
314
+ const stateEl = document.getElementById("__grimoire_state__");
315
+ if (stateEl) {
316
+ const state = JSON.parse(stateEl.textContent!);
317
+ lastState = {
318
+ data: state.data,
319
+ layoutData: state.layoutData,
320
+ params: state.params,
321
+ pattern: state.pattern,
322
+ };
323
+ (globalThis as any).__grimoire_current_pattern__ = state.pattern;
324
+ (globalThis as any).__grimoire_routes__ = routeMap;
325
+ (globalThis as any).__grimoire_rerender__ = hmrRerender;
326
+ (globalThis as any).__grimoire_navigate__ = (path: string) =>
327
+ navigate(path);
328
+ }
329
+
330
+ saveScrollPosition();
331
+ document.addEventListener("click", handleClick);
332
+ window.addEventListener("popstate", () => {
333
+ if (location.pathname !== currentPath) {
334
+ saveScrollPosition();
335
+ currentPath = location.pathname;
336
+ navigate(location.pathname);
337
+ }
338
+ });
339
+ setupPreload();
260
340
  }
261
341
 
262
342
  function updateHead(headHtml: string) {
263
- document
264
- .querySelectorAll("[data-grimoire-head]")
265
- //biome-ignore lint/suspicious/useIterableCallbackReturn: shut up
266
- .forEach((el) => el.remove());
267
- const parsed = headHtml
268
- ? new DOMParser().parseFromString(`<head>${headHtml}</head>`, "text/html")
269
- : null;
270
- const incomingTitle = parsed?.querySelector("title");
271
- //biome-ignore lint/suspicious/useIterableCallbackReturn: shut up
272
- document.querySelectorAll("title").forEach((el) => el.remove());
273
- document.title = incomingTitle?.textContent ?? document.title;
274
- if (parsed) {
275
- for (const el of Array.from(parsed.head.children)) {
276
- if (el.tagName === "TITLE") continue;
277
- (el as HTMLElement).dataset.grimoireHead = "1";
278
- document.head.appendChild(el);
279
- }
280
- }
343
+ document
344
+ .querySelectorAll("[data-grimoire-head]")
345
+ //biome-ignore lint/suspicious/useIterableCallbackReturn: shut up
346
+ .forEach((el) => el.remove());
347
+ const parsed = headHtml
348
+ ? new DOMParser().parseFromString(`<head>${headHtml}</head>`, "text/html")
349
+ : null;
350
+ const incomingTitle = parsed?.querySelector("title");
351
+ //biome-ignore lint/suspicious/useIterableCallbackReturn: shut up
352
+ document.querySelectorAll("title").forEach((el) => el.remove());
353
+ document.title = incomingTitle?.textContent ?? document.title;
354
+ if (parsed) {
355
+ for (const el of Array.from(parsed.head.children)) {
356
+ if (el.tagName === "TITLE") continue;
357
+ (el as HTMLElement).dataset.grimoireHead = "1";
358
+ document.head.appendChild(el);
359
+ }
360
+ }
281
361
  }
282
362
 
283
363
  function handleClick(e: MouseEvent) {
284
- const a = (e.target as Element).closest("a");
285
- if (!a) return;
286
- const href = a.getAttribute("href");
287
- if (!href) return;
288
- if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href)) return;
289
- e.preventDefault();
290
- navigate(href);
364
+ const a = (e.target as Element).closest("a");
365
+ if (!a) return;
366
+ const href = a.getAttribute("href");
367
+ if (!href) return;
368
+ if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href)) return;
369
+ e.preventDefault();
370
+ navigate(href);
291
371
  }