@sigil-dev/grimoire 0.9.20 → 0.9.22
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/README.md +83 -83
- package/index.ts +50 -48
- package/package.json +16 -5
- package/public/__grimoire__/grimoire-client.js +12 -0
- package/public/__grimoire__/runtime.js +1241 -0
- package/server.ts +22 -20
- package/src/adapters/bun.ts +17 -0
- package/src/adapters/static.ts +41 -0
- package/src/adapters/types.ts +36 -0
- package/src/base.ts +91 -0
- package/src/client/csrf.ts +47 -47
- package/src/client/deferred.ts +179 -179
- package/src/client/enhance.ts +160 -160
- package/src/client/router.ts +870 -833
- package/src/dev/compile-module.ts +211 -211
- package/src/dev/loader.ts +141 -141
- package/src/dev/resolve.ts +70 -70
- package/src/dev/runtime-bundle.ts +51 -51
- package/src/env/modules.ts +62 -62
- package/src/env/required.ts +42 -0
- package/src/env/typegen.ts +61 -61
- package/src/headers.ts +105 -114
- package/src/logger/transports.ts +117 -117
- package/src/rendering/head.ts +49 -49
- package/src/rendering/hydrate.ts +161 -161
- package/src/rendering/images.ts +43 -43
- package/src/rendering/index.ts +755 -745
- package/src/rendering/preload.ts +101 -95
- package/src/rendering/ssrPlugin.ts +108 -108
- package/src/rendering/timing.ts +40 -40
- package/src/routing/router.ts +186 -186
- package/src/routing/scanner.ts +225 -196
- package/src/routing/transform-routes.ts +102 -102
- package/src/server/after-response.ts +206 -194
- package/src/server/asset-cache.ts +57 -55
- package/src/server/build.ts +262 -249
- package/src/server/cached.ts +114 -114
- package/src/server/client-address.ts +82 -82
- package/src/server/client-dir.ts +57 -57
- package/src/server/client-entry.ts +44 -0
- package/src/server/cookie-utils.ts +80 -80
- package/src/server/coordinator.ts +476 -471
- package/src/server/hooks.ts +122 -122
- package/src/server/index.ts +1138 -1022
- package/src/server/plugins.ts +172 -172
- package/src/server/prerender.ts +444 -0
- package/src/server/reserved.ts +17 -0
- package/src/server/resolver.ts +98 -98
- package/src/server/rewrite.ts +28 -0
- package/src/server/warm.ts +91 -91
- package/src/server/with-headers.ts +27 -0
- package/src/server/worker.ts +74 -72
- package/src/testing/dom.ts +73 -0
- package/src/testing/index.ts +169 -0
- package/src/testing/server.ts +162 -0
- package/src/typegen/index.ts +450 -450
- package/src/types.ts +501 -432
- package/test/after-response.test.ts +132 -113
- package/test/asset-cache-policy.test.ts +96 -96
- package/test/base.test.ts +134 -0
- package/test/cached.test.ts +126 -126
- package/test/client-address.test.ts +78 -78
- package/test/client-csrf.test.ts +61 -61
- package/test/client-dir.test.ts +101 -69
- package/test/client-router.test.ts +789 -734
- package/test/coordinator.test.ts +96 -94
- package/test/deferred.test.ts +256 -256
- package/test/dev-loader.test.ts +30 -30
- package/test/env.test.ts +168 -168
- package/test/force-production.test.ts +44 -0
- package/test/images.test.ts +49 -49
- package/test/locals-header.test.ts +61 -0
- package/test/middleware.test.ts +243 -243
- package/test/parser-plugins.test.ts +92 -92
- package/test/plugin-handle.test.ts +62 -62
- package/test/plugin-services-context.test.ts +97 -97
- package/test/preload.test.ts +48 -48
- package/test/prerender.test.ts +353 -0
- package/test/rendering.test.ts +798 -798
- package/test/required-env.test.ts +32 -0
- package/test/rewrite-html.test.ts +90 -0
- package/test/scanning.test.ts +349 -314
- package/test/server.test.ts +640 -619
- package/test/services.test.ts +90 -90
- package/test/streaming.test.ts +378 -378
- package/test/testing-helpers.test.ts +166 -0
- package/test/typegen.test.ts +805 -799
- package/test/warm.test.ts +96 -96
- package/test/worker-context.test.ts +59 -59
- package/test/workspace-files.test.ts +149 -146
- package/test/workspace-versions.test.ts +131 -131
- package/.grimoire/_routes.ts +0 -4
- package/public/__grimoire__/client.js +0 -55
- package/public/__grimoire__/hydrate.js +0 -63
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { readFileSync, readdirSync } from "node:fs";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A packed tarball must not carry a version its manifest does not have.
|
|
7
|
-
*
|
|
8
|
-
* `bun pm pack` rewrites `workspace:*` to a concrete version by reading the
|
|
9
|
-
* *lockfile*, not the manifest. So editing a package.json to bump a version
|
|
10
|
-
* and then packing, without installing first, produces a tarball that
|
|
11
|
-
* silently depends on the old version of a sibling.
|
|
12
|
-
*
|
|
13
|
-
* Not hypothetical. Bumping `packages/compiler` to 0.9.12 without running
|
|
14
|
-
* `bun install` left `bun.lock` at 0.9.10, so every grimoire tarball packed
|
|
15
|
-
* afterwards pinned `@sigil-dev/compiler: 0.9.10`. The app installed it and
|
|
16
|
-
* failed at boot with
|
|
17
|
-
*
|
|
18
|
-
* Export named 'clientStyleSnippet' not found in
|
|
19
|
-
* .../@sigil-dev/compiler/src/babel/util/css.ts
|
|
20
|
-
*
|
|
21
|
-
* which reads like a compiler bug and is really a packaging one. It cost a
|
|
22
|
-
* long time to find, because nothing in the failure mentioned a version.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const ROOT = new URL("../../../", import.meta.url).pathname;
|
|
26
|
-
const lock = readFileSync(join(ROOT, "bun.lock"), "utf8");
|
|
27
|
-
|
|
28
|
-
interface Manifest {
|
|
29
|
-
name?: string;
|
|
30
|
-
version?: string;
|
|
31
|
-
private?: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Every workspace under `packages/*`, whether or not it carries a version. */
|
|
35
|
-
function allWorkspaces(): { dir: string; manifest: Manifest }[] {
|
|
36
|
-
return readdirSync(join(ROOT, "packages"), { withFileTypes: true })
|
|
37
|
-
.filter((e) => e.isDirectory())
|
|
38
|
-
.flatMap((e) => {
|
|
39
|
-
try {
|
|
40
|
-
const manifest = JSON.parse(
|
|
41
|
-
readFileSync(join(ROOT, "packages", e.name, "package.json"), "utf8"),
|
|
42
|
-
) as Manifest;
|
|
43
|
-
return [{ dir: e.name, manifest }];
|
|
44
|
-
} catch {
|
|
45
|
-
return [];
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
.filter(({ manifest }) => manifest.name?.startsWith("@sigil-dev/"));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* The ones an app can install. `site` and the two demos carry no version and
|
|
53
|
-
* are never packed, so demanding one of them would be this test failing for a
|
|
54
|
-
* reason that has nothing to do with the bug it exists to catch.
|
|
55
|
-
*/
|
|
56
|
-
function shipped(): { dir: string; manifest: Manifest & { name: string; version: string } }[] {
|
|
57
|
-
return allWorkspaces().filter(
|
|
58
|
-
(w): w is { dir: string; manifest: Manifest & { name: string; version: string } } =>
|
|
59
|
-
typeof w.manifest.name === "string" &&
|
|
60
|
-
typeof w.manifest.version === "string" &&
|
|
61
|
-
!w.manifest.private,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
describe("workspace versions", () => {
|
|
66
|
-
test("the lockfile agrees with every shipped manifest", () => {
|
|
67
|
-
// bun.lock records each workspace as
|
|
68
|
-
// "packages/compiler": { "name": "@sigil-dev/compiler", "version": "0.9.12",
|
|
69
|
-
// so a stale entry is a correct name next to a wrong version.
|
|
70
|
-
const mismatches: string[] = [];
|
|
71
|
-
for (const { dir, manifest } of shipped()) {
|
|
72
|
-
const entry = new RegExp(
|
|
73
|
-
`"packages/${dir}": \\{\\s*"name": "${manifest.name}",\\s*"version": "([^"]+)"`,
|
|
74
|
-
).exec(lock);
|
|
75
|
-
if (!entry) {
|
|
76
|
-
mismatches.push(`${manifest.name}: absent from bun.lock`);
|
|
77
|
-
continue;
|
|
78
|
-
}
|
|
79
|
-
if (entry[1] !== manifest.version) {
|
|
80
|
-
mismatches.push(
|
|
81
|
-
`${manifest.name}: manifest says ${manifest.version} but bun.lock says ` +
|
|
82
|
-
`${entry[1]} — run \`bun install\` before \`bun pm pack\`, or the ` +
|
|
83
|
-
`tarball pins the old version of a sibling`,
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
expect(mismatches).toEqual([]);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("every shipped package is at the same version", () => {
|
|
91
|
-
// Two packages at different versions means a `workspace:*` between
|
|
92
|
-
// them resolves to whichever one the lockfile saw, which is how a
|
|
93
|
-
// packed dependency ends up pointing at a version nothing claims.
|
|
94
|
-
const distinct = [...new Set(shipped().map(({ manifest }) => manifest.version))];
|
|
95
|
-
expect(
|
|
96
|
-
distinct.length === 1
|
|
97
|
-
? []
|
|
98
|
-
: [`packages sit at ${distinct.join(", ")} — a release moves them together`],
|
|
99
|
-
).toEqual([]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
test("the release version is not already published with other content", async () => {
|
|
103
|
-
// The same trap wearing a different hat. `@sigil-dev/grimoire@0.9.12`
|
|
104
|
-
// was on npm, published before plugin services existed, while this
|
|
105
|
-
// tree kept calling itself 0.9.12. An app pinning that exact version
|
|
106
|
-
// installed the registry copy *beside* the local tarball: two copies,
|
|
107
|
-
// both reporting 0.9.12, one with no `collectServices` at all.
|
|
108
|
-
//
|
|
109
|
-
// So a version is only safe to depend on once it is published *with*
|
|
110
|
-
// this content. Until then a consumer resolves to the older tarball.
|
|
111
|
-
const version = shipped()[0]?.manifest.version;
|
|
112
|
-
if (!version) return;
|
|
113
|
-
|
|
114
|
-
// Registry access is best-effort: a suite that needs the network to
|
|
115
|
-
// pass is a suite that gets skipped in CI without saying so.
|
|
116
|
-
const res = await fetch("https://registry.npmjs.org/@sigil-dev%2Fgrimoire", {
|
|
117
|
-
signal: AbortSignal.timeout(4000),
|
|
118
|
-
}).catch(() => null);
|
|
119
|
-
if (!res?.ok) return;
|
|
120
|
-
const body = (await res.json()) as { versions?: Record<string, unknown> };
|
|
121
|
-
const alreadyThere = Boolean(body.versions?.[version]);
|
|
122
|
-
expect(
|
|
123
|
-
alreadyThere
|
|
124
|
-
? []
|
|
125
|
-
: [
|
|
126
|
-
`${version} is not on npm yet, so it cannot be pinned by a consumer`,
|
|
127
|
-
`without pulling a different tarball at the same version number`,
|
|
128
|
-
],
|
|
129
|
-
).toEqual([]);
|
|
130
|
-
});
|
|
131
|
-
});
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A packed tarball must not carry a version its manifest does not have.
|
|
7
|
+
*
|
|
8
|
+
* `bun pm pack` rewrites `workspace:*` to a concrete version by reading the
|
|
9
|
+
* *lockfile*, not the manifest. So editing a package.json to bump a version
|
|
10
|
+
* and then packing, without installing first, produces a tarball that
|
|
11
|
+
* silently depends on the old version of a sibling.
|
|
12
|
+
*
|
|
13
|
+
* Not hypothetical. Bumping `packages/compiler` to 0.9.12 without running
|
|
14
|
+
* `bun install` left `bun.lock` at 0.9.10, so every grimoire tarball packed
|
|
15
|
+
* afterwards pinned `@sigil-dev/compiler: 0.9.10`. The app installed it and
|
|
16
|
+
* failed at boot with
|
|
17
|
+
*
|
|
18
|
+
* Export named 'clientStyleSnippet' not found in
|
|
19
|
+
* .../@sigil-dev/compiler/src/babel/util/css.ts
|
|
20
|
+
*
|
|
21
|
+
* which reads like a compiler bug and is really a packaging one. It cost a
|
|
22
|
+
* long time to find, because nothing in the failure mentioned a version.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const ROOT = new URL("../../../", import.meta.url).pathname;
|
|
26
|
+
const lock = readFileSync(join(ROOT, "bun.lock"), "utf8");
|
|
27
|
+
|
|
28
|
+
interface Manifest {
|
|
29
|
+
name?: string;
|
|
30
|
+
version?: string;
|
|
31
|
+
private?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Every workspace under `packages/*`, whether or not it carries a version. */
|
|
35
|
+
function allWorkspaces(): { dir: string; manifest: Manifest }[] {
|
|
36
|
+
return readdirSync(join(ROOT, "packages"), { withFileTypes: true })
|
|
37
|
+
.filter((e) => e.isDirectory())
|
|
38
|
+
.flatMap((e) => {
|
|
39
|
+
try {
|
|
40
|
+
const manifest = JSON.parse(
|
|
41
|
+
readFileSync(join(ROOT, "packages", e.name, "package.json"), "utf8"),
|
|
42
|
+
) as Manifest;
|
|
43
|
+
return [{ dir: e.name, manifest }];
|
|
44
|
+
} catch {
|
|
45
|
+
return [];
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.filter(({ manifest }) => manifest.name?.startsWith("@sigil-dev/"));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The ones an app can install. `site` and the two demos carry no version and
|
|
53
|
+
* are never packed, so demanding one of them would be this test failing for a
|
|
54
|
+
* reason that has nothing to do with the bug it exists to catch.
|
|
55
|
+
*/
|
|
56
|
+
function shipped(): { dir: string; manifest: Manifest & { name: string; version: string } }[] {
|
|
57
|
+
return allWorkspaces().filter(
|
|
58
|
+
(w): w is { dir: string; manifest: Manifest & { name: string; version: string } } =>
|
|
59
|
+
typeof w.manifest.name === "string" &&
|
|
60
|
+
typeof w.manifest.version === "string" &&
|
|
61
|
+
!w.manifest.private,
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe("workspace versions", () => {
|
|
66
|
+
test("the lockfile agrees with every shipped manifest", () => {
|
|
67
|
+
// bun.lock records each workspace as
|
|
68
|
+
// "packages/compiler": { "name": "@sigil-dev/compiler", "version": "0.9.12",
|
|
69
|
+
// so a stale entry is a correct name next to a wrong version.
|
|
70
|
+
const mismatches: string[] = [];
|
|
71
|
+
for (const { dir, manifest } of shipped()) {
|
|
72
|
+
const entry = new RegExp(
|
|
73
|
+
`"packages/${dir}": \\{\\s*"name": "${manifest.name}",\\s*"version": "([^"]+)"`,
|
|
74
|
+
).exec(lock);
|
|
75
|
+
if (!entry) {
|
|
76
|
+
mismatches.push(`${manifest.name}: absent from bun.lock`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if (entry[1] !== manifest.version) {
|
|
80
|
+
mismatches.push(
|
|
81
|
+
`${manifest.name}: manifest says ${manifest.version} but bun.lock says ` +
|
|
82
|
+
`${entry[1]} — run \`bun install\` before \`bun pm pack\`, or the ` +
|
|
83
|
+
`tarball pins the old version of a sibling`,
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
expect(mismatches).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("every shipped package is at the same version", () => {
|
|
91
|
+
// Two packages at different versions means a `workspace:*` between
|
|
92
|
+
// them resolves to whichever one the lockfile saw, which is how a
|
|
93
|
+
// packed dependency ends up pointing at a version nothing claims.
|
|
94
|
+
const distinct = [...new Set(shipped().map(({ manifest }) => manifest.version))];
|
|
95
|
+
expect(
|
|
96
|
+
distinct.length === 1
|
|
97
|
+
? []
|
|
98
|
+
: [`packages sit at ${distinct.join(", ")} — a release moves them together`],
|
|
99
|
+
).toEqual([]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("the release version is not already published with other content", async () => {
|
|
103
|
+
// The same trap wearing a different hat. `@sigil-dev/grimoire@0.9.12`
|
|
104
|
+
// was on npm, published before plugin services existed, while this
|
|
105
|
+
// tree kept calling itself 0.9.12. An app pinning that exact version
|
|
106
|
+
// installed the registry copy *beside* the local tarball: two copies,
|
|
107
|
+
// both reporting 0.9.12, one with no `collectServices` at all.
|
|
108
|
+
//
|
|
109
|
+
// So a version is only safe to depend on once it is published *with*
|
|
110
|
+
// this content. Until then a consumer resolves to the older tarball.
|
|
111
|
+
const version = shipped()[0]?.manifest.version;
|
|
112
|
+
if (!version) return;
|
|
113
|
+
|
|
114
|
+
// Registry access is best-effort: a suite that needs the network to
|
|
115
|
+
// pass is a suite that gets skipped in CI without saying so.
|
|
116
|
+
const res = await fetch("https://registry.npmjs.org/@sigil-dev%2Fgrimoire", {
|
|
117
|
+
signal: AbortSignal.timeout(4000),
|
|
118
|
+
}).catch(() => null);
|
|
119
|
+
if (!res?.ok) return;
|
|
120
|
+
const body = (await res.json()) as { versions?: Record<string, unknown> };
|
|
121
|
+
const alreadyThere = Boolean(body.versions?.[version]);
|
|
122
|
+
expect(
|
|
123
|
+
alreadyThere
|
|
124
|
+
? []
|
|
125
|
+
: [
|
|
126
|
+
`${version} is not on npm yet, so it cannot be pinned by a consumer`,
|
|
127
|
+
`without pulling a different tarball at the same version number`,
|
|
128
|
+
],
|
|
129
|
+
).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
});
|
package/.grimoire/_routes.ts
DELETED
|
@@ -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);
|