@sigil-dev/grimoire 0.9.11 → 0.9.13

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.
@@ -1,55 +0,0 @@
1
- // .grimoire/_routes.ts
2
- var routes = {};
3
-
4
- // src/client-router.ts
5
- var routeMap = {};
6
- async function navigate(path) {
7
- const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
8
- const json = await res.json();
9
- console.log("navigate response:", json);
10
- const { data, params, pattern, head } = json;
11
- const Page = routeMap[pattern];
12
- if (!Page) {
13
- window.location.href = path;
14
- return;
15
- }
16
- const node = Page({ ...data, params });
17
- const slot = document.getElementById("grimoire-page");
18
- if (!slot)
19
- return;
20
- slot.replaceChildren(node);
21
- updateHead(head);
22
- history.pushState({}, "", path);
23
- window.scrollTo(0, 0);
24
- }
25
- function initRouter(routes2) {
26
- routeMap = routes2;
27
- document.addEventListener("click", handleClick);
28
- window.addEventListener("popstate", () => navigate(location.pathname));
29
- }
30
- function updateHead(headHtml) {
31
- document.querySelectorAll("[data-grimoire-head]").forEach((el) => el.remove());
32
- if (!headHtml)
33
- return;
34
- const tmp = document.createElement("head");
35
- tmp.innerHTML = headHtml;
36
- for (const el of Array.from(tmp.children)) {
37
- el.dataset.grimoireHead = "1";
38
- document.head.appendChild(el);
39
- }
40
- }
41
- function handleClick(e) {
42
- const a = e.target.closest("a");
43
- if (!a)
44
- return;
45
- const href = a.getAttribute("href");
46
- if (!href)
47
- return;
48
- if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href))
49
- return;
50
- e.preventDefault();
51
- navigate(href);
52
- }
53
-
54
- // src/client.ts
55
- initRouter(routes);
@@ -1,63 +0,0 @@
1
- // .grimoire/_routes.ts
2
- var routes = {};
3
-
4
- // src/client-router.ts
5
- var routeMap = {};
6
- async function navigate(path) {
7
- const res = await fetch(path, { headers: { "x-grimoire-navigate": "1" } });
8
- const json = await res.json();
9
- console.log("navigate response:", json);
10
- const { data, params, pattern, head } = json;
11
- const Page = routeMap[pattern];
12
- if (!Page) {
13
- window.location.href = path;
14
- return;
15
- }
16
- const node = Page({ ...data, params });
17
- const slot = document.getElementById("grimoire-page");
18
- if (!slot)
19
- return;
20
- slot.replaceChildren(node);
21
- updateHead(head);
22
- history.pushState({}, "", path);
23
- window.scrollTo(0, 0);
24
- }
25
- function initRouter(routes2) {
26
- routeMap = routes2;
27
- document.addEventListener("click", handleClick);
28
- window.addEventListener("popstate", () => navigate(location.pathname));
29
- }
30
- function updateHead(headHtml) {
31
- document.querySelectorAll("[data-grimoire-head]").forEach((el) => el.remove());
32
- if (!headHtml)
33
- return;
34
- const tmp = document.createElement("head");
35
- tmp.innerHTML = headHtml;
36
- for (const el of Array.from(tmp.children)) {
37
- el.dataset.grimoireHead = "1";
38
- document.head.appendChild(el);
39
- }
40
- }
41
- function handleClick(e) {
42
- const a = e.target.closest("a");
43
- if (!a)
44
- return;
45
- const href = a.getAttribute("href");
46
- if (!href)
47
- return;
48
- if (/^(https?:\/\/|\/\/|#|mailto:|tel:)/.test(href))
49
- return;
50
- e.preventDefault();
51
- navigate(href);
52
- }
53
-
54
- // src/hydrate.ts
55
- var stateEl = document.getElementById("__grimoire_state__");
56
- if (stateEl) {
57
- const state = JSON.parse(stateEl.textContent);
58
- const Page = routes[state.pattern];
59
- if (Page) {
60
- Page({ ...state.data, params: state.params });
61
- }
62
- }
63
- initRouter(routes);